utest: add TCs for tbm_timeline 81/170481/1
authorSangjin.Lee <lsj119@samsung.com>
Tue, 20 Feb 2018 07:52:52 +0000 (16:52 +0900)
committerSangjin.Lee <lsj119@samsung.com>
Tue, 20 Feb 2018 07:52:52 +0000 (16:52 +0900)
Change-Id: I0e2da26347e946409d1521f30ac2522b9d9709b5

protocol/wayland-tbm-test.xml
utests/src/ut_base.cpp
utests/src/ut_wayland_tbm.cpp

index 3c84751..9def0fd 100644 (file)
@@ -42,6 +42,9 @@
       <arg name="queue_size" type="uint"/>
       <arg name="need_flush" type="uint"/>
     </request>
+    <request name="queue_flush">
+      <arg name="surface" type="object" interface="wl_surface"/>
+    </request>
     <enum name="prop_buffer">
       <entry name="none" value="0"/>
       <entry name="width" value="1"/>
     </event>
     <request name="destroy_queue_buffer">
       <arg name="wl_tbm" type="object" interface="wl_tbm"/>
-      <arg name="wl_buf" type="object" interface="wl_surface"/>
+      <arg name="surface" type="object" interface="wl_surface"/>
+    </request>
+    <request name="timeline_increase">
+      <arg name="buffer" type="object" interface="wl_buffer"/>
     </request>
   </interface>
 </protocol>
index d4dc818..319d086 100644 (file)
@@ -95,11 +95,15 @@ _wl_tbm_test_surface_attach(struct wl_client *client,
                return;
        }
 
-       tbm_buf = wayland_tbm_server_get_surface(wlt_server.wl_tbm_server, buffer);
-       if (tbm_buf == nullptr)
-       {
-               wl_tbm_test_send_error(wlt_surf->test, resource, WL_TBM_TEST_ERROR_INVALID_OBJECT, "The buffer is invalid");
-               return;
+       if (buffer) {
+               tbm_buf = wayland_tbm_server_get_surface(wlt_server.wl_tbm_server, buffer);
+               if (tbm_buf == nullptr)
+               {
+                       wl_tbm_test_send_error(wlt_surf->test, resource, WL_TBM_TEST_ERROR_INVALID_OBJECT, "The buffer is invalid");
+                       return;
+               }
+
+               wl_resource_add_destroy_listener(buffer, &wlt_surf->buf_destroy_cb);
        }
 
        if (wlt_surf->buffer)
@@ -109,7 +113,6 @@ _wl_tbm_test_surface_attach(struct wl_client *client,
        }
 
        wlt_surf->buffer = buffer;
-       wl_resource_add_destroy_listener(buffer, &wlt_surf->buf_destroy_cb);
 }
 
 static void
@@ -232,6 +235,12 @@ _wl_tbm_test_server_surface_detach_cb(struct wayland_tbm_client_queue *cqueue, t
 }
 
 static void
