Ares
Ares copied to clipboard
Crash if first sysout happens from other thread than runner thread
See title.
PoC with plain threads
package net.haspamelodica.aresexperiments.tests;
import static org.junit.jupiter.api.Assertions.assertEquals;
import de.tum.in.test.api.ActivateHiddenBefore;
import de.tum.in.test.api.AllowThreads;
import de.tum.in.test.api.BlacklistPath;
import de.tum.in.test.api.Deadline;
import de.tum.in.test.api.MirrorOutput;
import de.tum.in.test.api.PathType;
import de.tum.in.test.api.StrictTimeout;
import de.tum.in.test.api.WhitelistPath;
import de.tum.in.test.api.jupiter.PublicTest;
import net.haspamelodica.aresexperiments.ExampleTestee;
@MirrorOutput
@StrictTimeout(10000)
@Deadline("2021-11-15 05:30 Europe/Berlin")
@ActivateHiddenBefore("2021-11-05 16:30 Europe/Berlin")
//@WhitelistPath(value = "../pgdp2122*w03h01**", type = PathType.GLOB) // for manual assessment and development
@WhitelistPath("target") // mainly for Artemis
@BlacklistPath(value = "{src,target}**Test*.{java,class}", type = PathType.GLOB)
@AllowThreads
public class ExampleTest
{
@PublicTest
public void insecureTest()
{
assertEquals(1337, new ExampleTestee().getSecretNumber());
}
}
package net.haspamelodica.aresexperiments;
public class ExampleTestee
{
public long getSecretNumber()
{
//System.out.println("some output");
Thread thread = new Thread(() -> System.out.println("asdf"));
thread.start();
try
{
thread.join();
} catch(InterruptedException e)
{
throw new RuntimeException(e);
}
return 123;
}
}
This also happens from the CommonPool and crashes regardless of AllowThreads:
PoC with CommonPool
package net.haspamelodica.aresexperiments.tests;
import static org.junit.jupiter.api.Assertions.assertEquals;
import de.tum.in.test.api.ActivateHiddenBefore;
import de.tum.in.test.api.BlacklistPath;
import de.tum.in.test.api.Deadline;
import de.tum.in.test.api.MirrorOutput;
import de.tum.in.test.api.PathType;
import de.tum.in.test.api.StrictTimeout;
import de.tum.in.test.api.WhitelistPath;
import de.tum.in.test.api.jupiter.PublicTest;
import net.haspamelodica.aresexperiments.ExampleTestee;
@MirrorOutput
@StrictTimeout(10000)
@Deadline("2021-11-15 05:30 Europe/Berlin")
@ActivateHiddenBefore("2021-11-05 16:30 Europe/Berlin")
//@WhitelistPath(value = "../pgdp2122*w03h01**", type = PathType.GLOB) // for manual assessment and development
@WhitelistPath("target") // mainly for Artemis
@BlacklistPath(value = "{src,target}**Test*.{java,class}", type = PathType.GLOB)
public class ExampleTest
{
@PublicTest
public void insecureTest()
{
assertEquals(1337, new ExampleTestee().getSecretNumber());
}
}
package net.haspamelodica.aresexperiments;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.IntStream;
public class ExampleTestee
{
public long getSecretNumber()
{
//System.out.println("some output");
Thread forbiddenThread = Thread.currentThread();
AtomicBoolean firstOtherThread = new AtomicBoolean(true);
IntStream
.range(0, 100)
.parallel()
.forEach(i ->
{
if(Thread.currentThread() == forbiddenThread)
return;
if(!firstOtherThread.getAndSet(false))
return;
System.out.println("sysout from other thread");
});
return 123;
}
}
The core exception is thrown in OutputTester#acceptOutput line 56
Probably something related to the lambda creation, not visible in the Java sources.