FreeCalypso > hg > fc-tourmaline
comparison src/g23m-fad/app/app_gdd.c @ 1:fa8dc04885d8
src/g23m-*: import from Magnetite
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Fri, 16 Oct 2020 06:25:50 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
0:4e78acac3d88 | 1:fa8dc04885d8 |
---|---|
1 /* | |
2 +------------------------------------------------------------------------------ | |
3 | File: app_gdd.c | |
4 +------------------------------------------------------------------------------ | |
5 | Copyright 2004 Texas Instruments Berlin, AG | |
6 | All rights reserved. | |
7 | | |
8 | This file is confidential and a trade secret of Texas | |
9 | Instruments Berlin, AG | |
10 | The receipt of or possession of this file does not convey | |
11 | any rights to reproduce or disclose its contents or to | |
12 | manufacture, use, or sell anything it may describe, in | |
13 | whole, or in part, without the specific written consent of | |
14 | Texas Instruments Berlin, AG. | |
15 +----------------------------------------------------------------------------- | |
16 | Purpose : Test functions for testing the GDD interface -- command parser. | |
17 +----------------------------------------------------------------------------- | |
18 */ | |
19 | |
20 | |
21 #define APP_GDD_C | |
22 | |
23 /*==== INCLUDES =============================================================*/ | |
24 | |
25 #include "app_util.h" | |
26 | |
27 #include <string.h> /* String functions, e. g. strncpy(). */ | |
28 #include <ctype.h> | |
29 #include <stdlib.h> | |
30 #ifndef _SIMULATION_ | |
31 #endif /* _SIMULATION_ */ | |
32 #include "vsi.h" /* A lot of macros. */ | |
33 #ifndef _SIMULATION_ | |
34 #include "custom.h" | |
35 #include "gsm.h" /* A lot of macros. */ | |
36 #include "tools.h" /* Common tools. */ | |
37 #endif /* _SIMULATION_ */ | |
38 | |
39 #include "../gdd_dio/gdd.h" | |
40 #include "../gdd_dio/gdd_dio.h" | |
41 #include "../gdd_dio/dio_il_psi_stub.h" /* for DIO buffer manipulation functions */ | |
42 | |
43 /*==== Local defines =========================================================*/ | |
44 | |
45 /* Some bogus con handle */ | |
46 #define TEST_CON_HANDLE 1 | |
47 | |
48 /* Max number of test connections required */ | |
49 #define TEST_MAX_CON 4 | |
50 | |
51 | |
52 /* | |
53 * Command handler | |
54 */ | |
55 | |
56 /* The base GDD interface functions */ | |
57 static char *app_gdd_init(app_cmd_entry_t *, int, char * [], core_func_t) ; | |
58 static char *app_gdd_deinit(app_cmd_entry_t *, int, char * [], core_func_t) ; | |
59 static char *app_gdd_connect(app_cmd_entry_t *, int, char * [], core_func_t) ; | |
60 static char *app_gdd_disconnect(app_cmd_entry_t *, int, char * [], core_func_t) ; | |
61 static char *app_gdd_get_send_buffer(app_cmd_entry_t *, int, char * [], core_func_t) ; | |
62 static char *app_gdd_send_data(app_cmd_entry_t *, int, char * [], core_func_t) ; | |
63 static char *app_gdd_receive_data(app_cmd_entry_t *, int, char * [], core_func_t) ; | |
64 static char *app_gdd_sig_ready_rcv(app_cmd_entry_t *, int, char * [], core_func_t) ; | |
65 | |
66 /* More complex test functions encapsulated in functions */ | |
67 static char *app_gdd_init_test_parms(app_cmd_entry_t *, int, char * [], core_func_t) ; | |
68 static char *app_gdd_deinit_test_parms(app_cmd_entry_t *, int, char * [], core_func_t) ; | |
69 static char *app_gdd_connect_test_parms(app_cmd_entry_t *, int, char * [], core_func_t) ; | |
70 static char *app_gdd_disconnect_test_parms(app_cmd_entry_t *, int, char * [], core_func_t) ; | |
71 static char *app_gdd_get_send_buffer_test_parms(app_cmd_entry_t *, int, char * [], core_func_t) ; | |
72 static char *app_gdd_send_data_test_parms(app_cmd_entry_t *, int, char * [], core_func_t) ; | |
73 | |
74 static char *app_gdd_immediate_disconnect(app_cmd_entry_t *, int, char * [], core_func_t) ; | |
75 | |
76 #ifdef WIN32 | |
77 /* This function uses psi stub functions which are only available in simulation testing */ | |
78 static char *app_gdd_test_sig_sbuf_avail(app_cmd_entry_t *, int, char * [], core_func_t) ; | |
79 #endif /* WIN32 */ | |
80 | |
81 /*extern char *app_gdd_sys_test(app_cmd_entry_t *, int, char * [], core_func_t) ;*/ | |
82 static char *app_gdd_test_helper_functions(app_cmd_entry_t *, int, char * [], core_func_t) ; | |
83 | |
84 /* | |
85 * Core functions (to be called by the command handler, if applicable) | |
86 */ | |
87 | |
88 /* -- No core functions required for now */ | |
89 | |
90 | |
91 /* Command handler table. */ | |
92 static app_cmd_entry_t app_gdd_cmd_table[] = { | |
93 /* Commands that trigger the basic GDD API functions */ | |
94 { "gdd_init", (cmd_handler_t)app_gdd_init, (core_func_t)0, "[BAT|APP] {HowManyCon} [NO|YES]" }, | |
95 { "gdd_deinit", (cmd_handler_t)app_gdd_deinit, (core_func_t)0, "[BAT|APP]" }, | |
96 { "gdd_connect", (cmd_handler_t)app_gdd_connect, (core_func_t)0, "[BAT|APP]" }, | |
97 { "gdd_disconnect", (cmd_handler_t)app_gdd_disconnect, (core_func_t)0, "{ConNum}" }, | |
98 { "gdd_get_send_buffer", (cmd_handler_t)app_gdd_get_send_buffer, (core_func_t)0, "{ConNum} {NumBytes}" }, | |
99 { "gdd_test_send_data", (cmd_handler_t)app_gdd_send_data, (core_func_t)0, "{ConNum} {NumBytes}" }, | |
100 { "gdd_test_receive_data",(cmd_handler_t)app_gdd_receive_data, (core_func_t)0, "{ConNum} {NumBytes}" }, | |
101 { "gdd_sig_ready_rcv", (cmd_handler_t)app_gdd_sig_ready_rcv, (core_func_t)0, "{ConNum}" }, | |
102 /* Commands that test the input parameters of the API functions. | |
103 These tests are to make sure that the API can handler crappy user input/parameter values. */ | |
104 { "gdd_init_test_parms", (cmd_handler_t)app_gdd_init_test_parms, (core_func_t)0, "" }, | |
105 { "gdd_deinit_test_parms", (cmd_handler_t)app_gdd_deinit_test_parms, (core_func_t)0, "" }, | |
106 { "gdd_connect_test_parms", (cmd_handler_t)app_gdd_connect_test_parms, (core_func_t)0, "" }, | |
107 { "gdd_disconnect_test_parms", (cmd_handler_t)app_gdd_disconnect_test_parms, (core_func_t)0, "" }, | |
108 { "gdd_get_send_buffer_test_parms", (cmd_handler_t)app_gdd_get_send_buffer_test_parms, (core_func_t)0, "" }, | |
109 { "gdd_send_data_test_parms", (cmd_handler_t)app_gdd_send_data_test_parms, (core_func_t)0, "" }, | |
110 /* Test miscellaneous API function / combinations / special cases */ | |
111 { "gdd_test_immediate_disconnect", (cmd_handler_t)app_gdd_immediate_disconnect, (core_func_t)0, "" }, | |
112 #ifdef WIN32 | |
113 { "gdd_test_sig_sbuf_avail", (cmd_handler_t)app_gdd_test_sig_sbuf_avail, (core_func_t)0, "" }, | |
114 #endif /* WIN32 */ | |
115 { "gdd_helper_test", (cmd_handler_t)app_gdd_test_helper_functions, (core_func_t)0, "" }, | |
116 /* { "gdd_sys_test", app_gdd_sys_test, 0, "" }, */ | |
117 { 0, 0, 0, 0}, /* Terminate table */ | |
118 } ; | |
119 | |
120 | |
121 /*==== Local data ============================================================*/ | |
122 | |
123 #define GDD_MTU_SIZE 1500 | |
124 | |
125 static const T_GDD_FUNC * gdd_func = &gdd_func_dio; | |
126 | |
127 static const T_GDD_DIO_CAP gdd_dio_cap = { GDD_MTU_SIZE }; | |
128 | |
129 | |
130 /** Local structure for maintaining the test connections */ | |
131 typedef struct | |
132 { | |
133 T_GDD_CON_HANDLE con_handle; | |
134 T_GDD_BUF * send_buf; | |
135 T_GDD_BUF * rcv_buf; | |
136 int cnt_sigtype_send_buf_available; | |
137 } APP_GDD_CON_TABLE_ENTRY; | |
138 | |
139 static APP_GDD_CON_TABLE_ENTRY con_table[TEST_MAX_CON]; | |
140 | |
141 /*==== Local functions =======================================================*/ | |
142 | |
143 | |
144 /** Create capabilities structure */ | |
145 static T_GDD_CAP gdd_create_capabilities_300() | |
146 { | |
147 T_GDD_CAP cap; | |
148 cap.dio_cap = gdd_dio_cap; | |
149 return cap; | |
150 } | |
151 | |
152 | |
153 static void app_gdd_setup_segment(U8 * ptr, U16 size, U16 offset) | |
154 { | |
155 int i; | |
156 for(i=0; i < size; ++i) | |
157 { | |
158 ptr[i] = (U8)i + offset; | |
159 } | |
160 } | |
161 | |
162 | |
163 /** Setup the data bytes in provided buffer in order to create | |
164 * a well-defined test buffer. The test data is created according | |
165 * to a simple algorithm. The size is also used as an offset | |
166 * in the algorithm. | |
167 */ | |
168 void app_gdd_setup_test_buffer(T_GDD_BUF * buf, U16 size) | |
169 { | |
170 void * tmp_buf; | |
171 MALLOC(tmp_buf, size); | |
172 | |
173 app_gdd_setup_segment(tmp_buf, size, size); | |
174 | |
175 if(gdd_write_buf(tmp_buf, size, buf) < 0) | |
176 { | |
177 TRACE_ASSERT(0); | |
178 } | |
179 | |
180 MFREE(tmp_buf); | |
181 } | |
182 | |
183 /** Verify the integrity of a test buffer that has been created | |
184 * before with the function app_gdd_setup_test_buffer(). | |
185 * | |
186 * Return TRUE if two buffers are the same, FALSE otherwise */ | |
187 BOOL app_gdd_verify_test_buffer(const T_GDD_BUF * buf, U16 size) | |
188 { | |
189 char * tmp_buf_ref; | |
190 char * tmp_buf_received; | |
191 MALLOC(tmp_buf_ref, size); | |
192 MALLOC(tmp_buf_received, size); | |
193 | |
194 app_gdd_setup_segment((U8 *)tmp_buf_ref, size, size); | |
195 | |
196 if(gdd_read_buf(buf, (U8 *)tmp_buf_received, size) < 0) | |
197 { | |
198 TRACE_ASSERT(0); | |
199 } | |
200 | |
201 if(memcmp(tmp_buf_ref, tmp_buf_received, size)) | |
202 { | |
203 return FALSE; | |
204 } | |
205 | |
206 return TRUE; | |
207 } | |
208 | |
209 | |
210 /** Convert from instance string representation to the numeric instance number */ | |
211 int get_inst_num(const char * str) | |
212 { | |
213 if(!strncmp("BAT", str, 3)) | |
214 return GDD_INST_BAT; | |
215 else if(!strncmp("APP", str, 3)) | |
216 return GDD_INST_APP; | |
217 else if(!strncmp("TCP", str, 3)) | |
218 return GDD_INST_TCP; | |
219 else if(!strncmp("SOCK", str, 4)) | |
220 return GDD_INST_SOCK; | |
221 else if(!strncmp("SOCKCFG", str, 7)) | |
222 return GDD_INST_SOCKCFG; | |
223 else | |
224 return -1; /* invalid instance */ | |
225 } | |
226 | |
227 | |
228 /* For Target, we must include the two DIO buffer helper functions, | |
229 because we don't include the PSI stub, where they reside for simulation build. */ | |
230 #if defined (_TARGET_) | |
231 | |
232 void copy_dio_buf(const T_dio_buffer * buf_in, T_dio_buffer ** buf_out) | |
233 { | |
234 int i; | |
235 T_dio_segment * seg_in; | |
236 T_dio_segment * seg_out; | |
237 | |
238 TRACE_FUNCTION( "copy_dio_buf" ); | |
239 | |
240 /* Allocate new buffer */ | |
241 MALLOC((*buf_out), (USHORT)sizeof(T_dio_buffer)); | |
242 (*buf_out)->c_dio_segment = buf_in->c_dio_segment; | |
243 (*buf_out)->length=buf_in->length; | |
244 | |
245 /* allocate segement array and copy data accross */ | |
246 MALLOC((*buf_out)->ptr_dio_segment,(USHORT)sizeof(T_dio_segment)*buf_in->c_dio_segment); | |
247 memcpy((*buf_out)->ptr_dio_segment,buf_in->ptr_dio_segment,(USHORT)sizeof(T_dio_segment)*buf_in->c_dio_segment); | |
248 (*buf_out)->c_dio_segment = buf_in->c_dio_segment; | |
249 | |
250 /* Copy each segment */ | |
251 seg_in = buf_in->ptr_dio_segment; | |
252 seg_out = (*buf_out)->ptr_dio_segment; | |
253 for(i=0;i<buf_in->c_dio_segment;++i, ++seg_in, ++seg_out ) | |
254 { | |
255 seg_out->c_data = seg_in->c_data; | |
256 MALLOC(seg_out->ptr_data, seg_out->c_data); | |
257 memcpy(seg_out->ptr_data, seg_in->ptr_data, seg_out->c_data); | |
258 } | |
259 | |
260 TRACE_EVENT_P1("Allocated new DIO buffer %x", *buf_out); | |
261 } | |
262 | |
263 #define TEM__GDD_DIO_MTU_SIZE_MAX 1500 | |
264 | |
265 void allocate_rx_dio_buf(T_dio_buffer ** buf_out) | |
266 { | |
267 const U16 segments[] = {2, TEM__GDD_DIO_MTU_SIZE_MAX}; | |
268 | |
269 TRACE_FUNCTION( "allocate_rx_dio_buf" ); | |
270 | |
271 allocate_dio_buf(buf_out, segments, 2); | |
272 } | |
273 | |
274 | |
275 void allocate_dio_buf(T_dio_buffer ** buf_out, | |
276 const U16 seg_size[], U16 num_seg) | |
277 { | |
278 int idx_seg; | |
279 | |
280 TRACE_FUNCTION( "allocate_rx_dio_buf" ); | |
281 | |
282 /* allocate segement array and copy data accross */ | |
283 MALLOC(*buf_out, (USHORT)sizeof(T_dio_buffer)); | |
284 (*buf_out)->c_dio_segment = (U8)num_seg; | |
285 MALLOC((*buf_out)->ptr_dio_segment,(USHORT)sizeof(T_dio_segment)*(*buf_out)->c_dio_segment); | |
286 (*buf_out)->length = 0; | |
287 | |
288 for(idx_seg=0; idx_seg<num_seg; ++idx_seg) | |
289 { | |
290 T_dio_segment * seg = &((*buf_out)->ptr_dio_segment[idx_seg]); | |
291 seg->c_data = seg_size[idx_seg]; | |
292 MALLOC(seg->ptr_data, seg->c_data); | |
293 (*buf_out)->length += seg->c_data; | |
294 } | |
295 } | |
296 | |
297 void free_dio_buf(T_dio_buffer ** buf) | |
298 { | |
299 int i; | |
300 T_dio_segment * seg = (*buf)->ptr_dio_segment; | |
301 | |
302 TRACE_FUNCTION( "free_dio_buf" ); | |
303 | |
304 /* Free each segement */ | |
305 for(i=0;i<(*buf)->c_dio_segment; ++i, ++seg) | |
306 { | |
307 if (seg->ptr_data NEQ NULL) | |
308 MFREE(seg->ptr_data); | |
309 } | |
310 | |
311 /* Free segment array */ | |
312 if ((*buf)->ptr_dio_segment NEQ NULL) | |
313 MFREE((*buf)->ptr_dio_segment); | |
314 | |
315 /* Free the actual buffer */ | |
316 MFREE(*buf); | |
317 | |
318 (*buf) = 0; | |
319 } | |
320 | |
321 #endif /* (_TARGET_) */ | |
322 | |
323 | |
324 /*--------------------------------------------------------------------------- | |
325 * GDD callbacks | |
326 *---------------------------------------------------------------------------*/ | |
327 | |
328 /** gdd_receive_data_cb */ | |
329 GDD_RESULT app_gdd_receive_data_cb | |
330 ( T_GDD_CON_HANDLE con_handle, | |
331 T_GDD_BUF * buf ) | |
332 { | |
333 int i; | |
334 | |
335 TRACE_FUNCTION("app_gdd_receive_data_cb"); | |
336 | |
337 /* Search connection slot */ | |
338 for(i = 0; i < TEST_MAX_CON; ++i) | |
339 { | |
340 if(con_table[i].con_handle EQ con_handle) | |
341 { | |
342 T_GDD_BUF * new_buf; | |
343 | |
344 if(con_table[i].rcv_buf) | |
345 { | |
346 TRACE_ERROR("Receive buffer already in use"); | |
347 return GDD_INTERNAL_ERROR; | |
348 } | |
349 | |
350 /* Create a copy of the buffer */ | |
351 copy_dio_buf( | |
352 (const T_dio_buffer *)buf, | |
353 (T_dio_buffer **)(&new_buf)); | |
354 | |
355 con_table[i].rcv_buf = new_buf; | |
356 | |
357 return GDD_OK; | |
358 } | |
359 } | |
360 | |
361 TRACE_ERROR("callback called with bad connection handle"); | |
362 return GDD_INTERNAL_ERROR; | |
363 } | |
364 | |
365 /** gdd_signal_cb */ | |
366 GDD_RESULT app_gdd_signal_cb | |
367 ( T_GDD_CON_HANDLE con_handle, | |
368 T_GDD_SIGNAL sig ) | |
369 { | |
370 int i; | |
371 | |
372 TRACE_FUNCTION("app_gdd_signal_cb"); | |
373 | |
374 /* Search connection slot */ | |
375 for(i = 0; i < TEST_MAX_CON; ++i) | |
376 { | |
377 if(con_table[i].con_handle EQ con_handle) | |
378 { | |
379 if(sig.sig EQ GDD_SIGTYPE_SEND_BUF_AVAILABLE) | |
380 { | |
381 ++con_table[i].cnt_sigtype_send_buf_available; | |
382 } | |
383 /* Processing of other signals goes here ... */ | |
384 | |
385 return GDD_OK; | |
386 | |
387 } | |
388 } | |
389 | |
390 /* In case of the connection signal, we might not have a connection slot | |
391 at this stage, this it is not considered an error. */ | |
392 if( sig.sig NEQ GDD_SIGTYPE_CONNECTION_OPENED ) | |
393 TRACE_ERROR("callback called with bad connection handle"); | |
394 | |
395 return GDD_INTERNAL_ERROR; | |
396 } | |
397 | |
398 | |
399 /*--------------------------------------------------------------------------- | |
400 * Definition of command handler functions | |
401 *---------------------------------------------------------------------------*/ | |
402 | |
403 static char *app_gdd_init | |
404 (app_cmd_entry_t *cmd_entry_ptr, int argc, | |
405 char * argv[], core_func_t core_func) | |
406 { | |
407 GDD_RESULT result; | |
408 char * mem = 0; | |
409 int num_con = get_item(argv[2], 4, TRUE); | |
410 int inst_id = get_inst_num(argv[1]); | |
411 if(inst_id < 0) | |
412 { | |
413 TRACE_ERROR("Invalid instance specified"); | |
414 BAT_TEST_FAILED(); | |
415 return 0; | |
416 } | |
417 | |
418 TRACE_FUNCTION("app_gdd_init"); | |
419 | |
420 if(argv[3] && !strcmp(string_to_lower(argv[3]), "YES")) | |
421 { | |
422 MALLOC(mem, num_con * GDD_DIO_SIZEOF_CONDATA); | |
423 } | |
424 | |
425 result = gdd_func->gdd_init((T_GDD_INST_ID)inst_id, (char*)mem, (U16)num_con) ; | |
426 if(result != GDD_OK) | |
427 { | |
428 TRACE_ERROR("Call to gdd_init failed"); | |
429 BAT_TEST_FAILED(); | |
430 return 0; | |
431 } | |
432 | |
433 BAT_TEST_PASSED(); | |
434 return 0; | |
435 } | |
436 | |
437 static char *app_gdd_deinit | |
438 (app_cmd_entry_t *cmd_entry_ptr, int argc, | |
439 char * argv[], core_func_t core_func) | |
440 { | |
441 GDD_RESULT result; | |
442 int inst_id = get_inst_num(argv[1]); | |
443 if(inst_id < 0) | |
444 { | |
445 TRACE_ERROR("Invalid instance specified"); | |
446 BAT_TEST_FAILED(); | |
447 return 0; | |
448 } | |
449 | |
450 TRACE_FUNCTION("app_gdd_deinit"); | |
451 | |
452 result =(GDD_RESULT)gdd_func->gdd_deinit((T_GDD_INST_ID)inst_id) ; | |
453 if(result != GDD_OK) | |
454 { | |
455 TRACE_ERROR("Call to gdd_deinit failed"); | |
456 BAT_TEST_FAILED(); | |
457 return 0; | |
458 } | |
459 | |
460 BAT_TEST_PASSED(); | |
461 return 0; | |
462 } | |
463 | |
464 static char *app_gdd_connect | |
465 (app_cmd_entry_t *cmd_entry_ptr, int argc, | |
466 char * argv[], core_func_t core_func) | |
467 { | |
468 GDD_RESULT result; | |
469 int i = 0; | |
470 const T_GDD_CAP gdd_cap = gdd_create_capabilities_300(); | |
471 int inst_id = get_inst_num(argv[1]); | |
472 if(inst_id < 0) | |
473 { | |
474 TRACE_ERROR("Invalid instance specified"); | |
475 BAT_TEST_FAILED(); | |
476 return 0; | |
477 } | |
478 | |
479 TRACE_FUNCTION("app_gdd_connect"); | |
480 | |
481 | |
482 /* Find free slot for connection handle */ | |
483 while(i < TEST_MAX_CON && con_table[i].con_handle != 0) | |
484 { | |
485 ++i; | |
486 } | |
487 if(i EQ TEST_MAX_CON) | |
488 { | |
489 TRACE_ERROR("No free slot for connection handle"); | |
490 BAT_TEST_FAILED(); | |
491 return 0; | |
492 } | |
493 | |
494 result = gdd_func->gdd_connect | |
495 ((T_GDD_INST_ID)inst_id, &(con_table[i].con_handle), &gdd_cap,(T_GDD_RECEIVE_DATA_CB)app_gdd_receive_data_cb,(T_GDD_SIGNAL_CB) app_gdd_signal_cb); | |
496 if(result != GDD_OK) | |
497 { | |
498 TRACE_ERROR("Call to gdd_connect failed"); | |
499 BAT_TEST_FAILED(); | |
500 return 0; | |
501 } | |
502 | |
503 BAT_TEST_PASSED(); | |
504 return 0; | |
505 } | |
506 | |
507 static char *app_gdd_disconnect | |
508 (app_cmd_entry_t *cmd_entry_ptr, int argc, | |
509 char * argv[], core_func_t core_func) | |
510 { | |
511 GDD_RESULT result; | |
512 int con_num; /* connection number -index into local static connection table */ | |
513 | |
514 TRACE_FUNCTION("app_gdd_disconnect"); | |
515 | |
516 con_num = get_item(argv[1], 0, FALSE); | |
517 if(con_num >= TEST_MAX_CON) | |
518 { | |
519 TRACE_ERROR("Connection number out of bounds"); | |
520 BAT_TEST_FAILED(); | |
521 return 0; | |
522 } | |
523 if(con_table[con_num].con_handle EQ 0) | |
524 { | |
525 TRACE_ERROR("Connection number not valid - no connection handle"); | |
526 BAT_TEST_FAILED(); | |
527 return 0; | |
528 } | |
529 | |
530 result = gdd_func->gdd_disconnect(con_table[con_num].con_handle); | |
531 if(result != GDD_OK) | |
532 { | |
533 TRACE_ERROR("Call to gdd_disconnect failed"); | |
534 BAT_TEST_FAILED(); | |
535 return 0; | |
536 } | |
537 | |
538 /* Free our application buffers which we have allocated ourselfs */ | |
539 if(con_table[con_num].rcv_buf) | |
540 { | |
541 free_dio_buf((T_dio_buffer **)(&con_table[con_num].rcv_buf)); | |
542 con_table[con_num].rcv_buf = 0; | |
543 } | |
544 | |
545 con_table[con_num].con_handle = 0; | |
546 | |
547 BAT_TEST_PASSED(); | |
548 return 0; | |
549 } | |
550 | |
551 static char *app_gdd_get_send_buffer | |
552 (app_cmd_entry_t *cmd_entry_ptr, int argc, | |
553 char * argv[], core_func_t core_func) | |
554 { | |
555 GDD_RESULT result; | |
556 int con_num; /* connection number -index into local static connection table */ | |
557 int num_bytes; | |
558 T_GDD_BUF * buf; | |
559 | |
560 TRACE_FUNCTION("app_gdd_get_send_buffer"); | |
561 | |
562 con_num = get_item(argv[1], 0, TRUE); | |
563 if(con_num >= TEST_MAX_CON) | |
564 { | |
565 TRACE_ERROR("Connection number out of bounds"); | |
566 BAT_TEST_FAILED(); | |
567 return 0; | |
568 } | |
569 if(con_table[con_num].con_handle EQ 0) | |
570 { | |
571 TRACE_ERROR("Connection number not valid - no connection handle"); | |
572 BAT_TEST_FAILED(); | |
573 return 0; | |
574 } | |
575 | |
576 num_bytes = get_item(argv[2], 100, FALSE); | |
577 | |
578 result = gdd_func->gdd_get_send_buffer(con_table[con_num].con_handle, &buf, (U16)num_bytes); | |
579 if(result != GDD_OK) | |
580 { | |
581 TRACE_ERROR("Call to gdd_get_send_buffer failed"); | |
582 BAT_TEST_FAILED(); | |
583 return 0; | |
584 } | |
585 | |
586 con_table[con_num].send_buf = buf; | |
587 | |
588 BAT_TEST_PASSED(); | |
589 return 0; | |
590 } | |
591 | |
592 static char *app_gdd_send_data | |
593 (app_cmd_entry_t *cmd_entry_ptr, int argc, | |
594 char * argv[], core_func_t core_func) | |
595 { | |
596 GDD_RESULT result; | |
597 int con_num; /* connection number -index into local static connection table */ | |
598 int num_bytes; | |
599 T_GDD_BUF * buf; | |
600 | |
601 TRACE_FUNCTION("app_gdd_send_data"); | |
602 | |
603 con_num = get_item(argv[1], 0, TRUE); | |
604 if(con_num >= TEST_MAX_CON) | |
605 { | |
606 TRACE_ERROR("Connection number out of bounds"); | |
607 BAT_TEST_FAILED(); | |
608 return 0; | |
609 } | |
610 if(con_table[con_num].con_handle EQ 0) | |
611 { | |
612 TRACE_ERROR("Connection number not valid - no connection handle"); | |
613 BAT_TEST_FAILED(); | |
614 return 0; | |
615 } | |
616 buf = con_table[con_num].send_buf; | |
617 if(buf EQ 0) | |
618 { | |
619 TRACE_ERROR("No buffer for sending"); | |
620 BAT_TEST_FAILED(); | |
621 return 0; | |
622 } | |
623 | |
624 num_bytes = get_item(argv[2], 100, FALSE); | |
625 | |
626 app_gdd_setup_test_buffer(buf, (U16)num_bytes); | |
627 | |
628 result = gdd_func->gdd_send_data(con_table[con_num].con_handle, buf); | |
629 if(result != GDD_OK) | |
630 { | |
631 TRACE_ERROR("Call to gdd_get_send_buffer failed"); | |
632 BAT_TEST_FAILED(); | |
633 return 0; | |
634 } | |
635 | |
636 con_table[con_num].send_buf = 0; | |
637 | |
638 BAT_TEST_PASSED(); | |
639 return 0; | |
640 } | |
641 | |
642 | |
643 | |
644 static char *app_gdd_receive_data | |
645 (app_cmd_entry_t *cmd_entry_ptr, int argc, | |
646 char * argv[], core_func_t core_func) | |
647 { | |
648 int con_num; /* connection number -index into local static connection table */ | |
649 int num_bytes; | |
650 T_GDD_BUF * buf; | |
651 | |
652 TRACE_FUNCTION("app_gdd_receive_data"); | |
653 | |
654 con_num = get_item(argv[1], 0, FALSE); | |
655 if(con_num >= TEST_MAX_CON) | |
656 { | |
657 TRACE_ERROR("Connection number out of bounds"); | |
658 BAT_TEST_FAILED(); | |
659 return 0; | |
660 } | |
661 if(con_table[con_num].con_handle EQ 0) | |
662 { | |
663 TRACE_ERROR("Connection number not valid - no connection handle"); | |
664 BAT_TEST_FAILED(); | |
665 return 0; | |
666 } | |
667 buf = con_table[con_num].rcv_buf; | |
668 if(buf EQ 0) | |
669 { | |
670 TRACE_ERROR("No buffer received"); | |
671 BAT_TEST_FAILED(); | |
672 return 0; | |
673 } | |
674 | |
675 num_bytes = get_item(argv[2], 100, FALSE); | |
676 | |
677 /* Compare/verify the received buffer */ | |
678 if(app_gdd_verify_test_buffer(buf, (U16)num_bytes) EQ FALSE) | |
679 { | |
680 TRACE_ERROR("Verification of received buffer failed"); | |
681 BAT_TEST_FAILED(); | |
682 return 0; | |
683 } | |
684 | |
685 /* Free our application buffers which we have allocated ourselfs */ | |
686 if(con_table[con_num].rcv_buf) | |
687 { | |
688 free_dio_buf((T_dio_buffer **)(&con_table[con_num].rcv_buf)); | |
689 con_table[con_num].rcv_buf = 0; | |
690 } | |
691 | |
692 BAT_TEST_PASSED(); | |
693 return 0; | |
694 } | |
695 | |
696 | |
697 | |
698 static char *app_gdd_sig_ready_rcv | |
699 (app_cmd_entry_t *cmd_entry_ptr, int argc, | |
700 char * argv[], core_func_t core_func) | |
701 { | |
702 int con_num; /* connection number -index into local static connection table */ | |
703 | |
704 TRACE_FUNCTION("app_gdd_sig_ready_rcv"); | |
705 | |
706 con_num = get_item(argv[1], 0, FALSE); | |
707 if(con_num >= TEST_MAX_CON) | |
708 { | |
709 TRACE_ERROR("Connection number out of bounds"); | |
710 BAT_TEST_FAILED(); | |
711 return 0; | |
712 } | |
713 if(con_table[con_num].con_handle EQ 0) | |
714 { | |
715 TRACE_ERROR("Connection number not valid - no connection handle"); | |
716 BAT_TEST_FAILED(); | |
717 return 0; | |
718 } | |
719 | |
720 gdd_func->gdd_signal_ready_rcv(con_table[con_num].con_handle); | |
721 | |
722 BAT_TEST_PASSED(); | |
723 return 0; | |
724 } | |
725 | |
726 | |
727 static char *app_gdd_init_test_parms | |
728 (app_cmd_entry_t *cmd_entry_ptr, int argc, | |
729 char * argv[], core_func_t core_func) | |
730 { | |
731 GDD_RESULT result; | |
732 | |
733 TRACE_FUNCTION("app_gdd_init_test_parms"); | |
734 | |
735 /* | |
736 * Test range of user ID | |
737 */ | |
738 /*lint -e778*/ | |
739 result = gdd_func->gdd_init(GDD_INST_NONE, (void *)0, (U16)4) ; | |
740 if(result NEQ GDD_INVALID_PARAMS) | |
741 { | |
742 TRACE_ERROR("BAD param value *NOT* detected (user = GDD_INST_BAT - 1)"); | |
743 BAT_TEST_FAILED(); | |
744 return 0; | |
745 } | |
746 result = gdd_func->gdd_init(GDD_NUM_INSTS, 0, 4); | |
747 if(result NEQ GDD_INVALID_PARAMS) | |
748 { | |
749 TRACE_ERROR("BAD param value *NOT* detected (user = GDD_NUM_INSTS)"); | |
750 BAT_TEST_FAILED(); | |
751 return 0; | |
752 } | |
753 | |
754 /* | |
755 * Nothing to do for the mem parameter | |
756 * (should already have been tested before) | |
757 */ | |
758 | |
759 /* | |
760 * Test number of connections | |
761 */ | |
762 result = gdd_func->gdd_init(GDD_INST_BAT, 0, 0); | |
763 if(result NEQ GDD_INVALID_PARAMS) | |
764 { | |
765 TRACE_ERROR("BAD param value *NOT* detected (num_con = 0)"); | |
766 BAT_TEST_FAILED(); | |
767 return 0; | |
768 } | |
769 result = gdd_func->gdd_init(GDD_INST_BAT, 0, TEST_MAX_CON+1); | |
770 if(result NEQ GDD_INVALID_PARAMS) | |
771 { | |
772 TRACE_ERROR("BAD param value *NOT* detected (num_con = TEST_MAX_CON+1)"); | |
773 BAT_TEST_FAILED(); | |
774 return 0; | |
775 } | |
776 | |
777 BAT_TEST_PASSED(); | |
778 return 0; | |
779 } | |
780 | |
781 static char *app_gdd_deinit_test_parms | |
782 (app_cmd_entry_t *cmd_entry_ptr, int argc, | |
783 char * argv[], core_func_t core_func) | |
784 { | |
785 GDD_RESULT result; | |
786 | |
787 TRACE_FUNCTION("app_gdd_deinit_test_parms"); | |
788 | |
789 /* | |
790 * Test range of user ID | |
791 */ | |
792 result = gdd_func->gdd_deinit(GDD_INST_NONE) ; /*lint -e778*/ | |
793 if(result NEQ GDD_INVALID_PARAMS) | |
794 { | |
795 TRACE_ERROR("BAD param value *NOT* detected (user = GDD_INST_BAT - 1)"); | |
796 BAT_TEST_FAILED(); | |
797 return 0; | |
798 } | |
799 result = gdd_func->gdd_deinit(GDD_NUM_INSTS); | |
800 if(result NEQ GDD_INVALID_PARAMS) | |
801 { | |
802 TRACE_ERROR("BAD param value *NOT* detected (user = GDD_NUM_INSTS)"); | |
803 BAT_TEST_FAILED(); | |
804 return 0; | |
805 } | |
806 | |
807 BAT_TEST_PASSED(); | |
808 return 0; | |
809 } | |
810 | |
811 static char *app_gdd_connect_test_parms | |
812 (app_cmd_entry_t *cmd_entry_ptr, int argc, | |
813 char * argv[], core_func_t core_func) | |
814 { | |
815 GDD_RESULT result; | |
816 const T_GDD_CAP gdd_cap = gdd_create_capabilities_300(); | |
817 | |
818 TRACE_FUNCTION("app_gdd_connect_test_parms"); | |
819 | |
820 /* | |
821 * Test range of user ID | |
822 */ | |
823 result = gdd_func->gdd_connect(GDD_INST_NONE, &(con_table[0].con_handle), /*lint -e778*/ | |
824 &gdd_cap, (T_GDD_RECEIVE_DATA_CB)app_gdd_receive_data_cb, (T_GDD_SIGNAL_CB)app_gdd_signal_cb); | |
825 if(result NEQ GDD_INVALID_PARAMS) | |
826 { | |
827 TRACE_ERROR("BAD param value *NOT* detected (user = GDD_INST_BAT - 1)"); | |
828 BAT_TEST_FAILED(); | |
829 return 0; | |
830 } | |
831 result = gdd_func->gdd_connect(GDD_NUM_INSTS, &(con_table[0].con_handle), | |
832 &gdd_cap, (T_GDD_RECEIVE_DATA_CB)app_gdd_receive_data_cb, (T_GDD_SIGNAL_CB)app_gdd_signal_cb); | |
833 if(result NEQ GDD_INVALID_PARAMS) | |
834 { | |
835 TRACE_ERROR("BAD param value *NOT* detected (user = GDD_NUM_INSTS)"); | |
836 BAT_TEST_FAILED(); | |
837 return 0; | |
838 } | |
839 | |
840 /* Test handling of con_handle = 0 */ | |
841 result = gdd_func->gdd_connect(GDD_INST_BAT, 0, | |
842 &gdd_cap, (T_GDD_RECEIVE_DATA_CB)app_gdd_receive_data_cb, (T_GDD_SIGNAL_CB)app_gdd_signal_cb); | |
843 if(result NEQ GDD_INVALID_PARAMS) | |
844 { | |
845 TRACE_ERROR("BAD param value *NOT* detected (con_handle = 0)"); | |
846 BAT_TEST_FAILED(); | |
847 return 0; | |
848 } | |
849 | |
850 /* Test handling of cap = 0 */ | |
851 result = gdd_func->gdd_connect(GDD_INST_BAT, &(con_table[0].con_handle), | |
852 0, (T_GDD_RECEIVE_DATA_CB)app_gdd_receive_data_cb, (T_GDD_SIGNAL_CB)app_gdd_signal_cb); | |
853 if(result NEQ GDD_INVALID_PARAMS) | |
854 { | |
855 TRACE_ERROR("BAD param value *NOT* detected (cap = 0)"); | |
856 BAT_TEST_FAILED(); | |
857 return 0; | |
858 } | |
859 | |
860 /* Test handling of rcv_cb = 0 */ | |
861 result = gdd_func->gdd_connect(GDD_INST_BAT, &(con_table[0].con_handle), | |
862 &gdd_cap, 0,(T_GDD_SIGNAL_CB) app_gdd_signal_cb); | |
863 if(result NEQ GDD_INVALID_PARAMS) | |
864 { | |
865 TRACE_ERROR("BAD param value *NOT* detected (rcv_cb = 0)"); | |
866 BAT_TEST_FAILED(); | |
867 return 0; | |
868 } | |
869 | |
870 /* Test handling of sig_cb = 0 */ | |
871 result = gdd_func->gdd_connect(GDD_INST_BAT, &(con_table[0].con_handle), | |
872 &gdd_cap, app_gdd_receive_data_cb, 0); | |
873 if(result NEQ GDD_INVALID_PARAMS) | |
874 { | |
875 TRACE_ERROR("BAD param value *NOT* detected (sig_cb = 0)"); | |
876 BAT_TEST_FAILED(); | |
877 return 0; | |
878 } | |
879 | |
880 BAT_TEST_PASSED(); | |
881 return 0; | |
882 } | |
883 | |
884 static char *app_gdd_disconnect_test_parms | |
885 (app_cmd_entry_t *cmd_entry_ptr, int argc, | |
886 char * argv[], core_func_t core_func) | |
887 { | |
888 GDD_RESULT result; | |
889 | |
890 TRACE_FUNCTION("app_gdd_disconnect_test_parms"); | |
891 | |
892 /* Test handling of con_handle = 0 */ | |
893 result = gdd_func->gdd_disconnect(0); | |
894 if(result NEQ GDD_INVALID_PARAMS) | |
895 { | |
896 TRACE_ERROR("BAD param value *NOT* detected (con_handle = 0)"); | |
897 BAT_TEST_FAILED(); | |
898 return 0; | |
899 } | |
900 | |
901 BAT_TEST_PASSED(); | |
902 return 0; | |
903 } | |
904 | |
905 static char *app_gdd_get_send_buffer_test_parms | |
906 (app_cmd_entry_t *cmd_entry_ptr, int argc, | |
907 char * argv[], core_func_t core_func) | |
908 { | |
909 GDD_RESULT result; | |
910 T_GDD_BUF * buf; | |
911 | |
912 TRACE_FUNCTION("app_gdd_get_send_buffer_test_parms"); | |
913 | |
914 /* Test handling of con_handle = 0 */ | |
915 result = gdd_func->gdd_get_send_buffer(0, &buf, GDD_MTU_SIZE); | |
916 if(result NEQ GDD_INVALID_PARAMS) | |
917 { | |
918 TRACE_ERROR("BAD param value *NOT* detected (con_handle = 0)"); | |
919 BAT_TEST_FAILED(); | |
920 return 0; | |
921 } | |
922 | |
923 /* Test handling of buf = 0 */ | |
924 result = gdd_func->gdd_get_send_buffer(TEST_CON_HANDLE, 0, GDD_MTU_SIZE); | |
925 if(result NEQ GDD_INVALID_PARAMS) | |
926 { | |
927 TRACE_ERROR("BAD param value *NOT* detected (buf = 0)"); | |
928 BAT_TEST_FAILED(); | |
929 return 0; | |
930 } | |
931 | |
932 /* Test handling of size = 0 */ | |
933 result = gdd_func->gdd_get_send_buffer(TEST_CON_HANDLE, &buf, 0); | |
934 if(result NEQ GDD_INVALID_PARAMS) | |
935 { | |
936 TRACE_ERROR("BAD param value *NOT* detected (size = 0)"); | |
937 BAT_TEST_FAILED(); | |
938 return 0; | |
939 } | |
940 /* Test handling of size > GDD_MTU_SIZE */ | |
941 result = gdd_func->gdd_get_send_buffer(TEST_CON_HANDLE, &buf, GDD_MTU_SIZE+1); | |
942 if(result NEQ GDD_INVALID_PARAMS) | |
943 { | |
944 TRACE_ERROR("BAD param value *NOT* detected (size = GDD_MTU_SIZE+1)"); | |
945 BAT_TEST_FAILED(); | |
946 return 0; | |
947 } | |
948 | |
949 BAT_TEST_PASSED(); | |
950 return 0; | |
951 } | |
952 | |
953 static char *app_gdd_send_data_test_parms | |
954 (app_cmd_entry_t *cmd_entry_ptr, int argc, | |
955 char * argv[], core_func_t core_func) | |
956 { | |
957 GDD_RESULT result; | |
958 T_GDD_BUF buf; | |
959 | |
960 TRACE_FUNCTION("app_gdd_send_data_test_parms"); | |
961 | |
962 /* Test handling of con_handle = 0 */ | |
963 result = gdd_func->gdd_send_data(0, &buf); | |
964 if(result NEQ GDD_INVALID_PARAMS) | |
965 { | |
966 TRACE_ERROR("BAD param value *NOT* detected (con_handle = 0)"); | |
967 BAT_TEST_FAILED(); | |
968 return 0; | |
969 } | |
970 | |
971 /* Test handling of buf = 0 */ | |
972 result = gdd_func->gdd_send_data(TEST_CON_HANDLE, 0); | |
973 if(result NEQ GDD_INVALID_PARAMS) | |
974 { | |
975 TRACE_ERROR("BAD param value *NOT* detected (buf = 0)"); | |
976 BAT_TEST_FAILED(); | |
977 return 0; | |
978 } | |
979 | |
980 BAT_TEST_PASSED(); | |
981 return 0; | |
982 } | |
983 | |
984 | |
985 /* | |
986 * Test connect, followed by immedate disconnect without waiting for connect signal | |
987 */ | |
988 static char *app_gdd_immediate_disconnect | |
989 (app_cmd_entry_t *cmd_entry_ptr, int argc, | |
990 char * argv[], core_func_t core_func) | |
991 { | |
992 GDD_RESULT result; | |
993 int con_idx = 0; | |
994 | |
995 int user_id = get_item(argv[1], GDD_INST_BAT, TRUE); | |
996 const T_GDD_CAP gdd_cap = gdd_create_capabilities_300(); | |
997 | |
998 TRACE_FUNCTION("app_gdd_immediate_disconnect"); | |
999 | |
1000 /* Find free slot for connection handle */ | |
1001 while(con_idx < TEST_MAX_CON && con_table[con_idx].con_handle != 0) | |
1002 { | |
1003 ++con_idx; | |
1004 } | |
1005 if(con_idx EQ TEST_MAX_CON) | |
1006 { | |
1007 TRACE_ERROR("No free slot for connection handle"); | |
1008 BAT_TEST_FAILED(); | |
1009 return 0; | |
1010 } | |
1011 | |
1012 result = gdd_func->gdd_connect | |
1013 ((T_GDD_INST_ID)user_id, &(con_table[con_idx].con_handle), &gdd_cap, | |
1014 (T_GDD_RECEIVE_DATA_CB) app_gdd_receive_data_cb, (T_GDD_SIGNAL_CB)app_gdd_signal_cb); | |
1015 if(result != GDD_OK) | |
1016 { | |
1017 TRACE_ERROR("Call to gdd_connect failed"); | |
1018 BAT_TEST_FAILED(); | |
1019 return 0; | |
1020 } | |
1021 TRACE_EVENT_P2("Created connection, con_handle = %d (slot %d)", con_table[con_idx].con_handle, con_idx); | |
1022 | |
1023 /* Don't sleep - but you might want to activate for debugging */ | |
1024 /*vsi_t_sleep (VSI_CALLER 2000);*/ | |
1025 | |
1026 result = gdd_func->gdd_disconnect(con_table[con_idx].con_handle); | |
1027 if(result != GDD_OK) | |
1028 { | |
1029 TRACE_ERROR("Call to gdd_disconnect failed"); | |
1030 BAT_TEST_FAILED(); | |
1031 return 0; | |
1032 } | |
1033 TRACE_EVENT_P1("Disconnected connection, con_handle = %d", con_table[con_idx].con_handle); | |
1034 | |
1035 /* Free connection slot */ | |
1036 con_table[con_idx].con_handle = 0; | |
1037 | |
1038 BAT_TEST_PASSED(); | |
1039 return 0; | |
1040 } | |
1041 | |
1042 | |
1043 #ifdef WIN32 | |
1044 | |
1045 /* | |
1046 * The the correct sending of the signal GDD_SIGTYPE_SEND_BUF_AVAILABLE | |
1047 */ | |
1048 static char *app_gdd_test_sig_sbuf_avail | |
1049 (app_cmd_entry_t *cmd_entry_ptr, int argc, | |
1050 char * argv[], core_func_t core_func) | |
1051 { | |
1052 GDD_RESULT result; | |
1053 T_GDD_BUF * buf1, * buf2, * buf3; | |
1054 int con_idx = 0; | |
1055 int user_id = get_item(argv[1], GDD_INST_BAT, TRUE); | |
1056 const T_GDD_CAP gdd_cap = gdd_create_capabilities_300(); | |
1057 | |
1058 TRACE_FUNCTION("app_gdd_test_sig_sbuf_avail"); | |
1059 | |
1060 /* Switch off the automatic provision of send buffers in the PSI stub */ | |
1061 psi_stub_send_rx_buf_after_read(FALSE); | |
1062 | |
1063 /* Find free slot for connection handle */ | |
1064 while(con_idx < TEST_MAX_CON && con_table[con_idx].con_handle != 0) | |
1065 { | |
1066 ++con_idx; | |
1067 } | |
1068 if(con_idx EQ TEST_MAX_CON) | |
1069 { | |
1070 TRACE_ERROR("No free slot for connection handle"); | |
1071 BAT_TEST_FAILED(); | |
1072 return 0; | |
1073 } | |
1074 | |
1075 /* Connect & disconnect */ | |
1076 result = gdd_func->gdd_connect | |
1077 (user_id, &(con_table[con_idx].con_handle), &gdd_cap, app_gdd_receive_data_cb, app_gdd_signal_cb); | |
1078 if(result != GDD_OK) | |
1079 { | |
1080 TRACE_ERROR("Call to gdd_connect failed"); | |
1081 BAT_TEST_FAILED(); | |
1082 return 0; | |
1083 } | |
1084 result = gdd_func->gdd_disconnect(con_table[con_idx].con_handle); | |
1085 if(result != GDD_OK) | |
1086 { | |
1087 TRACE_ERROR("Call to gdd_disconnect failed"); | |
1088 BAT_TEST_FAILED(); | |
1089 return 0; | |
1090 } | |
1091 | |
1092 /* Reset test counter */ | |
1093 con_table[con_idx].cnt_sigtype_send_buf_available = 0; | |
1094 | |
1095 /* Create connection */ | |
1096 result = gdd_func->gdd_connect | |
1097 (user_id, &(con_table[con_idx].con_handle), &gdd_cap, app_gdd_receive_data_cb, app_gdd_signal_cb); | |
1098 if(result != GDD_OK) | |
1099 { | |
1100 TRACE_ERROR("Call to gdd_connect failed"); | |
1101 BAT_TEST_FAILED(); | |
1102 return 0; | |
1103 } | |
1104 TRACE_EVENT_P2("Created connection, con_handle = %d (slot %d)", con_table[con_idx].con_handle, con_idx); | |
1105 | |
1106 /* Wait for 2 seconds to be sure that we will have the send buffer by then. */ | |
1107 vsi_t_sleep (VSI_CALLER 2000); | |
1108 | |
1109 /* Get a first send buffer */ | |
1110 result = gdd_func->gdd_get_send_buffer(con_table[con_idx].con_handle, &buf1, GDD_MTU_SIZE); | |
1111 if(result NEQ GDD_OK) | |
1112 { | |
1113 TRACE_ERROR("Error: gdd_get_send_buffer() failed"); | |
1114 BAT_TEST_FAILED(); | |
1115 return 0; | |
1116 } | |
1117 | |
1118 result = gdd_func->gdd_get_send_buffer(con_table[con_idx].con_handle, &buf2, GDD_MTU_SIZE); | |
1119 if(result NEQ GDD_NO_BUF_AVAILABLE) | |
1120 { | |
1121 TRACE_ERROR("gdd_get_send_buffer() did not fail as expected"); | |
1122 BAT_TEST_FAILED(); | |
1123 return 0; | |
1124 } | |
1125 | |
1126 /* Now we send back the first buffer. */ | |
1127 result = gdd_func->gdd_send_data(con_table[con_idx].con_handle, buf1); | |
1128 if(result NEQ GDD_OK) | |
1129 { | |
1130 TRACE_ERROR("gdd_send_data() failed"); | |
1131 BAT_TEST_FAILED(); | |
1132 return 0; | |
1133 } | |
1134 | |
1135 /* Now we can get the second send buffer */ | |
1136 result = gdd_func->gdd_get_send_buffer(con_table[con_idx].con_handle, &buf2, GDD_MTU_SIZE); | |
1137 if(result NEQ GDD_OK) | |
1138 { | |
1139 TRACE_ERROR("gdd_get_send_buffer failed"); | |
1140 BAT_TEST_FAILED(); | |
1141 return 0; | |
1142 } | |
1143 | |
1144 /* Remove the receive buffer previously received */ | |
1145 free_dio_buf((T_dio_buffer **)(&con_table[con_idx].rcv_buf)); | |
1146 con_table[con_idx].rcv_buf = 0; | |
1147 | |
1148 /* Now we send back the 2nd buffer buffer. */ | |
1149 result = gdd_func->gdd_send_data(con_table[con_idx].con_handle, buf2); | |
1150 if(result NEQ GDD_OK) | |
1151 { | |
1152 TRACE_ERROR("gdd_send_data() failed"); | |
1153 BAT_TEST_FAILED(); | |
1154 return 0; | |
1155 } | |
1156 | |
1157 /* When we try to get the third buffer, we should now fail, | |
1158 as we switched of automatic provision of RX buffers at the beginning */ | |
1159 result = gdd_func->gdd_get_send_buffer(con_table[con_idx].con_handle, &buf3, GDD_MTU_SIZE); | |
1160 if(result NEQ GDD_NO_BUF_AVAILABLE) | |
1161 { | |
1162 TRACE_ERROR("gdd_get_send_buffer should have failed with GDD_NO_BUF_AVAILABLE"); | |
1163 BAT_TEST_FAILED(); | |
1164 return 0; | |
1165 } | |
1166 | |
1167 /* Create a new RX buffer in the PSI stub */ | |
1168 psi_stub_provide_rx_buf(); | |
1169 | |
1170 /* Now we should be able to get the new buffer */ | |
1171 result = gdd_func->gdd_get_send_buffer(con_table[con_idx].con_handle, &buf3, GDD_MTU_SIZE); | |
1172 if(result NEQ GDD_OK) | |
1173 { | |
1174 TRACE_ERROR("gdd_get_send_buffer failed"); | |
1175 BAT_TEST_FAILED(); | |
1176 return 0; | |
1177 } | |
1178 | |
1179 /* Two signals GDD_SIGTYPE_SEND_BUF_AVAILABLE should have been sent | |
1180 (one after the connection, and one when we called pst_stub_provide_rx_buf | |
1181 the last time) */ | |
1182 if(con_table[con_idx].cnt_sigtype_send_buf_available NEQ 1) | |
1183 { | |
1184 TRACE_ERROR("Wrong value in cnt_sigtype_send_buf_available"); | |
1185 BAT_TEST_FAILED(); | |
1186 return 0; | |
1187 } | |
1188 | |
1189 result = gdd_func->gdd_disconnect(con_table[con_idx].con_handle); | |
1190 if(result != GDD_OK) | |
1191 { | |
1192 TRACE_ERROR("Call to gdd_disconnect failed"); | |
1193 BAT_TEST_FAILED(); | |
1194 return 0; | |
1195 } | |
1196 TRACE_EVENT_P1("Disconnected connection, con_handle = %d", con_table[con_idx].con_handle); | |
1197 | |
1198 /* Free connection slot */ | |
1199 con_table[con_idx].con_handle = 0; | |
1200 | |
1201 /* Switch on the automatic provision of send buffers in the PSI stub */ | |
1202 psi_stub_send_rx_buf_after_read(TRUE); | |
1203 | |
1204 BAT_TEST_PASSED(); | |
1205 return 0; | |
1206 } | |
1207 | |
1208 #endif /* WIN32 */ | |
1209 | |
1210 | |
1211 | |
1212 /*--------------------------------------------------------------------------- | |
1213 * Testing helper functions. | |
1214 *---------------------------------------------------------------------------*/ | |
1215 | |
1216 static U32 test_gdd_write_buf() | |
1217 { | |
1218 T_dio_buffer * dest_buf; | |
1219 char src_buf[250]; | |
1220 | |
1221 allocate_rx_dio_buf(&dest_buf); | |
1222 if(dest_buf->c_dio_segment != 2) | |
1223 { | |
1224 return((U32) -1); | |
1225 } | |
1226 if(dest_buf->length < (sizeof(src_buf) + 2 /*PID*/)) | |
1227 { | |
1228 return((U32) -1); | |
1229 } | |
1230 | |
1231 app_gdd_setup_segment((U8 *)src_buf, sizeof(src_buf), 22 /* arbitrary offset */); | |
1232 | |
1233 if(gdd_write_buf(( U8 *)src_buf, sizeof(src_buf), (T_GDD_BUF*)dest_buf) < 0) | |
1234 { | |
1235 return((U32) -1); | |
1236 } | |
1237 | |
1238 if(memcmp(src_buf, dest_buf->ptr_dio_segment[1].ptr_data, sizeof(src_buf))) | |
1239 { | |
1240 return((U32) -1); | |
1241 } | |
1242 | |
1243 return 0; | |
1244 } | |
1245 | |
1246 | |
1247 /* | |
1248 * Test the function 'gdd_read_buf()'. Return 0 if OK. | |
1249 */ | |
1250 static U32 test_gdd_read_buf() | |
1251 { | |
1252 char src_buf[500]; | |
1253 char dest_buf[500]; | |
1254 T_dio_buffer * dio_buf; | |
1255 | |
1256 /* Totol size of 502 bytes over 6 segments (incl.PID in first seg) */ | |
1257 const U16 segments[] = {2, 15, 150, 35, 100, 200}; | |
1258 | |
1259 allocate_dio_buf(&dio_buf, segments, sizeof(segments)/sizeof(U16)); | |
1260 | |
1261 app_gdd_setup_segment((U8 *)src_buf, sizeof(src_buf), 22 /* arbitrary offset */); | |
1262 | |
1263 if(gdd_write_buf((U8 *)src_buf, sizeof(src_buf), (T_GDD_BUF*)dio_buf) < 0) | |
1264 { | |
1265 return((U32)-1); | |
1266 } | |
1267 | |
1268 if(gdd_read_buf((T_GDD_BUF*)dio_buf, (U8 *)dest_buf, sizeof(dest_buf)) < 0) | |
1269 { | |
1270 return((U32) -1); | |
1271 } | |
1272 | |
1273 if(memcmp(src_buf, dest_buf, sizeof(src_buf))) | |
1274 { | |
1275 return((U32)-1); | |
1276 } | |
1277 | |
1278 return 0; | |
1279 } | |
1280 | |
1281 | |
1282 static char *app_gdd_test_helper_functions | |
1283 (app_cmd_entry_t *cmd_entry_ptr, int argc, | |
1284 char * argv[], core_func_t core_func) | |
1285 { | |
1286 if(test_gdd_write_buf()) | |
1287 { | |
1288 BAT_TEST_FAILED(); | |
1289 } | |
1290 if(test_gdd_read_buf()) | |
1291 { | |
1292 BAT_TEST_FAILED(); | |
1293 } | |
1294 | |
1295 BAT_TEST_PASSED(); | |
1296 return 0; | |
1297 } | |
1298 | |
1299 | |
1300 /*--------------------------------------------------------------------------- | |
1301 * Definition of core functions | |
1302 *---------------------------------------------------------------------------*/ | |
1303 | |
1304 /* -- No core functions required for now */ | |
1305 | |
1306 | |
1307 /*==== Exported functions ====================================================*/ | |
1308 | |
1309 char *app_handle_command_gdd(char *command) | |
1310 { | |
1311 return app_handle_command(command, app_gdd_cmd_table); | |
1312 } | |
1313 | |
1314 | |
1315 /* EOF */ |