All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH] getsid02.c: Rewrite using new LTP API
@ 2022-08-30 10:54 Avinesh Kumar
  2022-08-31  6:40 ` Li Wang
  0 siblings, 1 reply; 4+ messages in thread
From: Avinesh Kumar @ 2022-08-30 10:54 UTC (permalink / raw)
  To: ltp

Signed-off-by: Avinesh Kumar <akumar@suse.de>
---
 testcases/kernel/syscalls/getsid/getsid02.c | 83 +++++----------------
 1 file changed, 17 insertions(+), 66 deletions(-)

diff --git a/testcases/kernel/syscalls/getsid/getsid02.c b/testcases/kernel/syscalls/getsid/getsid02.c
index b5ab339e2..c235af362 100644
--- a/testcases/kernel/syscalls/getsid/getsid02.c
+++ b/testcases/kernel/syscalls/getsid/getsid02.c
@@ -1,81 +1,32 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- *
  *   Copyright (c) International Business Machines  Corp., 2001
  *   Copyright (c) 2012 Cyril Hrubis <chrubis@suse.cz>
- *
- *   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
+ *   Copyright (c) 2022 SUSE LLC Avinesh Kumar <avinesh.kumar@suse.com>
  */
 
-#define _GNU_SOURCE 1
-
-#include "test.h"
-
-#include <errno.h>
+/*\
+ * [Description]
+ *
+ * Verify that getsid(2) fails with ESRCH errno when there is no
+ * process found with process ID pid.
+ */
 
-char *TCID = "getsid02";
-int TST_TOTAL = 1;
+#include "tst_test.h"
 
 static pid_t unused_pid;
 
-static void cleanup(void);
-static void setup(void);
-
-int main(int ac, char **av)
+static void setup(void)
 {
-	int lc;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		tst_count = 0;
-
-		TEST(getsid(unused_pid));
-
-		if (TEST_RETURN == 0) {
-			tst_resm(TFAIL, "call succeed when failure expected");
-			continue;
-		}
-
-		switch (TEST_ERRNO) {
-		case ESRCH:
-			tst_resm(TPASS, "expected failure - errno = %d - %s",
-				 TEST_ERRNO, strerror(TEST_ERRNO));
-			break;
-		default:
-			tst_resm(TFAIL, "call failed to produce "
-				 "expected error - errno = %d - %s",
-				 TEST_ERRNO, strerror(TEST_ERRNO));
-			break;
-		}
-	}
-
-	cleanup();
-	tst_exit();
+	unused_pid = tst_get_unused_pid();
 }
 
-void setup(void)
+static void run(void)
 {
-	unused_pid = tst_get_unused_pid(cleanup);
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
+	TST_EXP_FAIL(getsid(unused_pid), ESRCH);
 }
 
-void cleanup(void)
-{
-}
+static struct tst_test test = {
+	.setup = setup,
+	.test_all = run
+};
-- 
2.37.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [LTP] [PATCH] getsid02.c: Rewrite using new LTP API
  2022-08-30 10:54 [LTP] [PATCH] getsid02.c: Rewrite using new LTP API Avinesh Kumar
@ 2022-08-31  6:40 ` Li Wang
  2022-09-01 10:51   ` Avinesh Kumar
  0 siblings, 1 reply; 4+ messages in thread
From: Li Wang @ 2022-08-31  6:40 UTC (permalink / raw)
  To: Avinesh Kumar; +Cc: LTP List


[-- Attachment #1.1: Type: text/plain, Size: 3475 bytes --]

On Tue, Aug 30, 2022 at 6:54 PM Avinesh Kumar <akumar@suse.de> wrote:

> Signed-off-by: Avinesh Kumar <akumar@suse.de>
> ---
>  testcases/kernel/syscalls/getsid/getsid02.c | 83 +++++----------------
>  1 file changed, 17 insertions(+), 66 deletions(-)
>
> diff --git a/testcases/kernel/syscalls/getsid/getsid02.c
> b/testcases/kernel/syscalls/getsid/getsid02.c
> index b5ab339e2..c235af362 100644
> --- a/testcases/kernel/syscalls/getsid/getsid02.c
> +++ b/testcases/kernel/syscalls/getsid/getsid02.c
> @@ -1,81 +1,32 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
>  /*
> - *
>   *   Copyright (c) International Business Machines  Corp., 2001
>   *   Copyright (c) 2012 Cyril Hrubis <chrubis@suse.cz>
> - *
> - *   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
> + *   Copyright (c) 2022 SUSE LLC Avinesh Kumar <avinesh.kumar@suse.com>
>   */
>
> -#define _GNU_SOURCE 1
> -
> -#include "test.h"
> -
> -#include <errno.h>
> +/*\
> + * [Description]
> + *
> + * Verify that getsid(2) fails with ESRCH errno when there is no
> + * process found with process ID pid.
> + */
>
> -char *TCID = "getsid02";
> -int TST_TOTAL = 1;
> +#include "tst_test.h"
>
>  static pid_t unused_pid;
>
> -static void cleanup(void);
> -static void setup(void);
> -
> -int main(int ac, char **av)
> +static void setup(void)
>  {
> -       int lc;
> -
> -       tst_parse_opts(ac, av, NULL, NULL);
> -
> -       setup();
> -
> -       for (lc = 0; TEST_LOOPING(lc); lc++) {
> -               tst_count = 0;
> -
> -               TEST(getsid(unused_pid));
> -
> -               if (TEST_RETURN == 0) {
> -                       tst_resm(TFAIL, "call succeed when failure
> expected");
> -                       continue;
> -               }
> -
> -               switch (TEST_ERRNO) {
> -               case ESRCH:
> -                       tst_resm(TPASS, "expected failure - errno = %d -
> %s",
> -                                TEST_ERRNO, strerror(TEST_ERRNO));
> -                       break;
> -               default:
> -                       tst_resm(TFAIL, "call failed to produce "
> -                                "expected error - errno = %d - %s",
> -                                TEST_ERRNO, strerror(TEST_ERRNO));
> -                       break;
> -               }
> -       }
> -
> -       cleanup();
> -       tst_exit();
> +       unused_pid = tst_get_unused_pid();
>

We can simply move this to the main function to avoid unused PID
reusing again if people perform test with '-i N'.

How about this below:

#include "tst_test.h"

static void run(void)
{
    pid_t unused_pid;
    unused_pid = tst_get_unused_pid();

    TST_EXP_FAIL(getsid(unused_pid), ESRCH);
}

static struct tst_test test = {
    .test_all = run
};

-- 
Regards,
Li Wang

[-- Attachment #1.2: Type: text/html, Size: 5353 bytes --]

[-- Attachment #2: Type: text/plain, Size: 60 bytes --]


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [LTP] [PATCH] getsid02.c: Rewrite using new LTP API
  2022-08-31  6:40 ` Li Wang
