[prev in list] [next in list] [prev in thread] [next in thread] 

List:       ltp-list
Subject:    [LTP] About msgsnd05 Test Case Return Value Check
From:       Sandy Sun <a22017 () motorola ! com>
Date:       2014-02-27 1:48:56
Message-ID: CACwVHNonCpBcvNSwVCt=2Sdm_nOROszqpOF-h+L_9z29EQTsnw () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


Hi All,

We found msgsnd05 doesn't check the test result from child thread in parent
thread, otherwise parent thread will always return 0 even when the result
of the child thread is failed.


Here is a patch to fix this problem, is it better to check child
thread result in parent thread? Thank you!


diff --git a/testcases/kernel/syscalls/ipc/msgsnd/msgsnd05.c
b/testcases/kernel/syscalls/ipc/msgsnd/msgsnd05.c
index 523b13e..2df1c2d 100644
--- a/testcases/kernel/syscalls/ipc/msgsnd/msgsnd05.c
+++ b/testcases/kernel/syscalls/ipc/msgsnd/msgsnd05.c
@@ -94,6 +94,7 @@ int main(int ac, char **av)
        int lc;                 /* loop counter */
        char *msg;              /* message returned from parse_opts */
        pid_t c_pid;
+       int status;

        /* parse standard options */
        if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) {
@@ -166,7 +167,12 @@ int main(int ac, char **av)
                                tst_brkm(TBROK, cleanup, "kill failed");
                        }

-                       waitpid(c_pid, NULL, 0);
+                       /* wait for the child to finish */
+                       wait(&status);
+                       /* make sure the child returned a good exit status*/
+                       if (WIFEXITED(status) == 0) {
+                               tst_resm(TFAIL, "Failures reported above");
+                       }
                }
        }

@@ -180,6 +186,7 @@ int main(int ac, char **av)
  */
 void do_child()
 {
+       int retval = 0;
        if (sync_pipe_notify(sync_pipes) == -1)
                tst_brkm(TBROK, cleanup, "sync_pipe_notify failed");

@@ -201,13 +208,14 @@ void do_child()
                         TEST_ERRNO, strerror(TEST_ERRNO));
                break;
        default:
+               retval = 1;
                tst_resm(TFAIL,
                         "call failed with an unexpected error - %d : %s",
                         TEST_ERRNO, strerror(TEST_ERRNO));
                break;        }
 -       exit(0);

+       exit(retval);
 }

 void

BRs,
Sandy

[Attachment #5 (text/html)]

<div dir="ltr"><font face="courier new, monospace">Hi All,</font><div><font \
face="courier new, monospace"><br></font></div><div><font face="courier new, \
monospace">We found msgsnd05  <span \
style="color:rgb(53,53,53);font-size:9pt">doesn&#39;t check the test result  \
</span></font><span style="font-family:&#39;courier \
new&#39;,monospace;color:rgb(53,53,53);font-size:9pt">from child thread in parent \
thread, otherwise parent  </span><span style="font-family:&#39;courier \
new&#39;,monospace;color:rgb(53,53,53);font-size:9pt">thread will always return 0 \
even when the result of  </span><font face="courier new, monospace" \
style="color:rgb(53,53,53);font-size:9pt">the child thread is failed</font><span \
style="color:rgb(53,53,53);font-size:9pt">.</span></div> <pre class="" \
style="font-size:9pt;margin-top:0px;margin-bottom:0px;color:rgb(53,53,53)"><br></pre><pre \
class="" style="font-size:9pt;margin-top:0px;margin-bottom:0px;color:rgb(53,53,53)">Here \
is a patch to fix this problem, is it better to check child thread result in parent \
thread? Thank you!</pre> <pre class="" \
style="font-size:9pt;margin-top:0px;margin-bottom:0px;color:rgb(53,53,53)"><br></pre><pre \
class="" style="margin-top:0px;margin-bottom:0px"><font color="#353535">diff --git \
a/testcases/kernel/syscalls/ipc/msgsnd/msgsnd05.c \
b/testcases/kernel/syscalls/ipc/msgsnd/msgsnd05.c index 523b13e..2df1c2d 100644
--- a/testcases/kernel/syscalls/ipc/msgsnd/msgsnd05.c
+++ b/testcases/kernel/syscalls/ipc/msgsnd/msgsnd05.c
@@ -94,6 +94,7 @@ int main(int ac, char **av)
        int lc;                 /* loop counter */
        char *msg;              /* message returned from parse_opts */
        pid_t c_pid;
+       int status;
 
        /* parse standard options */
        if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) {
@@ -166,7 +167,12 @@ int main(int ac, char **av)
                                tst_brkm(TBROK, cleanup, &quot;kill failed&quot;);
                        }
 
-                       waitpid(c_pid, NULL, 0);
+                       /* wait for the child to finish */
+                       wait(&amp;status);
+                       /* make sure the child returned a good exit status*/
+                       if (WIFEXITED(status) == 0) {
+                               tst_resm(TFAIL, &quot;Failures reported above&quot;);
+                       }
                }
        }
 
@@ -180,6 +186,7 @@ int main(int ac, char **av)
  */
 void do_child()
 {
+       int retval = 0;
        if (sync_pipe_notify(sync_pipes) == -1)
                tst_brkm(TBROK, cleanup, &quot;sync_pipe_notify failed&quot;);
 
@@ -201,13 +208,14 @@ void do_child()
                         TEST_ERRNO, strerror(TEST_ERRNO));
                break;
        default:
+               retval = 1;
                tst_resm(TFAIL,
                         &quot;call failed with an unexpected error - %d : %s&quot;,
                         TEST_ERRNO, strerror(TEST_ERRNO));
                break;
<font face="times new roman, serif">        }
 
</font><font face="courier new, monospace">-       exit(0);</font></font><span \
style="color:rgb(53,53,53);font-size:9pt"><font face="courier new, monospace"> \
</font></span></pre><div><div><font face="courier new, monospace">+          \
exit(retval);</font></div><div><font face="courier new, monospace">  \
}</font></div><div><font face="times new roman, serif">  </font></div><div><font \
face="courier new, monospace">  void</font></div> </div><div><font face="courier new, \
monospace"><br></font></div><div><span style="font-family:&#39;courier \
new&#39;,monospace">BRs,</span><br></div><div><font face="courier new, \
monospace">Sandy</font></div></div>



------------------------------------------------------------------------------
Flow-based real-time traffic analytics software. Cisco certified tool.
Monitor traffic, SLAs, QoS, Medianet, WAAS etc. with NetFlow Analyzer
Customize your own dashboards, set traffic alerts and generate reports.
Network behavioral analysis & security monitoring. All-in-one tool.
http://pubads.g.doubleclick.net/gampad/clk?id=126839071&iu=/4140/ostg.clktrk

_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic