From patchwork Thu Apr 4 16:14:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muhammad Usama Anjum X-Patchwork-Id: 13618036 Received: from madrid.collaboradmins.com (madrid.collaboradmins.com [46.235.227.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4E97212C7FA; Thu, 4 Apr 2024 16:14:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=46.235.227.194 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712247256; cv=none; b=nXk4p42TD17j8KEbQCbycve4zGGFSpVxGv2sOH6dArmpGoZqdzDK5fp69mKLaruXB2Ui7fa3DuoVSId/m7ThU1ZHlU6/Zq+Rt7E+V5kRI46jkL06J3GunF6cL+Nm+oVeEENgUMvZoedzdkBTHFVdbwDVbvzrTzOADLmQ8uHOgkQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712247256; c=relaxed/simple; bh=boDL5nHOi6Lw/iE+qqB7X+GYBlXdpClEfHq4s6TIuWo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=QEo9Q+i8qYxO7XPKHYk1Quw9+68PxhovUFh53/19f3DY10qJ8tQDM8CFSmJbxxFBC2SWjc29Je8CIBVWDsXPdzjkOuSQJZLF8Bj29nkFknjxnT0wD3h4iBwfVEOFywPOs/LzjedogivsqGNnuqkb34xaSi4eVZJMUmnjIysDUOA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b=Ge1bY6gJ; arc=none smtp.client-ip=46.235.227.194 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="Ge1bY6gJ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1712247253; bh=boDL5nHOi6Lw/iE+qqB7X+GYBlXdpClEfHq4s6TIuWo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ge1bY6gJXP/VQg+cVNTG6HkpGguexAj/rR7+IrElRFFuC6JIWVk2BTA+MEQ/wtY8V qtyRZ8S2iIl+4J/4u4qMxUWf2k3VRpdg6ktbBjv3mBfE0p0Ynzlf4Wsw4OhHI7bDIW D4SvB2DcTayeOHd9wgGb13zqts5ZlfpBArMT6h72PANYY9Uigq2GeTA5eaJcAQ2URx 9u68VpEuWE4sbNOCOOo3ZzOZRIn7FyPZ1gWMeg0Ldd5XHiu2HzV0gq0XffLOirrdDk NuBVPhqxowuMVTRZ+YfFiXoWFsyMQHmBKAsHWhwKic+f6mFBgYehR/Ht7THAxSPg+D GEv+GZ8oU8NEA== Received: from localhost.localdomain (broslavsky.collaboradmins.com [68.183.210.73]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: usama.anjum) by madrid.collaboradmins.com (Postfix) with ESMTPSA id 50B4F3782129; Thu, 4 Apr 2024 16:14:08 +0000 (UTC) From: Muhammad Usama Anjum To: Eric Biederman , Kees Cook , Shuah Khan , Muhammad Usama Anjum , linux-mm@kvack.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Cc: kernel@collabora.com Subject: [PATCH 1/2] selftests: add ksft_exit_fail_perror() Date: Thu, 4 Apr 2024 21:14:32 +0500 Message-Id: <20240404161433.114497-2-usama.anjum@collabora.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240404161433.114497-1-usama.anjum@collabora.com> References: <20240404161433.114497-1-usama.anjum@collabora.com> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add a version of ksft_exit_fail_msg() which prints the errno and its string form with ease. There is no benefit of exit message without errno. Whenever some error occurs, instead of printing errno manually, this function would be very helpful. In the next TAP ports or new tests, this function will be used instead of ksft_exit_fail_msg() as it prints errno. Signed-off-by: Muhammad Usama Anjum --- tools/testing/selftests/kselftest.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tools/testing/selftests/kselftest.h b/tools/testing/selftests/kselftest.h index 159bf8e314fa3..2cd93d220f434 100644 --- a/tools/testing/selftests/kselftest.h +++ b/tools/testing/selftests/kselftest.h @@ -41,6 +41,7 @@ * the program is aborting before finishing all tests): * * ksft_exit_fail_msg(fmt, ...); + * ksft_exit_fail_perror(msg); * */ #ifndef __KSELFTEST_H @@ -370,6 +371,19 @@ static inline __printf(1, 2) int ksft_exit_fail_msg(const char *msg, ...) exit(KSFT_FAIL); } +static inline void ksft_exit_fail_perror(const char *msg) +{ +#ifndef NOLIBC + ksft_exit_fail_msg("%s: %s (%d)\n", msg, strerror(errno), errno); +#else + /* + * nolibc doesn't provide strerror() and it seems + * inappropriate to add one, just print the errno. + */ + ksft_exit_fail_msg("%s: %d)\n", msg, errno); +#endif +} + static inline int ksft_exit_xfail(void) { ksft_print_cnts(); From patchwork Thu Apr 4 16:14:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muhammad Usama Anjum X-Patchwork-Id: 13618037 Received: from madrid.collaboradmins.com (madrid.collaboradmins.com [46.235.227.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4C45612D758; Thu, 4 Apr 2024 16:14:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=46.235.227.194 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712247261; cv=none; b=kd/7xQdiGxwVQyenHlLgjFyeSym38yYJOUwKQ/6/Y3ZLHrmOiNksLejU3poDcrRnT172LXLm6d8BlAv2TXfY7AZnvdafM4unCf85sCa1T7BfRIbJMKg0SZaXikqNH/+i3URjCCfHwFQiu0mHHvO9QGGukGB88O09PjPduY/8ya0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712247261; c=relaxed/simple; bh=ldtvjkAh4uiGxCheNFBwI4fa4kaJRENVGkoL+ZPIS0g=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=jFnh6xCQ/8HCz+Zn/wVwhpmLGvlWfwIUiq4nxUnBO1+KBDZftPJN+I9Q8l0xlE9PR4h13YNCwlTwekYzXOk3uT55MdHQhIt0RglseV2ISOBFd9O2/paHExTOpMIMz9lTOystlVdSF/gRTxmke9HeqJko/zYVm8l9Q9P+snnRneE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b=fRx2C0Ai; arc=none smtp.client-ip=46.235.227.194 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="fRx2C0Ai" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1712247258; bh=ldtvjkAh4uiGxCheNFBwI4fa4kaJRENVGkoL+ZPIS0g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fRx2C0AiLQ4G1u6VFtu1nRt8ktODQ2HPoOEC4eASfbnsv3kNtEnb3RqER3Y2wbRY9 d/pJoQRl2pj7+q7DT0patY2f1zEPrCtrwOUGfyEg+1Y9GoFWQMUusXNax/Kl1k9DY1 73JunOQKqEIxh0+00nwpZp9kupfykapjNm13AahJ2r9U2cuRX5xsRw9syYMPjG5lR1 JnvrI/7rMjOBLXXhKhsNJ9b2Be3kKxApdA/+kWDhXAzANyGnmiGUzjGpQ0M/2GT64W SpEU9pSg90tT9ET8Bb0UgJvlZbj/k0v0OPetMnblBZWVFmWXQfOqKLD2YM0CZcB08/ VqJE/TPfcDIEA== Received: from localhost.localdomain (broslavsky.collaboradmins.com [68.183.210.73]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: usama.anjum) by madrid.collaboradmins.com (Postfix) with ESMTPSA id B8A7B378212B; Thu, 4 Apr 2024 16:14:14 +0000 (UTC) From: Muhammad Usama Anjum To: Eric Biederman , Kees Cook , Shuah Khan , Muhammad Usama Anjum , linux-mm@kvack.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Cc: kernel@collabora.com Subject: [PATCH 2/2] selftests: exec: Use new ksft_exit_fail_perror() helper Date: Thu, 4 Apr 2024 21:14:33 +0500 Message-Id: <20240404161433.114497-3-usama.anjum@collabora.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240404161433.114497-1-usama.anjum@collabora.com> References: <20240404161433.114497-1-usama.anjum@collabora.com> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Use ksft_exit_fail_perror() to print the value of errno and its string form. This is the first user of the ksft_exit_fail_perror() and proves the usefulness of this API. Signed-off-by: Muhammad Usama Anjum --- tools/testing/selftests/exec/recursion-depth.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tools/testing/selftests/exec/recursion-depth.c b/tools/testing/selftests/exec/recursion-depth.c index b2f37d86a5f62..438c8ff2fd260 100644 --- a/tools/testing/selftests/exec/recursion-depth.c +++ b/tools/testing/selftests/exec/recursion-depth.c @@ -37,25 +37,25 @@ int main(void) ksft_test_result_skip("error: unshare, errno %d\n", errno); ksft_finished(); } - ksft_exit_fail_msg("error: unshare, errno %d\n", errno); + ksft_exit_fail_perror("error: unshare"); } if (mount(NULL, "/", NULL, MS_PRIVATE | MS_REC, NULL) == -1) - ksft_exit_fail_msg("error: mount '/', errno %d\n", errno); + ksft_exit_fail_perror("error: mount '/'"); /* Require "exec" filesystem. */ if (mount(NULL, "/tmp", "ramfs", 0, NULL) == -1) - ksft_exit_fail_msg("error: mount ramfs, errno %d\n", errno); + ksft_exit_fail_perror("error: mount ramfs"); #define FILENAME "/tmp/1" fd = creat(FILENAME, 0700); if (fd == -1) - ksft_exit_fail_msg("error: creat, errno %d\n", errno); + ksft_exit_fail_perror("error: creat"); #define S "#!" FILENAME "\n" if (write(fd, S, strlen(S)) != strlen(S)) - ksft_exit_fail_msg("error: write, errno %d\n", errno); + ksft_exit_fail_perror("error: write"); close(fd);