P4C
The P4 Compiler
Loading...
Searching...
No Matches
pna/backend/metadata/metadata.h
1/*
2 * SPDX-FileCopyrightText: 2023 Intel Corporation
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7#ifndef BACKENDS_P4TOOLS_MODULES_TESTGEN_TARGETS_PNA_BACKEND_METADATA_METADATA_H_
8#define BACKENDS_P4TOOLS_MODULES_TESTGEN_TARGETS_PNA_BACKEND_METADATA_METADATA_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
20#include "ir/ir.h"
21#include "lib/cstring.h"
22
23#include "backends/p4tools/modules/testgen/lib/test_framework.h"
24#include "backends/p4tools/modules/testgen/lib/test_spec.h"
25
27
29class Metadata : public TestFramework {
31 std::ofstream metadataFile;
32
33 public:
34 ~Metadata() override = default;
35 Metadata(const Metadata &) = delete;
36 Metadata(Metadata &&) = delete;
37 Metadata &operator=(const Metadata &) = delete;
38 Metadata &operator=(Metadata &&) = delete;
39
40 explicit Metadata(const TestBackendConfiguration &testBackendConfiguration);
41
43 void writeTestToFile(const TestSpec *spec, cstring selectedBranches, size_t testId,
44 float currentCoverage) override;
45
46 private:
49 void emitPreamble(const std::string &preamble);
50
56 void emitTestcase(const TestSpec *testSpec, cstring selectedBranches, size_t testId,
57 const std::string &testCase, float currentCoverage);
58
62 static void computeTraceData(const TestSpec *testSpec, inja::json &dataJson);
63
65 static std::string getTestCaseTemplate();
66
68 static inja::json getSend(const TestSpec *testSpec);
69
71 static inja::json getVerify(const TestSpec *testSpec);
72
75 static std::vector<std::pair<size_t, size_t>> getIgnoreMasks(const IR::Constant *mask);
76};
77
78} // namespace P4::P4Tools::P4Testgen::Pna
79
80#endif /* BACKENDS_P4TOOLS_MODULES_TESTGEN_TARGETS_PNA_BACKEND_METADATA_METADATA_H_ */
void writeTestToFile(const TestSpec *spec, cstring selectedBranches, size_t testId, float currentCoverage) override
Produce a Metadata test.
Definition pna/backend/metadata/metadata.cpp:158
TestFramework(const TestBackendConfiguration &testBackendConfiguration)
Creates a generic test framework.
Definition test_framework.cpp:11
Definition lib/test_spec.h:303
Definition cstring.h:85
Inja.
Definition pna/backend/metadata/metadata.cpp:28
Definition test_backend_configuration.h:22