From patchwork Thu Jun 23 08:02:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avinesh Kumar X-Patchwork-Id: 1646923 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=SQeZ3YNP; dkim=fail reason="signature verification failed" header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=elvhLc0D; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=213.254.12.146; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LTCR10TNxz9sGT for ; Thu, 23 Jun 2022 18:02:37 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 131A73C952C for ; Thu, 23 Jun 2022 10:02:34 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-5.smtp.seeweb.it (in-5.smtp.seeweb.it [IPv6:2001:4b78:1:20::5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id BAAD23C9515 for ; Thu, 23 Jun 2022 10:02:23 +0200 (CEST) Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by in-5.smtp.seeweb.it (Postfix) with ESMTPS id CFF546005D2 for ; Thu, 23 Jun 2022 10:02:22 +0200 (CEST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 045E31FD48; Thu, 23 Jun 2022 08:02:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1655971342; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oAFBT5lZOPZHvsl8l7SbGABCEVu+WY93YoHRrBfvhAc=; b=SQeZ3YNPeYX5kbXjmNsTB+C4n4gkkYnXVHnsEBYM49NT04VG3jAY1NmGpGZLZ8f6cUSwLJ oT9Q0ajd/YzP15BDGZ1bE3w5auvn94U7YMr5f2fhVwIVySb2JUG9Tl008BigP6g3uC7Z/i hMT9cynIGAyhJfTWoiZJ1+CDHro4UdY= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1655971342; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oAFBT5lZOPZHvsl8l7SbGABCEVu+WY93YoHRrBfvhAc=; b=elvhLc0D1W3/VzBZBYfTuh73NzkWDM9eM7uRE8tgi0Z71NtyAuZU8+PS0xwZu/9lM/ZL6S d3BATF8cRA3B2JCQ== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 99517133A6; Thu, 23 Jun 2022 08:02:21 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id zPu2Gg0etGJcdgAAMHmgww (envelope-from ); Thu, 23 Jun 2022 08:02:21 +0000 From: Avinesh Kumar To: ltp@lists.linux.it Date: Thu, 23 Jun 2022 13:32:10 +0530 Message-Id: <20220623080215.24186-2-akumar@suse.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220623080215.24186-1-akumar@suse.de> References: <20220623080215.24186-1-akumar@suse.de> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.102.4 at in-5.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-5.smtp.seeweb.it Subject: [LTP] [PATCH v2 1/6] Rewrite utime01.c using new LTP API X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Signed-off-by: Avinesh Kumar Reviewed-by: Richard Palethorpe --- testcases/kernel/syscalls/utime/utime01.c | 263 +++++----------------- 1 file changed, 58 insertions(+), 205 deletions(-) diff --git a/testcases/kernel/syscalls/utime/utime01.c b/testcases/kernel/syscalls/utime/utime01.c index 1e6862515..2ce906751 100644 --- a/testcases/kernel/syscalls/utime/utime01.c +++ b/testcases/kernel/syscalls/utime/utime01.c @@ -1,223 +1,76 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* - * * Copyright (c) International Business Machines Corp., 2001 - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See - * the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * 07/2001 ported by John George + * Copyright (c) 2022 SUSE LLC Avinesh Kumar */ -/* - * Test Name: utime01 - * - * Test Description: - * Verify that the system call utime() successfully sets the modification - * and access times of a file to the current time, if the times argument - * is null, and the user ID of the process is "root". - * - * Expected Result: - * utime succeeds returning zero and sets the access and modification - * times of the file to the current time. - * - * Algorithm: - * Setup: - * Setup signal handling. - * Create temporary directory. - * Pause for SIGUSR1 if option specified. - * - * Test: - * Loop if the proper options are given. - * Execute system call - * Check return code, if system call failed (return=-1) - * Log the errno and Issue a FAIL message. - * Otherwise, - * Verify the Functionality of system call - * if successful, - * Issue Functionality-Pass message. - * Otherwise, - * Issue Functionality-Fail message. - * Cleanup: - * Print errno log and/or timing stats if options given - * Delete the temporary directory created. - * - * Usage: - * utime01 [-c n] [-e] [-f] [-i n] [-I x] [-p x] [-t] - * where, -c n : Run n copies concurrently. - * -e : Turn on errno logging. - * -f : Turn off functionality Testing. - * -i n : Execute test n times. - * -I x : Execute test for x seconds. - * -P x : Pause for x seconds between iterations. - * -t : Turn on syscall timing. - * - * History - * 07/2001 John George - * -Ported - * - * Restrictions: - * This test should be run by 'super-user' (root) only. +/*\ + * [Description] * + * Verify that the system call utime() successfully changes the last + * access and modification times of a file to the current time if the + * times argument is NULL and the user ID of the process is "root". */ -#include -#include -#include -#include -#include #include -#include -#include -#include -#include - -#include "test.h" -#include "safe_macros.h" - -#define TEMP_FILE "tmp_file" -#define FILE_MODE S_IRUSR | S_IRGRP | S_IROTH -char *TCID = "utime01"; -int TST_TOTAL = 1; -time_t curr_time; /* current time in seconds */ +#include "tst_test.h" +#include "tst_clocks.h" -void setup(); /* Main setup function of test */ -void cleanup(); /* cleanup function for the test */ +#define MNT_POINT "mntpoint" +#define TEMP_FILE MNT_POINT"/tmp_file" +#define FILE_MODE 0444 -int main(int ac, char **av) +static void setup(void) { - struct stat stat_buf; /* struct buffer to hold file info. */ - int lc; - long type; - time_t modf_time, access_time; - time_t pres_time; /* file modification/access/present time */ - - tst_parse_opts(ac, av, NULL, NULL); - - setup(); - - switch ((type = tst_fs_type(cleanup, "."))) { - case TST_NFS_MAGIC: - if (tst_kvercmp(2, 6, 18) < 0) - tst_brkm(TCONF, cleanup, "Cannot do utime on a file" - " on %s filesystem before 2.6.18", - tst_fs_type_name(type)); - break; - case TST_V9FS_MAGIC: - tst_brkm(TCONF, cleanup, - "Cannot do utime on a file on %s filesystem", - tst_fs_type_name(type)); - break; - } - - for (lc = 0; TEST_LOOPING(lc); lc++) { - - tst_count = 0; - - /* - * Invoke utime(2) to set TEMP_FILE access and - * modification times to the current time. - */ - TEST(utime(TEMP_FILE, NULL)); - - if (TEST_RETURN == -1) { - tst_resm(TFAIL|TTERRNO, "utime(%s) failed", TEMP_FILE); - } else { - /* - * Sleep for a second so that mod time and - * access times will be different from the - * current time - */ - sleep(2); - - /* - * Get the current time now, after calling - * utime(2) - */ - pres_time = time(NULL); - - /* - * Get the modification and access times of - * temporary file using stat(2). - */ - SAFE_STAT(cleanup, TEMP_FILE, &stat_buf); - modf_time = stat_buf.st_mtime; - access_time = stat_buf.st_atime; - - /* Now do the actual verification */ - if (modf_time <= curr_time || - modf_time >= pres_time || - access_time <= curr_time || - access_time >= pres_time) { - tst_resm(TFAIL, "%s access and " - "modification times not set", - TEMP_FILE); - } else { - tst_resm(TPASS, "Functionality of " - "utime(%s, NULL) successful", - TEMP_FILE); - } - } - tst_count++; - } - - cleanup(); - tst_exit(); + SAFE_TOUCH(TEMP_FILE, FILE_MODE, NULL); } -/* - * void - * setup() - performs all ONE TIME setup for this test. - * Create a temporary directory and change directory to it. - * Create a test file under temporary directory and close it - */ -void setup(void) +static void run(void) { - int fildes; /* file handle for temp file */ - - tst_require_root(); - - tst_sig(FORK, DEF_HANDLER, cleanup); - - TEST_PAUSE; - - tst_tmpdir(); - - /* Creat a temporary file under above directory */ - fildes = SAFE_CREAT(cleanup, TEMP_FILE, FILE_MODE); - - /* Close the temporary file created */ - SAFE_CLOSE(cleanup, fildes); - - /* Get the current time */ - curr_time = time(NULL); - - /* - * Sleep for a second so that mod time and access times will be - * different from the current time - */ - sleep(2); /* sleep(1) on IA64 sometimes sleeps < 1 sec!! */ + struct utimbuf utbuf; + struct stat stat_buf; + time_t pre_time, post_time; + + utbuf.modtime = tst_get_fs_timestamp() - 5; + utbuf.actime = utbuf.modtime + 1; + TST_EXP_PASS_SILENT(utime(TEMP_FILE, &utbuf)); + SAFE_STAT(TEMP_FILE, &stat_buf); + + TST_EXP_EQ_LI(stat_buf.st_atime, utbuf.actime); + TST_EXP_EQ_LI(stat_buf.st_mtime, utbuf.modtime); + + pre_time = tst_get_fs_timestamp(); + TST_EXP_PASS(utime(TEMP_FILE, NULL), "utime(%s, NULL)", TEMP_FILE); + if (!TST_PASS) + return; + post_time = tst_get_fs_timestamp(); + SAFE_STAT(TEMP_FILE, &stat_buf); + + if (stat_buf.st_mtime < pre_time || stat_buf.st_mtime > post_time) + tst_res(TFAIL, "utime() did not set expected mtime, " + "pre_time: %ld, post_time: %ld, st_mtime: %ld", + pre_time, post_time, stat_buf.st_mtime); + + if (stat_buf.st_atime < pre_time || stat_buf.st_atime > post_time) + tst_res(TFAIL, "utime() did not set expected atime, " + "pre_time: %ld, post_time: %ld, st_atime: %ld", + pre_time, post_time, stat_buf.st_atime); } -/* - * void - * cleanup() - performs all ONE TIME cleanup for this test at - * completion or premature exit. - * Remove the test directory and testfile created in the setup. - */ -void cleanup(void) -{ - - tst_rmdir(); - -} +static struct tst_test test = { + .test_all = run, + .setup = setup, + .needs_root = 1, + .needs_tmpdir = 1, + .mntpoint = MNT_POINT, + .mount_device = 1, + .all_filesystems = 1, + .skip_filesystems = (const char *const[]) { + "vfat", + "exfat", + NULL + } +}; From patchwork Thu Jun 23 08:02:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avinesh Kumar X-Patchwork-Id: 1646924 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=BYll4RSP; dkim=fail reason="signature verification failed" header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=L7xiYkRz; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=2001:1418:10:5::2; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LTCRL3PhQz9sGT for ; Thu, 23 Jun 2022 18:02:54 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 9164D3C954D for ; Thu, 23 Jun 2022 10:02:46 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-7.smtp.seeweb.it (in-7.smtp.seeweb.it [217.194.8.7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 1A4DC3C94E0 for ; Thu, 23 Jun 2022 10:02:25 +0200 (CEST) Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by in-7.smtp.seeweb.it (Postfix) with ESMTPS id 1EE61200ADF for ; Thu, 23 Jun 2022 10:02:24 +0200 (CEST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 943741FD43; Thu, 23 Jun 2022 08:02:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1655971344; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cyxq6j1ipDFcdsJVDpXx7hgRh3+yoOIwEgwrg6wX/rY=; b=BYll4RSPZaRlvSUbggPbeg5yyU5tFl113Hra7Eu4K7j6H86YJUqjttFtBRJz/RG3UIX/MX uciZzxt3DFu6MuqDVRJZyJF90W9kxKSjn9rZse5WrYLN8S2S2/mGoPF3ZTncNdkV1HtMBW NMAbSqgvUmag34maB/yQC+RhWcRBI5Y= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1655971344; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cyxq6j1ipDFcdsJVDpXx7hgRh3+yoOIwEgwrg6wX/rY=; b=L7xiYkRzxc6TUXyX8iBHuJJMFLaTMWNUFA4eogbUrM4wyhhquDzth97Ls/zFH47an4XS2v 2BLqoG8axmYwHCBQ== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 35499133A6; Thu, 23 Jun 2022 08:02:24 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 6xRzAhAetGJudgAAMHmgww (envelope-from ); Thu, 23 Jun 2022 08:02:24 +0000 From: Avinesh Kumar To: ltp@lists.linux.it Date: Thu, 23 Jun 2022 13:32:11 +0530 Message-Id: <20220623080215.24186-3-akumar@suse.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220623080215.24186-1-akumar@suse.de> References: <20220623080215.24186-1-akumar@suse.de> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.102.4 at in-7.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-7.smtp.seeweb.it Subject: [LTP] [PATCH v2 2/6] Rewrite utime02.c using new LTP API X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Signed-off-by: Avinesh Kumar Reviewed-by: Richard Palethorpe --- testcases/kernel/syscalls/utime/utime02.c | 283 ++++++---------------- 1 file changed, 68 insertions(+), 215 deletions(-) diff --git a/testcases/kernel/syscalls/utime/utime02.c b/testcases/kernel/syscalls/utime/utime02.c index 14d5e18c9..a145370e1 100644 --- a/testcases/kernel/syscalls/utime/utime02.c +++ b/testcases/kernel/syscalls/utime/utime02.c @@ -1,238 +1,91 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* - * * Copyright (c) International Business Machines Corp., 2001 - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See - * the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * 07/2001 ported by John George + * Copyright (c) 2022 SUSE LLC Avinesh Kumar */ -/* - * Test Name: utime02 - * - * Test Description: - * Verify that the system call utime() successfully sets the modification - * and access times of a file to the current time, under the following - * constraints, - * - The times argument is null. - * - The user ID of the process is not "root". - * - The file is owned by the user ID of the process. - * - * Expected Result: - * utime succeeds returning zero and sets the access and modification - * times of the file to the current time. - * - * Algorithm: - * Setup: - * Setup signal handling. - * Create temporary directory. - * Pause for SIGUSR1 if option specified. - * - * Test: - * Loop if the proper options are given. - * Execute system call - * Check return code, if system call failed (return=-1) - * Log the errno and Issue a FAIL message. - * Otherwise, - * Verify the Functionality of system call - * if successful, - * Issue Functionality-Pass message. - * Otherwise, - * Issue Functionality-Fail message. - * Cleanup: - * Print errno log and/or timing stats if options given - * Delete the temporary directory created. - * - * Usage: - * utime02 [-c n] [-e] [-f] [-i n] [-I x] [-p x] [-t] - * where, -c n : Run n copies concurrently. - * -e : Turn on errno logging. - * -f : Turn off functionality Testing. - * -i n : Execute test n times. - * -I x : Execute test for x seconds. - * -P x : Pause for x seconds between iterations. - * -t : Turn on syscall timing. - * - * History - * 07/2001 John George - * -Ported - * - * Restrictions: +/*\ + * [Description] * + * Verify that the system call utime() successfully changes the last + * access and modification times of a file to the current time, + * under the following constraints: + * - The times argument is NULL. + * - The user ID of the process is not "root". + * - The file is owned by the user ID of the process. */ -#include -#include -#include -#include -#include #include -#include -#include -#include #include -#include - -#include "test.h" -#include "safe_macros.h" -#define TEMP_FILE "tmp_file" -#define FILE_MODE S_IRUSR | S_IRGRP | S_IROTH +#include "tst_test.h" +#include "tst_clocks.h" -char *TCID = "utime02"; -int TST_TOTAL = 1; -time_t curr_time; /* current time in seconds */ - -char nobody_uid[] = "nobody"; -struct passwd *ltpuser; - -void setup(); /* Main setup function of test */ -void cleanup(); /* cleanup function for the test */ - -int main(int ac, char **av) -{ - struct stat stat_buf; /* struct buffer to hold file info. */ - int lc; - long type; - time_t modf_time, access_time; - time_t pres_time; /* file modification/access/present time */ - - tst_parse_opts(ac, av, NULL, NULL); - - setup(); - - switch ((type = tst_fs_type(cleanup, "."))) { - case TST_NFS_MAGIC: - if (tst_kvercmp(2, 6, 18) < 0) - tst_brkm(TCONF, cleanup, "Cannot do utime on a file" - " on %s filesystem before 2.6.18", - tst_fs_type_name(type)); - break; - case TST_V9FS_MAGIC: - tst_brkm(TCONF, cleanup, - "Cannot do utime on a file on %s filesystem", - tst_fs_type_name(type)); - break; - } +#define MNT_POINT "mntpoint" +#define TEMP_FILE MNT_POINT"/tmp_file" +#define FILE_MODE 0444 - for (lc = 0; TEST_LOOPING(lc); lc++) { - - tst_count = 0; - - /* - * Invoke utime(2) to set TEMP_FILE access and - * modification times to the current time. - */ - TEST(utime(TEMP_FILE, NULL)); - - if (TEST_RETURN == -1) { - tst_resm(TFAIL|TTERRNO, "utime(%s) failed", TEMP_FILE); - } else { - /* - * Sleep for a second so that mod time and - * access times will be different from the - * current time - */ - sleep(2); - - /* - * Get the current time now, after calling - * utime(2) - */ - pres_time = time(NULL); - - /* - * Get the modification and access times of - * temporary file using stat(2). - */ - SAFE_STAT(cleanup, TEMP_FILE, &stat_buf); - modf_time = stat_buf.st_mtime; - access_time = stat_buf.st_atime; - - /* Now do the actual verification */ - if (modf_time <= curr_time || - modf_time >= pres_time || - access_time <= curr_time || - access_time >= pres_time) { - tst_resm(TFAIL, "%s access and " - "modification times not set", - TEMP_FILE); - } else { - tst_resm(TPASS, "Functionality of " - "utime(%s, NULL) successful", - TEMP_FILE); - } - } - tst_count++; - } +#define TEST_USERNAME "nobody" - cleanup(); - tst_exit(); -} -/* - * void - * setup() - performs all ONE TIME setup for this test. - * Create a temporary directory and change directory to it. - * Create a test file under temporary directory and close it - */ -void setup(void) +static void setup(void) { - int fildes; /* file handle for temp file */ - - tst_require_root(); - - tst_sig(FORK, DEF_HANDLER, cleanup); - - /* Switch to nobody user for correct error code collection */ - ltpuser = SAFE_GETPWNAM(NULL, nobody_uid); - SAFE_SETUID(NULL, ltpuser->pw_uid); - - /* Pause if that option was specified - * TEST_PAUSE contains the code to fork the test with the -i option. - * You want to make sure you do this before you create your temporary - * directory. - */ - TEST_PAUSE; + struct passwd *pw; - tst_tmpdir(); + pw = SAFE_GETPWNAM(TEST_USERNAME); - /* Creat a temporary file under above directory */ - fildes = SAFE_CREAT(cleanup, TEMP_FILE, FILE_MODE); + SAFE_TOUCH(TEMP_FILE, FILE_MODE, NULL); + SAFE_CHOWN(TEMP_FILE, pw->pw_uid, pw->pw_gid); - /* Close the temporary file created */ - SAFE_CLOSE(cleanup, fildes); - - /* Get the current time */ - curr_time = time(NULL); - - /* - * Sleep for a second so that mod time and access times will be - * different from the current time - */ - sleep(2); /* sleep(1) on IA64 sometimes sleeps < 1 sec!! */ + tst_res(TINFO, "Switching effective user ID to user: %s", pw->pw_name); + SAFE_SETEUID(pw->pw_uid); } -/* - * void - * cleanup() - performs all ONE TIME cleanup for this test at - * completion or premature exit. - * Remove the test directory and testfile created in the setup. - */ -void cleanup(void) +static void run(void) { - - tst_rmdir(); - + struct utimbuf utbuf; + struct stat stat_buf; + time_t pre_time, post_time; + + utbuf.modtime = tst_get_fs_timestamp() - 5; + utbuf.actime = utbuf.modtime + 1; + TST_EXP_PASS_SILENT(utime(TEMP_FILE, &utbuf)); + SAFE_STAT(TEMP_FILE, &stat_buf); + + TST_EXP_EQ_LI(stat_buf.st_atime, utbuf.actime); + TST_EXP_EQ_LI(stat_buf.st_mtime, utbuf.modtime); + + pre_time = tst_get_fs_timestamp(); + TST_EXP_PASS(utime(TEMP_FILE, NULL), "utime(%s, NULL)", TEMP_FILE); + if (!TST_PASS) + return; + post_time = tst_get_fs_timestamp(); + SAFE_STAT(TEMP_FILE, &stat_buf); + + if (stat_buf.st_mtime < pre_time || stat_buf.st_mtime > post_time) + tst_res(TFAIL, "utime() did not set expected mtime, " + "pre_time: %ld, post_time: %ld, st_mtime: %ld", + pre_time, post_time, stat_buf.st_mtime); + + if (stat_buf.st_atime < pre_time || stat_buf.st_atime > post_time) + tst_res(TFAIL, "utime() did not set expected atime, " + "pre_time: %ld, post_time: %ld, st_atime: %ld", + pre_time, post_time, stat_buf.st_atime); } + +static struct tst_test test = { + .test_all = run, + .setup = setup, + .needs_root = 1, + .needs_tmpdir = 1, + .mntpoint = MNT_POINT, + .mount_device = 1, + .all_filesystems = 1, + .skip_filesystems = (const char *const[]) { + "vfat", + "exfat", + NULL + } +}; From patchwork Thu Jun 23 08:02:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avinesh Kumar X-Patchwork-Id: 1646925 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=fFSjE3KD; dkim=fail reason="signature verification failed" header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=wrMG8zzu; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=2001:1418:10:5::2; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LTCRS3xvNz9sGT for ; Thu, 23 Jun 2022 18:03:00 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id DDB5C3C01CC for ; Thu, 23 Jun 2022 10:02:57 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-6.smtp.seeweb.it (in-6.smtp.seeweb.it [217.194.8.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 41FFC3C954A for ; Thu, 23 Jun 2022 10:02:36 +0200 (CEST) Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by in-6.smtp.seeweb.it (Postfix) with ESMTPS id B3B8B1400E13 for ; Thu, 23 Jun 2022 10:02:34 +0200 (CEST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 0899321C09; Thu, 23 Jun 2022 08:02:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1655971354; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ins6M8IlnpUlQA938KhQZLbtjkqdAjGJHIyP+rRvvFs=; b=fFSjE3KDyCK37JAtdwD95JOPCAI7vV+XMVJmAsyb4XyupQlEiMKQETJT7E4Yqt5Z0rp6rd o502vk9DU96aSFPzUJdp0h32VKE0o3xbAapeZrItQQzjHPGvq82Vpi0WPAJBHC3LAEWjrQ zJXuBe9PAnyNpSEuaL62d5rhZMemFUA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1655971354; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ins6M8IlnpUlQA938KhQZLbtjkqdAjGJHIyP+rRvvFs=; b=wrMG8zzutw8sYACAytzresLIOOa8gPAuEpc0IhcPSExqon4wDBtOr3QGjmi1nnn43lwAnH 0oHRi+xiDQHSIsAA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 9BA05133A6; Thu, 23 Jun 2022 08:02:33 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id W/xSGxketGKAdgAAMHmgww (envelope-from ); Thu, 23 Jun 2022 08:02:33 +0000 From: Avinesh Kumar To: ltp@lists.linux.it Date: Thu, 23 Jun 2022 13:32:12 +0530 Message-Id: <20220623080215.24186-4-akumar@suse.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220623080215.24186-1-akumar@suse.de> References: <20220623080215.24186-1-akumar@suse.de> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.102.4 at in-6.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-6.smtp.seeweb.it Subject: [LTP] [PATCH v2 3/6] utime03.c: Remove unnecessary header includes X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Signed-off-by: Avinesh Kumar Reviewed-by: Richard Palethorpe --- testcases/kernel/syscalls/utime/utime03.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/testcases/kernel/syscalls/utime/utime03.c b/testcases/kernel/syscalls/utime/utime03.c index 2358fd70b..052846df3 100644 --- a/testcases/kernel/syscalls/utime/utime03.c +++ b/testcases/kernel/syscalls/utime/utime03.c @@ -18,10 +18,8 @@ * - The user ID of the process has write access to the file. */ -#include #include #include -#include #include #include "tst_test.h" From patchwork Thu Jun 23 08:02:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avinesh Kumar X-Patchwork-Id: 1646926 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=d1RBkK//; dkim=fail reason="signature verification failed" header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=0QXwOyXG; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=213.254.12.146; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LTCRh6YbYz9sGT for ; Thu, 23 Jun 2022 18:03:12 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id B2F3D3C9593 for ; Thu, 23 Jun 2022 10:03:10 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-2.smtp.seeweb.it (in-2.smtp.seeweb.it [IPv6:2001:4b78:1:20::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 273A03C9539 for ; Thu, 23 Jun 2022 10:02:38 +0200 (CEST) Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by in-2.smtp.seeweb.it (Postfix) with ESMTPS id 4C95460073E for ; Thu, 23 Jun 2022 10:02:36 +0200 (CEST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 950AA1FD43; Thu, 23 Jun 2022 08:02:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1655971356; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MdPY1YhfMouwEUlCWFE3OOvOcGLtj3uLl1uAZdAC5C0=; b=d1RBkK//sjW4ZFXZ4YiP4+8xFc3tkP/dhSBH5Y6ZUHQjXFndGPtOlT3AEU7x9n6hxjpQug Yw8GlvRCO3TYHXlfQ9enw2HfH12tSvE2/OUMP1F1UDspgqjIexmlDlVp5zcmYDIJ2JKWct Z7dgSbOJ8yIPjGUR/oddUIXbVPZdOEE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1655971356; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MdPY1YhfMouwEUlCWFE3OOvOcGLtj3uLl1uAZdAC5C0=; b=0QXwOyXG+U2yI7n3Jegw20oZaLW0FseOc+036DCVgHDnEUq9r/WgKIkgVfDSXMWWq+AFFy BnyBOJm3TNWYiDCA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 36399133A6; Thu, 23 Jun 2022 08:02:36 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id ujaKAhwetGKKdgAAMHmgww (envelope-from ); Thu, 23 Jun 2022 08:02:36 +0000 From: Avinesh Kumar To: ltp@lists.linux.it Date: Thu, 23 Jun 2022 13:32:13 +0530 Message-Id: <20220623080215.24186-5-akumar@suse.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220623080215.24186-1-akumar@suse.de> References: <20220623080215.24186-1-akumar@suse.de> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.102.4 at in-2.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-2.smtp.seeweb.it Subject: [LTP] [PATCH v2 4/6] Rewrite utime04.c using new LTP API X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Signed-off-by: Avinesh Kumar --- testcases/kernel/syscalls/utime/utime04.c | 203 ++++------------------ 1 file changed, 34 insertions(+), 169 deletions(-) diff --git a/testcases/kernel/syscalls/utime/utime04.c b/testcases/kernel/syscalls/utime/utime04.c index 5253f768a..84558d762 100644 --- a/testcases/kernel/syscalls/utime/utime04.c +++ b/testcases/kernel/syscalls/utime/utime04.c @@ -1,190 +1,55 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* - * * Copyright (c) International Business Machines Corp., 2001 - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See - * the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * 07/2001 ported by John George + * Copyright (c) 2022 SUSE LLC Avinesh Kumar */ -/* - * Test Name: utime04 - * - * Test Description: - * Verify that the system call utime() successfully sets the modification - * and access times of a file to the time specified by times argument, if - * the times argument is not null, and the user ID of the process is "root". - * - * Expected Result: - * utime succeeds returning zero and sets the access and modification - * times of the file to that specified by the times argument. - * - * Algorithm: - * Setup: - * Setup signal handling. - * Create temporary directory. - * Pause for SIGUSR1 if option specified. - * - * Test: - * Loop if the proper options are given. - * Execute system call - * Check return code, if system call failed (return=-1) - * Log the errno and Issue a FAIL message. - * Otherwise, - * Verify the Functionality of system call - * if successful, - * Issue Functionality-Pass message. - * Otherwise, - * Issue Functionality-Fail message. - * Cleanup: - * Print errno log and/or timing stats if options given - * Delete the temporary directory created. - * - * Usage: - * utime04 [-c n] [-e] [-f] [-i n] [-I x] [-p x] [-t] - * where, -c n : Run n copies concurrently. - * -e : Turn on errno logging. - * -f : Turn off functionality Testing. - * -i n : Execute test n times. - * -I x : Execute test for x seconds. - * -P x : Pause for x seconds between iterations. - * -t : Turn on syscall timing. - * - * History - * 07/2001 John George - * -Ported - * - * Restrictions: - * This test should be run by 'super-user' (root) only. +/*\ + * [Description] * + * Verify that the system call utime() successfully changes the last + * access and modification times of a file to the values specified by + * times argument, under the following constraints: + * - The times argument is not NULL. + * - The user ID of the process is "root". */ -#include -#include -#include -#include -#include #include -#include -#include -#include - -#include "test.h" -#include "safe_macros.h" +#include "tst_test.h" #define TEMP_FILE "tmp_file" -#define FILE_MODE S_IRUSR | S_IRGRP | S_IROTH -#define NEW_TIME 10000 - -char *TCID = "utime04"; -int TST_TOTAL = 1; +#define FILE_MODE 0444 +#define NEW_MODF_TIME 10000 +#define NEW_ACCESS_TIME 20000 -struct utimbuf times; /* struct. buffer for utime() */ +static struct utimbuf times = { + .modtime = NEW_MODF_TIME, + .actime = NEW_ACCESS_TIME +}; -void setup(); /* Main setup function of test */ -void cleanup(); /* cleanup function for the test */ - -int main(int ac, char **av) +static void setup(void) { - struct stat stat_buf; /* struct buffer to hold file info. */ - int lc; - time_t modf_time, access_time; - /* file modification/access time */ - - tst_parse_opts(ac, av, NULL, NULL); - - setup(); - - for (lc = 0; TEST_LOOPING(lc); lc++) { - - tst_count = 0; - - /* - * Invoke utime(2) to set TEMP_FILE access and - * modification times to that specified by - * times argument. - */ - TEST(utime(TEMP_FILE, ×)); - - if (TEST_RETURN == -1) { - tst_resm(TFAIL|TTERRNO, "utime(%s) failed", TEMP_FILE); - } else { - /* - * Get the modification and access times of - * temporary file using stat(2). - */ - SAFE_STAT(cleanup, TEMP_FILE, &stat_buf); - modf_time = stat_buf.st_mtime; - access_time = stat_buf.st_atime; - - /* Now do the actual verification */ - if ((modf_time != NEW_TIME) || - (access_time != NEW_TIME)) { - tst_resm(TFAIL, "%s access and " - "modification times not set", - TEMP_FILE); - } else { - tst_resm(TPASS, "Functionality of " - "utime(%s, ×) successful", - TEMP_FILE); - } - } - tst_count++; /* incr TEST_LOOP counter */ - } - - cleanup(); - tst_exit(); + SAFE_TOUCH(TEMP_FILE, FILE_MODE, NULL); } -/* - * void - * setup() - performs all ONE TIME setup for this test. - * Create a temporary directory and change directory to it. - * Create a test file under temporary directory and close it - */ -void setup(void) +static void run(void) { - int fildes; /* file handle for temp file */ - - tst_require_root(); - - tst_sig(NOFORK, DEF_HANDLER, cleanup); + struct stat stat_buf; - TEST_PAUSE; + TST_EXP_PASS(utime(TEMP_FILE, ×), "utime(%s, ×)", TEMP_FILE); + if (!TST_PASS) + return; - tst_tmpdir(); - - /* Creat a temporary file under above directory */ - fildes = SAFE_CREAT(cleanup, TEMP_FILE, FILE_MODE); - - /* Close the temporary file created */ - SAFE_CLOSE(cleanup, fildes); - - /* Initialize the modification and access time in the times arg */ - times.actime = NEW_TIME; - times.modtime = NEW_TIME; + SAFE_STAT(TEMP_FILE, &stat_buf); + TST_EXP_EQ_LI(stat_buf.st_mtime, NEW_MODF_TIME); + TST_EXP_EQ_LI(stat_buf.st_atime, NEW_ACCESS_TIME); } -/* - * void - * cleanup() - performs all ONE TIME cleanup for this test at - * completion or premature exit. - * Remove the test directory and testfile created in the setup. - */ -void cleanup(void) -{ - - tst_rmdir(); - -} +static struct tst_test test = { + .test_all = run, + .setup = setup, + .needs_root = 1, + .needs_tmpdir = 1 +}; From patchwork Thu Jun 23 08:02:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avinesh Kumar X-Patchwork-Id: 1646927 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=qrsFUQpo; dkim=fail reason="signature verification failed" header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=yDe/g1ES; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=2001:1418:10:5::2; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LTCRx63j0z9sGT for ; Thu, 23 Jun 2022 18:03:25 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 08D993C959C for ; Thu, 23 Jun 2022 10:03:23 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-3.smtp.seeweb.it (in-3.smtp.seeweb.it [217.194.8.3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 03E7B3C9564 for ; Thu, 23 Jun 2022 10:02:41 +0200 (CEST) Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by in-3.smtp.seeweb.it (Postfix) with ESMTPS id EFE911A00A5E for ; Thu, 23 Jun 2022 10:02:39 +0200 (CEST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 306CC21C09; Thu, 23 Jun 2022 08:02:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1655971359; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/7vc98AWe++Klm3+ivHonmgQhyEB30zqrBVteXb4Ypc=; b=qrsFUQpoetLnMDXTIcXyTTAp4jvdyUIJte4PjJVIDFFfz0Ga2OxVQlM1xT4g8XZRiTZGQt JMFPOUNYN9iuv5XAvqOy29UNCA1DZ8eqQ7n8LdGvIm+f6IjcHjYeqM7bOLa04g9LnV0foa E97ra12ltr9qZU5sHqlfQTY2ggZ+IKA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1655971359; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/7vc98AWe++Klm3+ivHonmgQhyEB30zqrBVteXb4Ypc=; b=yDe/g1ESaPqAeXu52jg4odKJgzdk+ElCDUYZqXfu/TdtHe+q+129KM7fxd6f4/rlq9Rayk gOsnKTlr6F0ZmaDg== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id C5C39133A6; Thu, 23 Jun 2022 08:02:38 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 3d23JR4etGKXdgAAMHmgww (envelope-from ); Thu, 23 Jun 2022 08:02:38 +0000 From: Avinesh Kumar To: ltp@lists.linux.it Date: Thu, 23 Jun 2022 13:32:14 +0530 Message-Id: <20220623080215.24186-6-akumar@suse.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220623080215.24186-1-akumar@suse.de> References: <20220623080215.24186-1-akumar@suse.de> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.102.4 at in-3.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-3.smtp.seeweb.it Subject: [LTP] [PATCH v2 5/6] Rewrite utime05.c using new LTP API X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Signed-off-by: Avinesh Kumar --- testcases/kernel/syscalls/utime/utime05.c | 213 ++++------------------ 1 file changed, 40 insertions(+), 173 deletions(-) diff --git a/testcases/kernel/syscalls/utime/utime05.c b/testcases/kernel/syscalls/utime/utime05.c index b2d2450bf..ad035330c 100644 --- a/testcases/kernel/syscalls/utime/utime05.c +++ b/testcases/kernel/syscalls/utime/utime05.c @@ -1,200 +1,67 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* - * * Copyright (c) International Business Machines Corp., 2001 - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See - * the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * 07/2001 ported by John George + * Copyright (c) 2022 SUSE LLC Avinesh Kumar */ -/* - * Test Name: utime05 - * - * Test Description: - * Verify that the system call utime() successfully sets the modification - * and access times of a file to the value specified by the times argument - * under the following constraints, - * - The times argument is not null, - * - The user ID of the process is not "root". - * - The file is owned by the user ID of the process. - * - * Expected Result: - * utime succeeds returning zero and sets the access and modification - * times of the file to that specified by the times argument. - * - * Algorithm: - * Setup: - * Setup signal handling. - * Create temporary directory. - * Pause for SIGUSR1 if option specified. - * - * Test: - * Loop if the proper options are given. - * Execute system call - * Check return code, if system call failed (return=-1) - * Log the errno and Issue a FAIL message. - * Otherwise, - * Verify the Functionality of system call - * if successful, - * Issue Functionality-Pass message. - * Otherwise, - * Issue Functionality-Fail message. - * Cleanup: - * Print errno log and/or timing stats if options given - * Delete the temporary directory created. - * - * Usage: - * utime05 [-c n] [-e] [-f] [-i n] [-I x] [-p x] [-t] - * where, -c n : Run n copies concurrently. - * -e : Turn on errno logging. - * -f : Turn off functionality Testing. - * -i n : Execute test n times. - * -I x : Execute test for x seconds. - * -P x : Pause for x seconds between iterations. - * -t : Turn on syscall timing. - * - * History - * 07/2001 John George - * -Ported - * - * Restrictions: +/*\ + * [Description] * + * Verify that the system call utime() successfully changes the last + * access and modification times of a file to the values specified by + * times argument, under the following constraints: + * - The times argument is not NULL. + * - The user ID of the process is not "root". + * - The file is owned by the user ID of the process. */ -#include -#include -#include -#include -#include #include -#include -#include -#include #include -#include "test.h" -#include "safe_macros.h" +#include "tst_test.h" #define TEMP_FILE "tmp_file" -#define FILE_MODE S_IRUSR | S_IRGRP | S_IROTH -#define NEW_TIME 10000 - -char *TCID = "utime05"; -int TST_TOTAL = 1; +#define FILE_MODE 0444 +#define NEW_MODF_TIME 10000 +#define NEW_ACCESS_TIME 20000 -char nobody_uid[] = "nobody"; -struct passwd *ltpuser; +#define TEST_USERNAME "nobody" -struct utimbuf times; /* struct. buffer for utime() */ +static struct utimbuf times = { + .modtime = NEW_MODF_TIME, + .actime = NEW_ACCESS_TIME +}; -void setup(); /* Main setup function of test */ -void cleanup(); /* cleanup function for the test */ - -int main(int ac, char **av) +static void setup(void) { - struct stat stat_buf; /* struct buffer to hold file info. */ - int lc; - time_t modf_time, access_time; - /* file modification/access time */ - - tst_parse_opts(ac, av, NULL, NULL); - - setup(); - - for (lc = 0; TEST_LOOPING(lc); lc++) { + struct passwd *pw; - tst_count = 0; + pw = SAFE_GETPWNAM(TEST_USERNAME); - /* - * Invoke utime(2) to set TEMP_FILE access and - * modification times to that specified by - * times argument. - */ - TEST(utime(TEMP_FILE, ×)); + tst_res(TINFO, "Switching effective user ID to user: %s", pw->pw_name); + SAFE_SETEUID(pw->pw_uid); - if (TEST_RETURN == -1) { - tst_resm(TFAIL|TTERRNO, "utime(%s) failed", TEMP_FILE); - } else { - /* - * Get the modification and access times of - * temporary file using stat(2). - */ - SAFE_STAT(cleanup, TEMP_FILE, &stat_buf); - modf_time = stat_buf.st_mtime; - access_time = stat_buf.st_atime; - - /* Now do the actual verification */ - if ((modf_time != NEW_TIME) || - (access_time != NEW_TIME)) { - tst_resm(TFAIL, "%s access and " - "modification times not set", - TEMP_FILE); - } else { - tst_resm(TPASS, "Functionality of " - "utime(%s, ×) successful", - TEMP_FILE); - } - } - tst_count++; /* incr TEST_LOOP counter */ - } - - cleanup(); - tst_exit(); + SAFE_TOUCH(TEMP_FILE, FILE_MODE, NULL); } -/* - * void - * setup() - performs all ONE TIME setup for this test. - * Create a temporary directory and change directory to it. - * Create a test file under temporary directory and close it - */ -void setup(void) +static void run(void) { - int fildes; /* file handle for temp file */ - - tst_require_root(); - - tst_sig(FORK, DEF_HANDLER, cleanup); - - /* Switch to nobody user for correct error code collection */ - ltpuser = SAFE_GETPWNAM(NULL, nobody_uid); - SAFE_SETUID(NULL, ltpuser->pw_uid); - - TEST_PAUSE; + struct stat stat_buf; - tst_tmpdir(); + TST_EXP_PASS(utime(TEMP_FILE, ×), "utime(%s, ×)", TEMP_FILE); + if (!TST_PASS) + return; - /* Creat a temporary file under above directory */ - fildes = SAFE_CREAT(cleanup, TEMP_FILE, FILE_MODE); - - /* Close the temporary file created */ - SAFE_CLOSE(cleanup, fildes); - - /* Initialize the modification and access time in the times arg */ - times.actime = NEW_TIME; - times.modtime = NEW_TIME; + SAFE_STAT(TEMP_FILE, &stat_buf); + TST_EXP_EQ_LI(stat_buf.st_mtime, NEW_MODF_TIME); + TST_EXP_EQ_LI(stat_buf.st_atime, NEW_ACCESS_TIME); } -/* - * void - * cleanup() - performs all ONE TIME cleanup for this test at - * completion or premature exit. - * Remove the test directory and testfile created in the setup. - */ -void cleanup(void) -{ - - tst_rmdir(); - -} +static struct tst_test test = { + .test_all = run, + .setup = setup, + .needs_root = 1, + .needs_tmpdir = 1 +}; From patchwork Thu Jun 23 08:02:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avinesh Kumar X-Patchwork-Id: 1646928 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=xj/HNs9L; dkim=fail reason="signature verification failed" header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=k8VfUKat; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=2001:1418:10:5::2; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LTCS76V1tz9sGT for ; Thu, 23 Jun 2022 18:03:35 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 599C53C9544 for ; Thu, 23 Jun 2022 10:03:33 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-7.smtp.seeweb.it (in-7.smtp.seeweb.it [217.194.8.7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 7AE2F3C9582 for ; Thu, 23 Jun 2022 10:02:43 +0200 (CEST) Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by in-7.smtp.seeweb.it (Postfix) with ESMTPS id 6C608200ACA for ; Thu, 23 Jun 2022 10:02:42 +0200 (CEST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id C01A31FD43; Thu, 23 Jun 2022 08:02:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1655971361; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FMq/34OpgOCxDSTmXLxeTx/npNIx87tZGCIcLbe9d0g=; b=xj/HNs9LwR3zmrfYNxe+eRQI4TBqyWO1VBGoKmEQxZxWf9mnuUBhaN0EqJTFwZDpxXigwn tx4YBxGSHfV5L2WY9I5F/98JWM+RvGw3pEm4I/D2Xi6wBGhHCHJVtSanm7VLQR9JOO9DJB 30uX0b67bM78vAvj6JZy2ufaRqEhGOE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1655971361; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FMq/34OpgOCxDSTmXLxeTx/npNIx87tZGCIcLbe9d0g=; b=k8VfUKat8/4uMH6DOzHFN0RXHcw/Ku4g+dHjSqCJDjd8G134QlGyxLpS1yM0gZI44QiwRj GBUA3t0a3Y55K+BQ== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 626C7133A6; Thu, 23 Jun 2022 08:02:41 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id +YpxDSEetGKcdgAAMHmgww (envelope-from ); Thu, 23 Jun 2022 08:02:41 +0000 From: Avinesh Kumar To: ltp@lists.linux.it Date: Thu, 23 Jun 2022 13:32:15 +0530 Message-Id: <20220623080215.24186-7-akumar@suse.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220623080215.24186-1-akumar@suse.de> References: <20220623080215.24186-1-akumar@suse.de> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.102.4 at in-7.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-7.smtp.seeweb.it Subject: [LTP] [PATCH v2 6/6] Rewrite utime06.c using new LTP API X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Signed-off-by: Avinesh Kumar Reviewed-by: Richard Palethorpe --- testcases/kernel/syscalls/utime/utime06.c | 188 +++++----------------- 1 file changed, 43 insertions(+), 145 deletions(-) diff --git a/testcases/kernel/syscalls/utime/utime06.c b/testcases/kernel/syscalls/utime/utime06.c index 6d80677e4..9057c29da 100644 --- a/testcases/kernel/syscalls/utime/utime06.c +++ b/testcases/kernel/syscalls/utime/utime06.c @@ -1,174 +1,72 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* - * Copyright (c) International Business Machines Corp., 2001 - * 07/2001 John George - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See - * the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Copyright (c) International Business Machines Corp., 2001 + * 07/2001 John George + * Copyright (c) 2022 SUSE LLC Avinesh Kumar */ -/* - * Test Description: - * 1. Verify that the system call utime() fails to set the modification - * and access times of a file to the current time, under the following - * constraints, - * - The times argument is null. - * - The user ID of the process is not "root". - * 2. Verify that the system call utime() fails to set the modification - * and access times of a file if the specified file doesn't exist. - * 3. Verify that the system call utime() fails to set the modification - * and access times of a file to the current time, under the following - * constraints, - * - The times argument is not null. - * - The user ID of the process is not "root". - * 4. Verify that the system call utime() fails to set the modification - * and access times of a file that resides on a read-only file system. +/*\ + * [Description] + * + * Verify that system call utime() fails with + * - EACCES when times argument is NULL and user does not have rights + * to modify the file. + * - ENOENT when specified file does not exist. + * - EPERM when times argument is not NULL and user does not have rights + * to modify the file. + * - EROFS when the path resides on a read-only filesystem. */ -#include -#include #include -#include -#include -#include -#include -#include #include -#include -#include -#include -#include -#include "test.h" -#include "safe_macros.h" +#include "tst_test.h" #define TEMP_FILE "tmp_file" #define MNT_POINT "mntpoint" +#define FILE_MODE 0644 +#define TEST_USERNAME "nobody" -char *TCID = "utime06"; -static struct passwd *ltpuser; static const struct utimbuf times; -static const char *dev; -static int mount_flag; -static void setup_nobody(void); -static void cleanup_nobody(void); -struct test_case_t { +static struct tcase { char *pathname; int exp_errno; - const struct utimbuf *times; - void (*setup_func)(void); - void (*cleanup_func)(void); -} Test_cases[] = { - {TEMP_FILE, EACCES, NULL, setup_nobody, cleanup_nobody}, - {"", ENOENT, NULL, NULL, NULL}, - {TEMP_FILE, EPERM, ×, setup_nobody, cleanup_nobody}, - {MNT_POINT, EROFS, NULL, NULL, NULL}, + const struct utimbuf *utimbuf; + char *err_desc; +} tcases[] = { + {TEMP_FILE, EACCES, NULL, "No write access"}, + {"", ENOENT, NULL, "File not exist"}, + {TEMP_FILE, EPERM, ×, "Not file owner"}, + {MNT_POINT, EROFS, NULL, "Read-only filesystem"} }; -int TST_TOTAL = ARRAY_SIZE(Test_cases); -static void setup(void); -static void utime_verify(const struct test_case_t *); -static void cleanup(void); - -int main(int ac, char **av) -{ - int lc; - int i; - - tst_parse_opts(ac, av, NULL, NULL); - - setup(); - - for (lc = 0; TEST_LOOPING(lc); lc++) { - tst_count = 0; - for (i = 0; i < TST_TOTAL; i++) - utime_verify(&Test_cases[i]); - } - - cleanup(); - tst_exit(); -} static void setup(void) { - const char *fs_type; - - tst_sig(NOFORK, DEF_HANDLER, cleanup); - - tst_require_root(); - - TEST_PAUSE; - - tst_tmpdir(); - - SAFE_TOUCH(cleanup, TEMP_FILE, 0644, NULL); + struct passwd *pw; - fs_type = tst_dev_fs_type(); - dev = tst_acquire_device(cleanup); - if (!dev) - tst_brkm(TCONF, cleanup, "Failed to acquire test device"); + SAFE_TOUCH(TEMP_FILE, FILE_MODE, NULL); - tst_mkfs(cleanup, dev, fs_type, NULL, NULL); - - SAFE_MKDIR(cleanup, MNT_POINT, 0644); - SAFE_MOUNT(cleanup, dev, MNT_POINT, fs_type, MS_RDONLY, NULL); - mount_flag = 1; - - ltpuser = SAFE_GETPWNAM(cleanup, "nobody"); -} - -static void utime_verify(const struct test_case_t *test) -{ - if (test->setup_func != NULL) - test->setup_func(); - - TEST(utime(test->pathname, test->times)); - - if (test->cleanup_func != NULL) - test->cleanup_func(); - - if (TEST_RETURN != -1) { - tst_resm(TFAIL, "utime succeeded unexpectedly"); - return; - } - - if (TEST_ERRNO == test->exp_errno) { - tst_resm(TPASS | TTERRNO, "utime failed as expected"); - } else { - tst_resm(TFAIL | TTERRNO, - "utime failed unexpectedly; expected: %d - %s", - test->exp_errno, strerror(test->exp_errno)); - } + pw = SAFE_GETPWNAM(TEST_USERNAME); + tst_res(TINFO, "Switching effective user ID to user: %s", pw->pw_name); + SAFE_SETEUID(pw->pw_uid); } -static void setup_nobody(void) +static void run(unsigned int i) { - SAFE_SETEUID(cleanup, ltpuser->pw_uid); -} + struct tcase *tc = &tcases[i]; -static void cleanup_nobody(void) -{ - SAFE_SETEUID(cleanup, 0); + TST_EXP_FAIL(utime(tc->pathname, tc->utimbuf), + tc->exp_errno, "%s", tc->err_desc); } -static void cleanup(void) -{ - if (mount_flag && tst_umount(MNT_POINT) < 0) - tst_resm(TWARN | TERRNO, "umount device:%s failed", dev); - - if (dev) - tst_release_device(dev); - - tst_rmdir(); -} +static struct tst_test test = { + .setup = setup, + .test = run, + .tcnt = ARRAY_SIZE(tcases), + .needs_root = 1, + .needs_tmpdir = 1, + .mntpoint = MNT_POINT, + .needs_rofs = 1 +};