Revert "drsuapi_dissect_element_DsGetNCChangesCtr6TS_ctr6 dissect_krb5_PAC_NDRHEADERBLOB"
[wireshark-sm.git] / tools / check_dissector.py
blob1461f66e6e4b8a7246bd08c37ded7ca6a103dc1d
1 #!/usr/bin/env python3
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
8 import sys
9 import os
10 import signal
11 import argparse
13 # Run battery of tests on one or more dissectors.
15 # For text colouring/highlighting.
16 class bcolors:
17 HEADER = '\033[95m'
18 OKBLUE = '\033[94m'
19 OKGREEN = '\033[92m'
20 ADDED = '\033[45m'
21 WARNING = '\033[93m'
22 FAIL = '\033[91m'
23 ENDC = '\033[0m'
24 BOLD = '\033[1m'
25 UNDERLINE = '\033[4m'
28 # Try to exit soon after Ctrl-C is pressed.
29 should_exit = False
31 def signal_handler(sig, frame):
32 global should_exit
33 should_exit = True
34 print('You pressed Ctrl+C - exiting')
36 signal.signal(signal.SIGINT, signal_handler)
38 # Command-line args
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',
45 help='build folder')
47 args = parser.parse_args()
49 if not args.file and not args.file_list:
50 print('Need to specify --file or --file-list')
51 exit(1)
53 # TODO: verify build-folder if set.
55 # Get list of files to check.
56 dissectors = []
58 # Individually-selected files
59 if args.file:
60 for f in args.file:
61 if not os.path.isfile(f):
62 print('Chosen file', f, 'does not exist.')
63 exit(1)
64 else:
65 dissectors.append(f)
67 # List of dissectors stored in a file
68 if args.file_list:
69 if not os.path.isfile(args.file_list):
70 print('Dissector-list file', args.file_list, 'does not exist.')
71 exit(1)
72 else:
73 with open(args.file_list, 'r') as f:
74 contents = f.read().splitlines()
75 for f in contents:
76 if not os.path.isfile(f):
77 print('Chosen file', f, 'does not exist.')
78 exit(1)
79 else:
80 dissectors.append(f)
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.
85 tools = [
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
104 command = ''
106 # Don't trust shebang on windows.
107 if sys.platform.startswith('win'):
108 if python:
109 command += 'python.exe '
110 else:
111 command += 'perl.exe '
113 command += tool[0]
114 if tool[1]:
115 command += ' --build-folder ' + args.build_folder
117 for d in dissectors:
118 # Add this dissector file to command-line args
119 command += ((' --file' if python else '') + ' ' + d)
121 # Run it
122 print(bcolors.BOLD + command + bcolors.ENDC)
123 os.system(command)
126 # Run all checks on all of my dissectors.
127 for tool in tools:
128 if should_exit:
129 exit(1)
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?
133 # Run it.
134 run_check(tool, dissectors, tool[0].find('.py') != -1)