@ 2022-09-01 10:51   ` Avinesh Kumar
  2022-09-02  3:00     ` Li Wang
  0 siblings, 1 reply; 4+ messages in thread
From: Avinesh Kumar @ 2022-09-01 10:51 UTC (permalink / raw)
  To: ltp, Li Wang

Hi Li,

On Wednesday, August 31, 2022 12:10:44 PM IST Li Wang wrote:
> On Tue, Aug 30, 2022 at 6:54 PM Avinesh Kumar <akumar@suse.de> wrote:
> 
> > Signed-off-by: Avinesh Kumar <akumar@suse.de>
> > ---
> >  testcases/kernel/syscalls/getsid/getsid02.c | 83 +++++----------------
> >  1 file changed, 17 insertions(+), 66 deletions(-)
> >
> > diff --git a/testcases/kernel/syscalls/getsid/getsid02.c
> > b/testcases/kernel/syscalls/getsid/getsid02.c
> > index b5ab339e2..c235af362 100644
> > --- a/testcases/kernel/syscalls/getsid/getsid02.c
> > +++ b/testcases/kernel/syscalls/getsid/getsid02.c
> > @@ -1,81 +1,32 @@
> > +// SPDX-License-Identifier: GPL-2.0-or-later
> >  /*
> > - *
> >   *   Copyright (c) International Business Machines  Corp., 2001
> >   *   Copyright (c) 2012 Cyril Hrubis <chrubis@suse.cz>
> > - *
> > - *   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
> > + *   Copyright (c) 2022 SUSE LLC Avinesh Kumar <avinesh.kumar@suse.com>
> >   */
> >
> > -#define _GNU_SOURCE 1
> > -
> > -#include "test.h"
> > -
> > -#include <errno.h>
> > +/*\
> > + * [Description]
> > + *
> > + * Verify that getsid(2) fails with ESRCH errno when there is no
> > + * process found with process ID pid.
> > + */
> >
> > -char *TCID = "getsid02";
> > -int TST_TOTAL = 1;
> > +#include "tst_test.h"
> >
> >  static pid_t unused_pid;
> >
> > -static void cleanup(void);
> > -static void setup(void);
> > -
> > -int main(int ac, char **av)
> > +static void setup(void)
> >  {
> > -       int lc;
> > -
> > -       tst_parse_opts(ac, av, NULL, NULL);
> > -
> > -       setup();
> > -
> > -       for (lc = 0; TEST_LOOPING(lc); lc++) {
> > -               tst_count = 0;
> > -
> > -               TEST(getsid(unused_pid));
> > -
> > -               if (TEST_RETURN == 0) {
> > -                       tst_resm(TFAIL, "call succeed when failure
> > expected");
> > -                       continue;
> > -               }
> > -
> > -               switch (TEST_ERRNO) {
> > -               case ESRCH:
> > -                       tst_resm(TPASS, "expected failure - errno = %d -
> > %s",
> > -                                TEST_ERRNO, strerror(TEST_ERRNO));
> > -                       break;
> > -               default:
> > -                       tst_resm(TFAIL, "call failed to produce "
> > -                                "expected error - errno = %d - %s",
> > -                                TEST_ERRNO, strerror(TEST_ERRNO));
> > -                       break;
> > -               }
> > -       }
> > -
> > -       cleanup();
> > -       tst_exit();
> > +       unused_pid = tst_get_unused_pid();
> >
> 
> We can simply move this to the main function to avoid unused PID
> reusing again if people perform test with '-i N'.
> 
> How about this below:
> 
> #include "tst_test.h"
> 
> static void run(void)
> {
>     pid_t unused_pid;
>     unused_pid = tst_get_unused_pid();
> 
>     TST_EXP_FAIL(getsid(unused_pid), ESRCH);
> }
> 
> static struct tst_test test = {
>     .test_all = run
> };
> 
> 
Yes, I agree to your suggestion. But while testing '-i N' with this code
also I am getting the same unused_pid which is equal to 
/proc/sys/kernel/pid_max in my env.


Regards,
Avinesh




-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [LTP] [PATCH] getsid02.c: Rewrite using new LTP API
  2022-09-01 10:51   ` Avinesh Kumar
@ 2022-09-02  3:00     ` Li Wang
  0 siblings, 0 replies; 4+ messages in thread
From: Li Wang @ 2022-09-02  3:00 UTC (permalink / raw)
  To: Avinesh Kumar; +Cc: LTP List


[-- Attachment #1.1: Type: text/plain, Size: 4624 bytes --]

On Thu, Sep 1, 2022 at 6:59 PM Avinesh Kumar <akumar@suse.de> wrote:

> Hi Li,
>
> On Wednesday, August 31, 2022 12:10:44 PM IST Li Wang wrote:
> > On Tue, Aug 30, 2022 at 6:54 PM Avinesh Kumar <akumar@suse.de> wrote:
> >
> > > Signed-off-by: Avinesh Kumar <akumar@suse.de>
> > > ---
> > >  testcases/kernel/syscalls/getsid/getsid02.c | 83 +++++----------------
> > >  1 file changed, 17 insertions(+), 66 deletions(-)
> > >
> > > diff --git a/testcases/kernel/syscalls/getsid/getsid02.c
> > > b/testcases/kernel/syscalls/getsid/getsid02.c
> > > index b5ab339e2..c235af362 100644
> > > --- a/testcases/kernel/syscalls/getsid/getsid02.c
> > > +++ b/testcases/kernel/syscalls/getsid/getsid02.c
> > > @@ -1,81 +1,32 @@
> > > +// SPDX-License-Identifier: GPL-2.0-or-later
> > >  /*
> > > - *
> > >   *   Copyright (c) International Business Machines  Corp., 2001
> > >   *   Copyright (c) 2012 Cyril Hrubis <chrubis@suse.cz>
> > > - *
> > > - *   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
> > > + *   Copyright (c) 2022 SUSE LLC Avinesh Kumar <
> avinesh.kumar@suse.com>
> > >   */
> > >
> > > -#define _GNU_SOURCE 1
> > > -
> > > -#include "test.h"
> > > -
> > > -#include <errno.h>
> > > +/*\
> > > + * [Description]
> > > + *
> > > + * Verify that getsid(2) fails with ESRCH errno when there is no
> > > + * process found with process ID pid.
> > > + */
> > >
> > > -char *TCID = "getsid02";
> > > -int TST_TOTAL = 1;
> > > +#include "tst_test.h"
> > >
> > >  static pid_t unused_pid;
> > >
> > > -static void cleanup(void);
> > > -static void setup(void);
> > > -
> > > -int main(int ac, char **av)
> > > +static void setup(void)
> > >  {
> > > -       int lc;
> > > -
> > > -       tst_parse_opts(ac, av, NULL, NULL);
> > > -
> > > -       setup();
> > > -
> > > -       for (lc = 0; TEST_LOOPING(lc); lc++) {
> > > -               tst_count = 0;
> > > -
> > > -               TEST(getsid(unused_pid));
> > > -
> > > -               if (TEST_RETURN == 0) {
> > > -                       tst_resm(TFAIL, "call succeed when failure
> > > expected");
> > > -                       continue;
> > > -               }
> > > -
> > > -               switch (TEST_ERRNO) {
> > > -               case ESRCH:
> > > -                       tst_resm(TPASS, "expected failure - errno = %d
> -
> > > %s",
> > > -                                TEST_ERRNO, strerror(TEST_ERRNO));
> > > -                       break;
> > > -               default:
> > > -                       tst_resm(TFAIL, "call failed to produce "
> > > -                                "expected error - errno = %d - %s",
> > > -                                TEST_ERRNO, strerror(TEST_ERRNO));
> > > -                       break;
> > > -               }
> > > -       }
> > > -
> > > -       cleanup();
> > > -       tst_exit();
> > > +       unused_pid = tst_get_unused_pid();
> > >
> >
> > We can simply move this to the main function to avoid unused PID
> > reusing again if people perform test with '-i N'.
> >
> > How about this below:
> >
> > #include "tst_test.h"
> >
> > static void run(void)
> > {
> >     pid_t unused_pid;
> >     unused_pid = tst_get_unused_pid();
> >
> >     TST_EXP_FAIL(getsid(unused_pid), ESRCH);
> > }
> >
> > static struct tst_test test = {
> >     .test_all = run
> > };
> >
> >
> Yes, I agree to your suggestion. But while testing '-i N' with this code
> also I am getting the same unused_pid which is equal to
> /proc/sys/kernel/pid_max in my env.
>

Ah, right. I additionally checked the "Linux Programming Interface
Handbook",
it says the maximum PID number that can be used is 'pid_max - 1'. So I
realized
that why the tst_unused_pid() just read the value of
'/proc/sys/kernel/pid_max'.

Anyway, I modified the patch as I commented above and pushed it.
(that will be more easiler with removing setup() function)


-- 
Regards,
Li Wang

[-- Attachment #1.2: Type: text/html, Size: 7047 bytes --]

[-- Attachment #2: Type: text/plain, Size: 60 bytes --]


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-09-02  3:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-30 10:54 [LTP] [PATCH] getsid02.c: Rewrite using new LTP API Avinesh Kumar
2022-08-31  6:40 ` Li Wang
2022-09-01 10:51   ` Avinesh Kumar
2022-09-02  3:00     ` Li Wang

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.