From 23c8dc7b277062c3a7e0cf0ce7f8cdb28fb4fe29 Mon Sep 17 00:00:00 2001 From: Daniel Stone Date: Sat, 25 Jun 2022 03:56:45 +0100 Subject: [PATCH] tests: Check requirements after setting up args Setting up the arguments may consume some of the arguments, e.g. if we provide a config file or extra modules, then the test harness is expected to be responsible for freeing those arguments. Checking the requirements and bailing first means that we never do that, and thus skipped tests result in leaks. Flip the order so we set up the args first and skip last, so we can consistently take ownership of all the provided setup parameters. Signed-off-by: Daniel Stone --- tests/weston-test-fixture-compositor.c | 89 +++++++++++++------------- 1 file changed, 46 insertions(+), 43 deletions(-) diff --git a/tests/weston-test-fixture-compositor.c b/tests/weston-test-fixture-compositor.c index 228bb48e..2e9333a2 100644 --- a/tests/weston-test-fixture-compositor.c +++ b/tests/weston-test-fixture-compositor.c @@ -291,48 +291,8 @@ execute_compositor(const struct compositor_setup *setup, struct prog_args args; char *tmp; const char *ctmp, *drm_device; - int ret, lock_fd = -1; - - if (setenv("WESTON_MODULE_MAP", WESTON_MODULE_MAP, 0) < 0 || - setenv("WESTON_DATA_DIR", WESTON_DATA_DIR, 0) < 0) { - fprintf(stderr, "Error: environment setup failed.\n"); - return RESULT_HARD_ERROR; - } - -#ifndef BUILD_DRM_COMPOSITOR - if (setup->backend == WESTON_BACKEND_DRM) { - fprintf(stderr, "DRM-backend required but not built, skipping.\n"); - return RESULT_SKIP; - } -#endif - -#ifndef BUILD_RDP_COMPOSITOR - if (setup->backend == WESTON_BACKEND_RDP) { - fprintf(stderr, "RDP-backend required but not built, skipping.\n"); - return RESULT_SKIP; - } -#endif - -#ifndef BUILD_WAYLAND_COMPOSITOR - if (setup->backend == WESTON_BACKEND_WAYLAND) { - fprintf(stderr, "wayland-backend required but not built, skipping.\n"); - return RESULT_SKIP; - } -#endif - -#ifndef BUILD_X11_COMPOSITOR - if (setup->backend == WESTON_BACKEND_X11) { - fprintf(stderr, "X11-backend required but not built, skipping.\n"); - return RESULT_SKIP; - } -#endif - -#ifndef ENABLE_EGL - if (setup->renderer == RENDERER_GL) { - fprintf(stderr, "GL-renderer required but not built, skipping.\n"); - return RESULT_SKIP; - } -#endif + int lock_fd = -1; + int ret = RESULT_OK; prog_args_init(&args); @@ -424,7 +384,50 @@ execute_compositor(const struct compositor_setup *setup, test_data.test_quirks = setup->test_quirks; test_data.test_private_data = data; prog_args_save(&args); - ret = wet_main(args.argc, args.argv, &test_data); + + if (setenv("WESTON_MODULE_MAP", WESTON_MODULE_MAP, 0) < 0 || + setenv("WESTON_DATA_DIR", WESTON_DATA_DIR, 0) < 0) { + fprintf(stderr, "Error: environment setup failed.\n"); + ret = RESULT_HARD_ERROR; + } + +#ifndef BUILD_DRM_COMPOSITOR + if (setup->backend == WESTON_BACKEND_DRM) { + fprintf(stderr, "DRM-backend required but not built, skipping.\n"); + ret = RESULT_SKIP; + } +#endif + +#ifndef BUILD_RDP_COMPOSITOR + if (setup->backend == WESTON_BACKEND_RDP) { + fprintf(stderr, "RDP-backend required but not built, skipping.\n"); + ret = RESULT_SKIP; + } +#endif + +#ifndef BUILD_WAYLAND_COMPOSITOR + if (setup->backend == WESTON_BACKEND_WAYLAND) { + fprintf(stderr, "wayland-backend required but not built, skipping.\n"); + ret = RESULT_SKIP; + } +#endif + +#ifndef BUILD_X11_COMPOSITOR + if (setup->backend == WESTON_BACKEND_X11) { + fprintf(stderr, "X11-backend required but not built, skipping.\n"); + ret = RESULT_SKIP; + } +#endif + +#ifndef ENABLE_EGL + if (setup->renderer == RENDERER_GL) { + fprintf(stderr, "GL-renderer required but not built, skipping.\n"); + ret = RESULT_SKIP; + } +#endif + + if (ret == RESULT_OK) + ret = wet_main(args.argc, args.argv, &test_data); out: prog_args_fini(&args);