| 38 | using namespace bytedance::bolt::exec; |
| 39 | |
| 40 | TEST(SpillConfig, spillLevel) { |
| 41 | const uint8_t kInitialBitOffset = 16; |
| 42 | const uint8_t kNumPartitionsBits = 3; |
| 43 | static const std::string emptyPath = ""; |
| 44 | GetSpillDirectoryPathCB getPathCb = [&]() -> const std::string& { |
| 45 | return emptyPath; |
| 46 | }; |
| 47 | UpdateAndCheckSpillLimitCB checkLimitCb = [&](uint64_t) {}; |
| 48 | const SpillConfig config( |
| 49 | getPathCb, |
| 50 | checkLimitCb, |
| 51 | "fakeSpillPath", |
| 52 | 0, |
| 53 | false, |
| 54 | 0, |
| 55 | nullptr, |
| 56 | 0, |
| 57 | 0, |
| 58 | kInitialBitOffset, |
| 59 | kNumPartitionsBits, |
| 60 | 0, |
| 61 | 0, |
| 62 | 0, |
| 63 | 0, |
| 64 | "none"); |
| 65 | struct { |
| 66 | uint8_t bitOffset; |
| 67 | // Indicates an invalid if 'expectedLevel' is negative. |
| 68 | int32_t expectedLevel; |
| 69 | |
| 70 | std::string debugString() const { |
| 71 | return fmt::format( |
| 72 | "bitOffset:{}, expectedLevel:{}", bitOffset, expectedLevel); |
| 73 | } |
| 74 | } testSettings[] = { |
| 75 | {0, -1}, |
| 76 | {kInitialBitOffset - 1, -1}, |
| 77 | {kInitialBitOffset - kNumPartitionsBits, -1}, |
| 78 | {kInitialBitOffset, 0}, |
| 79 | {kInitialBitOffset + 1, -1}, |
| 80 | {kInitialBitOffset + kNumPartitionsBits, 1}, |
| 81 | {kInitialBitOffset + 3 * kNumPartitionsBits, 3}, |
| 82 | {kInitialBitOffset + 15 * kNumPartitionsBits, 15}, |
| 83 | {kInitialBitOffset + 16 * kNumPartitionsBits, -1}}; |
| 84 | for (const auto& testData : testSettings) { |
| 85 | SCOPED_TRACE(testData.debugString()); |
| 86 | if (testData.expectedLevel == -1) { |
| 87 | ASSERT_ANY_THROW(config.joinSpillLevel(testData.bitOffset)); |
| 88 | } else { |
| 89 | ASSERT_EQ( |
| 90 | config.joinSpillLevel(testData.bitOffset), testData.expectedLevel); |
| 91 | } |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | TEST(SpillConfig, spillLevelLimit) { |
| 96 | struct { |
nothing calls this directly
no test coverage detected