Skip to content

Commit

Permalink
Improve run-image's boot.sh. (#2378)
Browse files Browse the repository at this point in the history
  • Loading branch information
floitsch authored Jun 3, 2024
1 parent 41f3bc2 commit 898a938
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 17 deletions.
18 changes: 4 additions & 14 deletions system/extensions/host/run-image-boot-sh.toit
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,6 @@ for (( ; ; )); do
export TOIT_CONFIG_DATA=\$(realpath \$PREFIX/\$current/config.ubjson)
if [ -e \$PREFIX/\$current/validated ]; then
already_validated=true
else
already_validated=false
fi
# Clear out the scratch directory.
rm -rf \$PREFIX/scratch
mkdir -p \$PREFIX/scratch
Expand Down Expand Up @@ -129,18 +123,14 @@ for (( ; ; )); do
echo "****************************************"
break
else
if [ ! \$exit_code -eq 0 -a ! \$exit_code -eq 18 ]; then
if [ ! \$exit_code -eq 0 -a ! \$exit_code -eq $EXIT-CODE-ROLLBACK-REQUESTED ]; then
echo "***********************************************"
echo "*** Firmware crashed with code=\$exit_code"
echo "***********************************************"
# Clear the flash-registry in case it was corrupted.
rm -f \$PREFIX/flash-registry
fi
if [ -e \$PREFIX/\$current/validated ]; then
if [ \$already_validated == false ]; then
echo "****************************************"
echo "*** Firmware successfully validated"
echo "****************************************"
fi
else
if [ ! -e \$PREFIX/\$current/validated ]; then
if [ \$exit_code -eq $EXIT-CODE-ROLLBACK-REQUESTED ]; then
echo "****************************************"
echo "*** Rollback requested"
Expand Down
43 changes: 43 additions & 0 deletions tests/envelope/boot-crash-source.toit
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright (C) 2024 Toitware ApS.
// Use of this source code is governed by a Zero-Clause BSD license that can
// be found in the tests/LICENSE file.
import host.file
import host.os
import system.firmware
import system.storage
import .exit-codes

main:
test-dir := os.env["BOOT_TEST_DIR"]
if file.is-file "$test-dir/mark":
second-call
else:
first-call test-dir

with-region [block]:
region := storage.Region.open --flash "toitlang.org/envelope-test-region" --capacity=100
block.call region
region.close

HELLO ::= "hello world"

first-call test-dir/string:
print "first call"
file.write-content --path="$test-dir/mark" "first"

with-region: | region/storage.Region |
region.write --at=0 HELLO

// Exit with a crash.
exit 1

second-call:
with-region: | region/storage.Region |
existing := region.read --from=0 --to=HELLO.size
if existing == HELLO:
print "Test failed"
else:
// The flash was correctly cleared after the crash.
print "Test succeeded"
exit EXIT-CODE-STOP
16 changes: 16 additions & 0 deletions tests/envelope/boot-crash-test.toit
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright (C) 2024 Toitware ApS.
// Use of this source code is governed by a Zero-Clause BSD license that can
// be found in the tests/LICENSE file.
import expect show *
import .exit-codes
import .util show EnvelopeTest with-test

main args:
with-test args: | test/EnvelopeTest |
test.install --name="crash" --source-path="./boot-crash-source.toit"
test.extract-to-dir --dir-path=test.tmp-dir
output := test.boot-backticks test.tmp-dir --env={
"BOOT_TEST_DIR": test.tmp-dir,
}
expect (output.contains "Test succeeded")
15 changes: 15 additions & 0 deletions tests/envelope/boot-deep-sleep-source.toit
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (C) 2024 Toitware ApS.
// Use of this source code is governed by a Zero-Clause BSD license that can
// be found in the tests/LICENSE file.
import host.file
import host.os
import .exit-codes

main:
test-dir := os.env["BOOT_TEST_DIR"]
if file.is-file "$test-dir/mark":
print "Test succeeded"
exit EXIT-CODE_STOP
file.write-content --path="$test-dir/mark" "first"
__deep_sleep__ 20 // Sleep 20 ms.
16 changes: 16 additions & 0 deletions tests/envelope/boot-deep-sleep-test.toit
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright (C) 2024 Toitware ApS.
// Use of this source code is governed by a Zero-Clause BSD license that can
// be found in the tests/LICENSE file.
import expect show *
import .exit-codes
import .util show EnvelopeTest with-test

main args:
with-test args: | test/EnvelopeTest |
test.install --name="deep-sleep" --source-path="./boot-deep-sleep-source.toit"
test.extract-to-dir --dir-path=test.tmp-dir
output := test.boot-backticks test.tmp-dir --env={
"BOOT_TEST_DIR": test.tmp-dir,
}
expect (output.contains "Test succeeded")
2 changes: 1 addition & 1 deletion tests/envelope/boot-flash-test.toit
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import .util show EnvelopeTest with-test

main args:
with-test args: | test/EnvelopeTest |
test.install --name="hello" --source-path="./boot-flash-source.toit"
test.install --name="flash" --source-path="./boot-flash-source.toit"
test.extract-to-dir --dir-path=test.tmp-dir
output := test.boot-backticks test.tmp-dir
expect (output.contains "Test succeeded")
1 change: 0 additions & 1 deletion tests/envelope/boot-upgrade-test.toit
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ test-success args/List:
"validation is pending",
"can rollback",
"validating",
"*** Firmware successfully validated", // From the boot script.
"hello from updated",
"validation is not pending",
"can not rollback",
Expand Down
3 changes: 2 additions & 1 deletion tests/envelope/boot-upgraded-success.toit
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import system.firmware
import host.file
import host.os
import .exit-codes

main:
print "hello from updated firmware!"
Expand All @@ -14,7 +15,7 @@ main:
test-dir := os.env["BOOT_TEST_DIR"]
if file.is-file "$test-dir/mark":
print "exiting"
exit 19
exit EXIT-CODE-STOP

print "validating"
firmware.validate
Expand Down

0 comments on commit 898a938

Please sign in to comment.