Skip to content

Commit 6fc81ad

Browse files
authored
Merge pull request #21514 from mguetschow/shell-commands-xfa
treewide: migrate to XFA SHELL_COMMAND
2 parents 3fa8d00 + 6abf12f commit 6fc81ad

File tree

19 files changed

+162
-285
lines changed

19 files changed

+162
-285
lines changed

examples/networking/coap/gcoap_dtls/client.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "net/sock/udp.h"
3232
#include "net/sock/util.h"
3333
#include "od.h"
34+
#include "shell.h"
3435
#include "uri_parser.h"
3536

3637
#include "gcoap_example.h"
@@ -229,7 +230,13 @@ static int _uristr2remote(const char *uri, sock_udp_ep_t *remote, const char **p
229230
return 0;
230231
}
231232

232-
int gcoap_cli_cmd(int argc, char **argv)
233+
/**
234+
* @brief Shell interface exposing the client side features of gcoap
235+
* @param argc Number of shell arguments (including shell command name)
236+
* @param argv Shell argument values (including shell command name)
237+
* @return Exit status of the shell command
238+
*/
239+
static int _cli_cmd(int argc, char **argv)
233240
{
234241
/* Ordered like the RFC method code numbers, but off by 1. GET is code 0. */
235242
char *method_codes[] = {"ping", "get", "post", "put"};
@@ -397,3 +404,5 @@ int gcoap_cli_cmd(int argc, char **argv)
397404
help:
398405
return _print_usage(argv);
399406
}
407+
408+
SHELL_COMMAND(coap, "CoAP example", _cli_cmd);

examples/networking/coap/gcoap_dtls/gcoap_example.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,6 @@ extern "C" {
3535

3636
extern uint16_t req_count; /**< Counts requests sent by CLI. */
3737

38-
/**
39-
* @brief Shell interface exposing the client side features of gcoap
40-
* @param argc Number of shell arguments (including shell command name)
41-
* @param argv Shell argument values (including shell command name)
42-
* @return Exit status of the shell command
43-
*/
44-
int gcoap_cli_cmd(int argc, char **argv);
45-
4638
/**
4739
* @brief Registers the CoAP resources exposed in the example app
4840
*

examples/networking/coap/gcoap_dtls/main.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,6 @@
2929
#define MAIN_QUEUE_SIZE (4)
3030
static msg_t _main_msg_queue[MAIN_QUEUE_SIZE];
3131

32-
static const shell_command_t shell_commands[] = {
33-
{ "coap", "CoAP example", gcoap_cli_cmd },
34-
{ NULL, NULL, NULL }
35-
};
36-
3732
int main(void)
3833
{
3934
/* for the thread running the shell */
@@ -44,7 +39,7 @@ int main(void)
4439
/* start shell */
4540
puts("All up, running the shell now");
4641
char line_buf[SHELL_DEFAULT_BUFSIZE];
47-
shell_run(shell_commands, line_buf, SHELL_DEFAULT_BUFSIZE);
42+
shell_run(NULL, line_buf, SHELL_DEFAULT_BUFSIZE);
4843

4944
/* should never be reached */
5045
return 0;

tests/build_system/test_tools/main.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ static int cmd_true(int argc, char **argv)
4545
return 0;
4646
}
4747

