diff options
author | Martin Mathieson <martin.mathieson@keysight.com> | 2020-08-16 21:41:18 +0100 |
---|---|---|
committer | Anders Broman <a.broman58@gmail.com> | 2020-08-17 02:58:01 +0000 |
commit | 3b67c5b3084cd74986115e06eab954b4f8332a3f (patch) | |
tree | 8af69228676d2f4e3af160960b693a3f8073d567 /tools | |
parent | e48ab21267c90bf5f870003299e00ea1656e2d7e (diff) |
TFS: Add some commonly-defined string pairs to tfs.c
'check_tfs.py --common' can look for tfs values that appear multiple times.
Current output prior to these dssector changes was:
('No Extension', 'Extension') appears 3 times in: ['epan/dissectors/packet-bssap.c', 'epan/dissectors/packet-camel.c', 'epan/dissectors/packet-gsm_map.c']
('Optimised for signalling traffic', 'Not optimised for signalling traffic') appears 3 times in: ['epan/dissectors/packet-gsm_a_gm.c', 'epan/dissectors/packet-gsm_map.c', 'epan/dissectors/packet-gtp.c']
('Data PDU', 'Control PDU') appears 3 times in: ['epan/dissectors/packet-pdcp-lte.c', 'epan/dissectors/packet-pdcp-nr.c', 'epan/dissectors/packet-rlc-nr.c']
('Message sent to originating side', 'Message sent from originating side') appears 3 times in: ['epan/dissectors/packet-q2931.c', 'epan/dissectors/packet-q931.c', 'epan/dissectors/packet-q933.c']
('User', 'Provider') appears 3 times in: ['epan/dissectors/packet-q2931.c', 'epan/dissectors/packet-q931.c', 'epan/dissectors/packet-q933.c']
The first and last ones were made common, the others seem a little too specialised.
Checking some of the existing items in tfs.c (using QtCreator's 'Find Usages'),
some of the common items are used a lot, but many of them are not referenced.
Change-Id: Ia4006d2c4fa7cafbc3b004dc7a367a986dbeb0c4
Reviewed-on: https://code.wireshark.org/review/38177
Petri-Dish: Martin Mathieson <martin.r.mathieson@googlemail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
Diffstat (limited to 'tools')
-rwxr-xr-x | tools/check_tfs.py | 43 |
1 files changed, 37 insertions, 6 deletions
diff --git a/tools/check_tfs.py b/tools/check_tfs.py index 63f885b0c4..a9b9097abe 100755 --- a/tools/check_tfs.py +++ b/tools/check_tfs.py @@ -29,6 +29,19 @@ def signal_handler(sig, frame): signal.signal(signal.SIGINT, signal_handler) + +# Keep track of custom entries that might appear in multiple dissectors, +# so we can consider adding them to tfs.c +custom_tfs_entries = {} +def AddCustomEntry(val1, val2, file): + global custom_tfs_entries + if (val1, val2) in custom_tfs_entries: + custom_tfs_entries[(val1, val2)].append(file) + else: + custom_tfs_entries[(val1, val2)] = [file] + + + class TFS: def __init__(self, file, name, val1, val2): self.file = file @@ -43,7 +56,7 @@ class TFS: print('N.B.: file=' + self.file + ' ' + self.name + ' - true val begins or ends with space \"' + self.val2 + '\"') def __str__(self): - return '{' + self.val1 + ',' + self.val2 + '}' + return '{' + '"' + self.val1 + '", "' + self.val2 + '"}' def removeComments(code_string): @@ -53,7 +66,7 @@ def removeComments(code_string): # Look for hf items in a dissector file. -def find_items(filename): +def findItems(filename): items = {} with open(filename, 'r') as f: @@ -94,18 +107,24 @@ def findDissectorFilesInFolder(folder): issues_found = 0 # Check the given dissector file. -def checkFile(filename, tfs_items): +def checkFile(filename, tfs_items, look_for_common=False): global issues_found # Find items. - items = find_items(filename) + items = findItems(filename) # See if any of these items already existed in tfs.c for i in items: for t in tfs_items: + found = False if tfs_items[t].val1 == items[i].val1 and tfs_items[t].val2 == items[i].val2: print(filename, i, "- could have used", t, 'from tfs.c instead: ', tfs_items[t]) issues_found += 1 + found = True + break + if not found: + if look_for_common: + AddCustomEntry(items[i].val1, items[i].val2, filename) ################################################################# @@ -120,6 +139,9 @@ parser.add_argument('--commits', action='store', help='last N commits to check') parser.add_argument('--open', action='store_true', help='check open files') +parser.add_argument('--common', action='store_true', + help='check for potential new entries for tfs.c') + args = parser.parse_args() @@ -174,13 +196,22 @@ else: # Get standard/ shared ones. -tfs_entries = find_items(os.path.join('epan', 'tfs.c')) +tfs_entries = findItems(os.path.join('epan', 'tfs.c')) # Now check the files to see if they could have used shared ones instead. for f in files: if should_exit: exit(1) - checkFile(f, tfs_entries) + checkFile(f, tfs_entries, look_for_common=args.common) + # Show summary. print(issues_found, 'issues found') + +if args.common: + # Looking for items that could potentially be moved to tfs.c + for c in custom_tfs_entries: + # Only want to see items that have 3 or more occurrences. + # Even then, probably only want to consider ones that sound generic. + if len(custom_tfs_entries[c]) > 2: + print(c, 'appears', len(custom_tfs_entries[c]), 'times, in: ', custom_tfs_entries[c]) |