Skip to content
Snippets Groups Projects
Commit f8601464 authored by Janis Daniel Dähne's avatar Janis Daniel Dähne
Browse files

- timeout was not applied (runner was not terminating when the users program not terminated)

parent 65aa5dd5
Branches
No related tags found
No related merge requests found
......@@ -119,8 +119,13 @@ public class Main {
static String DefaultCGroupName = "syndrom";
public static void main(String[] myArgs) throws IOException {
if (isDebug) {
System.out.println(Arrays.toString(myArgs));
}
......@@ -294,9 +299,9 @@ public class Main {
ArrayList<String> testContents = new ArrayList<>();
if (useDebugTestContent) {
testContents.add("$ 1");
//testContents.add("$ 1");
testContents.add("> 0");
testContents.add("> 1");
//testContents.add("> 1");
//testContents.add("< 42");
//testContents.add("> 42");
//testContents.add("> 42");
......@@ -656,18 +661,22 @@ public class Main {
} catch (InterruptedException e) {
//timeout hit
returnValue = 1;
futureResult = -100;
} catch (ExecutionException e) {
//this also happens if the program (to test) throws an error
//System.out.println("ExecutionException occurred");
returnValue = 2;
futureResult = -100;
} catch (TimeoutException e) {
//timeout hit
returnValue = 3;
futureResult = -100;
} catch (IllegalThreadStateException e) {
//executor.shutdownNow();
p.destroy(); //TODO does not stop child processes --> http://stackoverflow.com/questions/6356340/killing-a-process-using-java
returnValue = 3;
futureResult = -100;
}
if (isDebug) {
......@@ -681,13 +690,29 @@ public class Main {
readDebugFromErrorStream(errReader, true);
String line = null;
while (reader[0].ready()) {
//if the test ended and the program outputs something the test should fail...
if ((line = reader[0].readLine()) != null) {
Conversation.add(outputFromProgramChar + " " + toSafeLine(line.trim()));
Conversation.add(expectedOutputPrefix + " " + ""); //no more output expected... -> empty
outputMismatch[0] = true;
if (returnValue == 0) {
//process has finished normally so we can safely check the reader.ready()
//when there is a timeout (because user program waits for input reader.ready() would block this program...
//but the program terminated normally here...
while (reader[0].ready()) { //this line blocks if the process has not yet ended (user program waits for input??)
//if the test ended and the program outputs something the test should fail...
if ((line = reader[0].readLine()) != null) {
Conversation.add(outputFromProgramChar + " " + toSafeLine(line.trim()));
Conversation.add(expectedOutputPrefix + " " + ""); //no more output expected... -> empty
outputMismatch[0] = true;
}
}
} else {
//process has ended in an unusual way...
//Conversation.add(outputFromProgramChar + " " + toSafeLine(line.trim()));
//Conversation.add(expectedOutputPrefix + " " + ""); //no more output expected... -> empty
//pretend false output
//outputMismatch[0] = true;
//some thread exception ... pretend timeout...
returnValue = 3;
}
writer[0].close();
......@@ -696,8 +721,11 @@ public class Main {
//e.printStackTrace();
}
if (futureResult != 0) {
// 0 = all went well (java code)
// 0 = all went well (java code)
//-100 is timeout --> returnValue is 3
//this if would change this to 2
if (futureResult != 0 && futureResult != -100) {
//else some error?
errorReader = new BufferedReader(new InputStreamReader(p.getErrorStream()));
......@@ -715,6 +743,9 @@ public class Main {
//e.printStackTrace();
}
//}
//some error occurred during execution of the users program (e.g. numberformat exception....)
returnValue = 2;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment