Skip to content

Commit

Permalink
ci: automated tests first test
Browse files Browse the repository at this point in the history
Signed-off-by: Ionut Muthi <[email protected]>
  • Loading branch information
IonutMuthi committed Jun 19, 2024
1 parent e310a7d commit d5a7920
Show file tree
Hide file tree
Showing 7 changed files with 188 additions and 0 deletions.
35 changes: 35 additions & 0 deletions plugins/datalogger/test/dataLoggerAtuomatedTest.sh
Original file line number Diff line number Diff line change
@@ -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


91 changes: 91 additions & 0 deletions plugins/datalogger/test/dataLoggerAutomatedTest.js
Original file line number Diff line number Diff line change
@@ -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()
4 changes: 4 additions & 0 deletions plugins/datalogger/test/emuXml/pluto.xml

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)

13 changes: 13 additions & 0 deletions tests/automatedJSTests/scopyDeviceConnectionTest.js
Original file line number Diff line number Diff line change
@@ -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()
22 changes: 22 additions & 0 deletions tests/automatedJSTests/scopyDeviceConnectionTest.sh
Original file line number Diff line number Diff line change
@@ -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

4 changes: 4 additions & 0 deletions tests/emuXml/pluto.xml

Large diffs are not rendered by default.

0 comments on commit d5a7920

Please sign in to comment.