Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
lwc
/
compare
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Pipelines
Members
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
90b5d1d2
authored
Feb 19, 2020
by
lwc-tester
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updated f7 template to the new glorious pythonic way of doing things!
parent
82ad9eed
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
61 additions
and
214 deletions
+61
-214
templates/f7/test
+57
-210
test_common.py
+4
-4
No files found.
templates/f7/test
View file @
90b5d1d2
...
...
@@ -5,242 +5,89 @@ import sys
import
time
import
struct
import
serial
import
subprocess
import
pylink
sys
.
path
.
insert
(
0
,
'.'
)
from
test_common
import
(
SaleaeTimeMeasurements
,
parse_nist_aead_test_vectors
,
DeviceUnderTestAeadUARTP
,
run_nist_aead_test
,
)
RAM_SIZE
=
0x50000
def
eprint
(
*
args
,
**
kargs
):
print
(
*
args
,
file
=
sys
.
stderr
,
**
kargs
)
def
popen_jlink
():
pipe
=
subprocess
.
PIPE
cmd
=
[
'JLinkExe'
]
cmd
.
extend
([
'-autoconnect'
,
'1'
])
cmd
.
extend
([
'-device'
,
'STM32F746ZG'
])
cmd
.
extend
([
'-if'
,
'swd'
])
cmd
.
extend
([
'-speed'
,
'4000'
])
return
subprocess
.
Popen
(
cmd
,
stdout
=
sys
.
stderr
,
stdin
=
pipe
)
def
get_serial
():
import
serial.tools.list_ports
ports
=
serial
.
tools
.
list_ports
.
comports
()
for
port
in
ports
:
print
(
port
.
serial_number
)
devices
=
[
p
.
device
for
p
in
ports
if
p
.
serial_number
==
'FT2XA9MY'
]
devices
.
sort
()
return
serial
.
Serial
(
devices
[
0
],
baudrate
=
115200
,
timeout
=
5
)
def
flash
():
p
=
popen_jlink
()
return
p
.
communicate
((
"""
loadbin build/f7.bin 0x8000000
r
g
exit
"""
)
.
encode
(
'ascii'
))
class
F7
(
DeviceUnderTestAeadUARTP
):
RAM_SIZE
=
0x50000
def
__init__
(
self
):
DeviceUnderTestAeadUARTP
.
__init__
(
self
,
get_serial
())
self
.
jlink
=
pylink
.
JLink
()
self
.
jlink
.
open
(
779340002
)
def
fill_ram
():
p
=
popen_jlink
()
return
p
.
communicate
((
"""
h
loadbin ram_pattern.bin 0x20000000
savebin ram_copy.bin 0x20000000 0x
%
x
r
g
exit
"""
%
RAM_SIZE
)
.
encode
(
'ascii'
))
def
flash
(
self
):
jlink
=
self
.
jlink
jlink
.
connect
(
'STM32F746ZG'
)
jlink
.
flash_file
(
'build/f7.bin'
,
0x8000000
)
jlink
.
flash_file
(
'ram_pattern.bin'
,
0x20000000
)
jlink
.
reset
()
jlink
.
restart
()
def
dump_ram
():
p
=
popen_jlink
()
return
p
.
communicate
((
"""
h
savebin ram_dump.bin 0x20000000 0x
%
x
exit
"""
%
RAM_SIZE
)
.
encode
(
'ascii'
))
def
dump_ram
(
self
):
jlink
=
self
.
jlink
return
bytes
(
jlink
.
memory_read8
(
0x20000000
,
F7
.
RAM_SIZE
))
def
get_serial
():
import
serial.tools.list_ports
ports
=
serial
.
tools
.
list_ports
.
comports
()
devices
=
[
p
.
device
for
p
in
ports
]
devices
.
sort
()
return
devices
[
-
1
]
class
UARTP
:
def
__init__
(
self
,
ser
):
UARTP
.
SYN
=
0xf9
UARTP
.
FIN
=
0xf3
self
.
ser
=
ser
def
uart_read
(
self
):
r
=
self
.
ser
.
read
(
1
)
if
len
(
r
)
!=
1
:
raise
Exception
(
"Serial read error"
)
return
r
[
0
]
def
uart_write
(
self
,
c
):
b
=
struct
.
pack
(
"B"
,
c
)
r
=
self
.
ser
.
write
(
b
)
if
r
!=
len
(
b
):
raise
Exception
(
"Serial write error"
)
return
r
def
send
(
self
,
buf
):
self
.
uart_write
(
UARTP
.
SYN
)
len_ind_0
=
0xff
&
len
(
buf
)
len_ind_1
=
0xff
&
(
len
(
buf
)
>>
7
)
if
len
(
buf
)
<
128
:
self
.
uart_write
(
len_ind_0
)
else
:
self
.
uart_write
(
len_ind_0
|
0x80
)
self
.
uart_write
(
len_ind_1
)
fcs
=
0
for
i
in
range
(
len
(
buf
)):
info
=
buf
[
i
]
fcs
=
(
fcs
+
info
)
&
0xff
self
.
uart_write
(
buf
[
i
])
fcs
=
(
0xff
-
fcs
)
&
0xff
self
.
uart_write
(
fcs
)
self
.
uart_write
(
UARTP
.
FIN
)
eprint
(
"sent frame '
%
s'"
%
buf
.
hex
())
def
recv
(
self
):
tag_old
=
UARTP
.
FIN
while
1
:
tag
=
tag_old
while
1
:
if
tag_old
==
UARTP
.
FIN
:
if
tag
==
UARTP
.
SYN
:
break
tag_old
=
tag
tag
=
self
.
uart_read
()
tag_old
=
tag
l
=
self
.
uart_read
()
if
l
&
0x80
:
l
&=
0x7f
l
|=
self
.
uart_read
()
<<
7
fcs
=
0
buf
=
[]
for
i
in
range
(
l
):
info
=
self
.
uart_read
()
buf
.
append
(
info
)
fcs
=
(
fcs
+
info
)
&
0xff
fcs
=
(
fcs
+
self
.
uart_read
())
&
0xff
tag
=
self
.
uart_read
()
if
fcs
==
0xff
:
if
tag
==
UARTP
.
FIN
:
buf
=
bytes
(
buf
)
eprint
(
"rcvd frame '
%
s'"
%
buf
.
hex
())
if
len
(
buf
)
>=
1
and
buf
[
0
]
==
0xde
:
sys
.
stderr
.
buffer
.
write
(
buf
[
1
:])
sys
.
stderr
.
flush
()
else
:
return
buf
def
main
(
argv
):
if
len
(
argv
)
<
2
:
print
(
"Usage: test LWC_AEAD_KAT.txt"
)
kat
=
list
(
parse_nist_aead_test_vectors
(
argv
[
1
]))
def
main
(
argv
):
eprint
(
argv
[
0
])
script_dir
=
os
.
path
.
split
(
argv
[
0
])[
0
]
if
len
(
script_dir
)
>
0
:
os
.
chdir
(
script_dir
)
dev
=
get_serial
()
ser
=
serial
.
Serial
(
dev
,
baudrate
=
115200
,
timeout
=
5
)
uartp
=
UARTP
(
ser
)
dut
=
F7
()
flash
()
fill_ram
()
dut
.
flash
()
eprint
(
"Flashed"
)
time
.
sleep
(
0.1
)
def
stdin_read
(
n
):
b
=
sys
.
stdin
.
buffer
.
read
(
n
)
if
len
(
b
)
!=
n
:
sys
.
exit
(
1
)
return
b
def
stdin_readvar
():
l
=
stdin_read
(
4
)
(
l
,
)
=
struct
.
unpack
(
"<I"
,
l
)
v
=
stdin_read
(
l
)
return
v
exp_hello
=
b
"Hello, World!"
hello
=
ser
.
read
(
ser
.
in_waiting
)
if
hello
[
-
13
:]
!=
exp_hello
:
eprint
(
"Improper board initialization message:
%
s"
%
hello
)
return
1
dut
.
prepare
()
eprint
(
"Board initialized properly"
)
sys
.
stdout
.
write
(
"Hello, World!
\n
"
)
sys
.
stdout
.
flush
()
while
1
:
action
=
stdin_read
(
1
)[
0
]
eprint
(
"Command
%
c from stdin"
%
action
)
if
action
in
b
"ackmps"
:
v
=
stdin_readvar
()
uartp
.
send
(
struct
.
pack
(
"B"
,
action
)
+
v
)
ack
=
uartp
.
recv
()
if
len
(
ack
)
!=
1
or
ack
[
0
]
!=
action
:
raise
Exception
(
"Unacknowledged variable transfer"
)
eprint
(
"Var
%
c successfully sent to board"
%
action
)
elif
action
in
b
"ACKMPS"
:
c
=
struct
.
pack
(
"B"
,
action
)
uartp
.
send
(
c
)
v
=
uartp
.
recv
()
if
len
(
v
)
<
1
or
v
[
0
]
!=
action
:
raise
Exception
(
"Could not obtain variable from board"
)
v
=
v
[
1
:]
eprint
(
"Var
%
c received from board:
%
s"
%
(
action
,
v
.
hex
()))
l
=
struct
.
pack
(
"<I"
,
len
(
v
))
sys
.
stdout
.
buffer
.
write
(
l
+
v
)
sys
.
stdout
.
flush
()
elif
action
in
b
"ed"
:
c
=
struct
.
pack
(
"B"
,
action
)
uartp
.
send
(
c
)
ack
=
uartp
.
recv
()
if
len
(
ack
)
!=
1
or
ack
[
0
]
!=
action
:
raise
Exception
(
"Unacknowledged variable transfer"
)
eprint
(
"Operation
%
c completed successfully"
%
action
)
elif
action
in
b
"u"
:
dump_ram
()
with
open
(
"ram_copy.bin"
,
'rb'
)
as
dump
:
dump_a
=
dump
.
read
()
with
open
(
"ram_dump.bin"
,
'rb'
)
as
dump
:
dump_b
=
dump
.
read
()
if
len
(
dump_a
)
!=
RAM_SIZE
or
len
(
dump_b
)
!=
RAM_SIZE
:
raise
Exception
(
"Wrong dump sizes: 0x
%
x, 0x
%
x"
%
(
len
(
dump_a
),
len
(
dump_b
)))
streaks
=
[]
streak_beg
=
0
streak_end
=
0
for
i
in
range
(
len
(
dump_a
)):
if
dump_a
[
i
]
==
dump_b
[
i
]:
streak_end
=
i
else
:
if
streak_end
!=
streak_beg
:
streaks
.
append
((
streak_beg
,
streak_end
))
streak_beg
=
i
streak_end
=
i
for
b
,
e
in
streaks
:
eprint
(
"equal bytes from 0x
%
x to 0x
%
x (length:
%
d)"
%
(
b
,
e
,
e
-
b
))
b
,
e
=
max
(
streaks
,
key
=
lambda
a
:
a
[
1
]
-
a
[
0
])
eprint
(
"longest equal bytes streak from 0x
%
x to 0x
%
x (length:
%
d)"
%
(
b
,
e
,
e
-
b
))
v
=
struct
.
pack
(
"<II"
,
4
,
e
-
b
)
sys
.
stdout
.
buffer
.
write
(
v
)
sys
.
stdout
.
flush
()
else
:
raise
Exception
(
"Unknown action
%
c"
%
action
)
return
0
try
:
run_nist_aead_test
(
dut
,
kat
)
return
0
except
Exception
as
ex
:
print
(
"TEST FAILED"
)
raise
ex
finally
:
sys
.
stdout
.
flush
()
sys
.
stderr
.
flush
()
if
__name__
==
"__main__"
:
...
...
test_common.py
View file @
90b5d1d2
...
...
@@ -22,7 +22,7 @@ class DeviceUnderTest:
"""
pass
def
ram_dump
(
self
):
def
dump_ram
(
self
):
"""
This should be overridden to return the RAM dump as a bytes string.
"""
...
...
@@ -142,7 +142,7 @@ class UARTP:
def
run_nist_aead_test
(
dut
,
kat
):
dump_a
=
dut
.
ram_dump
()
dump_a
=
dut
.
dump_ram
()
tool
=
SaleaeTimeMeasurements
()
tool
.
begin_measurement
()
...
...
@@ -150,8 +150,8 @@ def run_nist_aead_test(dut, kat):
for
i
,
m
,
ad
,
k
,
npub
,
c
in
kat
:
run_nist_aead_test_line
(
dut
,
i
,
m
,
ad
,
k
,
npub
,
c
)
if
dump_a
is
not
None
and
i
==
0
:
dump_b
=
dut
.
ram_dump
()
if
dump_a
is
not
None
and
i
==
1
:
dump_b
=
dut
.
dump_ram
()
longest
=
compare_dumps
(
dump_a
,
dump_b
)
print
(
" longest chunk of untouched memory =
%
d"
%
longest
)
finally
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment