]>
git.proxmox.com Git - ceph.git/blob - ceph/src/seastar/dpdk/app/test/test_errno.c
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
;
21 #ifdef RTE_EXEC_ENV_FREEBSD
22 /* BSD has a colon in the string, unlike linux */
23 const char unknown_code_result
[] = "Unknown error: %d";
25 const char unknown_code_result
[] = "Unknown error %d";
27 char expected_libc_retval
[sizeof(unknown_code_result
)+3];
29 /* use a small selection of standard errors for testing */
30 int std_errs
[] = {EAGAIN
, EBADF
, EACCES
, EINTR
, EINVAL
};
31 /* test ALL registered RTE error codes for overlap */
32 int rte_errs
[] = {E_RTE_SECONDARY
, E_RTE_NO_CONFIG
};
38 /* check for standard errors we return the same as libc */
39 for (i
= 0; i
< sizeof(std_errs
)/sizeof(std_errs
[0]); i
++){
40 rte_retval
= rte_strerror(std_errs
[i
]);
41 libc_retval
= strerror(std_errs
[i
]);
42 printf("rte_strerror: '%s', strerror: '%s'\n",
43 rte_retval
, libc_retval
);
44 if (strcmp(rte_retval
, libc_retval
) != 0)
47 /* for rte-specific errors ensure we return a different string
48 * and that the string for libc is for an unknown error
50 for (i
= 0; i
< sizeof(rte_errs
)/sizeof(rte_errs
[0]); i
++){
51 rte_retval
= rte_strerror(rte_errs
[i
]);
52 libc_retval
= strerror(rte_errs
[i
]);
53 printf("rte_strerror: '%s', strerror: '%s'\n",
54 rte_retval
, libc_retval
);
55 if (strcmp(rte_retval
, libc_retval
) == 0)
57 /* generate appropriate error string for unknown error number
58 * and then check that this is what we got back. If not, we have
59 * a duplicate error number that conflicts with errno.h */
60 snprintf(expected_libc_retval
, sizeof(expected_libc_retval
),
61 unknown_code_result
, rte_errs
[i
]);
62 if ((strcmp(expected_libc_retval
, libc_retval
) != 0) &&
63 (strcmp("", libc_retval
) != 0)){
64 printf("Error, duplicate error code %d\n", rte_errs
[i
]);
69 /* ensure that beyond RTE_MAX_ERRNO, we always get an unknown code */
70 rte_retval
= rte_strerror(RTE_MAX_ERRNO
+ 1);
71 libc_retval
= strerror(RTE_MAX_ERRNO
+ 1);
72 snprintf(expected_libc_retval
, sizeof(expected_libc_retval
),
73 unknown_code_result
, RTE_MAX_ERRNO
+ 1);
74 printf("rte_strerror: '%s', strerror: '%s'\n",
75 rte_retval
, libc_retval
);
76 if ((strcmp(rte_retval
, libc_retval
) != 0) ||
77 (strcmp(expected_libc_retval
, libc_retval
) != 0)){
78 if (strcmp("", libc_retval
) != 0){
79 printf("Failed test for RTE_MAX_ERRNO + 1 value\n");
87 REGISTER_TEST_COMMAND(errno_autotest
, test_errno
);