<div dir="ltr"><div dir="ltr"><div class="gmail_default" style="font-size:small"><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Aug 30, 2022 at 6:54 PM Avinesh Kumar <<a href="mailto:akumar@suse.de">akumar@suse.de</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Signed-off-by: Avinesh Kumar <<a href="mailto:akumar@suse.de" target="_blank">akumar@suse.de</a>><br>
---<br>
 testcases/kernel/syscalls/getsid/getsid02.c | 83 +++++----------------<br>
 1 file changed, 17 insertions(+), 66 deletions(-)<br>
<br>
diff --git a/testcases/kernel/syscalls/getsid/getsid02.c b/testcases/kernel/syscalls/getsid/getsid02.c<br>
index b5ab339e2..c235af362 100644<br>
--- a/testcases/kernel/syscalls/getsid/getsid02.c<br>
+++ b/testcases/kernel/syscalls/getsid/getsid02.c<br>
@@ -1,81 +1,32 @@<br>
+// SPDX-License-Identifier: GPL-2.0-or-later<br>
 /*<br>
- *<br>
  *   Copyright (c) International Business Machines  Corp., 2001<br>
  *   Copyright (c) 2012 Cyril Hrubis <<a href="mailto:chrubis@suse.cz" target="_blank">chrubis@suse.cz</a>><br>
- *<br>
- *   This program is free software;  you can redistribute it and/or modify<br>
- *   it under the terms of the GNU General Public License as published by<br>
- *   the Free Software Foundation; either version 2 of the License, or<br>
- *   (at your option) any later version.<br>
- *<br>
- *   This program is distributed in the hope that it will be useful,<br>
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of<br>
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See<br>
- *   the GNU General Public License for more details.<br>
- *<br>
- *   You should have received a copy of the GNU General Public License<br>
- *   along with this program;  if not, write to the Free Software<br>
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA<br>
+ *   Copyright (c) 2022 SUSE LLC Avinesh Kumar <<a href="mailto:avinesh.kumar@suse.com" target="_blank">avinesh.kumar@suse.com</a>><br>
  */<br>
<br>
-#define _GNU_SOURCE 1<br>
-<br>
-#include "test.h"<br>
-<br>
-#include <errno.h><br>
+/*\<br>
+ * [Description]<br>
+ *<br>
+ * Verify that getsid(2) fails with ESRCH errno when there is no<br>
+ * process found with process ID pid.<br>
+ */<br>
<br>
-char *TCID = "getsid02";<br>
-int TST_TOTAL = 1;<br>
+#include "tst_test.h"<br>
<br>
 static pid_t unused_pid;<br>
<br>
-static void cleanup(void);<br>
-static void setup(void);<br>
-<br>
-int main(int ac, char **av)<br>
+static void setup(void)<br>
 {<br>
-       int lc;<br>
-<br>
-       tst_parse_opts(ac, av, NULL, NULL);<br>
-<br>
-       setup();<br>
-<br>
-       for (lc = 0; TEST_LOOPING(lc); lc++) {<br>
-               tst_count = 0;<br>
-<br>
-               TEST(getsid(unused_pid));<br>
-<br>
-               if (TEST_RETURN == 0) {<br>
-                       tst_resm(TFAIL, "call succeed when failure expected");<br>
-                       continue;<br>
-               }<br>
-<br>
-               switch (TEST_ERRNO) {<br>
-               case ESRCH:<br>
-                       tst_resm(TPASS, "expected failure - errno = %d - %s",<br>
-                                TEST_ERRNO, strerror(TEST_ERRNO));<br>
-                       break;<br>
-               default:<br>
-                       tst_resm(TFAIL, "call failed to produce "<br>
-                                "expected error - errno = %d - %s",<br>
-                                TEST_ERRNO, strerror(TEST_ERRNO));<br>
-                       break;<br>
-               }<br>
-       }<br>
-<br>
-       cleanup();<br>
-       tst_exit();<br>
+       unused_pid = tst_get_unused_pid();<br></blockquote><div><br></div><div><div class="gmail_default" style="font-size:small">We can simply move this to the main function to avoid unused PID</div><div class="gmail_default" style="font-size:small">reusing again if people perform test with '-i N'.</div><br></div><div><div class="gmail_default" style="font-size:small">How about this below:</div><br></div><div><div class="gmail_default" style="font-size:small">#include "tst_test.h"</div><br>static void run(void)<br>{<br>  <span class="gmail_default" style="font-size:small">    </span>pid_t unused_pid;<br>    <span class="gmail_default" style="font-size:small">    </span>unused_pid = tst_get_unused_pid();<br><br> <span class="gmail_default" style="font-size:small">    </span>TST_EXP_FAIL(getsid(unused_pid), ESRCH);<br>}<br><br>static struct tst_test test = {<br>       <span class="gmail_default" style="font-size:small">    </span>.test_all = run<br>};<br><div class="gmail_default" style="font-size:small"></div></div></div><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div>Regards,<br></div><div>Li Wang<br></div></div></div></div>