Skip to content

Commit 18eb600

Browse files
committed
tools/mpremote: Add initial regression tests for mpremote.
These tests are specifically for the command-line interface and cover: - resume/soft-reset/connect/disconnect - mount - fs cp,touch,mkdir,cat,hash,rm,rmdir - eval/exec/run This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
1 parent 1bf97e5 commit 18eb600

12 files changed

+615
-0
lines changed

tools/mpremote/tests/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.out
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/bash
2+
set -e
3+
4+
TEST_DIR=$(dirname $0)
5+
MPREMOTE=${TEST_DIR}/../mpremote.py
6+
7+
if [ -z "$1" ]; then
8+
# Find tests matching test_*.sh
9+
TESTS=${TEST_DIR}/test_*.sh
10+
else
11+
# Specific test path from the command line.
12+
TESTS="$1"
13+
fi
14+
15+
for t in $TESTS; do
16+
TMP=$(mktemp -d)
17+
echo -n "${t}: "
18+
# Strip CR and replace the random temp dir with a token.
19+
if env MPREMOTE=${MPREMOTE} TMP="${TMP}" "${t}" | tr -d '\r' | sed "s,${TMP},"'${TMP},g' > "${t}.out"; then
20+
if diff "${t}.out" "${t}.exp" > /dev/null; then
21+
echo "OK"
22+
else
23+
echo "FAIL"
24+
diff "${t}.out" "${t}.exp" || true
25+
fi
26+
else
27+
echo "CRASH"
28+
fi
29+
rm -r "${TMP}"
30+
done
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/bash
2+
set -e
3+
4+
$MPREMOTE exec "print('mpremote')"
5+
6+
$MPREMOTE exec "print('before sleep'); import time; time.sleep(0.1); print('after sleep')"
7+
$MPREMOTE exec --no-follow "print('before sleep'); import time; time.sleep(0.1); print('after sleep')"
8+
sleep 0.3
9+
10+
$MPREMOTE eval "1+2"
11+
$MPREMOTE eval "[{'a': 'b'}, (1,2,3,), True]"
12+
13+
cat << EOF > /tmp/run.py
14+
print("run")
15+
EOF
16+
17+
$MPREMOTE run /tmp/run.py
18+
19+
cat << EOF > /tmp/run.py
20+
import time
21+
for i in range(3):
22+
time.sleep(0.1)
23+
print("run")
24+
EOF
25+
$MPREMOTE run --no-follow /tmp/run.py
26+
sleep 0.5
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
mpremote
2+
before sleep
3+
after sleep
4+
3
5+
[{'a': 'b'}, (1, 2, 3), True]
6+
run
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# stm32
5+
$MPREMOTE exec --no-follow "import os, pyb, machine; os.umount('/flash'); os.VfsLfs2.mkfs(pyb.Flash(start=0)); os.mount(pyb.Flash(start=0), '/flash'); os.chdir('/flash'); machine.reset()"
6+
# rp2
7+
# $MPREMOTE exec --no-follow "import os, machine, rp2; os.umount('/'); bdev = rp2.Flash(); os.VfsLfs2.mkfs(bdev, progsize=256); vfs = os.VfsLfs2(bdev, progsize=256); os.mount(vfs, '/'); machine.reset()"
8+
# esp32/esp8266
9+
# $MPREMOTE exec --no-follow "import os; os.umount('/'); os.VfsLfs2.mkfs(bdev); os.mount(bdev, '/'); machine.reset()"
10+
sleep 2
11+
12+
echo -----
13+
$MPREMOTE ls
14+
15+
echo -----
16+
$MPREMOTE touch a.py
17+
$MPREMOTE touch :b.py
18+
$MPREMOTE ls :
19+
$MPREMOTE cat a.py
20+
$MPREMOTE cat :b.py
21+
$MPREMOTE hash a.py
22+
echo -n "" | sha256sum
23+
24+
echo -----
25+
cat << EOF > "${TMP}/a.py"
26+
print("Hello")
27+
print("World")
28+
EOF
29+
$MPREMOTE cp "${TMP}/a.py" :
30+
$MPREMOTE cp "${TMP}/a.py" :b.py
31+
$MPREMOTE cp "${TMP}/a.py" :c.py
32+
$MPREMOTE ls
33+
$MPREMOTE exec "import a; import b; import c"
34+
$MPREMOTE hash a.py
35+
cat "${TMP}/a.py" | sha256sum
36+
37+
echo -----
38+
$MPREMOTE mkdir aaa
39+
$MPREMOTE mkdir :bbb
40+
$MPREMOTE cp "${TMP}/a.py" :aaa
41+
$MPREMOTE cp "${TMP}/a.py" :bbb/b.py
42+
$MPREMOTE cat :aaa/a.py bbb/b.py
43+
44+
echo -----
45+
$MPREMOTE rm :b.py c.py
46+
$MPREMOTE ls
47+
$MPREMOTE rm :aaa/a.py bbb/b.py
48+
$MPREMOTE rmdir aaa :bbb
49+
$MPREMOTE ls
50+
51+
echo -----
52+
env EDITOR="sed -i s/Hello/Goodbye/" $MPREMOTE edit a.py
53+
$MPREMOTE hash :a.py
54+
$MPREMOTE exec "import a"
55+
56+
# Create a local directory structure and copy it to `:` on the device.
57+
echo -----
58+
mkdir -p "${TMP}/package"
59+
mkdir -p "${TMP}/package/subpackage"
60+
cat << EOF > "${TMP}/package/__init__.py"
61+
from .x import x
62+
from .subpackage import y
63+
EOF
64+
cat << EOF > "${TMP}/package/x.py"
65+
def x():
66+
print("x")
67+
EOF
68+
cat << EOF > "${TMP}/package/subpackage/__init__.py"
69+
from .y import y
70+
EOF
71+
cat << EOF > "${TMP}/package/subpackage/y.py"
72+
def y():
73+
print("y")
74+
EOF
75+
$MPREMOTE cp -r "${TMP}/package" :
76+
$MPREMOTE ls : :package :package/subpackage
77+
$MPREMOTE exec "import package; package.x(); package.y()"
78+
79+
# Same thing except with a destination directory name.
80+
echo -----
81+
$MPREMOTE cp -r "${TMP}/package" :package2
82+
$MPREMOTE ls : :package2 :package2/subpackage
83+
$MPREMOTE exec "import package2; package2.x(); package2.y()"
84+
85+
# Copy to an existing directory, it will be copied inside.
86+
echo -----
87+
$MPREMOTE mkdir :test
88+
$MPREMOTE cp -r "${TMP}/package" :test
89+
$MPREMOTE ls :test :test/package :test/package/subpackage
90+
91+
# Copy to non-existing sub-directory.
92+
echo -----
93+
$MPREMOTE cp -r "${TMP}/package" :test/package2
94+
$MPREMOTE ls :test :test/package2 :test/package2/subpackage
95+
96+
# Copy from the device back to local.
97+
echo -----
98+
mkdir "${TMP}/copy"
99+
$MPREMOTE cp -r :package "${TMP}/copy"
100+
ls "${TMP}/copy" "${TMP}/copy/package" "${TMP}/copy/package/subpackage"
101+
102+
# Copy from the device back to local with destination directory name.
103+
echo -----
104+
$MPREMOTE cp -r :package "${TMP}/copy/package2"
105+
ls "${TMP}/copy" "${TMP}/copy/package2" "${TMP}/copy/package2/subpackage"
106+
107+
# Copy from device to another location on the device with destination directory name.
108+
echo -----
109+
$MPREMOTE cp -r :package :package3
110+
$MPREMOTE ls : :package3 :package3/subpackage
111+
112+
# Copy from device to another location on the device into an existing directory.
113+
echo -----
114+
$MPREMOTE mkdir :package4
115+
$MPREMOTE cp -r :package :package4
116+
$MPREMOTE ls : :package4 :package4/package :package4/package/subpackage
117+
118+
# Repeat an existing copy with one file modified.
119+
echo -----
120+
cat << EOF > "${TMP}/package/subpackage/y.py"
121+
def y():
122+
print("y2")
123+
EOF
124+
$MPREMOTE cp -r "${TMP}/package" :
125+
$MPREMOTE ls : :package :package/subpackage
126+
$MPREMOTE exec "import package; package.x(); package.y()"
Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
-----
2+
ls :
3+
-----
4+
touch :a.py
5+
touch :b.py
6+
ls :
7+
0 a.py
8+
0 b.py
9+
hash :a.py
10+
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
11+
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 -
12+
-----
13+
cp ${TMP}/a.py :
14+
cp ${TMP}/a.py :b.py
15+
cp ${TMP}/a.py :c.py
16+
ls :
17+
30 a.py
18+
30 b.py
19+
30 c.py
20+
Hello
21+
World
22+
Hello
23+
World
24+
Hello
25+
World
26+
hash :a.py
27+
50f0a701dd6cd6125387b96515300c9d5294c006518f8e62fa9eea3b66587f21
28+
50f0a701dd6cd6125387b96515300c9d5294c006518f8e62fa9eea3b66587f21 -
29+
-----
30+
mkdir :aaa
31+
mkdir :bbb
32+
cp ${TMP}/a.py :aaa/a.py
33+
cp ${TMP}/a.py :bbb/b.py
34+
print("Hello")
35+
print("World")
36+
print("Hello")
37+
print("World")
38+
-----
39+
rm :b.py
40+
rm :c.py
41+
ls :
42+
30 a.py
43+
0 aaa/
44+
0 bbb/
45+
rm :aaa/a.py
46+
rm :bbb/b.py
47+
rmdir :aaa
48+
rmdir :bbb
49+
ls :
50+
30 a.py
51+
-----
52+
edit :a.py
53+
hash :a.py
54+
612c7ddb88390ac86b4174b26a6e5b52fc2f2838b234efd8f6f7c41631a49d04
55+
Goodbye
56+
World
57+
-----
58+
cp ${TMP}/package :
59+
ls :
60+
32 a.py
61+
0 package/
62+
ls :package
63+
43 __init__.py
64+
0 subpackage/
65+
22 x.py
66+
ls :package/subpackage
67+
17 __init__.py
68+
22 y.py
69+
x
70+
y
71+
-----
72+
cp ${TMP}/package :package2
73+
ls :
74+
32 a.py
75+
0 package2/
76+
0 package/
77+
ls :package2
78+
43 __init__.py
79+
0 subpackage/
80+
22 x.py
81+
ls :package2/subpackage
82+
17 __init__.py
83+
22 y.py
84+
x
85+
y
86+
-----
87+
mkdir :test
88+
cp ${TMP}/package :test
89+
ls :test
90+
0 package/
91+
ls :test/package
92+
43 __init__.py
93+
0 subpackage/
94+
22 x.py
95+
ls :test/package/subpackage
96+
17 __init__.py
97+
22 y.py
98+
-----
99+
cp ${TMP}/package :test/package2
100+
ls :test
101+
0 package2/
102+
0 package/
103+
ls :test/package2
104+
43 __init__.py
105+
0 subpackage/
106+
22 x.py
107+
ls :test/package2/subpackage
108+
17 __init__.py
109+
22 y.py
110+
-----
111+
cp :package ${TMP}/copy
112+
${TMP}/copy:
113+
package
114+
115+
${TMP}/copy/package:
116+
__init__.py
117+
subpackage
118+
x.py
119+
120+
${TMP}/copy/package/subpackage:
121+
__init__.py
122+
y.py
123+
-----
124+
cp :package ${TMP}/copy/package2
125+
${TMP}/copy:
126+
package
127+
package2
128+
129+
${TMP}/copy/package2:
130+
__init__.py
131+
subpackage
132+
x.py
133+
134+
${TMP}/copy/package2/subpackage:
135+
__init__.py
136+
y.py
137+
-----
138+
cp :package :package3
139+
ls :
140+
32 a.py
141+
0 package2/
142+
0 package3/
143+
0 package/
144+
0 test/
145+
ls :package3
146+
43 __init__.py
147+
0 subpackage/
148+
22 x.py
149+
ls :package3/subpackage
150+
17 __init__.py
151+
22 y.py
152+
-----
153+
mkdir :package4
154+
cp :package :package4
155+
ls :
156+
32 a.py
157+
0 package2/
158+
0 package3/
159+
0 package4/
160+
0 package/
161+
0 test/
162+
ls :package4
163+
0 package/
164+
ls :package4/package
165+
43 __init__.py
166+
0 subpackage/
167+
22 x.py
168+
ls :package4/package/subpackage
169+
17 __init__.py
170+
22 y.py
171+
-----
172+
cp ${TMP}/package :
173+
Up to date: ./package/x.py
174+
Up to date: ./package/__init__.py
175+
Up to date: ./package/subpackage/__init__.py
176+
ls :
177+
32 a.py
178+
0 package2/
179+
0 package3/
180+
0 package4/
181+
0 package/
182+
0 test/
183+
ls :package
184+
43 __init__.py
185+
0 subpackage/
186+
22 x.py
187+
ls :package/subpackage
188+
17 __init__.py
189+
23 y.py
190+
x
191+
y2

0 commit comments

Comments
 (0)