From 50e8c82a26ed4026ed1225369344ba408360061e Mon Sep 17 00:00:00 2001 From: Jason Hiser <jdhiser@gmail.com> Date: Tue, 31 Jan 2023 13:50:31 -0500 Subject: [PATCH] Update fix-calls to fix-all for go programs. Add go testing --- .gitlab-ci.yml | 1 + cicd_testing/go_tests.sh | 11 +++++ irdb-libs/ir_builders/fix_calls.cpp | 10 +++++ tests/go_test/.gitignore | 3 ++ tests/go_test/8q.go | 67 +++++++++++++++++++++++++++++ tests/go_test/panic.go | 29 +++++++++++++ tests/go_test/testit.sh | 40 +++++++++++++++++ 7 files changed, 161 insertions(+) create mode 100755 cicd_testing/go_tests.sh create mode 100644 tests/go_test/8q.go create mode 100644 tests/go_test/panic.go create mode 100755 tests/go_test/testit.sh diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 7e14a4be9..6955ca6b8 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -92,6 +92,7 @@ test-bins-arm64: - ./cicd_testing/eh-tests.sh - ./cicd_testing/builtin-xforms.sh - ./cicd_testing/elfdep.sh + - ./cicd_testing/go_tests.sh diff --git a/cicd_testing/go_tests.sh b/cicd_testing/go_tests.sh new file mode 100755 index 000000000..37566bf91 --- /dev/null +++ b/cicd_testing/go_tests.sh @@ -0,0 +1,11 @@ +#!/bin/bash +set -e +set -x + +cd /tmp/peasoup_test +export IDAROOT=$CICD_MODULE_WORK_DIR/idapro71 +export IDASDK=$CICD_MODULE_WORK_DIR/idapro71_sdk +source set_env_vars + +cd $PEASOUP_HOME/tests/go_test/ +./testit.sh diff --git a/irdb-libs/ir_builders/fix_calls.cpp b/irdb-libs/ir_builders/fix_calls.cpp index c566165a2..551ee9f43 100644 --- a/irdb-libs/ir_builders/fix_calls.cpp +++ b/irdb-libs/ir_builders/fix_calls.cpp @@ -960,6 +960,16 @@ class FixCalls_t : public TransformStep_t DatabaseID_t variant_id=BaseObj_t::NOT_IN_DATABASE; public: + FixCalls_t() + { + const auto exe_reader = new EXEIO::exeio; + assert(exe_reader); + exe_reader->load((char*)"a.ncexe"); + const auto has_pclntab = exe_reader->sections[".gopclntab"] != NULL; + if(has_pclntab) + fix_all=true; + } + int parseArgs(const vector<string> step_args) { diff --git a/tests/go_test/.gitignore b/tests/go_test/.gitignore index da2584ecd..d5f318345 100644 --- a/tests/go_test/.gitignore +++ b/tests/go_test/.gitignore @@ -1,2 +1,5 @@ hello +8q +panic +*.zipr peasoup_exe* diff --git a/tests/go_test/8q.go b/tests/go_test/8q.go new file mode 100644 index 000000000..94ad428c1 --- /dev/null +++ b/tests/go_test/8q.go @@ -0,0 +1,67 @@ +package main + +import ( + "fmt" + "math" +) + +type Point struct { + x int + y int +} + +var results = make([][]Point, 0) + +func main() { + Solve(8) + +} + +func Solve(n int) { + for col := 0; col < n; col++ { + start := Point{x: col, y: 0} + current := make([]Point, 0) + Recurse(start, current, n) + } + fmt.Print("Results:\n") + for _, result := range results { + fmt.Println(result) + } + fmt.Printf("There were %d results\n", len(results)) +} +func Recurse(point Point, current []Point, n int) { + if CanPlace(point, current) { + current = append(current, point) + if len(current) == n { + c := make([]Point, n) + for i, point := range current { + c[i] = point + } + results = append(results, c) + } else { + for col := 0; col < n; col++ { + for row := point.y; row < n; row++ { + nextStart := Point{x: col, y: row} + Recurse(nextStart, current, n) + + } + + } + } + } +} +func CanPlace(target Point, board []Point) bool { + for _, point := range board { + if CanAttack(point, target) { + return false + } + } + return true +} + +func CanAttack(a, b Point) bool { + //fmt.Print(a, b) + answer := a.x == b.x || a.y == b.y || math.Abs(float64(a.y-b.y)) == math.Abs(float64(a.x-b.x)) + //fmt.Print(answer) + return answer +} diff --git a/tests/go_test/panic.go b/tests/go_test/panic.go new file mode 100644 index 000000000..4c27a1c30 --- /dev/null +++ b/tests/go_test/panic.go @@ -0,0 +1,29 @@ +package main + +import "fmt" + +func main() { + f() + fmt.Println("Returned normally from f.") +} + +func f() { + defer func() { + if r := recover(); r != nil { + fmt.Println("Recovered in f", r) + } + }() + fmt.Println("Calling g.") + g(0) + fmt.Println("Returned normally from g.") +} + +func g(i int) { + if i > 3 { + fmt.Println("Panicking!") + panic(fmt.Sprintf("%v", i)) + } + defer fmt.Println("Defer in g", i) + fmt.Println("Printing in g", i) + g(i + 1) +} diff --git a/tests/go_test/testit.sh b/tests/go_test/testit.sh new file mode 100755 index 000000000..810f1bb91 --- /dev/null +++ b/tests/go_test/testit.sh @@ -0,0 +1,40 @@ +#!/bin/bash + +testone() +{ + local PUT=$1 + local OPTS=$2 + set -x + set -e + go build $PUT.go + + $PSZ $PUT ./$PUT.zipr $OPTS + diff <(./$PUT 2>&1 ) <(./$PUT.zipr 2>&1 ) + ./$PUT > /dev/null 2>&1 + local putRes=$? + ./$PUT.zipr > /dev/null 2>&1 + local putResZipr=$? + + if [[ $putRes != $putResZipr ]]; + then + echo failed! + exit 1 + fi + + rm -rf peasoup* $PUT.zipr $PUT.zipr +} + +main() +{ + for bench in panic hello 8q + do + for opts in "-c rida" "" + do + testone $bench "$opts" + done + done + exit 0 + +} + +main "$@" -- GitLab