blob: 2c7d43922b366db1d9014f8f6b6dec415e1384d6 [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"
Jens Wiklander254a3e32019-01-31 12:25:08 +010036#include "stats.h"
Igor Opaniuk136644a2016-09-13 13:40:56 +030037
Pascal Brandc639ac82015-07-02 08:53:34 +020038
Jens Wiklander74abfe32017-01-03 14:17:47 +010039ADBG_SUITE_DEFINE(benchmark);
Jerome Forissier213ca8a2017-03-31 11:27:56 +020040#ifdef WITH_GP_TESTS
41ADBG_SUITE_DEFINE(gp);
42#endif
Etienne Carriere109c1d72019-01-09 11:02:02 +010043#ifdef CFG_PKCS11_TA
44ADBG_SUITE_DEFINE(pkcs11);
45#endif
Jerome Forissier213ca8a2017-03-31 11:27:56 +020046ADBG_SUITE_DEFINE(regression);
Igor Opaniuk136644a2016-09-13 13:40:56 +030047
Jens Wiklander2190cdc2015-03-31 13:37:09 +020048char *_device = NULL;
Cedric Chaumontc3b6c282015-09-25 03:05:18 +020049unsigned int level = 0;
50static const char glevel[] = "0";
Etienne Carriere109c1d72019-01-09 11:02:02 +010051
Jerome Forissier213ca8a2017-03-31 11:27:56 +020052#ifdef WITH_GP_TESTS
Etienne Carriere109c1d72019-01-09 11:02:02 +010053#define GP_SUITE "+gp"
Jerome Forissier213ca8a2017-03-31 11:27:56 +020054#else
Etienne Carriere109c1d72019-01-09 11:02:02 +010055#define GP_SUITE ""
Jerome Forissier213ca8a2017-03-31 11:27:56 +020056#endif
Cedric Chaumontc3b6c282015-09-25 03:05:18 +020057
Etienne Carriere109c1d72019-01-09 11:02:02 +010058#ifdef CFG_PKCS11_TA
59#define PKCS11_SUITE "+pkcs11"
60#else
61#define PKCS11_SUITE ""
62#endif
63
64static char gsuitename[] = "regression" GP_SUITE PKCS11_SUITE;
65
Cedric Chaumontc3b6c282015-09-25 03:05:18 +020066void usage(char *program);
67
68void usage(char *program)
69{
70 printf("Usage: %s <options> <test_id>\n", program);
71 printf("\n");
72 printf("options:\n");
Jerome Forissier213ca8a2017-03-31 11:27:56 +020073 printf("\t-d <device-type> TEE device path. Default not set (use any)\n");
74 printf("\t-l <level> Test level [0-15]. Values higher than 0 enable\n");
75 printf("\t optional tests. Default: 0. All tests: 15.\n");
76 printf("\t-t <test_suite> Available test suites: regression benchmark");
77#ifdef WITH_GP_TESTS
78 printf(" gp");
79#endif
Etienne Carriere109c1d72019-01-09 11:02:02 +010080#ifdef CFG_PKCS11_TA
81 printf(" pkcs11");
82#endif
Jerome Forissier213ca8a2017-03-31 11:27:56 +020083 printf("\n");
84 printf("\t To run several suites, use multiple names\n");
85 printf("\t separated by a '+')\n");
86 printf("\t Default value: '%s'\n", gsuitename);
87 printf("\t-h Show usage\n");
Igor Opaniuk136644a2016-09-13 13:40:56 +030088 printf("applets:\n");
Jerome Forissier213ca8a2017-03-31 11:27:56 +020089 printf("\t--sha-perf [opts] SHA performance testing tool (-h for usage)\n");
90 printf("\t--aes-perf [opts] AES performance testing tool (-h for usage)\n");
Jens Wiklanderf261a6d2017-11-09 16:45:51 +010091#ifdef CFG_SECSTOR_TA_MGMT_PTA
92 printf("\t--install-ta [directory or list of TAs]\n");
93 printf("\t Install TAs\n");
94#endif
Etienne Carriere41343db2017-03-17 15:38:52 +010095#ifdef CFG_SECURE_DATA_PATH
Jerome Forissier213ca8a2017-03-31 11:27:56 +020096 printf("\t--sdp-basic [opts] Basic Secure Data Path test setup ('-h' for usage)\n");
Etienne Carriere41343db2017-03-17 15:38:52 +010097#endif
Jens Wiklander254a3e32019-01-31 12:25:08 +010098 printf("\t--stats [opts] Various statistics ('-h' for usage)\n");
Etienne Carriere41343db2017-03-17 15:38:52 +010099 printf("\n");
Cedric Chaumontc3b6c282015-09-25 03:05:18 +0200100}
Pascal Brandc639ac82015-07-02 08:53:34 +0200101
Jens Wiklander6f34e002018-05-03 21:21:54 +0200102static void init_ossl(void)
103{
104#ifdef OPENSSL_FOUND
105 OPENSSL_init();
106 OpenSSL_add_all_algorithms();
107 ERR_load_crypto_strings();
108#endif
109}
110
Pascal Brandc639ac82015-07-02 08:53:34 +0200111int main(int argc, char *argv[])
112{
Etienne Carrieree4ec9e42019-03-28 13:30:21 +0100113 int opt = 0;
114 int index = 0;
115 TEEC_Result tee_res = TEEC_ERROR_GENERIC;
116 int ret = 0;
Cedric Chaumontc3b6c282015-09-25 03:05:18 +0200117 char *p = (char *)glevel;
James Kung35b352d2015-09-07 18:01:16 +0800118 char *test_suite = (char *)gsuitename;
Etienne Carrieree4ec9e42019-03-28 13:30:21 +0100119 char *token = NULL;
120 ADBG_Suite_Definition_t all = {
121 .SuiteID_p = NULL,
122 .cases = TAILQ_HEAD_INITIALIZER(all.cases),
123 };
Pascal Brandc639ac82015-07-02 08:53:34 +0200124
James Kung35b352d2015-09-07 18:01:16 +0800125 opterr = 0;
126
Jens Wiklander02389a92016-12-16 11:13:38 +0100127 if (signal(SIGPIPE, SIG_IGN) == SIG_ERR)
128 warn("signal(SIGPIPE, SIG_IGN)");
129
130 if (signal(SIGHUP, SIG_IGN) == SIG_ERR)
131 warn("signal(SIGPIPE, SIG_IGN)");
132
Jens Wiklander6f34e002018-05-03 21:21:54 +0200133 init_ossl();
134
Igor Opaniuk44aff4b2016-09-16 10:18:00 +0300135 if (argc > 1 && !strcmp(argv[1], "--sha-perf"))
Igor Opaniuk136644a2016-09-13 13:40:56 +0300136 return sha_perf_runner_cmd_parser(argc-1, &argv[1]);
Igor Opaniuk44aff4b2016-09-16 10:18:00 +0300137 else if (argc > 1 && !strcmp(argv[1], "--aes-perf"))
138 return aes_perf_runner_cmd_parser(argc-1, &argv[1]);
Jens Wiklanderf261a6d2017-11-09 16:45:51 +0100139#ifdef CFG_SECSTOR_TA_MGMT_PTA
140 else if (argc > 1 && !strcmp(argv[1], "--install-ta"))
141 return install_ta_runner_cmd_parser(argc - 1, argv + 1);
142#endif
Etienne Carriere41343db2017-03-17 15:38:52 +0100143#ifdef CFG_SECURE_DATA_PATH
144 else if (argc > 1 && !strcmp(argv[1], "--sdp-basic"))
145 return sdp_basic_runner_cmd_parser(argc-1, &argv[1]);
146#endif
Jens Wiklander254a3e32019-01-31 12:25:08 +0100147 else if (argc > 1 && !strcmp(argv[1], "--stats"))
148 return stats_runner_cmd_parser(argc - 1, &argv[1]);
Igor Opaniuk136644a2016-09-13 13:40:56 +0300149
James Kung35b352d2015-09-07 18:01:16 +0800150 while ((opt = getopt(argc, argv, "d:l:t:h")) != -1)
Cedric Chaumontc3b6c282015-09-25 03:05:18 +0200151 switch (opt) {
152 case 'd':
153 _device = optarg;
154 break;
155 case 'l':
156 p = optarg;
157 break;
James Kung35b352d2015-09-07 18:01:16 +0800158 case 't':
159 test_suite = optarg;
160 break;
Cedric Chaumontc3b6c282015-09-25 03:05:18 +0200161 case 'h':
162 usage(argv[0]);
163 return 0;
164 default:
165 usage(argv[0]);
166 return -1;
167 }
Cedric Chaumontc3b6c282015-09-25 03:05:18 +0200168
169 for (index = optind; index < argc; index++)
170 printf("Test ID: %s\n", argv[index]);
171
172 if (p)
173 level = atoi(p);
174 else
175 level = 0;
176 printf("Run test suite with level=%d\n", level);
177
Pascal Brandc639ac82015-07-02 08:53:34 +0200178 printf("\nTEE test application started with device [%s]\n", _device);
179
Etienne Carriere69f914d2017-04-03 13:57:46 +0200180 tee_res = xtest_teec_ctx_init();
181 if (tee_res != TEEC_SUCCESS) {
Etienne Carriere7d18f552017-04-04 09:46:29 +0200182 fprintf(stderr, "Failed to open TEE context: 0x%" PRIx32 "\n",
183 tee_res);
Etienne Carriere69f914d2017-04-03 13:57:46 +0200184 return -1;
185 }
Pascal Brandc639ac82015-07-02 08:53:34 +0200186
Jerome Forissier213ca8a2017-03-31 11:27:56 +0200187 /* Concatenate all the selected suites into 'all' */
188 for (token = test_suite; ; token = NULL) {
189
190 token = strtok(token, "+");
191 if (!token)
192 break;
193
194 if (!strcmp(token, "regression"))
195 ret = Do_ADBG_AppendToSuite(&all, &ADBG_Suite_regression);
196 else if (!strcmp(token, "benchmark"))
197 ret = Do_ADBG_AppendToSuite(&all, &ADBG_Suite_benchmark);
198#ifdef WITH_GP_TESTS
199 else if (!strcmp(token, "gp"))
200 ret = Do_ADBG_AppendToSuite(&all, &ADBG_Suite_gp);
201#endif
Etienne Carriere109c1d72019-01-09 11:02:02 +0100202#ifdef CFG_PKCS11_TA
203 else if (!strcmp(token, "pkcs11"))
204 ret = Do_ADBG_AppendToSuite(&all, &ADBG_Suite_pkcs11);
205#endif
Jerome Forissier213ca8a2017-03-31 11:27:56 +0200206 else {
207 fprintf(stderr, "Unkown test suite: %s\n", token);
208 ret = -1;
209 }
210 if (ret < 0)
211 goto err;
James Kung35b352d2015-09-07 18:01:16 +0800212 }
Pascal Brandc639ac82015-07-02 08:53:34 +0200213
Jerome Forissier213ca8a2017-03-31 11:27:56 +0200214 /* Run the tests */
215 ret = Do_ADBG_RunSuite(&all, argc - optind, argv + optind);
216
217err:
218 free((void *)all.SuiteID_p);
Pascal Brandc639ac82015-07-02 08:53:34 +0200219 xtest_teec_ctx_deinit();
220
221 printf("TEE test application done!\n");
222 return ret;
223}