get_algos.py 2.58 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
import subprocess

9
def bench(algo_dir, template_dir="templates/linux"):
Enrico Pozzobon committed
10
    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 20 21 22 23
    shutil.copytree(algo_dir, build_dir)

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

24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
    hfiles = []
    cfiles = []
    for r, d, f in os.walk(build_dir):
        for file in f:
            if file.endswith(".c"):
                cfiles.append(file)
            elif file.endswith(".h"):
                hfiles.append(file)

    for f in os.listdir(template_dir):
        dst = os.path.join(build_dir, f)
        src = os.path.join(template_dir, f)
        if os.path.isfile(src) or os.path.islink(src):
            shutil.copy2(src, dst)
        elif os.path.isdir(src):
            shutil.copytree(src, dst)
        else:
            raise Exception("I don't know what %s is" % src)

Enrico Pozzobon committed
43 44
    wd = os.getcwd()
    try:
45
        env = os.environ
Enrico Pozzobon committed
46

47 48 49 50 51 52 53 54 55 56 57 58 59
        env['SRC_FILES'] = ' '.join(cfiles)
        env['HDR_FILES'] = ' '.join(hfiles)

        os.chdir(build_dir)
        if os.path.isfile('./configure'):
            p = subprocess.Popen(["./configure"], env=env)
            compout, comperr = p.communicate()
            print(compout)
            print("---")
            print(comperr)

        pargs = ['make']
        p = subprocess.Popen(pargs, env=env)
Enrico Pozzobon committed
60 61 62 63 64 65 66 67 68
        compout, comperr = p.communicate()
        print(compout)
        print("---")
        print(comperr)

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

69
    exit(0)  # stop immediately for now
Enrico Pozzobon committed
70 71 72



73
def main(argv):
Enrico Pozzobon committed
74
    submissions_dir = "all-lwc-submission-files"
75 76 77 78
    template_dir = "templates/linux"
    if len(argv) > 1:
        template_dir = argv[1]
    print("Using template %s" % template_dir)
Enrico Pozzobon committed
79 80 81 82 83 84 85 86 87 88 89 90
    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]
91
                    bench(d, template_dir)
Enrico Pozzobon committed
92 93 94 95 96 97 98
                    assert os.path.isdir(d)
                    files.add(d)
        print()


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