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