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 | 5beb236 | 2024-06-24 13:13:17 +0200 | [diff] [blame^] | 16 | CLIENT_BIN=$1 |
| 17 | shift |
| 18 | |
Valerio Setti | 4f4ade9 | 2024-05-03 17:28:04 +0200 | [diff] [blame] | 19 | function clean_run() { |
Valerio Setti | 655b979 | 2024-05-09 12:20:40 +0200 | [diff] [blame] | 20 | rm -f psa_notify_* |
Valerio Setti | 4f4ade9 | 2024-05-03 17:28:04 +0200 | [diff] [blame] | 21 | pkill psa_partition || true |
| 22 | pkill psa_client || true |
Tom Cosgrove | bdc4c2d | 2024-05-27 23:55:43 +0300 | [diff] [blame] | 23 | ipcs | grep q | awk '{ printf " -q " $2 }' | xargs ipcrm > /dev/null 2>&1 || true |
Valerio Setti | 4f4ade9 | 2024-05-03 17:28:04 +0200 | [diff] [blame] | 24 | } |
| 25 | |
| 26 | # The server creates some local files when it starts up so we can wait for this |
| 27 | # event as signal that the server is ready so that we can start client(s). |
| 28 | function wait_for_server_startup() { |
| 29 | while [ ! -f ./psa_notify_* ]; do |
Valerio Setti | 655b979 | 2024-05-09 12:20:40 +0200 | [diff] [blame] | 30 | sleep 0.1 |
Valerio Setti | 4f4ade9 | 2024-05-03 17:28:04 +0200 | [diff] [blame] | 31 | done |
| 32 | } |
| 33 | |
| 34 | clean_run |
| 35 | |
Valerio Setti | 5beb236 | 2024-06-24 13:13:17 +0200 | [diff] [blame^] | 36 | ./psa_partition & |
Valerio Setti | 4f4ade9 | 2024-05-03 17:28:04 +0200 | [diff] [blame] | 37 | wait_for_server_startup |
Valerio Setti | 5beb236 | 2024-06-24 13:13:17 +0200 | [diff] [blame^] | 38 | ./$CLIENT_BIN "$@" |
| 39 | |
| 40 | # Kill server once client exited |
| 41 | pkill psa_partition |