haltest: enhance tdm_client voutput test 55/200055/2
authorJunkyeong Kim <jk0430.kim@samsung.com>
Mon, 18 Feb 2019 11:59:37 +0000 (20:59 +0900)
committerSooChan Lim <sc1.lim@samsung.com>
Wed, 6 Mar 2019 08:39:29 +0000 (08:39 +0000)
add tdm voutput status handler to check the commands works well.(connect, disconnect, mode set)

Change-Id: Ia02bc04df72387995b0fcfb7b00acb9cf272cfb9
Signed-off-by: Junkyeong Kim <jk0430.kim@samsung.com>
haltests/src/tc_tdm_client.cpp

index 8243d1f..5d41486 100644 (file)
@@ -287,6 +287,53 @@ _tc_tdm_server_set_output_dpms(tdm_display *dpy, int msg)
 }
 
 static void
+_tc_tdm_test_server_cb_output_mode_change(tdm_output *output, unsigned int index, void *user_data)
+{
+       const tdm_output_mode *modes, *mode;
+       int count = 0;
+       tdm_error ret;
+
+       ret = tdm_output_get_available_modes(output, &modes, &count);
+       TDM_UT_RETURN_IF_FAIL(ret == TDM_ERROR_NONE);
+       TDM_UT_RETURN_IF_FAIL((int)index < count);
+
+       mode = &modes[index];
+
+       ret = tdm_output_set_mode(output, mode);
+       TDM_UT_RETURN_IF_FAIL(ret == TDM_ERROR_NONE);
+
+       ret = tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_ON);
+       TDM_UT_RETURN_IF_FAIL(ret == TDM_ERROR_NONE);
+
+       ret = tdm_output_commit(output, 0, NULL, NULL);
+       TDM_UT_RETURN_IF_FAIL(ret == TDM_ERROR_NONE);
+}
+
+static void
+_tc_tdm_output_cb_destroy_handler(tdm_output *output, void *user_data)
+{
+       tdm_error ret;
+
+       tdm_output_remove_mode_change_request_handler(output, _tc_tdm_test_server_cb_output_mode_change, NULL);
+       tdm_output_remove_destroy_handler(output, _tc_tdm_output_cb_destroy_handler, NULL);
+
+       ret = tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_OFF);
+       TDM_UT_RETURN_IF_FAIL(ret == TDM_ERROR_NONE);
+}
+
+static void
+_tc_tdm_output_cb_create_handler(tdm_display *dpy, tdm_output *output, void *user_data)
+{
+       tdm_error ret = TDM_ERROR_NONE;
+
+       ret = tdm_output_add_mode_change_request_handler(output, _tc_tdm_test_server_cb_output_mode_change, NULL);
+       TDM_UT_RETURN_IF_FAIL(ret == TDM_ERROR_NONE);
+
+       ret = tdm_output_add_destroy_handler(output, _tc_tdm_output_cb_destroy_handler, NULL);
+       TDM_UT_RETURN_IF_FAIL(ret == TDM_ERROR_NONE);
+}
+
+static void
 _tc_tdm_server_run(int *pipe_parent, int *pipe_child)
 {
        tdm_display *dpy = NULL;
@@ -294,6 +341,7 @@ _tc_tdm_server_run(int *pipe_parent, int *pipe_child)
        struct pollfd fds[2];
        int tdm_fd, err;
        int output_count = 0;
+       int virtual_conf;
 
        dpy = tdm_display_init(&ret);
        TDM_UT_GOTO_IF_FAIL(ret == TDM_ERROR_NONE, failed);
@@ -312,6 +360,12 @@ _tc_tdm_server_run(int *pipe_parent, int *pipe_child)
                TDM_UT_GOTO_IF_FAIL(tc_tdm_output_prepare(dpy, output, true) == true, failed);
        }
 
+       virtual_conf = tdm_config_get_int(TDM_CONFIG_KEY_GENERAL_VIRTUAL_OUTPUT, 0);
+       if (virtual_conf) {
+               ret = tdm_display_add_output_create_handler(dpy, _tc_tdm_output_cb_create_handler, NULL);
+               TDM_UT_GOTO_IF_FAIL(ret == TDM_ERROR_NONE, failed);
+       }
+
        TDM_UT_GOTO_IF_FAIL(_tc_tdm_pipe_write_msg(pipe_parent[1], -1, TDM_UT_PIPE_MSG_SERVER_READY) == true, done);
 
        TDM_INFO("*** server ready ***");
