From patchwork Mon Sep 10 13:23:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: subash X-Patchwork-Id: 968029 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=2001:1418:10:5::2; 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 [IPv6:2001:1418:10:5::2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4288014QGrz9s2P for ; Mon, 10 Sep 2018 23:24:17 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id E127E3E6295 for ; Mon, 10 Sep 2018 15:24:14 +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 [217.194.8.5]) by picard.linux.it (Postfix) with ESMTP id D0D223E602D for ; Mon, 10 Sep 2018 15:24:13 +0200 (CEST) Received: from mail.zilogic.com (mail.zilogic.com [45.33.14.236]) by in-5.smtp.seeweb.it (Postfix) with ESMTP id E5AF26013B5 for ; Mon, 10 Sep 2018 15:24:12 +0200 (CEST) Date: Mon, 10 Sep 2018 13:23:00 -0000 To: ltp@lists.linux.it Message-ID: <20180910132300.10853-1-subash@zilogic.com> From: "subash" Received: from localhost.localdomain (broadband.actcorp.in [106.51.154.17]) by mail.zilogic.com; Mon, 10 Sep 2018 13:23:16 -0000 X-Mailer: git-send-email 2.11.0 X-Virus-Scanned: clamav-milter 0.99.2 at in-5.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-5.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" * statx10.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 | 3 +- testcases/kernel/syscalls/statx/.gitignore | 3 +- testcases/kernel/syscalls/statx/statx10.c | 89 ++++++++++++++++++++++++++++++ 3 files changed, 93 insertions(+), 2 deletions(-) create mode 100644 testcases/kernel/syscalls/statx/statx10.c diff --git a/runtest/syscalls b/runtest/syscalls index 163acf948..815d42525 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -1506,4 +1506,5 @@ statx04 statx04 statx05 statx05 statx07 statx07 statx08 statx08 -statx09 statx09 \ No newline at end of file +statx09 statx09 +statx10 statx10 diff --git a/testcases/kernel/syscalls/statx/.gitignore b/testcases/kernel/syscalls/statx/.gitignore index 9c476d303..789309a54 100644 --- a/testcases/kernel/syscalls/statx/.gitignore +++ b/testcases/kernel/syscalls/statx/.gitignore @@ -5,4 +5,5 @@ /statx05 /statx07 /statx08 -/statx09 \ No newline at end of file +/statx09 +/statx10 \ No newline at end of file diff --git a/testcases/kernel/syscalls/statx/statx10.c b/testcases/kernel/syscalls/statx/statx10.c new file mode 100644 index 000000000..44c70238e --- /dev/null +++ b/testcases/kernel/syscalls/statx/statx10.c @@ -0,0 +1,89 @@ +//SPDX-License-Identifier:GPL-2.0-or-later +/* + * Copyright (c) Zilogic Systems Pvt. Ltd., 2018 + * Email : code@zilogic.com + */ + +/* + * Test case for statx10. + * + * 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 "lapi/stat.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, +};