[dpdk-dev] [PATCH v2 10/13] app/test: differentiate a strerror on different OS

Jie Zhou jizh at linux.microsoft.com
Wed Aug 18 19:13:51 CEST 2021


On Windows, strerror returns just "Unknown error" for errnum greater
than MAX_ERRNO, while linux and freebsd returns "Unknown error <num>",
which is the current expectation for errno_autotest. Differentiate
the error string on Windows to remove a "duplicate error code" failure.

Signed-off-by: Jie Zhou <jizh at linux.microsoft.com>
---
 app/test/test_errno.c             | 12 +++++++++++-
 lib/eal/common/eal_common_errno.c |  4 ++++
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/app/test/test_errno.c b/app/test/test_errno.c
index 3ff0456a58..d30ac212fd 100644
--- a/app/test/test_errno.c
+++ b/app/test/test_errno.c
@@ -18,13 +18,19 @@ test_errno(void)
 {
 	const char *rte_retval;
 	const char *libc_retval;
+
+#ifndef RTE_EXEC_ENV_WINDOWS
 #ifdef RTE_EXEC_ENV_FREEBSD
 	/* BSD has a colon in the string, unlike linux */
 	const char unknown_code_result[] = "Unknown error: %d";
 #else
 	const char unknown_code_result[] = "Unknown error %d";
 #endif
-	char expected_libc_retval[sizeof(unknown_code_result)+3];
+	char expected_libc_retval[sizeof(unknown_code_result) + 3];
+#else
+	/* Windows doesn't return error number for error greater than MAX_errno*/
+	const char expected_libc_retval[] = "Unknown error";
+#endif
 
 	/* use a small selection of standard errors for testing */
 	int std_errs[] = {EAGAIN, EBADF, EACCES, EINTR, EINVAL};
@@ -54,11 +60,13 @@ test_errno(void)
 				rte_retval, libc_retval);
 		if (strcmp(rte_retval, libc_retval) == 0)
 			return -1;
+#ifndef RTE_EXEC_ENV_WINDOWS
 		/* generate appropriate error string for unknown error number
 		 * and then check that this is what we got back. If not, we have
 		 * a duplicate error number that conflicts with errno.h */
 		snprintf(expected_libc_retval, sizeof(expected_libc_retval),
 				unknown_code_result, rte_errs[i]);
+#endif
 		if ((strcmp(expected_libc_retval, libc_retval) != 0) &&
 				(strcmp("", libc_retval) != 0)){
 			printf("Error, duplicate error code %d\n", rte_errs[i]);
@@ -69,8 +77,10 @@ test_errno(void)
 	/* ensure that beyond RTE_MAX_ERRNO, we always get an unknown code */
 	rte_retval = rte_strerror(RTE_MAX_ERRNO + 1);
 	libc_retval = strerror(RTE_MAX_ERRNO + 1);
+#ifndef RTE_EXEC_ENV_WINDOWS
 	snprintf(expected_libc_retval, sizeof(expected_libc_retval),
 			unknown_code_result, RTE_MAX_ERRNO + 1);
+#endif
 	printf("rte_strerror: '%s', strerror: '%s'\n",
 			rte_retval, libc_retval);
 	if ((strcmp(rte_retval, libc_retval) != 0) ||
diff --git a/lib/eal/common/eal_common_errno.c b/lib/eal/common/eal_common_errno.c
index f86802705a..4c4abb802e 100644
--- a/lib/eal/common/eal_common_errno.c
+++ b/lib/eal/common/eal_common_errno.c
@@ -37,7 +37,11 @@ rte_strerror(int errnum)
 	/* since some implementations of strerror_r throw an error
 	 * themselves if errnum is too big, we handle that case here */
 	if (errnum >= RTE_MAX_ERRNO)
+#ifdef RTE_EXEC_ENV_WINDOWS
+		snprintf(ret, RETVAL_SZ, "Unknown error%s", sep);
+#else
 		snprintf(ret, RETVAL_SZ, "Unknown error%s %d", sep, errnum);
+#endif
 	else
 		switch (errnum){
 		case E_RTE_SECONDARY:
-- 
2.32.0.windows.2



More information about the dev mailing list