@@ -1715,13 +1769,61 @@ TEST_F(TDMVirtualOutput, GetClientOutput)
        ASSERT_NE(output, NULL);
 }
 
-TEST_F(TDMVirtualOutput, Connect)
+static void
+_tc_voutput_output_handler_cb(tdm_client_output *output, tdm_output_change_type type,
+                                          tdm_value value, void *user_data)
+{
+       bool *done = (bool *)user_data;
+       tdm_output_conn_status status;
+
+       if (type == TDM_OUTPUT_CHANGE_CONNECTION) {
+               status = (tdm_output_conn_status)value.u32;
+
+               if (status == TDM_OUTPUT_CONN_STATUS_CONNECTED)
+                       if (done) *done = true;
+       }
+}
+
+static void
+_tc_voutput_output_handler_cb2(tdm_client_output *output, tdm_output_change_type type,
+                                          tdm_value value, void *user_data)
+{
+       bool *done = (bool *)user_data;
+       tdm_output_conn_status status;
+
+       if (type == TDM_OUTPUT_CHANGE_CONNECTION) {
+               status = (tdm_output_conn_status)value.u32;
+
+               if (status == TDM_OUTPUT_CONN_STATUS_DISCONNECTED)
+                       if (done) *done = true;
+       }
+}
+
+static void
+_tc_voutput_output_handler_cb3(tdm_client_output *output, tdm_output_change_type type,
+                                          tdm_value value, void *user_data)
+{
+       bool *done = (bool *)user_data;
+       tdm_output_conn_status status;
+
+       if (type == TDM_OUTPUT_CHANGE_CONNECTION) {
+               status = (tdm_output_conn_status)value.u32;
+
+               if (status == TDM_OUTPUT_CONN_STATUS_MODE_SETTED)
+                       if (done) *done = true;
+       }
+}
+
+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;
 
        if (this->voutput == NULL) {
                virtual_conf = tdm_config_get_int(TDM_CONFIG_KEY_GENERAL_VIRTUAL_OUTPUT, 0);
@@ -1729,6 +1831,16 @@ TEST_F(TDMVirtualOutput, Connect)
                return;
        }
 
+       output = tdm_client_voutput_get_client_output(this->voutput, &ret);
+       ASSERT_EQ(ret, TDM_ERROR_NONE);
+       ASSERT_NE(output, NULL);
+
+       ret = tdm_client_output_add_change_handler(output, _tc_voutput_output_handler_cb, &done);
+       ASSERT_EQ(ret, TDM_ERROR_NONE);
+
+       ret = tdm_client_output_add_change_handler(output, _tc_voutput_output_handler_cb2, &done2);
+       ASSERT_EQ(ret, TDM_ERROR_NONE);
+
        ret = tdm_client_voutput_set_physical_size(this->voutput, mmWidth, mmHeight);
        ASSERT_EQ(ret, TDM_ERROR_NONE);
 
@@ -1739,36 +1851,30 @@ TEST_F(TDMVirtualOutput, Connect)
        ret = tdm_client_voutput_connect(this->voutput);
        ASSERT_EQ(ret, TDM_ERROR_NONE);
 
-       tdm_client_handle_events_timeout(this->client, 0);
-}
-
-TEST_F(TDMVirtualOutput, Disconnect)
-{
-       tdm_error ret;
-       int virtual_conf;
-
-       if (this->voutput == NULL) {
-               virtual_conf = tdm_config_get_int(TDM_CONFIG_KEY_GENERAL_VIRTUAL_OUTPUT, 0);
-               ASSERT_EQ(virtual_conf, 0);
-               return;
-       }
-
-//     TDM_UT_WAIT("check & press");
+       while (!done)
+               ASSERT_EQ(tdm_client_handle_events_timeout(this->client, 3000), TDM_ERROR_NONE);
 
        ret = tdm_client_voutput_disconnect(this->voutput);
        ASSERT_EQ(ret, TDM_ERROR_NONE);
 
-       tdm_client_handle_events_timeout(this->client, 0);
-}
+       while (!done2)
+               ASSERT_EQ(tdm_client_handle_events_timeout(this->client, 3000), TDM_ERROR_NONE);
 
