Dave Barach | e9d9170 | 2017-11-29 16:59:01 -0500 | [diff] [blame] | 1 | /* |
| 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 | |
| 18 | clib_maplog_main_t maplog_main; |
| 19 | |
| 20 | typedef struct |
| 21 | { |
| 22 | u64 serial_number; |
| 23 | u64 junk[7]; |
| 24 | } test_entry_t; |
| 25 | |
Dave Barach | 04fee31 | 2017-12-01 16:20:32 -0500 | [diff] [blame] | 26 | static void |
| 27 | process_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 Barach | e9d9170 | 2017-11-29 16:59:01 -0500 | [diff] [blame] | 52 | int |
| 53 | test_maplog_main (unformat_input_t * input) |
| 54 | { |
| 55 | clib_maplog_main_t *mm = &maplog_main; |
Dave Barach | 04fee31 | 2017-12-01 16:20:32 -0500 | [diff] [blame] | 56 | clib_maplog_init_args_t _a, *a = &_a; |
Dave Barach | e9d9170 | 2017-11-29 16:59:01 -0500 | [diff] [blame] | 57 | int rv; |
| 58 | int i; |
| 59 | test_entry_t *t; |
| 60 | |
Dave Barach | 04fee31 | 2017-12-01 16:20:32 -0500 | [diff] [blame] | 61 | 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 Barach | e9d9170 | 2017-11-29 16:59:01 -0500 | [diff] [blame] | 72 | |
| 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 Barach | 04fee31 | 2017-12-01 16:20:32 -0500 | [diff] [blame] | 87 | clib_maplog_process ("/tmp/maplog_test", process_maplog_records); |
| 88 | |
Dave Barach | e9d9170 | 2017-11-29 16:59:01 -0500 | [diff] [blame] | 89 | return 0; |
| 90 | } |
| 91 | |
| 92 | #ifdef CLIB_UNIX |
| 93 | int |
| 94 | main (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 | */ |