aboutsummaryrefslogtreecommitdiff
path: root/tests/do_line_diff.py
blob: 6db65a133bed457364f2d34236ce9cf0d814b0c6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env python

"""
do_line_diff.py - Interactively runs all tests, and on any test where line_diff.py
showed an output, lets the user check the output and replace the test file with the output
file if they think it's safe to do so (in the sense that the test is actually passing). This
script was first used when enhancing the ssl protocol to not immediately stop detection upon
only detecting a client certificate. When server certificates were added, the this script
was helpful in checking which lines of which tests had appended server certificate info
to the line.
"""

import os
import sys
import time
import subprocess

program_base_args = ["../example/ndpiReader", "-p", "../example/protos.txt", "-q", "-i"]
line_diff_base_args = ["./line_diff.py"]
temp_output = "/tmp/reader.out"
result_folder = "result/"
pcap_folder = "pcap/"
pcap_file_list = os.listdir(pcap_folder)

def find_pcap(result_file):
    for pcap_file in pcap_file_list:
        if pcap_file == result_file[:-4]:
            return pcap_file

for result_file in os.listdir(result_folder):
    pcap_file = find_pcap(result_file)
    program_args = program_base_args + [pcap_folder + pcap_file, "-w", temp_output, "-v", "1"]
    program_output = subprocess.call(program_args)
    line_diff_args = line_diff_base_args + [result_folder + result_file, temp_output]
    line_diff_output = subprocess.check_output(line_diff_args, universal_newlines=True)
    if len(line_diff_output) > 0:
        print("File output " + result_file + " had line diff output. Here it is:")
        print(line_diff_output)
        replace = ""
        while replace.lower() != 'y' and replace.lower() != 'n':
            replace = input("Would you like to replace the file? ('y' or 'n') ")
            if replace == 'y':
                subprocess.check_output(["cp", temp_output, result_folder + result_file])
                print("")
            elif replace == 'n':
                break