From 1e1d39f11db7036bc2df93f8e07e105414181f6f Mon Sep 17 00:00:00 2001 From: Jens Wiklander Date: Tue, 28 Nov 2023 20:49:11 +0100 Subject: [PATCH] xtest: regression: add case 6021 object usage Adds case 6021 to test modifying and checking object usage of a persistent object. Link: https://github.com/OP-TEE/optee_os/issues/6495 Signed-off-by: Jens Wiklander --- host/xtest/regression_6000.c | 59 ++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/host/xtest/regression_6000.c b/host/xtest/regression_6000.c index e8c5dcb97..28b8f50b1 100644 --- a/host/xtest/regression_6000.c +++ b/host/xtest/regression_6000.c @@ -2254,3 +2254,62 @@ static void xtest_tee_test_6020_single(ADBG_Case_t *c, uint32_t storage_id) DEFINE_TEST_MULTIPLE_STORAGE_IDS(xtest_tee_test_6020) ADBG_CASE_DEFINE(regression, 6020, xtest_tee_test_6020, "Object IDs in SHM (negative)"); + +static void xtest_tee_test_6021_single(ADBG_Case_t *c, uint32_t storage_id) +{ + const uint32_t flags = TEE_DATA_FLAG_ACCESS_READ | + TEE_DATA_FLAG_ACCESS_WRITE | + TEE_DATA_FLAG_ACCESS_WRITE_META; + TEEC_Result res = TEEC_ERROR_GENERIC; + TEE_ObjectInfo obj_info = { }; + TEEC_Session sess = { }; + uint32_t orig = 0; + uint32_t obj = 0; + + res = xtest_teec_open_session(&sess, &storage_ta_uuid, NULL, &orig); + if (!ADBG_EXPECT_TEEC_SUCCESS(c, res)) + return; + + res = fs_create(&sess, file_01, sizeof(file_01), flags, 0, + data_00, sizeof(data_00), &obj, storage_id); + if (!ADBG_EXPECT_TEEC_SUCCESS(c, res)) + goto exit; + + res = fs_get_obj_info(&sess, obj, &obj_info); + if (!ADBG_EXPECT_TEEC_SUCCESS(c, res)) + goto exit; + ADBG_EXPECT_COMPARE_UNSIGNED(c, obj_info.objectUsage, ==, 0xffffffff); + + res = fs_restrict_usage(&sess, obj, 0xfffffffe); + if (!ADBG_EXPECT_TEEC_SUCCESS(c, res)) + goto exit; + + res = fs_get_obj_info(&sess, obj, &obj_info); + if (!ADBG_EXPECT_TEEC_SUCCESS(c, res)) + goto exit; + ADBG_EXPECT_COMPARE_UNSIGNED(c, obj_info.objectUsage, ==, 0xfffffffe); + + ADBG_EXPECT_TEEC_SUCCESS(c, fs_close(&sess, obj)); + TEEC_CloseSession(&sess); + + res = xtest_teec_open_session(&sess, &storage_ta_uuid, NULL, &orig); + if (!ADBG_EXPECT_TEEC_SUCCESS(c, res)) + return; + + res = fs_open(&sess, file_01, sizeof(file_01), flags, &obj, storage_id); + if (!ADBG_EXPECT_TEEC_SUCCESS(c, res)) + goto exit; + + res = fs_get_obj_info(&sess, obj, &obj_info); + if (!ADBG_EXPECT_TEEC_SUCCESS(c, res)) + goto exit; + ADBG_EXPECT_COMPARE_UNSIGNED(c, obj_info.objectUsage, ==, 0xfffffffe); + +exit: + ADBG_EXPECT_TEEC_SUCCESS(c, fs_unlink(&sess, obj)); + TEEC_CloseSession(&sess); + return; +} +DEFINE_TEST_MULTIPLE_STORAGE_IDS(xtest_tee_test_6021) +ADBG_CASE_DEFINE(regression, 6021, xtest_tee_test_6021, + "Modify and check object usage");