@@ -8,116 +8,89 @@ using namespace kv_cache_manager;
88class ChecksumVerifyUtilTest : public TESTBASE {};
99
1010// 所有 block 一致 -> mismatch=false, faulty_indices 空。
11- TEST_F (ChecksumVerifyUtilTest, FastPathAllMatch ) {
11+ TEST_F (ChecksumVerifyUtilTest, AllMatch ) {
1212 std::vector<int64_t > expected = {0x1111 , 0x2222 , 0x3333 };
1313 std::vector<int64_t > actual = expected;
14- auto r = VerifyBatchChecksums (expected, actual, /* strict_mode= */ false );
14+ auto r = VerifyBatchChecksums (expected, actual);
1515 EXPECT_FALSE (r.mismatch );
1616 EXPECT_TRUE (r.faulty_indices .empty ());
1717}
1818
1919// 检测到不匹配后应该回填 faulty_indices 让上层逐块打日志。
20- TEST_F (ChecksumVerifyUtilTest, FastPathDetectsMismatchAndLocatesIndex ) {
20+ TEST_F (ChecksumVerifyUtilTest, DetectsMismatchAndLocatesIndex ) {
2121 std::vector<int64_t > expected = {0x1111 , 0x2222 , 0x3333 };
2222 std::vector<int64_t > actual = {0x1111 , 0xFFFF , 0x3333 }; // block #1 错
23- auto r = VerifyBatchChecksums (expected, actual, /* strict_mode= */ false );
23+ auto r = VerifyBatchChecksums (expected, actual);
2424 ASSERT_TRUE (r.mismatch );
2525 ASSERT_EQ (r.faulty_indices .size (), 1u );
2626 EXPECT_EQ (r.faulty_indices [0 ], 1u );
2727}
2828
2929// 多个错位 block:把所有错的都列出来。
30- TEST_F (ChecksumVerifyUtilTest, FastPathListsAllFaultyBlocks ) {
30+ TEST_F (ChecksumVerifyUtilTest, ListsAllFaultyBlocks ) {
3131 std::vector<int64_t > expected = {0x1111 , 0x2222 , 0x3333 , 0x4444 };
3232 std::vector<int64_t > actual = {0xAAAA , 0x2222 , 0xBBBB , 0x4444 }; // #0, #2 错
33- auto r = VerifyBatchChecksums (expected, actual, /* strict_mode= */ false );
33+ auto r = VerifyBatchChecksums (expected, actual);
3434 ASSERT_TRUE (r.mismatch );
3535 ASSERT_EQ (r.faulty_indices .size (), 2u );
3636 EXPECT_EQ (r.faulty_indices [0 ], 0u );
3737 EXPECT_EQ (r.faulty_indices [1 ], 2u );
3838}
3939
4040// expected[i] == 0 是 sentinel (legacy data / legacy client),跳过比对。
41- TEST_F (ChecksumVerifyUtilTest, FastPathSentinelZeroIsSkipped ) {
41+ TEST_F (ChecksumVerifyUtilTest, SentinelZeroIsSkipped ) {
4242 std::vector<int64_t > expected = {0x1111 , 0 , 0x3333 }; // block #1 没有 checksum
4343 std::vector<int64_t > actual = {0x1111 , 0xDEADBEEF , 0x3333 }; // #1 的 actual 不会被比较
44- auto r = VerifyBatchChecksums (expected, actual, /* strict_mode= */ false );
44+ auto r = VerifyBatchChecksums (expected, actual);
4545 EXPECT_FALSE (r.mismatch );
4646}
4747
4848// 全 sentinel:没有可比较的项,等同于全 match。
49- TEST_F (ChecksumVerifyUtilTest, FastPathAllSentinelsTreatedAsMatch ) {
49+ TEST_F (ChecksumVerifyUtilTest, AllSentinelsTreatedAsMatch ) {
5050 std::vector<int64_t > expected = {0 , 0 , 0 };
5151 std::vector<int64_t > actual = {0xAA , 0xBB , 0xCC };
52- auto r = VerifyBatchChecksums (expected, actual, /* strict_mode= */ false );
52+ auto r = VerifyBatchChecksums (expected, actual);
5353 EXPECT_FALSE (r.mismatch );
5454}
5555
5656// Size mismatch (上层 bug): mismatch=true 且 faulty_indices 空 -> 上层走 size 错误日志。
5757TEST_F (ChecksumVerifyUtilTest, SizeMismatchReturnsMismatchWithoutIndices) {
5858 std::vector<int64_t > expected = {0x1111 , 0x2222 };
5959 std::vector<int64_t > actual = {0x1111 };
60- auto r = VerifyBatchChecksums (expected, actual, /* strict_mode= */ false );
60+ auto r = VerifyBatchChecksums (expected, actual);
6161 EXPECT_TRUE (r.mismatch );
6262 EXPECT_TRUE (r.faulty_indices .empty ());
6363}
6464
65- // strict_mode 参数保留兼容;当前实现始终逐块比对。
66- TEST_F (ChecksumVerifyUtilTest, StrictModeMatchesFastFallback) {
67- std::vector<int64_t > expected = {0x1111 , 0 , 0x3333 , 0x4444 };
68- std::vector<int64_t > actual = {0xAAAA , 0x2222 , 0x3333 , 0xBBBB }; // #0, #3 错;#1 是 sentinel
69- auto r = VerifyBatchChecksums (expected, actual, /* strict_mode=*/ true );
70- ASSERT_TRUE (r.mismatch );
71- ASSERT_EQ (r.faulty_indices .size (), 2u );
72- EXPECT_EQ (r.faulty_indices [0 ], 0u );
73- EXPECT_EQ (r.faulty_indices [1 ], 3u );
74- }
75-
76- // Strict mode + all match: 仍然 mismatch=false。
77- TEST_F (ChecksumVerifyUtilTest, StrictModeAllMatch) {
78- std::vector<int64_t > expected = {0x1111 , 0x2222 , 0x3333 };
79- std::vector<int64_t > actual = expected;
80- auto r = VerifyBatchChecksums (expected, actual, /* strict_mode=*/ true );
81- EXPECT_FALSE (r.mismatch );
82- }
83-
8465// Block swap (读串): expected=[A,B], actual=[B,A]. 必须识别并回填两个 faulty index。
85- TEST_F (ChecksumVerifyUtilTest, FastPathCatchesBlockSwap ) {
66+ TEST_F (ChecksumVerifyUtilTest, CatchesBlockSwap ) {
8667 std::vector<int64_t > expected = {0xAAAA , 0xBBBB };
8768 std::vector<int64_t > actual = {0xBBBB , 0xAAAA };
88- auto r_fast = VerifyBatchChecksums (expected, actual, /* strict_mode=*/ false );
89- ASSERT_TRUE (r_fast.mismatch );
90- ASSERT_EQ (r_fast.faulty_indices .size (), 2u );
91- EXPECT_EQ (r_fast.faulty_indices [0 ], 0u );
92- EXPECT_EQ (r_fast.faulty_indices [1 ], 1u );
93- // Strict 一致。
94- auto r_strict = VerifyBatchChecksums (expected, actual, /* strict_mode=*/ true );
95- ASSERT_TRUE (r_strict.mismatch );
96- EXPECT_EQ (r_strict.faulty_indices .size (), 2u );
69+ auto r = VerifyBatchChecksums (expected, actual);
70+ ASSERT_TRUE (r.mismatch );
71+ ASSERT_EQ (r.faulty_indices .size (), 2u );
72+ EXPECT_EQ (r.faulty_indices [0 ], 0u );
73+ EXPECT_EQ (r.faulty_indices [1 ], 1u );
9774}
9875
99- // Same-delta 成对突变:每个 block 都被同一 delta 改写 (expected=[A,B],
100- // actual=[A^X, B^X])。老 XOR fast 会 delta 对消而漏;逐块比对必须识别 。
76+ // Same-delta 成对突变:每个 block 都被同一 delta 改写。
77+ // 逐块比对不能让这种 batch 通过 。
10178TEST_F (ChecksumVerifyUtilTest, DetectsSameDeltaPairedMutation) {
10279 constexpr int64_t kDelta = 0x0F0F0F0F0F0F0F0FLL ;
10380 std::vector<int64_t > expected = {0xAAAA , 0xBBBB };
10481 std::vector<int64_t > actual = {0xAAAA ^ kDelta , 0xBBBB ^ kDelta };
105- auto r_fast = VerifyBatchChecksums (expected, actual, /* strict_mode=*/ false );
106- ASSERT_TRUE (r_fast.mismatch );
107- EXPECT_EQ (r_fast.faulty_indices .size (), 2u );
108- auto r_strict = VerifyBatchChecksums (expected, actual, /* strict_mode=*/ true );
109- ASSERT_TRUE (r_strict.mismatch );
110- EXPECT_EQ (r_strict.faulty_indices .size (), 2u );
82+ auto r = VerifyBatchChecksums (expected, actual);
83+ ASSERT_TRUE (r.mismatch );
84+ EXPECT_EQ (r.faulty_indices .size (), 2u );
11185}
11286
113- // High-bit 成对突变:奇数乘法聚合也会让最高位 delta 在偶数个 block 中抵消。
114- // 逐块比对不能接受这种 batch。
87+ // High-bit 成对突变:逐块比对不能接受这种 batch。
11588TEST_F (ChecksumVerifyUtilTest, DetectsHighBitPairedMutation) {
11689 constexpr int64_t kHighBit = static_cast <int64_t >(0x8000000000000000ULL );
11790 std::vector<int64_t > expected = {0x1111 , 0x2222 , 0x3333 };
11891 std::vector<int64_t > actual = {0x1111 ^ kHighBit , 0x2222 ^ kHighBit , 0x3333 };
11992
120- auto r = VerifyBatchChecksums (expected, actual, /* strict_mode= */ false );
93+ auto r = VerifyBatchChecksums (expected, actual);
12194 ASSERT_TRUE (r.mismatch );
12295 ASSERT_EQ (r.faulty_indices .size (), 2u );
12396 EXPECT_EQ (r.faulty_indices [0 ], 0u );
0 commit comments