<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 Fri, Aug 21, 2020 at 9:18 AM Yang Xu <<a href="mailto:xuyang2018.jy@cn.fujitsu.com">xuyang2018.jy@cn.fujitsu.com</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">Hi Li<br>
<br>
<br>
> <br>
> Feiyu Zhu <<a href="mailto:zhufy.jy@cn.fujitsu.com" target="_blank">zhufy.jy@cn.fujitsu.com</a> <mailto:<a href="mailto:zhufy.jy@cn.fujitsu.com" target="_blank">zhufy.jy@cn.fujitsu.com</a>>> wrote:<br>
> <br>
>     ...<br>
>     +#include <unistd.h><br>
>     +#include "tst_test.h"<br>
>     +<br>
>     +static pid_t real_pid, fake_pid, int_min_pid;<br>
>     +static void cleanup(void);<br>
>     +<br>
>     +static struct tcase {<br>
>     +       int test_sig;<br>
>     +       int exp_errno;<br>
>     +       int child_flag;<br>
> <br>
> <br>
> The child_flag field is not necessary, we could prepare a real child in <br>
> setup()<br>
> and reclaim it after testing via check the real_pid value, that will be <br>
> more easily.<br>
When I reviewed this patch in internal, I had the same idea. But when I <br>
try it and this case will hang because sub test will wait children <br>
finished by using tst_reap_childrens below:<br>
<br>
lib/tst_test.c<br>
static void run_tests(void)<br>
{<br>
        ...<br>
         for (i = 0; i < tst_test->tcnt; i++) {<br>
                 saved_results = *results;<br>
                 tst_test->test(i);<br>
<br>
                 if (getpid() != main_pid) {<br>
                         exit(0);<br>
                 }<br>
<br>
                 tst_reap_children();<br>
<br>
                 if (results_equal(&saved_results, results))<br>
                         tst_brk(TBROK, "Test %i haven't reported <br>
results!", i);<br>
         }<br>
<br>
<br>
}<br>
<br>
Also, we can use the current process id but it may has unexpected result <br>
when kill succeed. So fork a child to test maybe a better solution.<br></blockquote><div><br></div><div><div class="gmail_default" style="font-size:small">Hmm, sorry for the uncleared description, actually I meant, to use real_pid </div><div class="gmail_default" style="font-size:small">instead of the tc->child_flag directly, then start to reclaim the child when the</div><div class="gmail_default" style="font-size:small">real_pid test finishing.</div><br></div><div><div class="gmail_default" style="font-size:small">Does this below diff work for you?</div><br></div><div><div class="gmail_default" style="font-size:small">--- a/testcases/kernel/syscalls/kill/kill03.c</div>+++ b/testcases/kernel/syscalls/kill/kill03.c<br>@@ -21,24 +21,17 @@ static void cleanup(void);<br> static struct tcase {<br>        int test_sig;<br>        int exp_errno;<br>-       int child_flag;<br>        pid_t *pid;<br> } tcases[] = {<br>-       {2000, EINVAL, 1, &real_pid},<br>-       {SIGKILL, ESRCH, 0, &fake_pid},<br>-       {SIGKILL, ESRCH, 0, &int_min_pid}<br>+       {2000, EINVAL, &real_pid},<br>+       {SIGKILL, ESRCH, &fake_pid},<br>+       {SIGKILL, ESRCH, &int_min_pid}<br> };<br> <br> static void verify_kill(unsigned int n)<br> {<br>        struct tcase *tc = &tcases[n];<br> <br>-       if (tc->child_flag) {<br>-               real_pid = SAFE_FORK();<br>-               if (!real_pid)<br>-                       pause();<br>-       }<br>-<br>        TEST(kill(*tc->pid, tc->test_sig));<br>        if (TST_RET != -1) {<br>                tst_res(TFAIL, "kill should fail but not, return %ld", TST_RET);<br>@@ -51,14 +44,19 @@ static void verify_kill(unsigned int n)<br>                tst_res(TFAIL | TTERRNO, "kill expected %s but got",<br>                        tst_strerrno(tc->exp_errno));<br> <br>-       if (tc->child_flag) {<br>+       if (real_pid) {<br>                cleanup();<br>                real_pid = 0;<br>        }<br>+<br> }<br> <br> static void setup(void)<br> {<br>+       real_pid = SAFE_FORK();<br>+       if (!real_pid)<br>+               pause();<br>+<br>        fake_pid = tst_get_unused_pid();<br>        int_min_pid = INT_MIN;<br> }<br><div class="gmail_default" style="font-size:small"></div></div></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div>Regards,<br></div><div>Li Wang<br></div></div></div></div>