1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
| #ifndef __TEST_OUTPUT_H__ #define __TEST_OUTPUT_H__
#define OUTPUT_DIR "/data/test_output/" #define OUTPUT_FILE "<log_file_name>.output" #define MAX_MSG_LENTH (300) #define FULL_PATH_LENTH (100) #define FULL_CMD_LENTH (50 + FULL_PATH_LENTH)
inline static void test_output(char *output_info) { FILE *fp = NULL; char full_path[FULL_PATH_LENTH + 1]; char full_cmd[FULL_CMD_LENTH + 1];
memset(full_path, 0, sizeof(full_path)); memset(full_cmd, 0, sizeof(full_cmd)); snprintf(full_path, FULL_PATH_LENTH, "%s%s", OUTPUT_DIR, OUTPUT_FILE); snprintf(full_cmd, FULL_CMD_LENTH, "%s%s%s%s", "mkdir -p ", OUTPUT_DIR, ";touch ", full_path);
if (access(full_path, F_OK)) { system(full_cmd); }
fp = fopen(full_path, "a"); if (fp == NULL) { return; }
if (output_info == NULL) { fwrite("test_output internal error!!! output_info is null!\n", strlen("test_output internal error!!! output_info is null!\n"), 1, fp); return; } else if (strlen(output_info) >= MAX_MSG_LENTH) { fwrite("test_output internal error!!! output_info exceed lenth!\n", strlen("test_output internal error!!! output_info exceed lenth!\n"), 1, fp); return; } else { fwrite(output_info, strlen(output_info), 1, fp); }
fclose(fp);
return; }
#define TEST_OUTPUT(output_info, args...) do { \ char buffer[MAX_MSG_LENTH + 1]; \ time_t t; \ time(&t); \ struct tm *tmp_time = localtime(&t); \ char s[100]; \ \ strftime(s, sizeof(s), "%04Y%02m%02d %H:%M:%S", tmp_time); \ printf("%d: %s\n", (int)t, s); \ \ snprintf(buffer, MAX_MSG_LENTH, "[FUNC >> %s:%d t:%s] : "output_info"\n", \ __func__, __LINE__, s, ##args); \ test_output(buffer); \ } while (0)
#define IF_TRUE_TEST_OUTPUT(cond, output_info, args...) do { \ if (cond) { \ TEST_OUTPUT(output_info, ##args); \ } \ } while (0) #endif
|