From nobody Sun Nov 24 12:30:57 2024 Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 17E50215C51; Tue, 5 Nov 2024 20:26:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730838411; cv=none; b=RBxP4AWmu4CFiKB87ErkNF447MGhFOE/ayB8Du3AjQR7raGxtdcatCdCY40c4Mvln8/5zZGFMqQ+U4OI3Bj9x0cy7LQzj1pbyN/Qooxgz1JQzm3aydNtcZZVOdpXwcNijzlXXzwEPQmRepKMJZNeY00MpJakEeDNOeTFj1LNn/Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730838411; c=relaxed/simple; bh=hTYIysBb73pQcGfbMlCjZoUnXhX3kUj3HocGQiRzBNc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=edQdum2RGBs407tmqC5H8PPzPFhp8uKSaQ2tzmF7bzpWNiNi8nehBFz5Cduc63eo4tqrtwNVjwhQ118J0rxB2DV9WNj03UDujbo/ZwkKdonGb5vJMCzLCzL3qluBvifKkd4zyheTr1C21liiJrmzJ/DuF8juZ8IJv3f8P9jEgkw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=aJfJAFdg; arc=none smtp.client-ip=209.85.214.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="aJfJAFdg" Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-20cdb889222so57138005ad.3; Tue, 05 Nov 2024 12:26:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730838409; x=1731443209; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=XT3No7GRKZdPAGp3d2fZuE2pq7D1yoaPqndFuh7XbSc=; b=aJfJAFdguKgpqwyXE4QFi+IXkxp5rcM6v5Hpg5YNMgZKRIaKZ7hIt18BL/yh4CHvSC czpoKSTaAYHaZu9CgAJqAowkqrtIfyzFQL/TKBqTT2BuIXeK6nHqSc7kkPYHwE22AXql FF69mGBphsFnVkjHT+E6ComAZKnV7MNUsmpV63z+4lQD3ahkpAVWfaQv/qCit9gHJK37 3MOb10ipq8eQJQ2x0EDr0RzAd+BrTziKlb/1B3fCFhGfBanBblg5AxWCyNHP/FCBrUWZ 6MsLwGEY4FWm1xKgP4KaiIlJ/6c2R+HvvGBMoKWk3iQQ+HaSN7N89snGh+uy15KqfEtQ h58A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730838409; x=1731443209; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=XT3No7GRKZdPAGp3d2fZuE2pq7D1yoaPqndFuh7XbSc=; b=tJY69n9fyWHHybRnHJw33lbU9k75/4aIejlNpLbBKJ2N5bw56cWtHuz8Eaccw4riLb Ulpu6SRzb94v/2QVz4VPwJoc1dy01lPPorZGg4XCS9QnkZ5GFObJ6xS8RpmjMtOkPxkJ dOipgmEQer7AmCWVyykBqZWV58Q5W6nk/FAOys6nBFlPTWFfbzxsdqILht+DyrGO37vR 8upE2ylYR10A1VRwQgP7Hm0mG1Jf5tb97B61rAAwwyvKTZeuTAwRw1gVnH63Mxy2fnaM KXemfx9HdtXo/NQ6kxSR8WSrC3j+sQ+BWV1TTeNLmn+PppFQBbcMmxgI/7AtLXtQ6iFS iC0w== X-Forwarded-Encrypted: i=1; AJvYcCW22/M+nSmSMDY1TTMPlm/47FMir6ZQBWqBO9IE8ZrON8KrycJbJeVATRX/zn1HVazLOiAF/ku02tYsv08=@vger.kernel.org X-Gm-Message-State: AOJu0YyxeepBTEqUfyJ6uHmKS9Audn/7TR5FZiG/vU2PQtf4R5AR0FUo 9Mzpo1ujOckok7Ba+uzgy1g2nKpN2PmDzKwnIC538bzf3Dn23C2uvHnIFV7xBCs= X-Google-Smtp-Source: AGHT+IEwxHh0iEEsZU5B/rZ5kLIROF/Pb+NSxPOnyBg70usMGWg+EFVrM5CyKGQNf8tV2UwfzAWGoA== X-Received: by 2002:a17:902:ecc3:b0:20c:ee48:94f3 with SMTP id d9443c01a7336-21103accfbbmr273363285ad.14.1730838409417; Tue, 05 Nov 2024 12:26:49 -0800 (PST) Received: from localhost.localdomain ([27.7.141.222]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-211056edc65sm82640665ad.10.2024.11.05.12.26.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Nov 2024 12:26:49 -0800 (PST) From: Shivam Chaudhary To: shuah@kernel.org Cc: linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Shivam Chaudhary Subject: [PATCH v4 1/2] selftests:tmpfs: Add Skip test if not run as root Date: Wed, 6 Nov 2024 01:56:38 +0530 Message-ID: <20241105202639.1977356-2-cvam0000@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241105202639.1977356-1-cvam0000@gmail.com> References: <20241105202639.1977356-1-cvam0000@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add skip test if not run as root, with an appropriate Warning. Add 'ksft_print_header()' and 'ksft_set_plan()' to structure test outputs more effectively. Test logs : Before change: - Without root error: unshare, errno 1 - With root No, output After change: - Without root TAP version 13 1..1 - With root TAP version 13 1..1 Signed-off-by: Shivam Chaudhary --- =20 tools/testing/selftests/tmpfs/bug-link-o-tmpfile.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tools/testing/selftests/tmpfs/bug-link-o-tmpfile.c b/tools/tes= ting/selftests/tmpfs/bug-link-o-tmpfile.c index b5c3ddb90942..cdab1e8c0392 100644 --- a/tools/testing/selftests/tmpfs/bug-link-o-tmpfile.c +++ b/tools/testing/selftests/tmpfs/bug-link-o-tmpfile.c @@ -23,10 +23,23 @@ #include #include =20 +#include "../kselftest.h" + int main(void) { int fd; =20 + /* Setting up kselftest framework */ + ksft_print_header(); + ksft_set_plan(1); + + /* Check if test is run as root */ + if (geteuid()) { + ksft_print_msg("Skip : Need to run as root"); + exit(KSFT_SKIP); + + } + if (unshare(CLONE_NEWNS) =3D=3D -1) { if (errno =3D=3D ENOSYS || errno =3D=3D EPERM) { fprintf(stderr, "error: unshare, errno %d\n", errno); --=20 2.45.2 From nobody Sun Nov 24 12:30:58 2024 Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A2DBD215F53; Tue, 5 Nov 2024 20:26:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730838414; cv=none; b=mOXgFC2O7NrblP1jsb+5friOBKbHmXJMhzP0NdzA9sf5rRhHLNULeodS2Rk+vy6pEo7vGnuPA/AlxpBBTaI9TgnFnl2SrxmJkWO5nlWKkQIO1BD0QirDu3A3TGcps9vsroBu7h/GQx+BZOaNVa4c73WutHtIjXsxeqsOBXbjDaY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730838414; c=relaxed/simple; bh=ACzj8pdw96HChBwKsNw2pXfqhxjH1tOWpf8yeLsUYTc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=V3xwR9hpQx3G5+91nrXsLcJB9yQ1slU6K02tAxqdods0Brt3mn2b/myKTQB6iiHM8Bc82c2C+Ul3qB/9JbCKVPwxuz2aHtF+rCjSYRcaIAsMFRxfR0gO/0n2wXE57o1WK+FKmbhaVBVVLt3ArfCj+1ooTFEhH1r1EgtWBdxZXTM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=aF/PdT5m; arc=none smtp.client-ip=209.85.214.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="aF/PdT5m" Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-20cdbe608b3so59148915ad.1; Tue, 05 Nov 2024 12:26:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730838412; x=1731443212; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=aBHrik1+PfGY8aie53DmTfdP4VfBjoDYBEfpHdyGKow=; b=aF/PdT5m22+jnHr/h1cfLqdawxJmQ5zcDJj7EJSCuSWa1PtGgWr1yBkh4jqIoBJ/xc pB/4PRXDE6EWmqJeoCn6R/rOsVOvgMMf1fFcOluu14m7odoInRujY1fagcH3V9RjKYy8 jRV5nbzsJhohbsSaQoc6HHiF6UAQSHCoj9JcU4ZRGJKUUkHJI+P7EheyW+rF23MSrz9q zlv3snOuEKYA0ud6hMNOGWH+5ZzD9IIUtZaqlVJZlmwcBL937C5MI7OXQKo5vfWWeNt9 u8l2awoNfTxeyIO3KkFwwk0N/MxfPrPt1bdmE8XpAfqdWVtPnTVG/oS/WRvGoUH/FQFz 0z7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730838412; x=1731443212; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=aBHrik1+PfGY8aie53DmTfdP4VfBjoDYBEfpHdyGKow=; b=j+rTAi+m+u4Mgq9CDRkAFBGolQvFmeayAz83V/Z3kvVqco1n27914RnzCWJJ/H2yGL qTfS+6aBpQ3FRqK60kditOl3Pg5RSIv4b/FbLChdmbdlqkHI02u8d/GFH+Q5lT6r2mgn kI3rF8cp5ONCoW3gLwJEZFGBkUUs1Jv1rvWCfeUVy0Hueo+tRhdDixB/Bk3nSGuuZGsy syKDdfMj9tF9L0l8G0oGPDP85+cKpSVpvv8+h1P9fIiSDHScsLtTl1x4pHY2uNdn/MbT AU96gSVsbrblEnO6TnT2npeil7uIt/q0Y7/WsqPqlJj9E63wXgJGNDSRyemkgxDD9m0p gN1w== X-Forwarded-Encrypted: i=1; AJvYcCVWUe3W0DJ6PZ00tb/18Smtz55mM+UsCxdWrN138+XIm+34f2C8jDJeAc07PBHtR9jIIMvU9qaLPysMkkU=@vger.kernel.org X-Gm-Message-State: AOJu0YxJrYFTALtgJVPyKPGTQ57zN6jBy+O7qdazBW1v077uX7AmrzJI 9iqe3HJ9BCeSR+jOklp4IWag0szMSE1QSIvnDzti/HEgnpiBn4nl X-Google-Smtp-Source: AGHT+IGgG50y/0914XGUzjBnyX8itH1E9DWnEvzd+QSjNQAJxFQWvHUuU/80Z/ECufnnjL+pO/kGaQ== X-Received: by 2002:a17:902:db0f:b0:20b:65d6:d268 with SMTP id d9443c01a7336-210f76f53eemr353224415ad.53.1730838411972; Tue, 05 Nov 2024 12:26:51 -0800 (PST) Received: from localhost.localdomain ([27.7.141.222]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-211056edc65sm82640665ad.10.2024.11.05.12.26.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Nov 2024 12:26:51 -0800 (PST) From: Shivam Chaudhary To: shuah@kernel.org Cc: linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Shivam Chaudhary Subject: [PATCH v4 2/2] selftests: tmpfs: Add kselftest support to tmpfs Date: Wed, 6 Nov 2024 01:56:39 +0530 Message-ID: <20241105202639.1977356-3-cvam0000@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241105202639.1977356-1-cvam0000@gmail.com> References: <20241105202639.1977356-1-cvam0000@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Replace direct error handling with 'ksft_test_result_*', 'ksft_print_msg' and KSFT_SKIP macros for better reporting. Test logs: Before change: - Without root error: unshare, errno 1 - With root No, output After change: - Without root TAP version 13 1..1 ok 1 # SKIP This test needs root to run - With root TAP version 13 1..1 unshare(): Creat new mount namespace: Success. mount(): Root filesystem private mount: Success mount(): Mounting tmpfs on /tmp: Success openat(): Open first temporary file: Success linkat(): Linking the temporary file: Success openat(): Opening the second temporary file: Success ok 1 Test : Success Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0 Signed-off-by: Shivam Chaudhary --- .../selftests/tmpfs/bug-link-o-tmpfile.c | 66 ++++++++++++++----- 1 file changed, 49 insertions(+), 17 deletions(-) diff --git a/tools/testing/selftests/tmpfs/bug-link-o-tmpfile.c b/tools/tes= ting/selftests/tmpfs/bug-link-o-tmpfile.c index cdab1e8c0392..f2e6a5b20698 100644 --- a/tools/testing/selftests/tmpfs/bug-link-o-tmpfile.c +++ b/tools/testing/selftests/tmpfs/bug-link-o-tmpfile.c @@ -42,39 +42,71 @@ int main(void) =20 if (unshare(CLONE_NEWNS) =3D=3D -1) { if (errno =3D=3D ENOSYS || errno =3D=3D EPERM) { - fprintf(stderr, "error: unshare, errno %d\n", errno); - return 4; + ksft_print_msg("unshare() error: unshare, errno %d\n", errno); + exit(KSFT_SKIP); + + } + else{ + fprintf(stderr, "unshare() error: unshare, errno %d\n", errno); + return 1; + } - fprintf(stderr, "error: unshare, errno %d\n", errno); - return 1; + }=20 +=09 + else { + ksft_print_msg("unshare(): Creat new mount namespace: Success.\n"); + } - if (mount(NULL, "/", NULL, MS_PRIVATE|MS_REC, NULL) =3D=3D -1) { - fprintf(stderr, "error: mount '/', errno %d\n", errno); - return 1; + + + + if (mount(NULL, "/", NULL, MS_PRIVATE | MS_REC, NULL) =3D=3D -1) { + ksft_print_msg("mount() error: Root filesystem private mount: Fail %d\n"= , errno); + exit(KSFT_SKIP); + } else { + ksft_print_msg("mount(): Root filesystem private mount: Success\n"); } =20 + /* Our heroes: 1 root inode, 1 O_TMPFILE inode, 1 permanent inode. */ if (mount(NULL, "/tmp", "tmpfs", 0, "nr_inodes=3D3") =3D=3D -1) { - fprintf(stderr, "error: mount tmpfs, errno %d\n", errno); - return 1; + ksft_print_msg("mount() error: Mounting tmpfs on /tmp: Fail %d\n", errno= ); + exit(KSFT_SKIP); + } else { + ksft_print_msg("mount(): Mounting tmpfs on /tmp: Success\n"); } =20 - fd =3D openat(AT_FDCWD, "/tmp", O_WRONLY|O_TMPFILE, 0600); + + fd =3D openat(AT_FDCWD, "/tmp", O_WRONLY | O_TMPFILE, 0600); if (fd =3D=3D -1) { - fprintf(stderr, "error: open 1, errno %d\n", errno); - return 1; + ksft_print_msg("openat() error: Open first temporary file: Fail %d\n", e= rrno); + exit(KSFT_SKIP); + } else { + ksft_print_msg("openat(): Open first temporary file: Success\n"); } + + if (linkat(fd, "", AT_FDCWD, "/tmp/1", AT_EMPTY_PATH) =3D=3D -1) { - fprintf(stderr, "error: linkat, errno %d\n", errno); - return 1; + ksft_print_msg("linkat() error: Linking the temporary file: Fail %d\n", = errno); + /* Ensure fd is closed on failure */ + close(fd);=20 + exit(KSFT_SKIP); + } else { + ksft_print_msg("linkat(): Linking the temporary file: Success\n"); } close(fd); =20 - fd =3D openat(AT_FDCWD, "/tmp", O_WRONLY|O_TMPFILE, 0600); + + fd =3D openat(AT_FDCWD, "/tmp", O_WRONLY | O_TMPFILE, 0600); if (fd =3D=3D -1) { - fprintf(stderr, "error: open 2, errno %d\n", errno); - return 1; + ksft_print_msg("openat() error: Opening the second temporary file: Fail = %d\n", errno); + exit(KSFT_SKIP); + } else { + ksft_print_msg("openat(): Opening the second temporary file: Success\n"); } =20 + ksft_test_result_pass("Test : Success\n"); + ksft_exit_pass(); return 0; } + --=20 2.45.2