Skip to contentSkip to conversation

LTP : Fix connectors event_generator program : gen_fork

LTP Suzuki Poulose 4 participants 5 messages Sep 8, 2009 – Sep 9, 2009

lore
Share & tools
lore
#0 lore raw

Hi,

There is a testcase issue in the event_generator code. The gen_fork() is called to generate the fork event.

The child process prints the following message:

static inline void gen_fork(void)

{
        pid_t pid;
        int status;

        pid = fork();
        if (pid == 0) {
                printf("fork parent: %d, child: %d\n", getppid(), 
getpid());
                exit(0);
        } else if (pid < 0) {
                fprintf(stderr, "fork() failed\n");
                exit(1);
        }
}

Now the parent process just exits after this call. So, if the child doesn't get to run before parent exits, the child will see the ppid as 1, that of INIT and this contradicts the actual data. Hence the test fails.

Attached patch fixes the issue. I have verified the same. Please apply.

Thanks

Suzuki

testcases/kernel/connectors/pec/event_generator.c +6 -0
Index: ltp/testcases/kernel/connectors/pec/event_generator.c
===================================================================
@@ -25,6 +25,9 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <pwd.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+
 #include "test.h"
 
 #define DEFAULT_EVENT_NUM       1
@@ -94,6 +97,7 @@
 static inline void gen_fork(void)
 {
 	pid_t pid;
+	int status;
 
 	pid = fork();
 	if (pid == 0) {
@@ -102,6 +106,8 @@
 	} else if (pid < 0) {
 		fprintf(stderr, "fork() failed\n");
 		exit(1);
+	} else {  /* Parent should wait for the child */
+		wait(&status);
 	}
 }
 

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july

_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

Acked-by
#1 lore raw
Quoted 23 lines · Suzuki Poulose

Hi,

There is a testcase issue in the event_generator code. The gen_fork() is called to generate the fork event.

The child process prints the following message:

static inline void gen_fork(void)

{
        pid_t pid;
        int status;

        pid = fork();
        if (pid == 0) {
                printf("fork parent: %d, child: %d\n", getppid(),
getpid());
                exit(0);
        } else if (pid < 0) {
                fprintf(stderr, "fork() failed\n");
                exit(1);
        }
}
Quoted 6 lines

Now the parent process just exits after this call. So, if the child doesn't get to run before parent exits, the child will see the ppid as 1, that of INIT and this contradicts the actual data. Hence the test fails.

Attached patch fixes the issue. I have verified the same. Please apply.

Thanks for fixing it.

But you forgot to add your Signed-off-by in the patch. ;)

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

author Acked-by Li Zefan
#2 lore raw
Quoted 28 lines · Li Zefan
Quoted 27 lines · Suzuki Poulose

Hi,

There is a testcase issue in the event_generator code. The gen_fork() is called to generate the fork event.

The child process prints the following message:

static inline void gen_fork(void)

{
        pid_t pid;
        int status;

        pid = fork();
        if (pid == 0) {
                printf("fork parent: %d, child: %d\n", getppid(),
getpid());
                exit(0);
        } else if (pid < 0) {
                fprintf(stderr, "fork() failed\n");
                exit(1);
        }
}

Now the parent process just exits after this call. So, if the child doesn't get to run before parent exits, the child will see the ppid as 1, that of INIT and this contradicts the actual data. Hence the test fails.

Quoted 9 lines
Quoted 2 lines

Attached patch fixes the issue. I have verified the same. Please apply.

Thanks for fixing it.

But you forgot to add your Signed-off-by in the patch. ;)

Ah! Thanks for catching that ! Re-attaching it ;)

Thanks

Suzuki

gen_fork() event should wait until the child exits. Otherwise the child would see INIT as the parent and end up in collecting wrong information to compare with.

testcases/kernel/connectors/pec/event_generator.c +6 -0
Index: ltp/testcases/kernel/connectors/pec/event_generator.c
===================================================================
@@ -25,6 +25,9 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <pwd.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+
 #include "test.h"
 
 #define DEFAULT_EVENT_NUM       1
@@ -94,6 +97,7 @@
 static inline void gen_fork(void)
 {
 	pid_t pid;
+	int status;
 
 	pid = fork();
 	if (pid == 0) {
@@ -102,6 +106,8 @@
 	} else if (pid < 0) {
 		fprintf(stderr, "fork() failed\n");
 		exit(1);
+	} else {  /* Parent should wait for the child */
+		wait(&status);
 	}
 }
 

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july

_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

#3 lore raw
Quoted 42 lines · Suzuki Poulose
Quoted 28 lines · Li Zefan
Quoted 27 lines · Suzuki Poulose

Hi,

There is a testcase issue in the event_generator code. The gen_fork() is called to generate the fork event.

The child process prints the following message:

