blob: c49ebd6885e5deee0be566ee1194e8aac42d0030 [file] [log] [blame]
Dave Barache9d91702017-11-29 16:59:01 -05001/*
2 * Copyright (c) 2017 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14*/
15
16#include <vppinfra/maplog.h>
17
18clib_maplog_main_t maplog_main;
19
20typedef struct
21{
22 u64 serial_number;
23 u64 junk[7];
24} test_entry_t;
25
Dave Barach04fee312017-12-01 16:20:32 -050026static void
27process_maplog_records (clib_maplog_header_t * h,
28 test_entry_t * e, u64 records_this_file)
29{
30 static int print_header;
31 int i = 0;
32
33 if (print_header == 0)
34 {
35 print_header = 1;
36 fformat (stdout, "%U", format_maplog_header, h, 1 /* verbose */ );
37 }
38
39 while (records_this_file--)
40 {
41 fformat (stdout, "%4lld ", e->serial_number);
42 if (++i == 8)
43 {
44 fformat (stdout, "\n");
45 i = 0;
46 }
47 e++;
48 }
49 fformat (stdout, "--------------\n");
50}
51
Dave Barache9d91702017-11-29 16:59:01 -050052int
53test_maplog_main (unformat_input_t * input)
54{
55 clib_maplog_main_t *mm = &maplog_main;
Dave Barach04fee312017-12-01 16:20:32 -050056 clib_maplog_init_args_t _a, *a = &_a;
Dave Barache9d91702017-11-29 16:59:01 -050057 int rv;
58 int i;
59 test_entry_t *t;
60
Dave Barach04fee312017-12-01 16:20:32 -050061 memset (a, 0, sizeof (*a));
62 a->mm = mm;
63 a->file_basename = "/tmp/maplog_test";
64 a->file_size_in_bytes = 4096;
65 a->record_size_in_bytes = sizeof (test_entry_t);
66 a->application_id = 1;
67 a->application_major_version = 1;
68 a->application_minor_version = 0;
69 a->application_patch_version = 0;
70
71 rv = clib_maplog_init (a);
Dave Barache9d91702017-11-29 16:59:01 -050072
73 if (rv)
74 {
75 clib_warning ("clib_maplog_init returned %d", rv);
76 exit (1);
77 }
78
79 for (i = 0; i < 64 * 5; i++)
80 {
81 t = clib_maplog_get_entry (mm);
82 t->serial_number = i;
83 }
84
85 clib_maplog_close (mm);
86
Dave Barach04fee312017-12-01 16:20:32 -050087 clib_maplog_process ("/tmp/maplog_test", process_maplog_records);
88
Dave Barache9d91702017-11-29 16:59:01 -050089 return 0;
90}
91
92#ifdef CLIB_UNIX
93int
94main (int argc, char *argv[])
95{
96 unformat_input_t i;
97 int ret;
98
99 unformat_init_command_line (&i, argv);
100 ret = test_maplog_main (&i);
101 unformat_free (&i);
102
103 return ret;
104}
105#endif /* CLIB_UNIX */
106
107
108/*
109 * fd.io coding-style-patch-verification: ON
110 *
111 * Local Variables:
112 * eval: (c-set-style "gnu")
113 * End:
114 */