pull/36732/head
Craig Tiller 11 months ago
parent 5187c5c613
commit 1efc40b1b6
  1. 4
      test/core/call/yodel/test_main.cc
  2. 20
      test/core/call/yodel/yodel_test.cc
  3. 36
      test/core/call/yodel/yodel_test.h

@ -29,8 +29,8 @@ int main(int argc, char** argv) {
for (const auto& test : *tests) {
CHECK(test.make != nullptr) << "test:" << test.name;
::testing::RegisterTest(
"Yodel", test.name.c_str(), nullptr, nullptr, __FILE__, __LINE__,
[test = &test, &bitgen]() -> grpc_core::YodelTest* {
test.test_type.c_str(), test.name.c_str(), nullptr, nullptr, __FILE__,
__LINE__, [test = &test, &bitgen]() -> grpc_core::YodelTest* {
return test->make(fuzzing_event_engine::Actions(), bitgen);
});
}

@ -82,8 +82,9 @@ std::vector<TestRegistry::Test> TestRegistry::AllTests() {
if (absl::StartsWith(test.name, "DISABLED_")) continue;
out.emplace_back(std::move(test));
}
std::sort(out.begin(), out.end(),
[](const Test& a, const Test& b) { return a.name < b.name; });
std::stable_sort(out.begin(), out.end(), [](const Test& a, const Test& b) {
return std::make_tuple(a.file, a.line) < std::make_tuple(b.file, b.line);
});
return out;
}
@ -91,11 +92,24 @@ std::vector<TestRegistry::Test> TestRegistry::AllTests() {
// SimpleTestRegistry
void SimpleTestRegistry::RegisterTest(
absl::string_view file, int line, absl::string_view test_type,
absl::string_view name,
absl::AnyInvocable<YodelTest*(const fuzzing_event_engine::Actions&,
absl::BitGenRef) const>
create) {
tests_.push_back({std::string(name), std::move(create)});
tests_.push_back({file, line, std::string(test_type), std::string(name),
std::move(create)});
}
void SimpleTestRegistry::ContributeTests(std::vector<Test>& tests) {
for (const auto& test : tests_) {
tests.push_back(
{test.file, test.line, test.test_type, test.name,
[test = &test](const fuzzing_event_engine::Actions& actions,
absl::BitGenRef rng) {
return test->make(actions, rng);
}});
}
}
} // namespace yodel_detail

@ -208,6 +208,9 @@ class TestRegistry {
TestRegistry() : next_(root_) { root_ = this; }
struct Test {
absl::string_view file;
int line;
std::string test_type;
std::string name;
absl::AnyInvocable<YodelTest*(const fuzzing_event_engine::Actions&,
absl::BitGenRef) const>
@ -234,22 +237,14 @@ class SimpleTestRegistry final : public TestRegistry {
~SimpleTestRegistry() = delete;
void RegisterTest(
absl::string_view file, int line, absl::string_view test_type,
absl::string_view name,
absl::AnyInvocable<YodelTest*(const fuzzing_event_engine::Actions&,
absl::BitGenRef) const>
create);
private:
void ContributeTests(std::vector<Test>& tests) override {
for (const auto& test : tests_) {
tests.push_back(
{test.name,
[test = &test](const fuzzing_event_engine::Actions& actions,
absl::BitGenRef rng) {
return test->make(actions, rng);
}});
}
}
void ContributeTests(std::vector<Test>& tests) override;
std::vector<Test> tests_;
};
@ -260,34 +255,39 @@ class ParameterizedTestRegistry final : public TestRegistry {
ParameterizedTestRegistry() {}
~ParameterizedTestRegistry() = delete;
void RegisterTest(absl::string_view name,
void RegisterTest(absl::string_view file, int line,
absl::string_view test_type, absl::string_view name,
absl::AnyInvocable<YodelTest*(
const T&, const fuzzing_event_engine::Actions&,
absl::BitGenRef) const>
make) {
tests_.push_back({std::string(name), std::move(make)});
tests_.push_back({file, line, test_type, name, std::move(make)});
}
void RegisterParameter(absl::string_view name, T value) {
parameters_.push_back({std::string(name), std::move(value)});
parameters_.push_back({name, std::move(value)});
}
private:
struct ParameterizedTest {
std::string name;
absl::string_view file;
int line;
absl::string_view test_type;
absl::string_view name;
absl::AnyInvocable<YodelTest*(
const T&, const fuzzing_event_engine::Actions&, absl::BitGenRef) const>
make;
};
struct Parameter {
std::string name;
absl::string_view name;
T value;
};
void ContributeTests(std::vector<Test>& tests) override {
for (const auto& test : tests_) {
for (const auto& parameter : parameters_) {
tests.push_back({test.name + "/" + parameter.name,
tests.push_back({test.file, test.line, std::string(test.test_type),
absl::StrCat(test.name, "/", parameter.name),
[test = &test, parameter = &parameter](
const fuzzing_event_engine::Actions& actions,
absl::BitGenRef rng) {
@ -424,7 +424,7 @@ class YodelTest : public ::testing::Test {
int YodelTest_##name::registered_ = \
(grpc_core::NoDestructSingleton< \
grpc_core::yodel_detail::SimpleTestRegistry>::Get() \
->RegisterTest(#name, &Create), \
->RegisterTest(__FILE__, __LINE__, #test_type, #name, &Create), \
0); \
void YodelTest_##name::TestImpl()
@ -448,7 +448,7 @@ class YodelTest : public ::testing::Test {
(grpc_core::NoDestructSingleton< \
grpc_core::yodel_detail::ParameterizedTestRegistry< \
grpc_core::test_type, parameter_type>>::Get() \
->RegisterTest(#name, &Create), \
->RegisterTest(__FILE__, __LINE__, #test_type, #name, &Create), \
0); \
void YodelTest_##name::TestImpl()

Loading…
Cancel
Save