static inline void gen_fork(void)

{
        pid_t pid;
        int status;

        pid = fork();
        if (pid == 0) {
                printf("fork parent: %d, child: %d\n", getppid(),
getpid());
                exit(0);
        } else if (pid < 0) {
                fprintf(stderr, "fork() failed\n");
                exit(1);
        }
}

Now the parent process just exits after this call. So, if the child doesn't get to run before parent exits, the child will see the ppid as 1, that of INIT and this contradicts the actual data. Hence the test fails.

Quoted 9 lines
Quoted 2 lines

Attached patch fixes the issue. I have verified the same. Please apply.

Thanks for fixing it.

But you forgot to add your Signed-off-by in the patch. ;)

Ah! Thanks for catching that ! Re-attaching it ;)

Thanks

Quoted 8 lines

Suzuki
plain text document attachment
(connectors-gen_fork-wait-for-child.diff)
gen_fork() event should wait until the child exits. Otherwise the child would see INIT as the parent and end up in collecting wrong information to compare with.

Thanks.

Regards--
Subrata

Quoted 34 lines

Index: ltp/testcases/kernel/connectors/pec/event_generator.c
===================================================================

testcases/kernel/connectors/pec/event_generator.c +6 -1
@@ -25,6 +25,9 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <pwd.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+
 #include "test.h"
 
 #define DEFAULT_EVENT_NUM       1
@@ -94,6 +97,7 @@
 static inline void gen_fork(void)
 {
 	pid_t pid;
+	int status;
 
 	pid = fork();
 	if (pid == 0) {
@@ -102,6 +106,8 @@
 	} else if (pid < 0) {
 		fprintf(stderr, "fork() failed\n");
 		exit(1);
+	} else {  /* Parent should wait for the child */
+		wait(&status);
 	}
 }
 
------------------------------------------------------------------------------
Quoted 5 lines

Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________ Ltp-list mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ltp-list

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

#4 lore raw
Quoted 79 lines · Subrata Modak
Quoted 42 lines · Suzuki Poulose
Quoted 28 lines · Li Zefan
Quoted 27 lines · Suzuki Poulose

Hi,

There is a testcase issue in the event_generator code. The gen_fork() is called to generate the fork event.

The child process prints the following message:

static inline void gen_fork(void)
{
        pid_t pid;
        int status;

        pid = fork();
        if (pid == 0) {
                printf("fork parent: %d, child: %d\n", getppid(), getpid());
                exit(0);
        } else if (pid < 0) {
                fprintf(stderr, "fork() failed\n"); exit(1);
        }
}

Now the parent process just exits after this call. So, if the child doesn't get to run before parent exits, the child will see the ppid as 1, that of INIT and this contradicts the actual data. Hence the test fails.

Quoted 9 lines
Quoted 2 lines

Attached patch fixes the issue. I have verified the same. Please apply.

Thanks for fixing it.

But you forgot to add your Signed-off-by in the patch. ;)

Ah! Thanks for catching that ! Re-attaching it ;)

Thanks

Quoted 8 lines

Suzuki
plain text document attachment
(connectors-gen_fork-wait-for-child.diff)
gen_fork() event should wait until the child exits. Otherwise the child would see INIT as the parent and end up in collecting wrong information to compare with.

Thanks.

Regards--
Subrata

Quoted 22 lines

Index: ltp/testcases/kernel/connectors/pec/event_generator.c
===================================================================

testcases/kernel/connectors/pec/event_generator.c     2009-09-08 13:52:14.000000000 +0000 renamed from testcases/kernel/connectors/pec/event_generator.c        2008-10-22 13:40:31.000000000 +0000 +4 -0
@@ -25,6 +25,9 @@
  #include <stdlib.h>
  #include <stdio.h>
  #include <pwd.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+
  #include "test.h"
 
  #define DEFAULT_EVENT_NUM       1
@@ -94,6 +97,7 @@
  static inline void gen_fork(void)
  {
       pid_t pid;
+     int status;
 
Quoted 10 lines

testcases/kernel/connectors/pec/event_generator.c     2009-09-08 13:52:14.000000000 +0000 line 112

Quoted 10 lines
testcases/kernel/connectors/pec/event_generator.c     2009-09-08 13:52:14.000000000 +0000 renamed from testcases/kernel/connectors/pec/event_generator.c        2008-10-22 13:40:31.000000000 +0000 +2 -0
       pid = fork();
       if (pid == 0) {
@@ -102,6 +106,8 @@
       } else if (pid < 0) {
               fprintf(stderr, "fork() failed\n");
               exit(1);
+     } else {  /* Parent should wait for the child */
+             wait(&status);
       }
  }

Sorry -- this really could have been done `better' with waitpid because you wouldn't need the extra status field. Thanks,
-Garrett

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list