Pekka Paalanen | f5b74f7 | 2015-03-25 12:50:31 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2015 Collabora, Ltd. |
| 3 | * |
Bryce Harrington | 2cc9297 | 2015-06-11 15:39:40 -0700 | [diff] [blame] | 4 | * Permission is hereby granted, free of charge, to any person obtaining |
| 5 | * a copy of this software and associated documentation files (the |
| 6 | * "Software"), to deal in the Software without restriction, including |
| 7 | * without limitation the rights to use, copy, modify, merge, publish, |
| 8 | * distribute, sublicense, and/or sell copies of the Software, and to |
| 9 | * permit persons to whom the Software is furnished to do so, subject to |
| 10 | * the following conditions: |
Pekka Paalanen | f5b74f7 | 2015-03-25 12:50:31 +0200 | [diff] [blame] | 11 | * |
Bryce Harrington | 2cc9297 | 2015-06-11 15:39:40 -0700 | [diff] [blame] | 12 | * The above copyright notice and this permission notice (including the |
| 13 | * next paragraph) shall be included in all copies or substantial |
| 14 | * portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 17 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 18 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 19 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
| 20 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
| 21 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 23 | * SOFTWARE. |
Pekka Paalanen | f5b74f7 | 2015-03-25 12:50:31 +0200 | [diff] [blame] | 24 | */ |
| 25 | |
| 26 | #include "config.h" |
| 27 | |
Jussi Kukkonen | 649bbce | 2016-07-19 14:16:27 +0300 | [diff] [blame] | 28 | #include <stdint.h> |
Pekka Paalanen | f5b74f7 | 2015-03-25 12:50:31 +0200 | [diff] [blame] | 29 | #include <stdio.h> |
| 30 | #include <string.h> |
| 31 | |
Jon Cruz | 35b2eaa | 2015-06-15 15:37:08 -0700 | [diff] [blame] | 32 | #include "shared/helpers.h" |
Bryce Harrington | e99e4bf | 2016-03-16 14:15:18 -0700 | [diff] [blame] | 33 | #include "shared/xalloc.h" |
Pekka Paalanen | f5b74f7 | 2015-03-25 12:50:31 +0200 | [diff] [blame] | 34 | #include "weston-test-client-helper.h" |
| 35 | #include "ivi-application-client-protocol.h" |
| 36 | #include "ivi-test.h" |
| 37 | |
| 38 | struct runner { |
| 39 | struct client *client; |
| 40 | struct weston_test_runner *test_runner; |
| 41 | int done; |
| 42 | }; |
| 43 | |
| 44 | static void |
| 45 | runner_finished_handler(void *data, struct weston_test_runner *test_runner) |
| 46 | { |
| 47 | struct runner *runner = data; |
| 48 | |
| 49 | runner->done = 1; |
| 50 | } |
| 51 | |
| 52 | static const struct weston_test_runner_listener test_runner_listener = { |
| 53 | runner_finished_handler |
| 54 | }; |
| 55 | |
| 56 | static struct runner * |
| 57 | client_create_runner(struct client *client) |
| 58 | { |
| 59 | struct runner *runner; |
| 60 | struct global *g; |
| 61 | struct global *global_runner = NULL; |
| 62 | |
| 63 | runner = xzalloc(sizeof(*runner)); |
| 64 | runner->client = client; |
| 65 | |
| 66 | wl_list_for_each(g, &client->global_list, link) { |
| 67 | if (strcmp(g->interface, "weston_test_runner")) |
| 68 | continue; |
| 69 | |
| 70 | if (global_runner) |
| 71 | assert(0 && "multiple weston_test_runner objects"); |
| 72 | |
| 73 | global_runner = g; |
| 74 | } |
| 75 | |
| 76 | assert(global_runner && "no weston_test_runner found"); |
| 77 | assert(global_runner->version == 1); |
| 78 | |
| 79 | runner->test_runner = wl_registry_bind(client->wl_registry, |
| 80 | global_runner->name, |
| 81 | &weston_test_runner_interface, |
| 82 | 1); |
| 83 | assert(runner->test_runner); |
| 84 | |
| 85 | weston_test_runner_add_listener(runner->test_runner, |
| 86 | &test_runner_listener, runner); |
| 87 | |
| 88 | return runner; |
| 89 | } |
| 90 | |
| 91 | static void |
| 92 | runner_destroy(struct runner *runner) |
| 93 | { |
| 94 | weston_test_runner_destroy(runner->test_runner); |
| 95 | client_roundtrip(runner->client); |
| 96 | free(runner); |
| 97 | } |
| 98 | |
| 99 | static void |
| 100 | runner_run(struct runner *runner, const char *test_name) |
| 101 | { |
| 102 | fprintf(stderr, "weston_test_runner.run(\"%s\")\n", test_name); |
| 103 | |
| 104 | runner->done = 0; |
| 105 | weston_test_runner_run(runner->test_runner, test_name); |
| 106 | |
| 107 | while (!runner->done) { |
| 108 | if (wl_display_dispatch(runner->client->wl_display) < 0) |
| 109 | assert(0 && "runner wait"); |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | static struct ivi_application * |
| 114 | get_ivi_application(struct client *client) |
| 115 | { |
| 116 | struct global *g; |
| 117 | struct global *global_iviapp = NULL; |
| 118 | static struct ivi_application *iviapp; |
| 119 | |
| 120 | if (iviapp) |
| 121 | return iviapp; |
| 122 | |
| 123 | wl_list_for_each(g, &client->global_list, link) { |
| 124 | if (strcmp(g->interface, "ivi_application")) |
| 125 | continue; |
| 126 | |
| 127 | if (global_iviapp) |
| 128 | assert(0 && "multiple ivi_application objects"); |
| 129 | |
| 130 | global_iviapp = g; |
| 131 | } |
| 132 | |
| 133 | assert(global_iviapp && "no ivi_application found"); |
| 134 | |
| 135 | assert(global_iviapp->version == 1); |
| 136 | |
| 137 | iviapp = wl_registry_bind(client->wl_registry, global_iviapp->name, |
| 138 | &ivi_application_interface, 1); |
| 139 | assert(iviapp); |
| 140 | |
| 141 | return iviapp; |
| 142 | } |
| 143 | |
| 144 | struct ivi_window { |
| 145 | struct wl_surface *wl_surface; |
| 146 | struct ivi_surface *ivi_surface; |
| 147 | uint32_t ivi_id; |
| 148 | }; |
| 149 | |
| 150 | static struct ivi_window * |
| 151 | client_create_ivi_window(struct client *client, uint32_t ivi_id) |
| 152 | { |
| 153 | struct ivi_application *iviapp; |
| 154 | struct ivi_window *wnd; |
| 155 | |
| 156 | iviapp = get_ivi_application(client); |
| 157 | |
| 158 | wnd = xzalloc(sizeof(*wnd)); |
| 159 | wnd->wl_surface = wl_compositor_create_surface(client->wl_compositor); |
| 160 | wnd->ivi_surface = ivi_application_surface_create(iviapp, ivi_id, |
| 161 | wnd->wl_surface); |
| 162 | wnd->ivi_id = ivi_id; |
| 163 | |
| 164 | return wnd; |
| 165 | } |
| 166 | |
| 167 | static void |
| 168 | ivi_window_destroy(struct ivi_window *wnd) |
| 169 | { |
| 170 | ivi_surface_destroy(wnd->ivi_surface); |
| 171 | wl_surface_destroy(wnd->wl_surface); |
| 172 | free(wnd); |
| 173 | } |
| 174 | |
| 175 | /******************************** tests ********************************/ |
| 176 | |
| 177 | /* |
| 178 | * This is a test program, launched by ivi_layout-test-plugin.c. Each TEST() |
| 179 | * is forked and exec'd as usual with the weston-test-runner framework. |
| 180 | * |
| 181 | * These tests make use of weston_test_runner global interface exposed by |
| 182 | * ivi_layout-test-plugin.c. This allows these tests to trigger compositor-side |
| 183 | * checks. |
| 184 | * |
| 185 | * See ivi_layout-test-plugin.c for further details. |
| 186 | */ |
| 187 | |
| 188 | /** |
| 189 | * RUNNER_TEST() names are defined in ivi_layout-test-plugin.c. |
| 190 | * Each RUNNER_TEST name listed here uses the same simple initial client setup. |
| 191 | */ |
| 192 | const char * const basic_test_names[] = { |
| 193 | "surface_visibility", |
| 194 | "surface_opacity", |
Nobuhiko Tanibata | 23d9582 | 2015-06-22 15:33:17 +0900 | [diff] [blame] | 195 | "surface_orientation", |
| 196 | "surface_dimension", |
| 197 | "surface_position", |
| 198 | "surface_destination_rectangle", |
| 199 | "surface_source_rectangle", |
Nobuhiko Tanibata | c74bafa | 2015-06-22 15:33:26 +0900 | [diff] [blame] | 200 | "surface_bad_opacity", |
Nobuhiko Tanibata | 915303a | 2015-06-22 15:35:58 +0900 | [diff] [blame] | 201 | "surface_properties_changed_notification", |
Nobuhiko Tanibata | 0af22d4 | 2015-06-22 15:36:21 +0900 | [diff] [blame] | 202 | "surface_bad_properties_changed_notification", |
Ucan, Emre (ADITG/SW1) | 37d25bb | 2016-06-07 09:40:21 +0000 | [diff] [blame] | 203 | "surface_on_many_layer", |
Nobuhiko Tanibata | c74bafa | 2015-06-22 15:33:26 +0900 | [diff] [blame] | 204 | }; |
| 205 | |
| 206 | const char * const surface_property_commit_changes_test_names[] = { |
| 207 | "commit_changes_after_visibility_set_surface_destroy", |
| 208 | "commit_changes_after_opacity_set_surface_destroy", |
| 209 | "commit_changes_after_orientation_set_surface_destroy", |
Nobuhiko Tanibata | c74bafa | 2015-06-22 15:33:26 +0900 | [diff] [blame] | 210 | "commit_changes_after_source_rectangle_set_surface_destroy", |
| 211 | "commit_changes_after_destination_rectangle_set_surface_destroy", |
Pekka Paalanen | f5b74f7 | 2015-03-25 12:50:31 +0200 | [diff] [blame] | 212 | }; |
| 213 | |
Nobuhiko Tanibata | d364393 | 2015-06-22 15:34:09 +0900 | [diff] [blame] | 214 | const char * const render_order_test_names[] = { |
| 215 | "layer_render_order", |
Nobuhiko Tanibata | 0671b4d | 2015-06-22 15:34:42 +0900 | [diff] [blame] | 216 | "layer_bad_render_order", |
Ucan, Emre (ADITG/SW1) | 5d6aa9b | 2017-01-18 15:25:35 +0000 | [diff] [blame^] | 217 | "layer_add_surfaces", |
Nobuhiko Tanibata | d364393 | 2015-06-22 15:34:09 +0900 | [diff] [blame] | 218 | }; |
| 219 | |
Pekka Paalanen | f5b74f7 | 2015-03-25 12:50:31 +0200 | [diff] [blame] | 220 | TEST_P(ivi_layout_runner, basic_test_names) |
| 221 | { |
| 222 | /* an element from basic_test_names */ |
| 223 | const char * const *test_name = data; |
| 224 | struct client *client; |
| 225 | struct runner *runner; |
| 226 | struct ivi_window *wnd; |
| 227 | |
| 228 | client = create_client(); |
| 229 | runner = client_create_runner(client); |
| 230 | |
| 231 | wnd = client_create_ivi_window(client, IVI_TEST_SURFACE_ID(0)); |
| 232 | |
| 233 | runner_run(runner, *test_name); |
| 234 | |
| 235 | ivi_window_destroy(wnd); |
| 236 | runner_destroy(runner); |
| 237 | } |
| 238 | |
| 239 | TEST(ivi_layout_surface_create) |
| 240 | { |
| 241 | struct client *client; |
| 242 | struct runner *runner; |
| 243 | struct ivi_window *winds[2]; |
| 244 | |
| 245 | client = create_client(); |
| 246 | runner = client_create_runner(client); |
| 247 | |
| 248 | winds[0] = client_create_ivi_window(client, IVI_TEST_SURFACE_ID(0)); |
| 249 | winds[1] = client_create_ivi_window(client, IVI_TEST_SURFACE_ID(1)); |
| 250 | |
| 251 | runner_run(runner, "surface_create_p1"); |
| 252 | |
| 253 | ivi_window_destroy(winds[0]); |
| 254 | |
| 255 | runner_run(runner, "surface_create_p2"); |
| 256 | |
| 257 | ivi_window_destroy(winds[1]); |
| 258 | runner_destroy(runner); |
| 259 | } |
Nobuhiko Tanibata | c74bafa | 2015-06-22 15:33:26 +0900 | [diff] [blame] | 260 | |
| 261 | TEST_P(commit_changes_after_properties_set_surface_destroy, surface_property_commit_changes_test_names) |
| 262 | { |
| 263 | /* an element from surface_property_commit_changes_test_names */ |
| 264 | const char * const *test_name = data; |
| 265 | struct client *client; |
| 266 | struct runner *runner; |
| 267 | struct ivi_window *wnd; |
| 268 | |
| 269 | client = create_client(); |
| 270 | runner = client_create_runner(client); |
| 271 | |
| 272 | wnd = client_create_ivi_window(client, IVI_TEST_SURFACE_ID(0)); |
| 273 | |
| 274 | runner_run(runner, *test_name); |
| 275 | |
| 276 | ivi_window_destroy(wnd); |
| 277 | |
| 278 | runner_run(runner, "ivi_layout_commit_changes"); |
| 279 | |
| 280 | runner_destroy(runner); |
| 281 | } |
| 282 | |
| 283 | TEST(get_surface_after_destroy_ivi_surface) |
| 284 | { |
| 285 | struct client *client; |
| 286 | struct runner *runner; |
| 287 | struct ivi_window *wnd; |
| 288 | |
| 289 | client = create_client(); |
| 290 | runner = client_create_runner(client); |
| 291 | |
| 292 | wnd = client_create_ivi_window(client, IVI_TEST_SURFACE_ID(0)); |
| 293 | |
| 294 | ivi_surface_destroy(wnd->ivi_surface); |
| 295 | |
| 296 | runner_run(runner, "get_surface_after_destroy_surface"); |
| 297 | |
| 298 | wl_surface_destroy(wnd->wl_surface); |
| 299 | free(wnd); |
| 300 | runner_destroy(runner); |
| 301 | } |
| 302 | |
| 303 | TEST(get_surface_after_destroy_wl_surface) |
| 304 | { |
| 305 | struct client *client; |
| 306 | struct runner *runner; |
| 307 | struct ivi_window *wnd; |
| 308 | |
| 309 | client = create_client(); |
| 310 | runner = client_create_runner(client); |
| 311 | |
| 312 | wnd = client_create_ivi_window(client, IVI_TEST_SURFACE_ID(0)); |
| 313 | |
| 314 | wl_surface_destroy(wnd->wl_surface); |
| 315 | |
| 316 | runner_run(runner, "get_surface_after_destroy_surface"); |
| 317 | |
| 318 | ivi_surface_destroy(wnd->ivi_surface); |
| 319 | free(wnd); |
| 320 | runner_destroy(runner); |
| 321 | } |
Nobuhiko Tanibata | d364393 | 2015-06-22 15:34:09 +0900 | [diff] [blame] | 322 | |
| 323 | TEST_P(ivi_layout_layer_render_order_runner, render_order_test_names) |
| 324 | { |
| 325 | /* an element from render_order_test_names */ |
| 326 | const char * const *test_name = data; |
| 327 | struct client *client; |
| 328 | struct runner *runner; |
| 329 | struct ivi_window *winds[3]; |
| 330 | |
| 331 | client = create_client(); |
| 332 | runner = client_create_runner(client); |
| 333 | |
| 334 | winds[0] = client_create_ivi_window(client, IVI_TEST_SURFACE_ID(0)); |
| 335 | winds[1] = client_create_ivi_window(client, IVI_TEST_SURFACE_ID(1)); |
| 336 | winds[2] = client_create_ivi_window(client, IVI_TEST_SURFACE_ID(2)); |
| 337 | |
| 338 | runner_run(runner, *test_name); |
| 339 | |
| 340 | ivi_window_destroy(winds[0]); |
| 341 | ivi_window_destroy(winds[1]); |
| 342 | ivi_window_destroy(winds[2]); |
| 343 | runner_destroy(runner); |
| 344 | } |
Nobuhiko Tanibata | 0671b4d | 2015-06-22 15:34:42 +0900 | [diff] [blame] | 345 | |
| 346 | TEST(destroy_surface_after_layer_render_order) |
| 347 | { |
| 348 | struct client *client; |
| 349 | struct runner *runner; |
| 350 | struct ivi_window *winds[3]; |
| 351 | |
| 352 | client = create_client(); |
| 353 | runner = client_create_runner(client); |
| 354 | |
| 355 | winds[0] = client_create_ivi_window(client, IVI_TEST_SURFACE_ID(0)); |
| 356 | winds[1] = client_create_ivi_window(client, IVI_TEST_SURFACE_ID(1)); |
| 357 | winds[2] = client_create_ivi_window(client, IVI_TEST_SURFACE_ID(2)); |
| 358 | |
| 359 | runner_run(runner, "test_layer_render_order_destroy_one_surface_p1"); |
| 360 | |
| 361 | ivi_window_destroy(winds[1]); |
| 362 | |
| 363 | runner_run(runner, "test_layer_render_order_destroy_one_surface_p2"); |
| 364 | |
| 365 | ivi_window_destroy(winds[0]); |
| 366 | ivi_window_destroy(winds[2]); |
| 367 | runner_destroy(runner); |
| 368 | } |
| 369 | |
| 370 | TEST(commit_changes_after_render_order_set_surface_destroy) |
| 371 | { |
| 372 | struct client *client; |
| 373 | struct runner *runner; |
| 374 | struct ivi_window *winds[3]; |
| 375 | |
| 376 | client = create_client(); |
| 377 | runner = client_create_runner(client); |
| 378 | |
| 379 | winds[0] = client_create_ivi_window(client, IVI_TEST_SURFACE_ID(0)); |
| 380 | winds[1] = client_create_ivi_window(client, IVI_TEST_SURFACE_ID(1)); |
| 381 | winds[2] = client_create_ivi_window(client, IVI_TEST_SURFACE_ID(2)); |
| 382 | |
| 383 | runner_run(runner, "commit_changes_after_render_order_set_surface_destroy"); |
| 384 | |
| 385 | ivi_window_destroy(winds[1]); |
| 386 | |
| 387 | runner_run(runner, "ivi_layout_commit_changes"); |
| 388 | runner_run(runner, "cleanup_layer"); |
| 389 | |
| 390 | ivi_window_destroy(winds[0]); |
| 391 | ivi_window_destroy(winds[2]); |
| 392 | runner_destroy(runner); |
| 393 | } |
Nobuhiko Tanibata | 915303a | 2015-06-22 15:35:58 +0900 | [diff] [blame] | 394 | |
| 395 | TEST(ivi_layout_surface_configure_notification) |
| 396 | { |
| 397 | struct client *client; |
| 398 | struct runner *runner; |
| 399 | struct ivi_window *wind; |
Pekka Paalanen | 41d5231 | 2016-05-20 18:01:05 +0300 | [diff] [blame] | 400 | struct buffer *buffer; |
Nobuhiko Tanibata | 915303a | 2015-06-22 15:35:58 +0900 | [diff] [blame] | 401 | |
| 402 | client = create_client(); |
| 403 | runner = client_create_runner(client); |
| 404 | |
| 405 | runner_run(runner, "surface_configure_notification_p1"); |
| 406 | |
| 407 | wind = client_create_ivi_window(client, IVI_TEST_SURFACE_ID(0)); |
| 408 | |
Pekka Paalanen | 41d5231 | 2016-05-20 18:01:05 +0300 | [diff] [blame] | 409 | buffer = create_shm_buffer_a8r8g8b8(client, 200, 300); |
Nobuhiko Tanibata | 915303a | 2015-06-22 15:35:58 +0900 | [diff] [blame] | 410 | |
Pekka Paalanen | 41d5231 | 2016-05-20 18:01:05 +0300 | [diff] [blame] | 411 | wl_surface_attach(wind->wl_surface, buffer->proxy, 0, 0); |
Nobuhiko Tanibata | 915303a | 2015-06-22 15:35:58 +0900 | [diff] [blame] | 412 | wl_surface_damage(wind->wl_surface, 0, 0, 20, 30); |
| 413 | wl_surface_commit(wind->wl_surface); |
| 414 | |
| 415 | runner_run(runner, "surface_configure_notification_p2"); |
| 416 | |
Pekka Paalanen | 41d5231 | 2016-05-20 18:01:05 +0300 | [diff] [blame] | 417 | wl_surface_attach(wind->wl_surface, buffer->proxy, 0, 0); |
Nobuhiko Tanibata | 915303a | 2015-06-22 15:35:58 +0900 | [diff] [blame] | 418 | wl_surface_damage(wind->wl_surface, 0, 0, 40, 50); |
| 419 | wl_surface_commit(wind->wl_surface); |
| 420 | |
| 421 | runner_run(runner, "surface_configure_notification_p3"); |
| 422 | |
Pekka Paalanen | 41d5231 | 2016-05-20 18:01:05 +0300 | [diff] [blame] | 423 | buffer_destroy(buffer); |
Nobuhiko Tanibata | 915303a | 2015-06-22 15:35:58 +0900 | [diff] [blame] | 424 | ivi_window_destroy(wind); |
| 425 | runner_destroy(runner); |
| 426 | } |
| 427 | |
| 428 | TEST(ivi_layout_surface_create_notification) |
| 429 | { |
| 430 | struct client *client; |
| 431 | struct runner *runner; |
| 432 | struct ivi_window *wind; |
| 433 | |
| 434 | client = create_client(); |
| 435 | runner = client_create_runner(client); |
| 436 | |
| 437 | runner_run(runner, "surface_create_notification_p1"); |
| 438 | |
| 439 | wind = client_create_ivi_window(client, IVI_TEST_SURFACE_ID(0)); |
| 440 | |
| 441 | runner_run(runner, "surface_create_notification_p2"); |
| 442 | |
| 443 | ivi_window_destroy(wind); |
| 444 | wind = client_create_ivi_window(client, IVI_TEST_SURFACE_ID(0)); |
| 445 | runner_run(runner, "surface_create_notification_p3"); |
| 446 | |
| 447 | ivi_window_destroy(wind); |
| 448 | runner_destroy(runner); |
| 449 | } |
| 450 | |
| 451 | TEST(ivi_layout_surface_remove_notification) |
| 452 | { |
| 453 | struct client *client; |
| 454 | struct runner *runner; |
| 455 | struct ivi_window *wind; |
| 456 | |
| 457 | client = create_client(); |
| 458 | runner = client_create_runner(client); |
| 459 | |
| 460 | wind = client_create_ivi_window(client, IVI_TEST_SURFACE_ID(0)); |
| 461 | runner_run(runner, "surface_remove_notification_p1"); |
| 462 | ivi_window_destroy(wind); |
| 463 | |
| 464 | runner_run(runner, "surface_remove_notification_p2"); |
| 465 | |
| 466 | wind = client_create_ivi_window(client, IVI_TEST_SURFACE_ID(0)); |
| 467 | ivi_window_destroy(wind); |
| 468 | runner_run(runner, "surface_remove_notification_p3"); |
| 469 | |
| 470 | runner_destroy(runner); |
| 471 | } |