P4C
The P4 Compiler
Loading...
Searching...
No Matches
tofino/test_backend/stf.h
1/*******************************************************************************
2 * Copyright (C) 2024 Intel Corporation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing,
11 * software distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions
14 * and limitations under the License.
15 *
16 *
17 * SPDX-License-Identifier: Apache-2.0
18 ******************************************************************************/
19
20#ifndef BACKENDS_P4TOOLS_MODULES_TESTGEN_TARGETS_TOFINO_TEST_BACKEND_STF_H_
21#define BACKENDS_P4TOOLS_MODULES_TESTGEN_TARGETS_TOFINO_TEST_BACKEND_STF_H_
22
23#include <cstddef>
24#include <string>
25#include <vector>
26
27#include <inja/inja.hpp>
28
29#include "lib/cstring.h"
30
31#include "backends/p4tools/modules/testgen/lib/test_framework.h"
32#include "backends/p4tools/modules/testgen/lib/test_spec.h"
33
34namespace P4::P4Tools::P4Testgen::Tofino {
35
37class STF : public TestFramework {
38 public:
39 ~STF() override = default;
40
41 STF(const STF &) = delete;
42
43 STF(STF &&) = delete;
44
45 STF &operator=(const STF &) = delete;
46
47 STF &operator=(STF &&) = delete;
48
49 explicit STF(const TestBackendConfiguration &testBackendConfiguration);
50
52 void writeTestToFile(const TestSpec *spec, cstring selectedBranches, size_t testId,
53 float currentCoverage) override;
54
55 private:
61 void emitTestcase(const TestSpec *testSpec, cstring selectedBranches, size_t testId,
62 const std::string &testCase, float currentCoverage);
63
65 static std::string getTestCaseTemplate();
66
68 static inja::json getControlPlane(const TestSpec *testSpec);
69
71 static inja::json getSend(const TestSpec *testSpec);
72
74 static inja::json getVerify(const TestSpec *testSpec);
75
77 static inja::json getControlPlaneForTable(const TableMatchMap &matches,
78 const std::vector<ActionArg> &args);
79};
80
81} // namespace P4::P4Tools::P4Testgen::Tofino
82
83#endif /* BACKENDS_P4TOOLS_MODULES_TESTGEN_TARGETS_TOFINO_TEST_BACKEND_STF_H_ */
TestFramework(const TestBackendConfiguration &testBackendConfiguration)
Creates a generic test framework.
Definition test_framework.cpp:7
Definition lib/test_spec.h:296
void writeTestToFile(const TestSpec *spec, cstring selectedBranches, size_t testId, float currentCoverage) override
Produce an STF test.
Definition tofino/test_backend/stf.cpp:264
Definition cstring.h:85
Definition test_backend_configuration.h:16