blob: 06c9a1c0974e685c235feaa73c8d5903f7043965 [file] [log] [blame]
James Kung35b352d2015-09-07 18:01:16 +08001/*
2 * Copyright (c) 2015, Linaro Limited
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License Version 2 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 */
13
14#include <stdio.h>
James Kungdf1e6cf2015-09-14 22:42:24 +080015#include <stdlib.h>
James Kung35b352d2015-09-07 18:01:16 +080016#include <string.h>
17
18#include "xtest_test.h"
19#include "xtest_helpers.h"
20
James Kungdf1e6cf2015-09-14 22:42:24 +080021#include <ta_storage_benchmark.h>
22#include <util.h>
23
24#define DO_VERIFY 0
25#define DEFAULT_DATA_SIZE (2 * 1024 * 1024) /* 2MB */
26#define DEFAULT_CHUNK_SIZE (1 * 1024) /* 1KB */
27#define DEFAULT_COUNT (10)
28
29size_t data_size_table[] = {
30 256,
31 512,
32 1024,
33 2 * 1024,
34 4 * 1024,
35 16 * 1024,
36 512 * 1024,
37 1024 * 1024,
38 0
39};
James Kung35b352d2015-09-07 18:01:16 +080040
41static void xtest_tee_benchmark_1001(ADBG_Case_t *Case_p);
42static void xtest_tee_benchmark_1002(ADBG_Case_t *Case_p);
43static void xtest_tee_benchmark_1003(ADBG_Case_t *Case_p);
James Kung35b352d2015-09-07 18:01:16 +080044
James Kungdf1e6cf2015-09-14 22:42:24 +080045static TEEC_Result run_test_with_args(enum storage_benchmark_cmd cmd,
46 uint32_t arg0, uint32_t arg1, uint32_t arg2,
47 uint32_t arg3, uint32_t *out0, uint32_t *out1)
James Kung35b352d2015-09-07 18:01:16 +080048{
49 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
Etienne Carrieree4ec9e42019-03-28 13:30:21 +010050 TEEC_Result res = TEEC_ERROR_GENERIC;
51 TEEC_Session sess = { };
52 uint32_t orig = 0;
James Kung35b352d2015-09-07 18:01:16 +080053
James Kungdf1e6cf2015-09-14 22:42:24 +080054 res = xtest_teec_open_session(&sess, &storage_benchmark_ta_uuid, NULL, &orig);
James Kung35b352d2015-09-07 18:01:16 +080055 if (res != TEEC_SUCCESS)
56 return res;
57
James Kungdf1e6cf2015-09-14 22:42:24 +080058 op.params[0].value.a = arg0;
59 op.params[0].value.b = arg1;
60 op.params[1].value.a = arg2;
61 op.params[1].value.b = arg3;
62
63 op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT,
64 TEEC_VALUE_INPUT, TEEC_VALUE_OUTPUT, TEEC_NONE);
65
James Kung35b352d2015-09-07 18:01:16 +080066 res = TEEC_InvokeCommand(&sess, cmd, &op, &orig);
67
James Kungdf1e6cf2015-09-14 22:42:24 +080068 if (out0)
69 *out0 = op.params[2].value.a;
70 if (out1)
71 *out1 = op.params[2].value.b;
72
James Kung35b352d2015-09-07 18:01:16 +080073 TEEC_CloseSession(&sess);
74
75 return res;
76}
77
James Kungdf1e6cf2015-09-14 22:42:24 +080078struct test_record {
79 size_t data_size;
80 float spent_time;
81 float speed_in_kb;
82};
83
84static TEEC_Result run_chunk_access_test(enum storage_benchmark_cmd cmd,
85 uint32_t data_size, uint32_t chunk_size, struct test_record *rec)
86{
Etienne Carrieree4ec9e42019-03-28 13:30:21 +010087 TEE_Result res = TEEC_ERROR_GENERIC;
Zoltan Kuscsik761ac352016-05-20 13:59:31 +020088 uint32_t spent_time = 0;
James Kungdf1e6cf2015-09-14 22:42:24 +080089
90 res = run_test_with_args(cmd, data_size, chunk_size, DO_VERIFY, 0,
91 &spent_time, NULL);
92
93 rec->data_size = data_size;
94 rec->spent_time = (float)spent_time / 1000.0;
95 rec->speed_in_kb = ((float)data_size / 1024.0) / rec->spent_time;
96
97 return res;
98}
99
100static void show_test_result(struct test_record records[], size_t size)
101{
Etienne Carrieree4ec9e42019-03-28 13:30:21 +0100102 size_t i = 0;
James Kungdf1e6cf2015-09-14 22:42:24 +0800103
104 printf("-----------------+---------------+----------------\n");
105 printf(" Data Size (B) \t | Time (s)\t | Speed (kB/s)\t \n");
106 printf("-----------------+---------------+----------------\n");
107
108 for (i = 0; i < size; i++) {
109 printf(" %8zd \t | %8.3f \t | %8.3f\n",
110 records[i].data_size, records[i].spent_time,
111 records[i].speed_in_kb);
112 }
113
114 printf("-----------------+---------------+----------------\n");
115
116}
117
118static void chunk_test(ADBG_Case_t *c, enum storage_benchmark_cmd cmd)
119{
120 uint32_t chunk_size = DEFAULT_CHUNK_SIZE;
121 struct test_record records[ARRAY_SIZE(data_size_table) - 1];
Etienne Carrieree4ec9e42019-03-28 13:30:21 +0100122 size_t i = 0;
James Kungdf1e6cf2015-09-14 22:42:24 +0800123
124 for (i = 0; data_size_table[i]; i++) {
125 ADBG_EXPECT_TEEC_SUCCESS(c,
126 run_chunk_access_test(cmd, data_size_table[i],
127 chunk_size, &records[i]));
128 }
129
130 show_test_result(records, ARRAY_SIZE(records));
131}
132
James Kung35b352d2015-09-07 18:01:16 +0800133static void xtest_tee_benchmark_1001(ADBG_Case_t *c)
134{
James Kungdf1e6cf2015-09-14 22:42:24 +0800135 chunk_test(c, TA_STORAGE_BENCHMARK_CMD_TEST_WRITE);
James Kung35b352d2015-09-07 18:01:16 +0800136}
137
138static void xtest_tee_benchmark_1002(ADBG_Case_t *c)
139{
James Kungdf1e6cf2015-09-14 22:42:24 +0800140 chunk_test(c, TA_STORAGE_BENCHMARK_CMD_TEST_READ);
James Kung35b352d2015-09-07 18:01:16 +0800141}
142
143static void xtest_tee_benchmark_1003(ADBG_Case_t *c)
144{
James Kungdf1e6cf2015-09-14 22:42:24 +0800145 chunk_test(c, TA_STORAGE_BENCHMARK_CMD_TEST_REWRITE);
James Kung35b352d2015-09-07 18:01:16 +0800146}
147
Jens Wiklander74abfe32017-01-03 14:17:47 +0100148ADBG_CASE_DEFINE(benchmark, 1001, xtest_tee_benchmark_1001,
Jens Wiklander25a57fe2016-12-26 21:46:24 +0100149 "TEE Trusted Storage Performance Test (WRITE)");
Jens Wiklander74abfe32017-01-03 14:17:47 +0100150ADBG_CASE_DEFINE(benchmark, 1002, xtest_tee_benchmark_1002,
Jens Wiklander25a57fe2016-12-26 21:46:24 +0100151 "TEE Trusted Storage Performance Test (READ)");
Jens Wiklander74abfe32017-01-03 14:17:47 +0100152ADBG_CASE_DEFINE(benchmark, 1003, xtest_tee_benchmark_1003,
Jens Wiklander25a57fe2016-12-26 21:46:24 +0100153 "TEE Trusted Storage Performance Test (REWRITE)");