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
13 # Run battery of tests on one or more dissectors.
15 # For text colouring/highlighting.
28 # Try to exit soon after Ctrl-C is pressed.
31 def signal_handler(sig
, frame
):
34 print('You pressed Ctrl+C - exiting')
36 signal
.signal(signal
.SIGINT
, signal_handler
)
39 parser
= argparse
.ArgumentParser(description
="Run gamut of tests on dissector(s)")
40 parser
.add_argument('--file', action
='append',
41 help='specify individual dissector file to test')
42 parser
.add_argument('--file-list', action
='store',
43 help='file with list of dissectors')
44 parser
.add_argument('--build-folder', action
='store',
47 args
= parser
.parse_args()
49 if not args
.file and not args
.file_list
:
50 print('Need to specify --file or --file-list')
53 # TODO: verify build-folder if set.
55 # Get list of files to check.
58 # Individually-selected files
61 if not os
.path
.isfile(f
):
62 print('Chosen file', f
, 'does not exist.')
67 # List of dissectors stored in a file
69 if not os
.path
.isfile(args
.file_list
):
70 print('Dissector-list file', args
.file_list
, 'does not exist.')
73 with
open(args
.file_list
, 'r') as f
:
74 contents
= f
.read().splitlines()
76 if not os
.path
.isfile(f
):
77 print('Chosen file', f
, 'does not exist.')
82 # Tools that should be run on selected files.
83 # Boolean arg is for whether build-dir is needed in order to run it.
84 # 3rd is Windows support.
86 ('tools/delete_includes.py --folder .', True, True),
87 ('tools/check_spelling.py --comments --no-wikipedia', False, True),
88 ('tools/check_tfs.py --check-value-strings', False, True),
89 ('tools/check_typed_item_calls.py --all-checks', False, True),
90 ('tools/check_static.py', True, False),
91 ('tools/check_dissector_urls.py', False, True),
92 ('tools/check_val_to_str.py', False, True),
93 ('tools/check_col_apis.py', False, True),
94 ('tools/cppcheck/cppcheck.sh', False, True),
95 ('tools/checkhf.pl', False, True),
96 ('tools/checkAPIs.pl', False, True),
97 ('tools/fix-encoding-args.pl', False, True),
98 ('tools/checkfiltername.pl', False, True)
102 def run_check(tool
, dissectors
, python
):
103 # Create command-line with all dissectors included
106 # Don't trust shebang on windows.
107 if sys
.platform
.startswith('win'):
109 command
+= 'python.exe '
111 command
+= 'perl.exe '
115 command
+= ' --build-folder ' + args
.build_folder
118 # Add this dissector file to command-line args
119 command
+= ((' --file' if python
else '') + ' ' + d
)
122 print(bcolors
.BOLD
+ command
+ bcolors
.ENDC
)
126 # Run all checks on all of my dissectors.
130 if ((not sys
.platform
.startswith('win') or tool
[2]) and # Supported on this platform?
131 (not tool
[1] or (tool
[1] and args
.build_folder
))): # Have --build-folder if needed?
134 run_check(tool
, dissectors
, tool
[0].find('.py') != -1)