-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Make idempotency check a proper vulpix test #2457
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
|
||
import java.nio.file.{Files, Path, Paths} | ||
import java.util.stream.{ Stream => JStream } | ||
|
||
import scala.collection.JavaConverters._ | ||
|
||
object Test { | ||
|
||
def main(args: Array[String]): Unit = checkIdempotency() | ||
|
||
val blacklisted = Set( | ||
// Bridges on collections in different order. Second one in scala2 order. | ||
"pos/Map/scala/collection/immutable/Map", | ||
"pos/Map/scala/collection/immutable/AbstractMap", | ||
"pos/t1203a/NodeSeq", | ||
"pos/i2345/Whatever" | ||
) | ||
|
||
def checkIdempotency(): Unit = { | ||
var failed = 0 | ||
var total = 0 | ||
|
||
val groupedBytecodeFiles: List[(Path, Path, Path, Path)] = { | ||
val bytecodeFiles = { | ||
def bytecodeFiles(paths: JStream[Path]): List[Path] = { | ||
def isBytecode(file: String) = file.endsWith(".class") || file.endsWith(".tasty") | ||
paths.iterator.asScala.filter(path => isBytecode(path.toString)).toList | ||
} | ||
val compilerDir1 = Paths.get("../out/idempotency1") | ||
val compilerDir2 = Paths.get("../out/idempotency2") | ||
bytecodeFiles(Files.walk(compilerDir1)) ++ bytecodeFiles(Files.walk(compilerDir2)) | ||
} | ||
val groups = bytecodeFiles.groupBy(f => f.toString.substring("../out/idempotencyN/".length, f.toString.length - 6)) | ||
groups.filterNot(x => blacklisted(x._1)).valuesIterator.flatMap { g => | ||
def pred(f: Path, i: Int, isTasty: Boolean) = | ||
f.toString.contains("idempotency" + i) && f.toString.endsWith(if (isTasty) ".tasty" else ".class") | ||
val class1 = g.find(f => pred(f, 1, isTasty = false)) | ||
val class2 = g.find(f => pred(f, 2, isTasty = false)) | ||
val tasty1 = g.find(f => pred(f, 1, isTasty = true)) | ||
val tasty2 = g.find(f => pred(f, 2, isTasty = true)) | ||
assert(class1.isDefined, "Could not find class in idempotency1 for " + class2) | ||
assert(class2.isDefined, "Could not find class in idempotency2 for " + class1) | ||
if (tasty1.isEmpty || tasty2.isEmpty) Nil | ||
else List(Tuple4(class1.get, tasty1.get, class2.get, tasty2.get)) | ||
}.toList | ||
} | ||
|
||
for ((class1, tasty1, class2, tasty2) <- groupedBytecodeFiles) { | ||
total += 1 | ||
val bytes1 = Files.readAllBytes(class1) | ||
val bytes2 = Files.readAllBytes(class2) | ||
if (!java.util.Arrays.equals(bytes1, bytes2)) { | ||
failed += 1 | ||
val tastyBytes1 = Files.readAllBytes(tasty1) | ||
val tastyBytes2 = Files.readAllBytes(tasty2) | ||
if (java.util.Arrays.equals(tastyBytes1, tastyBytes2)) | ||
println(s"Idempotency test failed between $class1 and $class1 (same tasty)") | ||
else | ||
println(s"Idempotency test failed between $tasty1 and $tasty2") | ||
/* Dump bytes to console, could be useful if issue only appears in CI. | ||
* Create the .class locally with Files.write(path, Array[Byte](...)) with the printed array | ||
*/ | ||
// println(bytes1.mkString("Array[Byte](", ",", ")")) | ||
// println(bytes2.mkString("Array[Byte](", ",", ")")) | ||
} | ||
} | ||
|
||
assert(failed == 0, s"Failed $failed idempotency checks (out of $total)") | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this better?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because of reasons
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It improves the feedback from error messages for the venerable Stucki :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error messages and timing is handled by vupix. If there is a crash, vulpix will report it and continue running the test suite.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But why would there be a crash in the testcode?