Skip to content

Commit 22d3305

Browse files
committed
Add debug output to DPP example
1 parent 4633c19 commit 22d3305

File tree

4 files changed

+48
-2
lines changed

4 files changed

+48
-2
lines changed

apps/examples/dpp/main.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include <stddef.h>
3232

3333
#include "common/compiler.h"
34+
#include "common/constants.h"
3435
#include "common/macros.h"
3536
#include "event/event.h"
3637
#include "pal/pal.h"
@@ -53,6 +54,47 @@ const char *event_to_str(int id) {
5354
AM_ASSERT(0);
5455
}
5556

57+
static void log_pool(
58+
int pool_index, int event_index, const struct am_event *event, int size
59+
) {
60+
(void)size;
61+
am_pal_printf(
62+
"pool %d index %d event %s\n",
63+
pool_index,
64+
event_index,
65+
event_to_str(event->id)
66+
);
67+
}
68+
69+
static void log_queue(
70+
const char *name, int i, int len, int cap, const struct am_event *event
71+
) {
72+
am_pal_printf(
73+
"name %s, index %d, len %d cap %d event %s\n",
74+
name,
75+
i,
76+
len,
77+
cap,
78+
event_to_str(event->id)
79+
);
80+
}
81+
82+
AM_NORETURN void am_assert_failure(
83+
const char *assertion, const char *file, int line
84+
) {
85+
am_pal_printf(
86+
AM_COLOR_RED "ASSERT: %s (%s:%d)(task %d)\n" AM_COLOR_RESET,
87+
assertion,
88+
file,
89+
line,
90+
am_pal_task_own_id()
91+
);
92+
am_event_log_pools(/*num=*/-1, log_pool);
93+
am_ao_dump_event_queues(/*num=*/-1, log_queue);
94+
am_pal_flush();
95+
__builtin_trap();
96+
}
97+
5698
int main(void) {
5799
struct am_ao_state_cfg cfg_ao = {
58100
.crit_enter = am_pal_crit_enter, .crit_exit = am_pal_crit_exit

apps/examples/dpp/philo.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ static int philo_eating(struct philo *me, const struct am_event *event) {
109109
return AM_HSM_HANDLED();
110110

111111
case EVT_TIMEOUT: {
112+
am_pal_printf("philo %d publishing DONE\n", me->id);
112113
struct done *msg = (struct done *)am_event_allocate(
113114
EVT_DONE, sizeof(struct done), /*margin=*/0
114115
);

apps/examples/dpp/table.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "common/macros.h"
2929
#include "event/event.h"
3030
#include "hsm/hsm.h"
31+
#include "pal/pal.h"
3132
#include "ao/ao.h"
3233

3334
#include "events.h"
@@ -92,11 +93,13 @@ static void table_serve(int philo) {
9293
EVT_EAT, sizeof(struct eat), /*margin=*/0
9394
);
9495
eat->philo = philo;
96+
am_pal_printf("table serving philo %d\n", philo);
9597
am_ao_publish(&eat->event);
9698
philo_mark_eating(philo);
9799

98100
if (m_table.nsession) {
99101
--m_table.nsession;
102+
am_pal_printf("table session %d\n", m_table.nsession);
100103
}
101104
if (!m_table.nsession) {
102105
exit(0);
@@ -118,6 +121,7 @@ static int table_serving(struct table *me, const struct am_event *event) {
118121
case EVT_DONE: {
119122
const struct done *done = (const struct done *)event;
120123
AM_ASSERT(philo_is_eating(done->philo));
124+
am_pal_printf("table: philo %d is done\n", done->philo);
121125
philo_mark_done(done->philo);
122126
int left = LEFT(done->philo);
123127
if (philo_is_hungry(left)) {

apps/examples/meson.build

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,4 @@ e = executable(
5757
libao_dep,
5858
libevent_dep,
5959
libtimer_dep,
60-
libbit_dep,
61-
libassert_dep])
60+
libbit_dep])

0 commit comments

Comments
 (0)