1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation
10 #include <rte_per_lcore.h>
11 #include <rte_errno.h>
12 #include <rte_string_fns.h>
19 const char *rte_retval;
20 const char *libc_retval;
22 #ifndef RTE_EXEC_ENV_WINDOWS
23 #ifdef RTE_EXEC_ENV_FREEBSD
24 /* BSD has a colon in the string, unlike linux */
25 const char unknown_code_result[] = "Unknown error: %d";
27 const char unknown_code_result[] = "Unknown error %d";
29 char expected_libc_retval[sizeof(unknown_code_result) + 3];
31 /* Windows doesn't return error number for error greater than MAX_errno*/
32 static const char expected_libc_retval[] = "Unknown error";
35 /* use a small selection of standard errors for testing */
36 int std_errs[] = {EAGAIN, EBADF, EACCES, EINTR, EINVAL};
37 /* test ALL registered RTE error codes for overlap */
38 int rte_errs[] = {E_RTE_SECONDARY, E_RTE_NO_CONFIG};
44 /* check for standard errors we return the same as libc */
45 for (i = 0; i < RTE_DIM(std_errs); i++) {
46 rte_retval = rte_strerror(std_errs[i]);
47 libc_retval = strerror(std_errs[i]);
48 printf("rte_strerror: '%s', strerror: '%s'\n",
49 rte_retval, libc_retval);
50 if (strcmp(rte_retval, libc_retval) != 0)
53 /* for rte-specific errors ensure we return a different string
54 * and that the string for libc is for an unknown error
56 for (i = 0; i < RTE_DIM(rte_errs); i++) {
57 rte_retval = rte_strerror(rte_errs[i]);
58 libc_retval = strerror(rte_errs[i]);
59 printf("rte_strerror: '%s', strerror: '%s'\n",
60 rte_retval, libc_retval);
61 if (strcmp(rte_retval, libc_retval) == 0)
63 #ifndef RTE_EXEC_ENV_WINDOWS
64 /* generate appropriate error string for unknown error number
65 * and then check that this is what we got back. If not, we have
66 * a duplicate error number that conflicts with errno.h */
67 snprintf(expected_libc_retval, sizeof(expected_libc_retval),
68 unknown_code_result, rte_errs[i]);
70 if ((strcmp(expected_libc_retval, libc_retval) != 0) &&
71 (strcmp("", libc_retval) != 0)){
72 printf("Error, duplicate error code %d\n", rte_errs[i]);
77 /* ensure that beyond RTE_MAX_ERRNO, we always get an unknown code */
78 rte_retval = rte_strerror(RTE_MAX_ERRNO + 1);
79 libc_retval = strerror(RTE_MAX_ERRNO + 1);
80 #ifndef RTE_EXEC_ENV_WINDOWS
81 snprintf(expected_libc_retval, sizeof(expected_libc_retval),
82 unknown_code_result, RTE_MAX_ERRNO + 1);
84 printf("rte_strerror: '%s', strerror: '%s'\n",
85 rte_retval, libc_retval);
86 if ((strcmp(rte_retval, libc_retval) != 0) ||
87 (strcmp(expected_libc_retval, libc_retval) != 0)){
88 if (strcmp("", libc_retval) != 0){
89 printf("Failed test for RTE_MAX_ERRNO + 1 value\n");
97 REGISTER_TEST_COMMAND(errno_autotest, test_errno);