Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 1 | /* |
Jens Wiklander | 02389a9 | 2016-12-16 11:13:38 +0100 | [diff] [blame] | 2 | * Copyright (c) 2016, Linaro Limited |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 3 | * Copyright (c) 2014, STMicroelectronics International N.V. |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License Version 2 as |
| 7 | * published by the Free Software Foundation. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | */ |
| 14 | |
Jens Wiklander | 02389a9 | 2016-12-16 11:13:38 +0100 | [diff] [blame] | 15 | #include <err.h> |
Etienne Carriere | 7d18f55 | 2017-04-04 09:46:29 +0200 | [diff] [blame] | 16 | #include <inttypes.h> |
Jens Wiklander | 02389a9 | 2016-12-16 11:13:38 +0100 | [diff] [blame] | 17 | #include <signal.h> |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 18 | #include <stdio.h> |
Cedric Chaumont | c3b6c28 | 2015-09-25 03:05:18 +0200 | [diff] [blame] | 19 | #include <stdlib.h> |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 20 | #include <string.h> |
Cedric Chaumont | c3b6c28 | 2015-09-25 03:05:18 +0200 | [diff] [blame] | 21 | #include <unistd.h> |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 22 | |
Jens Wiklander | 6f34e00 | 2018-05-03 21:21:54 +0200 | [diff] [blame] | 23 | #ifdef OPENSSL_FOUND |
| 24 | #include <openssl/crypto.h> |
| 25 | #include <openssl/err.h> |
| 26 | #include <openssl/evp.h> |
| 27 | #endif |
| 28 | |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 29 | #include <adbg.h> |
| 30 | #include "xtest_test.h" |
| 31 | #include "xtest_helpers.h" |
Igor Opaniuk | 136644a | 2016-09-13 13:40:56 +0300 | [diff] [blame] | 32 | |
| 33 | /* include here shandalone tests */ |
Igor Opaniuk | f9b7fd2 | 2016-09-16 16:22:34 +0300 | [diff] [blame] | 34 | #include "crypto_common.h" |
Jens Wiklander | f261a6d | 2017-11-09 16:45:51 +0100 | [diff] [blame] | 35 | #include "install_ta.h" |
Jens Wiklander | 254a3e3 | 2019-01-31 12:25:08 +0100 | [diff] [blame^] | 36 | #include "stats.h" |
Igor Opaniuk | 136644a | 2016-09-13 13:40:56 +0300 | [diff] [blame] | 37 | |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 38 | |
Jens Wiklander | 74abfe3 | 2017-01-03 14:17:47 +0100 | [diff] [blame] | 39 | ADBG_SUITE_DEFINE(benchmark); |
Jerome Forissier | 213ca8a | 2017-03-31 11:27:56 +0200 | [diff] [blame] | 40 | #ifdef WITH_GP_TESTS |
| 41 | ADBG_SUITE_DEFINE(gp); |
| 42 | #endif |
| 43 | ADBG_SUITE_DEFINE(regression); |
Igor Opaniuk | 136644a | 2016-09-13 13:40:56 +0300 | [diff] [blame] | 44 | |
Jens Wiklander | 2190cdc | 2015-03-31 13:37:09 +0200 | [diff] [blame] | 45 | char *_device = NULL; |
Cedric Chaumont | c3b6c28 | 2015-09-25 03:05:18 +0200 | [diff] [blame] | 46 | unsigned int level = 0; |
| 47 | static const char glevel[] = "0"; |
Jerome Forissier | 213ca8a | 2017-03-31 11:27:56 +0200 | [diff] [blame] | 48 | #ifdef WITH_GP_TESTS |
| 49 | static char gsuitename[] = "regression+gp"; |
| 50 | #else |
| 51 | static char gsuitename[] = "regression"; |
| 52 | #endif |
Cedric Chaumont | c3b6c28 | 2015-09-25 03:05:18 +0200 | [diff] [blame] | 53 | |
| 54 | void usage(char *program); |
| 55 | |
| 56 | void usage(char *program) |
| 57 | { |
| 58 | printf("Usage: %s <options> <test_id>\n", program); |
| 59 | printf("\n"); |
| 60 | printf("options:\n"); |
Jerome Forissier | 213ca8a | 2017-03-31 11:27:56 +0200 | [diff] [blame] | 61 | printf("\t-d <device-type> TEE device path. Default not set (use any)\n"); |
| 62 | printf("\t-l <level> Test level [0-15]. Values higher than 0 enable\n"); |
| 63 | printf("\t optional tests. Default: 0. All tests: 15.\n"); |
| 64 | printf("\t-t <test_suite> Available test suites: regression benchmark"); |
| 65 | #ifdef WITH_GP_TESTS |
| 66 | printf(" gp"); |
| 67 | #endif |
| 68 | printf("\n"); |
| 69 | printf("\t To run several suites, use multiple names\n"); |
| 70 | printf("\t separated by a '+')\n"); |
| 71 | printf("\t Default value: '%s'\n", gsuitename); |
| 72 | printf("\t-h Show usage\n"); |
Igor Opaniuk | 136644a | 2016-09-13 13:40:56 +0300 | [diff] [blame] | 73 | printf("applets:\n"); |
Jerome Forissier | 213ca8a | 2017-03-31 11:27:56 +0200 | [diff] [blame] | 74 | printf("\t--sha-perf [opts] SHA performance testing tool (-h for usage)\n"); |
| 75 | printf("\t--aes-perf [opts] AES performance testing tool (-h for usage)\n"); |
Jens Wiklander | f261a6d | 2017-11-09 16:45:51 +0100 | [diff] [blame] | 76 | #ifdef CFG_SECSTOR_TA_MGMT_PTA |
| 77 | printf("\t--install-ta [directory or list of TAs]\n"); |
| 78 | printf("\t Install TAs\n"); |
| 79 | #endif |
Etienne Carriere | 41343db | 2017-03-17 15:38:52 +0100 | [diff] [blame] | 80 | #ifdef CFG_SECURE_DATA_PATH |
Jerome Forissier | 213ca8a | 2017-03-31 11:27:56 +0200 | [diff] [blame] | 81 | printf("\t--sdp-basic [opts] Basic Secure Data Path test setup ('-h' for usage)\n"); |
Etienne Carriere | 41343db | 2017-03-17 15:38:52 +0100 | [diff] [blame] | 82 | #endif |
Jens Wiklander | 254a3e3 | 2019-01-31 12:25:08 +0100 | [diff] [blame^] | 83 | printf("\t--stats [opts] Various statistics ('-h' for usage)\n"); |
Etienne Carriere | 41343db | 2017-03-17 15:38:52 +0100 | [diff] [blame] | 84 | printf("\n"); |
Cedric Chaumont | c3b6c28 | 2015-09-25 03:05:18 +0200 | [diff] [blame] | 85 | } |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 86 | |
Jens Wiklander | 6f34e00 | 2018-05-03 21:21:54 +0200 | [diff] [blame] | 87 | static void init_ossl(void) |
| 88 | { |
| 89 | #ifdef OPENSSL_FOUND |
| 90 | OPENSSL_init(); |
| 91 | OpenSSL_add_all_algorithms(); |
| 92 | ERR_load_crypto_strings(); |
| 93 | #endif |
| 94 | } |
| 95 | |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 96 | int main(int argc, char *argv[]) |
| 97 | { |
Cedric Chaumont | c3b6c28 | 2015-09-25 03:05:18 +0200 | [diff] [blame] | 98 | int opt; |
| 99 | int index; |
Etienne Carriere | 69f914d | 2017-04-03 13:57:46 +0200 | [diff] [blame] | 100 | TEEC_Result tee_res; |
Cedric Chaumont | c3b6c28 | 2015-09-25 03:05:18 +0200 | [diff] [blame] | 101 | int ret; |
| 102 | char *p = (char *)glevel; |
James Kung | 35b352d | 2015-09-07 18:01:16 +0800 | [diff] [blame] | 103 | char *test_suite = (char *)gsuitename; |
Jerome Forissier | 213ca8a | 2017-03-31 11:27:56 +0200 | [diff] [blame] | 104 | char *token; |
| 105 | ADBG_Suite_Definition_t all = { .SuiteID_p = NULL, |
| 106 | .cases = TAILQ_HEAD_INITIALIZER(all.cases), }; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 107 | |
James Kung | 35b352d | 2015-09-07 18:01:16 +0800 | [diff] [blame] | 108 | opterr = 0; |
| 109 | |
Jens Wiklander | 02389a9 | 2016-12-16 11:13:38 +0100 | [diff] [blame] | 110 | if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) |
| 111 | warn("signal(SIGPIPE, SIG_IGN)"); |
| 112 | |
| 113 | if (signal(SIGHUP, SIG_IGN) == SIG_ERR) |
| 114 | warn("signal(SIGPIPE, SIG_IGN)"); |
| 115 | |
Jens Wiklander | 6f34e00 | 2018-05-03 21:21:54 +0200 | [diff] [blame] | 116 | init_ossl(); |
| 117 | |
Igor Opaniuk | 44aff4b | 2016-09-16 10:18:00 +0300 | [diff] [blame] | 118 | if (argc > 1 && !strcmp(argv[1], "--sha-perf")) |
Igor Opaniuk | 136644a | 2016-09-13 13:40:56 +0300 | [diff] [blame] | 119 | return sha_perf_runner_cmd_parser(argc-1, &argv[1]); |
Igor Opaniuk | 44aff4b | 2016-09-16 10:18:00 +0300 | [diff] [blame] | 120 | else if (argc > 1 && !strcmp(argv[1], "--aes-perf")) |
| 121 | return aes_perf_runner_cmd_parser(argc-1, &argv[1]); |
Jens Wiklander | f261a6d | 2017-11-09 16:45:51 +0100 | [diff] [blame] | 122 | #ifdef CFG_SECSTOR_TA_MGMT_PTA |
| 123 | else if (argc > 1 && !strcmp(argv[1], "--install-ta")) |
| 124 | return install_ta_runner_cmd_parser(argc - 1, argv + 1); |
| 125 | #endif |
Etienne Carriere | 41343db | 2017-03-17 15:38:52 +0100 | [diff] [blame] | 126 | #ifdef CFG_SECURE_DATA_PATH |
| 127 | else if (argc > 1 && !strcmp(argv[1], "--sdp-basic")) |
| 128 | return sdp_basic_runner_cmd_parser(argc-1, &argv[1]); |
| 129 | #endif |
Jens Wiklander | 254a3e3 | 2019-01-31 12:25:08 +0100 | [diff] [blame^] | 130 | else if (argc > 1 && !strcmp(argv[1], "--stats")) |
| 131 | return stats_runner_cmd_parser(argc - 1, &argv[1]); |
Igor Opaniuk | 136644a | 2016-09-13 13:40:56 +0300 | [diff] [blame] | 132 | |
James Kung | 35b352d | 2015-09-07 18:01:16 +0800 | [diff] [blame] | 133 | while ((opt = getopt(argc, argv, "d:l:t:h")) != -1) |
Cedric Chaumont | c3b6c28 | 2015-09-25 03:05:18 +0200 | [diff] [blame] | 134 | switch (opt) { |
| 135 | case 'd': |
| 136 | _device = optarg; |
| 137 | break; |
| 138 | case 'l': |
| 139 | p = optarg; |
| 140 | break; |
James Kung | 35b352d | 2015-09-07 18:01:16 +0800 | [diff] [blame] | 141 | case 't': |
| 142 | test_suite = optarg; |
| 143 | break; |
Cedric Chaumont | c3b6c28 | 2015-09-25 03:05:18 +0200 | [diff] [blame] | 144 | case 'h': |
| 145 | usage(argv[0]); |
| 146 | return 0; |
| 147 | default: |
| 148 | usage(argv[0]); |
| 149 | return -1; |
| 150 | } |
Cedric Chaumont | c3b6c28 | 2015-09-25 03:05:18 +0200 | [diff] [blame] | 151 | |
| 152 | for (index = optind; index < argc; index++) |
| 153 | printf("Test ID: %s\n", argv[index]); |
| 154 | |
| 155 | if (p) |
| 156 | level = atoi(p); |
| 157 | else |
| 158 | level = 0; |
| 159 | printf("Run test suite with level=%d\n", level); |
| 160 | |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 161 | printf("\nTEE test application started with device [%s]\n", _device); |
| 162 | |
Etienne Carriere | 69f914d | 2017-04-03 13:57:46 +0200 | [diff] [blame] | 163 | tee_res = xtest_teec_ctx_init(); |
| 164 | if (tee_res != TEEC_SUCCESS) { |
Etienne Carriere | 7d18f55 | 2017-04-04 09:46:29 +0200 | [diff] [blame] | 165 | fprintf(stderr, "Failed to open TEE context: 0x%" PRIx32 "\n", |
| 166 | tee_res); |
Etienne Carriere | 69f914d | 2017-04-03 13:57:46 +0200 | [diff] [blame] | 167 | return -1; |
| 168 | } |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 169 | |
Jerome Forissier | 213ca8a | 2017-03-31 11:27:56 +0200 | [diff] [blame] | 170 | /* Concatenate all the selected suites into 'all' */ |
| 171 | for (token = test_suite; ; token = NULL) { |
| 172 | |
| 173 | token = strtok(token, "+"); |
| 174 | if (!token) |
| 175 | break; |
| 176 | |
| 177 | if (!strcmp(token, "regression")) |
| 178 | ret = Do_ADBG_AppendToSuite(&all, &ADBG_Suite_regression); |
| 179 | else if (!strcmp(token, "benchmark")) |
| 180 | ret = Do_ADBG_AppendToSuite(&all, &ADBG_Suite_benchmark); |
| 181 | #ifdef WITH_GP_TESTS |
| 182 | else if (!strcmp(token, "gp")) |
| 183 | ret = Do_ADBG_AppendToSuite(&all, &ADBG_Suite_gp); |
| 184 | #endif |
| 185 | else { |
| 186 | fprintf(stderr, "Unkown test suite: %s\n", token); |
| 187 | ret = -1; |
| 188 | } |
| 189 | if (ret < 0) |
| 190 | goto err; |
James Kung | 35b352d | 2015-09-07 18:01:16 +0800 | [diff] [blame] | 191 | } |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 192 | |
Jerome Forissier | 213ca8a | 2017-03-31 11:27:56 +0200 | [diff] [blame] | 193 | /* Run the tests */ |
| 194 | ret = Do_ADBG_RunSuite(&all, argc - optind, argv + optind); |
| 195 | |
| 196 | err: |
| 197 | free((void *)all.SuiteID_p); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 198 | xtest_teec_ctx_deinit(); |
| 199 | |
| 200 | printf("TEE test application done!\n"); |
| 201 | return ret; |
| 202 | } |