Merge branch '3.0' of https://github.com/taosdata/TDengine into enh/TS-5445-3.0

This commit is contained in:
Hongze Cheng 2025-02-26 15:09:54 +08:00
commit df96529e0d
13 changed files with 1123 additions and 543 deletions

View File

@ -47,8 +47,10 @@ int32_t taosGetProcMemory(int64_t *usedKB);
int32_t taosGetSysMemory(int64_t *usedKB);
int32_t taosGetSysAvailMemory(int64_t *availSize);
int32_t taosGetDiskSize(char *dataDir, SDiskSize *diskSize);
int32_t taosGetProcIO(int64_t *rchars, int64_t *wchars, int64_t *read_bytes, int64_t *write_bytes);
int32_t taosGetProcIODelta(int64_t *rchars, int64_t *wchars, int64_t *read_bytes, int64_t *write_bytes);
void taosSetDefaultProcIODelta(int64_t *rchars, int64_t *wchars, int64_t *read_bytes, int64_t *write_bytes);
int32_t taosGetCardInfo(int64_t *receive_bytes, int64_t *transmit_bytes);
int32_t taosGetCardInfoDelta(int64_t *receive_bytes, int64_t *transmit_bytes);
void taosSetDefaultCardInfoDelta(int64_t *receive_bytes, int64_t *transmit_bytes);

View File

