E. Scott Daniels | 8dd4641 | 2019-04-16 20:47:54 +0000 | [diff] [blame] | 1 | // : vi ts=4 sw=4 noet : |
| 2 | /* |
| 3 | ================================================================================== |
E. Scott Daniels | 11838bc | 2021-04-22 16:34:08 -0400 | [diff] [blame] | 4 | Copyright (c) 2019-2021 Nokia |
| 5 | Copyright (c) 2018-2021 AT&T Intellectual Property. |
E. Scott Daniels | 8dd4641 | 2019-04-16 20:47:54 +0000 | [diff] [blame] | 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 | |
E. Scott Daniels | 8790bf0 | 2019-04-23 12:59:28 +0000 | [diff] [blame] | 11 | http://www.apache.org/licenses/LICENSE-2.0 |
E. Scott Daniels | 8dd4641 | 2019-04-16 20:47:54 +0000 | [diff] [blame] | 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. |
E. Scott Daniels | d710957 | 2019-04-18 14:01:16 +0000 | [diff] [blame] | 25 | To allow the mbuf functions to be tested without the bulk of the |
E. Scott Daniels | 8790bf0 | 2019-04-23 12:59:28 +0000 | [diff] [blame] | 26 | RMr mechanics, we dummy up a couple of functions that are in |
| 27 | rmr[_nng].c. |
E. Scott Daniels | d710957 | 2019-04-18 14:01:16 +0000 | [diff] [blame] | 28 | |
E. Scott Daniels | 8dd4641 | 2019-04-16 20:47:54 +0000 | [diff] [blame] | 29 | Author: E. Scott Daniels |
| 30 | Date: 2 April 2019 |
| 31 | */ |
| 32 | |
| 33 | |
E. Scott Daniels | fc5c77b | 2020-02-21 13:24:29 -0500 | [diff] [blame] | 34 | #define NO_EMULATION |
| 35 | |
E. Scott Daniels | 8dd4641 | 2019-04-16 20:47:54 +0000 | [diff] [blame] | 36 | #include <stdio.h> |
| 37 | #include <stdlib.h> |
| 38 | #include <netdb.h> |
| 39 | #include <errno.h> |
| 40 | #include <string.h> |
| 41 | #include <errno.h> |
| 42 | #include <pthread.h> |
| 43 | #include <ctype.h> |
E. Scott Daniels | 412d53d | 2019-05-20 20:00:52 +0000 | [diff] [blame] | 44 | #include <pthread.h> |
| 45 | #include <semaphore.h> |
E. Scott Daniels | 8dd4641 | 2019-04-16 20:47:54 +0000 | [diff] [blame] | 46 | |
| 47 | |
E. Scott Daniels | 412d53d | 2019-05-20 20:00:52 +0000 | [diff] [blame] | 48 | #include "rmr.h" |
| 49 | #include "rmr_agnostic.h" |
E. Scott Daniels | 8dd4641 | 2019-04-16 20:47:54 +0000 | [diff] [blame] | 50 | |
E. Scott Daniels | fcea395 | 2020-10-30 15:04:16 -0400 | [diff] [blame] | 51 | #include "logging.c" |
E. Scott Daniels | 412d53d | 2019-05-20 20:00:52 +0000 | [diff] [blame] | 52 | #include "mbuf_api.c" |
E. Scott Daniels | 8dd4641 | 2019-04-16 20:47:54 +0000 | [diff] [blame] | 53 | |
E. Scott Daniels | 68d09fa | 2019-06-03 19:45:12 +0000 | [diff] [blame] | 54 | #define MSG_VER 3 |
E. Scott Daniels | 8dd4641 | 2019-04-16 20:47:54 +0000 | [diff] [blame] | 55 | #include "test_support.c" // our private library of test tools |
| 56 | #include "mbuf_api_static_test.c" // test functions |
| 57 | |
E. Scott Daniels | d710957 | 2019-04-18 14:01:16 +0000 | [diff] [blame] | 58 | // --- dummies ------------------------------------------------------------------- |
| 59 | |
| 60 | /* |
| 61 | This will leak, but we're not here to test free. |
| 62 | */ |
| 63 | extern void rmr_free_msg( rmr_mbuf_t* mbuf ) { |
| 64 | return; |
| 65 | } |
| 66 | |
| 67 | /* |
| 68 | Minimal buffer realloc to allow api to be tested without coverage hit if |
| 69 | we actually pulled in the sr static set. |
| 70 | |
| 71 | WARNING: this is NOT a complete realloc. We assume that we are testing |
E. Scott Daniels | 8790bf0 | 2019-04-23 12:59:28 +0000 | [diff] [blame] | 72 | just the trace length adjustment portion of the set_trace() |
E. Scott Daniels | d710957 | 2019-04-18 14:01:16 +0000 | [diff] [blame] | 73 | API and are not striving to test the real realloc function. That |
| 74 | will be tested when the mbuf_api_static_test code is used by the |
| 75 | more generic RMr test. So, not all fields in the realloc'd buffer |
| 76 | can be used. |
| 77 | */ |
| 78 | extern rmr_mbuf_t* rmr_realloc_msg( rmr_mbuf_t* msg, int new_tr_size ) { |
| 79 | rmr_mbuf_t* new_msg; |
| 80 | uta_mhdr_t* hdr; |
| 81 | |
| 82 | new_msg = (rmr_mbuf_t *) malloc( sizeof *new_msg ); |
| 83 | new_msg->tp_buf = (void *) malloc( 2048 ); |
| 84 | memset( new_msg->tp_buf, 0, 2048 ); |
| 85 | hdr = (uta_mhdr_t*) new_msg->tp_buf; |
| 86 | SET_HDR_LEN( hdr ); |
| 87 | SET_HDR_TR_LEN( hdr, new_tr_size ); |
| 88 | |
| 89 | new_msg->payload = new_msg->tp_buf + new_tr_size; |
| 90 | new_msg->header = new_msg->tp_buf; |
| 91 | new_msg->alloc_len = 2048; |
| 92 | new_msg->len = msg->len; |
E. Scott Daniels | 5efb1e6 | 2019-05-02 17:09:35 +0000 | [diff] [blame] | 93 | |
E. Scott Daniels | d710957 | 2019-04-18 14:01:16 +0000 | [diff] [blame] | 94 | return new_msg; |
| 95 | } |
| 96 | |
| 97 | // -------------------------------------------------------------------------------- |
| 98 | |
E. Scott Daniels | 8dd4641 | 2019-04-16 20:47:54 +0000 | [diff] [blame] | 99 | int main( ) { |
| 100 | int errors = 0; |
| 101 | |
| 102 | errors += mbuf_api_test( ); |
| 103 | |
E. Scott Daniels | 77526eb | 2020-09-17 16:39:31 -0400 | [diff] [blame] | 104 | test_summary( errors, "mbuf API tests" ); |
E. Scott Daniels | 8dd4641 | 2019-04-16 20:47:54 +0000 | [diff] [blame] | 105 | if( errors ) { |
| 106 | fprintf( stderr, "<FAIL> mbuf_api tests failed\n" ); |
| 107 | } else { |
| 108 | fprintf( stderr, "<OK> mbuf_api tests pass\n" ); |
| 109 | } |
E. Scott Daniels | 85c5bf7 | 2019-05-29 13:38:43 +0000 | [diff] [blame] | 110 | |
E. Scott Daniels | 11838bc | 2021-04-22 16:34:08 -0400 | [diff] [blame] | 111 | return !! errors; |
E. Scott Daniels | 8dd4641 | 2019-04-16 20:47:54 +0000 | [diff] [blame] | 112 | } |