From 12fe513c3df3aa977da90677f3ff91e962059bdd Mon Sep 17 00:00:00 2001 From: Sebastian Renner Date: Fri, 21 Feb 2020 12:49:25 +0100 Subject: [PATCH] compile for all templates and delete build files --- .gitignore | 1 + compile_all.py | 42 ++++++++++++++++++++++++------------------ process_zip.sh | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 78 insertions(+), 18 deletions(-) create mode 100755 process_zip.sh diff --git a/.gitignore b/.gitignore index a828ffd..0f5740e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ build/ measurements/ *.log +email-submissions/ diff --git a/compile_all.py b/compile_all.py index 44235b2..a0be5aa 100755 --- a/compile_all.py +++ b/compile_all.py @@ -3,21 +3,17 @@ import os import sys import stat +import argparse import shutil import random import subprocess +import shutil def build(algo_dir, template_dir, build_dir): if os.path.isdir(build_dir): return None - # create a new directory for the build - 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 print("Building in %s" % build_dir) # copy all the files from the submitted algorithm into the build directory @@ -103,15 +99,23 @@ def find_test_vectors(d): def main(argv): submissions_dir = "all-lwc-submission-files" - template_dir = "templates/linux" include_list = None - if len(argv) > 1: - template_dir = argv[1] - if len(argv) > 2: - with open(argv[2], 'r') as includes: - include_list = [] - for line in includes.readlines(): - include_list.append(line.strip()) + + # Parse the arguments + argparser = argparse.ArgumentParser( + description='Compiles all LWC submissions for a given template') + + argparser.add_argument('-v', '--verbose', action='count') + argparser.add_argument('-t', '--template', default='templates/linux') + argparser.add_argument('-b', '--build-dir') + argparser.add_argument('-i', '--include', action='append') + + args = argparser.parse_args(argv[1:]) + template_dir = args.template + build_root_dir = args.build_dir + + include_list = args.include + print("Using template %s" % template_dir) subs = os.listdir(submissions_dir) @@ -175,13 +179,13 @@ def main(argv): #files = files[:1] print("%d algorithms will be compiled" % len(files)) - if not os.path.isdir('build'): - os.mkdir('build') + if not os.path.isdir(build_root_dir): + os.mkdir(build_root_dir) print() # Write a script that executes all the tests one after the other - test_script_path = os.path.join("build", "test_all.sh") + test_script_path = os.path.join(build_root_dir, "test_all.sh") with open(test_script_path, 'w') as test_script: test_script.write("#!/bin/sh\n") test_script.write("mkdir -p logs\n") @@ -190,7 +194,7 @@ def main(argv): print() print(d) try: - build_dir = os.path.join("build", name) + build_dir = os.path.join(build_root_dir, name) b = build(d, template_dir, build_dir) if b is None: continue @@ -201,6 +205,8 @@ def main(argv): os.path.join(b, 'test_stderr.log'), os.path.join(b, 'test_stdout.log')) ) + shutil.copyfile(t, os.path.join(b, 'LWC_AEAD_KAT.txt')) + print("COMPILATION SUCCESS FOR %s" % d) except Exception as ex: diff --git a/process_zip.sh b/process_zip.sh new file mode 100755 index 0000000..c6be45c --- /dev/null +++ b/process_zip.sh @@ -0,0 +1,53 @@ +#!/bin/bash + + +shopt -s extglob + +function run() { + TEMPLATE="$1" + MAINDIR="$2" + + echo "Template is $TEMPLATE, main directory is $MAINDIR" + + mkdir -p $MAINDIR/$TEMPLATE + ./compile_all.py -t templates/$TEMPLATE -b $MAINDIR/$TEMPLATE + + for cipher in $MAINDIR/$TEMPLATE/*; do + case $TEMPLATE in + f7) mv $cipher/build/f7.bin $cipher/firmware.bin + ;; + + maixduino) mv $cipher/.pio/build/sipeed-maixduino/firmware.bin $cipher/firmware.bin + ;; + + bluepill) mv $cipher/.pio/build/bluepill_f103c8/firmware.bin $cipher/firmware.bin + ;; + + uno) mv $cipher/.pio/build/uno/firmware.hex $cipher/firmware.bin + ;; + + esp32) mv $cipher/.pio/build/esp32dev/firmware.bin $cipher/firmware.bin + ;; + esac + rm -r $(find $cipher ! -wholename $cipher ! -name "firmware.*" ! -name "LWC_AEAD_KAT.txt") + + done +} + +if [[ $1 == "run" ]]; then + run $2 $3 +else + + MAINDIR=email-submissions/$(date +%Y-%m-%d-%H:%M) + mkdir -p $MAINDIR + unzip $1 -d all-lwc-submission-files + for i in templates/*; do + TEMPLATE="${i##*/}" + echo "Template is $TEMPLATE" + touch $MAINDIR/locky.lock + flock $MAINDIR/locky.lock $0 run $TEMPLATE $MAINDIR + done + +fi + + -- libgit2 0.26.0