From 5f9cce10f1c5de83e38fcd72f0c6e68d794b94b2 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 17 Oct 2026 21:05:23 +0000 Subject: [PATCH] Tests: shorter calls on the test lines, less needless work - native-test's line tools (fax_line, codec_line, t30_line) at LINE_SPEED times the sample clock (line_speed.h); the fax tests ask for 2x (DMODEM_LINE_SPEED, 1 a phone line's pace): 4x leaves the DTE a quarter second for what class 1 times in a second, too tight on a busy machine - t30_line's first page some 70 KB in MH, not 220 KB (still two ECM blocks) - the Kermit and lrzsz interop tests' byte traces only when asked (KERMIT_TRACE, TRANSFER_TRACE): a file opened for each chunk; Kermit's big file 64 KB - two test JVMs at once Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_0172Hejd12i4aYikYW9vgpZs --- app/build.gradle.kts | 3 ++ .../com/neodesktop/dmodem/fax/FaxAppTest.kt | 2 +- .../com/neodesktop/dmodem/fax/FaxCallTest.kt | 2 +- .../java/com/neodesktop/dmodem/fax/FaxPty.kt | 12 ++++++- .../dmodem/transfer/KermitInteropTest.kt | 11 ++++-- .../dmodem/transfer/LrzszInteropTest.kt | 18 +++++----- native-test/codec_line.cpp | 7 ++-- native-test/fax_line.cpp | 6 ++-- native-test/line_speed.h | 35 +++++++++++++++++++ native-test/t30_line.cpp | 8 +++-- 10 files changed, 80 insertions(+), 24 deletions(-) create mode 100644 native-test/line_speed.h diff --git a/app/build.gradle.kts b/app/build.gradle.kts index a38165a..a81d67c 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -66,6 +66,9 @@ android { // UTF-8 file names, as Android has them (the JVM takes its file name encoding from the locale) it.environment("LC_ALL", "C.UTF-8") it.environment("LANG", "C.UTF-8") + // two test JVMs at once: the line tests (fax, the peer line, SIP) mostly wait on their + // lines' pace, not the CPU; their ports are the system's, but for SipFaxTest's (one class) + it.maxParallelForks = 2 } } diff --git a/app/src/test/java/com/neodesktop/dmodem/fax/FaxAppTest.kt b/app/src/test/java/com/neodesktop/dmodem/fax/FaxAppTest.kt index a307f7c..9baccde 100644 --- a/app/src/test/java/com/neodesktop/dmodem/fax/FaxAppTest.kt +++ b/app/src/test/java/com/neodesktop/dmodem/fax/FaxAppTest.kt @@ -51,7 +51,7 @@ class FaxAppTest { fun setUp() { val fl = faxLine() assumeTrue("fax_line isn't built (native-test)", fl != null) - val p = ProcessBuilder(fl!!.path).redirectErrorStream(true).start() + 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() } val end = System.currentTimeMillis() + 10_000 diff --git a/app/src/test/java/com/neodesktop/dmodem/fax/FaxCallTest.kt b/app/src/test/java/com/neodesktop/dmodem/fax/FaxCallTest.kt index ff077bb..a9b1889 100644 --- a/app/src/test/java/com/neodesktop/dmodem/fax/FaxCallTest.kt +++ b/app/src/test/java/com/neodesktop/dmodem/fax/FaxCallTest.kt @@ -49,7 +49,7 @@ class FaxCallTest { fun setUp() { val mt = modemTest() assumeTrue("fax_line isn't built (native-test)", mt != null) - val p = ProcessBuilder(mt!!.path).redirectErrorStream(true).start() + 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) } diff --git a/app/src/test/java/com/neodesktop/dmodem/fax/FaxPty.kt b/app/src/test/java/com/neodesktop/dmodem/fax/FaxPty.kt index b853eb6..a7a814c 100644 --- a/app/src/test/java/com/neodesktop/dmodem/fax/FaxPty.kt +++ b/app/src/test/java/com/neodesktop/dmodem/fax/FaxPty.kt @@ -16,6 +16,16 @@ fun nativeTool(env: String, name: String): File? = listOfNotNull( "build-host/$name", ).map { File(it) }.firstOrNull { it.canExecute() } +/** + * How fast the test lines run beside the sample clock (native-test's + * line_speed.h): twice a phone line's pace, the calls half as long. Not + * faster: class 1 gives the DTE a second or so of the line's time to + * answer (its frames after +FTH's CONNECT, say), which at 4x is a + * quarter of a second, and a busy test machine misses it now and then. + * DMODEM_LINE_SPEED=1: a real phone line's pace. + */ +val LINE_SPEED: String = System.getenv("DMODEM_LINE_SPEED") ?: "2" + /** * A line program running (its stderr and stdout into [log]), its * modems' ptys as it names them ("created modemA: "), each a @@ -23,7 +33,7 @@ fun nativeTool(env: String, name: String): File? = listOfNotNull( */ class FaxLineProcess(cmd: List) : AutoCloseable { val log = CopyOnWriteArrayList() - private val proc: Process = ProcessBuilder(cmd).start() + private val proc: Process = ProcessBuilder(cmd).apply { environment()["LINE_SPEED"] = LINE_SPEED }.start() private val closers = ArrayList<() -> Unit>() init { diff --git a/app/src/test/java/com/neodesktop/dmodem/transfer/KermitInteropTest.kt b/app/src/test/java/com/neodesktop/dmodem/transfer/KermitInteropTest.kt index 93a4c09..dfc87e8 100644 --- a/app/src/test/java/com/neodesktop/dmodem/transfer/KermitInteropTest.kt +++ b/app/src/test/java/com/neodesktop/dmodem/transfer/KermitInteropTest.kt @@ -64,6 +64,13 @@ class KermitInteropTest { } io.feed(b) } + // (KERMIT_TRACE=1: the line both ways in build/kermit-trace.txt, 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) { @@ -73,8 +80,6 @@ class KermitInteropTest { } + "\n") } } - assertTrue(l.start()) - return l to io } private fun waitExit(l: LocalLink): Int? { @@ -85,7 +90,7 @@ class KermitInteropTest { private fun files(dir: File): List { dir.mkdirs() - val big = File(dir, "binary.bin").apply { writeBytes(Random(7).nextBytes(200_000)) } + val big = File(dir, "binary.bin").apply { writeBytes(Random(7).nextBytes(64_000)) } val every = File(dir, "every-byte.dat").apply { writeBytes(ByteArray(4096) { it.toByte() } + ByteArray(3000) { '~'.code.toByte() } + ByteArray(2048) { '#'.code.toByte() } + ByteArray(500) { 0x80.toByte() }) } diff --git a/app/src/test/java/com/neodesktop/dmodem/transfer/LrzszInteropTest.kt b/app/src/test/java/com/neodesktop/dmodem/transfer/LrzszInteropTest.kt index 7905371..cea8732 100644 --- a/app/src/test/java/com/neodesktop/dmodem/transfer/LrzszInteropTest.kt +++ b/app/src/test/java/com/neodesktop/dmodem/transfer/LrzszInteropTest.kt @@ -63,14 +63,16 @@ class LrzszInteropTest { } io.feed(b) } - // (the bytes each way, for a failing run: build/transfer-trace.txt) - 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") + // (TRANSFER_TRACE=1: the bytes each way, for a failing run: build/transfer-trace.txt) + 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") + } } } assertTrue(l.start()) diff --git a/native-test/codec_line.cpp b/native-test/codec_line.cpp index bf645f3..72c6d1b 100644 --- a/native-test/codec_line.cpp +++ b/native-test/codec_line.cpp @@ -34,6 +34,7 @@ #include #include "options.h" +#include "line_speed.h" #include "pipe_modem.h" #ifdef HAVE_GSM @@ -185,10 +186,8 @@ int main(int argc, char *argv[]) std::thread(channel, b_out[0], a_in[1], codec).detach(); dmd::PipeModem a("modemA", 8000, opt.country, a_in[0], a_out[1]); dmd::PipeModem b("modemB", 8000, opt.country, b_in[0], b_out[1]); - bool realtime = !getenv("MODEM_REALTIME") || - atoi(getenv("MODEM_REALTIME")); - a.set_realtime(realtime); - b.set_realtime(realtime); + line_speed(a); + line_speed(b); fprintf(stderr, "codec: %s\ncreated modemA: %s\ncreated modemB: %s\n", codec.c_str(), a.pty().name(), b.pty().name()); dmd::PipeModem *modems[] = { &a, &b }; diff --git a/native-test/fax_line.cpp b/native-test/fax_line.cpp index 9be98f9..33e5de2 100644 --- a/native-test/fax_line.cpp +++ b/native-test/fax_line.cpp @@ -19,6 +19,7 @@ #include #include "options.h" +#include "line_speed.h" #include "pipe_modem.h" int main(int argc, char *argv[]) @@ -37,9 +38,8 @@ int main(int argc, char *argv[]) dmd::PipeModem a("modemA", 9600, opt.country, pipe1[0], pipe2[1]); dmd::PipeModem b("modemB", 9600, opt.country, pipe2[0], pipe1[1]); /* (unpaced only when asked: MODEM_REALTIME=0) */ - bool realtime = !getenv("MODEM_REALTIME") || atoi(getenv("MODEM_REALTIME")); - a.set_realtime(realtime); - b.set_realtime(realtime); + line_speed(a); + line_speed(b); fprintf(stderr, "created modemA: %s\ncreated modemB: %s\n", a.pty().name(), b.pty().name()); dmd::PipeModem *modems[] = { &a, &b }; diff --git a/native-test/line_speed.h b/native-test/line_speed.h new file mode 100644 index 0000000..d3cfb3b --- /dev/null +++ b/native-test/line_speed.h @@ -0,0 +1,35 @@ +/* + * SPDX-License-Identifier: AGPL-3.0-only + * Copyright (C) 2026 Neo-Desktop + * + * line_speed.h - how fast the test lines run (fax_line, codec_line, + * t30_line): at the sample clock, as a phone line does, + * or LINE_SPEED= times it (the tests' shorter + * calls: the DTE's timing, a fax program's T.30, then + * x times as slow beside the line's); MODEM_REALTIME=0 + * as fast as it goes + */ + +#ifndef LINE_SPEED_H +#define LINE_SPEED_H + +#include + +#include "pipe_modem.h" + +static inline void line_speed(dmd::PipeModem &m) +{ + const char *s = getenv("LINE_SPEED"); + double x = s ? atof(s) : 1; + if (getenv("MODEM_REALTIME") && !atoi(getenv("MODEM_REALTIME"))) { + m.set_realtime(false); + m.set_speed(0); + } else if (x > 1) { + m.set_realtime(false); + m.set_speed(x); + } else { + m.set_realtime(true); + } +} + +#endif diff --git a/native-test/t30_line.cpp b/native-test/t30_line.cpp index e56240e..9a07c7c 100644 --- a/native-test/t30_line.cpp +++ b/native-test/t30_line.cpp @@ -36,6 +36,7 @@ #include #include "options.h" +#include "line_speed.h" #include "pipe_modem.h" using namespace dsp; @@ -66,7 +67,8 @@ int next_page(void *, T4Page *p) if (pages_sent == 2) return 0; int n = ++pages_sent; - int rows = n == 1 ? 900 : 400; + /* (page 1's noise: some 70 KB in MH, two ECM blocks) */ + int rows = n == 1 ? 620 : 400; std::mt19937 r(n); unsigned char row[WIDTH / 8]; if (p->init(WIDTH, 1) < 0) @@ -79,7 +81,7 @@ int next_page(void *, T4Page *p) on = true; else if (y < 200) on = (x / (y % 9 + 1)) % 2 == 0; - else if (n == 1 && y < 700) + else if (n == 1 && y < 420) on = (r() & 3) == 0; else on = (x / 6 + y / 10) % 7 == 0; @@ -185,7 +187,7 @@ int main(int argc, char *argv[]) } std::thread(machine, from_modem[0], to_modem[1], cfg, snr).detach(); dmd::PipeModem a("modemA", 8000, opt.country, to_modem[0], from_modem[1]); - a.set_realtime(!getenv("MODEM_REALTIME") || atoi(getenv("MODEM_REALTIME"))); + line_speed(a); fprintf(stderr, "created modemA: %s\n", a.pty().name()); dmd::PipeModem *modems[] = { &a }; ret = dmd::PipeModem::run(modems, 1);