blob: e3da5531a5617f78baf0c002887bd68de19a1801 [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
23#include <adbg.h>
24#include "xtest_test.h"
25#include "xtest_helpers.h"
Igor Opaniuk136644a2016-09-13 13:40:56 +030026
27/* include here shandalone tests */
Igor Opaniukf9b7fd22016-09-16 16:22:34 +030028#include "crypto_common.h"
Jens Wiklanderf261a6d2017-11-09 16:45:51 +010029#include "install_ta.h"
Igor Opaniuk136644a2016-09-13 13:40:56 +030030
Pascal Brandc639ac82015-07-02 08:53:34 +020031
Jens Wiklander74abfe32017-01-03 14:17:47 +010032ADBG_SUITE_DEFINE(benchmark);
Jerome Forissier213ca8a2017-03-31 11:27:56 +020033#ifdef WITH_GP_TESTS
34ADBG_SUITE_DEFINE(gp);
35#endif
36ADBG_SUITE_DEFINE(regression);
Igor Opaniuk136644a2016-09-13 13:40:56 +030037
Jens Wiklander2190cdc2015-03-31 13:37:09 +020038char *_device = NULL;
Cedric Chaumontc3b6c282015-09-25 03:05:18 +020039unsigned int level = 0;
40static const char glevel[] = "0";
Jerome Forissier213ca8a2017-03-31 11:27:56 +020041#ifdef WITH_GP_TESTS
42static char gsuitename[] = "regression+gp";
43#else
44static char gsuitename[] = "regression";
45#endif
Cedric Chaumontc3b6c282015-09-25 03:05:18 +020046
47void usage(char *program);
48
49void usage(char *program)
50{
51 printf("Usage: %s <options> <test_id>\n", program);
52 printf("\n");
53 printf("options:\n");
Jerome Forissier213ca8a2017-03-31 11:27:56 +020054 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 Opaniuk136644a2016-09-13 13:40:56 +030066 printf("applets:\n");
Jerome Forissier213ca8a2017-03-31 11:27:56 +020067 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 Wiklanderf261a6d2017-11-09 16:45:51 +010069#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 Carriere41343db2017-03-17 15:38:52 +010073#ifdef CFG_SECURE_DATA_PATH
Jerome Forissier213ca8a2017-03-31 11:27:56 +020074 printf("\t--sdp-basic [opts] Basic Secure Data Path test setup ('-h' for usage)\n");
Etienne Carriere41343db2017-03-17 15:38:52 +010075#endif
76 printf("\n");
Cedric Chaumontc3b6c282015-09-25 03:05:18 +020077}
Pascal Brandc639ac82015-07-02 08:53:34 +020078
79int main(int argc, char *argv[])
80{
Cedric Chaumontc3b6c282015-09-25 03:05:18 +020081 int opt;
82 int index;
Etienne Carriere69f914d2017-04-03 13:57:46 +020083 TEEC_Result tee_res;
Cedric Chaumontc3b6c282015-09-25 03:05:18 +020084 int ret;
85 char *p = (char *)glevel;
James Kung35b352d2015-09-07 18:01:16 +080086 char *test_suite = (char *)gsuitename;
Jerome Forissier213ca8a2017-03-31 11:27:56 +020087 char *token;
88 ADBG_Suite_Definition_t all = { .SuiteID_p = NULL,
89 .cases = TAILQ_HEAD_INITIALIZER(all.cases), };
Pascal Brandc639ac82015-07-02 08:53:34 +020090
James Kung35b352d2015-09-07 18:01:16 +080091 opterr = 0;
92
Jens Wiklander02389a92016-12-16 11:13:38 +010093 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 Opaniuk44aff4b2016-09-16 10:18:00 +030099 if (argc > 1 && !strcmp(argv[1], "--sha-perf"))
Igor Opaniuk136644a2016-09-13 13:40:56 +0300100 return sha_perf_runner_cmd_parser(argc-1, &argv[1]);
Igor Opaniuk44aff4b2016-09-16 10:18:00 +0300101 else if (argc > 1 && !strcmp(argv[1], "--aes-perf"))
102 return aes_perf_runner_cmd_parser(argc-1, &argv[1]);
Jens Wiklanderf261a6d2017-11-09 16:45:51 +0100103#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 Carriere41343db2017-03-17 15:38:52 +0100107#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 Opaniuk136644a2016-09-13 13:40:56 +0300111
James Kung35b352d2015-09-07 18:01:16 +0800112 while ((opt = getopt(argc, argv, "d:l:t:h")) != -1)
Cedric Chaumontc3b6c282015-09-25 03:05:18 +0200113 switch (opt) {
114 case 'd':
115 _device = optarg;
116 break;
117 case 'l':
118 p = optarg;
119 break;
James Kung35b352d2015-09-07 18:01:16 +0800120 case 't':
121 test_suite = optarg;
122 break;
Cedric Chaumontc3b6c282015-09-25 03:05:18 +0200123 case 'h':
124 usage(argv[0]);
125 return 0;
126 default:
127 usage(argv[0]);
128 return -1;
129 }
Cedric Chaumontc3b6c282015-09-25 03:05:18 +0200130
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 Brandc639ac82015-07-02 08:53:34 +0200140 printf("\nTEE test application started with device [%s]\n", _device);
141
Etienne Carriere69f914d2017-04-03 13:57:46 +0200142 tee_res = xtest_teec_ctx_init();
143 if (tee_res != TEEC_SUCCESS) {
Etienne Carriere7d18f552017-04-04 09:46:29 +0200144 fprintf(stderr, "Failed to open TEE context: 0x%" PRIx32 "\n",
145 tee_res);
Etienne Carriere69f914d2017-04-03 13:57:46 +0200146 return -1;
147 }
Pascal Brandc639ac82015-07-02 08:53:34 +0200148
Jerome Forissier213ca8a2017-03-31 11:27:56 +0200149 /* 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 Kung35b352d2015-09-07 18:01:16 +0800170 }
Pascal Brandc639ac82015-07-02 08:53:34 +0200171
Jerome Forissier213ca8a2017-03-31 11:27:56 +0200172 /* Run the tests */
173 ret = Do_ADBG_RunSuite(&all, argc - optind, argv + optind);
174
175err:
176 free((void *)all.SuiteID_p);
Pascal Brandc639ac82015-07-02 08:53:34 +0200177 xtest_teec_ctx_deinit();
178
179 printf("TEE test application done!\n");
180 return ret;
181}