Skip to content

Commit 2337476

Browse files
committed
test: add ghidra integration test
1 parent 1bbf6a1 commit 2337476

1 file changed

Lines changed: 54 additions & 3 deletions

File tree

.github/workflows/ci.yml

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ jobs:
8484
# Integration Test (with Ghidra)
8585
# ============================================================
8686
integration:
87-
name: Integration Test
87+
name: Integration Test (Ghidra)
8888
runs-on: ubuntu-latest
89-
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
89+
# Run on all PRs and pushes to test Ghidra integration
9090

9191
steps:
9292
- uses: actions/checkout@v4
@@ -107,11 +107,12 @@ jobs:
107107
distribution: 'temurin'
108108
java-version: '17'
109109

110-
- name: Download Ghidra
110+
- name: Download and setup Ghidra
111111
run: |
112112
wget -q https://github.com/NationalSecurityAgency/ghidra/releases/download/Ghidra_11.2.1_build/ghidra_11.2.1_PUBLIC_20241105.zip
113113
unzip -q ghidra_11.2.1_PUBLIC_20241105.zip
114114
mv ghidra_11.2.1_PUBLIC $HOME/ghidra
115+
echo "GHIDRA_HOME=$HOME/ghidra" >> $GITHUB_ENV
115116
116117
- name: Build test fixtures
117118
run: |
@@ -140,13 +141,63 @@ jobs:
140141
mkdir -p test_output
141142
echo 'void test() { return; }' > test_output/sample.cpp
142143
python evaluate_quality.py test_output/
144+
145+
- name: Test quality evaluation with C files
146+
run: |
147+
# Test that *.c* pattern works for both .c and .cpp
148+
mkdir -p test_output_c
149+
echo 'int foo(void) { return 42; }' > test_output_c/sample.c
150+
echo 'void bar() { return; }' > test_output_c/sample.cpp
151+
python evaluate_quality.py test_output_c/
143152
144153
- name: Test libsurgeon help
145154
run: |
146155
python libsurgeon.py --help
147156
# Verify ELF module option exists
148157
python libsurgeon.py --help | grep -q "\-m.*prefix\|alpha\|camelcase\|single"
149158
159+
- name: Test architecture detection
160+
run: |
161+
python -c "
162+
from libsurgeon import detect_elf_architecture, ELF_MACHINE_MAP
163+
# Verify the mapping exists
164+
assert 0x28 in ELF_MACHINE_MAP, 'ARM should be in map'
165+
assert 0x3E in ELF_MACHINE_MAP, 'x86-64 should be in map'
166+
print('Architecture detection OK')
167+
"
168+
169+
- name: Test Ghidra decompilation of archive
170+
run: |
171+
# Test decompiling the test archive with Ghidra
172+
python libsurgeon.py -g $HOME/ghidra tests/fixtures/libtest.a -o test_decompile_output --clean
173+
174+
# Verify output was generated
175+
ls -la test_decompile_output/
176+
test -d test_decompile_output/libtest/src
177+
178+
# Check that at least one .cpp file was created
179+
cpp_count=$(find test_decompile_output/libtest/src -name "*.cpp" | wc -l)
180+
echo "Generated $cpp_count .cpp files"
181+
test $cpp_count -ge 1
182+
183+
- name: Test Ghidra decompilation with evaluation
184+
run: |
185+
# Test with --evaluate flag
186+
python libsurgeon.py -g $HOME/ghidra tests/fixtures/libtest.a -o test_eval_output --evaluate --clean
187+
188+
# Verify quality report was generated
189+
test -f test_eval_output/libtest/quality_report.json
190+
cat test_eval_output/libtest/quality_report.json
191+
192+
- name: Test ELF file decompilation
193+
run: |
194+
# Test decompiling ELF executable
195+
python libsurgeon.py -g $HOME/ghidra tests/fixtures/test_program.elf -o test_elf_output --clean
196+
197+
# Verify output
198+
ls -la test_elf_output/
199+
test -d test_elf_output/test_program/src
200+
150201
# ============================================================
151202
# Documentation
152203
# ============================================================

0 commit comments

Comments
 (0)