summaryrefslogtreecommitdiff
path: root/cesar/maximus/prototest/integration/src/test_integration.c
blob: 033358ed0fc8224f3afe00568bb1f2d412badd23 (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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
/* Cesar project {{{
 *
 * Copyright (C) 2007 Spidcom
 *
 * <<<Licence>>>
 *
 * }}} */
/**
 * \file    test_integration.c
 * \brief   integration test program
 * \ingroup maximus/prototest/integration
 *
 * this is a test program to check fcall feature well work on proto
 */
#include <cyg/infra/diag.h>
#include <cyg/kernel/kapi.h>
#include <errno.h>
#include "common/std.h"
#include "hle/hle.h"
#include "interface/interface.h"
#include "interface/inc/context.h"
#include "interface/fcall/interface_fcall.h"
#include "cl/inc/context.h"
#include "mac/sar/inc/sar_context.h"

interface_t *interface_ctx;
hle_t *hle_ctx;
cl_t cl_ctx;
sar_t sar_ctx;
mac_config_t mac_config_ctx;

typedef struct my_struct
{
    int i1;
    int i2;
    bool b;
} my_struct_t;

typedef long long my_type_t;

my_type_t my_param4;

unsigned int my_param6 = 123; // 0x0000007B
unsigned int my_param7 = 456; // 0x000001C8
bool my_param8 = false;
bool my_param9 = true;
unsigned short my_param10 = 0xFFEE;
unsigned long my_param11 = 0xFFEEDDCC;

void
my_return_function (void *data)
{
    static fcall_param_t return_param;
    static sci_msg_t return_msg;
    static unsigned char return_buffer[SCI_MSG_MAX_SIZE];
    unsigned short *return_msg_id = (unsigned short *)data;

    /* init structures */
    fcall_param_init(&return_param, "function_1_rsp", *return_msg_id);
    if (0 != sci_msg_init(&return_msg, return_buffer, SCI_MSG_MAX_SIZE))
    {
        diag_printf("%s: errno = %d", __FUNCTION__, errno);
    }

    /* do other tasks ... */
    diag_write_string("=> my_return_function\n");

    /* now make the return parameter list */
    fcall_param_reset(&return_param);
    fcall_param_add(&return_param, &return_msg, "result_2", sizeof(my_type_t), &my_param4);
    fcall_return(interface_ctx->fcall->fcall_ctx, &return_param, &return_msg);

    return; 
}

int
my_function1 (fcall_ctx_t *fcall, fcall_param_t **param, sci_msg_t **msg, void *data)
{
    unsigned short asynchronous_msg_id = 0;
    my_struct_t my_param1;
    int my_param2[10];
    char my_param3[6];
    int i;

    /* get parameters content */
    fcall_param_bind(*param, *msg, "param_1", sizeof(my_struct_t), &my_param1);
    fcall_param_bind(*param, *msg, "param_2", 10*sizeof(int), my_param2);
    fcall_param_bind(*param, *msg, "param_3", 6, (char*)my_param3);
    fcall_param_bind(*param, *msg, "param_4", sizeof(my_type_t), &my_param4);

    /* do other tasks ... */
    diag_write_string("=> my_function1\n");
    diag_printf("param 1 . i1 = %d\n", my_param1.i1);
    diag_printf("param 1 . i2 = %d\n", my_param1.i2);
    diag_printf("param 1 . b = %d\n", my_param1.b);
    diag_write_string("param 2 = ");
    for (i=0; i<10; i++)
    {
        diag_printf(" %d", my_param2[i]);
    }
    diag_write_string("\n");
    diag_printf("param 3 = %s\n", my_param3);
    diag_printf("param 4 = %lld\n", my_param4);

    /* prepare the future asynchronous return */
    fcall_param_set_async(*param, 1);
    asynchronous_msg_id = (*param)->msg_id;

    /* my_return_function() call */
    my_return_function(&asynchronous_msg_id);

    /* now return */    
    return 0; 
}

int
my_function2 (fcall_ctx_t *fcall, fcall_param_t **param, sci_msg_t **msg, void *data)
{
    bool my_param5;
    char my_result1[] = "this is result 1\0";
    
    /* get parameters content */
    if (-1 == fcall_param_bind(*param, *msg, "param_5", sizeof(bool), &my_param5))
    {
        diag_printf("errno = %d\n", errno);
        diag_printf("param nb = %d\n", (*param)->param_nb);
    }

    /* do other tasks ... */
    diag_write_string("=> my_function2\n");

    /* now make the return parameter list */
    fcall_param_reset(*param);
    fcall_param_add(*param, *msg, "result_1", strlen(my_result1)+1, &my_result1);
    
    return 0; 
}

void
my_function_rsp (void *data)
{
    static fcall_param_t return_param;
    static sci_msg_t return_msg;
    static unsigned char return_buffer[SCI_MSG_MAX_SIZE];
    unsigned short *return_msg_id = (unsigned short *)data;

    /* init structures */
    fcall_param_init(&return_param, "function_rsp", *return_msg_id);
    if (0 != sci_msg_init(&return_msg, return_buffer, SCI_MSG_MAX_SIZE))
    {
        diag_printf("%s: errno = %d", __FUNCTION__, errno);
    }

    /* do other tasks ... */
    diag_write_string("=> my_function_rsp\n");

    /* now make the return parameter list */
    fcall_param_reset(&return_param);
    fcall_return(interface_ctx->fcall->fcall_ctx, &return_param, &return_msg);

    return; 
}

int
my_function3 (fcall_ctx_t *fcall, fcall_param_t **param, sci_msg_t **msg, void *data)
{
    unsigned short asynchronous_msg_id = 0;
    
    /* do other tasks ... */
    diag_write_string("=> my_function3\n");
    
    /* prepare the future asynchronous return */
    fcall_param_set_async(*param, 1);
    asynchronous_msg_id = (*param)->msg_id;
    
    /* call my_function_rsp() */
    my_function_rsp((void*)&asynchronous_msg_id);
    
    return 0; 
}

int
my_function4 (fcall_ctx_t *fcall, fcall_param_t **param, sci_msg_t **msg, void *data)
{
    unsigned short asynchronous_msg_id = 0;
    
    /* do other tasks ... */
    diag_write_string("=> my_function4\n");

    /* prepare the future asynchronous return */
    fcall_param_set_async(*param, 1);
    asynchronous_msg_id = (*param)->msg_id;
    
    /* call my_function_rsp() */
    my_function_rsp((void*)&asynchronous_msg_id);
    
    return 0; 
}

int
my_function5 (fcall_ctx_t *fcall, fcall_param_t **param, sci_msg_t **msg, void *data)
{
    unsigned short asynchronous_msg_id = 0;
    
    /* do other tasks ... */
    diag_write_string("=> my_function5\n");

    /* prepare the future asynchronous return */
    fcall_param_set_async(*param, 1);
    asynchronous_msg_id = (*param)->msg_id;
    
    /* call my_function_rsp() */
    my_function_rsp((void*)&asynchronous_msg_id);
    
    return 0; 
}

void
cyg_user_start(void)
{
    hle_ctx = hle_init (&cl_ctx);

    interface_ctx = interface_init (hle_ctx,
                                    &cl_ctx,
                                    &sar_ctx,
                                    &mac_config_ctx);

    ipmbox_activate(NULL, true);

    fcall_register(interface_ctx->fcall->fcall_ctx, "function_1", (void*)&my_function1, NULL);
    fcall_register(interface_ctx->fcall->fcall_ctx, "function_2", (void*)&my_function2, NULL);
    fcall_register(interface_ctx->fcall->fcall_ctx, "function_3", (void*)&my_function3, NULL);
    fcall_register(interface_ctx->fcall->fcall_ctx, "function_4", (void*)&my_function4, NULL);
    fcall_register(interface_ctx->fcall->fcall_ctx, "function_5", (void*)&my_function5, NULL);

    probe_register(interface_ctx->fcall->probe_ctx, "param_6", sizeof(unsigned int), &my_param6);
    probe_register(interface_ctx->fcall->probe_ctx, "param_7", sizeof(unsigned int), &my_param7);
    probe_register(interface_ctx->fcall->probe_ctx, "param_8", sizeof(bool), &my_param8);
    probe_register(interface_ctx->fcall->probe_ctx, "param_9", sizeof(bool), &my_param9);
    probe_register(interface_ctx->fcall->probe_ctx, "param_10", sizeof(unsigned short), &my_param10);
    probe_register(interface_ctx->fcall->probe_ctx, "param_11", sizeof(unsigned long), &my_param11);

    return;
}