mirror of
https://github.com/D-Modem/app.git
synced 2026-11-28 17:38:05 -08:00
Tests: each run's logs in its own folder, a file for each test
build/test-runs/<date_time>/<module>-<task>/<class>/<test>.log: what each test printed, as it printed it, and a failure's stack trace (the root build's listener on every test task, the JVM's and Kotlin/Native's). A task's folder goes when nothing in it failed, the run's when empty; the build names a folder it keeps. The line tools' logs (peer_host, codec_line's filter, fax_line, t30_line, sip_fax_line), the class 1 and peer line logs, and the transfer traces into the test's log (TestLogs) instead of /tmp or one build/ file each run overwrote; peer_host's speaker recording (read by nothing) gone. The README says where to look. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0172Hejd12i4aYikYW9vgpZs
This commit is contained in:
10 files changed
+132
-30
No files matched your search
@@ -132,6 +132,19 @@ The host test needs OpenSSL's headers (libssl-dev):
|
||||
cmake --build build-host
|
||||
ctest --test-dir build-host --output-on-failure
|
||||
|
||||
With `build-host` built, the unit tests also make calls on its test
|
||||
lines (fax between modems, against efax and D-Modem-RE's own T.30, over
|
||||
SIP with T.38, phone to phone, through mobile codecs); without it those
|
||||
are skipped. The lines run at twice a phone line's pace
|
||||
(`DMODEM_LINE_SPEED=1` for a real one's).
|
||||
|
||||
Each test run's logs go to `build/test-runs/<date_time>/<module>-<task>/`,
|
||||
one file for each test (`<class>/<test>.log`: what it printed, the line
|
||||
tools' logs among it, and a failure's stack trace). A run where nothing
|
||||
failed deletes its folder; the build names the one it kept.
|
||||
`KERMIT_TRACE=1` and `TRANSFER_TRACE=1` add the transfer tests' bytes
|
||||
each way.
|
||||
|
||||
CI (`.github/workflows/android.yml`) runs all three; it needs a
|
||||
`DMODEM_RE_TOKEN` secret that can read the private D-Modem-RE submodule.
|
||||
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
// Copyright (C) 2026 Neo-Desktop
|
||||
package com.neodesktop.dmodem
|
||||
|
||||
import java.io.InputStream
|
||||
|
||||
/**
|
||||
* The tests' logs: what a test prints goes to its own file in the run's
|
||||
* folder (build/test-runs/<date_time>/..., the root build's listener; kept
|
||||
* only when something failed). Line tools' output and the like, printed.
|
||||
*/
|
||||
object TestLogs {
|
||||
/** [line] in the current test's log, [tag] before it */
|
||||
fun note(tag: String, line: String) = println("[$tag] $line")
|
||||
|
||||
/** [input]'s lines into the test's log as they come, on a thread of their own; each to [also] too */
|
||||
fun echo(tag: String, input: InputStream, also: (String) -> Unit = {}) {
|
||||
Thread {
|
||||
runCatching { input.bufferedReader().forEachLine { l -> note(tag, l); also(l) } }
|
||||
}.apply { isDaemon = true; start() }
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
// Copyright (C) 2026 Neo-Desktop
|
||||
package com.neodesktop.dmodem.cell
|
||||
|
||||
import com.neodesktop.dmodem.TestLogs
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import java.io.File
|
||||
@@ -24,8 +25,8 @@ class FakeNetwork(private val codec: String? = null, private val closers: Mutabl
|
||||
private var part = ByteArray(0)
|
||||
private val filter: Process? = codec?.let { c ->
|
||||
val bin = codecLine() ?: throw AssertionError("codec_line isn't built")
|
||||
ProcessBuilder(bin.path, "--filter", c).redirectError(File("/tmp/codec_$name.log")).start()
|
||||
.also { p -> closers.add { p.destroyForcibly() } }
|
||||
ProcessBuilder(bin.path, "--filter", c).start()
|
||||
.also { p -> closers.add { p.destroyForcibly() }; TestLogs.echo("codec $name", p.errorStream) }
|
||||
}
|
||||
@Volatile var open = true
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
// Copyright (C) 2026 Neo-Desktop
|
||||
package com.neodesktop.dmodem.fax
|
||||
|
||||
import com.neodesktop.dmodem.TestLogs
|
||||
import android.content.Context
|
||||
import android.net.Uri
|
||||
import android.os.Environment
|
||||
@@ -53,7 +54,7 @@ class FaxAppTest {
|
||||
assumeTrue("fax_line isn't built (native-test)", fl != null)
|
||||
val p = ProcessBuilder(fl!!.path).redirectErrorStream(true).apply { environment()["LINE_SPEED"] = LINE_SPEED }.start()
|
||||
line = p
|
||||
Thread { p.inputStream.bufferedReader().forEachLine { log.add(it) } }.apply { isDaemon = true; start() }
|
||||
TestLogs.echo("fax_line", p.inputStream) { log.add(it) }
|
||||
val end = System.currentTimeMillis() + 10_000
|
||||
while (System.currentTimeMillis() < end && log.none { it.startsWith("created modemB: ") }) Thread.sleep(20)
|
||||
a = log.first { it.startsWith("created modemA: ") }.substringAfter(": ")
|
||||
@@ -68,8 +69,8 @@ class FaxAppTest {
|
||||
|
||||
@After
|
||||
fun tearDown() {
|
||||
// (both sides' logs, for a failing run: build/fax-app-log.txt)
|
||||
File("build/fax-app-log.txt").writeText((ModemState.log.flow.value + listOf("----") + log).joinToString("\n"))
|
||||
// (the app's modem log, into the test's)
|
||||
ModemState.log.flow.value.forEach { TestLogs.note("app", it) }
|
||||
Fax.cancel()
|
||||
closers.forEach { runCatching { it() } }
|
||||
ModemState.dte.detach()
|
||||
@@ -93,7 +94,7 @@ class FaxAppTest {
|
||||
io.feed(buf, 0, n)
|
||||
}
|
||||
}.apply { isDaemon = true; start() }
|
||||
return Class1(io) { log.add("B: $it") }
|
||||
return Class1(io) { log.add("B: $it"); TestLogs.note("B", it) }
|
||||
}
|
||||
|
||||
private fun waitLog(what: String, secs: Int = 30): Boolean {
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
// Copyright (C) 2026 Neo-Desktop
|
||||
package com.neodesktop.dmodem.fax
|
||||
|
||||
import com.neodesktop.dmodem.TestLogs
|
||||
import com.neodesktop.dmodem.transfer.TransferIo
|
||||
import org.junit.After
|
||||
import org.junit.Assert.assertArrayEquals
|
||||
@@ -52,7 +53,7 @@ class FaxCallTest {
|
||||
val p = ProcessBuilder(mt!!.path).redirectErrorStream(true).apply { environment()["LINE_SPEED"] = LINE_SPEED }.start()
|
||||
modems = p
|
||||
Thread {
|
||||
p.inputStream.bufferedReader().forEachLine { l -> log.add(l) }
|
||||
p.inputStream.bufferedReader().forEachLine { l -> log.add(l); TestLogs.note("fax_line", l) }
|
||||
}.apply { isDaemon = true; start() }
|
||||
val end = System.currentTimeMillis() + 10_000
|
||||
while (System.currentTimeMillis() < end && log.none { it.startsWith("created modemB: ") }) Thread.sleep(20)
|
||||
@@ -79,7 +80,10 @@ class FaxCallTest {
|
||||
input = FileInputStream(path)
|
||||
output = FileOutputStream(path)
|
||||
io = TransferIo { bytes -> output.write(bytes); output.flush() }
|
||||
c1 = Class1(io) { line -> log.add("${path.substringAfterLast('/')}: $line") }
|
||||
c1 = Class1(io) { line ->
|
||||
log.add("${path.substringAfterLast('/')}: $line")
|
||||
TestLogs.note(path.substringAfterLast('/'), line)
|
||||
}
|
||||
Thread {
|
||||
val buf = ByteArray(4096)
|
||||
while (true) {
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
// Copyright (C) 2026 Neo-Desktop
|
||||
package com.neodesktop.dmodem.fax
|
||||
|
||||
import com.neodesktop.dmodem.TestLogs
|
||||
import com.neodesktop.dmodem.transfer.TransferIo
|
||||
import java.io.File
|
||||
import java.io.FileInputStream
|
||||
@@ -36,9 +37,11 @@ class FaxLineProcess(cmd: List<String>) : AutoCloseable {
|
||||
private val proc: Process = ProcessBuilder(cmd).apply { environment()["LINE_SPEED"] = LINE_SPEED }.start()
|
||||
private val closers = ArrayList<() -> Unit>()
|
||||
|
||||
private val tag = File(cmd.first()).name
|
||||
|
||||
init {
|
||||
Thread { proc.errorStream.bufferedReader().forEachLine { log.add(it) } }.apply { isDaemon = true; start() }
|
||||
Thread { proc.inputStream.bufferedReader().forEachLine { log.add(it) } }.apply { isDaemon = true; start() }
|
||||
TestLogs.echo(tag, proc.errorStream) { log.add(it) }
|
||||
TestLogs.echo(tag, proc.inputStream) { log.add(it) }
|
||||
}
|
||||
|
||||
/** the pty of [name] (modemA, modemB), opened raw: our class 1 modem on it */
|
||||
@@ -60,7 +63,7 @@ class FaxLineProcess(cmd: List<String>) : AutoCloseable {
|
||||
io.feed(buf, 0, n)
|
||||
}
|
||||
}.apply { isDaemon = true; start() }
|
||||
return Class1(io) { line -> log.add("$tag: $line") }
|
||||
return Class1(io) { line -> log.add("$tag: $line"); TestLogs.note(tag, line) }
|
||||
}
|
||||
|
||||
fun dump(n: Int = 80) = log.takeLast(n).joinToString("\n")
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
// Copyright (C) 2026 Neo-Desktop
|
||||
package com.neodesktop.dmodem.peer
|
||||
|
||||
import com.neodesktop.dmodem.TestLogs
|
||||
import java.io.File
|
||||
import java.io.IOException
|
||||
import java.net.Socket
|
||||
@@ -36,8 +37,8 @@ open class TestModem(
|
||||
init {
|
||||
val bin = peerHost()
|
||||
org.junit.Assume.assumeTrue("peer_host isn't built (native-test)", bin != null)
|
||||
proc = ProcessBuilder(bin!!.path, leadMs.toString()).redirectError(File("/tmp/peer_host_$name.log"))
|
||||
.apply { environment()["PEER_SPEAKER"] = "/tmp/peer_speaker_$name.raw" }.start()
|
||||
proc = ProcessBuilder(bin!!.path, leadMs.toString()).start()
|
||||
TestLogs.echo("peer_host $name", proc.errorStream)
|
||||
closers.add { proc.destroyForcibly() }
|
||||
Thread {
|
||||
proc.inputStream.bufferedReader().forEachLine { l -> out.add(l) }
|
||||
@@ -62,7 +63,7 @@ open class TestModem(
|
||||
}
|
||||
},
|
||||
target = { dial -> target(dial) },
|
||||
log = { log.add(it) },
|
||||
log = { log.add(it); TestLogs.note("line $name", it) },
|
||||
ringMs = 1000,
|
||||
pin = pin,
|
||||
)
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
// Copyright (C) 2026 Neo-Desktop
|
||||
package com.neodesktop.dmodem.transfer
|
||||
|
||||
import com.neodesktop.dmodem.TestLogs
|
||||
import com.neodesktop.dmodem.local.LocalLink
|
||||
import com.neodesktop.dmodem.local.LocalShellTest
|
||||
import com.neodesktop.dmodem.local.Pty
|
||||
@@ -64,21 +65,18 @@ class KermitInteropTest {
|
||||
}
|
||||
io.feed(b)
|
||||
}
|
||||
// (KERMIT_TRACE=1: the line both ways in build/kermit-trace.txt, for a failing run)
|
||||
// (KERMIT_TRACE=1: the line both ways in the test's log, for a failing run)
|
||||
if (System.getenv("KERMIT_TRACE") != null) traceTo(io)
|
||||
assertTrue(l.start())
|
||||
return l to io
|
||||
}
|
||||
|
||||
private fun traceTo(io: TransferIo) {
|
||||
val trace = File("build/kermit-trace.txt").apply { delete() }
|
||||
io.trace = { inbound, b ->
|
||||
synchronized(trace) {
|
||||
trace.appendText((if (inbound) "<< " else ">> ") + b.joinToString("") { c ->
|
||||
val v = c.toInt() and 0xff
|
||||
if (v in 0x20..0x7e) v.toChar().toString() else "\\x%02x".format(v)
|
||||
} + "\n")
|
||||
}
|
||||
TestLogs.note(if (inbound) "<<" else ">>", b.joinToString("") { c ->
|
||||
val v = c.toInt() and 0xff
|
||||
if (v in 0x20..0x7e) v.toChar().toString() else "\\x%02x".format(v)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
// Copyright (C) 2026 Neo-Desktop
|
||||
package com.neodesktop.dmodem.transfer
|
||||
|
||||
import com.neodesktop.dmodem.TestLogs
|
||||
import com.neodesktop.dmodem.local.LocalLink
|
||||
import com.neodesktop.dmodem.local.LocalShellTest
|
||||
import com.neodesktop.dmodem.local.Pty
|
||||
@@ -63,16 +64,13 @@ class LrzszInteropTest {
|
||||
}
|
||||
io.feed(b)
|
||||
}
|
||||
// (TRANSFER_TRACE=1: the bytes each way, for a failing run: build/transfer-trace.txt)
|
||||
// (TRANSFER_TRACE=1: the bytes each way, for a failing run: into the test's log)
|
||||
if (System.getenv("TRANSFER_TRACE") != null) {
|
||||
val trace = File("build/transfer-trace.txt").apply { delete() }
|
||||
io.trace = { inbound, b ->
|
||||
synchronized(trace) {
|
||||
trace.appendText((if (inbound) "<< " else ">> ") + b.joinToString("") { c ->
|
||||
val v = c.toInt() and 0xff
|
||||
if (v in 0x20..0x7e) v.toChar().toString() else "\\x%02x".format(v)
|
||||
} + "\n")
|
||||
}
|
||||
TestLogs.note(if (inbound) "<<" else ">>", b.joinToString("") { c ->
|
||||
val v = c.toInt() and 0xff
|
||||
if (v in 0x20..0x7e) v.toChar().toString() else "\\x%02x".format(v)
|
||||
})
|
||||
}
|
||||
}
|
||||
assertTrue(l.start())
|
||||
|
||||
@@ -5,3 +5,64 @@ plugins {
|
||||
alias(libs.plugins.kotlin.compose) apply false
|
||||
alias(libs.plugins.kotlin.multiplatform) apply false
|
||||
}
|
||||
|
||||
// Each run's test logs: build/test-runs/<date_time>/<module>-<task>/<class>/<test>.log, what each
|
||||
// test printed (the line tools' logs among it), as it printed it. A task's folder goes once it ends
|
||||
// with nothing failed, the run's once it's empty: what's left is the runs to look at.
|
||||
val testRunStamp: String = java.time.LocalDateTime.now()
|
||||
.format(java.time.format.DateTimeFormatter.ofPattern("yyyy-MM-dd_HH-mm-ss"))
|
||||
val testRunsDir = layout.buildDirectory.dir("test-runs").get().asFile
|
||||
val testRunDir = File(testRunsDir, testRunStamp)
|
||||
|
||||
subprojects {
|
||||
tasks.withType<AbstractTestTask>().configureEach {
|
||||
val dir = File(testRunDir, "${project.name}-$name")
|
||||
if (this is Test) systemProperty("dmodem.testRunDir", dir.path)
|
||||
val writers = java.util.concurrent.ConcurrentHashMap<String, java.io.Writer>()
|
||||
fun fileName(s: String) = s.replace(Regex("[^A-Za-z0-9._-]+"), "_").take(150)
|
||||
fun writer(d: TestDescriptor): java.io.Writer {
|
||||
val cls = d.className ?: d.parent?.className ?: "_run"
|
||||
val key = if (d.className != null && d.name != d.className) "${fileName(cls.substringAfterLast('.'))}/${fileName(d.name)}.log"
|
||||
else "${fileName(cls.substringAfterLast('.'))}/_class.log"
|
||||
return writers.computeIfAbsent(key) {
|
||||
File(dir, it).apply { parentFile.mkdirs() }.bufferedWriter()
|
||||
}
|
||||
}
|
||||
doFirst { dir.deleteRecursively() }
|
||||
addTestOutputListener(object : TestOutputListener {
|
||||
override fun onOutput(d: TestDescriptor, e: TestOutputEvent) {
|
||||
val w = writer(d)
|
||||
synchronized(w) {
|
||||
w.write(e.message)
|
||||
w.flush()
|
||||
}
|
||||
}
|
||||
})
|
||||
addTestListener(object : TestListener {
|
||||
override fun beforeSuite(suite: TestDescriptor) {}
|
||||
override fun beforeTest(d: TestDescriptor) {}
|
||||
override fun afterTest(d: TestDescriptor, r: TestResult) {
|
||||
// (a failure's stack trace at the end of its log)
|
||||
if (r.resultType == TestResult.ResultType.FAILURE) {
|
||||
val w = writer(d)
|
||||
synchronized(w) {
|
||||
w.write("\n---- FAILED ----\n")
|
||||
r.exceptions.forEach { w.write(it.stackTraceToString()) }
|
||||
w.flush()
|
||||
}
|
||||
}
|
||||
}
|
||||
override fun afterSuite(suite: TestDescriptor, r: TestResult) {
|
||||
if (suite.parent != null) return
|
||||
writers.values.forEach { runCatching { it.close() } }
|
||||
writers.clear()
|
||||
if (r.failedTestCount == 0L && r.resultType != TestResult.ResultType.FAILURE) {
|
||||
dir.deleteRecursively()
|
||||
if (testRunDir.list()?.isEmpty() == true) testRunDir.delete()
|
||||
} else {
|
||||
logger.warn("test logs: ${dir.path}")
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user