Skip to content

Commit 1019906

Browse files
author
AswiniViswanathan
committed
Implement devtest tool for testing in cli
1 parent 4c68fd8 commit 1019906

19 files changed

+850
-36
lines changed

inc/em.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ class em_t :
6161
pthread_t m_tid;
6262
bool m_exit;
6363
bool m_is_al_em;
64+
bool dev_test_enable;
6465

6566
/**
6667
* @brief Set of hashed messages that have been sent in co-located systems
@@ -1149,7 +1150,9 @@ class em_t :
11491150
*/
11501151
static const char *state_2_str(em_state_t state);
11511152

1152-
1153+
1154+
bool get_devteststatus(){return dev_test_enable;}
1155+
void set_devteststatus(bool enable ) { dev_test_enable = enable;}
11531156
/**!
11541157
* @brief Initializes the EasyMesh interface with the specified parameters.
11551158
*

inc/em_base.h

+27
Original file line numberDiff line numberDiff line change
@@ -1925,6 +1925,7 @@ typedef enum {
19251925
em_cmd_type_btm_sta,
19261926
em_cmd_type_dev_init,
19271927
em_cmd_type_dev_test,
1928+
em_cmd_type_set_dev_test,
19281929
em_cmd_type_cfg_renew,
19291930
em_cmd_type_vap_config,
19301931
em_cmd_type_sta_list,
@@ -2544,6 +2545,7 @@ typedef enum {
25442545
em_bus_event_type_chirp,
25452546
em_bus_event_type_reset,
25462547
em_bus_event_type_dev_test,
2548+
em_bus_event_type_set_dev_test,
25472549
em_bus_event_type_get_network,
25482550
em_bus_event_type_get_device,
25492551
em_bus_event_type_remove_device,
@@ -3063,6 +3065,31 @@ typedef struct {
30633065
em_cli_type_t cli_type;
30643066
} em_cli_params_t;
30653067

3068+
typedef enum {
3069+
em_dev_test_type_ssid,
3070+
em_dev_test_type_channel,
3071+
em_dev_test_type_max
3072+
} em_dev_test_type;
3073+
3074+
typedef enum {
3075+
em_dev_test_status_inprogess,
3076+
em_dev_test_status_idle,
3077+
em_dev_test_status_complete,
3078+
em_dev_test_status_failed,
3079+
em_dev_test_status_max
3080+
} em_dev_test_status;
3081+
3082+
typedef struct{
3083+
int num_iteration[em_dev_test_type_max];
3084+
em_dev_test_type test_type[em_dev_test_type_max];
3085+
int enabled[em_dev_test_type_max];
3086+
int num_of_iteration_completed[em_dev_test_type_max];
3087+
int test_inprogress[em_dev_test_type_max];
3088+
em_dev_test_status test_status[em_dev_test_type_max];
3089+
em_haul_type_t haul_type;
3090+
em_freq_band_t freq_band;
3091+
}em_dev_test_info;
3092+
30663093
#ifndef SSL_KEY
30673094
#if OPENSSL_VERSION_NUMBER < 0x30000000L
30683095
#define SSL_KEY EC_KEY

inc/em_cli.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
#include "em_base.h"
2323
#include "em_cmd_exec.h"
24+
#include <pthread.h>
2425

2526
class em_cli_t {
2627

@@ -40,7 +41,7 @@ class em_cli_t {
4041
*/
4142
em_cmd_t& get_command(char *in, size_t in_len, em_network_node_t *node = NULL);
4243
em_long_string_t m_lib_dbg_file_name;
43-
44+
pthread_mutex_t cli_lock;
4445
public:
4546

4647
em_cli_params_t m_params;
@@ -141,7 +142,6 @@ class em_cli_t {
141142
*/
142143
void dump_lib_dbg(char *str);
143144

144-
145145
/**!
146146
* @brief Constructor for the em_cli_t class.
147147
*

inc/em_cli_apis.h

-1
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,6 @@ extern "C" {
399399
* @note Ensure that the format string is correctly specified to avoid runtime errors.
400400
*/
401401
void dump_lib_dbg(char *fmt);
402-
403402
#ifdef __cplusplus
404403
} // extern "C"
405404
#endif

