Skip to content

Commit

Permalink
automatedTests: scopy default tests
Browse files Browse the repository at this point in the history
test for connect / disconnect
test for switch tool

Signed-off-by: Ionut Muthi <ionut.muthi@analog.com>
  • Loading branch information
IonutMuthi committed Jul 9, 2024
1 parent a4a681a commit 618f61b
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 13 deletions.
27 changes: 27 additions & 0 deletions JS/scopyDefaultTests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
export function connect(){
//CONNECT TO EMU
var deviceID = scopy.addDevice("", "ip:127.0.0.0")
//CONNECT TO DEVICE
scopy.connectDevice(deviceID)

}

export function disconnect(){
//DISCONNECT FROM DEVICE
scopy.disconnectDevice()
exit(0)
}

export function connectionTest(){
connect()
disconnect()
}

export function switchToolTest(){
connect()
scopy.switchTool("Time")
scopy.switchTool("DataLogger 0")
scopy.switchTool("Debugger")
disconnect()
}

29 changes: 29 additions & 0 deletions JS/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#! /bin/bash

# get scopy buil path from CMakeCache.txt
scopyBuildDir=$(grep 'SCOPY_BUILD_PATH' ../CMakeCache.txt | awk -F= '{print $2}')

isEmuRunning=TRUE

#if emu is not running start emu at provided path
if ! pgrep -x "iio-emu" > /dev/null; then
isEmuRunning=FALSE
if [ ! -z $1 ]; then
cd $1
iio-emu generic *.xml &
fi
fi
# run scopy functions of provided script
if [ ! -z $2 ]; then
cd $scopyBuildDir
./scopy --script=$2 --script-functions=$3
fi


# if emu was started by this script stop emu
if [ "$isEmuRunning" = FALSE ]; then
#stop emu
killall -9 iio-emu
fi


18 changes: 5 additions & 13 deletions core/src/scopymainwindow_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,26 +172,18 @@ void ScopyMainWindow_API::runFunctionOfScript(QString scriptPath, QStringList sc
qInfo(CAT_SCOPY_API) << "Run Script with functions" ;
QJSValue module = ScopyJS::GetInstance()->engine()->importModule(scriptPath);

int ret = EXIT_SUCCESS;

foreach (QString function, scriptFunctions) {

QJSValue scriptFunction = module.property(function);
QJSValue result = scriptFunction.call();
qInfo(CAT_SCOPY_API) <<"FUNCTION IS " << function << " RESTUL IS " << result.toString();

if(result.isError()) {
qWarning(CAT_SCOPY_API) << "Exception:" << result.toString();
ret = EXIT_FAILURE;
} else if(!result.isUndefined()) {
qWarning(CAT_SCOPY_API) << result.toString();
}
qInfo(CAT_SCOPY_API) <<"Running function: " << function ;
}


/* Exit application */
if(exitApp)
if(exitApp) {
int ret = EXIT_SUCCESS;
qApp->exit(ret);
}

}
void ScopyMainWindow_API::runScriptList(QStringList scriptPathList, bool exitApp)
{
Expand Down
12 changes: 12 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1 +1,13 @@
cmake_minimum_required(VERSION 3.5)

# 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 "ConnectionJSTest" COMMAND bash ${CMAKE_SOURCE_DIR}/JS/test.sh "${CMAKE_SOURCE_DIR}/resources/emuXml/" "${CMAKE_SOURCE_DIR}/JS/scopyDefaultTests.js" "connectionTest")
add_test(NAME "SwitchToolJSTest" COMMAND bash ${CMAKE_SOURCE_DIR}/JS/test.sh "${CMAKE_SOURCE_DIR}/resources/emuXml/" "${CMAKE_SOURCE_DIR}/JS/scopyDefaultTests.js" "switchToolTest")


0 comments on commit 618f61b

Please sign in to comment.