nat: Include platform specific headers on FreeBSD
[vpp.git] / src / plugins / nat / pnat / tests / test_genpackets.py
1 #!/usr/bin/env python3
2
3 import sys
4 import os
5 from importlib.machinery import SourceFileLoader
6 from scapy.all import *
7 from scapy.contrib.geneve import GENEVE
8
9
10 def hexstring(p):
11     s = bytes(p.__class__(p))
12     return ",".join("0x{:02x}".format(c) for c in s)
13
14
15 def output_test(filename, tests):
16     (name, ext) = os.path.basename(filename).split(".")
17     print("/* DO NOT EDIT: automatically generated by test_genpackets.py */")
18     print("/* clang-format off */")
19     print("test_t tests_{}[] = {{".format(name))
20
21     for t in tests:
22         print("  {")
23         print('    .name = "{}",'.format(t[0]))
24         print("    .nsend = {},".format(len(t[1])))
25         print("    .send = (char []){{{}}},".format(hexstring(t[1])))
26         print("    .nexpect = {},".format(len(t[2])))
27         print("    .expect = (char []){{{}}},".format(hexstring(t[2])))
28         print("    .expect_next_index = {}".format(t[3]))
29         print("  },")
30     print("};")
31     print("/* clang-format on */")
32
33
34 # Read tests from file
35 for filename in sys.argv[1:]:
36     with open(filename) as f:
37         content = f.read().replace("\n", "")
38
39     tests = eval(content)
40     output_test(filename, tests)