Skip to content

Commit

Permalink
Merge branch 'feature/mysql-support'
Browse files Browse the repository at this point in the history
  • Loading branch information
klausweinbauer committed Oct 14, 2023
2 parents ade17ed + d494a7a commit 9af4710
Show file tree
Hide file tree
Showing 23 changed files with 294 additions and 148 deletions.
10 changes: 5 additions & 5 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@
"postCreateCommand": "git config --global --add safe.directory /workspaces/ATTEST-Testsystem && git config --global --unset user.email && git config --global --unset user.name",
"containerEnv": {
"PYTHONPATH": "/workspaces/ATTEST-Testsystem:/workspaces/ATTEST-Testsystem/tests/integration_tests",
"RTS_ROOT": "/workspaces/ATTEST-Testsystem",
"RTS_LOG_FILE": "testsystem.log",
"RTS_DB_FILE": "testsystem.db",
"RTS_CONF_FILE": "testsystem.json",
"RTS_TC_ROOT_PATH": "/workspaces/ATTEST-Testsystem/testcases"
"ATTEST_ROOT": "/workspaces/ATTEST-Testsystem",
"ATTEST_LOG_FILE": "testsystem.log",
"ATTEST_DB_FILE": "testsystem.db",
"ATTEST_CONF_FILE": "testsystem.json",
"ATTEST_TC_ROOT_PATH": "/workspaces/ATTEST-Testsystem/testcases"
}
}
2 changes: 1 addition & 1 deletion .github/workflows/build_doc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:

env:
PYTHONPATH: .:./tests/integration_tests
RTS_ROOT: .
ATTEST_ROOT: .
GIT_PYTHON_REFRESH: quiet

jobs:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ _*.c
*__pycache__

config.json
_docker-compose.yml

DEPRECATED*
TESTARTEFACT*
Expand Down
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,25 @@ If you already have an MSP430 or a PicoScope connected to your host, you can che
The test system runs in a docker container. We suggest you first build the docker image because this may take a while.

```
docker build -t rts:latest .
docker build -t attest:latest .
```

When you have the docker image ready, you can inspect the available commands of the test system.

```
docker run --rm -t rts:latest python3 main.py --help
docker run --rm -t attest:latest python3 main.py --help
```

The provided ``docker-compos.yml`` file is a ready-to-use setup for the test system. It combines the test system with a MySQL database for persistent storage. Adjust the environment variables and the volumes according to your system setup. The ``docker-compose-template.yml`` is used by the bootstrap script for automatically generating a compose file with the correct device configuration.

