From patchwork Mon Sep 3 12:17:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "vaishnavi.d" X-Patchwork-Id: 965399 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 423pss6Vrjz9s8F for ; Mon, 3 Sep 2018 22:18:57 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 5C71F3E7119 for ; Mon, 3 Sep 2018 14:18:55 +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 106513E70E1 for ; Mon, 3 Sep 2018 14:18:53 +0200 (CEST) Received: from mail.zilogic.com (mail.zilogic.com [45.33.14.236]) by in-6.smtp.seeweb.it (Postfix) with ESMTP id 3BCE81401139 for ; Mon, 3 Sep 2018 14:18:51 +0200 (CEST) Date: Mon, 03 Sep 2018 12:17:53 -0000 To: ltp@lists.linux.it Message-ID: <20180903121753.3756-1-vaishnavi.d@zilogic.com> From: "Vaishnavi D" Received: from localhost.localdomain (broadband.actcorp.in [183.83.50.50]) by mail.zilogic.com; Mon, 03 Sep 2018 12:18:10 -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 v7 3/4] Testing statx syscall 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" From: vaishnavid * stat03.c: This file will check error code(errno) by providing required input in statx argument syscall. The following errno are checked: EBADF, EBADF, ENAMETOOLONG, ENOENT, ENOTDIR, EFAULT. Signed-off-by: Tarun.T.U Signed-off-by: Vaishnavi.D --- runtest/syscalls | 3 +- testcases/kernel/syscalls/statx/.gitignore | 3 +- testcases/kernel/syscalls/statx/statx03.c | 134 +++++++++++++++++++++++++++++ 3 files changed, 138 insertions(+), 2 deletions(-) create mode 100644 testcases/kernel/syscalls/statx/statx03.c diff --git a/runtest/syscalls b/runtest/syscalls index 079c18fc7..554ebe63f 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -1497,4 +1497,5 @@ memfd_create04 memfd_create04 copy_file_range01 copy_file_range01 statx01 statx01 -statx02 statx02 \ No newline at end of file +statx02 statx02 +statx03 statx03 \ No newline at end of file diff --git a/testcases/kernel/syscalls/statx/.gitignore b/testcases/kernel/syscalls/statx/.gitignore index 1849891d6..067ac6493 100644 --- a/testcases/kernel/syscalls/statx/.gitignore +++ b/testcases/kernel/syscalls/statx/.gitignore @@ -1,2 +1,3 @@ /statx01 -/statx02 \ No newline at end of file +/statx02 +/statx03 \ No newline at end of file diff --git a/testcases/kernel/syscalls/statx/statx03.c b/testcases/kernel/syscalls/statx/statx03.c new file mode 100644 index 000000000..3c11f198e --- /dev/null +++ b/testcases/kernel/syscalls/statx/statx03.c @@ -0,0 +1,134 @@ +// 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 . + */ + +/* + * Test statx + * + * This code tests if expected error values are returned for specific cases by + * statx. + * The error cases are simulated and the return value is checked against + * expected error number value. + * The following error values are tested: + * 1) EBADF - Bad file descriptor + * 2) EFAULT - Bad address + * 3) EINVAL - Invalid argument + * 4) ENOENT - No such file or directory + * 5) ENOTDIR - Not a directory + * 6) ENAMETOOLONG - Filename too long + * + * Error scenario is simulated for each listed flag by passing + * respective arguments. + * The obtained error flag is checked against the expected + * flag value for that scenario. + * + * Minimum Kernel version required is 4.11. + */ +#include +#include +#include "tst_test.h" +#include "tst_safe_macros.h" +#include "tst_get_bad_addr.h" +#include "lapi/stat.h" + +#define TESTFILE "test_file" +#define MODE 0644 + +static int file_fd; +static char long_pathname[257]; + +static char *test_fname = TESTFILE; +static char *efault_fname; +static char *empty_fname = ""; +static char *etoolong_fname = long_pathname; + +static struct test_case { + uint32_t dfd; + char **filename; + uint32_t flag; + uint32_t mask; + int32_t errnum; +} tcases[] = { + {.dfd = -1, .filename = &test_fname, .flag = 0, + .mask = 0, .errnum = EBADF}, + + {.dfd = AT_FDCWD, .filename = &efault_fname, .flag = 0, + .mask = 0, .errnum = EFAULT}, + + {.dfd = AT_FDCWD, .filename = &test_fname, .flag = -1, + .mask = 0, .errnum = EINVAL}, + + {.dfd = AT_FDCWD, .filename = &test_fname, .flag = 0, + .mask = -1, .errnum = EINVAL}, + + {.dfd = AT_FDCWD, .filename = &empty_fname, .flag = 0, + .mask = 0, .errnum = ENOENT}, + + {.dfd = 1, .filename = &test_fname, .flag = 0, + .mask = 0, .errnum = ENOTDIR}, + + {.dfd = AT_FDCWD, .filename = &etoolong_fname, .flag = 0, + .mask = 0, .errnum = ENAMETOOLONG}, +}; + +static void run_test(unsigned int i) +{ + struct statx buf; + struct test_case *tc = &tcases[i]; + + TEST(statx(tc->dfd, *(tc->filename), tc->flag, + tc->mask, &buf)); + + if (TST_RET != -1) { + tst_res(TFAIL, "statx() returned with %ld", TST_RET); + return; + } + + if (tc->errnum == TST_ERR) { + tst_res(TPASS | TTERRNO, "statx() failed with"); + return; + } + + tst_res(TFAIL | TTERRNO, + "statx() should fail with %s", tst_strerrno(tc->errnum)); +} + +static void setup(void) +{ + file_fd = SAFE_OPEN(TESTFILE, O_RDWR | O_CREAT, MODE); + + memset(long_pathname, '@', sizeof(long_pathname)); + long_pathname[sizeof(long_pathname) - 1] = 0; + + efault_fname = tst_get_bad_addr(NULL); +} + +static void cleanup(void) +{ + if (file_fd > 0) + SAFE_CLOSE(file_fd); +} + +static struct tst_test test = { + .tcnt = ARRAY_SIZE(tcases), + .test = run_test, + .setup = setup, + .cleanup = cleanup, + .min_kver = "4.11", + .needs_tmpdir = 1, +};