diff --git a/src/os/inc/osFile.h b/src/os/inc/osFile.h index 4f4d9e8aedf48b2334a8251d5beecc9118574051..c43428ab8208508c3df1f16bb5462cec555baafe 100644 --- a/src/os/inc/osFile.h +++ b/src/os/inc/osFile.h @@ -30,19 +30,24 @@ int taosFSendFileImp(FILE* out_file, FILE* in_file, int64_t* offset, int32_t #define taosTSendFile(dfd, sfd, offset, size) taosTSendFileImp(dfd, sfd, offset, size) #define taosFSendFile(outfile, infile, offset, count) taosTSendFileImp(fileno(outfile), fileno(infile), offset, size) -#ifndef TAOS_RANDOM_FILE_FAIL - #define taosTRead(fd, buf, count) taosTReadImp(fd, buf, count) - #define taosTWrite(fd, buf, count) taosTWriteImp(fd, buf, count) - #define taosLSeek(fd, offset, whence) lseek(fd, offset, whence) -#else +#define taosTRead(fd, buf, count) taosTReadImp(fd, buf, count) +#define taosTWrite(fd, buf, count) taosTWriteImp(fd, buf, count) +#define taosLSeek(fd, offset, whence) lseek(fd, offset, whence) + +#ifdef TAOS_RANDOM_FILE_FAIL void taosSetRandomFileFailFactor(int factor); void taosSetRandomFileFailOutput(const char *path); - ssize_t taosReadFileRandomFail(int fd, void *buf, size_t count, const char *file, uint32_t line); - ssize_t taosWriteFileRandomFail(int fd, void *buf, size_t count, const char *file, uint32_t line); - off_t taosLSeekRandomFail(int fd, off_t offset, int whence, const char *file, uint32_t line); - #define taosTRead(fd, buf, count) taosReadFileRandomFail(fd, buf, count, __FILE__, __LINE__) - #define taosTWrite(fd, buf, count) taosWriteFileRandomFail(fd, buf, count, __FILE__, __LINE__) - #define taosLSeek(fd, offset, whence) taosLSeekRandomFail(fd, offset, whence, __FILE__, __LINE__) + #ifdef TAOS_RANDOM_FILE_FAIL_TEST + ssize_t taosReadFileRandomFail(int fd, void *buf, size_t count, const char *file, uint32_t line); + ssize_t taosWriteFileRandomFail(int fd, void *buf, size_t count, const char *file, uint32_t line); + off_t taosLSeekRandomFail(int fd, off_t offset, int whence, const char *file, uint32_t line); + #undef taosTRead + #undef taosTWrite + #undef taosLSeek + #define taosTRead(fd, buf, count) taosReadFileRandomFail(fd, buf, count, __FILE__, __LINE__) + #define taosTWrite(fd, buf, count) taosWriteFileRandomFail(fd, buf, count, __FILE__, __LINE__) + #define taosLSeek(fd, offset, whence) taosLSeekRandomFail(fd, offset, whence, __FILE__, __LINE__) + #endif #endif // TAOS_OS_FUNC_FILE_GETTMPFILEPATH diff --git a/src/os/inc/osMemory.h b/src/os/inc/osMemory.h index eb2ff02f778f0ba2a4d8f039212e67c7721927bb..aaac8c68e31c480c9b7a793be110b0e8f316ff48 100644 --- a/src/os/inc/osMemory.h +++ b/src/os/inc/osMemory.h @@ -46,29 +46,38 @@ void taosTMemset(void *ptr, int c); } \ } while (0); -#ifndef TAOS_MEM_CHECK - #define taosMalloc(size) malloc(size) - #define taosCalloc(num, size) calloc(num, size) - #define taosRealloc(ptr, size) realloc(ptr, size) - #define taosFree(ptr) free(ptr) - #define taosStrdup(str) taosStrdupImp(str) - #define taosStrndup(str, size) taosStrndupImp(str, size) - #define taosGetline(lineptr, n, stream) taosGetlineImp(lineptr, n, stream) -#else - void * taos_malloc(size_t size, const char *file, uint32_t line); - void * taos_calloc(size_t num, size_t size, const char *file, uint32_t line); - void * taos_realloc(void *ptr, size_t size, const char *file, uint32_t line); - void taos_free(void *ptr, const char *file, uint32_t line); - char * taos_strdup(const char *str, const char *file, uint32_t line); - char * taos_strndup(const char *str, size_t size, const char *file, uint32_t line); - ssize_t taos_getline(char **lineptr, size_t *n, FILE *stream, const char *file, uint32_t line); - #define taosMalloc(size) taos_malloc(size, __FILE__, __LINE__) - #define taosCalloc(num, size) taos_calloc(num, size, __FILE__, __LINE__) - #define taosRealloc(ptr, size) taos_realloc(ptr, size, __FILE__, __LINE__) - #define taosFree(ptr) taos_free(ptr, __FILE__, __LINE__) - #define taosStrdup(str) taos_strdup(str, __FILE__, __LINE__) - #define taosStrndup(str, size) taos_strndup(str, size, __FILE__, __LINE__) - #define taosGetline(lineptr, n, stream) taos_getline(lineptr, n, stream, __FILE__, __LINE__) +#define taosMalloc(size) malloc(size) +#define taosCalloc(num, size) calloc(num, size) +#define taosRealloc(ptr, size) realloc(ptr, size) +#define taosFree(ptr) free(ptr) +#define taosStrdup(str) taosStrdupImp(str) +#define taosStrndup(str, size) taosStrndupImp(str, size) +#define taosGetline(lineptr, n, stream) taosGetlineImp(lineptr, n, stream) + +#ifdef TAOS_MEM_CHECK + #ifdef TAOS_MEM_CHECK_TEST + void * taos_malloc(size_t size, const char *file, uint32_t line); + void * taos_calloc(size_t num, size_t size, const char *file, uint32_t line); + void * taos_realloc(void *ptr, size_t size, const char *file, uint32_t line); + void taos_free(void *ptr, const char *file, uint32_t line); + char * taos_strdup(const char *str, const char *file, uint32_t line); + char * taos_strndup(const char *str, size_t size, const char *file, uint32_t line); + ssize_t taos_getline(char **lineptr, size_t *n, FILE *stream, const char *file, uint32_t line); + #undef taosMalloc + #undef taosCalloc + #undef taosRealloc + #undef taosFree + #undef taosStrdup + #undef taosStrndup + #undef taosGetline + #define taosMalloc(size) taos_malloc(size, __FILE__, __LINE__) + #define taosCalloc(num, size) taos_calloc(num, size, __FILE__, __LINE__) + #define taosRealloc(ptr, size) taos_realloc(ptr, size, __FILE__, __LINE__) + #define taosFree(ptr) taos_free(ptr, __FILE__, __LINE__) + #define taosStrdup(str) taos_strdup(str, __FILE__, __LINE__) + #define taosStrndup(str, size) taos_strndup(str, size, __FILE__, __LINE__) + #define taosGetline(lineptr, n, stream) taos_getline(lineptr, n, stream, __FILE__, __LINE__) + #endif #endif #ifdef __cplusplus diff --git a/src/os/inc/osSocket.h b/src/os/inc/osSocket.h index f013ae4a3a6fc96c30198d45cae045270b9c1e72..749d3906f5cd6d7393280c8912c466cfe2001170 100644 --- a/src/os/inc/osSocket.h +++ b/src/os/inc/osSocket.h @@ -35,18 +35,20 @@ extern "C" { #define taosClose(x) taosCloseSocket(x) #ifdef TAOS_RANDOM_NETWORK_FAIL - ssize_t taosSendRandomFail(int sockfd, const void *buf, size_t len, int flags); - ssize_t taosSendToRandomFail(int sockfd, const void *buf, size_t len, int flags, const struct sockaddr *dest_addr, socklen_t addrlen); - ssize_t taosReadSocketRandomFail(int fd, void *buf, size_t count); - ssize_t taosWriteSocketRandomFail(int fd, const void *buf, size_t count); - #undef taosSend - #undef taosSendto - #undef taosReadSocket - #undef taosWriteSocket - #define taosSend(sockfd, buf, len, flags) taosSendRandomFail(sockfd, buf, len, flags) - #define taosSendto(sockfd, buf, len, flags, dest_addr, addrlen) taosSendToRandomFail(sockfd, buf, len, flags, dest_addr, addrlen) - #define taosReadSocket(fd, buf, len) taosReadSocketRandomFail(fd, buf, len) - #define taosWriteSocket(fd, buf, len) taosWriteSocketRandomFail(fd, buf, len) + #ifdef TAOS_RANDOM_NETWORK_FAIL_TEST + ssize_t taosSendRandomFail(int sockfd, const void *buf, size_t len, int flags); + ssize_t taosSendToRandomFail(int sockfd, const void *buf, size_t len, int flags, const struct sockaddr *dest_addr, socklen_t addrlen); + ssize_t taosReadSocketRandomFail(int fd, void *buf, size_t count); + ssize_t taosWriteSocketRandomFail(int fd, const void *buf, size_t count); + #undef taosSend + #undef taosSendto + #undef taosReadSocket + #undef taosWriteSocket + #define taosSend(sockfd, buf, len, flags) taosSendRandomFail(sockfd, buf, len, flags) + #define taosSendto(sockfd, buf, len, flags, dest_addr, addrlen) taosSendToRandomFail(sockfd, buf, len, flags, dest_addr, addrlen) + #define taosReadSocket(fd, buf, len) taosReadSocketRandomFail(fd, buf, len) + #define taosWriteSocket(fd, buf, len) taosWriteSocketRandomFail(fd, buf, len) + #endif #endif // TAOS_OS_FUNC_SOCKET diff --git a/src/tsdb/src/tsdbFile.c b/src/tsdb/src/tsdbFile.c index 299802f9b418772a51c9f1d0501989ea06e527a9..e3800f811788d8d2fef25830b7ca8ef3df668d37 100644 --- a/src/tsdb/src/tsdbFile.c +++ b/src/tsdb/src/tsdbFile.c @@ -14,11 +14,11 @@ */ #define _DEFAULT_SOURCE #include "os.h" - #include "talgo.h" #include "tchecksum.h" #include "tsdbMain.h" #include "tutil.h" +#define TAOS_RANDOM_FILE_FAIL_TEST #ifdef TSDB_IDX const char *tsdbFileSuffix[] = {".idx", ".head", ".data", ".last", "", ".i", ".h", ".l"}; diff --git a/src/tsdb/src/tsdbMain.c b/src/tsdb/src/tsdbMain.c index e23228cc0ef9331c5853a5607b67b10e12be8af1..0d7a2866b7dfe55fe53db2cfeba1eeeda352f093 100644 --- a/src/tsdb/src/tsdbMain.c +++ b/src/tsdb/src/tsdbMain.c @@ -14,8 +14,6 @@ */ // no test file errors here -#undef TAOS_RANDOM_FILE_FAIL - #include "tsdbMain.h" #include "os.h" #include "talgo.h" @@ -25,7 +23,6 @@ #include "tsdb.h" #include "tulog.h" - #define TSDB_CFG_FILE_NAME "config" #define TSDB_DATA_DIR_NAME "data" #define TSDB_META_FILE_NAME "meta" diff --git a/src/tsdb/src/tsdbRWHelper.c b/src/tsdb/src/tsdbRWHelper.c index 9a96ec62e2ea42608526ab3568d5bbae3c70f809..6e14a86bd78fe22fa435ebdee2619fb2f91ef6b6 100644 --- a/src/tsdb/src/tsdbRWHelper.c +++ b/src/tsdb/src/tsdbRWHelper.c @@ -20,6 +20,7 @@ #include "tcoding.h" #include "tscompression.h" #include "tsdbMain.h" +#define TAOS_RANDOM_FILE_FAIL_TEST #define TSDB_GET_COMPCOL_LEN(nCols) (sizeof(SCompData) + sizeof(SCompCol) * (nCols) + sizeof(TSCKSUM)) #define TSDB_KEY_COL_OFFSET 0 diff --git a/src/util/src/tkvstore.c b/src/util/src/tkvstore.c index 2cea295c822a8564e4cab91c3a43ab0642a2a5fc..edcf9d45f2045bfe7fe8a745b405463cfd4416dc 100644 --- a/src/util/src/tkvstore.c +++ b/src/util/src/tkvstore.c @@ -21,6 +21,7 @@ #include "tcoding.h" #include "tkvstore.h" #include "tulog.h" +#define TAOS_RANDOM_FILE_FAIL_TEST #define TD_KVSTORE_HEADER_SIZE 512 #define TD_KVSTORE_MAJOR_VERSION 1 diff --git a/src/util/src/tlog.c b/src/util/src/tlog.c index 6bba8885b11a72d283cb64f2320560d30eb646f2..913989bf5286123130b4e08b4eb010362a258397 100644 --- a/src/util/src/tlog.c +++ b/src/util/src/tlog.c @@ -14,9 +14,6 @@ */ #define _DEFAULT_SOURCE -// no test file errors here -#undef TAOS_RANDOM_FILE_FAIL - #include "os.h" #include "tulog.h" #include "tlog.h" diff --git a/src/util/src/tnote.c b/src/util/src/tnote.c index 91916c92d7f1feb2b7b594ae1d7541cb95e4db07..ea097094498bdafdea19d71c48aa2a6f61a6e181 100644 --- a/src/util/src/tnote.c +++ b/src/util/src/tnote.c @@ -13,9 +13,7 @@ * along with this program. If not, see . */ -// no test file errors here -#undef TAOS_RANDOM_FILE_FAIL - +#include "os.h" #include "tnote.h" taosNoteInfo m_HttpNote; diff --git a/src/wal/src/walMain.c b/src/wal/src/walMain.c index a8f88c7be9532b646614c09d472505a2086a000f..4ac8a096c6027d10c7ff6f506ed7cefa703c861c 100644 --- a/src/wal/src/walMain.c +++ b/src/wal/src/walMain.c @@ -22,6 +22,7 @@ #include "taoserror.h" #include "twal.h" #include "tqueue.h" +#define TAOS_RANDOM_FILE_FAIL_TEST #define walPrefix "wal"