Skip to content

Commit

Permalink
Textual refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Xalava committed Feb 19, 2024
1 parent e40451d commit fe8ed84
Showing 1 changed file with 27 additions and 19 deletions.
46 changes: 27 additions & 19 deletions tests/run.sh
Original file line number Diff line number Diff line change
@@ -1,18 +1,34 @@
#!/bin/bash

# Script to build the docker image and run one or all tests and display a summary of the outcome
# This script runs tests in a docker container.

## Constants that can be adapted depending on the environment.
echo $(pwd)
STORAGE_STUDENT="$(pwd)/student.all"
# Constants that can be adapted depending on the environment.
STORAGE_STUDENT="$(pwd)/student"
TEMP_STUDENT="$(pwd)/student.temp"
rm -rf $TEMP_STUDENT # for debugging, the folder is left and removed a the next run
rm -rf $TEMP_STUDENT # For debugging purposes, the temporary folder is removed a the beginning of the next run
# These docker options should replicate the production environement
BaseOptions="--read-only --network none --memory 500M --cpus 2.0 --user 1000:1000 --env USERNAME=🧑‍🎓 --env HOME=/jail --env TMPDIR=/jail --workdir /jail --tmpfs /jail:size=100M,noatime,exec,nodev,nosuid,uid=1000,gid=1000,nr_inodes=5k,mode=1700 --volume $TEMP_STUDENT:/jail/student:ro"

## Summary display logic
# Initialisation of display variables (for clarity)
Results=""
testNumber=0
totalRuntime=0

displayHelp() {
#Display help (as it is formated here)
echo "Script to run tests in a docker container
Usage: $0 [clean|nuclear|testName|help]
Commands:
clean: Remove exited docker containers and images
nuclear: Remove all stopped containers, images and volumes
testname: Run a specific test in debug mode. E.g.: $0 retrieve-block-date
help: Display this help
If no parameters are provided, all tests are run."
}

synthesis() {
if [ $? -eq 0 ]; then
currentRuntime=$(($(date +%s%N) - $date))
Expand All @@ -30,9 +46,7 @@ synthesis() {
testNumber=$((testNumber + 1))
}

#@ Should replicate the production environement
BaseOptions="--read-only --network none --memory 500M --cpus 2.0 --user 1000:1000 --env USERNAME=🧑‍🎓 --env HOME=/jail --env TMPDIR=/jail --workdir /jail --tmpfs /jail:size=100M,noatime,exec,nodev,nosuid,uid=1000,gid=1000,nr_inodes=5k,mode=1700 --volume $TEMP_STUDENT:/jail/student:ro"

# Check if there is an argument:
if [ ! -z "$1" ]; then
if [ "$1" = "clean" ]; then
echo "▶️ Clean (docker housekeeping)"
Expand All @@ -51,14 +65,8 @@ if [ ! -z "$1" ]; then
rm -rf $TEMP_STUDENT
rm -rf node_modules
exit 0
elif [ "$1" = "help" ]; then
echo "Script to build the docker image and run one or all the tests"
echo ""
echo "Usage: ./runTests.sh [ clean | help | testName ]"
echo "testName: one test is run in debug mode, e.g. retrieve-block-date"
echo "clean: clean the docker environment"
echo "help: display this help"
echo "If no parameter is provided, all tests are run"
elif [ "$1" = "help" ] || ["$1" = "-h"]; then
displayHelp
exit 0
fi
# A specific test has been named, we run it with the debug flag
Expand All @@ -67,7 +75,7 @@ if [ ! -z "$1" ]; then
cp $STORAGE_STUDENT/$1.{sol,js,html,mjs} $TEMP_STUDENT 2>/dev/null
time docker run $BaseOptions -e DEBUG=true -e EXERCISE="$1" blockchain:latest
else
# No specific test has been named. Run all tests with a summary at the end
# No specific test has been named, run all tests with a summary at the end
echo "▶️ Docker build"
docker build . -t blockchain
echo "▶️ Running test"
Expand All @@ -85,6 +93,6 @@ else
sleep 1
echo "▶️ Results"
echo $Results
echo "tests ran:$testNumber in avg $(($totalRuntime / 1000000 / $testNumber)) ms"
echo "$testNumber tests ran in $(($totalRuntime / 1000000 / $testNumber)) ms avg"
fi
exit 0

0 comments on commit fe8ed84

Please sign in to comment.