get_algos.py 1.96 KB
Newer Older
Enrico Pozzobon committed
1 2 3 4 5
#!/usr/bin/env python3

import os
import sys
import shutil
Enrico Pozzobon committed
6
import random
Enrico Pozzobon committed
7 8 9 10
import subprocess

def bench(algo_dir):
    print(algo_dir)
Enrico Pozzobon committed
11 12 13 14 15 16 17
    build_dir = None
    while build_dir is None:
        r = "%09d" % random.randint(0, 999999999)
        d = os.path.join("build", r)
        if not os.path.isdir(d):
            build_dir = d
    
Enrico Pozzobon committed
18 19
    shutil.copytree(algo_dir, build_dir)

Enrico Pozzobon committed
20 21
    assets_dir = "assets"

Enrico Pozzobon committed
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
    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)

Enrico Pozzobon committed
57
    #exit(0)  # stop immediately for now
Enrico Pozzobon committed
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82



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))