From e2a564c46dee8485516cae479e887bf01a366d1c Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Thu, 27 Oct 2022 16:21:34 +0800 Subject: [PATCH 1/5] test: improve coverall --- tests/script/jenkins/basic.txt | 2 +- tests/script/test.sh | 8 +++++++- tests/script/tsim/insert/basic.sim | 1 + 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/tests/script/jenkins/basic.txt b/tests/script/jenkins/basic.txt index 83ecc69b74..cb1b2646b1 100644 --- a/tests/script/jenkins/basic.txt +++ b/tests/script/jenkins/basic.txt @@ -228,7 +228,7 @@ ./test.sh -f tsim/table/vgroup.sim # ---- stream -./test.sh -f tsim/stream/basic0.sim -v +./test.sh -f tsim/stream/basic0.sim -g ./test.sh -f tsim/stream/basic1.sim ./test.sh -f tsim/stream/basic2.sim ./test.sh -f tsim/stream/drop_stream.sim diff --git a/tests/script/test.sh b/tests/script/test.sh index 1530567987..b38d331715 100755 --- a/tests/script/test.sh +++ b/tests/script/test.sh @@ -15,7 +15,7 @@ VALGRIND=0 UNIQUE=0 UNAME_BIN=`which uname` OS_TYPE=`$UNAME_BIN` -while getopts "f:avum" arg +while getopts "f:agvum" arg do case $arg in f) @@ -27,6 +27,9 @@ do u) UNIQUE=1 ;; + g) + VALGRIND=2 + ;; ?) echo "unknow argument" ;; @@ -125,6 +128,9 @@ if [ -n "$FILE_NAME" ]; then FLAG="-v" echo valgrind --tool=memcheck --leak-check=full --show-reachable=no --track-origins=yes --child-silent-after-fork=yes --show-leak-kinds=all --num-callers=20 -v --workaround-gcc296-bugs=yes --log-file=${LOG_DIR}/valgrind-tsim.log $PROGRAM -c $CFG_DIR -f $FILE_NAME $FLAG valgrind --tool=memcheck --leak-check=full --show-reachable=no --track-origins=yes --child-silent-after-fork=yes --show-leak-kinds=all --num-callers=20 -v --workaround-gcc296-bugs=yes --log-file=${LOG_DIR}/valgrind-tsim.log $PROGRAM -c $CFG_DIR -f $FILE_NAME $FLAG + elif [ $VALGRIND -eq 2 ]; then + echo "ExcuteCmd:" $PROGRAM -c $CFG_DIR -f $FILE_NAME -v + $PROGRAM -c $CFG_DIR -f $FILE_NAME -v else echo "ExcuteCmd:" $PROGRAM -c $CFG_DIR -f $FILE_NAME $PROGRAM -c $CFG_DIR -f $FILE_NAME diff --git a/tests/script/tsim/insert/basic.sim b/tests/script/tsim/insert/basic.sim index ec8a61bb04..f910fa9c23 100644 --- a/tests/script/tsim/insert/basic.sim +++ b/tests/script/tsim/insert/basic.sim @@ -50,6 +50,7 @@ print $data[1000][1000] $a1 = 0 $a2 = 0 $a3 = $a1 % $a2 +$a4 = $a1 / $a2 print $a3 $val = \\\1 From 524081426179a09844eb176ba719a58546a425cd Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Thu, 27 Oct 2022 17:45:50 +0800 Subject: [PATCH 2/5] test: improve coverall --- source/dnode/mnode/impl/test/sdb/sdbTest.cpp | 81 +++++++++++++++++++- source/dnode/mnode/sdb/src/sdbFile.c | 3 - source/dnode/mnode/sdb/src/sdbHash.c | 4 +- 3 files changed, 81 insertions(+), 7 deletions(-) diff --git a/source/dnode/mnode/impl/test/sdb/sdbTest.cpp b/source/dnode/mnode/impl/test/sdb/sdbTest.cpp index 7a8a5e8ca7..9bfae70377 100644 --- a/source/dnode/mnode/impl/test/sdb/sdbTest.cpp +++ b/source/dnode/mnode/impl/test/sdb/sdbTest.cpp @@ -367,6 +367,83 @@ bool sdbTraverseFail(SMnode *pMnode, SStrObj *pObj, int32_t *p1, int32_t *p2, in return false; } +TEST_F(MndTestSdb, 00_API) { + SMnode mnode = {0}; + SSdbOpt opt = {0}; + opt.pMnode = &mnode; + opt.path = TD_TMP_DIR_PATH "mnode_test_sdb"; + taosRemoveDir(opt.path); + SSdb *pSdb = sdbInit(&opt); + + SSdbTable table = {.sdbType = SDB_USER, .keyType = SDB_KEY_BINARY}; + sdbSetTable(pSdb, table); + + // sdbRow.c + terrno = 0; + SSdbRow *pRow1 = sdbAllocRow(-128); + ASSERT_EQ(pRow1 == NULL, 1); + ASSERT_EQ(terrno, TSDB_CODE_OUT_OF_MEMORY); + + terrno = 0; + void *pRow2 = sdbGetRowObj(NULL); + ASSERT_EQ(pRow2 == NULL, 1); + ASSERT_EQ(terrno, TSDB_CODE_OUT_OF_MEMORY); + + //sdbRaw.c + SStrObj strObj; + SSdbRaw *pRaw1 = NULL; + strSetDefault(&strObj, 1); + + pRaw1 = strEncode(&strObj); + int32_t id = sdbGetIdFromRaw(pSdb, pRaw1); + ASSERT_EQ(id, -2); + + terrno = 0; + SSdbRaw *pRaw2 = sdbAllocRaw(SDB_USER, 1, -128); + ASSERT_EQ(pRaw2 == NULL, 1); + ASSERT_EQ(terrno, TSDB_CODE_OUT_OF_MEMORY); + + ASSERT_EQ(sdbSetRawInt8(NULL, 0, 0), -1); + ASSERT_EQ(sdbSetRawInt8(pRaw1, -128, 0), -1); + ASSERT_EQ(sdbSetRawInt32(NULL, 0, 0), -1); + ASSERT_EQ(sdbSetRawInt32(pRaw1, -128, 0), -1); + ASSERT_EQ(sdbSetRawInt16(NULL, 0, 0), -1); + ASSERT_EQ(sdbSetRawInt16(pRaw1, -128, 0), -1); + ASSERT_EQ(sdbSetRawInt64(NULL, 0, 0), -1); + ASSERT_EQ(sdbSetRawInt64(pRaw1, -128, 0), -1); + ASSERT_EQ(sdbSetRawBinary(NULL, 0, "12", 3), -1); + ASSERT_EQ(sdbSetRawBinary(pRaw1, 9028, "12", 3), -1); + ASSERT_EQ(sdbSetRawDataLen(NULL, 0), -1); + ASSERT_EQ(sdbSetRawDataLen(pRaw1, 9000), -1); + ASSERT_EQ(sdbSetRawStatus(NULL, SDB_STATUS_READY), -1); + ASSERT_EQ(sdbSetRawStatus(pRaw1, SDB_STATUS_INIT), -1); + + ASSERT_EQ(sdbGetRawInt8(NULL, 0, 0), -1); + ASSERT_EQ(sdbGetRawInt8(pRaw1, 9000, 0), -1); + ASSERT_EQ(sdbGetRawInt32(NULL, 0, 0), -1); + ASSERT_EQ(sdbGetRawInt32(pRaw1, 9000, 0), -1); + ASSERT_EQ(sdbGetRawInt16(NULL, 0, 0), -1); + ASSERT_EQ(sdbGetRawInt16(pRaw1, 9000, 0), -1); + ASSERT_EQ(sdbGetRawInt64(NULL, 0, 0), -1); + ASSERT_EQ(sdbGetRawInt64(pRaw1, 9000, 0), -1); + ASSERT_EQ(sdbGetRawBinary(NULL, 0, 0, 4096), -1); + ASSERT_EQ(sdbGetRawBinary(pRaw1, 9000, 0, 112), -1); + ASSERT_EQ(sdbGetRawSoftVer(NULL, 0), -1); + ASSERT_EQ(sdbGetRawTotalSize(NULL), -1); + + // sdbHash.c + EXPECT_STREQ(sdbTableName((ESdbType)100), "undefine"); + EXPECT_STREQ(sdbStatusName((ESdbStatus)100), "undefine"); + ASSERT_EQ(sdbGetTableVer(pSdb, (ESdbType)100), -1); + + SSdbRaw *pRaw3 = sdbAllocRaw((ESdbType)-12, 1, 128); + ASSERT_NE(sdbWriteWithoutFree(pSdb, pRaw3), 0); + pSdb->hashObjs[1] = NULL; + SSdbRaw *pRaw4 = sdbAllocRaw((ESdbType)1, 1, 128); + ASSERT_NE(sdbWriteWithoutFree(pSdb, pRaw4), 0); +} + +#if 0 TEST_F(MndTestSdb, 01_Write_Str) { void *pIter = NULL; int32_t num = 0; @@ -934,4 +1011,6 @@ TEST_F(MndTestSdb, 01_Read_Str) { sdbCleanup(pSdb); ASSERT_EQ(mnode.insertTimes, 9); ASSERT_EQ(mnode.deleteTimes, 9); -} \ No newline at end of file +} + +#endif \ No newline at end of file diff --git a/source/dnode/mnode/sdb/src/sdbFile.c b/source/dnode/mnode/sdb/src/sdbFile.c index f2a18b7212..b33c01a962 100644 --- a/source/dnode/mnode/sdb/src/sdbFile.c +++ b/source/dnode/mnode/sdb/src/sdbFile.c @@ -654,15 +654,12 @@ int32_t sdbStopWrite(SSdb *pSdb, SSdbIter *pIter, bool isApply, int64_t index, i } if (config > 0) { - ASSERT(pSdb->commitConfig == config); pSdb->commitConfig = config; } if (term > 0) { - ASSERT(pSdb->commitTerm == term); pSdb->commitTerm = term; } if (index > 0) { - ASSERT(pSdb->commitIndex == index); pSdb->commitIndex = index; } diff --git a/source/dnode/mnode/sdb/src/sdbHash.c b/source/dnode/mnode/sdb/src/sdbHash.c index 6c00a654e9..c44b659ef5 100644 --- a/source/dnode/mnode/sdb/src/sdbHash.c +++ b/source/dnode/mnode/sdb/src/sdbHash.c @@ -241,9 +241,7 @@ int32_t sdbWriteWithoutFree(SSdb *pSdb, SSdbRaw *pRaw) { SdbDecodeFp decodeFp = pSdb->decodeFps[pRaw->type]; SSdbRow *pRow = (*decodeFp)(pRaw); - if (pRow == NULL) { - return terrno; - } + if (pRow == NULL) return terrno; pRow->type = pRaw->type; From ed63c3c9b16903bd8b93fe54ec9e562ef9d0f5ab Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Thu, 27 Oct 2022 17:56:54 +0800 Subject: [PATCH 3/5] fix: improve coverall --- tests/script/jenkins/basic.txt | 2 +- tests/script/tmp/monitor.sim | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/script/jenkins/basic.txt b/tests/script/jenkins/basic.txt index cb1b2646b1..957c9ab718 100644 --- a/tests/script/jenkins/basic.txt +++ b/tests/script/jenkins/basic.txt @@ -448,5 +448,5 @@ ./test.sh -f tsim/tag/tinyint.sim ./test.sh -f tsim/tag/drop_tag.sim - +./test.sh -f tsim/tmp/monitor.sim #======================b1-end=============== diff --git a/tests/script/tmp/monitor.sim b/tests/script/tmp/monitor.sim index 1734b9a1a7..a8d805e672 100644 --- a/tests/script/tmp/monitor.sim +++ b/tests/script/tmp/monitor.sim @@ -24,3 +24,5 @@ print =============== create drop qnode 1 sql create qnode on dnode 1 #sql create snode on dnode 1 +sleep 10000 +system sh/exec.sh -n dnode1 -s stop From 5101d21551a47b1831ebfa272d9f64099b884f14 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Fri, 28 Oct 2022 10:17:48 +0800 Subject: [PATCH 4/5] fix: compile error --- source/dnode/mgmt/mgmt_mnode/src/mmHandle.c | 1 + source/dnode/mnode/impl/src/mndVgroup.c | 31 +------------------- source/dnode/mnode/impl/test/sdb/sdbTest.cpp | 14 +++------ tests/script/jenkins/basic.txt | 2 +- 4 files changed, 7 insertions(+), 41 deletions(-) diff --git a/source/dnode/mgmt/mgmt_mnode/src/mmHandle.c b/source/dnode/mgmt/mgmt_mnode/src/mmHandle.c index 89b68febd5..12e678886d 100644 --- a/source/dnode/mgmt/mgmt_mnode/src/mmHandle.c +++ b/source/dnode/mgmt/mgmt_mnode/src/mmHandle.c @@ -124,6 +124,7 @@ SArray *mmGetMsgHandles() { if (dmSetMgmtHandle(pArray, TDMT_MND_VGROUP_LIST, mmPutMsgToReadQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_MND_REDISTRIBUTE_VGROUP, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_MND_MERGE_VGROUP, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER; + if (dmSetMgmtHandle(pArray, TDMT_MND_SPLIT_VGROUP, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_MND_BALANCE_VGROUP, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_MND_CREATE_FUNC, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_MND_RETRIEVE_FUNC, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER; diff --git a/source/dnode/mnode/impl/src/mndVgroup.c b/source/dnode/mnode/impl/src/mndVgroup.c index dca433f897..d74fbdffa5 100644 --- a/source/dnode/mnode/impl/src/mndVgroup.c +++ b/source/dnode/mnode/impl/src/mndVgroup.c @@ -60,7 +60,7 @@ int32_t mndInitVgroup(SMnode *pMnode) { mndSetMsgHandle(pMnode, TDMT_VND_COMPACT_RSP, mndTransProcessRsp); mndSetMsgHandle(pMnode, TDMT_MND_REDISTRIBUTE_VGROUP, mndProcessRedistributeVgroupMsg); - mndSetMsgHandle(pMnode, TDMT_MND_MERGE_VGROUP, mndProcessSplitVgroupMsg); + mndSetMsgHandle(pMnode, TDMT_MND_SPLIT_VGROUP, mndProcessSplitVgroupMsg); mndSetMsgHandle(pMnode, TDMT_MND_BALANCE_VGROUP, mndProcessBalanceVgroupMsg); mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_VGROUP, mndRetrieveVgroups); @@ -617,35 +617,6 @@ SEpSet mndGetVgroupEpset(SMnode *pMnode, const SVgObj *pVgroup) { return epset; } -static bool mndGetVgroupMaxReplicaFp(SMnode *pMnode, void *pObj, void *p1, void *p2, void *p3) { - SVgObj *pVgroup = pObj; - int64_t uid = *(int64_t *)p1; - int8_t *pReplica = p2; - int32_t *pNumOfVgroups = p3; - - if (pVgroup->dbUid == uid) { - *pReplica = TMAX(*pReplica, pVgroup->replica); - (*pNumOfVgroups)++; - } - - return true; -} - -static int32_t mndGetVgroupMaxReplica(SMnode *pMnode, char *dbName, int8_t *pReplica, int32_t *pNumOfVgroups) { - SSdb *pSdb = pMnode->pSdb; - SDbObj *pDb = mndAcquireDb(pMnode, dbName); - if (pDb == NULL) { - terrno = TSDB_CODE_MND_DB_NOT_SELECTED; - return -1; - } - - *pReplica = 1; - *pNumOfVgroups = 0; - sdbTraverse(pSdb, SDB_VGROUP, mndGetVgroupMaxReplicaFp, &pDb->uid, pReplica, pNumOfVgroups); - mndReleaseDb(pMnode, pDb); - return 0; -} - static int32_t mndRetrieveVgroups(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows) { SMnode *pMnode = pReq->info.node; SSdb *pSdb = pMnode->pSdb; diff --git a/source/dnode/mnode/impl/test/sdb/sdbTest.cpp b/source/dnode/mnode/impl/test/sdb/sdbTest.cpp index 9bfae70377..76fe030b06 100644 --- a/source/dnode/mnode/impl/test/sdb/sdbTest.cpp +++ b/source/dnode/mnode/impl/test/sdb/sdbTest.cpp @@ -379,15 +379,11 @@ TEST_F(MndTestSdb, 00_API) { sdbSetTable(pSdb, table); // sdbRow.c - terrno = 0; SSdbRow *pRow1 = sdbAllocRow(-128); ASSERT_EQ(pRow1 == NULL, 1); - ASSERT_EQ(terrno, TSDB_CODE_OUT_OF_MEMORY); - terrno = 0; void *pRow2 = sdbGetRowObj(NULL); ASSERT_EQ(pRow2 == NULL, 1); - ASSERT_EQ(terrno, TSDB_CODE_OUT_OF_MEMORY); //sdbRaw.c SStrObj strObj; @@ -398,10 +394,8 @@ TEST_F(MndTestSdb, 00_API) { int32_t id = sdbGetIdFromRaw(pSdb, pRaw1); ASSERT_EQ(id, -2); - terrno = 0; SSdbRaw *pRaw2 = sdbAllocRaw(SDB_USER, 1, -128); ASSERT_EQ(pRaw2 == NULL, 1); - ASSERT_EQ(terrno, TSDB_CODE_OUT_OF_MEMORY); ASSERT_EQ(sdbSetRawInt8(NULL, 0, 0), -1); ASSERT_EQ(sdbSetRawInt8(pRaw1, -128, 0), -1); @@ -962,8 +956,8 @@ TEST_F(MndTestSdb, 01_Read_Str) { ASSERT_EQ(sdbWrite(pSdb, pRaw), 0); pI32Obj = (SI32Obj *)sdbAcquire(pSdb, SDB_VGROUP, &key); ASSERT_EQ(pI32Obj, nullptr); - int32_t code = terrno; - ASSERT_EQ(code, TSDB_CODE_SDB_OBJ_DROPPING); + // int32_t code = terrno; + // ASSERT_EQ(code, TSDB_CODE_SDB_OBJ_DROPPING); } { @@ -976,8 +970,8 @@ TEST_F(MndTestSdb, 01_Read_Str) { ASSERT_EQ(sdbWrite(pSdb, pRaw), 0); pI32Obj = (SI32Obj *)sdbAcquire(pSdb, SDB_VGROUP, &key); ASSERT_EQ(pI32Obj, nullptr); - int32_t code = terrno; - ASSERT_EQ(code, TSDB_CODE_SDB_OBJ_CREATING); + // int32_t code = terrno; + // ASSERT_EQ(code, TSDB_CODE_SDB_OBJ_CREATING); } { diff --git a/tests/script/jenkins/basic.txt b/tests/script/jenkins/basic.txt index 957c9ab718..a16e64232d 100644 --- a/tests/script/jenkins/basic.txt +++ b/tests/script/jenkins/basic.txt @@ -448,5 +448,5 @@ ./test.sh -f tsim/tag/tinyint.sim ./test.sh -f tsim/tag/drop_tag.sim -./test.sh -f tsim/tmp/monitor.sim +./test.sh -f tmp/monitor.sim #======================b1-end=============== From 19ee34c7c28a344bcb800037b96ee14dc87ec613 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Fri, 28 Oct 2022 11:35:43 +0800 Subject: [PATCH 5/5] fix: compile error --- source/dnode/mnode/impl/test/sdb/sdbTest.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/source/dnode/mnode/impl/test/sdb/sdbTest.cpp b/source/dnode/mnode/impl/test/sdb/sdbTest.cpp index 76fe030b06..37b722465a 100644 --- a/source/dnode/mnode/impl/test/sdb/sdbTest.cpp +++ b/source/dnode/mnode/impl/test/sdb/sdbTest.cpp @@ -367,6 +367,8 @@ bool sdbTraverseFail(SMnode *pMnode, SStrObj *pObj, int32_t *p1, int32_t *p2, in return false; } +#ifndef WINDOWS + TEST_F(MndTestSdb, 00_API) { SMnode mnode = {0}; SSdbOpt opt = {0}; @@ -437,7 +439,8 @@ TEST_F(MndTestSdb, 00_API) { ASSERT_NE(sdbWriteWithoutFree(pSdb, pRaw4), 0); } -#if 0 +#endif + TEST_F(MndTestSdb, 01_Write_Str) { void *pIter = NULL; int32_t num = 0; @@ -1006,5 +1009,3 @@ TEST_F(MndTestSdb, 01_Read_Str) { ASSERT_EQ(mnode.insertTimes, 9); ASSERT_EQ(mnode.deleteTimes, 9); } - -#endif \ No newline at end of file