Fix tests to properly recognize "tef-dummy" environment 44/162044/1
authorTomasz Swierczek <t.swierczek@samsung.com>
Tue, 28 Nov 2017 17:29:44 +0000 (18:29 +0100)
committerTomasz Swierczek <t.swierczek@samsung.com>
Tue, 28 Nov 2017 18:16:38 +0000 (19:16 +0100)
* Initialize TA only if security.tee feature is enabled
* Change security.tee feature recognition to be old-device-proof
* Change expected tef-dummy return value to NOT_IMPLEMENTED (following GP API spec)

Change-Id: I2918ea4bc5952de9adb7e19c48ca163a79adb4fa

src/libteec-tests/test_cases.cpp

index 4449a6d14368ee989232eab1c186578b783e490c..78859ab90bf9d55a94e29468de0f279fc0d28940 100644 (file)
@@ -209,8 +209,14 @@ bool checkIfTeeEnabled()
     if (!isChecked)
     {
         int ret = system_info_get_platform_bool("tizen.org/feature/security.tee", &isEnabled);
-        RUNNER_ASSERT_MSG(ret == SYSTEM_INFO_ERROR_NONE,
-            "Failed to get system info. Error: " << systemInfoErrToString(ret));
+        if (ret == SYSTEM_INFO_ERROR_INVALID_PARAMETER)
+        {
+            // device may be so old it does not have the security.tee setting in config at all
+            isEnabled = false;
+        } else {
+            RUNNER_ASSERT_MSG(ret == SYSTEM_INFO_ERROR_NONE,
+                "Failed to get system info. Error: " << systemInfoErrToString(ret));
+        }
         isChecked = true;
     }
     return isEnabled;
