diff --git a/CMakeLists.txt b/CMakeLists.txt
index 681559a37bee3ad4e4ac92e43785c8dfedd2f996..cda71fb3bf01ba1018a77c2741709a9d28a836c8 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -26,8 +26,9 @@ if(${BUILD_TEST})
endif(${BUILD_TEST})
add_subdirectory(source)
add_subdirectory(tools)
+add_subdirectory(tests)
# docs
add_subdirectory(docs)
-# tests (TODO)
\ No newline at end of file
+# tests (TODO)
diff --git a/include/util/tdef.h b/include/util/tdef.h
index dfb53de58fa570ed189c43130ff92b7bf4eec65e..02b5a1e620d883108ffb8ff44e61bac8d2f0a1d0 100644
--- a/include/util/tdef.h
+++ b/include/util/tdef.h
@@ -235,6 +235,7 @@ do { \
#define TSDB_MAX_VNODES 512
#define TSDB_MIN_VNODES_PER_DB 1
#define TSDB_MAX_VNODES_PER_DB 4096
+#define TSDB_DEFAULT_VN_PER_DB 2
#define TSDB_DNODE_ROLE_ANY 0
#define TSDB_DNODE_ROLE_MGMT 1
diff --git a/source/dnode/mgmt/daemon/src/daemon.c b/source/dnode/mgmt/daemon/src/daemon.c
index 0a725d9975c4a9379825169a7d895366fb2d7a5f..b9a1e4cecbfe333591844c3ebbaebe5a96a0c741 100644
--- a/source/dnode/mgmt/daemon/src/daemon.c
+++ b/source/dnode/mgmt/daemon/src/daemon.c
@@ -92,6 +92,7 @@ void dmnPrintVersion() {
}
int dmnReadConfig(const char *path) {
+ tstrncpy(configDir, global.configDir, PATH_MAX);
taosInitGlobalCfg();
taosReadGlobalLogCfg();
diff --git a/source/dnode/mnode/impl/inc/mndDef.h b/source/dnode/mnode/impl/inc/mndDef.h
index 74138500bdfbe9ebd0f9b393314e666080e904ed..36b6725737bb3b4cd6a070da92fe01060f80d17e 100644
--- a/source/dnode/mnode/impl/inc/mndDef.h
+++ b/source/dnode/mnode/impl/inc/mndDef.h
@@ -182,6 +182,7 @@ typedef struct {
} SUserObj;
typedef struct {
+ int32_t numOfVgroups;
int32_t cacheBlockSize;
int32_t totalBlocks;
int32_t daysPerFile;
@@ -209,7 +210,6 @@ typedef struct {
int64_t uid;
int32_t cfgVersion;
int32_t vgVersion;
- int32_t numOfVgroups;
int8_t hashMethod; // default is 1
SDbCfg cfg;
} SDbObj;
diff --git a/source/dnode/mnode/impl/src/mndDb.c b/source/dnode/mnode/impl/src/mndDb.c
index 188ca7963c7bfc8451e8547b96b61f4c67415cba..fbbae13b636f7f0f162b6cfd38c6f7677adbb3f7 100644
--- a/source/dnode/mnode/impl/src/mndDb.c
+++ b/source/dnode/mnode/impl/src/mndDb.c
@@ -77,8 +77,8 @@ static SSdbRaw *mndDbActionEncode(SDbObj *pDb) {
SDB_SET_INT64(pRaw, dataPos, pDb->uid)
SDB_SET_INT32(pRaw, dataPos, pDb->cfgVersion)
SDB_SET_INT32(pRaw, dataPos, pDb->vgVersion)
- SDB_SET_INT32(pRaw, dataPos, pDb->numOfVgroups)
SDB_SET_INT8(pRaw, dataPos, pDb->hashMethod)
+ SDB_SET_INT32(pRaw, dataPos, pDb->cfg.numOfVgroups)
SDB_SET_INT32(pRaw, dataPos, pDb->cfg.cacheBlockSize)
SDB_SET_INT32(pRaw, dataPos, pDb->cfg.totalBlocks)
SDB_SET_INT32(pRaw, dataPos, pDb->cfg.daysPerFile)
@@ -124,8 +124,8 @@ static SSdbRow *mndDbActionDecode(SSdbRaw *pRaw) {
SDB_GET_INT64(pRaw, pRow, dataPos, &pDb->uid)
SDB_GET_INT32(pRaw, pRow, dataPos, &pDb->cfgVersion)
SDB_GET_INT32(pRaw, pRow, dataPos, &pDb->vgVersion)
- SDB_GET_INT32(pRaw, pRow, dataPos, &pDb->numOfVgroups)
SDB_GET_INT8(pRaw, pRow, dataPos, &pDb->hashMethod)
+ SDB_GET_INT32(pRaw, pRow, dataPos, &pDb->cfg.numOfVgroups)
SDB_GET_INT32(pRaw, pRow, dataPos, &pDb->cfg.cacheBlockSize)
SDB_GET_INT32(pRaw, pRow, dataPos, &pDb->cfg.totalBlocks)
SDB_GET_INT32(pRaw, pRow, dataPos, &pDb->cfg.daysPerFile)
@@ -163,7 +163,6 @@ static int32_t mndDbActionUpdate(SSdb *pSdb, SDbObj *pOldDb, SDbObj *pNewDb) {
pOldDb->updateTime = pNewDb->createdTime;
pOldDb->cfgVersion = pNewDb->cfgVersion;
pOldDb->vgVersion = pNewDb->vgVersion;
- pOldDb->numOfVgroups = pNewDb->numOfVgroups;
memcpy(&pOldDb->cfg, &pNewDb->cfg, sizeof(SDbCfg));
return 0;
}
@@ -195,6 +194,7 @@ static int32_t mndCheckDbName(char *dbName, SUserObj *pUser) {
}
static int32_t mndCheckDbCfg(SMnode *pMnode, SDbCfg *pCfg) {
+ if (pCfg->numOfVgroups < TSDB_MIN_VNODES_PER_DB || pCfg->numOfVgroups > TSDB_MAX_VNODES_PER_DB) return -1;
if (pCfg->cacheBlockSize < TSDB_MIN_CACHE_BLOCK_SIZE || pCfg->cacheBlockSize > TSDB_MAX_CACHE_BLOCK_SIZE) return -1;
if (pCfg->totalBlocks < TSDB_MIN_TOTAL_BLOCKS || pCfg->totalBlocks > TSDB_MAX_TOTAL_BLOCKS) return -1;
if (pCfg->daysPerFile < TSDB_MIN_DAYS_PER_FILE || pCfg->daysPerFile > TSDB_MAX_DAYS_PER_FILE) return -1;
@@ -222,6 +222,7 @@ static int32_t mndCheckDbCfg(SMnode *pMnode, SDbCfg *pCfg) {
}
static void mndSetDefaultDbCfg(SDbCfg *pCfg) {
+ if (pCfg->numOfVgroups < 0) pCfg->numOfVgroups = TSDB_DEFAULT_VN_PER_DB;
if (pCfg->cacheBlockSize < 0) pCfg->cacheBlockSize = TSDB_DEFAULT_CACHE_BLOCK_SIZE;
if (pCfg->totalBlocks < 0) pCfg->totalBlocks = TSDB_DEFAULT_TOTAL_BLOCKS;
if (pCfg->daysPerFile < 0) pCfg->daysPerFile = TSDB_DEFAULT_DAYS_PER_FILE;
@@ -246,7 +247,7 @@ static int32_t mndSetRedoLogs(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVgOb
if (pDbRaw == NULL || mndTransAppendRedolog(pTrans, pDbRaw) != 0) return -1;
sdbSetRawStatus(pDbRaw, SDB_STATUS_CREATING);
- for (int v = 0; v < pDb->numOfVgroups; ++v) {
+ for (int v = 0; v < pDb->cfg.numOfVgroups; ++v) {
SSdbRaw *pVgRaw = mndVgroupActionEncode(pVgroups + v);
if (pVgRaw == NULL || mndTransAppendRedolog(pTrans, pVgRaw) != 0) return -1;
sdbSetRawStatus(pVgRaw, SDB_STATUS_CREATING);
@@ -260,7 +261,7 @@ static int32_t mndSetUndoLogs(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVgOb
if (pDbRaw == NULL || mndTransAppendUndolog(pTrans, pDbRaw) != 0) return -1;
sdbSetRawStatus(pDbRaw, SDB_STATUS_DROPPED);
- for (int v = 0; v < pDb->numOfVgroups; ++v) {
+ for (int v = 0; v < pDb->cfg.numOfVgroups; ++v) {
SSdbRaw *pVgRaw = mndVgroupActionEncode(pVgroups + v);
if (pVgRaw == NULL || mndTransAppendUndolog(pTrans, pVgRaw) != 0) return -1;
sdbSetRawStatus(pVgRaw, SDB_STATUS_DROPPED);
@@ -274,7 +275,7 @@ static int32_t mndSetCommitLogs(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVg
if (pDbRaw == NULL || mndTransAppendCommitlog(pTrans, pDbRaw) != 0) return -1;
sdbSetRawStatus(pDbRaw, SDB_STATUS_READY);
- for (int v = 0; v < pDb->numOfVgroups; ++v) {
+ for (int v = 0; v < pDb->cfg.numOfVgroups; ++v) {
SSdbRaw *pVgRaw = mndVgroupActionEncode(pVgroups + v);
if (pVgRaw == NULL || mndTransAppendCommitlog(pTrans, pVgRaw) != 0) return -1;
sdbSetRawStatus(pVgRaw, SDB_STATUS_READY);
@@ -298,11 +299,11 @@ static int32_t mndCreateDb(SMnode *pMnode, SMnodeMsg *pMsg, SCreateDbMsg *pCreat
dbObj.createdTime = taosGetTimestampMs();
dbObj.updateTime = dbObj.createdTime;
dbObj.uid = mndGenerateUid(dbObj.name, TSDB_FULL_DB_NAME_LEN);
- dbObj.numOfVgroups = pCreate->numOfVgroups;
dbObj.hashMethod = 1;
dbObj.cfgVersion = 1;
dbObj.vgVersion = 1;
- dbObj.cfg = (SDbCfg){.cacheBlockSize = pCreate->cacheBlockSize,
+ dbObj.cfg = (SDbCfg){.numOfVgroups = pCreate->numOfVgroups,
+ .cacheBlockSize = pCreate->cacheBlockSize,
.totalBlocks = pCreate->totalBlocks,
.daysPerFile = pCreate->daysPerFile,
.daysToKeep0 = pCreate->daysToKeep0,
@@ -643,7 +644,7 @@ static int32_t mndProcessUseDbMsg(SMnodeMsg *pMsg) {
return -1;
}
- int32_t contLen = sizeof(SUseDbRsp) + pDb->numOfVgroups * sizeof(SVgroupInfo);
+ int32_t contLen = sizeof(SUseDbRsp) + pDb->cfg.numOfVgroups * sizeof(SVgroupInfo);
SUseDbRsp *pRsp = rpcMallocCont(contLen);
if (pRsp == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
@@ -654,7 +655,7 @@ static int32_t mndProcessUseDbMsg(SMnodeMsg *pMsg) {
if (pUse->vgVersion < pDb->vgVersion) {
void *pIter = NULL;
- while (vindex < pDb->numOfVgroups) {
+ while (vindex < pDb->cfg.numOfVgroups) {
SVgObj *pVgroup = NULL;
pIter = sdbFetch(pSdb, SDB_VGROUP, pIter, (void **)&pVgroup);
if (pIter == NULL) break;
@@ -888,7 +889,7 @@ static int32_t mndRetrieveDbs(SMnodeMsg *pMsg, SShowObj *pShow, char *data, int3
cols++;
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
- *(int16_t *)pWrite = pDb->numOfVgroups;
+ *(int16_t *)pWrite = pDb->cfg.numOfVgroups;
cols++;
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
diff --git a/source/dnode/mnode/impl/src/mndVgroup.c b/source/dnode/mnode/impl/src/mndVgroup.c
index b880434bf6e8945c1454317b070d1dcf24291ed4..c2be7fa39a7830be7bd76844effb93c0a7766b5f 100644
--- a/source/dnode/mnode/impl/src/mndVgroup.c
+++ b/source/dnode/mnode/impl/src/mndVgroup.c
@@ -156,11 +156,6 @@ void mndReleaseVgroup(SMnode *pMnode, SVgObj *pVgroup) {
sdbRelease(pSdb, pVgroup);
}
-static int32_t mndGetDefaultVgroupSize(SMnode *pMnode) {
- // todo
- return 2;
-}
-
static int32_t mndGetAvailableDnode(SMnode *pMnode, SVgObj *pVgroup) {
SSdb *pSdb = pMnode->pSdb;
int32_t allocedVnodes = 0;
@@ -193,21 +188,7 @@ static int32_t mndGetAvailableDnode(SMnode *pMnode, SVgObj *pVgroup) {
}
int32_t mndAllocVgroup(SMnode *pMnode, SDbObj *pDb, SVgObj **ppVgroups) {
- if (pDb->numOfVgroups != -1 &&
- (pDb->numOfVgroups < TSDB_MIN_VNODES_PER_DB || pDb->numOfVgroups > TSDB_MAX_VNODES_PER_DB)) {
- terrno = TSDB_CODE_MND_INVALID_DB_OPTION;
- return -1;
- }
-
- if (pDb->numOfVgroups == -1) {
- pDb->numOfVgroups = mndGetDefaultVgroupSize(pMnode);
- if (pDb->numOfVgroups < 0) {
- terrno = TSDB_CODE_MND_NO_ENOUGH_DNODES;
- return -1;
- }
- }
-
- SVgObj *pVgroups = calloc(pDb->numOfVgroups, sizeof(SVgObj));
+ SVgObj *pVgroups = calloc(pDb->cfg.numOfVgroups, sizeof(SVgObj));
if (pVgroups == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
return -1;
@@ -217,9 +198,9 @@ int32_t mndAllocVgroup(SMnode *pMnode, SDbObj *pDb, SVgObj **ppVgroups) {
int32_t maxVgId = sdbGetMaxId(pMnode->pSdb, SDB_VGROUP);
uint32_t hashMin = 0;
uint32_t hashMax = UINT32_MAX;
- uint32_t hashInterval = (hashMax - hashMin) / pDb->numOfVgroups;
+ uint32_t hashInterval = (hashMax - hashMin) / pDb->cfg.numOfVgroups;
- for (uint32_t v = 0; v < pDb->numOfVgroups; v++) {
+ for (uint32_t v = 0; v < pDb->cfg.numOfVgroups; v++) {
SVgObj *pVgroup = &pVgroups[v];
pVgroup->vgId = maxVgId++;
pVgroup->createdTime = taosGetTimestampMs();
@@ -227,7 +208,7 @@ int32_t mndAllocVgroup(SMnode *pMnode, SDbObj *pDb, SVgObj **ppVgroups) {
pVgroup->version = 1;
pVgroup->dbUid = pDb->uid;
pVgroup->hashBegin = hashMin + hashInterval * v;
- if (v == pDb->numOfVgroups - 1) {
+ if (v == pDb->cfg.numOfVgroups - 1) {
pVgroup->hashEnd = hashMax;
} else {
pVgroup->hashEnd = hashMin + hashInterval * (v + 1) - 1;
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index e21905af3b88cd6628c5b83471ff70013dc996fc..966eb943541fda493dd120c12e1ba6be1c93cf48 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -1,15 +1,4 @@
-# generate debug version:
-# mkdir debug; cd debug; cmake -DCMAKE_BUILD_TYPE=Debug ..
-# generate release version:
-# mkdir release; cd release; cmake -DCMAKE_BUILD_TYPE=Release ..
-
-CMAKE_MINIMUM_REQUIRED(VERSION 2.8...3.20)
-PROJECT(TDengine)
-
-SET(CMAKE_C_STANDARD 11)
-SET(CMAKE_VERBOSE_MAKEFILE ON)
-
-ADD_SUBDIRECTORY(examples/c)
+#ADD_SUBDIRECTORY(examples/c)
ADD_SUBDIRECTORY(tsim)
-ADD_SUBDIRECTORY(test/c)
-ADD_SUBDIRECTORY(comparisonTest/tdengine)
+#ADD_SUBDIRECTORY(test/c)
+#ADD_SUBDIRECTORY(comparisonTest/tdengine)
diff --git a/tests/script/general/user/basic1.sim b/tests/script/general/user/basic1.sim
index 3670c1ddb097146f97135b2cab0022c9531d89e0..d4a663c096f99cfcde87399bfe57b66f424e2410 100644
--- a/tests/script/general/user/basic1.sim
+++ b/tests/script/general/user/basic1.sim
@@ -5,7 +5,7 @@ sql connect
print =============== show users
sql show users
-if $rows != 3 then
+if $rows != 1 then
return -1
endi
@@ -21,7 +21,7 @@ sql_error drop account root
print =============== create user1
sql create user user1 PASS 'user1'
sql show users
-if $rows != 4 then
+if $rows != 2 then
return -1
endi
@@ -33,7 +33,7 @@ print $data30 $data31 $data32
print =============== create user2
sql create user user2 PASS 'user2'
sql show users
-if $rows != 5 then
+if $rows != 3 then
return -1
endi
@@ -46,7 +46,7 @@ print $data40 $data41 $data42
print =============== drop user1
sql drop user user1
sql show users
-if $rows != 4 then
+if $rows != 2 then
return -1
endi
@@ -62,7 +62,7 @@ system sh/exec.sh -n dnode1 -s start
print =============== show users
sql show users
-if $rows != 4 then
+if $rows != 2 then
return -1
endi
diff --git a/tests/script/sh/deploy.sh b/tests/script/sh/deploy.sh
index cde27d7dc3fa00258d9d9d50ee3dfc82f858b138..03ce1c28885d158213c38a01363546675f46ae0a 100755
--- a/tests/script/sh/deploy.sh
+++ b/tests/script/sh/deploy.sh
@@ -1,5 +1,8 @@
#!/bin/bash
+set +e
+#set -x
+
echo "Executing deploy.sh"
if [ $# != 4 ]; then
@@ -50,12 +53,12 @@ else
fi
if [[ "$TAOSD_DIR" == *"$IN_TDINTERNAL"* ]]; then
- BIN_DIR=`find . -name "taosd"|grep bin|head -n1|cut -d '/' ${cut_opt}2,3`
+ BIN_DIR=`find . -name "taosd"|grep source|head -n1|cut -d '/' ${cut_opt}2,3`
else
- BIN_DIR=`find . -name "taosd"|grep bin|head -n1|cut -d '/' ${cut_opt}2`
+ BIN_DIR=`find . -name "taosd"|grep source|head -n1|cut -d '/' ${cut_opt}2`
fi
-BUILD_DIR=$TAOS_DIR/$BIN_DIR/build
+BUILD_DIR=$TAOS_DIR/$BIN_DIR
SIM_DIR=$TAOS_DIR/sim
diff --git a/tests/script/sh/exec.sh b/tests/script/sh/exec.sh
index 80b8cda428da72daf55fc6e0d4c47867ce191d35..d1572bb513c533d9a0d0465a03aeeebe6b85f6e6 100755
--- a/tests/script/sh/exec.sh
+++ b/tests/script/sh/exec.sh
@@ -8,6 +8,9 @@
# exit 1
# fi
+set +e
+#set -x
+
UNAME_BIN=`which uname`
OS_TYPE=`$UNAME_BIN`
@@ -62,16 +65,16 @@ else
fi
if [[ "$TAOSD_DIR" == *"$IN_TDINTERNAL"* ]]; then
- BIN_DIR=`find . -name "taosd"|grep bin|head -n1|cut -d '/' ${cut_opt}2,3`
+ BIN_DIR=`find . -name "taosd"|grep source|head -n1|cut -d '/' ${cut_opt}2,3`
else
- BIN_DIR=`find . -name "taosd"|grep bin|head -n1|cut -d '/' ${cut_opt}2`
+ BIN_DIR=`find . -name "taosd"|grep source|head -n1|cut -d '/' ${cut_opt}2`
fi
-BUILD_DIR=$TAOS_DIR/$BIN_DIR/build
+BUILD_DIR=$TAOS_DIR/$BIN_DIR
SIM_DIR=$TAOS_DIR/sim
NODE_DIR=$SIM_DIR/$NODE_NAME
-EXE_DIR=$BUILD_DIR/bin
+EXE_DIR=$BUILD_DIR/source/dnode/mgmt/daemon
CFG_DIR=$NODE_DIR/cfg
LOG_DIR=$NODE_DIR/log
DATA_DIR=$NODE_DIR/data
diff --git a/tests/script/test.sh b/tests/script/test.sh
index f2dc578987fb71df0a22e50eea4854f819ec200d..88ed7592969c6f7ba43e5998de2d02940dee2b9e 100755
--- a/tests/script/test.sh
+++ b/tests/script/test.sh
@@ -22,9 +22,6 @@ do
f)
FILE_NAME=$OPTARG
;;
- a)
- ASYNC=1
- ;;
v)
VALGRIND=1
;;
@@ -60,32 +57,22 @@ else
fi
if [[ "$TAOSD_DIR" == *"$IN_TDINTERNAL"* ]]; then
- BIN_DIR=`find . -name "taosd"|grep bin|head -n1|cut -d '/' ${cut_opt}2,3`
+ BIN_DIR=`find . -name "taosd"|grep source|head -n1|cut -d '/' ${cut_opt}2,3`
else
- BIN_DIR=`find . -name "taosd"|grep bin|head -n1|cut -d '/' ${cut_opt}2`
+ BIN_DIR=`find . -name "taosd"|grep source|head -n1|cut -d '/' ${cut_opt}2`
fi
-BUILD_DIR=$TOP_DIR/$BIN_DIR/build
+BUILD_DIR=$TOP_DIR/$BIN_DIR
SIM_DIR=$TOP_DIR/sim
-if [ $ASYNC -eq 0 ]; then
- PROGRAM=$BUILD_DIR/bin/tsim
-else
- PROGRAM="$BUILD_DIR/bin/tsim -a"
-fi
-
+PROGRAM=$BUILD_DIR/tests/tsim/tsim
PRG_DIR=$SIM_DIR/tsim
CFG_DIR=$PRG_DIR/cfg
LOG_DIR=$PRG_DIR/log
DATA_DIR=$PRG_DIR/data
-
-ARBITRATOR_PRG_DIR=$SIM_DIR/arbitrator
-ARBITRATOR_LOG_DIR=$ARBITRATOR_PRG_DIR/log
-
-
chmod -R 777 $PRG_DIR
echo "------------------------------------------------------------------------"
echo "Start TDengine Testing Case ..."
@@ -96,12 +83,10 @@ echo "CFG_DIR : $CFG_DIR"
rm -rf $LOG_DIR
rm -rf $CFG_DIR
-rm -rf $ARBITRATOR_LOG_DIR
mkdir -p $PRG_DIR
mkdir -p $LOG_DIR
mkdir -p $CFG_DIR
-mkdir -p $ARBITRATOR_LOG_DIR
TAOS_CFG=$PRG_DIR/cfg/taos.cfg
touch -f $TAOS_CFG
@@ -115,7 +100,7 @@ echo "secondEp ${HOSTNAME}:7200" >> $TAOS_CFG
echo "serverPort 7100" >> $TAOS_CFG
echo "dataDir $DATA_DIR" >> $TAOS_CFG
echo "logDir $LOG_DIR" >> $TAOS_CFG
-echo "scriptDir ${CODE_DIR}/../script" >> $TAOS_CFG
+echo "scriptDir ${CODE_DIR}" >> $TAOS_CFG
echo "numOfLogLines 100000000" >> $TAOS_CFG
echo "rpcDebugFlag 143" >> $TAOS_CFG
echo "tmrDebugFlag 131" >> $TAOS_CFG
@@ -141,7 +126,6 @@ if [ -n "$FILE_NAME" ]; then
else
echo "ExcuteCmd:" $PROGRAM -c $CFG_DIR -f $FILE_NAME
$PROGRAM -c $CFG_DIR -f $FILE_NAME
-# valgrind --tool=memcheck --leak-check=full --show-reachable=no --track-origins=yes --show-leak-kinds=all -v --workaround-gcc296-bugs=yes --log-file=${CODE_DIR}/../script/valgrind.log $PROGRAM -c $CFG_DIR -f $FILE_NAME
fi
else
echo "ExcuteCmd:" $PROGRAM -c $CFG_DIR -f basicSuite.sim
diff --git a/tests/tsim/CMakeLists.txt b/tests/tsim/CMakeLists.txt
index 50b42941aff12ec6762b2da904675e6fa0183cad..81737809d900a8931be71b4b7c605c9f18627d32 100644
--- a/tests/tsim/CMakeLists.txt
+++ b/tests/tsim/CMakeLists.txt
@@ -1,9 +1,14 @@
-PROJECT(TDengine)
-
-INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/client/inc)
-INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/cJson/inc)
-INCLUDE_DIRECTORIES(inc)
-
-AUX_SOURCE_DIRECTORY(src SRC)
-ADD_EXECUTABLE(tsim ${SRC})
-TARGET_LINK_LIBRARIES(tsim taos_static trpc tutil pthread cJson)
+aux_source_directory(src TSIM_SRC)
+add_executable(tsim ${TSIM_SRC})
+target_link_libraries(
+ tsim
+ PUBLIC taos
+ PUBLIC util
+ PUBLIC common
+ PUBLIC os
+ PUBLIC cjson
+)
+target_include_directories(
+ tsim
+ PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc"
+)
diff --git a/tests/tsim/inc/sim.h b/tests/tsim/inc/sim.h
index 39c6f6ac36a80ecf14b0f5a1029f3ef2ce75082e..4aa3c62a801229f19c251666a5d4326cfe79d0c2 100644
--- a/tests/tsim/inc/sim.h
+++ b/tests/tsim/inc/sim.h
@@ -13,8 +13,8 @@
* along with this program. If not, see .
*/
-#ifndef __SIM_H__
-#define __SIM_H__
+#ifndef _TD_SIM_H_
+#define _TD_SIM_H_
#include
#include
@@ -102,18 +102,18 @@ typedef struct _cmd_t {
int16_t cmdno;
int16_t nlen;
char name[MAX_SIM_CMD_NAME_LEN];
- bool (*parseCmd)(char *, struct _cmd_t *, int32_t);
- bool (*executeCmd)(struct _script_t *script, char *option);
+ bool (*parseCmd)(char *, struct _cmd_t *, int32_t);
+ bool (*executeCmd)(struct _script_t *script, char *option);
struct _cmd_t *next;
} SCommand;
typedef struct {
int16_t cmdno;
- int16_t jump; // jump position
- int16_t errorJump; // sql jump flag, while '-x' exist in sql cmd, this flag
- // will be SQL_JUMP_TRUE, otherwise is SQL_JUMP_FALSE */
- int16_t lineNum; // correspodning line number in original file
- int32_t optionOffset;// relative option offset
+ int16_t jump; // jump position
+ int16_t errorJump; // sql jump flag, while '-x' exist in sql cmd, this flag
+ // will be SQL_JUMP_TRUE, otherwise is SQL_JUMP_FALSE */
+ int16_t lineNum; // correspodning line number in original file
+ int32_t optionOffset; // relative option offset
} SCmdLine;
typedef struct _var_t {
@@ -123,24 +123,24 @@ typedef struct _var_t {
} SVariable;
typedef struct _script_t {
- int32_t type;
- bool killed;
- void * taos;
- char rows[12]; // number of rows data retrieved
- char data[MAX_QUERY_ROW_NUM][MAX_QUERY_COL_NUM][MAX_QUERY_VALUE_LEN]; // query results
- char system_exit_code[12];
- char system_ret_content[MAX_SYSTEM_RESULT_LEN];
- int32_t varLen;
- int32_t linePos; // current cmd position
- int32_t numOfLines; // number of lines in the script
- int32_t bgScriptLen;
- char fileName[MAX_FILE_NAME_LEN]; // script file name
- char error[MAX_ERROR_LEN];
- char * optionBuffer;
- SCmdLine *lines; // command list
- SVariable variables[MAX_VAR_LEN];
- pthread_t bgPid;
- char auth[128];
+ int32_t type;
+ bool killed;
+ void *taos;
+ char rows[12]; // number of rows data retrieved
+ char data[MAX_QUERY_ROW_NUM][MAX_QUERY_COL_NUM][MAX_QUERY_VALUE_LEN]; // query results
+ char system_exit_code[12];
+ char system_ret_content[MAX_SYSTEM_RESULT_LEN];
+ int32_t varLen;
+ int32_t linePos; // current cmd position
+ int32_t numOfLines; // number of lines in the script
+ int32_t bgScriptLen;
+ char fileName[MAX_FILE_NAME_LEN]; // script file name
+ char error[MAX_ERROR_LEN];
+ char *optionBuffer;
+ SCmdLine *lines; // command list
+ SVariable variables[MAX_VAR_LEN];
+ pthread_t bgPid;
+ char auth[128];
struct _script_t *bgScripts[MAX_BACKGROUND_SCRIPT_NUM];
} SScript;
@@ -150,16 +150,15 @@ extern int32_t simScriptPos;
extern int32_t simScriptSucced;
extern int32_t simDebugFlag;
extern char tsScriptDir[];
-extern bool simAsyncQuery;
extern bool abortExecution;
SScript *simParseScript(char *fileName);
SScript *simProcessCallOver(SScript *script);
-void * simExecuteScript(void *script);
+void *simExecuteScript(void *script);
void simInitsimCmdList();
bool simSystemInit();
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 simExecuteTestCmd(SScript *script, char *option);
bool simExecuteGotoCmd(SScript *script, char *option);
@@ -178,4 +177,4 @@ bool simExecuteLineInsertCmd(SScript *script, char *option);
bool simExecuteLineInsertErrorCmd(SScript *script, char *option);
void simVisuallizeOption(SScript *script, char *src, char *dst);
-#endif
\ No newline at end of file
+#endif /*_TD_SIM_H_*/
\ No newline at end of file
diff --git a/tests/tsim/inc/simParse.h b/tests/tsim/inc/simParse.h
index ef7d8e5ce72cc9bf0ae52380089d36576e84bd28..56ee90aadbdec34e15fc30a1ca368db603951422 100644
--- a/tests/tsim/inc/simParse.h
+++ b/tests/tsim/inc/simParse.h
@@ -13,8 +13,8 @@
* along with this program. If not, see .
*/
-#ifndef __SIM_PARSE_H__
-#define __SIM_PARSE_H__
+#ifndef _TD_SIM_PARSE_H_
+#define _TD_SIM_PARSE_H_
#define MAX_NUM_CMD 64
#define MAX_NUM_LABLES 100
@@ -40,10 +40,10 @@ typedef struct {
/* block definition */
typedef struct {
- char top; /* the number of blocks stacked */
- char type[MAX_NUM_BLOCK]; /* the block type */
- int16_t *pos[MAX_NUM_BLOCK]; /* position of the jump for if/elif/case */
- int16_t back[MAX_NUM_BLOCK]; /* go back, endw and continue */
+ char top; /* the number of blocks stacked */
+ char type[MAX_NUM_BLOCK]; /* the block type */
+ int16_t *pos[MAX_NUM_BLOCK]; /* position of the jump for if/elif/case */
+ int16_t back[MAX_NUM_BLOCK]; /* go back, endw and continue */
char numJump[MAX_NUM_BLOCK];
int16_t *jump[MAX_NUM_BLOCK][MAX_NUM_JUMP]; /* break or elif */
char sexp[MAX_NUM_BLOCK][40]; /*switch expression */
@@ -52,4 +52,4 @@ typedef struct {
bool simParseExpression(char *token, int32_t lineNum);
-#endif
\ No newline at end of file
+#endif /*_TD_SIM_PARSE_H_*/
\ No newline at end of file
diff --git a/tests/tsim/src/simExe.c b/tests/tsim/src/simExe.c
index 7a75dd7d8579537b8778819ec4b43086bdc28dc1..453d653919049881f94b47319b957ba04b62b50c 100644
--- a/tests/tsim/src/simExe.c
+++ b/tests/tsim/src/simExe.c
@@ -14,18 +14,18 @@
*/
#define _DEFAULT_SOURCE
-#include "../../../include/client/taos.h"
#include "cJSON.h"
#include "os.h"
#include "sim.h"
+#include "taos.h"
#include "taoserror.h"
#include "tglobal.h"
+#include "ttypes.h"
#include "tutil.h"
-#undef TAOS_MEM_CHECK
void simLogSql(char *sql, bool useSharp) {
static FILE *fp = NULL;
- char filename[256];
+ char filename[256];
sprintf(filename, "%s/sim.sql", tsScriptDir);
if (fp == NULL) {
fp = fopen(filename, "w");
@@ -74,7 +74,7 @@ char *simGetVariable(SScript *script, char *varName, int32_t varLen) {
return "null";
}
- char * keyName;
+ char *keyName;
int32_t keyLen;
paGetToken(varName + 6, &keyName, &keyLen);
@@ -91,7 +91,7 @@ char *simGetVariable(SScript *script, char *varName, int32_t varLen) {
return "null";
}
- char * keyName;
+ char *keyName;
int32_t keyLen;
paGetToken(varName + 7, &keyName, &keyLen);
@@ -144,7 +144,7 @@ char *simGetVariable(SScript *script, char *varName, int32_t varLen) {
}
int32_t simExecuteExpression(SScript *script, char *exp) {
- char * op1, *op2, *var1, *var2, *var3, *rest;
+ char *op1, *op2, *var1, *var2, *var3, *rest;
int32_t op1Len, op2Len, var1Len, var2Len, var3Len, val0, val1;
char t0[1024], t1[1024], t2[1024], t3[2048];
int32_t result;
@@ -302,10 +302,10 @@ bool simExecuteRunBackCmd(SScript *script, char *option) {
}
void simReplaceShToBat(char *dst) {
- char* sh = strstr(dst, ".sh");
+ char *sh = strstr(dst, ".sh");
if (sh != NULL) {
int32_t dstLen = (int32_t)strlen(dst);
- char *end = dst + dstLen;
+ char *end = dst + dstLen;
*(end + 1) = 0;
for (char *p = end; p >= sh; p--) {
@@ -436,7 +436,7 @@ bool simExecuteReturnCmd(SScript *script, char *option) {
}
void simVisuallizeOption(SScript *script, char *src, char *dst) {
- char * var, *token, *value;
+ char *var, *token, *value;
int32_t dstLen, srcLen, tokenLen;
dst[0] = 0, dstLen = 0;
@@ -466,10 +466,6 @@ void simVisuallizeOption(SScript *script, char *src, char *dst) {
strcpy(dst + dstLen, src);
}
-void simCloseRestFulConnect(SScript *script) {
- memset(script->auth, 0, sizeof(script->auth));
-}
-
void simCloseNativeConnect(SScript *script) {
if (script->taos == NULL) return;
@@ -479,168 +475,7 @@ void simCloseNativeConnect(SScript *script) {
script->taos = NULL;
}
-void simCloseTaosdConnect(SScript *script) {
- if (simAsyncQuery) {
- simCloseRestFulConnect(script);
- } else {
- simCloseNativeConnect(script);
- }
-}
-// {"status":"succ","code":0,"desc":"/KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04"}
-// {"status":"succ","head":["affected_rows"],"data":[[1]],"rows":1}
-// {"status":"succ","head":["ts","i"],"data":[["2017-12-25 21:28:41.022",1],["2017-12-25 21:28:42.022",2],["2017-12-25 21:28:43.022",3],["2017-12-25 21:28:44.022",4],["2017-12-25 21:28:45.022",5],["2017-12-25 21:28:46.022",6],["2017-12-25 21:28:47.022",7],["2017-12-25 21:28:48.022",8],["2017-12-25 21:28:49.022",9],["2017-12-25 21:28:50.022",10]],"rows":10}
-int32_t simParseHttpCommandResult(SScript *script, char *command) {
- cJSON* root = cJSON_Parse(command);
- if (root == NULL) {
- simError("script:%s, failed to parse json, response:%s", script->fileName, command);
- return -1;
- }
-
- cJSON *status = cJSON_GetObjectItem(root, "status");
- if (status == NULL) {
- simError("script:%s, failed to parse json, status is null, response:%s", script->fileName, command);
- cJSON_Delete(root);
- return -1;
- }
-
- if (status->valuestring == NULL || strlen(status->valuestring) == 0) {
- simError("script:%s, failed to parse json, status value is null, response:%s", script->fileName, command);
- cJSON_Delete(root);
- return -1;
- }
-
- if (strcmp(status->valuestring, "succ") != 0) {
- cJSON *code = cJSON_GetObjectItem(root, "code");
- if (code == NULL) {
- simError("script:%s, failed to parse json, code is null, response:%s", script->fileName, command);
- cJSON_Delete(root);
- return -1;
- }
- int32_t retcode = (int32_t)code->valueint;
- if (retcode != 1017) {
- simError("script:%s, json:status:%s not equal to succ, response:%s", script->fileName, status->valuestring,
- command);
- cJSON_Delete(root);
- return retcode;
- } else {
- simDebug("script:%s, json:status:%s not equal to succ, but code is %d, response:%s", script->fileName,
- status->valuestring, retcode, command);
- cJSON_Delete(root);
- return 0;
- }
- }
-
- cJSON *desc = cJSON_GetObjectItem(root, "desc");
- if (desc != NULL) {
- if (desc->valuestring == NULL || strlen(desc->valuestring) == 0) {
- simError("script:%s, failed to parse json, desc value is null, response:%s", script->fileName, command);
- cJSON_Delete(root);
- return -1;
- }
- strcpy(script->auth, desc->valuestring);
- cJSON_Delete(root);
- return 0;
- }
-
- cJSON *data = cJSON_GetObjectItem(root, "data");
- if (data == NULL) {
- simError("script:%s, failed to parse json, data is null, response:%s", script->fileName, command);
- cJSON_Delete(root);
- return -1;
- }
-
- int32_t rowsize = cJSON_GetArraySize(data);
- if (rowsize < 0) {
- simError("script:%s, failed to parse json:data, data size %d, response:%s", script->fileName, rowsize, command);
- cJSON_Delete(root);
- return -1;
- }
-
- int32_t rowIndex = 0;
- sprintf(script->rows, "%d", rowsize);
- for (int32_t r = 0; r < rowsize; ++r) {
- cJSON *row = cJSON_GetArrayItem(data, r);
- if (row == NULL) continue;
- if (rowIndex++ >= 10) break;
-
- int32_t colsize = cJSON_GetArraySize(row);
- if (colsize < 0) {
- break;
- }
-
- colsize = MIN(10, colsize);
- for (int32_t c = 0; c < colsize; ++c) {
- cJSON *col = cJSON_GetArrayItem(row, c);
- if (col->valuestring != NULL) {
- strcpy(script->data[r][c], col->valuestring);
- } else {
- if (col->numberstring[0] == 0) {
- strcpy(script->data[r][c], "null");
- } else {
- strcpy(script->data[r][c], col->numberstring);
- }
- }
- }
- }
-
- return 0;
-}
-
-int32_t simExecuteRestFulCommand(SScript *script, char *command) {
- char buf[5000] = {0};
- sprintf(buf, "%s 2>/dev/null", command);
-
- FILE *fp = popen(buf, "r");
- if (fp == NULL) {
- simError("failed to execute %s", buf);
- return -1;
- }
-
- int32_t mallocSize = 2000;
- int32_t alreadyReadSize = 0;
- char * content = malloc(mallocSize);
-
- while (!feof(fp)) {
- int32_t availSize = mallocSize - alreadyReadSize;
- int32_t len = (int32_t)fread(content + alreadyReadSize, 1, availSize, fp);
- if (len >= availSize) {
- alreadyReadSize += len;
- mallocSize *= 2;
- content = realloc(content, mallocSize);
- }
- }
-
- pclose(fp);
-
- return simParseHttpCommandResult(script, content);
-}
-
-bool simCreateRestFulConnect(SScript *script, char *user, char *pass) {
- char command[4096];
- sprintf(command, "curl 127.0.0.1:6041/rest/login/%s/%s", user, pass);
-
- bool success = false;
- for (int32_t attempt = 0; attempt < 10; ++attempt) {
- success = simExecuteRestFulCommand(script, command) == 0;
- if (!success) {
- simDebug("script:%s, user:%s connect taosd failed:%s, attempt:%d", script->fileName, user, taos_errstr(NULL),
- attempt);
- taosMsleep(1000);
- } else {
- simDebug("script:%s, user:%s connect taosd successed, attempt:%d", script->fileName, user, attempt);
- break;
- }
- }
-
- if (!success) {
- sprintf(script->error, "lineNum:%d. connect taosd failed:%s", script->lines[script->linePos].lineNum,
- taos_errstr(NULL));
- return false;
- }
-
- simDebug("script:%s, connect taosd successed, auth:%p", script->fileName, script->auth);
- return true;
-}
+void simCloseTaosdConnect(SScript *script) { simCloseNativeConnect(script); }
bool simCreateNativeConnect(SScript *script, char *user, char *pass) {
simCloseTaosdConnect(script);
@@ -651,7 +486,7 @@ bool simCreateNativeConnect(SScript *script, char *user, char *pass) {
return false;
}
- taos = taos_connect(NULL, user, pass, NULL, tsDnodeShellPort);
+ taos = taos_connect(NULL, user, pass, NULL, 0);
if (taos == NULL) {
simDebug("script:%s, user:%s connect taosd failed:%s, attempt:%d", script->fileName, user, taos_errstr(NULL),
attempt);
@@ -675,8 +510,8 @@ bool simCreateNativeConnect(SScript *script, char *user, char *pass) {
}
bool simCreateTaosdConnect(SScript *script, char *rest) {
- char * user = TSDB_DEFAULT_USER;
- char * token;
+ char *user = TSDB_DEFAULT_USER;
+ char *token;
int32_t tokenLen;
rest = paGetToken(rest, &token, &tokenLen);
rest = paGetToken(rest, &token, &tokenLen);
@@ -684,18 +519,14 @@ bool simCreateTaosdConnect(SScript *script, char *rest) {
user = token;
}
- if (simAsyncQuery) {
- return simCreateRestFulConnect(script, user, TSDB_DEFAULT_PASS);
- } else {
- return simCreateNativeConnect(script, user, TSDB_DEFAULT_PASS);
- }
+ return simCreateNativeConnect(script, user, TSDB_DEFAULT_PASS);
}
bool simExecuteNativeSqlCommand(SScript *script, char *rest, bool isSlow) {
char timeStr[30] = {0};
time_t tt;
struct tm *tp;
- SCmdLine * line = &script->lines[script->linePos];
+ SCmdLine *line = &script->lines[script->linePos];
int32_t ret = -1;
TAOS_RES *pSql = NULL;
@@ -710,7 +541,7 @@ bool simExecuteNativeSqlCommand(SScript *script, char *rest, bool isSlow) {
pSql = taos_query(script->taos, rest);
ret = taos_errno(pSql);
- if (ret == TSDB_CODE_MND_TABLE_ALREADY_EXIST || ret == TSDB_CODE_MND_DB_ALREADY_EXIST) {
+ if (ret == TSDB_CODE_MND_STB_ALREADY_EXIST || ret == TSDB_CODE_MND_DB_ALREADY_EXIST) {
simDebug("script:%s, taos:%p, %s success, ret:%d:%s", script->fileName, script->taos, rest, ret & 0XFFFF,
tstrerror(ret));
ret = 0;
@@ -756,7 +587,7 @@ bool simExecuteNativeSqlCommand(SScript *script, char *rest, bool isSlow) {
while ((row = taos_fetch_row(pSql))) {
if (numOfRows < MAX_QUERY_ROW_NUM) {
TAOS_FIELD *fields = taos_fetch_fields(pSql);
- int32_t * length = taos_fetch_lengths(pSql);
+ int32_t *length = taos_fetch_lengths(pSql);
for (int32_t i = 0; i < num_fields; i++) {
char *value = NULL;
@@ -780,7 +611,7 @@ bool simExecuteNativeSqlCommand(SScript *script, char *rest, bool isSlow) {
sprintf(value, "%d", *((int8_t *)row[i]));
break;
case TSDB_DATA_TYPE_UTINYINT:
- sprintf(value, "%u", *((uint8_t*)row[i]));
+ sprintf(value, "%u", *((uint8_t *)row[i]));
break;
case TSDB_DATA_TYPE_SMALLINT:
sprintf(value, "%d", *((int16_t *)row[i]));
@@ -846,7 +677,7 @@ bool simExecuteNativeSqlCommand(SScript *script, char *rest, bool isSlow) {
} else if (precision == TSDB_TIME_PRECISION_MICRO) {
sprintf(value, "%s.%06d", timeStr, (int32_t)(*((int64_t *)row[i]) % 1000000));
} else {
- sprintf(value, "%s.%09d", timeStr, (int32_t)(*((int64_t *)row[i]) % 1000000000));
+ sprintf(value, "%s.%09d", timeStr, (int32_t)(*((int64_t *)row[i]) % 1000000000));
}
break;
@@ -877,43 +708,8 @@ bool simExecuteNativeSqlCommand(SScript *script, char *rest, bool isSlow) {
return true;
}
-bool simExecuteRestFulSqlCommand(SScript *script, char *rest) {
- SCmdLine *line = &script->lines[script->linePos];
- char command[4096];
- sprintf(command, "curl -H 'Authorization: Taosd %s' -d \"%s\" 127.0.0.1:6041/rest/sql", script->auth, rest);
-
- int32_t ret = -1;
- for (int32_t attempt = 0; attempt < 10; ++attempt) {
- ret = simExecuteRestFulCommand(script, command);
- if (ret == TSDB_CODE_MND_TABLE_ALREADY_EXIST || ret == TSDB_CODE_MND_DB_ALREADY_EXIST) {
- simDebug("script:%s, taos:%p, %s success, ret:%d:%s", script->fileName, script->taos, rest, ret & 0XFFFF,
- tstrerror(ret));
- ret = 0;
- break;
- } else if (ret != 0) {
- simDebug("script:%s, taos:%p, %s failed, ret:%d", script->fileName, script->taos, rest, ret);
-
- if (line->errorJump == SQL_JUMP_TRUE) {
- script->linePos = line->jump;
- return true;
- }
- taosMsleep(1000);
- } else {
- break;
- }
- }
-
- if (ret) {
- sprintf(script->error, "lineNum:%d. sql:%s failed, ret:%d", line->lineNum, rest, ret);
- return false;
- }
-
- script->linePos++;
- return true;
-}
-
bool simExecuteSqlImpCmd(SScript *script, char *rest, bool isSlow) {
- char buf[3000];
+ char buf[3000];
SCmdLine *line = &script->lines[script->linePos];
simVisuallizeOption(script, rest, buf);
@@ -935,7 +731,7 @@ bool simExecuteSqlImpCmd(SScript *script, char *rest, bool isSlow) {
return true;
}
- if ((!simAsyncQuery && script->taos == NULL) || (simAsyncQuery && script->auth[0] == 0)) {
+ if (script->taos == NULL) {
if (!simCreateTaosdConnect(script, "connect root")) {
if (line->errorJump == SQL_JUMP_TRUE) {
script->linePos = line->jump;
@@ -951,11 +747,7 @@ bool simExecuteSqlImpCmd(SScript *script, char *rest, bool isSlow) {
return true;
}
- if (simAsyncQuery) {
- return simExecuteRestFulSqlCommand(script, rest);
- } else {
- return simExecuteNativeSqlCommand(script, rest, isSlow);
- }
+ return simExecuteNativeSqlCommand(script, rest, isSlow);
}
bool simExecuteSqlCmd(SScript *script, char *rest) {
@@ -1010,7 +802,7 @@ bool simExecuteRestfulCmd(SScript *script, char *rest) {
}
bool simExecuteSqlErrorCmd(SScript *script, char *rest) {
- char buf[3000];
+ char buf[3000];
SCmdLine *line = &script->lines[script->linePos];
simVisuallizeOption(script, rest, buf);
@@ -1032,7 +824,7 @@ bool simExecuteSqlErrorCmd(SScript *script, char *rest) {
return true;
}
- if ((!simAsyncQuery && script->taos == NULL) || (simAsyncQuery && script->auth[0] == 0)) {
+ if (script->taos == NULL) {
if (!simCreateTaosdConnect(script, "connect root")) {
if (line->errorJump == SQL_JUMP_TRUE) {
script->linePos = line->jump;
@@ -1048,17 +840,9 @@ bool simExecuteSqlErrorCmd(SScript *script, char *rest) {
return true;
}
- int32_t ret;
- TAOS_RES *pSql = NULL;
- if (simAsyncQuery) {
- char command[4096];
- sprintf(command, "curl -H 'Authorization: Taosd %s' -d '%s' 127.0.0.1:6041/rest/sql", script->auth, rest);
- ret = simExecuteRestFulCommand(script, command);
- } else {
- pSql = taos_query(script->taos, rest);
- ret = taos_errno(pSql);
- taos_free_result(pSql);
- }
+ TAOS_RES *pSql = pSql = taos_query(script->taos, rest);
+ int32_t ret = taos_errno(pSql);
+ taos_free_result(pSql);
if (ret != TSDB_CODE_SUCCESS) {
simDebug("script:%s, taos:%p, %s execute, expect failed, so success, ret:%d:%s", script->fileName, script->taos,
@@ -1083,15 +867,19 @@ bool simExecuteLineInsertCmd(SScript *script, char *rest) {
simInfo("script:%s, %s", script->fileName, rest);
simLogSql(buf, true);
- char * lines[] = {rest};
+ char *lines[] = {rest};
+#if 0
int32_t ret = taos_insert_lines(script->taos, lines, 1);
+#else
+ int32_t ret = 0;
+#endif
if (ret == TSDB_CODE_SUCCESS) {
simDebug("script:%s, taos:%p, %s executed. success.", script->fileName, script->taos, rest);
script->linePos++;
return true;
} else {
- sprintf(script->error, "lineNum: %d. line: %s failed, ret:%d:%s", line->lineNum, rest,
- ret & 0XFFFF, tstrerror(ret));
+ sprintf(script->error, "lineNum: %d. line: %s failed, ret:%d:%s", line->lineNum, rest, ret & 0XFFFF,
+ tstrerror(ret));
return false;
}
}
@@ -1106,15 +894,20 @@ bool simExecuteLineInsertErrorCmd(SScript *script, char *rest) {
simInfo("script:%s, %s", script->fileName, rest);
simLogSql(buf, true);
- char * lines[] = {rest};
+ char *lines[] = {rest};
+#if 0
int32_t ret = taos_insert_lines(script->taos, lines, 1);
+#else
+ int32_t ret = 0;
+#endif
if (ret == TSDB_CODE_SUCCESS) {
- sprintf(script->error, "script:%s, taos:%p, %s executed. expect failed, but success.", script->fileName, script->taos, rest);
+ sprintf(script->error, "script:%s, taos:%p, %s executed. expect failed, but success.", script->fileName,
+ script->taos, rest);
script->linePos++;
return false;
} else {
- simDebug("lineNum: %d. line: %s failed, ret:%d:%s. Expect failed, so success", line->lineNum, rest,
- ret & 0XFFFF, tstrerror(ret));
+ simDebug("lineNum: %d. line: %s failed, ret:%d:%s. Expect failed, so success", line->lineNum, rest, ret & 0XFFFF,
+ tstrerror(ret));
return true;
}
}
diff --git a/tests/tsim/src/simMain.c b/tests/tsim/src/simMain.c
index 7d74c62c7daf391fed1bf1afac233f51b84c8f0b..19d23daaceb61cf7f6b12db9b80a057eb9700e8a 100644
--- a/tests/tsim/src/simMain.c
+++ b/tests/tsim/src/simMain.c
@@ -15,19 +15,17 @@
#define _DEFAULT_SOURCE
#include "os.h"
-#include "tglobal.h"
#include "sim.h"
-#undef TAOS_MEM_CHECK
+#include "tglobal.h"
-bool simAsyncQuery = false;
bool simExecSuccess = false;
bool abortExecution = false;
void simHandleSignal(int32_t signo, void *sigInfo, void *context) {
simSystemCleanUp();
abortExecution = true;
-// runningScript->killed = true;
-// exit(1);
+ // runningScript->killed = true;
+ // exit(1);
}
int32_t main(int32_t argc, char *argv[]) {
@@ -38,8 +36,6 @@ int32_t main(int32_t argc, char *argv[]) {
tstrncpy(configDir, argv[++i], 128);
} else if (strcmp(argv[i], "-f") == 0 && i < argc - 1) {
strcpy(scriptFile, argv[++i]);
- } else if (strcmp(argv[i], "-a") == 0) {
- simAsyncQuery = true;
} else {
printf("usage: %s [options] \n", argv[0]);
printf(" [-c config]: config directory, default is: %s\n", configDir);
diff --git a/tests/tsim/src/simParse.c b/tests/tsim/src/simParse.c
index 1acdcd2ac6eb0ecb66e2977dee7577393ed242ef..0dfd5f4f3e920f68b94cf74d424f30c7021c61ba 100644
--- a/tests/tsim/src/simParse.c
+++ b/tests/tsim/src/simParse.c
@@ -60,9 +60,9 @@
#define _DEFAULT_SOURCE
#include "os.h"
#include "sim.h"
-#include "simParse.h"
#include "tutil.h"
-#undef TAOS_MEM_CHECK
+
+#include "simParse.h"
static SCommand *cmdHashList[MAX_NUM_CMD];
static SCmdLine cmdLine[MAX_CMD_LINES];
@@ -177,11 +177,11 @@ SScript *simBuildScriptObj(char *fileName) {
}
SScript *simParseScript(char *fileName) {
- FILE * fd;
+ FILE *fd;
int32_t tokenLen, lineNum = 0;
char buffer[MAX_LINE_LEN], name[128], *token, *rest;
SCommand *pCmd;
- SScript * script;
+ SScript *script;
if ((fileName[0] == '.') || (fileName[0] == '/')) {
strcpy(name, fileName);
@@ -252,7 +252,7 @@ SScript *simParseScript(char *fileName) {
}
int32_t simCheckExpression(char *exp) {
- char * op1, *op2, *op, *rest;
+ char *op1, *op2, *op, *rest;
int32_t op1Len, op2Len, opLen;
rest = paGetToken(exp, &op1, &op1Len);
@@ -336,7 +336,7 @@ bool simParseExpression(char *token, int32_t lineNum) {
}
bool simParseIfCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
- char * ret;
+ char *ret;
int32_t expLen;
expLen = simCheckExpression(rest);
@@ -502,7 +502,7 @@ bool simParseEndwCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
}
bool simParseSwitchCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
- char * token;
+ char *token;
int32_t tokenLen;
rest = paGetToken(rest, &token, &tokenLen);
@@ -525,7 +525,7 @@ bool simParseSwitchCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
}
bool simParseCaseCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
- char * token;
+ char *token;
int32_t tokenLen;
rest = paGetToken(rest, &token, &tokenLen);
@@ -666,7 +666,7 @@ bool simParsePrintCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
void simCheckSqlOption(char *rest) {
int32_t valueLen;
- char * value, *xpos;
+ char *value, *xpos;
xpos = strstr(rest, " -x"); // need a blank
if (xpos) {
@@ -750,7 +750,7 @@ bool simParseSystemContentCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
}
bool simParseSleepCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
- char * token;
+ char *token;
int32_t tokenLen;
cmdLine[numOfLines].cmdno = SIM_CMD_SLEEP;
@@ -769,7 +769,7 @@ bool simParseSleepCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
}
bool simParseReturnCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
- char * token;
+ char *token;
int32_t tokenLen;
cmdLine[numOfLines].cmdno = SIM_CMD_RETURN;
@@ -788,7 +788,7 @@ bool simParseReturnCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
}
bool simParseGotoCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
- char * token;
+ char *token;
int32_t tokenLen;
rest = paGetToken(rest, &token, &tokenLen);
@@ -811,7 +811,7 @@ bool simParseGotoCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
}
bool simParseRunCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
- char * token;
+ char *token;
int32_t tokenLen;
rest = paGetToken(rest, &token, &tokenLen);
@@ -838,7 +838,7 @@ bool simParseRunBackCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
return true;
}
-bool simParseLineInsertCmd(char* rest, SCommand* pCmd, int32_t lineNum) {
+bool simParseLineInsertCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
int32_t expLen;
rest++;
@@ -854,7 +854,7 @@ bool simParseLineInsertCmd(char* rest, SCommand* pCmd, int32_t lineNum) {
return true;
}
-bool simParseLineInsertErrorCmd(char* rest, SCommand* pCmd, int32_t lineNum) {
+bool simParseLineInsertErrorCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
int32_t expLen;
rest++;
diff --git a/tests/tsim/src/simSystem.c b/tests/tsim/src/simSystem.c
index 65612930ef3288cd260a795a6f4f037559457593..cb61e6b81454fc1828105081b9d646f4159c8564 100644
--- a/tests/tsim/src/simSystem.c
+++ b/tests/tsim/src/simSystem.c
@@ -14,15 +14,15 @@
*/
#define _DEFAULT_SOURCE
-#include "../../../include/client/taos.h"
#include "os.h"
#include "sim.h"
+#include "taos.h"
#include "taoserror.h"
#include "tglobal.h"
-#include "tsocket.h"
#include "ttimer.h"
#include "tutil.h"
-#undef TAOS_MEM_CHECK
+#include "tglobal.h"
+#include "tconfig.h"
SScript *simScriptList[MAX_MAIN_SCRIPT_NUM];
SCommand simCmdList[SIM_CMD_END];
@@ -81,10 +81,11 @@ char *simParseHostName(char *varName) {
}
bool simSystemInit() {
- if (taos_init()) {
- return false;
- }
taosGetFqdn(simHostName);
+
+ taosInitGlobalCfg();
+ taosReadCfgFromFile();
+
simInitsimCmdList();
memset(simScriptList, 0, sizeof(SScript *) * MAX_MAIN_SCRIPT_NUM);
return true;
@@ -171,7 +172,7 @@ void *simExecuteScript(void *inputScript) {
}
} else {
SCmdLine *line = &script->lines[script->linePos];
- char * option = script->optionBuffer + line->optionOffset;
+ char *option = script->optionBuffer + line->optionOffset;
simDebug("script:%s, line:%d with option \"%s\"", script->fileName, line->lineNum, option);
SCommand *cmd = &simCmdList[line->cmdno];
diff --git a/tools/shell/inc/shellCommand.h b/tools/shell/inc/shellCommand.h
index 6e4d3e382e3d7e8c50405c07da8ed73725230434..49f7dc01331e810864f87bd5b65fb13815fc7719 100644
--- a/tools/shell/inc/shellCommand.h
+++ b/tools/shell/inc/shellCommand.h
@@ -13,8 +13,8 @@
* along with this program. If not, see .
*/
-#ifndef __COMMAND_STRUCT__
-#define __COMMAND_STRUCT__
+#ifndef _TD_SHELL_COMMAND_H_
+#define _TD_SHELL_COMMAND_H_
#include "shell.h"
diff --git a/tools/shell/src/shellLinux.c b/tools/shell/src/shellLinux.c
index 766a57c968a7e39e5d80c1316920615fb82b7285..81d8c0a35bf86acc47c5f040c18ac97a6d97d53c 100644
--- a/tools/shell/src/shellLinux.c
+++ b/tools/shell/src/shellLinux.c
@@ -219,7 +219,9 @@ void shellParseArgument(int argc, char *argv[], SShellArguments *arguments) {
argp_parse(&argp, argc, argv, 0, 0, arguments);
if (arguments->abort) {
#ifndef _ALPINE
+ #if 0
error(10, 0, "ABORTED");
+ #endif
#else
abort();
#endif