Skip to content

Commit b0f2e3e

Browse files
jithu83Anas Nashif
authored andcommitted
tests: kernel: import obj_tracing test to unified kernel
obj_tracing test from legacy modified to use unified APIs directly. Jira: ZEP-932 Change-Id: Ib5d300334e527b842668be076c94c40b65d7cbe4 Signed-off-by: Jithu Joseph <[email protected]>
1 parent 38aaa7c commit b0f2e3e

File tree

9 files changed

+295
-0
lines changed

9 files changed

+295
-0
lines changed

tests/kernel/obj_tracing/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
BOARD ?= qemu_x86
2+
CONF_FILE = prj.conf
3+
4+
include ${ZEPHYR_BASE}/Makefile.test
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
Test Description
2+
----------------
3+
4+
The object tracing test is a sanity test to verify that the
5+
object tracing API remains healthy.
6+
7+
It uses the philsophers as an application that implements
8+
multiple threads that are synchronized with semaphores.
9+
10+
The application initializes their objects and starts the philosophers'
11+
thread interaction. A specific thread, called object monitor, accesses
12+
the object tracing API and reports the number of expected objects.
13+
14+
The sanity test script expects each test to finish its execution
15+
and then it considers the test completed. For that reason the
16+
philosophers' threads execute a finite number of iterations. After
17+
that the application execution ends.
18+
19+
Sample Output
20+
--------------
21+
***** BOOTING ZEPHYR OS vxxxx - BUILD: yyyyy *****
22+
tc_start() - OBJECT TRACING TEST
23+
SEMAPHORE REF: 0x001031f0
24+
SEMAPHORE REF: 0x001031dc
25+
SEMAPHORE REF: 0x001031c8
26+
SEMAPHORE REF: 0x001031b4
27+
SEMAPHORE REF: 0x001031a0
28+
SEMAPHORE QUANTITY: 5
29+
===================================================================
30+
PASS - object_monitor.
31+
COOP: 0x00102da0 OPTIONS: 0x00, STATE: 0x00
32+
COOP: 0x00104204 OPTIONS: 0x00, STATE: 0x00
33+
COOP: 0x00103e04 OPTIONS: 0x00, STATE: 0x00
34+
COOP: 0x00103a04 OPTIONS: 0x00, STATE: 0x02
35+
COOP: 0x00103604 OPTIONS: 0x00, STATE: 0x02
36+
COOP: 0x00103204 OPTIONS: 0x00, STATE: 0x00
37+
PREMPT: 0x00105340 OPTIONS: 0x00, STATE: 0x02
38+
COOP: 0x00104e40 OPTIONS: 0x01, STATE: 0x00
39+
THREAD QUANTITY: 8
40+
===================================================================
41+
PASS - test_thread_monitor.
42+
===================================================================
43+
PROJECT EXECUTION SUCCESSFUL