+       tdm_client_output_remove_change_handler(output, _tc_voutput_output_handler_cb, &done);
+       tdm_client_output_remove_change_handler(output, _tc_voutput_output_handler_cb2, &done2);
+}
 
 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;
+       bool done2 = false;
+       bool done3 = false;
 
        if (this->voutput == NULL) {
                virtual_conf = tdm_config_get_int(TDM_CONFIG_KEY_GENERAL_VIRTUAL_OUTPUT, 0);
@@ -1776,6 +1882,17 @@ TEST_F(TDMVirtualOutput, SetMode)
                return;
        }
 
+       output = tdm_client_voutput_get_client_output(this->voutput, &ret);
+       ASSERT_EQ(ret, TDM_ERROR_NONE);
+       ASSERT_NE(output, NULL);
+
+       ret = tdm_client_output_add_change_handler(output, _tc_voutput_output_handler_cb, &done);
+       ASSERT_EQ(ret, TDM_ERROR_NONE);
+       ret = tdm_client_output_add_change_handler(output, _tc_voutput_output_handler_cb2, &done2);
+       ASSERT_EQ(ret, TDM_ERROR_NONE);
+       ret = tdm_client_output_add_change_handler(output, _tc_voutput_output_handler_cb3, &done3);
+       ASSERT_EQ(ret, TDM_ERROR_NONE);
+
        ret = tdm_client_voutput_set_physical_size(this->voutput, mmWidth, mmHeight);
        ASSERT_EQ(ret, TDM_ERROR_NONE);
 
@@ -1786,16 +1903,23 @@ TEST_F(TDMVirtualOutput, SetMode)
        ret = tdm_client_voutput_connect(this->voutput);
        ASSERT_EQ(ret, TDM_ERROR_NONE);
 
-       tdm_client_handle_events_timeout(this->client, 100);
+       while (!done)
+               ASSERT_EQ(tdm_client_handle_events_timeout(this->client, 3000), TDM_ERROR_NONE);
 
        ASSERT_EQ(tdm_client_voutput_set_mode(this->voutput, count - 1), TDM_ERROR_NONE);
 
-       tdm_client_handle_events_timeout(this->client, 100);
+       while (!done3)
+               ASSERT_EQ(tdm_client_handle_events_timeout(this->client, 3000), TDM_ERROR_NONE);
 
        ret = tdm_client_voutput_disconnect(this->voutput);
        ASSERT_EQ(ret, TDM_ERROR_NONE);
 
-       tdm_client_handle_events_timeout(this->client, 0);
+       while (!done2)
+               ASSERT_EQ(tdm_client_handle_events_timeout(this->client, 3000), TDM_ERROR_NONE);
+
+       tdm_client_output_remove_change_handler(output, _tc_voutput_output_handler_cb, &done);
+       tdm_client_output_remove_change_handler(output, _tc_voutput_output_handler_cb2, &done2);
+       tdm_client_output_remove_change_handler(output, _tc_voutput_output_handler_cb3, &done3);
 }
 
 TEST_F(TDMVirtualOutput, SetModeNullObject)
@@ -1822,7 +1946,7 @@ TEST_F(TDMVirtualOutput, SetModeNullObject)
        ret = tdm_client_voutput_connect(this->voutput);
        ASSERT_EQ(ret, TDM_ERROR_NONE);
 
-       tdm_client_handle_events_timeout(this->client, 100);
+       tdm_client_handle_events_timeout(this->client, 50);
 
        ASSERT_EQ(tdm_client_voutput_set_mode(NULL, 0), TDM_ERROR_INVALID_PARAMETER);
 
@@ -1856,7 +1980,7 @@ TEST_F(TDMVirtualOutput, SetModeInvalidIndex)
        ret = tdm_client_voutput_connect(this->voutput);
        ASSERT_EQ(ret, TDM_ERROR_NONE);
 
-       tdm_client_handle_events_timeout(this->client, 100);
+       tdm_client_handle_events_timeout(this->client, 50);
 
        ASSERT_EQ(tdm_client_voutput_set_mode(this->voutput, -1), TDM_ERROR_INVALID_PARAMETER);