public inbox for frysk-cvs@sourceware.org
help / color / mirror / Atom feed
From: pmachata@sourceware.org
To: frysk-cvs@sourceware.org
Subject: [SCM]  master: New test for vfork
Date: Mon, 10 Dec 2007 13:25:00 -0000	[thread overview]
Message-ID: <20071210132538.23414.qmail@sourceware.org> (raw)

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


                 reply	other threads:[~2007-12-10 13:25 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20071210132538.23414.qmail@sourceware.org \
    --to=pmachata@sourceware.org \
    --cc=frysk-cvs@sourceware.org \
    --cc=frysk@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).