Skip to content

Commit

Permalink
apps/blestress: extend functionality of blestress
Browse files Browse the repository at this point in the history
This commit adds new enchancements to blestress app.
  • Loading branch information
piotrnarajowski committed Mar 21, 2024
1 parent a830ac3 commit 951aed9
Show file tree
Hide file tree
Showing 14 changed files with 440 additions and 140 deletions.
24 changes: 11 additions & 13 deletions apps/blestress/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

******************************************************************************

Expand Down Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions apps/blestress/pkg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
101 changes: 101 additions & 0 deletions apps/blestress/src/cmd.c
Original file line number Diff line number Diff line change
@@ -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 <assert.h>
#include <inttypes.h>
#include <errno.h>
#include <string.h>
#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");
}
29 changes: 29 additions & 0 deletions apps/blestress/src/cmd.h
Original file line number Diff line number Diff line change
@@ -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 <inttypes.h>
#include <parse_arg/parse_arg.h>
#include "host/ble_uuid.h"

void cmd_stress_init(void);

#endif
89 changes: 89 additions & 0 deletions apps/blestress/src/cmd_rx.c
Original file line number Diff line number Diff line change
@@ -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 <assert.h>
#include <inttypes.h>
#include <string.h>
#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);
}
29 changes: 29 additions & 0 deletions apps/blestress/src/cmd_rx.h
Original file line number Diff line number Diff line change
@@ -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 <inttypes.h>
#include "host/ble_uuid.h"
#include "cmd.h"

void rx_cmd_init(void);

#endif
24 changes: 10 additions & 14 deletions apps/blestress/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
#include <stdio.h>
#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"
Expand All @@ -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)
Expand All @@ -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();
}

/**
Expand All @@ -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");
Expand All @@ -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());
Expand Down
Loading

0 comments on commit 951aed9

Please sign in to comment.