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 | |
| 23 | #include <adbg.h> |
| 24 | #include "xtest_test.h" |
| 25 | #include "xtest_helpers.h" |
Igor Opaniuk | 136644a | 2016-09-13 13:40:56 +0300 | [diff] [blame] | 26 | |
| 27 | /* include here shandalone tests */ |
Igor Opaniuk | f9b7fd2 | 2016-09-16 16:22:34 +0300 | [diff] [blame] | 28 | #include "crypto_common.h" |
Jens Wiklander | f261a6d | 2017-11-09 16:45:51 +0100 | [diff] [blame] | 29 | #include "install_ta.h" |
Igor Opaniuk | 136644a | 2016-09-13 13:40:56 +0300 | [diff] [blame] | 30 | |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 31 | |
Jens Wiklander | 74abfe3 | 2017-01-03 14:17:47 +0100 | [diff] [blame] | 32 | ADBG_SUITE_DEFINE(benchmark); |
Jerome Forissier | 213ca8a | 2017-03-31 11:27:56 +0200 | [diff] [blame] | 33 | #ifdef WITH_GP_TESTS |
| 34 | ADBG_SUITE_DEFINE(gp); |
| 35 | #endif |
| 36 | ADBG_SUITE_DEFINE(regression); |
Igor Opaniuk | 136644a | 2016-09-13 13:40:56 +0300 | [diff] [blame] | 37 | |
Jens Wiklander | 2190cdc | 2015-03-31 13:37:09 +0200 | [diff] [blame] | 38 | char *_device = NULL; |
Cedric Chaumont | c3b6c28 | 2015-09-25 03:05:18 +0200 | [diff] [blame] | 39 | unsigned int level = 0; |
| 40 | static const char glevel[] = "0"; |
Jerome Forissier | 213ca8a | 2017-03-31 11:27:56 +0200 | [diff] [blame] | 41 | #ifdef WITH_GP_TESTS |
| 42 | static char gsuitename[] = "regression+gp"; |
| 43 | #else |
| 44 | static char gsuitename[] = "regression"; |
| 45 | #endif |
Cedric Chaumont | c3b6c28 | 2015-09-25 03:05:18 +0200 | [diff] [blame] | 46 | |
| 47 | void usage(char *program); |
| 48 | |
| 49 | void usage(char *program) |
| 50 | { |
| 51 | printf("Usage: %s <options> <test_id>\n", program); |
| 52 | printf("\n"); |
| 53 | printf("options:\n"); |
Jerome Forissier | 213ca8a | 2017-03-31 11:27:56 +0200 | [diff] [blame] | 54 | printf("\t-d <device-type> TEE device path. Default not set (use any)\n"); |
| 55 | printf("\t-l <level> Test level [0-15]. Values higher than 0 enable\n"); |
| 56 | printf("\t optional tests. Default: 0. All tests: 15.\n"); |
| 57 | printf("\t-t <test_suite> Available test suites: regression benchmark"); |
| 58 | #ifdef WITH_GP_TESTS |
| 59 | printf(" gp"); |
| 60 | #endif |
| 61 | printf("\n"); |
| 62 | printf("\t To run several suites, use multiple names\n"); |
| 63 | printf("\t separated by a '+')\n"); |
| 64 | printf("\t Default value: '%s'\n", gsuitename); |
| 65 | printf("\t-h Show usage\n"); |
Igor Opaniuk | 136644a | 2016-09-13 13:40:56 +0300 | [diff] [blame] | 66 | printf("applets:\n"); |
Jerome Forissier | 213ca8a | 2017-03-31 11:27:56 +0200 | [diff] [blame] | 67 | printf("\t--sha-perf [opts] SHA performance testing tool (-h for usage)\n"); |
| 68 | 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] | 69 | #ifdef CFG_SECSTOR_TA_MGMT_PTA |
| 70 | printf("\t--install-ta [directory or list of TAs]\n"); |
| 71 | printf("\t Install TAs\n"); |
| 72 | #endif |
Etienne Carriere | 41343db | 2017-03-17 15:38:52 +0100 | [diff] [blame] | 73 | #ifdef CFG_SECURE_DATA_PATH |
Jerome Forissier | 213ca8a | 2017-03-31 11:27:56 +0200 | [diff] [blame] | 74 | 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] | 75 | #endif |
| 76 | printf("\n"); |
Cedric Chaumont | c3b6c28 | 2015-09-25 03:05:18 +0200 | [diff] [blame] | 77 | } |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 78 | |
| 79 | int main(int argc, char *argv[]) |
| 80 | { |
Cedric Chaumont | c3b6c28 | 2015-09-25 03:05:18 +0200 | [diff] [blame] | 81 | int opt; |
| 82 | int index; |
Etienne Carriere | 69f914d | 2017-04-03 13:57:46 +0200 | [diff] [blame] | 83 | TEEC_Result tee_res; |
Cedric Chaumont | c3b6c28 | 2015-09-25 03:05:18 +0200 | [diff] [blame] | 84 | int ret; |
| 85 | char *p = (char *)glevel; |
James Kung | 35b352d | 2015-09-07 18:01:16 +0800 | [diff] [blame] | 86 | char *test_suite = (char *)gsuitename; |
Jerome Forissier | 213ca8a | 2017-03-31 11:27:56 +0200 | [diff] [blame] | 87 | char *token; |
| 88 | ADBG_Suite_Definition_t all = { .SuiteID_p = NULL, |
| 89 | .cases = TAILQ_HEAD_INITIALIZER(all.cases), }; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 90 | |
James Kung | 35b352d | 2015-09-07 18:01:16 +0800 | [diff] [blame] | 91 | opterr = 0; |
| 92 | |
Jens Wiklander | 02389a9 | 2016-12-16 11:13:38 +0100 | [diff] [blame] | 93 | if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) |
| 94 | warn("signal(SIGPIPE, SIG_IGN)"); |
| 95 | |
| 96 | if (signal(SIGHUP, SIG_IGN) == SIG_ERR) |
| 97 | warn("signal(SIGPIPE, SIG_IGN)"); |
| 98 | |
Igor Opaniuk | 44aff4b | 2016-09-16 10:18:00 +0300 | [diff] [blame] | 99 | if (argc > 1 && !strcmp(argv[1], "--sha-perf")) |
Igor Opaniuk | 136644a | 2016-09-13 13:40:56 +0300 | [diff] [blame] | 100 | return sha_perf_runner_cmd_parser(argc-1, &argv[1]); |
Igor Opaniuk | 44aff4b | 2016-09-16 10:18:00 +0300 | [diff] [blame] | 101 | else if (argc > 1 && !strcmp(argv[1], "--aes-perf")) |
| 102 | return aes_perf_runner_cmd_parser(argc-1, &argv[1]); |
Jens Wiklander | f261a6d | 2017-11-09 16:45:51 +0100 | [diff] [blame] | 103 | #ifdef CFG_SECSTOR_TA_MGMT_PTA |
| 104 | else if (argc > 1 && !strcmp(argv[1], "--install-ta")) |
| 105 | return install_ta_runner_cmd_parser(argc - 1, argv + 1); |
| 106 | #endif |
Etienne Carriere | 41343db | 2017-03-17 15:38:52 +0100 | [diff] [blame] | 107 | #ifdef CFG_SECURE_DATA_PATH |
| 108 | else if (argc > 1 && !strcmp(argv[1], "--sdp-basic")) |
| 109 | return sdp_basic_runner_cmd_parser(argc-1, &argv[1]); |
| 110 | #endif |
Igor Opaniuk | 136644a | 2016-09-13 13:40:56 +0300 | [diff] [blame] | 111 | |
James Kung | 35b352d | 2015-09-07 18:01:16 +0800 | [diff] [blame] | 112 | while ((opt = getopt(argc, argv, "d:l:t:h")) != -1) |
Cedric Chaumont | c3b6c28 | 2015-09-25 03:05:18 +0200 | [diff] [blame] | 113 | switch (opt) { |
| 114 | case 'd': |
| 115 | _device = optarg; |
| 116 | break; |
| 117 | case 'l': |
| 118 | p = optarg; |
| 119 | break; |
James Kung | 35b352d | 2015-09-07 18:01:16 +0800 | [diff] [blame] | 120 | case 't': |
| 121 | test_suite = optarg; |
| 122 | break; |
Cedric Chaumont | c3b6c28 | 2015-09-25 03:05:18 +0200 | [diff] [blame] | 123 | case 'h': |
| 124 | usage(argv[0]); |
| 125 | return 0; |
| 126 | default: |
| 127 | usage(argv[0]); |
| 128 | return -1; |
| 129 | } |
Cedric Chaumont | c3b6c28 | 2015-09-25 03:05:18 +0200 | [diff] [blame] | 130 | |
| 131 | for (index = optind; index < argc; index++) |
| 132 | printf("Test ID: %s\n", argv[index]); |
| 133 | |
| 134 | if (p) |
| 135 | level = atoi(p); |
| 136 | else |
| 137 | level = 0; |
| 138 | printf("Run test suite with level=%d\n", level); |
| 139 | |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 140 | printf("\nTEE test application started with device [%s]\n", _device); |
| 141 | |
Etienne Carriere | 69f914d | 2017-04-03 13:57:46 +0200 | [diff] [blame] | 142 | tee_res = xtest_teec_ctx_init(); |
| 143 | if (tee_res != TEEC_SUCCESS) { |
Etienne Carriere | 7d18f55 | 2017-04-04 09:46:29 +0200 | [diff] [blame] | 144 | fprintf(stderr, "Failed to open TEE context: 0x%" PRIx32 "\n", |
| 145 | tee_res); |
Etienne Carriere | 69f914d | 2017-04-03 13:57:46 +0200 | [diff] [blame] | 146 | return -1; |
| 147 | } |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 148 | |
Jerome Forissier | 213ca8a | 2017-03-31 11:27:56 +0200 | [diff] [blame] | 149 | /* Concatenate all the selected suites into 'all' */ |
| 150 | for (token = test_suite; ; token = NULL) { |
| 151 | |
| 152 | token = strtok(token, "+"); |
| 153 | if (!token) |
| 154 | break; |
| 155 | |
| 156 | if (!strcmp(token, "regression")) |
| 157 | ret = Do_ADBG_AppendToSuite(&all, &ADBG_Suite_regression); |
| 158 | else if (!strcmp(token, "benchmark")) |
| 159 | ret = Do_ADBG_AppendToSuite(&all, &ADBG_Suite_benchmark); |
| 160 | #ifdef WITH_GP_TESTS |
| 161 | else if (!strcmp(token, "gp")) |
| 162 | ret = Do_ADBG_AppendToSuite(&all, &ADBG_Suite_gp); |
| 163 | #endif |
| 164 | else { |
| 165 | fprintf(stderr, "Unkown test suite: %s\n", token); |
| 166 | ret = -1; |
| 167 | } |
| 168 | if (ret < 0) |
| 169 | goto err; |
James Kung | 35b352d | 2015-09-07 18:01:16 +0800 | [diff] [blame] | 170 | } |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 171 | |
Jerome Forissier | 213ca8a | 2017-03-31 11:27:56 +0200 | [diff] [blame] | 172 | /* Run the tests */ |
| 173 | ret = Do_ADBG_RunSuite(&all, argc - optind, argv + optind); |
| 174 | |
| 175 | err: |
| 176 | free((void *)all.SuiteID_p); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 177 | xtest_teec_ctx_deinit(); |
| 178 | |
| 179 | printf("TEE test application done!\n"); |
| 180 | return ret; |
| 181 | } |