From df3e0c4d7c89e57d505752b17ac8311ae5e15808 Mon Sep 17 00:00:00 2001 From: Dan <46821332+nsadeveloper789@users.noreply.github.com> Date: Wed, 20 May 2026 17:51:06 +0000 Subject: [PATCH] GP-0: Fix tests. --- .../sys/EmuAmd64SyscallUseropLibraryTest.java | 27 ++++++++++++------- .../java/agent/lldb/rmi/LldbHooksTest.java | 18 ++++++------- 2 files changed, 26 insertions(+), 19 deletions(-) diff --git a/Ghidra/Features/SystemEmulation/src/test/java/ghidra/pcode/emu/sys/EmuAmd64SyscallUseropLibraryTest.java b/Ghidra/Features/SystemEmulation/src/test/java/ghidra/pcode/emu/sys/EmuAmd64SyscallUseropLibraryTest.java index 6f898d085a..b3ddc5c57d 100644 --- a/Ghidra/Features/SystemEmulation/src/test/java/ghidra/pcode/emu/sys/EmuAmd64SyscallUseropLibraryTest.java +++ b/Ghidra/Features/SystemEmulation/src/test/java/ghidra/pcode/emu/sys/EmuAmd64SyscallUseropLibraryTest.java @@ -4,9 +4,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -15,8 +15,8 @@ */ package ghidra.pcode.emu.sys; -import static ghidra.pcode.emu.sys.EmuSyscallLibrary.*; -import static org.junit.Assert.*; +import static ghidra.pcode.emu.sys.EmuSyscallLibrary.SYSCALL_SPACE_NAME; +import static org.junit.Assert.assertEquals; import org.junit.*; @@ -181,18 +181,25 @@ public class EmuAmd64SyscallUseropLibraryTest extends AbstractGhidraHeadlessInte try (Transaction tx = program.openTransaction("Initialize")) { asm.assemble(start, "MOV RAX,0", - "MOV RCX,0xbeef", + "MOV RCX,0xbeef", // Will be clobbered with RIP by SYSCALL "MOV R10,0xdead", "SYSCALL"); } + /** + * This test is a bit nonsensical, because the calling conventions will cause parameters to + * get pulled from registers that get clobbered by the SYSCALL, per the ISA description, not + * just convention. Still, I want to test that the emulator obeys the assigned calling + * convention. + */ + SyscallTestPcodeEmulator emu = prepareEmulator(); PcodeThread thread = launchThread(emu, start); thread.stepInstruction(4); - assertArrayEquals(arithmetic.fromConst(0xbeef, regRAX.getNumBytes()), - thread.getState().getVar(regRAX, Reason.INSPECT)); + assertEquals("400017", + thread.getState().inspectRegisterValue(regRAX).getUnsignedValue().toString(16)); } @Test @@ -200,7 +207,7 @@ public class EmuAmd64SyscallUseropLibraryTest extends AbstractGhidraHeadlessInte try (Transaction tx = program.openTransaction("Initialize")) { asm.assemble(start, "MOV RAX,1", - "MOV RCX,0xdead", + "MOV RCX,0xdead", // Will be clobbered with RIP by SYSCALL "MOV R10,0xbeef", "SYSCALL"); } @@ -210,7 +217,7 @@ public class EmuAmd64SyscallUseropLibraryTest extends AbstractGhidraHeadlessInte thread.stepInstruction(4); - assertArrayEquals(arithmetic.fromConst(0xbeef, regRAX.getNumBytes()), - thread.getState().getVar(regRAX, Reason.INSPECT)); + assertEquals("dead", + thread.getState().inspectRegisterValue(regRAX).getUnsignedValue().toString(16)); } } diff --git a/Ghidra/Test/DebuggerIntegrationTest/src/test.slow/java/agent/lldb/rmi/LldbHooksTest.java b/Ghidra/Test/DebuggerIntegrationTest/src/test.slow/java/agent/lldb/rmi/LldbHooksTest.java index a221f80453..dbe4a95844 100644 --- a/Ghidra/Test/DebuggerIntegrationTest/src/test.slow/java/agent/lldb/rmi/LldbHooksTest.java +++ b/Ghidra/Test/DebuggerIntegrationTest/src/test.slow/java/agent/lldb/rmi/LldbHooksTest.java @@ -16,7 +16,8 @@ package agent.lldb.rmi; import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.*; +import static org.hamcrest.Matchers.greaterThan; +import static org.hamcrest.Matchers.instanceOf; import static org.junit.Assert.*; import java.nio.ByteBuffer; @@ -316,9 +317,9 @@ public class LldbHooksTest extends AbstractLldbTraceRmiTest { try (LldbAndTrace conn = startAndSyncLldb()) { start(conn, getSpecimenPrint()); - TraceObject inf = waitForValue(() -> tb.objAny0("Processes[]")); + TraceObject proc = waitForValue(() -> tb.objAny0("Processes[]")); waitForPass(() -> { - assertEquals("STOPPED", tb.objValue(inf, lastSnap(conn), "_state")); + assertEquals("STOPPED", tb.objValue(proc, lastSnap(conn), "_state")); }, RUN_TIMEOUT_MS, RETRY_MS); conn.success(); } @@ -412,11 +413,11 @@ public class LldbHooksTest extends AbstractLldbTraceRmiTest { waitStopped(conn.conn); conn.execute("breakpoint delete %s".formatted(brk.getCanonicalPath().index())); - conn.execute("stepi"); + waitForPass(noExc(() -> conn.execute("stepi"))); - waitForPass( - () -> assertEquals(0, - tb.objValues(lastSnap(conn), "Processes[].Breakpoints[]").size())); + waitForPass(() -> { + assertEquals(0, tb.objValues(lastSnap(conn), "Processes[].Breakpoints[]").size()); + }); conn.success(); } } @@ -438,8 +439,7 @@ public class LldbHooksTest extends AbstractLldbTraceRmiTest { conn.success(); } } - - + private void start(LldbAndTrace conn, String obj) { conn.execute("file " + obj); conn.execute("ghidra trace sync-enable");