1 /*
2 * This file is part of the openHiTLS project.
3 *
4 * openHiTLS is licensed under the Mulan PSL v2.
5 * You can use this software according to the terms and conditions of the Mulan PSL v2.
6 * You may obtain a copy of Mulan PSL v2 at:
7 *
8 * http://license.coscl.org.cn/MulanPSL2
9 *
10 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
11 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
12 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
13 * See the Mulan PSL v2 for more details.
14 */
15
16 #include <signal.h>
17 #include <stdarg.h>
18 #include <unistd.h>
19 #include "securec.h"
20
21 #define BUF_SIZE (65536 * 17)
22 #define MAX_RAND_SIZE (1024 * 16)
23 #define MAX_PATH 1024
24 #define MAX_FILE_NAME 200
25 #define MAX_IN_CASES 100000
26 #define OUTPUT_LINE_LENGTH 60
27
28 #ifdef FAIL_REPEAT_RUN
29 #define FAIL_TRY_TIMES 3
30 #else
31 #define FAIL_TRY_TIMES 0
32 #endif
33
34 #define FUNCTION_LOG_FORMAT "./log/%s.%s.log"
35 #define SUITE_LOG_FORMAT "./log/%s.log"
36 #define LOCAL_DIR "./"
37
38 typedef struct {
39 char buf[MAX_DATA_LINE_LEN];
40 char *arg[MAX_ARGUMENT_COUNT];
41 char testVectorName[MAX_FILE_NAME];
42 uint32_t argLen;
43 } TestArgs;
44
45 typedef struct {
46 void *param[MAX_ARGUMENT_COUNT];
47 int paramCount;
48 int intParam[MAX_ARGUMENT_COUNT];
49 int intParamCount;
50 Hex hexParam[MAX_ARGUMENT_COUNT];
51 int hexParamCount;
52 } TestParam;
53
54 static TestArgs *g_executeCases[MAX_IN_CASES];
55 static int g_executeCount = 0;
56
ConvertStringCase(const TestArgs * arg)57 static int ConvertStringCase(const TestArgs *arg)
58 {
59 for (uint32_t i = 1; i < arg->argLen; i += 2) {
60 if (strcmp(arg->arg[i], "char") == 0 || strcmp(arg->arg[i], "Hex") == 0) {
61 if (ConvertString((char **)&(arg->arg[i+1])) != 0) {
62 return 1;
63 }
64 }
65 }
66 return 0;
67 }
68
LoadDataFile(const char * fileName)69 static int LoadDataFile(const char *fileName)
70 {
71 if (g_executeCount > 0) {
72 return 0;
73 }
74 FILE *fpDatax = fopen(fileName, "r");
75 if (fpDatax == NULL) {
76 Print("Error opening file\n");
77 return (-1);
78 }
79 int rt = 0;
80 for (int i = 0; i < MAX_IN_CASES; i++) {
81 g_executeCases[i] = (TestArgs *)malloc(sizeof(TestArgs));
82 if (g_executeCases[i] == NULL) {
83 rt = -1;
84 goto EXIT;
85 }
86 g_executeCases[i]->argLen = MAX_ARGUMENT_COUNT;
87 if (ReadLine(fpDatax, g_executeCases[i]->testVectorName, MAX_FILE_NAME, 1, 1) != 0) {
88 free(g_executeCases[i]);
89 goto EXIT;
90 }
91 if (ReadLine(fpDatax, g_executeCases[i]->buf, MAX_DATA_LINE_LEN, 1, 1) != 0) {
92 free(g_executeCases[i]);
93 Print("Read vector failed, test vector should have 2 lines, here there's only one\n");
94 rt = -1;
95 goto EXIT;
96 }
97 if (SplitArguments(g_executeCases[i]->buf, strlen(g_executeCases[i]->buf),
98 g_executeCases[i]->arg, &(g_executeCases[i]->argLen)) != 0) {
99 free(g_executeCases[i]);
100 rt = -1;
101 goto EXIT;
102 }
103 if (ConvertStringCase(g_executeCases[i]) == 1) {
104 free(g_executeCases[i]);
105 rt = -1;
106 goto EXIT;
107 }
108 g_executeCount += 1;
109 }
110 char tmpName[MAX_FILE_NAME];
111 if (ReadLine(fpDatax, tmpName, MAX_FILE_NAME, 1, 1) == 0) {
112 Print("More test cases than max case num %d\n", MAX_IN_CASES);
113 rt = -1;
114 }
115
116 EXIT:
117 if (rt != 0) {
118 for (int i = 0; i < g_executeCount; i++) {
119 free(g_executeCases[i]);
120 }
121 g_executeCount = 0;
122 }
123 (void)fclose(fpDatax);
124 return rt;
125 }