Skip to content

Commit

Permalink
tests: tracing: add tests for tracing features
Browse files Browse the repository at this point in the history
Mostly build tests now, will be extended to verify CTF output once we
have this feature in sanitycheck.

Signed-off-by: Anas Nashif <[email protected]>
  • Loading branch information
nashif committed Sep 27, 2019
1 parent 8b976b1 commit 32a9435
Show file tree
Hide file tree
Showing 6 changed files with 138 additions and 12 deletions.
1 change: 1 addition & 0 deletions boards/arm/qemu_cortex_r5/qemu_cortex_r5.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,4 @@ testing:
- userspace
- util
- xip
- tracing
12 changes: 0 additions & 12 deletions samples/synchronization/sample.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,3 @@ tests:
regex:
- "threadA: Hello World from (.*)!"
- "threadB: Hello World from (.*)!"
sample.synchronization.openocd:
tags: kernel synchronization
extra_configs:
- CONFIG_OPENOCD_SUPPORT=y
arch_exclude: posix xtensa x86_64
platform_exclude: qemu_x86_long
harness: console
harness_config:
type: multi_line
regex:
- "thread_a: Hello World from (.*)!"
- "thread_b: Hello World from (.*)!"
8 changes: 8 additions & 0 deletions tests/subsys/debug/tracing/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.13.1)

include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
project(tracing_tests)

target_sources(app PRIVATE src/main.c)
2 changes: 2 additions & 0 deletions tests/subsys/debug/tracing/prj.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# enable to use thread names
CONFIG_THREAD_NAME=y
100 changes: 100 additions & 0 deletions tests/subsys/debug/tracing/src/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*
* Copyright (c) 2019 Intel Corporation
* Copyright (c) 2012-2014 Wind River Systems, Inc.
*
* SPDX-License-Identifier: Apache-2.0
*/

#include <zephyr.h>
#include <sys/printk.h>

/*
* The hello world demo has two threads that utilize semaphores and sleeping
* to take turns printing a greeting message at a controlled rate. The demo
* shows both the static and dynamic approaches for spawning a thread; a real
* world application would likely use the static approach for both threads.
*/


/* size of stack area used by each thread */
#define STACKSIZE 1024

/* scheduling priority used by each thread */
#define PRIORITY 7

/* delay between greetings (in ms) */
#define SLEEPTIME 500


/*
* @param my_name thread identification string
* @param my_sem thread's own semaphore
* @param other_sem other thread's semaphore
*/
void helloLoop(const char *my_name,
struct k_sem *my_sem, struct k_sem *other_sem)
{
const char *tname;

while (1) {
/* take my semaphore */
k_sem_take(my_sem, K_FOREVER);

/* say "hello" */
tname = k_thread_name_get(k_current_get());
if (tname == NULL) {
printk("%s: Hello World from %s!\n",
my_name, CONFIG_BOARD);
} else {
printk("%s: Hello World from %s!\n",
tname, CONFIG_BOARD);
}

/* wait a while, then let other thread have a turn */
k_sleep(SLEEPTIME);
k_sem_give(other_sem);
}
}

/* define semaphores */

K_SEM_DEFINE(threadA_sem, 1, 1); /* starts off "available" */
K_SEM_DEFINE(threadB_sem, 0, 1); /* starts off "not available" */


/* threadB is a dynamic thread that is spawned by threadA */

void threadB(void *dummy1, void *dummy2, void *dummy3)
{
ARG_UNUSED(dummy1);
ARG_UNUSED(dummy2);
ARG_UNUSED(dummy3);

/* invoke routine to ping-pong hello messages with threadA */
helloLoop(__func__, &threadB_sem, &threadA_sem);
}

K_THREAD_STACK_DEFINE(threadB_stack_area, STACKSIZE);
static struct k_thread threadB_data;

/* threadA is a static thread that is spawned automatically */

void threadA(void *dummy1, void *dummy2, void *dummy3)
{
ARG_UNUSED(dummy1);
ARG_UNUSED(dummy2);
ARG_UNUSED(dummy3);

/* spawn threadB */
k_tid_t tid = k_thread_create(&threadB_data, threadB_stack_area,
STACKSIZE, threadB, NULL, NULL, NULL,
PRIORITY, 0, K_NO_WAIT);

k_thread_name_set(tid, "thread_b");

/* invoke routine to ping-pong hello messages with threadB */
helloLoop(__func__, &threadA_sem, &threadB_sem);
}

K_THREAD_DEFINE(thread_a, STACKSIZE, threadA, NULL, NULL, NULL,
PRIORITY, 0, K_NO_WAIT);
27 changes: 27 additions & 0 deletions tests/subsys/debug/tracing/testcase.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
common:
tags: tracing debug
harness: console
harness_config:
type: multi_line
regex:
- "thread_a: Hello World from (.*)!"
- "thread_b: Hello World from (.*)!"
tests:
tracing.sysview:
platform_whitelist: nrf52840_pca10056
extra_configs:
- CONFIG_SEGGER_SYSTEMVIEW=y
- CONFIG_USE_SEGGER_RTT=y
tracing.ctf:
platform_whitelist: native_posix
extra_configs:
- CONFIG_TRACING_CTF=y
tracing.cpu_stats:
platform_whitelist: nrf52840_pca10056
extra_configs:
- CONFIG_TRACING_CPU_STATS=y
tracing.openocd:
extra_configs:
- CONFIG_OPENOCD_SUPPORT=y
arch_exclude: posix xtensa x86_64
platform_exclude: qemu_x86_long

0 comments on commit 32a9435

Please sign in to comment.