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 #ifndef HELPER_H 17 #define HELPER_H 18 19 #include <stdio.h> 20 #include <string.h> 21 #include <stdlib.h> 22 #include <stdbool.h> 23 #include <stdint.h> 24 #include <stdarg.h> 25 26 #ifdef __cplusplus 27 extern "C" { 28 #endif 29 30 #define MAX_TEST_FUCNTION_COUNT 100 31 #define MAX_TEST_FUNCTION_NAME 500 32 #define MAX_ARGUMENT_COUNT 50 33 #define MAX_EXPRESSION_COUNT 100 34 #define MAX_EXPRESSION_LEN 100 35 #define MAX_DATA_LINE_LEN 120000 36 #define MAX_FUNCTION_LINE_LEN 512 37 #define MAX_FILE_PATH_LEN 300 38 #define MAX_SUITE_COUNT 600 39 #define MAX_LOG_LEN 500 40 41 #define TAG_NOT_TAG 0 42 #define TAG_BEGIN_HEADER 1 43 #define TAG_END_HEADER 2 44 #define TAG_BEGIN_CASE 3 45 #define TAG_END_CASE 4 46 #define TAG_INCLUDE_BASE 5 47 48 #define SPILT_HEX_BLOCK_SIZE 4 49 50 #define ARG_TYPE_INT 1 51 #define ARG_TYPE_STR 2 52 #define ARG_TYPE_HEX 3 53 54 #define BASE_FILE_FORMAT "%s/%s.base.c" 55 #define LOG_FILE_DIR "./log/" 56 #define LOG_FILE_FORMAT "./log/%s" 57 #define FUZZ_PRINT_EXECUTES "\r%d" 58 59 typedef struct { 60 char name[MAX_FILE_PATH_LEN]; 61 int total; 62 int pass; 63 int skip; 64 int line; 65 } TestSuiteResult; 66 67 typedef struct { 68 char name[MAX_TEST_FUNCTION_NAME]; 69 int id; 70 int argType[MAX_ARGUMENT_COUNT]; 71 uint32_t argCount; 72 } FunctionTable; 73 74 typedef struct { 75 uint8_t *x; 76 uint32_t len; 77 } Hex; 78 79 extern FunctionTable g_testFunc[MAX_TEST_FUCNTION_COUNT]; 80 extern int g_testFuncCount; 81 extern char g_expTable[MAX_EXPRESSION_COUNT][MAX_EXPRESSION_LEN]; 82 extern int g_expCount; 83 84 void Print(const char *fmt, ...); 85 86 void SetOutputFile(FILE *fp); 87 88 FILE *GetOutputFile(void); 89 90 void FreeHex(Hex *data); 91 92 Hex *NewHex(void); 93 94 int IsInt(const char *str); 95 96 int ReadLine(FILE *file, char *buf, uint32_t bufLen, bool skipHash, bool skipEmptyLine); 97 98 int SplitArguments(char *inStr, uint32_t inLen, char **outParam, uint32_t *paramLen); 99 100 int ReadFunction(const char *in, const uint32_t inLen, char *outFuncName, uint32_t outLen, int argv[MAX_ARGUMENT_COUNT], 101 uint32_t *argCount); 102 103 int AddFunction(const char *funcName, int argv[MAX_ARGUMENT_COUNT], const uint32_t argCount); 104 105 int CheckTag(char *in, uint32_t len); 106 107 int GenFunctionWrapper(FILE *file, FunctionTable *function); 108 109 int ScanAllFunction(FILE *inFile, FILE *outFile); 110 111 int ScanHeader(FILE *inFile, FILE *outFile, const char *dir); 112 113 int GenFunctionPointer(FILE *file); 114 115 int GenDatax(FILE *inFile, FILE *outFile); 116 117 int GenExpTable(FILE *outFile); 118 119 int LoadFunctionName(FILE *outFile); 120 121 int LoadHelper(FILE *inFile, FILE *outFile); 122 123 int ScanFunctionFile(FILE *fpIn, FILE *fpOut, const char *dir); 124 125 int StripDir(const char *in, char *suiteName, const uint32_t suiteNameLen, char *dir, const uint32_t dirNameLen); 126 127 FILE *OpenFile(const char *name, const char *option, const char *format); 128 129 int GenResult(void); 130 131 int SplitHex(Hex *src, Hex *dest, int max); 132 133 int SplitHexRand(Hex *src, Hex *dest, int max); 134 135 int WriteHeader(FILE *outFile); 136 #ifdef __cplusplus 137 } 138 #endif 139 140 #endif // HELPER_H