wsutil/wsgcrypt.c decrypt_des_ecb
[wireshark-sm.git] / tools / check_dissector.py
bloba47dda7641fe998a97cd587d3ddf653e290370ab
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
12 import subprocess
14 # Run battery of tests on one or more dissectors.
16 # For text colouring/highlighting.
17 class bcolors:
18 HEADER = '\033[95m'
19 OKBLUE = '\033[94m'
20 OKGREEN = '\033[92m'
21 ADDED = '\033[45m'
22 WARNING = '\033[93m'
23 FAIL = '\033[91m'
24 ENDC = '\033[0m'
25 BOLD = '\033[1m'
26 UNDERLINE = '\033[4m'
29 # Try to exit soon after Ctrl-C is pressed.
30 should_exit = False
32 def signal_handler(sig, frame):
33 global should_exit
34 should_exit = True
35 print('You pressed Ctrl+C - exiting')
37 signal.signal(signal.SIGINT, signal_handler)
39 # Command-line args
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',
48 help='build folder')
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')
54 exit(1)
56 # TODO: verify build-folder if set.
58 # Get list of files to check.
59 dissectors = []
61 # Individually-selected files
62 if args.file:
63 for f in args.file:
64 if not os.path.isfile(f):
65 print('Chosen file', f, 'does not exist.')
66 exit(1)
67 else:
68 dissectors.append(f)
70 # List of dissectors stored in a file
71 if args.file_list:
72 if not os.path.isfile(args.file_list):
73 print('Dissector-list file', args.file_list, 'does not exist.')
74 exit(1)
75 else:
76 with open(args.file_list, 'r') as f:
77 contents = f.read().splitlines()
78 for f in contents:
79 if not os.path.isfile(f):
80 print('Chosen file', f, 'does not exist.')
81 exit(1)
82 else:
83 dissectors.append(f)
85 if args.open:
86 # Unstaged changes.
87 command = ['git', 'diff', '--name-only']
88 files = [f.decode('utf-8')
89 for f in subprocess.check_output(command).splitlines()]
90 # Filter files.
91 # TODO: should filter here (and below) with a better check for dissectors
92 dissectors = list(filter(lambda f : f.endswith('.c'), files))
94 # Staged changes.
95 command = ['git', 'diff', '--staged', '--name-only']
96 files_staged = [f.decode('utf-8')
97 for f in subprocess.check_output(command).splitlines()]
98 # Filter files.
99 files_staged = list(filter(lambda f : f.endwith('.c'), files_staged))
100 for f in files_staged:
101 if f not in files:
102 dissectors.append(f)
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.
107 tools = [
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
126 command = ''
128 # Don't trust shebang on windows.
129 if sys.platform.startswith('win'):
130 if python:
131 command += 'python.exe '
132 else:
133 command += 'perl.exe '
135 command += tool[0]
136 if tool[1]:
137 command += ' --build-folder ' + args.build_folder
139 for d in dissectors:
140 # Add this dissector file to command-line args
141 command += ((' --file' if python else '') + ' ' + d)
143 # Run it
144 print(bcolors.BOLD + command + bcolors.ENDC)
145 os.system(command)
148 # Run all checks on all of my dissectors.
149 if len(dissectors):
150 for tool in tools:
151 if should_exit:
152 exit(1)
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?
156 # Run it.
157 run_check(tool, dissectors, tool[0].find('.py') != -1)
158 else:
159 print('No dissectors selected')