blob: acc7f177254308bbcd48a416259f6b8b376f3c6b [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"
Igor Opaniuk136644a2016-09-13 13:40:56 +030029
Pascal Brandc639ac82015-07-02 08:53:34 +020030
Jens Wiklander74abfe32017-01-03 14:17:47 +010031ADBG_SUITE_DEFINE(regression);
32ADBG_SUITE_DEFINE(benchmark);
Igor Opaniuk136644a2016-09-13 13:40:56 +030033
Jens Wiklander2190cdc2015-03-31 13:37:09 +020034char *_device = NULL;
Cedric Chaumontc3b6c282015-09-25 03:05:18 +020035unsigned int level = 0;
36static const char glevel[] = "0";
James Kung35b352d2015-09-07 18:01:16 +080037static const char gsuitename[] = "regression";
Cedric Chaumontc3b6c282015-09-25 03:05:18 +020038
39void usage(char *program);
40
41void usage(char *program)
42{
43 printf("Usage: %s <options> <test_id>\n", program);
44 printf("\n");
45 printf("options:\n");
Jens Wiklander2190cdc2015-03-31 13:37:09 +020046 printf("\t-d <device-type> default not set, use any\n");
Cedric Chaumontc3b6c282015-09-25 03:05:18 +020047 printf("\t-l <level> test suite level: [0-15]\n");
Jens Wiklander569b8622015-12-03 11:23:09 +010048 printf("\t-t <test_suite> available test suite: regression, benchmark\n");
James Kung35b352d2015-09-07 18:01:16 +080049 printf("\t default value = %s\n", gsuitename);
Cedric Chaumontc3b6c282015-09-25 03:05:18 +020050 printf("\t-h show usage\n");
Igor Opaniuk136644a2016-09-13 13:40:56 +030051 printf("applets:\n");
52 printf("\t--sha-perf SHA performance testing tool for OP-TEE\n");
Etienne Carrierec92b55f2017-03-24 10:28:09 +010053 printf("\t--sha-perf -h show usage of SHA performance testing tool\n");
Cedric Chaumontc3b6c282015-09-25 03:05:18 +020054 printf("\n");
Igor Opaniuk44aff4b2016-09-16 10:18:00 +030055 printf("\t--aes-perf AES performance testing tool for OP-TEE\n");
Etienne Carrierec92b55f2017-03-24 10:28:09 +010056 printf("\t--aes-perf -h show usage of AES performance testing tool\n");
Igor Opaniuk44aff4b2016-09-16 10:18:00 +030057 printf("\n");
Etienne Carriere41343db2017-03-17 15:38:52 +010058#ifdef CFG_SECURE_DATA_PATH
59 printf("\t--sdp-basic Basic Secure Data Path test setup for OP-TEE ('-h' for usage)\n");
60#endif
61 printf("\n");
Cedric Chaumontc3b6c282015-09-25 03:05:18 +020062}
Pascal Brandc639ac82015-07-02 08:53:34 +020063
64int main(int argc, char *argv[])
65{
Cedric Chaumontc3b6c282015-09-25 03:05:18 +020066 int opt;
67 int index;
Etienne Carriere69f914d2017-04-03 13:57:46 +020068 TEEC_Result tee_res;
Cedric Chaumontc3b6c282015-09-25 03:05:18 +020069 int ret;
70 char *p = (char *)glevel;
James Kung35b352d2015-09-07 18:01:16 +080071 char *test_suite = (char *)gsuitename;
Pascal Brandc639ac82015-07-02 08:53:34 +020072
James Kung35b352d2015-09-07 18:01:16 +080073 opterr = 0;
74
Jens Wiklander02389a92016-12-16 11:13:38 +010075 if (signal(SIGPIPE, SIG_IGN) == SIG_ERR)
76 warn("signal(SIGPIPE, SIG_IGN)");
77
78 if (signal(SIGHUP, SIG_IGN) == SIG_ERR)
79 warn("signal(SIGPIPE, SIG_IGN)");
80
Igor Opaniuk44aff4b2016-09-16 10:18:00 +030081 if (argc > 1 && !strcmp(argv[1], "--sha-perf"))
Igor Opaniuk136644a2016-09-13 13:40:56 +030082 return sha_perf_runner_cmd_parser(argc-1, &argv[1]);
Igor Opaniuk44aff4b2016-09-16 10:18:00 +030083 else if (argc > 1 && !strcmp(argv[1], "--aes-perf"))
84 return aes_perf_runner_cmd_parser(argc-1, &argv[1]);
Etienne Carriere41343db2017-03-17 15:38:52 +010085#ifdef CFG_SECURE_DATA_PATH
86 else if (argc > 1 && !strcmp(argv[1], "--sdp-basic"))
87 return sdp_basic_runner_cmd_parser(argc-1, &argv[1]);
88#endif
Igor Opaniuk136644a2016-09-13 13:40:56 +030089
James Kung35b352d2015-09-07 18:01:16 +080090 while ((opt = getopt(argc, argv, "d:l:t:h")) != -1)
Cedric Chaumontc3b6c282015-09-25 03:05:18 +020091 switch (opt) {
92 case 'd':
93 _device = optarg;
94 break;
95 case 'l':
96 p = optarg;
97 break;
James Kung35b352d2015-09-07 18:01:16 +080098 case 't':
99 test_suite = optarg;
100 break;
Cedric Chaumontc3b6c282015-09-25 03:05:18 +0200101 case 'h':
102 usage(argv[0]);
103 return 0;
104 default:
105 usage(argv[0]);
106 return -1;
107 }
Cedric Chaumontc3b6c282015-09-25 03:05:18 +0200108
109 for (index = optind; index < argc; index++)
110 printf("Test ID: %s\n", argv[index]);
111
112 if (p)
113 level = atoi(p);
114 else
115 level = 0;
116 printf("Run test suite with level=%d\n", level);
117
Pascal Brandc639ac82015-07-02 08:53:34 +0200118 printf("\nTEE test application started with device [%s]\n", _device);
119
Etienne Carriere69f914d2017-04-03 13:57:46 +0200120 tee_res = xtest_teec_ctx_init();
121 if (tee_res != TEEC_SUCCESS) {
Etienne Carriere7d18f552017-04-04 09:46:29 +0200122 fprintf(stderr, "Failed to open TEE context: 0x%" PRIx32 "\n",
123 tee_res);
Etienne Carriere69f914d2017-04-03 13:57:46 +0200124 return -1;
125 }
Pascal Brandc639ac82015-07-02 08:53:34 +0200126
Jens Wiklander569b8622015-12-03 11:23:09 +0100127 if (strcmp(test_suite, "regression") == 0)
Jens Wiklander74abfe32017-01-03 14:17:47 +0100128 ret = Do_ADBG_RunSuite(&ADBG_Suite_regression,
129 argc - optind, argv + optind);
James Kung35b352d2015-09-07 18:01:16 +0800130 else if (strcmp(test_suite, "benchmark") == 0)
Jens Wiklander74abfe32017-01-03 14:17:47 +0100131 ret = Do_ADBG_RunSuite(&ADBG_Suite_benchmark,
132 argc - optind, argv + optind);
James Kung35b352d2015-09-07 18:01:16 +0800133 else {
134 fprintf(stderr, "No test suite found: %s\n", test_suite);
135 ret = -1;
136 }
Pascal Brandc639ac82015-07-02 08:53:34 +0200137
138 xtest_teec_ctx_deinit();
139
140 printf("TEE test application done!\n");
141 return ret;
142}