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

taosdata / TDengine / #3558

17 Dec 2024 06:05AM UTC coverage: 59.778% (+1.6%) from 58.204%
#3558

push

travis-ci

web-flow
Merge pull request #29179 from taosdata/merge/mainto3.0

merge: form main to 3.0 branch

132787 of 287595 branches covered (46.17%)

Branch coverage included in aggregate %.

104 of 191 new or added lines in 5 files covered. (54.45%)

6085 existing lines in 168 files now uncovered.

209348 of 284746 relevant lines covered (73.52%)

8164844.48 hits per line

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

55.46
/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
#include "tversion.h"
19

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

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

37
  taosVersionStrToInt(td_version, &rpcInit.compatibilityVer);
1✔
38
  clientRpc = rpcOpen(&rpcInit);
1✔
39
  if (clientRpc == NULL) {
1!
40
    printf("failed to init net test client since %s\r\n", terrstr());
×
41
    goto _OVER;
×
42
  }
43

44
  if (pArgs->host == NULL) {
1!
45
    pArgs->host = tsFirst;
1✔
46
  }
47
  char fqdn[TSDB_FQDN_LEN] = {0};
1✔
48
  tstrncpy(fqdn, pArgs->host, TSDB_FQDN_LEN);
1✔
49
  strtok(fqdn, ":");
1✔
50

51
  if (pArgs->port == 0) {
1!
52
    pArgs->port = tsServerPort;
1✔
53
  }
54

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

57
  tstrncpy(epSet.eps[0].fqdn, fqdn, TSDB_FQDN_LEN);
1✔
58
  epSet.eps[0].port = (uint16_t)pArgs->port;
1✔
59

60
  int32_t  totalSucc = 0;
1✔
61
  uint64_t startTime = taosGetTimestampUs();
1✔
62

63
  for (int32_t i = 0; i < pArgs->pktNum; ++i) {
11✔
64
    SRpcMsg rpcMsg = {.info.ahandle = (void *)0x9525, .info.notFreeAhandle = 1, .msgType = TDMT_DND_NET_TEST};
10✔
65
    rpcMsg.pCont = rpcMallocCont(pArgs->pktLen);
10✔
66
    rpcMsg.contLen = pArgs->pktLen;
10✔
67

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

77
    rpcFreeCont(rpcRsp.pCont);
10✔
78
    rpcRsp.pCont = NULL;
10✔
79
  }
80

81
  uint64_t endTime = taosGetTimestampUs();
1✔
82
  uint64_t elT = endTime - startTime;
1✔
83

84
  printf("\r\ntotal succ:%5d/%d\tcost:%8.2lf ms\tspeed:%8.2lf MB/s\r\n", totalSucc, pArgs->pktNum, elT / 1000.0,
1✔
85
         pArgs->pktLen / (elT / 1000000.0) / 1024.0 / 1024.0 * totalSucc);
1✔
86

87
_OVER:
1✔
88
  if (clientRpc != NULL) {
1!
89
    rpcClose(clientRpc);
1✔
90
  }
91
  if (rpcRsp.pCont != NULL) {
1!
92
    rpcFreeCont(rpcRsp.pCont);
×
93
  }
94
}
1✔
95

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

109
void shellNettestHandler(int32_t signum, void *sigInfo, void *context) { shellExit(); }
×
110

UNCOV
111
static void shellWorkAsServer() {
×
UNCOV
112
  SShellArgs *pArgs = &shell.args;
×
113

UNCOV
114
  if (pArgs->port == 0) {
×
UNCOV
115
    pArgs->port = tsServerPort;
×
116
  }
117

UNCOV
118
  SRpcInit rpcInit = {0};
×
UNCOV
119
  memcpy(rpcInit.localFqdn, tsLocalFqdn, strlen(tsLocalFqdn));
×
UNCOV
120
  rpcInit.localPort = pArgs->port;
×
UNCOV
121
  rpcInit.label = "CHK";
×
UNCOV
122
  rpcInit.numOfThreads = 2;
×
UNCOV
123
  rpcInit.cfp = (RpcCfp)shellProcessMsg;
×
UNCOV
124
  rpcInit.sessions = 10;
×
UNCOV
125
  rpcInit.connType = TAOS_CONN_SERVER;
×
UNCOV
126
  rpcInit.idleTime = tsShellActivityTimer * 1000;
×
127

UNCOV
128
  taosVersionStrToInt(td_version, &rpcInit.compatibilityVer);
×
129

UNCOV
130
  void *serverRpc = rpcOpen(&rpcInit);
×
UNCOV
131
  if (serverRpc == NULL) {
×
UNCOV
132
    printf("failed to init net test server since %s\r\n", terrstr());
×
133
  } else {
134
    printf("network test server is initialized, port:%u\r\n", pArgs->port);
×
135
    taosSetSignal(SIGTERM, shellNettestHandler);
×
136
    while (1) taosMsleep(10);
×
137
  }
UNCOV
138
}
×
139

140
void shellTestNetWork() {
1✔
141
  if (strcmp(shell.args.netrole, "client") == 0) {
1!
142
    shellWorkAsClient();
1✔
143
  }
144

145
  if (strcmp(shell.args.netrole, "server") == 0) {
1!
UNCOV
146
    shellWorkAsServer();
×
147
  }
148
}
1✔
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