Fix meid related core dump
[ric-plt/lib/rmr.git] / test / mbuf_api_test.c
1 // : vi ts=4 sw=4 noet :
2 /*
3 ==================================================================================
4             Copyright (c) 2019 Nokia
5             Copyright (c) 2018-2019 AT&T Intellectual Property.
6
7    Licensed under the Apache License, Version 2.0 (the "License");
8    you may not use this file except in compliance with the License.
9    You may obtain a copy of the License at
10
11            http://www.apache.org/licenses/LICENSE-2.0
12
13    Unless required by applicable law or agreed to in writing, software
14    distributed under the License is distributed on an "AS IS" BASIS,
15    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16    See the License for the specific language governing permissions and
17    limitations under the License.
18 ==================================================================================
19 */
20
21
22 /*
23         Mnemonic:       mbuf_api_test.c
24         Abstract:       Unit tests for the mbuf common API functions.
25                                 To allow the mbuf functions to be tested without the bulk of the
26                                 RMr mechanics, we dummy up a couple of functions that are in
27                                 rmr[_nng].c.
28
29         Author:         E. Scott Daniels
30         Date:           2 April 2019
31 */
32
33
34 #include <stdio.h>
35 #include <stdlib.h>
36 #include <netdb.h>
37 #include <errno.h>
38 #include <string.h>
39 #include <errno.h>
40 #include <pthread.h>
41 #include <ctype.h>
42 #include <pthread.h>
43 #include <semaphore.h>
44
45
46 #include "rmr.h"
47 #include "rmr_agnostic.h"
48
49 #include "mbuf_api.c"
50
51 #define MSG_VER 3
52 #include "test_support.c"                                               // our private library of test tools
53 #include "mbuf_api_static_test.c"                               // test functions
54
55 // --- dummies -------------------------------------------------------------------
56
57 /*
58         This will leak, but we're not here to test free.
59 */
60 extern void rmr_free_msg( rmr_mbuf_t* mbuf ) {
61         return;
62 }
63
64 /*
65         Minimal buffer realloc to allow api to be tested without coverage hit if
66         we actually pulled in the sr static set.
67
68         WARNING:  this is NOT a complete realloc.  We assume that we are testing
69                         just the trace length adjustment portion of the set_trace()
70                         API and are not striving to test the real realloc function. That
71                         will be tested when the mbuf_api_static_test code is used by the
72                         more generic RMr test.  So, not all fields in the realloc'd buffer
73                         can be used.
74 */
75 extern rmr_mbuf_t* rmr_realloc_msg( rmr_mbuf_t* msg, int new_tr_size ) {
76         rmr_mbuf_t*     new_msg;
77         uta_mhdr_t* hdr;
78
79         new_msg = (rmr_mbuf_t *) malloc( sizeof *new_msg );
80         new_msg->tp_buf = (void *) malloc( 2048 );
81         memset( new_msg->tp_buf, 0, 2048 );
82         hdr = (uta_mhdr_t*) new_msg->tp_buf;
83         SET_HDR_LEN( hdr );
84         SET_HDR_TR_LEN( hdr, new_tr_size );
85
86         new_msg->payload = new_msg->tp_buf + new_tr_size;
87         new_msg->header = new_msg->tp_buf;
88         new_msg->alloc_len = 2048;
89         new_msg->len = msg->len;
90
91         return new_msg;
92 }
93
94 // --------------------------------------------------------------------------------
95
96 int main( ) {
97         int errors = 0;
98
99         errors += mbuf_api_test( );
100
101         if( errors ) {
102                 fprintf( stderr, "<FAIL> mbuf_api tests failed\n" );
103         } else {
104                 fprintf( stderr, "<OK>   mbuf_api tests pass\n" );
105         }
106
107         return errors;
108 }