blob: a94ed2bd4109bfbebeb09ec68aa82904de602b40 [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>
16#include <signal.h>
Pascal Brandc639ac82015-07-02 08:53:34 +020017#include <stdio.h>
Cedric Chaumontc3b6c282015-09-25 03:05:18 +020018#include <stdlib.h>
Pascal Brandc639ac82015-07-02 08:53:34 +020019#include <string.h>
Cedric Chaumontc3b6c282015-09-25 03:05:18 +020020#include <unistd.h>
Pascal Brandc639ac82015-07-02 08:53:34 +020021
22#include <adbg.h>
23#include "xtest_test.h"
24#include "xtest_helpers.h"
Igor Opaniuk136644a2016-09-13 13:40:56 +030025
26/* include here shandalone tests */
Igor Opaniukf9b7fd22016-09-16 16:22:34 +030027#include "crypto_common.h"
Igor Opaniuk136644a2016-09-13 13:40:56 +030028
Pascal Brandc639ac82015-07-02 08:53:34 +020029
Jens Wiklander74abfe32017-01-03 14:17:47 +010030ADBG_SUITE_DEFINE(regression);
31ADBG_SUITE_DEFINE(benchmark);
Igor Opaniuk136644a2016-09-13 13:40:56 +030032
Jens Wiklander2190cdc2015-03-31 13:37:09 +020033char *_device = NULL;
Cedric Chaumontc3b6c282015-09-25 03:05:18 +020034unsigned int level = 0;
35static const char glevel[] = "0";
James Kung35b352d2015-09-07 18:01:16 +080036static const char gsuitename[] = "regression";
Cedric Chaumontc3b6c282015-09-25 03:05:18 +020037
38void usage(char *program);
39
40void usage(char *program)
41{
42 printf("Usage: %s <options> <test_id>\n", program);
43 printf("\n");
44 printf("options:\n");
Jens Wiklander2190cdc2015-03-31 13:37:09 +020045 printf("\t-d <device-type> default not set, use any\n");
Cedric Chaumontc3b6c282015-09-25 03:05:18 +020046 printf("\t-l <level> test suite level: [0-15]\n");
Jens Wiklander569b8622015-12-03 11:23:09 +010047 printf("\t-t <test_suite> available test suite: regression, benchmark\n");
James Kung35b352d2015-09-07 18:01:16 +080048 printf("\t default value = %s\n", gsuitename);
Cedric Chaumontc3b6c282015-09-25 03:05:18 +020049 printf("\t-h show usage\n");
Igor Opaniuk136644a2016-09-13 13:40:56 +030050 printf("applets:\n");
51 printf("\t--sha-perf SHA performance testing tool for OP-TEE\n");
Etienne Carrierec92b55f2017-03-24 10:28:09 +010052 printf("\t--sha-perf -h show usage of SHA performance testing tool\n");
Cedric Chaumontc3b6c282015-09-25 03:05:18 +020053 printf("\n");
Igor Opaniuk44aff4b2016-09-16 10:18:00 +030054 printf("\t--aes-perf AES performance testing tool for OP-TEE\n");
Etienne Carrierec92b55f2017-03-24 10:28:09 +010055 printf("\t--aes-perf -h show usage of AES performance testing tool\n");
Igor Opaniuk44aff4b2016-09-16 10:18:00 +030056 printf("\n");
Etienne Carriere41343db2017-03-17 15:38:52 +010057#ifdef CFG_SECURE_DATA_PATH
58 printf("\t--sdp-basic Basic Secure Data Path test setup for OP-TEE ('-h' for usage)\n");
59#endif
60 printf("\n");
Cedric Chaumontc3b6c282015-09-25 03:05:18 +020061}
Pascal Brandc639ac82015-07-02 08:53:34 +020062
63int main(int argc, char *argv[])
64{
Cedric Chaumontc3b6c282015-09-25 03:05:18 +020065 int opt;
66 int index;
Etienne Carriere69f914d2017-04-03 13:57:46 +020067 TEEC_Result tee_res;
Cedric Chaumontc3b6c282015-09-25 03:05:18 +020068 int ret;
69 char *p = (char *)glevel;
James Kung35b352d2015-09-07 18:01:16 +080070 char *test_suite = (char *)gsuitename;
Pascal Brandc639ac82015-07-02 08:53:34 +020071
James Kung35b352d2015-09-07 18:01:16 +080072 opterr = 0;
73
Jens Wiklander02389a92016-12-16 11:13:38 +010074 if (signal(SIGPIPE, SIG_IGN) == SIG_ERR)
75 warn("signal(SIGPIPE, SIG_IGN)");
76
77 if (signal(SIGHUP, SIG_IGN) == SIG_ERR)
78 warn("signal(SIGPIPE, SIG_IGN)");
79
Igor Opaniuk44aff4b2016-09-16 10:18:00 +030080 if (argc > 1 && !strcmp(argv[1], "--sha-perf"))
Igor Opaniuk136644a2016-09-13 13:40:56 +030081 return sha_perf_runner_cmd_parser(argc-1, &argv[1]);
Igor Opaniuk44aff4b2016-09-16 10:18:00 +030082 else if (argc > 1 && !strcmp(argv[1], "--aes-perf"))
83 return aes_perf_runner_cmd_parser(argc-1, &argv[1]);
Etienne Carriere41343db2017-03-17 15:38:52 +010084#ifdef CFG_SECURE_DATA_PATH
85 else if (argc > 1 && !strcmp(argv[1], "--sdp-basic"))
86 return sdp_basic_runner_cmd_parser(argc-1, &argv[1]);
87#endif
Igor Opaniuk136644a2016-09-13 13:40:56 +030088
James Kung35b352d2015-09-07 18:01:16 +080089 while ((opt = getopt(argc, argv, "d:l:t:h")) != -1)
Cedric Chaumontc3b6c282015-09-25 03:05:18 +020090 switch (opt) {
91 case 'd':
92 _device = optarg;
93 break;
94 case 'l':
95 p = optarg;
96 break;
James Kung35b352d2015-09-07 18:01:16 +080097 case 't':
98 test_suite = optarg;
99 break;
Cedric Chaumontc3b6c282015-09-25 03:05:18 +0200100 case 'h':
101 usage(argv[0]);
102 return 0;
103 default:
104 usage(argv[0]);
105 return -1;
106 }
Cedric Chaumontc3b6c282015-09-25 03:05:18 +0200107
108 for (index = optind; index < argc; index++)
109 printf("Test ID: %s\n", argv[index]);
110
111 if (p)
112 level = atoi(p);
113 else
114 level = 0;
115 printf("Run test suite with level=%d\n", level);
116
Pascal Brandc639ac82015-07-02 08:53:34 +0200117 printf("\nTEE test application started with device [%s]\n", _device);
118
Etienne Carriere69f914d2017-04-03 13:57:46 +0200119 tee_res = xtest_teec_ctx_init();
120 if (tee_res != TEEC_SUCCESS) {
121 fprintf(stderr, "Failed to open TEE context: 0x%x\n", token);
122 return -1;
123 }
Pascal Brandc639ac82015-07-02 08:53:34 +0200124
Jens Wiklander569b8622015-12-03 11:23:09 +0100125 if (strcmp(test_suite, "regression") == 0)
Jens Wiklander74abfe32017-01-03 14:17:47 +0100126 ret = Do_ADBG_RunSuite(&ADBG_Suite_regression,
127 argc - optind, argv + optind);
James Kung35b352d2015-09-07 18:01:16 +0800128 else if (strcmp(test_suite, "benchmark") == 0)
Jens Wiklander74abfe32017-01-03 14:17:47 +0100129 ret = Do_ADBG_RunSuite(&ADBG_Suite_benchmark,
130 argc - optind, argv + optind);
James Kung35b352d2015-09-07 18:01:16 +0800131 else {
132 fprintf(stderr, "No test suite found: %s\n", test_suite);
133 ret = -1;
134 }
Pascal Brandc639ac82015-07-02 08:53:34 +0200135
136 xtest_teec_ctx_deinit();
137
138 printf("TEE test application done!\n");
139 return ret;
140}