os_test: add case for setjmp/longjmp

Reviewed-by: Pascal Brand <pascal.brand@linaro.org>
Reviewed-by: Jerome Forissier <jerome.forissier@linaro.org>
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
diff --git a/ta/os_test/os_test.c b/ta/os_test/os_test.c
index 30471d0..ff85236 100644
--- a/ta/os_test/os_test.c
+++ b/ta/os_test/os_test.c
@@ -25,6 +25,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include <stdint.h>
+#include <setjmp.h>
 
 #include <compiler.h>
 #include <ta_crypt.h>
@@ -619,6 +620,26 @@
 }
 #endif /*CFG_TA_FLOAT_SUPPORT*/
 
+static __noinline void call_longjmp(jmp_buf env)
+{
+	DMSG("Calling longjmp");
+	longjmp(env, 1);
+	EMSG("error: longjmp returned to calling function");
+}
+
+static TEE_Result test_setjmp(void)
+{
+	jmp_buf env;
+
+	if (setjmp(env)) {
+		IMSG("Returned via longjmp");
+		return TEE_SUCCESS;
+	} else {
+		call_longjmp(env);
+		return TEE_ERROR_GENERIC;
+	}
+}
+
 TEE_Result ta_entry_basic(uint32_t param_types, TEE_Param params[4])
 {
 	TEE_Result res = TEE_ERROR_GENERIC;
@@ -645,6 +666,10 @@
 	if (res != TEE_SUCCESS)
 		return res;
 
+	res = test_setjmp();
+	if (res != TEE_SUCCESS)
+		return res;
+
 	/* mpa lib test bench, panics TA on failure */
 	tb_main();