Created
November 3, 2023 20:51
-
-
Save hbmartin/a2af9046f0d05c1b6a6d64267136d933 to your computer and use it in GitHub Desktop.
This file contains 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
import com.esotericsoftware.kryo.io.Input | |
import com.google.common.collect.ImmutableMap | |
import java.io.File | |
import java.io.FileInputStream | |
import java.io.FileNotFoundException | |
import java.io.UncheckedIOException | |
fun main(args: Array<String>) { | |
val reader = Reader( | |
/* indexFile = */ File(".../build/test-results/macosArm64Test/binary/output.bin.idx"), | |
/* outputsFile = */ | |
File(".../build/test-results/macosArm64Test/binary/output.bin") | |
) | |
} | |
class Reader(indexFile: File, outputsFile: File) { | |
private var index: Index? = null | |
init { | |
if (outputsFile.exists()) { | |
check(indexFile.exists()) { | |
String.format( | |
"Test outputs data file '%s' exists but the index file '%s' does not", | |
outputsFile, | |
indexFile | |
) | |
} | |
val input: Input | |
input = try { | |
Input(FileInputStream(indexFile)) | |
} catch (e: FileNotFoundException) { | |
throw UncheckedIOException(e) | |
} | |
var rootBuilder: IndexBuilder? = null | |
try { | |
val numClasses = input.readInt(true) | |
println("numClasses: $numClasses") | |
rootBuilder = IndexBuilder() | |
for (classCounter in 0 until numClasses) { | |
val classId = input.readLong(true) | |
println("classId: $classId") | |
val classBuilder = IndexBuilder() | |
val numEntries = input.readInt(true) | |
println("numEntries: $numEntries") | |
for (entryCounter in 0 until numEntries) { | |
val testId = input.readLong(true) | |
println("testId: $testId") | |
val stdOut = Region(input.readLong(), input.readLong()) | |
// println("stdOut: $stdOut") | |
val stdErr = Region(input.readLong(), input.readLong()) | |
classBuilder.add(testId, Index(stdOut, stdErr)) | |
} | |
rootBuilder.add(classId, classBuilder.build()) | |
} | |
} finally { | |
input.close() | |
} | |
index = rootBuilder!!.build() | |
} else { // no outputs file | |
check(!indexFile.exists()) { | |
String.format( | |
"Test outputs data file '%s' does not exist but the index file '%s' does", | |
outputsFile, | |
indexFile | |
) | |
} | |
index = null | |
} | |
} | |
} | |
class Region { | |
var start: Long | |
var stop: Long | |
constructor() { | |
start = -1 | |
stop = -1 | |
} | |
constructor(start: Long, stop: Long) { | |
this.start = start | |
this.stop = stop | |
} | |
override fun toString(): String = "$start, $stop" | |
} | |
class Index { | |
val children: ImmutableMap<Long, Index> | |
val stdOut: Region | |
val stdErr: Region | |
constructor(stdOut: Region, stdErr: Region) { | |
children = ImmutableMap.of() | |
this.stdOut = stdOut | |
this.stdErr = stdErr | |
} | |
constructor(children: ImmutableMap<Long, Index>, stdOut: Region, stdErr: Region) { | |
this.children = children | |
this.stdOut = stdOut | |
this.stdErr = stdErr | |
} | |
} | |
class IndexBuilder { | |
val stdOut = Region() | |
val stdErr = Region() | |
private val children: ImmutableMap.Builder<Long, Index> = ImmutableMap.builder() | |
fun add(key: Long, index: Index) { | |
if (stdOut.start < 0) { | |
stdOut.start = index.stdOut.start | |
} | |
if (stdErr.start < 0) { | |
stdErr.start = index.stdErr.start | |
} | |
if (index.stdOut.stop > stdOut.stop) { | |
stdOut.stop = index.stdOut.stop | |
} | |
if (index.stdErr.stop > stdErr.stop) { | |
stdErr.stop = index.stdErr.stop | |
} | |
children.put(key, index) | |
} | |
fun build(): Index { | |
return Index(children.build(), stdOut, stdErr) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment