public inbox for frysk-cvs@sourceware.org
help / color / mirror / Atom feed
* [SCM]  master: Delete ProcCounter.
@ 2008-03-11 20:28 cagney
  0 siblings, 0 replies; only message in thread
From: cagney @ 2008-03-11 20:28 UTC (permalink / raw)
  To: frysk-cvs

The branch, master has been updated
       via  339efbdf21c71154f4927bb94915bf009bdba38e (commit)
       via  8b0dca95c1a5df49517ed1817283acc9e6a50207 (commit)
      from  fbc2e7379f2b9ca0e5aac52425f94521527d26f0 (commit)

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

- Log -----------------------------------------------------------------
commit 339efbdf21c71154f4927bb94915bf009bdba38e
Author: Andrew Cagney <cagney@redhat.com>
Date:   Tue Mar 11 16:27:18 2008 -0400

    Delete ProcCounter.
    
    frysk-core/frysk/testbed/ChangeLog
    2008-03-11  Andrew Cagney  <cagney@redhat.com>
    
    	* ProcCounter.java: Delete.

commit 8b0dca95c1a5df49517ed1817283acc9e6a50207
Author: Andrew Cagney <cagney@redhat.com>
Date:   Tue Mar 11 16:23:57 2008 -0400

    Don't use ProcCounter in TestTaskForkedObserver.
    
    frysk-core/frysk/proc/ChangeLog
    2008-03-11  Andrew Cagney  <cagney@redhat.com>
    
    	* TestRun.java: Update to match StopEventLoopWhenProcTerminated.
    	* TestTaskForkedObserver.java: Do not use ProcCounter or
    	StopEventLoopWhenProcRemoved.
    
    frysk-core/frysk/testbed/ChangeLog
    2008-03-11  Andrew Cagney  <cagney@redhat.com>
    
    	* StopEventLoopWhenProcTerminated.java: Rename
    	StopEventLoopWhenProcTerminates.java.
    	(StopEventLoopWhenProcTerminated(Offspring)): New.
    	* TestStopEventLoopWhenProcTerminates.java: Update.

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

Summary of changes:
 frysk-core/frysk/proc/ChangeLog                    |    4 +
 frysk-core/frysk/proc/TestRun.java                 |    6 +-
 frysk-core/frysk/proc/TestTaskForkedObserver.java  |  109 +++++++++-----------
 frysk-core/frysk/testbed/ChangeLog                 |    7 ++
 frysk-core/frysk/testbed/ProcCounter.java          |  101 ------------------
 ...s.java => StopEventLoopWhenProcTerminated.java} |   14 ++-
 .../TestStopEventLoopWhenProcTerminates.java       |    8 +-
 7 files changed, 77 insertions(+), 172 deletions(-)
 delete mode 100644 frysk-core/frysk/testbed/ProcCounter.java
 rename frysk-core/frysk/testbed/{StopEventLoopWhenProcTerminates.java => StopEventLoopWhenProcTerminated.java} (88%)

First 500 lines of diff:
diff --git a/frysk-core/frysk/proc/ChangeLog b/frysk-core/frysk/proc/ChangeLog
index 5385f0b..0403483 100644
--- a/frysk-core/frysk/proc/ChangeLog
+++ b/frysk-core/frysk/proc/ChangeLog
@@ -1,5 +1,9 @@
 2008-03-11  Andrew Cagney  <cagney@redhat.com>
 
+	* TestRun.java: Update to match StopEventLoopWhenProcTerminated.
+	* TestTaskForkedObserver.java: Do not use ProcCounter or
+	StopEventLoopWhenProcRemoved.
+
 	* TestFindProc.java (ProcCounter): Delete.
 	(doFindProc(SlaveOffspring)): Replace doFindProc(SlaveOffspring,int).
 
diff --git a/frysk-core/frysk/proc/TestRun.java b/frysk-core/frysk/proc/TestRun.java
index ff3c2d4..d1f475b 100644
--- a/frysk-core/frysk/proc/TestRun.java
+++ b/frysk-core/frysk/proc/TestRun.java
@@ -42,7 +42,7 @@ package frysk.proc;
 
 import frysk.testbed.TearDownFile;
 import frysk.testbed.TestLib;
-import frysk.testbed.StopEventLoopWhenProcTerminates;
+import frysk.testbed.StopEventLoopWhenProcTerminated;
 import frysk.testbed.TaskSet;
 import frysk.testbed.TaskObserverBase;
 
@@ -87,7 +87,7 @@ public class TestRun
     assertRunUntilStop("run \"rm\" to entry for tid");
 
     // Once the proc destroyed has been seen stop the event loop.
-    new StopEventLoopWhenProcTerminates(createdObserver.proc);
+    new StopEventLoopWhenProcTerminated(createdObserver.proc);
 
     // Run the event loop, cap it at 5 seconds.
     assertRunUntilStop("run \"rm\" to exit");
@@ -137,7 +137,7 @@ public class TestRun
     assertTrue("tmp file exists", tmpFile.stillExists());
 
     // Once the proc destroyed has been seen stop the event loop.
-    new StopEventLoopWhenProcTerminates(createdObserver.proc);
+    new StopEventLoopWhenProcTerminated(createdObserver.proc);
 
     // Unblock the attached task and resume the event loop. This
     // will allow the "rm" command to run to completion.
diff --git a/frysk-core/frysk/proc/TestTaskForkedObserver.java b/frysk-core/frysk/proc/TestTaskForkedObserver.java
index ee24c7c..5990546 100644
--- a/frysk-core/frysk/proc/TestTaskForkedObserver.java
+++ b/frysk-core/frysk/proc/TestTaskForkedObserver.java
@@ -41,48 +41,42 @@
 package frysk.proc;
 
 import frysk.testbed.TestLib;
-import frysk.testbed.ProcCounter;
-import frysk.testbed.StopEventLoopWhenProcRemoved;
+import frysk.testbed.StopEventLoopWhenProcTerminated;
 import frysk.testbed.Fibonacci;
 import frysk.testbed.TaskObserverBase;
 import frysk.testbed.DaemonBlockedAtEntry;
+import frysk.isa.signals.Signal;
 
 /**
  * Check that the observer TaskObserver.Forked works.
  */
 