48+
SHELL_COMMAND(true, "do nothing, successfully", cmd_true);
49+
4850
/**
4951
* @brief shellping, replies shellpong
5052
*
@@ -64,6 +66,8 @@ static int cmd_shellping(int argc, char **argv)
6466
return 0;
6567
}
6668

69+
SHELL_COMMAND(shellping, "Just print 'shellpong'", cmd_shellping);
70+
6771
/**
6872
* @brief Uppercase the first word
6973
*
@@ -95,6 +99,8 @@ static int cmd_toupper(int argc, char **argv)
9599
return 0;
96100
}
97101

102+
SHELL_COMMAND(toupper, "uppercase first argument", cmd_toupper);
103+
98104
/**
99105
* @brief getchar, read one character
100106
*
@@ -114,20 +120,14 @@ static int cmd_getchar(int argc, char **argv)
114120
return 0;
115121
}
116122

117-
static const shell_command_t shell_commands[] = {
118-
{ "shellping", "Just print 'shellpong'", cmd_shellping },
119-
{ "true", "do nothing, successfully", cmd_true },
120-
{ "toupper", "uppercase first argument", cmd_toupper },
121-
{ "getchar", "Get one character and print the hex value", cmd_getchar },
122-
{ NULL, NULL, NULL }
123-
};
123+
SHELL_COMMAND(getchar, "Get one character and print the hex value", cmd_getchar);
124124

125125
int main(void)
126126
{
127127
puts("Running 'tests_tools' application");
128128

129129
char line_buf[SHELL_DEFAULT_BUFSIZE];
130-
shell_run(shell_commands, line_buf, SHELL_DEFAULT_BUFSIZE);
130+
shell_run(NULL, line_buf, SHELL_DEFAULT_BUFSIZE);
131131

132132
return 0;
133133
}

tests/cpu/cortexm_address_check/main.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,7 @@ static int cmd_check(int argc, char **argv)
4747
return 0;
4848
}
4949

50-
static const shell_command_t shell_commands[] = {
51-
{ "check", "Check address", cmd_check},
52-
{ NULL, NULL, NULL }
53-
};
50+
SHELL_COMMAND(check, "Check address", cmd_check);
5451

5552
int main(void)
5653
{
@@ -61,6 +58,6 @@ int main(void)
6158

6259
/* run the shell */
6360
char line_buf[SHELL_DEFAULT_BUFSIZE];
64-
shell_run(shell_commands, line_buf, SHELL_DEFAULT_BUFSIZE);
61+
shell_run(NULL, line_buf, SHELL_DEFAULT_BUFSIZE);
6562
return 0;
6663
}

tests/sys/atomic_utils/main.c

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -812,20 +812,6 @@ static uint64_t stats_ops;
812812
static uint64_t stats_tests;
813813
static uint64_t stats_failures;
814814

