From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 7FD3BA0C4B; Thu, 14 Oct 2021 18:22:48 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 8FC9B4121D; Thu, 14 Oct 2021 18:21:59 +0200 (CEST) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mails.dpdk.org (Postfix) with ESMTP id CAA3A410E0 for ; Thu, 14 Oct 2021 18:21:47 +0200 (CEST) Received: from linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net (linux.microsoft.com [13.77.154.182]) by linux.microsoft.com (Postfix) with ESMTPSA id EDF8320B9D1A; Thu, 14 Oct 2021 09:21:46 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com EDF8320B9D1A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1634228507; bh=VYLH4NBv4NAU2SjeXbbOZkZFgZEebGzSYAwOMUwDVWA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JmrCmUrUUo/+BGzVaBy4jzzxrazcPyITheunWsnMiUNj/ao/JBPQhUuLm8vSsnW+f vPv+nd3bTEUltum32/kd26cmo9L2+mH5DNT5rlLWfccoU4S2+LrL/GsjmqPK//HU/J xDOX4g6tKy90ktRo4eM7eWWLxhsM4LSfe0IqUEsQ= From: Jie Zhou To: dev@dpdk.org Cc: dmitry.kozliuk@gmail.com, roretzla@microsoft.com, navasile@linux.microsoft.com, dmitrym@microsoft.com, pallavi.kadam@intel.com, talshn@nvidia.com, thomas@monjalon.net, aconole@redhat.com Date: Thu, 14 Oct 2021 09:21:39 -0700 Message-Id: <1634228502-14701-10-git-send-email-jizh@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1634228502-14701-1-git-send-email-jizh@linux.microsoft.com> References: <1634187170-3986-1-git-send-email-jizh@linux.microsoft.com> <1634228502-14701-1-git-send-email-jizh@linux.microsoft.com> Subject: [dpdk-dev] [PATCH v6 09/12] app/test: differentiate a strerror on different OS X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" On Windows, strerror returns just "Unknown error" for errnum greater than MAX_ERRNO, while linux and freebsd returns "Unknown error ", 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 --- 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..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