get_algos.py 1.84 KB
Newer Older
Enrico Pozzobon committed
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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
#!/usr/bin/env python3

import os
import sys
import shutil
import subprocess

def bench(algo_dir):
    print(algo_dir)
    build_dir = "build"
    assets_dir = "assets"
    while os.path.isdir(build_dir):
        shutil.rmtree(build_dir)
    shutil.copytree(algo_dir, build_dir)

    hs = os.path.join(assets_dir, "crypto_aead.h")
    h = os.path.join(build_dir, "crypto_aead.h")
    shutil.copy(hs, h)

    ms = os.path.join(assets_dir, "main.c")
    m = os.path.join(build_dir, "main.c")
    shutil.copy(ms, m)

    c = os.path.join(build_dir, "genkat_aead.c")
    if os.path.exists(c):
        os.remove(c)

    wd = os.getcwd()
    try:
        os.chdir(build_dir)

        cfiles = []
        for r, d, f in os.walk("."):
            for file in f:
                if file.endswith(".c"):
                    cfiles.append(file)
        
        pargs = ['gcc']
        pargs.extend(cfiles)
        pargs.extend(["-o", "test"])
        p = subprocess.Popen(pargs)
        compout, comperr = p.communicate()
        print(compout)
        print("---")
        print(comperr)

    finally:
        os.chdir(wd)
        # shutil.rmtree(build_dir)

    exit(0)  # stop immediately for now



def main(*argv):
    submissions_dir = "all-lwc-submission-files"
    subs = os.listdir(submissions_dir)

    files = set()
    for submission in subs:
        implementations_dir = os.path.join(submissions_dir, submission, "Implementations", "crypto_aead")

        # r=root, d=directories, f = files
        for r, d, f in os.walk(implementations_dir):
            for file in f:
                if file == "encrypt.c":
                    f = os.path.join(r, file)
                    d = os.path.split(f)[0]
                    bench(d)
                    assert os.path.isdir(d)
                    files.add(d)
        print()


if __name__ == "__main__":
    sys.exit(main(sys.argv))