You've already forked MicroPythonOS
mirror of
https://github.com/m5stack/MicroPythonOS.git
synced 2026-05-20 11:51:27 -07:00
unittest.sh: add support for on-device testing
This allows running unit tests on an ESP32 device connected to the USB serial port. It uses mpremote.py for this.
This commit is contained in:
+23
-4
@@ -6,6 +6,7 @@ testdir="$mydir"
|
||||
scriptdir=$(readlink -f "$mydir"/../scripts/)
|
||||
fs="$mydir"/../internal_filesystem/
|
||||
onetest="$1"
|
||||
ondevice="$2"
|
||||
|
||||
|
||||
# print os and set binary
|
||||
@@ -26,10 +27,25 @@ one_test() {
|
||||
file="$1"
|
||||
pushd "$fs"
|
||||
echo "Testing $file"
|
||||
"$binary" -X heapsize=8M -c "import sys ; sys.path.append('lib')
|
||||
if [ -z "$ondevice" ]; then
|
||||
"$binary" -X heapsize=8M -c "import sys ; sys.path.append('lib')
|
||||
$(cat $file)
|
||||
result = unittest.main() ; sys.exit(0 if result.wasSuccessful() else 1) "
|
||||
result=$?
|
||||
result=$?
|
||||
else
|
||||
cleanname=$(echo "$file" | sed "s#/#_#g")
|
||||
testlog=/tmp/"$cleanname".log
|
||||
mpremote.py exec "import sys ; sys.path.append('lib')
|
||||
$(cat $file)
|
||||
result = unittest.main()
|
||||
if result.wasSuccessful():
|
||||
print('TEST WAS A SUCCESS')
|
||||
else:
|
||||
print('TEST WAS A FAILURE')
|
||||
" > "$testlog"
|
||||
grep "TEST WAS A SUCCESS" "$testlog"
|
||||
result=$?
|
||||
fi
|
||||
popd
|
||||
return "$result"
|
||||
}
|
||||
@@ -37,10 +53,13 @@ result = unittest.main() ; sys.exit(0 if result.wasSuccessful() else 1) "
|
||||
failed=0
|
||||
|
||||
if [ -z "$onetest" ]; then
|
||||
echo "Usage: $0 [one_test_to_run.py]"
|
||||
echo "Usage: $0 [one_test_to_run.py] [ondevice]"
|
||||
echo "Example: $0 tests/simple.py"
|
||||
echo "Example: $0 tests/simple.py ondevice"
|
||||
echo
|
||||
echo "If no test is specified: run all tests from $testdir"
|
||||
echo "If no test is specified: run all tests from $testdir on local machine."
|
||||
echo
|
||||
echo "The 'ondevice' argument will try to run the test on a connected device using mpremote.py (should be on the PATH) over a serial connection."
|
||||
while read file; do
|
||||
one_test "$file"
|
||||
result=$?
|
||||
|
||||
Reference in New Issue
Block a user