Skip to content

Commit

Permalink
update.
Browse files Browse the repository at this point in the history
  • Loading branch information
aoli-al committed Jun 27, 2024
1 parent 01121ca commit 78d1105
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 11 deletions.
8 changes: 2 additions & 6 deletions core/src/main/kotlin/cmu/pasta/fray/core/GlobalContext.kt
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@ object GlobalContext {
context.pendingOperation = ParkBlocking()
scheduleNextOperation(true)

context.checkInterrupt()
// Well, unpark is signaled everywhere. We cannot really rely on it to
// block the thread.
LockSupport.unpark(t)
Expand All @@ -216,14 +215,11 @@ object GlobalContext {
val t = Thread.currentThread()
val context = registeredThreads[t.id]!!

if (!context.unparkSignaled) {
if (!context.unparkSignaled && !context.interruptSignaled) {
context.pendingOperation = ParkBlocking()
context.state = ThreadState.Paused
scheduleNextOperation(true)
if (context.unparkSignaled) {
context.checkInterrupt()
}
} else {
} else if (context.unparkSignaled) {
context.unparkSignaled = false
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ data class ExecutionInfo(
sealed class ExecutionConfig(name: String) : OptionGroup(name) {
open fun getExecutionInfo(): ExecutionInfo {
return ExecutionInfo(
MethodExecutor("", "", emptyList(), emptyList()), false, false, false, 10000000)
MethodExecutor("", "", emptyList(), emptyList(), emptyMap()), false, false, false, 10000000)
}
}

Expand All @@ -50,10 +50,12 @@ class CliExecutionConfig : ExecutionConfig("cli") {
val ignoreUnhandledExceptions by option("-e", "--ignore-unhandled-exceptions").flag()
val interleaveMemoryOps by option("-m", "--memory").flag()
val maxScheduledStep by option("-s", "--max-scheduled-step").int().default(10000)
val properties by option("-D", help = "System properties").pair().multiple()

override fun getExecutionInfo(): ExecutionInfo {
val propertyMap = properties.toMap()
return ExecutionInfo(
MethodExecutor(clazz, method, targetArgs, classpaths),
MethodExecutor(clazz, method, targetArgs, classpaths, propertyMap),
ignoreUnhandledExceptions,
timedOpAsYield,
interleaveMemoryOps,
Expand Down
6 changes: 5 additions & 1 deletion core/src/main/kotlin/cmu/pasta/fray/core/command/Executor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@ data class MethodExecutor(
val clazz: String,
val method: String,
val args: List<String>,
val classpaths: List<String>
val classpaths: List<String>,
val properties: Map<String, String>
) : Executor {
override fun execute() {
for (property in properties) {
System.setProperty(property.key, property.value)
}
val classLoader =
URLClassLoader(
classpaths.map { it -> URI("file://$it").toURL() }.toTypedArray(),
Expand Down
3 changes: 3 additions & 0 deletions junit-analyzer/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ repositories {

dependencies {
compileOnly("junit:junit:4.13.2")
compileOnly("org.junit.platform:junit-platform-engine:1.10.2")
compileOnly("org.junit.platform:junit-platform-launcher:1.10.2")
compileOnly("org.junit.platform:junit-platform-console-standalone:1.10.2")
compileOnly(project(":runtime"))
implementation(project(":instrumentation"))
implementation(kotlin("stdlib-jdk8"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ class JunitRunnerTransformer : ClassFileTransformer {
): ByteArray {
val classReader = ClassReader(classfileBuffer)
val classWriter = ClassWriter(classReader, ClassWriter.COMPUTE_MAXS)
val cv: ClassVisitor = JunitInstrumenter(classWriter)
var cv: ClassVisitor = JunitInstrumenter(classWriter)
cv = OutcomeDelayingEngineExecutionListenerInstrumenter(cv)
classReader.accept(cv, ClassReader.EXPAND_FRAMES)
return classWriter.toByteArray()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package cmu.pasta.fray.junit

import cmu.pasta.fray.instrumentation.visitors.ClassVisitorBase
import cmu.pasta.fray.instrumentation.visitors.Utils
import org.objectweb.asm.ClassVisitor
import org.objectweb.asm.MethodVisitor
import org.objectweb.asm.Type
import org.objectweb.asm.commons.AdviceAdapter

class OutcomeDelayingEngineExecutionListenerInstrumenter(cv: ClassVisitor) :
ClassVisitorBase(
cv, "org.junit.platform.launcher.core.OutcomeDelayingEngineExecutionListener") {
override fun instrumentMethod(
mv: MethodVisitor,
access: Int,
name: String,
descriptor: String,
signature: String?,
exceptions: Array<out String>?
): MethodVisitor {
if (name == "executionStarted") {
return object : AdviceAdapter(ASM9, mv, access, name, descriptor) {
override fun onMethodEnter() {
loadArgs()
invokeStatic(
Type.getObjectType(Recorder::class.java.name.replace(".", "/")),
Utils.kFunctionToASMMethod(Recorder::executionStarted),
)
}
}
}
if (name == "executionFinished") {
return object : AdviceAdapter(ASM9, mv, access, name, descriptor) {
override fun onMethodEnter() {
loadArgs()
invokeStatic(
Type.getObjectType(Recorder::class.java.name.replace(".", "/")),
Utils.kFunctionToASMMethod(Recorder::executionFinished),
)
}
}
}
return mv
}
}
36 changes: 35 additions & 1 deletion junit-analyzer/src/main/kotlin/cmu/pasta/fray/junit/Recorder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import cmu.pasta.fray.runtime.Runtime
import java.io.File
import java.lang.instrument.Instrumentation
import junit.framework.TestCase
import org.junit.platform.engine.TestDescriptor
import org.junit.platform.engine.TestExecutionResult
import org.junit.platform.engine.support.descriptor.ClassSource
import org.junit.vintage.engine.descriptor.VintageTestDescriptor

object Recorder {
var newThreadSpawned = false
Expand All @@ -18,6 +22,36 @@ object Recorder {
newThreadSpawned = false
}

@JvmStatic
fun executionStarted(descriptor: TestDescriptor) {
newThreadSpawned = false
}

@JvmStatic
fun executionFinished(descriptor: TestDescriptor, result: TestExecutionResult) {
if (newThreadSpawned) {
if (descriptor is VintageTestDescriptor) {
val methodName = descriptor.displayName
if (descriptor.parent.isPresent) {
val parent = descriptor.parent.get()
if (parent.source.isPresent) {
val source = parent.source.get()
if (source is ClassSource) {
source.className
f.appendText("${source.className}#${methodName}\n")
}
}
}
}
}
newThreadSpawned = false
}

@JvmStatic
fun execution(descriptor: TestDescriptor) {
newThreadSpawned = false
}

@JvmStatic
fun testEnd(testCase: TestCase) {
if (newThreadSpawned) {
Expand All @@ -27,7 +61,7 @@ object Recorder {
}

fun init() {
f.deleteOnExit()
f.delete()
f.createNewFile()
}
}
Expand Down

0 comments on commit 78d1105

Please sign in to comment.