James Kung | 35b352d | 2015-09-07 18:01:16 +0800 | [diff] [blame] | 1 | /* |
| 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 Kung | df1e6cf | 2015-09-14 22:42:24 +0800 | [diff] [blame] | 15 | #include <stdlib.h> |
James Kung | 35b352d | 2015-09-07 18:01:16 +0800 | [diff] [blame] | 16 | #include <string.h> |
| 17 | |
| 18 | #include "xtest_test.h" |
| 19 | #include "xtest_helpers.h" |
| 20 | |
James Kung | df1e6cf | 2015-09-14 22:42:24 +0800 | [diff] [blame] | 21 | #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 | |
| 29 | size_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 Kung | 35b352d | 2015-09-07 18:01:16 +0800 | [diff] [blame] | 40 | |
| 41 | static void xtest_tee_benchmark_1001(ADBG_Case_t *Case_p); |
| 42 | static void xtest_tee_benchmark_1002(ADBG_Case_t *Case_p); |
| 43 | static void xtest_tee_benchmark_1003(ADBG_Case_t *Case_p); |
James Kung | 35b352d | 2015-09-07 18:01:16 +0800 | [diff] [blame] | 44 | |
James Kung | df1e6cf | 2015-09-14 22:42:24 +0800 | [diff] [blame] | 45 | static 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 Kung | 35b352d | 2015-09-07 18:01:16 +0800 | [diff] [blame] | 48 | { |
| 49 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 50 | TEEC_Result res; |
| 51 | TEEC_Session sess; |
| 52 | uint32_t orig; |
| 53 | |
James Kung | df1e6cf | 2015-09-14 22:42:24 +0800 | [diff] [blame] | 54 | res = xtest_teec_open_session(&sess, &storage_benchmark_ta_uuid, NULL, &orig); |
James Kung | 35b352d | 2015-09-07 18:01:16 +0800 | [diff] [blame] | 55 | if (res != TEEC_SUCCESS) |
| 56 | return res; |
| 57 | |
James Kung | df1e6cf | 2015-09-14 22:42:24 +0800 | [diff] [blame] | 58 | 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 Kung | 35b352d | 2015-09-07 18:01:16 +0800 | [diff] [blame] | 66 | res = TEEC_InvokeCommand(&sess, cmd, &op, &orig); |
| 67 | |
James Kung | df1e6cf | 2015-09-14 22:42:24 +0800 | [diff] [blame] | 68 | if (out0) |
| 69 | *out0 = op.params[2].value.a; |
| 70 | if (out1) |
| 71 | *out1 = op.params[2].value.b; |
| 72 | |
James Kung | 35b352d | 2015-09-07 18:01:16 +0800 | [diff] [blame] | 73 | TEEC_CloseSession(&sess); |
| 74 | |
| 75 | return res; |
| 76 | } |
| 77 | |
James Kung | df1e6cf | 2015-09-14 22:42:24 +0800 | [diff] [blame] | 78 | struct test_record { |
| 79 | size_t data_size; |
| 80 | float spent_time; |
| 81 | float speed_in_kb; |
| 82 | }; |
| 83 | |
| 84 | static 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 | { |
| 87 | TEE_Result res; |
Zoltan Kuscsik | 761ac35 | 2016-05-20 13:59:31 +0200 | [diff] [blame] | 88 | uint32_t spent_time = 0; |
James Kung | df1e6cf | 2015-09-14 22:42:24 +0800 | [diff] [blame] | 89 | |
| 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 | |
| 100 | static void show_test_result(struct test_record records[], size_t size) |
| 101 | { |
André Draszik | 3733864 | 2019-02-07 01:31:27 +0000 | [diff] [blame] | 102 | size_t i; |
James Kung | df1e6cf | 2015-09-14 22:42:24 +0800 | [diff] [blame] | 103 | |
| 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 | |
| 118 | static 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]; |
André Draszik | 3733864 | 2019-02-07 01:31:27 +0000 | [diff] [blame] | 122 | size_t i; |
James Kung | df1e6cf | 2015-09-14 22:42:24 +0800 | [diff] [blame] | 123 | |
| 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 Kung | 35b352d | 2015-09-07 18:01:16 +0800 | [diff] [blame] | 133 | static void xtest_tee_benchmark_1001(ADBG_Case_t *c) |
| 134 | { |
James Kung | df1e6cf | 2015-09-14 22:42:24 +0800 | [diff] [blame] | 135 | chunk_test(c, TA_STORAGE_BENCHMARK_CMD_TEST_WRITE); |
James Kung | 35b352d | 2015-09-07 18:01:16 +0800 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | static void xtest_tee_benchmark_1002(ADBG_Case_t *c) |
| 139 | { |
James Kung | df1e6cf | 2015-09-14 22:42:24 +0800 | [diff] [blame] | 140 | chunk_test(c, TA_STORAGE_BENCHMARK_CMD_TEST_READ); |
James Kung | 35b352d | 2015-09-07 18:01:16 +0800 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | static void xtest_tee_benchmark_1003(ADBG_Case_t *c) |
| 144 | { |
James Kung | df1e6cf | 2015-09-14 22:42:24 +0800 | [diff] [blame] | 145 | chunk_test(c, TA_STORAGE_BENCHMARK_CMD_TEST_REWRITE); |
James Kung | 35b352d | 2015-09-07 18:01:16 +0800 | [diff] [blame] | 146 | } |
| 147 | |
Jens Wiklander | 74abfe3 | 2017-01-03 14:17:47 +0100 | [diff] [blame] | 148 | ADBG_CASE_DEFINE(benchmark, 1001, xtest_tee_benchmark_1001, |
Jens Wiklander | 25a57fe | 2016-12-26 21:46:24 +0100 | [diff] [blame] | 149 | "TEE Trusted Storage Performance Test (WRITE)"); |
Jens Wiklander | 74abfe3 | 2017-01-03 14:17:47 +0100 | [diff] [blame] | 150 | ADBG_CASE_DEFINE(benchmark, 1002, xtest_tee_benchmark_1002, |
Jens Wiklander | 25a57fe | 2016-12-26 21:46:24 +0100 | [diff] [blame] | 151 | "TEE Trusted Storage Performance Test (READ)"); |
Jens Wiklander | 74abfe3 | 2017-01-03 14:17:47 +0100 | [diff] [blame] | 152 | ADBG_CASE_DEFINE(benchmark, 1003, xtest_tee_benchmark_1003, |
Jens Wiklander | 25a57fe | 2016-12-26 21:46:24 +0100 | [diff] [blame] | 153 | "TEE Trusted Storage Performance Test (REWRITE)"); |