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: