• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

taosdata / TDengine / #4815

17 Oct 2025 06:47AM UTC coverage: 61.177% (-0.03%) from 61.206%
#4815

push

travis-ci

web-flow
Merge pull request #33289 from taosdata/3.0

enh: Code Optimization (#33283)

155629 of 324369 branches covered (47.98%)

Branch coverage included in aggregate %.

1 of 1 new or added line in 1 file covered. (100.0%)

555 existing lines in 123 files now uncovered.

207706 of 269535 relevant lines covered (77.06%)

127615938.53 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

53.66
/tools/shell/src/shellNettest.c
1
/*
2
 * Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
3
 *
4
 * This program is free software: you can use, redistribute, and/or modify
5
 * it under the terms of the GNU Affero General Public License, version 3
6
 * or later ("AGPL"), as published by the Free Software Foundation.
7
 *
8
 * This program is distributed in the hope that it will be useful, but WITHOUT
9
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10
 * FITNESS FOR A PARTICULAR PURPOSE.
11
 *
12
 * You should have received a copy of the GNU Affero General Public License
13
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14
 */
15

16
#define _GNU_SOURCE
17
#include "shellInt.h"
18

19
static void shellWorkAsClient() {
269✔
20
  SShellArgs *pArgs = &shell.args;
269✔
21
  SRpcInit    rpcInit = {0};
269✔
22
  SEpSet      epSet = {.inUse = 0, .numOfEps = 1};
269✔
23
  SRpcMsg     rpcRsp = {0};
269✔
24
  void       *clientRpc = NULL;
269✔
25
  char        pass[TSDB_PASSWORD_LEN + 1] = {0};
269✔
26

27
  taosEncryptPass_c((uint8_t *)("_pwd"), strlen("_pwd"), pass);
28
  rpcInit.label = "CHK";
269✔
29
  rpcInit.numOfThreads = 1;
269✔
30
  rpcInit.sessions = 16;
269✔
31
  rpcInit.connType = TAOS_CONN_CLIENT;
269✔
32
  rpcInit.idleTime = 3000;
269✔
33
  rpcInit.user = "_dnd";
269✔
34
  rpcInit.timeToGetConn = 500000;
269✔
35

36
  memcpy(rpcInit.caPath, tsTLSCaPath, strlen(tsTLSCaPath));
269!
37
  memcpy(rpcInit.certPath, tsTLSSvrCertPath, strlen(tsTLSSvrCertPath));
269!
38
  memcpy(rpcInit.keyPath, tsTLSSvrKeyPath, strlen(tsTLSSvrKeyPath));
269!
39
  memcpy(rpcInit.cliCertPath, tsTLSCliCertPath, strlen(tsTLSCliCertPath));
269!
40
  memcpy(rpcInit.cliKeyPath, tsTLSCliKeyPath, strlen(tsTLSCliKeyPath));
269!
41

42
  taosVersionStrToInt(td_version, &rpcInit.compatibilityVer);
269✔
43
  clientRpc = rpcOpen(&rpcInit);
269✔
44
  if (clientRpc == NULL) {
269!
45
    printf("failed to init net test client since %s\r\n", terrstr());
×
46
    goto _OVER;
×
47
  }
48

49
  if (pArgs->port == 0) {
269!
50
    pArgs->port = 6030;
269✔
51
  }
52
  if (pArgs->host == NULL) {
269!
53
    pArgs->host = "localhost";
269✔
54
  }
55
  char fqdn[TSDB_FQDN_LEN] = {0};
269✔
56
  tstrncpy(fqdn, pArgs->host, TSDB_FQDN_LEN);
269!
57
  strtok(fqdn, ":");
269✔
58

59
  printf("network test client is initialized, the server is %s:%u\r\n", fqdn, pArgs->port);
269✔
60

61
  tstrncpy(epSet.eps[0].fqdn, fqdn, TSDB_FQDN_LEN);
269✔
62
  epSet.eps[0].port = (uint16_t)pArgs->port;
269✔
63

64
  int32_t  totalSucc = 0;
269✔
65
  uint64_t startTime = taosGetTimestampUs();
269✔
66

67
  for (int32_t i = 0; i < pArgs->pktNum; ++i) {
10,699✔
68
    SRpcMsg rpcMsg = {.info.ahandle = (void *)0x9525, .info.notFreeAhandle = 1, .msgType = TDMT_DND_NET_TEST};
10,430✔
69
    rpcMsg.pCont = rpcMallocCont(pArgs->pktLen);
10,430✔
70
    rpcMsg.contLen = pArgs->pktLen;
10,430✔
71

72
    printf("request is sent, size:%d\r\n", rpcMsg.contLen);
10,430✔
73
    rpcSendRecv(clientRpc, &epSet, &rpcMsg, &rpcRsp);
10,430✔
74
    if (rpcRsp.code == 0 && rpcRsp.contLen == rpcMsg.contLen) {
10,430!
75
      printf("response is received, size:%d\r\n", rpcMsg.contLen);
10,430✔
76
      if (rpcRsp.code == 0) totalSucc++;
10,430!
77
    } else {
78
      printf("response not received since %s\r\n", tstrerror(rpcRsp.code));
×
79
    }
80

81
    rpcFreeCont(rpcRsp.pCont);
10,430✔
82
    rpcRsp.pCont = NULL;
10,430✔
83
  }
84

85
  uint64_t endTime = taosGetTimestampUs();
269✔
86
  uint64_t elT = endTime - startTime;
269✔
87

88
  printf("\r\ntotal succ:%5d/%d\tcost:%8.2lf ms\tspeed:%8.2lf MB/s\r\n", totalSucc, pArgs->pktNum, elT / 1000.0,
269✔
89
         pArgs->pktLen / (elT / 1000000.0) / 1024.0 / 1024.0 * totalSucc);
269!
90

91
_OVER:
269✔
92
  if (clientRpc != NULL) {
269!
93
    rpcClose(clientRpc);
269✔
94
  }
95
  if (rpcRsp.pCont != NULL) {
269!
96
    rpcFreeCont(rpcRsp.pCont);
×
97
  }
98
}
269✔
99

100
static void shellProcessMsg(void *p, SRpcMsg *pRpc, SEpSet *pEpSet) {
×
101
  printf("request is received, size:%d\r\n", pRpc->contLen);
×
102
  fflush(stdout);
×
103
  SRpcMsg rsp = {.info = pRpc->info, .code = 0};
×
104
  rsp.pCont = rpcMallocCont(pRpc->contLen);
×
105
  if (rsp.pCont == NULL) {
×
106
    rsp.code = TSDB_CODE_OUT_OF_MEMORY;
×
107
  } else {
108
    rsp.contLen = pRpc->contLen;
×
109
  }
110
  rpcSendResponse(&rsp);
×
111
}
×
112

113
void shellNettestHandler(int32_t signum, void *sigInfo, void *context) { shellExit(); }
×
114

UNCOV
115
static void shellWorkAsServer() {
×
UNCOV
116
  SShellArgs *pArgs = &shell.args;
×
117

UNCOV
118
  if (pArgs->port == 0) {
×
UNCOV
119
    pArgs->port = 6030;
×
120
  }
UNCOV
121
  if (pArgs->host == NULL) {
×
UNCOV
122
    pArgs->host = "127.0.0.1";
×
123
  }
124

UNCOV
125
  SRpcInit rpcInit = {0};
×
UNCOV
126
  memcpy(rpcInit.localFqdn, pArgs->host, strlen(pArgs->host));
×
UNCOV
127
  rpcInit.localPort = pArgs->port;
×
UNCOV
128
  rpcInit.label = "CHK";
×
UNCOV
129
  rpcInit.numOfThreads = 2;
×
UNCOV
130
  rpcInit.cfp = (RpcCfp)shellProcessMsg;
×
UNCOV
131
  rpcInit.sessions = 10;
×
UNCOV
132
  rpcInit.connType = TAOS_CONN_SERVER;
×
UNCOV
133
  rpcInit.idleTime = 3000;
×
134

UNCOV
135
  taosVersionStrToInt(td_version, &rpcInit.compatibilityVer);
×
136

UNCOV
137
  void *serverRpc = rpcOpen(&rpcInit);
×
UNCOV
138
  if (serverRpc == NULL) {
×
UNCOV
139
    printf("failed to init net test server since %s\r\n", terrstr());
×
140
  } else {
141
    printf("network test server is initialized, %s:%u\r\n", pArgs->host, pArgs->port);
×
142
    taosSetSignal(SIGTERM, shellNettestHandler);
×
143
    while (1) taosMsleep(10);
×
144
  }
UNCOV
145
}
×
146

147
void shellTestNetWork() {
269✔
148
  (void)osDefaultInit();
269✔
149
  (void)rpcInit();
269✔
150

151
  if (strcmp(shell.args.netrole, "client") == 0) {
269!
152
    shellWorkAsClient();
269✔
153
  }
154

155
  if (strcmp(shell.args.netrole, "server") == 0) {
269!
UNCOV
156
    shellWorkAsServer();
×
157
  }
158
}
269✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc