diff --git a/.travis.yml b/.travis.yml index 8413a009777eb1ff5eef0b574b9d0703eeb8c84e..994928bb01b1ec3676c2168625cd5f68af21bb43 100644 --- a/.travis.yml +++ b/.travis.yml @@ -24,10 +24,11 @@ matrix: - python-setuptools - python3-pip - python3-setuptools + - valgrind before_install: - sudo apt update -y -qq - - sudo apt install -y net-tools python-pip python-setuptools python3-pip python3-setuptools + - sudo apt install -y net-tools python-pip python-setuptools python3-pip python3-setuptools valgrind before_script: - cd ${TRAVIS_BUILD_DIR} @@ -43,16 +44,32 @@ matrix: case $TRAVIS_OS_NAME in linux) cd ${TRAVIS_BUILD_DIR}/debug - sudo make install || exit $? + sudo make install || travis_terminate $? pip install --user ${TRAVIS_BUILD_DIR}/src/connector/python/linux/python2/ pip3 install --user ${TRAVIS_BUILD_DIR}/src/connector/python/linux/python3/ cd ${TRAVIS_BUILD_DIR}/tests - bash ./test-all.sh + ./test-all.sh || travis_terminate $? - if [ "$?" -ne "0" ]; then - exit $? + cd ${TRAVIS_BUILD_DIR}/tests/pytest + ./simpletest.sh -g 2>&1 | tee mem-error-out.txt + sleep 1 + + # Color setting + RED='\033[0;31m' + GREEN='\033[1;32m' + GREEN_DARK='\033[0;32m' + GREEN_UNDERLINE='\033[4;32m' + NC='\033[0m' + + memError=`grep -m 1 'ERROR SUMMARY' mem-error-out.txt | awk '{print $4}'` + + if [ -n "$memError" ]; then + if [ "$memError" -gt 23 ]; then + echo -e "${RED} ## Memory errors number valgrind reports is $memError. More than our threshold! ## ${NC} " + travis_terminate $memError + fi fi ;; @@ -74,12 +91,12 @@ matrix: # GitHub project metadata # ** specific to your project ** project: - name: sangshuduo/TDengine + name: TDengine version: 2.x - description: sangshuduo/TDengine + description: taosdata/TDengine # Where email notification of build analysis results will be sent - notification_email: sangshuduo@gmail.com + notification_email: sdsang@taosdata.com # Commands to prepare for build_command # ** likely specific to your build ** @@ -87,7 +104,7 @@ matrix: # The command that will be added as an argument to "cov-build" to compile your project for analysis, # ** likely specific to your build ** - build_command: cmake --build . + build_command: make # Pattern to match selecting branches that will run analysis. We recommend leaving this set to 'coverity_scan'. # Take care in resource usage, and consider the build frequency allowances per @@ -132,17 +149,17 @@ matrix: case $TRAVIS_OS_NAME in linux) cd ${TRAVIS_BUILD_DIR}/debug - sudo make install || exit $? + sudo make install || travis_terminate $? pip install --user ${TRAVIS_BUILD_DIR}/src/connector/python/linux/python2/ pip3 install --user ${TRAVIS_BUILD_DIR}/src/connector/python/linux/python3/ cd ${TRAVIS_BUILD_DIR}/tests - bash ./test-all.sh + ./test-all.sh if [ "$?" -ne "0" ]; then - exit $? + travis_terminate $? fi sudo pkill taosd @@ -150,7 +167,7 @@ matrix: cd ${TRAVIS_BUILD_DIR} lcov -d . --capture --rc lcov_branch_coverage=1 -o coverage.info - lcov -l --rc lcov_branch_coverage=1 coverage.info || exit $? + lcov -l --rc lcov_branch_coverage=1 coverage.info || travis_terminate $? gem install coveralls-lcov @@ -166,7 +183,6 @@ matrix: echo -e "${GREEN} ## Uploaded to Coveralls.io! ## ${NC}" else echo -e "${RED} ## Coveralls.io not collect coverage report! ## ${NC} " - exit $? fi bash <(curl -s https://codecov.io/bash) -y .codecov.yml -f coverage.info @@ -174,7 +190,6 @@ matrix: echo -e "${GREEN} ## Uploaded to Codecov! ## ${NC} " else echo -e "${RED} ## Codecov did not collect coverage report! ## ${NC} " - exit $? fi ;; diff --git a/src/client/inc/tsclient.h b/src/client/inc/tsclient.h index f225d546f387b0b10c85f506874f48f9e44a442d..bba45a672e53509c294b357905589f013611191f 100644 --- a/src/client/inc/tsclient.h +++ b/src/client/inc/tsclient.h @@ -465,7 +465,7 @@ extern void * tscQhandle; extern int tscKeepConn[]; extern int tsInsertHeadSize; extern int tscNumOfThreads; -extern SRpcIpSet tscMgmtIpList; +extern SRpcIpSet tscMgmtIpSet; typedef void (*__async_cb_func_t)(void *param, TAOS_RES *tres, int numOfRows); diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index ad5f9cd0afe0ae6195f4883648563b99d91d9227..d1fd3f9a2d3090af6e0e9acd83ea1541c6d09fa9 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -30,7 +30,7 @@ #define TSC_MGMT_VNODE 999 -SRpcIpSet tscMgmtIpList; +SRpcIpSet tscMgmtIpSet; SRpcIpSet tscDnodeIpSet; int (*tscBuildMsg[TSDB_SQL_MAX])(SSqlObj *pSql, SSqlInfo *pInfo) = {0}; @@ -58,35 +58,40 @@ static void tscSetDnodeIpList(SSqlObj* pSql, STableMeta* pTableMeta) { } void tscPrintMgmtIp() { - if (tscMgmtIpList.numOfIps <= 0) { - tscError("invalid mgmt IP list:%d", tscMgmtIpList.numOfIps); + if (tscMgmtIpSet.numOfIps <= 0) { + tscError("invalid mgmt IP list:%d", tscMgmtIpSet.numOfIps); } else { - for (int i = 0; i < tscMgmtIpList.numOfIps; ++i) { - tscTrace("mgmt index:%d ip:%d", i, tscMgmtIpList.ip[i]); + for (int i = 0; i < tscMgmtIpSet.numOfIps; ++i) { + tscTrace("mgmt index:%d ip:%d", i, tscMgmtIpSet.ip[i]); } } } void tscSetMgmtIpListFromCluster(SRpcIpSet *pIpList) { - tscMgmtIpList.numOfIps = htons(pIpList->numOfIps); - tscMgmtIpList.inUse = htons(pIpList->inUse); - tscMgmtIpList.port = htons(pIpList->port); - for (int32_t i = 0; i ip[i]; + tscMgmtIpSet.numOfIps = pIpList->numOfIps; + tscMgmtIpSet.inUse = pIpList->inUse; + tscMgmtIpSet.port = htons(pIpList->port); + for (int32_t i = 0; i < tscMgmtIpSet.numOfIps; ++i) { + tscMgmtIpSet.ip[i] = htonl(pIpList->ip[i]); } } void tscSetMgmtIpListFromEdge() { - if (tscMgmtIpList.numOfIps != 1) { - tscMgmtIpList.numOfIps = 1; - tscMgmtIpList.inUse = 0; - tscMgmtIpList.port = tsMnodeShellPort; - tscMgmtIpList.ip[0] = inet_addr(tsMasterIp); + if (tscMgmtIpSet.numOfIps != 1) { + tscMgmtIpSet.numOfIps = 1; + tscMgmtIpSet.inUse = 0; + tscMgmtIpSet.port = tsMnodeShellPort; + tscMgmtIpSet.ip[0] = inet_addr(tsMasterIp); tscTrace("edge mgmt IP list:"); tscPrintMgmtIp(); } } +void tscUpdateIpSet(void *ahandle, SRpcIpSet *pIpSet) { + tscTrace("mgmt IP list is changed for ufp is called"); + tscMgmtIpSet = *pIpSet; +} + void tscSetMgmtIpList(SRpcIpSet *pIpList) { /* * The iplist returned by the cluster edition is the current management nodes @@ -109,7 +114,7 @@ void tscSetMgmtIpList(SRpcIpSet *pIpList) { UNUSED_FUNC static int32_t tscGetMgmtConnMaxRetryTimes() { int32_t factor = 2; - return tscMgmtIpList.numOfIps * factor; + return tscMgmtIpSet.numOfIps * factor; } void tscProcessHeartBeatRsp(void *param, TAOS_RES *tres, int code) { @@ -204,7 +209,7 @@ int tscSendMsgToServer(SSqlObj *pSql) { }; rpcSendRequest(pVnodeConn, &pSql->ipList, &rpcMsg); } else { - pSql->ipList = tscMgmtIpList; + pSql->ipList = tscMgmtIpSet; pSql->ipList.port = tsMnodeShellPort; tscTrace("%p msg:%s is sent to server %d", pSql, taosMsg[pSql->cmd.msgType], pSql->ipList.port); @@ -425,7 +430,7 @@ int tscProcessSql(SSqlObj *pSql) { return pSql->res.code; } } else if (pSql->cmd.command < TSDB_SQL_LOCAL) { - pSql->ipList = tscMgmtIpList; + pSql->ipList = tscMgmtIpSet; } else { // local handler return (*tscProcessMsgRsp[pCmd->command])(pSql); } @@ -2224,10 +2229,7 @@ int tscProcessConnectRsp(SSqlObj *pSql) { assert(len <= tListLen(pObj->db)); strncpy(pObj->db, temp, tListLen(pObj->db)); -// SIpList * pIpList; -// char *rsp = pRes->pRsp + sizeof(SCMConnectRsp); -// pIpList = (SIpList *)rsp; -// tscSetMgmtIpList(pIpList); + tscSetMgmtIpList(&pConnect->ipList); strcpy(pObj->sversion, pConnect->serverVersion); pObj->writeAuth = pConnect->writeAuth; diff --git a/src/client/src/tscSql.c b/src/client/src/tscSql.c index 4f02a96eecf399ab1f025b2ce79af9e63676eeda..6fbd5e773960e34299d646c8f924a212599f9405 100644 --- a/src/client/src/tscSql.c +++ b/src/client/src/tscSql.c @@ -72,23 +72,23 @@ STscObj *taosConnectImpl(const char *ip, const char *user, const char *pass, con } if (ip && ip[0]) { - tscMgmtIpList.inUse = 0; - tscMgmtIpList.port = tsMnodeShellPort; - tscMgmtIpList.numOfIps = 1; - tscMgmtIpList.ip[0] = inet_addr(ip); + tscMgmtIpSet.inUse = 0; + tscMgmtIpSet.port = tsMnodeShellPort; + tscMgmtIpSet.numOfIps = 1; + tscMgmtIpSet.ip[0] = inet_addr(ip); if (tsMasterIp[0] && strcmp(ip, tsMasterIp) != 0) { - tscMgmtIpList.numOfIps = 2; - tscMgmtIpList.ip[1] = inet_addr(tsMasterIp); + tscMgmtIpSet.numOfIps = 2; + tscMgmtIpSet.ip[1] = inet_addr(tsMasterIp); } if (tsSecondIp[0] && strcmp(tsSecondIp, tsMasterIp) != 0) { - tscMgmtIpList.numOfIps = 3; - tscMgmtIpList.ip[2] = inet_addr(tsSecondIp); + tscMgmtIpSet.numOfIps = 3; + tscMgmtIpSet.ip[2] = inet_addr(tsSecondIp); } } - tscMgmtIpList.port = port ? port : tsMnodeShellPort; + tscMgmtIpSet.port = port ? port : tsMnodeShellPort; STscObj *pObj = (STscObj *)calloc(1, sizeof(STscObj)); if (NULL == pObj) { diff --git a/src/client/src/tscSystem.c b/src/client/src/tscSystem.c index a24ca4d0454a60704a6da10364380a23c17a53a3..68b11ce416c8224a375e3d4d2a09216e1b95f0ae 100644 --- a/src/client/src/tscSystem.c +++ b/src/client/src/tscSystem.c @@ -47,6 +47,7 @@ int tscNumOfThreads; static pthread_once_t tscinit = PTHREAD_ONCE_INIT; void taosInitNote(int numOfNoteLines, int maxNotes, char* lable); +void tscUpdateIpSet(void *ahandle, SRpcIpSet *pIpSet); void tscCheckDiskUsage(void *para, void *unused) { taosGetDisk(); @@ -65,6 +66,7 @@ int32_t tscInitRpc(const char *user, const char *secret) { rpcInit.label = "TSC-vnode"; rpcInit.numOfThreads = tscNumOfThreads; rpcInit.cfp = tscProcessMsgFromServer; + rpcInit.ufp = tscUpdateIpSet; rpcInit.sessions = tsMaxVnodeConnections; rpcInit.connType = TAOS_CONN_CLIENT; rpcInit.user = (char*)user; @@ -145,14 +147,14 @@ void taos_init_imp() { taosInitNote(tsNumOfLogLines / 10, 1, (char*)"tsc_note"); } - tscMgmtIpList.inUse = 0; - tscMgmtIpList.port = tsMnodeShellPort; - tscMgmtIpList.numOfIps = 1; - tscMgmtIpList.ip[0] = inet_addr(tsMasterIp); + tscMgmtIpSet.inUse = 0; + tscMgmtIpSet.port = tsMnodeShellPort; + tscMgmtIpSet.numOfIps = 1; + tscMgmtIpSet.ip[0] = inet_addr(tsMasterIp); if (tsSecondIp[0] && strcmp(tsSecondIp, tsMasterIp) != 0) { - tscMgmtIpList.numOfIps = 2; - tscMgmtIpList.ip[1] = inet_addr(tsSecondIp); + tscMgmtIpSet.numOfIps = 2; + tscMgmtIpSet.ip[1] = inet_addr(tsSecondIp); } tscInitMsgsFp(); diff --git a/src/dnode/src/dnodeMClient.c b/src/dnode/src/dnodeMClient.c index 8d5d0a02ec5eb1e805e8d7af690286b6997dbe86..78f4d076fc2e167510339d0f1669176afeacf271 100644 --- a/src/dnode/src/dnodeMClient.c +++ b/src/dnode/src/dnodeMClient.c @@ -54,6 +54,11 @@ static SRpcIpSet tsMnodeIpSet = {0}; static SDMMnodeInfos tsMnodeInfos = {0}; static SDMDnodeCfg tsDnodeCfg = {0}; +void dnodeUpdateIpSet(void *ahandle, SRpcIpSet *pIpSet) { + dTrace("mgmt IP list is changed for ufp is called"); + tsMnodeIpSet = *pIpSet; +} + int32_t dnodeInitMClient() { dnodeReadDnodeCfg(); tsRebootTime = taosGetTimestampSec(); @@ -90,6 +95,7 @@ int32_t dnodeInitMClient() { rpcInit.label = "DND-MC"; rpcInit.numOfThreads = 1; rpcInit.cfp = dnodeProcessRspFromMnode; + rpcInit.ufp = dnodeUpdateIpSet; rpcInit.sessions = 100; rpcInit.connType = TAOS_CONN_CLIENT; rpcInit.idleTime = tsShellActivityTimer * 2000; diff --git a/src/mnode/inc/mgmtMnode.h b/src/mnode/inc/mgmtMnode.h index f9f2909d9551c96460d3bf81aacda9be2fb4c81d..4fb57d71511f626c9f3db3b581cf426f0801f08a 100644 --- a/src/mnode/inc/mgmtMnode.h +++ b/src/mnode/inc/mgmtMnode.h @@ -40,7 +40,7 @@ void * mgmtGetNextMnode(void *pNode, struct SMnodeObj **pMnode); void mgmtReleaseMnode(struct SMnodeObj *pMnode); char * mgmtGetMnodeRoleStr(); -void mgmtGetMnodeIpList(SRpcIpSet *ipSet, bool usePublicIp); +void mgmtGetMnodeIpSet(SRpcIpSet *ipSet, bool usePublicIp); void mgmtGetMnodeInfos(void *mnodes); #ifdef __cplusplus diff --git a/src/mnode/src/mgmtDServer.c b/src/mnode/src/mgmtDServer.c index 80a87813d91d5a820e3c724a76148570134626d6..b551c0eae52d3a3694ba0d2c09e432f13dab1155 100644 --- a/src/mnode/src/mgmtDServer.c +++ b/src/mnode/src/mgmtDServer.c @@ -28,8 +28,10 @@ #include "mgmtLog.h" #include "mgmtDb.h" #include "mgmtDServer.h" +#include "mgmtMnode.h" #include "mgmtProfile.h" #include "mgmtShell.h" +#include "mgmtSdb.h" #include "mgmtTable.h" #include "mgmtVgroup.h" @@ -99,6 +101,18 @@ static void mgmtProcessMsgFromDnode(SRpcMsg *rpcMsg) { mgmtSendSimpleResp(rpcMsg->handle, TSDB_CODE_INVALID_MSG_LEN); return; } + + if (!sdbIsMaster()) { + SRpcConnInfo connInfo; + rpcGetConnInfo(rpcMsg->handle, &connInfo); + bool usePublicIp = false; + + SRpcIpSet ipSet = {0}; + mgmtGetMnodeIpSet(&ipSet, usePublicIp); + mTrace("conn from dnode ip:%s redirect msg", taosIpStr(connInfo.clientIp)); + rpcSendRedirectRsp(rpcMsg->handle, &ipSet); + return; + } if (mgmtProcessDnodeMsgFp[rpcMsg->msgType]) { SRpcMsg *pMsg = malloc(sizeof(SRpcMsg)); diff --git a/src/mnode/src/mgmtMnode.c b/src/mnode/src/mgmtMnode.c index 6546b8ea3783a3a2fe059de1166c0d78b7b7d7dc..05de2ecfdb7452be2dc7fbc1ecb3df54aa31635f 100644 --- a/src/mnode/src/mgmtMnode.c +++ b/src/mnode/src/mgmtMnode.c @@ -171,7 +171,7 @@ char *mgmtGetMnodeRoleStr(int32_t role) { } } -void mgmtGetMnodeIpList(SRpcIpSet *ipSet, bool usePublicIp) { +void mgmtGetMnodeIpSet(SRpcIpSet *ipSet, bool usePublicIp) { void *pNode = NULL; while (1) { SMnodeObj *pMnode = NULL; diff --git a/src/mnode/src/mgmtShell.c b/src/mnode/src/mgmtShell.c index 522968895ed91a41f425d44bc1c24b92d895fcc4..e2f393e6e9a3fc9edc1471f20129c081693a8482 100644 --- a/src/mnode/src/mgmtShell.c +++ b/src/mnode/src/mgmtShell.c @@ -141,13 +141,19 @@ void mgmtDealyedAddToShellQueue(SQueuedMsg *queuedMsg) { static void mgmtProcessMsgFromShell(SRpcMsg *rpcMsg) { if (rpcMsg == NULL || rpcMsg->pCont == NULL) { + mgmtSendSimpleResp(rpcMsg->handle, TSDB_CODE_INVALID_MSG_LEN); return; } if (!sdbIsMaster()) { - // rpcSendRedirectRsp(rpcMsg->handle, mgmtGetMnodeIpListForRedirect()); - mgmtSendSimpleResp(rpcMsg->handle, TSDB_CODE_NO_MASTER); - rpcFreeCont(rpcMsg->pCont); + SRpcConnInfo connInfo; + rpcGetConnInfo(rpcMsg->handle, &connInfo); + bool usePublicIp = (connInfo.serverIp == tsPublicIpInt); + + SRpcIpSet ipSet = {0}; + mgmtGetMnodeIpSet(&ipSet, usePublicIp); + mTrace("conn from ip:%s user:%s redirect msg", taosIpStr(connInfo.clientIp), connInfo.user); + rpcSendRedirectRsp(rpcMsg->handle, &ipSet); return; } @@ -332,7 +338,7 @@ static void mgmtProcessHeartBeatMsg(SQueuedMsg *pMsg) { return; } - mgmtGetMnodeIpList(&pHBRsp->ipList, pMsg->usePublicIp); + mgmtGetMnodeIpSet(&pHBRsp->ipList, pMsg->usePublicIp); /* * TODO @@ -357,6 +363,11 @@ static int mgmtShellRetriveAuth(char *user, char *spi, char *encrypt, char *secr *encrypt = 0; *ckey = 0; + if (!sdbIsMaster()) { + *secret = 0; + return TSDB_CODE_SUCCESS; + } + SUserObj *pUser = mgmtGetUser(user); if (pUser == NULL) { *secret = 0; @@ -414,7 +425,7 @@ static void mgmtProcessConnectMsg(SQueuedMsg *pMsg) { pConnectRsp->writeAuth = pUser->writeAuth; pConnectRsp->superAuth = pUser->superAuth; - mgmtGetMnodeIpList(&pConnectRsp->ipList, pMsg->usePublicIp); + mgmtGetMnodeIpSet(&pConnectRsp->ipList, pMsg->usePublicIp); connect_over: rpcRsp.code = code; diff --git a/tests/pytest/simpletest.sh b/tests/pytest/simpletest.sh index bffb3689b2f24136851e736b5b516c4aa96c621c..a6e023bde8c0a38a7d87b772639fed38233efb71 100755 --- a/tests/pytest/simpletest.sh +++ b/tests/pytest/simpletest.sh @@ -1 +1,3 @@ -sudo python ./test.py -f insert/basic.py +#!/bin/bash +python2 ./test.py -f insert/basic.py $1 +python2 ./test.py -s $1 diff --git a/tests/pytest/test.py b/tests/pytest/test.py index ea727d5f6ed09a079687f143cdf5ae33a7d315a2..f5d4cc7c2998f55bbfe5c9f94ad872357b4a4bab 100644 --- a/tests/pytest/test.py +++ b/tests/pytest/test.py @@ -15,6 +15,9 @@ # -*- coding: utf-8 -*- import sys import getopt +import subprocess +from distutils.log import warn as printf + from util.log import * from util.dnodes import * from util.cases import * @@ -29,8 +32,10 @@ if __name__ == "__main__": deployPath = "" masterIp = "" testCluster = False - opts, args = getopt.getopt(sys.argv[1:], 'f:p:m:sch', [ - 'file=', 'path=', 'master', 'stop', 'cluster', 'help']) + valgrind = 0 + stop = 0 + opts, args = getopt.gnu_getopt(sys.argv[1:], 'f:p:m:scgh', [ + 'file=', 'path=', 'master', 'stop', 'cluster', 'valgrind', 'help']) for key, value in opts: if key in ['-h', '--help']: tdLog.printNoPrefix( @@ -41,21 +46,49 @@ if __name__ == "__main__": tdLog.printNoPrefix('-c Test Cluster Flag') tdLog.printNoPrefix('-s stop All dnodes') sys.exit(0) + if key in ['-f', '--file']: fileName = value + if key in ['-p', '--path']: deployPath = value + if key in ['-m', '--master']: masterIp = value + if key in ['-c', '--cluster']: testCluster = True + + if key in ['-g', '--valgrind']: + valgrind = 1 + if key in ['-s', '--stop']: - cmd = "ps -ef|grep -w taosd | grep 'taosd' | grep -v grep | awk '{print $2}' && pkill -9 taosd" - os.system(cmd) - tdLog.exit('stop All dnodes') + stop = 1 + + if (stop != 0): + if (valgrind == 0): + toBeKilled = "taosd" + else: + toBeKilled = "valgrind.bin" + + killCmd = "ps -ef|grep -w %s| grep -v grep | awk '{print $2}' | xargs kill -HUP " % toBeKilled + os.system(killCmd) + time.sleep(1) + + psCmd = "ps -ef|grep -w %s| grep -v grep | awk '{print $2}'" % toBeKilled + processID = subprocess.check_output(psCmd, shell=True) + + while( processID ): + os.system(killCmd) + time.sleep(1) + processID = subprocess.check_output(psCmd, shell=True) + + tdLog.exit('stop All dnodes') if masterIp == "": tdDnodes.init(deployPath) + tdDnodes.setValgrind(valgrind) + if testCluster: tdLog.notice("Procedures for testing cluster") if fileName == "all": diff --git a/tests/pytest/util/dnodes.py b/tests/pytest/util/dnodes.py index 2be4f94802a2637f393d6471aa09f8ed0f2ea125..45eaa9b30b75d92d87f9a4d6c04dcc7e0436266b 100644 --- a/tests/pytest/util/dnodes.py +++ b/tests/pytest/util/dnodes.py @@ -14,6 +14,7 @@ import sys import os import os.path +import subprocess from util.log import * @@ -29,6 +30,9 @@ class TDSimClient: if os.system(cmd) != 0: tdLog.exit(cmd) + def setValgrind(self, value): + self.valgrind = value + def deploy(self): self.logDir = "%s/sim/psim/log" % (self.path,) self.cfgDir = "%s/sim/psim/cfg" % (self.path) @@ -78,10 +82,14 @@ class TDDnode: self.index = index self.running = 0 self.deployed = 0 + self.valgrind = 0 def init(self, path): self.path = path + def setValgrind(self, value): + self.valgrind = value + def deploy(self): self.logDir = "%s/sim/dnode%d/log" % (self.path, self.index) self.dataDir = "%s/sim/dnode%d/data" % (self.path, self.index) @@ -164,9 +172,18 @@ class TDDnode: if self.deployed == 0: tdLog.exit("dnode:%d is not deployed" % (self.index)) - cmd = "nohup %staosd -c %s > /dev/null 2>&1 & " % ( - binPath, self.cfgDir) - print(cmd) + + if self.valgrind == 0: + cmd = "nohup %staosd -c %s > /dev/null 2>&1 & " % ( + binPath, self.cfgDir) + else: + valgrindCmdline = "valgrind --tool=memcheck --leak-check=full --show-reachable=no --track-origins=yes --show-leak-kinds=all -v --workaround-gcc296-bugs=yes" + + cmd = "nohup %s %staosd -c %s 2>&1 & " % ( + valgrindCmdline, binPath, self.cfgDir) + + print(cmd) + if os.system(cmd) != 0: tdLog.exit(cmd) self.running = 1 @@ -275,8 +292,12 @@ class TDDnodes: self.sim.init(self.path) self.sim.deploy() + def setValgrind(self, value): + self.valgrind = value + def deploy(self, index): self.check(index) + self.dnodes[index - 1].setValgrind(self.valgrind) self.dnodes[index - 1].deploy() def cfg(self, index, option, value): @@ -312,11 +333,14 @@ class TDDnodes: for i in range(len(self.dnodes)): self.dnodes[i].stop() - cmd = "sudo systemctl stop taosd" - os.system(cmd) + psCmd = "ps -ef | grep -w taosd | grep 'root' | grep -v grep | awk '{print $2}'" + processID = subprocess.check_output(psCmd, shell=True) + if processID: + cmd = "sudo systemctl stop taosd" + os.system(cmd) # if os.system(cmd) != 0 : # tdLog.exit(cmd) - cmd = "ps -ef | grep -w taosd | grep 'dnode' | grep -v grep | awk '{print $2}' && sudo pkill -sigkill taosd" + cmd = "ps -ef | grep -w taosd | grep 'dnode' | grep -v grep | awk '{print $2}' && pkill -sigkill taosd" os.system(cmd) # if os.system(cmd) != 0 : # tdLog.exit(cmd) diff --git a/tests/pytest/util/log.py b/tests/pytest/util/log.py index c7032df3c4a67d14eeaab95e705f2a9d59624bc9..97c8b2ef7f2d2b7b207aa632e07328beab06f440 100644 --- a/tests/pytest/util/log.py +++ b/tests/pytest/util/log.py @@ -42,7 +42,7 @@ class TDLog: printf("\033[1;31m%s %s\033[0m" % (datetime.datetime.now(), err)) sys.exit(1) - def printfNoPrefix(self, info): + def printNoPrefix(self, info): printf("\033[1;36m%s\033[0m" % (info)) diff --git a/tests/script/sh/deploy.sh b/tests/script/sh/deploy.sh index 12f9689fd34cc3a3d7488e1d46cdd1af58ae656d..6c4ada50fe86c272d7a96ec8fa7f698d9ba3e200 100755 --- a/tests/script/sh/deploy.sh +++ b/tests/script/sh/deploy.sh @@ -93,7 +93,7 @@ echo "privateIp $NODE_IP" >> $TAOS_CFG echo "dDebugFlag 199" >> $TAOS_CFG echo "mDebugFlag 199" >> $TAOS_CFG echo "sdbDebugFlag 199" >> $TAOS_CFG -echo "rpcDebugFlag 131" >> $TAOS_CFG +echo "rpcDebugFlag 135" >> $TAOS_CFG echo "tmrDebugFlag 131" >> $TAOS_CFG echo "cDebugFlag 135" >> $TAOS_CFG echo "httpDebugFlag 131" >> $TAOS_CFG diff --git a/tests/script/test.sh b/tests/script/test.sh index 5fd80d39098dfc45c63e78c4f13291322f7af81b..bce6291fbe060a12c032b39ae7befee3e9c9ec22 100755 --- a/tests/script/test.sh +++ b/tests/script/test.sh @@ -11,7 +11,8 @@ set +e FILE_NAME= RELEASE=0 ASYNC=0 -while getopts "f:a" arg +VALGRIND=0 +while getopts "f:av" arg do case $arg in f) @@ -20,6 +21,9 @@ do a) ASYNC=1 ;; + v) + VALGRIND=1 + ;; ?) echo "unknow argument" ;; @@ -96,10 +100,14 @@ ulimit -c unlimited #sudo sysctl -w kernel.core_pattern=$TOP_DIR/core.%p.%e if [ -n "$FILE_NAME" ]; then - echo "ExcuteCmd:" $PROGRAM -c $CFG_DIR -f $FILE_NAME echo "------------------------------------------------------------------------" - #valgrind --tool=memcheck --leak-check=full --show-reachable=no --track-origins=yes --show-leak-kinds=all -v --workaround-gcc296-bugs=yes --log-file=valgrind.log $PROGRAM -c $CFG_DIR -f $FILE_NAME - $PROGRAM -c $CFG_DIR -f $FILE_NAME + if [ $VALGRIND -eq 1 ]; then + echo 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 + 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 + else + echo "ExcuteCmd:" $PROGRAM -c $CFG_DIR -f $FILE_NAME + $PROGRAM -c $CFG_DIR -f $FILE_NAME + fi else echo "ExcuteCmd:" $PROGRAM -c $CFG_DIR -f basicSuite.sim echo "------------------------------------------------------------------------" diff --git a/tests/script/unique/mnode/mgmt22.sim b/tests/script/unique/mnode/mgmt22.sim index 3bfa86b55ab17fd31be3f4770f88a62b02298d7d..f6e54ffc2f044edee9b686b681354c99a65349f4 100644 --- a/tests/script/unique/mnode/mgmt22.sim +++ b/tests/script/unique/mnode/mgmt22.sim @@ -109,3 +109,7 @@ endi if $data3_3 != null then goto show7 endi + +system sh/exec_up.sh -n dnode1 -s stop +system sh/exec_up.sh -n dnode2 -s stop +system sh/exec_up.sh -n dnode3 -s stop \ No newline at end of file diff --git a/tests/script/unique/mnode/mgmt24.sim b/tests/script/unique/mnode/mgmt24.sim index 6635c4e706ac2ec0cfd5002aa0d787cc443bcb02..9418fd339863c71ba83fce12b1ade752b88834b0 100644 --- a/tests/script/unique/mnode/mgmt24.sim +++ b/tests/script/unique/mnode/mgmt24.sim @@ -77,4 +77,8 @@ if $data3_1 != master then endi if $data3_2 != slave then goto step5 -endi \ No newline at end of file +endi + +system sh/exec_up.sh -n dnode1 -s stop +system sh/exec_up.sh -n dnode2 -s stop +system sh/exec_up.sh -n dnode3 -s stop \ No newline at end of file diff --git a/tests/script/unique/mnode/mgmt25.sim b/tests/script/unique/mnode/mgmt25.sim index ca935d744fa7678b55c5d6b430523ccd55af88cb..4f5e2bf3c8ad38b22545280a0ea62db8c77bd699 100644 --- a/tests/script/unique/mnode/mgmt25.sim +++ b/tests/script/unique/mnode/mgmt25.sim @@ -93,3 +93,7 @@ endi if $dnode3Role != slave then return -1 endi + +system sh/exec_up.sh -n dnode1 -s stop +system sh/exec_up.sh -n dnode2 -s stop +system sh/exec_up.sh -n dnode3 -s stop \ No newline at end of file diff --git a/tests/script/unique/mnode/mgmt26.sim b/tests/script/unique/mnode/mgmt26.sim index 4a5958b88aa3151ebadbf52695348fe25a345947..57c600343133980ff95e6558391d2cb2e0b297b7 100644 --- a/tests/script/unique/mnode/mgmt26.sim +++ b/tests/script/unique/mnode/mgmt26.sim @@ -123,3 +123,6 @@ if $dnode3Role != slave then return -1 endi +system sh/exec_up.sh -n dnode1 -s stop +system sh/exec_up.sh -n dnode2 -s stop +system sh/exec_up.sh -n dnode3 -s stop \ No newline at end of file diff --git a/tests/script/unique/mnode/mgmtr2.sim b/tests/script/unique/mnode/mgmtr2.sim index 06e8f6b9d9b730e68227f8d582fb909bb31128a1..666b8a7b3343453fede4623538f405ad5e264a55 100644 --- a/tests/script/unique/mnode/mgmtr2.sim +++ b/tests/script/unique/mnode/mgmtr2.sim @@ -83,3 +83,7 @@ endi if $dnode3Role != null then return -1 endi + +system sh/exec_up.sh -n dnode1 -s stop +system sh/exec_up.sh -n dnode2 -s stop +system sh/exec_up.sh -n dnode3 -s stop \ No newline at end of file diff --git a/tests/script/unique/mnode/secondIp.sim b/tests/script/unique/mnode/secondIp.sim index 29d27cd88c0a4763abfd2203f4af3df01271361c..6902c7d49843079a63018c918f7e76aeff1ecb4f 100644 --- a/tests/script/unique/mnode/secondIp.sim +++ b/tests/script/unique/mnode/secondIp.sim @@ -38,5 +38,6 @@ if $data4_2 != 4 then return -1 endi - - +system sh/exec_up.sh -n dnode1 -s stop +system sh/exec_up.sh -n dnode2 -s stop +system sh/exec_up.sh -n dnode3 -s stop \ No newline at end of file diff --git a/tests/script/unique/mnode/testSuite.sim b/tests/script/unique/mnode/testSuite.sim index e1712fa4f6ebb509286f8397bd7f643578decfbd..279574e47d0647395a91d7cbd785aa72814476ec 100644 --- a/tests/script/unique/mnode/testSuite.sim +++ b/tests/script/unique/mnode/testSuite.sim @@ -7,4 +7,3 @@ run unique/mnode/mgmt33.sim run unique/mnode/mgmt34.sim run unique/mnode/mgmtr2.sim run unique/mnode/secondIp.sim - diff --git a/tests/test-all.sh b/tests/test-all.sh index 8bd01119c4cee2e836d39ce181ca30941271ed85..dee89b9dc57da7e6a8292ee0aca82b329b8865f2 100755 --- a/tests/test-all.sh +++ b/tests/test-all.sh @@ -8,32 +8,33 @@ GREEN_UNDERLINE='\033[4;32m' NC='\033[0m' cd script -sudo ./test.sh 2>&1 | grep 'success\|failed' | tee out.txt +./test.sh -f basicSuite.sim 2>&1 | grep 'success\|failed\|fault' | tee out.txt -total_success=`grep success out.txt | wc -l` +totalSuccess=`grep success out.txt | wc -l` +totalBasic=`grep success out.txt | grep Suite | wc -l` -if [ "$total_success" -gt "0" ]; then - total_success=`expr $total_success - 1` - echo -e "${GREEN} ### Total $total_success TSIM case(s) succeed! ### ${NC}" +if [ "$totalSuccess" -gt "0" ]; then + totalSuccess=`expr $totalSuccess - $totalBasic` + echo -e "${GREEN} ### Total $totalSuccess TSIM case(s) succeed! ### ${NC}" fi -total_failed=`grep failed out.txt | wc -l` -if [ "$total_failed" -ne "0" ]; then - echo -e "${RED} ### Total $total_failed TSIM case(s) failed! ### ${NC}" - exit $total_failed +totalFailed=`grep 'failed\|fault' out.txt | wc -l` +if [ "$totalFailed" -ne "0" ]; then + echo -e "${RED} ### Total $totalFailed TSIM case(s) failed! ### ${NC}" + exit $totalFailed fi cd ../pytest -sudo ./simpletest.sh 2>&1 | grep 'successfully executed\|failed' | tee pytest-out.txt -total_py_success=`grep 'successfully executed' pytest-out.txt | wc -l` +./simpletest.sh 2>&1 | grep 'successfully executed\|failed' | tee pytest-out.txt +totalPySuccess=`grep 'successfully executed' pytest-out.txt | wc -l` -if [ "$total_py_success" -gt "0" ]; then - echo -e "${GREEN} ### Total $total_py_success python case(s) succeed! ### ${NC}" +if [ "$totalPySuccess" -gt "0" ]; then + echo -e "${GREEN} ### Total $totalPySuccess python case(s) succeed! ### ${NC}" fi -total_py_failed=`grep 'failed' pytest-out.txt | wc -l` -if [ "$total_py_failed" -ne "0" ]; then - echo -e "${RED} ### Total $total_py_failed python case(s) failed! ### ${NC}" - exit $total_py_failed +totalPyFailed=`grep 'failed' pytest-out.txt | wc -l` +if [ "$totalPyFailed" -ne "0" ]; then + echo -e "${RED} ### Total $totalPyFailed python case(s) failed! ### ${NC}" + exit $totalPyFailed fi