From d5a79202e8865a4a1f1b56b80b5e9313b5491602 Mon Sep 17 00:00:00 2001 From: Ionut Muthi Date: Wed, 19 Jun 2024 09:55:02 +0300 Subject: [PATCH] ci: automated tests first test Signed-off-by: Ionut Muthi --- .../test/dataLoggerAtuomatedTest.sh | 35 +++++++ .../test/dataLoggerAutomatedTest.js | 91 +++++++++++++++++++ plugins/datalogger/test/emuXml/pluto.xml | 4 + tests/CMakeLists.txt | 19 ++++ .../scopyDeviceConnectionTest.js | 13 +++ .../scopyDeviceConnectionTest.sh | 22 +++++ tests/emuXml/pluto.xml | 4 + 7 files changed, 188 insertions(+) create mode 100755 plugins/datalogger/test/dataLoggerAtuomatedTest.sh create mode 100644 plugins/datalogger/test/dataLoggerAutomatedTest.js create mode 100644 plugins/datalogger/test/emuXml/pluto.xml create mode 100644 tests/automatedJSTests/scopyDeviceConnectionTest.js create mode 100644 tests/automatedJSTests/scopyDeviceConnectionTest.sh create mode 100644 tests/emuXml/pluto.xml diff --git a/plugins/datalogger/test/dataLoggerAtuomatedTest.sh b/plugins/datalogger/test/dataLoggerAtuomatedTest.sh new file mode 100755 index 0000000000..19329df1d3 --- /dev/null +++ b/plugins/datalogger/test/dataLoggerAtuomatedTest.sh @@ -0,0 +1,35 @@ +#! /bin/bash + +# run all the tests in this file as CTest ?? in CMAKE + +# get scopy buil path from CMakeCache.txt +scopyBuildDir=$(grep 'SCOPY_BUILD_PATH' ../CMakeCache.txt | awk -F= '{print $2}') +scopySourceDir=$(grep 'SCOPY_SOURCE_PATH' ../CMakeCache.txt | awk -F= '{print $2}') + +isEmuRunning=TRUE + +testScript=$(find $scopySourceDir -name "dataLoggerAutomatedTest.js"); +if [ ! -z $testScript ]; then + + #check if emu is running + if ! pgrep -x "iio-emu" > /dev/null + then + # if no emu running start emu for datalogger + isEmuRunning=FALSE + emuXmlPath=$scopySourceDir/plugins/datalogger/test/emuXml + cd $emuXmlPath + iio-emu generic *.xml & + fi + + cd $scopyBuildDir + # run scopy with the wanted script + QT_QPA_PLATFORM=offscreen ./scopy -s "$testScript" + + # kill emu process if started by this test + if [ "$isEmuRunning" = FALSE ]; then + #stop emu + killall -9 iio-emu + fi +fi + + diff --git a/plugins/datalogger/test/dataLoggerAutomatedTest.js b/plugins/datalogger/test/dataLoggerAutomatedTest.js new file mode 100644 index 0000000000..f8d58f077c --- /dev/null +++ b/plugins/datalogger/test/dataLoggerAutomatedTest.js @@ -0,0 +1,91 @@ + +/* log data test */ +function logData(tool, filePath, selectedMonitors) { + datalogger.enableMonitorOfTool(tool, selectedMonitors[0]) + datalogger.enableMonitorOfTool(tool, selectedMonitors[1]) + datalogger.clearData() + msleep(500) + datalogger.setRunning(true) + msleep(1000) + datalogger.logAtPathForTool(tool, filePath) + datalogger.continuousLogAtPathForTool(tool, filePath) + msleep(5000) + datalogger.disableMonitorOfTool(tool, selectedMonitors[0]) + datalogger.disableMonitorOfTool(tool, selectedMonitors[1]) + datalogger.setRunning(false) + datalogger.stopContinuousLogForTool(tool) + + printToConsole("Data logged for tool : " + tool + " at :" + filePath) +} + +/* load data test */ +function loadData(tool, filePath, selectedMonitors) { + + datalogger.importDataFromPathForTool(tool, filePath) + msleep(500) + datalogger.enableMonitorOfTool(tool, "Import: test.csv:" + selectedMonitors[0]) + datalogger.enableMonitorOfTool(tool, "Import: test.csv:" + selectedMonitors[1]) + + printToConsole("Data loaded for tool : " + tool + " from :" + filePath) +} + +function createTool(deviceID){ + var newTool = datalogger.createTool() + if (newTool !== "") { + scopy.switchTool(deviceID, newTool) + printToConsole("New tool created: " + newTool) + } else { + printToConsole("ERROR: Tool creation failed") + exit(1) + } + return "DataLogger 1" +} + +function getMonitors(tool){ + var monitors = datalogger.showAvailableMonitors() + printToConsole("Monitors list: " + monitors) + var monitorList = monitors.split(/\n/) + var voltage0Monitor = monitorList[2] + printToConsole("Monitor1 : " + voltage0Monitor) + var voltage1Monitor = monitorList[3] + printToConsole("Monitor2 : " + voltage1Monitor) + var selectedMonitors = [] + selectedMonitors[0] = voltage0Monitor + selectedMonitors[1] = voltage1Monitor + + return selectedMonitors +} + +/* main function */ +function main(){ + //TODO REPLACE WITH VAR + const filePath = "/home/ubuntu/Documents/git/scopy/dev/plugins/datalogger/test/automatedTests" + "/test.csv" + + printToConsole("FILE IS " + filePath) + //CONNECT TO EMU + var deviceID = scopy.addDevice("", "ip:127.0.0.0") + scopy.connectDevice(deviceID) + + //TEST DATA LOGGER + printToConsole(datalogger.showAvailableMonitors()) + + //CREATE NEW TOOL + var tool = createTool(deviceID) + + printToConsole("FILE IS " + tool) + + if (tool !== "") { + //GET 2 CHANNELS OF THE TOOL + var selectedMonitors = getMonitors(tool) + printToConsole("Monitors : " + selectedMonitors) + //LOG DATA ON THE TOOL CHANNELS + logData(tool, filePath, selectedMonitors) + msleep(2000) + //LOAD DATA FOR THE TOOL CHANNELS + loadData(tool, filePath, selectedMonitors) + msleep(2000) + } + +} + +main() diff --git a/plugins/datalogger/test/emuXml/pluto.xml b/plugins/datalogger/test/emuXml/pluto.xml new file mode 100644 index 0000000000..fa4921ff31 --- /dev/null +++ b/plugins/datalogger/test/emuXml/pluto.xml @@ -0,0 +1,4 @@ +]> \ No newline at end of file diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index b5caf61376..de6e8531c8 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1 +1,20 @@ cmake_minimum_required(VERSION 3.5) + +include(ScopyTest) + +# JS AUTOMATED TESTS + +# Set build path as CMAKE CACHE variable to use in tests +set(SCOPY_BUILD_PATH ${CMAKE_BINARY_DIR} CACHE STRING "SCOPY_BUILD_PATH" FORCE) +set(SCOPY_SOURCE_PATH ${CMAKE_SOURCE_DIR} CACHE STRING "SCOPY_SOURCE_PATH" FORCE) + + +#SCOPY BASE TESTS +add_test(NAME "DeviceConnectionJSTest" COMMAND bash ${CMAKE_CURRENT_SOURCE_DIR}/automatedJSTests/scopyDeviceConnectionTest.sh) + + +# PLUGIN SPECIFIC TESTS + +# DATALOGGER SPECIFIC TESTS +add_test(NAME "DataLoggerJSTest" COMMAND bash ${CMAKE_SOURCE_DIR}/plugins/datalogger/test/dataLoggerAtuomatedTest.sh) + diff --git a/tests/automatedJSTests/scopyDeviceConnectionTest.js b/tests/automatedJSTests/scopyDeviceConnectionTest.js new file mode 100644 index 0000000000..519f630099 --- /dev/null +++ b/tests/automatedJSTests/scopyDeviceConnectionTest.js @@ -0,0 +1,13 @@ +/* main function */ +function main(){ + //CONNECT TO EMU + var deviceID = scopy.addDevice("", "ip:127.0.0.0") + //CONNECT TO DEVICE + scopy.connectDevice(deviceID) + //DISCONNECT FROM DEVICE + scopy.disconnectDevice(deviceID) + + exit(0) +} + +main() diff --git a/tests/automatedJSTests/scopyDeviceConnectionTest.sh b/tests/automatedJSTests/scopyDeviceConnectionTest.sh new file mode 100644 index 0000000000..847c5f3f96 --- /dev/null +++ b/tests/automatedJSTests/scopyDeviceConnectionTest.sh @@ -0,0 +1,22 @@ +#! /bin/bash + +# get scopy buil path from CMakeCache.txt +scopyBuildDir=$(grep 'SCOPY_BUILD_PATH' ../CMakeCache.txt | awk -F= '{print $2}') +scopySourceDir=$(grep 'SCOPY_SOURCE_PATH' ../CMakeCache.txt | awk -F= '{print $2}') + +testScript=$(find $scopySourceDir -name "scopyDeviceConnectionTest.js"); + +if [ ! -z $testScript ]; then + # start emu + emuXmlPath="$scopySourceDir/tests/emuXml"; + cd $emuXmlPath + iio-emu generic *.xml & + + # go to where scopy is build and run it with the scipt + cd $scopyBuildDir + QT_QPA_PLATFORM=offscreen ./scopy -s "$testScript" + + #stop emu + killall -9 iio-emu +fi + diff --git a/tests/emuXml/pluto.xml b/tests/emuXml/pluto.xml new file mode 100644 index 0000000000..fa4921ff31 --- /dev/null +++ b/tests/emuXml/pluto.xml @@ -0,0 +1,4 @@ +]> \ No newline at end of file