2 * Copyright (c) 2019 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 <vlib/vlib.h>
17 #include <vlib/buffer_funcs.h>
19 #define TEST_I(_cond, _comment, _args...) \
21 int _evald = (_cond); \
23 fformat(stderr, "FAIL:%d: " _comment "\n", \
26 fformat(stderr, "PASS:%d: " _comment "\n", \
32 #define TEST(_cond, _comment, _args...) \
34 if (!TEST_I(_cond, _comment, ##_args)) { \
39 /* test function for a specific case where current_data is negative, verify
40 * that there is no crash */
42 linearize_negative_current_data (vlib_main_t * vm)
45 TEST (ARRAY_LEN (bi) == vlib_buffer_alloc (vm, bi, ARRAY_LEN (bi)),
47 u32 data_size = vlib_buffer_get_default_data_size (vm);
49 for (i = 0; i < ARRAY_LEN (bi) - 1; ++i)
51 vlib_buffer_t *b = vlib_get_buffer (vm, bi[i]);
52 b->next_buffer = bi[i + 1];
53 b->flags |= VLIB_BUFFER_NEXT_PRESENT;
54 b->current_data = -14;
55 b->current_length = 14 + data_size;
58 (void) vlib_buffer_chain_linearize (vm, vlib_get_buffer (vm, bi[0]));
64 test_linearize_fn (vlib_main_t * vm, unformat_input_t * input,
65 vlib_cli_command_t * cmd)
68 if (linearize_negative_current_data (vm))
70 return clib_error_return (0, "linearize_negative_current_data failed");
77 VLIB_CLI_COMMAND (test_linearize_command, static) =
79 .path = "test chained-buffer-linearization",
80 .short_help = "test chained-buffer-linearization",
81 .function = test_linearize_fn,
86 * fd.io coding-style-patch-verification: ON
89 * eval: (c-set-style "gnu")