1
0
mirror of https://github.com/antonblanchard/microwatt.git synced 2026-01-11 23:43:15 +00:00
antonblanchard.microwatt/scripts/test_micropython_long.py
Anton Blanchard d0b5050ca4 Update micropython
The current version of micropython in tests/micropython.bin is ancient.
Bug #135 points out that more recent versions are much smaller and they
also handle restart when ctrl+D is pressed.

Save all three versions of the file (elf, bin and hex) in micropython/

Signed-off-by: Anton Blanchard <anton@linux.ibm.com>
2020-01-19 21:36:38 +11:00

49 lines
1.1 KiB
Python
Executable File

#!/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, 'micropython/firmware.bin'),
os.path.join(tempdir.name, 'main_ram.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)