3 * Copyright (C) 2006-2012 Sawtooth Consulting Ltd.
5 * This file is part of CyaSSL.
7 * CyaSSL is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * CyaSSL is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
24 #include <cyassl/ssl.h>
25 #include <tests/unit.h>
29 #define MAX_COMMAND_SZ 240
32 void client_test(void*);
33 THREAD_RETURN CYASSL_THREAD server_test(void*);
36 static void execute_test_case(int svr_argc, char** svr_argv,
37 int cli_argc, char** cli_argv)
39 func_args cliArgs = {cli_argc, cli_argv, 0, NULL};
40 func_args svrArgs = {svr_argc, svr_argv, 0, NULL};
43 THREAD_TYPE serverThread;
44 char commandLine[MAX_COMMAND_SZ];
48 commandLine[0] = '\0';
49 for (i = 0; i < svr_argc; i++) {
50 strcat(commandLine, svr_argv[i]);
51 strcat(commandLine, " ");
53 printf("trying server command line[%d]: %s\n", tests, commandLine);
55 commandLine[0] = '\0';
56 for (i = 0; i < cli_argc; i++) {
57 strcat(commandLine, cli_argv[i]);
58 strcat(commandLine, " ");
60 printf("trying client command line[%d]: %s\n", tests++, commandLine);
65 svrArgs.signal = &ready;
66 start_thread(server_test, &svrArgs, &serverThread);
67 wait_tcp_ready(&svrArgs);
70 client_test(&cliArgs);
73 if (cliArgs.return_code != 0) {
74 printf("client_test failed\n");
78 join_thread(serverThread);
79 if (svrArgs.return_code != 0) {
80 printf("server_test failed\n");
88 void test_harness(void* vargs)
90 func_args* args = (func_args*)vargs;
93 int cliMode = 0; /* server or client command flag, server first */
95 char* svrArgs[MAX_ARGS];
97 char* cliArgs[MAX_ARGS];
101 char* fname = "tests/test.conf";
104 if (args->argc == 1) {
105 printf("notice: using default file %s\n", fname);
107 else if(args->argc != 2) {
108 printf("usage: harness [FILE]\n");
109 args->return_code = 1;
113 fname = args->argv[1];
116 file = fopen(fname, "r");
118 fprintf(stderr, "unable to open %s\n", fname);
119 args->return_code = 1;
122 fseek(file, 0, SEEK_END);
126 fprintf(stderr, "%s is empty\n", fname);
128 args->return_code = 1;
132 script = (char*)malloc(sz+1);
134 fprintf(stderr, "unable to allocte script buffer\n");
136 args->return_code = 1;
140 len = fread(script, 1, sz, file);
142 fprintf(stderr, "read error\n");
144 args->return_code = 1;
153 svrArgs[0] = args->argv[0];
155 cliArgs[0] = args->argv[0];
157 while (*cursor != 0) {
162 /* A blank line triggers test case execution or switches
163 to client mode if we don't have the client command yet */
165 cliMode = 1; /* switch to client mode processing */
167 do_it = 1; /* Do It, we have server and client */
171 /* Ignore lines that start with a #. */
172 comment = strsep(&cursor, "\n");
173 printf("%s\n", comment);
176 /* Parameters start with a -. They end in either a newline
177 * or a space. Capture until either, save in Args list. */
179 cliArgs[cliArgsSz++] = strsep(&cursor, " \n");
181 svrArgs[svrArgsSz++] = strsep(&cursor, " \n");
184 /* Anything from cursor until end of line that isn't the above
185 * is data for a paramter. Just up until the next newline in
188 cliArgs[cliArgsSz++] = strsep(&cursor, "\n");
190 svrArgs[svrArgsSz++] = strsep(&cursor, "\n");
191 if (*cursor == 0) /* eof */
195 if (svrArgsSz == MAX_ARGS || cliArgsSz == MAX_ARGS) {
196 fprintf(stderr, "too many arguments, forcing test run\n");
201 execute_test_case(svrArgsSz, svrArgs, cliArgsSz, cliArgs);
209 args->return_code = 0;
219 printf(" Begin Cipher Suite Tests\n");
222 myArgv[0] = argv0[0];
223 myArgv[1] = argv0[1];
225 strcpy(argv0[0], "SuiteTest");
229 printf("starting default cipher suite tests\n");
231 if (args.return_code != 0) {
232 printf("error from script %d\n", args.return_code);
236 /* any extra cases will need another argument */
240 /* add openssl extra suites */
241 strcpy(argv0[1], "tests/test-openssl.conf");
242 printf("starting openssl extra cipher suite tests\n");
244 if (args.return_code != 0) {
245 printf("error from script %d\n", args.return_code);
251 /* add hc128 extra suites */
252 strcpy(argv0[1], "tests/test-hc128.conf");
253 printf("starting hc128 extra cipher suite tests\n");
255 if (args.return_code != 0) {
256 printf("error from script %d\n", args.return_code);
262 /* add psk extra suites */
263 strcpy(argv0[1], "tests/test-psk.conf");
264 printf("starting psk extra cipher suite tests\n");
266 if (args.return_code != 0) {
267 printf("error from script %d\n", args.return_code);
273 /* add ntru extra suites */
274 strcpy(argv0[1], "tests/test-ntru.conf");
275 printf("starting ntru extra cipher suite tests\n");
277 if (args.return_code != 0) {
278 printf("error from script %d\n", args.return_code);
284 /* add ecc extra suites */
285 strcpy(argv0[1], "tests/test-ecc.conf");
286 printf("starting ecc extra cipher suite tests\n");
288 if (args.return_code != 0) {
289 printf("error from script %d\n", args.return_code);
295 /* add aesgcm extra suites */
296 strcpy(argv0[1], "tests/test-aesgcm.conf");
297 printf("starting aesgcm extra cipher suite tests\n");
299 if (args.return_code != 0) {
300 printf("error from script %d\n", args.return_code);
305 #if defined(HAVE_AESGCM) && defined(OPENSSL_EXTRA)
306 /* add aesgcm openssl extra suites */
307 strcpy(argv0[1], "tests/test-aesgcm-openssl.conf");
308 printf("starting aesgcm openssl extra cipher suite tests\n");
310 if (args.return_code != 0) {
311 printf("error from script %d\n", args.return_code);
316 #if defined(HAVE_AESGCM) && defined(HAVE_ECC)
317 /* add aesgcm ecc extra suites */
318 strcpy(argv0[1], "tests/test-aesgcm-ecc.conf");
319 printf("starting aesgcm ecc extra cipher suite tests\n");
321 if (args.return_code != 0) {
322 printf("error from script %d\n", args.return_code);
328 /* add dtls extra suites */
329 strcpy(argv0[1], "tests/test-dtls.conf");
330 printf("starting dtls extra cipher suite tests\n");
332 if (args.return_code != 0) {
333 printf("error from script %d\n", args.return_code);
338 printf(" End Cipher Suite Tests\n");
340 return args.return_code;