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 v3] sched_getattr/sched_getattr02: Add new testcase for sched_getattr
Date: Mon, 2 Nov 2015 18:28:09 +0100	[thread overview]
Message-ID: <20151102172809.GD28478@rei> (raw)
In-Reply-To: <563463CC.3090703@huawei.com>

Hi!
> +static pid_t pid;
> +static pid_t unused_pid;
> +struct sched_attr attr_copy;
> +static unsigned int flags;
> +static unsigned int inval_flags = 10000;
> +
> +static struct test_case {
> +	pid_t *pid;
> +	struct sched_attr *a;
> +	unsigned int size;
> +	unsigned int *flags;
> +	int exp_errno;
> +} test_cases[] = {
> +	{&unused_pid, &attr_copy, sizeof(struct sched_attr), &flags, ESRCH},
> +	{&pid, NULL, sizeof(struct sched_attr), &flags, EINVAL},
> +	{&pid, &attr_copy, sizeof(struct sched_attr) - 1, &flags, EINVAL},
> +	{&pid, &attr_copy, sizeof(struct sched_attr), &inval_flags, EINVAL}

The flags are also compile time constant, so we can just initialize it
here with 0 and 10000 for invalid flags the same way as the size.

> +};
> +
> +static void setup(void);
> +static void sched_getattr_verify(const struct test_case *test);
> +
> +int TST_TOTAL = ARRAY_SIZE(test_cases);
> +
> +void *run_deadline(void *data LTP_ATTRIBUTE_UNUSED)
> +{
> +	int i;
> +
> +	for (i = 0; i < TST_TOTAL; i++)
> +		sched_getattr_verify(&test_cases[i]);
> +
> +	return NULL;
> +}
> +
> +static void sched_getattr_verify(const struct test_case *test)
> +{
> +	TEST(sched_getattr(*(test->pid), test->a, test->size,
> +			*(test->flags)));
> +
> +	if (TEST_RETURN != -1) {
> +		tst_resm(TFAIL, "sched_getattr() succeeded unexpectedly.");
> +		return;
> +	}
> +
> +	if (TEST_ERRNO == test->exp_errno) {
> +		tst_resm(TPASS | TTERRNO,
> +			"sched_getattr() failed expectedly");
> +		return;
> +	}
> +
> +	tst_resm(TFAIL | TTERRNO, "sched_getattr() failed unexpectedly "
> +		": expected: %d - %s",
> +		test->exp_errno, tst_strerrno(test->exp_errno));
> +}
> +
> +int main(int argc, char **argv)
> +{
> +	pthread_t thread;
> +	int lc;
> +
> +	tst_parse_opts(argc, argv, NULL, NULL);
> +
> +	setup();
> +
> +	for (lc = 0; TEST_LOOPING(lc); lc++) {
> +		pthread_create(&thread, NULL, run_deadline, NULL);
> +		pthread_join(thread, NULL);

And since we do not call the sched_setattr() anymore, there is no reason
to run the test in separate thread, or is it?

I would just do the for loop over the testcase here inside the
TEST_LOOPING() loop.

> +	}
> +
> +	tst_exit();
> +}

The rest looks good.

-- 
Cyril Hrubis
chrubis@suse.cz

  reply	other threads:[~2015-11-02 17:28 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-20 12:59 [LTP] [PATCH] sched_getattr/sched_getattr02: Add new testcase for sched_getattr Cui Bixuan
2015-10-26 15:47 ` Cyril Hrubis
2015-10-28  1:40   ` [LTP] [PATCH v2] " Cui Bixuan
2015-10-29 16:09     ` Cyril Hrubis
2015-10-31  6:46       ` [LTP] [PATCH v3] " Cui Bixuan
2015-11-02 17:28         ` Cyril Hrubis [this message]
2015-11-03  9:22           ` [LTP] [PATCH v4] " Cui Bixuan
2015-11-03 11:29           ` [LTP] [PATCH v5] " Cui Bixuan
2015-11-03 13:21             ` Cyril Hrubis

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=20151102172809.GD28478@rei \
    --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