parse_logic.py 2.71 KB
Newer Older
1 2 3 4
#!/usr/bin/python3

import os
import sys
Sebastian Renner committed
5
import statistics
6 7 8

def parse_capture(filename):
    f = open('measurements/' + filename)
Sebastian Renner committed
9 10
    # Skip the first two false positves (risky)
    counter = -1
11 12 13 14 15 16 17 18 19
    lets_use_a_flag = False
    six_ts = ''
    two_ts = ''
    enc_deltas = {}
    dec_deltas = {}
    for l in f.readlines():
        l_array = l.split(" ")
        bit_field = l_array[-1][:-1]
        # l_array? That's the best you came up with?
Sebastian Renner committed
20 21
        if bit_field == '2':
            two_ts = l_array[0][:-1]
22 23 24
            lets_use_a_flag = True
            continue
        if lets_use_a_flag:
Sebastian Renner committed
25 26 27 28 29 30 31
            if bit_field == '6':
                if counter <= 0:
                    counter = counter + 1
                    lets_use_a_flag = False
                    continue
                six_ts = l_array[0][:-1]
                delta = float(six_ts) - float(two_ts)
32 33 34 35 36 37 38 39
                if counter % 2 == 1:
                    enc_deltas[(counter+1)/2] = delta
                else:
                    dec_deltas[counter/2] = delta
                counter = counter + 1
            else:
                lets_use_a_flag = False
    f.close()
Sebastian Renner committed
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56

    print("Average enc time[s] = %f" % (statistics.mean(enc_deltas.values())))
    print("Average dec time[s] = %f"  % (statistics.mean(dec_deltas.values())))
    print()
    #for key in enc_deltas:
        #print("Vector %d was encrypted in %f seconds" % (key, enc_deltas[key]))
    #for key in dec_deltas:
        #print("Vector %d was decrypted in %f seconds" % (key, dec_deltas[key]))

    enc_len = len(enc_deltas)
    dec_len = len(dec_deltas)

    if dec_len != enc_len:
        raise Exception("#Encryptions (%d) does not match #decryptions (%d)" % (enc_len, dec_len))

    if dec_len != 1089 or enc_len != 1089:
        raise Exception("#Number of encrypted test vectors (%d)/ decrypted test vectors (%d) does not match guidelines (1089)" % (enc_len, dec_len))
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

def read_log(d):
    # Soo readlines, much efficient
    f = open(d + '/test_stdout.log', 'r')
    content = f.readlines()
    
    are_we_happy = content[-1].split(' ')[-1]
    if are_we_happy != 'SUCCESSFUL\n':
        print ("Test unsuccesful or log file structure corrupted")
        return
    
    # I like to split it, split it 
    algorithm = content[0].split(' ')[-1].split('/')[-2]
    # Path to logic data is in the second to last line
    logic_file = content[-2].split('/')[-1][:-2]
    
    f. close()
    
Sebastian Renner committed
75
    print("Evaluating results for %s" % (algorithm))
76 77 78 79 80 81
        
    parse_capture(logic_file)

def main():
    print('THE LWC BENCHMARK SPLITTER')
    print('powered by Deutsche Bahn')
Sebastian Renner committed
82
    build_dir = 'build/new/'
83 84 85 86 87 88 89 90
    for d in os.listdir(build_dir):
        read_log(os.path.join(build_dir + d))



if __name__ == "__main__":
    main()