Skip to content

Commit

Permalink
Add local/global option
Browse files Browse the repository at this point in the history
  • Loading branch information
p51lee committed Jan 18, 2025
1 parent cc7403e commit 8eb37eb
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 7 deletions.
22 changes: 20 additions & 2 deletions src/main/scala/esmeta/es/util/fuzzer/FSTree.scala
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ class FSTreeWrapper(
) {
val fixedSensMap = MMap.empty[List[String], Int]
var root: FSTree = FSTree(status = FSTreeStatus.Noticed, depth = 0)
var rootHits: Long = 0
var rootMisses: Long = 0

def sensDistr: Map[Int, Int] =
root.stacks.groupBy(_.size).transform((_, v) => v.size).withDefault(_ => 0)
Expand Down Expand Up @@ -107,6 +109,7 @@ class FSTreeWrapper(
stacks.foreach { s =>
root.touchByStack(s.take(config.maxSensitivity), isHit = true)
}
rootHits += stacks.size
MinifyFuzz.sampler("FSTree.touch") += System.currentTimeMillis() - startTime

/** Insert feature stacks from a single script into the tree. The script
Expand All @@ -122,6 +125,7 @@ class FSTreeWrapper(
stacks.foreach { s =>
root.touchByStack(s.take(config.maxSensitivity), isHit = false)
}
rootMisses += stacks.size
MinifyFuzz.sampler("FSTree.touch") += System.currentTimeMillis() - startTime

def apply(stack: List[String]): Int =
Expand Down Expand Up @@ -202,7 +206,12 @@ class FSTreeWrapper(
isHit: Boolean,
): Unit =
if isHit then hits += 1 else misses += 1
updateMyChiSqValue()

if (config.useLocalCorrelation)
updateMyLocalChiSqValue()
else
updateMyGlobalChiSqValue()

updateMyStatus()

stack match {
Expand All @@ -221,14 +230,22 @@ class FSTreeWrapper(
}
}

private def updateMyChiSqValue(): Unit =
private def updateMyLocalChiSqValue(): Unit =
chiSqValue = computeFeatureChiSq(
hits = hits,
misses = misses,
pHits = parentHits,
pMisses = parentMisses,
)

private def updateMyGlobalChiSqValue(): Unit =
chiSqValue = computeFeatureChiSq(
hits = hits,
misses = misses,
pHits = rootHits,
pMisses = rootMisses,
)

private def updateMyStatus(): Unit =
status match {
case Noticed =>
Expand Down Expand Up @@ -344,6 +361,7 @@ case class FSTreeConfig(
oneSided: Boolean = true,
isSelective: Boolean = true,
useSrv: Boolean = true,
useLocalCorrelation: Boolean = false,
)

/** Status of a node in the tree
Expand Down
1 change: 0 additions & 1 deletion src/main/scala/esmeta/es/util/fuzzer/Fuzzer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,6 @@ class Fuzzer(
BuiltinSynthesizer(cfg.spec.algorithms).initPool
.map(BuiltinSynthesizer(cfg.spec.algorithms).name -> _),
)
.take(42)

lazy val logDir: String = s"$FUZZ_LOG_DIR/fuzz-$dateStr"
lazy val symlink: String = s"$FUZZ_LOG_DIR/recent"
Expand Down
1 change: 0 additions & 1 deletion src/main/scala/esmeta/phase/Fuzz.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import esmeta.es.*
import esmeta.es.util.fuzzer.{Fuzzer, FSTreeConfig}
import esmeta.es.util.{UnitWalker, Coverage, ValidityChecker}
import esmeta.spec.util.GrammarGraph
import esmeta.synthesizer.{SimpleSynthesizer, BuiltinSynthesizer}
import scala.collection.mutable.ArrayBuffer

/** `fuzz` phase */
Expand Down
23 changes: 20 additions & 3 deletions src/main/scala/esmeta/phase/MinifyFuzz.scala
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,14 @@ case object MinifyFuzz extends Phase[CFG, Coverage] {
minTouch = config.fsMinTouch,
oneSided = config.oneSided,
isSelective = config.isSelectiveOpt
.getOrElse(
throw new Exception("sensitivity type is not set"),
),
.getOrElse {
println(
"Sensitivity type is not set. Use selective by default.",
)
true
},
useSrv = config.useSrv,
useLocalCorrelation = config.useLocalCorrelation,
),
keepBugs = config.keepBugs,
minifyCmd = config.minifier,
Expand Down Expand Up @@ -194,6 +198,18 @@ case object MinifyFuzz extends Phase[CFG, Coverage] {
BoolOption(c => c.useSrv = false),
"use the CLI to transpile scripts (default: server).",
),
(
"correlation-type",
StrOption((c, s) =>
c.useLocalCorrelation = s match {
case "local" => true
case "global" => false
case _ =>
error("invalid correlation type: please set local or global")
},
),
"set the correlation type: local or global",
),
)
case class Config(
var log: Boolean = false,
Expand All @@ -216,5 +232,6 @@ case object MinifyFuzz extends Phase[CFG, Coverage] {
var minifier: Option[String] = None,
var onlineTest: Boolean = false,
var useSrv: Boolean = true,
var useLocalCorrelation: Boolean = false,
)
}

0 comments on commit 8eb37eb

Please sign in to comment.