Commit 23e6c280 by Enrico Pozzobon

arduino uno measurements start

parent 2ec67af2
...@@ -16,6 +16,7 @@ def build(algo_dir, template_dir): ...@@ -16,6 +16,7 @@ def build(algo_dir, template_dir):
d = os.path.join("build", r) d = os.path.join("build", r)
if not os.path.isdir(d): if not os.path.isdir(d):
build_dir = d build_dir = d
print("Building in %s" % build_dir)
# copy all the files from the submitted algorithm into the build directory # copy all the files from the submitted algorithm into the build directory
shutil.copytree(algo_dir, build_dir) shutil.copytree(algo_dir, build_dir)
...@@ -65,6 +66,8 @@ def build(algo_dir, template_dir): ...@@ -65,6 +66,8 @@ def build(algo_dir, template_dir):
assert p.returncode == 0 assert p.returncode == 0
finally: finally:
sys.stdout.flush()
sys.stderr.flush()
os.chdir(wd) os.chdir(wd)
# if execution arrives here, the build was successful # if execution arrives here, the build was successful
...@@ -132,7 +135,7 @@ def main(argv): ...@@ -132,7 +135,7 @@ def main(argv):
# For testing, we only do the first 1 # For testing, we only do the first 1
files = files[:1] #files = files[:1]
# Clear the build directory as it is a leftover from the previous execution # Clear the build directory as it is a leftover from the previous execution
if os.path.isdir('build'): if os.path.isdir('build'):
...@@ -148,8 +151,13 @@ def main(argv): ...@@ -148,8 +151,13 @@ def main(argv):
for t, d in files: for t, d in files:
print() print()
print(d) print(d)
b = build(d, template_dir) try:
test_script.write("./test.py %s %s\n" % (t, os.path.join(b, 'test'))) b = build(d, template_dir)
test_script.write("echo \"TESTING %s\"\n./test.py %s %s\n" % (d, t, os.path.join(b, 'test')))
print("COMPILATION SUCCESS FOR %s" % d)
except Exception:
print("COMPILATION FAILED FOR %s" % d)
st = os.stat(test_script_path) st = os.stat(test_script_path)
os.chmod(test_script_path, st.st_mode | stat.S_IEXEC) os.chmod(test_script_path, st.st_mode | stat.S_IEXEC)
......
#!/bin/bash #!/bin/bash
mv *.c src/ mv -n *.c *.C *.s *.S src/
mv *.h include/ mv -n *.h *.H include/
sed -i src/encrypt.c -e "s/\(\s\)init(/\1_init(/g"
exit 0
...@@ -96,14 +96,22 @@ void loop() { ...@@ -96,14 +96,22 @@ void loop() {
case 'p': assert(l == CRYPTO_NPUBBYTES); memcpy(npub, var, l); break; case 'p': assert(l == CRYPTO_NPUBBYTES); memcpy(npub, var, l); break;
case 's': assert(l == CRYPTO_NSECBYTES); memcpy(nsec, var, l); break; case 's': assert(l == CRYPTO_NSECBYTES); memcpy(nsec, var, l); break;
case 'e': case 'e':
noInterrupts();
asm("nop");
digitalWrite(LED_BUILTIN, LOW); digitalWrite(LED_BUILTIN, LOW);
res = crypto_aead_encrypt(c, &clen, m, mlen, ad, adlen, nsec, npub, k); res = crypto_aead_encrypt(c, &clen, m, mlen, ad, adlen, nsec, npub, k);
digitalWrite(LED_BUILTIN, HIGH); digitalWrite(LED_BUILTIN, HIGH);
asm("nop");
interrupts();
break; break;
case 'd': case 'd':
noInterrupts();
asm("nop");
digitalWrite(LED_BUILTIN, LOW); digitalWrite(LED_BUILTIN, LOW);
res = crypto_aead_decrypt(m, &mlen, nsec, c, clen, ad, adlen, npub, k); res = crypto_aead_decrypt(m, &mlen, nsec, c, clen, ad, adlen, npub, k);
digitalWrite(LED_BUILTIN, HIGH); digitalWrite(LED_BUILTIN, HIGH);
asm("nop");
interrupts();
break; break;
case'M': var = m; rl = mlen; break; case'M': var = m; rl = mlen; break;
case'C': var = c; rl = clen; break; case'C': var = c; rl = clen; break;
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
import os import os
import sys import sys
import time
import struct import struct
import serial import serial
import subprocess import subprocess
...@@ -12,9 +13,12 @@ def eprint(*args, **kargs): ...@@ -12,9 +13,12 @@ def eprint(*args, **kargs):
print(*args, file=sys.stderr, **kargs) print(*args, file=sys.stderr, **kargs)
def flash(): def flash(tty=None):
pipe = subprocess.PIPE pipe = subprocess.PIPE
p = subprocess.Popen(['platformio', 'run', '-e', 'uno', '--target', 'upload'], cmd = ['platformio', 'run', '-e', 'uno', '--target', 'upload']
if tty is not None:
cmd.extend(['--upload-port', tty])
p = subprocess.Popen(cmd,
stdout=sys.stderr, stdin=pipe) stdout=sys.stderr, stdin=pipe)
stdout, stderr = p.communicate("") stdout, stderr = p.communicate("")
...@@ -105,9 +109,12 @@ def main(argv): ...@@ -105,9 +109,12 @@ def main(argv):
script_dir = os.path.split(argv[0])[0] script_dir = os.path.split(argv[0])[0]
if len(script_dir) > 0: if len(script_dir) > 0:
os.chdir(script_dir) os.chdir(script_dir)
flash()
dev = get_serial() dev = get_serial()
flash(dev)
eprint("Flashed")
time.sleep(1)
ser = serial.Serial(dev, baudrate=115200, timeout=5) ser = serial.Serial(dev, baudrate=115200, timeout=5)
uartp = UARTP(ser) uartp = UARTP(ser)
......
...@@ -7,14 +7,34 @@ import struct ...@@ -7,14 +7,34 @@ import struct
from subprocess import Popen, PIPE from subprocess import Popen, PIPE
def main(argv): def main(argv):
if len(argv) < 3: if len(argv) < 3:
print("Usage: test.py LWC_AEAD_KAT.txt program [arguments]") print("Usage: test.py LWC_AEAD_KAT.txt program [arguments]")
test_file = open(argv[1], 'r') test_file = open(argv[1], 'r')
p = Popen(argv[2:], bufsize=0, stdin=PIPE, stdout=PIPE) cmd = argv[2:]
for attempt in range(3):
print("beginning test %d of '%s' using test vectors '%s'" % (attempt, ' '.join(cmd), argv[1]))
measurements = begin_measurement()
try:
test(test_file, cmd)
print("TEST SUCCESSFUL")
return 0
except Exception as ex:
print(str(ex))
print("TEST FAILED")
finally:
end_measurement(measurements)
sys.stdout.flush()
sys.stderr.flush()
return 1
def test(test_file, cmd):
p = Popen(cmd, bufsize=0, stdin=PIPE, stdout=PIPE)
def write(data): def write(data):
l = p.stdin.write(data) l = p.stdin.write(data)
...@@ -22,6 +42,8 @@ def main(argv): ...@@ -22,6 +42,8 @@ def main(argv):
raise Exception("could not write %d bytes of data (put %d)" % (len(data), l)) raise Exception("could not write %d bytes of data (put %d)" % (len(data), l))
def read(l): def read(l):
if l == 0:
return b""
data = p.stdout.read(l) data = p.stdout.read(l)
if len(data) == 0: if len(data) == 0:
print("Unexpected end of stream", file=sys.stderr) print("Unexpected end of stream", file=sys.stderr)
...@@ -40,8 +62,9 @@ def main(argv): ...@@ -40,8 +62,9 @@ def main(argv):
(l, ) = struct.unpack("<I", l) (l, ) = struct.unpack("<I", l)
return read(l) return read(l)
if read(14) != b"Hello, World!\n": output = read(14)
raise Exception("Unexpected output") if output != b"Hello, World!\n":
raise Exception("Unexpected output: %s" % output)
print("Ready") print("Ready")
m = b"" m = b""
...@@ -110,6 +133,33 @@ def main(argv): ...@@ -110,6 +133,33 @@ def main(argv):
else: else:
print("ERROR: unparsed line in test vectors file: '%s'" % line) print("ERROR: unparsed line in test vectors file: '%s'" % line)
def begin_measurement():
import saleae
import time
sal = saleae.Saleae()
sal.set_active_channels([0, 1], [])
sal.set_sample_rate(sal.get_all_sample_rates()[0])
sal.set_capture_seconds(6000)
sal.capture_start()
time.sleep(1)
return sal
def end_measurement(sal):
import time
time.sleep(1)
sal.capture_stop();
while not sal.is_processing_complete():
pass
outfile = "measurement_%s.csv" % time.strftime("%Y%m%d-%H%M%S")
outfile = os.path.join("measurements", outfile)
if os.path.isfile(outfile):
os.unlink(outfile)
sal.export_data2(os.path.abspath(outfile))
print("Measurements written to '%s'" % outfile)
mdbfile = os.path.join("measurements", "measurements.txt")
mdbfile = open(mdbfile, "a")
mdbfile.write("%s > %s\n" % (' '.join(sys.argv), outfile))
mdbfile.close()
if __name__ == "__main__": if __name__ == "__main__":
sys.exit(main(sys.argv)) sys.exit(main(sys.argv))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment