public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Cyril Hrubis <chrubis@suse.cz>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v5] syscalls/fcntl36: add tests for OFD locks
Date: Wed, 23 Aug 2017 15:35:12 +0200	[thread overview]
Message-ID: <20170823133512.GA20766@rei.lan> (raw)
In-Reply-To: <1503494101-27530-1-git-send-email-xzhou@redhat.com>

Hi!
> +/* OFD write lock writing data*/
> +static void *fn_ofd_w(void *arg)
> +{
> +	unsigned char buf[write_size];
> +	struct param *pa = (struct param *)arg;
> +	int fd = SAFE_OPEN(fname, O_RDWR);
> +	long wt = pa->cnt;
> +
> +	struct flock64 lck = {
> +		.l_whence = SEEK_SET,
> +		.l_start  = pa->offset,
> +		.l_len    = pa->length,
> +		.l_pid    = 0,
> +	};
> +
> +	while (loop_flag) {
> +
> +		memset(buf, wt, write_size);
> +
> +		lck.l_type = F_WRLCK;
> +		SAFE_FCNTL(fd, F_OFD_SETLKW, &lck);
> +
> +		SAFE_LSEEK(fd, pa->offset, SEEK_SET);
> +		SAFE_WRITE(1, fd, buf, pa->length);

Just a minor note, we use both write_size and pa->length randomly here
and in all of the test functions. It would be a much cleaner to use only
pa->lenght instead.

> +/* Test different functions and verify data */
> +static void test_fn(void *f0(void *), void *f1(void *), const char *msg)
> +{
> +	int i, k, fd;
> +	pthread_t id0[thread_cnt];
> +	pthread_t id1[thread_cnt];
> +	struct param p0[thread_cnt];
> +	struct param p1[thread_cnt];
> +	unsigned char buf[write_size];
> +
> +	if (tst_fill_file(fname, 1, write_size, thread_cnt))
> +		tst_brk(TBROK, "Failed to create tst file");
> +
> +	tst_res(TINFO, msg);
> +
> +	for (i = 0; i < thread_cnt; i++) {
> +
> +		p0[i].offset = i * write_size;
> +		p0[i].length = write_size;
> +		p0[i].cnt = i + 2;
> +
> +		p1[i].offset = i * write_size;
> +		p1[i].offset += write_size / 2;
> +		p1[i].length = write_size;
> +		p1[i].cnt = i + 2;
> +	}

We should reset the fail_cnt here. And it would be safer to rename it to
fail_flag and set it to 1 on a failure because if we are terribly
unlucky the incements can overflow and we may as well end up with a
zero.

Otherwise it looks good.

-- 
Cyril Hrubis
chrubis@suse.cz

  reply	other threads:[~2017-08-23 13:35 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-11  3:14 [LTP] [PATCH] syscalls/fcntl36: add tests for OFD locks Xiong Zhou
2017-08-14 16:02 ` Cyril Hrubis
2017-08-21 11:17   ` [LTP] [PATCH v2] " Xiong Zhou
2017-08-21 16:00     ` Cyril Hrubis
2017-08-22  8:35       ` [LTP] [PATCH v3] " Xiong Zhou
2017-08-22 14:23         ` Cyril Hrubis
2017-08-23  4:15           ` Xiong Zhou
2017-08-23  8:40             ` Cyril Hrubis
2017-08-23  9:42               ` [LTP] [PATCH v4] " Xiong Zhou
2017-08-23  9:53             ` [LTP] [PATCH v3] " Cyril Hrubis
2017-08-23 13:15               ` [LTP] [PATCH v5] " Xiong Zhou
2017-08-23 13:35                 ` Cyril Hrubis [this message]
2017-08-24  7:48                   ` [LTP] [PATCH v6] " Xiong Zhou
2017-08-29 14:27                     ` Cyril Hrubis
2017-09-01  3:00                       ` [LTP] [PATCH v7] " Xiong Zhou
2017-09-05 12:06                         ` Cyril Hrubis
2017-09-05 13:13                           ` Xiong Zhou

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=20170823133512.GA20766@rei.lan \
    --to=chrubis@suse.cz \
    --cc=ltp@lists.linux.it \
    /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