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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #include <vppinfra/maplog.h>
18 clib_maplog_main_t maplog_main;
27 process_maplog_records (clib_maplog_header_t * h,
28 test_entry_t * e, u64 records_this_file)
30 static int print_header;
33 if (print_header == 0)
36 fformat (stdout, "%U", format_maplog_header, h, 1 /* verbose */ );
39 while (records_this_file--)
41 /* Padding at the end of a damaged log? */
42 if (e->serial_number == 0ULL)
44 fformat (stdout, "%4lld ", e->serial_number);
47 fformat (stdout, "\n");
52 fformat (stdout, "--------------\n");
56 test_maplog_main (unformat_input_t * input)
58 clib_maplog_main_t *mm = &maplog_main;
59 clib_maplog_init_args_t _a, *a = &_a;
65 if (unformat (input, "noclose"))
68 memset (a, 0, sizeof (*a));
70 a->file_basename = "/tmp/maplog_test";
71 a->file_size_in_bytes = 4096;
72 a->record_size_in_bytes = sizeof (test_entry_t);
73 a->application_id = 1;
74 a->application_major_version = 1;
75 a->application_minor_version = 0;
76 a->application_patch_version = 0;
78 rv = clib_maplog_init (a);
82 clib_warning ("clib_maplog_init returned %d", rv);
86 for (i = 0; i < 64 * 5; i++)
88 t = clib_maplog_get_entry (mm);
89 t->serial_number = i + 1;
93 memset (mm, 0, sizeof (*mm));
95 clib_maplog_close (mm);
97 clib_maplog_process ("/tmp/maplog_test", process_maplog_records);
104 main (int argc, char *argv[])
109 unformat_init_command_line (&i, argv);
110 ret = test_maplog_main (&i);
115 #endif /* CLIB_UNIX */
119 * fd.io coding-style-patch-verification: ON
122 * eval: (c-set-style "gnu")