Skip to content

Commit

Permalink
Support declarations of operations, global parameters, and operation …
Browse files Browse the repository at this point in the history
…groups in parent classes
  • Loading branch information
ndkoval committed Oct 18, 2019
1 parent ab80a19 commit d3dc35f
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,31 +57,43 @@ private CTestStructure(List<ActorGenerator> actorGenerators, List<OperationGroup
* Constructs {@link CTestStructure} for the specified test class.
*/
public static CTestStructure getFromTestClass(Class<?> testClass) {
// Read named parameter paramgen (declared for class)
Map<String, ParameterGenerator<?>> namedGens = new HashMap<>();
for (Param paramAnn : testClass.getAnnotationsByType(Param.class)) {
Map<String, OperationGroup> groupConfigs = new HashMap<>();
List<ActorGenerator> actorGenerators = new ArrayList<>();
Class<?> clazz = testClass;
while (clazz != null) {
readTestStructureFromClass(clazz, namedGens, groupConfigs, actorGenerators);
clazz = clazz.getSuperclass();
}
// Create StressCTest class configuration
return new CTestStructure(actorGenerators, new ArrayList<>(groupConfigs.values()));
}

private static void readTestStructureFromClass(Class<?> clazz, Map<String, ParameterGenerator<?>> namedGens,
Map<String, OperationGroup> groupConfigs,
List<ActorGenerator> actorGenerators) {
// Read named parameter paramgen (declared for class)
for (Param paramAnn : clazz.getAnnotationsByType(Param.class)) {
if (paramAnn.name().isEmpty()) {
throw new IllegalArgumentException("@Param name in class declaration cannot be empty");
}
namedGens.put(paramAnn.name(), createGenerator(paramAnn));
}
// Read group configurations
Map<String, OperationGroup> groupConfigs = new HashMap<>();
for (OpGroupConfig opGroupConfigAnn: testClass.getAnnotationsByType(OpGroupConfig.class)) {
for (OpGroupConfig opGroupConfigAnn: clazz.getAnnotationsByType(OpGroupConfig.class)) {
groupConfigs.put(opGroupConfigAnn.name(), new OperationGroup(opGroupConfigAnn.name(),
opGroupConfigAnn.nonParallel()));
opGroupConfigAnn.nonParallel()));
}
// Create actor paramgen
List<ActorGenerator> actorGenerators = new ArrayList<>();
for (Method m : testClass.getDeclaredMethods()) {
for (Method m : clazz.getDeclaredMethods()) {
// Operation
if (m.isAnnotationPresent(Operation.class)) {
Operation operationAnn = m.getAnnotation(Operation.class);
boolean isSuspendableMethod = isSuspendable(m);
// Check that params() in @Operation is empty or has the same size as the method
if (operationAnn.params().length > 0 && operationAnn.params().length != m.getParameterCount()) {
throw new IllegalArgumentException("Invalid count of paramgen for " + m.toString()
+ " method in @Operation");
+ " method in @Operation");
}
// Construct list of parameter paramgen
final List<ParameterGenerator<?>> gens = new ArrayList<>();
Expand All @@ -104,8 +116,6 @@ public static CTestStructure getFromTestClass(Class<?> testClass) {
}
}
}
// Create StressCTest class configuration
return new CTestStructure(actorGenerators, new ArrayList<>(groupConfigs.values()));
}

private static ParameterGenerator<?> getOrCreateGenerator(Method m, Parameter p, String nameInOperation,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.jetbrains.kotlinx.lincheck.test

import org.jetbrains.kotlinx.lincheck.*
import org.jetbrains.kotlinx.lincheck.annotations.*
import org.jetbrains.kotlinx.lincheck.strategy.stress.*
import org.junit.*
import java.lang.AssertionError
import kotlin.random.*

@StressCTest(iterations = 1, minimizeFailedScenario = false, requireStateEquivalenceImplCheck = false)
class OperationsInAbstractClassTest : AbstractTestClass() {
@Operation
fun goodOperation() = 10

@Test(expected = AssertionError::class)
fun test(): Unit = LinChecker.check(this::class.java)
}

open class AbstractTestClass {
@Operation
fun badOperation() = Random.nextInt(10)
}

0 comments on commit d3dc35f

Please sign in to comment.