From abe3bebcc029715b784d90bbf12615858cbab859 Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Thu, 23 Jun 2022 17:31:29 +0900 Subject: [PATCH] tests: unittest: Add unittest of pass-parser module PASS daemon requires the json configuration containing the device-dependent information. The described information of json configuration are used for PASS opeartion. Add unittest of pass-parser module for both valid and invalid case under 'device_list' property. Change-Id: I63b650dc34ddefe9873f28e0a9c46fff21e90936 Signed-off-by: Chanwoo Choi --- tests/unittest/CMakeLists.txt | 2 ++ tests/unittest/pass-unittests.cc | 26 ++++++++++++++++++ tests/unittest/scripts/invalid/pass.json | 45 ++++++++++++++++++++++++++++++++ tests/unittest/scripts/valid/pass.json | 45 ++++++++++++++++++++++++++++++++ 4 files changed, 118 insertions(+) create mode 100644 tests/unittest/scripts/invalid/pass.json create mode 100644 tests/unittest/scripts/valid/pass.json diff --git a/tests/unittest/CMakeLists.txt b/tests/unittest/CMakeLists.txt index 9d89951..a5ba5af 100644 --- a/tests/unittest/CMakeLists.txt +++ b/tests/unittest/CMakeLists.txt @@ -5,7 +5,9 @@ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -Wall -Werror") SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS} -Wall -Werror") SET(PASS_SRCS + ${CMAKE_SOURCE_DIR}/src/util/common.c ${CMAKE_SOURCE_DIR}/src/pass/pass-hal.c + ${CMAKE_SOURCE_DIR}/src/pass/pass-parser.c ) AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/ PASS_UNITTEST_SRCS) diff --git a/tests/unittest/pass-unittests.cc b/tests/unittest/pass-unittests.cc index 736ebde..207e64b 100644 --- a/tests/unittest/pass-unittests.cc +++ b/tests/unittest/pass-unittests.cc @@ -26,6 +26,7 @@ extern "C" { #include "pass.h" #include "pass-hal.h" +#include "pass-parser.h" } #include "hal-api-power-mock.hpp" @@ -490,6 +491,31 @@ TEST_F(PassHalTest, pass_hal_set_pmqos_data) { EXPECT_NE(ret, 0); } +/* Unittest of pass-parser module */ +class PassParserTest : public testing::Test { +public: + virtual void SetUp() {} + virtual void TearDown() {} +}; + +TEST(PassParserTest, pass_parser_get_resource_config_valid) { + struct pass pass; + const char path_json[] = "./scripts/valid/pass.json"; + + int ret = pass_parser_get_resource_config(&pass, path_json); + ASSERT_EQ(ret, 0); + + pass_parser_put_resource_config(&pass); +} + +TEST(PassParserTest, pass_parser_get_resource_config_invalid) { + struct pass pass; + const char path_json[] = "./scripts/invalid/pass.json"; + + int ret = pass_parser_get_resource_config(&pass, path_json); + EXPECT_NE(ret, 0); +} + int main(int argc, char *argv[]) { try { diff --git a/tests/unittest/scripts/invalid/pass.json b/tests/unittest/scripts/invalid/pass.json new file mode 100644 index 0000000..84df24a --- /dev/null +++ b/tests/unittest/scripts/invalid/pass.json @@ -0,0 +1,45 @@ +{ + "device_list" : + [ + { + //"device_type" : "cpu", + //"device_name" : "cpu0", + //"device_config_path" : "./scripts/valid/pass-cpu0.json", + "thermal_device_name" : "thermal_zone0", + "cpu,number_of_cpus" : 4, + "cpu,first_cpu" : 0 + }, { + //"device_type" : "cpu", + "device_name" : "cpu4", + "device_config_path" : "./scripts/valid/pass-cpu4.json", + "thermal_device_name" : "thermal_zone1", + "cpu,number_of_cpus" : 4, + "cpu,first_cpu" : 4 + }, { + "device_type" : "bus", + "device_name" : "devfreq0", + //"device_config_path" : "./scripts/valid/pass-bus.json", + "thermal_device_name" : null + }, { + "device_type" : "bus", + //"device_name" : "devfreq5", + "device_config_path" : "./scripts/valid/pass-bus1.json", + "thermal_device_name" : null + }, { + "device_type" : "gpu", + "device_name" : "devfreq10", + //"device_config_path" : "./scripts/vaild/pass-gpu.json", + "thermal_device_name" : "thermal_zone3" + }, { + "device_type" : "memory", + "device_name" : "memory", + //"device_config_path" : "./scripts/valid/pass-memory.json" + }, { + "device_type" : "battery", + //"device_name" : "battery", + "device_config_path" : "./scripts/valid/pass-battery.json", + "thermal_device_name" : "thermal_zone5", + "cooling_device_name" : null + } + ] +} diff --git a/tests/unittest/scripts/valid/pass.json b/tests/unittest/scripts/valid/pass.json new file mode 100644 index 0000000..d3eea11 --- /dev/null +++ b/tests/unittest/scripts/valid/pass.json @@ -0,0 +1,45 @@ +{ + "device_list" : + [ + { + "device_type" : "cpu", + "device_name" : "cpu0", + "device_config_path" : "./scripts/valid/pass-cpu0.json", + "thermal_device_name" : "thermal_zone0", + "cpu,number_of_cpus" : 4, + "cpu,first_cpu" : 0 + }, { + "device_type" : "cpu", + "device_name" : "cpu4", + "device_config_path" : "./scripts/valid/pass-cpu4.json", + "thermal_device_name" : "thermal_zone1", + "cpu,number_of_cpus" : 4, + "cpu,first_cpu" : 4 + }, { + "device_type" : "bus", + "device_name" : "devfreq0", + "device_config_path" : "./scripts/valid/pass-bus0.json", + "thermal_device_name" : null + }, { + "device_type" : "bus", + "device_name" : "devfreq5", + "device_config_path" : "./scripts/valid/pass-bus1.json", + "thermal_device_name" : null + }, { + "device_type" : "gpu", + "device_name" : "devfreq10", + "device_config_path" : "./scripts/valid/pass-gpu.json", + "thermal_device_name" : "thermal_zone3" + }, { + "device_type" : "memory", + "device_name" : "memory", + "device_config_path" : "./scripts/valid/pass-memory.json" + }, { + "device_type" : "battery", + "device_name" : "battery", + "device_config_path" : "./scripts/valid/pass-battery.json", + "thermal_device_name" : "thermal_zone5", + "cooling_device_name" : null + } + ] +} -- 2.7.4