summaryrefslogtreecommitdiff
path: root/cesar/test_general/dataplane/src/trace_dump.c
blob: 8ab9735af14795358272ef1a1b2007fc531333d9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/* Cesar project {{{
 *
 * Copyright (C) 2009 Spidcom
 *
 * <<<Licence>>>
 *
 * }}} */
/**
 * \file    src/trace_dump.c
 * \brief   Module trace dumps.
 * \ingroup test
 */
#include "common/std.h"

#include "lib/trace.h"
#include "hal/arch/io.h"
#include "host/fcall/fcall.h"

#include "inc/context.h"

static void
test_dataplane_trace_dump_fcall_return (test_dataplane_t *ctx)
{
    fcall_param_t param;
    sci_msg_t msg;
    u8 buffer[64];
    dbg_assert (ctx);
    dbg_assert (ctx->fcall);
    fcall_param_init (&param, "trace_dump", ctx->fcall_msg_id);
    sci_msg_init (&msg, buffer, sizeof (buffer));
    fcall_param_reset (&param);
    dbg_check (fcall_return (ctx->fcall, &param, &msg) != -1);
    ctx->fcall = NULL;
}

static int
trace_buffer_dbg_dump_callback (void *user, const char *text, uint text_size)
{
    dbg_assert (text && text_size);
    arch_io_write (text, text_size);
    return text_size;
}

static void
test_dataplane_trace_dump (test_dataplane_t *ctx, test_dataplane_msg_t *msg)
{
    dbg_assert (ctx);
#if CONFIG_TRACE
    test_dataplane_msg_trace_dump_t *m = &msg->msg.trace_dump;
    /* Dump traces. */
    if (m->all)
    {
        trace_bundle_dump_all (m->name, trace_buffer_dbg_dump_callback, NULL);
    }
    else
    {
        trace_bundle_start (m->name, trace_buffer_dbg_dump_callback, NULL);
        if (m->phy)
            trace_buffer_dump (trace_buffer_get ("phy"),
                               trace_buffer_dbg_dump_callback, NULL);
        if (m->ca)
            trace_buffer_dump (trace_buffer_get ("ca"),
                               trace_buffer_dbg_dump_callback, NULL);
        if (m->pbproc)
            trace_buffer_dump (trace_buffer_get ("pbproc"),
                               trace_buffer_dbg_dump_callback, NULL);
        if (m->sar)
            trace_buffer_dump (trace_buffer_get ("sar"),
                               trace_buffer_dbg_dump_callback, NULL);
        if (m->cl)
            trace_buffer_dump (trace_buffer_get ("cl"),
                               trace_buffer_dbg_dump_callback, NULL);
        if (m->hle)
            trace_buffer_dump (trace_buffer_get ("hle"),
                               trace_buffer_dbg_dump_callback, NULL);
        trace_bundle_stop (trace_buffer_dbg_dump_callback, NULL);
    }
#endif /* CONFIG_TRACE */
    /* Return. */
    test_dataplane_trace_dump_fcall_return (ctx);
}

static int
test_dataplane_trace_dump_fcall (fcall_ctx_t *fcall, fcall_param_t **param,
                                 sci_msg_t **msg, void *data)
{
    dbg_assert (fcall);
    dbg_assert (param && *param);
    dbg_assert (msg && *msg);
    test_dataplane_t *ctx = (void *) data;
    dbg_assert (ctx);
    /* Only one message at a time. */
    if (ctx->msg.cb)
        return -1;
    ctx->msg.cb = test_dataplane_trace_dump;
    /* Read message. */
    test_dataplane_msg_trace_dump_t *m = &ctx->msg.msg.trace_dump;
    uint name_len = fcall_param_bind (*param, *msg, "bundle",
                                      sizeof (m->name), m->name);
    m->name[name_len] = '\0';
    if (name_len == sizeof (m->name) || name_len == (uint) -1)
        return -1;
    if (!fcall_param_bind_helper ("all", m->all))
        m->all = false;
    if (!m->all)
    {
        if (!fcall_param_bind_helper ("phy", m->phy))
            m->phy = false;
        if (!fcall_param_bind_helper ("ca", m->ca))
            m->ca = false;
        if (!fcall_param_bind_helper ("pbproc", m->pbproc))
            m->pbproc = false;
        if (!fcall_param_bind_helper ("sar", m->sar))
            m->sar = false;
        if (!fcall_param_bind_helper ("cl", m->cl))
            m->cl = false;
        if (!fcall_param_bind_helper ("hle", m->hle))
            m->hle = false;
    }
    /* Message accepted, will return later. */
    fcall_param_set_async (*param, 1);
    dbg_assert (ctx->fcall == NULL);
    ctx->fcall = fcall;
    ctx->fcall_msg_id = fcall_param_get_msg_id (*param);
    /* Post message. */
    cyg_semaphore_post (&ctx->msg_sem);
    return 0;
}

void
test_dataplane_trace_dump_init (test_dataplane_t *ctx, fcall_ctx_t *fcall)
{
    fcall_register (fcall, "trace_dump", test_dataplane_trace_dump_fcall,
                    ctx);
}