From 86c10fa9ec47163be0b5a27181b7681742102897 Mon Sep 17 00:00:00 2001 From: Ionut Muthi Date: Wed, 10 Jul 2024 14:04:24 +0300 Subject: [PATCH] automatedTests: datalogger test Signed-off-by: Ionut Muthi --- .../datalogger/JS/dataLoggerAutomatedTest.js | 38 ++++++++++++ plugins/datalogger/JS/dataLoggerFunctions.js | 62 +++++++++++++++++++ tests/CMakeLists.txt | 9 +++ 3 files changed, 109 insertions(+) create mode 100644 plugins/datalogger/JS/dataLoggerAutomatedTest.js create mode 100644 plugins/datalogger/JS/dataLoggerFunctions.js diff --git a/plugins/datalogger/JS/dataLoggerAutomatedTest.js b/plugins/datalogger/JS/dataLoggerAutomatedTest.js new file mode 100644 index 0000000000..590ff50ca7 --- /dev/null +++ b/plugins/datalogger/JS/dataLoggerAutomatedTest.js @@ -0,0 +1,38 @@ +//This import paht is relative to where scopy is build +importFileContent("../JS/scpyDefaultJsFunctions.js") +importFileContent("../plugins/datalogger/JS/dataLoggerFunctions.js") + +function dataLogAndLoadTest(){ + //TODO REPLACE WITH VAR + const filePath = "../plugins/datalogger/JS/test.csv" + + printToConsole("FILE IS " + filePath) + + //CONNECT TO EMU + connect() + + msleep(1000) + //TEST DATA LOGGER + printToConsole(datalogger.showAvailableMonitors()) + + //CREATE NEW TOOL + msleep(1000) + var tool = "DataLogger 0" + + if (tool !== "") { + //GET 2 CHANNELS OF THE TOOL + scopy.switchTool(tool) + var selectedMonitors = getMonitors(tool) + printToConsole("Monitors : " + selectedMonitors) + //LOG DATA ON THE TOOL CHANNELS + logData(tool, filePath, selectedMonitors) + msleep(1000) + //LOAD DATA FOR THE TOOL CHANNELS + loadData(tool, filePath, selectedMonitors) + msleep(1000) + } + disconnect() +} + +dataLogAndLoadTest() + diff --git a/plugins/datalogger/JS/dataLoggerFunctions.js b/plugins/datalogger/JS/dataLoggerFunctions.js new file mode 100644 index 0000000000..7607d885c7 --- /dev/null +++ b/plugins/datalogger/JS/dataLoggerFunctions.js @@ -0,0 +1,62 @@ +/* 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 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 +} + +function createTool(deviceID){ + printToConsole("############################### HERE in file ") + 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 test(ceva){ + printToConsole("############################### HERE in file test " + ceva) +} + diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 835ae0ceb7..a36043e327 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -5,6 +5,15 @@ cmake_minimum_required(VERSION 3.5) # Set build path as CMAKE CACHE variable to use in tests set(SCOPY_BUILD_PATH ${CMAKE_BINARY_DIR} CACHE STRING "SCOPY_BUILD_PATH" FORCE) +# SCOPY GENERIC TESTS add_test(NAME "ScopyDefaultJSTests" COMMAND bash ${CMAKE_SOURCE_DIR}/JS/test.sh "${CMAKE_SOURCE_DIR}/resources/emuXml/" "${CMAKE_SOURCE_DIR}/JS/scopyDefaultTests.js" ) + +# PLUGIN SPECIFIC TESTS + +# DATALOGGER +add_test(NAME "DataloggerLogAndLoadJSTests" + COMMAND bash ${CMAKE_SOURCE_DIR}/JS/test.sh "${CMAKE_SOURCE_DIR}/resources/emuXml/" + "${CMAKE_SOURCE_DIR}/plugins/datalogger/JS/dataLoggerAutomatedTest.js" +)