P4C
The P4 Compiler
Loading...
Searching...
No Matches
pna/backend/metadata/metadata.h
1#ifndef BACKENDS_P4TOOLS_MODULES_TESTGEN_TARGETS_PNA_BACKEND_METADATA_METADATA_H_
2#define BACKENDS_P4TOOLS_MODULES_TESTGEN_TARGETS_PNA_BACKEND_METADATA_METADATA_H_
3
4#include <cstddef>
5#include <filesystem>
6#include <fstream>
7#include <optional>
8#include <string>
9#include <utility>
10#include <vector>
11
12#include <inja/inja.hpp>
13
14#include "ir/ir.h"
15#include "lib/cstring.h"
16
17#include "backends/p4tools/modules/testgen/lib/test_framework.h"
18#include "backends/p4tools/modules/testgen/lib/test_spec.h"
19
21
23class Metadata : public TestFramework {
25 std::ofstream metadataFile;
26
27 public:
28 ~Metadata() override = default;
29 Metadata(const Metadata &) = delete;
30 Metadata(Metadata &&) = delete;
31 Metadata &operator=(const Metadata &) = delete;
32 Metadata &operator=(Metadata &&) = delete;
33
34 explicit Metadata(const TestBackendConfiguration &testBackendConfiguration);
35
37 void writeTestToFile(const TestSpec *spec, cstring selectedBranches, size_t testId,
38 float currentCoverage) override;
39
40 private:
43 void emitPreamble(const std::string &preamble);
44
50 void emitTestcase(const TestSpec *testSpec, cstring selectedBranches, size_t testId,
51 const std::string &testCase, float currentCoverage);
52
56 static void computeTraceData(const TestSpec *testSpec, inja::json &dataJson);
57
59 static std::string getTestCaseTemplate();
60
62 static inja::json getSend(const TestSpec *testSpec);
63
65 static inja::json getVerify(const TestSpec *testSpec);
66
69 static std::vector<std::pair<size_t, size_t>> getIgnoreMasks(const IR::Constant *mask);
70};
71
72} // namespace P4::P4Tools::P4Testgen::Pna
73
74#endif /* BACKENDS_P4TOOLS_MODULES_TESTGEN_TARGETS_PNA_BACKEND_METADATA_METADATA_H_ */
Extracts information from the @testSpec to emit a Metadata test case.
Definition pna/backend/metadata/metadata.h:23
void writeTestToFile(const TestSpec *spec, cstring selectedBranches, size_t testId, float currentCoverage) override
Produce a Metadata test.
Definition pna/backend/metadata/metadata.cpp:154
Definition test_framework.h:54
Definition lib/test_spec.h:296
Definition cstring.h:85
Inja.
Definition pna/backend/metadata/metadata.cpp:24
Definition test_backend_configuration.h:16