All of lore.kernel.org
 help / color / mirror / Atom feed
From: chrubis@suse.cz
To: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
Cc: ltp-list <ltp-list@lists.sourceforge.net>
Subject: Re: [LTP] [PATCH] read/read02.c: add new error number tests
Date: Tue, 29 Apr 2014 18:31:37 +0200	[thread overview]
Message-ID: <20140429163137.GG12523@rei> (raw)
In-Reply-To: <1395991331.5017.4.camel@G08JYZSD130126>

Hi!
>  static struct test_case_t {
>  	int *fd;
> -	void *buf;
> +	void **buf;
> +	size_t count;
>  	int exp_error;
>  } TC[] = {
> -	{&badfd, buf, EBADF},
> -	{&fd2, buf, EISDIR},
> -	{&fd3, (void *)-1, EFAULT},
> +	{&badfd, (void **)&buf, 1, EBADF},
> +	{&fd2, (void **)&buf, 1, EISDIR},
> +	{&fd3, &outside_buf, 1, EFAULT},
> +	{&fd4, &addr4, 4096, EINVAL},
> +	{&fd4, &addr5, 1, EINVAL},
>  };
>  
>  int TST_TOTAL = ARRAY_SIZE(TC);
> @@ -89,6 +107,11 @@ int main(int ac, char **av)
>  
>  static void setup(void)
>  {
> +	if ((tst_kvercmp(2, 4, 10)) < 0)
> +		tst_brkm(TCONF, NULL, "This test needs kernel 2.4.10 or newer");

Linux 2.4.10 is from 2001 I would say that it's old enough so we can
expect that O_DIRECT is generally available.

> +	tst_require_root(NULL);

Does O_DIRECT require root?
(I haven't found anything in read man page that would suggests so)

>  	tst_sig(NOFORK, DEF_HANDLER, cleanup);
>  
>  	TEST_PAUSE;
> @@ -100,11 +123,19 @@ static void setup(void)
>  	SAFE_FILE_PRINTF(cleanup, TEST_FILE, "A");
>  
>  	fd3 = SAFE_OPEN(cleanup, TEST_FILE, O_RDWR | O_CREAT, 0666);
> +
> +	temp = SAFE_MALLOC(cleanup, 4096*10);
> +
> +	addr4 = (char *)(((long)buf & (~4095)) + 1);
> +	addr5 = (char *)((long)buf & (~4095));

You can allocate aligned buffer with memalign() instead.

> +	SAFE_FILE_PRINTF(cleanup, TEST_FILE4, "A");
> +	fd4 = SAFE_OPEN(cleanup, TEST_FILE4, O_RDWR | O_DIRECT, 0777);
>  }
>  
>  static void read_verify(const struct test_case_t *test)
>  {
> -	TEST(read(*test->fd, test->buf, 1));
> +	TEST(read(*test->fd, *test->buf, test->count));
>  
>  	if (TEST_RETURN != -1) {
>  		tst_resm(TFAIL, "call succeeded unexpectedly");
> @@ -127,6 +158,14 @@ static void cleanup(void)
>  {
>  	TEST_CLEANUP;
>  
> +	free(temp);
> +
> +	if (fd4 > 0)
> +		close(fd4);
> +
> +	if (unlink(TEST_FILE4) < 0)
> +		tst_resm(TWARN | TERRNO, "unlink(\"%s\") failed", TEST_FILE4);

There is no need to unlink files if you call tst_rmdir(). You only need
to close filedescriptors.

>  	if (fd3 > 0)
>  		close(fd3);
>  

-- 
Cyril Hrubis
chrubis@suse.cz

------------------------------------------------------------------------------
"Accelerate Dev Cycles with Automated Cross-Browser Testing - For FREE
Instantly run your Selenium tests across 300+ browser/OS combos.  Get 
unparalleled scalability from the best Selenium testing platform available.
Simple to use. Nothing to install. Get started now for free."
http://p.sf.net/sfu/SauceLabs
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

  reply	other threads:[~2014-04-29 16:32 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-28  7:20 [LTP] [PATCH] read/read02.c: cleanup Zeng Linggang
2014-03-28  7:22 ` [LTP] [PATCH] read/read02.c: add new error number tests Zeng Linggang
2014-04-29 16:31   ` chrubis [this message]
     [not found]     ` <1399262735.3177.14.camel@G08JYZSD130126>
2014-05-05 11:53       ` chrubis
     [not found]         ` <1399362493.3177.40.camel@G08JYZSD130126>
     [not found]           ` <1399362582.3177.41.camel@G08JYZSD130126>
2014-05-26 13:37             ` [LTP] [PATCH v2 1/3] SAFE_MACROS: Add memalign() chrubis
     [not found]           ` <1399362661.3177.43.camel@G08JYZSD130126>
2014-05-26 13:37             ` [LTP] [PATCH v2 2/3] read/read02.c: cleanup chrubis
     [not found]           ` <1399362721.3177.44.camel@G08JYZSD130126>
2014-05-26 13:39             ` [LTP] [PATCH v2 3/3] read/read02.c: add new error number tests chrubis
2014-05-26 13:44             ` chrubis
     [not found]               ` <1401171983.23078.0.camel@G08JYZSD130126>
2014-05-27 16:41                 ` [LTP] [PATCH] read/read02.c: fix skipping all testes on tmpfs chrubis
2014-04-29 16:10 ` [LTP] [PATCH] read/read02.c: cleanup 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=20140429163137.GG12523@rei \
    --to=chrubis@suse.cz \
    --cc=ltp-list@lists.sourceforge.net \
    --cc=zenglg.jy@cn.fujitsu.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.