OLD | NEW |
1 // Copyright (C) 2010 The Chromium OS Authors. All rights reserved. | 1 // Copyright (C) 2010 The Chromium OS Authors. All rights reserved. |
2 // Use of this source code is governed by the GPL v2 license that can | 2 // Use of this source code is governed by the GPL v2 license that can |
3 // be found in the LICENSE file. | 3 // be found in the LICENSE file. |
4 // | 4 // |
5 // Basic unittesting of dm-bht using google-gtest. | 5 // Basic unittesting of dm-bht using google-gtest. |
6 | 6 |
7 #include <base/basictypes.h> | 7 #include <base/basictypes.h> |
8 #include <base/logging.h> | 8 #include <base/logging.h> |
9 #include <base/scoped_ptr.h> | 9 #include <base/scoped_ptr.h> |
10 #include <gtest/gtest.h> | 10 #include <gtest/gtest.h> |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 | 199 |
200 for (unsigned int blocks = 0; blocks < total_blocks; ++blocks) { | 200 for (unsigned int blocks = 0; blocks < total_blocks; ++blocks) { |
201 DLOG(INFO) << "verifying block: " << blocks; | 201 DLOG(INFO) << "verifying block: " << blocks; |
202 EXPECT_EQ(0, dm_bht_verify_block(bht_.get(), blocks, zero_page)); | 202 EXPECT_EQ(0, dm_bht_verify_block(bht_.get(), blocks, zero_page)); |
203 } | 203 } |
204 | 204 |
205 EXPECT_EQ(0, dm_bht_destroy(bht_.get())); | 205 EXPECT_EQ(0, dm_bht_destroy(bht_.get())); |
206 free(zero_page); | 206 free(zero_page); |
207 } | 207 } |
208 | 208 |
209 TEST_F(MemoryBhtTest, CreateThenVerifyOddCount) { | 209 TEST_F(MemoryBhtTest, CreateThenVerifyRealParameters) { |
| 210 static const unsigned int total_blocks = 217600; |
| 211 // Set the root hash for a 0-filled image |
| 212 static const char kRootDigest[] = |
| 213 "15d5a180b5080a1d43e3fbd1f2cd021d0fc3ea91a8e330bad468b980c2fd4d8b"; |
| 214 // A page of all zeros |
| 215 u8 *zero_page = (u8 *)my_memalign(PAGE_SIZE, PAGE_SIZE); |
| 216 |
| 217 memset(zero_page, 0, PAGE_SIZE); |
| 218 |
| 219 SetupBht(3, total_blocks, "sha256"); |
| 220 dm_bht_set_root_hexdigest(bht_.get(), |
| 221 reinterpret_cast<const u8 *>(kRootDigest)); |
| 222 |
| 223 for (unsigned int blocks = 0; blocks < total_blocks; ++blocks) { |
| 224 DLOG(INFO) << "verifying block: " << blocks; |
| 225 EXPECT_EQ(0, dm_bht_verify_block(bht_.get(), blocks, zero_page)); |
| 226 } |
| 227 |
| 228 EXPECT_EQ(0, dm_bht_destroy(bht_.get())); |
| 229 free(zero_page); |
| 230 } |
| 231 |
| 232 TEST_F(MemoryBhtTest, CreateThenVerifyOddLeafCount) { |
210 static const unsigned int total_blocks = 16383; | 233 static const unsigned int total_blocks = 16383; |
211 // Set the root hash for a 0-filled image | 234 // Set the root hash for a 0-filled image |
212 static const char kRootDigest[] = | 235 static const char kRootDigest[] = |
213 "c78d187c430465bd7831fe4908247b6ab5107e3a826d933b71e85aa9a932e03c"; | 236 "c78d187c430465bd7831fe4908247b6ab5107e3a826d933b71e85aa9a932e03c"; |
214 // A page of all zeros | 237 // A page of all zeros |
215 u8 *zero_page = (u8 *)my_memalign(PAGE_SIZE, PAGE_SIZE); | 238 u8 *zero_page = (u8 *)my_memalign(PAGE_SIZE, PAGE_SIZE); |
216 | 239 |
217 memset(zero_page, 0, PAGE_SIZE); | 240 memset(zero_page, 0, PAGE_SIZE); |
218 | 241 |
219 SetupBht(4, total_blocks, "sha256"); | 242 SetupBht(4, total_blocks, "sha256"); |
220 dm_bht_set_root_hexdigest(bht_.get(), | 243 dm_bht_set_root_hexdigest(bht_.get(), |
221 reinterpret_cast<const u8 *>(kRootDigest)); | 244 reinterpret_cast<const u8 *>(kRootDigest)); |
222 | 245 |
223 for (unsigned int blocks = 0; blocks < total_blocks; ++blocks) { | 246 for (unsigned int blocks = 0; blocks < total_blocks; ++blocks) { |
224 DLOG(INFO) << "verifying block: " << blocks; | 247 DLOG(INFO) << "verifying block: " << blocks; |
225 EXPECT_EQ(0, dm_bht_verify_block(bht_.get(), blocks, zero_page)); | 248 EXPECT_EQ(0, dm_bht_verify_block(bht_.get(), blocks, zero_page)); |
226 } | 249 } |
227 | 250 |
228 EXPECT_EQ(0, dm_bht_destroy(bht_.get())); | 251 EXPECT_EQ(0, dm_bht_destroy(bht_.get())); |
229 free(zero_page); | 252 free(zero_page); |
230 } | 253 } |
231 | 254 |
| 255 TEST_F(MemoryBhtTest, CreateThenVerifyOddNodeCount) { |
| 256 static const unsigned int total_blocks = 16000; |
| 257 // Set the root hash for a 0-filled image |
| 258 static const char kRootDigest[] = |
| 259 "13e04b6aa410187b900834aa23e45f3e5240b0c4d2fadb2d8836a357c33499f0"; |
| 260 // A page of all zeros |
| 261 u8 *zero_page = (u8 *)my_memalign(PAGE_SIZE, PAGE_SIZE); |
| 262 |
| 263 memset(zero_page, 0, PAGE_SIZE); |
| 264 |
| 265 SetupBht(4, total_blocks, "sha256"); |
| 266 dm_bht_set_root_hexdigest(bht_.get(), |
| 267 reinterpret_cast<const u8 *>(kRootDigest)); |
| 268 |
| 269 for (unsigned int blocks = 0; blocks < total_blocks; ++blocks) { |
| 270 DLOG(INFO) << "verifying block: " << blocks; |
| 271 EXPECT_EQ(0, dm_bht_verify_block(bht_.get(), blocks, zero_page)); |
| 272 } |
| 273 |
| 274 EXPECT_EQ(0, dm_bht_destroy(bht_.get())); |
| 275 free(zero_page); |
| 276 } |
| 277 |
232 TEST_F(MemoryBhtTest, CreateThenVerifyBadHashBlock) { | 278 TEST_F(MemoryBhtTest, CreateThenVerifyBadHashBlock) { |
233 static const unsigned int total_blocks = 16384; | 279 static const unsigned int total_blocks = 16384; |
234 // Set the root hash for a 0-filled image | 280 // Set the root hash for a 0-filled image |
235 static const char kRootDigest[] = | 281 static const char kRootDigest[] = |
236 "45d65d6f9e5a962f4d80b5f1bd7a918152251c27bdad8c5f52b590c129833372"; | 282 "45d65d6f9e5a962f4d80b5f1bd7a918152251c27bdad8c5f52b590c129833372"; |
237 // A page of all zeros | 283 // A page of all zeros |
238 u8 *zero_page = (u8 *)my_memalign(PAGE_SIZE, PAGE_SIZE); | 284 u8 *zero_page = (u8 *)my_memalign(PAGE_SIZE, PAGE_SIZE); |
239 | 285 |
240 memset(zero_page, 0, PAGE_SIZE); | 286 memset(zero_page, 0, PAGE_SIZE); |
241 | 287 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 EXPECT_LT(dm_bht_verify_block(bht_.get(), 0, bad_page), 0); | 339 EXPECT_LT(dm_bht_verify_block(bht_.get(), 0, bad_page), 0); |
294 EXPECT_LT(dm_bht_verify_block(bht_.get(), 127, bad_page), 0); | 340 EXPECT_LT(dm_bht_verify_block(bht_.get(), 127, bad_page), 0); |
295 EXPECT_LT(dm_bht_verify_block(bht_.get(), 128, bad_page), 0); | 341 EXPECT_LT(dm_bht_verify_block(bht_.get(), 128, bad_page), 0); |
296 EXPECT_LT(dm_bht_verify_block(bht_.get(), 255, bad_page), 0); | 342 EXPECT_LT(dm_bht_verify_block(bht_.get(), 255, bad_page), 0); |
297 EXPECT_LT(dm_bht_verify_block(bht_.get(), 256, bad_page), 0); | 343 EXPECT_LT(dm_bht_verify_block(bht_.get(), 256, bad_page), 0); |
298 EXPECT_LT(dm_bht_verify_block(bht_.get(), 383, bad_page), 0); | 344 EXPECT_LT(dm_bht_verify_block(bht_.get(), 383, bad_page), 0); |
299 | 345 |
300 EXPECT_EQ(0, dm_bht_destroy(bht_.get())); | 346 EXPECT_EQ(0, dm_bht_destroy(bht_.get())); |
301 free(bad_page); | 347 free(bad_page); |
302 } | 348 } |
OLD | NEW |