From patchwork Tue Sep 4 08:01:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: subash X-Patchwork-Id: 965815 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) 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=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=zilogic.com Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 424K8y2H1Rz9sfN for ; Tue, 4 Sep 2018 18:03:46 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id AC63F3E7412 for ; Tue, 4 Sep 2018 10:03:21 +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]) by picard.linux.it (Postfix) with ESMTP id E23513E7082 for ; Tue, 4 Sep 2018 10:03:19 +0200 (CEST) Received: from mail.zilogic.com (mail.zilogic.com [45.33.14.236]) by in-3.smtp.seeweb.it (Postfix) with ESMTP id 2B2C71A01126 for ; Tue, 4 Sep 2018 10:03:17 +0200 (CEST) Date: Tue, 04 Sep 2018 08:01:52 -0000 To: ltp@lists.linux.it Message-ID: <20180904080152.22488-1-subash@zilogic.com> From: "subash" Received: from localhost.localdomain (broadband.actcorp.in [49.206.120.236]) by mail.zilogic.com; Tue, 04 Sep 2018 08:02:33 -0000 X-Mailer: git-send-email 2.11.0 X-Virus-Scanned: clamav-milter 0.99.2 at in-3.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.0 required=7.0 tests=MSGID_FROM_MTA_HEADER, SPF_PASS autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-3.smtp.seeweb.it Subject: [LTP] [PATCH v2 1/4] Testing statx syscall Timestamp fields X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.18 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" * statx_btime.c:The time before and after the execution of the create system call is noted. It is checked whether the birth time returned by statx lies in this range. Signed-off-by: Subash Signed-off-by: Vaishnavi.D --- runtest/syscalls | 2 + testcases/kernel/syscalls/statx/.gitignore | 2 + testcases/kernel/syscalls/statx/Makefile | 29 +++++++ testcases/kernel/syscalls/statx/statx_btime.c | 91 ++++++++++++++++++++++ testcases/kernel/syscalls/statx/timestamp_helper.c | 40 ++++++++++ testcases/kernel/syscalls/statx/timestamp_helper.h | 31 ++++++++ 6 files changed, 195 insertions(+) create mode 100644 testcases/kernel/syscalls/statx/.gitignore create mode 100644 testcases/kernel/syscalls/statx/Makefile create mode 100644 testcases/kernel/syscalls/statx/statx_btime.c create mode 100644 testcases/kernel/syscalls/statx/timestamp_helper.c create mode 100644 testcases/kernel/syscalls/statx/timestamp_helper.h diff --git a/runtest/syscalls b/runtest/syscalls index 3161d918d..048fb9cc4 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -1493,3 +1493,5 @@ memfd_create01 memfd_create01 memfd_create02 memfd_create02 copy_file_range01 copy_file_range01 + +statx_btime statx_btime diff --git a/testcases/kernel/syscalls/statx/.gitignore b/testcases/kernel/syscalls/statx/.gitignore new file mode 100644 index 000000000..4fb6f516f --- /dev/null +++ b/testcases/kernel/syscalls/statx/.gitignore @@ -0,0 +1,2 @@ +/timestamp_helper +/statx_btime \ No newline at end of file diff --git a/testcases/kernel/syscalls/statx/Makefile b/testcases/kernel/syscalls/statx/Makefile new file mode 100644 index 000000000..3a326423c --- /dev/null +++ b/testcases/kernel/syscalls/statx/Makefile @@ -0,0 +1,29 @@ +# Copyright (c) Zilogic Systems Pvt. Ltd., 2018 +# Email : code@zilogic.com +# +# 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 St, Fifth Floor, Boston, MA 02110-1301 USA +# + +top_srcdir ?= ../../../.. + +include $(top_srcdir)/include/mk/testcases.mk + +FILTER_OUT_MAKE_TARGETS := timestamp_helper + +%_64: CPPFLAGS += -D_FILE_OFFSET_BITS=64 + +include $(top_srcdir)/include/mk/generic_leaf_target.mk + +$(MAKE_TARGETS): %: %.o timestamp_helper.o diff --git a/testcases/kernel/syscalls/statx/statx_btime.c b/testcases/kernel/syscalls/statx/statx_btime.c new file mode 100644 index 000000000..47a40efa9 --- /dev/null +++ b/testcases/kernel/syscalls/statx/statx_btime.c @@ -0,0 +1,91 @@ +//SPDX-License-Identifier:GPL-2.0-or-later +/* + * Copyright (c) Zilogic Systems Pvt. Ltd., 2018 + * Email : code@zilogic.com + * + * 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. + */ + +/* + * Test case for statx_btime. + * + * DESCRIPTION : The time before and after the execution of the create + * system call is noted. It is checked whether the birth time + * returned by statx lies in this range. + * + */ + +#include +#include "tst_test.h" +#include "lapi/stat.h" +#include "tst_timer.h" +#include "tst_safe_macros.h" +#include +#include "timestamp_helper.h" + +#define MOUNT_POINT "mount_ext" +#define TEST_FILE MOUNT_POINT"/test_file.txt" + +static void create_file(void) +{ + int test_file_fd; + + test_file_fd = SAFE_CREAT(TEST_FILE, 0666); + SAFE_CLOSE(test_file_fd); +} + +static void test_statx_btime(void) +{ + struct statx buff; + struct timespec before_time; + struct timespec after_time; + struct timespec statx_time; + + SAFE_CLOCK_GETTIME(CLOCK_REALTIME_COARSE, &before_time); + clock_wait_tick(); + create_file(); + clock_wait_tick(); + SAFE_CLOCK_GETTIME(CLOCK_REALTIME_COARSE, &after_time); + + + TEST(statx(AT_FDCWD, TEST_FILE, 0, STATX_ALL, &buff)); + if (TST_RET != 0) + tst_brk(TFAIL | TTERRNO, + "statx(AT_FDCWD, %s, 0, STATX_ALL, &buff)", TEST_FILE); + + statx_timestamp_to_timespec(&buff.stx_btime, &statx_time); + + if (tst_timespec_lt(statx_time, before_time)) + tst_res(TFAIL, "Birth time < before time"); + else if (tst_timespec_lt(after_time, statx_time)) + tst_res(TFAIL, "Birth time > after_time"); + else + tst_res(TPASS, "Birth Time Passed\n"); + +} + +void cleanup(void) +{ + SAFE_UNLINK(TEST_FILE); +} + +static struct tst_test test = { + .test_all = test_statx_btime, + .min_kver = "4.11", + .needs_root = 1, + .needs_tmpdir = 1, + .mntpoint = MOUNT_POINT, + .mount_device = 1, + .dev_fs_type = "ext4", + .dev_min_size = 512, + .mnt_flags = MS_STRICTATIME, + .cleanup = cleanup, +}; diff --git a/testcases/kernel/syscalls/statx/timestamp_helper.c b/testcases/kernel/syscalls/statx/timestamp_helper.c new file mode 100644 index 000000000..6b12dfd26 --- /dev/null +++ b/testcases/kernel/syscalls/statx/timestamp_helper.c @@ -0,0 +1,40 @@ +//SPDX-License-Identifier:GPL-2.0-or-later +/* + * Copyright (c) Zilogic Systems Pvt. Ltd., 2018 + * Email: code@zilogic.com + * + * 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, see . + */ + +#define TST_NO_DEFAULT_MAIN + +#include "timestamp_helper.h" + +void statx_timestamp_to_timespec(const struct statx_timestamp *timestamp, + struct timespec *timespec) +{ + timespec->tv_sec = timestamp->tv_sec; + timespec->tv_nsec = timestamp->tv_nsec; +} + +void clock_wait_tick(void) +{ + struct timespec res; + unsigned int usecs; + + SAFE_CLOCK_GETRES(CLOCK_REALTIME_COARSE, &res); + usecs = ((res.tv_sec * 1000000) + (res.tv_nsec / 1000)) * 1.5; + + usleep(usecs); +} diff --git a/testcases/kernel/syscalls/statx/timestamp_helper.h b/testcases/kernel/syscalls/statx/timestamp_helper.h new file mode 100644 index 000000000..bb6794920 --- /dev/null +++ b/testcases/kernel/syscalls/statx/timestamp_helper.h @@ -0,0 +1,31 @@ +//SPDX-License-Identifier:GPL-2.0-or-later +/* + * Copyright (c) Zilogic Systems Pvt. Ltd., 2018 + * Email: code@zilogic.com + * + * 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, see . + */ + +#ifndef TIMESTAMP_HELPER +#define TIMESTAMP_HELPER + +#include +#include "lapi/stat.h" +#include "tst_test.h" +#include "tst_safe_macros.h" + +void statx_timestamp_to_timespec(const struct statx_timestamp *timestamp, + struct timespec *timespec); +void clock_wait_tick(void); +#endif From patchwork Tue Sep 4 08:03:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: subash X-Patchwork-Id: 965818 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) 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=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=zilogic.com Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 424K9k5c8Vz9sfN for ; Tue, 4 Sep 2018 18:04:26 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 47B0C3E7684 for ; Tue, 4 Sep 2018 10:04:24 +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]) by picard.linux.it (Postfix) with ESMTP id E16783E73C3 for ; Tue, 4 Sep 2018 10:04:18 +0200 (CEST) Received: from mail.zilogic.com (mail.zilogic.com [45.33.14.236]) by in-6.smtp.seeweb.it (Postfix) with ESMTP id 0C4B61401622 for ; Tue, 4 Sep 2018 10:04:17 +0200 (CEST) Date: Tue, 04 Sep 2018 08:03:03 -0000 To: ltp@lists.linux.it Message-ID: <20180904080303.22546-1-subash@zilogic.com> From: "subash" Received: from localhost.localdomain (broadband.actcorp.in [49.206.120.236]) by mail.zilogic.com; Tue, 04 Sep 2018 08:03:32 -0000 X-Mailer: git-send-email 2.11.0 X-Virus-Scanned: clamav-milter 0.99.2 at in-6.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.0 required=7.0 tests=MSGID_FROM_MTA_HEADER, SPF_PASS autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-6.smtp.seeweb.it Subject: [LTP] [PATCH v2 2/4] Testing statx syscall Timestamp fields X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.18 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" * statx_atime.c:The time before and after the execution of the read system call is noted. It is checked whether the access time returned by statx lies in this range. Signed-off-by: Subash Signed-off-by: Vaishnavi.D --- runtest/syscalls | 1 + testcases/kernel/syscalls/statx/.gitignore | 3 +- testcases/kernel/syscalls/statx/statx_atime.c | 96 +++++++++++++++++++++++++++ 3 files changed, 99 insertions(+), 1 deletion(-) create mode 100644 testcases/kernel/syscalls/statx/statx_atime.c diff --git a/runtest/syscalls b/runtest/syscalls index 048fb9cc4..6f5eb656a 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -1495,3 +1495,4 @@ memfd_create02 memfd_create02 copy_file_range01 copy_file_range01 statx_btime statx_btime +statx_atime statx_atime diff --git a/testcases/kernel/syscalls/statx/.gitignore b/testcases/kernel/syscalls/statx/.gitignore index 4fb6f516f..c5433d6bc 100644 --- a/testcases/kernel/syscalls/statx/.gitignore +++ b/testcases/kernel/syscalls/statx/.gitignore @@ -1,2 +1,3 @@ /timestamp_helper -/statx_btime \ No newline at end of file +/statx_btime +/statx_atime diff --git a/testcases/kernel/syscalls/statx/statx_atime.c b/testcases/kernel/syscalls/statx/statx_atime.c new file mode 100644 index 000000000..3e0ed8c2f --- /dev/null +++ b/testcases/kernel/syscalls/statx/statx_atime.c @@ -0,0 +1,96 @@ +//SPDX-License-Identifier:GPL-2.0-or-later +/* + * Copyright (c) Zilogic Systems Pvt. Ltd., 2018 + * Email : code@zilogic.com + * + * 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. + */ +/* + * Test case for statx_atime. + * + * DESCRIPTION : The time before and after the execution of the read + * system call is noted. It is checked whether the access time + * returned by statx lies in this range. + * + */ + +#include +#include "tst_test.h" +#include "tst_timer.h" +#include +#include "tst_safe_macros.h" +#include "timestamp_helper.h" + +#define MOUNT_POINT "mount_ext" +#define TEST_FILE MOUNT_POINT"/test_file.txt" +#define SIZE 2 + +static int test_file_fd; + +static void setup(void) +{ + test_file_fd = SAFE_OPEN(TEST_FILE, O_CREAT | O_RDWR, 0666); +} + +static void read_file(void) +{ + char data[SIZE]; + + SAFE_READ(0, test_file_fd, data, sizeof(data)); +} + +static void test_statx_atime(void) +{ + struct statx buff; + struct timespec before_time; + struct timespec after_time; + struct timespec statx_time; + + SAFE_CLOCK_GETTIME(CLOCK_REALTIME_COARSE, &before_time); + clock_wait_tick(); + read_file(); + clock_wait_tick(); + SAFE_CLOCK_GETTIME(CLOCK_REALTIME_COARSE, &after_time); + + TEST(statx(AT_FDCWD, TEST_FILE, 0, STATX_ALL, &buff)); + if (TST_RET != 0) + tst_brk(TFAIL | TTERRNO, + "statx(AT_FDCWD, %s, 0, STATX_ALL, &buff)", TEST_FILE); + + statx_timestamp_to_timespec(&buff.stx_atime, &statx_time); + + if (tst_timespec_lt(statx_time, before_time)) + tst_res(TFAIL, "Access time < before time"); + else if (tst_timespec_lt(after_time, statx_time)) + tst_res(TFAIL, "Access time > after_time"); + else + tst_res(TPASS, "Access Time Passed\n"); +} + +static void cleanup(void) +{ + SAFE_CLOSE(test_file_fd); + SAFE_UNLINK(TEST_FILE); +} + +static struct tst_test test = { + .setup = setup, + .cleanup = cleanup, + .test_all = test_statx_atime, + .min_kver = "4.11", + .needs_root = 1, + .needs_tmpdir = 1, + .mntpoint = MOUNT_POINT, + .mount_device = 1, + .dev_fs_type = "ext4", + .dev_min_size = 512, + .mnt_flags = MS_STRICTATIME, +}; From patchwork Tue Sep 4 08:03:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: subash X-Patchwork-Id: 965816 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) 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=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=zilogic.com Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 424K9g3SWWz9sfR for ; Tue, 4 Sep 2018 18:04:23 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 02C0E3E7429 for ; Tue, 4 Sep 2018 10:04:21 +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]) by picard.linux.it (Postfix) with ESMTP id D894F3E708E for ; Tue, 4 Sep 2018 10:04:18 +0200 (CEST) Received: from mail.zilogic.com (mail.zilogic.com [45.33.14.236]) by in-6.smtp.seeweb.it (Postfix) with ESMTP id 1A695140162E for ; Tue, 4 Sep 2018 10:04:17 +0200 (CEST) Date: Tue, 04 Sep 2018 08:03:57 -0000 To: ltp@lists.linux.it Message-ID: <20180904080357.22601-1-subash@zilogic.com> From: "subash" Received: from localhost.localdomain (broadband.actcorp.in [49.206.120.236]) by mail.zilogic.com; Tue, 04 Sep 2018 08:04:15 -0000 X-Mailer: git-send-email 2.11.0 X-Virus-Scanned: clamav-milter 0.99.2 at in-6.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.0 required=7.0 tests=MSGID_FROM_MTA_HEADER, SPF_PASS autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-6.smtp.seeweb.it Subject: [LTP] [PATCH v2 3/4] Testing statx syscall Timestamp fields X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.18 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" * statx_mtime.c:The time before and after the execution of the write system call is noted. It is checked whether the modification time returned by statx lies in this range. Signed-off-by: Subash Signed-off-by: Vaishnavi.D --- runtest/syscalls | 1 + testcases/kernel/syscalls/statx/.gitignore | 1 + testcases/kernel/syscalls/statx/statx_mtime.c | 97 +++++++++++++++++++++++++++ 3 files changed, 99 insertions(+) create mode 100644 testcases/kernel/syscalls/statx/statx_mtime.c diff --git a/runtest/syscalls b/runtest/syscalls index 6f5eb656a..eea045aac 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -1496,3 +1496,4 @@ copy_file_range01 copy_file_range01 statx_btime statx_btime statx_atime statx_atime +statx_mtime statx_mtime diff --git a/testcases/kernel/syscalls/statx/.gitignore b/testcases/kernel/syscalls/statx/.gitignore index c5433d6bc..c9aef59be 100644 --- a/testcases/kernel/syscalls/statx/.gitignore +++ b/testcases/kernel/syscalls/statx/.gitignore @@ -1,3 +1,4 @@ /timestamp_helper /statx_btime /statx_atime +/statx_mtime diff --git a/testcases/kernel/syscalls/statx/statx_mtime.c b/testcases/kernel/syscalls/statx/statx_mtime.c new file mode 100644 index 000000000..c3fb1ea40 --- /dev/null +++ b/testcases/kernel/syscalls/statx/statx_mtime.c @@ -0,0 +1,97 @@ +//SPDX-License-Identifier:GPL-2.0-or-later +/* + * Copyright (c) Zilogic Systems Pvt. Ltd., 2018 + * Email : code@zilogic.com + * + * 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. + */ +/* + * Test case for statx_mtime. + * + * DESCRIPTION : The time before and after the execution of the write + * system call is noted. It is checked whether the modified time + * returned by statx lies in this range. + * + */ + +#include +#include "tst_test.h" +#include "tst_timer.h" +#include +#include "tst_safe_macros.h" +#include "timestamp_helper.h" + +#define MOUNT_POINT "mount_ext" +#define TEST_FILE MOUNT_POINT"/test_file.txt" +#define SIZE 2 + +static int test_file_fd; + +static void setup(void) +{ + test_file_fd = SAFE_OPEN(TEST_FILE, O_CREAT | O_RDWR, 0666); +} + +static void write_file(void) +{ + char data[SIZE] = "hi"; + + SAFE_WRITE(0, test_file_fd, data, sizeof(data)); +} + +static void test_statx_mtime(void) +{ + struct statx buff; + struct timespec before_time; + struct timespec after_time; + struct timespec statx_time; + + + SAFE_CLOCK_GETTIME(CLOCK_REALTIME_COARSE, &before_time); + clock_wait_tick(); + write_file(); + clock_wait_tick(); + SAFE_CLOCK_GETTIME(CLOCK_REALTIME_COARSE, &after_time); + + TEST(statx(AT_FDCWD, TEST_FILE, 0, STATX_ALL, &buff)); + if (TST_RET != 0) + tst_brk(TFAIL | TTERRNO, + "statx(AT_FDCWD, %s, 0, STATX_ALL, &buff)", TEST_FILE); + + statx_timestamp_to_timespec(&buff.stx_mtime, &statx_time); + + if (tst_timespec_lt(statx_time, before_time)) + tst_res(TFAIL, "Modification time < before time"); + else if (tst_timespec_lt(after_time, statx_time)) + tst_res(TFAIL, "Modification time > after_time"); + else + tst_res(TPASS, "Modification time Passed\n"); +} + +static void cleanup(void) +{ + SAFE_CLOSE(test_file_fd); + SAFE_UNLINK(TEST_FILE); +} + +static struct tst_test test = { + .setup = setup, + .cleanup = cleanup, + .test_all = test_statx_mtime, + .min_kver = "4.11", + .needs_root = 1, + .needs_tmpdir = 1, + .mntpoint = MOUNT_POINT, + .mount_device = 1, + .dev_fs_type = "ext4", + .dev_min_size = 512, + .mnt_flags = MS_STRICTATIME, +}; From patchwork Tue Sep 4 08:04:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: subash X-Patchwork-Id: 965824 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) 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=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=zilogic.com Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 424KCG0gQgz9sfN for ; Tue, 4 Sep 2018 18:05:46 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 9E7EA3E7440 for ; Tue, 4 Sep 2018 10:05:22 +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 [IPv6:2001:4b78:1:20::7]) by picard.linux.it (Postfix) with ESMTP id 14FA43E73FE for ; Tue, 4 Sep 2018 10:05:20 +0200 (CEST) Received: from mail.zilogic.com (mail.zilogic.com [45.33.14.236]) by in-7.smtp.seeweb.it (Postfix) with ESMTP id 4A20B20100C for ; Tue, 4 Sep 2018 10:05:18 +0200 (CEST) Date: Tue, 04 Sep 2018 08:04:28 -0000 To: ltp@lists.linux.it Message-ID: <20180904080428.22656-1-subash@zilogic.com> From: "subash" Received: from localhost.localdomain (broadband.actcorp.in [49.206.120.236]) by mail.zilogic.com; Tue, 04 Sep 2018 08:04:43 -0000 X-Mailer: git-send-email 2.11.0 X-Virus-Scanned: clamav-milter 0.99.2 at in-7.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.0 required=7.0 tests=MSGID_FROM_MTA_HEADER, SPF_PASS autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-7.smtp.seeweb.it Subject: [LTP] [PATCH v2 4/4] Testing statx syscall Timestamp fields X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.18 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" * statx_ctime.c:The time before and after the execution of the chmod system call is noted. It is checked whether the status change time returned by statx lies in this range. Signed-off-by: Subash Signed-off-by: Vaishnavi.D --- runtest/syscalls | 1 + testcases/kernel/syscalls/statx/.gitignore | 1 + testcases/kernel/syscalls/statx/statx_ctime.c | 88 +++++++++++++++++++++++++++ 3 files changed, 90 insertions(+) create mode 100644 testcases/kernel/syscalls/statx/statx_ctime.c diff --git a/runtest/syscalls b/runtest/syscalls index eea045aac..7f7affe26 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -1497,3 +1497,4 @@ copy_file_range01 copy_file_range01 statx_btime statx_btime statx_atime statx_atime statx_mtime statx_mtime +statx_ctime statx_ctime diff --git a/testcases/kernel/syscalls/statx/.gitignore b/testcases/kernel/syscalls/statx/.gitignore index c9aef59be..dd2fa1ed2 100644 --- a/testcases/kernel/syscalls/statx/.gitignore +++ b/testcases/kernel/syscalls/statx/.gitignore @@ -2,3 +2,4 @@ /statx_btime /statx_atime /statx_mtime +/statx_ctime diff --git a/testcases/kernel/syscalls/statx/statx_ctime.c b/testcases/kernel/syscalls/statx/statx_ctime.c new file mode 100644 index 000000000..289d812a4 --- /dev/null +++ b/testcases/kernel/syscalls/statx/statx_ctime.c @@ -0,0 +1,88 @@ +//SPDX-License-Identifier:GPL-2.0-or-later +/* + * Copyright (c) Zilogic Systems Pvt. Ltd., 2018 + * Email : code@zilogic.com + * + * 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. + */ +/* + * Test case for statx_ctime. + * + * DESCRIPTION : The time before and after the execution of the chmod + * system call is noted. It is checked whether the status change + * time returned by statx lies in this range. + * + */ + +#include +#include "tst_test.h" +#include "tst_timer.h" +#include +#include "tst_safe_macros.h" +#include "timestamp_helper.h" + +#define MOUNT_POINT "mount_ext" +#define TEST_FILE MOUNT_POINT"/test_file.txt" + +static void setup(void) +{ + int test_file_fd; + + test_file_fd = SAFE_OPEN(TEST_FILE, O_CREAT | O_RDWR, 0666); + SAFE_CLOSE(test_file_fd); +} + +static void test_statx_ctime(void) +{ + struct statx buff; + struct timespec before_time; + struct timespec after_time; + struct timespec statx_time; + + SAFE_CLOCK_GETTIME(CLOCK_REALTIME_COARSE, &before_time); + clock_wait_tick(); + SAFE_CHMOD(TEST_FILE, 0777); + clock_wait_tick(); + SAFE_CLOCK_GETTIME(CLOCK_REALTIME_COARSE, &after_time); + + TEST(statx(AT_FDCWD, TEST_FILE, 0, STATX_ALL, &buff)); + if (TST_RET != 0) + tst_brk(TFAIL | TTERRNO, + "statx(AT_FDCWD, %s, 0, STATX_ALL, &buff)", TEST_FILE); + + statx_timestamp_to_timespec(&buff.stx_ctime, &statx_time); + + if (tst_timespec_lt(statx_time, before_time)) + tst_res(TFAIL, "Status change time < before time"); + else if (tst_timespec_lt(after_time, statx_time)) + tst_res(TFAIL, "Status change time > after_time"); + else + tst_res(TPASS, "Status change time Passed\n"); +} + +static void cleanup(void) +{ + SAFE_UNLINK(TEST_FILE); +} + +static struct tst_test test = { + .setup = setup, + .cleanup = cleanup, + .test_all = test_statx_ctime, + .min_kver = "4.11", + .needs_root = 1, + .needs_tmpdir = 1, + .mntpoint = MOUNT_POINT, + .mount_device = 1, + .dev_fs_type = "ext4", + .dev_min_size = 512, + .mnt_flags = MS_STRICTATIME, +};