Dave Barach | e5389bb | 2016-03-28 17:12:19 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2016 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 <vlib/vlib.h> |
| 17 | #include <vppinfra/elog.h> |
| 18 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 19 | static inline void |
| 20 | elog_four_int_sample (u32 * data) |
Dave Barach | e5389bb | 2016-03-28 17:12:19 -0400 | [diff] [blame] | 21 | { |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 22 | ELOG_TYPE_DECLARE (e) = |
| 23 | { |
| 24 | .format = "four int: first %d second %d third %d fourth %d",.format_args = |
| 25 | "i4i4i4i4",}; |
| 26 | struct |
| 27 | { |
| 28 | u32 data[4]; |
| 29 | } *ed; |
Dave Barach | e5389bb | 2016-03-28 17:12:19 -0400 | [diff] [blame] | 30 | ed = ELOG_DATA (&vlib_global_main.elog_main, e); |
| 31 | ed->data[0] = data[0]; |
| 32 | ed->data[1] = data[1]; |
| 33 | ed->data[2] = data[2]; |
| 34 | ed->data[3] = data[3]; |
| 35 | } |
| 36 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 37 | static inline void |
| 38 | elog_four_int_track_sample (u32 * data) |
Dave Barach | e5389bb | 2016-03-28 17:12:19 -0400 | [diff] [blame] | 39 | { |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 40 | ELOG_TYPE_DECLARE (e) = |
| 41 | { |
| 42 | .format = |
| 43 | "four_int_track: first %d second %d third %d fourth %d",.format_args = |
| 44 | "i4i4i4i4",}; |
| 45 | struct |
| 46 | { |
| 47 | u32 data[4]; |
| 48 | } *ed; |
| 49 | ELOG_TRACK (sample_track); |
Dave Barach | e5389bb | 2016-03-28 17:12:19 -0400 | [diff] [blame] | 50 | ed = ELOG_TRACK_DATA (&vlib_global_main.elog_main, e, sample_track); |
| 51 | ed->data[0] = data[0]; |
| 52 | ed->data[1] = data[1]; |
| 53 | ed->data[2] = data[2]; |
| 54 | ed->data[3] = data[3]; |
| 55 | } |
| 56 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 57 | static inline void |
| 58 | elog_enum_sample (u8 which) |
Dave Barach | e5389bb | 2016-03-28 17:12:19 -0400 | [diff] [blame] | 59 | { |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 60 | ELOG_TYPE_DECLARE (e) = |
| 61 | { |
| 62 | .format = "my enum: %s",.format_args = "t1",.n_enum_strings = |
| 63 | 2,.enum_strings = |
Dave Barach | e5389bb | 2016-03-28 17:12:19 -0400 | [diff] [blame] | 64 | { |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 65 | "string 1", "string 2",},}; |
| 66 | struct |
| 67 | { |
| 68 | u8 which; |
| 69 | } *ed; |
Dave Barach | e5389bb | 2016-03-28 17:12:19 -0400 | [diff] [blame] | 70 | ed = ELOG_DATA (&vlib_global_main.elog_main, e); |
| 71 | ed->which = which; |
| 72 | } |
| 73 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 74 | static inline void |
| 75 | elog_one_datum_sample (u32 data) |
Dave Barach | e5389bb | 2016-03-28 17:12:19 -0400 | [diff] [blame] | 76 | { |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 77 | ELOG_TYPE_DECLARE (e) = |
| 78 | { |
| 79 | .format = "one datum: %d",.format_args = "i4",}; |
| 80 | |
Dave Barach | e5389bb | 2016-03-28 17:12:19 -0400 | [diff] [blame] | 81 | elog (&vlib_global_main.elog_main, &e, data); |
| 82 | } |
| 83 | |
| 84 | static clib_error_t * |
| 85 | test_elog_command_fn (vlib_main_t * vm, |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 86 | unformat_input_t * input, vlib_cli_command_t * cmd) |
Dave Barach | e5389bb | 2016-03-28 17:12:19 -0400 | [diff] [blame] | 87 | { |
| 88 | int i; |
| 89 | u32 samples[4]; |
| 90 | |
| 91 | for (i = 0; i < 10; i++) |
| 92 | { |
| 93 | samples[0] = i; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 94 | samples[1] = i + 1; |
| 95 | samples[2] = i + 2; |
| 96 | samples[3] = i + 3; |
Dave Barach | e5389bb | 2016-03-28 17:12:19 -0400 | [diff] [blame] | 97 | |
| 98 | elog_four_int_sample (samples); |
| 99 | elog_four_int_track_sample (samples); |
| 100 | elog_enum_sample (0); |
| 101 | elog_enum_sample (1); |
| 102 | elog_one_datum_sample (i); |
| 103 | } |
| 104 | |
| 105 | return 0; |
| 106 | } |
| 107 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 108 | /* *INDENT-OFF* */ |
Dave Barach | e5389bb | 2016-03-28 17:12:19 -0400 | [diff] [blame] | 109 | VLIB_CLI_COMMAND (test_elog_command, static) = { |
| 110 | .path = "test elog sample", |
| 111 | .short_help = "test elog sample", |
| 112 | .function = test_elog_command_fn, |
| 113 | }; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 114 | /* *INDENT-ON* */ |
| 115 | |
| 116 | /* |
| 117 | * fd.io coding-style-patch-verification: ON |
| 118 | * |
| 119 | * Local Variables: |
| 120 | * eval: (c-set-style "gnu") |
| 121 | * End: |
| 122 | */ |