psa-client-server: move psasim from framework repo to the mbedtls one
This is a temporary fix that will be reverted once the framework
repository will have CI checks.
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
diff --git a/tests/psa-client-server/psasim/test/Makefile b/tests/psa-client-server/psasim/test/Makefile
new file mode 100644
index 0000000..34b86b6
--- /dev/null
+++ b/tests/psa-client-server/psasim/test/Makefile
@@ -0,0 +1,29 @@
+INCLUDE := -I../include/ -I./psa_manifest
+LIB := -L../src -lpsaff
+
+TEST_BIN = psa_client \
+ psa_partition
+
+GENERATED_H_FILES = psa_manifest/manifest.h \
+ psa_manifest/pid.h \
+ psa_manifest/sid.h
+
+PARTITION_SERVER_BOOTSTRAP = psa_ff_bootstrap_TEST_PARTITION.c
+
+.PHONY: all clean
+
+all: $(TEST_BIN)
+
+psa_client: client.c $(GENERATED_H_FILES)
+ $(CC) $(INCLUDE) $(CFLAGS) $< $(LIB) -o $@
+
+psa_partition: $(PARTITION_SERVER_BOOTSTRAP) $(GENERATED_H_FILES)
+ $(CC) $(INCLUDE) $(CFLAGS) $< $(LIB) -o $@
+
+$(PARTITION_SERVER_BOOTSTRAP) $(GENERATED_H_FILES): manifest.json server.c
+ ../tools/psa_autogen.py $<
+
+clean:
+ rm -f $(TEST_BIN) psa_ff_bootstrap_*.c
+ rm -f psa_notify_* psa_service_*
+ rm -f psa_manifest/*
diff --git a/tests/psa-client-server/psasim/test/client.c b/tests/psa-client-server/psasim/test/client.c
new file mode 100644
index 0000000..5bde82f
--- /dev/null
+++ b/tests/psa-client-server/psasim/test/client.c
@@ -0,0 +1,48 @@
+/* psasim test client */
+
+/*
+ * Copyright The Mbed TLS Contributors
+ * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
+ */
+
+#include <psa/client.h>
+#include <psa/util.h>
+#include "psa_manifest/sid.h"
+#include <stdio.h>
+#include <unistd.h>
+
+#define CLIENT_PRINT(fmt, ...) \
+ PRINT("Client: " fmt, ##__VA_ARGS__)
+
+int main()
+{
+ const char *text = "FOOBARCOOL!!";
+ char output[100] = { 0 };
+ CLIENT_PRINT("My PID: %d", getpid());
+
+ CLIENT_PRINT("PSA version: %u", psa_version(PSA_SID_SHA256_SID));
+ psa_handle_t h = psa_connect(PSA_SID_SHA256_SID, 1);
+
+ if (h < 0) {
+ CLIENT_PRINT("Couldn't connect %d", h);
+ return 1;
+ } else {
+ int type = 2;
+ CLIENT_PRINT("psa_call() w/o invec returned: %d", psa_call(h, type, NULL, 0, NULL, 0));
+ psa_invec invecs[1];
+ psa_outvec outvecs[1];
+ invecs[0].base = text;
+ invecs[0].len = sizeof(text);
+ outvecs[0].base = output;
+ outvecs[0].len = sizeof(output);
+
+ CLIENT_PRINT("invec len: %lu", invecs[0].len);
+ CLIENT_PRINT("psa_call() w/ invec returned: %d", psa_call(h, type, invecs, 1, outvecs, 1));
+ CLIENT_PRINT("Received payload len: %ld", outvecs[0].len);
+ CLIENT_PRINT("Received payload content: %s", output);
+ CLIENT_PRINT("Closing handle");
+ psa_close(h);
+ }
+
+ return 0;
+}
diff --git a/tests/psa-client-server/psasim/test/manifest.json b/tests/psa-client-server/psasim/test/manifest.json
new file mode 100644
index 0000000..0ab83ef
--- /dev/null
+++ b/tests/psa-client-server/psasim/test/manifest.json
@@ -0,0 +1,29 @@
+{
+ "psa_framework_version":1.0,
+ "name":"TEST_PARTITION",
+ "type":"PSA-ROT",
+ "priority":"LOW",
+ "entry_point":"psa_sha256_main",
+ "stack_size":"0x400",
+ "heap_size":"0x100",
+ "services":[
+ {
+ "name":"PSA_SID_SHA256",
+ "sid":"0x0000F000",
+ "signal":"PSA_SHA256",
+ "non_secure_clients": "true",
+ "minor_version":1,
+ "minor_policy":"STRICT"
+ }
+ ],
+ "irqs": [
+ {
+ "source": "SIGINT",
+ "signal": "SIGINT_SIG"
+ },
+ {
+ "source": "SIGTSTP",
+ "signal": "SIGSTP_SIG"
+ }
+ ]
+}
diff --git a/tests/psa-client-server/psasim/test/run_test.sh b/tests/psa-client-server/psasim/test/run_test.sh
new file mode 100755
index 0000000..f0e7a62
--- /dev/null
+++ b/tests/psa-client-server/psasim/test/run_test.sh
@@ -0,0 +1,34 @@
+#!/bin/bash
+
+# This is a simple bash script that tests psa_client/psa_server interaction.
+# This script is automatically executed when "make run" is launched by the
+# "psasim" root folder. The script can also be launched manually once
+# binary files are built (i.e. after "make test" is executed from the "psasim"
+# root folder).
+#
+# Copyright The Mbed TLS Contributors
+# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
+
+set -e
+
+function clean_run() {
+ pkill psa_partition || true
+ pkill psa_client || true
+ ipcs | grep q | awk '{ printf " -q " $$2 }' | xargs ipcrm > /dev/null 2>&1 || true
+}
+
+# The server creates some local files when it starts up so we can wait for this
+# event as signal that the server is ready so that we can start client(s).
+function wait_for_server_startup() {
+ while [ ! -f ./psa_notify_* ]; do
+ sleep 0.1
+ done
+}
+
+clean_run
+
+./psa_partition -k &
+SERV_PID=$!
+wait_for_server_startup
+./psa_client
+wait $SERV_PID
diff --git a/tests/psa-client-server/psasim/test/server.c b/tests/psa-client-server/psasim/test/server.c
new file mode 100644
index 0000000..c4b6d9c
--- /dev/null
+++ b/tests/psa-client-server/psasim/test/server.c
@@ -0,0 +1,119 @@
+/* psasim test server */
+
+/*
+ * Copyright The Mbed TLS Contributors
+ * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
+ */
+
+#include <unistd.h>
+#include <stdio.h>
+
+#include "psa/service.h"
+#include "psa/error.h"
+#include "psa/util.h"
+#include "psa_manifest/manifest.h"
+
+#define SERVER_PRINT(fmt, ...) \
+ PRINT("Server: " fmt, ##__VA_ARGS__)
+
+#define BUF_SIZE 25
+
+static int kill_on_disconnect = 0; /* Kill the server on client disconnection. */
+
+void parse_input_args(int argc, char *argv[])
+{
+ int opt;
+
+ while ((opt = getopt(argc, argv, "k")) != -1) {
+ switch (opt) {
+ case 'k':
+ kill_on_disconnect = 1;
+ break;
+ default:
+ fprintf(stderr, "Usage: %s [-k]\n", argv[0]);
+ exit(EXIT_FAILURE);
+ }
+ }
+}
+
+int psa_sha256_main(int argc, char *argv[])
+{
+ psa_status_t ret = PSA_ERROR_PROGRAMMER_ERROR;
+ psa_msg_t msg = { -1 };
+ char foo[BUF_SIZE] = { 0 };
+ const int magic_num = 66;
+ int client_disconnected = 0;
+
+ parse_input_args(argc, argv);
+ SERVER_PRINT("Starting");
+
+ while (!(kill_on_disconnect && client_disconnected)) {
+ psa_signal_t signals = psa_wait(PSA_WAIT_ANY, PSA_BLOCK);
+
+ if (signals > 0) {
+ SERVER_PRINT("Signals: 0x%08x", signals);
+ }
+
+ if (signals & PSA_SHA256_SIGNAL) {
+ if (PSA_SUCCESS == psa_get(PSA_SHA256_SIGNAL, &msg)) {
+ SERVER_PRINT("My handle is %d", msg.handle);
+ SERVER_PRINT("My rhandle is %p", (int *) msg.rhandle);
+ switch (msg.type) {
+ case PSA_IPC_CONNECT:
+ SERVER_PRINT("Got a connection message");
+ psa_set_rhandle(msg.handle, (void *) &magic_num);
+ ret = PSA_SUCCESS;
+ break;
+ case PSA_IPC_DISCONNECT:
+ SERVER_PRINT("Got a disconnection message");
+ ret = PSA_SUCCESS;
+ client_disconnected = 1;
+ break;
+
+ default:
+ SERVER_PRINT("Got an IPC call of type %d", msg.type);
+ ret = 42;
+ size_t size = msg.in_size[0];
+
+ if ((size > 0) && (size <= sizeof(foo))) {
+ psa_read(msg.handle, 0, foo, 6);
+ foo[(BUF_SIZE-1)] = '\0';
+ SERVER_PRINT("Reading payload: %s", foo);
+ psa_read(msg.handle, 0, foo+6, 6);
+ foo[(BUF_SIZE-1)] = '\0';
+ SERVER_PRINT("Reading payload: %s", foo);
+ }
+
+ size = msg.out_size[0];
+ if ((size > 0)) {
+ SERVER_PRINT("Writing response");
+ psa_write(msg.handle, 0, "RESP", 4);
+ psa_write(msg.handle, 0, "ONSE", 4);
+ }
+
+ if (msg.client_id > 0) {
+ psa_notify(msg.client_id);
+ } else {
+ SERVER_PRINT("Client is non-secure, so won't notify");
+ }
+
+ }
+
+ psa_reply(msg.handle, ret);
+ } else {
+ SERVER_PRINT("Failed to retrieve message");
+ }
+ } else if (SIGSTP_SIG & signals) {
+ SERVER_PRINT("Recieved SIGSTP signal. Gonna EOI it.");
+ psa_eoi(SIGSTP_SIG);
+ } else if (SIGINT_SIG & signals) {
+ SERVER_PRINT("Handling interrupt!");
+ SERVER_PRINT("Gracefully quitting");
+ psa_panic();
+ } else {
+ SERVER_PRINT("No signal asserted");
+ }
+ }
+
+ return 0;
+}