From 960ca8255209ddd9191958b375edff45b69c92a3 Mon Sep 17 00:00:00 2001 From: Pauli Virtanen Date: Sat, 14 Oct 2023 18:02:37 +0300 Subject: [PATCH] spa: deduplicate test-helper.h --- spa/plugins/audioconvert/meson.build | 5 +- spa/plugins/audiomixer/meson.build | 4 +- spa/plugins/audiomixer/test-helper.h | 97 ------------------- .../{audioconvert => test}/test-helper.h | 0 4 files changed, 5 insertions(+), 101 deletions(-) delete mode 100644 spa/plugins/audiomixer/test-helper.h rename spa/plugins/{audioconvert => test}/test-helper.h (100%) diff --git a/spa/plugins/audioconvert/meson.build b/spa/plugins/audioconvert/meson.build index dfc1dcc45..d18f64b53 100644 --- a/spa/plugins/audioconvert/meson.build +++ b/spa/plugins/audioconvert/meson.build @@ -135,6 +135,7 @@ test_lib = static_library('test_lib', dependencies : [ spa_dep ], install : false ) +test_inc = include_directories('../test') test_apps = [ 'test-audioadapter', @@ -149,7 +150,7 @@ foreach a : test_apps test(a, executable(a, a + '.c', dependencies : [ spa_dep, dl_lib, pthread_lib, mathlib, audioconvert_dep, spa_audioconvert_dep ], - include_directories : [ configinc ], + include_directories : [ configinc, test_inc ], link_with : [ test_lib ], install_rpath : spa_plugindir / 'audioconvert', c_args : [ simd_cargs ], @@ -180,7 +181,7 @@ foreach a : benchmark_apps benchmark(a, executable(a, a + '.c', dependencies : [ spa_dep, dl_lib, pthread_lib, mathlib, audioconvert_dep, spa_audioconvert_dep ], - include_directories : [ configinc ], + include_directories : [ configinc, test_inc ], c_args : [ simd_cargs ], install_rpath : spa_plugindir / 'audioconvert', install : installed_tests_enabled, diff --git a/spa/plugins/audiomixer/meson.build b/spa/plugins/audiomixer/meson.build index 5a4a1fbfe..65aafee20 100644 --- a/spa/plugins/audiomixer/meson.build +++ b/spa/plugins/audiomixer/meson.build @@ -74,7 +74,7 @@ foreach a : test_apps test(a, executable(a, a + '.c', dependencies : [ spa_dep, dl_lib, pthread_lib, mathlib, audiomixer_dep ], - include_directories : [ configinc ], + include_directories : [ configinc, test_inc ], link_with : [ test_lib ], install_rpath : spa_plugindir / 'audiomixer', c_args : [ simd_cargs ], @@ -104,7 +104,7 @@ foreach a : benchmark_apps benchmark(a, executable(a, a + '.c', dependencies : [ spa_dep, dl_lib, pthread_lib, mathlib, audiomixer_dep ], - include_directories : [ configinc ], + include_directories : [ configinc, test_inc ], c_args : [ simd_cargs ], install_rpath : spa_plugindir / 'audiomixer', install : installed_tests_enabled, diff --git a/spa/plugins/audiomixer/test-helper.h b/spa/plugins/audiomixer/test-helper.h deleted file mode 100644 index 8c789bd45..000000000 --- a/spa/plugins/audiomixer/test-helper.h +++ /dev/null @@ -1,97 +0,0 @@ -#include - -#include -#include -#include -#include -#include - -static inline const struct spa_handle_factory *get_factory(spa_handle_factory_enum_func_t enum_func, - const char *name, uint32_t version) -{ - uint32_t i; - int res; - const struct spa_handle_factory *factory; - - for (i = 0;;) { - if ((res = enum_func(&factory, &i)) <= 0) { - if (res < 0) - errno = -res; - break; - } - if (factory->version >= version && - !strcmp(factory->name, name)) - return factory; - } - return NULL; -} - -static inline struct spa_handle *load_handle(const struct spa_support *support, - uint32_t n_support, const char *lib, const char *name) -{ - int res, len; - void *hnd; - spa_handle_factory_enum_func_t enum_func; - const struct spa_handle_factory *factory; - struct spa_handle *handle; - const char *str; - char *path; - - if ((str = getenv("SPA_PLUGIN_DIR")) == NULL) - str = PLUGINDIR; - - len = strlen(str) + strlen(lib) + 2; - path = alloca(len); - snprintf(path, len, "%s/%s", str, lib); - - if ((hnd = dlopen(path, RTLD_NOW)) == NULL) { - fprintf(stderr, "can't load %s: %s\n", lib, dlerror()); - res = -ENOENT; - goto error; - } - if ((enum_func = dlsym(hnd, SPA_HANDLE_FACTORY_ENUM_FUNC_NAME)) == NULL) { - fprintf(stderr, "can't find enum function\n"); - res = -ENXIO; - goto error_close; - } - - if ((factory = get_factory(enum_func, name, SPA_VERSION_HANDLE_FACTORY)) == NULL) { - fprintf(stderr, "can't find factory\n"); - res = -ENOENT; - goto error_close; - } - handle = calloc(1, spa_handle_factory_get_size(factory, NULL)); - if ((res = spa_handle_factory_init(factory, handle, - NULL, support, n_support)) < 0) { - fprintf(stderr, "can't make factory instance: %d\n", res); - goto error_close; - } - return handle; - -error_close: - dlclose(hnd); -error: - errno = -res; - return NULL; -} - -static inline uint32_t get_cpu_flags(void) -{ - struct spa_handle *handle; - uint32_t flags; - void *iface; - int res; - - handle = load_handle(NULL, 0, "support/libspa-support.so", SPA_NAME_SUPPORT_CPU); - if (handle == NULL) - return 0; - if ((res = spa_handle_get_interface(handle, SPA_TYPE_INTERFACE_CPU, &iface)) < 0) { - fprintf(stderr, "can't get CPU interface %s\n", spa_strerror(res)); - return 0; - } - flags = spa_cpu_get_flags((struct spa_cpu*)iface); - - free(handle); - - return flags; -} diff --git a/spa/plugins/audioconvert/test-helper.h b/spa/plugins/test/test-helper.h similarity index 100% rename from spa/plugins/audioconvert/test-helper.h rename to spa/plugins/test/test-helper.h