blob: ac73976be7cda4a79549a269d30d9d874a14cc27 [file] [log] [blame]
E. Scott Daniels8dd46412019-04-16 20:47:54 +00001// : vi ts=4 sw=4 noet :
2/*
3==================================================================================
E. Scott Daniels8790bf02019-04-23 12:59:28 +00004 Copyright (c) 2019 Nokia
5 Copyright (c) 2018-2019 AT&T Intellectual Property.
E. Scott Daniels8dd46412019-04-16 20:47:54 +00006
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 Daniels8790bf02019-04-23 12:59:28 +000011 http://www.apache.org/licenses/LICENSE-2.0
E. Scott Daniels8dd46412019-04-16 20:47:54 +000012
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 Danielsd7109572019-04-18 14:01:16 +000025 To allow the mbuf functions to be tested without the bulk of the
E. Scott Daniels8790bf02019-04-23 12:59:28 +000026 RMr mechanics, we dummy up a couple of functions that are in
27 rmr[_nng].c.
E. Scott Danielsd7109572019-04-18 14:01:16 +000028
E. Scott Daniels8dd46412019-04-16 20:47:54 +000029 Author: E. Scott Daniels
30 Date: 2 April 2019
31*/
32
33
E. Scott Danielsfc5c77b2020-02-21 13:24:29 -050034#define NO_EMULATION
35
E. Scott Daniels8dd46412019-04-16 20:47:54 +000036#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 Daniels412d53d2019-05-20 20:00:52 +000044#include <pthread.h>
45#include <semaphore.h>
E. Scott Daniels8dd46412019-04-16 20:47:54 +000046
47
E. Scott Daniels412d53d2019-05-20 20:00:52 +000048#include "rmr.h"
49#include "rmr_agnostic.h"
E. Scott Daniels8dd46412019-04-16 20:47:54 +000050
E. Scott Daniels412d53d2019-05-20 20:00:52 +000051#include "mbuf_api.c"
E. Scott Daniels8dd46412019-04-16 20:47:54 +000052
E. Scott Daniels68d09fa2019-06-03 19:45:12 +000053#define MSG_VER 3
E. Scott Daniels8dd46412019-04-16 20:47:54 +000054#include "test_support.c" // our private library of test tools
55#include "mbuf_api_static_test.c" // test functions
56
E. Scott Danielsd7109572019-04-18 14:01:16 +000057// --- dummies -------------------------------------------------------------------
58
59/*
60 This will leak, but we're not here to test free.
61*/
62extern void rmr_free_msg( rmr_mbuf_t* mbuf ) {
63 return;
64}
65
66/*
67 Minimal buffer realloc to allow api to be tested without coverage hit if
68 we actually pulled in the sr static set.
69
70 WARNING: this is NOT a complete realloc. We assume that we are testing
E. Scott Daniels8790bf02019-04-23 12:59:28 +000071 just the trace length adjustment portion of the set_trace()
E. Scott Danielsd7109572019-04-18 14:01:16 +000072 API and are not striving to test the real realloc function. That
73 will be tested when the mbuf_api_static_test code is used by the
74 more generic RMr test. So, not all fields in the realloc'd buffer
75 can be used.
76*/
77extern rmr_mbuf_t* rmr_realloc_msg( rmr_mbuf_t* msg, int new_tr_size ) {
78 rmr_mbuf_t* new_msg;
79 uta_mhdr_t* hdr;
80
81 new_msg = (rmr_mbuf_t *) malloc( sizeof *new_msg );
82 new_msg->tp_buf = (void *) malloc( 2048 );
83 memset( new_msg->tp_buf, 0, 2048 );
84 hdr = (uta_mhdr_t*) new_msg->tp_buf;
85 SET_HDR_LEN( hdr );
86 SET_HDR_TR_LEN( hdr, new_tr_size );
87
88 new_msg->payload = new_msg->tp_buf + new_tr_size;
89 new_msg->header = new_msg->tp_buf;
90 new_msg->alloc_len = 2048;
91 new_msg->len = msg->len;
E. Scott Daniels5efb1e62019-05-02 17:09:35 +000092
E. Scott Danielsd7109572019-04-18 14:01:16 +000093 return new_msg;
94}
95
96// --------------------------------------------------------------------------------
97
E. Scott Daniels8dd46412019-04-16 20:47:54 +000098int main( ) {
99 int errors = 0;
100
101 errors += mbuf_api_test( );
102
E. Scott Daniels77526eb2020-09-17 16:39:31 -0400103 test_summary( errors, "mbuf API tests" );
E. Scott Daniels8dd46412019-04-16 20:47:54 +0000104 if( errors ) {
105 fprintf( stderr, "<FAIL> mbuf_api tests failed\n" );
106 } else {
107 fprintf( stderr, "<OK> mbuf_api tests pass\n" );
108 }
E. Scott Daniels85c5bf72019-05-29 13:38:43 +0000109
110 return errors;
E. Scott Daniels8dd46412019-04-16 20:47:54 +0000111}