Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/framework-tests-matrix.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
},
{
"PART_NAME": "examples-part2",
"TESTS_TO_RUN": "--tests \"org.utbot.examples.exceptions.*\" --tests \"org.utbot.examples.invokes.*\" --tests \"org.utbot.examples.lambda.*\" --tests \"org.utbot.examples.make.symbolic.*\" --tests \"org.utbot.examples.math.*\" --tests \"org.utbot.examples.mixed.*\" --tests \"org.utbot.examples.mock.*\" --tests \"org.utbot.examples.models.*\" --tests \"org.utbot.examples.natives.*\" --tests \"org.utbot.examples.objects.*\" --tests \"org.utbot.examples.reflection.*\""
"TESTS_TO_RUN": "--tests \"org.utbot.examples.exceptions.*\" --tests \"org.utbot.examples.invokes.*\" --tests \"org.utbot.examples.lambda.*\" --tests \"org.utbot.examples.make.symbolic.*\" --tests \"org.utbot.examples.math.*\" --tests \"org.utbot.examples.mixed.*\" --tests \"org.utbot.examples.mock.*\" --tests \"org.utbot.examples.models.*\" --tests \"org.utbot.examples.natives.*\" --tests \"org.utbot.examples.objects.*\" --tests \"org.utbot.examples.reflection.*\" --tests \"org.utbot.examples.threads.*\""
},
{
"PART_NAME": "examples-part3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package org.utbot.framework.plugin.api.visible
/**
* An artificial exception that stores an exception that would be thrown in case of consuming stream by invoking terminal operations.
* [innerException] stores this possible exception (null if [UtStreamConsumingException] was constructed by the engine).
*
* NOTE: this class should be visible in almost all parts of the tool - Soot, engine, concrete execution and code generation,
* that's the reason why this class is placed in this module and this package is called `visible`.
*/
data class UtStreamConsumingException(private val innerException: Exception?) : RuntimeException() {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package org.utbot.examples.annotations
import org.junit.jupiter.api.Disabled
import org.junit.jupiter.api.Test
import org.utbot.testcheckers.eq
import org.utbot.testing.AtLeast
import org.utbot.testing.UtValueTestCaseChecker

internal class NotNullAnnotationTest : UtValueTestCaseChecker(testClass = NotNullAnnotation::class) {
Expand Down Expand Up @@ -68,7 +69,8 @@ internal class NotNullAnnotationTest : UtValueTestCaseChecker(testClass = NotNul
checkStatics(
NotNullAnnotation::notNullStaticField,
eq(1),
{ statics, result -> result == statics.values.single().value }
{ statics, result -> result == statics.values.single().value },
coverage = AtLeast(66)
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.utbot.examples.threads

import org.junit.jupiter.api.Test
import org.utbot.testcheckers.eq
import org.utbot.testing.AtLeast
import org.utbot.testing.UtValueTestCaseChecker

class CountDownLatchExamplesTest : UtValueTestCaseChecker(testClass = CountDownLatchExamples::class) {
@Test
fun testGetAndDown() {
check(
CountDownLatchExamples::getAndDown,
eq(2),
{ countDownLatch, l -> countDownLatch.count == 0L && l == 0L },
{ countDownLatch, l ->
val firstCount = countDownLatch.count

firstCount != 0L && l == firstCount - 1
},
coverage = AtLeast(83)
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package org.utbot.examples.threads

import org.junit.jupiter.api.Test
import org.utbot.testcheckers.withoutConcrete
import org.utbot.testing.AtLeast
import org.utbot.testing.UtValueTestCaseChecker
import org.utbot.testing.ignoreExecutionsNumber
import org.utbot.testing.isException

// IMPORTANT: most of the these tests test only the symbolic engine
// and should not be used for testing conrete or code generation since they are possibly flaky in the concrete execution
// (see https://github.com/UnitTestBot/UTBotJava/issues/1610)
class ExecutorServiceExamplesTest : UtValueTestCaseChecker(testClass = ExecutorServiceExamples::class) {
@Test
fun testExceptionInExecute() {
withoutConcrete {
withEnabledTestingCodeGeneration(false) {
checkWithException(
ExecutorServiceExamples::throwingInExecute,
ignoreExecutionsNumber,
{ r -> r.isException<IllegalStateException>() }
)
}
}
}

@Test
fun testChangingCollectionInExecute() {
withoutConcrete {
withEnabledTestingCodeGeneration(false) {
check(
ExecutorServiceExamples::changingCollectionInExecute,
ignoreExecutionsNumber,
{ r -> r == 42 },
coverage = AtLeast(78)
)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package org.utbot.examples.threads

import org.junit.jupiter.api.Test
import org.utbot.testcheckers.eq
import org.utbot.testcheckers.withoutConcrete
import org.utbot.testing.AtLeast
import org.utbot.testing.UtValueTestCaseChecker
import org.utbot.testing.isException
import java.util.concurrent.ExecutionException

// IMPORTANT: most of the these tests test only the symbolic engine
// and should not be used for testing conrete or code generation since they are possibly flaky in the concrete execution
// (see https://github.com/UnitTestBot/UTBotJava/issues/1610)
class FutureExamplesTest : UtValueTestCaseChecker(testClass = FutureExamples::class) {
@Test
fun testThrowingRunnable() {
withoutConcrete {
checkWithException(
FutureExamples::throwingRunnableExample,
eq(1),
{ r -> r.isException<ExecutionException>() },
coverage = AtLeast(71)
)
}
}

@Test
fun testResultFromGet() {
check(
FutureExamples::resultFromGet,
eq(1),
{ r -> r == 42 },
)
}

@Test
fun testChangingCollectionInFuture() {
withEnabledTestingCodeGeneration(false) {
check(
FutureExamples::changingCollectionInFuture,
eq(1),
{ r -> r == 42 },
)
}
}

@Test
fun testChangingCollectionInFutureWithoutGet() {
withoutConcrete {
withEnabledTestingCodeGeneration(false) {
check(
FutureExamples::changingCollectionInFutureWithoutGet,
eq(1),
{ r -> r == 42 },
coverage = AtLeast(78)
)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package org.utbot.examples.threads

import org.junit.jupiter.api.Test
import org.utbot.testcheckers.withoutConcrete
import org.utbot.testing.AtLeast
import org.utbot.testing.UtValueTestCaseChecker
import org.utbot.testing.ignoreExecutionsNumber
import org.utbot.testing.isException

// IMPORTANT: most of the these tests test only the symbolic engine
// and should not be used for testing conrete or code generation since they are possibly flaky in the concrete execution
// (see https://github.com/UnitTestBot/UTBotJava/issues/1610)
class ThreadExamplesTest : UtValueTestCaseChecker(testClass = ThreadExamples::class) {
@Test
fun testExceptionInStart() {
withoutConcrete {
withEnabledTestingCodeGeneration(false) {
checkWithException(
ThreadExamples::explicitExceptionInStart,
ignoreExecutionsNumber,
{ r -> r.isException<IllegalStateException>() }
)
}
}
}

@Test
fun testChangingCollectionInThread() {
withoutConcrete {
withEnabledTestingCodeGeneration(false) {
check(
ThreadExamples::changingCollectionInThread,
ignoreExecutionsNumber,
{ r -> r == 42 },
coverage = AtLeast(81)
)
}
}
}

@Test
fun testChangingCollectionInThreadWithoutStart() {
withoutConcrete {
withEnabledTestingCodeGeneration(false) {
checkWithException(
ThreadExamples::changingCollectionInThreadWithoutStart,
ignoreExecutionsNumber,
{ r -> r.isException<IndexOutOfBoundsException>() },
coverage = AtLeast(81)
)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.utbot.engine.overrides.security;

import org.utbot.api.mock.UtMock;

import java.security.Permission;

/**
Expand All @@ -13,4 +15,8 @@ public void checkPermission(Permission perm) {
public void checkPackageAccess(String pkg) {
// Do nothing to allow everything
}

public ThreadGroup getThreadGroup() {
return new ThreadGroup(UtMock.makeSymbolic());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import static org.utbot.engine.overrides.UtOverrideMock.visit;
import static java.lang.Math.min;

@SuppressWarnings({"ConstantConditions", "unused"})
@SuppressWarnings("unused")
public class UtString implements java.io.Serializable, Comparable<String>, CharSequence {
char[] value;
int length;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package org.utbot.engine.overrides.threads;

import org.utbot.api.annotation.UtClassMock;

import java.util.concurrent.Executor;
import java.util.function.Supplier;

@UtClassMock(target = java.util.concurrent.CompletableFuture.class, internalUsage = true)
public class CompletableFuture {
public static java.util.concurrent.CompletableFuture<Void> runAsync(Runnable runnable) {
java.util.concurrent.CompletableFuture<Void> future = new java.util.concurrent.CompletableFuture<>();

return future.thenRun(runnable);
}

@SuppressWarnings("unused")
public static java.util.concurrent.CompletableFuture<Void> runAsync(Runnable runnable, Executor ignoredExecutor) {
return runAsync(runnable);
}

public static <U> java.util.concurrent.CompletableFuture<U> supplyAsync(Supplier<U> supplier) {
try {
final U value = supplier.get();

return new UtCompletableFuture<>(value).toCompletableFuture();
} catch (Throwable e) {
return new UtCompletableFuture<U>(e).toCompletableFuture();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
package org.utbot.engine.overrides.threads;

import org.utbot.api.annotation.UtClassMock;
import org.utbot.api.mock.UtMock;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ThreadFactory;

@UtClassMock(target = java.util.concurrent.Executors.class, internalUsage = true)
public class Executors {
public static ExecutorService newFixedThreadPool(int nThreads) {
if (nThreads <= 0) {
throw new IllegalArgumentException();
}

return new UtExecutorService();
}

public static ExecutorService newWorkStealingPool() {
return new UtExecutorService();
}

public static ExecutorService newWorkStealingPool(int parallelism) {
if (parallelism <= 0) {
throw new IllegalArgumentException();
}

return new UtExecutorService();
}

public static ExecutorService newFixedThreadPool(int nThreads, ThreadFactory threadFactory) {
if (threadFactory == null) {
throw new NullPointerException();
}

return newFixedThreadPool(nThreads);
}

public static ExecutorService newSingleThreadExecutor() {
return new UtExecutorService();
}

public static ExecutorService newSingleThreadExecutor(ThreadFactory threadFactory) {
if (threadFactory == null) {
throw new NullPointerException();
}

return new UtExecutorService();
}

public static ExecutorService newCachedThreadPool() {
return new UtExecutorService();
}

public static ExecutorService newCachedThreadPool(ThreadFactory threadFactory) {
if (threadFactory == null) {
throw new NullPointerException();
}

return new UtExecutorService();
}

public static ScheduledExecutorService newSingleThreadScheduledExecutor() {
return new UtExecutorService();
}

public static ScheduledExecutorService newSingleThreadScheduledExecutor(ThreadFactory threadFactory) {
if (threadFactory == null) {
throw new NullPointerException();
}

return new UtExecutorService();
}

public static ScheduledExecutorService newScheduledThreadPool(int corePoolSize) {
if (corePoolSize < 0) {
throw new IllegalArgumentException();
}

return new UtExecutorService();
}

public static ScheduledExecutorService newScheduledThreadPool(int corePoolSize, ThreadFactory threadFactory) {
if (corePoolSize < 0) {
throw new IllegalArgumentException();
}

if (threadFactory == null) {
throw new NullPointerException();
}

return new UtExecutorService();
}

public static ExecutorService unconfigurableExecutorService(ExecutorService executor) {
if (executor == null) {
throw new NullPointerException();
}

return new UtExecutorService();
}

public static ScheduledExecutorService unconfigurableScheduledExecutorService(ScheduledExecutorService executor) {
if (executor == null) {
throw new NullPointerException();
}

return new UtExecutorService();
}

public static ThreadFactory defaultThreadFactory() {
// TODO make a wrapper?
return UtMock.makeSymbolic();
}

public static ThreadFactory privilegedThreadFactory() {
return defaultThreadFactory();
}
}
Loading