Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
xlauko committed Sep 6, 2024
1 parent 469e5a9 commit 20bcfbb
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 42 deletions.
20 changes: 11 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,14 @@ jobs:

- name: Test ${{ matrix.build-type }} with sanitizers set ${{ matrix.sanitizers }}
run: |
mkdir -p ./builds/ci/test/ghidra/Output/
touch ./builds/ci/test/ghidra/Output/output.json
sudo chmod -R 777 ./builds/ci/test/ghidra/Output
/usr/lib/llvm-18/bin/clang ./test/ghidra/test.c -o ./builds/ci/test/ghidra/Output/test.o
docker run --rm \
-v ${{ github.workspace }}/builds/ci/test/ghidra/Output:/mnt/output:rw \
trailofbits/patchestry-decompilation:latest \
/mnt/output/test.o test /mnt/output/output.json
cat ./builds/ci/test/ghidra/Output/output.json
lit ./builds/ci/test -v -DCI_OUTPUT_FOLDER=${{ github.workspace }}/builds/ci/test/ghidra/Output --filter=argc.c
# mkdir -p ./builds/ci/test/ghidra/Output/
# touch ./builds/ci/test/ghidra/Output/output.json
# sudo chmod -R 777 ./builds/ci/test/ghidra/Output
# /usr/lib/llvm-18/bin/clang ./test/ghidra/test.c -o ./builds/ci/test/ghidra/Output/test.o
# docker run --rm \
# -v ${{ github.workspace }}/builds/ci/test/ghidra/Output:/mnt/output:rw \
# trailofbits/patchestry-decompilation:latest \
# /mnt/output/test.o test /mnt/output/output.json
# cat ./builds/ci/test/ghidra/Output/output.json
64 changes: 32 additions & 32 deletions scripts/ghidra/decompile-headless.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ show_help() {
echo " -o, --output Path to the output file where results will be saved"
echo " -v, --verbose Enable verbose output"
echo " -t, --interactive Start Docker container in interactive mode"
echo " -c, --ci Run in CI mode"
echo
}

Expand All @@ -26,7 +25,6 @@ FUNCTION_NAME=""
OUTPUT_PATH=""
VERBOSE=false
INTERACTIVE=false
CI=""

while [[ $# -gt 0 ]]; do
case "$1" in
Expand Down Expand Up @@ -54,10 +52,6 @@ while [[ $# -gt 0 ]]; do
INTERACTIVE=true
shift
;;
-c|--ci)
CI="$2"
shift 2
;;
*)
echo "Unknown option: $1"
show_help
Expand Down Expand Up @@ -99,15 +93,10 @@ if [ "$VERBOSE" = true ]; then
fi

absolute_path() {
if [ $CI = true ]; then
FILE_NAME=$(basename "$1")
echo "$CI/builds/ci/test/ghidra/Output/$FILE_NAME"
if [[ "$1" = /* ]]; then
echo "$1"
else
if [[ "$1" = /* ]]; then
echo "$1"
else
echo "$(pwd)/$1"
fi
echo "$(pwd)/$1"
fi
}

Expand All @@ -124,28 +113,39 @@ if [ ! -e "$OUTPUT_PATH" ]; then
exit 1
fi

RUN="docker run --rm \
-v \"$INPUT_PATH:/input.o\" \
-v \"$OUTPUT_PATH:/output.json\" \
trailofbits/patchestry-decompilation:latest"
printenv

if file "$INPUT_PATH" | grep -q "Mach-O"; then
FUNCTION_NAME="_$FUNCTION_NAME"
if [ -n $CI_OUTPUT_FOLDER ]; then
echo "CI_OUTPUT_FOLDER is set to $CI_OUTPUT_FOLDER"
fi

if [ "$INTERACTIVE" = true ]; then
RUN=$(echo "$RUN" | sed 's/docker run --rm/docker run -it --rm --entrypoint \/bin\/bash/')
else
RUN="$RUN /input.o \"$FUNCTION_NAME\" /output.json"
if [ ! -e $CI_OUTPUT_FOLDER ]; then
echo "Error: CI_OUTPUT_FOLDER does not exist: $CI_OUTPUT_FOLDER"
exit 1
fi

if [ "$VERBOSE" = true ]; then
echo "Running Docker container with the following command:"
echo "$RUN"
fi
# RUN="docker run --rm \
# -v \"$INPUT_PATH:/input.o\" \
# -v \"$OUTPUT_PATH:/output.json\" \
# trailofbits/patchestry-decompilation:latest"

if [ "$VERBOSE" = true ]; then
echo "Starting Docker container..."
fi
# if file "$INPUT_PATH" | grep -q "Mach-O"; then
# FUNCTION_NAME="_$FUNCTION_NAME"
# fi

# if [ "$INTERACTIVE" = true ]; then
# RUN=$(echo "$RUN" | sed 's/docker run --rm/docker run -it --rm --entrypoint \/bin\/bash/')
# else
# RUN="$RUN /input.o \"$FUNCTION_NAME\" /output.json"
# fi

# if [ "$VERBOSE" = true ]; then
# echo "Running Docker container with the following command:"
# echo "$RUN"
# fi

# if [ "$VERBOSE" = true ]; then
# echo "Starting Docker container..."
# fi

eval "$RUN"
# eval "$RUN"
2 changes: 1 addition & 1 deletion test/ghidra/argc.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// UNSUPPORTED: system-windows
// RUN: %cc %s -g -o %t.o
// RUN: %decompile-headless --input %t.o --function argc --output %t
// RUN: %decompile-headless --input %t.o --function argc --output %t %ci_output_folder
// RUN: %file-check -vv %s --input-file %t
// CHECK: "name":"{{_?argc}}"

Expand Down
4 changes: 4 additions & 0 deletions test/lit.cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,7 @@

# Add PATH to substitutions
config.substitutions.append(('%PATH%', config.environment['PATH']))

ci_output_folder = config.params['CI_OUTPUT_FOLDER']
if ci_output_folder:
config.substitutions.append(('%ci_output_folder', f"--ci ci_output_folder"))

0 comments on commit 20bcfbb

Please sign in to comment.