5 from importlib.machinery import SourceFileLoader
6 from scapy.all import *
7 from scapy.contrib.geneve import GENEVE
10 s = bytes(p.__class__(p))
11 return ",".join("0x{:02x}".format(c) for c in s)
13 def output_test(filename, tests):
14 (name, ext) = os.path.basename(filename).split(".")
15 print('/* DO NOT EDIT: automatically generated by test_genpackets.py */')
16 print('/* clang-format off */')
17 print('test_t tests_{}[] = {{'.format(name))
21 print(' .name = "{}",'.format(t[0]))
22 print(' .nsend = {},'.format(len(t[1])))
23 print(' .send = (char []){{{}}},'.format(hexstring(t[1])))
24 print(' .nexpect = {},'.format(len(t[2])))
25 print(' .expect = (char []){{{}}},'.format(hexstring(t[2])))
26 print(' .expect_next_index = {}'.format(t[3]))
29 print('/* clang-format on */')
31 # Read tests from file
32 for filename in sys.argv[1:]:
33 with open(filename) as f:
34 content = f.read().replace('\n', '')
37 output_test(filename, tests)