From patchwork Thu Jan 2 10:04:58 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shivam Chaudhary X-Patchwork-Id: 855095 Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) (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 832CA38F82; Thu, 2 Jan 2025 10:05:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735812313; cv=none; b=pc47VxmY5ZiVmNxBCM2TTWYHQDPA91C1b7BbetdzYbBLUXuOy+xSx2PmOAjL7cGezV7xC4QEFCNSpQP4fvVtSa5Ufd0ye8/pcnZKVQ0o/o6YUx5/pzqqPqrqgHZbiANc9j1OR8AQl94lEHVS3FWaBzReK0YT7GwzDYq7TOjLCOo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735812313; c=relaxed/simple; bh=b9n0Nfj91k3h2Q0NrLnOiA5u+xyBUwsV4tN9YTKRxUU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=OYUv4e0Tsgl1GZYwaYnrIiKYWM/4qMNCgS3NTwUg2o7swrsE6LJbnQuljQBtwYP4OodE0tfe6X+xXuTBHICCPgcyhAnlcdcYJKNGBKwWjHcssawSzOb2bq9FfpO1noqFY3KU/tpQZH36ey/gCFt8Fe+naLXC57Gu6gk9tVRaQU8= 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=IGxGsE+D; arc=none smtp.client-ip=209.85.214.174 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="IGxGsE+D" Received: by mail-pl1-f174.google.com with SMTP id d9443c01a7336-2166651f752so175959855ad.3; Thu, 02 Jan 2025 02:05:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1735812312; x=1736417112; 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=HNHzGCV835rfMgYwKPqKqPeLuQwNVSkguSfQpszEKyw=; b=IGxGsE+DDfq7JMs4J/YcyXsEwULhjEhMLQV9ELeFWrZz3K6NcuLYs6s4QLH7z2LpeF LtPNSGPFgpJ3m5RzFjBUPlKW3Uef4fUaIOlduuYIpOgcoB3jD3uk/jD3S6SVKv+Mxrv7 jCrz2W/yCosVi7QDlP6cpZdGdhJREUZCLt/OCHEotLgmAgnp3w+Wq55T0a7ySfvfv2Ba 0A/Mob4h3Ebgl01OUnpHIl5uXPlAxZP5TQjDu9GcBGP28TFhC0T+nNowOggLNCjrVg0G ctmQ06CT2G33aqw/s0Xj5EN7XoAZoSVsLX6XGeOtyguVMWvFlQiKjHBuDU5tBf7h5gJe a+oA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735812312; x=1736417112; 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=HNHzGCV835rfMgYwKPqKqPeLuQwNVSkguSfQpszEKyw=; b=wTlDZqzfFoDVXi62O9NHwzXkeGzKeEud+hE0evfL6y3ZCb7oYpMjT09gOq9cV20lb2 E/kgm56G+HKeufXyP5y0xJ4WiKiwpX+BH4t4OpBzvYD412SO4rcHcA+czzeDcBd9RD9Y DA+27bm5xFPjcHlkalZIj3d9UM+KP+kT6xp8JdBjBI6Wz39w1ZtTp7MJS+/aOc6xFbi0 WELocWGVZTGw04uNN97w7cXFXm4llc4j65ICVenPfDwevVY1NrDhLHMGO8vBVqNfOSqm dVyGz170+li4n5SYWReiS48ayQylqDbnE2Ufyy0jA6utLSaROwxJV3h6GaZMwERVEKev Ntag== X-Forwarded-Encrypted: i=1; AJvYcCVZbDdej3M/qfCgRHZIgjM2ApqxzZSFUrE/zE7MAeU99dy07ji4cvUS+VJTlxcUiKNwJ/k6RKKrJqreIcg=@vger.kernel.org X-Gm-Message-State: AOJu0YxGtYiiwHoDEMLxlNPWyp1bN2CrnIgV0EJ7MoeoxxQhmpSu0MF2 ARG2QPxxf/vc1zqaEPsnKm2BmnOx/xJhc0kbXGHYKCmfteI35jdD X-Gm-Gg: ASbGncs1Z4Z0WeEhKaxZCVYPCyarLBgP1A33oPAEM6j1CZbZ+FZSkxkkLUYnor7p5hg naJbakBGL5oldRAxyvsuYbYIGOWTke/TNAKj+YC+rxZLG+e8JzUGN9rDYUsIkYOu92IYSL/BusA iSPmfc+6dlBy44o5N/Ty+UtjelTg/unKtYnJavF8YViT0cf1FPgXgQwnkmNqTfF5i1JT46EOA3o 7IFn7DJaL8kHk/Mj7MkiQ7ECcW8ukT1nm9DHIQNn+jQPExBxhYgAGvJ5Ulby7yw56lMVw== X-Google-Smtp-Source: AGHT+IFldj1if8zVbTvd5PDfPXH25cCNHuSw/XOHV0+DzqhjVMup+QSPzaNNiyCG3KCag27u/etb6w== X-Received: by 2002:a17:903:2285:b0:215:3661:747e with SMTP id d9443c01a7336-219e6e8bb0amr613483315ad.8.1735812311489; Thu, 02 Jan 2025 02:05:11 -0800 (PST) Received: from 2abb50c-lcedt.nvidia.com ([203.200.25.7]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-219dc9f7457sm219759945ad.201.2025.01.02.02.05.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Jan 2025 02:05:11 -0800 (PST) From: Shivam Chaudhary To: shuah@kernel.org Cc: linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Shivam Chaudhary Subject: [PATCH v7 1/2] selftests: tmpfs: Add Test-skip if not run as root Date: Thu, 2 Jan 2025 15:34:58 +0530 Message-Id: <20250102100459.1291426-2-cvam0000@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250102100459.1291426-1-cvam0000@gmail.com> References: <20250102100459.1291426-1-cvam0000@gmail.com> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add 'ksft_exit_skip()', 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 ok 2 # SKIP This test needs root to run! Totals: pass:0 fail:0 xfail:0 xpass:0 skip:1 error:0 - With root TAP version 13 1..1 Signed-off-by: Shivam Chaudhary --- tools/testing/selftests/tmpfs/bug-link-o-tmpfile.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tools/testing/selftests/tmpfs/bug-link-o-tmpfile.c b/tools/testing/selftests/tmpfs/bug-link-o-tmpfile.c index b5c3ddb90942..657b64857e82 100644 --- a/tools/testing/selftests/tmpfs/bug-link-o-tmpfile.c +++ b/tools/testing/selftests/tmpfs/bug-link-o-tmpfile.c @@ -23,10 +23,22 @@ #include #include +#include "../kselftest.h" + int main(void) { int fd; + // Setting up kselftest framework + ksft_print_header(); + ksft_set_plan(1); + + // Check if test is run as root + if (geteuid()) { + ksft_exit_skip("This test needs root to run!\n"); + return 1; + } + if (unshare(CLONE_NEWNS) == -1) { if (errno == ENOSYS || errno == EPERM) { fprintf(stderr, "error: unshare, errno %d\n", errno); From patchwork Thu Jan 2 10:04:59 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shivam Chaudhary X-Patchwork-Id: 854788 Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) (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 ECF9319D8BB; Thu, 2 Jan 2025 10:05:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735812315; cv=none; b=SzRTqJdbZniMc4rixXC6Nr+YD8v+FGZjK3TZlrEUe1ZHUnx9IByZmLj4T+7gEvV/nxIM4wdEN+p3cVcN1hhVm4MFNrN3Ewv2YLuCcrBd552pfbOY/PfsDm0kcX3ku1ZLH+RDEtsNHbr0IOgdouMXZcY+U1aZqqkBh6/9dE0gsaw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735812315; c=relaxed/simple; bh=E5B04nP/p1tjctc7tRaDi3KpmTPtDYnoyQ4NxS9KzGo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=XDsaal0m5zmsEhGkcR9aPri+3jHkuJ7oNx4Y4YNzEzZ8prDTamrevzlT+AGPnr2gyRdF/vqCydlXc0k+Mgp2S5yEEzjQFCHtov/wAI36/rc/Y6biTveDkxvZivrcZsFII9Fqzh7p5dC4ldJ/G+c/qaZ9L6BEMRM1p+7d3S+zi4I= 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=GmSRfDER; arc=none smtp.client-ip=209.85.214.182 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="GmSRfDER" Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-2164b1f05caso150222135ad.3; Thu, 02 Jan 2025 02:05:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1735812313; x=1736417113; 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=R9pqvO/HmvM8F30k0JXImorQhWQmk8hgeeTlW54kQmw=; b=GmSRfDERU4TdvSwWQjR2HchpZ9ijLb79HIvIM2i7QYfJuh0vBSoPbLVp0+yIvoU0Jw TsLIuLeA+qUVrHJ8sSI9G2stpG3sda6toc2XWW4aafvC+4+Gm7Zaul2CVjEK+AXZw2R/ Hw/BfUYhwxANZzTcIYZJHDLFke5fYvyKug8H7pvgRskaSPeJzrg5FEk4OsFngCSUL0U/ tYARLSJpYgMKEUu/4wwIT+XFs4IgvD7u0RtbsRyjscmWAwAe3IBhIXjoyJoXlaj07ih/ mh5hs6OaRI5Ymc22hg8ozctTTrTEmy6iQJHyaEfh4f8zXKyg/e1D0hYanNzlsJSDuINm Oq6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735812313; x=1736417113; 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=R9pqvO/HmvM8F30k0JXImorQhWQmk8hgeeTlW54kQmw=; b=q8gY5DBm6Gw9rejPlOVddUTd6OutJnPW7GnDkoRtBOW1V4OX6dT4BvYZCiocySYPiM dLHuZxuSuY46YVULoohNAHmfh2RcQFVqjiZyuEzIu6tHKn0G0PdeaLK688iGnBl3C1j5 rs8ZIP6GlwVdFOB63YPP5Yevez3WqJe1WaPuqJJG8sGKHs3Nd5SUc2qpIx/xjXzuT05N UlZ9Gi3nx7baa01eMofBVFsvI7/QmF3ciecpnQkbkFX39cCi0aXpFHrDUwVTrEUriMjH wd2H8X3YaXAGZ/Prm2BZc6TZPQStM5UFjJMGb7H3N33+yTwlW3htlKgAyA8G8qmCEZUC EdqQ== X-Forwarded-Encrypted: i=1; AJvYcCUl8giPWPLcb7KvHKlcBroAsd3+TPWuMIbD3r3GY9kW4Llo9lhNyWxkoPHK2sA69imHAsdaRlItbrwoVV4=@vger.kernel.org X-Gm-Message-State: AOJu0YyTcbD1yWc3GnjgC2MkKfCro3SL8CuCPHm5eSe1BW0ub/W0NjDE WQREBGLwxTkKJlemcTZR5aRanGtiYD1FCLNrAC6yp/LOnKjmV7kpIOCFtg== X-Gm-Gg: ASbGncvs93gdbNiu7aIgdQN2brf2CRLqkJhKwL0GUSz6a5gXJIJgXxJyUMf5NRRZl0E 3Gp3arYI3TbQuyokJxQZ0EoMoobNN6D2lHd4DYvKuq6p78PO5GiLmfSfqZ3C11GA2gTLwLnUuwv UEv6nBgCoLJh4tOUE14DyJtnSZMsexNPaGNOZQpyqgWaiMEAKcX2dbtPUGxt7Rx2skNysfiPF2f zyZBq5DOpmOpcpsU2dldoxXcNpeInrcGAR9PfO2oEjAIaqqUkGs6sv95TrxrCUBwKAfVQ== X-Google-Smtp-Source: AGHT+IGz+JOKRKnBWp+Kh76fkqrY6rwNqq4as+W+NSqOnua3pty4goNpTJyyEFi2UrgSyhbSUDMM/Q== X-Received: by 2002:a17:902:fc4e:b0:216:31aa:1308 with SMTP id d9443c01a7336-219e6ec1da0mr683111145ad.34.1735812313322; Thu, 02 Jan 2025 02:05:13 -0800 (PST) Received: from 2abb50c-lcedt.nvidia.com ([203.200.25.7]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-219dc9f7457sm219759945ad.201.2025.01.02.02.05.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Jan 2025 02:05:13 -0800 (PST) From: Shivam Chaudhary To: shuah@kernel.org Cc: linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Shivam Chaudhary Subject: [PATCH v7 2/2] selftests: tmpfs: Add kselftest support to tmpfs Date: Thu, 2 Jan 2025 15:34:59 +0530 Message-Id: <20250102100459.1291426-3-cvam0000@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250102100459.1291426-1-cvam0000@gmail.com> References: <20250102100459.1291426-1-cvam0000@gmail.com> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Replace direct error handling with 'ksft_test_result_*' 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 2 # SKIP This test needs root to run! Totals: pass:0 fail:0 xfail:0 xpass:0 skip:1 error:0 - With root TAP version 13 1..1 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 | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/tools/testing/selftests/tmpfs/bug-link-o-tmpfile.c b/tools/testing/selftests/tmpfs/bug-link-o-tmpfile.c index 657b64857e82..290f11a81d2b 100644 --- a/tools/testing/selftests/tmpfs/bug-link-o-tmpfile.c +++ b/tools/testing/selftests/tmpfs/bug-link-o-tmpfile.c @@ -41,39 +41,39 @@ int main(void) if (unshare(CLONE_NEWNS) == -1) { if (errno == ENOSYS || errno == EPERM) { - fprintf(stderr, "error: unshare, errno %d\n", errno); - return 4; + ksft_exit_skip("unshare() error: unshare, errno %d\n", errno); + } else { + ksft_exit_fail_msg("unshare() error: unshare, errno %d\n", errno); } - fprintf(stderr, "error: unshare, errno %d\n", errno); - return 1; } + if (mount(NULL, "/", NULL, MS_PRIVATE|MS_REC, NULL) == -1) { - fprintf(stderr, "error: mount '/', errno %d\n", errno); - return 1; + ksft_exit_fail_msg("mount() error: Root filesystem private mount: Fail %d\n", errno); } /* Our heroes: 1 root inode, 1 O_TMPFILE inode, 1 permanent inode. */ if (mount(NULL, "/tmp", "tmpfs", 0, "nr_inodes=3") == -1) { - fprintf(stderr, "error: mount tmpfs, errno %d\n", errno); - return 1; + ksft_exit_fail_msg("mount() error: Mounting tmpfs on /tmp: Fail %d\n", errno); } fd = openat(AT_FDCWD, "/tmp", O_WRONLY|O_TMPFILE, 0600); if (fd == -1) { - fprintf(stderr, "error: open 1, errno %d\n", errno); - return 1; + ksft_exit_fail_msg("openat() error: Open first temporary file: Fail %d\n", errno); } + if (linkat(fd, "", AT_FDCWD, "/tmp/1", AT_EMPTY_PATH) == -1) { - fprintf(stderr, "error: linkat, errno %d\n", errno); - return 1; + ksft_exit_fail_msg("linkat() error: Linking the temporary file: Fail %d\n", errno); + /* Ensure fd is closed on failure */ + close(fd); } close(fd); fd = openat(AT_FDCWD, "/tmp", O_WRONLY|O_TMPFILE, 0600); if (fd == -1) { - fprintf(stderr, "error: open 2, errno %d\n", errno); - return 1; + ksft_exit_fail_msg("openat() error: Opening the second temporary file: Fail %d\n", errno); } + ksft_test_result_pass("Test : Success\n"); + ksft_exit_pass(); return 0; }