Skip to content

Commit c63f26b

Browse files
authored
Add a runner to load raw Protobuf tests. (#13)
* Add run-bmv2-proto-test.py script. * Add testing script. * Read in the initial configuration. * Add a git ignore file.
1 parent bba7aea commit c63f26b

File tree

3 files changed

+501
-0
lines changed

3 files changed

+501
-0
lines changed

.gitignore

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,134 @@
3030
*.exe
3131
*.out
3232
*.app
33+
34+
35+
36+
37+
############ PYTHON
38+
39+
# Byte-compiled / optimized / DLL files
40+
__pycache__/
41+
*.py[cod]
42+
*$py.class
43+
44+
# C extensions
45+
*.so
46+
47+
# Distribution / packaging
48+
.Python
49+
build/
50+
develop-eggs/
51+
dist/
52+
downloads/
53+
eggs/
54+
.eggs/
55+
lib/
56+
lib64/
57+
parts/
58+
sdist/
59+
var/
60+
wheels/
61+
pip-wheel-metadata/
62+
share/python-wheels/
63+
*.egg-info/
64+
.installed.cfg
65+
*.egg
66+
MANIFEST
67+
68+
# PyInstaller
69+
# Usually these files are written by a python script from a template
70+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
71+
*.manifest
72+
*.spec
73+
74+
# Installer logs
75+
pip-log.txt
76+
pip-delete-this-directory.txt
77+
78+
# Unit test / coverage reports
79+
htmlcov/
80+
.tox/
81+
.nox/
82+
.coverage
83+
.coverage.*
84+
.cache
85+
nosetests.xml
86+
coverage.xml
87+
*.cover
88+
*.py,cover
89+
.hypothesis/
90+
.pytest_cache/
91+
92+
# Translations
93+
*.mo
94+
*.pot
95+
96+
# Django stuff:
97+
*.log
98+
local_settings.py
99+
db.sqlite3
100+
db.sqlite3-journal
101+
102+
# Flask stuff:
103+
instance/
104+
.webassets-cache
105+
106+
# Scrapy stuff:
107+
.scrapy
108+
109+
# Sphinx documentation
110+
docs/_build/
111+
112+
# PyBuilder
113+
target/
114+
115+
# Jupyter Notebook
116+
.ipynb_checkpoints
117+
118+
# IPython
119+
profile_default/
120+
ipython_config.py
121+
122+
# pyenv
123+
.python-version
124+
125+
# pipenv
126+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
127+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
128+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
129+
# install all needed dependencies.
130+
#Pipfile.lock
131+
132+
# celery beat schedule file
133+
celerybeat-schedule
134+
135+
# SageMath parsed files
136+
*.sage.py
137+
138+
# Environments
139+
.env
140+
.venv
141+
env/
142+
venv/
143+
ENV/
144+
env.bak/
145+
venv.bak/
146+
147+
# Spyder project settings
148+
.spyderproject
149+
.spyproject
150+
151+
# Rope project settings
152+
.ropeproject
153+
154+
# mkdocs documentation
155+
/site
156+
157+
# mypy
158+
.mypy_cache/
159+
.dmypy.json
160+
dmypy.json
161+
162+
# Pyre type checker
163+
.pyre/
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
from functools import wraps
2+
from typing import Any, List
3+
4+
import google.protobuf.text_format
5+
import grpc
6+
from p4.config.v1 import p4info_pb2
7+
from p4.v1 import p4runtime_pb2, p4runtime_pb2_grpc
8+
from ptf import config
9+
from ptf import testutils as ptfutils
10+
from ptf.base_tests import BaseTest
11+
from ptf.mask import Mask
12+
13+
from tools import testutils
14+
from tools.ptf import base_test as bt
15+
16+
17+
class AbstractTest(bt.P4RuntimeTest):
18+
@bt.autocleanup
19+
def setUp(self) -> None:
20+
bt.P4RuntimeTest.setUp(self)
21+
success = bt.P4RuntimeTest.updateConfig(self)
22+
assert success
23+
24+
def tearDown(self) -> None:
25+
bt.P4RuntimeTest.tearDown(self)
26+
27+
def createWriteRequest(self) -> p4runtime_pb2.WriteRequest:
28+
req = p4runtime_pb2.WriteRequest()
29+
req.device_id = self.device_id
30+
return req
31+
32+
def setupCtrlPlane(self) -> None:
33+
initial_config_path = ptfutils.test_param_get("initial_config_file")
34+
assert initial_config_path is not None
35+
req = self.createWriteRequest()
36+
with open(initial_config_path, "r", encoding="utf-8") as initial_config_file:
37+
google.protobuf.text_format.Merge(
38+
initial_config_file.read(), req, allow_unknown_field=True
39+
)
40+
testutils.log.info("Initial configuration %s", req)
41+
raise NotImplementedError(
42+
"Fill the missing parts of this method where you send this request to BMv2."
43+
)
44+
45+
def sendCtrlPlaneUpdate(self) -> None:
46+
pass
47+
48+
def runTestImpl(self) -> None:
49+
testutils.log.info("Configuring control plane...")
50+
self.setupCtrlPlane()
51+
52+
testutils.log.info("Sending control plane updates...")
53+
self.sendCtrlPlaneUpdate()
54+
55+
56+
class SetUpControlPlaneTest(AbstractTest):
57+
def runTest(self) -> None:
58+
self.runTestImpl()

0 commit comments

Comments
 (0)