public inbox for frysk-cvs@sourceware.org
help / color / mirror / Atom feed
* [SCM]  master: New test for vfork
@ 2007-12-10 13:25 pmachata
  0 siblings, 0 replies; only message in thread
From: pmachata @ 2007-12-10 13:25 UTC (permalink / raw)
  To: frysk-cvs

The branch, master has been updated
       via  898a3b520202dc904f4dbd2863380842bcf0e727 (commit)
      from  d168e117465114bc38e66b5779a4b4cc93399140 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email.

- Log -----------------------------------------------------------------
commit 898a3b520202dc904f4dbd2863380842bcf0e727
Author: Petr Machata <pmachata@redhat.com>
Date:   Mon Dec 10 14:05:30 2007 +0100

    New test for vfork

-----------------------------------------------------------------------

Summary of changes:
 frysk-core/frysk/pkglibdir/ChangeLog               |    4 +
 .../{funit-syscallloop.c => funit-vfork.c}         |   32 +++--
 frysk-core/frysk/proc/ChangeLog                    |    8 ++
 frysk-core/frysk/proc/TestTaskForkedObserver.java  |  124 ++++++++++++--------
 4 files changed, 106 insertions(+), 62 deletions(-)
 copy frysk-core/frysk/pkglibdir/{funit-syscallloop.c => funit-vfork.c} (86%)

First 500 lines of diff:
diff --git a/frysk-core/frysk/pkglibdir/ChangeLog b/frysk-core/frysk/pkglibdir/ChangeLog
index 989cefa..2acecab 100644
--- a/frysk-core/frysk/pkglibdir/ChangeLog
+++ b/frysk-core/frysk/pkglibdir/ChangeLog
@@ -1,3 +1,7 @@
+2007-12-10  Petr Machata  <pmachata@redhat.com>
+
+	* funit-vfork.c: New file.
+
 2007-12-04  Jose Flavio Aguilar Paulino <joseflavio@gmail.com>
 
 	* funit-regs.S: Add floating support for PowerPC64.
diff --git a/frysk-core/frysk/pkglibdir/funit-syscallloop.c b/frysk-core/frysk/pkglibdir/funit-vfork.c
similarity index 86%
copy from frysk-core/frysk/pkglibdir/funit-syscallloop.c
copy to frysk-core/frysk/pkglibdir/funit-vfork.c
index 293c514..d40b923 100644
--- a/frysk-core/frysk/pkglibdir/funit-syscallloop.c
+++ b/frysk-core/frysk/pkglibdir/funit-vfork.c
@@ -1,6 +1,6 @@
 // This file is part of the program FRYSK.
 //
-// Copyright 2005, 2006, Red Hat Inc.
+// Copyright 2007 Red Hat Inc.
 //
 // FRYSK is free software; you can redistribute it and/or modify it
 // under the terms of the GNU General Public License as published by
@@ -37,24 +37,30 @@
 // version and license this file solely under the GPL without
 // exception.
 
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
 
 int
