From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <dev-bounces@dpdk.org>
Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124])
	by inbox.dpdk.org (Postfix) with ESMTP id 6F60AA00C3;
	Wed,  8 Dec 2021 02:52:12 +0100 (CET)
Received: from [217.70.189.124] (localhost [127.0.0.1])
	by mails.dpdk.org (Postfix) with ESMTP id 1C7324276A;
	Wed,  8 Dec 2021 02:51:21 +0100 (CET)
Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182])
 by mails.dpdk.org (Postfix) with ESMTP id 2516641233
 for <dev@dpdk.org>; Wed,  8 Dec 2021 02:51:08 +0100 (CET)
Received: from
 linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net
 (linux.microsoft.com [13.77.154.182])
 by linux.microsoft.com (Postfix) with ESMTPSA id B0DF920B7189;
 Tue,  7 Dec 2021 17:51:06 -0800 (PST)
DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com B0DF920B7189
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com;
 s=default; t=1638928266;
 bh=fXG6QRWDuqosgbodRfBD3bU01lHTBhToToexzk+7bBM=;
 h=From:To:Cc:Subject:Date:In-Reply-To:References:From;
 b=DzW2vNkhZut723PHLsGObdPz/P206qsOiC3Gwa2Z8S58a8KmahzHW90+/wxOYduWn
 0GiPLY5ib/SL4YZbDLW2QmUUyZ627bYqx0nWfbf2PZ5T7KENWQ5Kmj8g3i7DXGBjI0
 xDSmggBFxBtsg3cG7HULnHVQQ7B77o8l1YaCfcBw=
From: Jie Zhou <jizh@linux.microsoft.com>
To: dev@dpdk.org
Cc: dmitry.kozliuk@gmail.com, bruce.richardson@intel.com,
 roretzla@microsoft.com, navasile@linux.microsoft.com,
 dmitrym@microsoft.com, pallavi.kadam@intel.com, talshn@nvidia.com,
 thomas@monjalon.net, aconole@redhat.com
Subject: [PATCH v13 06/11] app/test: differentiate a strerror on different OS
Date: Tue,  7 Dec 2021 17:50:57 -0800
Message-Id: <1638928262-13177-7-git-send-email-jizh@linux.microsoft.com>
X-Mailer: git-send-email 1.8.3.1
In-Reply-To: <1638928262-13177-1-git-send-email-jizh@linux.microsoft.com>
References: <1638912263-7054-1-git-send-email-jizh@linux.microsoft.com>
 <1638928262-13177-1-git-send-email-jizh@linux.microsoft.com>
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: DPDK patches and discussions <dev.dpdk.org>
List-Unsubscribe: <https://mails.dpdk.org/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://mails.dpdk.org/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <https://mails.dpdk.org/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
Errors-To: dev-bounces@dpdk.org

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@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..0db4fbc8b3 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*/
+	static 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..7507c746ec 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");
+#else
 		snprintf(ret, RETVAL_SZ, "Unknown error%s %d", sep, errnum);
+#endif
 	else
 		switch (errnum){
 		case E_RTE_SECONDARY:
-- 
2.31.0.vfs.0.1