| 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, CreateThenVerifyZeroDepth) { |
| 210 static const unsigned int total_blocks = 16384; |
| 211 // Set the root hash for a 0-filled image |
| 212 static const char kRootDigest[] = |
| 213 "45d65d6f9e5a962f4d80b5f1bd7a918152251c27bdad8c5f52b590c129833372"; |
| 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(0, 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 |
| 209 TEST_F(MemoryBhtTest, CreateThenVerifyRealParameters) { | 232 TEST_F(MemoryBhtTest, CreateThenVerifyRealParameters) { |
| 210 static const unsigned int total_blocks = 217600; | 233 static const unsigned int total_blocks = 217600; |
| 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 "15d5a180b5080a1d43e3fbd1f2cd021d0fc3ea91a8e330bad468b980c2fd4d8b"; | 236 "15d5a180b5080a1d43e3fbd1f2cd021d0fc3ea91a8e330bad468b980c2fd4d8b"; |
| 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 |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 EXPECT_LT(dm_bht_verify_block(bht_.get(), 0, bad_page), 0); | 362 EXPECT_LT(dm_bht_verify_block(bht_.get(), 0, bad_page), 0); |
| 340 EXPECT_LT(dm_bht_verify_block(bht_.get(), 127, bad_page), 0); | 363 EXPECT_LT(dm_bht_verify_block(bht_.get(), 127, bad_page), 0); |
| 341 EXPECT_LT(dm_bht_verify_block(bht_.get(), 128, bad_page), 0); | 364 EXPECT_LT(dm_bht_verify_block(bht_.get(), 128, bad_page), 0); |
| 342 EXPECT_LT(dm_bht_verify_block(bht_.get(), 255, bad_page), 0); | 365 EXPECT_LT(dm_bht_verify_block(bht_.get(), 255, bad_page), 0); |
| 343 EXPECT_LT(dm_bht_verify_block(bht_.get(), 256, bad_page), 0); | 366 EXPECT_LT(dm_bht_verify_block(bht_.get(), 256, bad_page), 0); |
| 344 EXPECT_LT(dm_bht_verify_block(bht_.get(), 383, bad_page), 0); | 367 EXPECT_LT(dm_bht_verify_block(bht_.get(), 383, bad_page), 0); |
| 345 | 368 |
| 346 EXPECT_EQ(0, dm_bht_destroy(bht_.get())); | 369 EXPECT_EQ(0, dm_bht_destroy(bht_.get())); |
| 347 free(bad_page); | 370 free(bad_page); |
| 348 } | 371 } |
| OLD | NEW |