5 from shutil
import copyfile
7 from pexpect
import fdpexpect
11 tempdir
= tempfile
.TemporaryDirectory()
13 os
.chdir(tempdir
.name
)
15 copyfile(os
.path
.join(cwd
, 'micropython/firmware.bin'),
16 os
.path
.join(tempdir
.name
, 'main_ram.bin'))
18 cmd
= [ os
.path
.join(cwd
, './core_tb') ]
20 devNull
= open(os
.devnull
, 'w')
21 p
= subprocess
.Popen(cmd
, stdout
=devNull
,
22 stdin
=subprocess
.PIPE
, stderr
=subprocess
.PIPE
)
24 exp
= fdpexpect
.fdspawn(p
.stderr
)
25 exp
.logfile
= sys
.stdout
.buffer
27 exp
.expect('Type "help\(\)" for more information.')
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')
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)
48 os
.kill(p
.pid
, signal
.SIGKILL
)