Valerio Setti | 4f4ade9 | 2024-05-03 17:28:04 +0200 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | # This is a simple bash script that tests psa_client/psa_server interaction. |
| 4 | # This script is automatically executed when "make run" is launched by the |
| 5 | # "psasim" root folder. The script can also be launched manually once |
| 6 | # binary files are built (i.e. after "make test" is executed from the "psasim" |
| 7 | # root folder). |
| 8 | # |
| 9 | # Copyright The Mbed TLS Contributors |
| 10 | # SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later |
| 11 | |
| 12 | set -e |
| 13 | |
Valerio Setti | 655b979 | 2024-05-09 12:20:40 +0200 | [diff] [blame] | 14 | cd "$(dirname "$0")" |
| 15 | |
Valerio Setti | 4f4ade9 | 2024-05-03 17:28:04 +0200 | [diff] [blame] | 16 | function clean_run() { |
Valerio Setti | 655b979 | 2024-05-09 12:20:40 +0200 | [diff] [blame] | 17 | rm -f psa_notify_* |
Valerio Setti | 4f4ade9 | 2024-05-03 17:28:04 +0200 | [diff] [blame] | 18 | pkill psa_partition || true |
| 19 | pkill psa_client || true |
| 20 | ipcs | grep q | awk '{ printf " -q " $$2 }' | xargs ipcrm > /dev/null 2>&1 || true |
| 21 | } |
| 22 | |
| 23 | # The server creates some local files when it starts up so we can wait for this |
| 24 | # event as signal that the server is ready so that we can start client(s). |
| 25 | function wait_for_server_startup() { |
| 26 | while [ ! -f ./psa_notify_* ]; do |
Valerio Setti | 655b979 | 2024-05-09 12:20:40 +0200 | [diff] [blame] | 27 | sleep 0.1 |
Valerio Setti | 4f4ade9 | 2024-05-03 17:28:04 +0200 | [diff] [blame] | 28 | done |
| 29 | } |
| 30 | |
| 31 | clean_run |
| 32 | |
Valerio Setti | 4362aae | 2024-05-09 09:15:39 +0200 | [diff] [blame] | 33 | ./psa_partition -k > psa_partition.log 2>&1 & |
Valerio Setti | 4f4ade9 | 2024-05-03 17:28:04 +0200 | [diff] [blame] | 34 | SERV_PID=$! |
| 35 | wait_for_server_startup |
Valerio Setti | 4362aae | 2024-05-09 09:15:39 +0200 | [diff] [blame] | 36 | ./psa_client > psa_client.log 2>&1 |
Valerio Setti | 4f4ade9 | 2024-05-03 17:28:04 +0200 | [diff] [blame] | 37 | wait $SERV_PID |