X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=src%2Fsidecars%2Flistener%2Funit_test.c;fp=src%2Fsidecars%2Flistener%2Funit_test.c;h=79bc43fd409c3990f1ce2db5bb8f3903d4171758;hb=5f75c08e01fa73a8f54dd0d474c0a50b8dd23845;hp=0000000000000000000000000000000000000000;hpb=59f84608ec15c016958a6e0e0ddd813f376c0925;p=ric-app%2Fmc.git diff --git a/src/sidecars/listener/unit_test.c b/src/sidecars/listener/unit_test.c new file mode 100644 index 0000000..79bc43f --- /dev/null +++ b/src/sidecars/listener/unit_test.c @@ -0,0 +1,77 @@ +// vim: ts=4 sw=4 noet: +/* + -------------------------------------------------------------------------------- + Copyright (c) 2018-2019 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. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + -------------------------------------------------------------------------------- +*/ + +/* + Mnemonic: unit_test.c + Abstract: Basic unit tests for the mc listener. + Date: 22 August 2019 + Author: E. Scott Daniels +*/ + +// this/these are what we are testing; include them directly +#include "mcl.c" + +/* + Parms: [fifo-dir-name] +*/ +int main( int argc, char** argv ) { + void* ctx; + int errors; + char* dname = "/tmp/fifos"; + char* port = "4560"; + int fd; + int fd2; + + if( argc > 1 ) { + dname = argv[1]; + } + + ctx = mcl_mk_context( dname ); + if( ctx == NULL ) { + fprintf( stderr, "[FAIL] couldn't make context" ); + exit( 1 ); + } + + mcl_set_sigh(); // prevent colobber from broken pipe + + fd = suss_fifo( ctx, 101, 1 ); // should open the file for writing and return the fdes + if( fd < 0 ) { + fprintf( stderr, "[FAIL] suss_fifo did not return a valid fd\n" ); + errors++; + } + + fd2= suss_fifo( ctx, 101, 0 ); // should open the file file for reading and return a different fd + if( fd < 0 ) { + fprintf( stderr, "[FAIL] suss_fifo did not return a valid fd\n" ); + errors++; + } + if( fd == fd2 ) { + fprintf( stderr, "[FAIL] reading and writing fifo file descriptors expected to differ; both were %d\n", fd ); + errors++; + } + + mcl_start_listening( ctx, port, 0 ); // start the listener, no waiting for rt since we don't send + + if( ! errors ) { + fprintf( stderr, "[PASS] all tests look peachy\n" ); + } + + return errors != 0; +} +