-public class TestTaskForkedObserver
-    extends TestLib
-{
-    static int n = 10;
+public class TestTaskForkedObserver extends TestLib {
+    private 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.
+     * 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 ()
-    {
+    public void testTaskForkedObserver() {
 	ForkObserver forkObserver = new ForkObserver();
-	ProcCounter procCounter
-	    = setupForkTest(forkObserver, new String[]
-		{
-		    getExecPath ("funit-fib-fork"),
-		    Integer.toString(n)
-		});
-
+	runForkTest(forkObserver, new String[]
+	    {
+		getExecPath ("funit-fib-fork"),
+		Integer.toString(n)
+	    });
+	
 	Fibonacci fib = new Fibonacci(n);
 
-	assertEquals("number of child processes created (not counting first)",
+	assertEquals("number of forks (not counting initial process)",
 		     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",
+		     forkObserver.forkCount);
+	assertEquals("number of exits (includes initial process)",
 		     fib.getCallCount(),
+		     forkObserver.terminatedCount);
+	assertEquals("number of times forked+terminated observer added",
+		     fib.getCallCount() * 2,
 		     forkObserver.addedCount());
-	assertEquals("number of forks (one less than number of processes)",
-		     fib.getCallCount() - 1, forkObserver.count);
     }
 
     public void testTaskVforkObserver ()
@@ -91,57 +85,54 @@ public class TestTaskForkedObserver
 	    return;
 
 	ForkObserver forkObserver = new ForkObserver();
-	ProcCounter procCounter
-	    = setupForkTest(forkObserver,
-			    new String[] { getExecPath ("funit-vfork") });
+	runForkTest(forkObserver, new String[] { getExecPath ("funit-vfork") });
 
 	assertEquals("number of child processes created",
-		     1, procCounter.added.size());
+		     1, forkObserver.forkCount);
 	assertEquals("number of child processes destroyed",
-		     1, procCounter.removed.size());
+		     1, forkObserver.terminatedCount);
 	assertEquals("number of times fork observer added",
 		     2, forkObserver.addedCount());
-	assertEquals("number of forks (one less than number of processes)",
-		     1, forkObserver.count);
     }
 
-  public ProcCounter setupForkTest (ForkObserver forkObserver, String[] argv)
-  {
-    // Run a program that forks wildly.
-    DaemonBlockedAtEntry child = new DaemonBlockedAtEntry(argv);
-    int pid = child.getMainTask().getProc().getPid();
-    ProcCounter procCounter = new ProcCounter(pid);
-
-    new StopEventLoopWhenProcRemoved(child);
-    child.getMainTask().requestAddForkedObserver(forkObserver);
-    child.requestRemoveBlock();
-    assertRunUntilStop("run \"fork\" until exit");
-
-    return procCounter;
-
-  }
+    private void runForkTest(ForkObserver forkObserver, String[] argv) {
+	// Run a program that forks wildly.
+	DaemonBlockedAtEntry child = new DaemonBlockedAtEntry(argv);
+	new StopEventLoopWhenProcTerminated(child);
+	forkObserver.watch(child.getMainTask());
+	child.requestRemoveBlock();
+	assertRunUntilStop("run \"fork\" until exit");
+    }
 
-    // Watch for any Task fork events, accumulating them as they
-    // arrive.
+    /**
+     * Watch for any Task fork events, accumulating them as they
+     * arrive.
+     */
     class ForkObserver
 	extends TaskObserverBase
-	implements TaskObserver.Forked
+	implements TaskObserver.Forked, TaskObserver.Terminated
     {
-	int count;
+	int forkCount;
+	int terminatedCount;
 
-	public Action updateForkedParent (Task parent, Task offspring)
-	{
-	    count++;
+	public Action updateTerminated(Task task, Signal signal, int status) {
+	    terminatedCount++;
+	    return Action.CONTINUE;
+	}
+
+	public Action updateForkedParent(Task parent, Task offspring) {
 	    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.
+	void watch(Task offspring) {
 	    offspring.requestAddForkedObserver(this);
+	    offspring.requestAddTerminatedObserver(this);
+	}
+
+	public Action updateForkedOffspring(Task parent, Task offspring) {
+	    forkCount++;
+	    watch(offspring);
 	    offspring.requestUnblock(this);
 	    return Action.BLOCK;
 	}
diff --git a/frysk-core/frysk/testbed/ChangeLog b/frysk-core/frysk/testbed/ChangeLog
index 0d05d31..d167f0b 100644
--- a/frysk-core/frysk/testbed/ChangeLog
+++ b/frysk-core/frysk/testbed/ChangeLog
@@ -1,5 +1,12 @@
 2008-03-11  Andrew Cagney  <cagney@redhat.com>
 
+	* ProcCounter.java: Delete.
+
+	* StopEventLoopWhenProcTerminated.java: Rename
+	StopEventLoopWhenProcTerminates.java.
+	(StopEventLoopWhenProcTerminated(Offspring)): New.
+	* TestStopEventLoopWhenProcTerminates.java: Update.
+
 	* TestLib.java (assertRunToFindProc(ProcessIdentifier)): New.
 	* Offspring.java (assertRunToFindProc()): New.
 	(assertFindProcAndTasks()): Delete.
diff --git a/frysk-core/frysk/testbed/ProcCounter.java b/frysk-core/frysk/testbed/ProcCounter.java
deleted file mode 100644
index 12ac9c8..0000000
--- a/frysk-core/frysk/testbed/ProcCounter.java
+++ /dev/null
@@ -1,101 +0,0 @@
-// This file is part of the program FRYSK.
-//
-// Copyright 2005, 2006, 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
-// the Free Software Foundation; version 2 of the License.
-//
-// FRYSK is distributed in the hope that it will be useful, but
-// WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// General Public License for more details.
-// 
-// You should have received a copy of the GNU General Public License
-// along with FRYSK; if not, write to the Free Software Foundation,
-// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
-// 
-// In addition, as a special exception, Red Hat, Inc. gives You the
-// additional right to link the code of FRYSK with code not covered
-// under the GNU General Public License ("Non-GPL Code") and to
-// distribute linked combinations including the two, subject to the
-// limitations in this paragraph. Non-GPL Code permitted under this
-// exception must only link to the code of FRYSK through those well
-// defined interfaces identified in the file named EXCEPTION found in
-// the source code files (the "Approved Interfaces"). The files of
-// Non-GPL Code may instantiate templates or use macros or inline
-// functions from the Approved Interfaces without causing the
-// resulting work to be covered by the GNU General Public
-// License. Only Red Hat, Inc. may make changes or additions to the
-// list of Approved Interfaces. You must obey the GNU General Public
-// License in all respects for all of the FRYSK code and other code
-// used in conjunction with FRYSK except the Non-GPL Code covered by
-// this exception. If you modify this file, you may extend this
-// exception to your version of the file, but you are not obligated to
-// do so. If you do not wish to provide this exception without
-// modification, you must delete this exception statement from your
-// version and license this file solely under the GPL without
-// exception.
-
-package frysk.testbed;
-
-import java.util.LinkedList;
-import java.util.Observer;
-import java.util.Observable;
-import frysk.proc.Proc;
-import frysk.proc.Manager;
-
-/**
- * Observer that counts the number of processes added and removed.
- * Automaticaly registers itself.
- */
-
-public class ProcCounter
-{
-    // Base count.
-    public final LinkedList added = new LinkedList();
-
-    public final LinkedList removed = new LinkedList();
-
-    /**
-     * Process root; only count descendants of this.
-     */
-    private final int root;
-
-    /**
-     * Create a new ProcCounter counting processes added and
-     * removed. If descendantsOnly, only count children of this
-     * process.
-     */
-    public ProcCounter (int root) {
-	this.root = root;
-	// Set up observers to count proc add and delete events.
-	Manager.host.observableProcAddedXXX.addObserver(new Observer() {
-		public void update (Observable o, Object obj) {
-		    Proc proc = (Proc) obj;
-		    if (ProcCounter.this.root > 0
-			&& !TestLib.isDescendantOf(ProcCounter.this.root,
-						   proc))
-			return;
-		    added.add(proc);
-		}
-	    });
-	Manager.host.observableProcRemovedXXX.addObserver(new Observer() {
-		public void update (Observable o, Object obj) {
-		    Proc proc = (Proc) obj;
-		    if (ProcCounter.this.root > 0
-			&& !TestLib.isDescendantOf(ProcCounter.this.root,
-						   proc))
-			return;
-		    removed.add(proc);
-		}
-	    });
-    }
-	
-    /**
-     * Count all Proc's added and removed.
-     */
-    public ProcCounter() {
-	this(0);
-    }
-}
diff --git a/frysk-core/frysk/testbed/StopEventLoopWhenProcTerminates.java b/frysk-core/frysk/testbed/StopEventLoopWhenProcTerminated.java
similarity index 88%
rename from frysk-core/frysk/testbed/StopEventLoopWhenProcTerminates.java
rename to frysk-core/frysk/testbed/StopEventLoopWhenProcTerminated.java
index b9a2449..5b8737d 100644
--- a/frysk-core/frysk/testbed/StopEventLoopWhenProcTerminates.java
+++ b/frysk-core/frysk/testbed/StopEventLoopWhenProcTerminated.java
@@ -50,14 +50,14 @@ import frysk.sys.ProcessIdentifier;
 
 /**
  * An observer that stops the eventloop when the process with the
- * given pid terminates.
+ * given pid generates a terminated event.
  */
 
-public class StopEventLoopWhenProcTerminates extends TaskObserverBase
+public class StopEventLoopWhenProcTerminated extends TaskObserverBase
     implements TaskObserver.Terminated
 {
     private static final Log fine
-	= Log.fine(StopEventLoopWhenProcTerminates.class);
+	= Log.fine(StopEventLoopWhenProcTerminated.class);
 
     public boolean terminated;
     public Signal signal;
@@ -68,14 +68,18 @@ public class StopEventLoopWhenProcTerminates extends TaskObserverBase
 	return proc.toString();
     }
 
-    public StopEventLoopWhenProcTerminates(Proc proc) {
+    public StopEventLoopWhenProcTerminated(Proc proc) {
 	proc.getMainTask().requestAddTerminatedObserver(this);
     }
 
-    public StopEventLoopWhenProcTerminates(ProcessIdentifier pid) {
+    public StopEventLoopWhenProcTerminated(ProcessIdentifier pid) {
 	this(TestLib.assertRunToFindProc(pid));
     }
 
+    public StopEventLoopWhenProcTerminated(Offspring offspring) {
+	this(offspring.assertRunToFindProc());
+    }
+
     public Action updateTerminated(Task task, Signal signal, int status) {
 	fine.log(this, "updateTerminated", task, "signal", signal, "status",
 		 status);
diff --git a/frysk-core/frysk/testbed/TestStopEventLoopWhenProcTerminates.java b/frysk-core/frysk/testbed/TestStopEventLoopWhenProcTerminates.java
index 6298d77..c253966 100644
--- a/frysk-core/frysk/testbed/TestStopEventLoopWhenProcTerminates.java
+++ b/frysk-core/frysk/testbed/TestStopEventLoopWhenProcTerminates.java
@@ -59,8 +59,8 @@ public class TestStopEventLoopWhenProcTerminates extends TestLib {
 		hello, "world"
 	    });
 	fine.log("adding stopper");
-	StopEventLoopWhenProcTerminates stopper
-	    = new StopEventLoopWhenProcTerminates(daemon.getPid());
+	StopEventLoopWhenProcTerminated stopper
+	    = new StopEventLoopWhenProcTerminated(daemon.getPid());
 	fine.log("unblocking daemon");
 	daemon.requestUnblock();
 	assertRunUntilStop("running hello-world to end");
@@ -74,8 +74,8 @@ public class TestStopEventLoopWhenProcTerminates extends TestLib {
 		hello
 	    });
 	fine.log("adding stopper");
-	StopEventLoopWhenProcTerminates stopper
-	    = new StopEventLoopWhenProcTerminates(daemon.getPid());
+	StopEventLoopWhenProcTerminated stopper
+	    = new StopEventLoopWhenProcTerminated(daemon.getPid());
 	fine.log("unblocking daemon");
 	daemon.requestUnblock();
 	assertRunUntilStop("running hello-world to end");


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


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

only message in thread, other threads:[~2008-03-11 20:28 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-03-11 20:28 [SCM] master: Delete ProcCounter cagney

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).