CI: Add silent cmake SonarCloud scan
[ric-plt/lib/rmr.git] / test / test_ctx_support.c
1 // : vi ts=4 sw=4 noet :
2 /*
3 ==================================================================================
4             Copyright (c) 2020 Nokia
5             Copyright (c) 2020 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         Mnemonic:       test_ctx_support.c
23         Abstract:       This is some support for defining dummy contex struct as
24                                 they may need to contian rings and the like for successful
25                                 testing, and it may be too much to call rmr_init() to generate
26                                 one without dragging the whole test under.
27
28         Author:         E. Scott Daniels
29         Date:           21 February 2020
30 */
31
32 #ifndef _test_ctx_support_c
33 #define _test_ctx_support_c
34
35 #ifdef NNG_UNDER_TEST                                                   // add in the nng only things
36
37 #include <rmr_nng_private.h>                    // nng specific context
38
39 static inline uta_ctx_t *mk_dummy_ctx() {
40         uta_ctx_t*      ctx;
41
42         ctx = (uta_ctx_t *) malloc( sizeof( *ctx ) );
43         if( ctx == NULL ) {
44                 return NULL;
45         }
46
47         memset( ctx, 0, sizeof( *ctx ) );
48         ctx->snarf_rt_fd = -1;
49
50         return ctx;
51 }
52
53 #else                                                                                   // assume si is under test
54
55 #include <rmr_si_private.h>                                             // si specific context
56 #include <ring_static.c>
57
58 static inline uta_ctx_t *mk_dummy_ctx() {
59         uta_ctx_t*      ctx;
60
61         ctx = (uta_ctx_t *) malloc( sizeof( *ctx ) );
62         if( ctx == NULL ) {
63                 return NULL;
64         }
65         memset( ctx, 0, sizeof( *ctx ) );
66
67         ctx->ephash = rmr_sym_alloc( 129 );
68
69         ctx->mring = uta_mk_ring( 4096 );                               // message ring is always on for si
70         ctx->zcb_mring = uta_mk_ring( 128 );            // zero copy buffer mbuf ring to reduce malloc/free calls
71         ctx->si_ctx = malloc( 1024 );
72         ctx->my_name = strdup( "hostname1" );
73         ctx->my_ip = strdup( "123.45.67.89" );
74         ctx->snarf_rt_fd = -1;
75
76         ctx->rtgate = (pthread_mutex_t *) malloc( sizeof( *ctx->rtgate ) );
77     if( ctx->rtgate != NULL ) {
78         pthread_mutex_init( ctx->rtgate, NULL );
79     }
80
81
82         return ctx;
83 }
84
85 #endif
86
87 #endif