Skip to content

Commit

Permalink
[NFC][sanitizer] Rename stack depot tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vitalybuka committed Oct 16, 2021
1 parent beb7862 commit c0b1b52
Showing 1 changed file with 28 additions and 18 deletions.
Expand Up @@ -24,7 +24,16 @@

namespace __sanitizer {

TEST(SanitizerCommon, StackDepotBasic) {
class StackDepotTest : public testing::Test {
protected:
void TearDown() override {
StackDepotStats stack_depot_stats = StackDepotGetStats();
Printf("StackDepot: %zd ids; %zdM allocated\n",
stack_depot_stats.n_uniq_ids, stack_depot_stats.allocated >> 20);
}
};

TEST_F(StackDepotTest, Basic) {
uptr array[] = {1, 2, 3, 4, 5};
StackTrace s1(array, ARRAY_SIZE(array));
u32 i1 = StackDepotPut(s1);
Expand All @@ -34,23 +43,23 @@ TEST(SanitizerCommon, StackDepotBasic) {
EXPECT_EQ(0, internal_memcmp(stack.trace, array, sizeof(array)));
}

TEST(SanitizerCommon, StackDepotAbsent) {
TEST_F(StackDepotTest, Absent) {
StackTrace stack = StackDepotGet((1 << 30) - 1);
EXPECT_EQ((uptr*)0, stack.trace);
}

TEST(SanitizerCommon, StackDepotEmptyStack) {
TEST_F(StackDepotTest, EmptyStack) {
u32 i1 = StackDepotPut(StackTrace());
StackTrace stack = StackDepotGet(i1);
EXPECT_EQ((uptr*)0, stack.trace);
}

TEST(SanitizerCommon, StackDepotZeroId) {
TEST_F(StackDepotTest, ZeroId) {
StackTrace stack = StackDepotGet(0);
EXPECT_EQ((uptr*)0, stack.trace);
}

TEST(SanitizerCommon, StackDepotSame) {
TEST_F(StackDepotTest, Same) {
uptr array[] = {1, 2, 3, 4, 6};
StackTrace s1(array, ARRAY_SIZE(array));
u32 i1 = StackDepotPut(s1);
Expand All @@ -62,7 +71,7 @@ TEST(SanitizerCommon, StackDepotSame) {
EXPECT_EQ(0, internal_memcmp(stack.trace, array, sizeof(array)));
}

TEST(SanitizerCommon, StackDepotSeveral) {
TEST_F(StackDepotTest, Several) {
uptr array1[] = {1, 2, 3, 4, 7};
StackTrace s1(array1, ARRAY_SIZE(array1));
u32 i1 = StackDepotPut(s1);
Expand All @@ -72,7 +81,7 @@ TEST(SanitizerCommon, StackDepotSeveral) {
EXPECT_NE(i1, i2);
}

TEST(SanitizerCommon, StackDepotPrint) {
TEST_F(StackDepotTest, Print) {
uptr array1[] = {0x111, 0x222, 0x333, 0x444, 0x777};
StackTrace s1(array1, ARRAY_SIZE(array1));
u32 i1 = StackDepotPut(s1);
Expand All @@ -95,7 +104,7 @@ TEST(SanitizerCommon, StackDepotPrint) {
"Stack for id .*#0 0x1.*#1 0x2.*#2 0x3.*#3 0x4.*#4 0x8.*#5 0x9.*"));
}

TEST(SanitizerCommon, StackDepotPrintNoLock) {
TEST_F(StackDepotTest, PrintNoLock) {
u32 n = 2000;
std::vector<u32> idx2id(n);
for (u32 i = 0; i < n; ++i) {
Expand All @@ -111,13 +120,13 @@ TEST(SanitizerCommon, StackDepotPrintNoLock) {
}
}

static struct SanitizerCommonBenchmarkparams {
static struct StackDepotBenchmarkParams {
int UniqueStacksPerThread;
int RepeatPerThread;
int Threads;
bool UniqueThreads;
bool UseCount;
} Params[] = {
} params[] = {
// All traces are unique, very unusual.
{10000000, 1, 1},
{8000000, 1, 4},
Expand All @@ -139,17 +148,18 @@ static struct SanitizerCommonBenchmarkparams {
{800000, 10, 16, true, true},
};

std::string PrintSanitizerCommonBenchmarkparams(
const testing::TestParamInfo<SanitizerCommonBenchmarkparams>& info) {
static std::string PrintStackDepotBenchmarkParams(
const testing::TestParamInfo<StackDepotBenchmarkParams>& info) {
std::stringstream name;
name << info.param.UniqueStacksPerThread << "_" << info.param.RepeatPerThread
<< "_" << info.param.Threads << (info.param.UseCount ? "_UseCount" : "")
<< (info.param.UniqueThreads ? "_UniqueThreads" : "");
return name.str();
}

class SanitizerCommonBenchmark
: public testing::TestWithParam<SanitizerCommonBenchmarkparams> {
class StackDepotBenchmark
: public StackDepotTest,
public testing::WithParamInterface<StackDepotBenchmarkParams> {
protected:
void Run() {
auto Param = GetParam();
Expand Down Expand Up @@ -183,13 +193,13 @@ class SanitizerCommonBenchmark
// down check-sanitizer.
// Usage: Sanitizer-<ARCH>-Test --gtest_also_run_disabled_tests \
// '--gtest_filter=*Benchmark*'
TEST_P(SanitizerCommonBenchmark, DISABLED_Benchmark) {
TEST_P(StackDepotBenchmark, DISABLED_Benchmark) {
// Call in subprocess to avoid reuse of the depot.
EXPECT_EXIT((Run(), exit(0)), ::testing::ExitedWithCode(0), "");
}

INSTANTIATE_TEST_SUITE_P(SanitizerCommonBenchmarkSuite,
SanitizerCommonBenchmark, testing::ValuesIn(Params),
PrintSanitizerCommonBenchmarkparams);
INSTANTIATE_TEST_SUITE_P(StackDepotBenchmarkSuite, StackDepotBenchmark,
testing::ValuesIn(params),
PrintStackDepotBenchmarkParams);

} // namespace __sanitizer

0 comments on commit c0b1b52

Please sign in to comment.