Compare commits

...

33 Commits

Author SHA1 Message Date
Eric Kilmer e371046481 CI: Use default compiler on runner instead of clang 2022-04-22 10:48:19 -04:00
Eric Kilmer e69a0323b7 Fix CMake message for selected Ghidra git reference 2022-04-22 10:43:17 -04:00
Eric Kilmer cf4a096a7f support: Simplify CMake source file listing for library 2022-04-22 10:43:17 -04:00
Eric Kilmer a149784982 CI: Use default build generator and compiler
We should test with default configurations because this is likely what
people will be using when they test the project.

GNU Makefiles generator is also useful to test because it is usually the
simplest (read: least featured) generator and exposes a bug with the way
we have set up our CMake target dependencies when generating Git version
information.
2022-04-22 10:43:17 -04:00
Eric Kilmer 593ef2d5f3 CI: Don't fail-fast with matrix builds
All of our builds are testing separate things and it would be nice to
know if only one combination is troublesome or not. This is hard to
determine if all other builds are canceled when one fails.
2022-04-22 10:43:17 -04:00
auto-updater[bot] 3703123e79 Update Ghidra HEAD to commit 9c04807c8 (#88)
* Bump Ghidra HEAD commit 9c04807c8

* Add new source file

Co-authored-by: ekilmer <ekilmer@users.noreply.github.com>
Co-authored-by: Eric Kilmer <eric.d.kilmer@gmail.com>
2022-04-22 09:53:02 -04:00
Eric Kilmer e8383e673b Revert "Add new source file"
This reverts commit eb22b705d9.
2022-04-22 09:02:14 -04:00
Eric Kilmer eb22b705d9 Add new source file 2022-04-22 09:01:35 -04:00
Eric Kilmer 264204577d Update to Ghidra stable 10.1.3 (#87)
https://github.com/NationalSecurityAgency/ghidra/releases/tag/Ghidra_10.1.3_build

* Synchronize spec files list with HEAD
2022-04-22 08:54:05 -04:00
auto-updater[bot] 521a606fa9 Bump Ghidra HEAD commit 0ab836add (#86)
Co-authored-by: pgoodman <pgoodman@users.noreply.github.com>
2022-04-18 11:10:50 +10:00
auto-updater[bot] 13392ebf97 Bump Ghidra HEAD commit 4adddf061 (#84)
Co-authored-by: pgoodman <pgoodman@users.noreply.github.com>
2022-04-11 11:32:20 +10:00
Alex Cameron 4662552d17 cmake: Build SLEIGH with C++11 (#83)
* cmake: Build SLEIGH with C++11

* cmake: Expose compile flag as PUBLIC so that sleigh-lift inherits it

* test: Link support in find_package test
2022-04-05 00:02:43 +10:00
auto-updater[bot] e4558db017 Bump Ghidra HEAD commit 7080c10df (#82)
Co-authored-by: pgoodman <pgoodman@users.noreply.github.com>
2022-04-04 14:17:17 +10:00
auto-updater[bot] b15f26bac8 Bump Ghidra HEAD commit 883f5a687 (#80)
Co-authored-by: pgoodman <pgoodman@users.noreply.github.com>
2022-03-27 20:25:31 -04:00
auto-updater[bot] 274058b4d9 Bump Ghidra HEAD commit b6181be1e (#79)
Co-authored-by: ekilmer <ekilmer@users.noreply.github.com>
2022-03-23 09:29:52 -04:00
dependabot[bot] b8e35dc652 build(deps): bump peter-evans/create-pull-request from 3 to 4 (#78)
Bumps [peter-evans/create-pull-request](https://github.com/peter-evans/create-pull-request) from 3 to 4.
- [Release notes](https://github.com/peter-evans/create-pull-request/releases)
- [Commits](https://github.com/peter-evans/create-pull-request/compare/v3...v4)

---
updated-dependencies:
- dependency-name: peter-evans/create-pull-request
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-03-24 00:06:44 +11:00
dependabot[bot] 72c58bc7e3 build(deps): bump actions/cache from 2 to 3 (#76)
Bumps [actions/cache](https://github.com/actions/cache) from 2 to 3.
- [Release notes](https://github.com/actions/cache/releases)
- [Commits](https://github.com/actions/cache/compare/v2...v3)

---
updated-dependencies:
- dependency-name: actions/cache
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-03-22 09:49:30 -04:00
auto-updater[bot] 96b58968a7 Bump Ghidra HEAD commit 2d7c8d505 (#75)
Co-authored-by: pgoodman <pgoodman@users.noreply.github.com>
2022-03-21 12:15:34 +11:00
auto-updater[bot] f152f04095 Bump Ghidra HEAD commit 4200ae567 (#74)
Co-authored-by: pgoodman <pgoodman@users.noreply.github.com>
2022-03-14 11:36:04 +11:00
Eric Kilmer 759fe7ff76 Bump package version v10.1.2-2 (#73) 2022-03-11 11:34:16 -05:00
Eric Kilmer 3ba6dd5a3e Support minimum macOS 10.15 in CI artifacts (#72) 2022-03-11 10:41:55 -05:00
Eric Kilmer dbc3dbd15f Let user specify path to sleigh compiler in CMake module (#69)
This allows user to specify an arbitrary sleigh compiler. Almost always
it's going to be the sleigh::sleigh_opt target, but in the case of
cross-compiling, that won't work because the host won't be able to run
it.
2022-03-11 09:27:41 -05:00
auto-updater[bot] 893c97711f Bump Ghidra HEAD commit ee268dea0 (#71)
Co-authored-by: pgoodman <pgoodman@users.noreply.github.com>
2022-03-07 12:43:48 +11:00
dependabot[bot] a66b0abf26 build(deps): bump actions/upload-artifact from 2.3.1 to 3 (#70)
Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 2.3.1 to 3.
- [Release notes](https://github.com/actions/upload-artifact/releases)
- [Commits](https://github.com/actions/upload-artifact/compare/v2.3.1...v3)

---
updated-dependencies:
- dependency-name: actions/upload-artifact
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-03-04 09:20:39 -05:00
Eric Kilmer f8f4b7e550 Update apt in CI before installing dependencies 2022-03-04 08:54:36 -05:00
dependabot[bot] a3dd5d5ca1 build(deps): bump actions/checkout from 2.4.0 to 3 (#68)
Bumps [actions/checkout](https://github.com/actions/checkout) from 2.4.0 to 3.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v2.4.0...v3)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-03-02 16:53:42 +11:00
dependabot[bot] d4e2eb5aa2 build(deps): bump actions/setup-python from 2 to 3 (#67)
Bumps [actions/setup-python](https://github.com/actions/setup-python) from 2 to 3.
- [Release notes](https://github.com/actions/setup-python/releases)
- [Commits](https://github.com/actions/setup-python/compare/v2...v3)

---
updated-dependencies:
- dependency-name: actions/setup-python
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-03-01 17:42:12 +11:00
Eric Kilmer cb86cb0c22 Add data tests (#62)
* Add sleigh datatests tests as CTest target

* Fix Ghidra test runner not reporting failed tests in exit code
2022-02-28 15:47:36 -05:00
Eric Kilmer f395ce311a Shallow clone for stable builds (#65)
Saves a little bit of time
2022-02-28 15:29:30 -05:00
Eric Kilmer 8dfe626001 Remove cmake_path and lower minimum required CMake version (#64)
New minimum is CMake 3.15
2022-02-28 14:56:46 -05:00
auto-updater[bot] 901efbb17e Bump Ghidra HEAD commit 3e245c6f8 (#66) 2022-02-20 21:17:52 -05:00
auto-updater[bot] c44e6ad2ab Bump Ghidra HEAD commit 1a1d06b74 (#63)
Co-authored-by: pgoodman <pgoodman@users.noreply.github.com>
2022-02-14 11:29:57 +11:00
Eric Kilmer 6ed111cc3b Only upload stable assets to release page 2022-02-08 10:15:43 -05:00
12 changed files with 420 additions and 111 deletions
+18 -17
View File
@@ -18,13 +18,14 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest]
build_type: [RelWithDebInfo, Debug]
release: [stable, HEAD]
steps:
- uses: actions/checkout@v2.4.0
- uses: actions/checkout@v3
- name: Setup Git User for Applying Patches
# See this thread for more details https://github.community/t/github-actions-bot-email-address/17204/5
@@ -35,6 +36,7 @@ jobs:
- name: Install Linux system dependencies
if: runner.os == 'Linux'
run: |
sudo apt-get update
sudo apt-get install -y \
clang \
rpm \
@@ -43,21 +45,20 @@ jobs:
graphviz
# Minimum supported CMake version testing
curl -L "https://github.com/Kitware/CMake/releases/download/v3.21.0/cmake-3.21.0-linux-$(uname -m).sh" -o /tmp/cmake-install.sh
curl -L "https://github.com/Kitware/CMake/releases/download/v3.15.0/cmake-3.15.0-Linux-$(uname -m).sh" -o /tmp/cmake-install.sh
mkdir -p "${HOME}/.local"
bash /tmp/cmake-install.sh --skip-license --exclude-subdir "--prefix=${HOME}/.local"
# Use Homebrew for latest build tool version for use in CI
brew install \
ccache \
ninja
ccache
- name: Install macOS system dependencies
if: runner.os == 'macOS'
run: |
echo "MACOSX_DEPLOYMENT_TARGET=10.15" >> ${GITHUB_ENV}
brew install \
ccache \
ninja \
cmake \
doxygen \
graphviz
@@ -71,7 +72,7 @@ jobs:
message("::set-output name=timestamp::${current_date}")
- name: Update the cache (ccache)
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: "${{ github.workspace }}/ccache"
key: ${{ steps.cache_key.outputs.VALUE }}_ccache_${{ steps.cache_key.outputs.timestamp }}
@@ -99,9 +100,6 @@ jobs:
cmake \
-S . \
-B build \
-G Ninja \
-DCMAKE_C_COMPILER=clang \
-DCMAKE_CXX_COMPILER=clang++ \
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
-DCMAKE_C_COMPILER_LAUNCHER=ccache \
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \
@@ -115,6 +113,7 @@ jobs:
run: |
cmake \
--build build \
-j 2 \
-v
- name: Run the tests
@@ -125,6 +124,7 @@ jobs:
run: |
cmake \
--build build \
-j 2 \
--target sleighexample_runner
- name: Run the install target
@@ -136,13 +136,14 @@ jobs:
working-directory: tests/find_package
run: |
cmake -B build -S . -Dsleigh_DIR=${{ github.workspace }}/install/lib/cmake/sleigh
cmake --build build
cmake --build build -j 2
./build/sleigh_test
- name: Create the packages
run: |
cmake \
--build build \
-j 2 \
--target package
- name: Test the DEB package
@@ -155,7 +156,7 @@ jobs:
-B find_package_build
cmake \
--build find_package_build --verbose
--build find_package_build -j 2 --verbose
- name: Locate the packages (RelWithDebInfo only)
if: matrix.build_type == 'RelWithDebInfo'
@@ -178,41 +179,41 @@ jobs:
# DEB Package
- name: Upload the DEB package artifact (RelWithDebInfo only)
if: matrix.build_type == 'RelWithDebInfo' && runner.os == 'Linux'
uses: actions/upload-artifact@v2.3.1
uses: actions/upload-artifact@v3
with:
name: ${{ steps.package_locations.outputs.DEB_PACKAGE_NAME }}
path: ${{ steps.package_locations.outputs.DEB_PACKAGE_PATH }}
- name: Release DEB package artifact (RelWithDebInfo only)
uses: softprops/action-gh-release@v0.1.14
if: matrix.build_type == 'RelWithDebInfo' && runner.os == 'Linux' && startsWith(github.ref, 'refs/tags/')
if: matrix.build_type == 'RelWithDebInfo' && runner.os == 'Linux' && startsWith(github.ref, 'refs/tags/') && matrix.release == 'stable'
with:
files: ${{ steps.package_locations.outputs.DEB_PACKAGE_PATH }}
# RPM Package
- name: Upload the RPM package artifact (RelWithDebInfo only)
if: matrix.build_type == 'RelWithDebInfo' && runner.os == 'Linux'
uses: actions/upload-artifact@v2.3.1
uses: actions/upload-artifact@v3
with:
name: ${{ steps.package_locations.outputs.RPM_PACKAGE_NAME }}
path: ${{ steps.package_locations.outputs.RPM_PACKAGE_PATH }}
- name: Release RPM package artifact (RelWithDebInfo only)
uses: softprops/action-gh-release@v0.1.14
if: matrix.build_type == 'RelWithDebInfo' && runner.os == 'Linux' && startsWith(github.ref, 'refs/tags/')
if: matrix.build_type == 'RelWithDebInfo' && runner.os == 'Linux' && startsWith(github.ref, 'refs/tags/') && matrix.release == 'stable'
with:
files: ${{ steps.package_locations.outputs.RPM_PACKAGE_PATH }}
# TGZ Package
- name: Upload the TGZ package artifact (RelWithDebInfo only)
if: matrix.build_type == 'RelWithDebInfo'
uses: actions/upload-artifact@v2.3.1
uses: actions/upload-artifact@v3
with:
name: ${{ steps.package_locations.outputs.TGZ_PACKAGE_NAME }}
path: ${{ steps.package_locations.outputs.TGZ_PACKAGE_PATH }}
- name: Release TGZ package artifact (RelWithDebInfo only)
uses: softprops/action-gh-release@v0.1.14
if: matrix.build_type == 'RelWithDebInfo' && startsWith(github.ref, 'refs/tags/')
if: matrix.build_type == 'RelWithDebInfo' && startsWith(github.ref, 'refs/tags/') && matrix.release == 'stable'
with:
files: ${{ steps.package_locations.outputs.TGZ_PACKAGE_PATH }}
+3 -3
View File
@@ -12,9 +12,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2.4.0
- uses: actions/checkout@v3
- uses: actions/setup-python@v2
- uses: actions/setup-python@v3
with:
# Use oldest supported version for maximum script compatibility
python-version: '3.7'
@@ -36,7 +36,7 @@ jobs:
- name: Create PR
if: steps.head_update.outputs.did_update
uses: peter-evans/create-pull-request@v3
uses: peter-evans/create-pull-request@v4
with:
title: Update Ghidra HEAD to commit ${{ steps.head_update.outputs.short_sha }}
commit-message: Bump Ghidra HEAD commit ${{ steps.head_update.outputs.short_sha }}
+35 -16
View File
@@ -6,7 +6,7 @@
# the LICENSE file found in the root directory of this source tree.
#
cmake_minimum_required(VERSION 3.21.0)
cmake_minimum_required(VERSION 3.15)
# Sets "library_root" variable for decompiler cpp root directory
# Sets "ghidra_version" for numeric version number
@@ -133,6 +133,11 @@ set(sleigh_deccore_source_list
"${library_root}/opbehavior.cc"
"${library_root}/paramid.cc"
)
if("${sleigh_GHIDRA_RELEASE_TYPE}" STREQUAL "HEAD")
list(APPEND sleigh_deccore_source_list
"${library_root}/unionresolve.cc"
)
endif()
set(sleigh_extra_source_list
"${library_root}/callgraph.cc"
@@ -191,7 +196,7 @@ add_library(sleigh_settings INTERFACE)
add_library(sleigh::sleigh_settings ALIAS sleigh_settings)
target_compile_features(sleigh_settings INTERFACE
cxx_std_17
cxx_std_11
)
set(sleigh_SPEC_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/share/sleigh/specfiles/")
@@ -315,9 +320,16 @@ if(sleigh_ENABLE_TESTS)
)
add_test(
NAME ghidra_test_dbg
NAME ghidra_unittest_dbg
COMMAND ghidra_test_dbg -sleighpath "${CMAKE_CURRENT_BINARY_DIR}" unittests
)
add_test(
NAME ghidra_datatest_dbg
COMMAND ghidra_test_dbg -sleighpath "${CMAKE_CURRENT_BINARY_DIR}"
-path "${ghidrasource_SOURCE_DIR}/Ghidra/Features/Decompiler/src/decompile/datatests"
datatests
)
endif()
#
@@ -454,7 +466,7 @@ if(sleigh_ENABLE_DOCUMENTATION)
set(documentation_output "${CMAKE_CURRENT_BINARY_DIR}/doc")
# Always run this target because we have no source file tracking for incremental builds
add_custom_target(sleigh_documentation
COMMAND "${CMAKE_COMMAND}" -E rm -rf "${library_root}/../doc" "${documentation_output}"
COMMAND "${CMAKE_COMMAND}" -E remove_directory "${library_root}/../doc" "${documentation_output}"
COMMAND Doxygen::doxygen Doxyfile
COMMAND "${CMAKE_COMMAND}" -E copy_directory "${library_root}/../doc" "${documentation_output}"
COMMENT "sleigh: Generating the Doxygen documentation"
@@ -494,17 +506,23 @@ include(cmake/modules/sleighCompile.cmake)
# Example: '<ghidra_source_prefix>/Ghidra/Processors/8051/data/languages/mx51.slaspec'
foreach(spec_file ${spec_file_list})
# Get 'mx51'
cmake_path(GET spec_file STEM LAST_ONLY spec_name)
get_filename_component(spec_name "${spec_file}" NAME_WLE)
# Get '<ghidra_source_prefix>/Ghidra/Processors/8051/data/languages'
cmake_path(GET spec_file PARENT_PATH spec_dir)
get_filename_component(spec_dir "${spec_file}" DIRECTORY)
# Get '8051/data/languages'
cmake_path(RELATIVE_PATH spec_dir
BASE_DIRECTORY "${ghidrasource_SOURCE_DIR}/${spec_files_dir_prefix}"
OUTPUT_VARIABLE spec_proc_dir
file(RELATIVE_PATH spec_proc_dir
"${ghidrasource_SOURCE_DIR}/${spec_files_dir_prefix}"
"${spec_dir}"
)
# Add relative spec processor directory for later processing
list(APPEND spec_dirs ${spec_proc_dir})
# Get '8051'
cmake_path(GET spec_proc_dir PARENT_PATH proc_name)
cmake_path(GET proc_name PARENT_PATH proc_name)
get_filename_component(proc_name "${spec_proc_dir}" DIRECTORY)
get_filename_component(proc_name "${proc_name}" DIRECTORY)
set(spec_build_log "${spec_files_build_log_dir}/${spec_name}_build.log")
# Combine back again for the build directory output like
@@ -513,15 +531,13 @@ foreach(spec_file ${spec_file_list})
# '<build_prefix>/Ghidra/Processors/8051/data/languages/mx51.sla'
set(spec_out "${spec_out_dir}/${spec_name}.sla")
# Add relative spec processor directory for later processing
list(APPEND spec_dirs "${spec_proc_dir}")
string(REPLACE "." "_" spec_target_name ${spec_name})
set(spec_target "sleigh_spec_${spec_target_name}")
# Compile the sla file
sleigh_compile(
TARGET "${spec_target}"
COMPILER "$<TARGET_FILE:sleigh::sleigh_opt>"
SLASPEC "${spec_file}"
LOG_FILE "${spec_build_log}"
OUT_FILE "${spec_out}"
@@ -537,8 +553,11 @@ list(REMOVE_DUPLICATES spec_dirs)
foreach(spec_dir ${spec_dirs})
set(spec_src_dir "${ghidrasource_SOURCE_DIR}/${spec_files_dir_prefix}/${spec_dir}")
set(spec_out_dir "${spec_files_root_dir}/${spec_dir}")
cmake_path(GET spec_dir PARENT_PATH proc_name)
cmake_path(GET proc_name PARENT_PATH proc_name)
# Get the processor directory name
get_filename_component(proc_name "${spec_dir}" DIRECTORY)
get_filename_component(proc_name "${proc_name}" DIRECTORY)
# Copy all other files from the slaspec source directory:
# '<ghidra_source_prefix>/Ghidra/Processors/8051/data/languages'
# NOTE: This only copies the directory once, so you will need to remove the
+3 -2
View File
@@ -11,6 +11,7 @@ cmake_minimum_required(VERSION 3.15)
# Takes the following required arguments:
#
# TARGET: Named CMake target for performing sleigh compilation
# COMPILER: Path to sleigh compiler executable
# SLASPEC: Path to slaspec file
# LOG_FILE: File to write logs
# OUT_FILE: Compiled sleigh output file (should be in build directory somewhere)
@@ -20,7 +21,7 @@ cmake_minimum_required(VERSION 3.15)
# rebuild the sleigh file then you must delete the OUT_FILE
function(sleigh_compile)
set(options)
set(oneValueArgs TARGET SLASPEC LOG_FILE OUT_FILE)
set(oneValueArgs TARGET COMPILER SLASPEC LOG_FILE OUT_FILE)
set(multiValueArgs)
cmake_parse_arguments(parsed
"${options}"
@@ -54,7 +55,7 @@ function(sleigh_compile)
MAIN_DEPENDENCY "${spec_file}"
COMMAND ${CMAKE_COMMAND} -E make_directory "${spec_out_dir}"
COMMAND ${CMAKE_COMMAND} -E make_directory "${spec_build_log_dir}"
COMMAND "$<TARGET_FILE:sleigh::sleigh_opt>" ${spec_file} "${spec_out}" > "${spec_build_log}" 2>&1
COMMAND "${parsed_COMPILER}" ${spec_file} "${spec_out}" > "${spec_build_log}" 2>&1
WORKING_DIRECTORY "${spec_dir}"
COMMENT "sleigh: Compiling the '${spec_name}' spec file (logs written in '${spec_build_log}')"
BYPRODUCTS "${spec_build_log}"
@@ -0,0 +1,165 @@
From 031d9830abe8517540389672fd22dc479e46d696 Mon Sep 17 00:00:00 2001
From: Eric Kilmer <eric.d.kilmer@gmail.com>
Date: Sun, 13 Feb 2022 12:59:42 -0500
Subject: [PATCH] Small improvements to C++ decompiler testing from CLI
* Fixes argument parsing to accept more than one option for specifying
paths.
* Return a non-zero exit code (clamped to max value 255, even if more
than 255 tests fail) indicating number of failed tests. This is
helpful when running in a script (like in CI) to detect failures
instead of detecting failures through manual visual inspection of
output text.
---
.../Decompiler/src/decompile/cpp/test.cc | 42 ++++++++++++++-----
.../Decompiler/src/decompile/cpp/test.hh | 2 +-
.../src/decompile/cpp/testfunction.cc | 3 +-
.../src/decompile/cpp/testfunction.hh | 2 +-
4 files changed, 36 insertions(+), 13 deletions(-)
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/test.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/test.cc
index e81f2564a..ebc049c29 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/test.cc
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/test.cc
@@ -14,6 +14,9 @@
* limitations under the License.
*/
#include "test.hh"
+
+#include <algorithm>
+
#include "libdecomp.hh"
vector<UnitTest *> UnitTest::tests;
@@ -21,7 +24,8 @@ vector<UnitTest *> UnitTest::tests;
/// Run all the tests unless a non-empty set of names is passed in.
/// In which case, only the named tests in the set are run.
/// \param testNames is the set of names
-void UnitTest::run(set<string> &testNames)
+/// \return number of failed tests
+int UnitTest::run(set<string> &testNames)
{
int total = 0;
@@ -42,6 +46,7 @@ void UnitTest::run(set<string> &testNames)
}
std::cerr << "==============================" << std::endl;
std::cerr << passed << "/" << total << " tests passed." << std::endl;
+ return total - passed;
}
/// Create list of the absolute path of all tests to be run
@@ -85,7 +90,7 @@ int main(int argc, char **argv) {
set<string> dataTestNames;
string dirname("../datatests");
string sleighdirname("../../../../../../..");
- if (argc > 0) {
+ while (argc > 0) {
string command(argv[0]);
if (command == "-path") {
dirname = argv[1];
@@ -109,30 +114,47 @@ int main(int argc, char **argv) {
argv += 1;
argc -= 1;
}
- }
- if (argc > 0) {
- string command(argv[0]);
- if (command == "unittests") {
+ else if (command == "unittests") {
runUnitTests = true;
runDataTests = false; // Run only unit tests
unitTestNames.insert(argv + 1,argv + argc);
+ break;
}
else if (command == "datatests") {
runUnitTests = false; // Run only data-tests
runDataTests = true;
dataTestNames.insert(argv + 1,argv + argc);
+ break;
}
else {
- cout << "USAGE: ghidra_test [-path <datatestdir>] [[unittests|datatests] [testname1 testname2 ...]]" << endl;
+ cout << "USAGE: ghidra_test [-usesleighenv] [-sleighpath <sleighdir>] [-path <datatestdir>] [[unittests|datatests] [testname1 testname2 ...]]" << endl;
+ return -1;
}
}
startDecompilerLibrary(sleighdirname.c_str());
- if (runUnitTests)
- UnitTest::run(unitTestNames);
+
+ // Keep track of failed tests as return code to indicate failures, clamped at
+ // max 255 value
+ int failedTests = 0;
+ if (runUnitTests) {
+ int errors = UnitTest::run(unitTestNames);
+ // Clamp at 255 max return code
+ failedTests = std::min(
+ failedTests +
+ (errors < 0 ? 255 : std::min(errors, 255)),
+ 255);
+ }
if (runDataTests) {
vector<string> testFiles;
gatherDataTests(dirname,dataTestNames,testFiles);
cout << endl << endl;
- FunctionTestCollection::runTestFiles(testFiles,cout);
+ int errors = FunctionTestCollection::runTestFiles(testFiles,cout);
+ // Clamp at 255 max return code
+ failedTests = std::min(
+ failedTests +
+ (errors < 0 ? 255 : std::min(errors, 255)),
+ 255);
}
+
+ return failedTests;
}
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/test.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/test.hh
index 8b762c5b1..a138f511d 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/test.hh
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/test.hh
@@ -54,7 +54,7 @@ struct UnitTest {
tests.push_back(this);
}
- static void run(std::set<std::string> &testNames); ///< Run all the instantiated tests
+ static int run(std::set<std::string> &testNames); ///< Run all the instantiated tests
};
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/testfunction.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/testfunction.cc
index 66f8d3fa2..c136a964b 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/testfunction.cc
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/testfunction.cc
@@ -304,7 +304,7 @@ void FunctionTestCollection::runTests(list<string> &lateStream)
/// Run through all XML files in the given list, processing each in turn.
/// \param testFiles is the given list of test files
/// \param s is the output stream to print results to
-void FunctionTestCollection::runTestFiles(const vector<string> &testFiles,ostream &s)
+int FunctionTestCollection::runTestFiles(const vector<string> &testFiles,ostream &s)
{
int4 totalTestsApplied = 0;
@@ -344,4 +344,5 @@ void FunctionTestCollection::runTestFiles(const vector<string> &testFiles,ostrea
if (iter == failures.end()) break;
}
}
+ return totalTestsApplied - totalTestsSucceeded;
}
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/testfunction.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/testfunction.hh
index 52125b401..46abd6bce 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/testfunction.hh
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/testfunction.hh
@@ -91,7 +91,7 @@ class FunctionTestCollection {
void restoreXml(DocumentStorage &store,const Element *el); ///< Load tests from a \<decompilertest> tag.
void restoreXmlOldForm(DocumentStorage &store,const Element *el); ///< Load tests from \<binaryimage> tag.
void runTests(list<string> &lateStream); ///< Run the script and perform the tests
- static void runTestFiles(const vector<string> &testFiles,ostream &s); ///< Run tests for each listed file
+ static int runTestFiles(const vector<string> &testFiles,ostream &s); ///< Run tests for each listed file
};
#endif
--
2.35.1
@@ -1,53 +0,0 @@
From d0b7efa848938b880332a729629c31a724dbf855 Mon Sep 17 00:00:00 2001
From: Eric Kilmer <eric.d.kilmer@gmail.com>
Date: Mon, 1 Nov 2021 17:10:18 -0400
Subject: [PATCH] Fix arg parsing in sleigh C++ test runner
---
Ghidra/Features/Decompiler/src/decompile/cpp/test.cc | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/test.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/test.cc
index e81f2564a..7c5557158 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/test.cc
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/test.cc
@@ -85,7 +85,7 @@ int main(int argc, char **argv) {
set<string> dataTestNames;
string dirname("../datatests");
string sleighdirname("../../../../../../..");
- if (argc > 0) {
+ while (argc > 0) {
string command(argv[0]);
if (command == "-path") {
dirname = argv[1];
@@ -109,21 +109,23 @@ int main(int argc, char **argv) {
argv += 1;
argc -= 1;
}
- }
- if (argc > 0) {
- string command(argv[0]);
- if (command == "unittests") {
+ else if (command == "unittests") {
runUnitTests = true;
runDataTests = false; // Run only unit tests
unitTestNames.insert(argv + 1,argv + argc);
+ argv += 1;
+ argc -=1;
}
else if (command == "datatests") {
runUnitTests = false; // Run only data-tests
runDataTests = true;
dataTestNames.insert(argv + 1,argv + argc);
+ argv += 1;
+ argc -=1;
}
else {
cout << "USAGE: ghidra_test [-path <datatestdir>] [[unittests|datatests] [testname1 testname2 ...]]" << endl;
+ return -1;
}
}
startDecompilerLibrary(sleighdirname.c_str());
--
2.33.1
@@ -0,0 +1,165 @@
From 031d9830abe8517540389672fd22dc479e46d696 Mon Sep 17 00:00:00 2001
From: Eric Kilmer <eric.d.kilmer@gmail.com>
Date: Sun, 13 Feb 2022 12:59:42 -0500
Subject: [PATCH] Small improvements to C++ decompiler testing from CLI
* Fixes argument parsing to accept more than one option for specifying
paths.
* Return a non-zero exit code (clamped to max value 255, even if more
than 255 tests fail) indicating number of failed tests. This is
helpful when running in a script (like in CI) to detect failures
instead of detecting failures through manual visual inspection of
output text.
---
.../Decompiler/src/decompile/cpp/test.cc | 42 ++++++++++++++-----
.../Decompiler/src/decompile/cpp/test.hh | 2 +-
.../src/decompile/cpp/testfunction.cc | 3 +-
.../src/decompile/cpp/testfunction.hh | 2 +-
4 files changed, 36 insertions(+), 13 deletions(-)
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/test.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/test.cc
index e81f2564a..ebc049c29 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/test.cc
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/test.cc
@@ -14,6 +14,9 @@
* limitations under the License.
*/
#include "test.hh"
+
+#include <algorithm>
+
#include "libdecomp.hh"
vector<UnitTest *> UnitTest::tests;
@@ -21,7 +24,8 @@ vector<UnitTest *> UnitTest::tests;
/// Run all the tests unless a non-empty set of names is passed in.
/// In which case, only the named tests in the set are run.
/// \param testNames is the set of names
-void UnitTest::run(set<string> &testNames)
+/// \return number of failed tests
+int UnitTest::run(set<string> &testNames)
{
int total = 0;
@@ -42,6 +46,7 @@ void UnitTest::run(set<string> &testNames)
}
std::cerr << "==============================" << std::endl;
std::cerr << passed << "/" << total << " tests passed." << std::endl;
+ return total - passed;
}
/// Create list of the absolute path of all tests to be run
@@ -85,7 +90,7 @@ int main(int argc, char **argv) {
set<string> dataTestNames;
string dirname("../datatests");
string sleighdirname("../../../../../../..");
- if (argc > 0) {
+ while (argc > 0) {
string command(argv[0]);
if (command == "-path") {
dirname = argv[1];
@@ -109,30 +114,47 @@ int main(int argc, char **argv) {
argv += 1;
argc -= 1;
}
- }
- if (argc > 0) {
- string command(argv[0]);
- if (command == "unittests") {
+ else if (command == "unittests") {
runUnitTests = true;
runDataTests = false; // Run only unit tests
unitTestNames.insert(argv + 1,argv + argc);
+ break;
}
else if (command == "datatests") {
runUnitTests = false; // Run only data-tests
runDataTests = true;
dataTestNames.insert(argv + 1,argv + argc);
+ break;
}
else {
- cout << "USAGE: ghidra_test [-path <datatestdir>] [[unittests|datatests] [testname1 testname2 ...]]" << endl;
+ cout << "USAGE: ghidra_test [-usesleighenv] [-sleighpath <sleighdir>] [-path <datatestdir>] [[unittests|datatests] [testname1 testname2 ...]]" << endl;
+ return -1;
}
}
startDecompilerLibrary(sleighdirname.c_str());
- if (runUnitTests)
- UnitTest::run(unitTestNames);
+
+ // Keep track of failed tests as return code to indicate failures, clamped at
+ // max 255 value
+ int failedTests = 0;
+ if (runUnitTests) {
+ int errors = UnitTest::run(unitTestNames);
+ // Clamp at 255 max return code
+ failedTests = std::min(
+ failedTests +
+ (errors < 0 ? 255 : std::min(errors, 255)),
+ 255);
+ }
if (runDataTests) {
vector<string> testFiles;
gatherDataTests(dirname,dataTestNames,testFiles);
cout << endl << endl;
- FunctionTestCollection::runTestFiles(testFiles,cout);
+ int errors = FunctionTestCollection::runTestFiles(testFiles,cout);
+ // Clamp at 255 max return code
+ failedTests = std::min(
+ failedTests +
+ (errors < 0 ? 255 : std::min(errors, 255)),
+ 255);
}
+
+ return failedTests;
}
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/test.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/test.hh
index 8b762c5b1..a138f511d 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/test.hh
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/test.hh
@@ -54,7 +54,7 @@ struct UnitTest {
tests.push_back(this);
}
- static void run(std::set<std::string> &testNames); ///< Run all the instantiated tests
+ static int run(std::set<std::string> &testNames); ///< Run all the instantiated tests
};
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/testfunction.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/testfunction.cc
index 66f8d3fa2..c136a964b 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/testfunction.cc
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/testfunction.cc
@@ -304,7 +304,7 @@ void FunctionTestCollection::runTests(list<string> &lateStream)
/// Run through all XML files in the given list, processing each in turn.
/// \param testFiles is the given list of test files
/// \param s is the output stream to print results to
-void FunctionTestCollection::runTestFiles(const vector<string> &testFiles,ostream &s)
+int FunctionTestCollection::runTestFiles(const vector<string> &testFiles,ostream &s)
{
int4 totalTestsApplied = 0;
@@ -344,4 +344,5 @@ void FunctionTestCollection::runTestFiles(const vector<string> &testFiles,ostrea
if (iter == failures.end()) break;
}
}
+ return totalTestsApplied - totalTestsSucceeded;
}
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/testfunction.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/testfunction.hh
index 52125b401..46abd6bce 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/testfunction.hh
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/testfunction.hh
@@ -91,7 +91,7 @@ class FunctionTestCollection {
void restoreXml(DocumentStorage &store,const Element *el); ///< Load tests from a \<decompilertest> tag.
void restoreXmlOldForm(DocumentStorage &store,const Element *el); ///< Load tests from \<binaryimage> tag.
void runTests(list<string> &lateStream); ///< Run the script and perform the tests
- static void runTestFiles(const vector<string> &testFiles,ostream &s); ///< Run tests for each listed file
+ static int runTestFiles(const vector<string> &testFiles,ostream &s); ///< Run tests for each listed file
};
#endif
--
2.35.1
+3 -2
View File
@@ -5,8 +5,6 @@ set(spec_file_list
"${ghidrasource_SOURCE_DIR}/Ghidra/Processors/68000/data/languages/68030.slaspec"
"${ghidrasource_SOURCE_DIR}/Ghidra/Processors/68000/data/languages/68040.slaspec"
"${ghidrasource_SOURCE_DIR}/Ghidra/Processors/68000/data/languages/coldfire.slaspec"
"${ghidrasource_SOURCE_DIR}/Ghidra/Processors/6805/data/languages/6805.slaspec"
"${ghidrasource_SOURCE_DIR}/Ghidra/Processors/6805/data/languages/6809.slaspec"
"${ghidrasource_SOURCE_DIR}/Ghidra/Processors/8048/data/languages/8048.slaspec"
"${ghidrasource_SOURCE_DIR}/Ghidra/Processors/8051/data/languages/80251.slaspec"
"${ghidrasource_SOURCE_DIR}/Ghidra/Processors/8051/data/languages/80390.slaspec"
@@ -57,6 +55,9 @@ set(spec_file_list
"${ghidrasource_SOURCE_DIR}/Ghidra/Processors/HCS12/data/languages/HCS12.slaspec"
"${ghidrasource_SOURCE_DIR}/Ghidra/Processors/JVM/data/languages/JVM.slaspec"
"${ghidrasource_SOURCE_DIR}/Ghidra/Processors/M8C/data/languages/m8c.slaspec"
"${ghidrasource_SOURCE_DIR}/Ghidra/Processors/MC6800/data/languages/6805.slaspec"
"${ghidrasource_SOURCE_DIR}/Ghidra/Processors/MC6800/data/languages/6809.slaspec"
"${ghidrasource_SOURCE_DIR}/Ghidra/Processors/MC6800/data/languages/H6309.slaspec"
"${ghidrasource_SOURCE_DIR}/Ghidra/Processors/MCS96/data/languages/MCS96.slaspec"
"${ghidrasource_SOURCE_DIR}/Ghidra/Processors/MIPS/data/languages/mips32R6be.slaspec"
"${ghidrasource_SOURCE_DIR}/Ghidra/Processors/MIPS/data/languages/mips32R6le.slaspec"
+3 -2
View File
@@ -5,8 +5,6 @@ set(spec_file_list
"${ghidrasource_SOURCE_DIR}/Ghidra/Processors/68000/data/languages/68030.slaspec"
"${ghidrasource_SOURCE_DIR}/Ghidra/Processors/68000/data/languages/68040.slaspec"
"${ghidrasource_SOURCE_DIR}/Ghidra/Processors/68000/data/languages/coldfire.slaspec"
"${ghidrasource_SOURCE_DIR}/Ghidra/Processors/6805/data/languages/6805.slaspec"
"${ghidrasource_SOURCE_DIR}/Ghidra/Processors/6805/data/languages/6809.slaspec"
"${ghidrasource_SOURCE_DIR}/Ghidra/Processors/8048/data/languages/8048.slaspec"
"${ghidrasource_SOURCE_DIR}/Ghidra/Processors/8051/data/languages/80251.slaspec"
"${ghidrasource_SOURCE_DIR}/Ghidra/Processors/8051/data/languages/80390.slaspec"
@@ -57,6 +55,9 @@ set(spec_file_list
"${ghidrasource_SOURCE_DIR}/Ghidra/Processors/HCS12/data/languages/HCS12.slaspec"
"${ghidrasource_SOURCE_DIR}/Ghidra/Processors/JVM/data/languages/JVM.slaspec"
"${ghidrasource_SOURCE_DIR}/Ghidra/Processors/M8C/data/languages/m8c.slaspec"
"${ghidrasource_SOURCE_DIR}/Ghidra/Processors/MC6800/data/languages/6805.slaspec"
"${ghidrasource_SOURCE_DIR}/Ghidra/Processors/MC6800/data/languages/6809.slaspec"
"${ghidrasource_SOURCE_DIR}/Ghidra/Processors/MC6800/data/languages/H6309.slaspec"
"${ghidrasource_SOURCE_DIR}/Ghidra/Processors/MCS96/data/languages/MCS96.slaspec"
"${ghidrasource_SOURCE_DIR}/Ghidra/Processors/MIPS/data/languages/mips32R6be.slaspec"
"${ghidrasource_SOURCE_DIR}/Ghidra/Processors/MIPS/data/languages/mips32R6le.slaspec"
+12 -8
View File
@@ -10,12 +10,13 @@ set_property(CACHE sleigh_GHIDRA_RELEASE_TYPE PROPERTY STRINGS "stable" "HEAD")
# **** Setup pinned git info ****
# Ghidra pinned stable version commit
set(ghidra_version "10.1.2")
set(ghidra_git_tag "63bb30ac8bee0e3ff34c9812d751edcfdc70dbe4")
set(ghidra_version "10.1.3")
set(ghidra_git_tag "Ghidra_10.1.3_build")
set(ghidra_shallow TRUE)
# pinned stable patches list
set(ghidra_patches
PATCH_COMMAND git am --ignore-space-change --ignore-whitespace --no-gpg-sign
"${CMAKE_CURRENT_SOURCE_DIR}/patches/stable/0001-Fix-arg-parsing-in-sleigh-C-test-runner.patch"
"${CMAKE_CURRENT_SOURCE_DIR}/patches/stable/0001-Small-improvements-to-C-decompiler-testing-from-CLI.patch"
)
# Ghidra pinned commits used for pinning last known working HEAD commit
@@ -24,17 +25,19 @@ if("${sleigh_GHIDRA_RELEASE_TYPE}" STREQUAL HEAD)
# TODO: CMake only likes numeric characters in the version string....
set(ghidra_head_version "10.2")
set(ghidra_version "${ghidra_head_version}")
set(ghidra_head_git_tag "3eb03b1608b24aaae1cd1d5c86a5df36270ac54d")
set(ghidra_head_git_tag "9c04807c8cbf3516ea4ff8c4321bc18d38f27661")
set(ghidra_git_tag "${ghidra_head_git_tag}")
set(ghidra_shallow FALSE)
set(ghidra_patches
PATCH_COMMAND git am --ignore-space-change --ignore-whitespace --no-gpg-sign
"${CMAKE_CURRENT_SOURCE_DIR}/patches/stable/0001-Fix-arg-parsing-in-sleigh-C-test-runner.patch"
"${CMAKE_CURRENT_SOURCE_DIR}/patches/HEAD/0001-Small-improvements-to-C-decompiler-testing-from-CLI.patch"
)
string(SUBSTRING "${ghidra_git_tag}" 0 7 ghidra_short_commit)
else()
set(ghidra_short_commit "${ghidra_git_tag}")
endif()
string(SUBSTRING "${ghidra_git_tag}" 0 7 ghidra_short_commit)
message(STATUS "Using Ghidra version ${ghidra_version} at commit ${ghidra_short_commit}")
message(STATUS "Using Ghidra version ${ghidra_version} at git ref ${ghidra_short_commit}")
include(FetchContent)
@@ -46,6 +49,7 @@ FetchContent_Declare(GhidraSource
GIT_REPOSITORY https://github.com/NationalSecurityAgency/ghidra
GIT_TAG ${ghidra_git_tag}
GIT_PROGRESS TRUE
GIT_SHALLOW ${ghidra_shallow}
${ghidra_patches}
)
FetchContent_MakeAvailable(GhidraSource)
+12 -8
View File
@@ -32,21 +32,25 @@ configure_file(
@ONLY
)
set(sleigh_support_source_list
add_library(support
Support.cpp
${POST_CONFIGURE_FILE}
"${POST_CONFIGURE_FILE}"
"${CMAKE_CURRENT_BINARY_DIR}/GhidraVersion.cpp"
)
add_library(support
${sleigh_support_source_list}
)
# Need to explicitly add this dependency because BYPRODUCTS doesn't work under
# CMake 3.16 with GNU Makefiles
add_dependencies(support check_git)
add_library(sleigh::support ALIAS support)
target_link_libraries(support PUBLIC
sleigh::sleigh_settings
target_compile_features(support PUBLIC
cxx_std_17
)
set_target_properties(support PROPERTIES
INTERFACE_POSITION_INDEPENDENT_CODE ON
)
target_include_directories(support PRIVATE
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>"
"$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/support>"
+1
View File
@@ -18,4 +18,5 @@ add_executable(sleigh_test
target_link_libraries(sleigh_test PRIVATE
sleigh::sla
sleigh::decomp
sleigh::support
)