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