blob: 3afe47bbafcfe506c111c050d9fcca7e0d7facce [file] [log] [blame]
E. Scott Daniels0b79fc22019-12-04 15:20:16 -05001// : vi ts=4 sw=4 noet :
2/*
3==================================================================================
4 Copyright (c) 2019 Nokia
5 Copyright (c) 2018-2019 AT&T Intellectual Property.
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
11 http://www.apache.org/licenses/LICENSE-2.0
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 Mnemonic: test_gen_rt.c
23 Abstract: This provides the means to generate a route table to disk.
24 Author: E. Scott Daniels
25 Date: 6 January 2019
26*/
27
28#ifndef _test_gen_rt_c
29#define _test_gen_rt_c
30
31
32/*
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.
E. Scott Daniels05850e02020-11-11 15:57:22 -050040
41 Once the file is generated, it is forced in via static read and the file
42 is unlinked.
E. Scott Daniels0b79fc22019-12-04 15:20:16 -050043*/
44static void gen_rt( uta_ctx_t* ctx ) {
45 int fd;
46 char* rt_stuff; // strings for the route table
47
48 fd = open( "utesting.rt", O_WRONLY | O_CREAT, 0600 );
49 if( fd < 0 ) {
50 fprintf( stderr, "<BUGGERED> unable to open file for testing route table gen\n" );
51 return;
52 }
53
54 rt_stuff =
E. Scott Daniels8c6756d2021-04-19 15:13:51 -040055 "updatert|start\n" // update check before whole table received
56 "updatert|end\n"
E. Scott Daniels0b79fc22019-12-04 15:20:16 -050057 "newrt|end\n" // end of table check before start of table found
58 "# comment to drive full comment test\n"
59 "\n" // handle blank lines
60 " \n" // handle blank lines
61 "mse|4|10|localhost:4561\n" // entry before start message
62 "rte|4|localhost:4561\n" // entry before start message
63 "newrt|start\n" // false start to drive detection
64 "xxx|badentry to drive default case"
65 "newrt|start\n"
66 "rte|0|localhost:4560,localhost:4562\n" // these are legitimate entries for our testing
67 "rte|1|localhost:4562;localhost:4561,localhost:4569\n"
68 "rte|2|localhost:4562| 10\n" // new subid at end
69 "mse|4|10|localhost:4561\n" // new msg/subid specifier rec
70 "mse|4|localhost:4561\n" // new mse entry with less than needed fields
71 " rte| 5 |localhost:4563 #garbage comment\n" // tests white space cleanup
72 "rte|6|localhost:4562\n"
73 "newrt|end\n";
74
75 setenv( "RMR_SEED_RT", "utesting.rt", 1 );
76 write( fd, rt_stuff, strlen( rt_stuff ) ); // write in the whole table
77
78 rt_stuff = // add an meid map which will fail
79 "meid_map | start\n"
E. Scott Daniels05850e02020-11-11 15:57:22 -050080 "mme_ar | e2t-1 | one two three four\r" // also test bloody apple way with \r
E. Scott Daniels0b79fc22019-12-04 15:20:16 -050081 "mme_del | one two\n"
82 "mme_del \n" // short entries drive various checks for coverage
83 "mme_ar \n"
84 "mme_ar | e2t-0 \n"
85 "meid_map | end | 5\n"; // this will fail as the short recs don't "count"
86 write( fd, rt_stuff, strlen( rt_stuff ) );
87
88 rt_stuff =
89 "updatert|start\n" // this is an update to the table
90 "mse|4|99|fooapp:9999,barapp:9999;logger:9999\n" // update just one entry
91 "updatert|end | 3\n"; // bad count; this update should be rejected
92 write( fd, rt_stuff, strlen( rt_stuff ) );
93
94
95 rt_stuff =
96 "updatert|start\n" // this is an update to the table
97 "mse|4|10|fooapp:4561,barapp:4561;logger:9999\n" // update just one entry
98 "mse | 99 | -1 | %meid\n" // type 99 will route based on meid and not mtype
99 "del|2|-1\n" // delete an entry; not there so no action
100 "del|2|10\n" // delete an entry
101 "updatert|end | 4\n"; // end table; updates have a count as last field
102 write( fd, rt_stuff, strlen( rt_stuff ) );
103
104 rt_stuff = // this leaves an meid map in place too
105 "meid_map | start\n"
106 "mme_ar | localhost:4567 | meid1 meid2 meid3 meid4\n"
107 "mme_ar | localhost:4067 | meid11 meid12\n"
108 "meid_map | end | 2\n";
109 write( fd, rt_stuff, strlen( rt_stuff ) );
110
111 rt_stuff = // verify that we can del entries in the current table
112 "meid_map | start\n"
113 "mme_del | meid11 meid12 meid13\n" // includes a non-existant meid
114 "meid_map | end | 1\n";
115 write( fd, rt_stuff, strlen( rt_stuff ) );
116
117 close( fd );
118 read_static_rt( ctx, 1 ); // force in verbose mode to see stats on tty if failure
119 unlink( "utesting.rt" );
120}
121
122
123
124/*
125 Generate a custom route table file using the buffer passed in.
E. Scott Daniels05850e02020-11-11 15:57:22 -0500126 Then force it to be read into the current route table. The file
127 is unlinked when finished.
E. Scott Daniels0b79fc22019-12-04 15:20:16 -0500128*/
129static void gen_custom_rt( uta_ctx_t* ctx, char* buf ) {
130 int fd;
E. Scott Daniels0b79fc22019-12-04 15:20:16 -0500131
E. Scott Daniels05850e02020-11-11 15:57:22 -0500132 fd = open( "Xutesting.rt", O_WRONLY | O_CREAT, 0600 );
E. Scott Daniels0b79fc22019-12-04 15:20:16 -0500133 if( fd < 0 ) {
134 fprintf( stderr, "<BUGGERED> unable to open file for testing route table gen\n" );
135 return;
136 }
E. Scott Daniels05850e02020-11-11 15:57:22 -0500137 setenv( "RMR_SEED_RT", "Xutesting.rt", 1 );
E. Scott Daniels0b79fc22019-12-04 15:20:16 -0500138
E. Scott Daniels84423e62020-12-04 13:04:29 -0500139 fprintf( stderr, "<INFO> creating custom rt from buffer (%d bytes)\n", (int) strlen (buf ) );
E. Scott Daniels05850e02020-11-11 15:57:22 -0500140 if( write( fd, buf, strlen( buf ) ) != strlen( buf ) ) {
141 fprintf( stderr, "<BUGGERED> write failed: %s\n", strerror( errno ) );
142 }
E. Scott Daniels0b79fc22019-12-04 15:20:16 -0500143
144 close( fd );
145 read_static_rt( ctx, 1 ); // force in verbose mode to see stats on tty if failure
146 unlink( "utesting.rt" );
147}
148
149
150#endif