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;
33 process_maplog_records (clib_maplog_header_t * h,
34 test_entry_t * e, u64 records_this_file)
36 static int print_header;
39 if (print_header == 0)
42 fformat (stdout, "%U", format_maplog_header, h, 1 /* verbose */ );
45 while (records_this_file--)
47 /* Padding at the end of a damaged log? */
48 if (e->serial_number == 0ULL)
50 fformat (stdout, "%4lld ", e->serial_number);
53 fformat (stdout, "\n");
58 fformat (stdout, "\n--------------\n");
62 test_maplog_main (unformat_input_t * input)
64 clib_maplog_main_t *mm = &maplog_main;
65 clib_maplog_init_args_t _a, *a = &_a;
70 test_type_t which = TEST_NORMAL;
72 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
74 if (unformat (input, "noclose"))
76 else if (unformat (input, "circular"))
77 which = TEST_CIRCULAR;
79 clib_warning ("unknown input '%U'", format_unformat_error, input);
82 memset (a, 0, sizeof (*a));
84 a->file_basename = "/tmp/maplog_test";
85 a->file_size_in_bytes = 4096;
86 a->record_size_in_bytes = sizeof (test_entry_t);
87 a->application_id = 1;
88 a->application_major_version = 1;
89 a->application_minor_version = 0;
90 a->application_patch_version = 0;
91 a->maplog_is_circular = (which == TEST_CIRCULAR) ? 1 : 0;
93 rv = clib_maplog_init (a);
97 clib_warning ("clib_maplog_init returned %d", rv);
101 limit = (which == TEST_CIRCULAR) ? (64 + 2) : 64 * 5;
103 for (i = 0; i < limit; i++)
105 t = clib_maplog_get_entry (mm);
106 t->serial_number = i + 1;
110 memset (mm, 0, sizeof (*mm));
112 clib_maplog_close (mm);
114 clib_maplog_process ("/tmp/maplog_test", process_maplog_records);
121 main (int argc, char *argv[])
126 unformat_init_command_line (&i, argv);
127 ret = test_maplog_main (&i);
132 #endif /* CLIB_UNIX */
136 * fd.io coding-style-patch-verification: ON
139 * eval: (c-set-style "gnu")