regression: don't use files in plugin tests
QEMU, xtest run while logged in as user test:
o regression_1033.2 Pass array to a plugin
regression_1000.c:2420: fp has an unexpected value: (nil), expected not NULL
regression_1033.2 FAILED
The same test passes when logged in as root. The problem is, xtest tries to open,
read and delete a file created by tee-supplicant and permissions do not allow this.
Now request/response is used to test the ability to pass arrays to a plugin.
This approach is simpler and more robust.
Signed-off-by: Aleksandr Anisimov <a.anisimov@omprussia.ru>
Reviewed-by: Jerome Forissier <jerome@forissier.org>
diff --git a/host/supp_plugin/test_supp_plugin.c b/host/supp_plugin/test_supp_plugin.c
index 6b90b17..56e79b1 100644
--- a/host/supp_plugin/test_supp_plugin.c
+++ b/host/supp_plugin/test_supp_plugin.c
@@ -32,32 +32,20 @@
return TEEC_SUCCESS;
}
-static TEEC_Result write_test_arr(unsigned int sub_cmd, void *data,
+static TEEC_Result proc_input_arr(unsigned int sub_cmd, void *data,
size_t data_len, size_t *out_len)
{
(void)sub_cmd;
- (void)out_len;
- int fd = -1;
- int n = -1;
- char template[] = "/tmp/testplugin-XXXXXX";
- char fname[PATH_MAX] = { 0 };
+ size_t i = 0;
+ uint8_t sum = 0;
+ uint8_t *d = data;
- strcpy(fname, template);
+ for (; i < data_len; ++i)
+ sum += d[i];
- fd = mkstemp(fname);
- if (fd < 0)
- return TEEC_ERROR_GENERIC;
-
- n = write(fd, (const void *)data, data_len);
- if (n < 0) {
- close(fd);
- return TEEC_ERROR_GENERIC;
- }
-
- *out_len = sizeof(template);
- memcpy(data, (const void *)fname, *out_len);
- close(fd);
+ d[0] = sum;
+ *out_len = sizeof(sum);
return TEEC_SUCCESS;
}
@@ -88,7 +76,7 @@
case TEST_PLUGIN_CMD_PASS_VALUES:
return pass_values(sub_cmd, data, data_len, out_len);
case TEST_PLUGIN_CMD_WRITE_ARR:
- return write_test_arr(sub_cmd, data, data_len, out_len);
+ return proc_input_arr(sub_cmd, data, data_len, out_len);
case TEST_PLUGIN_CMD_GET_ARR:
return get_test_arr(sub_cmd, data, data_len, out_len);
default:
diff --git a/host/xtest/regression_1000.c b/host/xtest/regression_1000.c
index 46b341f..abaf1dd 100644
--- a/host/xtest/regression_1000.c
+++ b/host/xtest/regression_1000.c
@@ -2354,7 +2354,6 @@
{
TEEC_Session session = { };
uint32_t ret_orig = 0;
- size_t count = 0;
/* TA will ping the test plugin during open session operation */
if (!ADBG_EXPECT_TEEC_SUCCESS(c,
@@ -2394,17 +2393,12 @@
Do_ADBG_BeginSubCase(c, "Pass array to a plugin");
{
TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
- char to_plugin[] = "Plugin must write this array to the test file";
- char from_file[sizeof(to_plugin)] = { };
- char test_fname[PATH_MAX] = { };
- FILE *fp = NULL;
+ uint8_t to_plugin[] = { 0, 1, 2, 3, 4, 5 };
op.params[0].tmpref.buffer = to_plugin;
op.params[0].tmpref.size = sizeof(to_plugin);
- op.params[1].tmpref.buffer = test_fname;
- op.params[1].tmpref.size = PATH_MAX;
op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT,
- TEEC_MEMREF_TEMP_OUTPUT,
+ TEEC_VALUE_OUTPUT,
TEEC_NONE, TEEC_NONE);
ADBG_EXPECT_TEEC_SUCCESS(c,
@@ -2413,18 +2407,10 @@
&op, &ret_orig));
/*
- * Test file is generated by the plugin with the help of
- * mkstemp(). Check the file content here.
+ * The test plugin must calculate a sum of the input elements
+ * and store it to 'op.params[1].value.a'
*/
- fp = fopen(test_fname, "r");
- ADBG_EXPECT_NOT_NULL(c, fp);
- if (fp) {
- count = fread(from_file, sizeof(char), sizeof(to_plugin), fp);
- ADBG_EXPECT_COMPARE_UNSIGNED(c, count, ==, sizeof(to_plugin));
- ADBG_EXPECT_EQUAL(c, to_plugin, from_file, sizeof(to_plugin));
- fclose(fp);
- remove(test_fname);
- }
+ ADBG_EXPECT(c, 15, op.params[1].value.a);
}
Do_ADBG_EndSubCase(c, "Pass array to a plugin");