Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash if first sysout happens from other thread than runner thread #316

Open
Haspamelodica opened this issue Aug 9, 2023 · 2 comments
Open
Labels
bug Something isn't working

Comments

@Haspamelodica
Copy link
Contributor

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;
	}
}
@Haspamelodica
Copy link
Contributor Author

The core exception is thrown in OutputTester#acceptOutput line 56

@MaisiKoleni MaisiKoleni added the bug Something isn't working label Aug 9, 2023
@MaisiKoleni MaisiKoleni added this to the Version 1.13.1 milestone Aug 9, 2023
@MaisiKoleni
Copy link
Collaborator

Probably something related to the lambda creation, not visible in the Java sources.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants