From: Richard Palethorpe <rpalethorpe@suse.de>
To: Petr Vorel <pvorel@suse.cz>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [v5,2/2] semop04: Refactor with new API
Date: Tue, 29 Aug 2023 10:20:44 +0100 [thread overview]
Message-ID: <874jkijj9p.fsf@suse.de> (raw)
In-Reply-To: <20230621102506.GB393195@pevik>
Hello,
Petr Vorel <pvorel@suse.cz> writes:
> Hi Wei,
>
>> -void delayloop()
>> +static void delayloop(void)
>> {
>> int delay;
>> +
>> delay = 1 + ((100.0 * rand()) / RAND_MAX);
>> - if (verbose)
>> - printf("in delay function for %d microseconds\n", delay);
>> usleep(delay);
>> }
>
> ...
>> + for (i = 0; i < LOOPS; i++) {
>> + semdown(semid);
>> delayloop();
> Why not just:
>
> usleep(1 + ((100.0 * rand()) / RAND_MAX));
>
> and delete whole delayloop() function?
>
>> - if (semup(semid)) {
>> - printf("semup failed\n");
>> - }
>> - if (verbose)
>> - printf("sem is up\n");
>> + semup(semid);
>> }
>
> ...
>> /* set up the semaphore */
>> - if ((semid = semget((key_t) 9142, 1, 0666 | IPC_CREAT)) < 0) {
>> - printf("error in semget()\n");
>> - exit(-1);
>> - }
>> + semid = SAFE_SEMGET((key_t) 9142, 1, 0666 | IPC_CREAT);
>> +
>> semunion.val = 1;
>> - if (semctl(semid, 0, SETVAL, semunion) == -1) {
>> - printf("error in semctl\n");
>> - }
>
>> - if ((pid = fork()) < 0) {
>> - printf("fork error\n");
>> - exit(-1);
>> - }
>> + SAFE_SEMCTL(semid, 0, SETVAL, semunion);
>> +
>> + pid = SAFE_FORK();
>> +
>> if (pid) {
>> - /* parent */
>> srand(pid);
>> mainloop(semid);
>> - waitpid(pid, &chstat, 0);
>> - if (!WIFEXITED(chstat)) {
>> - printf("child exited with status\n");
>> - exit(-1);
>> - }
>> - if (semctl(semid, 0, IPC_RMID, semunion) == -1) {
>> - printf("error in semctl\n");
>> - }
>> - if (errors) {
>> - printf("FAIL: there were %d errors\n", errors);
>> - } else {
>> - printf("PASS: error count is 0\n");
>> - }
>> - exit(errors);
>> + tst_reap_children();
>> + SAFE_SEMCTL(semid, 0, IPC_RMID, semunion);
>> + tst_res(TPASS, "Semaphore up/down check success");
>
> Maybe here use plain semctl() verified with TST_EXP_POSITIVE() from
> tst_test_macros.h? This way we'd get TFAIL on failure instead of TPASS.
>
> Kind regards,
> Petr
Setting to changes requested in patchwork.
--
Thank you,
Richard.
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next prev parent reply other threads:[~2023-08-29 9:22 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-19 13:25 [LTP] [PATCH v1] Move semaphore/ tests to semop/ Wei Gao via ltp
2023-01-19 18:00 ` Petr Vorel
2023-01-20 1:05 ` [LTP] [PATCH v2] " Wei Gao via ltp
2023-02-28 9:15 ` Richard Palethorpe
2023-03-02 7:15 ` [LTP] [PATCH v3 0/2] Refactor semaphore Wei Gao via ltp
2023-03-02 7:15 ` [LTP] [PATCH v3 1/2] Move semaphore/ tests to semop/ Wei Gao via ltp
2023-03-15 12:31 ` Petr Vorel
2023-03-15 13:11 ` Wei Gao via ltp
2023-03-15 17:47 ` Petr Vorel
2023-03-17 12:29 ` Li Wang
2023-03-19 17:05 ` Petr Vorel
2023-03-02 7:15 ` [LTP] [PATCH v3 2/2] semop04:Refactor with new API Wei Gao via ltp
2023-03-15 12:36 ` Petr Vorel
2023-03-15 13:03 ` Wei Gao via ltp
2023-03-15 18:39 ` Petr Vorel
2023-03-16 7:22 ` [LTP] [PATCH v4 0/2] Refactor semaphore Wei Gao via ltp
2023-03-16 7:22 ` [LTP] [PATCH v4 1/2] Move semaphore/ tests to semop/ Wei Gao via ltp
2023-03-16 7:22 ` [LTP] [PATCH v4 2/2] semop04:Refactor with new API Wei Gao via ltp
2023-05-29 18:34 ` Petr Vorel
2023-05-30 12:07 ` [LTP] [v5,2/2] semop04: Refactor " Wei Gao via ltp
2023-06-21 10:25 ` Petr Vorel
2023-08-29 9:20 ` Richard Palethorpe [this message]
2023-08-29 11:00 ` [LTP] [v6,2/2] " Wei Gao via ltp
2023-08-29 11:18 ` [LTP] [v7,2/2] " Wei Gao via ltp
2023-08-30 11:41 ` Andrea Cervesato via ltp
2023-09-01 7:38 ` Richard Palethorpe
2023-09-02 11:32 ` [LTP] [PATCH v8] " Wei Gao 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=874jkijj9p.fsf@suse.de \
--to=rpalethorpe@suse.de \
--cc=ltp@lists.linux.it \
--cc=pvorel@suse.cz \
/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