C706 Fall 2009 Homework #4 Due: After the midterm, Tuesday, 11/10 Test your Homework #3 SC monitor solution to the Unisex Bathroom problem. I am providing 6 test cases that you can use to test your solutions. You can also use reachability testing to detect deadlocks in your code. A description of the test cases and directions on testing your programs are given below. Submit: - Two listings of your Homework #3 UnisexBathroom monitor: - the first listing is the one that you submitted for Homework #3 - the second listing is your final version, which should reflect any changes that you made during testing. - An indication of which tests that your final program passed/failed. - A description of any errors that you found in your program during testing - The result of running reachability testing with deadlock detection. Preparing your program: The tests require you to place calls to exerciseEvent() in the correct places in your monitor methods. These calls were in the template program that I gave you for Homework #3. The general form of your methods is: - The enter() methods have a "request" event before the wait, and an "enter" event right before exitMonitor(). - The exit() methods has an "exit" event right before exitMonitor(). private void manEnter(int ID) { enterMonitor("manEnter"); exerciseEvent("manRequest"+ID); if (...) wait() ... more code ... exerciseEvent("manEnter"+ID); exitMonitor(); } private void manExit(int ID) { enterMonitor("manExit"); ... your code ... exerciseEvent("manExit"+ID); exitMonitor(); } private void womanEnter(int ID) { enterMonitor("womanEnter"); exerciseEvent("womanRequest"+ID); if (...) wait() .. more code .... exerciseEvent("womanEnter"+ID); exitMonitor(); } private void womanExit(int ID) { enterMonitor("womanExit"); ... your code ... exerciseEvent("womanExit"+ID); exitMonitor(); } Make sure that the calls to exerciseEvent() are as shown above, and that the event labels match. ***** IMPORTANT ********* Note: You need to change the labels in the code template I gave you to match the ones shown above. ************************* Zip file hm4.zip file contains test cases. There are 6 test files, named "sequence1.txt", "sequence2.txt" ... "sequence6.txt". A description of each test is provided at the end of this file. Running the tests: Below is the procedure for running the tests. The tests assume that your program uses 3 men and 3 women threads. In the template I gave you, I wrote: Man m1 = new Man(c,1); Man m2 = new Man(c,2); Man m3 = new Man(c,3); Woman w1 = new Woman(c,1); Woman w2 = new Woman(c,2); Woman w3 = new Woman(c,3); m1.start(); w1.start(); m2.start(); w2.start(); m3.start(); w3.start(); try { m1.join(); w1.join(); m2.join(); w2.join(); m3.join(); w3.join(); } catch (InterruptedException e) {} Note that the IDs for the men are 1, 2, and 3; same for the women. You should *use this same code*, including the try-catch with the calls to join(); First, make sure your program runs, i.e., all the men and women are able to enter and exit the bathroom, no exceptions are generated, your program terminates, etc. Once you have passed this "sanity check", you are ready to run the tests. If your program has a deadlock, and you can't figure out why the deadock occurs, you can run your program with deadlock detection. If a deadlock is detected, you will get a message explaining, for each thread, the condition variable on which the thread is blocked. To turn on deadlock detection, run your program using: java -Dmode=trace -DdeadlockDetection=on UnisexBathroomSC Note that trace mode creates a file "monitor-spectest.txt" with a trace of your execution. This trace contains the sequence of event labels generated by the calls to exerciseEvent. A trace of a different format is generated in file "monitor-test.txt". To get a more readable trace it helps if you provide each condition variable with a unique name when you construct the condition variable. For example: conditionVariable mensLine = new conditionVarable("mensLine"); But make sure each name is unique, e.g., "mensLine" and "womensLine". ***** IMPORTANT ********* Make sure you run your program at least once in trace mode (as shown above) so that the proper files (e.g., threadID.txt) are created before you start testing your program. If you run reachability testing first, you need to execute your program in trace mode before you run any tests; the ThreadID.txt file produced by reachability testing is different from the one produced during trace mode. ************************* You run a test by copying one of the test sequences I gave to you into a file named "monitor-spectest.txt" and executing the program using: java -Dmode=spectest UnisexBathroomSC This will determine whether the sequence of events in file "monitor-spectest.txt" is feasible. If the sequence is a valid sequnce, it should be feasible. If this sequence is invalid, it should be infeasible. You've been given both valid and invalid sequences. (See the descriptions below.) When you run your test, you'll see the following message if the sequence is feasible: ***Sequence Completed*** If the sequence is infeasible, you'll get a message (after a few seconds) indicating the first event in the sequence that could not be exercised. For example, here is sequence4, which is an invalid sequence: (1,manRequest1) (1,manEnter1) (4,womanRequest1) (4,womanEnter1) and the expected output for sequence4: Infeasible Sequence - timeout waiting for event 4: (4,womanEnter1) If your program is implemented correctly, it should not allow the 4th event to occur; otherwise, it means that your program allows men and women to be in the bathroom at the same time. The above message indicates that the program did not allow the 4th event to occur, as expected. You'll have to copy the contents of the test sequnce files, one by one, into file "monitor-spectest.txt". After passing all the test sequences, you can perform reachability testing (RT) with symmetry reduction on your program by executing: java -Dmode=rt -DdeadlockDetection=on -DsymmetryReduction=on RTDriver UnisexBathroomSC Reachability testing will execute all possible sequences, of which there may many. If reachability testing with symmetry reduction is taking too long, you can reduce the number of threads to 2 men and 2 women. Use -Xmx512m if you are having trouble with the heap size. ************************************* The test files are as follows. sequence1.txt: a valid sequence: man enter and exit then women enter and exit. expected output: ***Sequence Completed*** (1,manRequest1) (1,manEnter1) (2,manRequest2) (2,manEnter2) (3,manRequest3) (3,manEnter3) (1,manExit1) (2,manExit2) (3,manExit3) (4,womanRequest1) (4,womanEnter1) (5,womanRequest2) (5,womanEnter2) (6,womanRequest3) (6,womanEnter3) (4,womanExit1) (5,womanExit2) (6,womanExit3) sequence2.txt: a valid sequence expected output: ***Sequence Completed*** (1,manRequest1) (1,manEnter1) (2,manRequest2) (2,manEnter2) (4,womanRequest1) (1,manExit1) (2,manExit2) (4,womanEnter1) (5,womanRequest2) (5,womanEnter2) (4,womanExit1) (3,manRequest3) (5,womanExit2) (3,manEnter3) (6,womanRequest3) (3,manExit3) (6,womanEnter3) (6,womanExit3) sequence3.txt: a valid sequence expected output: ***Sequence Completed*** (1,manRequest1) (1,manEnter1) (2,manRequest2) (2,manEnter2) (4,womanRequest1) (5,womanRequest2) (1,manExit1) (2,manExit2) (4,womanEnter1) (5,womanEnter2) (4,womanExit1) (3,manRequest3) (5,womanExit2) (3,manEnter3) (6,womanRequest3) (3,manExit3) (6,womanEnter3) (6,womanExit3) sequence4.txt: an invalid sequence. purpose: detect men and women in the bathroom at the same time expected output: Infeasible Sequence - timeout waiting for event 4: (4,womanEnter1) (1,manRequest1) (1,manEnter1) (4,womanRequest1) (4,womanEnter1) sequence5.txt: an invalid sequence purpose: Same kind of sequence as sequence3, but with woman entering first expected output: Infeasible Sequence - timeout waiting for event 4: (1,manEnter1) (4,womanRequest1) (4,womanEnter1) (1,manRequest1) (1,manEnter1) sequence6.txt: an invalid sequence purpose: Man 3 barges ahead of waiting women 1 expected output: Infeasible Sequence - timeout waiting for event 9: (3,manEnter3) (1,manRequest1) (1,manEnter1) (2,manRequest2) (2,manEnter2) (4,womanRequest1) (1,manExit1) (2,manExit2) (3,manRequest3) (3,manEnter3)