Skip to content

Commit

Permalink
Add a helper to get the project root.
Browse files Browse the repository at this point in the history
  • Loading branch information
fruffy committed Feb 29, 2024
1 parent 4b0babd commit dea239e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <gtest/gtest.h>

#include "backends/p4tools/common/lib/logging.h"
#include "test/gtest/helpers.h"

#include "backends/p4tools/modules/testgen/core/symbolic_executor/path_selection.h"
#include "backends/p4tools/modules/testgen/options.h"
Expand All @@ -10,11 +11,13 @@
namespace Test {

TEST(P4TestgenBenchmark, SuccessfullyGenerate1000Tests) {
auto compilerOptions = CompilerOptions();
auto compilerOptions = P4CContextWithOptions<CompilerOptions>::get().options();
compilerOptions.target = "bmv2";
compilerOptions.arch = "v1model";
auto fabricFile = std::filesystem::path(__FILE__).replace_filename(
"../../../../../../../../testdata/p4_16_samples/fabric_20190420/fabric.p4");
auto includePath = P4CTestEnvironment::getProjectRoot() / "p4include";
compilerOptions.preprocessor_options = "-I" + includePath.string();
auto fabricFile =
P4CTestEnvironment::getProjectRoot() / "testdata/p4_16_samples/fabric_20190420/fabric.p4";
compilerOptions.file = fabricFile.string();
auto &testgenOptions = P4Tools::P4Testgen::TestgenOptions::get();
testgenOptions.testBackend = "PROTOBUF_IR";
Expand Down
4 changes: 4 additions & 0 deletions test/gtest/helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ P4CTestEnvironment::P4CTestEnvironment() {
_psaP4 = readHeader(psaPath.c_str(), true);
}

std::filesystem::path P4CTestEnvironment::getProjectRoot() {
return std::filesystem::path(__FILE__).parent_path().parent_path().parent_path();
}

namespace Test {

/* static */ std::optional<FrontendTestCase> FrontendTestCase::create(
Expand Down
4 changes: 4 additions & 0 deletions test/gtest/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ limitations under the License.

#include <gtest/gtest.h>

#include <filesystem>
#include <optional>
#include <string>

Expand Down Expand Up @@ -92,6 +93,9 @@ class P4CTestEnvironment {
/// @return a string containing the "psa.p4" P4 standard header.
const std::string &psaP4() const { return _psaP4; }

/// @return the path to the P4C project root.
static std::filesystem::path getProjectRoot();

private:
P4CTestEnvironment();

Expand Down

0 comments on commit dea239e

Please sign in to comment.