inc/em_cmd_cli.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ class em_cmd_cli_t : public em_cmd_exec_t {
4747
*
4848
* @note Ensure that the node and buff are properly initialized before calling this function.
4949
*/
50-
int get_edited_node(em_network_node_t *node, const char *header, char *buff);
51-
50+
static int get_edited_node(em_network_node_t *node, const char *header, char *buff);
51+
5252
/**!
5353
* @brief Executes a command and stores the result.
5454
*
@@ -64,7 +64,6 @@ class em_cmd_cli_t : public em_cmd_exec_t {
6464
*/
6565
int execute(char *result);
6666

67-
6867
/**!
6968
* @brief Constructor for the em_cmd_cli_t class.
7069
*

inc/em_ctrl.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "dm_easy_mesh_ctrl.h"
2525
#include "em_orch_ctrl.h"
2626
#include "bus.h"
27+
#include "em_dev_test_ctrl.h"
2728

2829
class em_cmd_ctrl_t;
2930
class AlServiceAccessPoint;
@@ -34,7 +35,7 @@ class em_ctrl_t : public em_mgr_t {
3435
em_cmd_ctrl_t *m_ctrl_cmd;
3536
em_orch_ctrl_t *m_orch;
3637
bus_handle_t m_bus_hdl;
37-
38+
em_dev_test_t dev_test;
3839

3940
/**!
4041
* @brief Handles a bus event.
@@ -306,7 +307,8 @@ class em_ctrl_t : public em_mgr_t {
306307
*
307308
* @note Ensure that the event structure is properly initialized before passing it to this function.
308309
*/
309-
void handle_dev_test(em_bus_event_t *evt);
310+
void handle_get_dev_test(em_bus_event_t *evt);
311+
void handle_set_dev_test(em_bus_event_t *evt);
310312

311313
/**!
312314
* @brief Handles the get database event.

inc/em_dev_test_ctrl.h

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* Copyright 2023 Comcast Cable Communications Management, LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* SPDX-License-Identifier: Apache-2.0
17+
*/
18+
19+
#ifndef EMDEVTEST_H
20+
#define EMDEVTEST_H
21+
22+
#include "em_base.h"
23+
#define DEV_TEST_COMMAND_COUNT 2
24+
class em_dev_test_t {
25+
26+
public:
27+
em_dev_test_info dev_test_info;
28+
void encode(em_subdoc_info_t *subdoc, hash_map_t *m_em_map, bool update, bool autconfig_renew_status);
29+
void analyze_set_dev_test(em_bus_event_t *evt, hash_map_t *m_em_map);
30+
void decode(em_subdoc_info_t *subdoc, hash_map_t *m_em_map, const char *str);
31+
em_dev_test_t();
32+
~em_dev_test_t();
33+
34+
};
35+
36+
#endif

inc/em_orch.h

+11
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,17 @@ class em_orch_t {
259259
* @returns True if the command type is in progress, false otherwise.
260260
*/
261261
bool is_cmd_type_in_progress(em_bus_event_t *evt);
262+
263+
/**!
264+
* @brief Checks if a command type is currently in progress.
265+
*
266+
* This function determines whether a dev test commands types are identified by the
267+
* parameter `type`, is currently being processed or is in progress.
268+
*
269+
*
270+
* @returns True if the command type is in progress, false otherwise.
271+
*/
272+
bool get_dev_test_status();
262273

263274
/**!
264275
* @brief Checks if a command type is currently in progress.

src/agent/dm_easy_mesh_agent.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,13 @@ int dm_easy_mesh_agent_t::analyze_autoconfig_renew(em_bus_event_t *evt, em_cmd_t
159159
int num = 0;
160160
unsigned int index = 0;
161161
em_cmd_t *tmp;
162+
mac_addr_str_t mac_str;
162163

163164
raw = (em_bus_event_type_cfg_renew_params_t *)evt->u.raw_buff;
164165
memcpy(dm.get_controller_interface_mac(), raw->ctrl_src, sizeof(mac_address_t));
165166
memcpy(dm.get_radio(index)->get_radio_info()->intf.mac, raw->radio, sizeof(mac_address_t));
167+
dm_easy_mesh_t::macbytes_to_string(raw->radio, mac_str);
168+
printf("%s:%d Renew Radiomac = %s\n", __func__, __LINE__,mac_str);
166169
pcmd[num] = new em_cmd_cfg_renew_t(em_service_type_agent, evt->params, dm);
167170
tmp = pcmd[num];
168171
num++;

src/cli/em_cli.cpp

+13-7
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
#include "em_cli.h"
4444
#include <readline/readline.h>
4545
#include <readline/history.h>
46-
4746
em_cli_t g_cli;
4847

4948
em_network_node_t *em_cli_t::get_reset_tree(char *platform)
@@ -191,7 +190,16 @@ em_cmd_t& em_cli_t::get_command(char *in, size_t in_len, em_network_node_t *node
191190
strlen("Summary@RadioEnable"));
192191
}
193192
break;
194-
193+
case em_cmd_type_dev_test:
194+
if ((tmp = strstr(cmd->m_param.u.args.fixed_args, "DevTest")) != NULL) {
195+
*tmp = 0;
196+
}
197+
if (strncmp(args[num_args - 1], "1", strlen("1")) == 0) {
198+
strncat(cmd->m_param.u.args.fixed_args, "DevTest@update", strlen("DevTest@update"));
199+
} else {
200+
strncat(cmd->m_param.u.args.fixed_args, "DevTest", strlen("DevTest"));
201+
}
202+
break;
195203
default:
196204
break;
197205
}
@@ -210,7 +218,6 @@ em_cmd_t& em_cli_t::get_command(char *in, size_t in_len, em_network_node_t *node
210218

211219
em_cmd_cli_t::m_client_cmd_spec[idx].m_param.net_node = node;
212220

213-
214221
return em_cmd_cli_t::m_client_cmd_spec[idx];
215222
}
216223

@@ -221,6 +228,7 @@ em_network_node_t *em_cli_t::exec(char *in, size_t sz, em_network_node_t *node)
221228
em_network_node_t *new_node;
222229
em_cmd_cli_t *cli_cmd;
223230

231+
pthread_mutex_lock(&cli_lock);
224232
snprintf(cmd, sizeof(cmd), "%s", in);
225233
cli_cmd = new em_cmd_cli_t(get_command(cmd, sz, node));
226234

@@ -239,10 +247,9 @@ em_network_node_t *em_cli_t::exec(char *in, size_t sz, em_network_node_t *node)
239247
}
240248

241249
delete cli_cmd;
242-
250+
pthread_mutex_unlock(&cli_lock);
243251
new_node = em_net_node_t::get_network_tree(result);
244252
free(result);
245-
246253
return new_node;
247254
}
248255

@@ -266,13 +273,12 @@ void em_cli_t::dump_lib_dbg(char *str)
266273
return;
267274
}
268275

269-
fputs("\n==========\n", fp);
276+
fputs("\n==========\n", fp);
270277
fputs(str, fp);
271278

272279
fclose(fp);
273280
}
274281

275-
276282
int em_cli_t::init(em_cli_params_t *params)
277283
{
278284
memcpy(&m_params, params, sizeof(em_cli_params_t));

src/cli/em_cmd_cli.cpp

+23-6
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ em_cmd_params_t spec_params[] = {
4848
{.u = {.args = {0, {"", "", "", "", ""}, "none"}}},
4949
{.u = {.args = {2, {"", "", "", "", ""}, "Reset.json"}}},
5050
{.u = {.args = {1, {"", "", "", "", ""}, "Radiocap.json"}}},
51-
{.u = {.args = {1, {"", "", "", "", ""}, "DevTest"}}},
51+
{.u = {.args = {2, {"", "", "", "", ""}, "DevTest"}}},
5252
{.u = {.args = {1, {"", "", "", "", ""}, "CfgRenew.json"}}},
5353
{.u = {.args = {1, {"", "", "", "", ""}, "VapConfig.json"}}},
5454
{.u = {.args = {2, {"", "", "", "", ""}, "Network"}}},
@@ -73,6 +73,7 @@ em_cmd_params_t spec_params[] = {
7373
{.u = {.args = {2, {"", "", "", "", ""}, "ScanResult"}}},
7474
{.u = {.args = {2, {"", "", "", "", ""}, "MLDConfig"}}},
7575
{.u = {.args = {2, {"", "", "", "", ""}, "MLDReconfig"}}},
76+
{.u = {.args = {2, {"", "", "", "", ""}, "DevTest.json"}}},
7677
{.u = {.args = {0, {"", "", "", "", ""}, "max"}}},
7778
};
7879

@@ -106,7 +107,8 @@ em_cmd_t em_cmd_cli_t::m_client_cmd_spec[] = {
106107
em_cmd_t(em_cmd_type_set_policy, spec_params[24]),
107108
em_cmd_t(em_cmd_type_get_mld_config, spec_params[26]),
108109
em_cmd_t(em_cmd_type_mld_reconfig, spec_params[27]),
109-
em_cmd_t(em_cmd_type_max, spec_params[28]),
110+
em_cmd_t(em_cmd_type_set_dev_test, spec_params[28]),
111+
em_cmd_t(em_cmd_type_max, spec_params[29]),
110112
};
111113

112114
int em_cmd_cli_t::get_edited_node(em_network_node_t *node, const char *header, char *buff)
@@ -117,7 +119,8 @@ int em_cmd_cli_t::get_edited_node(em_network_node_t *node, const char *header, c
117119
bool found_result = false;
118120
unsigned int i;
119121
em_long_string_t key;
120-
char *net_id = m_cmd.m_param.u.args.args[1], *formatted, *node_str;
122+
em_small_string_t net_id = "OneWifiMesh";
123+
char *formatted, *node_str;
121124

122125
for (i = 0; i < node->num_children; i++) {
123126
if (strncmp(node->child[i]->key, "Result", strlen("Result")) == 0) {
@@ -155,7 +158,7 @@ int em_cmd_cli_t::get_edited_node(em_network_node_t *node, const char *header, c
155158
}
156159

157160
node_str = em_net_node_t::get_network_tree_string(new_node);
158-
m_cli.dump_lib_dbg(node_str);
161+
// m_cli.dump_lib_dbg(node_str);
159162
em_net_node_t::free_network_tree_string(node_str);
160163
obj = (cJSON *)em_net_node_t::network_tree_to_json(new_node);
161164
formatted = cJSON_Print(obj);
@@ -201,7 +204,20 @@ int em_cmd_cli_t::execute(char *result)
201204
case em_cmd_type_dev_test:
202205
bevt->type = em_bus_event_type_dev_test;
203206
info = &bevt->u.subdoc;
204-
snprintf(info->name, sizeof(info->name), "%s", param->u.args.fixed_args);
207+
strncpy(info->name, param->u.args.fixed_args, strlen(param->u.args.fixed_args) + 1);
208+
break;
209+
210+
case em_cmd_type_set_dev_test:
211+
if ((node = m_cmd.m_param.net_node) == NULL) {
212+
return -1;
213+
}
214+
bevt->type = em_bus_event_type_set_dev_test;
215+
info = &bevt->u.subdoc;
216+
strncpy(info->name, param->u.args.fixed_args, strlen(param->u.args.fixed_args) + 1);
217+
if ((bevt->data_len = get_edited_node(node, "SetDevTest", info->buff)) < 0) {
218+
printf("%s:%d: failed to open file at location:%s error:%d\n", __func__, __LINE__, param->u.args.fixed_args, errno);
219+
return -1;
220+
}
205221
break;
206222

207223
case em_cmd_type_cfg_renew:
@@ -485,7 +501,8 @@ int em_cmd_cli_t::execute(char *result)
485501

486502
/* Receive result. */
487503
if ((ret = recv(dsock, (unsigned char *)result, EM_MAX_EVENT_DATA_LEN, 0)) <= 0) {
488-
printf("%s:%d: result read error on socket, err:%d\n", __func__, __LINE__, errno);
504+
snprintf(result, sizeof(em_long_string_t), "%s:%d: result read error on socket, err:%d\n", __func__, __LINE__, errno);
505+
//g_cli.dump_lib_dbg(result);
489506
return -1;
490507
}
491508

0 commit comments

Comments
 (0)