P4C
The P4 Compiler
Loading...
Searching...
No Matches
bmv2/test_backend/ptf.h
1/*
2 * SPDX-FileCopyrightText: 2023 Google LLC
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7#ifndef BACKENDS_P4TOOLS_MODULES_TESTGEN_TARGETS_BMV2_TEST_BACKEND_PTF_H_
8#define BACKENDS_P4TOOLS_MODULES_TESTGEN_TARGETS_BMV2_TEST_BACKEND_PTF_H_
9
10#include <cstddef>
11#include <filesystem>
12#include <fstream>
13#include <optional>
14#include <string>
15#include <utility>
16#include <vector>
17
18#include <inja/inja.hpp>
19
21#include "ir/ir.h"
22#include "lib/cstring.h"
23
24#include "backends/p4tools/modules/testgen/lib/test_object.h"
25#include "backends/p4tools/modules/testgen/lib/test_spec.h"
26#include "backends/p4tools/modules/testgen/targets/bmv2/test_backend/common.h"
27
29
31class PTF : public Bmv2TestFramework {
32 public:
33 explicit PTF(const TestBackendConfiguration &testBackendConfiguration);
34
36 void writeTestToFile(const TestSpec *spec, cstring selectedBranches, size_t testId,
37 float currentCoverage) override;
38
39 private:
41 bool preambleEmitted = false;
42
44 std::ofstream ptfFileStream;
45
48 void emitPreamble();
49
55 void emitTestcase(const TestSpec *testSpec, cstring selectedBranches, size_t testId,
56 const std::string &testCase, float currentCoverage);
57
59 static std::string getTestCaseTemplate();
60
61 inja::json getExpectedPacket(const TestSpec *testSpec) const override;
62
65 static std::vector<std::pair<size_t, size_t>> getIgnoreMasks(const IR::Constant *mask);
66};
67
68} // namespace P4::P4Tools::P4Testgen::Bmv2
69
70#endif /* BACKENDS_P4TOOLS_MODULES_TESTGEN_TARGETS_BMV2_TEST_BACKEND_PTF_H_ */
void writeTestToFile(const TestSpec *spec, cstring selectedBranches, size_t testId, float currentCoverage) override
Produce a PTF test.
Definition bmv2/test_backend/ptf.cpp:133
Definition lib/test_spec.h:303
Definition cstring.h:85
Inja.
Definition targets/bmv2/cmd_stepper.cpp:37
Definition test_backend_configuration.h:22