Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions test/ghidra_real_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package main

import (
"os"
"path/filepath"
"testing"
)

// requireRealGhidra gates the tests that actually run analyzeHeadless. A cold
// import costs minutes and writes a Ghidra project, so it is opt-in and never
// runs in CI. LRECON_GHIDRA_CACHE and LRECON_STATE point at the test's temp
// dir, so the run leaves the user's project and session state untouched.
func requireRealGhidra(t *testing.T) {
t.Helper()
if testing.Short() {
t.Skip("real ghidra import")
}
if os.Getenv("CI") != "" {
t.Skip("real ghidra import is skipped in CI")
}
if os.Getenv("LRECON_OPS_GHIDRA") != "1" {
t.Skip("real ghidra import is opt-in: set LRECON_OPS_GHIDRA=1")
}
if _, _, err := findGhidra(); err != nil {
t.Skip("ghidra analyzeHeadless not installed")
}
root := t.TempDir()
t.Setenv("LRECON_GHIDRA_CACHE", filepath.Join(root, "ghidra-cache"))
t.Setenv("LRECON_STATE", filepath.Join(root, "state"))
t.Setenv("LRECON_GHIDRA_TIMEOUT", "300s")
}
7 changes: 1 addition & 6 deletions test/op_contract_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,7 @@ func TestOpMapResultExit0(t *testing.T) {

// A route G item on the happy path: the moved declines must not swallow it.
func TestOpGhidraResultExit0(t *testing.T) {
if _, _, err := findGhidra(); err != nil {
t.Skip("ghidra analyzeHeadless not installed")
}
// The 50 s default would turn a cold import into a timeout envelope; this
// test is about the happy path, so it pays for the import.
t.Setenv("LRECON_GHIDRA_TIMEOUT", "300s")
requireRealGhidra(t)
stdout, stderr, code := runCLIAll(t, "--op", "list_segments", "/bin/ls")
if code != 0 {
t.Fatalf("exit %d, want 0; stderr:\n%s", code, stderr)
Expand Down
10 changes: 1 addition & 9 deletions test/op_meta_real_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,7 @@ func metaRealFuncAddr(t *testing.T, path string) string {
// proves wiring; this proves the script compiles in Ghidra and that the values
// it reports are the ones the project really stored.
func TestMetaGhidraReal(t *testing.T) {
if testing.Short() {
t.Skip("real ghidra import")
}
if _, err := metaGhidraPath(); err != nil {
t.Skip("ghidra analyzeHeadless not installed")
}
// A cold real import outlasts the 50 s op budget, and this test asserts on
// stored values rather than on the timeout envelope.
t.Setenv("LRECON_GHIDRA_TIMEOUT", "300s")
requireRealGhidra(t)
target, addr := metaRealTarget(t)

// PRE, not PLATE: "PRE" was the mode the Go side asked for while Meta.java
Expand Down
10 changes: 1 addition & 9 deletions test/op_native_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,15 +187,7 @@ func TestOpNativeGhidraAbsent(t *testing.T) {
}

func TestOpNativeGhidraRealImport(t *testing.T) {
if testing.Short() {
t.Skip("real ghidra import")
}
if _, _, err := findGhidra(); err != nil {
t.Skip("ghidra analyzeHeadless not installed")
}
// A real import is the case the 50 s default refuses to gamble on: the
// budget must outlast it or the test asserts on a timeout envelope.
t.Setenv("LRECON_GHIDRA_TIMEOUT", "300s")
requireRealGhidra(t)
res, err := ops["list_segments"].run("/usr/bin/true")
if err != nil {
t.Fatalf("list_segments on /usr/bin/true: %v", err)
Expand Down
4 changes: 1 addition & 3 deletions test/op_tur7_bucket22_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,13 +196,11 @@ func tur22CallTargets(ins []tur22Insn) map[uint64]bool {
}

func TestTur7Bucket22ProcedureGraph(t *testing.T) {
requireRealGhidra(t)
fixture, err := filepath.Abs(tur22Fixture)
if err != nil {
t.Fatalf("fixture path: %v", err)
}
// A cold import is a legitimate run, not a failure of the tool: give the
// documented budget room and assert content, never duration.
t.Setenv("LRECON_GHIDRA_TIMEOUT", "300s")

// 1. procedure_info: the name and the address are two ways to ask about one
// procedure, and the answer has to be the same one either way — the entry
Expand Down
2 changes: 1 addition & 1 deletion test/op_tur7_bucket26_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
// targets independently of Ghidra; every hop the tool returns must be one of
// them, in order.
func TestTur7Bucket26CallPathDisasmHops(t *testing.T) {
requireRealGhidra(t)
dir := t.TempDir()
src := `package main

Expand Down Expand Up @@ -90,7 +91,6 @@ func main() { println(alpha(2)) }

t.Setenv("LRECON_FROM", "main.alpha")
t.Setenv("LRECON_TO", "main.gamma")
t.Setenv("LRECON_GHIDRA_TIMEOUT", "300s")
stdout, code := runCLI(t, "--json", "--op", "trace_call_path", bin)
if code != 0 {
t.Fatalf("trace_call_path exit %d, want 0; output:\n%s", code, stdout)
Expand Down
Loading