1 // : vi ts=4 sw=4 noet :
3 ==================================================================================
4 Copyright (c) 2019 Nokia
5 Copyright (c) 2018-2019 AT&T Intellectual Property.
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
11 http://www.apache.org/licenses/LICENSE-2.0
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 ==================================================================================
22 Mnemonic: test_gen_rt.c
23 Abstract: This provides the means to generate a route table to disk.
24 Author: E. Scott Daniels
28 #ifndef _test_gen_rt_c
29 #define _test_gen_rt_c
33 Generate a simple route table (for all but direct route table testing).
34 This gets tricky inasmuch as we generate two in one; first a whole table
35 and then two update tables. The first is a table with a bad counter in the
36 last record to test that we don't load that table and error. The second
37 is a good update. The same applies to the meid map; first has a bad counter
38 and some bad records to drive coverage testing. The end should leave a good
39 meid map in the table.
41 static void gen_rt( uta_ctx_t* ctx ) {
43 char* rt_stuff; // strings for the route table
45 fd = open( "utesting.rt", O_WRONLY | O_CREAT, 0600 );
47 fprintf( stderr, "<BUGGERED> unable to open file for testing route table gen\n" );
52 "newrt|end\n" // end of table check before start of table found
53 "# comment to drive full comment test\n"
54 "\n" // handle blank lines
55 " \n" // handle blank lines
56 "mse|4|10|localhost:4561\n" // entry before start message
57 "rte|4|localhost:4561\n" // entry before start message
58 "newrt|start\n" // false start to drive detection
59 "xxx|badentry to drive default case"
61 "rte|0|localhost:4560,localhost:4562\n" // these are legitimate entries for our testing
62 "rte|1|localhost:4562;localhost:4561,localhost:4569\n"
63 "rte|2|localhost:4562| 10\n" // new subid at end
64 "mse|4|10|localhost:4561\n" // new msg/subid specifier rec
65 "mse|4|localhost:4561\n" // new mse entry with less than needed fields
66 " rte| 5 |localhost:4563 #garbage comment\n" // tests white space cleanup
67 "rte|6|localhost:4562\n"
70 setenv( "RMR_SEED_RT", "utesting.rt", 1 );
71 write( fd, rt_stuff, strlen( rt_stuff ) ); // write in the whole table
73 rt_stuff = // add an meid map which will fail
75 "mme_ar | e2t-1 | one two three four\n"
77 "mme_del \n" // short entries drive various checks for coverage
80 "meid_map | end | 5\n"; // this will fail as the short recs don't "count"
81 write( fd, rt_stuff, strlen( rt_stuff ) );
84 "updatert|start\n" // this is an update to the table
85 "mse|4|99|fooapp:9999,barapp:9999;logger:9999\n" // update just one entry
86 "updatert|end | 3\n"; // bad count; this update should be rejected
87 write( fd, rt_stuff, strlen( rt_stuff ) );
91 "updatert|start\n" // this is an update to the table
92 "mse|4|10|fooapp:4561,barapp:4561;logger:9999\n" // update just one entry
93 "mse | 99 | -1 | %meid\n" // type 99 will route based on meid and not mtype
94 "del|2|-1\n" // delete an entry; not there so no action
95 "del|2|10\n" // delete an entry
96 "updatert|end | 4\n"; // end table; updates have a count as last field
97 write( fd, rt_stuff, strlen( rt_stuff ) );
99 rt_stuff = // this leaves an meid map in place too
101 "mme_ar | localhost:4567 | meid1 meid2 meid3 meid4\n"
102 "mme_ar | localhost:4067 | meid11 meid12\n"
103 "meid_map | end | 2\n";
104 write( fd, rt_stuff, strlen( rt_stuff ) );
106 rt_stuff = // verify that we can del entries in the current table
108 "mme_del | meid11 meid12 meid13\n" // includes a non-existant meid
109 "meid_map | end | 1\n";
110 write( fd, rt_stuff, strlen( rt_stuff ) );
113 read_static_rt( ctx, 1 ); // force in verbose mode to see stats on tty if failure
114 unlink( "utesting.rt" );
120 Generate a custom route table file using the buffer passed in.
122 static void gen_custom_rt( uta_ctx_t* ctx, char* buf ) {
124 char* rt_stuff; // strings for the route table
126 fd = open( "utesting.rt", O_WRONLY | O_CREAT, 0600 );
128 fprintf( stderr, "<BUGGERED> unable to open file for testing route table gen\n" );
131 setenv( "RMR_SEED_RT", "utesting.rt", 1 );
133 write( fd, rt_stuff, strlen( buf ) );
136 read_static_rt( ctx, 1 ); // force in verbose mode to see stats on tty if failure
137 unlink( "utesting.rt" );