From 4c25ea5c1398b70ce7a53290022cdf1db68a88fc Mon Sep 17 00:00:00 2001 From: Fabian Ruffy <5960321+fruffy@users.noreply.github.com> Date: Sat, 27 Jul 2024 06:29:31 +0200 Subject: [PATCH] [P4Testgen] Initialize the testgen targets when invoking the library API (#4706) * Register P4Testgen targets to fix library invocation. Signed-off-by: fruffy * Also ensure that the returned tests are not null. Signed-off-by: fruffy --------- Signed-off-by: fruffy --- .../testgen/targets/bmv2/test/testgen_api/benchmark.cpp | 3 ++- backends/p4tools/modules/testgen/testgen.cpp | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/backends/p4tools/modules/testgen/targets/bmv2/test/testgen_api/benchmark.cpp b/backends/p4tools/modules/testgen/targets/bmv2/test/testgen_api/benchmark.cpp index d726364f1fd..06f8074661c 100644 --- a/backends/p4tools/modules/testgen/targets/bmv2/test/testgen_api/benchmark.cpp +++ b/backends/p4tools/modules/testgen/targets/bmv2/test/testgen_api/benchmark.cpp @@ -35,7 +35,8 @@ TEST(P4TestgenBenchmark, SuccessfullyGenerate1000Tests) { // This enables performance printing. P4Tools::enablePerformanceLogging(); - P4Tools::P4Testgen::Testgen::generateTests(compilerOptions, testgenOptions); + auto testList = P4Tools::P4Testgen::Testgen::generateTests(compilerOptions, testgenOptions); + ASSERT_TRUE(testList.has_value()); // Print the report. P4Tools::printPerformanceReport(); diff --git a/backends/p4tools/modules/testgen/testgen.cpp b/backends/p4tools/modules/testgen/testgen.cpp index ae4d73bcf22..431f982c6e6 100644 --- a/backends/p4tools/modules/testgen/testgen.cpp +++ b/backends/p4tools/modules/testgen/testgen.cpp @@ -147,6 +147,7 @@ std::optional generateTestsImpl(std::optional