crypto-client test: ensure that client/server are linked against proper MbedTLS libraries

Ensure that both server and client can call mbedtls_version_get_string_full()
to verify that they are linked against proper libraries.

Note: each side (client/server) performs the call against its own
MbedTLS library. There is no IPC communication involved in this
test. Client/server communication will come later.

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
diff --git a/tests/psa-client-server/psasim/Makefile b/tests/psa-client-server/psasim/Makefile
index a84483c..50fd0ad 100644
--- a/tests/psa-client-server/psasim/Makefile
+++ b/tests/psa-client-server/psasim/Makefile
@@ -1,4 +1,4 @@
-CFLAGS ?= -Wall -Werror -std=c99 -D_XOPEN_SOURCE=1 -D_POSIX_C_SOURCE=200809L
+CFLAGS += -Wall -Werror -std=c99 -D_XOPEN_SOURCE=1 -D_POSIX_C_SOURCE=200809L
 
 ifeq ($(DEBUG),1)
 	CFLAGS += -DDEBUG -O0 -g
@@ -9,10 +9,10 @@
 all: lib test
 
 lib:
-	$(MAKE) -C src CFLAGS="$(CFLAGS)"
+	$(MAKE) -C src CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)"
 
 test: lib
-	$(MAKE) -C test CFLAGS="$(CFLAGS)"
+	$(MAKE) -C test CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)"
 
 clean:
 	rm -f $(PSA_LIB) $(PSA_LIB_OBJS)
diff --git a/tests/psa-client-server/psasim/test/Makefile b/tests/psa-client-server/psasim/test/Makefile
index 34b86b6..5afc8f5 100644
--- a/tests/psa-client-server/psasim/test/Makefile
+++ b/tests/psa-client-server/psasim/test/Makefile
@@ -1,5 +1,16 @@
-INCLUDE := -I../include/ -I./psa_manifest
-LIB := -L../src -lpsaff
+LIBPSASIM_PATH := ..
+LIBPSACLIENT_PATH := ../../../libpsaclient
+LIBPSASERVER_PATH := ../../../libpsaserver
+
+LIBPSASIM := -L$(LIBPSASIM_PATH)/src -lpsaff
+LIBPSACLIENT := -L$(LIBPSACLIENT_PATH)/library -lmbedcrypto -lmbedx509 -lmbedtls
+LIBPSASERVER := -L$(LIBPSASERVER_PATH)/library -lmbedcrypto
+
+LIBPSASIM_H := -I$(LIBPSASIM_PATH)/include
+LIBPSACLIENT_H := -I$(LIBPSACLIENT_PATH)/include
+LIBPSASERVER_H := -I$(LIBPSASERVER_PATH)/include
+
+COMMON_INCLUDE := $(LIBPSASIM_H) -I./psa_manifest
 
 TEST_BIN = 	psa_client \
 			psa_partition
@@ -15,10 +26,10 @@
 all: $(TEST_BIN)
 
 psa_client: client.c $(GENERATED_H_FILES)
-	$(CC) $(INCLUDE) $(CFLAGS) $< $(LIB) -o $@
+	$(CC) $(COMMON_INCLUDE) $(LIBPSACLIENT_H) $(CFLAGS) $< $(LIBPSASIM) $(LIBPSACLIENT) -o $@
 
 psa_partition: $(PARTITION_SERVER_BOOTSTRAP) $(GENERATED_H_FILES)
-	$(CC) $(INCLUDE) $(CFLAGS) $< $(LIB) -o $@
+	$(CC) $(COMMON_INCLUDE) $(LIBPSASERVER_H) $(CFLAGS) $< $(LIBPSASIM) $(LIBPSASERVER) -o $@
 
 $(PARTITION_SERVER_BOOTSTRAP) $(GENERATED_H_FILES): manifest.json server.c
 	../tools/psa_autogen.py $<
diff --git a/tests/psa-client-server/psasim/test/client.c b/tests/psa-client-server/psasim/test/client.c
index 5bde82f..3c61120 100644
--- a/tests/psa-client-server/psasim/test/client.c
+++ b/tests/psa-client-server/psasim/test/client.c
@@ -5,19 +5,27 @@
  *  SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
  */
 
+#include <stdio.h>
+#include <unistd.h>
+
 #include <psa/client.h>
 #include <psa/util.h>
 #include "psa_manifest/sid.h"
-#include <stdio.h>
-#include <unistd.h>
+
+#include "mbedtls/version.h"
 
 #define CLIENT_PRINT(fmt, ...) \
     PRINT("Client: " fmt, ##__VA_ARGS__)
 
 int main()
 {
+    char mbedtls_version[18];
     const char *text = "FOOBARCOOL!!";
     char output[100] = { 0 };
+
+    mbedtls_version_get_string_full(mbedtls_version);
+    CLIENT_PRINT("%s", mbedtls_version);
+
     CLIENT_PRINT("My PID: %d", getpid());
 
     CLIENT_PRINT("PSA version: %u", psa_version(PSA_SID_SHA256_SID));
diff --git a/tests/psa-client-server/psasim/test/run_test.sh b/tests/psa-client-server/psasim/test/run_test.sh
index f0e7a62..0ffaaea 100755
--- a/tests/psa-client-server/psasim/test/run_test.sh
+++ b/tests/psa-client-server/psasim/test/run_test.sh
@@ -27,8 +27,8 @@
 
 clean_run
 
-./psa_partition -k &
+./psa_partition -k > psa_partition.log 2>&1 &
 SERV_PID=$!
 wait_for_server_startup
-./psa_client
+./psa_client > psa_client.log 2>&1
 wait $SERV_PID
diff --git a/tests/psa-client-server/psasim/test/server.c b/tests/psa-client-server/psasim/test/server.c
index c4b6d9c..1c873c6 100644
--- a/tests/psa-client-server/psasim/test/server.c
+++ b/tests/psa-client-server/psasim/test/server.c
@@ -13,6 +13,8 @@
 #include "psa/util.h"
 #include "psa_manifest/manifest.h"
 
+#include "mbedtls/version.h"
+
 #define SERVER_PRINT(fmt, ...) \
     PRINT("Server: " fmt, ##__VA_ARGS__)
 
@@ -43,6 +45,10 @@
     char foo[BUF_SIZE] = { 0 };
     const int magic_num = 66;
     int client_disconnected = 0;
+    char mbedtls_version[18];
+
+    mbedtls_version_get_string_full(mbedtls_version);
+    SERVER_PRINT("%s", mbedtls_version);
 
     parse_input_args(argc, argv);
     SERVER_PRINT("Starting");
diff --git a/tests/scripts/all.sh b/tests/scripts/all.sh
index 43db578..d280512 100755
--- a/tests/scripts/all.sh
+++ b/tests/scripts/all.sh
@@ -6210,7 +6210,7 @@
     helper_crypto_client_build server
 
     msg "build psasim"
-    make -C tests/psa-client-server/psasim
+    make -C tests/psa-client-server/psasim CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
 
     msg "test psasim"
     make -C tests/psa-client-server/psasim run