From efb387b0d23e28e05d8fd19b3f5d8009f8fbd78b Mon Sep 17 00:00:00 2001 From: Anton Blanchard Date: Sat, 14 Aug 2021 16:59:50 +1000 Subject: [PATCH] makefile: Add some verilator micropython tests These are the same micropython tests we use against the ghdl simulation. Signed-off-by: Anton Blanchard --- Makefile | 6 ++++ scripts/test_micropython_verilator.py | 31 +++++++++++++++++ scripts/test_micropython_verilator_long.py | 39 ++++++++++++++++++++++ 3 files changed, 76 insertions(+) create mode 100755 scripts/test_micropython_verilator.py create mode 100755 scripts/test_micropython_verilator_long.py diff --git a/Makefile b/Makefile index ca3ee5f..46bfdaa 100644 --- a/Makefile +++ b/Makefile @@ -241,9 +241,15 @@ $(tests_console): core_tb test_micropython: core_tb @./scripts/test_micropython.py +test_micropython_verilator: microwatt-verilator + @./scripts/test_micropython_verilator.py + test_micropython_long: core_tb @./scripts/test_micropython_long.py +test_micropython_verilator_long: microwatt-verilator + @./scripts/test_micropython_verilator_long.py + tests_soc_tb = $(patsubst %_tb,%_tb_test,$(soc_tbs)) %_test: % diff --git a/scripts/test_micropython_verilator.py b/scripts/test_micropython_verilator.py new file mode 100755 index 0000000..fe94d52 --- /dev/null +++ b/scripts/test_micropython_verilator.py @@ -0,0 +1,31 @@ +#!/usr/bin/python3 + +import os +import subprocess +from pexpect import fdpexpect +import sys +import signal + +cmd = [ './microwatt-verilator' ] + +devNull = open(os.devnull, 'w') +p = subprocess.Popen(cmd, stdout=subprocess.PIPE, + stdin=subprocess.PIPE, stderr=devNull) + +exp = fdpexpect.fdspawn(p.stdout) +exp.logfile = sys.stdout.buffer + +exp.expect('Type "help\(\)" for more information.') +exp.expect('>>>') + +p.stdin.write(b'print("foo")\r\n') +p.stdin.flush() + +# Catch the command echoed back to the console +exp.expect('foo', timeout=600) + +# Now catch the output +exp.expect('foo', timeout=600) +exp.expect('>>>') + +os.kill(p.pid, signal.SIGKILL) diff --git a/scripts/test_micropython_verilator_long.py b/scripts/test_micropython_verilator_long.py new file mode 100755 index 0000000..36175f9 --- /dev/null +++ b/scripts/test_micropython_verilator_long.py @@ -0,0 +1,39 @@ +#!/usr/bin/python3 + +import os +import subprocess +from pexpect import fdpexpect +import sys +import signal + +cmd = [ './microwatt-verilator' ] + +devNull = open(os.devnull, 'w') +p = subprocess.Popen(cmd, stdout=subprocess.PIPE, + stdin=subprocess.PIPE, stderr=devNull) + +exp = fdpexpect.fdspawn(p.stdout) +exp.logfile = sys.stdout.buffer + +exp.expect('Type "help\(\)" for more information.') +exp.expect('>>>') + +p.stdin.write(b'n2=0\r\n') +p.stdin.write(b'n1=1\r\n') +p.stdin.write(b'for i in range(5):\r\n') +p.stdin.write(b' n0 = n1 + n2\r\n') +p.stdin.write(b' print(n0)\r\n') +p.stdin.write(b' n2 = n1\r\n') +p.stdin.write(b' n1 = n0\r\n') +p.stdin.write(b'\r\n') +p.stdin.flush() + +exp.expect('n1 = n0', timeout=600) +exp.expect('1', timeout=600) +exp.expect('2', timeout=600) +exp.expect('3', timeout=600) +exp.expect('5', timeout=600) +exp.expect('8', timeout=600) +exp.expect('>>>', timeout=600) + +os.kill(p.pid, signal.SIGKILL)