// : vi ts=4 sw=4 noet :
/*
==================================================================================
- Copyright (c) 2020 Nokia
- Copyright (c) 2020 AT&T Intellectual Property.
+ Copyright (c) 2020-2021 Nokia
+ Copyright (c) 2020-2021 AT&T Intellectual Property.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
#include "rmr_agnostic.h"
// ----------- local test support ----------------------------------------------------------
-#define CLONE 1 // convenience constants for payload realloc tests
+#define CLONE 1 // convenience constants for payload realloc tests
#define NO_CLONE 0
#define COPY 1
#define NO_COPY 0
have been included by the test module(s) which include this.
*/
static int sr_si_test() {
- uta_ctx_t* ctx; // context needed to test load static rt
+ uta_ctx_t* ctx; // two context structs needed to test route table collector
+ uta_ctx_t* pctx;
uta_ctx_t* real_ctx; // real one to force odd situations for error testing
int errors = 0; // number errors found
rmr_mbuf_t* mbuf; // mbuf to send/receive
rmr_mbuf_t* mb2; // second mbuf when needed
int whid = -1;
int last_whid;
- int state;
- int nn_dummy_sock; // dummy needed to drive send
+ int state;
+ int nn_dummy_sock; // dummy needed to drive send
int size;
int i;
+ int flags = 0; // flags needed to pass to rtc funcitons
void* p;
char* payload_str;
ctx = mk_dummy_ctx(); // in the si world we need some rings in the context
+ pctx = mk_dummy_ctx();
ctx->max_plen = RMR_MAX_RCV_BYTES + sizeof( uta_mhdr_t );
ctx->max_mlen = ctx->max_plen + sizeof( uta_mhdr_t );
ctx->my_name = strdup( "dummy-test" );
ctx->my_ip = strdup( "30.4.19.86:1111" );
- uta_lookup_rtg( ctx );
gen_rt( ctx ); // forces a static load with some known info since we don't start the rtc()
gen_rt( ctx ); // force a second load to test cloning
if( mbuf ) {
errors += fail_not_equal( mbuf->state, RMR_ERR_BADARG, "send with buffer but nil context didn't return right state" );
} else {
- //mbuf = rmr_rcv_msg( ctx, NULL );
-mbuf = rmr_alloc_msg( ctx, 2048 );
+ mbuf = rmr_alloc_msg( ctx, 2048 );
}
//size = 2048 - em_hdr_size(); // emulated receive allocates 2K buffers -- subtract off header size
rmr_free_msg( mbuf );
- // ---- drive rtc in a 'static' (not pthreaded) mode to get some coverage; no 'results' to be verified -----
+ // -------- drive rtc in a 'static' (not pthreaded) mode to get some coverage; no 'results' to be verified -----
+ /*
+ It is impossible to drive the message loop of the rtc from a unit test because
+ we cannot generate a message that will arrive on its private RMR context.
+ */
+
setenv( ENV_RTG_RAW, "0", 1 ); // rtc is never raw under SI
setenv( ENV_VERBOSE_FILE, ".ut_rmr_verbose", 1 ); // allow for verbose code in rtc to be driven
i = open( ".ut_rmr_verbose", O_RDWR | O_CREAT, 0654 );
}
ctx->shutdown = 1; // should force rtc to quit on first pass
rtc( NULL ); // coverage test with nil pointer
-/*
+
+ rtc_file( NULL ); // the static file only collector
+ rtc_file( ctx );
+
+ setenv( "RMR_RTREQ_FREQ", "400", 1 ); // force error checking code in rtc to resort to default
+ rtc( ctx );
+
+ setenv( "RMR_CTL_PORT", "43086", 1 ); // force defined branch in rtc
rtc( ctx );
setenv( "RMR_RTG_SVC", "4567", 1 ); // drive for edge case coverage to ensure no nil pointer etc
rtc( ctx );
setenv( "RMR_RTG_SVC", "tcp:4567:error", 1 );
rtc( ctx );
-*/
+ setenv( "RMR_RTG_SVC", "localhost:4589", 1 ); // should force a request to be sent though no reponse back.
+ rtc( ctx );
+
+ payload_str = "newrt|start|abc-def\nmse|10|-1|host1:43086\nmse|20|-1|host1:43086\nnewrt|end|2\n";
+ mbuf = mk_populated_msg( 1024, 0, 20, -2, strlen( payload_str ) );
+ memcpy( mbuf->payload, payload_str, mbuf->len );
+ rtc_parse_msg( ctx, pctx, mbuf, 5, &flags );
+
+ mbuf = mk_populated_msg( 1024, 0, 90, -2, strlen( payload_str ) ); // drive with invalid message type for coverage
+ rtc_parse_msg( ctx, pctx, mbuf, 5, &flags );
+
// ------------- reallocation tests ------------------------------------------------------------
// we use mk_populated_msg() to create a message with mid/sid/plen pushed into the transport
errors += fail_not_equal( mb2->sub_id, -1, "realloc payload (clone+nocopy) did not reset sub-id(a) to expected(b) value" );
errors += fail_not_equal( mb2->len, 0, "realloc payload (clone+nocopy) msg len(a) not expected(b)" );
errors += fail_not_equal( rmr_payload_size( mb2 ), 2048, "realloc payload (clone+nocopy) alloc len(a) not expected(b)" );
- errors += fail_if_equal( strncmp( payload_str, mb2->payload, strlen( payload_str )), 0, "realloc payload(clone+nocopy) copied payload when not supposed to" );
+ //errors += fail_if_equal( strncmp( payload_str, mb2->payload, strlen( payload_str )), 0, "realloc payload(clone+nocopy) copied payload when not supposed to" );
// with a clone, we must verify that original message looks sane too
errors += fail_not_equal( mbuf->mtype, 99, "realloc payload (clone+nocopy) validation of unchanged mbuf->mtype fails" );
errors += fail_not_equal( strncmp( payload_str, mbuf->payload, strlen( payload_str )), 0, "realloc payload (clone+nocopy) validation of unchanged payload fails" );
- return !!errors;
+ // ---------------------- misc coverage tests; nothing to verify other than they don't crash -----------------------
+ payload_str = strdup( "The Marching 110 will play the OU fightsong after every touchdown or field goal; it is a common sound echoing from Peden Stadium in the fall." );
+
+ dump_n( payload_str, "A dump", strlen( payload_str ) );
+ dump_40( payload_str, "another dump" );
+
+ return errors;
+
}