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 11785A00C3; Tue, 7 Dec 2021 22:24:52 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 4B1E2426F1; Tue, 7 Dec 2021 22:24:34 +0100 (CET) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mails.dpdk.org (Postfix) with ESMTP id 3562A4114A for ; Tue, 7 Dec 2021 22:24:29 +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 2C4E620B7189; Tue, 7 Dec 2021 13:24:28 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 2C4E620B7189 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1638912268; bh=fXG6QRWDuqosgbodRfBD3bU01lHTBhToToexzk+7bBM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MtXWThv9d/45LOiBbxbj0MzmOqpi38nGH/DDPdS2ytAXjOcbBtZFT7qr2xNVq8Lk2 X+AI69/NAu88hL0EowmhKG4iWXjT8exZK7utM3GUMN2XJxqD44pryneVvQfqBqyXOh YXT/zVlY+S4Q+FfmfhzKCcv1hICUGiuuXvg9vJtI= From: Jie Zhou 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 v12 06/11] app/test: differentiate a strerror on different OS Date: Tue, 7 Dec 2021 13:24:18 -0800 Message-Id: <1638912263-7054-7-git-send-email-jizh@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1638912263-7054-1-git-send-email-jizh@linux.microsoft.com> References: <1638490007-9939-1-git-send-email-jizh@linux.microsoft.com> <1638912263-7054-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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-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 ", 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..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