@ -751,7 +751,7 @@ static int32_t smlFindNearestPowerOf2(int32_t length, uint8_t type) {
}
static int32_t smlProcessSchemaAction(SSmlHandle *info, SSchema *schemaField, SHashObj *schemaHash, SArray *cols,
SArray *checkDumplicateCols, ESchemaAction *action, bool isTag) {
SHashObj *schemaHashCheck, ESchemaAction *action, bool isTag) {
int32_t code = TSDB_CODE_SUCCESS;
int32_t lino = 0;
for (int j = 0; j < taosArrayGetSize(cols); ++j) {
@ -759,15 +759,11 @@ static int32_t smlProcessSchemaAction(SSmlHandle *info, SSchema *schemaField, SH
SSmlKv *kv = (SSmlKv *)taosArrayGet(cols, j);
SML_CHECK_NULL(kv);
SML_CHECK_CODE(smlGenerateSchemaAction(schemaField, schemaHash, kv, isTag, action, info));
}
for (int j = 0; j < taosArrayGetSize(checkDumplicateCols); ++j) {
SSmlKv *kv = (SSmlKv *)taosArrayGet(checkDumplicateCols, j);
SML_CHECK_NULL(kv);
if (taosHashGet(schemaHash, kv->key, kv->keyLen) != NULL) {
if (taosHashGet(schemaHashCheck, kv->key, kv->keyLen) != NULL) {
SML_CHECK_CODE(TSDB_CODE_PAR_DUPLICATED_COLUMN);
}
}
END:
RETURN
}
@ -998,14 +994,14 @@ static int32_t smlBuildFields(SArray **pColumns, SArray **pTags, STableMeta *pTa
END:
RETURN
}
static int32_t smlModifyTag(SSmlHandle *info, SHashObj* hashTmp, SRequestConnInfo *conn,
static int32_t smlModifyTag(SSmlHandle *info, SHashObj* hashTmpCheck, SHashObj* hashTmp, SRequestConnInfo *conn,
SSmlSTableMeta *sTableData, SName *pName, STableMeta **pTableMeta){
ESchemaAction action = SCHEMA_ACTION_NULL;
SArray *pColumns = NULL;
SArray *pTags = NULL;
int32_t code = 0;
int32_t lino = 0;
SML_CHECK_CODE(smlProcessSchemaAction(info, (*pTableMeta)->schema, hashTmp, sTableData->tags, sTableData->cols, &action, true));
SML_CHECK_CODE(smlProcessSchemaAction(info, (*pTableMeta)->schema, hashTmp, sTableData->tags, hashTmpCheck, &action, true));
if (action != SCHEMA_ACTION_NULL) {
SML_CHECK_CODE(smlCheckAuth(info, conn, pName->tname, AUTH_TYPE_WRITE));
@ -1029,14 +1025,14 @@ END:
RETURN
}
static int32_t smlModifyCols(SSmlHandle *info, SHashObj* hashTmp, SRequestConnInfo *conn,
static int32_t smlModifyCols(SSmlHandle *info, SHashObj* hashTmpCheck, SHashObj* hashTmp, SRequestConnInfo *conn,
SSmlSTableMeta *sTableData, SName *pName, STableMeta **pTableMeta){
ESchemaAction action = SCHEMA_ACTION_NULL;
SArray *pColumns = NULL;
SArray *pTags = NULL;
int32_t code = 0;
int32_t lino = 0;
SML_CHECK_CODE(smlProcessSchemaAction(info, (*pTableMeta)->schema, hashTmp, sTableData->cols, sTableData->tags, &action, false));
SML_CHECK_CODE(smlProcessSchemaAction(info, (*pTableMeta)->schema, hashTmp, sTableData->cols, hashTmpCheck, &action, false));
if (action != SCHEMA_ACTION_NULL) {
SML_CHECK_CODE(smlCheckAuth(info, conn, pName->tname, AUTH_TYPE_WRITE));
@ -1079,7 +1075,8 @@ static int32_t smlModifyDBSchemas(SSmlHandle *info) {
}
int32_t code = 0;
int32_t lino = 0;
SHashObj *hashTmp = NULL;
SHashObj *colHashTmp = NULL;
SHashObj *tagHashTmp = NULL;
STableMeta *pTableMeta = NULL;
SName pName = {TSDB_TABLE_NAME_T, info->taos->acctId, {0}, {0}};
@ -1119,17 +1116,21 @@ static int32_t smlModifyDBSchemas(SSmlHandle *info) {
SML_CHECK_CODE(TSDB_CODE_SML_NOT_SUPPORT_PK);
}
hashTmp = taosHashInit(pTableMeta->tableInfo.numOfTags, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
SML_CHECK_NULL(hashTmp);
SML_CHECK_CODE(smlBuildTempHash(hashTmp, pTableMeta, pTableMeta->tableInfo.numOfColumns, pTableMeta->tableInfo.numOfColumns + pTableMeta->tableInfo.numOfTags));
SML_CHECK_CODE(smlModifyTag(info, hashTmp, &conn, sTableData, &pName, &pTableMeta));
taosHashClear(hashTmp);
SML_CHECK_CODE(smlBuildTempHash(hashTmp, pTableMeta, 0, pTableMeta->tableInfo.numOfColumns));
SML_CHECK_CODE(smlModifyCols(info, hashTmp, &conn, sTableData, &pName, &pTableMeta));
colHashTmp = taosHashInit(pTableMeta->tableInfo.numOfColumns, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
tagHashTmp = taosHashInit(pTableMeta->tableInfo.numOfTags, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
SML_CHECK_NULL(colHashTmp);
SML_CHECK_NULL(tagHashTmp);
SML_CHECK_CODE(smlBuildTempHash(tagHashTmp, pTableMeta, pTableMeta->tableInfo.numOfColumns, pTableMeta->tableInfo.numOfColumns + pTableMeta->tableInfo.numOfTags));
SML_CHECK_CODE(smlBuildTempHash(colHashTmp, pTableMeta, 0, pTableMeta->tableInfo.numOfColumns));
SML_CHECK_CODE(smlModifyTag(info, colHashTmp, tagHashTmp, &conn, sTableData, &pName, &pTableMeta));
SML_CHECK_CODE(smlModifyCols(info, tagHashTmp, colHashTmp, &conn, sTableData, &pName, &pTableMeta));
needCheckMeta = true;
taosHashCleanup(hashTmp);
hashTmp = NULL;
taosHashCleanup(colHashTmp);
taosHashCleanup(tagHashTmp);
colHashTmp = NULL;
tagHashTmp = NULL;
} else {
uError("SML:0x%" PRIx64 " %s load table meta error: %s", info->id, __FUNCTION__, tstrerror(code));
goto END;
@ -1153,7 +1154,8 @@ static int32_t smlModifyDBSchemas(SSmlHandle *info) {
END:
taosHashCancelIterate(info->superTables, tmp);
taosHashCleanup(hashTmp);
taosHashCleanup(colHashTmp);
taosHashCleanup(tagHashTmp);
taosMemoryFreeClear(pTableMeta);
(void)catalogRefreshTableMeta(info->pCatalog, &conn, &pName, 1); // ignore refresh meta code if there is an error
uError("SML:0x%" PRIx64 " %s end failed:%d:%s, format:%d, needModifySchema:%d", info->id, __FUNCTION__, code,
@ -1924,3 +1926,4 @@ TAOS_RES *taos_schemaless_insert_raw(TAOS *taos, char *lines, int len, int32_t *
return taos_schemaless_insert_raw_ttl_with_reqid(taos, lines, len, totalRows, protocol, precision,
TSDB_DEFAULT_TABLE_TTL, 0);
}

View File

@ -1259,6 +1259,7 @@ static int32_t mndProcessCreateStbReq(SRpcMsg *pReq) {
SDbObj *pDb = NULL;
SMCreateStbReq createReq = {0};
bool isAlter = false;
SHashObj *pHash = NULL;
if (tDeserializeSMCreateStbReq(pReq->pCont, pReq->contLen, &createReq) != 0) {
code = TSDB_CODE_INVALID_MSG;
@ -1319,6 +1320,33 @@ static int32_t mndProcessCreateStbReq(SRpcMsg *pReq) {
goto _OVER;
}
pHash = taosHashInit(createReq.numOfColumns + createReq.numOfTags, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY),
false, HASH_NO_LOCK);
if (pHash == NULL) {
code = TSDB_CODE_OUT_OF_MEMORY;
goto _OVER;
}
for (int32_t i = 0; i < createReq.numOfColumns; ++i) {
SFieldWithOptions *pField = taosArrayGet(createReq.pColumns, i);
if ((code = taosHashPut(pHash, pField->name, strlen(pField->name), NULL, 0)) != 0) {
if (code == TSDB_CODE_DUP_KEY) {
code = TSDB_CODE_TSC_DUP_COL_NAMES;
}
goto _OVER;
}
}
for (int32_t i = 0; i < createReq.numOfTags; ++i) {
SField *pField = taosArrayGet(createReq.pTags, i);
if ((code = taosHashPut(pHash, pField->name, strlen(pField->name), NULL, 0)) != 0) {
if (code == TSDB_CODE_DUP_KEY) {
code = TSDB_CODE_TSC_DUP_COL_NAMES;
}
goto _OVER;
}
}
pDb = mndAcquireDbByStb(pMnode, createReq.name);
if (pDb == NULL) {
code = TSDB_CODE_MND_DB_NOT_SELECTED;
@ -1383,6 +1411,10 @@ _OVER:
mndReleaseDb(pMnode, pDb);
tFreeSMCreateStbReq(&createReq);
if (pHash != NULL) {
taosHashCleanup(pHash);
}
TAOS_RETURN(code);
}

View File

@ -25,6 +25,7 @@ class MndTestStb : public ::testing::Test {
void* BuildCreateDbReq(const char* dbname, int32_t* pContLen);
void* BuildDropDbReq(const char* dbname, int32_t* pContLen);
void* BuildCreateStbReq(const char* stbname, int32_t* pContLen);
void* BuildCreateStbDuplicateReq(const char* stbname, int32_t* pContLen);
void* BuildAlterStbAddTagReq(const char* stbname, const char* tagname, int32_t* pContLen);
void* BuildAlterStbDropTagReq(const char* stbname, const char* tagname, int32_t* pContLen);
void* BuildAlterStbUpdateTagNameReq(const char* stbname, const char* tagname, const char* newtagname,
@ -137,6 +138,71 @@ void* MndTestStb::BuildCreateStbReq(const char* stbname, int32_t* pContLen) {
return pHead;
}
void* MndTestStb::BuildCreateStbDuplicateReq(const char* stbname, int32_t* pContLen) {
SMCreateStbReq createReq = {0};
createReq.numOfColumns = 2;
createReq.numOfTags = 4;
createReq.igExists = 0;
createReq.pColumns = taosArrayInit(createReq.numOfColumns, sizeof(SField));
createReq.pTags = taosArrayInit(createReq.numOfTags, sizeof(SField));
strcpy(createReq.name, stbname);
{
SField field = {0};
field.bytes = 8;
field.type = TSDB_DATA_TYPE_TIMESTAMP;
strcpy(field.name, "ts");
taosArrayPush(createReq.pColumns, &field);
}
{
SField field = {0};
field.bytes = 12;
field.type = TSDB_DATA_TYPE_BINARY;
strcpy(field.name, "col1");
taosArrayPush(createReq.pColumns, &field);
}
{
SField field = {0};
field.bytes = 2;
field.type = TSDB_DATA_TYPE_TINYINT;
strcpy(field.name, "tag1");
taosArrayPush(createReq.pTags, &field);
}
{
SField field = {0};
field.bytes = 8;
field.type = TSDB_DATA_TYPE_BIGINT;
strcpy(field.name, "tag2");
taosArrayPush(createReq.pTags, &field);
}
{
SField field = {0};
field.bytes = 16;
field.type = TSDB_DATA_TYPE_BINARY;
strcpy(field.name, "tag3");
taosArrayPush(createReq.pTags, &field);
}
{
SField field = {0};
field.bytes = 16;
field.type = TSDB_DATA_TYPE_BINARY;
strcpy(field.name, "tag3");
taosArrayPush(createReq.pTags, &field);
}
int32_t tlen = tSerializeSMCreateStbReq(NULL, 0, &createReq);
void* pHead = rpcMallocCont(tlen);
tSerializeSMCreateStbReq(pHead, tlen, &createReq);
tFreeSMCreateStbReq(&createReq);
*pContLen = tlen;
return pHead;
}
void* MndTestStb::BuildAlterStbAddTagReq(const char* stbname, const char* tagname, int32_t* pContLen) {
SMAlterStbReq req = {0};
strcpy(req.name, stbname);
@ -896,3 +962,26 @@ TEST_F(MndTestStb, 08_Alter_Stb_AlterTagBytes) {
rpcFreeCont(pRsp->pCont);
}
}
TEST_F(MndTestStb, 09_Create_Duplicate_Stb) {
const char* dbname = "1.d2";
const char* stbname = "1.d2.stb";
{
int32_t contLen = 0;
void* pReq = BuildCreateDbReq(dbname, &contLen);
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DB, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pRsp->code, 0);
rpcFreeCont(pRsp->pCont);
}
{
int32_t contLen = 0;
void* pReq = BuildCreateStbDuplicateReq(stbname, &contLen);
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_STB, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pRsp->code, TSDB_CODE_TSC_DUP_COL_NAMES);
rpcFreeCont(pRsp->pCont);
}
}

View File

@ -87,7 +87,7 @@ void taosRandStr(char* str, int32_t size) {
void taosRandStr2(char* str, int32_t size) {
const char* set = "abcdefghijklmnopqrstuvwxyz0123456789@";
int32_t len = strlen(set);
int32_t len = 37;
for (int32_t i = 0; i < size; ++i) {
str[i] = set[taosRand() % len];

View File

@ -114,6 +114,7 @@ int32_t taosDflSignal(int32_t signum) {
return 0;
}
#if 0
int32_t taosKillChildOnParentStopped() {
#ifndef _TD_DARWIN_64
int32_t code = prctl(PR_SET_PDEATHSIG, SIGKILL);
@ -126,5 +127,6 @@ int32_t taosKillChildOnParentStopped() {
#endif
return 0;
}
#endif
#endif

View File

@ -294,6 +294,7 @@ int32_t tasoUcs4Compare(TdUcs4 *f1_ucs4, TdUcs4 *f2_ucs4, int32_t bytes) {
//#endif
}
#if 0
int32_t tasoUcs4Copy(TdUcs4 *target_ucs4, TdUcs4 *source_ucs4, int32_t len_ucs4) {
if (target_ucs4 == NULL || source_ucs4 == NULL || len_ucs4 <= 0) {
return TSDB_CODE_INVALID_PARA;
@ -307,11 +308,12 @@ int32_t tasoUcs4Copy(TdUcs4 *target_ucs4, TdUcs4 *source_ucs4, int32_t len_ucs4)
return TSDB_CODE_SUCCESS;
}
#endif
iconv_t taosAcquireConv(int32_t *idx, ConvType type, void* charsetCxt) {
if(idx == NULL) {
terrno = TSDB_CODE_INVALID_PARA;
return (iconv_t)-1;
return (iconv_t)NULL;
}
if (charsetCxt == NULL){
charsetCxt = tsCharsetCxt;

View File

@ -147,7 +147,6 @@ static void taosGetProcIOnfos() {
#endif
static int32_t taosGetSysCpuInfo(SysCpuInfo *cpuInfo) {
OS_PARAM_CHECK(cpuInfo);
int32_t code = 0;
#ifdef WINDOWS
FILETIME pre_idleTime = {0};
@ -200,7 +199,6 @@ static int32_t taosGetSysCpuInfo(SysCpuInfo *cpuInfo) {
}
static int32_t taosGetProcCpuInfo(ProcCpuInfo *cpuInfo) {
OS_PARAM_CHECK(cpuInfo);
int32_t code = 0;
#ifdef WINDOWS
@ -541,7 +539,6 @@ int32_t taosGetCpuInfo(char *cpuModel, int32_t maxLen, float *numOfCores) {
// Returns the container's CPU quota if successful, otherwise returns the physical CPU cores
static int32_t taosCntrGetCpuCores(float *numOfCores) {
OS_PARAM_CHECK(numOfCores);
#ifdef WINDOWS
return TSDB_CODE_UNSUPPORT_OS;
#elif defined(_TD_DARWIN_64)
@ -1092,6 +1089,7 @@ void taosSetDefaultCardInfoDelta(int64_t *receive_bytes, int64_t *transmit_bytes
if (transmit_bytes) *transmit_bytes = 0;
}
#if 0
void taosKillSystem() {
#ifdef WINDOWS
printf("function taosKillSystem, exit!");
@ -1105,6 +1103,7 @@ void taosKillSystem() {
(void)kill(tsProcId, 2);
#endif
}
#endif
#define UUIDLEN (36)
int32_t taosGetSystemUUIDLimit36(char *uid, int32_t uidlen) {

View File

@ -15,36 +15,47 @@ ENDIF()
INCLUDE_DIRECTORIES(${TD_SOURCE_DIR}/src/util/inc)
if(TD_LINUX)
add_executable(osAtomicTests "osAtomicTests.cpp")
target_link_libraries(osAtomicTests os util gtest_main)
add_test(
NAME osAtomicTests
COMMAND osAtomicTests
)
endif()
add_executable(osAtomicTests "osAtomicTests.cpp")
target_link_libraries(osAtomicTests os util gtest_main)
add_test(
NAME osAtomicTests
COMMAND osAtomicTests
)
if(TD_LINUX)
add_executable(osDirTests "osDirTests.cpp")
target_link_libraries(osDirTests os util gtest_main)
add_test(
NAME osDirTests
COMMAND osDirTests
)
add_executable(osFileTests "osFileTests.cpp")
target_link_libraries(osFileTests os util gtest_main)
add_test(
NAME osFileTests
COMMAND osFileTests
)
endif()
add_executable(osDirTests "osDirTests.cpp")
target_link_libraries(osDirTests os util gtest_main)
add_test(
NAME osDirTests
COMMAND osDirTests
)
if(TD_LINUX)
add_executable(osEnvTests "osEnvTests.cpp")
target_link_libraries(osEnvTests os util gtest_main)
add_test(
NAME osEnvTests
COMMAND osEnvTests
)
add_executable(osFileTests "osFileTests.cpp")
target_link_libraries(osFileTests os util gtest_main)
add_test(
NAME osFileTests
COMMAND osFileTests
)
add_executable(osEnvTests "osEnvTests.cpp")
target_link_libraries(osEnvTests os util gtest_main)
add_test(
NAME osEnvTests
COMMAND osEnvTests
)
add_executable(osTests "osTests.cpp")
target_link_libraries(osTests os util gtest_main)
add_test(
NAME osTests
COMMAND osTests
)
add_executable(osThreadTests "osThreadTests.cpp")
target_link_libraries(osThreadTests os util gtest_main)
add_test(
NAME osThreadTests
COMMAND osThreadTests
)
endif()
add_executable(osMathTests "osMathTests.cpp")
@ -61,13 +72,6 @@ add_test(
COMMAND osSemaphoreTests
)
add_executable(osSignalTests "osSignalTests.cpp")
target_link_libraries(osSignalTests os util gtest_main)
add_test(
NAME osSignalTests
COMMAND osSignalTests
)
add_executable(osSleepTests "osSleepTests.cpp")
target_link_libraries(osSleepTests os util gtest_main)
add_test(
@ -82,13 +86,6 @@ add_test(
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(
@ -96,19 +93,9 @@ add_test(
COMMAND osSystemTests
)
if(TD_LINUX)
add_executable(osThreadTests "osThreadTests.cpp")
target_link_libraries(osThreadTests os util gtest_main)
add_test(
NAME osThreadTests
COMMAND osThreadTests
)
endif()
add_executable(osTimeTests "osTimeTests.cpp")
target_link_libraries(osTimeTests os util gtest_main)
add_test(
NAME osTimeTests
COMMAND osTimeTests
)

View File

@ -1,40 +0,0 @@
/*
* 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 "os.h"
#include "tlog.h"
TEST(osSignalTests, taosSetSignal) {
// Set up SIGINT handler using taosSetSignal
//taosSetSignal(SIGINT, sigint_handler);
// Print PID for testing purposes
// printf("PID: %d\n", getpid());
// Wait for signal to be received
}

File diff suppressed because it is too large Load Diff

View File

@ -14,8 +14,8 @@
*/
#include <gtest/gtest.h>
#include <iostream>
#include <inttypes.h>
#include <iostream>
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wwrite-strings"
@ -36,6 +36,230 @@
#include <arpa/inet.h>
TEST(osTest, locale) {
char *ret = taosCharsetReplace(NULL);
EXPECT_EQ(ret, nullptr);
ret = taosCharsetReplace("utf8");
EXPECT_NE(ret, nullptr);
ret = taosCharsetReplace("utf-8");
EXPECT_NE(ret, nullptr);
taosGetSystemLocale(NULL, "");
taosGetSystemLocale("", NULL);
}
TEST(osTest, memory) {
int32_t ret = taosMemoryDbgInitRestore();
EXPECT_EQ(ret, 0);
int64_t ret64 = taosMemSize(NULL);
EXPECT_EQ(ret64, 0);
}
TEST(osTest, rand2) {
char str[128] = {0};
taosRandStr2(str, 100);
}
TEST(osTest, socket2) {
int32_t ret32 = taosCloseSocket(NULL);
EXPECT_NE(ret32, 0);
ret32 = taosSetSockOpt(NULL, 0, 0, NULL, 0);
EXPECT_NE(ret32, 0);
#if defined(LINUX)
struct in_addr ipInt;
ipInt.s_addr = htonl(0x7F000001);
char buf[128] = {0};
taosInetNtop(ipInt, buf, 32);
#endif
ret32 = taosGetIpv4FromFqdn("localhost", NULL);
EXPECT_NE(ret32, 0);
uint32_t ip = 0;
ret32 = taosGetIpv4FromFqdn(NULL, &ip);
EXPECT_NE(ret32, 0);
taosInetNtoa(NULL, ip);
ret32 = taosInetAddr(NULL);
EXPECT_EQ(ret32, 0);
ret32 = taosWinSocketInit();
EXPECT_EQ(ret32, 0);
}
TEST(osTest, time2) {
taosGetLocalTimezoneOffset();
char buf[12] = {0};
char fmt[12] = {0};
void *retptr = taosStrpTime(NULL, fmt, NULL);
EXPECT_EQ(retptr, nullptr);
retptr = taosStrpTime(buf, NULL, NULL);
EXPECT_EQ(retptr, nullptr);
size_t ret = taosStrfTime(NULL, 0, fmt, NULL);
EXPECT_EQ(ret, 0);
ret = taosStrfTime(buf, 0, NULL, NULL);
EXPECT_EQ(ret, 0);
time_t tp = {0};
struct tm *retptr2 = taosGmTimeR(&tp, NULL);
EXPECT_EQ(retptr2, nullptr);
retptr2 = taosGmTimeR(NULL, NULL);
EXPECT_EQ(retptr2, nullptr);
time_t rett = taosTimeGm(NULL);
EXPECT_EQ(rett, -1);
timezone_t tz = {0};
retptr2 = taosLocalTime(&tp, NULL, NULL, 0, tz);
EXPECT_EQ(retptr2, nullptr);
retptr2 = taosLocalTime(NULL, NULL, NULL, 0, tz);
EXPECT_EQ(retptr2, nullptr);
}
TEST(osTest, system) {
#if defined(LINUX)
taosSetConsoleEcho(false);
taosSetConsoleEcho(true);
taosGetOldTerminalMode();
taosCloseCmd(NULL);
TdCmdPtr ptr = taosOpenCmd(NULL);
EXPECT_EQ(ptr, nullptr);
taosCloseCmd(&ptr);
ptr = taosOpenCmd("echo 'hello world'");
ASSERT_NE(ptr, nullptr);
char buf[256] = {0};
int64_t ret64 = taosGetsCmd(NULL, 0, NULL);
EXPECT_LE(ret64, 0);
ret64 = taosGetsCmd(ptr, 0, NULL);
EXPECT_LE(ret64, 0);
ret64 = taosGetsCmd(ptr, 255, buf);
EXPECT_GT(ret64, 0);
taosCloseCmd(&ptr);
ptr = taosOpenCmd("echoxxx 'hello world'");
ASSERT_NE(ptr, nullptr);
ret64 = taosGetsCmd(ptr, 255, buf);
EXPECT_LE(ret64, 0);
taosCloseCmd(&ptr);
ret64 = taosGetLineCmd(NULL, NULL);
EXPECT_LE(ret64, 0);
ret64 = taosGetLineCmd(ptr, NULL);
EXPECT_LE(ret64, 0);
ptr = taosOpenCmd("echo 'hello world'");
ASSERT_NE(ptr, nullptr);
char *ptrBuf = NULL;
ret64 = taosGetLineCmd(ptr, &ptrBuf);
EXPECT_GE(ret64, 0);
taosCloseCmd(&ptr);
ptr = taosOpenCmd("echoxxx 'hello world'");
ASSERT_NE(ptr, nullptr);
ret64 = taosGetLineCmd(ptr, &ptrBuf);
EXPECT_LE(ret64, 0);
taosCloseCmd(&ptr);
int32_t ret32 = taosEOFCmd(NULL);
EXPECT_EQ(ret32, 0);
#endif
}
TEST(osTest, sysinfo) {
#if defined(LINUX)
int32_t ret32 = 0;
ret32 = taosGetEmail(NULL, 0);
EXPECT_NE(ret32, 0);
ret32 = taosGetOsReleaseName(NULL, NULL, NULL, 0);
EXPECT_NE(ret32, 0);
char buf[128] = {0};
float numOfCores = 0;
ret32 = taosGetCpuInfo(buf, 0, NULL);
EXPECT_NE(ret32, 0);
ret32 = taosGetCpuInfo(NULL, 0, &numOfCores);
EXPECT_NE(ret32, 0);
ret32 = taosGetCpuCores(NULL, false);
EXPECT_NE(ret32, 0);
ret32 = taosGetTotalMemory(NULL);
EXPECT_NE(ret32, 0);
ret32 = taosGetProcMemory(NULL);
EXPECT_NE(ret32, 0);
ret32 = taosGetSysMemory(NULL);
EXPECT_NE(ret32, 0);
ret32 = taosGetDiskSize(buf, NULL);
EXPECT_NE(ret32, 0);
SDiskSize disksize = {0};
ret32 = taosGetDiskSize(NULL, &disksize);
EXPECT_NE(ret32, 0);
int64_t tmp = 0;
ret32 = taosGetProcIO(NULL, NULL, NULL, NULL);
EXPECT_NE(ret32, 0);
ret32 = taosGetProcIO(&tmp, NULL, NULL, NULL);
EXPECT_NE(ret32, 0);
ret32 = taosGetProcIO(&tmp, &tmp, NULL, NULL);
EXPECT_NE(ret32, 0);
ret32 = taosGetProcIO(&tmp, &tmp, &tmp, NULL);
EXPECT_NE(ret32, 0);
ret32 = taosGetProcIODelta(NULL, NULL, NULL, NULL);
EXPECT_NE(ret32, 0);
ret32 = taosGetProcIODelta(&tmp, NULL, NULL, NULL);
EXPECT_NE(ret32, 0);
ret32 = taosGetProcIODelta(&tmp, &tmp, NULL, NULL);
EXPECT_NE(ret32, 0);
ret32 = taosGetProcIODelta(&tmp, &tmp, &tmp, NULL);
EXPECT_NE(ret32, 0);
taosGetProcIODelta(NULL, NULL, NULL, NULL);
taosGetProcIODelta(&tmp, &tmp, &tmp, &tmp);
ret32 = taosGetCardInfo(NULL, NULL);
EXPECT_NE(ret32, 0);
ret32 = taosGetCardInfo(&tmp, NULL);
EXPECT_NE(ret32, 0);
ret32 = taosGetCardInfoDelta(NULL, NULL);
EXPECT_NE(ret32, 0);
ret32 = taosGetCardInfoDelta(&tmp, NULL);
EXPECT_NE(ret32, 0);
taosGetCardInfoDelta(NULL, NULL);
taosGetCardInfoDelta(&tmp, &tmp);
ret32 = taosGetSystemUUIDLimit36(NULL, 0);
EXPECT_NE(ret32, 0);
ret32 = taosGetSystemUUIDLen(NULL, 0);
EXPECT_NE(ret32, 0);
ret32 = taosGetSystemUUIDLen(buf, -1);
EXPECT_NE(ret32, 0);
taosSetCoreDump(false);
ret32 = taosGetlocalhostname(NULL, 0);
EXPECT_NE(ret32, 0);
#endif
}
TEST(osTest, osFQDNSuccess) {
char fqdn[TD_FQDN_LEN];
char ipString[INET_ADDRSTRLEN];
@ -47,8 +271,8 @@ TEST(osTest, osFQDNSuccess) {
struct in_addr addr;
addr.s_addr = htonl(ipv4);
(void)snprintf(ipString, INET_ADDRSTRLEN, "%u.%u.%u.%u", (unsigned int)(addr.s_addr >> 24) & 0xFF,
(unsigned int)(addr.s_addr >> 16) & 0xFF, (unsigned int)(addr.s_addr >> 8) & 0xFF,
(unsigned int)(addr.s_addr) & 0xFF);
(unsigned int)(addr.s_addr >> 16) & 0xFF, (unsigned int)(addr.s_addr >> 8) & 0xFF,
(unsigned int)(addr.s_addr) & 0xFF);
(void)printf("fqdn:%s ip:%s\n", fqdn, ipString);
}
@ -56,7 +280,7 @@ TEST(osTest, osFQDNFailed) {
char fqdn[1024] = "fqdn_test_not_found";
char ipString[24];
uint32_t ipv4 = 0;
int32_t code = taosGetIpv4FromFqdn(fqdn, &ipv4);
int32_t code = taosGetIpv4FromFqdn(fqdn, &ipv4);
ASSERT_NE(code, 0);
terrno = TSDB_CODE_RPC_FQDN_ERROR;
@ -79,7 +303,7 @@ TEST(osTest, osSystem) {
}
void fileOperateOnFree(void *param) {
char * fname = (char *)param;
char *fname = (char *)param;
TdFilePtr pFile = taosOpenFile(fname, TD_FILE_CREATE | TD_FILE_WRITE);
(void)printf("On free thread open file\n");
ASSERT_NE(pFile, nullptr);
@ -101,7 +325,7 @@ void *fileOperateOnFreeThread(void *param) {
return NULL;
}
void fileOperateOnBusy(void *param) {
char * fname = (char *)param;
char *fname = (char *)param;
TdFilePtr pFile = taosOpenFile(fname, TD_FILE_CREATE | TD_FILE_WRITE);
(void)printf("On busy thread open file\n");
if (pFile == NULL) return;
@ -165,9 +389,9 @@ TEST(osTest, osFile) {
(void)taosThreadJoin(thread2, NULL);
taosThreadClear(&thread2);
//int ret = taosRemoveFile(fname);
//ASSERT_EQ(ret, 0);
//printf("remove file success");
// int ret = taosRemoveFile(fname);
// ASSERT_EQ(ret, 0);
// printf("remove file success");
}
#ifndef OSFILE_PERFORMANCE_TEST
@ -178,18 +402,109 @@ TEST(osTest, osFile) {
#define TESTTIMES 1000
char *getRandomWord() {
static char words[][MAX_WORD_LENGTH] = {
"Lorem", "ipsum", "dolor", "sit", "amet", "consectetur", "adipiscing", "elit",
"sed", "do", "eiusmod", "tempor", "incididunt", "ut", "labore", "et", "dolore", "magna",
"aliqua", "Ut", "enim", "ad", "minim", "veniam", "quis", "nostrud", "exercitation", "ullamco",
"Why", "do", "programmers", "prefer", "using", "dark", "mode?", "Because", "light", "attracts",
"bugs", "and", "they", "want", "to", "code", "in", "peace,", "like", "a", "ninja", "in", "the", "shadows."
"aliqua", "Ut", "enim", "ad", "minim", "veniam", "quis", "nostrud", "exercitation", "ullamco",
"laboris", "nisi", "ut", "aliquip", "ex", "ea", "commodo", "consequat", "Duis", "aute", "irure",
"dolor", "in", "reprehenderit", "in", "voluptate", "velit", "esse", "cillum", "dolore", "eu",
"fugiat", "nulla", "pariatur", "Excepteur", "sint", "occaecat", "cupidatat", "non", "proident",
"sunt", "in", "culpa", "qui", "officia", "deserunt", "mollit", "anim", "id", "est", "laborum"
};
static char words[][MAX_WORD_LENGTH] = {"Lorem",
"ipsum",
"dolor",
"sit",
"amet",
"consectetur",
"adipiscing",
"elit",
"sed",
"do",
"eiusmod",
"tempor",
"incididunt",
"ut",
"labore",
"et",
"dolore",
"magna",
"aliqua",
"Ut",
"enim",
"ad",
"minim",
"veniam",
"quis",
"nostrud",
"exercitation",
"ullamco",
"Why",
"do",
"programmers",
"prefer",
"using",
"dark",
"mode?",
"Because",
"light",
"attracts",
"bugs",
"and",
"they",
"want",
"to",
"code",
"in",
"peace,",
"like",
"a",
"ninja",
"in",
"the",
"shadows."
"aliqua",
"Ut",
"enim",
"ad",
"minim",
"veniam",
"quis",
"nostrud",
"exercitation",
"ullamco",
"laboris",
"nisi",
"ut",
"aliquip",
"ex",
"ea",
"commodo",
"consequat",
"Duis",
"aute",
"irure",
"dolor",
"in",
"reprehenderit",
"in",
"voluptate",
"velit",
"esse",
"cillum",
"dolore",
"eu",
"fugiat",
"nulla",
"pariatur",
"Excepteur",
"sint",
"occaecat",
"cupidatat",
"non",
"proident",
"sunt",
"in",
"culpa",
"qui",
"officia",
"deserunt",
"mollit",
"anim",
"id",
"est",
"laborum"};
return words[taosRand() % MAX_WORDS];
}
@ -197,7 +512,7 @@ char *getRandomWord() {
int64_t fillBufferWithRandomWords(char *buffer, int64_t maxBufferSize) {
int64_t len = 0;
while (len < maxBufferSize) {
char * word = getRandomWord();
char *word = getRandomWord();
size_t wordLen = strlen(word);
if (len + wordLen + 1 < maxBufferSize) {
@ -246,11 +561,11 @@ TEST(osTest, osFilePerformance) {
int64_t OpenForWriteCloseFileCost;
int64_t OpenForReadCloseFileCost;
char * buffer;
char * writeBuffer = (char *)taosMemoryCalloc(1, MAX_TEST_FILE_SIZE);
char * readBuffer = (char *)taosMemoryCalloc(1, MAX_TEST_FILE_SIZE);
char *buffer;
char *writeBuffer = (char *)taosMemoryCalloc(1, MAX_TEST_FILE_SIZE);
char *readBuffer = (char *)taosMemoryCalloc(1, MAX_TEST_FILE_SIZE);
int64_t size = fillBufferWithRandomWords(writeBuffer, MAX_TEST_FILE_SIZE);
char * fname = "./osFilePerformanceTest.txt";
char *fname = "./osFilePerformanceTest.txt";
TdFilePtr pOutFD = taosCreateFile(fname, TD_FILE_WRITE | TD_FILE_CREATE | TD_FILE_TRUNC);
ASSERT_NE(pOutFD, nullptr);
@ -342,6 +657,6 @@ TEST(osTest, osFilePerformance) {
(void)printf("Test OpenForRead & Close file %d times, cost: %" PRId64 "us\n", TESTTIMES, OpenForReadCloseFileCost);
}
#endif // OSFILE_PERFORMANCE_TEST
#endif // OSFILE_PERFORMANCE_TEST
#pragma GCC diagnostic pop

View File

@ -498,4 +498,42 @@ TEST(osThreadTests, spinlock) {
TEST(osThreadTests, others) {
taosThreadTestCancel();
taosThreadClear(NULL);
TdThread tid1 = {0};
TdThread tid2 = {0};
TdThread *thread = &tid1;
taosResetPthread(NULL);
taosResetPthread(thread);
bool retb = taosComparePthread(tid1, tid2);
EXPECT_TRUE(retb);
int32_t ret32 = taosGetAppName(NULL, NULL);
EXPECT_NE(ret32, 0);
char name[32] = {0};
int32_t pid;
ret32 = taosGetPIdByName(name, NULL);
EXPECT_NE(ret32, 0);
ret32 = taosGetPIdByName(NULL, &pid);
EXPECT_NE(ret32, 0);
ret32 = tsem_timewait(NULL, 124);
EXPECT_NE(ret32, 0);
ret32 = tsem_wait(NULL);
EXPECT_NE(ret32, 0);
ret32 = tsem2_init(NULL, 0, 0);
EXPECT_NE(ret32, 0);
ret32 = tsem_post(NULL);
EXPECT_NE(ret32, 0);
ret32 = tsem_destroy(NULL);
EXPECT_NE(ret32, 0);
ret32 = tsem2_post(NULL);
EXPECT_NE(ret32, 0);
ret32 = tsem2_destroy(NULL);
EXPECT_NE(ret32, 0);
ret32 = tsem2_wait(NULL);
EXPECT_NE(ret32, 0);
ret32 = tsem2_timewait(NULL, 128);
EXPECT_NE(ret32, 0);
}