-main (int argc, char **argv)
+main(void)
 {
-  int i;
-  int loop_count = atoi (argv[1]);
-
-  if(loop_count == -1){
-    while(1){
-       close (-1);
+  pid_t pid = vfork();
+  if (pid == -1)
+    {
+      perror ("vfork");
+      exit (1);
     }
-  }else{
-    for (i = 0; i < loop_count; ++i){
-      close (-1);
+  else if (pid == 0)
+    {
+      puts ("child");
+      _exit (1);
+    }
+  else
+    {
+      waitpid (pid, NULL, 0);
+      puts ("child done");
     }
-  }
-
   return 0;
 }
diff --git a/frysk-core/frysk/proc/ChangeLog b/frysk-core/frysk/proc/ChangeLog
index 91240ee..6ce4ae9 100644
--- a/frysk-core/frysk/proc/ChangeLog
+++ b/frysk-core/frysk/proc/ChangeLog
@@ -1,3 +1,11 @@
+2007-12-10  Petr Machata  <pmachata@redhat.com>
+
+	* TestTaskForkedObserver.java:
+	(ForkObserver): Class moved from testTaskForkedObserver.
+	(setupForkTest): New method, contains what's common for the two tests.
+	(testTaskForkedObserver): Adjusted to above changes.
+	(testTaskVforkObserver): New test.
+
 2007-12-04  Andrew Cagney  <cagney@redhat.com>
 
 	Merge frysk.sys.Sig into frysk.sys.Signal.
diff --git a/frysk-core/frysk/proc/TestTaskForkedObserver.java b/frysk-core/frysk/proc/TestTaskForkedObserver.java
index 5adc87e..f8f5462 100644
--- a/frysk-core/frysk/proc/TestTaskForkedObserver.java
+++ b/frysk-core/frysk/proc/TestTaskForkedObserver.java
@@ -54,47 +54,58 @@ import frysk.testbed.DaemonBlockedAtEntry;
 public class TestTaskForkedObserver
     extends TestLib
 {
-  static int n = 10;
+    static int n = 10;
 
-  /**
-   * Test that the fork count from a sub-program that, in turn, creates lots and
-   * lots of sub-processes matches the expected.
-   */
-  public void testTaskForkedObserver ()
-  {
-    // Watch for any Task fork events, accumulating them as they
-    // arrive.
-    class ForkObserver
-        extends TaskObserverBase
-        implements TaskObserver.Forked
+    /**
+     * Test that the fork count from a sub-program that, in turn, creates lots and
+     * lots of sub-processes matches the expected.
+     */
+    public void testTaskForkedObserver ()
+    {
+	ForkObserver forkObserver = new ForkObserver();
+	ProcCounter procCounter
+	    = setupForkTest(forkObserver, new String[]
+		{
+		    getExecPath ("funit-fib-fork"),
+		    Integer.toString(n)
+		});
+
+	Fibonacci fib = new Fibonacci(n);
+
+	assertEquals("number of child processes created (not counting first)",
+		     fib.getCallCount() - 1,
+		     procCounter.added.size());
+	assertEquals("number of child processes destroyed (not counting first)",
+		     fib.getCallCount() - 1,
+		     procCounter.removed.size());
+	assertEquals("number of times fork observer added",
+		     fib.getCallCount(),
+		     forkObserver.addedCount());
+	assertEquals("number of forks (one less than number of processes)",
+		     fib.getCallCount() - 1, forkObserver.count);
+    }
+
+    public void testTaskVforkObserver ()
     {
-      int count;
-
-      public Action updateForkedParent (Task parent, Task offspring)
-      {
-        count++;
-        parent.requestUnblock(this);
-        return Action.BLOCK;
-      }
-
-      public Action updateForkedOffspring (Task parent, Task offspring)
-      {
-        // XXX: Is this legit? Like knowing that the request
-        // won't be processed until the event loop is run
-        // again so that there's no race condition.
-        offspring.requestAddForkedObserver(this);
-        offspring.requestUnblock(this);
-        return Action.BLOCK;
-      }
+	ForkObserver forkObserver = new ForkObserver();
+	ProcCounter procCounter
+	    = setupForkTest(forkObserver,
+			    new String[] { getExecPath ("funit-vfork") });
+
+	assertEquals("number of child processes created",
+		     1, procCounter.added.size());
+	assertEquals("number of child processes destroyed",
+		     1, procCounter.removed.size());
+	assertEquals("number of times fork observer added",
+		     2, forkObserver.addedCount());
+	assertEquals("number of forks (one less than number of processes)",
+		     1, forkObserver.count);
     }
-    ForkObserver forkObserver = new ForkObserver();
 
+  public ProcCounter setupForkTest (ForkObserver forkObserver, String[] argv)
+  {
     // Run a program that forks wildly.
-    DaemonBlockedAtEntry child = new DaemonBlockedAtEntry(new String[]
-	{
-	    getExecPath ("funit-fib-fork"),
-	    Integer.toString(n)
-	});
+    DaemonBlockedAtEntry child = new DaemonBlockedAtEntry(argv);
     int pid = child.getMainTask().getProc().getPid();
     ProcCounter procCounter = new ProcCounter(pid);
 
@@ -103,18 +114,33 @@ public class TestTaskForkedObserver
     child.requestRemoveBlock();
     assertRunUntilStop("run \"fork\" until exit");
 
-    Fibonacci fib = new Fibonacci(n);
-
-    assertEquals("number of child processes created (not counting first)",
-		 fib.getCallCount() - 1,
-                 procCounter.added.size());
-    assertEquals("number of child processes destroyed (not counting first)",
-		 fib.getCallCount() - 1,
-                 procCounter.removed.size());
-    assertEquals("number of times fork observer added",
-		 fib.getCallCount(),
-                 forkObserver.addedCount());
-    assertEquals("number of forks (one less than number of processes)",
-                 fib.getCallCount() - 1, forkObserver.count);
+    return procCounter;
+
   }
+
+    // Watch for any Task fork events, accumulating them as they
+    // arrive.
+    class ForkObserver
+	extends TaskObserverBase
+	implements TaskObserver.Forked
+    {
+	int count;
+
+	public Action updateForkedParent (Task parent, Task offspring)
+	{
+	    count++;
+	    parent.requestUnblock(this);
+	    return Action.BLOCK;
+	}
+
+	public Action updateForkedOffspring (Task parent, Task offspring)
+	{
+	    // XXX: Is this legit? Like knowing that the request
+	    // won't be processed until the event loop is run
+	    // again so that there's no race condition.
+	    offspring.requestAddForkedObserver(this);
+	    offspring.requestUnblock(this);
+	    return Action.BLOCK;
+	}
+    }
 }


hooks/post-receive
--
frysk system monitor/debugger


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2007-12-10 13:25 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-12-10 13:25 [SCM] master: New test for vfork pmachata

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).