815-
static int sc_tearing_test(int argc, char **argv);
816-
static int sc_lost_update_test(int argc, char **argv);
817-
static int sc_stats(int argc, char **argv);
818-
static int sc_stop(int argc, char **argv);
819-
static int sc_list(int argc, char **argv);
820-
static const shell_command_t shell_commands[] = {
821-
{ "tearing_test", "Run a store/load tearing test", sc_tearing_test },
822-
{ "lost_update_test", "Run a lost update test", sc_lost_update_test },
823-
{ "stats", "Show stats of current test", sc_stats },
824-
{ "stop", "Stop running test", sc_stop },
825-
{ "list", "List functions that can be tested", sc_list },
826-
{ NULL, NULL, NULL }
827-
};
828-
829815
static void tearing_test_worker(test_state_t *state)
830816
{
831817
switch (state->conf.width) {
@@ -1100,6 +1086,8 @@ static void *thread_checker_func(void *arg)
11001086
return NULL;
11011087
}
11021088

1089+
static int sc_stop(int argc, char **argv);
1090+
11031091
static void *thread_timeout_func(void *arg)
11041092
{
11051093
(void)arg;
@@ -1226,6 +1214,8 @@ static int sc_tearing_test(int argc, char **argv)
12261214
return select_func_and_start_test(argv[1], timeout);
12271215
}
12281216

1217+
SHELL_COMMAND(tearing_test, "Run a store/load tearing test", sc_tearing_test );
1218+
12291219
static int sc_lost_update_test(int argc, char **argv)
12301220
{
12311221
if ((argc != 2) && (argc != 3)) {
@@ -1253,6 +1243,8 @@ static int sc_lost_update_test(int argc, char **argv)
12531243
return select_func_and_start_test(argv[1], timeout);
12541244
}
12551245

1246+
SHELL_COMMAND(lost_update_test, "Run a lost update test", sc_lost_update_test );
1247+
12561248
static int sc_stats(int argc, char **argv)
12571249
{
12581250
(void)argc;
@@ -1272,6 +1264,8 @@ static int sc_stats(int argc, char **argv)
12721264
return 0;
12731265
}
12741266

1267+
SHELL_COMMAND(stats, "Show stats of current test", sc_stats );
1268+
12751269
static int sc_stop(int argc, char **argv)
12761270
{
12771271
(void)argc;
@@ -1291,6 +1285,8 @@ static int sc_stop(int argc, char **argv)
12911285
return 0;
12921286
}
12931287

1288+
SHELL_COMMAND(stop, "Stop running test", sc_stop );
1289+
12941290
static int sc_list(int argc, char **argv)
12951291
{
12961292
(void)argc;
@@ -1319,6 +1315,8 @@ static int sc_list(int argc, char **argv)
13191315
return 0;
13201316
}
13211317

1318+
SHELL_COMMAND(list, "List functions that can be tested", sc_list );
1319+
13221320
int main(void)
13231321
{
13241322
thread_create(thread_worker_stack, sizeof(thread_worker_stack),
@@ -1356,7 +1354,7 @@ int main(void)
13561354
"test is working as expected.\n"
13571355
);
13581356
char line_buf[SHELL_DEFAULT_BUFSIZE];
1359-
shell_run(shell_commands, line_buf, SHELL_DEFAULT_BUFSIZE);
1357+
shell_run(NULL, line_buf, SHELL_DEFAULT_BUFSIZE);
13601358

13611359
return 0;
13621360
}

tests/sys/congure_abe/main.c

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,28 +24,12 @@
2424

2525
#include "congure_impl.h"
2626

27-
static int _json_statham(int argc, char **argv);
28-
static int _set_cwnd(int argc, char **argv);
29-
static int _get_fr_calls(int argc, char **argv);
30-
static int _set_same_wnd_adv_res(int argc, char **argv);
31-
3227
static congure_abe_snd_t _congure_state;
33-
static const shell_command_t shell_commands[] = {
34-
{ "state", "Prints current CongURE state object as JSON", _json_statham },
35-
{ "set_cwnd", "Set cwnd member for CongURE state object", _set_cwnd },
36-
{ "get_ff_calls",
37-
"Get the number of calls to fast_retransmit callback of CongURE state "
38-
"object", _get_fr_calls },
39-
{ "set_same_wnd_adv",
40-
"Set the result for the same_window_advertised callback of CongURE state "
41-
"object", _set_same_wnd_adv_res },
42-
{ NULL, NULL, NULL }
43-
};
4428

4529
int main(void)
4630
{
4731
char line_buf[SHELL_DEFAULT_BUFSIZE];
48-
shell_run(shell_commands, line_buf, SHELL_DEFAULT_BUFSIZE);
32+
shell_run(NULL, line_buf, SHELL_DEFAULT_BUFSIZE);
4933
return 0;
5034
}
5135

@@ -109,6 +93,8 @@ static int _json_statham(int argc, char **argv)
10993
return 0;
11094
}
11195

96+
SHELL_COMMAND(state, "Prints current CongURE state object as JSON", _json_statham );
97+
11298
static int _set_cwnd(int argc, char **argv)
11399
{
114100
uint32_t tmp;
@@ -125,6 +111,8 @@ static int _set_cwnd(int argc, char **argv)
125111
return 0;
126112
}
127113

114+
SHELL_COMMAND(set_cwnd, "Set cwnd member for CongURE state object", _set_cwnd );
115+
128116
static int _get_fr_calls(int argc, char **argv)
129117
{
130118
(void)argc;
@@ -136,6 +124,9 @@ static int _get_fr_calls(int argc, char **argv)
136124
return 0;
137125
}
138126

127+
SHELL_COMMAND(get_ff_calls, "Get the number of calls to fast_retransmit"
128+
"callback of CongURE state object", _get_fr_calls);
129+
139130
static int _set_same_wnd_adv_res(int argc, char **argv)
140131
{
141132
if (argc < 2) {
@@ -148,4 +139,7 @@ static int _set_same_wnd_adv_res(int argc, char **argv)
148139
return 0;
149140
}
150141

142+
SHELL_COMMAND(set_same_wnd_adv, "Set the result for the same_window_advertised"
143+
"callback of CongURE state object", _set_same_wnd_adv_res);
144+
151145
/** @} */

tests/sys/congure_quic/main.c

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -24,36 +24,12 @@
2424

2525
#include "congure_impl.h"
2626

27-
static int _json_statham(int argc, char **argv);
28-
static int _set_cwnd(int argc, char **argv);
29-
static int _set_ssthresh(int argc, char **argv);
30-
static int _set_limited(int argc, char **argv);
31-
static int _set_max_ack_delay(int argc, char **argv);
32-
static int _set_recovery_start(int argc, char **argv);
33-
static int _get_event_cb(int argc, char **argv);
34-
3527
static congure_quic_snd_t _congure_state;
36-
static const shell_command_t shell_commands[] = {
37-
{ "state", "Prints current CongURE state object as JSON", _json_statham },
38-
{ "set_cwnd", "Set cwnd member for CongURE state object", _set_cwnd },
39-
{ "set_ssthresh", "Set ssthresh member for CongURE state object",
40-
_set_ssthresh },
41-
{ "set_limited", "Set limited member for CongURE state object",
42-
_set_limited },
43-
{ "set_max_ack_delay", "Set max_ack_delay member for CongURE state object",
44-
_set_max_ack_delay },
45-
{ "set_recovery_start", "Set recovery_start member for CongURE state object",
46-
_set_recovery_start },
47-
{ "get_event_cb",
48-
"Get state of cong_event_cb mock of CongURE state object",
49-
_get_event_cb },
50-
{ NULL, NULL, NULL }
51-
};
5228

5329
int main(void)
5430
{
5531
char line_buf[SHELL_DEFAULT_BUFSIZE];
56-
shell_run(shell_commands, line_buf, SHELL_DEFAULT_BUFSIZE);
32+
shell_run(NULL, line_buf, SHELL_DEFAULT_BUFSIZE);
5733
return 0;
5834
}
5935

@@ -124,6 +100,8 @@ static int _json_statham(int argc, char **argv)
124100
return 0;
125101
}
126102

103+
SHELL_COMMAND(state, "Prints current CongURE state object as JSON", _json_statham);
104+
127105
static int _set_cwnd(int argc, char **argv)
128106
{
129107
uint32_t tmp;
@@ -140,6 +118,8 @@ static int _set_cwnd(int argc, char **argv)
140118
return 0;
141119
}
142120

121+
SHELL_COMMAND(set_cwnd, "Set cwnd member for CongURE state object", _set_cwnd);
122+
143123
static int _set_ssthresh(int argc, char **argv)
144124
{
145125
uint32_t tmp;
@@ -156,6 +136,8 @@ static int _set_ssthresh(int argc, char **argv)
156136
return 0;
157137
}
158138

139+
SHELL_COMMAND(set_ssthresh, "Set ssthresh member for CongURE state object", _set_ssthresh);
140+
159141
static int _set_limited(int argc, char **argv)
160142
{
161143
uint32_t tmp;
@@ -172,6 +154,8 @@ static int _set_limited(int argc, char **argv)
172154
return 0;
173155
}
174156

157+
SHELL_COMMAND(set_limited, "Set limited member for CongURE state object", _set_limited);
158+
175159
static int _set_max_ack_delay(int argc, char **argv)
176160
{
177161
uint32_t tmp;
@@ -188,6 +172,9 @@ static int _set_max_ack_delay(int argc, char **argv)
188172
return 0;
189173
}
190174

175+
SHELL_COMMAND(set_max_ack_delay,
176+
"Set max_ack_delay member for CongURE state object", _set_max_ack_delay);
177+
191178
static int _set_recovery_start(int argc, char **argv)
192179
{
193180
if (argc < 2) {
@@ -198,6 +185,9 @@ static int _set_recovery_start(int argc, char **argv)
198185
return 0;
199186
}
200187

188+
SHELL_COMMAND(set_recovery_start,
189+
"Set recovery_start member for CongURE state object", _set_recovery_start);
190+
201191
static int _get_event_cb(int argc, char **argv)
202192
{
203193
(void)argc;
@@ -215,4 +205,7 @@ static int _get_event_cb(int argc, char **argv)
215205
return 0;
216206
}
217207

208+
SHELL_COMMAND(get_event_cb,
209+
"Get state of cong_event_cb mock of CongURE state object", _get_event_cb);
210+
218211
/** @} */

0 commit comments

Comments
 (0)