diff --git a/apps/blestress/README.md b/apps/blestress/README.md index 8524397ace..b8188c77ca 100644 --- a/apps/blestress/README.md +++ b/apps/blestress/README.md @@ -5,18 +5,16 @@ BLE Stress Tests You need 2 controllers supported by MyNewt. One will become TX device, the other will become RX device. - 1. Set role (TX=0, RX=1) for current device in syscfg.yml - BLE_STRESS_TEST_ROLE: 1 + 1. Set role (TX/RX) using shell command. The RX has LED2 turned on. 2. Set (in syscfg.yml) number of times to repeat each tested action in use case, e.g. do 1000 times connect/disconnect to complete use case. - RX_STRESS_REPEAT: 1000 + BLE_STRESS_REPEAT: 1000 - 3. To perform only specific test, go to rx_stress.c, - find definition of rx_stress_main_task_fn(void *arg) and in place of - for-loop just paste function rx_stress_start(i), where i is id of test. + 3. To perform only specific test, as RX device use start_test command with + num parameter. NULL parameter or num=0 will run all tests. ****************************************************************************** @@ -90,13 +88,13 @@ No | Use case adapts to the advertised use case and runs a test. Stress Task vs Semaphore: - The rx_stress_start_auto function starts main stress test task that runs - all stress tests one by one. The tests are based on event handling, so to - synchronize main task with events, a semaphore is used. On use case start - there is 0 tokens for semaphore. After main task starts one of use cases, - it comes across a semaphore and has to wait. When use case is completed, - 1 token is released, so main task can use it to pass through semaphore. - The tx_stress_start_auto function works analogically. + The rx_stress_main_task_fn function starts main stress test task that runs + selected test or all stress tests one by one. The tests are based on event + handling, so to synchronize main task with events, a semaphore is used. + On use case start there is 0 tokens for semaphore. After main task starts + one of use cases, it comes across a semaphore and has to wait. When use cass + is completed, 1 token is released, so main task can use it to pass through + semaphore. The tx_stress_main_task_fn function works analogically. Newt target set example: diff --git a/apps/blestress/pkg.yml b/apps/blestress/pkg.yml index e56cdd64a2..847b558989 100644 --- a/apps/blestress/pkg.yml +++ b/apps/blestress/pkg.yml @@ -35,3 +35,5 @@ pkg.deps: - "@apache-mynewt-nimble/nimble/host/services/gap" - "@apache-mynewt-nimble/nimble/host/services/gatt" - "@apache-mynewt-nimble/nimble/host/store/config" + - "@apache-mynewt-core/sys/shell" + - "@apache-mynewt-core/util/parse_arg" diff --git a/apps/blestress/src/cmd.c b/apps/blestress/src/cmd.c new file mode 100644 index 0000000000..10f44340d2 --- /dev/null +++ b/apps/blestress/src/cmd.c @@ -0,0 +1,101 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#include +#include +#include +#include +#include "os/mynewt.h" +#include "bsp/bsp.h" +#include "hal/hal_gpio.h" + +#include "nimble/ble.h" +#include "nimble/nimble_opt.h" + +#include "console/console.h" +#include "shell/shell.h" + +#include "cmd.h" + +struct os_sem stress_main_sem; +struct os_sem tx_stress_start_sem; + +static int +device_role_rx(int argc, char **argv) +{ + hal_gpio_init_out(LED_2, 1); + hal_gpio_toggle(LED_2); + + console_printf("RX device"); + shell_register_default_module("rx_cmd"); + + console_printf("\033[1;36mRX device\033[0m\n"); + console_printf("Type start_test num=(1-15) to start a specific test " + "case\n"); + + return 0; +} + +static int +device_role_tx(int argc, char **argv) +{ + console_printf("\033[1;36mTX device\033[0m\n"); + + os_sem_release(&tx_stress_start_sem); + + return 0; +} + +#if MYNEWT_VAL(SHELL_CMD_HELP) +static const struct shell_cmd_help tx_stress_help = { + .summary = "TX Device: advertiser", + .usage = NULL, + .params = NULL, +}; + +static const struct shell_cmd_help rx_stress_help = { + .summary = "RX Device: scanner", + .usage = NULL, + .params = NULL, +}; +#endif + +static const struct shell_cmd stress_cmd[] = { + { + .sc_cmd = "rx", + .sc_cmd_func = device_role_rx, +#if MYNEWT_VAL(SHELL_CMD_HELP) + .help = &rx_stress_help, +#endif + }, + { + .sc_cmd = "tx", + .sc_cmd_func = device_role_tx, +#if MYNEWT_VAL(SHELL_CMD_HELP) + .help = &tx_stress_help, +#endif + }, +}; + +void +cmd_stress_init(void) +{ + shell_register("blestress", stress_cmd); + shell_register_default_module("blestress"); +} diff --git a/apps/blestress/src/cmd.h b/apps/blestress/src/cmd.h new file mode 100644 index 0000000000..0f1a21a53e --- /dev/null +++ b/apps/blestress/src/cmd.h @@ -0,0 +1,29 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#ifndef CMD_H +#define CMD_H + +#include +#include +#include "host/ble_uuid.h" + +void cmd_stress_init(void); + +#endif diff --git a/apps/blestress/src/cmd_rx.c b/apps/blestress/src/cmd_rx.c new file mode 100644 index 0000000000..312f1418a9 --- /dev/null +++ b/apps/blestress/src/cmd_rx.c @@ -0,0 +1,89 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#include +#include +#include +#include "os/mynewt.h" + +#include "console/console.h" +#include "shell/shell.h" + +#include "cmd.h" + +int test_case_num; +struct os_sem rx_stress_test_sem; + +static int +start_test_case(int argc, char **argv) +{ + uint8_t test_num; + uint8_t min = 1; + uint8_t max = 15; + uint8_t dflt = 0; + int rc; + + rc = parse_arg_init(argc - 1, argv +1); + if (rc != 0) { + return rc; + } + + test_num = parse_arg_uint8_bounds_dflt("num", min, max, dflt, &rc); + if (rc != 0) { + console_printf("Invalid test number parameter\n"); + return rc; + } + + test_case_num = test_num; + + os_sem_release(&rx_stress_test_sem); + + return 0; +} + +#if MYNEWT_VAL(SHELL_CMD_HELP) +static const struct shell_param stress_test_params[] = { + {"num", "Test case number, usage: =[1-15], default: 0"}, + {NULL, NULL} +}; + +static const struct shell_cmd_help test_help = { + .summary = "\nType start_test num (1-15) as a parameter to " + "start a specific test case.\nNULL parameter or num=0 will run" + " all test cases", + .usage = NULL, + .params = stress_test_params, +}; +#endif + +static const struct shell_cmd rx_cmd[] = { + { + .sc_cmd = "start_test", + .sc_cmd_func = start_test_case, +#if MYNEWT_VAL(SHELL_CMD_HELP) + .help = &test_help, +#endif + }, +}; + +void +rx_cmd_init(void) +{ + shell_register("rx_cmd", rx_cmd); +} diff --git a/apps/blestress/src/cmd_rx.h b/apps/blestress/src/cmd_rx.h new file mode 100644 index 0000000000..25f4c581ce --- /dev/null +++ b/apps/blestress/src/cmd_rx.h @@ -0,0 +1,29 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#ifndef CMD_RX_H +#define CMD_RX_H + +#include +#include "host/ble_uuid.h" +#include "cmd.h" + +void rx_cmd_init(void); + +#endif diff --git a/apps/blestress/src/main.c b/apps/blestress/src/main.c index c19e0cdd32..2bd88fc66b 100644 --- a/apps/blestress/src/main.c +++ b/apps/blestress/src/main.c @@ -21,8 +21,7 @@ #include #include "os/mynewt.h" #include "config/config.h" -#include "bsp.h" -#include "hal/hal_gpio.h" +#include "console/console.h" /* BLE */ #include "nimble/ble.h" @@ -33,7 +32,8 @@ /* Application-specified header. */ #include "rx_stress.h" #include "tx_stress.h" -#include "stress_gatt.h" +#include "cmd.h" +#include "cmd_rx.h" static void stress_test_on_reset(int reason) @@ -50,11 +50,8 @@ stress_test_on_sync(void) rc = ble_hs_util_ensure_addr(1); assert(rc == 0); -#if MYNEWT_VAL(BLE_STRESS_TEST_ROLE) - rx_stress_start_auto(); -#else - tx_stress_start_auto(); -#endif + rx_stress_task(); + tx_stress_task(); } /** @@ -71,10 +68,13 @@ mynewt_main(int argc, char **argv) int rc; sysinit(); + cmd_stress_init(); + rx_cmd_init(); ble_hs_cfg.reset_cb = stress_test_on_reset; ble_hs_cfg.sync_cb = stress_test_on_sync; ble_hs_cfg.store_status_cb = ble_store_util_status_rr; + ble_hs_cfg.gatts_register_cb = gatt_svr_register_cb; /* Please do not change name. Otherwise some tests could fail. */ rc = ble_svc_gap_device_name_set("STRESS"); @@ -85,12 +85,8 @@ mynewt_main(int argc, char **argv) rc = gatt_svr_init(); assert(rc == 0); -#if MYNEWT_VAL(BLE_STRESS_TEST_ROLE) - /* RX device */ - ble_hs_cfg.gatts_register_cb = gatt_svr_register_cb; - hal_gpio_init_out(LED_2, 1); - hal_gpio_toggle(LED_2); -#endif + console_printf("\033[1;36mBLE Stress app\033[0m\n"); + console_printf("Please type rx or tx to choose device role \n"); while (1) { os_eventq_run(os_eventq_dflt_get()); diff --git a/apps/blestress/src/rx_stress.c b/apps/blestress/src/rx_stress.c index d684ab40b4..8deafa50f9 100644 --- a/apps/blestress/src/rx_stress.c +++ b/apps/blestress/src/rx_stress.c @@ -19,6 +19,8 @@ #include #include "rx_stress.h" +#include "tx_stress.h" +#include "cmd_rx.h" /* UUID128 of stress test use cases*/ static uint8_t rx_stress_uuid128[STRESS_UUIDS_NUM][16]; @@ -57,10 +59,21 @@ static struct os_task rx_stress_main_task; static os_stack_t rx_stress_main_task_stack[RX_STRESS_MAIN_TASK_STACK_SIZE]; static struct os_sem rx_stress_main_sem; +int all_test_run; +extern int test_case_num; +extern struct os_sem rx_stress_test_sem; + static void rx_stress_on_test_finish(int test_num) { console_printf("\033[0;32m\nStress test %d completed\033[0m\n", test_num); + + if (!all_test_run) { + /* Print test result of specific test case */ + com_stress_print_report(rx_stress_ctx, test_case_num); + memset(&(rx_stress_ctx->con_stat[test_num]), 0, + sizeof(struct stress_con_stat)); + } os_sem_release(&rx_stress_main_sem); } @@ -215,6 +228,7 @@ rx_stress_0_gap_event(struct ble_gap_event *event, void *arg) ble_gap_ext_adv_stop(TEST_INSTANCE); ble_gap_terminate(event->connect.conn_handle, BLE_ERR_REM_USER_CONN_TERM); + os_sem_release(&rx_stress_main_sem); } else { /* Connection failed; resume advertising */ MODLOG_DFLT(INFO, "Connection failed; status=%d ", @@ -777,8 +791,8 @@ rx_stress_10_l2cap_event(struct ble_l2cap_event *event, void *arg) chan_info.peer_l2cap_mtu); struct ble_l2cap_sig_update_params params = { - .itvl_min = 0x0006,//BLE_GAP_INITIAL_CONN_ITVL_MIN - .itvl_max = 0x0006,//BLE_GAP_INITIAL_CONN_ITVL_MIN + .itvl_min = 0x0006,/*BLE_GAP_INITIAL_CONN_ITVL_MIN */ + .itvl_max = 0x0006,/*BLE_GAP_INITIAL_CONN_ITVL_MIN */ .slave_latency = 0x0000, .timeout_multiplier = 0x0100, }; @@ -1417,7 +1431,7 @@ rx_stress_start(int test_num) } /* Wait for the test to finish. Then 1 token will be released - * allowing to pass through semaphore. */ + * allowing to pass through semaphore. */ os_sem_pend(&rx_stress_main_sem, OS_TIMEOUT_NEVER); ble_gap_ext_adv_stop(SWITCHER_INSTANCE); @@ -1439,43 +1453,36 @@ stress_uuid_init() } } -static void -rx_stress_read_command_cb(void) -{ - console_printf("Start testing\n"); - os_sem_release(&rx_stress_main_sem); -} - -static void +void rx_stress_main_task_fn(void *arg) { int i; stress_uuid_init(); - console_printf("\033[1;36mRX device\033[0m\n"); - console_printf("Press ENTER to start: \n"); - console_init(&rx_stress_read_command_cb); - - /* Waite for pressing ENTER in console */ - os_sem_pend(&rx_stress_main_sem, OS_TIMEOUT_NEVER); - - /* Standard tests perform */ - for (i = 1; i < STRESS_UUIDS_NUM; ++i) { - /* Start test. */ - rx_stress_start(i); - } - - /* Print tests results */ - com_stress_print_report(rx_stress_ctx); - - /* Task should never return */ while (1) { + /* Waite for pressing ENTER in console */ + os_sem_pend(&rx_stress_test_sem, OS_TIMEOUT_NEVER); + + if (test_case_num == 0) { + for (i = 1; i < STRESS_UUIDS_NUM; ++i) { + /* Run all tests. */ + rx_stress_start(i); + } + all_test_run = 1; + console_printf("\033[0;32mAll tests completed\033[0m\n"); + for (i = 1; i < STRESS_UUIDS_NUM; ++i) { + /* Print test results of all tests */ + com_stress_print_report(rx_stress_ctx, i); + } + } else { + rx_stress_start(test_case_num); + } } } void -rx_stress_start_auto() +rx_stress_task() { /* Start task that will run all stress tests one by one. */ os_task_init(&rx_stress_main_task, "rx_stress_main_task", diff --git a/apps/blestress/src/rx_stress.h b/apps/blestress/src/rx_stress.h index b2f897197a..466bfa7a0b 100644 --- a/apps/blestress/src/rx_stress.h +++ b/apps/blestress/src/rx_stress.h @@ -44,10 +44,12 @@ extern "C" { /* * Executes stress tests one by one. */ +void rx_stress_task(); +void rx_stress_main_task_fn(void *arg); void rx_stress_start_auto(); #ifdef __cplusplus } #endif -#endif //_BLE_STRESS_RX_H +#endif /*_BLE_STRESS_RX_H */ diff --git a/apps/blestress/src/stress.c b/apps/blestress/src/stress.c index 1a9cb0c0d9..3bcc8ef411 100644 --- a/apps/blestress/src/stress.c +++ b/apps/blestress/src/stress.c @@ -22,75 +22,109 @@ static struct os_callout stress_timer_callout; void -com_stress_print_report(const struct com_stress_test_ctx *test_ctxs) +com_stress_print_report(const struct com_stress_test_ctx *test_ctxs, + int test_num) { - console_printf("\033[0;32mAll tests completed\033[0m\n"); - console_printf("Tests results:\n"); - - console_printf( - "\033[0;33mUse case 1 - Stress Connect -> Connect Cancel: \n\033[0m"); - console_printf("Con attempts = %d\n", test_ctxs->con_stat[1].attempts_num); - console_printf("Con success = %d\n", test_ctxs->con_stat[1].num); - - console_printf( - "\033[0;33mUse case 2 - Stress Connect/Disconnect legacy: \n\033[0m"); - console_printf("Con attempts = %d\n", test_ctxs->con_stat[2].attempts_num); - console_printf("Con success = %d\n", test_ctxs->con_stat[2].num); - - console_printf( - "\033[0;33mUse case 3 - Stress Connect/Disconnect ext adv: \n\033[0m"); - console_printf("Con attempts = %d\n", test_ctxs->con_stat[3].attempts_num); - console_printf("Con success = %d\n", test_ctxs->con_stat[3].num); - - console_printf( - "\033[0;33mUse case 4 - Stress connection params update (TX): \n\033[0m"); - console_printf("Params updates = %d\n", - test_ctxs->con_stat[4].prms_upd_num); - - console_printf( - "\033[0;33mUse case 5 - Stress connection params update (RX): \n\033[0m"); - console_printf("Params updates = %d\n", - test_ctxs->con_stat[5].prms_upd_num); - - console_printf("\033[0;33mUse case 6 - Stress Scan: \n\033[0m"); - console_printf("Received first packets = %d\n", - test_ctxs->s6_rcv_adv_first); - console_printf("Received all packets = %d\n", test_ctxs->s6_rcv_adv_suc); - - console_printf("\033[0;33mUse case 7 - Stress PHY Update (TX): \n\033[0m"); - console_printf("PHY updates = %d\n", test_ctxs->con_stat[7].phy_upd_num); - - console_printf("\033[0;33mUse case 8 - Stress PHY Update (RX): \n\033[0m"); - console_printf("PHY updates = %d\n", test_ctxs->con_stat[8].phy_upd_num); - - console_printf( - "\033[0;33mUse case 9 - Stress multi connection: \n\033[0m"); - console_printf("Max reached num of connections = %d\n", - test_ctxs->con_stat[9].max_num); - - console_printf("\033[0;33mUse case 10 - Stress L2CAP send: \n\033[0m"); - console_printf("Average bit rate = %d\n", test_ctxs->s10_bit_rate); - console_printf("Max received MTU = %lld\n", test_ctxs->s10_max_mtu); - - console_printf("\033[0;33mUse case 11 - " - "Stress Advertise/Connect/Continue adv \n\033[0m"); -// console_printf(" = %d\n",); - - console_printf("\033[0;33mUse case 12 - " - "Stress GATT indication: \n\033[0m"); - console_printf("Average bit rate = %d\n", test_ctxs->s12_notif_time); - - console_printf("\033[0;33mUse case 13 - " - "Stress GATT notification: \n\033[0m"); - console_printf("Average time = %d\n", test_ctxs->s13_notif_time); - - console_printf("\033[0;33mUse case 14 - " - "Stress GATT Subscribe/Notify/Unsubscribe: \n\033[0m"); - console_printf("Average time = %d\n", test_ctxs->s14_notif_time); - - console_printf("\033[0;33mUse case 15 - " - "Stress Connect/Send/Disconnect: \n\033[0m"); - console_printf("Con num = %d\n", test_ctxs->con_stat[15].num); + console_printf("Tests result:\n"); + + switch (test_num) { + case 1: + console_printf( + "\033[0;33mUse case 1 - " + "Stress Connect -> Connect Cancel: \n\033[0m"); + console_printf("Con attempts = %d\n", + test_ctxs->con_stat[1].attempts_num); + console_printf("Con success = %d\n", test_ctxs->con_stat[1].num); + break; + case 2: + console_printf( + "\033[0;33mUse case 2 - " + "Stress Connect/Disconnect legacy: \n\033[0m"); + console_printf("Con attempts = %d\n", + test_ctxs->con_stat[2].attempts_num); + console_printf("Con success = %d\n", test_ctxs->con_stat[2].num); + break; + case 3: + console_printf( + "\033[0;33mUse case 3 - " + "Stress Connect/Disconnect ext adv: \n\033[0m"); + console_printf("Con attempts = %d\n", + test_ctxs->con_stat[3].attempts_num); + console_printf("Con success = %d\n", test_ctxs->con_stat[3].num); + break; + case 4: + console_printf( + "\033[0;33mUse case 4 - " + "Stress connection params update (TX): \n\033[0m"); + console_printf("Params updates = %d\n", + test_ctxs->con_stat[4].prms_upd_num); + break; + case 5: + console_printf( + "\033[0;33mUse case 5 - " + "Stress connection params update (RX): \n\033[0m"); + console_printf("Params updates = %d\n", + test_ctxs->con_stat[5].prms_upd_num); + break; + case 6: + console_printf("\033[0;33mUse case 6 - Stress Scan: \n\033[0m"); + console_printf("Received first packets = %d\n", + test_ctxs->s6_rcv_adv_first); + console_printf("Received all packets = %d\n", + test_ctxs->s6_rcv_adv_suc); + break; + case 7: + console_printf("\033[0;33mUse case 7 - Stress PHY Update (TX): \n\033[0m"); + console_printf("PHY updates = %d\n", + test_ctxs->con_stat[7].phy_upd_num); + break; + case 8: + + console_printf("\033[0;33mUse case 8 - " + "Stress PHY Update (RX): \n\033[0m"); + console_printf("PHY updates = %d\n", + test_ctxs->con_stat[8].phy_upd_num); + break; + case 9: + console_printf( + "\033[0;33mUse case 9 - Stress multi connection: \n\033[0m"); + console_printf("Max reached num of connections = %d\n", + test_ctxs->con_stat[9].max_num); + break; + case 10: + console_printf("\033[0;33mUse case 10 - " + "Stress L2CAP send: \n\033[0m"); + console_printf("Average bit rate = %d\n", test_ctxs->s10_bit_rate); + console_printf("Max received MTU = %lld\n", + test_ctxs->s10_max_mtu); + break; + case 11: + console_printf("\033[0;33mUse case 11 - " + "Stress Advertise/Connect/Continue adv \n\033[0m"); + break; + case 12: + console_printf("\033[0;33mUse case 12 - " + "Stress GATT indication: \n\033[0m"); + console_printf("Average bit rate = %d\n", + test_ctxs->s12_notif_time); + break; + case 13: + console_printf("\033[0;33mUse case 13 - " + "Stress GATT notification: \n\033[0m"); + console_printf("Average time = %d\n", test_ctxs->s13_notif_time); + break; + case 14: + console_printf("\033[0;33mUse case 14 - " + "Stress GATT Subscribe/Notify/Unsubscribe: \n\033[0m"); + console_printf("Average time = %d\n", + test_ctxs->s14_notif_time); + break; + case 15: + console_printf("\033[0;33mUse case 15 - " + "Stress Connect/Send/Disconnect: \n\033[0m"); + console_printf("Con num = %d\n", test_ctxs->con_stat[15].num); + break; + } } void diff --git a/apps/blestress/src/stress.h b/apps/blestress/src/stress.h index db4fbb36f1..dfc85f3075 100644 --- a/apps/blestress/src/stress.h +++ b/apps/blestress/src/stress.h @@ -348,7 +348,8 @@ static const uint8_t test_6_pattern[STRESS_PAT_LEN] = { void stress_clear_ctx_reusable_var(struct com_stress_test_ctx *ctx); -void com_stress_print_report(const struct com_stress_test_ctx test_ctxs[]); +void com_stress_print_report(const struct com_stress_test_ctx test_ctxs[], + int test_num); int stress_fill_mbuf_with_pattern(struct os_mbuf *om, uint16_t len); diff --git a/apps/blestress/src/tx_stress.c b/apps/blestress/src/tx_stress.c index 18296e52f9..98574ce6e0 100644 --- a/apps/blestress/src/tx_stress.c +++ b/apps/blestress/src/tx_stress.c @@ -19,13 +19,11 @@ #include #include -#include -#include #include "tx_stress.h" /* Main test task priority. Set a high value so that the task does not * interfere with event handling */ -#define TX_STRESS_MAIN_TASK_PRIO 0xf0 +#define TX_STRESS_MAIN_TASK_PRIO 0xef #define BASE_UUID_LEN 13 /* Contexts for stress tests. */ @@ -41,6 +39,7 @@ static struct com_stress_test_ctx *tx_stress_ctx; static struct os_task tx_stress_main_task; static os_stack_t tx_stress_main_task_stack[TX_STRESS_MAIN_TASK_STACK_SIZE]; static struct os_sem tx_stress_main_sem; +extern struct os_sem tx_stress_start_sem; /* Test use case and address of test advertiser. */ static int tx_stress_use_case; static int completed_tests = 0; @@ -50,7 +49,10 @@ tx_stress_on_test_finish(int test_num) { console_printf("\033[0;32m\nStress test %d completed\033[0m\n", test_num); ++completed_tests; + com_stress_print_report(tx_stress_ctx, tx_stress_use_case); tx_stress_ctx->completed[test_num] = true; + memset(&(tx_stress_ctx->con_stat[test_num]), 0, + sizeof(struct stress_con_stat)); os_sem_release(&tx_stress_main_sem); } @@ -990,7 +992,8 @@ tx_stress_10_l2cap_send(struct ble_l2cap_chan *chan, uint8_t *data, return rc; } -void tx_stress_10_timer_ev_cb(struct os_event *ev) +void +tx_stress_10_timer_ev_cb(struct os_event *ev) { assert(ev != NULL); @@ -1527,9 +1530,11 @@ static void tx_stress_test_perform(int test_num) { /* Perform every test only once */ -// if (test_num <= 0 || tx_stress_ctx->completed[test_num] == true) { -// return; -// } +/* + if (test_num <= 0 || tx_stress_ctx->completed[test_num] == true) { + return; + } + */ tx_stress_ctx->cur_test_id = test_num; tx_stress_ctx->completed[test_num] = false; @@ -1608,7 +1613,7 @@ tx_stress_test_perform(int test_num) } /* Wait for the test to finish. Then 1 token will be released - * allowing to pass through semaphore. */ + * allowing to pass through semaphore. */ os_sem_pend(&tx_stress_main_sem, OS_TIMEOUT_NEVER); stress_clear_ctx_reusable_var(tx_stress_ctx); @@ -1621,11 +1626,13 @@ tx_stress_read_command_cb(void) os_sem_release(&tx_stress_main_sem); } -static void +void tx_stress_main_task_fn(void *arg) { int rc; + os_sem_pend(&tx_stress_start_sem, OS_TIMEOUT_NEVER); + tx_stress_ctx = &tx_stress_ctxD; console_printf("\033[1;36mTX device\033[0m\n"); @@ -1640,13 +1647,13 @@ tx_stress_main_task_fn(void *arg) assert(rc == 0); /* Start test 1 - Connect/Connect cancel */ - //tx_stress_test_perform(1); + /*tx_stress_test_perform(1); */ while (1) { console_printf("\033[0;36mStart scan for test\033[0m\n"); /* Scan for known UUID128 of one of the stress tests. */ - tx_stress_simple_scan(scan_for_test_gap_event, 2000); + tx_stress_simple_scan(scan_for_test_gap_event, 6000); /* Wait for the scan to find the test. Then 1 token will be * released allowing to pass through semaphore. */ @@ -1661,7 +1668,7 @@ tx_stress_main_task_fn(void *arg) } /* Print tests results */ - com_stress_print_report(tx_stress_ctx); + com_stress_print_report(tx_stress_ctx, tx_stress_use_case); /* Task should never return */ while (1) { @@ -1670,7 +1677,8 @@ tx_stress_main_task_fn(void *arg) } } -void tx_stress_start_auto() +void +tx_stress_task() { /* Start task that will run all stress tests one by one. */ os_task_init(&tx_stress_main_task, "tx_stress_main_task", diff --git a/apps/blestress/src/tx_stress.h b/apps/blestress/src/tx_stress.h index 83ed302031..dd5ff3a7e4 100644 --- a/apps/blestress/src/tx_stress.h +++ b/apps/blestress/src/tx_stress.h @@ -40,7 +40,8 @@ extern "C" { /* * Scan and execute tests one by one. */ -void tx_stress_start_auto(); +void tx_stress_task(); +void tx_stress_main_task_fn(void *arg); #ifdef __cplusplus } diff --git a/apps/blestress/syscfg.yml b/apps/blestress/syscfg.yml index b24280436b..f444ca88cc 100644 --- a/apps/blestress/syscfg.yml +++ b/apps/blestress/syscfg.yml @@ -41,6 +41,9 @@ syscfg.vals: # Change these settings: + # Enable the shell task. + SHELL_TASK: 1 + # Set 0 to print all debug logs, but keep in mind that plenty of # adv packets will be lost during scan tests. LOG_LEVEL: 1