tests: unittest: Add unittest of pass-parser module 23/276923/2
authorChanwoo Choi <cw00.choi@samsung.com>
Thu, 23 Jun 2022 08:31:29 +0000 (17:31 +0900)
committerChanwoo Choi <cw00.choi@samsung.com>
Mon, 4 Jul 2022 06:43:21 +0000 (15:43 +0900)
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 <cw00.choi@samsung.com>
tests/unittest/CMakeLists.txt
tests/unittest/pass-unittests.cc
tests/unittest/scripts/invalid/pass.json [new file with mode: 0644]
tests/unittest/scripts/valid/pass.json [new file with mode: 0644]

index 9d8995134c32efe826e36cd5e29dda28ebf4ba87..a5ba5af1c37fd408e9e98b1dcb0c11c6c1c83b67 100644 (file)
@@ -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)
index 736ebde8da96721a2ef3ed800a9327025ac8e0df..207e64b3c80108ffb187757e56d40a52410e7077 100644 (file)
@@ -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 (file)
index 0000000..84df24a
--- /dev/null
@@ -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 (file)
index 0000000..d3eea11
--- /dev/null
@@ -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
+               }
+       ]
+}