@@ -221,7 +227,7 @@ RUNNER_TEST_GROUP_INIT(LIBTEEC)
 
 RUNNER_CHILD_TEST(libteec_01_load_TA_as_app)
 {
-    Ta ta(taUuid);
+    auto taPtr = std::unique_ptr<Ta>(nullptr);
 
     TemporaryTestUser tmpUser("libteec_01_test_user", GUM_USERTYPE_NORMAL);
     tmpUser.create();
@@ -233,6 +239,11 @@ RUNNER_CHILD_TEST(libteec_01_load_TA_as_app)
 
     bool isTeeEnabled = checkIfTeeEnabled();
 
+    if (isTeeEnabled)
+    {
+        taPtr.reset(new Ta(taUuid));
+    }
+
     auto fun = [&]()
     {
         auto contextPtr = std::unique_ptr<TEEC_Context, decltype(&TEEC_FinalizeContext)>
@@ -251,7 +262,7 @@ RUNNER_CHILD_TEST(libteec_01_load_TA_as_app)
         TEEC_Result res = TEEC_InitializeContext(NULL, &context);
         contextPtr.reset(&context);
 
-        TEEC_Result desiredResult = isTeeEnabled ? TEEC_SUCCESS : TEEC_ERROR_NOT_SUPPORTED;
+        TEEC_Result desiredResult = isTeeEnabled ? TEEC_SUCCESS : TEEC_ERROR_NOT_IMPLEMENTED;
         RUNNER_ASSERT_MSG(res == desiredResult,
             "Failed to initialize context. Error code: " << errToString(res)
             << ", expected: " << errToString(desiredResult));
@@ -261,7 +272,7 @@ RUNNER_CHILD_TEST(libteec_01_load_TA_as_app)
             &session, &taUuid, TEEC_LOGIN_PUBLIC, NULL, NULL, &returnOrigin);
         sessionPtr.reset(&session);
 
-        desiredResult = isTeeEnabled ? TEEC_SUCCESS : TEEC_ERROR_NOT_SUPPORTED;
+        desiredResult = isTeeEnabled ? TEEC_SUCCESS : TEEC_ERROR_NOT_IMPLEMENTED;
         RUNNER_ASSERT_MSG(res == desiredResult,
             "Opening libteec session returned wrong value: " << errToString(res)
             << ", expected: " << errToString(desiredResult));
@@ -277,10 +288,15 @@ RUNNER_CHILD_TEST(libteec_01_load_TA_as_app)
 
 RUNNER_CHILD_TEST(libteec_02_load_TA_as_system)
 {
-    Ta ta(taUuid);
+    auto taPtr = std::unique_ptr<Ta>(nullptr);
 
     bool isTeeEnabled = checkIfTeeEnabled();
 
+    if (isTeeEnabled)
+    {
+        taPtr.reset(new Ta(taUuid));
+    }
+
     auto fun = [&]()
     {
         auto contextPtr = std::unique_ptr<TEEC_Context, decltype(&TEEC_FinalizeContext)>
@@ -297,7 +313,7 @@ RUNNER_CHILD_TEST(libteec_02_load_TA_as_system)
         TEEC_Result res = TEEC_InitializeContext(NULL, &context);
         contextPtr.reset(&context);
 
-        TEEC_Result desiredResult = isTeeEnabled ? TEEC_SUCCESS : TEEC_ERROR_NOT_SUPPORTED;
+        TEEC_Result desiredResult = isTeeEnabled ? TEEC_SUCCESS : TEEC_ERROR_NOT_IMPLEMENTED;
         RUNNER_ASSERT_MSG(res == desiredResult,
             "Failed to initialize context. Error code: " << errToString(res)
             << ", expected: " << errToString(desiredResult));
@@ -307,7 +323,7 @@ RUNNER_CHILD_TEST(libteec_02_load_TA_as_system)
             &session, &taUuid, TEEC_LOGIN_PUBLIC, NULL, NULL, &returnOrigin);
         sessionPtr.reset(&session);
 
-        desiredResult = isTeeEnabled ? TEEC_SUCCESS : TEEC_ERROR_NOT_SUPPORTED;
+        desiredResult = isTeeEnabled ? TEEC_SUCCESS : TEEC_ERROR_NOT_IMPLEMENTED;
         RUNNER_ASSERT_MSG(res == desiredResult,
             "Opening libteec session returned wrong value: " << errToString(res)
             << ", expected: " << errToString(desiredResult));
@@ -378,7 +394,7 @@ RUNNER_CHILD_TEST(libteec_03_try_use_libteec_with_no_cynara_perm_as_app)
         contextPtr.reset(&context);
 
         // OpTEE return TEEC_ERROR_ITEM_NOT_FOUND, when cannot access to /dev/tee
-        TEEC_Result desiredResult = isTeeEnabled ? TEEC_ERROR_ACCESS_DENIED : TEEC_ERROR_NOT_SUPPORTED;
+        TEEC_Result desiredResult = isTeeEnabled ? TEEC_ERROR_ACCESS_DENIED : TEEC_ERROR_NOT_IMPLEMENTED;
         RUNNER_ASSERT_MSG(res == desiredResult,
             "Initializing context returned wrong error code: " << errToString(res)
             << ", expected: " << errToString(desiredResult));
@@ -413,7 +429,7 @@ RUNNER_CHILD_TEST(libteec_04_invalid_context_name)
         TEEC_Result res = TEEC_InitializeContext("Invalid context name", &context);
         contextPtr.reset(&context);
 
-        TEEC_Result desiredResult = isTeeEnabled ? TEEC_ERROR_ITEM_NOT_FOUND : TEEC_ERROR_NOT_SUPPORTED;
+        TEEC_Result desiredResult = isTeeEnabled ? TEEC_ERROR_ITEM_NOT_FOUND : TEEC_ERROR_NOT_IMPLEMENTED;
         RUNNER_ASSERT_MSG(res == desiredResult,
             "Initializing context returned wrong error code: " << errToString(res)
             << ", expected: " << errToString(desiredResult));