public inbox for frysk-cvs@sourceware.org help / color / mirror / Atom feed
From: cagney@sourceware.org To: frysk-cvs@sourceware.org Subject: [SCM] master: Really commit frysk.testbed.StatState Date: Wed, 16 Jan 2008 12:55:00 -0000 [thread overview] Message-ID: <20080116125458.4006.qmail@sourceware.org> (raw) The branch, master has been updated via 0443d3a51378ad5454ed4b04d12823380e7385cf (commit) from b9f0693a2c3c776ceba0aa5cf3e172a3084547bb (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email. - Log ----------------------------------------------------------------- commit 0443d3a51378ad5454ed4b04d12823380e7385cf Author: Andrew Cagney <cagney@redhat.com> Date: Wed Jan 16 07:52:11 2008 -0500 Really commit frysk.testbed.StatState ----------------------------------------------------------------------- Summary of changes: frysk-core/frysk/testbed/StatState.java | 124 ++++++++++++++++++++ .../TestStatState.java} | 25 ++--- 2 files changed, 135 insertions(+), 14 deletions(-) create mode 100644 frysk-core/frysk/testbed/StatState.java copy frysk-core/frysk/{debuginfo/CompilerVersion.java => testbed/TestStatState.java} (84%) First 500 lines of diff: diff --git a/frysk-core/frysk/testbed/StatState.java b/frysk-core/frysk/testbed/StatState.java new file mode 100644 index 0000000..5085e8e --- /dev/null +++ b/frysk-core/frysk/testbed/StatState.java @@ -0,0 +1,124 @@ +// This file is part of the program FRYSK. +// +// Copyright 2008, 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 frysk.proc.Manager; +import frysk.junit.TestCase; +import frysk.sys.proc.Stat; +import frysk.rsl.Log; +import frysk.event.TimerEvent; + +/** + * Class for directly tracking <tt>/proc/$$/stat</tt>. + */ + +public class StatState { + private final static Log fine = Log.fine(StatState.class); + private final static Log finest = Log.finest(StatState.class); + + private final char state; + private StatState(char state) { + this.state = state; + } + + public String toString() { + return "StatState." + state; + } + + public static final StatState RUNNING = new StatState('R'); + public static final StatState SLEEPING = new StatState('S'); + public static final StatState DISK_WAIT = new StatState('D'); + public static final StatState ZOMBIE = new StatState('Z'); + public static final StatState TRACED_OR_STOPPED = new StatState('T'); + public static final StatState PAGING = new StatState('W'); + + /** + * Asserts that TID is in the specified state; or transitions to + * that state within a short period of time. + */ + public void assertIs(int tid) { + fine.log(this, "assertInState", tid); + Stat stat = new Stat(); + long startTime = System.currentTimeMillis(); + stat.refresh(tid); + do { + stat.refresh(); + finest.log(this, "assertInState tid", tid, "in", stat.state); + if (stat.state == state) + break; + try { + Thread.sleep(100); + } catch (InterruptedException ie) { + finest.log(this, "assertInState: ignoring interrupt"); + } + } while (System.currentTimeMillis() + < startTime + TestCase.getTimeoutMilliseconds()); + TestCase.assertEquals("Stat state for tid " + tid, + state, stat.state); + } + + private static class Probe extends TimerEvent { + private final Stat stat; + private final StatState state; + Probe(int pid, StatState state) { + super(0, 100); // Refresh every 100ms + this.stat = new Stat(pid); + this.state = state; + } + public void execute() { + stat.refresh(); + finest.log(state, "assertRunToState tid", stat.tid, "in", + stat.state); + if (state.state == stat.state) { + Manager.eventLoop.remove(this); + Manager.eventLoop.requestStop(); + } + } + } + + public void assertRunUntil(int tid) { + fine.log(this, "assertRunToState tid", tid); + Manager.eventLoop.add(new Probe(tid, this)); + long timeout = TestCase.getTimeoutMilliseconds(); + TestCase.assertTrue("run to state: " + state, + Manager.eventLoop.runPolling(timeout)); + + } +} diff --git a/frysk-core/frysk/debuginfo/CompilerVersion.java b/frysk-core/frysk/testbed/TestStatState.java similarity index 84% copy from frysk-core/frysk/debuginfo/CompilerVersion.java copy to frysk-core/frysk/testbed/TestStatState.java index eb50621..679e672 100644 --- a/frysk-core/frysk/debuginfo/CompilerVersion.java +++ b/frysk-core/frysk/testbed/TestStatState.java @@ -37,22 +37,19 @@ // version and license this file solely under the GPL without // exception. -package frysk.debuginfo; +package frysk.testbed; -import frysk.rsl.Log; +/** + * Class for directly tracking <tt>/proc/$$/stat</tt>. + */ -public class CompilerVersion { - - protected static Log fine = Log.fine(CompilerVersion.class); - public final String compilerString; - - CompilerVersion(String compString) { - this.compilerString = compString; - fine.log(this, "Created compilerVersion for:", compString); +public class TestStatState extends TestLib { + public void testSleeping() { + Offspring daemon = SlaveOffspring.createDaemon(); + daemon.assertIs(StatState.SLEEPING); } - - public boolean supportsClassType() { - return false; + public void testRunToSleeping() { + Offspring daemon = SlaveOffspring.createDaemon(); + daemon.assertRunUntil(StatState.SLEEPING); } - } hooks/post-receive -- frysk system monitor/debugger
reply other threads:[~2008-01-16 12:55 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=20080116125458.4006.qmail@sourceware.org \ --to=cagney@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: linkBe 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).