commit
d3af2ff741
|
@ -355,7 +355,7 @@ void atomic_store_double(double volatile* ptr, double val) {
|
||||||
double_number ret_num = {0};
|
double_number ret_num = {0};
|
||||||
ret_num.i = atomic_val_compare_exchange_64((volatile int64_t*)ptr, old_num.i, new_num.i);
|
ret_num.i = atomic_val_compare_exchange_64((volatile int64_t*)ptr, old_num.i, new_num.i);
|
||||||
|
|
||||||
if (ret_num.i == old_num.i) return;
|
if (ret_num.i == old_num.i) break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -414,6 +414,8 @@ int64_t atomic_exchange_64(int64_t volatile* ptr, int64_t val) {
|
||||||
}
|
}
|
||||||
|
|
||||||
double atomic_exchange_double(double volatile* ptr, double val) {
|
double atomic_exchange_double(double volatile* ptr, double val) {
|
||||||
|
double ret = 0;
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
double_number old_num = {0};
|
double_number old_num = {0};
|
||||||
old_num.d = *ptr; // current old value
|
old_num.d = *ptr; // current old value
|
||||||
|
@ -425,9 +427,11 @@ double atomic_exchange_double(double volatile* ptr, double val) {
|
||||||
ret_num.i = atomic_val_compare_exchange_64((volatile int64_t*)ptr, old_num.i, new_num.i);
|
ret_num.i = atomic_val_compare_exchange_64((volatile int64_t*)ptr, old_num.i, new_num.i);
|
||||||
|
|
||||||
if (ret_num.i == old_num.i) {
|
if (ret_num.i == old_num.i) {
|
||||||
return ret_num.d;
|
ret = ret_num.d;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void* atomic_exchange_ptr(void* ptr, void* val) {
|
void* atomic_exchange_ptr(void* ptr, void* val) {
|
||||||
|
@ -589,6 +593,8 @@ int64_t atomic_fetch_add_64(int64_t volatile* ptr, int64_t val) {
|
||||||
}
|
}
|
||||||
|
|
||||||
double atomic_fetch_add_double(double volatile* ptr, double val) {
|
double atomic_fetch_add_double(double volatile* ptr, double val) {
|
||||||
|
double ret = 0;
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
double_number old_num = {0};
|
double_number old_num = {0};
|
||||||
old_num.d = *ptr; // current old value
|
old_num.d = *ptr; // current old value
|
||||||
|
@ -599,8 +605,13 @@ double atomic_fetch_add_double(double volatile* ptr, double val) {
|
||||||
double_number ret_num = {0};
|
double_number ret_num = {0};
|
||||||
ret_num.i = atomic_val_compare_exchange_64((volatile int64_t*)ptr, old_num.i, new_num.i);
|
ret_num.i = atomic_val_compare_exchange_64((volatile int64_t*)ptr, old_num.i, new_num.i);
|
||||||
|
|
||||||
if (ret_num.i == old_num.i) return ret_num.d;
|
if (ret_num.i == old_num.i) {
|
||||||
|
ret = ret_num.d;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void* atomic_fetch_add_ptr(void* ptr, int64_t val) {
|
void* atomic_fetch_add_ptr(void* ptr, int64_t val) {
|
||||||
|
@ -710,6 +721,8 @@ int64_t atomic_fetch_sub_64(int64_t volatile* ptr, int64_t val) {
|
||||||
}
|
}
|
||||||
|
|
||||||
double atomic_fetch_sub_double(double volatile* ptr, double val) {
|
double atomic_fetch_sub_double(double volatile* ptr, double val) {
|
||||||
|
double ret = 0;
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
double_number old_num = {0};
|
double_number old_num = {0};
|
||||||
old_num.d = *ptr; // current old value
|
old_num.d = *ptr; // current old value
|
||||||
|
@ -720,8 +733,13 @@ double atomic_fetch_sub_double(double volatile* ptr, double val) {
|
||||||
double_number ret_num = {0};
|
double_number ret_num = {0};
|
||||||
ret_num.i = atomic_val_compare_exchange_64((volatile int64_t*)ptr, old_num.i, new_num.i);
|
ret_num.i = atomic_val_compare_exchange_64((volatile int64_t*)ptr, old_num.i, new_num.i);
|
||||||
|
|
||||||
if (ret_num.i == old_num.i) return ret_num.d;
|
if (ret_num.i == old_num.i) {
|
||||||
|
ret = ret_num.d;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void* atomic_fetch_sub_ptr(void* ptr, int64_t val) {
|
void* atomic_fetch_sub_ptr(void* ptr, int64_t val) {
|
||||||
|
|
|
@ -23,18 +23,16 @@ int32_t taosThreadCreate(TdThread *tid, const TdThreadAttr *attr, void *(*start)
|
||||||
int32_t code = pthread_create(tid, attr, start, arg);
|
int32_t code = pthread_create(tid, attr, start, arg);
|
||||||
if (code) {
|
if (code) {
|
||||||
taosThreadClear(tid);
|
taosThreadClear(tid);
|
||||||
terrno = TAOS_SYSTEM_ERROR(code);
|
return (terrno = TAOS_SYSTEM_ERROR(code));
|
||||||
return terrno;
|
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t taosThreadAttrDestroy(TdThreadAttr *attr) {
|
int32_t taosThreadAttrDestroy(TdThreadAttr *attr) {
|
||||||
OS_PARAM_CHECK(attr);
|
OS_PARAM_CHECK(attr);
|
||||||
int32_t code = pthread_attr_destroy(attr);
|
int32_t code = pthread_attr_destroy(attr);
|
||||||
if (code) {
|
if (code) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(code);
|
return (terrno = TAOS_SYSTEM_ERROR(code));
|
||||||
return terrno;
|
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
@ -44,8 +42,7 @@ int32_t taosThreadAttrGetDetachState(const TdThreadAttr *attr, int32_t *detachst
|
||||||
OS_PARAM_CHECK(detachstate);
|
OS_PARAM_CHECK(detachstate);
|
||||||
int32_t code = pthread_attr_getdetachstate(attr, detachstate);
|
int32_t code = pthread_attr_getdetachstate(attr, detachstate);
|
||||||
if (code) {
|
if (code) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(code);
|
return (terrno = TAOS_SYSTEM_ERROR(code));
|
||||||
return terrno;
|
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
@ -55,8 +52,7 @@ int32_t taosThreadAttrGetInheritSched(const TdThreadAttr *attr, int32_t *inherit
|
||||||
OS_PARAM_CHECK(inheritsched);
|
OS_PARAM_CHECK(inheritsched);
|
||||||
int32_t code = pthread_attr_getinheritsched(attr, inheritsched);
|
int32_t code = pthread_attr_getinheritsched(attr, inheritsched);
|
||||||
if (code) {
|
if (code) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(code);
|
return (terrno = TAOS_SYSTEM_ERROR(code));
|
||||||
return terrno;
|
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
@ -66,8 +62,7 @@ int32_t taosThreadAttrGetSchedParam(const TdThreadAttr *attr, struct sched_param
|
||||||
OS_PARAM_CHECK(param);
|
OS_PARAM_CHECK(param);
|
||||||
int32_t code = pthread_attr_getschedparam(attr, param);
|
int32_t code = pthread_attr_getschedparam(attr, param);
|
||||||
if (code) {
|
if (code) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(code);
|
return (terrno = TAOS_SYSTEM_ERROR(code));
|
||||||
return terrno;
|
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
@ -77,8 +72,7 @@ int32_t taosThreadAttrGetSchedPolicy(const TdThreadAttr *attr, int32_t *policy)
|
||||||
OS_PARAM_CHECK(policy);
|
OS_PARAM_CHECK(policy);
|
||||||
int32_t code = pthread_attr_getschedpolicy(attr, policy);
|
int32_t code = pthread_attr_getschedpolicy(attr, policy);
|
||||||
if (code) {
|
if (code) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(code);
|
return (terrno = TAOS_SYSTEM_ERROR(code));
|
||||||
return terrno;
|
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
@ -88,8 +82,7 @@ int32_t taosThreadAttrGetScope(const TdThreadAttr *attr, int32_t *contentionscop
|
||||||
OS_PARAM_CHECK(contentionscope);
|
OS_PARAM_CHECK(contentionscope);
|
||||||
int32_t code = pthread_attr_getscope(attr, contentionscope);
|
int32_t code = pthread_attr_getscope(attr, contentionscope);
|
||||||
if (code) {
|
if (code) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(code);
|
return (terrno = TAOS_SYSTEM_ERROR(code));
|
||||||
return terrno;
|
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
@ -99,18 +92,16 @@ int32_t taosThreadAttrGetStackSize(const TdThreadAttr *attr, size_t *stacksize)
|
||||||
OS_PARAM_CHECK(stacksize);
|
OS_PARAM_CHECK(stacksize);
|
||||||
int32_t code = pthread_attr_getstacksize(attr, stacksize);
|
int32_t code = pthread_attr_getstacksize(attr, stacksize);
|
||||||
if (code) {
|
if (code) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(code);
|
return (terrno = TAOS_SYSTEM_ERROR(code));
|
||||||
return terrno;
|
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t taosThreadAttrInit(TdThreadAttr *attr) {
|
int32_t taosThreadAttrInit(TdThreadAttr *attr) {
|
||||||
OS_PARAM_CHECK(attr);
|
OS_PARAM_CHECK(attr);
|
||||||
int32_t code = pthread_attr_init(attr);
|
int32_t code = pthread_attr_init(attr);
|
||||||
if (code) {
|
if (code) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(code);
|
return (terrno = TAOS_SYSTEM_ERROR(code));
|
||||||
return terrno;
|
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
@ -119,8 +110,7 @@ int32_t taosThreadAttrSetDetachState(TdThreadAttr *attr, int32_t detachstate) {
|
||||||
OS_PARAM_CHECK(attr);
|
OS_PARAM_CHECK(attr);
|
||||||
int32_t code = pthread_attr_setdetachstate(attr, detachstate);
|
int32_t code = pthread_attr_setdetachstate(attr, detachstate);
|
||||||
if (code) {
|
if (code) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(code);
|
return (terrno = TAOS_SYSTEM_ERROR(code));
|
||||||
return terrno;
|
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
@ -129,8 +119,7 @@ int32_t taosThreadAttrSetInheritSched(TdThreadAttr *attr, int32_t inheritsched)
|
||||||
OS_PARAM_CHECK(attr);
|
OS_PARAM_CHECK(attr);
|
||||||
int32_t code = pthread_attr_setinheritsched(attr, inheritsched);
|
int32_t code = pthread_attr_setinheritsched(attr, inheritsched);
|
||||||
if (code) {
|
if (code) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(code);
|
return (terrno = TAOS_SYSTEM_ERROR(code));
|
||||||
return terrno;
|
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
@ -139,8 +128,7 @@ int32_t taosThreadAttrSetSchedParam(TdThreadAttr *attr, const struct sched_param
|
||||||
OS_PARAM_CHECK(attr);
|
OS_PARAM_CHECK(attr);
|
||||||
int32_t code = pthread_attr_setschedparam(attr, param);
|
int32_t code = pthread_attr_setschedparam(attr, param);
|
||||||
if (code) {
|
if (code) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(code);
|
return (terrno = TAOS_SYSTEM_ERROR(code));
|
||||||
return terrno;
|
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
@ -149,8 +137,7 @@ int32_t taosThreadAttrSetSchedPolicy(TdThreadAttr *attr, int32_t policy) {
|
||||||
OS_PARAM_CHECK(attr);
|
OS_PARAM_CHECK(attr);
|
||||||
int32_t code = pthread_attr_setschedpolicy(attr, policy);
|
int32_t code = pthread_attr_setschedpolicy(attr, policy);
|
||||||
if (code) {
|
if (code) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(code);
|
return (terrno = TAOS_SYSTEM_ERROR(code));
|
||||||
return terrno;
|
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
@ -159,8 +146,7 @@ int32_t taosThreadAttrSetScope(TdThreadAttr *attr, int32_t contentionscope) {
|
||||||
OS_PARAM_CHECK(attr);
|
OS_PARAM_CHECK(attr);
|
||||||
int32_t code = pthread_attr_setscope(attr, contentionscope);
|
int32_t code = pthread_attr_setscope(attr, contentionscope);
|
||||||
if (code) {
|
if (code) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(code);
|
return (terrno = TAOS_SYSTEM_ERROR(code));
|
||||||
return terrno;
|
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
@ -169,17 +155,15 @@ int32_t taosThreadAttrSetStackSize(TdThreadAttr *attr, size_t stacksize) {
|
||||||
OS_PARAM_CHECK(attr);
|
OS_PARAM_CHECK(attr);
|
||||||
int32_t code = pthread_attr_setstacksize(attr, stacksize);
|
int32_t code = pthread_attr_setstacksize(attr, stacksize);
|
||||||
if (code) {
|
if (code) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(code);
|
return (terrno = TAOS_SYSTEM_ERROR(code));
|
||||||
return terrno;
|
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t taosThreadCancel(TdThread thread) {
|
int32_t taosThreadCancel(TdThread thread) {
|
||||||
int32_t code = pthread_cancel(thread);
|
int32_t code = pthread_cancel(thread);
|
||||||
if (code) {
|
if (code) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(code);
|
return (terrno = TAOS_SYSTEM_ERROR(code));
|
||||||
return terrno;
|
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
@ -191,8 +175,7 @@ int32_t taosThreadCondDestroy(TdThreadCond *cond) {
|
||||||
#else
|
#else
|
||||||
int32_t code = pthread_cond_destroy(cond);
|
int32_t code = pthread_cond_destroy(cond);
|
||||||
if (code) {
|
if (code) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(code);
|
return (terrno = TAOS_SYSTEM_ERROR(code));
|
||||||
return terrno;
|
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
#endif
|
#endif
|
||||||
|
@ -206,8 +189,7 @@ int32_t taosThreadCondInit(TdThreadCond *cond, const TdThreadCondAttr *attr) {
|
||||||
#else
|
#else
|
||||||
int32_t code = pthread_cond_init(cond, attr);
|
int32_t code = pthread_cond_init(cond, attr);
|
||||||
if (code) {
|
if (code) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(code);
|
return (terrno = TAOS_SYSTEM_ERROR(code));
|
||||||
return terrno;
|
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
#endif
|
#endif
|
||||||
|
@ -221,8 +203,7 @@ int32_t taosThreadCondSignal(TdThreadCond *cond) {
|
||||||
#else
|
#else
|
||||||
int32_t code = pthread_cond_signal(cond);
|
int32_t code = pthread_cond_signal(cond);
|
||||||
if (code) {
|
if (code) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(code);
|
return (terrno = TAOS_SYSTEM_ERROR(code));
|
||||||
return terrno;
|
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
#endif
|
#endif
|
||||||
|
@ -236,8 +217,7 @@ int32_t taosThreadCondBroadcast(TdThreadCond *cond) {
|
||||||
#else
|
#else
|
||||||
int32_t code = pthread_cond_broadcast(cond);
|
int32_t code = pthread_cond_broadcast(cond);
|
||||||
if (code) {
|
if (code) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(code);
|
return (terrno = TAOS_SYSTEM_ERROR(code));
|
||||||
return terrno;
|
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
#endif
|
#endif
|
||||||
|
@ -254,8 +234,7 @@ int32_t taosThreadCondWait(TdThreadCond *cond, TdThreadMutex *mutex) {
|
||||||
#else
|
#else
|
||||||
int32_t code = pthread_cond_wait(cond, mutex);
|
int32_t code = pthread_cond_wait(cond, mutex);
|
||||||
if (code) {
|
if (code) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(code);
|
return (terrno = TAOS_SYSTEM_ERROR(code));
|
||||||
return terrno;
|
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
#endif
|
#endif
|
||||||
|
@ -274,7 +253,7 @@ int32_t taosThreadCondTimedWait(TdThreadCond *cond, TdThreadMutex *mutex, const
|
||||||
return TAOS_SYSTEM_WINAPI_ERROR(error);
|
return TAOS_SYSTEM_WINAPI_ERROR(error);
|
||||||
#else
|
#else
|
||||||
int32_t code = pthread_cond_timedwait(cond, mutex, abstime);
|
int32_t code = pthread_cond_timedwait(cond, mutex, abstime);
|
||||||
if(code == ETIMEDOUT) {
|
if (code == ETIMEDOUT) {
|
||||||
return TSDB_CODE_TIMEOUT_ERROR;
|
return TSDB_CODE_TIMEOUT_ERROR;
|
||||||
} else if (code) {
|
} else if (code) {
|
||||||
return TAOS_SYSTEM_ERROR(code);
|
return TAOS_SYSTEM_ERROR(code);
|
||||||
|
@ -291,14 +270,14 @@ int32_t taosThreadCondAttrDestroy(TdThreadCondAttr *attr) {
|
||||||
OS_PARAM_CHECK(attr);
|
OS_PARAM_CHECK(attr);
|
||||||
int32_t code = pthread_condattr_destroy(attr);
|
int32_t code = pthread_condattr_destroy(attr);
|
||||||
if (code) {
|
if (code) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(code);
|
return (terrno = TAOS_SYSTEM_ERROR(code));
|
||||||
return terrno;
|
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t taosThreadCondAttrGetPshared(const TdThreadCondAttr *attr, int32_t *pshared) {
|
int32_t taosThreadCondAttrGetPshared(const TdThreadCondAttr *attr, int32_t *pshared) {
|
||||||
|
OS_PARAM_CHECK(attr);
|
||||||
OS_PARAM_CHECK(pshared);
|
OS_PARAM_CHECK(pshared);
|
||||||
#ifdef __USE_WIN_THREAD
|
#ifdef __USE_WIN_THREAD
|
||||||
if (pshared) *pshared = PTHREAD_PROCESS_PRIVATE;
|
if (pshared) *pshared = PTHREAD_PROCESS_PRIVATE;
|
||||||
|
@ -307,8 +286,7 @@ int32_t taosThreadCondAttrGetPshared(const TdThreadCondAttr *attr, int32_t *psha
|
||||||
OS_PARAM_CHECK(attr);
|
OS_PARAM_CHECK(attr);
|
||||||
int32_t code = pthread_condattr_getpshared(attr, pshared);
|
int32_t code = pthread_condattr_getpshared(attr, pshared);
|
||||||
if (code) {
|
if (code) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(code);
|
return (terrno = TAOS_SYSTEM_ERROR(code));
|
||||||
return terrno;
|
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
#endif
|
#endif
|
||||||
|
@ -321,8 +299,7 @@ int32_t taosThreadCondAttrInit(TdThreadCondAttr *attr) {
|
||||||
OS_PARAM_CHECK(attr);
|
OS_PARAM_CHECK(attr);
|
||||||
int32_t code = pthread_condattr_init(attr);
|
int32_t code = pthread_condattr_init(attr);
|
||||||
if (code) {
|
if (code) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(code);
|
return (terrno = TAOS_SYSTEM_ERROR(code));
|
||||||
return terrno;
|
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
#endif
|
#endif
|
||||||
|
@ -337,8 +314,7 @@ int32_t taosThreadCondAttrSetclock(TdThreadCondAttr *attr, int clockId) {
|
||||||
OS_PARAM_CHECK(attr);
|
OS_PARAM_CHECK(attr);
|
||||||
int32_t code = pthread_condattr_setclock(attr, clockId);
|
int32_t code = pthread_condattr_setclock(attr, clockId);
|
||||||
if (code) {
|
if (code) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(code);
|
return (terrno = TAOS_SYSTEM_ERROR(code));
|
||||||
return terrno;
|
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
#endif
|
#endif
|
||||||
|
@ -351,28 +327,24 @@ int32_t taosThreadCondAttrSetPshared(TdThreadCondAttr *attr, int32_t pshared) {
|
||||||
#else
|
#else
|
||||||
int32_t code = pthread_condattr_setpshared(attr, pshared);
|
int32_t code = pthread_condattr_setpshared(attr, pshared);
|
||||||
if (code) {
|
if (code) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(code);
|
return (terrno = TAOS_SYSTEM_ERROR(code));
|
||||||
return terrno;
|
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t taosThreadDetach(TdThread thread) {
|
int32_t taosThreadDetach(TdThread thread) {
|
||||||
int32_t code = pthread_detach(thread);
|
int32_t code = pthread_detach(thread);
|
||||||
if (code) {
|
if (code) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(code);
|
return (terrno = TAOS_SYSTEM_ERROR(code));
|
||||||
return terrno;
|
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t taosThreadEqual(TdThread t1, TdThread t2) {
|
int32_t taosThreadEqual(TdThread t1, TdThread t2) { return pthread_equal(t1, t2); }
|
||||||
return pthread_equal(t1, t2);
|
|
||||||
}
|
|
||||||
|
|
||||||
void taosThreadExit(void *valuePtr) {
|
void taosThreadExit(void *valuePtr) {
|
||||||
if(valuePtr) return pthread_exit(valuePtr);
|
if (valuePtr) return pthread_exit(valuePtr);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t taosThreadGetSchedParam(TdThread thread, int32_t *policy, struct sched_param *param) {
|
int32_t taosThreadGetSchedParam(TdThread thread, int32_t *policy, struct sched_param *param) {
|
||||||
|
@ -380,21 +352,17 @@ int32_t taosThreadGetSchedParam(TdThread thread, int32_t *policy, struct sched_p
|
||||||
OS_PARAM_CHECK(param);
|
OS_PARAM_CHECK(param);
|
||||||
int32_t code = pthread_getschedparam(thread, policy, param);
|
int32_t code = pthread_getschedparam(thread, policy, param);
|
||||||
if (code) {
|
if (code) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(code);
|
return (terrno = TAOS_SYSTEM_ERROR(code));
|
||||||
return terrno;
|
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *taosThreadGetSpecific(TdThreadKey key) {
|
void *taosThreadGetSpecific(TdThreadKey key) { return pthread_getspecific(key); }
|
||||||
return pthread_getspecific(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t taosThreadJoin(TdThread thread, void **valuePtr) {
|
int32_t taosThreadJoin(TdThread thread, void **valuePtr) {
|
||||||
int32_t code = pthread_join(thread, valuePtr);
|
int32_t code = pthread_join(thread, valuePtr);
|
||||||
if (code) {
|
if (code) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(code);
|
return (terrno = TAOS_SYSTEM_ERROR(code));
|
||||||
return terrno;
|
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
@ -403,26 +371,23 @@ int32_t taosThreadKeyCreate(TdThreadKey *key, void (*destructor)(void *)) {
|
||||||
OS_PARAM_CHECK(key);
|
OS_PARAM_CHECK(key);
|
||||||
int32_t code = pthread_key_create(key, destructor);
|
int32_t code = pthread_key_create(key, destructor);
|
||||||
if (code) {
|
if (code) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(code);
|
return (terrno = TAOS_SYSTEM_ERROR(code));
|
||||||
return terrno;
|
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t taosThreadKeyDelete(TdThreadKey key) {
|
int32_t taosThreadKeyDelete(TdThreadKey key) {
|
||||||
int32_t code = pthread_key_delete(key);
|
int32_t code = pthread_key_delete(key);
|
||||||
if (code) {
|
if (code) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(code);
|
return (terrno = TAOS_SYSTEM_ERROR(code));
|
||||||
return terrno;
|
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t taosThreadKill(TdThread thread, int32_t sig) {
|
int32_t taosThreadKill(TdThread thread, int32_t sig) {
|
||||||
int32_t code = pthread_kill(thread, sig);
|
int32_t code = pthread_kill(thread, sig);
|
||||||
if (code) {
|
if (code) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(code);
|
return (terrno = TAOS_SYSTEM_ERROR(code));
|
||||||
return terrno;
|
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
@ -439,8 +404,7 @@ int32_t taosThreadMutexDestroy(TdThreadMutex *mutex) {
|
||||||
#else
|
#else
|
||||||
int32_t code = pthread_mutex_destroy(mutex);
|
int32_t code = pthread_mutex_destroy(mutex);
|
||||||
if (code) {
|
if (code) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(code);
|
return (terrno = TAOS_SYSTEM_ERROR(code));
|
||||||
return terrno;
|
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
#endif
|
#endif
|
||||||
|
@ -459,8 +423,7 @@ int32_t taosThreadMutexInit(TdThreadMutex *mutex, const TdThreadMutexAttr *attr)
|
||||||
#else
|
#else
|
||||||
int32_t code = pthread_mutex_init(mutex, attr);
|
int32_t code = pthread_mutex_init(mutex, attr);
|
||||||
if (code) {
|
if (code) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(code);
|
return (terrno = TAOS_SYSTEM_ERROR(code));
|
||||||
return terrno;
|
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
#endif
|
#endif
|
||||||
|
@ -474,8 +437,7 @@ int32_t taosThreadMutexLock(TdThreadMutex *mutex) {
|
||||||
#else
|
#else
|
||||||
int32_t code = pthread_mutex_lock(mutex);
|
int32_t code = pthread_mutex_lock(mutex);
|
||||||
if (code) {
|
if (code) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(code);
|
return (terrno = TAOS_SYSTEM_ERROR(code));
|
||||||
return terrno;
|
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
#endif
|
#endif
|
||||||
|
@ -507,8 +469,7 @@ int32_t taosThreadMutexUnlock(TdThreadMutex *mutex) {
|
||||||
#else
|
#else
|
||||||
int32_t code = pthread_mutex_unlock(mutex);
|
int32_t code = pthread_mutex_unlock(mutex);
|
||||||
if (code) {
|
if (code) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(code);
|
return (terrno = TAOS_SYSTEM_ERROR(code));
|
||||||
return terrno;
|
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
#endif
|
#endif
|
||||||
|
@ -521,8 +482,7 @@ int32_t taosThreadMutexAttrDestroy(TdThreadMutexAttr *attr) {
|
||||||
OS_PARAM_CHECK(attr);
|
OS_PARAM_CHECK(attr);
|
||||||
int32_t code = pthread_mutexattr_destroy(attr);
|
int32_t code = pthread_mutexattr_destroy(attr);
|
||||||
if (code) {
|
if (code) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(code);
|
return (terrno = TAOS_SYSTEM_ERROR(code));
|
||||||
return terrno;
|
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
#endif
|
#endif
|
||||||
|
@ -537,8 +497,7 @@ int32_t taosThreadMutexAttrGetPshared(const TdThreadMutexAttr *attr, int32_t *ps
|
||||||
OS_PARAM_CHECK(attr);
|
OS_PARAM_CHECK(attr);
|
||||||
int32_t code = pthread_mutexattr_getpshared(attr, pshared);
|
int32_t code = pthread_mutexattr_getpshared(attr, pshared);
|
||||||
if (code) {
|
if (code) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(code);
|
return (terrno = TAOS_SYSTEM_ERROR(code));
|
||||||
return terrno;
|
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
#endif
|
#endif
|
||||||
|
@ -557,8 +516,7 @@ int32_t taosThreadMutexAttrGetType(const TdThreadMutexAttr *attr, int32_t *kind)
|
||||||
OS_PARAM_CHECK(attr);
|
OS_PARAM_CHECK(attr);
|
||||||
int32_t code = pthread_mutexattr_gettype(attr, kind);
|
int32_t code = pthread_mutexattr_gettype(attr, kind);
|
||||||
if (code) {
|
if (code) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(code);
|
return (terrno = TAOS_SYSTEM_ERROR(code));
|
||||||
return terrno;
|
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
#endif
|
#endif
|
||||||
|
@ -571,8 +529,7 @@ int32_t taosThreadMutexAttrInit(TdThreadMutexAttr *attr) {
|
||||||
OS_PARAM_CHECK(attr);
|
OS_PARAM_CHECK(attr);
|
||||||
int32_t code = pthread_mutexattr_init(attr);
|
int32_t code = pthread_mutexattr_init(attr);
|
||||||
if (code) {
|
if (code) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(code);
|
return (terrno = TAOS_SYSTEM_ERROR(code));
|
||||||
return terrno;
|
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
#endif
|
#endif
|
||||||
|
@ -585,8 +542,7 @@ int32_t taosThreadMutexAttrSetPshared(TdThreadMutexAttr *attr, int32_t pshared)
|
||||||
OS_PARAM_CHECK(attr);
|
OS_PARAM_CHECK(attr);
|
||||||
int32_t code = pthread_mutexattr_setpshared(attr, pshared);
|
int32_t code = pthread_mutexattr_setpshared(attr, pshared);
|
||||||
if (code) {
|
if (code) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(code);
|
return (terrno = TAOS_SYSTEM_ERROR(code));
|
||||||
return terrno;
|
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
#endif
|
#endif
|
||||||
|
@ -603,8 +559,7 @@ int32_t taosThreadMutexAttrSetType(TdThreadMutexAttr *attr, int32_t kind) {
|
||||||
OS_PARAM_CHECK(attr);
|
OS_PARAM_CHECK(attr);
|
||||||
int32_t code = pthread_mutexattr_settype(attr, kind);
|
int32_t code = pthread_mutexattr_settype(attr, kind);
|
||||||
if (code) {
|
if (code) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(code);
|
return (terrno = TAOS_SYSTEM_ERROR(code));
|
||||||
return terrno;
|
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
#endif
|
#endif
|
||||||
|
@ -613,8 +568,7 @@ int32_t taosThreadMutexAttrSetType(TdThreadMutexAttr *attr, int32_t kind) {
|
||||||
int32_t taosThreadOnce(TdThreadOnce *onceControl, void (*initRoutine)(void)) {
|
int32_t taosThreadOnce(TdThreadOnce *onceControl, void (*initRoutine)(void)) {
|
||||||
int32_t code = pthread_once(onceControl, initRoutine);
|
int32_t code = pthread_once(onceControl, initRoutine);
|
||||||
if (code) {
|
if (code) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(code);
|
return (terrno = TAOS_SYSTEM_ERROR(code));
|
||||||
return terrno;
|
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
@ -626,11 +580,10 @@ int32_t taosThreadRwlockDestroy(TdThreadRwlock *rwlock) {
|
||||||
*/
|
*/
|
||||||
return 0;
|
return 0;
|
||||||
#else
|
#else
|
||||||
OS_PARAM_CHECK(rwlock);
|
OS_PARAM_CHECK(rwlock);
|
||||||
int32_t code = pthread_rwlock_destroy(rwlock);
|
int32_t code = pthread_rwlock_destroy(rwlock);
|
||||||
if (code) {
|
if (code) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(code);
|
return (terrno = TAOS_SYSTEM_ERROR(code));
|
||||||
return terrno;
|
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
#endif
|
#endif
|
||||||
|
@ -645,8 +598,7 @@ int32_t taosThreadRwlockInit(TdThreadRwlock *rwlock, const TdThreadRwlockAttr *a
|
||||||
#else
|
#else
|
||||||
int32_t code = pthread_rwlock_init(rwlock, attr);
|
int32_t code = pthread_rwlock_init(rwlock, attr);
|
||||||
if (code) {
|
if (code) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(code);
|
return (terrno = TAOS_SYSTEM_ERROR(code));
|
||||||
return terrno;
|
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
#endif
|
#endif
|
||||||
|
@ -660,8 +612,7 @@ int32_t taosThreadRwlockRdlock(TdThreadRwlock *rwlock) {
|
||||||
#else
|
#else
|
||||||
int32_t code = pthread_rwlock_rdlock(rwlock);
|
int32_t code = pthread_rwlock_rdlock(rwlock);
|
||||||
if (code) {
|
if (code) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(code);
|
return (terrno = TAOS_SYSTEM_ERROR(code));
|
||||||
return terrno;
|
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
#endif
|
#endif
|
||||||
|
@ -683,8 +634,7 @@ int32_t taosThreadRwlockTryRdlock(TdThreadRwlock *rwlock) {
|
||||||
#else
|
#else
|
||||||
int32_t code = pthread_rwlock_tryrdlock(rwlock);
|
int32_t code = pthread_rwlock_tryrdlock(rwlock);
|
||||||
if (code) {
|
if (code) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(code);
|
return (terrno = TAOS_SYSTEM_ERROR(code));
|
||||||
return terrno;
|
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
#endif
|
#endif
|
||||||
|
@ -699,8 +649,7 @@ int32_t taosThreadRwlockTryWrlock(TdThreadRwlock *rwlock) {
|
||||||
#else
|
#else
|
||||||
int32_t code = pthread_rwlock_trywrlock(rwlock);
|
int32_t code = pthread_rwlock_trywrlock(rwlock);
|
||||||
if (code) {
|
if (code) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(code);
|
return (terrno = TAOS_SYSTEM_ERROR(code));
|
||||||
return terrno;
|
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
#endif
|
#endif
|
||||||
|
@ -718,8 +667,7 @@ int32_t taosThreadRwlockUnlock(TdThreadRwlock *rwlock) {
|
||||||
#else
|
#else
|
||||||
int32_t code = pthread_rwlock_unlock(rwlock);
|
int32_t code = pthread_rwlock_unlock(rwlock);
|
||||||
if (code) {
|
if (code) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(code);
|
return (terrno = TAOS_SYSTEM_ERROR(code));
|
||||||
return terrno;
|
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
#endif
|
#endif
|
||||||
|
@ -734,8 +682,7 @@ int32_t taosThreadRwlockWrlock(TdThreadRwlock *rwlock) {
|
||||||
#else
|
#else
|
||||||
int32_t code = pthread_rwlock_wrlock(rwlock);
|
int32_t code = pthread_rwlock_wrlock(rwlock);
|
||||||
if (code) {
|
if (code) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(code);
|
return (terrno = TAOS_SYSTEM_ERROR(code));
|
||||||
return terrno;
|
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
#endif
|
#endif
|
||||||
|
@ -748,14 +695,14 @@ int32_t taosThreadRwlockAttrDestroy(TdThreadRwlockAttr *attr) {
|
||||||
OS_PARAM_CHECK(attr);
|
OS_PARAM_CHECK(attr);
|
||||||
int32_t code = pthread_rwlockattr_destroy(attr);
|
int32_t code = pthread_rwlockattr_destroy(attr);
|
||||||
if (code) {
|
if (code) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(code);
|
return (terrno = TAOS_SYSTEM_ERROR(code));
|
||||||
return terrno;
|
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t taosThreadRwlockAttrGetPshared(const TdThreadRwlockAttr *attr, int32_t *pshared) {
|
int32_t taosThreadRwlockAttrGetPshared(const TdThreadRwlockAttr *attr, int32_t *pshared) {
|
||||||
|
OS_PARAM_CHECK(attr);
|
||||||
OS_PARAM_CHECK(pshared);
|
OS_PARAM_CHECK(pshared);
|
||||||
#ifdef __USE_WIN_THREAD
|
#ifdef __USE_WIN_THREAD
|
||||||
if (pshared) *pshared = PTHREAD_PROCESS_PRIVATE;
|
if (pshared) *pshared = PTHREAD_PROCESS_PRIVATE;
|
||||||
|
@ -763,8 +710,7 @@ int32_t taosThreadRwlockAttrGetPshared(const TdThreadRwlockAttr *attr, int32_t *
|
||||||
#else
|
#else
|
||||||
int32_t code = pthread_rwlockattr_getpshared(attr, pshared);
|
int32_t code = pthread_rwlockattr_getpshared(attr, pshared);
|
||||||
if (code) {
|
if (code) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(code);
|
return (terrno = TAOS_SYSTEM_ERROR(code));
|
||||||
return terrno;
|
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
#endif
|
#endif
|
||||||
|
@ -777,8 +723,7 @@ int32_t taosThreadRwlockAttrInit(TdThreadRwlockAttr *attr) {
|
||||||
OS_PARAM_CHECK(attr);
|
OS_PARAM_CHECK(attr);
|
||||||
int32_t code = pthread_rwlockattr_init(attr);
|
int32_t code = pthread_rwlockattr_init(attr);
|
||||||
if (code) {
|
if (code) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(code);
|
return (terrno = TAOS_SYSTEM_ERROR(code));
|
||||||
return terrno;
|
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
#endif
|
#endif
|
||||||
|
@ -791,8 +736,7 @@ int32_t taosThreadRwlockAttrSetPshared(TdThreadRwlockAttr *attr, int32_t pshared
|
||||||
OS_PARAM_CHECK(attr);
|
OS_PARAM_CHECK(attr);
|
||||||
int32_t code = pthread_rwlockattr_setpshared(attr, pshared);
|
int32_t code = pthread_rwlockattr_setpshared(attr, pshared);
|
||||||
if (code) {
|
if (code) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(code);
|
return (terrno = TAOS_SYSTEM_ERROR(code));
|
||||||
return terrno;
|
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
#endif
|
#endif
|
||||||
|
@ -800,20 +744,18 @@ int32_t taosThreadRwlockAttrSetPshared(TdThreadRwlockAttr *attr, int32_t pshared
|
||||||
|
|
||||||
TdThread taosThreadSelf(void) { return pthread_self(); }
|
TdThread taosThreadSelf(void) { return pthread_self(); }
|
||||||
|
|
||||||
int32_t taosThreadSetCancelState(int32_t state, int32_t *oldstate) {
|
int32_t taosThreadSetCancelState(int32_t state, int32_t *oldstate) {
|
||||||
int32_t code = pthread_setcancelstate(state, oldstate);
|
int32_t code = pthread_setcancelstate(state, oldstate);
|
||||||
if (code) {
|
if (code) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(code);
|
return (terrno = TAOS_SYSTEM_ERROR(code));
|
||||||
return terrno;
|
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t taosThreadSetCancelType(int32_t type, int32_t *oldtype) {
|
int32_t taosThreadSetCancelType(int32_t type, int32_t *oldtype) {
|
||||||
int32_t code = pthread_setcanceltype(type, oldtype);
|
int32_t code = pthread_setcanceltype(type, oldtype);
|
||||||
if (code) {
|
if (code) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(code);
|
return (terrno = TAOS_SYSTEM_ERROR(code));
|
||||||
return terrno;
|
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
@ -822,18 +764,16 @@ int32_t taosThreadSetSchedParam(TdThread thread, int32_t policy, const struct sc
|
||||||
OS_PARAM_CHECK(param);
|
OS_PARAM_CHECK(param);
|
||||||
int32_t code = pthread_setschedparam(thread, policy, param);
|
int32_t code = pthread_setschedparam(thread, policy, param);
|
||||||
if (code) {
|
if (code) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(code);
|
return (terrno = TAOS_SYSTEM_ERROR(code));
|
||||||
return terrno;
|
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t taosThreadSetSpecific(TdThreadKey key, const void *value) {
|
int32_t taosThreadSetSpecific(TdThreadKey key, const void *value) {
|
||||||
OS_PARAM_CHECK(value);
|
OS_PARAM_CHECK(value);
|
||||||
int32_t code = pthread_setspecific(key, value);
|
int32_t code = pthread_setspecific(key, value);
|
||||||
if (code) {
|
if (code) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(code);
|
return (terrno = TAOS_SYSTEM_ERROR(code));
|
||||||
return terrno;
|
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
@ -845,8 +785,7 @@ int32_t taosThreadSpinDestroy(TdThreadSpinlock *lock) {
|
||||||
#else
|
#else
|
||||||
int32_t code = pthread_spin_destroy((pthread_spinlock_t *)lock);
|
int32_t code = pthread_spin_destroy((pthread_spinlock_t *)lock);
|
||||||
if (code) {
|
if (code) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(code);
|
return (terrno = TAOS_SYSTEM_ERROR(code));
|
||||||
return terrno;
|
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
#endif
|
#endif
|
||||||
|
@ -860,8 +799,7 @@ int32_t taosThreadSpinInit(TdThreadSpinlock *lock, int32_t pshared) {
|
||||||
#else
|
#else
|
||||||
int32_t code = pthread_spin_init((pthread_spinlock_t *)lock, pshared);
|
int32_t code = pthread_spin_init((pthread_spinlock_t *)lock, pshared);
|
||||||
if (code) {
|
if (code) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(code);
|
return (terrno = TAOS_SYSTEM_ERROR(code));
|
||||||
return terrno;
|
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
#endif
|
#endif
|
||||||
|
@ -874,8 +812,7 @@ int32_t taosThreadSpinLock(TdThreadSpinlock *lock) {
|
||||||
#else
|
#else
|
||||||
int32_t code = pthread_spin_lock((pthread_spinlock_t *)lock);
|
int32_t code = pthread_spin_lock((pthread_spinlock_t *)lock);
|
||||||
if (code) {
|
if (code) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(code);
|
return (terrno = TAOS_SYSTEM_ERROR(code));
|
||||||
return terrno;
|
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
#endif
|
#endif
|
||||||
|
@ -901,20 +838,17 @@ int32_t taosThreadSpinUnlock(TdThreadSpinlock *lock) {
|
||||||
#else
|
#else
|
||||||
int32_t code = pthread_spin_unlock((pthread_spinlock_t *)lock);
|
int32_t code = pthread_spin_unlock((pthread_spinlock_t *)lock);
|
||||||
if (code) {
|
if (code) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(code);
|
return (terrno = TAOS_SYSTEM_ERROR(code));
|
||||||
return terrno;
|
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void taosThreadTestCancel(void) {
|
void taosThreadTestCancel(void) { return pthread_testcancel(); }
|
||||||
return pthread_testcancel();
|
|
||||||
}
|
|
||||||
|
|
||||||
void taosThreadClear(TdThread *thread) {
|
void taosThreadClear(TdThread *thread) {
|
||||||
if (!thread) return;
|
if (!thread) return;
|
||||||
(void)memset(thread, 0, sizeof(TdThread));
|
(void)memset(thread, 0, sizeof(TdThread));
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
|
|
|
@ -31,7 +31,7 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
//#define TM_YEAR_BASE 1970 //origin
|
// #define TM_YEAR_BASE 1970 //origin
|
||||||
#define TM_YEAR_BASE 1900 // slguan
|
#define TM_YEAR_BASE 1900 // slguan
|
||||||
|
|
||||||
// This magic number is the number of 100 nanosecond intervals since January 1, 1601 (UTC)
|
// This magic number is the number of 100 nanosecond intervals since January 1, 1601 (UTC)
|
||||||
|
@ -345,8 +345,7 @@ char *taosStrpTime(const char *buf, const char *fmt, struct tm *tm) {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t
|
size_t taosStrfTime(char *s, size_t maxsize, char const *format, struct tm const *t) {
|
||||||
taosStrfTime(char *s, size_t maxsize, char const *format, struct tm const *t){
|
|
||||||
if (!s || !format || !t) return 0;
|
if (!s || !format || !t) return 0;
|
||||||
return strftime(s, maxsize, format, t);
|
return strftime(s, maxsize, format, t);
|
||||||
}
|
}
|
||||||
|
@ -379,7 +378,7 @@ int32_t taosTime(time_t *t) {
|
||||||
if (t == NULL) {
|
if (t == NULL) {
|
||||||
return TSDB_CODE_INVALID_PARA;
|
return TSDB_CODE_INVALID_PARA;
|
||||||
}
|
}
|
||||||
time_t r = time(t);
|
time_t r = time(t);
|
||||||
if (r == (time_t)-1) {
|
if (r == (time_t)-1) {
|
||||||
return TAOS_SYSTEM_ERROR(errno);
|
return TAOS_SYSTEM_ERROR(errno);
|
||||||
}
|
}
|
||||||
|
@ -433,15 +432,15 @@ time_t taosMktime(struct tm *timep, timezone_t tz) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
int64_t tzw = 0;
|
int64_t tzw = 0;
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
#if _MSC_VER >= 1900
|
#if _MSC_VER >= 1900
|
||||||
tzw = _timezone;
|
tzw = _timezone;
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
return user_mktime64(timep->tm_year + 1900, timep->tm_mon + 1, timep->tm_mday, timep->tm_hour, timep->tm_min,
|
return user_mktime64(timep->tm_year + 1900, timep->tm_mon + 1, timep->tm_mday, timep->tm_hour, timep->tm_min,
|
||||||
timep->tm_sec, tzw);
|
timep->tm_sec, tzw);
|
||||||
#else
|
#else
|
||||||
time_t r = tz != NULL ? mktime_z(tz, timep) : mktime(timep);
|
time_t r = (tz != NULL ? mktime_z(tz, timep) : mktime(timep));
|
||||||
if (r == (time_t)-1) {
|
if (r == (time_t)-1) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
}
|
}
|
||||||
|
@ -450,7 +449,7 @@ time_t taosMktime(struct tm *timep, timezone_t tz) {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
struct tm *taosGmTimeR(const time_t *timep, struct tm *result){
|
struct tm *taosGmTimeR(const time_t *timep, struct tm *result) {
|
||||||
if (timep == NULL || result == NULL) {
|
if (timep == NULL || result == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -461,7 +460,7 @@ struct tm *taosGmTimeR(const time_t *timep, struct tm *result){
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
time_t taosTimeGm(struct tm *tmp){
|
time_t taosTimeGm(struct tm *tmp) {
|
||||||
if (tmp == NULL) {
|
if (tmp == NULL) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -530,7 +529,7 @@ struct tm *taosLocalTime(const time_t *timep, struct tm *result, char *buf, int3
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
#else
|
#else
|
||||||
res = tz != NULL ? localtime_rz(tz, timep, result): localtime_r(timep, result);
|
res = (tz != NULL ? localtime_rz(tz, timep, result) : localtime_r(timep, result));
|
||||||
if (res == NULL && buf != NULL) {
|
if (res == NULL && buf != NULL) {
|
||||||
(void)snprintf(buf, bufSize, "NaN");
|
(void)snprintf(buf, bufSize, "NaN");
|
||||||
}
|
}
|
||||||
|
@ -544,8 +543,8 @@ int32_t taosGetTimestampSec() { return (int32_t)time(NULL); }
|
||||||
int32_t taosClockGetTime(int clock_id, struct timespec *pTS) {
|
int32_t taosClockGetTime(int clock_id, struct timespec *pTS) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
LARGE_INTEGER t;
|
LARGE_INTEGER t;
|
||||||
FILETIME f;
|
FILETIME f;
|
||||||
|
|
||||||
GetSystemTimeAsFileTime(&f);
|
GetSystemTimeAsFileTime(&f);
|
||||||
t.QuadPart = f.dwHighDateTime;
|
t.QuadPart = f.dwHighDateTime;
|
||||||
|
|
|
@ -750,13 +750,14 @@ int32_t taosSetGlobalTimezone(const char *tz) {
|
||||||
int32_t code = TSDB_CODE_SUCCESS;
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
uDebug("[tz]set timezone to %s", tz)
|
uDebug("[tz]set timezone to %s", tz)
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
char winStr[TD_TIMEZONE_LEN * 2] = {0};
|
char winStr[TD_TIMEZONE_LEN * 2] = {0};
|
||||||
for (size_t i = 0; i < W_TZ_CITY_NUM; i++) {
|
for (size_t i = 0; i < W_TZ_CITY_NUM; i++) {
|
||||||
if (strcmp(tz_win[i][0], tz) == 0) {
|
if (strcmp(tz_win[i][0], tz) == 0) {
|
||||||
char keyPath[256] = {0};
|
char keyPath[256] = {0};
|
||||||
char keyValue[100] = {0};
|
char keyValue[100] = {0};
|
||||||
DWORD keyValueSize = sizeof(keyValue);
|
DWORD keyValueSize = sizeof(keyValue);
|
||||||
snprintf(keyPath, sizeof(keyPath), "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones\\%s", tz_win[i][1]);
|
snprintf(keyPath, sizeof(keyPath), "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones\\%s",
|
||||||
|
tz_win[i][1]);
|
||||||
RegGetValue(HKEY_LOCAL_MACHINE, keyPath, "Display", RRF_RT_ANY, NULL, (PVOID)&keyValue, &keyValueSize);
|
RegGetValue(HKEY_LOCAL_MACHINE, keyPath, "Display", RRF_RT_ANY, NULL, (PVOID)&keyValue, &keyValueSize);
|
||||||
if (keyValueSize > 0) {
|
if (keyValueSize > 0) {
|
||||||
keyValue[4] = (keyValue[4] == '+' ? '-' : '+');
|
keyValue[4] = (keyValue[4] == '+' ? '-' : '+');
|
||||||
|
@ -770,7 +771,7 @@ int32_t taosSetGlobalTimezone(const char *tz) {
|
||||||
_putenv(winStr);
|
_putenv(winStr);
|
||||||
_tzset();
|
_tzset();
|
||||||
#else
|
#else
|
||||||
code = setenv("TZ", tz, 1);
|
code = setenv("TZ", tz, 1);
|
||||||
if (-1 == code) {
|
if (-1 == code) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
return terrno;
|
return terrno;
|
||||||
|
@ -779,7 +780,7 @@ int32_t taosSetGlobalTimezone(const char *tz) {
|
||||||
tzset();
|
tzset();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
time_t tx1 = taosGetTimestampSec();
|
time_t tx1 = taosGetTimestampSec();
|
||||||
return taosFormatTimezoneStr(tx1, tz, NULL, tsTimezoneStr);
|
return taosFormatTimezoneStr(tx1, tz, NULL, tsTimezoneStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -797,7 +798,7 @@ int32_t taosGetLocalTimezoneOffset() {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t taosFormatTimezoneStr(time_t t, const char* tz, timezone_t sp, char *outTimezoneStr){
|
int32_t taosFormatTimezoneStr(time_t t, const char *tz, timezone_t sp, char *outTimezoneStr) {
|
||||||
struct tm tm1;
|
struct tm tm1;
|
||||||
if (taosLocalTime(&t, &tm1, NULL, 0, sp) == NULL) {
|
if (taosLocalTime(&t, &tm1, NULL, 0, sp) == NULL) {
|
||||||
uError("%s failed to get local time: code:%d", __FUNCTION__, errno);
|
uError("%s failed to get local time: code:%d", __FUNCTION__, errno);
|
||||||
|
@ -813,16 +814,17 @@ int32_t taosFormatTimezoneStr(time_t t, const char* tz, timezone_t sp, char *out
|
||||||
*/
|
*/
|
||||||
|
|
||||||
char str1[TD_TIMEZONE_LEN] = {0};
|
char str1[TD_TIMEZONE_LEN] = {0};
|
||||||
if (taosStrfTime(str1, sizeof(str1), "%Z", &tm1) == 0){
|
if (taosStrfTime(str1, sizeof(str1), "%Z", &tm1) == 0) {
|
||||||
uError("failed to get timezone name");
|
uError("failed to get timezone name");
|
||||||
return TSDB_CODE_TIME_ERROR;
|
return TSDB_CODE_TIME_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
char str2[TD_TIMEZONE_LEN] = {0};
|
char str2[TD_TIMEZONE_LEN] = {0};
|
||||||
if (taosStrfTime(str2, sizeof(str2), "%z", &tm1) == 0){
|
if (taosStrfTime(str2, sizeof(str2), "%z", &tm1) == 0) {
|
||||||
uError("failed to get timezone offset");
|
uError("failed to get timezone offset");
|
||||||
return TSDB_CODE_TIME_ERROR;
|
return TSDB_CODE_TIME_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
(void)snprintf(outTimezoneStr, TD_TIMEZONE_LEN, "%s (%s, %s)", tz, str1, str2);
|
(void)snprintf(outTimezoneStr, TD_TIMEZONE_LEN, "%s (%s, %s)", tz, str1, str2);
|
||||||
uDebug("[tz] system timezone:%s", outTimezoneStr);
|
uDebug("[tz] system timezone:%s", outTimezoneStr);
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -847,7 +849,6 @@ void getTimezoneStr(char *tz) {
|
||||||
goto END;
|
goto END;
|
||||||
} while (0);
|
} while (0);
|
||||||
|
|
||||||
|
|
||||||
TdFilePtr pFile = taosOpenFile("/etc/timezone", TD_FILE_READ);
|
TdFilePtr pFile = taosOpenFile("/etc/timezone", TD_FILE_READ);
|
||||||
if (pFile == NULL) {
|
if (pFile == NULL) {
|
||||||
uWarn("[tz] failed to open /etc/timezone, reason:%s", strerror(errno));
|
uWarn("[tz] failed to open /etc/timezone, reason:%s", strerror(errno));
|
||||||
|
@ -876,8 +877,8 @@ int32_t taosGetSystemTimezone(char *outTimezoneStr) {
|
||||||
char value[100] = {0};
|
char value[100] = {0};
|
||||||
char keyPath[100] = {0};
|
char keyPath[100] = {0};
|
||||||
DWORD bufferSize = sizeof(value);
|
DWORD bufferSize = sizeof(value);
|
||||||
LONG result = RegGetValue(HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Control\\TimeZoneInformation", "TimeZoneKeyName",
|
LONG result = RegGetValue(HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Control\\TimeZoneInformation",
|
||||||
RRF_RT_ANY, NULL, (PVOID)&value, &bufferSize);
|
"TimeZoneKeyName", RRF_RT_ANY, NULL, (PVOID)&value, &bufferSize);
|
||||||
if (result != ERROR_SUCCESS) {
|
if (result != ERROR_SUCCESS) {
|
||||||
return TAOS_SYSTEM_WINAPI_ERROR(result);
|
return TAOS_SYSTEM_WINAPI_ERROR(result);
|
||||||
}
|
}
|
||||||
|
@ -891,9 +892,9 @@ int32_t taosGetSystemTimezone(char *outTimezoneStr) {
|
||||||
if (result != ERROR_SUCCESS) {
|
if (result != ERROR_SUCCESS) {
|
||||||
return TAOS_SYSTEM_WINAPI_ERROR(result);
|
return TAOS_SYSTEM_WINAPI_ERROR(result);
|
||||||
}
|
}
|
||||||
if (bufferSize > 0) { // value like (UTC+05:30) Chennai, Kolkata, Mumbai, New Delhi
|
if (bufferSize > 0) { // value like (UTC+05:30) Chennai, Kolkata, Mumbai, New Delhi
|
||||||
snprintf(outTimezoneStr, TD_TIMEZONE_LEN, "%s (UTC, %c%c%c%c%c)", outTimezoneStr,
|
snprintf(outTimezoneStr, TD_TIMEZONE_LEN, "%s (UTC, %c%c%c%c%c)", outTimezoneStr, value[4], value[5],
|
||||||
value[4], value[5], value[6], value[8], value[9]);
|
value[6], value[8], value[9]);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -903,7 +904,7 @@ int32_t taosGetSystemTimezone(char *outTimezoneStr) {
|
||||||
#else
|
#else
|
||||||
char tz[TD_TIMEZONE_LEN] = {0};
|
char tz[TD_TIMEZONE_LEN] = {0};
|
||||||
getTimezoneStr(tz);
|
getTimezoneStr(tz);
|
||||||
time_t tx1 = taosGetTimestampSec();
|
time_t tx1 = taosGetTimestampSec();
|
||||||
return taosFormatTimezoneStr(tx1, tz, NULL, outTimezoneStr);
|
return taosFormatTimezoneStr(tx1, tz, NULL, outTimezoneStr);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
|
@ -14,20 +14,32 @@ ENDIF()
|
||||||
|
|
||||||
INCLUDE_DIRECTORIES(${TD_SOURCE_DIR}/src/util/inc)
|
INCLUDE_DIRECTORIES(${TD_SOURCE_DIR}/src/util/inc)
|
||||||
|
|
||||||
# osTests
|
if(TD_LINUX)
|
||||||
add_executable(osTests "osTests.cpp")
|
add_executable(osAtomicTests "osAtomicTests.cpp")
|
||||||
target_link_libraries(osTests os util gtest_main)
|
target_link_libraries(osAtomicTests os util gtest_main)
|
||||||
add_test(
|
add_test(
|
||||||
NAME osTests
|
NAME osAtomicTests
|
||||||
COMMAND osTests
|
COMMAND osAtomicTests
|
||||||
)
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
add_executable(osSystemTests "osSystemTests.cpp")
|
if(TD_LINUX)
|
||||||
target_link_libraries(osSystemTests os util gtest_main)
|
add_executable(osDirTests "osDirTests.cpp")
|
||||||
|
target_link_libraries(osDirTests os util gtest_main)
|
||||||
add_test(
|
add_test(
|
||||||
NAME osSystemTests
|
NAME osDirTests
|
||||||
COMMAND osSystemTests
|
COMMAND osDirTests
|
||||||
)
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(TD_LINUX)
|
||||||
|
add_executable(osEnvTests "osEnvTests.cpp")
|
||||||
|
target_link_libraries(osEnvTests os util gtest_main)
|
||||||
|
add_test(
|
||||||
|
NAME osEnvTests
|
||||||
|
COMMAND osEnvTests
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
add_executable(osMathTests "osMathTests.cpp")
|
add_executable(osMathTests "osMathTests.cpp")
|
||||||
target_link_libraries(osMathTests os util gtest_main)
|
target_link_libraries(osMathTests os util gtest_main)
|
||||||
|
@ -36,6 +48,13 @@ add_test(
|
||||||
COMMAND osMathTests
|
COMMAND osMathTests
|
||||||
)
|
)
|
||||||
|
|
||||||
|
add_executable(osSemaphoreTests "osSemaphoreTests.cpp")
|
||||||
|
target_link_libraries(osSemaphoreTests os util gtest_main)
|
||||||
|
add_test(
|
||||||
|
NAME osSemaphoreTests
|
||||||
|
COMMAND osSemaphoreTests
|
||||||
|
)
|
||||||
|
|
||||||
add_executable(osSignalTests "osSignalTests.cpp")
|
add_executable(osSignalTests "osSignalTests.cpp")
|
||||||
target_link_libraries(osSignalTests os util gtest_main)
|
target_link_libraries(osSignalTests os util gtest_main)
|
||||||
add_test(
|
add_test(
|
||||||
|
@ -57,12 +76,28 @@ add_test(
|
||||||
COMMAND osStringTests
|
COMMAND osStringTests
|
||||||
)
|
)
|
||||||
|
|
||||||
|
add_executable(osTests "osTests.cpp")
|
||||||
|
target_link_libraries(osTests os util gtest_main)
|
||||||
|
add_test(
|
||||||
|
NAME osTests
|
||||||
|
COMMAND osTests
|
||||||
|
)
|
||||||
|
|
||||||
|
add_executable(osSystemTests "osSystemTests.cpp")
|
||||||
|
target_link_libraries(osSystemTests os util gtest_main)
|
||||||
|
add_test(
|
||||||
|
NAME osSystemTests
|
||||||
|
COMMAND osSystemTests
|
||||||
|
)
|
||||||
|
|
||||||
|
if(TD_LINUX)
|
||||||
add_executable(osThreadTests "osThreadTests.cpp")
|
add_executable(osThreadTests "osThreadTests.cpp")
|
||||||
target_link_libraries(osThreadTests os util gtest_main)
|
target_link_libraries(osThreadTests os util gtest_main)
|
||||||
add_test(
|
add_test(
|
||||||
NAME osThreadTests
|
NAME osThreadTests
|
||||||
COMMAND osThreadTests
|
COMMAND osThreadTests
|
||||||
)
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
add_executable(osTimeTests "osTimeTests.cpp")
|
add_executable(osTimeTests "osTimeTests.cpp")
|
||||||
target_link_libraries(osTimeTests os util gtest_main)
|
target_link_libraries(osTimeTests os util gtest_main)
|
||||||
|
@ -71,35 +106,3 @@ add_test(
|
||||||
COMMAND osTimeTests
|
COMMAND osTimeTests
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
if(TD_LINUX)
|
|
||||||
|
|
||||||
add_executable(osAtomicTests "osAtomicTests.cpp")
|
|
||||||
target_link_libraries(osAtomicTests os util gtest_main)
|
|
||||||
add_test(
|
|
||||||
NAME osAtomicTests
|
|
||||||
COMMAND osAtomicTests
|
|
||||||
)
|
|
||||||
|
|
||||||
add_executable(osDirTests "osDirTests.cpp")
|
|
||||||
target_link_libraries(osDirTests os util gtest_main)
|
|
||||||
add_test(
|
|
||||||
NAME osDirTests
|
|
||||||
COMMAND osDirTests
|
|
||||||
)
|
|
||||||
|
|
||||||
add_executable(osEnvTests "osEnvTests.cpp")
|
|
||||||
target_link_libraries(osEnvTests os util gtest_main)
|
|
||||||
add_test(
|
|
||||||
NAME osEnvTests
|
|
||||||
COMMAND osEnvTests
|
|
||||||
)
|
|
||||||
|
|
||||||
endif()
|
|
||||||
|
|
||||||
add_executable(osSemaphoreTests "osSemaphoreTests.cpp")
|
|
||||||
target_link_libraries(osSemaphoreTests os util gtest_main)
|
|
||||||
add_test(
|
|
||||||
NAME osSemaphoreTests
|
|
||||||
COMMAND osSemaphoreTests
|
|
||||||
)
|
|
||||||
|
|
|
@ -29,6 +29,473 @@
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
#include "tlog.h"
|
#include "tlog.h"
|
||||||
|
|
||||||
TEST(osThreadTests, osThreadTests1) {
|
static int32_t globalVar = 0;
|
||||||
|
|
||||||
|
static void funcPtrKey(void *param) { taosMsleep(100); }
|
||||||
|
|
||||||
|
static void *funcPtr200(void *param) {
|
||||||
|
TdThread thread = taosThreadSelf();
|
||||||
|
|
||||||
|
TdThreadKey key = {0};
|
||||||
|
taosThreadKeyCreate(&key, funcPtrKey);
|
||||||
|
void *oldVal = taosThreadGetSpecific(key);
|
||||||
|
taosThreadSetSpecific(key, oldVal);
|
||||||
|
taosThreadKeyDelete(key);
|
||||||
|
|
||||||
|
int32_t oldType = 0;
|
||||||
|
taosThreadSetCancelType(-1, &oldType);
|
||||||
|
taosThreadSetCancelType(0, &oldType);
|
||||||
|
|
||||||
|
int32_t oldState = 0;
|
||||||
|
taosThreadSetCancelState(-1, &oldState);
|
||||||
|
taosThreadSetCancelState(0, &oldState);
|
||||||
|
|
||||||
|
int32_t policy;
|
||||||
|
struct sched_param para;
|
||||||
|
taosThreadGetSchedParam(thread, &policy, ¶);
|
||||||
|
taosThreadGetSchedParam(thread, NULL, ¶);
|
||||||
|
taosThreadGetSchedParam(thread, &policy, NULL);
|
||||||
|
// taosThreadSetSchedParam(NULL, 0, ¶);
|
||||||
|
taosThreadSetSchedParam(thread, 0, ¶);
|
||||||
|
taosMsleep(200);
|
||||||
|
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void *funcPtr501(void *param) {
|
||||||
|
taosMsleep(500);
|
||||||
|
TdThread thread = taosThreadSelf();
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void *funcPtr502(void *param) {
|
||||||
|
taosMsleep(500);
|
||||||
|
TdThread thread = taosThreadSelf();
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void *funcPtr503(void *param) {
|
||||||
|
taosMsleep(500);
|
||||||
|
TdThread thread = taosThreadSelf();
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void *funcPtr504(void *param) {
|
||||||
|
taosMsleep(500);
|
||||||
|
TdThread thread = taosThreadSelf();
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void *funcPtrExit1(void *param) {
|
||||||
|
taosThreadExit(NULL);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void *funcPtrExit2(void *param) {
|
||||||
|
taosThreadExit(&globalVar);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(osThreadTests, thread) {
|
||||||
|
TdThread tid1 = {0};
|
||||||
|
TdThread tid2 = {0};
|
||||||
|
int32_t reti = 0;
|
||||||
|
|
||||||
|
reti = taosThreadCreate(NULL, NULL, funcPtr200, NULL);
|
||||||
|
EXPECT_NE(reti, 0);
|
||||||
|
reti = taosThreadCreate(&tid1, NULL, NULL, NULL);
|
||||||
|
EXPECT_NE(reti, 0);
|
||||||
|
reti = taosThreadCreate(&tid1, NULL, funcPtr200, NULL);
|
||||||
|
EXPECT_EQ(reti, 0);
|
||||||
|
taosMsleep(300);
|
||||||
|
|
||||||
|
(void)taosThreadCancel(tid1);
|
||||||
|
|
||||||
|
reti = taosThreadCreate(&tid2, NULL, funcPtr501, NULL);
|
||||||
|
EXPECT_EQ(reti, 0);
|
||||||
|
taosMsleep(1000);
|
||||||
|
(void)taosThreadCancel(tid2);
|
||||||
|
|
||||||
|
taosThreadDetach(tid1);
|
||||||
|
reti = taosThreadCreate(&tid2, NULL, funcPtr502, NULL);
|
||||||
|
EXPECT_EQ(reti, 0);
|
||||||
|
reti = taosThreadDetach(tid2);
|
||||||
|
|
||||||
|
reti = taosThreadEqual(tid1, tid2);
|
||||||
|
EXPECT_NE(reti, 0);
|
||||||
|
|
||||||
|
reti = taosThreadCreate(&tid2, NULL, funcPtrExit1, NULL);
|
||||||
|
EXPECT_EQ(reti, 0);
|
||||||
|
reti = taosThreadCreate(&tid2, NULL, funcPtrExit2, NULL);
|
||||||
|
EXPECT_EQ(reti, 0);
|
||||||
|
|
||||||
|
taosMsleep(1000);
|
||||||
|
|
||||||
|
// reti = taosThreadCreate(&tid2, NULL, funcPtr503, NULL);
|
||||||
|
// EXPECT_EQ(reti, 0);
|
||||||
|
// taosThreadKill(tid2, SIGINT);
|
||||||
|
|
||||||
|
int32_t policy;
|
||||||
|
struct sched_param para;
|
||||||
|
taosThreadGetSchedParam(tid2, &policy, ¶);
|
||||||
|
taosThreadGetSchedParam(tid2, NULL, ¶);
|
||||||
|
taosThreadGetSchedParam(tid2, &policy, NULL);
|
||||||
|
// taosThreadSetSchedParam(NULL, 0, ¶);
|
||||||
|
taosThreadSetSchedParam(tid2, 0, ¶);
|
||||||
|
|
||||||
|
TdThreadKey key = {0};
|
||||||
|
taosThreadKeyCreate(&key, funcPtrKey);
|
||||||
|
void *oldVal = taosThreadGetSpecific(key);
|
||||||
|
taosThreadSetSpecific(key, oldVal);
|
||||||
|
taosThreadKeyDelete(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(osThreadTests, attr) {
|
||||||
|
int32_t reti = 0;
|
||||||
|
TdThreadAttr attr = {0};
|
||||||
|
int32_t param = 0;
|
||||||
|
|
||||||
|
reti = taosThreadAttrInit(NULL);
|
||||||
|
EXPECT_NE(reti, 0);
|
||||||
|
reti = taosThreadAttrDestroy(NULL);
|
||||||
|
EXPECT_NE(reti, 0);
|
||||||
|
|
||||||
|
(void)taosThreadAttrInit(&attr);
|
||||||
|
|
||||||
|
reti = taosThreadAttrSetDetachState(&attr, PTHREAD_CREATE_JOINABLE);
|
||||||
|
EXPECT_EQ(reti, 0);
|
||||||
|
reti = taosThreadAttrSetDetachState(&attr, -1);
|
||||||
|
EXPECT_NE(reti, 0);
|
||||||
|
reti = taosThreadAttrSetDetachState(NULL, -1);
|
||||||
|
EXPECT_NE(reti, 0);
|
||||||
|
reti = taosThreadAttrGetDetachState(NULL, ¶m);
|
||||||
|
EXPECT_NE(reti, 0);
|
||||||
|
reti = taosThreadAttrGetDetachState(&attr, NULL);
|
||||||
|
EXPECT_NE(reti, 0);
|
||||||
|
reti = taosThreadAttrGetDetachState(&attr, ¶m);
|
||||||
|
EXPECT_EQ(reti, 0);
|
||||||
|
|
||||||
|
reti = taosThreadAttrSetInheritSched(&attr, PTHREAD_INHERIT_SCHED);
|
||||||
|
EXPECT_EQ(reti, 0);
|
||||||
|
reti = taosThreadAttrSetInheritSched(&attr, -1);
|
||||||
|
EXPECT_NE(reti, 0);
|
||||||
|
reti = taosThreadAttrSetInheritSched(NULL, -1);
|
||||||
|
EXPECT_NE(reti, 0);
|
||||||
|
reti = taosThreadAttrGetInheritSched(NULL, ¶m);
|
||||||
|
EXPECT_NE(reti, 0);
|
||||||
|
reti = taosThreadAttrGetInheritSched(&attr, NULL);
|
||||||
|
EXPECT_NE(reti, 0);
|
||||||
|
reti = taosThreadAttrGetInheritSched(&attr, ¶m);
|
||||||
|
EXPECT_EQ(reti, 0);
|
||||||
|
|
||||||
|
struct sched_param schedparam = {0};
|
||||||
|
reti = taosThreadAttrGetSchedParam(&attr, &schedparam);
|
||||||
|
EXPECT_EQ(reti, 0);
|
||||||
|
reti = taosThreadAttrSetSchedParam(&attr, &schedparam);
|
||||||
|
EXPECT_EQ(reti, 0);
|
||||||
|
schedparam.sched_priority = -1;
|
||||||
|
reti = taosThreadAttrSetSchedParam(&attr, &schedparam);
|
||||||
|
EXPECT_NE(reti, 0);
|
||||||
|
reti = taosThreadAttrSetSchedParam(NULL, &schedparam);
|
||||||
|
EXPECT_NE(reti, 0);
|
||||||
|
reti = taosThreadAttrGetSchedParam(NULL, &schedparam);
|
||||||
|
EXPECT_NE(reti, 0);
|
||||||
|
reti = taosThreadAttrGetSchedParam(&attr, NULL);
|
||||||
|
EXPECT_NE(reti, 0);
|
||||||
|
|
||||||
|
reti = taosThreadAttrSetSchedPolicy(&attr, SCHED_FIFO);
|
||||||
|
EXPECT_EQ(reti, 0);
|
||||||
|
reti = taosThreadAttrSetSchedPolicy(&attr, -1);
|
||||||
|
EXPECT_NE(reti, 0);
|
||||||
|
reti = taosThreadAttrSetSchedPolicy(NULL, -1);
|
||||||
|
EXPECT_NE(reti, 0);
|
||||||
|
reti = taosThreadAttrGetSchedPolicy(NULL, ¶m);
|
||||||
|
EXPECT_NE(reti, 0);
|
||||||
|
reti = taosThreadAttrGetSchedPolicy(&attr, NULL);
|
||||||
|
EXPECT_NE(reti, 0);
|
||||||
|
reti = taosThreadAttrGetSchedPolicy(&attr, ¶m);
|
||||||
|
EXPECT_EQ(reti, 0);
|
||||||
|
|
||||||
|
reti = taosThreadAttrSetScope(&attr, PTHREAD_SCOPE_SYSTEM);
|
||||||
|
EXPECT_EQ(reti, 0);
|
||||||
|
reti = taosThreadAttrSetScope(&attr, -1);
|
||||||
|
EXPECT_NE(reti, 0);
|
||||||
|
reti = taosThreadAttrSetScope(NULL, -1);
|
||||||
|
EXPECT_NE(reti, 0);
|
||||||
|
reti = taosThreadAttrGetScope(NULL, ¶m);
|
||||||
|
EXPECT_NE(reti, 0);
|
||||||
|
reti = taosThreadAttrGetScope(&attr, NULL);
|
||||||
|
EXPECT_NE(reti, 0);
|
||||||
|
reti = taosThreadAttrGetScope(&attr, ¶m);
|
||||||
|
EXPECT_EQ(reti, 0);
|
||||||
|
|
||||||
|
size_t stacksize;
|
||||||
|
reti = taosThreadAttrGetStackSize(&attr, &stacksize);
|
||||||
|
EXPECT_EQ(reti, 0);
|
||||||
|
reti = taosThreadAttrSetStackSize(&attr, stacksize);
|
||||||
|
EXPECT_EQ(reti, 0);
|
||||||
|
reti = taosThreadAttrSetStackSize(&attr, 2048);
|
||||||
|
EXPECT_NE(reti, 0);
|
||||||
|
reti = taosThreadAttrSetStackSize(NULL, stacksize);
|
||||||
|
EXPECT_NE(reti, 0);
|
||||||
|
reti = taosThreadAttrGetStackSize(NULL, &stacksize);
|
||||||
|
EXPECT_NE(reti, 0);
|
||||||
|
reti = taosThreadAttrGetStackSize(&attr, NULL);
|
||||||
|
EXPECT_NE(reti, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(osThreadTests, cond) {
|
||||||
|
int32_t reti = 0;
|
||||||
|
|
||||||
|
reti = taosThreadCondInit(NULL, NULL);
|
||||||
|
EXPECT_NE(reti, 0);
|
||||||
|
reti = taosThreadCondDestroy(NULL);
|
||||||
|
EXPECT_NE(reti, 0);
|
||||||
|
reti = taosThreadCondSignal(NULL);
|
||||||
|
EXPECT_NE(reti, 0);
|
||||||
|
reti = taosThreadCondBroadcast(NULL);
|
||||||
|
EXPECT_NE(reti, 0);
|
||||||
|
|
||||||
|
TdThreadCond cond{0};
|
||||||
|
TdThreadMutex mutex = {0};
|
||||||
|
reti = taosThreadCondWait(&cond, NULL);
|
||||||
|
EXPECT_NE(reti, 0);
|
||||||
|
reti = taosThreadCondWait(NULL, &mutex);
|
||||||
|
EXPECT_NE(reti, 0);
|
||||||
|
|
||||||
|
struct timespec abstime = {0};
|
||||||
|
reti = taosThreadCondTimedWait(&cond, NULL, &abstime);
|
||||||
|
EXPECT_NE(reti, 0);
|
||||||
|
reti = taosThreadCondTimedWait(NULL, &mutex, &abstime);
|
||||||
|
EXPECT_NE(reti, 0);
|
||||||
|
reti = taosThreadCondTimedWait(&cond, &mutex, NULL);
|
||||||
|
EXPECT_EQ(reti, 0);
|
||||||
|
|
||||||
|
TdThreadCondAttr condattr = {0};
|
||||||
|
(void)taosThreadCondAttrInit(&condattr);
|
||||||
|
reti = taosThreadCondAttrInit(NULL);
|
||||||
|
EXPECT_NE(reti, 0);
|
||||||
|
int32_t pshared;
|
||||||
|
reti = taosThreadCondAttrGetPshared(&condattr, &pshared);
|
||||||
|
EXPECT_EQ(reti, 0);
|
||||||
|
reti = taosThreadCondAttrSetPshared(&condattr, pshared);
|
||||||
|
EXPECT_EQ(reti, 0);
|
||||||
|
reti = taosThreadCondAttrSetPshared(&condattr, -1);
|
||||||
|
EXPECT_NE(reti, 0);
|
||||||
|
reti = taosThreadCondAttrSetPshared(NULL, pshared);
|
||||||
|
EXPECT_NE(reti, 0);
|
||||||
|
reti = taosThreadCondAttrGetPshared(NULL, &pshared);
|
||||||
|
EXPECT_NE(reti, 0);
|
||||||
|
reti = taosThreadCondAttrGetPshared(&condattr, NULL);
|
||||||
|
EXPECT_NE(reti, 0);
|
||||||
|
|
||||||
|
reti = taosThreadCondAttrSetclock(NULL, -1);
|
||||||
|
EXPECT_NE(reti, 0);
|
||||||
|
|
||||||
|
reti = taosThreadCondAttrDestroy(NULL);
|
||||||
|
EXPECT_NE(reti, 0);
|
||||||
|
reti = taosThreadCondAttrDestroy(&condattr);
|
||||||
|
EXPECT_EQ(reti, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(osThreadTests, mutex) {
|
||||||
|
int32_t reti = 0;
|
||||||
|
TdThreadMutex mutex;
|
||||||
|
reti = taosThreadMutexInit(NULL, 0);
|
||||||
|
EXPECT_NE(reti, 0);
|
||||||
|
reti = taosThreadMutexInit(&mutex, 0);
|
||||||
|
EXPECT_EQ(reti, 0);
|
||||||
|
|
||||||
|
reti = taosThreadMutexTryLock(NULL);
|
||||||
|
EXPECT_NE(reti, 0);
|
||||||
|
reti = taosThreadMutexTryLock(&mutex);
|
||||||
|
EXPECT_EQ(reti, 0);
|
||||||
|
reti = taosThreadMutexTryLock(&mutex);
|
||||||
|
EXPECT_NE(reti, 0);
|
||||||
|
|
||||||
|
reti = taosThreadMutexUnlock(NULL);
|
||||||
|
EXPECT_NE(reti, 0);
|
||||||
|
reti = taosThreadMutexUnlock(&mutex);
|
||||||
|
EXPECT_EQ(reti, 0);
|
||||||
|
|
||||||
|
reti = taosThreadMutexLock(NULL);
|
||||||
|
EXPECT_NE(reti, 0);
|
||||||
|
reti = taosThreadMutexLock(&mutex);
|
||||||
|
EXPECT_EQ(reti, 0);
|
||||||
|
reti = taosThreadMutexUnlock(&mutex);
|
||||||
|
EXPECT_EQ(reti, 0);
|
||||||
|
|
||||||
|
reti = taosThreadMutexDestroy(NULL);
|
||||||
|
EXPECT_NE(reti, 0);
|
||||||
|
reti = taosThreadMutexDestroy(&mutex);
|
||||||
|
EXPECT_EQ(reti, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(osThreadTests, mutexAttr) {
|
||||||
|
int32_t reti = 0;
|
||||||
|
TdThreadMutexAttr mutexAttr;
|
||||||
|
reti = taosThreadMutexAttrInit(NULL);
|
||||||
|
EXPECT_NE(reti, 0);
|
||||||
|
reti = taosThreadMutexAttrInit(&mutexAttr);
|
||||||
|
EXPECT_EQ(reti, 0);
|
||||||
|
|
||||||
|
int32_t pshared;
|
||||||
|
reti = taosThreadMutexAttrGetPshared(&mutexAttr, &pshared);
|
||||||
|
EXPECT_EQ(reti, 0);
|
||||||
|
reti = taosThreadMutexAttrSetPshared(&mutexAttr, pshared);
|
||||||
|
EXPECT_EQ(reti, 0);
|
||||||
|
reti = taosThreadMutexAttrSetPshared(&mutexAttr, -1);
|
||||||
|
EXPECT_NE(reti, 0);
|
||||||
|
reti = taosThreadMutexAttrSetPshared(NULL, pshared);
|
||||||
|
EXPECT_NE(reti, 0);
|
||||||
|
reti = taosThreadMutexAttrGetPshared(NULL, &pshared);
|
||||||
|
EXPECT_NE(reti, 0);
|
||||||
|
reti = taosThreadMutexAttrGetPshared(&mutexAttr, NULL);
|
||||||
|
EXPECT_NE(reti, 0);
|
||||||
|
|
||||||
|
int32_t kind;
|
||||||
|
reti = taosThreadMutexAttrGetType(&mutexAttr, &kind);
|
||||||
|
EXPECT_EQ(reti, 0);
|
||||||
|
reti = taosThreadMutexAttrSetType(&mutexAttr, kind);
|
||||||
|
EXPECT_EQ(reti, 0);
|
||||||
|
reti = taosThreadMutexAttrSetType(&mutexAttr, -1);
|
||||||
|
EXPECT_NE(reti, 0);
|
||||||
|
reti = taosThreadMutexAttrSetType(NULL, kind);
|
||||||
|
EXPECT_NE(reti, 0);
|
||||||
|
reti = taosThreadMutexAttrGetType(NULL, &kind);
|
||||||
|
EXPECT_NE(reti, 0);
|
||||||
|
reti = taosThreadMutexAttrGetType(&mutexAttr, NULL);
|
||||||
|
EXPECT_NE(reti, 0);
|
||||||
|
|
||||||
|
reti = taosThreadMutexAttrDestroy(NULL);
|
||||||
|
EXPECT_NE(reti, 0);
|
||||||
|
reti = taosThreadMutexAttrDestroy(&mutexAttr);
|
||||||
|
EXPECT_EQ(reti, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(osThreadTests, rwlock) {
|
||||||
|
int32_t reti = 0;
|
||||||
|
TdThreadRwlock rwlock;
|
||||||
|
reti = taosThreadRwlockInit(NULL, 0);
|
||||||
|
EXPECT_NE(reti, 0);
|
||||||
|
reti = taosThreadRwlockInit(&rwlock, 0);
|
||||||
|
EXPECT_EQ(reti, 0);
|
||||||
|
|
||||||
|
reti = taosThreadRwlockTryRdlock(NULL);
|
||||||
|
EXPECT_NE(reti, 0);
|
||||||
|
reti = taosThreadRwlockTryRdlock(&rwlock);
|
||||||
|
EXPECT_EQ(reti, 0);
|
||||||
|
|
||||||
|
reti = taosThreadRwlockUnlock(NULL);
|
||||||
|
EXPECT_NE(reti, 0);
|
||||||
|
reti = taosThreadRwlockUnlock(&rwlock);
|
||||||
|
EXPECT_EQ(reti, 0);
|
||||||
|
|
||||||
|
reti = taosThreadRwlockRdlock(NULL);
|
||||||
|
EXPECT_NE(reti, 0);
|
||||||
|
reti = taosThreadRwlockRdlock(&rwlock);
|
||||||
|
EXPECT_EQ(reti, 0);
|
||||||
|
reti = taosThreadRwlockUnlock(&rwlock);
|
||||||
|
EXPECT_EQ(reti, 0);
|
||||||
|
|
||||||
|
reti = taosThreadRwlockDestroy(NULL);
|
||||||
|
EXPECT_NE(reti, 0);
|
||||||
|
reti = taosThreadRwlockDestroy(&rwlock);
|
||||||
|
EXPECT_EQ(reti, 0);
|
||||||
|
|
||||||
|
reti = taosThreadRwlockInit(NULL, 0);
|
||||||
|
EXPECT_NE(reti, 0);
|
||||||
|
reti = taosThreadRwlockInit(&rwlock, 0);
|
||||||
|
EXPECT_EQ(reti, 0);
|
||||||
|
|
||||||
|
reti = taosThreadRwlockTryWrlock(NULL);
|
||||||
|
EXPECT_NE(reti, 0);
|
||||||
|
reti = taosThreadRwlockTryWrlock(&rwlock);
|
||||||
|
EXPECT_EQ(reti, 0);
|
||||||
|
|
||||||
|
reti = taosThreadRwlockUnlock(NULL);
|
||||||
|
EXPECT_NE(reti, 0);
|
||||||
|
reti = taosThreadRwlockUnlock(&rwlock);
|
||||||
|
EXPECT_EQ(reti, 0);
|
||||||
|
|
||||||
|
reti = taosThreadRwlockWrlock(NULL);
|
||||||
|
EXPECT_NE(reti, 0);
|
||||||
|
reti = taosThreadRwlockWrlock(&rwlock);
|
||||||
|
EXPECT_EQ(reti, 0);
|
||||||
|
reti = taosThreadRwlockUnlock(&rwlock);
|
||||||
|
EXPECT_EQ(reti, 0);
|
||||||
|
|
||||||
|
reti = taosThreadRwlockDestroy(NULL);
|
||||||
|
EXPECT_NE(reti, 0);
|
||||||
|
reti = taosThreadRwlockDestroy(&rwlock);
|
||||||
|
EXPECT_EQ(reti, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(osThreadTests, rdlockAttr) {
|
||||||
|
int32_t reti = 0;
|
||||||
|
TdThreadRwlockAttr rdlockAttr;
|
||||||
|
reti = taosThreadRwlockAttrInit(NULL);
|
||||||
|
EXPECT_NE(reti, 0);
|
||||||
|
reti = taosThreadRwlockAttrInit(&rdlockAttr);
|
||||||
|
EXPECT_EQ(reti, 0);
|
||||||
|
|
||||||
|
int32_t pshared;
|
||||||
|
reti = taosThreadRwlockAttrGetPshared(&rdlockAttr, &pshared);
|
||||||
|
EXPECT_EQ(reti, 0);
|
||||||
|
reti = taosThreadRwlockAttrSetPshared(&rdlockAttr, pshared);
|
||||||
|
EXPECT_EQ(reti, 0);
|
||||||
|
reti = taosThreadRwlockAttrSetPshared(&rdlockAttr, -1);
|
||||||
|
EXPECT_NE(reti, 0);
|
||||||
|
reti = taosThreadRwlockAttrSetPshared(NULL, pshared);
|
||||||
|
EXPECT_NE(reti, 0);
|
||||||
|
reti = taosThreadRwlockAttrGetPshared(NULL, &pshared);
|
||||||
|
EXPECT_NE(reti, 0);
|
||||||
|
reti = taosThreadRwlockAttrGetPshared(&rdlockAttr, NULL);
|
||||||
|
EXPECT_NE(reti, 0);
|
||||||
|
|
||||||
|
reti = taosThreadRwlockAttrDestroy(NULL);
|
||||||
|
EXPECT_NE(reti, 0);
|
||||||
|
reti = taosThreadRwlockAttrDestroy(&rdlockAttr);
|
||||||
|
EXPECT_EQ(reti, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(osThreadTests, spinlock) {
|
||||||
|
int32_t reti = 0;
|
||||||
|
|
||||||
|
TdThreadSpinlock lock = {0};
|
||||||
|
reti = taosThreadSpinInit(&lock, -1);
|
||||||
|
EXPECT_EQ(reti, 0);
|
||||||
|
reti = taosThreadSpinLock(&lock);
|
||||||
|
EXPECT_EQ(reti, 0);
|
||||||
|
reti = taosThreadSpinTrylock(&lock);
|
||||||
|
EXPECT_NE(reti, 0);
|
||||||
|
reti = taosThreadSpinUnlock(&lock);
|
||||||
|
EXPECT_EQ(reti, 0);
|
||||||
|
reti = taosThreadSpinDestroy(&lock);
|
||||||
|
EXPECT_EQ(reti, 0);
|
||||||
|
|
||||||
|
reti = taosThreadSpinInit(&lock, -1);
|
||||||
|
EXPECT_EQ(reti, 0);
|
||||||
|
reti = taosThreadSpinTrylock(&lock);
|
||||||
|
EXPECT_EQ(reti, 0);
|
||||||
|
reti = taosThreadSpinUnlock(&lock);
|
||||||
|
EXPECT_EQ(reti, 0);
|
||||||
|
reti = taosThreadSpinDestroy(&lock);
|
||||||
|
EXPECT_EQ(reti, 0);
|
||||||
|
|
||||||
|
reti = taosThreadSpinInit(NULL, 0);
|
||||||
|
EXPECT_NE(reti, 0);
|
||||||
|
reti = taosThreadSpinLock(NULL);
|
||||||
|
EXPECT_NE(reti, 0);
|
||||||
|
reti = taosThreadSpinTrylock(NULL);
|
||||||
|
EXPECT_NE(reti, 0);
|
||||||
|
reti = taosThreadSpinUnlock(NULL);
|
||||||
|
EXPECT_NE(reti, 0);
|
||||||
|
reti = taosThreadSpinDestroy(NULL);
|
||||||
|
EXPECT_NE(reti, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(osThreadTests, others) {
|
||||||
|
taosThreadTestCancel();
|
||||||
|
taosThreadClear(NULL);
|
||||||
|
}
|
|
@ -33,7 +33,7 @@ TEST(osTimeTests, taosLocalTime) {
|
||||||
// Test 1: Test when both timep and result are not NULL
|
// Test 1: Test when both timep and result are not NULL
|
||||||
time_t timep = 1617531000; // 2021-04-04 18:10:00
|
time_t timep = 1617531000; // 2021-04-04 18:10:00
|
||||||
struct tm result;
|
struct tm result;
|
||||||
struct tm* local_time = taosLocalTime(&timep, &result, NULL, 0, NULL);
|
struct tm *local_time = taosLocalTime(&timep, &result, NULL, 0, NULL);
|
||||||
ASSERT_NE(local_time, nullptr);
|
ASSERT_NE(local_time, nullptr);
|
||||||
ASSERT_EQ(local_time->tm_year, 121);
|
ASSERT_EQ(local_time->tm_year, 121);
|
||||||
ASSERT_EQ(local_time->tm_mon, 3);
|
ASSERT_EQ(local_time->tm_mon, 3);
|
||||||
|
@ -92,4 +92,55 @@ TEST(osTimeTests, taosLocalTime) {
|
||||||
local_time = taosLocalTime(&neg_timep3, &result, NULL, 0, NULL);
|
local_time = taosLocalTime(&neg_timep3, &result, NULL, 0, NULL);
|
||||||
ASSERT_EQ(local_time, nullptr);
|
ASSERT_EQ(local_time, nullptr);
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(osTimeTests, invalidParameter) {
|
||||||
|
void *retp = NULL;
|
||||||
|
int32_t reti = 0;
|
||||||
|
char buf[1024] = {0};
|
||||||
|
char fmt[1024] = {0};
|
||||||
|
struct tm tm = {0};
|
||||||
|
struct timeval tv = {0};
|
||||||
|
|
||||||
|
retp = taosStrpTime(buf, fmt, NULL);
|
||||||
|
EXPECT_EQ(retp, nullptr);
|
||||||
|
retp = taosStrpTime(NULL, fmt, &tm);
|
||||||
|
EXPECT_EQ(retp, nullptr);
|
||||||
|
retp = taosStrpTime(buf, NULL, &tm);
|
||||||
|
EXPECT_EQ(retp, nullptr);
|
||||||
|
|
||||||
|
reti = taosGetTimeOfDay(NULL);
|
||||||
|
EXPECT_NE(reti, 0);
|
||||||
|
|
||||||
|
reti = taosTime(NULL);
|
||||||
|
EXPECT_NE(reti, 0);
|
||||||
|
|
||||||
|
tm.tm_year = 2024;
|
||||||
|
tm.tm_mon = 10;
|
||||||
|
tm.tm_mday = 23;
|
||||||
|
tm.tm_hour = 12;
|
||||||
|
tm.tm_min = 1;
|
||||||
|
tm.tm_sec = 0;
|
||||||
|
tm.tm_isdst = -1;
|
||||||
|
time_t rett = taosMktime(&tm, NULL);
|
||||||
|
EXPECT_NE(rett, 0);
|
||||||
|
|
||||||
|
retp = taosLocalTime(NULL, &tm, NULL, 0, NULL);
|
||||||
|
EXPECT_EQ(retp, nullptr);
|
||||||
|
|
||||||
|
retp = taosLocalTime(&rett, NULL, NULL, 0, NULL);
|
||||||
|
EXPECT_EQ(retp, nullptr);
|
||||||
|
|
||||||
|
reti = taosSetGlobalTimezone(NULL);
|
||||||
|
EXPECT_NE(reti, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(osTimeTests, user_mktime64) {
|
||||||
|
int64_t reti = 0;
|
||||||
|
|
||||||
|
reti = user_mktime64(2024, 10, 23, 12, 3, 2, 1);
|
||||||
|
EXPECT_NE(reti, 0);
|
||||||
|
|
||||||
|
reti = user_mktime64(2024, 1, 23, 12, 3, 2, 1);
|
||||||
|
EXPECT_NE(reti, 0);
|
||||||
}
|
}
|
|
@ -0,0 +1,388 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Color setting
|
||||||
|
RED='\033[0;31m'
|
||||||
|
GREEN='\033[1;32m'
|
||||||
|
GREEN_DARK='\033[0;32m'
|
||||||
|
GREEN_UNDERLINE='\033[4;32m'
|
||||||
|
NC='\033[0m'
|
||||||
|
|
||||||
|
function print_color() {
|
||||||
|
local color="$1"
|
||||||
|
local message="$2"
|
||||||
|
echo -e "${color}${message}${NC}"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Initialization parameter
|
||||||
|
TDENGINE_DIR="/root/TDinternal/community"
|
||||||
|
BRANCH=""
|
||||||
|
TDENGINE_GCDA_DIR="/root/TDinternal/community/debug/"
|
||||||
|
|
||||||
|
# Parse command line parameters
|
||||||
|
while getopts "hd:b:f:c:u:i:" arg; do
|
||||||
|
case $arg in
|
||||||
|
d)
|
||||||
|
TDENGINE_DIR=$OPTARG
|
||||||
|
;;
|
||||||
|
b)
|
||||||
|
BRANCH=$OPTARG
|
||||||
|
;;
|
||||||
|
f)
|
||||||
|
TDENGINE_GCDA_DIR=$OPTARG
|
||||||
|
;;
|
||||||
|
c)
|
||||||
|
TEST_CASE=$OPTARG
|
||||||
|
;;
|
||||||
|
u)
|
||||||
|
UNIT_TEST_CASE=$OPTARG
|
||||||
|
;;
|
||||||
|
i)
|
||||||
|
BRANCH_BUILD=$OPTARG
|
||||||
|
;;
|
||||||
|
h)
|
||||||
|
echo "Usage: $(basename $0) -d [TDengine dir] -b [Test branch] -i [Build test branch] -f [TDengine gcda dir] -c [Test single case/all cases] -u [Unit test case]"
|
||||||
|
echo " -d [TDengine dir] [default /root/TDinternal/community; eg: /home/TDinternal/community] "
|
||||||
|
echo " -b [Test branch] [default local branch; eg:cover/3.0] "
|
||||||
|
echo " -i [Build test branch] [default no:not build, but still install ;yes:will build and install ] "
|
||||||
|
echo " -f [TDengine gcda dir] [default /root/TDinternal/community/debug; eg:/root/TDinternal/community/debug/community/source/dnode/vnode/CMakeFiles/vnode.dir/src/tq/] "
|
||||||
|
echo " -c [Test single case/all cases] [default null; -c all : include parallel_test/longtimeruning_cases.task and all unit cases; -c task : include parallel_test/longtimeruning_cases.task; single case: eg: -c './test.sh -f tsim/stream/streamFwcIntervalFill.sim' ] "
|
||||||
|
echo " -u [Unit test case] [default null; eg: './schedulerTest' ] "
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
?)
|
||||||
|
echo "Usage: ./$(basename $0) -h"
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
# Check if the command name is provided
|
||||||
|
if [ -z "$TDENGINE_DIR" ]; then
|
||||||
|
echo "Error: TDengine dir is required."
|
||||||
|
echo "Usage: $(basename $0) -d [TDengine dir] -b [Test branch] -i [Build test branch] -f [TDengine gcda dir] -c [Test single case/all cases] -u [Unit test case] "
|
||||||
|
echo " -d [TDengine dir] [default /root/TDinternal/community; eg: /home/TDinternal/community] "
|
||||||
|
echo " -b [Test branch] [default local branch; eg:cover/3.0] "
|
||||||
|
echo " -i [Build test branch] [default no:not build, but still install ;yes:will build and install ] "
|
||||||
|
echo " -f [TDengine gcda dir] [default /root/TDinternal/community/debug; eg:/root/TDinternal/community/debug/community/source/dnode/vnode/CMakeFiles/vnode.dir/src/tq/] "
|
||||||
|
echo " -c [Test casingle case/all casesse] [default null; -c all : include parallel_test/longtimeruning_cases.task and all unit cases; -c task : include parallel_test/longtimeruning_cases.task; single case: eg: -c './test.sh -f tsim/stream/streamFwcIntervalFill.sim' ] "
|
||||||
|
echo " -u [Unit test case] [default null; eg: './schedulerTest' ] "
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
echo "TDENGINE_DIR = $TDENGINE_DIR"
|
||||||
|
today=`date +"%Y%m%d"`
|
||||||
|
TDENGINE_ALLCI_REPORT="$TDENGINE_DIR/tests/all-ci-report-$today.log"
|
||||||
|
|
||||||
|
function pullTDengine() {
|
||||||
|
print_color "$GREEN" "TDengine pull start"
|
||||||
|
|
||||||
|
# pull parent code
|
||||||
|
cd "$TDENGINE_DIR/../"
|
||||||
|
print_color "$GREEN" "git pull parent code..."
|
||||||
|
|
||||||
|
git reset --hard
|
||||||
|
git checkout -- .
|
||||||
|
git checkout $branch
|
||||||
|
git checkout -- .
|
||||||
|
git clean -f
|
||||||
|
git pull
|
||||||
|
|
||||||
|
# pull tdengine code
|
||||||
|
cd $TDENGINE_DIR
|
||||||
|
print_color "$GREEN" "git pull tdengine code..."
|
||||||
|
|
||||||
|
git reset --hard
|
||||||
|
git checkout -- .
|
||||||
|
git checkout $branch
|
||||||
|
git checkout -- .
|
||||||
|
git clean -f
|
||||||
|
git pull
|
||||||
|
|
||||||
|
print_color "$GREEN" "TDengine pull end"
|
||||||
|
}
|
||||||
|
|
||||||
|
function buildTDengine() {
|
||||||
|
print_color "$GREEN" "TDengine build start"
|
||||||
|
|
||||||
|
[ -d $TDENGINE_DIR/debug ] || mkdir $TDENGINE_DIR/debug
|
||||||
|
cd $TDENGINE_DIR/debug
|
||||||
|
|
||||||
|
print_color "$GREEN" "rebuild.."
|
||||||
|
rm -rf *
|
||||||
|
makecmd="cmake -DCOVER=true -DBUILD_TEST=false -DBUILD_HTTP=false -DBUILD_DEPENDENCY_TESTS=0 -DBUILD_TOOLS=true -DBUILD_GEOS=true -DBUILD_TEST=true -DBUILD_CONTRIB=false ../../"
|
||||||
|
print_color "$GREEN" "$makecmd"
|
||||||
|
$makecmd
|
||||||
|
make -j 8 install
|
||||||
|
}
|
||||||
|
|
||||||
|
# Check and get the branch name and build branch
|
||||||
|
if [ -n "$BRANCH" ] && [ -z "$BRANCH_BUILD" ] ; then
|
||||||
|
branch="$BRANCH"
|
||||||
|
print_color "$GREEN" "Testing branch: $branch "
|
||||||
|
print_color "$GREEN" "Build is required for this test!"
|
||||||
|
pullTDengine
|
||||||
|
buildTDengine
|
||||||
|
elif [ -n "$BRANCH_BUILD" ] && [ "$BRANCH_BUILD" == "yes" ] ; then
|
||||||
|
branch="$BRANCH"
|
||||||
|
print_color "$GREEN" "Testing branch: $branch "
|
||||||
|
print_color "$GREEN" "Build is required for this test!"
|
||||||
|
pullTDengine
|
||||||
|
buildTDengine
|
||||||
|
elif [ -n "$BRANCH_BUILD" ] && [ "$BRANCH_BUILD" == "no" ] ; then
|
||||||
|
branch="$BRANCH"
|
||||||
|
print_color "$GREEN" "Testing branch: $branch "
|
||||||
|
print_color "$GREEN" "not build,only install!"
|
||||||
|
cd "$TDENGINE_DIR/../"
|
||||||
|
git pull
|
||||||
|
cd "$TDENGINE_DIR/"
|
||||||
|
git pull
|
||||||
|
cd $TDENGINE_DIR/debug
|
||||||
|
make -j 8 install
|
||||||
|
else
|
||||||
|
print_color "$GREEN" "Build is not required for this test!"
|
||||||
|
fi
|
||||||
|
|
||||||
|
function runCasesOneByOne () {
|
||||||
|
while read -r line; do
|
||||||
|
if [[ "$line" != "#"* ]]; then
|
||||||
|
cmd=`echo $line | cut -d',' -f 5`
|
||||||
|
if [[ "$2" == "sim" ]] && [[ $line == *"script"* ]]; then
|
||||||
|
echo $cmd
|
||||||
|
case=`echo $cmd | cut -d' ' -f 3`
|
||||||
|
case_file=`echo $case | tr -d ' /' `
|
||||||
|
start_time=`date +%s`
|
||||||
|
date +%F\ %T | tee -a $TDENGINE_ALLCI_REPORT && timeout 20m $cmd > $TDENGINE_DIR/tests/$case_file.log 2>&1 && \
|
||||||
|
echo -e "${GREEN}$case success${NC}" | tee -a $TDENGINE_ALLCI_REPORT || \
|
||||||
|
echo -e "${RED}$case failed${NC}" | tee -a $TDENGINE_ALLCI_REPORT
|
||||||
|
end_time=`date +%s`
|
||||||
|
echo execution time of $case was `expr $end_time - $start_time`s. | tee -a $TDENGINE_ALLCI_REPORT
|
||||||
|
|
||||||
|
elif [[ "$line" == *"$2"* ]]; then
|
||||||
|
echo $cmd
|
||||||
|
if [[ "$cmd" == *"pytest.sh"* ]]; then
|
||||||
|
cmd=`echo $cmd | cut -d' ' -f 2-20`
|
||||||
|
fi
|
||||||
|
case=`echo $cmd | cut -d' ' -f 4-20`
|
||||||
|
case_file=`echo $case | tr -d ' /' `
|
||||||
|
start_time=`date +%s`
|
||||||
|
date +%F\ %T | tee -a $TDENGINE_ALLCI_REPORT && timeout 20m $cmd > $TDENGINE_DIR/tests/$case_file.log 2>&1 && \
|
||||||
|
echo -e "${GREEN}$case success${NC}" | tee -a $TDENGINE_ALLCI_REPORT || \
|
||||||
|
echo -e "${RED}$case failed${NC}" | tee -a $TDENGINE_ALLCI_REPORT
|
||||||
|
end_time=`date +%s`
|
||||||
|
echo execution time of $case was `expr $end_time - $start_time`s. | tee -a $TDENGINE_ALLCI_REPORT
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done < $1
|
||||||
|
}
|
||||||
|
|
||||||
|
function runUnitTest() {
|
||||||
|
print_color "$GREEN" "=== Run unit test case ==="
|
||||||
|
print_color "$GREEN" " $TDENGINE_DIR/debug"
|
||||||
|
cd $TDENGINE_DIR/debug
|
||||||
|
ctest -j12
|
||||||
|
print_color "$GREEN" "3.0 unit test done"
|
||||||
|
}
|
||||||
|
|
||||||
|
function runSimCases() {
|
||||||
|
print_color "$GREEN" "=== Run sim cases ==="
|
||||||
|
|
||||||
|
cd $TDENGINE_DIR/tests/script
|
||||||
|
runCasesOneByOne $TDENGINE_DIR/tests/parallel_test/longtimeruning_cases.task sim
|
||||||
|
|
||||||
|
totalSuccess=`grep 'sim success' $TDENGINE_ALLCI_REPORT | wc -l`
|
||||||
|
if [ "$totalSuccess" -gt "0" ]; then
|
||||||
|
print_color "$GREEN" "### Total $totalSuccess SIM test case(s) succeed! ###" | tee -a $TDENGINE_ALLCI_REPORT
|
||||||
|
fi
|
||||||
|
|
||||||
|
totalFailed=`grep 'sim failed\|fault' $TDENGINE_ALLCI_REPORT | wc -l`
|
||||||
|
if [ "$totalFailed" -ne "0" ]; then
|
||||||
|
print_color "$RED" "### Total $totalFailed SIM test case(s) failed! ###" | tee -a $TDENGINE_ALLCI_REPORT
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function runPythonCases() {
|
||||||
|
print_color "$GREEN" "=== Run python cases ==="
|
||||||
|
|
||||||
|
cd $TDENGINE_DIR/tests/parallel_test
|
||||||
|
sed -i '/compatibility.py/d' longtimeruning_cases.task
|
||||||
|
|
||||||
|
# army
|
||||||
|
cd $TDENGINE_DIR/tests/army
|
||||||
|
runCasesOneByOne ../parallel_test/longtimeruning_cases.task army
|
||||||
|
|
||||||
|
# system-test
|
||||||
|
cd $TDENGINE_DIR/tests/system-test
|
||||||
|
runCasesOneByOne ../parallel_test/longtimeruning_cases.task system-test
|
||||||
|
|
||||||
|
# develop-test
|
||||||
|
cd $TDENGINE_DIR/tests/develop-test
|
||||||
|
runCasesOneByOne ../parallel_test/longtimeruning_cases.task develop-test
|
||||||
|
|
||||||
|
totalSuccess=`grep 'py success' $TDENGINE_ALLCI_REPORT | wc -l`
|
||||||
|
if [ "$totalSuccess" -gt "0" ]; then
|
||||||
|
print_color "$GREEN" "### Total $totalSuccess python test case(s) succeed! ###" | tee -a $TDENGINE_ALLCI_REPORT
|
||||||
|
fi
|
||||||
|
|
||||||
|
totalFailed=`grep 'py failed\|fault' $TDENGINE_ALLCI_REPORT | wc -l`
|
||||||
|
if [ "$totalFailed" -ne "0" ]; then
|
||||||
|
print_color "$RED" "### Total $totalFailed python test case(s) failed! ###" | tee -a $TDENGINE_ALLCI_REPORT
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function runTest_all() {
|
||||||
|
print_color "$GREEN" "run Test"
|
||||||
|
|
||||||
|
cd $TDENGINE_DIR
|
||||||
|
[ -d sim ] && rm -rf sim
|
||||||
|
[ -f $TDENGINE_ALLCI_REPORT ] && rm $TDENGINE_ALLCI_REPORT
|
||||||
|
|
||||||
|
runUnitTest
|
||||||
|
runSimCases
|
||||||
|
runPythonCases
|
||||||
|
|
||||||
|
stopTaosd
|
||||||
|
cd $TDENGINE_DIR/tests/script
|
||||||
|
find . -name '*.sql' | xargs rm -f
|
||||||
|
|
||||||
|
cd $TDENGINE_DIR/tests/pytest
|
||||||
|
find . -name '*.sql' | xargs rm -f
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function runTest() {
|
||||||
|
print_color "$GREEN" "run Test"
|
||||||
|
|
||||||
|
cd $TDENGINE_DIR
|
||||||
|
[ -d sim ] && rm -rf sim
|
||||||
|
[ -f $TDENGINE_ALLCI_REPORT ] && rm $TDENGINE_ALLCI_REPORT
|
||||||
|
|
||||||
|
if [ -n "$TEST_CASE" ] && [ "$TEST_CASE" != "all" ] && [ "$TEST_CASE" != "task" ]; then
|
||||||
|
TEST_CASE="$TEST_CASE"
|
||||||
|
print_color "$GREEN" "Test case: $TEST_CASE "
|
||||||
|
cd $TDENGINE_DIR/tests/script/ && $TEST_CASE
|
||||||
|
cd $TDENGINE_DIR/tests/army/ && $TEST_CASE
|
||||||
|
cd $TDENGINE_DIR/tests/system-test/ && $TEST_CASE
|
||||||
|
cd $TDENGINE_DIR/tests/develop-test/ && $TEST_CASE
|
||||||
|
elif [ "$TEST_CASE" == "all" ]; then
|
||||||
|
print_color "$GREEN" "Test case is : parallel_test/longtimeruning_cases.task and all unit cases"
|
||||||
|
runTest_all
|
||||||
|
elif [ "$TEST_CASE" == "task" ]; then
|
||||||
|
print_color "$GREEN" "Test case is only: parallel_test/longtimeruning_cases.task "
|
||||||
|
runSimCases
|
||||||
|
runPythonCases
|
||||||
|
elif [ -n "$UNIT_TEST_CASE" ]; then
|
||||||
|
UNIT_TEST_CASE="$UNIT_TEST_CASE"
|
||||||
|
cd $TDENGINE_DIR/debug/build/bin/ && $UNIT_TEST_CASE
|
||||||
|
else
|
||||||
|
print_color "$GREEN" "Test case is null"
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
stopTaosd
|
||||||
|
cd $TDENGINE_DIR/tests/script
|
||||||
|
find . -name '*.sql' | xargs rm -f
|
||||||
|
|
||||||
|
cd $TDENGINE_DIR/tests/pytest
|
||||||
|
find . -name '*.sql' | xargs rm -f
|
||||||
|
}
|
||||||
|
|
||||||
|
function lcovFunc {
|
||||||
|
echo "collect data by lcov"
|
||||||
|
cd $TDENGINE_DIR
|
||||||
|
|
||||||
|
if [ -n "$TDENGINE_GCDA_DIR" ]; then
|
||||||
|
TDENGINE_GCDA_DIR="$TDENGINE_GCDA_DIR"
|
||||||
|
print_color "$GREEN" "Test gcda file dir: $TDENGINE_GCDA_DIR "
|
||||||
|
else
|
||||||
|
print_color "$GREEN" "Test gcda file dir is default: /root/TDinternal/community/debug"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# collect data
|
||||||
|
lcov -d "$TDENGINE_GCDA_DIR" -capture --rc lcov_branch_coverage=1 --rc genhtml_branch_coverage=1 --no-external -b $TDENGINE_DIR -o coverage.info
|
||||||
|
|
||||||
|
# remove exclude paths
|
||||||
|
lcov --remove coverage.info \
|
||||||
|
'*/contrib/*' '*/test/*' '*/packaging/*' '*/taos-tools/*' '*/taosadapter/*' '*/TSZ/*' \
|
||||||
|
'*/AccessBridgeCalls.c' '*/ttszip.c' '*/dataInserter.c' '*/tlinearhash.c' '*/tsimplehash.c' '*/tsdbDiskData.c' '/*/enterprise/*' '*/docs/*' '*/sim/*'\
|
||||||
|
'*/texpr.c' '*/runUdf.c' '*/schDbg.c' '*/syncIO.c' '*/tdbOs.c' '*/pushServer.c' '*/osLz4.c'\
|
||||||
|
'*/tbase64.c' '*/tbuffer.c' '*/tdes.c' '*/texception.c' '*/examples/*' '*/tidpool.c' '*/tmempool.c'\
|
||||||
|
'*/clientJniConnector.c' '*/clientTmqConnector.c' '*/version.cc'\
|
||||||
|
'*/tthread.c' '*/tversion.c' '*/ctgDbg.c' '*/schDbg.c' '*/qwDbg.c' '*/tencode.h' \
|
||||||
|
'*/shellAuto.c' '*/shellTire.c' '*/shellCommand.c'\
|
||||||
|
'*/sql.c' '*/sql.y' '*/smaSnapshot.c' '*/smaCommit.c' '*/debug/*' '*/tests/*'\
|
||||||
|
--rc lcov_branch_coverage=1 -o coverage.info
|
||||||
|
|
||||||
|
# generate result
|
||||||
|
echo "generate result"
|
||||||
|
lcov -l --rc lcov_branch_coverage=1 coverage.info | tee -a $TDENGINE_COVERAGE_REPORT
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function stopTaosd {
|
||||||
|
print_color "$GREEN" "Stop taosd start"
|
||||||
|
systemctl stop taosd
|
||||||
|
PID=`ps -ef|grep -w taosd | grep -v grep | awk '{print $2}'`
|
||||||
|
while [ -n "$PID" ]
|
||||||
|
do
|
||||||
|
pkill -TERM -x taosd
|
||||||
|
sleep 1
|
||||||
|
PID=`ps -ef|grep -w taosd | grep -v grep | awk '{print $2}'`
|
||||||
|
done
|
||||||
|
print_color "$GREEN" "Stop tasod end"
|
||||||
|
}
|
||||||
|
|
||||||
|
function stopTaosadapter {
|
||||||
|
print_color "$GREEN" "Stop taosadapter"
|
||||||
|
systemctl stop taosadapter.service
|
||||||
|
PID=`ps -ef|grep -w taosadapter | grep -v grep | awk '{print $2}'`
|
||||||
|
while [ -n "$PID" ]
|
||||||
|
do
|
||||||
|
pkill -TERM -x taosadapter
|
||||||
|
sleep 1
|
||||||
|
PID=`ps -ef|grep -w taosd | grep -v grep | awk '{print $2}'`
|
||||||
|
done
|
||||||
|
print_color "$GREEN" "Stop tasoadapter end"
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
WORK_DIR=/root
|
||||||
|
|
||||||
|
date >> $WORK_DIR/date.log
|
||||||
|
print_color "$GREEN" "Run local coverage test cases" | tee -a $WORK_DIR/date.log
|
||||||
|
|
||||||
|
stopTaosd
|
||||||
|
|
||||||
|
runTest
|
||||||
|
|
||||||
|
lcovFunc
|
||||||
|
|
||||||
|
|
||||||
|
date >> $WORK_DIR/date.log
|
||||||
|
print_color "$GREEN" "End of local coverage test cases" | tee -a $WORK_DIR/date.log
|
||||||
|
|
||||||
|
|
||||||
|
# Define coverage information files and output directories
|
||||||
|
COVERAGE_INFO="$TDENGINE_DIR/coverage.info"
|
||||||
|
OUTPUT_DIR="$WORK_DIR/coverage_report"
|
||||||
|
|
||||||
|
# Check whether the coverage information file exists
|
||||||
|
if [ ! -f "$COVERAGE_INFO" ]; then
|
||||||
|
echo "Error: $COVERAGE_INFO not found!"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Generate local HTML reports
|
||||||
|
genhtml "$COVERAGE_INFO" --branch-coverage --function-coverage --output-directory "$OUTPUT_DIR"
|
||||||
|
|
||||||
|
# Check whether the report was generated successfully
|
||||||
|
if [ $? -eq 0 ]; then
|
||||||
|
echo "HTML coverage report generated successfully in $OUTPUT_DIR"
|
||||||
|
echo "For more details : "
|
||||||
|
echo "http://192.168.1.61:7000/"
|
||||||
|
else
|
||||||
|
echo "Error generating HTML coverage report"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
|
@ -0,0 +1,388 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Color setting
|
||||||
|
RED='\033[0;31m'
|
||||||
|
GREEN='\033[1;32m'
|
||||||
|
GREEN_DARK='\033[0;32m'
|
||||||
|
GREEN_UNDERLINE='\033[4;32m'
|
||||||
|
NC='\033[0m'
|
||||||
|
|
||||||
|
function print_color() {
|
||||||
|
local color="$1"
|
||||||
|
local message="$2"
|
||||||
|
echo -e "${color}${message}${NC}"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Initialization parameter
|
||||||
|
TDENGINE_DIR="/root/TDinternal/community"
|
||||||
|
BRANCH=""
|
||||||
|
TDENGINE_GCDA_DIR="/root/TDinternal/community/debug/"
|
||||||
|
|
||||||
|
# Parse command line parameters
|
||||||
|
while getopts "hd:b:f:c:u:i:" arg; do
|
||||||
|
case $arg in
|
||||||
|
d)
|
||||||
|
TDENGINE_DIR=$OPTARG
|
||||||
|
;;
|
||||||
|
b)
|
||||||
|
BRANCH=$OPTARG
|
||||||
|
;;
|
||||||
|
f)
|
||||||
|
TDENGINE_GCDA_DIR=$OPTARG
|
||||||
|
;;
|
||||||
|
c)
|
||||||
|
TEST_CASE=$OPTARG
|
||||||
|
;;
|
||||||
|
u)
|
||||||
|
UNIT_TEST_CASE=$OPTARG
|
||||||
|
;;
|
||||||
|
i)
|
||||||
|
BRANCH_BUILD=$OPTARG
|
||||||
|
;;
|
||||||
|
h)
|
||||||
|
echo "Usage: $(basename $0) -d [TDengine dir] -b [Test branch] -i [Build test branch] -f [TDengine gcda dir] -c [Test single case/all cases] -u [Unit test case]"
|
||||||
|
echo " -d [TDengine dir] [default /root/TDinternal/community; eg: /home/TDinternal/community] "
|
||||||
|
echo " -b [Test branch] [default local branch; eg:cover/3.0] "
|
||||||
|
echo " -i [Build test branch] [default no:not build, but still install ;yes:will build and install ] "
|
||||||
|
echo " -f [TDengine gcda dir] [default /root/TDinternal/community/debug; eg:/root/TDinternal/community/debug/community/source/dnode/vnode/CMakeFiles/vnode.dir/src/tq/] "
|
||||||
|
echo " -c [Test single case/all cases] [default null; -c all : include parallel_test/longtimeruning_cases.task and all unit cases; -c task : include parallel_test/longtimeruning_cases.task; single case: eg: -c './test.sh -f tsim/stream/streamFwcIntervalFill.sim' ] "
|
||||||
|
echo " -u [Unit test case] [default null; eg: './schedulerTest' ] "
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
?)
|
||||||
|
echo "Usage: ./$(basename $0) -h"
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
# Check if the command name is provided
|
||||||
|
if [ -z "$TDENGINE_DIR" ]; then
|
||||||
|
echo "Error: TDengine dir is required."
|
||||||
|
echo "Usage: $(basename $0) -d [TDengine dir] -b [Test branch] -i [Build test branch] -f [TDengine gcda dir] -c [Test single case/all cases] -u [Unit test case] "
|
||||||
|
echo " -d [TDengine dir] [default /root/TDinternal/community; eg: /home/TDinternal/community] "
|
||||||
|
echo " -b [Test branch] [default local branch; eg:cover/3.0] "
|
||||||
|
echo " -i [Build test branch] [default no:not build, but still install ;yes:will build and install ] "
|
||||||
|
echo " -f [TDengine gcda dir] [default /root/TDinternal/community/debug; eg:/root/TDinternal/community/debug/community/source/dnode/vnode/CMakeFiles/vnode.dir/src/tq/] "
|
||||||
|
echo " -c [Test casingle case/all casesse] [default null; -c all : include parallel_test/longtimeruning_cases.task and all unit cases; -c task : include parallel_test/longtimeruning_cases.task; single case: eg: -c './test.sh -f tsim/stream/streamFwcIntervalFill.sim' ] "
|
||||||
|
echo " -u [Unit test case] [default null; eg: './schedulerTest' ] "
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
echo "TDENGINE_DIR = $TDENGINE_DIR"
|
||||||
|
today=`date +"%Y%m%d"`
|
||||||
|
TDENGINE_ALLCI_REPORT="$TDENGINE_DIR/tests/all-ci-report-$today.log"
|
||||||
|
|
||||||
|
function pullTDengine() {
|
||||||
|
print_color "$GREEN" "TDengine pull start"
|
||||||
|
|
||||||
|
# pull parent code
|
||||||
|
cd "$TDENGINE_DIR/../"
|
||||||
|
print_color "$GREEN" "git pull parent code..."
|
||||||
|
|
||||||
|
git reset --hard
|
||||||
|
git checkout -- .
|
||||||
|
git checkout $branch
|
||||||
|
git checkout -- .
|
||||||
|
git clean -f
|
||||||
|
git pull
|
||||||
|
|
||||||
|
# pull tdengine code
|
||||||
|
cd $TDENGINE_DIR
|
||||||
|
print_color "$GREEN" "git pull tdengine code..."
|
||||||
|
|
||||||
|
git reset --hard
|
||||||
|
git checkout -- .
|
||||||
|
git checkout $branch
|
||||||
|
git checkout -- .
|
||||||
|
git clean -f
|
||||||
|
git pull
|
||||||
|
|
||||||
|
print_color "$GREEN" "TDengine pull end"
|
||||||
|
}
|
||||||
|
|
||||||
|
function buildTDengine() {
|
||||||
|
print_color "$GREEN" "TDengine build start"
|
||||||
|
|
||||||
|
[ -d $TDENGINE_DIR/debug ] || mkdir $TDENGINE_DIR/debug
|
||||||
|
cd $TDENGINE_DIR/debug
|
||||||
|
|
||||||
|
print_color "$GREEN" "rebuild.."
|
||||||
|
rm -rf *
|
||||||
|
makecmd="cmake -DCOVER=true -DBUILD_TEST=false -DBUILD_HTTP=false -DBUILD_DEPENDENCY_TESTS=0 -DBUILD_TOOLS=true -DBUILD_GEOS=true -DBUILD_TEST=true -DBUILD_CONTRIB=false ../../"
|
||||||
|
print_color "$GREEN" "$makecmd"
|
||||||
|
$makecmd
|
||||||
|
make -j 8 install
|
||||||
|
}
|
||||||
|
|
||||||
|
# Check and get the branch name and build branch
|
||||||
|
if [ -n "$BRANCH" ] && [ -z "$BRANCH_BUILD" ] ; then
|
||||||
|
branch="$BRANCH"
|
||||||
|
print_color "$GREEN" "Testing branch: $branch "
|
||||||
|
print_color "$GREEN" "Build is required for this test!"
|
||||||
|
pullTDengine
|
||||||
|
buildTDengine
|
||||||
|
elif [ -n "$BRANCH_BUILD" ] && [ "$BRANCH_BUILD" == "yes" ] ; then
|
||||||
|
branch="$BRANCH"
|
||||||
|
print_color "$GREEN" "Testing branch: $branch "
|
||||||
|
print_color "$GREEN" "Build is required for this test!"
|
||||||
|
pullTDengine
|
||||||
|
buildTDengine
|
||||||
|
elif [ -n "$BRANCH_BUILD" ] && [ "$BRANCH_BUILD" == "no" ] ; then
|
||||||
|
branch="$BRANCH"
|
||||||
|
print_color "$GREEN" "Testing branch: $branch "
|
||||||
|
print_color "$GREEN" "not build,only install!"
|
||||||
|
cd "$TDENGINE_DIR/../"
|
||||||
|
git pull
|
||||||
|
cd "$TDENGINE_DIR/"
|
||||||
|
git pull
|
||||||
|
cd $TDENGINE_DIR/debug
|
||||||
|
make -j 8 install
|
||||||
|
else
|
||||||
|
print_color "$GREEN" "Build is not required for this test!"
|
||||||
|
fi
|
||||||
|
|
||||||
|
function runCasesOneByOne () {
|
||||||
|
while read -r line; do
|
||||||
|
if [[ "$line" != "#"* ]]; then
|
||||||
|
cmd=`echo $line | cut -d',' -f 5`
|
||||||
|
if [[ "$2" == "sim" ]] && [[ $line == *"script"* ]]; then
|
||||||
|
echo $cmd
|
||||||
|
case=`echo $cmd | cut -d' ' -f 3`
|
||||||
|
case_file=`echo $case | tr -d ' /' `
|
||||||
|
start_time=`date +%s`
|
||||||
|
date +%F\ %T | tee -a $TDENGINE_ALLCI_REPORT && timeout 20m $cmd > $TDENGINE_DIR/tests/$case_file.log 2>&1 && \
|
||||||
|
echo -e "${GREEN}$case success${NC}" | tee -a $TDENGINE_ALLCI_REPORT || \
|
||||||
|
echo -e "${RED}$case failed${NC}" | tee -a $TDENGINE_ALLCI_REPORT
|
||||||
|
end_time=`date +%s`
|
||||||
|
echo execution time of $case was `expr $end_time - $start_time`s. | tee -a $TDENGINE_ALLCI_REPORT
|
||||||
|
|
||||||
|
elif [[ "$line" == *"$2"* ]]; then
|
||||||
|
echo $cmd
|
||||||
|
if [[ "$cmd" == *"pytest.sh"* ]]; then
|
||||||
|
cmd=`echo $cmd | cut -d' ' -f 2-20`
|
||||||
|
fi
|
||||||
|
case=`echo $cmd | cut -d' ' -f 4-20`
|
||||||
|
case_file=`echo $case | tr -d ' /' `
|
||||||
|
start_time=`date +%s`
|
||||||
|
date +%F\ %T | tee -a $TDENGINE_ALLCI_REPORT && timeout 20m $cmd > $TDENGINE_DIR/tests/$case_file.log 2>&1 && \
|
||||||
|
echo -e "${GREEN}$case success${NC}" | tee -a $TDENGINE_ALLCI_REPORT || \
|
||||||
|
echo -e "${RED}$case failed${NC}" | tee -a $TDENGINE_ALLCI_REPORT
|
||||||
|
end_time=`date +%s`
|
||||||
|
echo execution time of $case was `expr $end_time - $start_time`s. | tee -a $TDENGINE_ALLCI_REPORT
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done < $1
|
||||||
|
}
|
||||||
|
|
||||||
|
function runUnitTest() {
|
||||||
|
print_color "$GREEN" "=== Run unit test case ==="
|
||||||
|
print_color "$GREEN" " $TDENGINE_DIR/debug"
|
||||||
|
cd $TDENGINE_DIR/debug
|
||||||
|
ctest -j12
|
||||||
|
print_color "$GREEN" "3.0 unit test done"
|
||||||
|
}
|
||||||
|
|
||||||
|
function runSimCases() {
|
||||||
|
print_color "$GREEN" "=== Run sim cases ==="
|
||||||
|
|
||||||
|
cd $TDENGINE_DIR/tests/script
|
||||||
|
runCasesOneByOne $TDENGINE_DIR/tests/parallel_test/longtimeruning_cases.task sim
|
||||||
|
|
||||||
|
totalSuccess=`grep 'sim success' $TDENGINE_ALLCI_REPORT | wc -l`
|
||||||
|
if [ "$totalSuccess" -gt "0" ]; then
|
||||||
|
print_color "$GREEN" "### Total $totalSuccess SIM test case(s) succeed! ###" | tee -a $TDENGINE_ALLCI_REPORT
|
||||||
|
fi
|
||||||
|
|
||||||
|
totalFailed=`grep 'sim failed\|fault' $TDENGINE_ALLCI_REPORT | wc -l`
|
||||||
|
if [ "$totalFailed" -ne "0" ]; then
|
||||||
|
print_color "$RED" "### Total $totalFailed SIM test case(s) failed! ###" | tee -a $TDENGINE_ALLCI_REPORT
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function runPythonCases() {
|
||||||
|
print_color "$GREEN" "=== Run python cases ==="
|
||||||
|
|
||||||
|
cd $TDENGINE_DIR/tests/parallel_test
|
||||||
|
sed -i '/compatibility.py/d' longtimeruning_cases.task
|
||||||
|
|
||||||
|
# army
|
||||||
|
cd $TDENGINE_DIR/tests/army
|
||||||
|
runCasesOneByOne ../parallel_test/longtimeruning_cases.task army
|
||||||
|
|
||||||
|
# system-test
|
||||||
|
cd $TDENGINE_DIR/tests/system-test
|
||||||
|
runCasesOneByOne ../parallel_test/longtimeruning_cases.task system-test
|
||||||
|
|
||||||
|
# develop-test
|
||||||
|
cd $TDENGINE_DIR/tests/develop-test
|
||||||
|
runCasesOneByOne ../parallel_test/longtimeruning_cases.task develop-test
|
||||||
|
|
||||||
|
totalSuccess=`grep 'py success' $TDENGINE_ALLCI_REPORT | wc -l`
|
||||||
|
if [ "$totalSuccess" -gt "0" ]; then
|
||||||
|
print_color "$GREEN" "### Total $totalSuccess python test case(s) succeed! ###" | tee -a $TDENGINE_ALLCI_REPORT
|
||||||
|
fi
|
||||||
|
|
||||||
|
totalFailed=`grep 'py failed\|fault' $TDENGINE_ALLCI_REPORT | wc -l`
|
||||||
|
if [ "$totalFailed" -ne "0" ]; then
|
||||||
|
print_color "$RED" "### Total $totalFailed python test case(s) failed! ###" | tee -a $TDENGINE_ALLCI_REPORT
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function runTest_all() {
|
||||||
|
print_color "$GREEN" "run Test"
|
||||||
|
|
||||||
|
cd $TDENGINE_DIR
|
||||||
|
[ -d sim ] && rm -rf sim
|
||||||
|
[ -f $TDENGINE_ALLCI_REPORT ] && rm $TDENGINE_ALLCI_REPORT
|
||||||
|
|
||||||
|
runUnitTest
|
||||||
|
runSimCases
|
||||||
|
runPythonCases
|
||||||
|
|
||||||
|
stopTaosd
|
||||||
|
cd $TDENGINE_DIR/tests/script
|
||||||
|
find . -name '*.sql' | xargs rm -f
|
||||||
|
|
||||||
|
cd $TDENGINE_DIR/tests/pytest
|
||||||
|
find . -name '*.sql' | xargs rm -f
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function runTest() {
|
||||||
|
print_color "$GREEN" "run Test"
|
||||||
|
|
||||||
|
cd $TDENGINE_DIR
|
||||||
|
[ -d sim ] && rm -rf sim
|
||||||
|
[ -f $TDENGINE_ALLCI_REPORT ] && rm $TDENGINE_ALLCI_REPORT
|
||||||
|
|
||||||
|
if [ -n "$TEST_CASE" ] && [ "$TEST_CASE" != "all" ] && [ "$TEST_CASE" != "task" ]; then
|
||||||
|
TEST_CASE="$TEST_CASE"
|
||||||
|
print_color "$GREEN" "Test case: $TEST_CASE "
|
||||||
|
cd $TDENGINE_DIR/tests/script/ && $TEST_CASE
|
||||||
|
cd $TDENGINE_DIR/tests/army/ && $TEST_CASE
|
||||||
|
cd $TDENGINE_DIR/tests/system-test/ && $TEST_CASE
|
||||||
|
cd $TDENGINE_DIR/tests/develop-test/ && $TEST_CASE
|
||||||
|
elif [ "$TEST_CASE" == "all" ]; then
|
||||||
|
print_color "$GREEN" "Test case is : parallel_test/longtimeruning_cases.task and all unit cases"
|
||||||
|
runTest_all
|
||||||
|
elif [ "$TEST_CASE" == "task" ]; then
|
||||||
|
print_color "$GREEN" "Test case is only: parallel_test/longtimeruning_cases.task "
|
||||||
|
runSimCases
|
||||||
|
runPythonCases
|
||||||
|
elif [ -n "$UNIT_TEST_CASE" ]; then
|
||||||
|
UNIT_TEST_CASE="$UNIT_TEST_CASE"
|
||||||
|
cd $TDENGINE_DIR/debug/build/bin/ && $UNIT_TEST_CASE
|
||||||
|
else
|
||||||
|
print_color "$GREEN" "Test case is null"
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
stopTaosd
|
||||||
|
cd $TDENGINE_DIR/tests/script
|
||||||
|
find . -name '*.sql' | xargs rm -f
|
||||||
|
|
||||||
|
cd $TDENGINE_DIR/tests/pytest
|
||||||
|
find . -name '*.sql' | xargs rm -f
|
||||||
|
}
|
||||||
|
|
||||||
|
function lcovFunc {
|
||||||
|
echo "collect data by lcov"
|
||||||
|
cd $TDENGINE_DIR
|
||||||
|
|
||||||
|
if [ -n "$TDENGINE_GCDA_DIR" ]; then
|
||||||
|
TDENGINE_GCDA_DIR="$TDENGINE_GCDA_DIR"
|
||||||
|
print_color "$GREEN" "Test gcda file dir: $TDENGINE_GCDA_DIR "
|
||||||
|
else
|
||||||
|
print_color "$GREEN" "Test gcda file dir is default: /root/TDinternal/community/debug"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# collect data
|
||||||
|
lcov -d "$TDENGINE_GCDA_DIR" -capture --rc lcov_branch_coverage=0 --rc genhtml_branch_coverage=1 --no-external -b $TDENGINE_DIR -o coverage.info
|
||||||
|
|
||||||
|
# remove exclude paths
|
||||||
|
lcov --remove coverage.info \
|
||||||
|
'*/contrib/*' '*/test/*' '*/packaging/*' '*/taos-tools/*' '*/taosadapter/*' '*/TSZ/*' \
|
||||||
|
'*/AccessBridgeCalls.c' '*/ttszip.c' '*/dataInserter.c' '*/tlinearhash.c' '*/tsimplehash.c' '*/tsdbDiskData.c' '/*/enterprise/*' '*/docs/*' '*/sim/*'\
|
||||||
|
'*/texpr.c' '*/runUdf.c' '*/schDbg.c' '*/syncIO.c' '*/tdbOs.c' '*/pushServer.c' '*/osLz4.c'\
|
||||||
|
'*/tbase64.c' '*/tbuffer.c' '*/tdes.c' '*/texception.c' '*/examples/*' '*/tidpool.c' '*/tmempool.c'\
|
||||||
|
'*/clientJniConnector.c' '*/clientTmqConnector.c' '*/version.cc' '*/branch/*'\
|
||||||
|
'*/tthread.c' '*/tversion.c' '*/ctgDbg.c' '*/schDbg.c' '*/qwDbg.c' '*/tencode.h' \
|
||||||
|
'*/shellAuto.c' '*/shellTire.c' '*/shellCommand.c'\
|
||||||
|
'*/sql.c' '*/sql.y' '*/smaSnapshot.c' '*/smaCommit.c' '*/debug/*' '*/tests/*'\
|
||||||
|
--rc lcov_branch_coverage=1 -o coverage.info
|
||||||
|
|
||||||
|
# generate result
|
||||||
|
echo "generate result"
|
||||||
|
lcov -l --rc lcov_branch_coverage=1 coverage.info | tee -a $TDENGINE_COVERAGE_REPORT
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function stopTaosd {
|
||||||
|
print_color "$GREEN" "Stop taosd start"
|
||||||
|
systemctl stop taosd
|
||||||
|
PID=`ps -ef|grep -w taosd | grep -v grep | awk '{print $2}'`
|
||||||
|
while [ -n "$PID" ]
|
||||||
|
do
|
||||||
|
pkill -TERM -x taosd
|
||||||
|
sleep 1
|
||||||
|
PID=`ps -ef|grep -w taosd | grep -v grep | awk '{print $2}'`
|
||||||
|
done
|
||||||
|
print_color "$GREEN" "Stop tasod end"
|
||||||
|
}
|
||||||
|
|
||||||
|
function stopTaosadapter {
|
||||||
|
print_color "$GREEN" "Stop taosadapter"
|
||||||
|
systemctl stop taosadapter.service
|
||||||
|
PID=`ps -ef|grep -w taosadapter | grep -v grep | awk '{print $2}'`
|
||||||
|
while [ -n "$PID" ]
|
||||||
|
do
|
||||||
|
pkill -TERM -x taosadapter
|
||||||
|
sleep 1
|
||||||
|
PID=`ps -ef|grep -w taosd | grep -v grep | awk '{print $2}'`
|
||||||
|
done
|
||||||
|
print_color "$GREEN" "Stop tasoadapter end"
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
WORK_DIR=/root
|
||||||
|
|
||||||
|
date >> $WORK_DIR/date.log
|
||||||
|
print_color "$GREEN" "Run local coverage test cases" | tee -a $WORK_DIR/date.log
|
||||||
|
|
||||||
|
stopTaosd
|
||||||
|
|
||||||
|
runTest
|
||||||
|
|
||||||
|
lcovFunc
|
||||||
|
|
||||||
|
|
||||||
|
date >> $WORK_DIR/date.log
|
||||||
|
print_color "$GREEN" "End of local coverage test cases" | tee -a $WORK_DIR/date.log
|
||||||
|
|
||||||
|
|
||||||
|
# Define coverage information files and output directories
|
||||||
|
COVERAGE_INFO="$TDENGINE_DIR/coverage.info"
|
||||||
|
OUTPUT_DIR="$WORK_DIR/coverage_report"
|
||||||
|
|
||||||
|
# Check whether the coverage information file exists
|
||||||
|
if [ ! -f "$COVERAGE_INFO" ]; then
|
||||||
|
echo "Error: $COVERAGE_INFO not found!"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Generate local HTML reports
|
||||||
|
genhtml "$COVERAGE_INFO" --branch-coverage --function-coverage --output-directory "$OUTPUT_DIR"
|
||||||
|
|
||||||
|
# Check whether the report was generated successfully
|
||||||
|
if [ $? -eq 0 ]; then
|
||||||
|
echo "HTML coverage report generated successfully in $OUTPUT_DIR"
|
||||||
|
echo "For more details : "
|
||||||
|
echo "http://192.168.1.61:7000/"
|
||||||
|
else
|
||||||
|
echo "Error generating HTML coverage report"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
|
@ -1,14 +1,29 @@
|
||||||
aux_source_directory(src TSIM_SRC)
|
LIST(APPEND TSIM_SRC src/simEntry.c)
|
||||||
add_executable(tsim ${TSIM_SRC})
|
LIST(APPEND TSIM_SRC src/simExec.c)
|
||||||
target_link_libraries(
|
LIST(APPEND TSIM_SRC src/simParse.c)
|
||||||
tsim
|
LIST(APPEND TSIM_SRC src/simSystem.c)
|
||||||
|
|
||||||
|
ADD_LIBRARY(tsim_static STATIC ${TSIM_SRC})
|
||||||
|
TARGET_INCLUDE_DIRECTORIES(
|
||||||
|
tsim_static
|
||||||
|
PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/inc"
|
||||||
|
)
|
||||||
|
TARGET_LINK_LIBRARIES(
|
||||||
|
tsim_static
|
||||||
PUBLIC ${TAOS_LIB}
|
PUBLIC ${TAOS_LIB}
|
||||||
PUBLIC util
|
PUBLIC util
|
||||||
PUBLIC common
|
PUBLIC common
|
||||||
PUBLIC os
|
PUBLIC os
|
||||||
PUBLIC cjson
|
PUBLIC cjson
|
||||||
)
|
)
|
||||||
target_include_directories(
|
|
||||||
|
LIST(APPEND TSIM_EXE_SRC src/simMain.c)
|
||||||
|
ADD_EXECUTABLE(tsim ${TSIM_EXE_SRC})
|
||||||
|
TARGET_LINK_LIBRARIES(
|
||||||
tsim
|
tsim
|
||||||
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc"
|
PUBLIC tsim_static
|
||||||
)
|
)
|
||||||
|
|
||||||
|
IF(${BUILD_TEST})
|
||||||
|
ADD_SUBDIRECTORY(test)
|
||||||
|
ENDIF(${BUILD_TEST})
|
||||||
|
|
|
@ -16,6 +16,10 @@
|
||||||
#ifndef _TD_SIM_INT_H_
|
#ifndef _TD_SIM_INT_H_
|
||||||
#define _TD_SIM_INT_H_
|
#define _TD_SIM_INT_H_
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
|
|
||||||
#include "cJSON.h"
|
#include "cJSON.h"
|
||||||
|
@ -161,8 +165,8 @@ typedef struct _script_t {
|
||||||
int32_t type;
|
int32_t type;
|
||||||
bool killed;
|
bool killed;
|
||||||
void *taos;
|
void *taos;
|
||||||
char rows[12]; // number of rows data retrieved
|
char rows[12]; // number of rows data retrieved
|
||||||
char cols[12]; // number of columns data retrieved
|
char cols[12]; // number of columns data retrieved
|
||||||
char data[MAX_QUERY_ROW_NUM][MAX_QUERY_COL_NUM][MAX_QUERY_VALUE_LEN]; // query results
|
char data[MAX_QUERY_ROW_NUM][MAX_QUERY_COL_NUM][MAX_QUERY_VALUE_LEN]; // query results
|
||||||
char system_exit_code[12];
|
char system_exit_code[12];
|
||||||
char system_ret_content[MAX_SYSTEM_RESULT_LEN];
|
char system_ret_content[MAX_SYSTEM_RESULT_LEN];
|
||||||
|
@ -192,7 +196,7 @@ SScript *simParseScript(char *fileName);
|
||||||
SScript *simProcessCallOver(SScript *script);
|
SScript *simProcessCallOver(SScript *script);
|
||||||
void *simExecuteScript(void *script);
|
void *simExecuteScript(void *script);
|
||||||
void simInitsimCmdList();
|
void simInitsimCmdList();
|
||||||
bool simSystemInit();
|
void simSystemInit();
|
||||||
void simSystemCleanUp();
|
void simSystemCleanUp();
|
||||||
char *simGetVariable(SScript *script, char *varName, int32_t varLen);
|
char *simGetVariable(SScript *script, char *varName, int32_t varLen);
|
||||||
bool simExecuteExpCmd(SScript *script, char *option);
|
bool simExecuteExpCmd(SScript *script, char *option);
|
||||||
|
@ -214,4 +218,11 @@ bool simExecuteLineInsertErrorCmd(SScript *script, char *option);
|
||||||
bool simExecuteSetBIModeCmd(SScript *script, char *option);
|
bool simExecuteSetBIModeCmd(SScript *script, char *option);
|
||||||
void simVisuallizeOption(SScript *script, char *src, char *dst);
|
void simVisuallizeOption(SScript *script, char *src, char *dst);
|
||||||
|
|
||||||
|
int32_t simEntry(int32_t argc, char **argv);
|
||||||
|
void simHandleSignal(int32_t signo, void *sigInfo, void *context);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /*_TD_SIM_INT_H_*/
|
#endif /*_TD_SIM_INT_H_*/
|
||||||
|
|
|
@ -0,0 +1,64 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||||
|
*
|
||||||
|
* This program is free software: you can use, redistribute, and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License, version 3
|
||||||
|
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define _DEFAULT_SOURCE
|
||||||
|
#include "simInt.h"
|
||||||
|
|
||||||
|
bool simExecSuccess = false;
|
||||||
|
bool abortExecution = false;
|
||||||
|
bool useValgrind = false;
|
||||||
|
|
||||||
|
void simHandleSignal(int32_t signo, void *sigInfo, void *context) {
|
||||||
|
simSystemCleanUp();
|
||||||
|
abortExecution = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t simEntry(int32_t argc, char **argv) {
|
||||||
|
char scriptFile[MAX_FILE_NAME_LEN] = "sim_main_test.sim";
|
||||||
|
|
||||||
|
for (int32_t i = 1; i < argc; ++i) {
|
||||||
|
if (strcmp(argv[i], "-c") == 0 && i < argc - 1) {
|
||||||
|
tstrncpy(configDir, argv[++i], 128);
|
||||||
|
} else if (strcmp(argv[i], "-f") == 0 && i < argc - 1) {
|
||||||
|
tstrncpy(scriptFile, argv[++i], MAX_FILE_NAME_LEN);
|
||||||
|
} else if (strcmp(argv[i], "-v") == 0) {
|
||||||
|
useValgrind = true;
|
||||||
|
} else {
|
||||||
|
printf("usage: %s [options] \n", argv[0]);
|
||||||
|
printf(" [-c config]: config directory, default is: %s\n", configDir);
|
||||||
|
printf(" [-f script]: script filename\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
simInfo("simulator is running ...");
|
||||||
|
|
||||||
|
simSystemInit();
|
||||||
|
taosSetSignal(SIGINT, simHandleSignal);
|
||||||
|
|
||||||
|
SScript *script = simParseScript(scriptFile);
|
||||||
|
if (script == NULL) {
|
||||||
|
simError("parse script file:%s failed", scriptFile);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
simScriptList[++simScriptPos] = script;
|
||||||
|
simExecuteScript(script);
|
||||||
|
|
||||||
|
int32_t ret = simExecSuccess ? 0 : -1;
|
||||||
|
simInfo("execute result %d", ret);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
|
@ -382,8 +382,8 @@ bool simExecuteRunBackCmd(SScript *script, char *option) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void simReplaceDirSep(char *buf) {
|
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
|
void simReplaceDirSep(char *buf) {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while (buf[i] != '\0') {
|
while (buf[i] != '\0') {
|
||||||
if (buf[i] == '/') {
|
if (buf[i] == '/') {
|
||||||
|
@ -391,8 +391,8 @@ void simReplaceDirSep(char *buf) {
|
||||||
}
|
}
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
bool simReplaceStr(char *buf, char *src, char *dst) {
|
bool simReplaceStr(char *buf, char *src, char *dst) {
|
||||||
bool replaced = false;
|
bool replaced = false;
|
|
@ -16,58 +16,7 @@
|
||||||
#define _DEFAULT_SOURCE
|
#define _DEFAULT_SOURCE
|
||||||
#include "simInt.h"
|
#include "simInt.h"
|
||||||
|
|
||||||
bool simExecSuccess = false;
|
|
||||||
bool abortExecution = false;
|
|
||||||
bool useValgrind = false;
|
|
||||||
|
|
||||||
void simHandleSignal(int32_t signo, void *sigInfo, void *context) {
|
|
||||||
simSystemCleanUp();
|
|
||||||
abortExecution = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t main(int32_t argc, char *argv[]) {
|
int32_t main(int32_t argc, char *argv[]) {
|
||||||
char scriptFile[MAX_FILE_NAME_LEN] = "sim_main_test.sim";
|
// entry function used for unit testing.
|
||||||
|
return simEntry(argc, argv);
|
||||||
for (int32_t i = 1; i < argc; ++i) {
|
|
||||||
if (strcmp(argv[i], "-c") == 0 && i < argc - 1) {
|
|
||||||
tstrncpy(configDir, argv[++i], 128);
|
|
||||||
} else if (strcmp(argv[i], "-f") == 0 && i < argc - 1) {
|
|
||||||
tstrncpy(scriptFile, argv[++i], MAX_FILE_NAME_LEN);
|
|
||||||
} else if (strcmp(argv[i], "-v") == 0) {
|
|
||||||
useValgrind = true;
|
|
||||||
} else {
|
|
||||||
printf("usage: %s [options] \n", argv[0]);
|
|
||||||
printf(" [-c config]: config directory, default is: %s\n", configDir);
|
|
||||||
printf(" [-f script]: script filename\n");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!simSystemInit()) {
|
|
||||||
simError("failed to initialize the system");
|
|
||||||
simSystemCleanUp();
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
simInfo("simulator is running ...");
|
|
||||||
taosSetSignal(SIGINT, simHandleSignal);
|
|
||||||
|
|
||||||
SScript *script = simParseScript(scriptFile);
|
|
||||||
if (script == NULL) {
|
|
||||||
simError("parse script file:%s failed", scriptFile);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (abortExecution) {
|
|
||||||
simError("execute abort");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
simScriptList[++simScriptPos] = script;
|
|
||||||
simExecuteScript(script);
|
|
||||||
|
|
||||||
int32_t ret = simExecSuccess ? 0 : -1;
|
|
||||||
simInfo("execute result %d", ret);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,11 +35,10 @@ int32_t simInitCfg() {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool simSystemInit() {
|
void simSystemInit() {
|
||||||
simInitCfg();
|
simInitCfg();
|
||||||
simInitsimCmdList();
|
simInitsimCmdList();
|
||||||
memset(simScriptList, 0, sizeof(SScript *) * MAX_MAIN_SCRIPT_NUM);
|
memset(simScriptList, 0, sizeof(SScript *) * MAX_MAIN_SCRIPT_NUM);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void simSystemCleanUp() {}
|
void simSystemCleanUp() {}
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
CMAKE_MINIMUM_REQUIRED(VERSION 2.8...3.20)
|
||||||
|
PROJECT(TDengine)
|
||||||
|
|
||||||
|
FIND_PATH(HEADER_GTEST_INCLUDE_DIR gtest.h /usr/include/gtest /usr/local/include/gtest)
|
||||||
|
FIND_LIBRARY(LIB_GTEST_STATIC_DIR libgtest.a /usr/lib/ /usr/local/lib /usr/lib64)
|
||||||
|
FIND_LIBRARY(LIB_GTEST_SHARED_DIR libgtest.so /usr/lib/ /usr/local/lib /usr/lib64)
|
||||||
|
|
||||||
|
IF(HEADER_GTEST_INCLUDE_DIR AND(LIB_GTEST_STATIC_DIR OR LIB_GTEST_SHARED_DIR))
|
||||||
|
MESSAGE(STATUS "gTest library found, build os test")
|
||||||
|
|
||||||
|
INCLUDE_DIRECTORIES(${HEADER_GTEST_INCLUDE_DIR})
|
||||||
|
AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} SOURCE_LIST)
|
||||||
|
ENDIF()
|
||||||
|
|
||||||
|
INCLUDE_DIRECTORIES(${TD_SOURCE_DIR}/src/util/inc)
|
||||||
|
|
||||||
|
ADD_EXECUTABLE(simTests "simTests.cpp")
|
||||||
|
TARGET_LINK_LIBRARIES(simTests os util tsim_static gtest_main)
|
||||||
|
|
||||||
|
ADD_TEST(
|
||||||
|
NAME simTests
|
||||||
|
COMMAND simTests
|
||||||
|
)
|
|
@ -0,0 +1,61 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||||
|
*
|
||||||
|
* This program is free software: you can use, redistribute, and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License, version 3
|
||||||
|
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <gtest/gtest.h>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#pragma GCC diagnostic push
|
||||||
|
#pragma GCC diagnostic ignored "-Wwrite-strings"
|
||||||
|
#pragma GCC diagnostic ignored "-Wunused-function"
|
||||||
|
#pragma GCC diagnostic ignored "-Wunused-variable"
|
||||||
|
#pragma GCC diagnostic ignored "-Wsign-compare"
|
||||||
|
#pragma GCC diagnostic ignored "-Wsign-compare"
|
||||||
|
#pragma GCC diagnostic ignored "-Wformat"
|
||||||
|
#pragma GCC diagnostic ignored "-Wint-to-pointer-cast"
|
||||||
|
#pragma GCC diagnostic ignored "-Wpointer-arith"
|
||||||
|
|
||||||
|
#include "simInt.h"
|
||||||
|
|
||||||
|
void simHandleSignal(int32_t signo, void *sigInfo, void *context);
|
||||||
|
|
||||||
|
TEST(simTests, parameters) {
|
||||||
|
int32_t ret = 0;
|
||||||
|
int32_t argc = 2;
|
||||||
|
char *argv[4] = {0};
|
||||||
|
|
||||||
|
simSystemCleanUp();
|
||||||
|
// argv[1] = "-c";
|
||||||
|
// ret = simEntry(argc, argv);
|
||||||
|
// EXPECT_EQ(ret, 0);
|
||||||
|
|
||||||
|
// argv[1] = "-f";
|
||||||
|
// ret = simEntry(argc, argv);
|
||||||
|
// EXPECT_EQ(ret, 0);
|
||||||
|
|
||||||
|
// argv[1] = "-v";
|
||||||
|
// ret = simEntry(argc, argv);
|
||||||
|
// EXPECT_EQ(ret, 0);
|
||||||
|
|
||||||
|
// argv[1] = "-h";
|
||||||
|
// ret = simEntry(argc, argv);
|
||||||
|
// EXPECT_EQ(ret, 0);
|
||||||
|
|
||||||
|
// simHandleSignal(0, NULL, NULL);
|
||||||
|
|
||||||
|
// simDebugFlag = 0;
|
||||||
|
// argc = 1;
|
||||||
|
// ret = simEntry(argc, argv);
|
||||||
|
// EXPECT_EQ(ret, -1);
|
||||||
|
}
|
Loading…
Reference in New Issue