+_wl_tbm_test_queue_dequeue_cb(struct wayland_tbm_client_queue *queue, tbm_surface_h surface, void *data)
+{
+
+}
+
+static void
 _wl_tbm_test_set_active(struct wl_client *client, struct wl_resource *resource, struct wl_resource *surface,
                                        uint32_t active,
                                        uint32_t usage,
@@ -256,6 +265,8 @@ _wl_tbm_test_set_active(struct wl_client *client, struct wl_resource *resource,
        wlt_surf->is_active = active;
        if (active) {
                uint32_t i = 0;
+               wayland_tbm_server_client_queue_set_dequeue_cb(wlt_queue, _wl_tbm_test_queue_dequeue_cb, wlt_surf);
+
                while (i < queue_size) {
                        tbm_surf = tbm_surface_create(100, 200, TBM_FORMAT_ARGB8888);
                        if (i == 0)
@@ -280,6 +291,20 @@ _wl_tbm_test_set_active(struct wl_client *client, struct wl_resource *resource,
 }
 
 static void
+_wl_tbm_test_queue_flush(struct wl_client *client, struct wl_resource *resource, struct wl_resource *surface)
+{
+       struct wayland_tbm_client_queue *queue;
+
+       queue = wayland_tbm_server_client_queue_get(wlt_server.wl_tbm_server, surface);
+       if (!queue) {
+               wl_tbm_test_send_error(resource, surface, WL_TBM_TEST_ERROR_INVALID_OBJECT, "flush: invalid surface");
+               return;
+       }
+
+       wayland_tbm_server_client_queue_flush(queue);
+}
+
+static void
 _wl_tbm_test_check_buffer(struct wl_client *client, struct wl_resource *resource, struct wl_resource *buffer,
                                        uint32_t property,
                                        uint32_t value)
@@ -345,12 +370,27 @@ _wl_tbm_test_destroy_queue_buffer(struct wl_client *client, struct wl_resource *
        wl_client_flush(client);
 }
 
+static void
+_wl_tbm_test_timeline_increase(struct wl_client *client, struct wl_resource *resource, struct wl_resource *buffer)
+{
+       if (!wayland_tbm_server_buffer_has_sync_timeline(wlt_server.wl_tbm_server, buffer)) {
+               wl_tbm_test_send_error(resource, buffer, WL_TBM_TEST_ERROR_INVALID_OBJECT, "timeline: no timeline");
+               wl_client_flush(client);
+               return;
+       }
+
+       wayland_tbm_server_increase_buffer_sync_timeline(wlt_server.wl_tbm_server, buffer, 1);
+       wl_client_flush(client);
+}
+
 static const struct wl_tbm_test_interface wl_tbm_test_impl = {
        _wl_tbm_test_destroy,
        _wl_tbm_test_create_surface,
        _wl_tbm_test_set_active,
+       _wl_tbm_test_queue_flush,
        _wl_tbm_test_check_buffer,
-       _wl_tbm_test_destroy_queue_buffer
+       _wl_tbm_test_destroy_queue_buffer,
+       _wl_tbm_test_timeline_increase
 };
 
 static void
@@ -396,6 +436,7 @@ launch_server(void)
 #ifdef TIZEN_TEST_GCOV
        setenv("GCOV_PREFIX", "/tmp", 1);
 #endif
+       unsetenv("WAYLAND_DEBUG");
 
        wlt_server.wl_disp = wl_display_create();
        if (!wlt_server.wl_disp)
index fe15858..5958369 100644 (file)
@@ -32,6 +32,9 @@ DEALINGS IN THE SOFTWARE.
 #include <wayland-client.h>
 #include <tbm_surface.h>
 #include <tbm_surface_queue.h>
+extern "C" {
+#include <tbm_sync.h>
+}
 #include "wayland-tbm-client.h"
 #include "wayland-tbm-int.h"
 #include "wayland-tbm-client-protocol.h"
@@ -44,11 +47,12 @@ class UtWlTbm : public ::testing::Test
        static void TearDownTestCase();
        void SetUp();
        void TearDown();
-       int CheckServerError();
+       static int CheckServerError();
 
   public:
        static int server_error;
        static int server_pid;
+       static int monitor_done;
        static struct wl_display *wl_disp;
        static struct wayland_tbm_client *wl_tbm_client;
        static struct wl_tbm_test *wl_tbm_test;
@@ -66,11 +70,15 @@ class UtWlTbm : public ::testing::Test
                                                const char *options, const char *request_id);
        static const struct wl_tbm_monitor_listener wlt_monitor_listener;
 
-       struct wl_surface *create_surface();
+       static void wlt_queue_buffer_release_cb(void *data, struct wl_buffer *wl_buffer);
+       static const struct wl_buffer_listener wlt_queue_buffer_listener;
+
+       static void SendMonitorCmd(const char *cmd);
 };
 
 int UtWlTbm::server_error = 0;
 int UtWlTbm::server_pid = -1;
+int UtWlTbm::monitor_done = 0;
 struct wl_display *UtWlTbm::wl_disp = nullptr;
 struct wayland_tbm_client *UtWlTbm::wl_tbm_client = nullptr;
 struct wl_tbm_test *UtWlTbm::wl_tbm_test = nullptr;
@@ -92,6 +100,10 @@ const struct wl_tbm_monitor_listener UtWlTbm::wlt_monitor_listener =
        UtWlTbm::wlt_monitor_request_to_client_cb
 };
 
+const struct wl_buffer_listener UtWlTbm::wlt_queue_buffer_listener = {
+       UtWlTbm::wlt_queue_buffer_release_cb
+};
+
 void UtWlTbm::wlt_test_error_cb(void *data,
                                                                struct wl_tbm_test *wl_tbm_test,
                                                                void *object, uint32_t code, const char *message)
@@ -117,6 +129,7 @@ void UtWlTbm::wlt_reg_handle_global_cb(void *data,
 void
 UtWlTbm::wlt_monitor_done_cb(void *data, struct wl_tbm_monitor *wl_tbm_monitor, const char *message)
 {
+       UtWlTbm::monitor_done = 1;
        printf("%s", message);
 }
 
@@ -189,16 +202,32 @@ void UtWlTbm::TearDown()
 
 int UtWlTbm::CheckServerError()
 {
-       server_error = 0;
-       wl_display_roundtrip(wl_disp);
+       UtWlTbm::server_error = 0;
+       wl_display_roundtrip(UtWlTbm::wl_disp);
+
+       return UtWlTbm::server_error;
+}
+
+void UtWlTbm::SendMonitorCmd(const char *cmd)
+{
+       int ret;
 
-       return server_error;
+       UtWlTbm::monitor_done = 0;
+       wl_tbm_monitor_request_to_sever(wl_tbm_monitor, cmd);
+       ASSERT_EQ(CheckServerError(), 0);
+       while(!UtWlTbm::monitor_done) {
+               ret = wl_display_dispatch(UtWlTbm::wl_disp);
+               ASSERT_NE(ret, -1);
+       }
 }
 
-struct wl_surface *
-create_surface()
+void UtWlTbm::wlt_queue_buffer_release_cb(void *data, struct wl_buffer *wl_buffer)
 {
-       return wl_tbm_test_create_surface(UtWlTbm::wl_tbm_test);
+       tbm_surface_queue_h queue = (tbm_surface_queue_h)data;
+       tbm_surface_h surface = (tbm_surface_h)wl_buffer_get_user_data(wl_buffer);
+
+       wayland_tbm_client_destroy_buffer(UtWlTbm::wl_tbm_client, wl_buffer);
+       tbm_surface_queue_release(queue, surface);
 }
 
 TEST_F(UtWlTbm, GetBufMgr)
@@ -608,7 +637,7 @@ TEST_F(UtWlTbm, BufQueueDequeue)
        ASSERT_NE(wlt_surface, nullptr);
        ASSERT_EQ(CheckServerError(), 0);
 
-       tbm_queue = wayland_tbm_client_create_surface_queue(wl_tbm_client, wlt_surface, 3, 100, 200, TBM_FORMAT_ABGR8888);
+       tbm_queue = wayland_tbm_client_create_surface_queue(wl_tbm_client, wlt_surface, 3, 100, 200, TBM_FORMAT_ARGB8888);
        ASSERT_NE(tbm_queue, nullptr);
        ASSERT_EQ(CheckServerError(), 0);
 
@@ -616,12 +645,18 @@ TEST_F(UtWlTbm, BufQueueDequeue)
        ASSERT_EQ(CheckServerError(), 0);
 
        while (i < 3) {
-               tbm_err = tbm_surface_queue_dequeue(tbm_queue, &tbm_surf);
-               ASSERT_EQ(tbm_err, TBM_SURFACE_QUEUE_ERROR_NONE);
-               wl_buf = wayland_tbm_client_create_buffer(wl_tbm_client, tbm_surf);
-               ASSERT_NE(wl_buf, nullptr);
+               if (tbm_surface_queue_can_dequeue(tbm_queue, 0)) {
+                       tbm_err = tbm_surface_queue_dequeue(tbm_queue, &tbm_surf);
+                       ASSERT_EQ(tbm_err, TBM_SURFACE_QUEUE_ERROR_NONE);
+                       ASSERT_EQ(CheckServerError(), 0);
 
-               wayland_tbm_client_destroy_buffer(wl_tbm_client, wl_buf);
+                       wl_buf = wayland_tbm_client_create_buffer(wl_tbm_client, tbm_surf);
+                       ASSERT_NE(wl_buf, nullptr);
+                       ASSERT_EQ(CheckServerError(), 0);
+
+                       wayland_tbm_client_destroy_buffer(wl_tbm_client, wl_buf);
+                       ASSERT_EQ(CheckServerError(), 0);
+               }
                i++;
        }
 
@@ -630,36 +665,140 @@ TEST_F(UtWlTbm, BufQueueDequeue)
        ASSERT_EQ(CheckServerError(), 0);
 }
 
-TEST_F(UtWlTbm, MonitorHelp)
+TEST_F(UtWlTbm, BufQueueDequeueNotify)
 {
-       const char *msg = "";
+       struct wl_surface *wlt_surface;
+       tbm_surface_queue_h tbm_queue;
+       int i = 0;
+       tbm_surface_h tbm_surf;
+       tbm_surface_queue_error_e tbm_err;
+
+       wlt_surface = wl_tbm_test_create_surface(wl_tbm_test);
+       ASSERT_NE(wlt_surface, nullptr);
+       ASSERT_EQ(CheckServerError(), 0);
+
+       tbm_queue = wayland_tbm_client_create_surface_queue(wl_tbm_client, wlt_surface, 3, 100, 200, TBM_FORMAT_ABGR8888);
+       ASSERT_NE(tbm_queue, nullptr);
+       ASSERT_EQ(CheckServerError(), 0);
+
+       while (i++ < 3) {
+               if (tbm_surface_queue_can_dequeue(tbm_queue, 1)) {
+                       tbm_err = tbm_surface_queue_dequeue(tbm_queue, &tbm_surf);
+                       ASSERT_EQ(tbm_err, TBM_SURFACE_QUEUE_ERROR_NONE);
+
+                       tbm_err = tbm_surface_queue_enqueue(tbm_queue, tbm_surf);
+                       ASSERT_EQ(tbm_err, TBM_SURFACE_QUEUE_ERROR_NONE);
+
+                       tbm_err = tbm_surface_queue_acquire(tbm_queue, &tbm_surf);
+                       ASSERT_EQ(tbm_err, TBM_SURFACE_QUEUE_ERROR_NONE);
+
+                       tbm_err = tbm_surface_queue_release(tbm_queue, tbm_surf);
+                       ASSERT_EQ(tbm_err, TBM_SURFACE_QUEUE_ERROR_NONE);
+               }
+       }
 
-       wl_tbm_monitor_request_to_sever(wl_tbm_monitor, msg);
+       wl_tbm_test_queue_flush(wl_tbm_test, wlt_surface);
+       ASSERT_EQ(CheckServerError(), 0);
+
+       tbm_surface_queue_destroy(tbm_queue);
+       wl_surface_destroy(wlt_surface);
        ASSERT_EQ(CheckServerError(), 0);
 }
 
-TEST_F(UtWlTbm, MonitorList)
+TEST_F(UtWlTbm, BufQueueAttach)
 {
-       const char *msg = "-list";
+       struct wl_surface *wlt_surface;
+       struct wl_buffer *wl_buf;
+
+       tbm_surface_queue_h tbm_queue;
+       tbm_surface_h tbm_surf;
+       tbm_surface_queue_error_e tbm_err;
+
+       wlt_surface = wl_tbm_test_create_surface(wl_tbm_test);
+       ASSERT_NE(wlt_surface, nullptr);
+       ASSERT_EQ(CheckServerError(), 0);
+
+       tbm_queue = wayland_tbm_client_create_surface_queue(wl_tbm_client, wlt_surface, 3, 100, 200, TBM_FORMAT_ABGR8888);
+       ASSERT_NE(tbm_queue, nullptr);
+       ASSERT_EQ(CheckServerError(), 0);
 
-       wl_tbm_monitor_request_to_sever(wl_tbm_monitor, msg);
+       tbm_err = tbm_surface_queue_dequeue(tbm_queue, &tbm_surf);
+       ASSERT_EQ(tbm_err, TBM_SURFACE_QUEUE_ERROR_NONE);
+
+       tbm_err = tbm_surface_queue_enqueue(tbm_queue, tbm_surf);
+       ASSERT_EQ(tbm_err, TBM_SURFACE_QUEUE_ERROR_NONE);
+
+       tbm_err = tbm_surface_queue_acquire(tbm_queue, &tbm_surf);
+       ASSERT_EQ(tbm_err, TBM_SURFACE_QUEUE_ERROR_NONE);
+
+       wl_buf = wayland_tbm_client_create_buffer(wl_tbm_client, tbm_surf);
+       ASSERT_NE(wl_buf, nullptr);
+       wl_buffer_add_listener(wl_buf, &wlt_queue_buffer_listener, (void*)tbm_queue);
+       wl_surface_attach(wlt_surface, wl_buf, 0, 0);
+       ASSERT_EQ(CheckServerError(), 0);
+
+       /*Make null attch for release*/
+       wl_surface_attach(wlt_surface, nullptr, 0, 0);
+       ASSERT_EQ(CheckServerError(), 0);
+
+       wl_tbm_test_queue_flush(wl_tbm_test, wlt_surface);
+       ASSERT_EQ(CheckServerError(), 0);
+
+       tbm_surface_queue_destroy(tbm_queue);
+       wl_surface_destroy(wlt_surface);
        ASSERT_EQ(CheckServerError(), 0);
 }
 
-TEST_F(UtWlTbm, MonitorShowAll)
+TEST_F(UtWlTbm, BufQueueFlush)
 {
-       const char *msg = "-show all";
+       struct wl_surface *wlt_surface;
+       tbm_surface_queue_h tbm_queue;
+       int i = 0;
+       tbm_surface_h tbm_surf;
+       tbm_surface_queue_error_e tbm_err;
+
+       wlt_surface = wl_tbm_test_create_surface(wl_tbm_test);
+       ASSERT_NE(wlt_surface, nullptr);
+       ASSERT_EQ(CheckServerError(), 0);
 
-       wl_tbm_monitor_request_to_sever(wl_tbm_monitor, msg);
+       tbm_queue = wayland_tbm_client_create_surface_queue(wl_tbm_client, wlt_surface, 3, 100, 200, TBM_FORMAT_ABGR8888);
+       ASSERT_NE(tbm_queue, nullptr);
+       ASSERT_EQ(CheckServerError(), 0);
+
+       while (i < 3) {
+               tbm_err = tbm_surface_queue_dequeue(tbm_queue, &tbm_surf);
+               ASSERT_EQ(tbm_err, TBM_SURFACE_QUEUE_ERROR_NONE);
+
+               tbm_surface_queue_enqueue(tbm_queue, tbm_surf);
+               i++;
+       }
+
+       wl_tbm_test_queue_flush(wl_tbm_test, wlt_surface);
+       ASSERT_EQ(CheckServerError(), 0);
+
+       tbm_surface_queue_destroy(tbm_queue);
+       wl_surface_destroy(wlt_surface);
        ASSERT_EQ(CheckServerError(), 0);
 }
 
-TEST_F(UtWlTbm, MonitorShowServer)
+TEST_F(UtWlTbm, MonitorHelp)
 {
-       const char *msg = "-show server";
+       SendMonitorCmd("");
+}
 
-       wl_tbm_monitor_request_to_sever(wl_tbm_monitor, msg);
-       ASSERT_EQ(CheckServerError(), 0);
+TEST_F(UtWlTbm, MonitorList)
+{
+       SendMonitorCmd("-list");
+}
+
+TEST_F(UtWlTbm, MonitorShowAll)
+{
+       SendMonitorCmd("-show all");
+}
+
+TEST_F(UtWlTbm, MonitorShowServer)
+{
+       SendMonitorCmd("-show server");
 }
 
 TEST_F(UtWlTbm, MonitorShowClient)
@@ -668,14 +807,79 @@ TEST_F(UtWlTbm, MonitorShowClient)
        int pid = getpid();
 
        snprintf(msg, 127, "%s %d", "-show ", pid);
-       wl_tbm_monitor_request_to_sever(wl_tbm_monitor, msg);
-       ASSERT_EQ(CheckServerError(), 0);
+       SendMonitorCmd(msg);
 }
 
 TEST_F(UtWlTbm, MonitorTraceOnOffAll)
 {
-       wl_tbm_monitor_request_to_sever(wl_tbm_monitor, "-trace on all");
+       SendMonitorCmd("-trace on all");
+       SendMonitorCmd("-trace off all");
+}
+
+TEST_F(UtWlTbm, MonitorDumpSnapshot)
+{
+       SendMonitorCmd("-dump_snapshot all");
+}
+
+TEST_F(UtWlTbm, MonitorDumpQueue)
+{
+       SendMonitorCmd("-dump_queue on all");
+       SendMonitorCmd("-dump_queue off all");
+}
+
+TEST_F(UtWlTbm, SyncCreate)
+{
+       tbm_fd td;
+       tbm_surface_h tbm_surf;
+       struct wl_buffer *wl_buf;
+
+       td = tbm_sync_timeline_create();
+       ASSERT_NE(td, -1);
+
+       tbm_surf = tbm_surface_create(100, 200, TBM_FORMAT_ARGB8888);
+       ASSERT_NE(tbm_surf, nullptr);
+
+       wl_buf = wayland_tbm_client_create_buffer(wl_tbm_client, tbm_surf);
+       ASSERT_NE(wl_buf, nullptr);
        ASSERT_EQ(CheckServerError(), 0);
-       wl_tbm_monitor_request_to_sever(wl_tbm_monitor, "-trace off all");
+
+       wayland_tbm_client_set_sync_timeline(wl_tbm_client, wl_buf, td);
        ASSERT_EQ(CheckServerError(), 0);
+
+       wayland_tbm_client_destroy_buffer(wl_tbm_client, wl_buf);
+       tbm_surface_destroy(tbm_surf);
+       close(td);
 }
