Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2014, STMicroelectronics International N.V. |
| 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 <string.h> |
| 15 | #include <stdio.h> |
Lijianhui (Airbak) | 29d7c7a | 2016-08-24 17:35:55 +0800 | [diff] [blame] | 16 | #include <pthread.h> |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 17 | |
| 18 | #include <adbg.h> |
| 19 | #include <xtest_test.h> |
| 20 | #include <xtest_helpers.h> |
| 21 | |
| 22 | #include <tee_client_api.h> |
| 23 | #include <ta_storage.h> |
| 24 | #include <tee_api_defines.h> |
Jerome Forissier | 0e99d6a | 2016-07-25 14:21:43 +0200 | [diff] [blame] | 25 | #include <tee_api_defines_extensions.h> |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 26 | #include <tee_api_types.h> |
Jerome Forissier | e368834 | 2015-09-24 10:45:17 -0700 | [diff] [blame] | 27 | #ifdef WITH_GP_TESTS |
Pascal Brand | 8a74e36 | 2015-09-10 12:41:52 +0200 | [diff] [blame] | 28 | #include <TTA_DS_protocol.h> |
| 29 | #endif |
Jerome Forissier | 0e99d6a | 2016-07-25 14:21:43 +0200 | [diff] [blame] | 30 | #include <util.h> |
| 31 | |
| 32 | static uint32_t storage_ids[] = { |
| 33 | TEE_STORAGE_PRIVATE, |
| 34 | #ifdef CFG_REE_FS |
| 35 | TEE_STORAGE_PRIVATE_REE, |
| 36 | #endif |
| 37 | #ifdef CFG_RPMB_FS |
| 38 | TEE_STORAGE_PRIVATE_RPMB, |
| 39 | #endif |
Jerome Forissier | a966bb4 | 2016-08-16 16:41:47 +0200 | [diff] [blame] | 40 | #ifdef CFG_SQL_FS |
| 41 | TEE_STORAGE_PRIVATE_SQL, |
| 42 | #endif |
Jerome Forissier | 0e99d6a | 2016-07-25 14:21:43 +0200 | [diff] [blame] | 43 | }; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 44 | |
| 45 | static uint8_t file_00[] = { |
| 46 | 0x00, 0x6E, 0x04, 0x57, 0x08, 0xFB, 0x71, 0x96, |
| 47 | 0xF0, 0x2E, 0x55, 0x3D, 0x02, 0xC3, 0xA6, 0x92, |
| 48 | 0xE9, 0xC3, 0xEF, 0x8A, 0xB2, 0x34, 0x53, 0xE6, |
| 49 | 0xF0, 0x74, 0x9C, 0xD6, 0x36, 0xE7, 0xA8, 0x8E |
| 50 | }; |
| 51 | |
| 52 | static uint8_t file_01[] = { |
| 53 | 0x01, 0x00 |
| 54 | }; |
| 55 | |
| 56 | static uint8_t file_02[] = { |
| 57 | 0x02, 0x11, 0x02 |
| 58 | }; |
| 59 | |
| 60 | static uint8_t file_03[] = { |
| 61 | 0x03, 0x13, 0x03 |
| 62 | }; |
| 63 | |
Pascal Brand | eb84c44 | 2016-04-19 17:49:49 +0200 | [diff] [blame] | 64 | static uint8_t file_04[] = { |
| 65 | 0x00, 0x01, 0x02 |
| 66 | }; |
| 67 | |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 68 | static uint8_t data_00[] = { |
| 69 | 0x00, 0x6E, 0x04, 0x57, 0x08, 0xFB, 0x71, 0x96, |
| 70 | 0x00, 0x2E, 0x55, 0x3D, 0x02, 0xC3, 0xA6, 0x92, |
| 71 | 0x00, 0xC3, 0xEF, 0x8A, 0xB2, 0x34, 0x53, 0xE6, |
| 72 | 0x00, 0x74, 0x9C, 0xD6, 0x36, 0xE7, 0xA8, 0x00 |
| 73 | }; |
| 74 | |
| 75 | static uint8_t data_01[] = { |
| 76 | 0x01, 0x6E, 0x04, 0x57, 0x08, 0xFB, 0x71, 0x96, |
| 77 | 0x01, 0x2E, 0x55, 0x3D, 0x02, 0xC3, 0xA6, 0x92, |
| 78 | 0x01, 0xC3, 0xEF, 0x8A, 0xB2, 0x34, 0x53, 0xE6, |
| 79 | 0x01, 0x74, 0x9C, 0xD6, 0x36, 0xE7, 0xA8, 0x01 |
| 80 | }; |
| 81 | |
| 82 | static TEEC_Result fs_open(TEEC_Session *sess, void *id, uint32_t id_size, |
Jerome Forissier | 0e99d6a | 2016-07-25 14:21:43 +0200 | [diff] [blame] | 83 | uint32_t flags, uint32_t *obj, uint32_t storage_id) |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 84 | { |
Aijun Sun | 473d907 | 2015-08-06 15:24:49 +0800 | [diff] [blame] | 85 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 86 | TEEC_Result res; |
| 87 | uint32_t org; |
| 88 | |
| 89 | op.params[0].tmpref.buffer = id; |
| 90 | op.params[0].tmpref.size = id_size; |
| 91 | op.params[1].value.a = flags; |
| 92 | op.params[1].value.b = 0; |
Jerome Forissier | 0e99d6a | 2016-07-25 14:21:43 +0200 | [diff] [blame] | 93 | op.params[2].value.a = storage_id; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 94 | |
| 95 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT, |
Jerome Forissier | 0e99d6a | 2016-07-25 14:21:43 +0200 | [diff] [blame] | 96 | TEEC_VALUE_INOUT, TEEC_VALUE_INPUT, |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 97 | TEEC_NONE); |
| 98 | |
| 99 | res = TEEC_InvokeCommand(sess, TA_STORAGE_CMD_OPEN, &op, &org); |
| 100 | |
| 101 | if (res == TEEC_SUCCESS) |
| 102 | *obj = op.params[1].value.b; |
| 103 | |
| 104 | return res; |
| 105 | } |
| 106 | |
| 107 | static TEEC_Result fs_create(TEEC_Session *sess, void *id, uint32_t id_size, |
| 108 | uint32_t flags, uint32_t attr, void *data, |
Jerome Forissier | 0e99d6a | 2016-07-25 14:21:43 +0200 | [diff] [blame] | 109 | uint32_t data_size, uint32_t *obj, |
| 110 | uint32_t storage_id) |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 111 | { |
Aijun Sun | 473d907 | 2015-08-06 15:24:49 +0800 | [diff] [blame] | 112 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 113 | TEEC_Result res; |
| 114 | uint32_t org; |
| 115 | |
| 116 | op.params[0].tmpref.buffer = id; |
| 117 | op.params[0].tmpref.size = id_size; |
| 118 | op.params[1].value.a = flags; |
| 119 | op.params[1].value.b = 0; |
| 120 | op.params[2].value.a = attr; |
Jerome Forissier | 0e99d6a | 2016-07-25 14:21:43 +0200 | [diff] [blame] | 121 | op.params[2].value.b = storage_id; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 122 | op.params[3].tmpref.buffer = data; |
| 123 | op.params[3].tmpref.size = data_size; |
| 124 | |
| 125 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT, |
| 126 | TEEC_VALUE_INOUT, TEEC_VALUE_INPUT, |
| 127 | TEEC_MEMREF_TEMP_INPUT); |
| 128 | |
| 129 | res = TEEC_InvokeCommand(sess, TA_STORAGE_CMD_CREATE, &op, &org); |
| 130 | |
| 131 | if (res == TEEC_SUCCESS) |
| 132 | *obj = op.params[1].value.b; |
| 133 | |
| 134 | return res; |
| 135 | } |
| 136 | |
Pascal Brand | eb84c44 | 2016-04-19 17:49:49 +0200 | [diff] [blame] | 137 | static TEEC_Result fs_create_overwrite(TEEC_Session *sess, void *id, |
Jerome Forissier | 0e99d6a | 2016-07-25 14:21:43 +0200 | [diff] [blame] | 138 | uint32_t id_size, uint32_t storage_id) |
Pascal Brand | eb84c44 | 2016-04-19 17:49:49 +0200 | [diff] [blame] | 139 | { |
| 140 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 141 | TEEC_Result res; |
| 142 | uint32_t org; |
| 143 | |
| 144 | op.params[0].tmpref.buffer = id; |
| 145 | op.params[0].tmpref.size = id_size; |
Jerome Forissier | 0e99d6a | 2016-07-25 14:21:43 +0200 | [diff] [blame] | 146 | op.params[1].value.a = storage_id; |
Pascal Brand | eb84c44 | 2016-04-19 17:49:49 +0200 | [diff] [blame] | 147 | |
| 148 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT, |
Jerome Forissier | 0e99d6a | 2016-07-25 14:21:43 +0200 | [diff] [blame] | 149 | TEEC_VALUE_INPUT, TEEC_NONE, |
Pascal Brand | eb84c44 | 2016-04-19 17:49:49 +0200 | [diff] [blame] | 150 | TEEC_NONE); |
| 151 | |
| 152 | res = TEEC_InvokeCommand(sess, TA_STORAGE_CMD_CREATE_OVERWRITE, &op, &org); |
| 153 | |
| 154 | return res; |
| 155 | } |
| 156 | |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 157 | static TEEC_Result fs_close(TEEC_Session *sess, uint32_t obj) |
| 158 | { |
Aijun Sun | 473d907 | 2015-08-06 15:24:49 +0800 | [diff] [blame] | 159 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 160 | uint32_t org; |
| 161 | |
| 162 | op.params[0].value.a = obj; |
| 163 | |
| 164 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, TEEC_NONE, |
| 165 | TEEC_NONE, TEEC_NONE); |
| 166 | |
| 167 | return TEEC_InvokeCommand(sess, TA_STORAGE_CMD_CLOSE, &op, &org); |
| 168 | } |
| 169 | |
| 170 | static TEEC_Result fs_read(TEEC_Session *sess, uint32_t obj, void *data, |
| 171 | uint32_t data_size, uint32_t *count) |
| 172 | { |
| 173 | TEEC_Result res; |
Aijun Sun | 473d907 | 2015-08-06 15:24:49 +0800 | [diff] [blame] | 174 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 175 | uint32_t org; |
| 176 | |
| 177 | op.params[0].tmpref.buffer = data; |
| 178 | op.params[0].tmpref.size = data_size; |
| 179 | op.params[1].value.a = obj; |
| 180 | op.params[1].value.b = 0; |
| 181 | |
| 182 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_OUTPUT, |
| 183 | TEEC_VALUE_INOUT, TEEC_NONE, |
| 184 | TEEC_NONE); |
| 185 | |
| 186 | res = TEEC_InvokeCommand(sess, TA_STORAGE_CMD_READ, &op, &org); |
| 187 | |
| 188 | if (res == TEEC_SUCCESS) |
| 189 | *count = op.params[1].value.b; |
| 190 | |
| 191 | return res; |
| 192 | } |
| 193 | |
| 194 | static TEEC_Result fs_write(TEEC_Session *sess, uint32_t obj, void *data, |
| 195 | uint32_t data_size) |
| 196 | { |
Aijun Sun | 473d907 | 2015-08-06 15:24:49 +0800 | [diff] [blame] | 197 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 198 | uint32_t org; |
| 199 | |
| 200 | op.params[0].tmpref.buffer = data; |
| 201 | op.params[0].tmpref.size = data_size; |
| 202 | op.params[1].value.a = obj; |
| 203 | op.params[1].value.b = 0; |
| 204 | |
| 205 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT, |
| 206 | TEEC_VALUE_INPUT, TEEC_NONE, |
| 207 | TEEC_NONE); |
| 208 | |
| 209 | return TEEC_InvokeCommand(sess, TA_STORAGE_CMD_WRITE, &op, &org); |
| 210 | } |
| 211 | |
| 212 | static TEEC_Result fs_seek(TEEC_Session *sess, uint32_t obj, int32_t offset, |
| 213 | int32_t whence) |
| 214 | { |
Aijun Sun | 473d907 | 2015-08-06 15:24:49 +0800 | [diff] [blame] | 215 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 216 | uint32_t org; |
| 217 | |
| 218 | op.params[0].value.a = obj; |
| 219 | op.params[0].value.b = offset; |
| 220 | op.params[1].value.a = whence; |
| 221 | |
| 222 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, TEEC_VALUE_INOUT, |
| 223 | TEEC_NONE, TEEC_NONE); |
| 224 | |
| 225 | return TEEC_InvokeCommand(sess, TA_STORAGE_CMD_SEEK, &op, &org); |
| 226 | } |
| 227 | |
| 228 | static TEEC_Result fs_unlink(TEEC_Session *sess, uint32_t obj) |
| 229 | { |
Aijun Sun | 473d907 | 2015-08-06 15:24:49 +0800 | [diff] [blame] | 230 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 231 | uint32_t org; |
| 232 | |
| 233 | op.params[0].value.a = obj; |
| 234 | |
| 235 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, TEEC_NONE, |
| 236 | TEEC_NONE, TEEC_NONE); |
| 237 | |
| 238 | return TEEC_InvokeCommand(sess, TA_STORAGE_CMD_UNLINK, &op, &org); |
| 239 | } |
| 240 | |
| 241 | static TEEC_Result fs_trunc(TEEC_Session *sess, uint32_t obj, uint32_t len) |
| 242 | { |
Aijun Sun | 473d907 | 2015-08-06 15:24:49 +0800 | [diff] [blame] | 243 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 244 | uint32_t org; |
| 245 | |
| 246 | op.params[0].value.a = obj; |
| 247 | op.params[0].value.b = len; |
| 248 | |
| 249 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, TEEC_NONE, |
| 250 | TEEC_NONE, TEEC_NONE); |
| 251 | |
| 252 | return TEEC_InvokeCommand(sess, TA_STORAGE_CMD_TRUNC, &op, &org); |
| 253 | } |
| 254 | |
| 255 | static TEEC_Result fs_rename(TEEC_Session *sess, uint32_t obj, void *id, |
| 256 | uint32_t id_size) |
| 257 | { |
Aijun Sun | 473d907 | 2015-08-06 15:24:49 +0800 | [diff] [blame] | 258 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 259 | uint32_t org; |
| 260 | |
| 261 | op.params[0].value.a = obj; |
| 262 | op.params[1].tmpref.buffer = id; |
| 263 | op.params[1].tmpref.size = id_size; |
| 264 | |
| 265 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, |
| 266 | TEEC_MEMREF_TEMP_INPUT, TEEC_NONE, |
| 267 | TEEC_NONE); |
| 268 | |
| 269 | return TEEC_InvokeCommand(sess, TA_STORAGE_CMD_RENAME, &op, &org); |
| 270 | } |
| 271 | |
| 272 | static TEEC_Result fs_alloc_enum(TEEC_Session *sess, uint32_t *e) |
| 273 | { |
| 274 | TEEC_Result res; |
Aijun Sun | 473d907 | 2015-08-06 15:24:49 +0800 | [diff] [blame] | 275 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 276 | uint32_t org; |
| 277 | |
| 278 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_OUTPUT, TEEC_NONE, |
| 279 | TEEC_NONE, TEEC_NONE); |
| 280 | |
| 281 | res = TEEC_InvokeCommand(sess, TA_STORAGE_CMD_ALLOC_ENUM, &op, &org); |
| 282 | |
| 283 | if (res == TEEC_SUCCESS) |
| 284 | *e = op.params[0].value.a; |
| 285 | |
| 286 | return res; |
| 287 | } |
| 288 | |
| 289 | static TEEC_Result fs_free_enum(TEEC_Session *sess, uint32_t e) |
| 290 | { |
Aijun Sun | 473d907 | 2015-08-06 15:24:49 +0800 | [diff] [blame] | 291 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 292 | uint32_t org; |
| 293 | |
| 294 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, TEEC_NONE, TEEC_NONE, |
| 295 | TEEC_NONE); |
| 296 | |
| 297 | op.params[0].value.a = e; |
| 298 | |
| 299 | return TEEC_InvokeCommand(sess, TA_STORAGE_CMD_FREE_ENUM, &op, &org); |
| 300 | } |
| 301 | |
Jerome Forissier | 0e99d6a | 2016-07-25 14:21:43 +0200 | [diff] [blame] | 302 | static TEEC_Result fs_start_enum(TEEC_Session *sess, uint32_t e, |
| 303 | uint32_t storage_id) |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 304 | { |
Aijun Sun | 473d907 | 2015-08-06 15:24:49 +0800 | [diff] [blame] | 305 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 306 | uint32_t org; |
| 307 | |
| 308 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, TEEC_NONE, |
| 309 | TEEC_NONE, TEEC_NONE); |
| 310 | |
| 311 | op.params[0].value.a = e; |
Jerome Forissier | 0e99d6a | 2016-07-25 14:21:43 +0200 | [diff] [blame] | 312 | op.params[0].value.b = storage_id; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 313 | |
| 314 | return TEEC_InvokeCommand(sess, TA_STORAGE_CMD_START_ENUM, &op, &org); |
| 315 | } |
| 316 | |
| 317 | static TEEC_Result fs_next_enum(TEEC_Session *sess, uint32_t e, void *obj_info, |
| 318 | size_t info_size, void *id, uint32_t id_size) |
| 319 | { |
Aijun Sun | 473d907 | 2015-08-06 15:24:49 +0800 | [diff] [blame] | 320 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 321 | uint32_t org; |
| 322 | |
Pascal Brand | c603e0d | 2016-04-25 12:37:18 +0200 | [diff] [blame] | 323 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, TEEC_NONE, |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 324 | TEEC_MEMREF_TEMP_OUTPUT, TEEC_NONE); |
Pascal Brand | c603e0d | 2016-04-25 12:37:18 +0200 | [diff] [blame] | 325 | if (obj_info && info_size) |
| 326 | op.paramTypes |= (TEEC_MEMREF_TEMP_OUTPUT << 4); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 327 | |
| 328 | op.params[0].value.a = e; |
| 329 | op.params[1].tmpref.buffer = obj_info; |
| 330 | op.params[1].tmpref.size = info_size; |
| 331 | op.params[2].tmpref.buffer = id; |
| 332 | op.params[2].tmpref.size = id_size; |
| 333 | |
| 334 | return TEEC_InvokeCommand(sess, TA_STORAGE_CMD_NEXT_ENUM, &op, &org); |
| 335 | } |
| 336 | |
James Kung | 98c0ba1 | 2015-09-09 15:51:59 +0800 | [diff] [blame] | 337 | /* trunc */ |
Jerome Forissier | 0e99d6a | 2016-07-25 14:21:43 +0200 | [diff] [blame] | 338 | static void test_truncate_file_length(ADBG_Case_t *c, uint32_t storage_id) |
James Kung | 98c0ba1 | 2015-09-09 15:51:59 +0800 | [diff] [blame] | 339 | { |
| 340 | TEEC_Session sess; |
| 341 | uint32_t obj; |
| 342 | uint8_t out[10] = { 0 }; |
| 343 | uint32_t count; |
| 344 | uint32_t orig; |
| 345 | |
| 346 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 347 | xtest_teec_open_session(&sess, &storage_ta_uuid, NULL, &orig))) |
| 348 | return; |
| 349 | |
| 350 | /* create */ |
| 351 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 352 | fs_create(&sess, file_01, sizeof(file_01), |
| 353 | TEE_DATA_FLAG_ACCESS_WRITE | |
| 354 | TEE_DATA_FLAG_ACCESS_READ | |
| 355 | TEE_DATA_FLAG_ACCESS_WRITE_META, 0, data_00, |
Jerome Forissier | 0e99d6a | 2016-07-25 14:21:43 +0200 | [diff] [blame] | 356 | sizeof(data_00), &obj, storage_id))) |
James Kung | 98c0ba1 | 2015-09-09 15:51:59 +0800 | [diff] [blame] | 357 | goto exit; |
| 358 | |
| 359 | /* trunc */ |
| 360 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_trunc(&sess, obj, 10))) |
| 361 | goto exit; |
| 362 | |
| 363 | /* seek */ |
| 364 | if (!ADBG_EXPECT_TEEC_SUCCESS( |
| 365 | c, fs_seek(&sess, obj, 5, TEE_DATA_SEEK_SET))) |
| 366 | goto exit; |
| 367 | |
| 368 | /* verify */ |
| 369 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_read(&sess, obj, out, 10, &count))) |
| 370 | goto exit; |
| 371 | |
| 372 | /* check buffer */ |
| 373 | (void)ADBG_EXPECT_BUFFER(c, &data_00[5], 5, out, count); |
| 374 | |
| 375 | /* clean */ |
| 376 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_unlink(&sess, obj))) |
| 377 | goto exit; |
| 378 | |
| 379 | exit: |
| 380 | TEEC_CloseSession(&sess); |
| 381 | } |
| 382 | |
| 383 | /* extend */ |
Jerome Forissier | 0e99d6a | 2016-07-25 14:21:43 +0200 | [diff] [blame] | 384 | static void test_extend_file_length(ADBG_Case_t *c, uint32_t storage_id) |
James Kung | 98c0ba1 | 2015-09-09 15:51:59 +0800 | [diff] [blame] | 385 | { |
| 386 | TEEC_Session sess; |
| 387 | uint32_t obj; |
| 388 | uint8_t out[10] = { 0 }; |
| 389 | uint8_t expect[10] = { 0 }; |
| 390 | uint32_t count; |
| 391 | uint32_t orig; |
| 392 | |
| 393 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 394 | xtest_teec_open_session(&sess, &storage_ta_uuid, NULL, &orig))) |
| 395 | return; |
| 396 | |
| 397 | /* create */ |
| 398 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 399 | fs_create(&sess, file_01, sizeof(file_01), |
| 400 | TEE_DATA_FLAG_ACCESS_WRITE | |
| 401 | TEE_DATA_FLAG_ACCESS_READ | |
| 402 | TEE_DATA_FLAG_ACCESS_WRITE_META, 0, data_00, |
Jerome Forissier | 0e99d6a | 2016-07-25 14:21:43 +0200 | [diff] [blame] | 403 | sizeof(data_00), &obj, storage_id))) |
James Kung | 98c0ba1 | 2015-09-09 15:51:59 +0800 | [diff] [blame] | 404 | goto exit; |
| 405 | |
| 406 | /* extend */ |
| 407 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_trunc(&sess, obj, 40))) |
| 408 | goto exit; |
| 409 | |
| 410 | /* seek */ |
| 411 | if (!ADBG_EXPECT_TEEC_SUCCESS( |
| 412 | c, fs_seek(&sess, obj, 30, TEE_DATA_SEEK_SET))) |
| 413 | goto exit; |
| 414 | |
| 415 | /* verify */ |
| 416 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_read(&sess, obj, out, 10, &count))) |
| 417 | goto exit; |
| 418 | |
| 419 | /* check buffer */ |
| 420 | expect[0] = data_00[30]; |
| 421 | expect[1] = data_00[31]; |
| 422 | (void)ADBG_EXPECT_BUFFER(c, &expect[0], 10, out, count); |
| 423 | |
| 424 | /* clean */ |
| 425 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_unlink(&sess, obj))) |
| 426 | goto exit; |
| 427 | |
| 428 | exit: |
| 429 | TEEC_CloseSession(&sess); |
| 430 | } |
| 431 | |
| 432 | /* file hole */ |
Jerome Forissier | 0e99d6a | 2016-07-25 14:21:43 +0200 | [diff] [blame] | 433 | static void test_file_hole(ADBG_Case_t *c, uint32_t storage_id) |
James Kung | 98c0ba1 | 2015-09-09 15:51:59 +0800 | [diff] [blame] | 434 | { |
| 435 | TEEC_Session sess; |
| 436 | uint32_t obj; |
| 437 | uint8_t out[10] = { 0 }; |
| 438 | uint8_t expect[10] = { 0 }; |
| 439 | uint32_t count; |
| 440 | uint32_t orig; |
| 441 | |
| 442 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 443 | xtest_teec_open_session(&sess, &storage_ta_uuid, NULL, &orig))) |
| 444 | return; |
| 445 | |
| 446 | /* create */ |
| 447 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 448 | fs_create(&sess, file_01, sizeof(file_01), |
| 449 | TEE_DATA_FLAG_ACCESS_WRITE | |
| 450 | TEE_DATA_FLAG_ACCESS_READ | |
| 451 | TEE_DATA_FLAG_ACCESS_WRITE_META, 0, data_00, |
Jerome Forissier | 0e99d6a | 2016-07-25 14:21:43 +0200 | [diff] [blame] | 452 | sizeof(data_00), &obj, storage_id))) |
James Kung | 98c0ba1 | 2015-09-09 15:51:59 +0800 | [diff] [blame] | 453 | goto exit; |
| 454 | |
| 455 | /* seek */ |
| 456 | if (!ADBG_EXPECT_TEEC_SUCCESS( |
| 457 | c, fs_seek(&sess, obj, 80, TEE_DATA_SEEK_SET))) |
| 458 | goto exit; |
| 459 | |
| 460 | /* write */ |
| 461 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_write(&sess, obj, data_00, |
| 462 | sizeof(data_00)))) |
| 463 | goto exit; |
| 464 | |
| 465 | /* seek */ |
| 466 | if (!ADBG_EXPECT_TEEC_SUCCESS( |
| 467 | c, fs_seek(&sess, obj, 74, TEE_DATA_SEEK_SET))) |
| 468 | goto exit; |
| 469 | |
| 470 | /* verify */ |
| 471 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_read(&sess, obj, out, 10, &count))) |
| 472 | goto exit; |
| 473 | |
| 474 | /* check buffer */ |
| 475 | expect[6] = data_00[0]; |
| 476 | expect[7] = data_00[1]; |
| 477 | expect[8] = data_00[2]; |
| 478 | expect[9] = data_00[3]; |
| 479 | (void)ADBG_EXPECT_BUFFER(c, &expect[0], 10, out, count); |
| 480 | |
| 481 | /* clean */ |
| 482 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_unlink(&sess, obj))) |
| 483 | goto exit; |
| 484 | |
| 485 | exit: |
| 486 | TEEC_CloseSession(&sess); |
| 487 | } |
| 488 | |
Jerome Forissier | e368834 | 2015-09-24 10:45:17 -0700 | [diff] [blame] | 489 | #ifdef WITH_GP_TESTS |
Pascal Brand | 8a74e36 | 2015-09-10 12:41:52 +0200 | [diff] [blame] | 490 | static TEEC_Result ds_open_access_conf(TEEC_Session *sess) |
| 491 | { |
| 492 | TEEC_Operation op; |
| 493 | uint32_t org; |
| 494 | |
| 495 | op.paramTypes = TEEC_PARAM_TYPES( |
| 496 | TEEC_NONE, TEEC_NONE, TEEC_NONE, TEEC_NONE); |
| 497 | |
| 498 | return TEEC_InvokeCommand( |
| 499 | sess, CMD_CreatePersistentObject_AccessConflict, &op, &org); |
| 500 | } |
| 501 | |
| 502 | static TEEC_Result ds_res_obj_panic(TEEC_Session *sess) |
| 503 | { |
| 504 | TEEC_Operation op; |
| 505 | uint32_t org; |
| 506 | |
| 507 | op.paramTypes = TEEC_PARAM_TYPES( |
| 508 | TEEC_NONE, TEEC_NONE, TEEC_NONE, TEEC_NONE); |
| 509 | |
| 510 | return TEEC_InvokeCommand( |
| 511 | sess, CMD_RestrictObjectUsagePanic, &op, &org); |
| 512 | } |
| 513 | |
| 514 | static TEEC_Result ds_seek_obj_inv_handle(TEEC_Session *sess) |
| 515 | { |
| 516 | TEEC_Operation op; |
| 517 | uint32_t org; |
| 518 | |
| 519 | op.paramTypes = TEEC_PARAM_TYPES( |
| 520 | TEEC_VALUE_INPUT, TEEC_NONE, TEEC_NONE, TEEC_NONE); |
| 521 | |
| 522 | op.params[0].value.a = CASE_DATA_OBJECT_NOT_PERSISTENT; |
| 523 | |
| 524 | return TEEC_InvokeCommand( |
| 525 | sess, CMD_SeekObjectData_panic, &op, &org); |
| 526 | } |
| 527 | |
| 528 | static TEEC_Result ds_seek_obj_bad_handle(TEEC_Session *sess) |
| 529 | { |
| 530 | TEEC_Operation op; |
| 531 | uint32_t org; |
| 532 | |
| 533 | op.paramTypes = TEEC_PARAM_TYPES( |
| 534 | TEEC_VALUE_INPUT, TEEC_NONE, TEEC_NONE, TEEC_NONE); |
| 535 | |
| 536 | op.params[0].value.a = CASE_DATA_BAD_HANDLE; |
| 537 | |
| 538 | return TEEC_InvokeCommand( |
| 539 | sess, CMD_SeekObjectData_panic, &op, &org); |
| 540 | } |
| 541 | |
| 542 | static TEEC_Result ds_seek_gp( |
| 543 | TEEC_Session *sess, TEE_Whence wh, uint32_t wh_off, uint32_t set_off, |
| 544 | void *in, size_t in_size, void *out, size_t out_size) |
| 545 | { |
| 546 | TEEC_Operation op; |
| 547 | uint32_t org; |
| 548 | |
| 549 | op.paramTypes = TEEC_PARAM_TYPES( |
| 550 | TEEC_VALUE_INPUT, TEEC_VALUE_INPUT, TEEC_MEMREF_TEMP_INPUT, |
| 551 | TEEC_MEMREF_TEMP_OUTPUT); |
| 552 | |
| 553 | op.params[0].value.a = wh; |
| 554 | op.params[0].value.b = wh_off; |
| 555 | op.params[1].value.a = set_off; |
| 556 | op.params[2].tmpref.buffer = in; |
| 557 | op.params[2].tmpref.size = in_size; |
| 558 | op.params[3].tmpref.buffer = out; |
| 559 | op.params[3].tmpref.size = out_size; |
| 560 | |
| 561 | return TEEC_InvokeCommand(sess, CMD_SeekWriteReadObjectData, &op, &org); |
| 562 | } |
| 563 | |
| 564 | static TEEC_Result ds_init_object_and_attributes(TEEC_Session *sess, |
| 565 | uint32_t obj_type, uint32_t obj_size, const void *attr_meta, |
| 566 | size_t attr_meta_len, const void *attr_data, size_t attr_data_len, |
| 567 | uint32_t option) |
| 568 | { |
| 569 | TEEC_Operation op; |
| 570 | uint32_t org; |
| 571 | |
| 572 | op.paramTypes = TEEC_PARAM_TYPES( |
| 573 | TEEC_VALUE_INPUT, TEEC_MEMREF_TEMP_INPUT, |
| 574 | TEEC_MEMREF_TEMP_INPUT, TEEC_VALUE_INPUT); |
| 575 | |
| 576 | op.params[0].value.a = obj_type; |
| 577 | op.params[0].value.b = obj_size; |
| 578 | op.params[1].tmpref.buffer = (void *)attr_meta; |
| 579 | op.params[1].tmpref.size = attr_meta_len; |
| 580 | op.params[2].tmpref.buffer = (void *)attr_data; |
| 581 | op.params[2].tmpref.size = attr_data_len; |
| 582 | op.params[3].value.a = option; |
| 583 | |
| 584 | return TEEC_InvokeCommand(sess, CMD_InitObjectAndAttributes, &op, &org); |
| 585 | } |
| 586 | |
| 587 | static TEEC_Result ds_rename_access_conflict(TEEC_Session *sess) |
| 588 | { |
| 589 | TEEC_Operation op; |
| 590 | uint32_t org; |
| 591 | |
| 592 | op.paramTypes = TEEC_PARAM_TYPES( |
| 593 | TEEC_NONE, TEEC_NONE, TEEC_NONE, TEEC_NONE); |
| 594 | |
| 595 | return TEEC_InvokeCommand( |
| 596 | sess, CMD_RenamePersistentObject_AccessConflict, &op, &org); |
| 597 | } |
| 598 | |
| 599 | static TEEC_Result ds_start_enum_no_item(TEEC_Session *sess) |
| 600 | { |
| 601 | TEEC_Operation op; |
| 602 | uint32_t org; |
| 603 | TEEC_Result res; |
| 604 | |
| 605 | op.paramTypes = TEEC_PARAM_TYPES( |
| 606 | TEEC_VALUE_OUTPUT, TEEC_NONE, TEEC_NONE, TEEC_NONE); |
| 607 | |
| 608 | res = TEEC_InvokeCommand( |
| 609 | sess, CMD_StartNGetPersistentObjectEnumerator_itemNotFound, &op, &org); |
| 610 | |
| 611 | if (res != TEEC_SUCCESS) |
| 612 | return res; |
| 613 | |
| 614 | if (op.params[0].value.a != 0 || op.params[0].value.b != 0) |
| 615 | return TEEC_ERROR_GENERIC; |
| 616 | |
| 617 | return res; |
| 618 | } |
| 619 | |
| 620 | static TEEC_Result ds_rename_success(TEEC_Session *sess) |
| 621 | { |
| 622 | TEEC_Operation op; |
| 623 | uint32_t org; |
| 624 | |
| 625 | op.paramTypes = TEEC_PARAM_TYPES( |
| 626 | TEEC_NONE, TEEC_NONE, TEEC_NONE, TEEC_NONE); |
| 627 | |
| 628 | return TEEC_InvokeCommand( |
| 629 | sess, CMD_RenamePersistentObject_Success, &op, &org); |
| 630 | } |
| 631 | |
| 632 | static TEEC_Result ds_null_close_free_reset(TEEC_Session *sess) |
| 633 | { |
| 634 | TEEC_Operation op; |
| 635 | uint32_t org; |
| 636 | |
| 637 | op.paramTypes = TEEC_PARAM_TYPES( |
| 638 | TEEC_NONE, TEEC_NONE, TEEC_NONE, TEEC_NONE); |
| 639 | |
| 640 | return TEEC_InvokeCommand( |
| 641 | sess, CMD_CloseFreeAndResetObjectSuccessHandleNull, &op, &org); |
| 642 | } |
| 643 | #endif |
| 644 | |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 645 | /* create */ |
Jerome Forissier | 0e99d6a | 2016-07-25 14:21:43 +0200 | [diff] [blame] | 646 | static void xtest_tee_test_6001_single(ADBG_Case_t *c, uint32_t storage_id) |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 647 | { |
| 648 | TEEC_Session sess; |
| 649 | uint32_t obj; |
| 650 | uint32_t orig; |
| 651 | |
| 652 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 653 | xtest_teec_open_session(&sess, &storage_ta_uuid, NULL, &orig))) |
| 654 | return; |
| 655 | |
| 656 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 657 | fs_create(&sess, file_00, sizeof(file_00), |
| 658 | TEE_DATA_FLAG_ACCESS_WRITE | |
| 659 | TEE_DATA_FLAG_ACCESS_WRITE_META, 0, data_00, |
Jerome Forissier | 0e99d6a | 2016-07-25 14:21:43 +0200 | [diff] [blame] | 660 | sizeof(data_00), &obj, storage_id))) |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 661 | goto exit; |
| 662 | |
| 663 | /* clean */ |
| 664 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_unlink(&sess, obj))) |
| 665 | goto exit; |
| 666 | |
| 667 | exit: |
| 668 | TEEC_CloseSession(&sess); |
| 669 | } |
| 670 | |
Jerome Forissier | 0e99d6a | 2016-07-25 14:21:43 +0200 | [diff] [blame] | 671 | #define DEFINE_TEST_MULTIPLE_STORAGE_IDS(test_name) \ |
| 672 | static void test_name(ADBG_Case_t *c) \ |
| 673 | { \ |
| 674 | size_t i; \ |
| 675 | \ |
| 676 | for (i = 0; i < ARRAY_SIZE(storage_ids); i++) { \ |
| 677 | Do_ADBG_BeginSubCase(c, "Storage id: %08x", storage_ids[i]); \ |
| 678 | test_name##_single(c, storage_ids[i]); \ |
| 679 | Do_ADBG_EndSubCase(c, "Storage id: %08x", storage_ids[i]); \ |
| 680 | } \ |
| 681 | } |
| 682 | |
| 683 | DEFINE_TEST_MULTIPLE_STORAGE_IDS(xtest_tee_test_6001) |
| 684 | |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 685 | /* open */ |
Jerome Forissier | 0e99d6a | 2016-07-25 14:21:43 +0200 | [diff] [blame] | 686 | static void xtest_tee_test_6002_single(ADBG_Case_t *c, uint32_t storage_id) |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 687 | { |
| 688 | TEEC_Session sess; |
| 689 | uint32_t obj; |
| 690 | uint32_t orig; |
| 691 | |
| 692 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 693 | xtest_teec_open_session(&sess, &storage_ta_uuid, NULL, &orig))) |
| 694 | return; |
| 695 | |
| 696 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 697 | fs_create(&sess, file_01, sizeof(file_01), |
| 698 | TEE_DATA_FLAG_ACCESS_WRITE, 0, data_00, |
Jerome Forissier | 0e99d6a | 2016-07-25 14:21:43 +0200 | [diff] [blame] | 699 | sizeof(data_00), &obj, storage_id))) |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 700 | goto exit; |
| 701 | |
| 702 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_close(&sess, obj))) |
| 703 | goto exit; |
| 704 | |
| 705 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 706 | fs_open(&sess, file_01, sizeof(file_01), |
Jerome Forissier | 0e99d6a | 2016-07-25 14:21:43 +0200 | [diff] [blame] | 707 | TEE_DATA_FLAG_ACCESS_WRITE_META, &obj, storage_id))) |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 708 | goto exit; |
| 709 | |
| 710 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_close(&sess, obj))) |
| 711 | goto exit; |
| 712 | |
| 713 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 714 | fs_open(&sess, file_01, sizeof(file_01), |
Jerome Forissier | 0e99d6a | 2016-07-25 14:21:43 +0200 | [diff] [blame] | 715 | TEE_DATA_FLAG_ACCESS_WRITE_META, &obj, storage_id))) |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 716 | goto exit; |
| 717 | |
| 718 | /* clean */ |
| 719 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_unlink(&sess, obj))) |
| 720 | goto exit; |
| 721 | |
| 722 | exit: |
| 723 | TEEC_CloseSession(&sess); |
| 724 | } |
| 725 | |
Jerome Forissier | 0e99d6a | 2016-07-25 14:21:43 +0200 | [diff] [blame] | 726 | DEFINE_TEST_MULTIPLE_STORAGE_IDS(xtest_tee_test_6002) |
| 727 | |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 728 | /* read */ |
Jerome Forissier | 0e99d6a | 2016-07-25 14:21:43 +0200 | [diff] [blame] | 729 | static void xtest_tee_test_6003_single(ADBG_Case_t *c, uint32_t storage_id) |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 730 | { |
| 731 | TEEC_Session sess; |
| 732 | uint32_t obj; |
| 733 | uint8_t out[10] = { 0 }; |
| 734 | uint32_t count; |
| 735 | uint32_t orig; |
| 736 | |
| 737 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 738 | xtest_teec_open_session(&sess, &storage_ta_uuid, NULL, &orig))) |
| 739 | return; |
| 740 | |
| 741 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 742 | fs_create(&sess, file_02, sizeof(file_02), |
| 743 | TEE_DATA_FLAG_ACCESS_WRITE, 0, data_01, |
Jerome Forissier | 0e99d6a | 2016-07-25 14:21:43 +0200 | [diff] [blame] | 744 | sizeof(data_01), &obj, storage_id))) |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 745 | goto exit; |
| 746 | |
| 747 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_close(&sess, obj))) |
| 748 | goto exit; |
| 749 | |
| 750 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 751 | fs_open(&sess, file_02, sizeof(file_02), |
| 752 | TEE_DATA_FLAG_ACCESS_READ | |
Jerome Forissier | 0e99d6a | 2016-07-25 14:21:43 +0200 | [diff] [blame] | 753 | TEE_DATA_FLAG_ACCESS_WRITE_META, &obj, storage_id))) |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 754 | goto exit; |
| 755 | |
| 756 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_read(&sess, obj, out, 10, &count))) |
| 757 | goto exit; |
| 758 | |
| 759 | (void)ADBG_EXPECT_BUFFER(c, data_01, 10, out, count); |
| 760 | |
| 761 | /* clean */ |
| 762 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_unlink(&sess, obj))) |
| 763 | goto exit; |
| 764 | |
| 765 | exit: |
| 766 | TEEC_CloseSession(&sess); |
| 767 | } |
| 768 | |
Jerome Forissier | 0e99d6a | 2016-07-25 14:21:43 +0200 | [diff] [blame] | 769 | DEFINE_TEST_MULTIPLE_STORAGE_IDS(xtest_tee_test_6003) |
| 770 | |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 771 | /* write */ |
Jerome Forissier | 0e99d6a | 2016-07-25 14:21:43 +0200 | [diff] [blame] | 772 | static void xtest_tee_test_6004_single(ADBG_Case_t *c, uint32_t storage_id) |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 773 | { |
| 774 | TEEC_Session sess; |
| 775 | uint32_t obj; |
| 776 | uint8_t out[10] = { 0 }; |
| 777 | uint32_t count; |
| 778 | uint32_t orig; |
| 779 | |
| 780 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 781 | xtest_teec_open_session(&sess, &storage_ta_uuid, NULL, &orig))) |
| 782 | return; |
| 783 | |
| 784 | /* create */ |
| 785 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 786 | fs_create(&sess, file_02, sizeof(file_02), |
| 787 | TEE_DATA_FLAG_ACCESS_WRITE, 0, data_01, |
Jerome Forissier | 0e99d6a | 2016-07-25 14:21:43 +0200 | [diff] [blame] | 788 | sizeof(data_01), &obj, storage_id))) |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 789 | goto exit; |
| 790 | |
| 791 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_close(&sess, obj))) |
| 792 | goto exit; |
| 793 | |
| 794 | /* write new data */ |
| 795 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 796 | fs_open(&sess, file_02, sizeof(file_02), |
Jerome Forissier | 0e99d6a | 2016-07-25 14:21:43 +0200 | [diff] [blame] | 797 | TEE_DATA_FLAG_ACCESS_WRITE, &obj, storage_id))) |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 798 | goto exit; |
| 799 | |
| 800 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 801 | fs_write(&sess, obj, data_00, sizeof(data_00)))) |
| 802 | goto exit; |
| 803 | |
| 804 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_close(&sess, obj))) |
| 805 | goto exit; |
| 806 | |
| 807 | /* verify */ |
| 808 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 809 | fs_open(&sess, file_02, sizeof(file_02), |
| 810 | TEE_DATA_FLAG_ACCESS_READ | |
Jerome Forissier | 0e99d6a | 2016-07-25 14:21:43 +0200 | [diff] [blame] | 811 | TEE_DATA_FLAG_ACCESS_WRITE_META, &obj, storage_id))) |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 812 | goto exit; |
| 813 | |
| 814 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_read(&sess, obj, out, 10, &count))) |
| 815 | goto exit; |
| 816 | |
| 817 | (void)ADBG_EXPECT_BUFFER(c, data_00, 10, out, count); |
| 818 | |
| 819 | /* clean */ |
| 820 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_unlink(&sess, obj))) |
| 821 | goto exit; |
| 822 | |
| 823 | exit: |
| 824 | TEEC_CloseSession(&sess); |
| 825 | } |
| 826 | |
Jerome Forissier | 0e99d6a | 2016-07-25 14:21:43 +0200 | [diff] [blame] | 827 | DEFINE_TEST_MULTIPLE_STORAGE_IDS(xtest_tee_test_6004) |
| 828 | |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 829 | /* seek */ |
Jerome Forissier | 0e99d6a | 2016-07-25 14:21:43 +0200 | [diff] [blame] | 830 | static void xtest_tee_test_6005_single(ADBG_Case_t *c, uint32_t storage_id) |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 831 | { |
| 832 | TEEC_Session sess; |
| 833 | uint32_t obj; |
| 834 | uint8_t out[10] = { 0 }; |
| 835 | uint32_t count; |
| 836 | uint32_t orig; |
| 837 | |
| 838 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 839 | xtest_teec_open_session(&sess, &storage_ta_uuid, NULL, &orig))) |
| 840 | return; |
| 841 | |
| 842 | /* create */ |
| 843 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 844 | fs_create(&sess, file_01, sizeof(file_01), |
| 845 | TEE_DATA_FLAG_ACCESS_WRITE | |
| 846 | TEE_DATA_FLAG_ACCESS_READ | |
| 847 | TEE_DATA_FLAG_ACCESS_WRITE_META, 0, data_00, |
Jerome Forissier | 0e99d6a | 2016-07-25 14:21:43 +0200 | [diff] [blame] | 848 | sizeof(data_00), &obj, storage_id))) |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 849 | goto exit; |
| 850 | |
| 851 | /* seek */ |
| 852 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 853 | fs_seek(&sess, obj, 10, TEE_DATA_SEEK_SET))) |
| 854 | goto exit; |
| 855 | |
| 856 | /* verify */ |
| 857 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_read(&sess, obj, out, 10, &count))) |
| 858 | goto exit; |
| 859 | |
| 860 | (void)ADBG_EXPECT_BUFFER(c, &data_00[10], 10, out, count); |
| 861 | |
| 862 | /* clean */ |
| 863 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_unlink(&sess, obj))) |
| 864 | goto exit; |
| 865 | |
| 866 | exit: |
| 867 | TEEC_CloseSession(&sess); |
| 868 | } |
| 869 | |
Jerome Forissier | 0e99d6a | 2016-07-25 14:21:43 +0200 | [diff] [blame] | 870 | DEFINE_TEST_MULTIPLE_STORAGE_IDS(xtest_tee_test_6005) |
| 871 | |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 872 | /* unlink */ |
Jerome Forissier | 0e99d6a | 2016-07-25 14:21:43 +0200 | [diff] [blame] | 873 | static void xtest_tee_test_6006_single(ADBG_Case_t *c, uint32_t storage_id) |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 874 | { |
| 875 | TEEC_Session sess; |
| 876 | uint32_t obj; |
| 877 | uint32_t orig; |
| 878 | |
| 879 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 880 | xtest_teec_open_session(&sess, &storage_ta_uuid, NULL, &orig))) |
| 881 | return; |
| 882 | |
| 883 | /* create */ |
| 884 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 885 | fs_create(&sess, file_01, sizeof(file_01), |
| 886 | TEE_DATA_FLAG_ACCESS_WRITE_META, 0, data_00, |
Jerome Forissier | 0e99d6a | 2016-07-25 14:21:43 +0200 | [diff] [blame] | 887 | sizeof(data_00), &obj, storage_id))) |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 888 | goto exit; |
| 889 | |
| 890 | /* del & close */ |
| 891 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_unlink(&sess, obj))) |
| 892 | goto exit; |
| 893 | |
| 894 | /* check result */ |
| 895 | if (!ADBG_EXPECT_TEEC_RESULT(c, TEEC_ERROR_ITEM_NOT_FOUND, |
| 896 | fs_open(&sess, file_01, sizeof(file_01), |
Jerome Forissier | 0e99d6a | 2016-07-25 14:21:43 +0200 | [diff] [blame] | 897 | TEE_DATA_FLAG_ACCESS_READ, &obj, storage_id))) |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 898 | goto exit; |
| 899 | |
| 900 | exit: |
| 901 | TEEC_CloseSession(&sess); |
| 902 | } |
| 903 | |
Jerome Forissier | 0e99d6a | 2016-07-25 14:21:43 +0200 | [diff] [blame] | 904 | DEFINE_TEST_MULTIPLE_STORAGE_IDS(xtest_tee_test_6006) |
| 905 | |
| 906 | static void xtest_tee_test_6007_single(ADBG_Case_t *c, uint32_t storage_id) |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 907 | { |
James Kung | 98c0ba1 | 2015-09-09 15:51:59 +0800 | [diff] [blame] | 908 | Do_ADBG_BeginSubCase(c, "Test truncate file length"); |
Jerome Forissier | 0e99d6a | 2016-07-25 14:21:43 +0200 | [diff] [blame] | 909 | test_truncate_file_length(c, storage_id); |
James Kung | 98c0ba1 | 2015-09-09 15:51:59 +0800 | [diff] [blame] | 910 | Do_ADBG_EndSubCase(c, "Test truncate file length"); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 911 | |
James Kung | 98c0ba1 | 2015-09-09 15:51:59 +0800 | [diff] [blame] | 912 | Do_ADBG_BeginSubCase(c, "Test extend file length"); |
Jerome Forissier | 0e99d6a | 2016-07-25 14:21:43 +0200 | [diff] [blame] | 913 | test_extend_file_length(c, storage_id); |
James Kung | 98c0ba1 | 2015-09-09 15:51:59 +0800 | [diff] [blame] | 914 | Do_ADBG_EndSubCase(c, "Test extend file length"); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 915 | |
James Kung | 98c0ba1 | 2015-09-09 15:51:59 +0800 | [diff] [blame] | 916 | Do_ADBG_BeginSubCase(c, "Test file hole"); |
Jerome Forissier | 0e99d6a | 2016-07-25 14:21:43 +0200 | [diff] [blame] | 917 | test_file_hole(c, storage_id); |
James Kung | 98c0ba1 | 2015-09-09 15:51:59 +0800 | [diff] [blame] | 918 | Do_ADBG_EndSubCase(c, "Test file hole"); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 919 | } |
| 920 | |
Jerome Forissier | 0e99d6a | 2016-07-25 14:21:43 +0200 | [diff] [blame] | 921 | DEFINE_TEST_MULTIPLE_STORAGE_IDS(xtest_tee_test_6007) |
| 922 | |
| 923 | static void xtest_tee_test_6008_single(ADBG_Case_t *c, uint32_t storage_id) |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 924 | { |
| 925 | TEEC_Session sess; |
| 926 | uint32_t obj; |
| 927 | uint8_t out[10] = { 0 }; |
| 928 | uint32_t count; |
| 929 | uint32_t orig; |
| 930 | |
| 931 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 932 | xtest_teec_open_session(&sess, &storage_ta_uuid, NULL, &orig))) |
| 933 | return; |
| 934 | |
| 935 | /* create */ |
| 936 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 937 | fs_create(&sess, file_02, sizeof(file_02), |
| 938 | TEE_DATA_FLAG_ACCESS_WRITE, 0, data_01, |
Jerome Forissier | 0e99d6a | 2016-07-25 14:21:43 +0200 | [diff] [blame] | 939 | sizeof(data_01), &obj, storage_id))) |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 940 | goto exit; |
| 941 | |
| 942 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_close(&sess, obj))) |
| 943 | goto exit; |
| 944 | |
| 945 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 946 | fs_open(&sess, file_02, sizeof(file_02), |
| 947 | TEE_DATA_FLAG_ACCESS_WRITE | |
Jerome Forissier | 0e99d6a | 2016-07-25 14:21:43 +0200 | [diff] [blame] | 948 | TEE_DATA_FLAG_ACCESS_WRITE_META, &obj, storage_id))) |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 949 | goto exit; |
| 950 | |
| 951 | /* write new data */ |
| 952 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 953 | fs_write(&sess, obj, data_00, sizeof(data_00)))) |
| 954 | goto exit; |
| 955 | |
| 956 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 957 | fs_rename(&sess, obj, file_03, sizeof(file_03)))) |
| 958 | goto exit; |
| 959 | |
| 960 | /* close */ |
| 961 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_close(&sess, obj))) |
| 962 | goto exit; |
| 963 | |
| 964 | /* verify */ |
| 965 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 966 | fs_open(&sess, file_03, sizeof(file_03), |
| 967 | TEE_DATA_FLAG_ACCESS_READ | |
Jerome Forissier | 0e99d6a | 2016-07-25 14:21:43 +0200 | [diff] [blame] | 968 | TEE_DATA_FLAG_ACCESS_WRITE_META, &obj, storage_id))) |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 969 | goto exit; |
| 970 | |
| 971 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_read(&sess, obj, out, 10, &count))) |
| 972 | goto exit; |
| 973 | |
| 974 | /* check buffer */ |
| 975 | (void)ADBG_EXPECT_BUFFER(c, data_00, 10, out, count); |
| 976 | |
| 977 | /* clean */ |
| 978 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_unlink(&sess, obj))) |
| 979 | goto exit; |
| 980 | |
| 981 | exit: |
| 982 | TEEC_CloseSession(&sess); |
| 983 | } |
| 984 | |
Jerome Forissier | 0e99d6a | 2016-07-25 14:21:43 +0200 | [diff] [blame] | 985 | DEFINE_TEST_MULTIPLE_STORAGE_IDS(xtest_tee_test_6008) |
| 986 | |
| 987 | static void xtest_tee_test_6009_single(ADBG_Case_t *c, uint32_t storage_id) |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 988 | { |
| 989 | TEEC_Session sess; |
| 990 | uint32_t obj0; |
| 991 | uint32_t obj1; |
| 992 | uint32_t obj2; |
| 993 | uint32_t e = 0; |
| 994 | uint8_t info[200]; |
| 995 | uint8_t id[200]; |
| 996 | uint32_t orig; |
| 997 | |
| 998 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 999 | xtest_teec_open_session(&sess, &storage_ta_uuid, NULL, &orig))) |
| 1000 | return; |
| 1001 | |
| 1002 | /* create file 00 */ |
| 1003 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1004 | fs_create(&sess, file_00, sizeof(file_00), |
| 1005 | TEE_DATA_FLAG_ACCESS_WRITE, 0, data_01, |
Jerome Forissier | 0e99d6a | 2016-07-25 14:21:43 +0200 | [diff] [blame] | 1006 | sizeof(data_01), &obj0, storage_id))) |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 1007 | goto exit; |
| 1008 | |
| 1009 | /* create file 01 */ |
| 1010 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1011 | fs_create(&sess, file_01, sizeof(file_01), |
| 1012 | TEE_DATA_FLAG_ACCESS_WRITE, 0, data_01, |
Jerome Forissier | 0e99d6a | 2016-07-25 14:21:43 +0200 | [diff] [blame] | 1013 | sizeof(data_01), &obj1, storage_id))) |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 1014 | goto exit; |
| 1015 | |
| 1016 | /* create file 02 */ |
| 1017 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1018 | fs_create(&sess, file_02, sizeof(file_02), |
| 1019 | TEE_DATA_FLAG_ACCESS_WRITE, 0, data_01, |
Jerome Forissier | 0e99d6a | 2016-07-25 14:21:43 +0200 | [diff] [blame] | 1020 | sizeof(data_01), &obj2, storage_id))) |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 1021 | goto exit; |
| 1022 | |
| 1023 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_close(&sess, obj0))) |
| 1024 | goto exit; |
| 1025 | |
| 1026 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_close(&sess, obj1))) |
| 1027 | goto exit; |
| 1028 | |
| 1029 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_close(&sess, obj2))) |
| 1030 | goto exit; |
| 1031 | |
| 1032 | /* iterate */ |
| 1033 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_alloc_enum(&sess, &e))) |
| 1034 | goto exit; |
| 1035 | |
Jerome Forissier | 0e99d6a | 2016-07-25 14:21:43 +0200 | [diff] [blame] | 1036 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_start_enum(&sess, e, storage_id))) |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 1037 | goto exit; |
| 1038 | |
| 1039 | /* get 00 */ |
| 1040 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1041 | fs_next_enum(&sess, e, info, sizeof(info), id, sizeof(id)))) |
| 1042 | goto exit; |
| 1043 | |
| 1044 | /* get 01 */ |
| 1045 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
Pascal Brand | c603e0d | 2016-04-25 12:37:18 +0200 | [diff] [blame] | 1046 | fs_next_enum(&sess, e, NULL, 0, id, sizeof(id)))) |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 1047 | goto exit; |
| 1048 | |
| 1049 | /* get 02 */ |
| 1050 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1051 | fs_next_enum(&sess, e, info, sizeof(info), id, sizeof(id)))) |
| 1052 | goto exit; |
| 1053 | |
| 1054 | /* we should not have more files */ |
| 1055 | if (!ADBG_EXPECT_TEEC_RESULT(c, TEEC_ERROR_ITEM_NOT_FOUND, |
| 1056 | fs_next_enum(&sess, e, info, sizeof(info), id, sizeof(id)))) |
| 1057 | goto exit; |
| 1058 | |
| 1059 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_free_enum(&sess, e))) |
| 1060 | goto exit; |
| 1061 | |
| 1062 | /* clean */ |
| 1063 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1064 | fs_open(&sess, file_00, sizeof(file_00), |
Jerome Forissier | 0e99d6a | 2016-07-25 14:21:43 +0200 | [diff] [blame] | 1065 | TEE_DATA_FLAG_ACCESS_WRITE_META, &obj0, storage_id))) |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 1066 | goto exit; |
| 1067 | |
| 1068 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_unlink(&sess, obj0))) |
| 1069 | goto exit; |
| 1070 | |
| 1071 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1072 | fs_open(&sess, file_01, sizeof(file_01), |
Jerome Forissier | 0e99d6a | 2016-07-25 14:21:43 +0200 | [diff] [blame] | 1073 | TEE_DATA_FLAG_ACCESS_WRITE_META, &obj1, storage_id))) |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 1074 | goto exit; |
| 1075 | |
| 1076 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_unlink(&sess, obj1))) |
| 1077 | goto exit; |
| 1078 | |
| 1079 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1080 | fs_open(&sess, file_02, sizeof(file_02), |
Jerome Forissier | 0e99d6a | 2016-07-25 14:21:43 +0200 | [diff] [blame] | 1081 | TEE_DATA_FLAG_ACCESS_WRITE_META, &obj2, storage_id))) |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 1082 | goto exit; |
| 1083 | |
| 1084 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_unlink(&sess, obj2))) |
| 1085 | goto exit; |
| 1086 | |
| 1087 | exit: |
| 1088 | TEEC_CloseSession(&sess); |
| 1089 | } |
| 1090 | |
Jerome Forissier | 0e99d6a | 2016-07-25 14:21:43 +0200 | [diff] [blame] | 1091 | DEFINE_TEST_MULTIPLE_STORAGE_IDS(xtest_tee_test_6009) |
| 1092 | |
Jerome Forissier | e368834 | 2015-09-24 10:45:17 -0700 | [diff] [blame] | 1093 | #ifdef WITH_GP_TESTS |
Pascal Brand | 8a74e36 | 2015-09-10 12:41:52 +0200 | [diff] [blame] | 1094 | static void xtest_tee_test_6010(ADBG_Case_t *c) |
| 1095 | { |
| 1096 | TEEC_Session sess; |
| 1097 | uint32_t orig; |
| 1098 | uint8_t out[4000] = {0}; |
| 1099 | uint8_t in[0x12c] = {'b'}; |
Pascal Brand | 3084492 | 2015-09-17 12:12:42 +0200 | [diff] [blame] | 1100 | int i; |
| 1101 | |
| 1102 | for (i=0; i<sizeof(in); i++) |
| 1103 | in[i] = i; |
Pascal Brand | 8a74e36 | 2015-09-10 12:41:52 +0200 | [diff] [blame] | 1104 | |
| 1105 | if (!ADBG_EXPECT_TEEC_SUCCESS( |
| 1106 | c, xtest_teec_open_session( |
| 1107 | &sess, &gp_tta_ds_uuid, NULL, &orig))) |
| 1108 | return; |
| 1109 | |
| 1110 | Do_ADBG_BeginSubCase( |
| 1111 | c, "GP DS CreatePersistentObject AccessConflict (9d-1d-62)"); |
| 1112 | |
| 1113 | if (!ADBG_EXPECT_TEEC_RESULT( |
| 1114 | c, TEEC_ERROR_ACCESS_CONFLICT, ds_open_access_conf(&sess))) |
| 1115 | goto exit; |
| 1116 | |
| 1117 | Do_ADBG_EndSubCase( |
| 1118 | c, "GP DS CreatePersistentObject AccessConflict (9d-1d-62)"); |
| 1119 | Do_ADBG_BeginSubCase( |
| 1120 | c, "GP DS RestrictObjectUsagePanic (9d-5d-46)"); |
| 1121 | |
| 1122 | if (!ADBG_EXPECT_TEEC_RESULT( |
| 1123 | c, TEE_ERROR_TARGET_DEAD, ds_res_obj_panic(&sess))) |
| 1124 | goto exit; |
| 1125 | |
| 1126 | TEEC_CloseSession(&sess); |
| 1127 | |
| 1128 | Do_ADBG_EndSubCase( |
| 1129 | c, "GP DS RestrictObjectUsagePanic (9d-5d-46)"); |
| 1130 | Do_ADBG_BeginSubCase( |
| 1131 | c, "GP DS SeekObjectData BadHandle (9d-c3-c8)"); |
| 1132 | |
| 1133 | if (!ADBG_EXPECT_TEEC_SUCCESS( |
| 1134 | c, xtest_teec_open_session( |
| 1135 | &sess, &gp_tta_ds_uuid, NULL, &orig))) |
| 1136 | return; |
| 1137 | |
| 1138 | if (!ADBG_EXPECT_TEEC_RESULT( |
| 1139 | c, TEE_ERROR_TARGET_DEAD, ds_seek_obj_bad_handle(&sess))) |
| 1140 | goto exit; |
| 1141 | |
| 1142 | TEEC_CloseSession(&sess); |
| 1143 | |
| 1144 | Do_ADBG_EndSubCase( |
| 1145 | c, "GP DS SeekObjectData BadHandle (9d-c3-c8)"); |
| 1146 | Do_ADBG_BeginSubCase( |
| 1147 | c, "GP DS SeekObjectData NotPersist (9d-db-4a)"); |
| 1148 | |
| 1149 | if (!ADBG_EXPECT_TEEC_SUCCESS( |
| 1150 | c, xtest_teec_open_session( |
| 1151 | &sess, &gp_tta_ds_uuid, NULL, &orig))) |
| 1152 | return; |
| 1153 | |
| 1154 | if (!ADBG_EXPECT_TEEC_RESULT( |
| 1155 | c, TEE_ERROR_TARGET_DEAD, ds_seek_obj_inv_handle(&sess))) |
| 1156 | goto exit; |
| 1157 | |
| 1158 | TEEC_CloseSession(&sess); |
| 1159 | |
| 1160 | Do_ADBG_EndSubCase( |
| 1161 | c, "GP DS SeekObjectData NotPersist (9d-db-4a)"); |
| 1162 | Do_ADBG_BeginSubCase(c, "GP DS SeekWriteRead SEEK_END (9d-e4-58)"); |
| 1163 | |
| 1164 | if (!ADBG_EXPECT_TEEC_SUCCESS( |
| 1165 | c, xtest_teec_open_session( |
| 1166 | &sess, &gp_tta_ds_uuid, NULL, &orig))) |
| 1167 | return; |
| 1168 | |
| 1169 | if (!ADBG_EXPECT_TEEC_SUCCESS( |
| 1170 | c, ds_seek_gp( |
| 1171 | &sess, TEE_DATA_SEEK_END, 0, 2, data_00, sizeof(data_00), out, |
| 1172 | sizeof(out)))) |
| 1173 | goto exit; |
| 1174 | |
| 1175 | /* check buffer */ |
| 1176 | (void)ADBG_EXPECT_BUFFER( |
| 1177 | c, data_00, sizeof(data_00), out, sizeof(data_00)); |
Pascal Brand | 3084492 | 2015-09-17 12:12:42 +0200 | [diff] [blame] | 1178 | memset(out, 0xab, sizeof(out)); |
Pascal Brand | 8a74e36 | 2015-09-10 12:41:52 +0200 | [diff] [blame] | 1179 | |
| 1180 | if (!ADBG_EXPECT_TEEC_SUCCESS( |
| 1181 | c, ds_seek_gp( |
Pascal Brand | 3084492 | 2015-09-17 12:12:42 +0200 | [diff] [blame] | 1182 | &sess, TEE_DATA_SEEK_END, sizeof(in)/2, 0, in, sizeof(in), out, |
Pascal Brand | 8a74e36 | 2015-09-10 12:41:52 +0200 | [diff] [blame] | 1183 | sizeof(out)))) |
| 1184 | goto exit; |
| 1185 | |
Pascal Brand | 3084492 | 2015-09-17 12:12:42 +0200 | [diff] [blame] | 1186 | (void)ADBG_EXPECT_BUFFER(c, in, sizeof(in) / 2, |
| 1187 | out + (sizeof(in) / 2), sizeof(in) / 2); |
| 1188 | memset(in, 0, sizeof(in)); |
| 1189 | (void)ADBG_EXPECT_BUFFER(c, in, sizeof(in) / 2, |
| 1190 | out, sizeof(in)/2); |
| 1191 | memset(out, 0xab, sizeof(out)); |
Pascal Brand | 8a74e36 | 2015-09-10 12:41:52 +0200 | [diff] [blame] | 1192 | |
| 1193 | Do_ADBG_EndSubCase(c, "GP DS SeekWriteRead SEEK_END (9d-e4-58)"); |
| 1194 | Do_ADBG_BeginSubCase(c, "GP DS Rename Access Conflict (9d-29-d1)"); |
| 1195 | |
| 1196 | if (!ADBG_EXPECT_TEEC_RESULT( |
| 1197 | c, TEE_ERROR_ACCESS_CONFLICT, ds_rename_access_conflict(&sess))) |
| 1198 | goto exit; |
| 1199 | |
| 1200 | Do_ADBG_EndSubCase(c, "GP DS Rename Access Conflict (9d-29-d1)"); |
| 1201 | Do_ADBG_BeginSubCase( |
| 1202 | c, "GP DS StartPersistentObjectEnumerator ItemNotFound (9d-52-ec)"); |
| 1203 | |
| 1204 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, ds_start_enum_no_item(&sess))) |
| 1205 | goto exit; |
| 1206 | |
| 1207 | Do_ADBG_EndSubCase( |
| 1208 | c, "GP DS StartPersistentObjectEnumerator ItemNotFound (9d-52-ec)"); |
| 1209 | Do_ADBG_BeginSubCase( |
| 1210 | c, "GP DS RenamePersistent ReadWrite (9d-19-88)"); |
| 1211 | |
| 1212 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, ds_rename_success(&sess))) |
| 1213 | goto exit; |
| 1214 | |
| 1215 | Do_ADBG_EndSubCase( |
| 1216 | c, "GP DS RenamePersistent ReadWrite (9d-19-88)"); |
| 1217 | Do_ADBG_BeginSubCase( |
| 1218 | c, "GP DS Close Free Reset Null (9d-6d-87)"); |
| 1219 | |
| 1220 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, ds_null_close_free_reset(&sess))) |
| 1221 | goto exit; |
| 1222 | |
| 1223 | Do_ADBG_EndSubCase( |
| 1224 | c, "GP DS Close Free Reset Null (9d-6d-87)"); |
| 1225 | |
| 1226 | exit: |
| 1227 | TEEC_CloseSession(&sess); |
| 1228 | } |
| 1229 | |
| 1230 | static void xtest_tee_test_6011(ADBG_Case_t *c) |
| 1231 | { |
| 1232 | TEEC_Session sess; |
| 1233 | uint32_t orig; |
| 1234 | /* |
| 1235 | * Test data from |
| 1236 | * Invoke_InitObjectAndAttributes_TEE_TYPE_AES_success_attribute_ |
| 1237 | * TEE_ATTR_SECRET_VALUE_correct_size (9d-9a-91) |
| 1238 | */ |
| 1239 | static const uint8_t attr_meta[] = { |
| 1240 | 0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00, |
| 1241 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
| 1242 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
| 1243 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
| 1244 | }; |
| 1245 | static const uint8_t attr_data[] = { |
| 1246 | 0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77, |
| 1247 | 0x81,0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,0x2d,0x98,0x10,0xa3,0x09,0x14, |
| 1248 | 0xdf,0xf4, |
| 1249 | }; |
| 1250 | |
| 1251 | if (!ADBG_EXPECT_TEEC_SUCCESS( |
| 1252 | c, xtest_teec_open_session( |
| 1253 | &sess, &gp_tta_ds_uuid, NULL, &orig))) |
| 1254 | return; |
| 1255 | |
| 1256 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, ds_init_object_and_attributes(&sess, |
| 1257 | 0xa0000010, 0x100, attr_meta, sizeof(attr_meta), attr_data, |
| 1258 | sizeof(attr_data), 0))) |
| 1259 | goto exit; |
| 1260 | |
| 1261 | exit: |
| 1262 | TEEC_CloseSession(&sess); |
| 1263 | } |
| 1264 | #endif |
| 1265 | |
Jerome Forissier | 0e99d6a | 2016-07-25 14:21:43 +0200 | [diff] [blame] | 1266 | static void xtest_tee_test_6012_single(ADBG_Case_t *c, uint32_t storage_id) |
Pascal Brand | eb84c44 | 2016-04-19 17:49:49 +0200 | [diff] [blame] | 1267 | { |
| 1268 | TEEC_Session sess; |
| 1269 | uint32_t orig; |
| 1270 | uint32_t obj; |
| 1271 | |
| 1272 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1273 | xtest_teec_open_session(&sess, &storage_ta_uuid, NULL, &orig))) |
| 1274 | return; |
| 1275 | |
| 1276 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
Jerome Forissier | 0e99d6a | 2016-07-25 14:21:43 +0200 | [diff] [blame] | 1277 | fs_create_overwrite(&sess, file_04, sizeof(file_04), storage_id))) |
Pascal Brand | eb84c44 | 2016-04-19 17:49:49 +0200 | [diff] [blame] | 1278 | goto exit; |
| 1279 | |
| 1280 | TEEC_CloseSession(&sess); |
| 1281 | |
| 1282 | /* re-create the same */ |
| 1283 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1284 | xtest_teec_open_session(&sess, &storage_ta_uuid, NULL, &orig))) |
| 1285 | return; |
| 1286 | |
| 1287 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
Jerome Forissier | 0e99d6a | 2016-07-25 14:21:43 +0200 | [diff] [blame] | 1288 | fs_create_overwrite(&sess, file_04, sizeof(file_04), |
| 1289 | storage_id))) |
Pascal Brand | eb84c44 | 2016-04-19 17:49:49 +0200 | [diff] [blame] | 1290 | goto exit; |
| 1291 | |
| 1292 | /* |
| 1293 | * recreate it with an object, and remove it so that xtest 6009 |
| 1294 | * can be replayed |
| 1295 | */ |
| 1296 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1297 | fs_create(&sess, file_04, sizeof(file_04), |
| 1298 | TEE_DATA_FLAG_ACCESS_WRITE | |
Jerome Forissier | 0e99d6a | 2016-07-25 14:21:43 +0200 | [diff] [blame] | 1299 | TEE_DATA_FLAG_ACCESS_WRITE_META | |
| 1300 | TEE_DATA_FLAG_OVERWRITE, 0, NULL, 0, &obj, |
| 1301 | storage_id))) |
Pascal Brand | eb84c44 | 2016-04-19 17:49:49 +0200 | [diff] [blame] | 1302 | goto exit; |
| 1303 | |
| 1304 | /* clean */ |
| 1305 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_unlink(&sess, obj))) |
| 1306 | goto exit; |
| 1307 | |
| 1308 | exit: |
| 1309 | TEEC_CloseSession(&sess); |
| 1310 | } |
| 1311 | |
Jerome Forissier | 0e99d6a | 2016-07-25 14:21:43 +0200 | [diff] [blame] | 1312 | DEFINE_TEST_MULTIPLE_STORAGE_IDS(xtest_tee_test_6012) |
| 1313 | |
| 1314 | static void xtest_tee_test_6013_single(ADBG_Case_t *c, uint32_t storage_id) |
Pascal Brand | 90f2335 | 2016-05-19 15:15:47 +0200 | [diff] [blame] | 1315 | { |
| 1316 | TEEC_Session sess; |
| 1317 | uint32_t orig; |
| 1318 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 1319 | |
| 1320 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1321 | xtest_teec_open_session(&sess, &storage_ta_uuid, NULL, &orig))) |
| 1322 | return; |
| 1323 | |
Jerome Forissier | 0e99d6a | 2016-07-25 14:21:43 +0200 | [diff] [blame] | 1324 | op.params[0].value.a = storage_id; |
| 1325 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, TEEC_NONE, |
Pascal Brand | 90f2335 | 2016-05-19 15:15:47 +0200 | [diff] [blame] | 1326 | TEEC_NONE, TEEC_NONE); |
| 1327 | |
| 1328 | ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1329 | TEEC_InvokeCommand(&sess, TA_STORAGE_CMD_KEY_IN_PERSISTENT, |
| 1330 | &op, &orig)); |
| 1331 | |
| 1332 | TEEC_CloseSession(&sess); |
| 1333 | } |
| 1334 | |
Jerome Forissier | 0e99d6a | 2016-07-25 14:21:43 +0200 | [diff] [blame] | 1335 | DEFINE_TEST_MULTIPLE_STORAGE_IDS(xtest_tee_test_6013) |
| 1336 | |
| 1337 | static void xtest_tee_test_6014_single(ADBG_Case_t *c, uint32_t storage_id) |
Pascal Brand | 29ee18f | 2016-05-23 14:13:56 +0200 | [diff] [blame] | 1338 | { |
| 1339 | TEEC_Session sess; |
| 1340 | uint32_t orig; |
| 1341 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 1342 | |
| 1343 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1344 | xtest_teec_open_session(&sess, &storage_ta_uuid, NULL, &orig))) |
| 1345 | return; |
| 1346 | |
Jerome Forissier | 0e99d6a | 2016-07-25 14:21:43 +0200 | [diff] [blame] | 1347 | op.params[0].value.a = storage_id; |
| 1348 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, TEEC_NONE, |
Pascal Brand | 29ee18f | 2016-05-23 14:13:56 +0200 | [diff] [blame] | 1349 | TEEC_NONE, TEEC_NONE); |
| 1350 | |
| 1351 | ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1352 | TEEC_InvokeCommand(&sess, TA_STORAGE_CMD_LOOP, &op, &orig)); |
| 1353 | |
| 1354 | TEEC_CloseSession(&sess); |
| 1355 | } |
| 1356 | |
Jerome Forissier | 0e99d6a | 2016-07-25 14:21:43 +0200 | [diff] [blame] | 1357 | DEFINE_TEST_MULTIPLE_STORAGE_IDS(xtest_tee_test_6014) |
| 1358 | |
Jerome Forissier | e385416 | 2016-08-12 12:40:12 +0200 | [diff] [blame] | 1359 | static int get_ta_storage_path(TEEC_UUID *p_uuid, char *buffer, uint32_t len) |
| 1360 | { |
| 1361 | int s; |
| 1362 | |
| 1363 | if (!p_uuid || !buffer) |
| 1364 | return -1; |
| 1365 | |
| 1366 | s = snprintf(buffer, len, "/data/tee/"); |
| 1367 | if (s < 0 || s >= (int)len) |
| 1368 | return -1; |
| 1369 | |
| 1370 | len -= s; |
| 1371 | buffer += s; |
| 1372 | |
| 1373 | s = ree_fs_get_ta_dirname(p_uuid, buffer, len); |
| 1374 | return s; |
| 1375 | } |
| 1376 | |
| 1377 | static int rename_data_dir(TEEC_UUID *old, TEEC_UUID *nw) |
| 1378 | { |
| 1379 | char opath[150]; |
| 1380 | char npath[150]; |
| 1381 | int s; |
| 1382 | |
| 1383 | s = get_ta_storage_path(old, opath, sizeof(opath)); |
| 1384 | if (s < 0 || s >= (int)sizeof(opath)) { |
| 1385 | s = -1; |
| 1386 | goto exit; |
| 1387 | } |
| 1388 | s = get_ta_storage_path(nw, npath, sizeof(npath)); |
| 1389 | if (s < 0 || s >= (int)sizeof(opath)) { |
| 1390 | s = -1; |
| 1391 | goto exit; |
| 1392 | } |
| 1393 | s = rename(opath, npath); |
| 1394 | exit: |
| 1395 | if (s < 0) |
| 1396 | fprintf(stderr, "Warning: could not rename %s -> %s\n", opath, |
| 1397 | npath); |
| 1398 | return s; |
| 1399 | } |
| 1400 | |
| 1401 | static void xtest_tee_test_6015_single(ADBG_Case_t *c, uint32_t storage_id) |
| 1402 | { |
| 1403 | TEEC_Session sess; |
| 1404 | TEEC_Session sess2; |
| 1405 | uint32_t orig; |
| 1406 | uint32_t obj; |
| 1407 | uint32_t obj2; |
| 1408 | TEEC_UUID uuid = TA_STORAGE_UUID; |
| 1409 | TEEC_UUID uuid2 = TA_STORAGE2_UUID; |
| 1410 | |
| 1411 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1412 | xtest_teec_open_session(&sess, &storage_ta_uuid, NULL, &orig))) |
| 1413 | return; |
| 1414 | |
| 1415 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1416 | xtest_teec_open_session(&sess2, &storage2_ta_uuid, NULL, |
| 1417 | &orig))) |
| 1418 | goto exit2; |
| 1419 | |
| 1420 | /* TA #1 creates a persistent object */ |
| 1421 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1422 | fs_create(&sess, file_01, sizeof(file_01), |
| 1423 | TEE_DATA_FLAG_ACCESS_WRITE | |
| 1424 | TEE_DATA_FLAG_ACCESS_READ | |
| 1425 | TEE_DATA_FLAG_ACCESS_WRITE_META, 0, data_00, |
| 1426 | sizeof(data_00), &obj, storage_id))) |
| 1427 | goto exit; |
| 1428 | |
| 1429 | /* TA #2 tries to open the object created by TA #1 */ |
| 1430 | if (!ADBG_EXPECT_TEEC_RESULT(c, TEEC_ERROR_ITEM_NOT_FOUND, |
| 1431 | fs_open(&sess2, file_01, sizeof(file_01), |
| 1432 | TEE_DATA_FLAG_ACCESS_READ, &obj2, storage_id))) |
| 1433 | goto clean; |
| 1434 | |
| 1435 | if (storage_id == TEE_STORAGE_PRIVATE_REE) { |
| 1436 | /* |
| 1437 | * When the storage backend is the REE filesystem, we can |
| 1438 | * simulate a hack attempt by renaming the TA storage. Should |
| 1439 | * be detected by the TEE. |
| 1440 | */ |
| 1441 | if (rename_data_dir(&uuid, &uuid2) < 0) |
| 1442 | goto clean; |
| 1443 | |
| 1444 | /* TA #2 tries to open the object created by TA #1 */ |
| 1445 | ADBG_EXPECT_TEEC_RESULT(c, TEE_ERROR_CORRUPT_OBJECT, |
| 1446 | fs_open(&sess2, file_01, sizeof(file_01), |
| 1447 | TEE_DATA_FLAG_ACCESS_READ, &obj2, storage_id)); |
| 1448 | /* |
| 1449 | * At this point, the TEE is expected to have removed the |
| 1450 | * corrupt object, so there is no need to try and restore the |
| 1451 | * directory name. |
| 1452 | */ |
| 1453 | goto exit; |
| 1454 | } |
| 1455 | |
| 1456 | clean: |
| 1457 | ADBG_EXPECT_TEEC_SUCCESS(c, fs_unlink(&sess, obj)); |
| 1458 | exit: |
| 1459 | TEEC_CloseSession(&sess2); |
| 1460 | exit2: |
| 1461 | TEEC_CloseSession(&sess); |
| 1462 | } |
| 1463 | |
| 1464 | DEFINE_TEST_MULTIPLE_STORAGE_IDS(xtest_tee_test_6015) |
| 1465 | |
Lijianhui (Airbak) | 29d7c7a | 2016-08-24 17:35:55 +0800 | [diff] [blame] | 1466 | |
| 1467 | struct test_6016_thread_arg { |
| 1468 | ADBG_Case_t *case_t; |
| 1469 | uint32_t storage_id; |
Jerome Forissier | 54cfbef | 2016-08-31 18:34:31 +0200 | [diff] [blame] | 1470 | char file_name[8]; |
Lijianhui (Airbak) | 29d7c7a | 2016-08-24 17:35:55 +0800 | [diff] [blame] | 1471 | TEEC_Session session; |
| 1472 | }; |
| 1473 | |
| 1474 | static void *test_6016_thread(void *arg) |
| 1475 | { |
| 1476 | struct test_6016_thread_arg *a = arg; |
| 1477 | TEEC_Session sess = a->session; |
| 1478 | uint32_t obj; |
| 1479 | uint8_t out[10] = { 0 }; |
| 1480 | uint32_t count; |
| 1481 | |
| 1482 | /* create */ |
| 1483 | if (!ADBG_EXPECT_TEEC_SUCCESS(a->case_t, |
| 1484 | fs_create(&sess, a->file_name, sizeof(a->file_name), |
| 1485 | TEE_DATA_FLAG_ACCESS_WRITE, 0, data_01, |
| 1486 | sizeof(data_01), &obj, a->storage_id))) |
| 1487 | goto exit; |
| 1488 | |
| 1489 | if (!ADBG_EXPECT_TEEC_SUCCESS(a->case_t, fs_close(&sess, obj))) |
| 1490 | goto exit; |
| 1491 | |
| 1492 | /* write new data */ |
| 1493 | if (!ADBG_EXPECT_TEEC_SUCCESS(a->case_t, |
| 1494 | fs_open(&sess, a->file_name, sizeof(a->file_name), |
| 1495 | TEE_DATA_FLAG_ACCESS_WRITE, &obj, a->storage_id))) |
| 1496 | goto exit; |
| 1497 | |
| 1498 | if (!ADBG_EXPECT_TEEC_SUCCESS(a->case_t, |
| 1499 | fs_write(&sess, obj, data_00, sizeof(data_00)))) |
| 1500 | goto exit; |
| 1501 | |
| 1502 | if (!ADBG_EXPECT_TEEC_SUCCESS(a->case_t, fs_close(&sess, obj))) |
| 1503 | goto exit; |
| 1504 | |
| 1505 | /* verify */ |
| 1506 | if (!ADBG_EXPECT_TEEC_SUCCESS(a->case_t, |
| 1507 | fs_open(&sess, a->file_name, sizeof(a->file_name), |
| 1508 | TEE_DATA_FLAG_ACCESS_READ | |
| 1509 | TEE_DATA_FLAG_ACCESS_WRITE_META, &obj, a->storage_id))) |
| 1510 | goto exit; |
| 1511 | |
| 1512 | if (!ADBG_EXPECT_TEEC_SUCCESS(a->case_t, |
| 1513 | fs_read(&sess, obj, out, 10, &count))) |
| 1514 | goto exit; |
| 1515 | |
| 1516 | (void)ADBG_EXPECT_BUFFER(a->case_t, data_00, 10, out, count); |
| 1517 | |
| 1518 | /* clean */ |
| 1519 | if (!ADBG_EXPECT_TEEC_SUCCESS(a->case_t, fs_unlink(&sess, obj))) |
| 1520 | goto exit; |
| 1521 | |
| 1522 | exit: |
| 1523 | return NULL; |
| 1524 | } |
| 1525 | |
| 1526 | |
| 1527 | #define NUM_THREADS 4 |
| 1528 | static void xtest_tee_test_6016_loop(ADBG_Case_t *c, uint32_t storage_id) |
| 1529 | { |
| 1530 | size_t num_threads = NUM_THREADS; |
| 1531 | struct test_6016_thread_arg arg[num_threads]; |
| 1532 | pthread_t thr[num_threads]; |
| 1533 | uint32_t orig; |
| 1534 | size_t i; |
| 1535 | size_t n = 0; |
| 1536 | size_t m; |
| 1537 | |
| 1538 | memset(arg, 0, sizeof(arg)); |
| 1539 | |
| 1540 | for (m = 0; m < num_threads; m++) |
| 1541 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1542 | xtest_teec_open_session(&arg[m].session, |
| 1543 | &storage_ta_uuid, NULL, &orig))) |
| 1544 | goto out; |
| 1545 | |
| 1546 | for (n = 0; n < num_threads; n++) { |
| 1547 | arg[n].case_t = c; |
| 1548 | arg[n].storage_id = storage_id; |
Jerome Forissier | cb10f83 | 2016-09-01 14:53:05 +0200 | [diff] [blame^] | 1549 | snprintf(arg[n].file_name, sizeof(arg[n].file_name), |
Lijianhui (Airbak) | 29d7c7a | 2016-08-24 17:35:55 +0800 | [diff] [blame] | 1550 | "file_%d", n); |
| 1551 | if (!ADBG_EXPECT(c, 0, pthread_create(thr + n, NULL, |
| 1552 | test_6016_thread, arg + n))) |
| 1553 | goto out; |
| 1554 | } |
| 1555 | |
| 1556 | out: |
| 1557 | for (i = 0; i < n; i++) |
| 1558 | ADBG_EXPECT(c, 0, pthread_join(thr[i], NULL)); |
| 1559 | for (i = 0; i < m; i++) |
| 1560 | TEEC_CloseSession(&arg[i].session); |
| 1561 | } |
| 1562 | |
| 1563 | /* concurency */ |
| 1564 | static void xtest_tee_test_6016_single(ADBG_Case_t *c, uint32_t storage_id) |
| 1565 | { |
| 1566 | int i; |
| 1567 | int loops = 8; |
| 1568 | |
| 1569 | Do_ADBG_Log(" threads: %d, loops: %d", NUM_THREADS, loops); |
| 1570 | for (i = 0; i < loops; i++) |
| 1571 | xtest_tee_test_6016_loop(c, storage_id); |
| 1572 | } |
| 1573 | |
| 1574 | /* |
| 1575 | * To be replaced with: DEFINE_TEST_MULTIPLE_STORAGE_IDS(xtest_tee_test_6016) |
| 1576 | * when all filesystems support concurrency |
| 1577 | */ |
| 1578 | static void xtest_tee_test_6016(ADBG_Case_t *c) |
| 1579 | { |
| 1580 | #ifdef CFG_RPMB_FS |
| 1581 | Do_ADBG_BeginSubCase(c, "Storage id: %08x", TEE_STORAGE_PRIVATE_RPMB); |
| 1582 | xtest_tee_test_6016_single(c, TEE_STORAGE_PRIVATE_RPMB); |
| 1583 | Do_ADBG_EndSubCase(c, "Storage id: %08x", TEE_STORAGE_PRIVATE_RPMB); |
| 1584 | #else |
| 1585 | Do_ADBG_Log(" Only RPMB supports concurrency. Test disabled."); |
| 1586 | #endif |
| 1587 | } |
| 1588 | |
| 1589 | |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 1590 | ADBG_CASE_DEFINE( |
| 1591 | XTEST_TEE_6001, xtest_tee_test_6001, |
| 1592 | /* Title */ |
| 1593 | "Test TEE_CreatePersistentObject", |
| 1594 | /* Short description */ |
| 1595 | "Short description ...", |
| 1596 | /* Requirement IDs */ |
| 1597 | "TEE-??", |
| 1598 | /* How to implement */ |
| 1599 | "Description of how to implement ..." |
| 1600 | ); |
| 1601 | |
| 1602 | ADBG_CASE_DEFINE( |
| 1603 | XTEST_TEE_6002, xtest_tee_test_6002, |
| 1604 | /* Title */ |
| 1605 | "Test TEE_OpenPersistentObject", |
| 1606 | /* Short description */ |
| 1607 | "Short description ...", |
| 1608 | /* Requirement IDs */ |
| 1609 | "TEE-??", |
| 1610 | /* How to implement */ |
| 1611 | "Description of how to implement ..." |
| 1612 | ); |
| 1613 | |
| 1614 | ADBG_CASE_DEFINE( |
| 1615 | XTEST_TEE_6003, xtest_tee_test_6003, |
| 1616 | /* Title */ |
| 1617 | "Test TEE_ReadObjectData", |
| 1618 | /* Short description */ |
| 1619 | "Short description ...", |
| 1620 | /* Requirement IDs */ |
| 1621 | "TEE-??", |
| 1622 | /* How to implement */ |
| 1623 | "Description of how to implement ..." |
| 1624 | ); |
| 1625 | |
| 1626 | ADBG_CASE_DEFINE( |
| 1627 | XTEST_TEE_6004, xtest_tee_test_6004, |
| 1628 | /* Title */ |
| 1629 | "Test TEE_WriteObjectData", |
| 1630 | /* Short description */ |
| 1631 | "Short description ...", |
| 1632 | /* Requirement IDs */ |
| 1633 | "TEE-??", |
| 1634 | /* How to implement */ |
| 1635 | "Description of how to implement ..." |
| 1636 | ); |
| 1637 | |
| 1638 | ADBG_CASE_DEFINE( |
| 1639 | XTEST_TEE_6005, xtest_tee_test_6005, |
| 1640 | /* Title */ |
| 1641 | "Test TEE_SeekObjectData", |
| 1642 | /* Short description */ |
| 1643 | "Short description ...", |
| 1644 | /* Requirement IDs */ |
| 1645 | "TEE-??", |
| 1646 | /* How to implement */ |
| 1647 | "Description of how to implement ..." |
| 1648 | ); |
| 1649 | |
| 1650 | ADBG_CASE_DEFINE( |
| 1651 | XTEST_TEE_6006, xtest_tee_test_6006, |
| 1652 | /* Title */ |
| 1653 | "Test TEE_CloseAndDeletePersistentObject", |
| 1654 | /* Short description */ |
| 1655 | "Short description ...", |
| 1656 | /* Requirement IDs */ |
| 1657 | "TEE-??", |
| 1658 | /* How to implement */ |
| 1659 | "Description of how to implement ..." |
| 1660 | ); |
| 1661 | |
| 1662 | ADBG_CASE_DEFINE( |
| 1663 | XTEST_TEE_6007, xtest_tee_test_6007, |
| 1664 | /* Title */ |
| 1665 | "Test TEE_TruncateObjectData", |
| 1666 | /* Short description */ |
| 1667 | "Short description ...", |
| 1668 | /* Requirement IDs */ |
| 1669 | "TEE-??", |
| 1670 | /* How to implement */ |
| 1671 | "Description of how to implement ..." |
| 1672 | ); |
| 1673 | |
| 1674 | ADBG_CASE_DEFINE( |
| 1675 | XTEST_TEE_6008, xtest_tee_test_6008, |
| 1676 | /* Title */ |
| 1677 | "Test TEE_RenamePersistentObject", |
| 1678 | /* Short description */ |
| 1679 | "Short description ...", |
| 1680 | /* Requirement IDs */ |
| 1681 | "TEE-??", |
| 1682 | /* How to implement */ |
| 1683 | "Description of how to implement ..." |
| 1684 | ); |
| 1685 | |
| 1686 | ADBG_CASE_DEFINE( |
| 1687 | XTEST_TEE_6009, xtest_tee_test_6009, |
| 1688 | /* Title */ |
| 1689 | "Test TEE Internal API Persistent Object Enumeration Functions", |
| 1690 | /* Short description */ |
| 1691 | "Short description ...", |
| 1692 | /* Requirement IDs */ |
| 1693 | "TEE-??", |
| 1694 | /* How to implement */ |
| 1695 | "Description of how to implement ..." |
| 1696 | ); |
Pascal Brand | 8a74e36 | 2015-09-10 12:41:52 +0200 | [diff] [blame] | 1697 | |
Jerome Forissier | e368834 | 2015-09-24 10:45:17 -0700 | [diff] [blame] | 1698 | #ifdef WITH_GP_TESTS |
Pascal Brand | 8a74e36 | 2015-09-10 12:41:52 +0200 | [diff] [blame] | 1699 | ADBG_CASE_DEFINE( |
| 1700 | XTEST_TEE_6010, xtest_tee_test_6010, |
| 1701 | /* Title */ |
| 1702 | "Test TEE GP TTA DS storage", |
| 1703 | /* Short description */ |
| 1704 | "Short description ...", |
| 1705 | /* Requirement IDs */ |
| 1706 | "TEE-??", |
| 1707 | /* How to implement */ |
| 1708 | "Description of how to implement ..." |
| 1709 | ); |
| 1710 | |
| 1711 | ADBG_CASE_DEFINE( |
| 1712 | XTEST_TEE_6011, xtest_tee_test_6011, |
| 1713 | /* Title */ |
| 1714 | "Test TEE GP TTA DS init objects", |
| 1715 | /* Short description */ |
| 1716 | "Short description ...", |
| 1717 | /* Requirement IDs */ |
| 1718 | "TEE-??", |
| 1719 | /* How to implement */ |
| 1720 | "Description of how to implement ..." |
| 1721 | ); |
| 1722 | #endif |
Pascal Brand | eb84c44 | 2016-04-19 17:49:49 +0200 | [diff] [blame] | 1723 | |
| 1724 | ADBG_CASE_DEFINE( |
| 1725 | XTEST_TEE_6012, xtest_tee_test_6012, |
| 1726 | /* Title */ |
| 1727 | "Test TEE GP TTA DS init objects", |
| 1728 | /* Short description */ |
| 1729 | "Short description ...", |
| 1730 | /* Requirement IDs */ |
| 1731 | "TEE-??", |
| 1732 | /* How to implement */ |
| 1733 | "Description of how to implement ..." |
| 1734 | ); |
Pascal Brand | 90f2335 | 2016-05-19 15:15:47 +0200 | [diff] [blame] | 1735 | |
| 1736 | ADBG_CASE_DEFINE( |
| 1737 | XTEST_TEE_6013, xtest_tee_test_6013, |
| 1738 | /* Title */ |
| 1739 | "Key usage in Persistent objects", |
| 1740 | /* Short description */ |
| 1741 | "Short description ...", |
| 1742 | /* Requirement IDs */ |
| 1743 | "TEE-??", |
| 1744 | /* How to implement */ |
| 1745 | "Description of how to implement ..." |
| 1746 | ); |
Pascal Brand | 29ee18f | 2016-05-23 14:13:56 +0200 | [diff] [blame] | 1747 | |
| 1748 | ADBG_CASE_DEFINE( |
| 1749 | XTEST_TEE_6014, xtest_tee_test_6014, |
| 1750 | /* Title */ |
| 1751 | "Loop on Persistent objects", |
| 1752 | /* Short description */ |
| 1753 | "Short description ...", |
| 1754 | /* Requirement IDs */ |
| 1755 | "TEE-??", |
| 1756 | /* How to implement */ |
| 1757 | "Description of how to implement ..." |
| 1758 | ); |
Jerome Forissier | e385416 | 2016-08-12 12:40:12 +0200 | [diff] [blame] | 1759 | |
| 1760 | ADBG_CASE_DEFINE( |
| 1761 | XTEST_TEE_6015, xtest_tee_test_6015, |
| 1762 | /* Title */ |
| 1763 | "Storage isolation", |
| 1764 | /* Short description */ |
| 1765 | "TA #2 tries to open object created by TA #1, should fail", |
| 1766 | /* Requirement IDs */ |
| 1767 | "", |
| 1768 | /* How to implement */ |
| 1769 | "" |
| 1770 | ); |
Lijianhui (Airbak) | 29d7c7a | 2016-08-24 17:35:55 +0800 | [diff] [blame] | 1771 | |
| 1772 | ADBG_CASE_DEFINE( |
| 1773 | XTEST_TEE_6016, xtest_tee_test_6016, |
| 1774 | /* Title */ |
| 1775 | "Storage concurency", |
| 1776 | /* Short description */ |
| 1777 | "Multiple thread operate secure storage", |
| 1778 | /* Requirement IDs */ |
| 1779 | "", |
| 1780 | /* How to implement */ |
| 1781 | "" |
| 1782 | ); |