tests/kernel/obj_tracing/prj.conf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
CONFIG_DEBUG_TRACING_KERNEL_OBJECTS=y
2+
CONFIG_THREAD_MONITOR=y
3+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
ccflags-y += -I${ZEPHYR_BASE}/tests/include
2+
3+
obj-y = philosopher.o main.o object_monitor.o
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/* phil_task.c - dining philosophers */
2+
3+
/*
4+
* Copyright (c) 2011-2016 Wind River Systems, Inc.
5+
*
6+
* SPDX-License-Identifier: Apache-2.0
7+
*/
8+
9+
#include <zephyr.h>
10+
#include "phil.h"
11+
12+
#define STSIZE 1024
13+
14+
extern void phil_entry(void);
15+
extern void object_monitor(void);
16+
17+
char __stack phil_stack[N_PHILOSOPHERS][STSIZE];
18+
char __stack mon_stack[STSIZE];
19+
struct k_sem forks[N_PHILOSOPHERS];
20+
21+
/**
22+
*
23+
* @brief Nanokernel entry point
24+
*
25+
*/
26+
27+
int main(void)
28+
{
29+
int i;
30+
31+
for (i = 0; i < N_PHILOSOPHERS; i++) {
32+
k_sem_init(&forks[i], 0, 1);
33+
k_sem_give(&forks[i]);
34+
}
35+
36+
/* create philosopher threads */
37+
for (i = 0; i < N_PHILOSOPHERS; i++) {
38+
k_thread_spawn(&phil_stack[i][0], STSIZE,
39+
(k_thread_entry_t)phil_entry, NULL, NULL, NULL,
40+
K_PRIO_COOP(6), 0, K_NO_WAIT);
41+
}
42+
43+
/* create object counter monitor thread */
44+
k_thread_spawn(mon_stack, STSIZE,
45+
(k_thread_entry_t)object_monitor, NULL, NULL, NULL,
46+
K_PRIO_COOP(7), 0, K_NO_WAIT);
47+
48+
return 0;
49+
}
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
/* object_monitor.c - object monitor */
2+
3+
/*
4+
* Copyright (c) 2016 Intel Corporation.
5+
*
6+
* SPDX-License-Identifier: Apache-2.0
7+
*/
8+
9+
#include <zephyr.h>
10+
#include <tc_util.h>
11+
#include <util_test_common.h>
12+
#include <debug/object_tracing.h>
13+
#include "phil.h"
14+
15+
/**
16+
*
17+
* @brief Thread that traverses, counts and reports
18+
* the kernel objects in the philosophers application.
19+
*
20+
*/
21+
22+
#define TOTAL_TEST_NUMBER 2
23+
24+
/* 1 IPM console fiber if enabled */
25+
#if defined(CONFIG_IPM_CONSOLE_RECEIVER) && defined(CONFIG_PRINTK)
26+
#define IPM_THREAD 1
27+
#else
28+
#define IPM_THREAD 0
29+
#endif /* CONFIG_IPM_CONSOLE_RECEIVER && CONFIG_PRINTK*/
30+
31+
/* Must account for:
32+
* N Philosopher threads
33+
* 1 Object monitor thread
34+
* 1 System idle thread
35+
* 1 System workqueue thread
36+
* 1 IPM console thread
37+
*/
38+
39+
void *force_sys_work_q_in = (void *)&k_sys_work_q;
40+
41+
#define TOTAL_THREADS (N_PHILOSOPHERS + 3 + IPM_THREAD)
42+
43+
#define OBJ_LIST_NAME k_sem
44+
#define OBJ_LIST_TYPE struct k_sem
45+
46+
static inline int test_thread_monitor(void)
47+
{
48+
int obj_counter = 0;
49+
struct k_thread *thread_list = NULL;
50+
51+
/* wait a bit to allow any initialization-only threads to terminate */
52+
k_sleep(100);
53+
54+
thread_list = (struct k_thread *)SYS_THREAD_MONITOR_HEAD;
55+
while (thread_list != NULL) {
56+
if (thread_list->base.prio == -1) {
57+
TC_PRINT("PREMPT: %p OPTIONS: 0x%02x, STATE: 0x%02x\n",
58+
thread_list,
59+
thread_list->base.user_options,
60+
thread_list->base.thread_state);
61+
} else {
62+
TC_PRINT("COOP: %p OPTIONS: 0x%02x, STATE: 0x%02x\n",
63+
thread_list,
64+
thread_list->base.user_options,
65+
thread_list->base.thread_state);
66+
}
67+
thread_list =
68+
(struct k_thread *)SYS_THREAD_MONITOR_NEXT(thread_list);
69+
obj_counter++;
70+
}
71+
TC_PRINT("THREAD QUANTITY: %d\n", obj_counter);
72+
73+
if (obj_counter == TOTAL_THREADS) {
74+
TC_END_RESULT(TC_PASS);
75+
return 1;
76+
}
77+
78+
TC_END_RESULT(TC_FAIL);
79+
return 0;
80+
}
81+
82+
void object_monitor(void)
83+
{
84+
int obj_counter;
85+
int test_counter = 0;
86+
void *obj_list = NULL;
87+
88+
TC_START("OBJECT TRACING TEST");
89+
90+
obj_counter = 0;
91+
obj_list = SYS_TRACING_HEAD(OBJ_LIST_TYPE, OBJ_LIST_NAME);
92+
while (obj_list != NULL) {
93+
TC_PRINT("SEMAPHORE REF: %p\n", obj_list);
94+
obj_list = SYS_TRACING_NEXT(OBJ_LIST_TYPE, OBJ_LIST_NAME,
95+
obj_list);
96+
obj_counter++;
97+
}
98+
TC_PRINT("SEMAPHORE QUANTITY: %d\n", obj_counter);
99+
100+
if (obj_counter == N_PHILOSOPHERS) {
101+
TC_END_RESULT(TC_PASS);
102+
test_counter++;
103+
} else {
104+
TC_END_RESULT(TC_FAIL);
105+
}
106+
107+
test_counter += test_thread_monitor();
108+
109+
if (test_counter == TOTAL_TEST_NUMBER) {
110+
TC_END_REPORT(TC_PASS);
111+
} else {
112+
TC_END_REPORT(TC_FAIL);
113+
}
114+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/* phil.h - dining philosophers header file*/
2+
3+
/*
4+
* Copyright (c) 2011-2016 Wind River Systems, Inc.
5+
*
6+
* SPDX-License-Identifier: Apache-2.0
7+
*/
8+
#define N_PHILOSOPHERS 5
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/* phil_thread.c - dining philosopher */
2+
3+
/*
4+
* Copyright (c) 2011-2016 Wind River Systems, Inc.
5+
*
6+
* SPDX-License-Identifier: Apache-2.0
7+
*/
8+
9+
#include <zephyr.h>
10+
#include <tc_util.h>
11+
#include "phil.h"
12+
13+
#define FORK(x) (&forks[x])
14+
#define TAKE(x) k_sem_take(x, K_FOREVER)
15+
#define GIVE(x) k_sem_give(x)
16+
17+
#define RANDDELAY(x) k_sleep(10 * (x) + 1)
18+
19+
/* externs */
20+
21+
extern struct k_sem forks[N_PHILOSOPHERS];
22+
23+
24+
25+
/**
26+
*
27+
* @brief Entry point to a philosopher's thread
28+
*
29+
* This routine runs as a task in the microkernel environment
30+
* and as a thread in the nanokernel environment.
31+
*
32+
* @return N/A
33+
*/
34+
35+
void phil_entry(void)
36+
{
37+
int counter;
38+
struct k_sem *f1; /* fork #1 */
39+
struct k_sem *f2; /* fork #2 */
40+
static int myId; /* next philosopher ID */
41+
int pri = irq_lock(); /* interrupt lock level */
42+
int id = myId++; /* current philosopher ID */
43+
44+
irq_unlock(pri);
45+
46+
/* always take the lowest fork first */
47+
if ((id+1) != N_PHILOSOPHERS) {
48+
f1 = FORK(id);
49+
f2 = FORK(id + 1);
50+
} else {
51+
f1 = FORK(0);
52+
f2 = FORK(id);
53+
}
54+
55+
for (counter = 0; counter < 5; counter++) {
56+
TAKE(f1);
57+
TAKE(f2);
58+
59+
RANDDELAY(id);
60+
61+
GIVE(f2);
62+
GIVE(f1);
63+
64+
RANDDELAY(id);
65+
}
66+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[test]
2+
tags = core
3+
# Make sure it has enough memory
4+
filter = not ((CONFIG_DEBUG or CONFIG_ASSERT)) and ( CONFIG_SRAM_SIZE >= 32
5+
or CONFIG_DCCM_SIZE >= 32 or CONFIG_RAM_SIZE >= 32)

0 commit comments

Comments
 (0)