未验证 提交 2fd5aa30 编写于 作者: sangshuduo's avatar sangshuduo 提交者: GitHub

Hotfix/sangshuduo/td 3197 fix taosdemo coverity scan (#8422)

* [TD-3197] <fix>: fix taosdemo coverity scan issues.

* [TD-3197] <fix>: fix taosdemo coverity scan issue.

fix subscribeTest pids uninitialized.

* [TD-3197] <fix>: fix taosdemo coverity scan issues.

* [TD-3197] <fix>: fix coverity scan issues.

check super tbl info pointer.

* [TD-3197] <fix>: fix coverity scan issues.

move sub tbl query thread join into loop

* [TD-3197] <fix>: fix coverity scan issues.

remove unused variable

* [TD-3197] <fix>: fix coverity scan issues.

use more secure random library

* [TD-3197] <fix>: fix coverity scan issues.

use strncpy for more safe

* [TD-3197] <fix>: fix taosdemo coverity scan issue.

replace arc4random with rand().

* [TD-3197] <fix>: fix coverity scan issues.

check stb info pointer for start time

* [TD-3197] <fix>: fix coverity scan issues.

fix strcpy vulnerability

* [TD-3197] <fix>: fix taosdemo coverity scan issue.

modify taosdemoTest2. try to check database continously.

* [TD-3197] <fix>: taosdemo coverity scan issues.

* [TD-3197] <fix>: fix memory leak when parsing arguments.

* [TD-3197] <fix>: fix cmake strip arguments.

* [TD-3197] <fix>: taosdemo coverity scan.

fix cmake string manipulation.

* [TD-3197]<fix>: taosdemo coverity scan issue.

configDir buffer overwrite.

* [TD-3197]<fix>: coverity scan issue.

taosdump argument validation.

* [TD-3197]<fix>: taosdemo and taosdump coverity scan issues.

* [TD-3197]<fix>: taosdemo coverity scan.

append result buf to file. for develop branch.

* exit if read sample file failed.

* fix converity scan issue.

* fix coverity scan issue.

* fix coverity scan memory leak.

* fix resource leak reported by coverity scan.

* fix taosdemo coverity scan issue.

* fix tcsetattr and getchar return value determination bug.

* fix coverity scan issue.

* fix two more coverity scan issues.

* fix stmt batch coverity scan issue.

* change to portable format.

* delete tests/examples/c/'-g' file

* fix example compile error.

* fix coverity scan issue

* fix taosdemo coverity scan issue.

* fix taosdemo test case for restful query

* make initOfQueryMeta() back to solve restful issue.

* fix test case keep 36 days.
Co-authored-by: NShuduo Sang <sdsang@taosdata.com>
上级 d645395b
......@@ -3482,8 +3482,14 @@ static int postProceSql(char *host, uint16_t port,
'w', 'x', 'y', 'z', '0', '1', '2', '3',
'4', '5', '6', '7', '8', '9', '+', '/'};
snprintf(userpass_buf, INPUT_BUF_LEN, "%s:%s",
g_Dbs.user, g_Dbs.password);
if (g_args.test_mode == INSERT_TEST) {
snprintf(userpass_buf, INPUT_BUF_LEN, "%s:%s",
g_Dbs.user, g_Dbs.password);
} else {
snprintf(userpass_buf, INPUT_BUF_LEN, "%s:%s",
g_queryInfo.user, g_queryInfo.password);
}
size_t userpass_buf_len = strlen(userpass_buf);
size_t encoded_len = 4 * ((userpass_buf_len +2) / 3);
......
......@@ -22,7 +22,7 @@
"cache": 50,
"blocks": 8,
"precision": "ms",
"keep": 365,
"keep": 36500,
"minRows": 100,
"maxRows": 4096,
"comp":2,
......@@ -36,7 +36,7 @@
"name": "stb0",
"child_table_exists":"no",
"childtable_count": 60,
"childtable_prefix": "stb00_",
"childtable_prefix": "stb00_",
"auto_create_table": "no",
"batch_create_tbl_num": 20,
"data_source": "rand",
......
......@@ -22,7 +22,7 @@
"cache": 50,
"blocks": 8,
"precision": "ms",
"keep": 36,
"keep": 36500,
"minRows": 100,
"maxRows": 4096,
"comp":2,
......
......@@ -22,7 +22,7 @@
"cache": 50,
"blocks": 8,
"precision": "ns",
"keep": 36,
"keep": 36500,
"minRows": 100,
"maxRows": 4096,
"comp":2,
......
......@@ -22,7 +22,7 @@
"cache": 50,
"blocks": 8,
"precision": "us",
"keep": 36,
"keep": 36500,
"minRows": 100,
"maxRows": 4096,
"comp":2,
......
......@@ -22,7 +22,7 @@
"cache": 50,
"blocks": 8,
"precision": "ns",
"keep": 36,
"keep": 36500,
"minRows": 100,
"maxRows": 4096,
"comp":2,
......
......@@ -22,7 +22,7 @@
"cache": 50,
"blocks": 8,
"precision": "ns",
"keep": 36,
"keep": 36500,
"minRows": 100,
"maxRows": 4096,
"comp":2,
......
......@@ -22,7 +22,7 @@
"cache": 50,
"blocks": 8,
"precision": "ns",
"keep": 36,
"keep": 36500,
"minRows": 100,
"maxRows": 4096,
"comp":2,
......
......@@ -22,7 +22,7 @@
"cache": 50,
"blocks": 8,
"precision": "ns",
"keep": 36,
"keep": 36500,
"minRows": 100,
"maxRows": 4096,
"comp":2,
......
......@@ -20,14 +20,16 @@ from util.dnodes import *
import time
from datetime import datetime
import ast
import re
# from assertpy import assert_that
import subprocess
class TDTestCase:
def init(self, conn, logSql):
tdLog.debug("start to execute %s" % __file__)
tdSql.init(conn.cursor(), logSql)
def getBuildPath(self):
selfPath = os.path.dirname(os.path.realpath(__file__))
......@@ -40,52 +42,54 @@ class TDTestCase:
if ("taosd" in files):
rootRealPath = os.path.dirname(os.path.realpath(root))
if ("packaging" not in rootRealPath):
buildPath = root[:len(root)-len("/build/bin")]
buildPath = root[:len(root) - len("/build/bin")]
break
return buildPath
# 获取taosc接口查询的结果文件中的内容,返回每行数据,并断言数据的第一列内容。
def assertfileDataTaosc(self,filename,expectResult):
def assertfileDataTaosc(self, filename, expectResult):
self.filename = filename
self.expectResult = expectResult
with open("%s" % filename, 'r+') as f1:
with open("%s" % filename, 'r+') as f1:
for line in f1.readlines():
queryResult = line.strip().split()[0]
self.assertCheck(filename,queryResult,expectResult)
self.assertCheck(filename, queryResult, expectResult)
# 获取restful接口查询的结果文件中的关键内容,目前的关键内容找到第一个key就跳出循,所以就只有一个数据。后续再修改多个结果文件。
def getfileDataRestful(self,filename):
def getfileDataRestful(self, filename):
self.filename = filename
with open("%s" % filename, 'r+') as f1:
with open("%s" % filename, 'r+') as f1:
for line in f1.readlines():
contents = line.strip()
if contents.find("data") != -1:
pattern = re.compile("{.*}")
contents = pattern.search(contents).group()
contentsDict = ast.literal_eval(contents) # 字符串转换为字典
queryResult = contentsDict['data'][0][0]
break
return queryResult
# 获取taosc接口查询次数
def queryTimesTaosc(self,filename):
def queryTimesTaosc(self, filename):
self.filename = filename
command = 'cat %s |wc -l'% filename
times = int(subprocess.getstatusoutput(command)[1])
command = 'cat %s |wc -l' % filename
times = int(subprocess.getstatusoutput(command)[1])
return times
# 获取restful接口查询次数
def queryTimesRestful(self,filename):
def queryTimesRestful(self, filename):
self.filename = filename
command = 'cat %s |grep "200 OK" |wc -l'% filename
times = int(subprocess.getstatusoutput(command)[1])
command = 'cat %s |grep "200 OK" |wc -l' % filename
times = int(subprocess.getstatusoutput(command)[1])
return times
# 定义断言结果是否正确。不正确返回错误结果,正确即通过。
def assertCheck(self,filename,queryResult,expectResult):
def assertCheck(self, filename, queryResult, expectResult):
self.filename = filename
self.queryResult = queryResult
self.expectResult = expectResult
args0 = (filename, queryResult, expectResult)
assert queryResult == expectResult , "Queryfile:%s ,result is %s != expect: %s" % args0
assert queryResult == expectResult, "Queryfile:%s ,result is %s != expect: %s" % args0
def run(self):
buildPath = self.getBuildPath()
......@@ -93,109 +97,144 @@ class TDTestCase:
tdLog.exit("taosd not found!")
else:
tdLog.info("taosd found in %s" % buildPath)
binPath = buildPath+ "/build/bin/"
binPath = buildPath + "/build/bin/"
# delete useless files
os.system("rm -rf ./query_res*")
os.system("rm -rf ./query_res*")
os.system("rm -rf ./all_query*")
# taosc query: query specified table and query super table
os.system("%staosdemo -f tools/taosdemoAllTest/queryInsertdata.json" % binPath)
os.system("%staosdemo -f tools/taosdemoAllTest/queryTaosc.json" % binPath)
# taosc query: query specified table and query super table
os.system(
"%staosdemo -f tools/taosdemoAllTest/queryInsertdata.json" %
binPath)
os.system(
"%staosdemo -f tools/taosdemoAllTest/queryTaosc.json" %
binPath)
os.system("cat query_res0.txt* > all_query_res0_taosc.txt")
os.system("cat query_res1.txt* > all_query_res1_taosc.txt")
os.system("cat query_res2.txt* > all_query_res2_taosc.txt")
# correct Times testcases
# correct Times testcases
queryTimes0Taosc = self.queryTimesTaosc("all_query_res0_taosc.txt")
self.assertCheck("all_query_res0_taosc.txt",queryTimes0Taosc,6)
self.assertCheck("all_query_res0_taosc.txt", queryTimes0Taosc, 6)
queryTimes1Taosc = self.queryTimesTaosc("all_query_res1_taosc.txt")
self.assertCheck("all_query_res1_taosc.txt",queryTimes1Taosc,6)
self.assertCheck("all_query_res1_taosc.txt", queryTimes1Taosc, 6)
queryTimes2Taosc = self.queryTimesTaosc("all_query_res2_taosc.txt")
self.assertCheck("all_query_res2_taosc.txt",queryTimes2Taosc,20)
self.assertCheck("all_query_res2_taosc.txt", queryTimes2Taosc, 20)
# correct data testcase
self.assertfileDataTaosc("all_query_res0_taosc.txt","1604160000099")
self.assertfileDataTaosc("all_query_res1_taosc.txt","100")
self.assertfileDataTaosc("all_query_res2_taosc.txt","1604160000199")
self.assertfileDataTaosc("all_query_res0_taosc.txt", "1604160000099")
self.assertfileDataTaosc("all_query_res1_taosc.txt", "100")
self.assertfileDataTaosc("all_query_res2_taosc.txt", "1604160000199")
# delete useless files
os.system("rm -rf ./query_res*")
os.system("rm -rf ./query_res*")
os.system("rm -rf ./all_query*")
# use restful api to query
os.system("%staosdemo -f tools/taosdemoAllTest/queryInsertrestdata.json" % binPath)
os.system("%staosdemo -f tools/taosdemoAllTest/queryRestful.json" % binPath)
os.system(
"%staosdemo -f tools/taosdemoAllTest/queryInsertrestdata.json" %
binPath)
os.system(
"%staosdemo -f tools/taosdemoAllTest/queryRestful.json" %
binPath)
os.system("cat query_res0.txt* > all_query_res0_rest.txt")
os.system("cat query_res1.txt* > all_query_res1_rest.txt")
os.system("cat query_res2.txt* > all_query_res2_rest.txt")
# correct Times testcases
# correct Times testcases
queryTimes0Restful = self.queryTimesRestful("all_query_res0_rest.txt")
self.assertCheck("all_query_res0_rest.txt",queryTimes0Restful,6)
self.assertCheck("all_query_res0_rest.txt", queryTimes0Restful, 6)
queryTimes1Restful = self.queryTimesRestful("all_query_res1_rest.txt")
self.assertCheck("all_query_res1_rest.txt",queryTimes1Restful,6)
self.assertCheck("all_query_res1_rest.txt", queryTimes1Restful, 6)
queryTimes2Restful = self.queryTimesRestful("all_query_res2_rest.txt")
self.assertCheck("all_query_res2_rest.txt",queryTimes2Restful,4)
self.assertCheck("all_query_res2_rest.txt", queryTimes2Restful, 4)
# correct data testcase
data0 = self.getfileDataRestful("all_query_res0_rest.txt")
self.assertCheck('all_query_res0_rest.txt',data0,"2020-11-01 00:00:00.009")
self.assertCheck(
'all_query_res0_rest.txt',
data0,
"2020-11-01 00:00:00.009")
data1 = self.getfileDataRestful("all_query_res1_rest.txt")
self.assertCheck('all_query_res1_rest.txt',data1,10)
self.assertCheck('all_query_res1_rest.txt', data1, 10)
data2 = self.getfileDataRestful("all_query_res2_rest.txt")
self.assertCheck('all_query_res2_rest.txt',data2,"2020-11-01 00:00:00.004")
self.assertCheck(
'all_query_res2_rest.txt',
data2,
"2020-11-01 00:00:00.004")
# query times less than or equal to 100
os.system("%staosdemo -f tools/taosdemoAllTest/queryInsertdata.json" % binPath)
os.system("%staosdemo -f tools/taosdemoAllTest/querySpeciMutisql100.json" % binPath)
os.system("%staosdemo -f tools/taosdemoAllTest/querySuperMutisql100.json" % binPath)
#query result print QPS
os.system("%staosdemo -f tools/taosdemoAllTest/queryInsertdata.json" % binPath)
os.system("%staosdemo -f tools/taosdemoAllTest/queryQps.json" % binPath)
os.system(
"%staosdemo -f tools/taosdemoAllTest/queryInsertdata.json" %
binPath)
os.system(
"%staosdemo -f tools/taosdemoAllTest/querySpeciMutisql100.json" %
binPath)
os.system(
"%staosdemo -f tools/taosdemoAllTest/querySuperMutisql100.json" %
binPath)
# query result print QPS
os.system(
"%staosdemo -f tools/taosdemoAllTest/queryInsertdata.json" %
binPath)
os.system(
"%staosdemo -f tools/taosdemoAllTest/queryQps.json" %
binPath)
# use illegal or out of range parameters query json file
os.system("%staosdemo -f tools/taosdemoAllTest/queryInsertdata.json" % binPath)
exceptcode = os.system("%staosdemo -f tools/taosdemoAllTest/queryTimes0.json" % binPath)
os.system(
"%staosdemo -f tools/taosdemoAllTest/queryInsertdata.json" %
binPath)
exceptcode = os.system(
"%staosdemo -f tools/taosdemoAllTest/queryTimes0.json" %
binPath)
assert exceptcode != 0
exceptcode0 = os.system("%staosdemo -f tools/taosdemoAllTest/queryTimesless0.json" % binPath)
exceptcode0 = os.system(
"%staosdemo -f tools/taosdemoAllTest/queryTimesless0.json" %
binPath)
assert exceptcode0 != 0
exceptcode1 = os.system("%staosdemo -f tools/taosdemoAllTest/queryConcurrentless0.json" % binPath)
exceptcode1 = os.system(
"%staosdemo -f tools/taosdemoAllTest/queryConcurrentless0.json" %
binPath)
assert exceptcode1 != 0
exceptcode2 = os.system("%staosdemo -f tools/taosdemoAllTest/queryConcurrent0.json" % binPath)
exceptcode2 = os.system(
"%staosdemo -f tools/taosdemoAllTest/queryConcurrent0.json" %
binPath)
assert exceptcode2 != 0
exceptcode3 = os.system("%staosdemo -f tools/taosdemoAllTest/querrThreadsless0.json" % binPath)
exceptcode3 = os.system(
"%staosdemo -f tools/taosdemoAllTest/querrThreadsless0.json" %
binPath)
assert exceptcode3 != 0
exceptcode4 = os.system("%staosdemo -f tools/taosdemoAllTest/querrThreads0.json" % binPath)
exceptcode4 = os.system(
"%staosdemo -f tools/taosdemoAllTest/querrThreads0.json" %
binPath)
assert exceptcode4 != 0
# delete useless files
os.system("rm -rf ./insert_res.txt")
os.system("rm -rf tools/taosdemoAllTest/*.py.sql")
os.system("rm -rf ./querySystemInfo*")
os.system("rm -rf ./query_res*")
os.system("rm -rf ./all_query*")
os.system("rm -rf tools/taosdemoAllTest/*.py.sql")
os.system("rm -rf ./querySystemInfo*")
os.system("rm -rf ./query_res*")
# os.system("rm -rf ./all_query*")
os.system("rm -rf ./test_query_res0.txt")
def stop(self):
tdSql.close()
tdLog.success("%s successfully executed" % __file__)
tdCases.addWindows(__file__, TDTestCase())
tdCases.addLinux(__file__, TDTestCase())
......@@ -36,7 +36,7 @@ class TDTestCase:
if ("taosd" in files):
rootRealPath = os.path.dirname(os.path.realpath(root))
if ("packaging" not in rootRealPath):
buildPath = root[:len(root)-len("/build/bin")]
buildPath = root[:len(root) - len("/build/bin")]
break
return buildPath
......@@ -46,14 +46,15 @@ class TDTestCase:
tdLog.exit("taosd not found!")
else:
tdLog.info("taosd found in %s" % buildPath)
binPath = buildPath+ "/build/bin/"
binPath = buildPath + "/build/bin/"
# insert: create one or mutiple tables per sql and insert multiple rows per sql
# insert data from a special timestamp
# check stable stb0
os.system("%staosdemo -f tools/taosdemoAllTest/taosdemoTestNanoDatabase.json -y " % binPath)
os.system(
"%staosdemo -f tools/taosdemoAllTest/taosdemoTestNanoDatabase.json -y " %
binPath)
tdSql.execute("use nsdb")
tdSql.query("show stables")
tdSql.checkData(0, 4, 100)
......@@ -64,9 +65,9 @@ class TDTestCase:
tdSql.query("select count(*) from stb0")
tdSql.checkData(0, 0, 10000)
tdSql.query("describe stb0")
tdSql.checkDataType(9, 1,"TIMESTAMP")
tdSql.checkDataType(9, 1, "TIMESTAMP")
tdSql.query("select last(ts) from stb0")
tdSql.checkData(0, 0,"2021-07-01 00:00:00.990000000")
tdSql.checkData(0, 0, "2021-07-01 00:00:00.990000000")
# check stable stb1 which is insert with disord
......@@ -78,16 +79,18 @@ class TDTestCase:
tdSql.checkData(0, 0, 10000)
# check c8 is an nano timestamp
tdSql.query("describe stb1")
tdSql.checkDataType(9, 1,"TIMESTAMP")
tdSql.checkDataType(9, 1, "TIMESTAMP")
# check insert timestamp_step is nano_second
tdSql.query("select last(ts) from stb1")
tdSql.checkData(0, 0,"2021-07-01 00:00:00.990000000")
tdSql.checkData(0, 0, "2021-07-01 00:00:00.990000000")
# insert data from now time
# check stable stb0
os.system("%staosdemo -f tools/taosdemoAllTest/taosdemoTestNanoDatabaseNow.json -y " % binPath)
os.system(
"%staosdemo -f tools/taosdemoAllTest/taosdemoTestNanoDatabaseNow.json -y " %
binPath)
tdSql.execute("use nsdb2")
tdSql.query("show stables")
tdSql.checkData(0, 4, 100)
......@@ -99,11 +102,14 @@ class TDTestCase:
tdSql.checkData(0, 0, 10000)
# check c8 is an nano timestamp
tdSql.query("describe stb0")
tdSql.checkDataType(9,1,"TIMESTAMP")
tdSql.checkDataType(9, 1, "TIMESTAMP")
# insert by csv files and timetamp is long int , strings in ts and
# cols
# insert by csv files and timetamp is long int , strings in ts and cols
os.system("%staosdemo -f tools/taosdemoAllTest/taosdemoTestNanoDatabasecsv.json -y " % binPath)
os.system(
"%staosdemo -f tools/taosdemoAllTest/taosdemoTestNanoDatabasecsv.json -y " %
binPath)
tdSql.execute("use nsdbcsv")
tdSql.query("show stables")
tdSql.checkData(0, 4, 100)
......@@ -111,29 +117,36 @@ class TDTestCase:
tdSql.checkData(0, 0, 10000)
tdSql.query("describe stb0")
tdSql.checkDataType(3, 1, "TIMESTAMP")
tdSql.query("select count(*) from stb0 where ts > \"2021-07-01 00:00:00.490000000\"")
tdSql.query(
"select count(*) from stb0 where ts > \"2021-07-01 00:00:00.490000000\"")
tdSql.checkData(0, 0, 5000)
tdSql.query("select count(*) from stb0 where ts < 1626918583000000000")
tdSql.checkData(0, 0, 10000)
os.system("rm -rf ./insert_res.txt")
os.system("rm -rf tools/taosdemoAllTest/taosdemoTestSupportNano*.py.sql")
# taosdemo test insert with command and parameter , detals show taosdemo --help
os.system("%staosdemo -u root -ptaosdata -P 6030 -a 1 -m pre -n 10 -T 20 -t 60 -o res.txt -y " % binPath)
# taosdemo test insert with command and parameter , detals show
# taosdemo --help
os.system(
"%staosdemo -u root -ptaosdata -P 6030 -a 1 -m pre -n 10 -T 20 -t 60 -o res.txt -y " %
binPath)
tdSql.query("select count(*) from test.meters")
tdSql.checkData(0, 0, 600)
# check taosdemo -s
sqls_ls = ['drop database if exists nsdbsql;','create database nsdbsql precision "ns" keep 36 days 6 update 1;',
'use nsdbsql;','CREATE STABLE meters (ts timestamp, current float, voltage int, phase float) TAGS (location binary(64), groupdId int);',
'CREATE TABLE d1001 USING meters TAGS ("Beijing.Chaoyang", 2);',
'INSERT INTO d1001 USING METERS TAGS ("Beijng.Chaoyang", 2) VALUES (now, 10.2, 219, 0.32);',
'INSERT INTO d1001 USING METERS TAGS ("Beijng.Chaoyang", 2) VALUES (now, 85, 32, 0.76);']
sqls_ls = [
'drop database if exists nsdbsql;',
'create database nsdbsql precision "ns" keep 36500 days 6 update 1;',
'use nsdbsql;',
'CREATE STABLE meters (ts timestamp, current float, voltage int, phase float) TAGS (location binary(64), groupdId int);',
'CREATE TABLE d1001 USING meters TAGS ("Beijing.Chaoyang", 2);',
'INSERT INTO d1001 USING METERS TAGS ("Beijng.Chaoyang", 2) VALUES (now, 10.2, 219, 0.32);',
'INSERT INTO d1001 USING METERS TAGS ("Beijng.Chaoyang", 2) VALUES (now, 85, 32, 0.76);']
with open("./taosdemoTestNanoCreateDB.sql",mode ="a" ) as sql_files:
with open("./taosdemoTestNanoCreateDB.sql", mode="a") as sql_files:
for sql in sqls_ls:
sql_files.write(sql+"\n")
sql_files.write(sql + "\n")
sql_files.close()
sleep(10)
......@@ -141,11 +154,10 @@ class TDTestCase:
os.system("%staosdemo -s taosdemoTestNanoCreateDB.sql -y " % binPath)
tdSql.query("select count(*) from nsdbsql.meters")
tdSql.checkData(0, 0, 2)
os.system("rm -rf ./res.txt")
os.system("rm -rf ./*.py.sql")
os.system("rm -rf ./taosdemoTestNanoCreateDB.sql")
def stop(self):
tdSql.close()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册