public inbox for mauve-discuss@sourceware.org
 help / color / mirror / Atom feed
* another suggestion for mauve
       [not found] <199812072248.PAA21437@lal.cs.utah.edu>
@ 1998-12-07 15:04 ` Godmar Back
  0 siblings, 0 replies; only message in thread
From: Godmar Back @ 1998-12-07 15:04 UTC (permalink / raw)
  To: mauve-discuss

 Another suggestion/idea.
Right now, there's no guard against a test that calls check repeatedly.

I think a feature that prevents that would be useful.  Take a look at
the test I appended, specifically tests 4/5 (search for "watchdog").  It 
makes use of a watchdog thread.  If an operation times out, check(false) 
would be invoked in the mauve framework, if an operation succeeds, 
check(true), or vice versa, depending on what the desired semantics is.
Ideally, you would want to ignore or prevent the second call.

It is certainly possible to write test cases such that they call check()
only once, no doubt.  However, the test harness might be a place where
tests can share the necessary synchronization code to accomplish this.

For that to work, however, it appears that the tests must pass a
parameter to the check function;  this could for instance be the
testlet itself and an identifier, such as a string or a number.
Identifiers would be determined by the testlet.

So instead of check(true), it would be check(this, 1, true).
The harness would ignore subsequent calls to check(this, 1, _).
For backward compatibility, check(boolean b) could be implemented
as check(null, -1, b); where null and -1 would be out of the range
of valid testcase descriptors and ignored as such.

	- Godmar

/**
 * Tests for Thread.interrupt()
 * This tests only basic functionality, no corner cases.
 *
 * @author Godmar Back <gback@cs.utah.edu>
 */
import java.io.*;
import java.net.ServerSocket;

public class ThreadInterrupt {
    public static void main(String av[]) throws Exception {
	Thread t;
	t = new Thread() {
	    public void run() {
		synchronized(this) {
		    try {
			wait();
			System.out.println("FAIL: returned from wait"); 
		    } catch (InterruptedException e) {
			if (isInterrupted() || interrupted()) {
			    System.out.println(
				"FAIL: interrupted flag has been turned on."); 
			} else {
			    System.out.println("Success 0a.");
			}
		    }
		}
	    }
	};
	ssij(t);
	t = new Thread() {
	    public void run() {
		try {
		    Thread.sleep(5000);
		    System.out.println("FAIL: returned from sleep"); 
		} catch (InterruptedException e) {
		    if (isInterrupted() || interrupted()) {
			System.out.println(
			    "FAIL: interrupted flag has been turned on."); 
		    } else {
			System.out.println("Success 0b.");
		    }
		}
	    }
	};
	ssij(t);
	t = new Thread() {
	    public void run() {
		synchronized (this) {
		    try {
			wait();
		    } catch (InterruptedException e) {
			if (isInterrupted() || interrupted()) {
			    System.out.println(
				"FAIL: interrupted flag has been turned on."); 
			} 
		    }
		    if (isInterrupted() || interrupted()) {
			System.out.println(
			    "FAIL: interrupted flag has been turned on."); 
		    } 
		    try {
			Thread.sleep(1000);
		    } catch (InterruptedException e) {
			System.out.println("FAIL: " + e);
		    }
		}
	    }
	};
	t.start();
	Thread.sleep(1000);
	synchronized(t) {
	    t.interrupt();
	    if (t.isInterrupted()) {
		System.out.println("Success 1.");
	    } else {
		System.out.println("Failure 1.");
	    }
	    // make sure isInterrupted doesn't clear the flag.
	    if (t.isInterrupted()) {
		System.out.println("Success 2.");
	    } else {
		System.out.println("Failure 2.");
	    }
	}
	Thread.sleep(1000);		// let thread finish
	if (t.isInterrupted()) {
	    System.out.println("Failure 3.");
	} else {
	    System.out.println("Success 3.");
	}
	t.join();
	Thread watchdog = new Thread() {
	    public void run() {
		try {
		    Thread.sleep(3000);
		} catch (InterruptedException _) { }
		System.out.println("Failure 4/5.:   Time out.");
		System.exit(-1);
	    }
	};
	watchdog.start();

	Thread me = Thread.currentThread();
	me.interrupt();
	synchronized(me) {
	    try {
		me.wait(4000);
		System.out.println("Failure 4.");
	    } catch (InterruptedException e) {
		System.out.println("Success 4.");
	    }

	    me.interrupt();
	    try {
		Thread.sleep(4000);
		System.out.println("Failure 5.");
	    } catch (InterruptedException e) {
		System.out.println("Success 5.");
	    }
	}
	System.exit(0);
    }

    static void ssij(Thread t) {
	t.start();
	try {
	    Thread.sleep(1000);
	    t.interrupt();
	    t.join();
	} catch (InterruptedException e) { 
	    System.out.println("caught " + e);
	}
    }
}

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

only message in thread, other threads:[~1998-12-07 15:04 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <199812072248.PAA21437@lal.cs.utah.edu>
1998-12-07 15:04 ` another suggestion for mauve Godmar Back

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