blob: bd17ca42afc516323af60b0b4ef7fa43553cf1a9 [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
43ADBG_SUITE_DEFINE(regression);
Igor Opaniuk136644a2016-09-13 13:40:56 +030044
Jens Wiklander2190cdc2015-03-31 13:37:09 +020045char *_device = NULL;
Cedric Chaumontc3b6c282015-09-25 03:05:18 +020046unsigned int level = 0;
47static const char glevel[] = "0";
Jerome Forissier213ca8a2017-03-31 11:27:56 +020048#ifdef WITH_GP_TESTS
49static char gsuitename[] = "regression+gp";
50#else
51static char gsuitename[] = "regression";
52#endif
Cedric Chaumontc3b6c282015-09-25 03:05:18 +020053
54void usage(char *program);
55
56void usage(char *program)
57{
58 printf("Usage: %s <options> <test_id>\n", program);
59 printf("\n");
60 printf("options:\n");
Jerome Forissier213ca8a2017-03-31 11:27:56 +020061 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 Opaniuk136644a2016-09-13 13:40:56 +030073 printf("applets:\n");
Jerome Forissier213ca8a2017-03-31 11:27:56 +020074 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 Wiklanderf261a6d2017-11-09 16:45:51 +010076#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 Carriere41343db2017-03-17 15:38:52 +010080#ifdef CFG_SECURE_DATA_PATH
Jerome Forissier213ca8a2017-03-31 11:27:56 +020081 printf("\t--sdp-basic [opts] Basic Secure Data Path test setup ('-h' for usage)\n");
Etienne Carriere41343db2017-03-17 15:38:52 +010082#endif
Jens Wiklander254a3e32019-01-31 12:25:08 +010083 printf("\t--stats [opts] Various statistics ('-h' for usage)\n");
Etienne Carriere41343db2017-03-17 15:38:52 +010084 printf("\n");
Cedric Chaumontc3b6c282015-09-25 03:05:18 +020085}
Pascal Brandc639ac82015-07-02 08:53:34 +020086
Jens Wiklander6f34e002018-05-03 21:21:54 +020087static 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 Brandc639ac82015-07-02 08:53:34 +020096int main(int argc, char *argv[])
97{
Etienne Carrieree4ec9e42019-03-28 13:30:21 +010098 int opt = 0;
99 int index = 0;
100 TEEC_Result tee_res = TEEC_ERROR_GENERIC;
101 int ret = 0;
Cedric Chaumontc3b6c282015-09-25 03:05:18 +0200102 char *p = (char *)glevel;
James Kung35b352d2015-09-07 18:01:16 +0800103 char *test_suite = (char *)gsuitename;
Etienne Carrieree4ec9e42019-03-28 13:30:21 +0100104 char *token = NULL;
105 ADBG_Suite_Definition_t all = {
106 .SuiteID_p = NULL,
107 .cases = TAILQ_HEAD_INITIALIZER(all.cases),
108 };
Pascal Brandc639ac82015-07-02 08:53:34 +0200109
James Kung35b352d2015-09-07 18:01:16 +0800110 opterr = 0;
111
Jens Wiklander02389a92016-12-16 11:13:38 +0100112 if (signal(SIGPIPE, SIG_IGN) == SIG_ERR)
113 warn("signal(SIGPIPE, SIG_IGN)");
114
115 if (signal(SIGHUP, SIG_IGN) == SIG_ERR)
116 warn("signal(SIGPIPE, SIG_IGN)");
117
Jens Wiklander6f34e002018-05-03 21:21:54 +0200118 init_ossl();
119
Igor Opaniuk44aff4b2016-09-16 10:18:00 +0300120 if (argc > 1 && !strcmp(argv[1], "--sha-perf"))
Igor Opaniuk136644a2016-09-13 13:40:56 +0300121 return sha_perf_runner_cmd_parser(argc-1, &argv[1]);
Igor Opaniuk44aff4b2016-09-16 10:18:00 +0300122 else if (argc > 1 && !strcmp(argv[1], "--aes-perf"))
123 return aes_perf_runner_cmd_parser(argc-1, &argv[1]);
Jens Wiklanderf261a6d2017-11-09 16:45:51 +0100124#ifdef CFG_SECSTOR_TA_MGMT_PTA
125 else if (argc > 1 && !strcmp(argv[1], "--install-ta"))
126 return install_ta_runner_cmd_parser(argc - 1, argv + 1);
127#endif
Etienne Carriere41343db2017-03-17 15:38:52 +0100128#ifdef CFG_SECURE_DATA_PATH
129 else if (argc > 1 && !strcmp(argv[1], "--sdp-basic"))
130 return sdp_basic_runner_cmd_parser(argc-1, &argv[1]);
131#endif
Jens Wiklander254a3e32019-01-31 12:25:08 +0100132 else if (argc > 1 && !strcmp(argv[1], "--stats"))
133 return stats_runner_cmd_parser(argc - 1, &argv[1]);
Igor Opaniuk136644a2016-09-13 13:40:56 +0300134
James Kung35b352d2015-09-07 18:01:16 +0800135 while ((opt = getopt(argc, argv, "d:l:t:h")) != -1)
Cedric Chaumontc3b6c282015-09-25 03:05:18 +0200136 switch (opt) {
137 case 'd':
138 _device = optarg;
139 break;
140 case 'l':
141 p = optarg;
142 break;
James Kung35b352d2015-09-07 18:01:16 +0800143 case 't':
144 test_suite = optarg;
145 break;
Cedric Chaumontc3b6c282015-09-25 03:05:18 +0200146 case 'h':
147 usage(argv[0]);
148 return 0;
149 default:
150 usage(argv[0]);
151 return -1;
152 }
Cedric Chaumontc3b6c282015-09-25 03:05:18 +0200153
154 for (index = optind; index < argc; index++)
155 printf("Test ID: %s\n", argv[index]);
156
157 if (p)
158 level = atoi(p);
159 else
160 level = 0;
161 printf("Run test suite with level=%d\n", level);
162
Pascal Brandc639ac82015-07-02 08:53:34 +0200163 printf("\nTEE test application started with device [%s]\n", _device);
164
Etienne Carriere69f914d2017-04-03 13:57:46 +0200165 tee_res = xtest_teec_ctx_init();
166 if (tee_res != TEEC_SUCCESS) {
Etienne Carriere7d18f552017-04-04 09:46:29 +0200167 fprintf(stderr, "Failed to open TEE context: 0x%" PRIx32 "\n",
168 tee_res);
Etienne Carriere69f914d2017-04-03 13:57:46 +0200169 return -1;
170 }
Pascal Brandc639ac82015-07-02 08:53:34 +0200171
Jerome Forissier213ca8a2017-03-31 11:27:56 +0200172 /* Concatenate all the selected suites into 'all' */
173 for (token = test_suite; ; token = NULL) {
174
175 token = strtok(token, "+");
176 if (!token)
177 break;
178
179 if (!strcmp(token, "regression"))
180 ret = Do_ADBG_AppendToSuite(&all, &ADBG_Suite_regression);
181 else if (!strcmp(token, "benchmark"))
182 ret = Do_ADBG_AppendToSuite(&all, &ADBG_Suite_benchmark);
183#ifdef WITH_GP_TESTS
184 else if (!strcmp(token, "gp"))
185 ret = Do_ADBG_AppendToSuite(&all, &ADBG_Suite_gp);
186#endif
187 else {
188 fprintf(stderr, "Unkown test suite: %s\n", token);
189 ret = -1;
190 }
191 if (ret < 0)
192 goto err;
James Kung35b352d2015-09-07 18:01:16 +0800193 }
Pascal Brandc639ac82015-07-02 08:53:34 +0200194
Jerome Forissier213ca8a2017-03-31 11:27:56 +0200195 /* Run the tests */
196 ret = Do_ADBG_RunSuite(&all, argc - optind, argv + optind);
197
198err:
199 free((void *)all.SuiteID_p);
Pascal Brandc639ac82015-07-02 08:53:34 +0200200 xtest_teec_ctx_deinit();
201
202 printf("TEE test application done!\n");
203 return ret;
204}