## Documentation
For comprehensive documentation, please visit the [project website](https://eas-attest.github.io/ATTEST-Testsystem/index.html).

Or you build the documentation locally by running the following command after you have the docker image ready. The documentation will be generated in the current working directory.
Or you build the documentation locally by running the following command after you have the docker image ready. The documentation will be generated in the current working directory.

```
docker run --rm -t \
-v "$(pwd)":/host rts:latest \
-v "$(pwd)":/host attest:latest \
bash -c "make html && cp -R _build/html /host/documentation"
```

Expand Down
54 changes: 20 additions & 34 deletions bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,20 @@

#################### CONFIG ####################

DOCKER_IMAGE_NAME="rts"
DOCKER_IMAGE_NAME="attest"
DOCKER_IMAGE_TAG="latest"
DOCKER_FILE="dockerfile"
DOCKER_CONTAINER_NAME="rts"
# Path to the ssh directory for the test system user on the host
SSH_PATH="/rtos/.ssh"
# Log, DB and Config path
SYS_PATH="/rtos"
DOCKER_CONTAINER_NAME="attest"
MSP_SERIAL_PORT_NAME="ttyACM"
PICO_SCOPE_USB_NAME="PicoScope"

##################### END ######################

DOCKER_BUILD_CONTEXT="."
DOCKER_RUN_ARGS=""
DOCKER_MODE="-it"
DOCKER_MODE=""

DOCKER_COMPOSE_FILE="_docker-compose.yml"

while test $# -gt 0
do
Expand Down Expand Up @@ -92,7 +90,7 @@ get_device_string(){
for DEVICE in $ACM_DEVICES
do
ACM_DEVICE_CNT=$(( $ACM_DEVICE_CNT + 1 ))
LINKED_DEVICE_STR="$LINKED_DEVICE_STR --device=/dev/$DEVICE"
LINKED_DEVICE_STR="${LINKED_DEVICE_STR} - /dev/${DEVICE}:/dev/${DEVICE}"$'\n'
done

echo "[INFO] Found $ACM_DEVICE_CNT possible serial connections to MSP boards."
Expand All @@ -102,7 +100,7 @@ get_device_string(){
TOKEN=( $LINE )
USB_BUS=${TOKEN[1]}
USB_DEVICE=$(echo ${TOKEN[3]} | sed 's/://')
echo " --device=/dev/bus/usb/$USB_BUS/$USB_DEVICE"
echo "/dev/bus/usb/$USB_BUS/$USB_DEVICE"
done )

if [ ${#SCOPE_DEVICES[@]} -eq 0 ] && [ $$ACM_DEVICE_CNT -eq 0 ]
Expand All @@ -115,40 +113,28 @@ get_device_string(){

for DEVICE in $SCOPE_DEVICES
do
LINKED_DEVICE_STR="$LINKED_DEVICE_STR $DEVICE"
LINKED_DEVICE_STR="${LINKED_DEVICE_STR} - ${DEVICE}:${DEVICE}"$'\n'
done
}

get_device_string

awk -v r="$LINKED_DEVICE_STR" '{gsub(/_DEVICES_/,r)}1' docker-compose-template.yml > $DOCKER_COMPOSE_FILE
sed -i -e "s%_ARGS_%$DOCKER_RUN_ARGS%g" $DOCKER_COMPOSE_FILE
sed -i -e "s%_ATTEST_IMG_%$DOCKER_IMAGE_NAME:$DOCKER_IMAGE_TAG%g" $DOCKER_COMPOSE_FILE

DOCKER_RET_CODE=0
start_container() {
ARGS="$LINKED_DEVICE_STR --rm $DOCKER_MODE --name $DOCKER_CONTAINER_NAME -v $SYS_PATH:/host -v $SSH_PATH:/root/.ssh"
IMG="$DOCKER_IMAGE_NAME:$DOCKER_IMAGE_TAG"
CMD="python3 main.py"
echo "[INFO] Start docker container."
echo "[INFO] Arguments: $ARGS"
echo "[INFO] Image: $IMG"
echo "[INFO] Command: $CMD"
echo "[INFO] Command Parameters: $DOCKER_RUN_ARGS"
docker run $ARGS $IMG $CMD $DOCKER_RUN_ARGS
start_docker() {
echo "[INFO] Start docker compose."
docker compose -f $DOCKER_COMPOSE_FILE up $DOCKER_MODE
DOCKER_RET_CODE=$?
echo "[INFO] Container started. Use 'docker attach rts' to interact with the testsystem or 'docker attach --sig-proxy=false rts' to inspect the log output."
echo "[INFO] Containers started. Use 'docker attach --sig-proxy=false $DOCKER_CONTAINER_NAME' to inspect the log output."
}

get_device_string
start_container
start_docker
if [ $DOCKER_RET_CODE -eq 0 ]
then
exit 0
elif [ $DOCKER_RET_CODE -eq 2 ]
then
echo "[WARNING] Failed to detect PicoScopes. This may happen after connecting the PicoScopes."
echo "[INFO] Trying to get new device names and restarting."
get_device_string
start_container
if [ $DOCKER_RET_CODE -eq 0 ]
then
exit 0
fi
fi

echo "[ERROR] Starting the test system failed with exit code $DOCKER_RET_CODE."
echo "[ERROR] Starting the test system failed with exit code $DOCKER_RET_CODE."
5 changes: 2 additions & 3 deletions doc/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ Environment Variables
Configuration via environment variables can be used to customize the test system on
startup. Environment variables are instrumental when the system runs as a docker image
or as part of docker-compose. The naming convention for environment variables is
UPPER_CASE with underscores and prefixed with ``RTS_`` \. The environment variable
prefix RTS stands for **R**\ eal-Time Operating System **T**\ est **S**\ ystem.
UPPER_CASE with underscores and prefixed with ``ATTEST_`` \.

.. note::

Expand All @@ -48,7 +47,7 @@ environment variable:

.. code-block::
RTS_RUN_HELLO_TESTSYSTEM=True
ATTEST_RUN_HELLO_TESTSYSTEM=True
Config File
Expand Down
35 changes: 20 additions & 15 deletions doc/testsystem.rst
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ because it needs to compile the libmsp library from scratch.

.. code-block::
docker build -t rts:latest .
docker build -t attest:latest .
To check if the setup works, run the *hello testsystem* program. This is the hello world
equivalent of the test system. It should greet you with basic information about the
Expand All @@ -125,7 +125,7 @@ They will show up in the log.

.. code-block::
docker run --rm -t -v "$(pwd)":/host rts:latest python3 main.py --hello-testsystem
docker run --rm -t -v "$(pwd)":/host attest:latest python3 main.py --hello-testsystem
.. note::

Expand All @@ -140,7 +140,7 @@ those files. So make sure this directory is mounted somewhere in the host system

.. code-block::
docker run --rm -v "$(pwd)":/host -t rts:latest python3 main.py
docker run --rm -v "$(pwd)":/host -t attest:latest python3 main.py
Other Docker Commands
Expand All @@ -150,33 +150,33 @@ Display available commands from the test system:

.. code-block::
docker run --rm -t rts:latest python3 main.py --help
docker run --rm -t attest:latest python3 main.py --help
Get a list of all MSPs and PicoScopes that have ever been connected to the test system:

.. code-block::
docker run --rm -v "$(pwd)":/host -t rts:latest python3 main.py --list-devices
docker run --rm -v "$(pwd)":/host -t attest:latest python3 main.py --list-devices
Set the display name for a device. This name is for example shown in the system report:

.. code-block::
docker run --rm -v "$(pwd)":/host -t rts:latest python3 main.py --set-name <SN> <NAME>
docker run --rm -v "$(pwd)":/host -t attest:latest python3 main.py --set-name <SN> <NAME>
Build documentation:

.. code-block::
docker run --rm -t \
-v "$(pwd)":/host rts:latest \
-v "$(pwd)":/host attest:latest \
bash -c "make html && cp -R _build/html /host/documentation"
Run unit tests:

.. code-block::
docker run --rm -t rts:latest pytest tests/unit_tests
docker run --rm -t attest:latest pytest tests/unit_tests
To successfully run integration tests, make sure to use the correct device paths for MPS
and PicoScope. The following command runs integration tests with one test unit:
Expand All @@ -187,7 +187,7 @@ and PicoScope. The following command runs integration tests with one test unit:
--device=/dev/ttyACM0 \
--device=/dev/ttyACM1 \
--device=/dev/bus/usb/001/003 \
rts:latest pytest tests/integration_tests
attest:latest pytest tests/integration_tests
Hardware
========
Expand Down Expand Up @@ -260,24 +260,28 @@ command looks similar to this:
Bootstrap Script
================

The bootstrap script automates the build and start of the test system.
The bootstrap script automates the build and start of the production test system with a MySQL database.
The test system needs access to the PicoScopes and MSP430 boards connected via USB to the host.
The script builds the test system container if it does not exist, builds the device connection string based on the USB devices present at the host, and starts the test system container.
The script runs the container in detached mode.
The script builds the test system container if it does not exist,
discovers device connections present at the host,
and starts the test system container and a persistent database.
It generates a docker-compose file from the ``docker-compose-template.yml``,
which is used to start the containers with the correct configuration.
The script runs the docker-compose in detached mode.
That means the test system no longer uses the terminal after the build process and runs in the background.
To reattach the terminal to the test system, use the following command:

.. code-block::
docker attach --sig-proxy=false rts
docker attach --sig-proxy=false attest
The previous command only shows the test system output. By pressing ``CTRL`` + ``C``, the
terminal gets detached, but the test system continues in the background. To terminate
the test system, either set ``--sig-proxy`` to true when attaching or set the
:py:attr:`~testsystem.config.Config.stop` property in the configuration.

You can add an arbitrary number of arguments when calling the bootstrap script.
These arguments are forwarded to docker and the test system (exceptions in the following table).
These arguments are forwarded to the test system container (exceptions in the following table).
For example, you can call the test systems help menu directly with the bootstrap script:

.. code-block::
Expand All @@ -288,7 +292,8 @@ For example, you can call the test systems help menu directly with the bootstrap
The arguments in this table are an exception to those passed to docker.
They will be handled directly by the bootstrap script.
You can combine them with an arbitrary number of other arguments you want to pass to the test system.
The order does not matter; the bootstrap script handles arguments from the table, and all others are passed down to docker.
The order does not matter; the bootstrap script handles arguments from the table,
and all others are passed down to docker.

.. csv-table::
:header: "Arguments", "Description"
Expand Down
43 changes: 43 additions & 0 deletions docker-compose-template.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
version: '2'
services:
db:
image: mysql:latest
environment:
MYSQL_ROOT_PASSWORD: 'secure'
MYSQL_DATABASE: 'testsystem'
MYSQL_USER: 'testsystem'
MYSQL_PASSWORD: 'Password1'
volumes:
- data:/var/lib/mysql
ports:
- "3306:3306"
attest:
image: _ATTEST_IMG_
container_name: attest
depends_on:
- "db"
environment:
ATTEST_START_DELAY: 5
ATTEST_DB_TYPE: 'mysql'
ATTEST_DB_USER: 'testsystem'
ATTEST_DB_PASSWORD: 'Password1'
ATTEST_DB_DATABASE: 'testsystem'
ATTEST_DB_SERVER: 'db'
ATTEST_GIT_SERVER: 'ssh://git@iti-gitlab.tugraz.at'
ATTEST_GIT_PUBLIC_PATH: 'eas/teaching/RTOS_SS99'
ATTEST_GIT_STUDENT_PATH: 'eas/teaching/RTOS_SS99'
ATTEST_GIT_SYSTEM_PATH: 'eas/teaching/RTOS_SS99/Testsystem_Reports_SS99'
ATTEST_TERM: 'SS99'
ATTEST_GROUP_IDS: '1;2;3;4;5;6;7;8;9;10'
ATTEST_EXERCISE_NR: 1
volumes:
- host:/host
- type: bind
source: ~/.ssh
target: /root/.ssh
devices:
_DEVICES_
command: python3 main.py _ARGS_
volumes:
data:
host:
41 changes: 41 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
version: '2'
services:
db:
image: mysql:latest
environment:
MYSQL_ROOT_PASSWORD: 'secure'
MYSQL_DATABASE: 'testsystem'
MYSQL_USER: 'testsystem'
MYSQL_PASSWORD: 'Password1'
volumes:
- data:/var/lib/mysql
ports:
- "3306:3306"
attest:
image: attest:latest
container_name: attest
depends_on:
- "db"
environment:
ATTEST_START_DELAY: 5
ATTEST_DB_TYPE: 'mysql'
ATTEST_DB_USER: 'testsystem'
ATTEST_DB_PASSWORD: 'Password1'
ATTEST_DB_DATABASE: 'testsystem'
ATTEST_DB_SERVER: 'db'
ATTEST_GIT_SERVER: 'ssh://git@iti-gitlab.tugraz.at'
ATTEST_GIT_PUBLIC_PATH: 'eas/teaching/RTOS_SS99'
ATTEST_GIT_STUDENT_PATH: 'eas/teaching/RTOS_SS99'
ATTEST_GIT_SYSTEM_PATH: 'eas/teaching/RTOS_SS99/Testsystem_Reports_SS99'
ATTEST_TERM: 'SS99'
ATTEST_GROUP_IDS: '1;2;3;4;5;6;7;8;9;10'
ATTEST_EXERCISE_NR: 1
volumes:
- host:/host
- type: bind
source: ~/.ssh
target: /root/.ssh
command: python3 main.py
volumes:
data:
host:
Loading

0 comments on commit 9af4710

Please sign in to comment.