From c6db85cd4376059fd0c7cbcc6b47efa436be85f9 Mon Sep 17 00:00:00 2001 From: Yongjoo Ahn Date: Thu, 18 Apr 2024 13:13:12 +0900 Subject: [PATCH] [test] Let test daemon launches per testsuite not single testcase - Let the test daemon launches per testsuite. Launching it for each testcase is not practical. Signed-off-by: Yongjoo Ahn --- tests/capi/unittest_capi_service_agent_client.cc | 22 +++++++------ tests/capi/unittest_capi_service_extension.cc | 12 +++----- tests/capi/unittest_capi_service_offloading.cc | 36 +++++++++++++++------- .../unittest_capi_service_training_offloading.cc | 22 +++++++------ 4 files changed, 54 insertions(+), 38 deletions(-) diff --git a/tests/capi/unittest_capi_service_agent_client.cc b/tests/capi/unittest_capi_service_agent_client.cc index 0ec25ed..d579ff2 100644 --- a/tests/capi/unittest_capi_service_agent_client.cc +++ b/tests/capi/unittest_capi_service_agent_client.cc @@ -22,13 +22,12 @@ class MLServiceAgentTest : public ::testing::Test { protected: - GTestDBus *dbus; + static GTestDBus *dbus; - public: /** - * @brief Setup method for each test case. + * @brief Setup method for entire testsuite. */ - void SetUp () override + static void SetUpTestSuite () { g_autofree gchar *services_dir = g_build_filename (EXEC_PREFIX, "ml-test", "services", NULL); @@ -42,14 +41,12 @@ class MLServiceAgentTest : public ::testing::Test } /** - * @brief Teardown method for each test case. + * @brief Teardown method for entire testsuite. */ - void TearDown () override + static void TearDownTestSuite () { - if (dbus) { - g_test_dbus_down (dbus); - g_object_unref (dbus); - } + g_test_dbus_down (dbus); + g_object_unref (dbus); } /** @@ -84,6 +81,11 @@ class MLServiceAgentTest : public ::testing::Test }; /** + * @brief GTestDbus object to run ml-agent. + */ +GTestDBus *MLServiceAgentTest::dbus = nullptr; + +/** * @brief use case of using service api and agent */ TEST_F (MLServiceAgentTest, usecase_00) diff --git a/tests/capi/unittest_capi_service_extension.cc b/tests/capi/unittest_capi_service_extension.cc index 33f299e..c184bdc 100755 --- a/tests/capi/unittest_capi_service_extension.cc +++ b/tests/capi/unittest_capi_service_extension.cc @@ -46,7 +46,7 @@ class MLServiceExtensionTest : public ::testing::Test static GTestDBus *dbus; /** - * @brief Setup method for each test case. + * @brief Setup method for entire testsuite. */ static void SetUpTestSuite () { @@ -61,19 +61,17 @@ class MLServiceExtensionTest : public ::testing::Test } /** - * @brief Teardown method for each test case. + * @brief Teardown method for entire testsuite. */ static void TearDownTestSuite () { - if (dbus) { - g_test_dbus_down (dbus); - g_object_unref (dbus); - } + g_test_dbus_down (dbus); + g_object_unref (dbus); } }; /** - * @brief Test dbus to run ml-agent. + * @brief GTestDbus object to run ml-agent. */ GTestDBus *MLServiceExtensionTest::dbus = nullptr; diff --git a/tests/capi/unittest_capi_service_offloading.cc b/tests/capi/unittest_capi_service_offloading.cc index 9c30d44..1c55eb9 100644 --- a/tests/capi/unittest_capi_service_offloading.cc +++ b/tests/capi/unittest_capi_service_offloading.cc @@ -52,17 +52,16 @@ _get_config_path (const gchar *config_name) class MLOffloadingService : public ::testing::Test { protected: - GTestDBus *dbus; + static GTestDBus *dbus; int status; ml_service_h client_h; ml_service_h server_h; _ml_service_test_data_s test_data; - public: /** - * @brief Setup method for each test case. + * @brief Setup method for entire testsuite. */ - void SetUp () override + static void SetUpTestSuite () { g_autofree gchar *services_dir = g_build_filename (EXEC_PREFIX, "ml-test", "services", NULL); @@ -73,10 +72,25 @@ class MLOffloadingService : public ::testing::Test g_test_dbus_add_service_dir (dbus, services_dir); g_test_dbus_up (dbus); + } + /** + * @brief Teardown method for entire testsuite. + */ + static void TearDownTestSuite () + { + g_test_dbus_down (dbus); + g_object_unref (dbus); + } + + /** + * @brief Setup method for each test case. + */ + void SetUp () override + { g_autofree gchar *receiver_config = _get_config_path ("service_offloading_receiver.conf"); - status = ml_service_new (receiver_config, &server_h); + int status = ml_service_new (receiver_config, &server_h); ASSERT_EQ (status, ML_ERROR_NONE); test_data.handle = server_h; @@ -88,13 +102,8 @@ class MLOffloadingService : public ::testing::Test /** * @brief Teardown method for each test case. */ - void TearDown () override + void TearDown () { - if (dbus) { - g_test_dbus_down (dbus); - g_object_unref (dbus); - } - status = ml_service_destroy (server_h); EXPECT_EQ (ML_ERROR_NONE, status); status = ml_service_destroy (client_h); @@ -133,6 +142,11 @@ class MLOffloadingService : public ::testing::Test }; /** + * @brief GTestDbus object to run ml-agent. + */ +GTestDBus *MLOffloadingService::dbus = nullptr; + +/** * @brief Callback function for scenario test. */ static void diff --git a/tests/capi/unittest_capi_service_training_offloading.cc b/tests/capi/unittest_capi_service_training_offloading.cc index 69f0516..c248e39 100644 --- a/tests/capi/unittest_capi_service_training_offloading.cc +++ b/tests/capi/unittest_capi_service_training_offloading.cc @@ -40,13 +40,12 @@ _get_config_path (const gchar *config_name) class MLServiceTrainingOffloading : public ::testing::Test { protected: - GTestDBus *dbus; + static GTestDBus *dbus; - public: /** - * @brief Setup method for each test case. + * @brief Setup method for entire testsuite. */ - void SetUp () override + static void SetUpTestSuite () { g_autofree gchar *services_dir = g_build_filename (EXEC_PREFIX, "ml-test", "services", NULL); @@ -59,18 +58,21 @@ class MLServiceTrainingOffloading : public ::testing::Test } /** - * @brief Teardown method for each test case. + * @brief Teardown method for entire testsuite. */ - void TearDown () override + static void TearDownTestSuite () { - if (dbus) { - g_test_dbus_down (dbus); - g_object_unref (dbus); - } + g_test_dbus_down (dbus); + g_object_unref (dbus); } }; /** + * @brief GTestDbus object to run ml-agent. + */ +GTestDBus *MLServiceTrainingOffloading::dbus = nullptr; + +/** * @brief Callback function for reply test. */ static void -- 2.7.4