From 4f1d35c651da45178f887f5342513c8f0510593b Mon Sep 17 00:00:00 2001
From: Alexander Schwinn <al.schwinn@gsi.de>
Date: Mon, 4 Mar 2024 11:29:44 +0100
Subject: [PATCH] Add startManually file and Timing.xml file to git

---
 test/AllTypesFESA_DU/.gitignore               |   2 -
 .../startManually_AllTypesFESA_DU_M.sh        | 143 ++++++++++++++++++
 .../src/test/vmla016/vmla016Timing.xml        |  13 ++
 3 files changed, 156 insertions(+), 2 deletions(-)
 create mode 100755 test/AllTypesFESA_DU/src/test/vmla016/startManually_AllTypesFESA_DU_M.sh
 create mode 100644 test/AllTypesFESA_DU/src/test/vmla016/vmla016Timing.xml

diff --git a/test/AllTypesFESA_DU/.gitignore b/test/AllTypesFESA_DU/.gitignore
index e06478b..11496ee 100644
--- a/test/AllTypesFESA_DU/.gitignore
+++ b/test/AllTypesFESA_DU/.gitignore
@@ -8,8 +8,6 @@ bin/
 build/
 generated/
 precompiled/
-src/test/*/*
-!src/test/*/*.instance
 !src/test/*/README
 *.backup
 generated-silecs
diff --git a/test/AllTypesFESA_DU/src/test/vmla016/startManually_AllTypesFESA_DU_M.sh b/test/AllTypesFESA_DU/src/test/vmla016/startManually_AllTypesFESA_DU_M.sh
new file mode 100755
index 0000000..d46869b
--- /dev/null
+++ b/test/AllTypesFESA_DU/src/test/vmla016/startManually_AllTypesFESA_DU_M.sh
@@ -0,0 +1,143 @@
+#!/bin/sh
+set -u
+set -e
+
+# Automatically generated start script for FESA3 deploy-unit for manual testing and debugging only
+# Please note that this script will be overwritten upon recreation.
+
+print_help()
+{ 
+    echo -e "	Supported Arguments:"
+    echo -e "		-h	Show this help"
+    echo -e "		-g	launch the deploy-unit with GDB for debugging"
+    echo -e "		-r	launch the deploy-unit for remote debugging"
+    echo -e "		-c	launch as client in order to listen to an open remote debugging session ( script started with '-r' on FEC )"
+    echo -e "		-f	pass a list of arguments to the deployment unit (use '-f -h' to see all possibilities"
+    exit 1
+}
+
+CPU=x86_64                          # CPU architecture
+FESA_VERSION=7.5.0
+DU_NAME=AllTypesFESA_DU
+EXEC_APPENDIX=_M         # used in order to differ between mixed / rt / server executables
+GDB="false"                         # debugging via GDB
+REMOTE="false"                      # remote debugging
+REMOTE_CLIENT="false"                      # remote debugging client
+ARG=""                              # optional arguments for the deploy-unit
+
+SCRIPT=$(readlink -f "$0")
+SCRIPTPATH=$(dirname "$SCRIPT")     # path where this script is located in
+
+# TODO: https://samindaw.wordpress.com/2009/02/25/how-to-findout-what-ports-are-free-using-a-linux-shell-script/
+REMOTE_DEBUG_PORT=46697
+
+while getopts ":f:grhc" opt; do
+  case $opt in
+  h)
+    print_help
+    ;;
+  \?)
+    echo "Invalid option: -$OPTARG" >&2 
+    print_help
+    ;;
+  :)
+    echo "Option -$OPTARG requires an argument." >&2 
+    print_help
+    ;;
+  g)
+    GDB="true"
+    ;;
+  r)
+    REMOTE="true"
+    ;;
+  f)
+    ARG=$OPTARG
+    ;;
+  c)
+    REMOTE_CLIENT="true"
+    ;;
+  esac
+done
+
+# The default configuration
+# works for starting the binary from a FEC (scu, scuxl, sddsc ) /opt/fesa/nfs/local/*
+# works for starting the binary from */common/export/*
+CONFIG_PATH=${SCRIPTPATH}
+BINARY=${SCRIPTPATH}/${DU_NAME}
+INSTANCE=${SCRIPTPATH}/${DU_NAME}.instance
+FESA_CFG=${SCRIPTPATH}/fesa.cfg
+
+# overwrite variables in case of starting the binary from the home folder
+if [[ ${SCRIPTPATH} == */home/* ]]; then
+    if [ -d "${HOME}/tmp/opt/fesa/fesa-fwk/${FESA_VERSION}/resources" ]; then
+        CONFIG_PATH=${HOME}/tmp/opt/fesa/fesa-fwk/${FESA_VERSION}/resources
+    else
+        CONFIG_PATH=/common/export/fesa/global/etc/fesa/${FESA_VERSION}
+    fi
+    BINARY=../../../build/bin/${CPU}/${DU_NAME}${EXEC_APPENDIX}
+    INSTANCE=${SCRIPTPATH}/DeviceData_${DU_NAME}.instance
+    FESA_CFG=${CONFIG_PATH}/fesa.aslCluster.cfg
+fi
+
+# Special case: If we start a delivered binary on asl/vml, we dont use the delivered fesa.cfg, but the global one
+# That's because the delivered fesa.cfg only works if the binary is started with root privileges
+if [[ ${SCRIPTPATH} == */common/export/* ]]; then
+    FESA_CFG=/common/export/fesa/global/etc/fesa/${FESA_VERSION}/fesa.aslCluster.cfg
+fi
+
+LOG_CFG=${CONFIG_PATH}/log.cfg
+CMW_CFG=${CONFIG_PATH}/cmw.cfg
+MSG_CFG=${CONFIG_PATH}/messages.cfg
+MSG_GSI_CFG=${CONFIG_PATH}/messagesLab.cfg
+
+# SAFTlib library path for asl/vml
+export LD_LIBRARY_PATH=/common/export/timing-rte/tg-fallout-v6.2.x-rocky9/x86_64/lib/:${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}
+
+# default CMW directory server, environment variable needs to be adjusted for test/production
+export CMW_DIRECTORY_CLIENT_SERVERLIST=cmwint00a.acc.gsi.de:5021
+
+# check if a daemon already runs the binary
+PROCESS_NUM=$(ps a | grep du/${DU_NAME}/${DU_NAME} | grep du/${DU_NAME}/${DU_NAME}.instance | grep -v "grep" | wc -l)
+if [ $PROCESS_NUM -gt 0 ]; then
+    echo "Error: The FESA binary du/${DU_NAME}/${DU_NAME} using the instance file: du/${DU_NAME}/${DU_NAME}.instance is already running as a daemon service"
+    exit 1
+fi
+
+# check if the binary already was launched manually
+PROCESS_NUM=$(ps a | grep ${BINARY} | grep ${INSTANCE} | grep -v "grep" | wc -l)
+if [ $PROCESS_NUM -gt 0 ]; then
+    echo "Error: The FESA binary ${BINARY} using the instance file: ${INSTANCE} was already started"
+    exit 1
+fi
+
+ARGUMENTS="-cfgcmw ${CMW_CFG} -cfglog ${LOG_CFG} -cfgfesa ${FESA_CFG} -cfgmsg ${MSG_CFG} -cfgmsglab ${MSG_GSI_CFG} -instance ${INSTANCE}"
+echo -e "
+application arguments:"
+echo -e "-cfgcmw ${CMW_CFG}
+-cfglog ${LOG_CFG}
+-cfgfesa ${FESA_CFG}
+-cfgmsg ${MSG_CFG}
+-cfgmsglab ${MSG_GSI_CFG}
+-instance ${INSTANCE}
+${ARG}"
+
+if [ "${GDB}" == "true" ]; then
+    echo -e "Launching FESA software with:"
+    echo -e "gdb -ex "break +2" -ex "run" --args ${BINARY} ${ARGUMENTS} ${ARG}"
+    echo "- break at first line in main"
+    echo "- run gdb with binary + arguments"
+    gdb -ex "break +2" -ex "run" --args ${BINARY} ${ARGUMENTS} ${ARG}
+elif [ "${REMOTE}" == "true" ]; then
+    echo -e "Launching FESA software as GDB server:"
+    echo -e "gdbserver localhost:${REMOTE_DEBUG_PORT} ${BINARY} ${ARGUMENTS} ${ARG}"
+    gdbserver localhost:${REMOTE_DEBUG_PORT} ${BINARY} ${ARGUMENTS} ${ARG}
+elif [ "${REMOTE_CLIENT}" == "true" ]; then
+    FEC_NAME=${PWD##*/}
+    echo -e "Launching FESA software as remote client for GDB:"
+    echo -e "gdb -ex "target remote ${FEC_NAME}:${REMOTE_DEBUG_PORT}" -s ${BINARY}"
+    gdb -ex "target remote ${FEC_NAME}:${REMOTE_DEBUG_PORT}" -s ${BINARY}
+else
+    echo -e "Launching FESA software with:"
+    echo -e "${BINARY} ${ARGUMENTS} ${ARG}"
+    exec ${BINARY} ${ARGUMENTS} ${ARG}
+fi
diff --git a/test/AllTypesFESA_DU/src/test/vmla016/vmla016Timing.xml b/test/AllTypesFESA_DU/src/test/vmla016/vmla016Timing.xml
new file mode 100644
index 0000000..346bca3
--- /dev/null
+++ b/test/AllTypesFESA_DU/src/test/vmla016/vmla016Timing.xml
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?><fec name="vmla016">
+<local-timing>
+        <!-- example:
+<complex name="MY_COMPLEX_1">
+<machine name="MY_MACHINE_1">
+<zone name="MY_ZONE_1" code="1234"/>
+<zone name="MY_ZONE_2" code="5678"/>
+</machine>
+</complex>
+<event name="MY_TIMING_EVENT_1" code="4711"/>
+<event name="MY_TIMING_EVENT_2" code="4712"/>-->
+    </local-timing>
+</fec>
-- 
GitLab