Fix binding to IPv6 interfaces
[ric-plt/lib/rmr.git] / test / rmr_debug_si_test.c
1 // vim: ts=4 sw=4 noet
2 /*
3 ==================================================================================
4         Copyright (c) 2021 Alexandre Huff (UTFPR).
5
6         Licensed under the Apache License, Version 2.0 (the "License");
7         you may not use this file except in compliance with the License.
8         You may obtain a copy of the License at
9
10                 http://www.apache.org/licenses/LICENSE-2.0
11
12         Unless required by applicable law or agreed to in writing, software
13         distributed under the License is distributed on an "AS IS" BASIS,
14         WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15         See the License for the specific language governing permissions and
16         limitations under the License.
17 ==================================================================================
18 */
19
20 /*
21         Mnemonic:       rmr_debug_si_test.c
22         Abstract:       This is the main driver to test the si95 debug functions
23
24         Date:           24 December 2021
25         Author:         Alexandre Huff
26 */
27 #include <netdb.h>
28 #include <errno.h>
29
30 #define DEBUG 1
31 #undef NNG_UNDER_TEST                                           // NNG is NOT under test so undefine if set
32 #define NO_EMULATION 1                                          // no emulation of transport functions
33
34 #include "rmr.h"
35 #include "rmr_agnostic.h"
36
37 #include "si95/socket_if.h"
38 #undef uta_ctx_t
39 #include "rmr_si_private.h"
40
41 #include "test_support.c"                                       // things like fail_if()
42
43 #include "rmr_debug_si.c"                   // api under test
44
45
46
47
48 // ------------- dummy functions to force edge cases when we can ---------------------------------------
49
50 #define SYSTEM_UNDER_TEST       1                               // for conditional code
51
52
53 // ----------------------------------------------------------------------------------------
54
55 static int get_debug_info_test( uta_ctx_t *ctx ) {
56     int errors = 0;
57     int ret;
58     rmr_rx_debug_t info;
59
60     ctx->acc_dcount = 5;    // dummy info
61     ctx->acc_ecount = 10;
62
63     // argument related things
64     ret = rmr_get_rx_debug_info( NULL, &info );
65     errors += fail_not_equal( EINVAL, errno, "get_debug_info_test: rmr_get_rx_debug_info did not set errno to EINVAL on nil global context" );
66     errors += fail_if_equal( 0, ret, "get_debug_info_test: rmr_get_rx_debug_info returned 0 on error" );
67
68     errno = 0;
69     ret = rmr_get_rx_debug_info( ctx, NULL );
70     errors += fail_not_equal( EINVAL, errno, "get_debug_info_test: rmr_get_rx_debug_info did not set errno to EINVAL on nil info struct" );
71     errors += fail_if_equal( 0, ret, "get_debug_info_test: rmr_get_rx_debug_info returned 0 on error" );
72
73     // test rx debug struct values
74     ret = rmr_get_rx_debug_info( ctx, &info );
75     errors += fail_not_equal( 0, ret, "get_debug_info_test: rmr_get_rx_debug_info did not return 0 on success" );
76     errors += fail_not_equal( 5, ctx->acc_dcount, "get_debug_info_test: rmr_get_rx_debug_info unexpected acc_dcount value in info struct" );
77     errors += fail_not_equal( 10, ctx->acc_ecount, "get_debug_info_test: rmr_get_rx_debug_info unexpected acc_ecount value in info struct" );
78
79     fprintf( stderr, "<INFO> get_debug_info_test finished with %d errors\n", errors );
80
81     return errors;
82 }
83
84 static int reset_debug_test(uta_ctx_t *ctx) {
85     int errors = 0;
86     int ret;
87
88     ctx->acc_dcount = 5;    // dummy info
89     ctx->acc_ecount = 10;
90
91     ret = rmr_reset_rx_debug_count( NULL ); // expect to fail
92     errors += fail_not_equal( EINVAL, errno, "reset_debug_test: rmr_reset_rx_debug_count did not set errno to EINVAL on error" );
93     errors += fail_if_equal( 0, ret, "reset_debug_test: rmr_reset_rx_debug_count returned 0 on error" );
94
95     ret = rmr_reset_rx_debug_count( ctx );  // expect to return successfully
96     errors += fail_not_equal( 0, ret, "reset_debug_test: reset_debug_rx_count did not return 0 on success" );
97     errors += fail_not_equal( 0, ctx->acc_dcount, "reset_debug_test: rmr_reset_rx_debug_count did not reset acc_dcount to 0" );
98     errors += fail_not_equal( 0, ctx->acc_ecount, "reset_debug_test: rmr_reset_rx_debug_count did not reset acc_ecount to 0" );
99
100     fprintf( stderr, "<INFO> reset_debug_test finished with %d errors\n", errors );
101
102     return errors;
103 }
104
105 // ----------------------------------------------------------------------------------------
106
107 /*
108         Drive tests...
109 */
110 int main() {
111     uta_ctx_t si_ctx;
112     int errors = 0;
113
114         fprintf( stderr, "\n<INFO> starting SI95 debug api tests\n" );
115
116     errors += get_debug_info_test( &si_ctx );
117     errors += reset_debug_test( &si_ctx );
118
119         test_summary( errors, "SI95 debug api tests" );
120         if( errors == 0 ) {
121                 fprintf( stderr, "<PASS> all tests were OK\n\n" );
122         } else {
123                 fprintf( stderr, "<FAIL> %d errors in SI95 debug api code\n\n", errors );
124         }
125
126         return !!errors;
127 }