5 from importlib.machinery import SourceFileLoader
6 from scapy.all import *
7 from scapy.contrib.geneve import GENEVE
11 s = bytes(p.__class__(p))
12 return ",".join("0x{:02x}".format(c) for c in s)
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))
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]))
31 print("/* clang-format on */")
34 # Read tests from file
35 for filename in sys.argv[1:]:
36 with open(filename) as f:
37 content = f.read().replace("\n", "")
40 output_test(filename, tests)