1
0
mirror of https://github.com/antonblanchard/microwatt.git synced 2026-04-30 05:45:38 +00:00

Initial import of microwatt

Signed-off-by: Anton Blanchard <anton@linux.ibm.com>
This commit is contained in:
Anton Blanchard
2019-08-22 16:46:13 +10:00
committed by Anton Blanchard
commit 5a29cb4699
2049 changed files with 38352 additions and 0 deletions

25
scripts/dependencies.py Executable file
View File

@@ -0,0 +1,25 @@
#!/usr/bin/python3
# Create makefile dependencies for VHDL files, looking for "use work" and
# "entity work" declarations
import sys
import re
work = re.compile('use work\.([^.]+)\.')
entity = re.compile('entity work\.(.*)')
for filename in sys.argv[1:]:
with open(filename, 'r') as f:
(basename, suffix) = filename.split('.')
print('%s.o:' % basename, end='')
for line in f:
m = work.search(line)
if m:
print(' %s.o' % m.group(1), end='')
m = entity.search(line)
if m:
print(' %s.o' % m.group(1), end='')
print()

16
scripts/hash.py Executable file
View File

@@ -0,0 +1,16 @@
#!/usr/bin/python3
import re
import fileinput
r = re.compile("REG ([0-9A-F]+)");
regs = list()
for line in fileinput.input():
m = r.search(line)
if m:
regs.append(int(m.group(1), 16))
#print("%016X"% int(m.group(1), 16))
print("%x" % hash(tuple(regs)))

33
scripts/run_test.sh Executable file
View File

@@ -0,0 +1,33 @@
#!/bin/bash
if [ $# -ne 1 ]; then
echo "Usage: run_test.sh <test>"
exit 1
fi
TEST=$1
TMPDIR=$(mktemp -d)
function finish {
rm -rf "$TMPDIR"
}
trap finish EXIT
MICROWATT_DIR=$PWD
Y=$(${MICROWATT_DIR}/scripts/hash.py tests/${TEST}.out)
cd $TMPDIR
cp ${MICROWATT_DIR}/tests/${TEST}.bin simple_ram_behavioural.bin
X=$( ${MICROWATT_DIR}/core_tb | ${MICROWATT_DIR}/scripts/hash.py )
if [ $X == $Y ]; then
echo "$TEST PASS"
else
echo "$TEST FAIL ********"
exit 1
fi

40
scripts/test_micropython.py Executable file
View File

@@ -0,0 +1,40 @@
#!/usr/bin/python3
import tempfile
import os
from shutil import copyfile
import subprocess
from pexpect import fdpexpect
import sys
import signal
tempdir = tempfile.TemporaryDirectory()
cwd = os.getcwd()
os.chdir(tempdir.name)
copyfile(os.path.join(cwd, 'tests/micropython.bin'),
os.path.join(tempdir.name, 'simple_ram_behavioural.bin'))
cmd = [ os.path.join(cwd, './core_tb') ]
devNull = open(os.devnull, 'w')
p = subprocess.Popen(cmd, stdout=devNull,
stdin=subprocess.PIPE, stderr=subprocess.PIPE)
exp = fdpexpect.fdspawn(p.stderr)
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)

View File

@@ -0,0 +1,48 @@
#!/usr/bin/python3
import tempfile
import os
from shutil import copyfile
import subprocess
from pexpect import fdpexpect
import sys
import signal
tempdir = tempfile.TemporaryDirectory()
cwd = os.getcwd()
os.chdir(tempdir.name)
copyfile(os.path.join(cwd, 'tests/micropython.bin'),
os.path.join(tempdir.name, 'simple_ram_behavioural.bin'))
cmd = [ os.path.join(cwd, './core_tb') ]
devNull = open(os.devnull, 'w')
p = subprocess.Popen(cmd, stdout=devNull,
stdin=subprocess.PIPE, stderr=subprocess.PIPE)
exp = fdpexpect.fdspawn(p.stderr)
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)