blob: f9cdbb123b7f5fb97a9de2a5412fe6f081ca0593 [file] [log] [blame]
Pascal Brandc639ac82015-07-02 08:53:34 +02001/*
Jens Wiklander02389a92016-12-16 11:13:38 +01002 * Copyright (c) 2016, Linaro Limited
Pascal Brandc639ac82015-07-02 08:53:34 +02003 * 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 Wiklander02389a92016-12-16 11:13:38 +010015#include <err.h>
Etienne Carriere7d18f552017-04-04 09:46:29 +020016#include <inttypes.h>
Jens Wiklander02389a92016-12-16 11:13:38 +010017#include <signal.h>
Pascal Brandc639ac82015-07-02 08:53:34 +020018#include <stdio.h>
Cedric Chaumontc3b6c282015-09-25 03:05:18 +020019#include <stdlib.h>
Pascal Brandc639ac82015-07-02 08:53:34 +020020#include <string.h>
Cedric Chaumontc3b6c282015-09-25 03:05:18 +020021#include <unistd.h>
Pascal Brandc639ac82015-07-02 08:53:34 +020022
Jens Wiklander6f34e002018-05-03 21:21:54 +020023#ifdef OPENSSL_FOUND
24#include <openssl/crypto.h>
25#include <openssl/err.h>
26#include <openssl/evp.h>
27#endif
28
Pascal Brandc639ac82015-07-02 08:53:34 +020029#include <adbg.h>
30#include "xtest_test.h"
31#include "xtest_helpers.h"
Igor Opaniuk136644a2016-09-13 13:40:56 +030032
33/* include here shandalone tests */
Igor Opaniukf9b7fd22016-09-16 16:22:34 +030034#include "crypto_common.h"
Jens Wiklanderf261a6d2017-11-09 16:45:51 +010035#include "install_ta.h"
Igor Opaniuk136644a2016-09-13 13:40:56 +030036
Pascal Brandc639ac82015-07-02 08:53:34 +020037
Jens Wiklander74abfe32017-01-03 14:17:47 +010038ADBG_SUITE_DEFINE(benchmark);
Jerome Forissier213ca8a2017-03-31 11:27:56 +020039#ifdef WITH_GP_TESTS
40ADBG_SUITE_DEFINE(gp);
41#endif
42ADBG_SUITE_DEFINE(regression);
Igor Opaniuk136644a2016-09-13 13:40:56 +030043
Jens Wiklander2190cdc2015-03-31 13:37:09 +020044char *_device = NULL;
Cedric Chaumontc3b6c282015-09-25 03:05:18 +020045unsigned int level = 0;
46static const char glevel[] = "0";
Jerome Forissier213ca8a2017-03-31 11:27:56 +020047#ifdef WITH_GP_TESTS
48static char gsuitename[] = "regression+gp";
49#else
50static char gsuitename[] = "regression";
51#endif
Cedric Chaumontc3b6c282015-09-25 03:05:18 +020052
53void usage(char *program);
54
55void usage(char *program)
56{
57 printf("Usage: %s <options> <test_id>\n", program);
58 printf("\n");
59 printf("options:\n");
Jerome Forissier213ca8a2017-03-31 11:27:56 +020060 printf("\t-d <device-type> TEE device path. Default not set (use any)\n");
61 printf("\t-l <level> Test level [0-15]. Values higher than 0 enable\n");
62 printf("\t optional tests. Default: 0. All tests: 15.\n");
63 printf("\t-t <test_suite> Available test suites: regression benchmark");
64#ifdef WITH_GP_TESTS
65 printf(" gp");
66#endif
67 printf("\n");
68 printf("\t To run several suites, use multiple names\n");
69 printf("\t separated by a '+')\n");
70 printf("\t Default value: '%s'\n", gsuitename);
71 printf("\t-h Show usage\n");
Igor Opaniuk136644a2016-09-13 13:40:56 +030072 printf("applets:\n");
Jerome Forissier213ca8a2017-03-31 11:27:56 +020073 printf("\t--sha-perf [opts] SHA performance testing tool (-h for usage)\n");
74 printf("\t--aes-perf [opts] AES performance testing tool (-h for usage)\n");
Jens Wiklanderf261a6d2017-11-09 16:45:51 +010075#ifdef CFG_SECSTOR_TA_MGMT_PTA
76 printf("\t--install-ta [directory or list of TAs]\n");
77 printf("\t Install TAs\n");
78#endif
Etienne Carriere41343db2017-03-17 15:38:52 +010079#ifdef CFG_SECURE_DATA_PATH
Jerome Forissier213ca8a2017-03-31 11:27:56 +020080 printf("\t--sdp-basic [opts] Basic Secure Data Path test setup ('-h' for usage)\n");
Etienne Carriere41343db2017-03-17 15:38:52 +010081#endif
82 printf("\n");
Cedric Chaumontc3b6c282015-09-25 03:05:18 +020083}
Pascal Brandc639ac82015-07-02 08:53:34 +020084
Jens Wiklander6f34e002018-05-03 21:21:54 +020085static void init_ossl(void)
86{
87#ifdef OPENSSL_FOUND
88 OPENSSL_init();
89 OpenSSL_add_all_algorithms();
90 ERR_load_crypto_strings();
91#endif
92}
93
Pascal Brandc639ac82015-07-02 08:53:34 +020094int main(int argc, char *argv[])
95{
Cedric Chaumontc3b6c282015-09-25 03:05:18 +020096 int opt;
97 int index;
Etienne Carriere69f914d2017-04-03 13:57:46 +020098 TEEC_Result tee_res;
Cedric Chaumontc3b6c282015-09-25 03:05:18 +020099 int ret;
100 char *p = (char *)glevel;
James Kung35b352d2015-09-07 18:01:16 +0800101 char *test_suite = (char *)gsuitename;
Jerome Forissier213ca8a2017-03-31 11:27:56 +0200102 char *token;
103 ADBG_Suite_Definition_t all = { .SuiteID_p = NULL,
104 .cases = TAILQ_HEAD_INITIALIZER(all.cases), };
Pascal Brandc639ac82015-07-02 08:53:34 +0200105
James Kung35b352d2015-09-07 18:01:16 +0800106 opterr = 0;
107
Jens Wiklander02389a92016-12-16 11:13:38 +0100108 if (signal(SIGPIPE, SIG_IGN) == SIG_ERR)
109 warn("signal(SIGPIPE, SIG_IGN)");
110
111 if (signal(SIGHUP, SIG_IGN) == SIG_ERR)
112 warn("signal(SIGPIPE, SIG_IGN)");
113
Jens Wiklander6f34e002018-05-03 21:21:54 +0200114 init_ossl();
115
Igor Opaniuk44aff4b2016-09-16 10:18:00 +0300116 if (argc > 1 && !strcmp(argv[1], "--sha-perf"))
Igor Opaniuk136644a2016-09-13 13:40:56 +0300117 return sha_perf_runner_cmd_parser(argc-1, &argv[1]);
Igor Opaniuk44aff4b2016-09-16 10:18:00 +0300118 else if (argc > 1 && !strcmp(argv[1], "--aes-perf"))
119 return aes_perf_runner_cmd_parser(argc-1, &argv[1]);
Jens Wiklanderf261a6d2017-11-09 16:45:51 +0100120#ifdef CFG_SECSTOR_TA_MGMT_PTA
121 else if (argc > 1 && !strcmp(argv[1], "--install-ta"))
122 return install_ta_runner_cmd_parser(argc - 1, argv + 1);
123#endif
Etienne Carriere41343db2017-03-17 15:38:52 +0100124#ifdef CFG_SECURE_DATA_PATH
125 else if (argc > 1 && !strcmp(argv[1], "--sdp-basic"))
126 return sdp_basic_runner_cmd_parser(argc-1, &argv[1]);
127#endif
Igor Opaniuk136644a2016-09-13 13:40:56 +0300128
James Kung35b352d2015-09-07 18:01:16 +0800129 while ((opt = getopt(argc, argv, "d:l:t:h")) != -1)
Cedric Chaumontc3b6c282015-09-25 03:05:18 +0200130 switch (opt) {
131 case 'd':
132 _device = optarg;
133 break;
134 case 'l':
135 p = optarg;
136 break;
James Kung35b352d2015-09-07 18:01:16 +0800137 case 't':
138 test_suite = optarg;
139 break;
Cedric Chaumontc3b6c282015-09-25 03:05:18 +0200140 case 'h':
141 usage(argv[0]);
142 return 0;
143 default:
144 usage(argv[0]);
145 return -1;
146 }
Cedric Chaumontc3b6c282015-09-25 03:05:18 +0200147
148 for (index = optind; index < argc; index++)
149 printf("Test ID: %s\n", argv[index]);
150
151 if (p)
152 level = atoi(p);
153 else
154 level = 0;
155 printf("Run test suite with level=%d\n", level);
156
Pascal Brandc639ac82015-07-02 08:53:34 +0200157 printf("\nTEE test application started with device [%s]\n", _device);
158
Etienne Carriere69f914d2017-04-03 13:57:46 +0200159 tee_res = xtest_teec_ctx_init();
160 if (tee_res != TEEC_SUCCESS) {
Etienne Carriere7d18f552017-04-04 09:46:29 +0200161 fprintf(stderr, "Failed to open TEE context: 0x%" PRIx32 "\n",
162 tee_res);
Etienne Carriere69f914d2017-04-03 13:57:46 +0200163 return -1;
164 }
Pascal Brandc639ac82015-07-02 08:53:34 +0200165
Jerome Forissier213ca8a2017-03-31 11:27:56 +0200166 /* Concatenate all the selected suites into 'all' */
167 for (token = test_suite; ; token = NULL) {
168
169 token = strtok(token, "+");
170 if (!token)
171 break;
172
173 if (!strcmp(token, "regression"))
174 ret = Do_ADBG_AppendToSuite(&all, &ADBG_Suite_regression);
175 else if (!strcmp(token, "benchmark"))
176 ret = Do_ADBG_AppendToSuite(&all, &ADBG_Suite_benchmark);
177#ifdef WITH_GP_TESTS
178 else if (!strcmp(token, "gp"))
179 ret = Do_ADBG_AppendToSuite(&all, &ADBG_Suite_gp);
180#endif
181 else {
182 fprintf(stderr, "Unkown test suite: %s\n", token);
183 ret = -1;
184 }
185 if (ret < 0)
186 goto err;
James Kung35b352d2015-09-07 18:01:16 +0800187 }
Pascal Brandc639ac82015-07-02 08:53:34 +0200188
Jerome Forissier213ca8a2017-03-31 11:27:56 +0200189 /* Run the tests */
190 ret = Do_ADBG_RunSuite(&all, argc - optind, argv + optind);
191
192err:
193 free((void *)all.SuiteID_p);
Pascal Brandc639ac82015-07-02 08:53:34 +0200194 xtest_teec_ctx_deinit();
195
196 printf("TEE test application done!\n");
197 return ret;
198}