public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Caspar Zhang <caspar@casparzhang.com>
To: Jan Stancek <jstancek@redhat.com>
Cc: ltp-list@lists.sourceforge.net
Subject: Re: [LTP] [PATCH 1/2] new syscall test: readahead01
Date: Thu, 16 Aug 2012 11:02:33 +0800	[thread overview]
Message-ID: <502C62C9.2040908@casparzhang.com> (raw)
In-Reply-To: <7fa9c1ccd34208d5b20d0438629639ab3ea70cae.1345032017.git.jstancek@redhat.com>

On 08/15/2012 08:03 PM, Jan Stancek wrote:
> errno testcase for readahead(2).
>
> Signed-off-by: Jan Stancek<jstancek@redhat.com>
> ---
>   testcases/kernel/syscalls/readahead/Makefile      |   22 +++
>   testcases/kernel/syscalls/readahead/readahead01.c |  161 +++++++++++++++++++++
>   2 files changed, 183 insertions(+), 0 deletions(-)
>   create mode 100644 testcases/kernel/syscalls/readahead/Makefile
>   create mode 100644 testcases/kernel/syscalls/readahead/readahead01.c
>
>
> 0001-new-syscall-test-readahead01.patch
>
>
> diff --git a/testcases/kernel/syscalls/readahead/Makefile b/testcases/kernel/syscalls/readahead/Makefile
> new file mode 100644
> index 0000000..45a3bbc
> --- /dev/null
> +++ b/testcases/kernel/syscalls/readahead/Makefile
> @@ -0,0 +1,22 @@
> +#
> +#  Copyright (C) 2012 Linux Test Project, Inc.
> +#
> +#  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
> +include $(top_srcdir)/include/mk/generic_leaf_target.mk
> diff --git a/testcases/kernel/syscalls/readahead/readahead01.c b/testcases/kernel/syscalls/readahead/readahead01.c
> new file mode 100644
> index 0000000..727dd7b
> --- /dev/null
> +++ b/testcases/kernel/syscalls/readahead/readahead01.c
> @@ -0,0 +1,161 @@
> +/*
> + * Copyright (C) 2012 Linux Test Project, Inc.
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of version 2 of the GNU General Public
> + * License as published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope that it would be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
> + *
> + * Further, this software is distributed without any warranty that it
> + * is free of the rightful claim of any third person regarding
> + * infringement or the like.  Any license provided herein, whether
> + * implied or otherwise, applies only to this software file.  Patent
> + * licenses, if any, provided herein do not apply to combinations of
> + * this program with other software, or any other product whatsoever.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, write the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
> + * 02110-1301, USA.
> + */
> +
> +/*
> + * errno tests for readahead() syscall
> + */
> +#include <sys/types.h>
> +#include <sys/stat.h>
> +#include <sys/syscall.h>
> +#include <sys/socket.h>
> +#include <errno.h>
> +#include <stdio.h>
> +#include <stdlib.h>
> +#include <unistd.h>
> +#include "config.h"
> +#include "test.h"
> +#include "usctest.h"
> +#include "safe_macros.h"
> +#include "linux_syscall_numbers.h"
> +
> +char *TCID = "readahead01";
> +int  TST_TOTAL = 1;
> +
> +#if defined(__NR_readahead)
> +static void setup(char *argv[]);
> +static void cleanup(void);
> +
> +static int check_ret(long expected_ret)
> +{
> +	if (expected_ret == TEST_RETURN) {
> +		tst_resm(TPASS, "expected ret success - "
> +			"returned value = %ld", TEST_RETURN);
> +		return 0;
> +	} else
> +		tst_resm(TFAIL, "unexpected failure - "
> +			"returned value = %ld, expected: %ld",
> +			TEST_RETURN, expected_ret);
> +	return 1;
> +}
> +
> +static int check_errno(long expected_errno)
> +{
> +	if (TEST_ERRNO == expected_errno) {
> +		tst_resm(TPASS|TTERRNO, "expected failure");
> +		return 0;
> +	} else if (TEST_ERRNO == 0)
> +		tst_resm(TFAIL, "call succeeded unexpectedly");
> +	else
> +		tst_resm(TFAIL|TTERRNO, "unexpected failure - "
> +			"expected = %ld : %s, actual",
> +			expected_errno, strerror(expected_errno));
> +	return 1;
> +}
> +
> +static void test_bad_fd()

