2 * Copyright (c) 2018 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.
15 #include <vlib/vlib.h>
16 #include <vppinfra/string.h>
19 test_clib_memset (vlib_main_t * vm, unformat_input_t * input)
25 vlib_cli_output (vm, "Test memset_s...");
27 err = memset_s (dst, ARRAY_LEN (dst), 0xfe, ARRAY_LEN (dst));
32 for (i = 0; i < ARRAY_LEN (dst); i++)
36 err = memset_s (dst, ARRAY_LEN (dst), 0xfa, ARRAY_LEN (dst) + 1);
45 test_memcpy (vlib_main_t * vm, unformat_input_t * input)
47 char src[64], dst[64];
51 vlib_cli_output (vm, "Test memcpy_s...");
53 for (i = 0; i < ARRAY_LEN (src); i++)
57 err = memcpy_s (dst, sizeof (dst), src, sizeof (src));
62 /* This better not fail but check anyhow */
63 for (i = 0; i < ARRAY_LEN (dst); i++)
68 err = memcpy_s (dst + 1, sizeof (dst) - 1, src, sizeof (src));
74 err = memcpy_s (dst, sizeof (dst), dst + 1, sizeof (dst) - 1);
79 /* Zero length copy */
80 err = memcpy_s (0, sizeof (dst), src, 0);
85 /* OK, seems to work */
90 string_test_command_fn (vlib_main_t * vm,
91 unformat_input_t * input,
92 vlib_cli_command_t * cmd_arg)
99 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
101 if (unformat (input, "memcpy_s"))
103 else if (unformat (input, "memset_s"))
108 specific_test = t_memcpy + t_clib_memset;
110 if (specific_test == 0)
112 res = test_memcpy (vm, input);
113 res += test_clib_memset (vm, input);
118 res = test_memcpy (vm, input);
119 else if (t_clib_memset)
120 res = test_clib_memset (vm, input);
124 vlib_cli_output (vm, "String unit test(s) failed...");
126 vlib_cli_output (vm, "String unit test(s) OK...");
131 VLIB_CLI_COMMAND (string_test_command, static) =
133 .path = "test string",
134 .short_help = "string library tests",
135 .function = string_test_command_fn,
140 * fd.io coding-style-patch-verification: ON
143 * eval: (c-set-style "gnu")