diff --git a/bridge/native/test_rea_lldb_tracer.py b/bridge/native/test_rea_lldb_tracer.py index b73c08b31..6672d9bc8 100644 --- a/bridge/native/test_rea_lldb_tracer.py +++ b/bridge/native/test_rea_lldb_tracer.py @@ -269,9 +269,23 @@ class NativeTraceBudgetTests(unittest.TestCase): def GetFileSpec(self): return FileSpec() + class SourceFileSpec: + def IsValid(self): + return True + + def __str__(self): + return source_path + class Address: def GetLineEntry(self): - return types.SimpleNamespace(IsValid=lambda: False) + if source_path is None: + return types.SimpleNamespace(IsValid=lambda: False) + return types.SimpleNamespace( + IsValid=lambda: True, + GetFileSpec=SourceFileSpec, + GetLine=lambda: 15, + GetColumn=lambda: 3, + ) def GetModule(self): return Module() @@ -299,19 +313,35 @@ class NativeTraceBudgetTests(unittest.TestCase): breakpoint_count = 1000 created = [[Breakpoint()] for _ in range(breakpoint_count)] config = {"breakpoints": [{"kind": "objc-method"}] * breakpoint_count} - report, locations_truncated = tracer._breakpoint_report( - object(), created, config - ) - retained_bytes = sum( - len(json.dumps(location).encode("utf-8")) - + (1 if index > 0 else 0) - for row in report - for index, location in enumerate(row["locations"]) - ) - self.assertTrue(locations_truncated) - self.assertEqual(sum(row["location_count"] for row in report), 64_000) - self.assertLess(sum(len(row["locations"]) for row in report), 64_000) - self.assertLessEqual(retained_bytes, tracer.MAX_BREAKPOINT_LOCATION_BYTES) + for source_path in (None, "/tmp/" + "源🚀" * 3000 + "/calls.pas"): + with self.subTest(source_path_present=source_path is not None): + report, locations_truncated = tracer._breakpoint_report( + object(), created, config + ) + retained_bytes = sum( + len(json.dumps(location).encode("utf-8")) + + (1 if index > 0 else 0) + for row in report + for index, location in enumerate(row["locations"]) + ) + self.assertTrue(locations_truncated) + self.assertEqual( + sum(row["location_count"] for row in report), 64_000 + ) + self.assertLess( + sum(len(row["locations"]) for row in report), 64_000 + ) + self.assertLessEqual( + retained_bytes, tracer.MAX_BREAKPOINT_LOCATION_BYTES + ) + if source_path is not None: + self.assertTrue( + any( + location["source_location"]["file_path"] == source_path + for row in report + for location in row["locations"] + ) + ) if __name__ == "__main__": diff --git a/scripts/verify-native-pascal-calls.mjs b/scripts/verify-native-pascal-calls.mjs index b1ef06d6a..62cc31daf 100644 --- a/scripts/verify-native-pascal-calls.mjs +++ b/scripts/verify-native-pascal-calls.mjs @@ -1,6 +1,6 @@ import assert from "node:assert/strict"; import { execFile } from "node:child_process"; -import { mkdtemp, rm } from "node:fs/promises"; +import { mkdtemp, readFile, rm } from "node:fs/promises"; import { tmpdir } from "node:os"; import { isAbsolute, join } from "node:path"; import { fileURLToPath } from "node:url"; @@ -21,6 +21,16 @@ if (process.platform !== "darwin" || !isAbsolute(compiler ?? "")) const source = fileURLToPath( new URL("../tests/conformance/native/calls.pas", import.meta.url), ); +const fixtureLines = (await readFile(source, "utf8")).split(/\r?\n/u); +const callerLines = new Set( + ["REA_VERIFY_CALLER_LOOP", "REA_VERIFY_CALLER_CALL"].map((marker) => { + const matches = fixtureLines.flatMap((line, index) => + line.includes(marker) ? [index + 1] : [], + ); + assert.equal(matches.length, 1, `fixture has one ${marker} marker`); + return matches[0]; + }), +); const directory = await mkdtemp(join(tmpdir(), "rea-pascal-calls-")); const input = { breakpoints: [{ kind: "function", name: "rea_pascal_call" }], @@ -44,7 +54,7 @@ const inspect = (result) => { assert.equal(event.backtrace[0].source_location?.file_path, source); assert.equal(event.backtrace[0].module_path, join(directory, "calls")); assert.ok( - [14, 15].includes(event.backtrace[0].source_location.line), + callerLines.has(event.backtrace[0].source_location.line), "caller is the Pascal loop/call site", ); } @@ -69,10 +79,13 @@ const stable = (result) => })); try { const version = ( - await execute(compiler, ["-iV"], { timeout: 30_000 }) + await execute(compiler, ["-iV"], { timeout: 30_000, killSignal: "SIGKILL" }) ).stdout.trim(); const architecture = ( - await execute(compiler, ["-iTP"], { timeout: 30_000 }) + await execute(compiler, ["-iTP"], { + timeout: 30_000, + killSignal: "SIGKILL", + }) ).stdout.trim(); await execute( compiler, @@ -85,7 +98,7 @@ try { `-FU${directory}`, source, ], - { timeout: 120_000 }, + { timeout: 120_000, killSignal: "SIGKILL" }, ); const binary = join(directory, "calls"); const cli = await artifactCli( diff --git a/tests/conformance/native/calls.pas b/tests/conformance/native/calls.pas index d9d7f8855..c9ebe1d02 100644 --- a/tests/conformance/native/calls.pas +++ b/tests/conformance/native/calls.pas @@ -11,6 +11,6 @@ end; var Index: LongInt; begin - for Index := 0 to 2 do - ReaPascalCall(Index); + for Index := 0 to 2 do { REA_VERIFY_CALLER_LOOP } + ReaPascalCall(Index); { REA_VERIFY_CALLER_CALL } end.