Add Tercel PHY reset synchronization
[microwatt.git] / scripts / test_micropython_long.py
1 #!/usr/bin/python3
2
3 import tempfile
4 import os
5 from shutil import copyfile
6 import subprocess
7 from pexpect import fdpexpect
8 import sys
9 import signal
10
11 tempdir = tempfile.TemporaryDirectory()
12 cwd = os.getcwd()
13 os.chdir(tempdir.name)
14
15 copyfile(os.path.join(cwd, 'micropython/firmware.bin'),
16 os.path.join(tempdir.name, 'main_ram.bin'))
17
18 cmd = [ os.path.join(cwd, './core_tb') ]
19
20 devNull = open(os.devnull, 'w')
21 p = subprocess.Popen(cmd, stdout=devNull,
22 stdin=subprocess.PIPE, stderr=subprocess.PIPE)
23
24 exp = fdpexpect.fdspawn(p.stderr)
25 exp.logfile = sys.stdout.buffer
26
27 exp.expect('Type "help\(\)" for more information.')
28 exp.expect('>>>')
29
30 p.stdin.write(b'n2=0\r\n')
31 p.stdin.write(b'n1=1\r\n')
32 p.stdin.write(b'for i in range(5):\r\n')
33 p.stdin.write(b' n0 = n1 + n2\r\n')
34 p.stdin.write(b' print(n0)\r\n')
35 p.stdin.write(b' n2 = n1\r\n')
36 p.stdin.write(b' n1 = n0\r\n')
37 p.stdin.write(b'\r\n')
38 p.stdin.flush()
39
40 exp.expect('n1 = n0', timeout=600)
41 exp.expect('1', timeout=600)
42 exp.expect('2', timeout=600)
43 exp.expect('3', timeout=600)
44 exp.expect('5', timeout=600)
45 exp.expect('8', timeout=600)
46 exp.expect('>>>', timeout=600)
47
48 os.kill(p.pid, signal.SIGKILL)