From 0a309a36399db2216c31e21b8164fcd23e178981 Mon Sep 17 00:00:00 2001 From: Kyle Date: Sat, 2 Aug 2025 23:16:18 +0800 Subject: [PATCH] Fix DebugServerTests issue --- Sources/OpenGraphCxx/DebugServer/og-debug-server.mm | 13 ++++++++++--- .../OpenGraphCxx/DebugServer/og-debug-server.hpp | 3 +++ .../Debug/DebugServerTests.swift | 6 ++++-- Tests/OpenGraphTests/DummyTests.swift | 2 +- 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/Sources/OpenGraphCxx/DebugServer/og-debug-server.mm b/Sources/OpenGraphCxx/DebugServer/og-debug-server.mm index fcb9eefd..5255b59d 100644 --- a/Sources/OpenGraphCxx/DebugServer/og-debug-server.mm +++ b/Sources/OpenGraphCxx/DebugServer/og-debug-server.mm @@ -126,11 +126,18 @@ // log os_log_info(misc_log(), "debug server graph://%s:%d/?token=%u", address, port, token); - fprintf(stderr, "debug server graph://%s:%d/?token=%u\\n", address, port, token); + fprintf(stderr, "debug server graph://%s:%d/?token=%u\n", address, port, token); } -// TODO: To be implemented -OG::DebugServer::~DebugServer() {} +OG::DebugServer::~DebugServer() { + shutdown(); + for (auto &connection : connections) { + connection.reset(); + } + if (connections.data()) { + free(connections.data()); + } +} // TODO: select will fail here void OG::DebugServer::run(int timeout) { diff --git a/Sources/OpenGraphCxx/include/OpenGraphCxx/DebugServer/og-debug-server.hpp b/Sources/OpenGraphCxx/include/OpenGraphCxx/DebugServer/og-debug-server.hpp index 53e9970d..2ff5b8cd 100644 --- a/Sources/OpenGraphCxx/include/OpenGraphCxx/DebugServer/og-debug-server.hpp +++ b/Sources/OpenGraphCxx/include/OpenGraphCxx/DebugServer/og-debug-server.hpp @@ -16,6 +16,8 @@ OG_ASSUME_NONNULL_BEGIN +OG_IMPLICIT_BRIDGING_ENABLED + namespace OG { struct OGDebugServerMessageHeader { uint32_t token; @@ -61,6 +63,7 @@ typedef struct OGDebugServerStorage { OG::DebugServer debugServer; } OGDebugServerStorage; +OG_IMPLICIT_BRIDGING_DISABLED OG_ASSUME_NONNULL_END diff --git a/Tests/OpenGraphCompatibilityTests/Debug/DebugServerTests.swift b/Tests/OpenGraphCompatibilityTests/Debug/DebugServerTests.swift index a144609a..c5c3a0b0 100644 --- a/Tests/OpenGraphCompatibilityTests/Debug/DebugServerTests.swift +++ b/Tests/OpenGraphCompatibilityTests/Debug/DebugServerTests.swift @@ -7,13 +7,14 @@ import CoreFoundation import Foundation import Testing +@MainActor struct DebugServerTests { @Test func testMode0() { #expect(OGDebugServer.start(mode: 0) == nil) #expect(OGDebugServer.copyURL() == nil) } - + // To make AG start debugServer, we need to pass internal_diagnostics check. // In debug mode, we can breakpoint on `_ZN2AG11DebugServer5startEj` and // executable `reg write w0 1` after `internal_diagnostics` call. @@ -22,11 +23,12 @@ struct DebugServerTests { .disabled(if: compatibilityTestEnabled, "Skip on AG due to internal_diagnostics check"), ) func testMode1() throws { - _ = try #require(OGDebugServer.start(mode: 1)) + let _ = try #require(OGDebugServer.start(mode: 1)) let url = try #require(OGDebugServer.copyURL()) let urlString = (url as URL).absoluteString #expect(urlString.hasPrefix("graph://")) OGDebugServer.run(timeout: 1) + OGDebugServer.stop() } } #endif diff --git a/Tests/OpenGraphTests/DummyTests.swift b/Tests/OpenGraphTests/DummyTests.swift index 0f015532..f2b881bc 100644 --- a/Tests/OpenGraphTests/DummyTests.swift +++ b/Tests/OpenGraphTests/DummyTests.swift @@ -2,7 +2,7 @@ // DummyTests.swift // OpenGraphTests -@testable import OpenGraph +import OpenGraph import Testing struct DummyTests {}