should add "void" inside parentheses.

> +{
> +	char tempname[PATH_MAX] = "readahead01_XXXXXX";
> +	int fd;
> +
> +	tst_resm(TINFO, "test_bad_fd -1");
> +	TEST(syscall(__NR_readahead, -1, 0, getpagesize()));
> +	check_ret(-1);
> +	check_errno(EBADF);
> +
> +	tst_resm(TINFO, "test_bad_fd O_WRONLY");
> +	fd = mkstemp(tempname);
> +	if (fd == -1)
> +		tst_resm(TBROK|TERRNO, "mkstemp failed");
> +	close(fd);
> +	fd = open(tempname, O_WRONLY);
> +	if (fd == -1)
> +		tst_resm(TBROK|TERRNO, "Failed to open testfile");
> +	TEST(syscall(__NR_readahead, fd, 0, getpagesize()));
> +	check_ret(-1);
> +	check_errno(EBADF);
> +	close(fd);
> +	unlink(tempname);
> +}
> +
> +static void test_invalid_fd()
> +{
> +	int fd[2];
> +
> +	tst_resm(TINFO, "test_invalid_fd pipe");
> +	if (pipe(fd) < 0)
> +		tst_resm(TBROK|TERRNO, "Failed to create pipe");
> +	TEST(syscall(__NR_readahead, fd[0], 0, getpagesize()));
> +	check_ret(-1);
> +	check_errno(EINVAL);
> +	close(fd[0]);
> +	close(fd[1]);
> +
> +	tst_resm(TINFO, "test_invalid_fd socket");
> +	fd[0] = socket(AF_INET, SOCK_STREAM, 0);
> +	if (fd[0] < 0)
> +		tst_resm(TBROK|TERRNO, "Failed to create socket");
> +	TEST(syscall(__NR_readahead, fd[0], 0, getpagesize()));
> +	check_ret(-1);
> +	check_errno(EINVAL);
> +	close(fd[0]);
> +}
> +
> +int main(int argc, char *argv[])
> +{
> +	int lc;
> +
> +	setup(argv);
> +	for (lc = 0; TEST_LOOPING(lc); lc++) {
> +		Tst_count = 0;
> +		test_bad_fd();
> +		test_invalid_fd();
> +	}
> +	cleanup();
> +	tst_exit();
> +}
> +
> +static void setup(char *argv[])

Hmmm, I don't see where argv is used in setup() function...

Rest looks good to me, I think these are minor issues, so

Reviewed-by: Caspar Zhang <caspar@casparzhang.com>

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

  parent reply	other threads:[~2012-08-16  3:03 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-15 12:03 [LTP] [PATCH 1/2] new syscall test: readahead01 Jan Stancek
2012-08-15 12:04 ` [LTP] [PATCH 2/2] new syscall test: readahead02 Jan Stancek
2012-08-16  3:06   ` Caspar Zhang
2012-08-17  7:33     ` Jan Stancek
2012-10-04 11:33       ` chrubis
2012-10-04 14:25   ` chrubis
2012-08-16  3:02 ` Caspar Zhang [this message]
2012-10-04 14:18 ` [LTP] [PATCH 1/2] new syscall test: readahead01 chrubis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=502C62C9.2040908@casparzhang.com \
    --to=caspar@casparzhang.com \
    --cc=jstancek@redhat.com \
    --cc=ltp-list@lists.sourceforge.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox