mirror of
https://github.com/D-Modem/app.git
synced 2026-11-28 17:38:05 -08:00
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 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0172Hejd12i4aYikYW9vgpZs
This commit is contained in:
10 files changed
+80
-24
No files matched your search
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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) }
|
||||
|
||||
@@ -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: <pty>"), each a
|
||||
@@ -23,7 +33,7 @@ fun nativeTool(env: String, name: String): File? = listOfNotNull(
|
||||
*/
|
||||
class FaxLineProcess(cmd: List<String>) : AutoCloseable {
|
||||
val log = CopyOnWriteArrayList<String>()
|
||||
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 {
|
||||
|
||||
@@ -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<File> {
|
||||
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() })
|
||||
}
|
||||
|
||||
@@ -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())
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
#include <log.h>
|
||||
|
||||
#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 };
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#include <log.h>
|
||||
|
||||
#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 };
|
||||
|
||||
@@ -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=<x> 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 <stdlib.h>
|
||||
|
||||
#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
|
||||
@@ -36,6 +36,7 @@
|
||||
#include <t4.h>
|
||||
|
||||
#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);
|
||||
|
||||
Reference in new issue
Block a user