#!/usr/bin/env python3 import re import os import sys import struct from subprocess import Popen, PIPE def main(argv): if len(argv) < 3: print("Usage: test.py LWC_AEAD_KAT.txt program [arguments]") cmd = argv[2:] for attempt in range(3): print("beginning test %d of '%s' using test vectors '%s'" % (attempt, ' '.join(cmd), argv[1])) try: test(argv[1], cmd) print("TEST SUCCESSFUL") return 0 except Exception as ex: print(str(ex)) print("TEST FAILED") finally: sys.stdout.flush() sys.stderr.flush() return 1 def test(test_file, cmd): test_file = open(test_file, 'r') p = Popen(cmd, bufsize=0, stdin=PIPE, stdout=PIPE) def write(data): l = p.stdin.write(data) if len(data) != l: raise Exception("could not write %d bytes of data (put %d)" % (len(data), l)) def read(l): if l == 0: return b"" data = p.stdout.read(l) if len(data) == 0: print("Unexpected end of stream", file=sys.stderr) #sys.exit(1) if len(data) != l: raise Exception("could not read %d bytes of data (got %d)" % (l, len(data))) return data def submit(action, data): h = struct.pack("