From 419e9a01283127641806dafa42f7c3b09fa70857 Mon Sep 17 00:00:00 2001
From: Dominik Loidolt <dominik.loidolt@univie.ac.at>
Date: Thu, 4 Apr 2024 19:48:16 +0200
Subject: [PATCH] Add wrapper to execute programmes on our LEON setup

---
 sparc-efl-gcc.txt            |  1 +
 test/tools/flash_run_leon.sh | 24 ++++++++++++++++++++++++
 2 files changed, 25 insertions(+)
 create mode 100755 test/tools/flash_run_leon.sh

diff --git a/sparc-efl-gcc.txt b/sparc-efl-gcc.txt
index 817f115..c4f1378 100644
--- a/sparc-efl-gcc.txt
+++ b/sparc-efl-gcc.txt
@@ -5,6 +5,7 @@ objc = 'sparc-elf-gcc'
 ar = 'sparc-elf-ar'
 strip = 'sparc-elf-strip'
 ld = 'sparc-elf-ld'
+exe_wrapper = '@GLOBAL_SOURCE_ROOT@' / 'test' / 'tools' / 'flash_run_leon.sh'
 
 # pkgconfig = ['false']
 # cmake = ['false']
diff --git a/test/tools/flash_run_leon.sh b/test/tools/flash_run_leon.sh
new file mode 100755
index 0000000..a6a3224
--- /dev/null
+++ b/test/tools/flash_run_leon.sh
@@ -0,0 +1,24 @@
+#!/bin/bash
+set -euo pipefail
+IFS=$'\n\t'
+
+# This script is custom-tailored for our test setup and may not run everywhere.
+
+bin_path=${1:-}
+if [[ -z "$bin_path" ]]; then
+    echo "usage: $0 <binary file>"
+    exit 1
+fi
+
+rm -f grmon_output
+script -c "grmon -freq 80 -ftdi -u -jtagcable 1 -e 'reset; wash; load $bin_path; run; reg i0; exit'" grmon_output
+
+
+if grep -q "Program exited normally" grmon_output; then
+    if grep -q "i0 =" grmon_output; then
+        ret=$(grep  'i0 =' grmon_output | tr -s ' ' | cut -d ' ' -f 4)
+        exit $ret
+    fi
+fi
+
+exit 1
-- 
GitLab