2 # Wireshark - Network traffic analyzer
3 # By Gerald Combs <gerald@wireshark.org>
4 # Copyright 1998 Gerald Combs
6 # SPDX-License-Identifier: GPL-2.0-or-later
14 # Run battery of tests on one or more dissectors.
16 # For text colouring/highlighting.
29 # Try to exit soon after Ctrl-C is pressed.
32 def signal_handler(sig
, frame
):
35 print('You pressed Ctrl+C - exiting')
37 signal
.signal(signal
.SIGINT
, signal_handler
)
40 parser
= argparse
.ArgumentParser(description
="Run gamut of tests on dissector(s)")
41 parser
.add_argument('--file', action
='append',
42 help='specify individual dissector file to test')
43 parser
.add_argument('--file-list', action
='store',
44 help='file with list of dissectors')
45 parser
.add_argument('--open', action
='store_true',
46 help='look for dissectors among upon files')
47 parser
.add_argument('--build-folder', action
='store',
50 args
= parser
.parse_args()
52 if not args
.file and not args
.file_list
and not args
.open:
53 print('Need to specify --file, --file-list or --open')
56 # TODO: verify build-folder if set.
58 # Get list of files to check.
61 # Individually-selected files
64 if not os
.path
.isfile(f
):
65 print('Chosen file', f
, 'does not exist.')
70 # List of dissectors stored in a file
72 if not os
.path
.isfile(args
.file_list
):
73 print('Dissector-list file', args
.file_list
, 'does not exist.')
76 with
open(args
.file_list
, 'r') as f
:
77 contents
= f
.read().splitlines()
79 if not os
.path
.isfile(f
):
80 print('Chosen file', f
, 'does not exist.')
87 command
= ['git', 'diff', '--name-only']
88 files
= [f
.decode('utf-8')
89 for f
in subprocess
.check_output(command
).splitlines()]
91 # TODO: should filter here (and below) with a better check for dissectors
92 dissectors
= list(filter(lambda f
: f
.endswith('.c'), files
))
95 command
= ['git', 'diff', '--staged', '--name-only']
96 files_staged
= [f
.decode('utf-8')
97 for f
in subprocess
.check_output(command
).splitlines()]
99 files_staged
= list(filter(lambda f
: f
.endwith('.c'), files_staged
))
100 for f
in files_staged
:
104 # Tools that should be run on selected files.
105 # Boolean arg is for whether build-dir is needed in order to run it.
106 # 3rd is Windows support.
108 ('tools/check_spelling.py --comments --no-wikipedia', False, True),
109 ('tools/check_tfs.py --check-value-strings', False, True),
110 ('tools/check_typed_item_calls.py --all-checks ' +
111 '--extra-value-string-checks --check-expert-items', False, True),
112 ('tools/check_static.py', True, False),
113 ('tools/check_dissector_urls.py', False, True),
114 ('tools/check_val_to_str.py', False, True),
115 ('tools/check_col_apis.py', False, True),
116 ('tools/cppcheck/cppcheck.sh', False, True),
117 ('tools/checkhf.pl', False, True),
118 ('tools/checkAPIs.pl', False, True),
119 ('tools/fix-encoding-args.pl', False, True),
120 ('tools/checkfiltername.pl', False, True)
124 def run_check(tool
, dissectors
, python
):
125 # Create command-line with all dissectors included
128 # Don't trust shebang on windows.
129 if sys
.platform
.startswith('win'):
131 command
+= 'python.exe '
133 command
+= 'perl.exe '
137 command
+= ' --build-folder ' + args
.build_folder
140 # Add this dissector file to command-line args
141 command
+= ((' --file' if python
else '') + ' ' + d
)
144 print(bcolors
.BOLD
+ command
+ bcolors
.ENDC
)
148 # Run all checks on all of my dissectors.
153 if ((not sys
.platform
.startswith('win') or tool
[2]) and # Supported on this platform?
154 (not tool
[1] or (tool
[1] and args
.build_folder
))): # Have --build-folder if needed?
157 run_check(tool
, dissectors
, tool
[0].find('.py') != -1)
159 print('No dissectors selected')