4 * Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 #include <rte_per_lcore.h>
40 #include <rte_errno.h>
41 #include <rte_string_fns.h>
48 const char *rte_retval;
49 const char *libc_retval;
50 #ifdef RTE_EXEC_ENV_BSDAPP
51 /* BSD has a colon in the string, unlike linux */
52 const char unknown_code_result[] = "Unknown error: %d";
54 const char unknown_code_result[] = "Unknown error %d";
56 char expected_libc_retval[sizeof(unknown_code_result)+3];
58 /* use a small selection of standard errors for testing */
59 int std_errs[] = {EAGAIN, EBADF, EACCES, EINTR, EINVAL};
60 /* test ALL registered RTE error codes for overlap */
61 int rte_errs[] = {E_RTE_SECONDARY, E_RTE_NO_CONFIG, E_RTE_NO_TAILQ};
67 /* check for standard errors we return the same as libc */
68 for (i = 0; i < sizeof(std_errs)/sizeof(std_errs[0]); i++){
69 rte_retval = rte_strerror(std_errs[i]);
70 libc_retval = strerror(std_errs[i]);
71 printf("rte_strerror: '%s', strerror: '%s'\n",
72 rte_retval, libc_retval);
73 if (strcmp(rte_retval, libc_retval) != 0)
76 /* for rte-specific errors ensure we return a different string
77 * and that the string for libc is for an unknown error
79 for (i = 0; i < sizeof(rte_errs)/sizeof(rte_errs[0]); i++){
80 rte_retval = rte_strerror(rte_errs[i]);
81 libc_retval = strerror(rte_errs[i]);
82 printf("rte_strerror: '%s', strerror: '%s'\n",
83 rte_retval, libc_retval);
84 if (strcmp(rte_retval, libc_retval) == 0)
86 /* generate appropriate error string for unknown error number
87 * and then check that this is what we got back. If not, we have
88 * a duplicate error number that conflicts with errno.h */
89 snprintf(expected_libc_retval, sizeof(expected_libc_retval),
90 unknown_code_result, rte_errs[i]);
91 if ((strcmp(expected_libc_retval, libc_retval) != 0) &&
92 (strcmp("", libc_retval) != 0)){
93 printf("Error, duplicate error code %d\n", rte_errs[i]);
98 /* ensure that beyond RTE_MAX_ERRNO, we always get an unknown code */
99 rte_retval = rte_strerror(RTE_MAX_ERRNO + 1);
100 libc_retval = strerror(RTE_MAX_ERRNO + 1);
101 snprintf(expected_libc_retval, sizeof(expected_libc_retval),
102 unknown_code_result, RTE_MAX_ERRNO + 1);
103 printf("rte_strerror: '%s', strerror: '%s'\n",
104 rte_retval, libc_retval);
105 if ((strcmp(rte_retval, libc_retval) != 0) ||
106 (strcmp(expected_libc_retval, libc_retval) != 0)){
107 if (strcmp("", libc_retval) != 0){
108 printf("Failed test for RTE_MAX_ERRNO + 1 value\n");
116 static struct test_command errno_cmd = {
117 .command = "errno_autotest",
118 .callback = test_errno,
120 REGISTER_TEST_COMMAND(errno_cmd);