3 ==================================================================================
4 Copyright (c) 2021 Alexandre Huff (UTFPR).
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
10 http://www.apache.org/licenses/LICENSE-2.0
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 ==================================================================================
21 Mnemonic: rmr_debug_si_test.c
22 Abstract: This is the main driver to test the si95 debug functions
24 Date: 24 December 2021
25 Author: Alexandre Huff
31 #undef NNG_UNDER_TEST // NNG is NOT under test so undefine if set
32 #define NO_EMULATION 1 // no emulation of transport functions
35 #include "rmr_agnostic.h"
37 #include "si95/socket_if.h"
39 #include "rmr_si_private.h"
41 #include "test_support.c" // things like fail_if()
43 #include "rmr_debug_si.c" // api under test
48 // ------------- dummy functions to force edge cases when we can ---------------------------------------
50 #define SYSTEM_UNDER_TEST 1 // for conditional code
53 // ----------------------------------------------------------------------------------------
55 static int get_debug_info_test( uta_ctx_t *ctx ) {
60 ctx->acc_dcount = 5; // dummy info
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" );
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" );
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" );
79 fprintf( stderr, "<INFO> get_debug_info_test finished with %d errors\n", errors );
84 static int reset_debug_test(uta_ctx_t *ctx) {
88 ctx->acc_dcount = 5; // dummy info
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" );
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" );
100 fprintf( stderr, "<INFO> reset_debug_test finished with %d errors\n", errors );
105 // ----------------------------------------------------------------------------------------
114 fprintf( stderr, "\n<INFO> starting SI95 debug api tests\n" );
116 errors += get_debug_info_test( &si_ctx );
117 errors += reset_debug_test( &si_ctx );
119 test_summary( errors, "SI95 debug api tests" );
121 fprintf( stderr, "<PASS> all tests were OK\n\n" );
123 fprintf( stderr, "<FAIL> %d errors in SI95 debug api code\n\n", errors );