From: Changyeon Lee Date: Mon, 4 Jul 2022 10:24:50 +0000 (+0900) Subject: haltest/client: Remove duplicate code X-Git-Tag: accepted/tizen/unified/20220719.131729~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F13%2F277513%2F1;p=platform%2Fcore%2Fuifw%2Flibtdm.git haltest/client: Remove duplicate code Change-Id: I31311d011e5af46eb6a5323bdc9b0db402b9ca27 --- diff --git a/haltests/src/tc_tdm_client.cpp b/haltests/src/tc_tdm_client.cpp index 2b5847a..ee35135 100644 --- a/haltests/src/tc_tdm_client.cpp +++ b/haltests/src/tc_tdm_client.cpp @@ -62,6 +62,7 @@ enum { static int _tc_tdm_pipe_read_msg(int fd); static bool _tc_tdm_pipe_write_msg(int fd, int reply_fd, int msg); static pid_t _tc_tdm_client_server_fork(int *pipe_to_parent, int *pipe_to_child); +static void _tc_tdm_client_server_kill(int *pipe_parent, int *pipe_child, pid_t server_pid); class TDMClient : public TDMEnv { @@ -112,28 +113,7 @@ void TDMClient::ServerFork(void) void TDMClient::ServerKill(void) { - if (pipe_child[0] >= 0) - close(pipe_child[0]); - if (pipe_child[1] >= 0) { - if (server_pid > 0) { - bool ret = _tc_tdm_pipe_write_msg(pipe_child[1], pipe_parent[0], TDM_UT_PIPE_MSG_TERMINATE_SERVER); - if (ret) { - if (waitpid(server_pid, NULL, 0) == server_pid) - TDM_INFO("*** server terminated ***"); - else - TDM_ERR("*** failed to terminate server ***"); - } else { - if (kill(server_pid, 9) < 0) - TDM_ERR("*** failed to kill server ***"); - } - } - close(pipe_child[1]); - } - - if (pipe_parent[0] >= 0) - close(pipe_parent[0]); - if (pipe_parent[1] >= 0) - close(pipe_parent[1]); + _tc_tdm_client_server_kill(pipe_parent, pipe_child, server_pid); server_pid = -1; pipe_parent[0] = pipe_parent[1] = -1; @@ -462,6 +442,33 @@ failed: } +static void +_tc_tdm_client_server_kill(int *pipe_parent, int *pipe_child, pid_t server_pid) +{ + if (pipe_child[0] >= 0) + close(pipe_child[0]); + if (pipe_child[1] >= 0) { + if (server_pid > 0) { + bool ret = _tc_tdm_pipe_write_msg(pipe_child[1], pipe_parent[0], TDM_UT_PIPE_MSG_TERMINATE_SERVER); + if (ret) { + if (waitpid(server_pid, NULL, 0) == server_pid) + TDM_INFO("*** server terminated ***"); + else + TDM_ERR("*** failed to terminate server ***"); + } else { + if (kill(server_pid, 9) < 0) + TDM_ERR("*** failed to kill server ***"); + } + } + close(pipe_child[1]); + } + + if (pipe_parent[0] >= 0) + close(pipe_parent[0]); + if (pipe_parent[1] >= 0) + close(pipe_parent[1]); +} + static void _tc_tdm_client_sig_handler(int sig) { TDM_UT_ERR("got signal: %d", sig); @@ -1163,6 +1170,31 @@ TEST_P(TDMClient, ClientVblankWaitInterval0) EXPECT_EQ(tdm_client_vblank_wait(vblank, 0, _tc_tdm_client_vblank_cb2, NULL), TDM_ERROR_INVALID_PARAMETER); } +static void +_tc_tdm_client_print_vblank_info(double start, double end, int vrefresh_interval, int t) +{ + /* "+ vrefresh_interval" consider the delay of socket communication between kernel and platform */ + //EXPECT_GT((end - start), (vrefresh_interval * (t - 1))); + double a = end - start; + double b = vrefresh_interval * (t - 1); + if (a > b) + std::cout << "\033[0;35m" + << "==> Error: " + << "\033[0;33m" + << "Expected: ((end - start) > (vrefresh_interval * (t - 1))), " + << "actual: " << a << " vs " << b << "\033[0;0m" << std::endl; + + //EXPECT_LT((end - start), (vrefresh_interval * t + vrefresh_interval)); + a = end - start; + b = vrefresh_interval * t + vrefresh_interval; + if (a < b) + std::cout << "\033[0;35m" + << "==> Error: " + << "\033[0;33m" + << "Expected: ((end - start) < (vrefresh_interval * t + vrefresh_interval)), " + << "actual: " << a << " vs " << b << "\033[0;0m" << std::endl; +} + TEST_P(TDMClient, ClientVblankWaitInterval) { bool done; @@ -1181,26 +1213,7 @@ TEST_P(TDMClient, ClientVblankWaitInterval) EXPECT_EQ(tdm_client_handle_events_timeout(client, 3000), TDM_ERROR_NONE); end = tdm_helper_get_time(); - /* "+ vrefresh_interval" consider the delay of socket communication between kernel and platform */ - //EXPECT_GT((end - start), (vrefresh_interval * (t - 1))); - double a = end - start; - double b = vrefresh_interval * (t - 1); - if (a > b) - std::cout << "\033[0;35m" - << "==> Error: " - << "\033[0;33m" - << "Expected: ((end - start) > (vrefresh_interval * (t - 1))), " - << "actual: " << a << " vs " << b << "\033[0;0m" << std::endl; - - //EXPECT_LT((end - start), (vrefresh_interval * t + vrefresh_interval)); - a = end - start; - b = vrefresh_interval * t + vrefresh_interval; - if (a < b) - std::cout << "\033[0;35m" - << "==> Error: " - << "\033[0;33m" - << "Expected: ((end - start) < (vrefresh_interval * t + vrefresh_interval)), " - << "actual: " << a << " vs " << b << "\033[0;0m" << std::endl; + _tc_tdm_client_print_vblank_info(start, end, vrefresh_interval, t); } } @@ -1261,26 +1274,7 @@ TEST_P(TDMClient, ClientVblankWaitSeqInterval) EXPECT_EQ(tdm_client_handle_events_timeout(client, 3000), TDM_ERROR_NONE); end = tdm_helper_get_time(); - /* "+ vrefresh_interval" consider the delay of socket communication between kernel and platform */ - //EXPECT_GT((end - start), (vrefresh_interval * (t - 1))); - double a = end - start; - double b = vrefresh_interval * (t - 1); - if (a > b) - std::cout << "\033[0;35m" - << "==> Error: " - << "\033[0;33m" - << "Expected: ((end - start) > (vrefresh_interval * (t - 1))), " - << "actual: " << a << " vs " << b << "\033[0;0m" << std::endl; - - //EXPECT_LT((end - start), (vrefresh_interval * t + vrefresh_interval)); - a = end - start; - b = vrefresh_interval * t + vrefresh_interval; - if (a < b) - std::cout << "\033[0;35m" - << "==> Error: " - << "\033[0;33m" - << "Expected: ((end - start) < (vrefresh_interval * t + vrefresh_interval)), " - << "actual: " << a << " vs " << b << "\033[0;0m" << std::endl; + _tc_tdm_client_print_vblank_info(start, end, vrefresh_interval, t); } } @@ -1568,6 +1562,7 @@ public: static void SetUpTestCase(); static void TearDownTestCase(); static bool PrepareVOutput(void); + static bool ConnectVOutput(unsigned int mmWidth, unsigned int mmHeight, int mode_count); protected: static tdm_client *client; @@ -1593,28 +1588,7 @@ tdm_client_voutput* TDMVirtualOutput::voutput = nullptr; void TDMVirtualOutput::ServerKill(void) { - if (pipe_child[0] >= 0) - close(pipe_child[0]); - if (pipe_child[1] >= 0) { - if (server_pid > 0) { - bool ret = _tc_tdm_pipe_write_msg(pipe_child[1], pipe_parent[0], TDM_UT_PIPE_MSG_TERMINATE_SERVER); - if (ret) { - if (waitpid(server_pid, NULL, 0) == server_pid) - TDM_INFO("*** server terminated ***"); - else - TDM_ERR("*** failed to terminate server ***"); - } else { - if (kill(server_pid, 9) < 0) - TDM_ERR("*** failed to kill server ***"); - } - } - close(pipe_child[1]); - } - - if (pipe_parent[0] >= 0) - close(pipe_parent[0]); - if (pipe_parent[1] >= 0) - close(pipe_parent[1]); + _tc_tdm_client_server_kill(pipe_parent, pipe_child, server_pid); server_pid = -1; pipe_parent[0] = pipe_parent[1] = -1; @@ -1704,6 +1678,24 @@ _tc_tdm_client_virutual_make_available_mode(tdm_client_output_mode *modes, int c } } +bool TDMVirtualOutput::ConnectVOutput(unsigned int mmWidth, unsigned int mmHeight, int mode_count) +{ + tdm_client_output_mode modes[mode_count]; + tdm_error ret; + + ret = tdm_client_voutput_set_physical_size(voutput, mmWidth, mmHeight); + TDM_UT_RETURN_FALSE_IF_FAIL(ret == TDM_ERROR_NONE); + + _tc_tdm_client_virutual_make_available_mode(modes, mode_count); + ret = tdm_client_voutput_set_available_modes(voutput, modes, mode_count); + TDM_UT_RETURN_FALSE_IF_FAIL(ret == TDM_ERROR_NONE); + + ret = tdm_client_voutput_connect(voutput); + TDM_UT_RETURN_FALSE_IF_FAIL(ret == TDM_ERROR_NONE); + + return true; +} + TEST_F(TDMVirtualOutput, SetAvailableModes) { tdm_error ret; @@ -1894,8 +1886,6 @@ TEST_F(TDMVirtualOutput, ConnectDisconnect) tdm_error ret; tdm_client_output *output; unsigned int mmWidth = 300, mmHeight = 150; - tdm_client_output_mode modes[this->MODE_COUNT]; - int count = this->MODE_COUNT; int virtual_conf; bool done = false; bool done2 = false; @@ -1917,15 +1907,7 @@ TEST_F(TDMVirtualOutput, ConnectDisconnect) ret = tdm_client_output_add_change_handler(output, _tc_voutput_output_handler_cb2, &done2); EXPECT_EQ(ret, TDM_ERROR_NONE); - ret = tdm_client_voutput_set_physical_size(this->voutput, mmWidth, mmHeight); - EXPECT_EQ(ret, TDM_ERROR_NONE); - - _tc_tdm_client_virutual_make_available_mode(modes, count); - ret = tdm_client_voutput_set_available_modes(this->voutput, modes, count); - EXPECT_EQ(ret, TDM_ERROR_NONE); - - ret = tdm_client_voutput_connect(this->voutput); - EXPECT_EQ(ret, TDM_ERROR_NONE); + EXPECT_EQ(ConnectVOutput(mmWidth, mmHeight, this->MODE_COUNT), true); while (!done) EXPECT_EQ(tdm_client_handle_events_timeout(this->client, 3000), TDM_ERROR_NONE); @@ -1945,7 +1927,6 @@ TEST_F(TDMVirtualOutput, SetMode) tdm_error ret; tdm_client_output *output; unsigned int mmWidth = 300, mmHeight = 150; - tdm_client_output_mode modes[this->MODE_COUNT]; int count = this->MODE_COUNT; int virtual_conf; bool done = false; @@ -1970,15 +1951,7 @@ TEST_F(TDMVirtualOutput, SetMode) ret = tdm_client_output_add_change_handler(output, _tc_voutput_output_handler_cb3, &done3); EXPECT_EQ(ret, TDM_ERROR_NONE); - ret = tdm_client_voutput_set_physical_size(this->voutput, mmWidth, mmHeight); - EXPECT_EQ(ret, TDM_ERROR_NONE); - - _tc_tdm_client_virutual_make_available_mode(modes, count); - ret = tdm_client_voutput_set_available_modes(this->voutput, modes, count); - EXPECT_EQ(ret, TDM_ERROR_NONE); - - ret = tdm_client_voutput_connect(this->voutput); - EXPECT_EQ(ret, TDM_ERROR_NONE); + EXPECT_EQ(ConnectVOutput(mmWidth, mmHeight, this->MODE_COUNT), true); while (!done) EXPECT_EQ(tdm_client_handle_events_timeout(this->client, 3000), TDM_ERROR_NONE); @@ -2003,8 +1976,6 @@ TEST_F(TDMVirtualOutput, SetModeNullObject) { tdm_error ret; unsigned int mmWidth = 300, mmHeight = 150; - tdm_client_output_mode modes[this->MODE_COUNT]; - int count = this->MODE_COUNT; int virtual_conf; if (this->voutput == NULL) { @@ -2014,15 +1985,7 @@ TEST_F(TDMVirtualOutput, SetModeNullObject) return; } - ret = tdm_client_voutput_set_physical_size(this->voutput, mmWidth, mmHeight); - EXPECT_EQ(ret, TDM_ERROR_NONE); - - _tc_tdm_client_virutual_make_available_mode(modes, count); - ret = tdm_client_voutput_set_available_modes(this->voutput, modes, count); - EXPECT_EQ(ret, TDM_ERROR_NONE); - - ret = tdm_client_voutput_connect(this->voutput); - EXPECT_EQ(ret, TDM_ERROR_NONE); + EXPECT_EQ(ConnectVOutput(mmWidth, mmHeight, this->MODE_COUNT), true); tdm_client_handle_events_timeout(this->client, 50); @@ -2038,8 +2001,6 @@ TEST_F(TDMVirtualOutput, SetModeInvalidIndex) { tdm_error ret; unsigned int mmWidth = 300, mmHeight = 150; - tdm_client_output_mode modes[this->MODE_COUNT]; - int count = this->MODE_COUNT; int virtual_conf; if (this->voutput == NULL) { @@ -2049,15 +2010,7 @@ TEST_F(TDMVirtualOutput, SetModeInvalidIndex) return; } - ret = tdm_client_voutput_set_physical_size(this->voutput, mmWidth, mmHeight); - EXPECT_EQ(ret, TDM_ERROR_NONE); - - _tc_tdm_client_virutual_make_available_mode(modes, count); - ret = tdm_client_voutput_set_available_modes(this->voutput, modes, count); - EXPECT_EQ(ret, TDM_ERROR_NONE); - - ret = tdm_client_voutput_connect(this->voutput); - EXPECT_EQ(ret, TDM_ERROR_NONE); + EXPECT_EQ(ConnectVOutput(mmWidth, mmHeight, this->MODE_COUNT), true); tdm_client_handle_events_timeout(this->client, 50);