+
+TEST_F(UtWlTbm, SyncWait)
+{
+       tbm_fd td, fence;
+       tbm_surface_h tbm_surf;
+       struct wl_buffer *wl_buf;
+
+       td = tbm_sync_timeline_create();
+       ASSERT_NE(td, -1);
+
+       tbm_surf = tbm_surface_create(100, 200, TBM_FORMAT_ARGB8888);
+       ASSERT_NE(tbm_surf, nullptr);
+
+       wl_buf = wayland_tbm_client_create_buffer(wl_tbm_client, tbm_surf);
+       ASSERT_NE(wl_buf, nullptr);
+       ASSERT_EQ(CheckServerError(), 0);
+
+       fence = tbm_sync_fence_create(td, "test", 0);
+       ASSERT_NE(wl_buf, -1);
+
+       wayland_tbm_client_set_sync_timeline(wl_tbm_client, wl_buf, td);
+       ASSERT_EQ(CheckServerError(), 0);
+
+       wl_tbm_test_timeline_increase(wl_tbm_test, wl_buf);
+       ASSERT_EQ(CheckServerError(), 0);
+
+       ASSERT_EQ(tbm_sync_fence_wait(fence, 1), 0);
+
+       wayland_tbm_client_destroy_buffer(wl_tbm_client, wl_buf);
+       tbm_surface_destroy(tbm_surf);
+       close(fence);
+       close(td);
+}
\ No newline at end of file