From: Andrea Cervesato via ltp <ltp@lists.linux.it>
To: rpalethorpe@suse.de, Andrea Cervesato <andrea.cervesato@suse.de>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH v1 1/2] Rewrite gettid01 test
Date: Thu, 5 Oct 2023 13:57:33 +0200 [thread overview]
Message-ID: <a379dd67-e786-41b9-91d0-5606cd67d419@suse.com> (raw)
In-Reply-To: <87mswx1lul.fsf@suse.de>
Hi!
On 10/5/23 10:50, Richard Palethorpe wrote:
> Hello,
>
> Andrea Cervesato <andrea.cervesato@suse.de> writes:
>
>> From: Andrea Cervesato <andrea.cervesato@suse.com>
>>
>> The old test wasn't doing anything meaningful, but just checking
>> gettid() syscall was working. In this test we checks if gettid() is
>> working and if PID differs from its return value.
>>
>> Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
>> ---
>> testcases/kernel/syscalls/gettid/gettid01.c | 102 +++-----------------
>> 1 file changed, 14 insertions(+), 88 deletions(-)
>>
>> diff --git a/testcases/kernel/syscalls/gettid/gettid01.c b/testcases/kernel/syscalls/gettid/gettid01.c
>> index 7e5b6b175..3ee139d5f 100644
>> --- a/testcases/kernel/syscalls/gettid/gettid01.c
>> +++ b/testcases/kernel/syscalls/gettid/gettid01.c
>> @@ -1,96 +1,22 @@
>> +// SPDX-License-Identifier: GPL-2.0-or-later
>> /*
>> - * Crackerjack Project
>> - *
>> - * Copyright (C) 2007-2008, Hitachi, Ltd.
>> - * Author(s): Takahiro Yasui <takahiro.yasui.mp@hitachi.com>,
>> - * Yumiko Sugita <yumiko.sugita.yf@hitachi.com>,
>> - * Satoshi Fujiwara <sa-fuji@sdl.hitachi.co.jp>
>> - *
>> - * This program is free software; you can redistribute it and/or
>> - * modify it under the terms of the GNU General Public License
>> - * as published by the Free Software Foundation; either version 2
>> - * of the License, or (at your option) any later version.
>> - *
>> - * This program is distributed in the hope that it will be useful,
>> - * but WITHOUT ANY WARRANTY; without even the implied warranty of
>> - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
>> - * GNU General Public License for more details.
>> - *
>> - * You should have received a copy of the GNU General Public License
>> - * along with this program; if not, write to the Free Software
>> - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
>> - *
>> - * $Id: gettid01.c,v 1.5 2009/10/26 14:55:47 subrata_modak Exp $
>> + * Copyright (C) 2023 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
>> + */
>> +/*\
>> + * [Description]
>> *
>> + * This test checks if parent pid is equal to tid in single-threaded
>> + * application.
>> */
>>
>> -/* Porting from Crackerjack to LTP is done
>> - by Masatake YAMATO <yamato@redhat.com> */
>> -
>> -#include <sys/types.h>
>> -#include <linux/unistd.h>
>> -#include <errno.h>
>> -
>> -#include "test.h"
>> -
>> -void setup();
>> -void cleanup();
>> +#include "tst_test.h"
>> +#include "lapi/syscalls.h"
>>
>> -char *TCID = "gettid01";
>> -
>> -int TST_TOTAL = 1;
>> -
>> -pid_t my_gettid(void)
>> +static void run(void)
>> {
>> - return (pid_t) syscall(__NR_gettid);
>> + TST_EXP_EQ_LI(getpid(), tst_syscall(__NR_gettid));
> Perhaps this is nit picking, but this assumes libc didn't put us in a
> thread or just caches the wrong value in getpid. So it is more a test of
> libc than the kernel.
I understand the cache part. Probably we need to call
tst_syscall(__NR_getpid) instead of getpid(), but I don't get the thread
part. Is it possible that libc moves test function inside a thread?
> Is there some other way we could check that the main test process is not
> a thread? There could be some file in proc I guess. Then we are
> comparing information from multiple sources and it should all align.
>
> Also getpid could be called directly avoiding libc.
>
>> }
>>
>> -int main(int ac, char **av)
>> -{
>> - int lc;
>> -
>> - tst_parse_opts(ac, av, NULL, NULL);
>> -
>> - setup();
>> -
>> - /*
>> - * The following loop checks looping state if -c option given
>> - */
>> - for (lc = 0; TEST_LOOPING(lc); lc++) {
>> -
>> - tst_count = 0;
>> -
>> - TEST(my_gettid());
>> -
>> - if (TEST_RETURN == -1) {
>> - tst_resm(TFAIL, "gettid() Failed, errno=%d: %s",
>> - TEST_ERRNO, strerror(TEST_ERRNO));
>> - } else {
>> - tst_resm(TPASS, "gettid() returned %ld",
>> - TEST_RETURN);
>> - }
>> - }
>> -
>> - cleanup();
>> - tst_exit();
>> -}
>> -
>> -/*
>> - * setup() - performs all ONE TIME setup for this test.
>> - */
>> -void setup(void)
>> -{
>> -
>> - tst_sig(NOFORK, DEF_HANDLER, cleanup);
>> -
>> - TEST_PAUSE;
>> -
>> -}
>> -
>> -/*
>> - * cleanup() - performs all ONE TIME cleanup for this test at
>> - * completion or premature exit.
>> - */
>> -void cleanup(void)
>> -{
>> -}
>> +static struct tst_test test = {
>> + .test_all = run,
>> +};
>> --
>> 2.35.3
>
Andrea
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next prev parent reply other threads:[~2023-10-05 11:57 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-05 11:41 [LTP] [PATCH v1 0/2] Rewrite the gettid() testing suite Andrea Cervesato
2023-09-05 11:41 ` [LTP] [PATCH v1 1/2] Rewrite gettid01 test Andrea Cervesato
2023-10-05 8:50 ` Richard Palethorpe
2023-10-05 11:57 ` Andrea Cervesato via ltp [this message]
2023-10-06 9:45 ` Richard Palethorpe
2023-09-05 11:41 ` [LTP] [PATCH v1 2/2] Add gettid02 test Andrea Cervesato
2023-10-05 9:18 ` Richard Palethorpe
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=a379dd67-e786-41b9-91d0-5606cd67d419@suse.com \
--to=ltp@lists.linux.it \
--cc=andrea.cervesato@suse.com \
--cc=andrea.cervesato@suse.de \
--cc=rpalethorpe@suse.de \
/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.