From: Petr Vorel <pvorel@suse.cz>
To: Zhao Gongyi <zhaogongyi@huawei.com>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH] nice05: Add testcase for nice() syscall
Date: Fri, 27 May 2022 13:07:32 +0200 [thread overview]
Message-ID: <YpCw9Kj5CvvmYjME@pevik> (raw)
In-Reply-To: <20220507073642.219085-1-zhaogongyi@huawei.com>
Hi Zhao,
on first look LGTM, few notes below.
make check complains about style, could you please fix it?
$ make check-nice05
CHECK testcases/kernel/syscalls/nice/nice05.c
nice05.c:48: ERROR: "foo* bar" should be "foo *bar"
nice05.c:48: ERROR: "foo* bar" should be "foo *bar"
nice05.c:53: ERROR: "(foo*)" should be "(foo *)"
nice05.c:70: ERROR: "foo* bar" should be "foo *bar"
nice05.c:70: ERROR: "foo* bar" should be "foo *bar"
nice05.c:75: ERROR: "(foo*)" should be "(foo *)"
nice05.c:104: WARNING: braces {} are not necessary for single statement blocks
nice05.c:114: WARNING: braces {} are not necessary for single statement blocks
nice05.c:138: ERROR: "(foo*)" should be "(foo *)"
nice05.c:139: ERROR: "(foo*)" should be "(foo *)"
nice05.c:148: ERROR: space required before the open parenthesis '('
nice05.c:154: ERROR: space required before the open parenthesis '('
make: [../../../../include/mk/rules.mk:56: check-nice05] Error 1 (ignored)
> Add test verify that the low nice thread execute more cycles than
^ executes
> the high nice thread since the two thread binded on the same cpu.
> Signed-off-by: Zhao Gongyi <zhaogongyi@huawei.com>
...
> diff --git a/testcases/kernel/syscalls/nice/nice05.c b/testcases/kernel/syscalls/nice/nice05.c
...
> +/*\
> + * [Description]
> + *
> + * 1. Create a high nice thread and a low nice thread, the main
> + * thread wake them at the same time
> + * 2. Both threads run on the same CPU
> + * 3. Verify that the low nice thread execute more cycles than
^ executes
> + * the high nice thread
> + */
> +
> +#define _GNU_SOURCE
> +#include <pthread.h>
> +#include "tst_test.h"
> +#include "tst_safe_pthread.h"
> +
> +#define LIMIT_TIME 3
> +#define RUN_TIMES 1000000
It might be useful if user could change this value with getopt switch (to debug
on error to speedup). I also wonder if we hit timeout on some slow machine.
...
> +static void verify_nice(void)
> +{
> + int ret;
> + int nice_inc_high = -1;
> + int nice_inc_low = -2;
> + pthread_t nice_low, nice_high;
> +
> + ret = pthread_barrier_init(&barrier, NULL, 3);
> + if (ret != 0) {
> + tst_brk(TBROK, "pthread_barrier_init() returned %s",
> + tst_strerrno(-ret));
> + }
Maybe just:
if (pthread_barrier_init(&barrier, NULL, 3) != 0)
tst_brk(TBROK | TERRNO, "pthread_barrier_init() failed");
Or feel free to use ret if you need it (see below), the point is with tst_brk()
use TERRNO. Or am I missing something pthread specific?
> + SAFE_PTHREAD_CREATE(&nice_high, NULL, nice_high_thread, (void*)&nice_inc_high);
> + SAFE_PTHREAD_CREATE(&nice_low, NULL, nice_low_thread, (void*)&nice_inc_low);
> +
> + pthread_barrier_wait(&barrier);
Not an expert on pthread, but IMHO you should compare
PTHREAD_BARRIER_SERIAL_THREAD with the result of pthread_barrier_wait(), with
your current code you compare with the result of pthread_barrier_init().
> + if (ret != 0 && ret != PTHREAD_BARRIER_SERIAL_THREAD)
> + tst_brk(TBROK | TERRNO, "pthread_barrier_wait() failed");
> +
> + sleep(LIMIT_TIME);
> +
> + ret = pthread_cancel(nice_high);
> + if(ret) {
> + tst_brk(TBROK, "pthread_cancel() returned %s",
> + tst_strerrno(-ret));
if (pthread_cancel(nice_high))
tst_brk(TBROK | TERRNO, "pthread_cancel() failed");
> + }
> +
> + ret = pthread_cancel(nice_low);
> + if(ret) {
> + tst_brk(TBROK, "pthread_cancel() returned %s",
> + tst_strerrno(-ret));
and here as well.
> + }
> +
> + ret = pthread_barrier_destroy(&barrier);
> + if (ret) {
> + tst_brk(TBROK, "pthread_barrier_destroy() returned %s",
> + tst_strerrno(-ret));
> + }
> +
> + SAFE_PTHREAD_JOIN(nice_high, NULL);
> + SAFE_PTHREAD_JOIN(nice_low, NULL);
> +
> + if (time_nice_low > time_nice_high) {
> + tst_res(TPASS, "time_nice_low = %lld time_nice_high = %lld",
> + time_nice_low, time_nice_high);
> + } else {
> + tst_brk(TFAIL | TTERRNO, "Test failed :"
Wrong space between ':', missing after it, use:
tst_brk(TFAIL | TTERRNO, "Test failed: "
Kind regards,
Petr
> + "time_nice_low = %lld time_nice_high = %lld",
> + time_nice_low, time_nice_high);
> + }
> +}
> +
> +static struct tst_test test = {
> + .setup = setup,
> + .cleanup = cleanup,
> + .test_all = verify_nice,
> + .needs_root = 1,
> +};
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next prev parent reply other threads:[~2022-05-27 11:07 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-07 7:36 [LTP] [PATCH] nice05: Add testcase for nice() syscall Zhao Gongyi via ltp
2022-05-27 11:07 ` Petr Vorel [this message]
-- strict thread matches above, loose matches on Subject: below --
2022-06-18 1:54 zhaogongyi via ltp
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=YpCw9Kj5CvvmYjME@pevik \
--to=pvorel@suse.cz \
--cc=ltp@lists.linux.it \
--cc=zhaogongyi@huawei.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.