Merge pull request #5 from D-Modem/claude/project-thread-bb7ios

Fix CI failures on main: lost bytes in ByteQueue, flaky loopback tests, iOS build
This commit is contained in:
Neo authored and GitHub committed 2026-10-30 07:15:47 -07:00
commit 1eb596d6d3
8 files changed
+79 -13

No files matched your search

+2 -1
View File
@@ -49,13 +49,14 @@ jobs:
- name: The shared Kotlin as an XCFramework
run: ./gradlew :shared:assembleDModemSharedReleaseXCFramework
# arm64 only: the shared Kotlin's XCFramework has no x86_64 simulator slice
- name: The iOS app (simulator)
run: |
brew install xcodegen
cd ios/DModem && xcodegen generate
xcodebuild -project DModem.xcodeproj -scheme DModem \
-destination 'generic/platform=iOS Simulator' \
CODE_SIGNING_ALLOWED=NO build
ARCHS=arm64 CODE_SIGNING_ALLOWED=NO build
- uses: actions/upload-artifact@v4
with:
@@ -37,10 +37,15 @@ class NativeModemTest {
NativeModem.listener = null
}
/** a SIP account at nowhere (no call is made), the modem's data in the app's files */
/**
* a SIP account at nowhere (no call is made), the modem's data in the
* app's files; SIP's log at level 4, which names its addresses
* ("SIP on ...") before start returns: at 3 a modem with no call and
* no registrar has nothing to say in the test's time
*/
private fun config() = NativeModem.Config(
user = "test", password = "x", domain = "127.0.0.1:5999", sipPort = 15060,
dns = listOf("127.0.0.1"), logLevel = 1, sipLogLevel = 3,
dns = listOf("127.0.0.1"), logLevel = 1, sipLogLevel = 4,
dataFile = File(InstrumentationRegistry.getInstrumentation().targetContext.filesDir, "test_dsp").path,
)
+6 -2
View File
@@ -20,11 +20,15 @@ let engineLinking: [LinkerSetting] = [
]),
.linkedLibrary("dmodem_engine"), .linkedLibrary("dmodem_sip"), .linkedLibrary("re"),
.linkedLibrary("ssl"), .linkedLibrary("crypto"), .linkedLibrary("stdc++"), .linkedLibrary("dl"),
.linkedLibrary("m"),
.linkedLibrary("m"), .linkedLibrary("resolv"),
]
#else
let engine: Target = .binaryTarget(name: "DModemEngine", path: "../../build-apple/DModemEngine.xcframework")
let engineLinking: [LinkerSetting] = [.linkedLibrary("c++")]
let engineLinking: [LinkerSetting] = [
.linkedLibrary("c++"), .linkedLibrary("resolv"),
// libre asks the system for its DNS servers (srv.c, SCDynamicStore)
.linkedFramework("SystemConfiguration"), .linkedFramework("CoreFoundation"),
]
#endif
let package = Package(
+5 -1
View File
@@ -14,7 +14,11 @@ let package = Package(
.testTarget(
name: "DModemSmokeTests",
dependencies: ["DModemEngine"],
linkerSettings: [.linkedLibrary("c++")]
linkerSettings: [
.linkedLibrary("c++"), .linkedLibrary("resolv"),
// libre asks macOS for its DNS servers (srv.c, SCDynamicStore)
.linkedFramework("SystemConfiguration"), .linkedFramework("CoreFoundation"),
]
),
]
)
+4 -1
View File
@@ -32,7 +32,10 @@ build() {
-DCMAKE_OSX_DEPLOYMENT_TARGET="$min" \
-DDMODEM_CRYPTO=mbedtls
if [ "$system" = iOS ]; then
set -- "$@" -DCMAKE_SYSTEM_NAME=iOS
# (no app bundles: D-Modem-RE's dmodemd, which is never built
# here, is an executable that CMake would make a bundle on iOS,
# and its install rule has no BUNDLE DESTINATION for one)
set -- "$@" -DCMAKE_SYSTEM_NAME=iOS -DCMAKE_MACOSX_BUNDLE=OFF
fi
cmake "$@"
cmake --build "$dir/build" --target dmodem_engine
@@ -2,10 +2,12 @@
// Copyright (C) 2026 Neo-Desktop
package com.neodesktop.dmodem.io
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.delay
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withTimeoutOrNull
import kotlinx.coroutines.selects.onTimeout
import kotlinx.coroutines.selects.select
import kotlin.time.TimeSource
/**
@@ -84,11 +86,21 @@ class ByteQueue {
ch.trySend(b)
}
/** the next chunk, waiting up to [ms]; null if none came (the reader's thread) */
/**
* the next chunk, waiting up to [ms]; null if none came (the reader's
* thread). (A select, not receive() in withTimeoutOrNull: a chunk sent
* just as that timed out was taken by the cancelled receive and lost.)
*/
@OptIn(ExperimentalCoroutinesApi::class)
fun poll(ms: Long): ByteArray? {
poll()?.let { return it }
if (ms <= 0) return null
return runBlocking { withTimeoutOrNull(ms) { ch.receive() } }
return runBlocking {
select {
ch.onReceive { it }
onTimeout(ms) { null }
}
}
}
/** the next chunk if one waits, else null */
@@ -0,0 +1,37 @@
// SPDX-License-Identifier: AGPL-3.0-only
// Copyright (C) 2026 Neo-Desktop
package com.neodesktop.dmodem.io
import kotlin.concurrent.Volatile
import kotlin.test.Test
import kotlin.test.assertEquals
/** A ByteQueue between two threads loses nothing, whatever its reads' timeouts. */
class ByteQueueTest {
private class Flag { @Volatile var on = false }
/** chunks put while the reader's short waits keep timing out all come, in order */
@Test
fun nothingLostToATimeout() {
val q = ByteQueue()
val n = 3000
val done = Flag()
background("writer") {
for (i in 0 until n) {
q.put(byteArrayOf((i shr 8).toByte(), i.toByte()))
// (now and then just as the reader's wait runs out)
if (i % 3 == 0) sleepMs(1)
}
done.on = true
}
var next = 0
val end = monotonicMs() + 30_000
while (next < n && monotonicMs() < end) {
val b = q.poll(1) ?: continue
val i = ((b[0].toInt() and 0xff) shl 8) or (b[1].toInt() and 0xff)
assertEquals(next, i, "chunk $next")
next++
}
assertEquals(n, next)
}
}
@@ -34,11 +34,11 @@ class PeerLoopbackTest {
/** a pipe's end: reads [inw], writes [outw] */
private class End(private val inw: Way, private val outw: Way, override val name: String) : Duplex {
override val input = object : Source {
/** the next of what came the other way, into [b] (waited for): how much, -1 once closed */
/** the next of what came the other way, into [b] (waited for): how much, -1 once closed and read to its end */
override fun read(b: ByteArray, off: Int, len: Int): Int {
while (inw.at >= inw.cur.size) {
if (inw.closed) return -1
inw.cur = inw.q.poll(50) ?: continue
// (what was written before the close still comes, as on a socket: a DENIED, say)
inw.cur = inw.q.poll() ?: if (inw.closed) return -1 else inw.q.poll(50) ?: continue
inw.at = 0
}
val n = minOf(len, inw.cur.size - inw.at)