Browse Source

Use unique test bundle names so tests can run in parallel

add_opts_to_lv2apply
David Robillard 8 months ago
parent
commit
830c41e979
  1. 22
      src/filesystem.c
  2. 15
      src/filesystem.h
  3. 32
      test/lilv_test_utils.c
  4. 12
      test/lilv_test_utils.h
  5. 6
      test/test_bad_port_index.c
  6. 6
      test/test_bad_port_symbol.c
  7. 7
      test/test_classes.c
  8. 5
      test/test_discovery.c
  9. 5
      test/test_get_symbol.c
  10. 5
      test/test_no_author.c
  11. 5
      test/test_no_verify.c
  12. 9
      test/test_plugin.c
  13. 5
      test/test_port.c
  14. 5
      test/test_preset.c
  15. 5
      test/test_project.c
  16. 6
      test/test_project_no_author.c
  17. 5
      test/test_prototype.c
  18. 14
      test/test_reload_bundle.c
  19. 6
      test/test_ui.c
  20. 5
      test/test_value.c
  21. 5
      test/test_verify.c

22
src/filesystem.c

@ -426,7 +426,7 @@ lilv_dir_for_each(const char* path,
}
char*
lilv_create_temporary_directory(const char* pattern)
lilv_create_temporary_directory_in(const char* pattern, const char* parent)
{
#ifdef _WIN32
static const char chars[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
@ -438,13 +438,10 @@ lilv_create_temporary_directory(const char* pattern)
return NULL;
}
char* const tmpdir = lilv_temp_directory_path();
char* const path_pattern = lilv_path_join(tmpdir, pattern);
char* const path_pattern = lilv_path_join(parent, pattern);
const size_t path_pattern_len = strlen(path_pattern);
char* const suffix = path_pattern + path_pattern_len - 6;
free(tmpdir);
for (unsigned attempt = 0; attempt < 128; ++attempt) {
for (unsigned i = 0; i < 6; ++i) {
suffix[i] = chars[rand() % n_chars];
@ -457,14 +454,23 @@ lilv_create_temporary_directory(const char* pattern)
return NULL;
#else
char* const tmpdir = lilv_temp_directory_path();
char* const path_pattern = lilv_path_join(tmpdir, pattern);
char* const path_pattern = lilv_path_join(parent, pattern);
free(tmpdir);
return mkdtemp(path_pattern); // NOLINT (not a leak)
#endif
}
char*
lilv_create_temporary_directory(const char* pattern)
{
char* const tmpdir = lilv_temp_directory_path();
char* const result = lilv_create_temporary_directory_in(pattern, tmpdir);
free(tmpdir);
return result;
}
int
lilv_create_directories(const char* dir_path)
{

15
src/filesystem.h

@ -146,12 +146,21 @@ lilv_dir_for_each(const char* path,
void (*f)(const char* path, const char* name, void* data));
/**
Create a unique temporary directory.
Create a unique temporary directory in a specific directory.
The last six characters of `pattern` must be `XXXXXX` and will be replaced
with random characters. This works roughly like mkdtemp, except the pattern
should only be a directory name, not a full path. The returned path will be
in a suitable system temporary directory.
should only be a directory name, not a full path. The created path will be
a child of the given parent directory.
*/
char*
lilv_create_temporary_directory_in(const char* pattern, const char* parent);
/**
Create a unique temporary directory.
This is like lilv_create_temporary_directory_in(), except it creates the
directory in the system temporary directory.
*/
char*
lilv_create_temporary_directory(const char* pattern);

32
test/lilv_test_utils.c

@ -71,14 +71,19 @@ lilv_test_env_free(LilvTestEnv* env)
}
int
create_bundle(LilvTestEnv* env, const char* manifest, const char* plugin)
create_bundle(LilvTestEnv* env,
const char* name,
const char* manifest,
const char* plugin)
{
{
static const char* const bundle_path = "/test_lv2_path/lilv-test.lv2";
char* const test_dir = lilv_path_canonical(LILV_TEST_DIR);
char* const bundle_dir = lilv_path_join(test_dir, name);
char* const test_path = lilv_path_canonical(LILV_TEST_DIR);
env->test_bundle_path = lilv_strjoin(test_path, bundle_path, NULL);
lilv_free(test_path);
env->test_bundle_path = lilv_path_join(bundle_dir, "");
lilv_free(bundle_dir);
lilv_free(test_dir);
}
if (lilv_create_directories(env->test_bundle_path)) {
@ -92,11 +97,10 @@ create_bundle(LilvTestEnv* env, const char* manifest, const char* plugin)
SerdNode s = serd_node_new_file_uri(
(const uint8_t*)env->test_bundle_path, NULL, NULL, true);
env->test_bundle_uri = lilv_strjoin((const char*)s.buf, "/", NULL);
env->test_bundle_uri = lilv_new_uri(env->world, (const char*)s.buf);
env->test_manifest_path =
lilv_strjoin(env->test_bundle_path, "/manifest.ttl", NULL);
env->test_content_path =
lilv_strjoin(env->test_bundle_path, "/plugin.ttl", NULL);
lilv_path_join(env->test_bundle_path, "manifest.ttl");
env->test_content_path = lilv_path_join(env->test_bundle_path, "plugin.ttl");
serd_node_free(&s);
@ -130,13 +134,17 @@ create_bundle(LilvTestEnv* env, const char* manifest, const char* plugin)
}
int
start_bundle(LilvTestEnv* env, const char* manifest, const char* plugin)
start_bundle(LilvTestEnv* env,
const char* name,
const char* manifest,
const char* plugin)
{
if (create_bundle(env, manifest, plugin)) {
if (create_bundle(env, name, manifest, plugin)) {
return 1;
}
lilv_world_load_all(env->world);
lilv_world_load_bundle(env->world, env->test_bundle_uri);
return 0;
}

12
test/lilv_test_utils.h

@ -55,7 +55,7 @@ typedef struct {
LilvNode* plugin1_uri;
LilvNode* plugin2_uri;
char* test_bundle_path;
char* test_bundle_uri;
LilvNode* test_bundle_uri;
char* test_manifest_path;
char* test_content_path;
int test_count;
@ -72,11 +72,17 @@ lilv_test_env_free(LilvTestEnv* env);
// Create a bundle with a manifest and plugin files, without loading anything
int
create_bundle(LilvTestEnv* env, const char* manifest, const char* plugin);
create_bundle(LilvTestEnv* env,
const char* name,
const char* manifest,
const char* plugin);
// Create a bundle with a manifest and plugin files, then load everything
int
start_bundle(LilvTestEnv* env, const char* manifest, const char* plugin);
start_bundle(LilvTestEnv* env,
const char* name,
const char* manifest,
const char* plugin);
// Remove the created bundle from the file system and free its paths in `env`
void

6
test/test_bad_port_index.c

@ -41,10 +41,14 @@ main(void)
LilvTestEnv* const env = lilv_test_env_new();
LilvWorld* const world = env->world;
if (start_bundle(env, SIMPLE_MANIFEST_TTL, plugin_ttl)) {
if (create_bundle(
env, "bad_port_index.lv2", SIMPLE_MANIFEST_TTL, plugin_ttl)) {
return 1;
}
lilv_world_load_specifications(env->world);
lilv_world_load_bundle(env->world, env->test_bundle_uri);
const LilvPlugins* plugins = lilv_world_get_all_plugins(world);
const LilvPlugin* plug = lilv_plugins_get_by_uri(plugins, env->plugin1_uri);

6
test/test_bad_port_symbol.c

@ -41,10 +41,14 @@ main(void)
LilvTestEnv* const env = lilv_test_env_new();
LilvWorld* const world = env->world;
if (start_bundle(env, SIMPLE_MANIFEST_TTL, plugin_ttl)) {
if (create_bundle(
env, "bad_port_symbol.lv2", SIMPLE_MANIFEST_TTL, plugin_ttl)) {
return 1;
}
lilv_world_load_specifications(env->world);
lilv_world_load_bundle(env->world, env->test_bundle_uri);
const LilvPlugins* plugins = lilv_world_get_all_plugins(world);
const LilvPlugin* plug = lilv_plugins_get_by_uri(plugins, env->plugin1_uri);

7
test/test_classes.c

@ -41,10 +41,15 @@ main(void)
LilvTestEnv* const env = lilv_test_env_new();
LilvWorld* const world = env->world;
if (start_bundle(env, SIMPLE_MANIFEST_TTL, plugin_ttl)) {
lilv_world_load_all(world);
if (create_bundle(env, "classes.lv2", SIMPLE_MANIFEST_TTL, plugin_ttl)) {
return 1;
}
lilv_world_load_specifications(env->world);
lilv_world_load_bundle(env->world, env->test_bundle_uri);
const LilvPluginClass* plugin = lilv_world_get_plugin_class(world);
const LilvPluginClasses* classes = lilv_world_get_plugin_classes(world);
LilvPluginClasses* children = lilv_plugin_class_get_children(plugin);

5
test/test_discovery.c

@ -59,10 +59,13 @@ main(void)
LilvTestEnv* const env = lilv_test_env_new();
LilvWorld* const world = env->world;
if (start_bundle(env, SIMPLE_MANIFEST_TTL, plugin_ttl)) {
if (create_bundle(env, "discovery.lv2", SIMPLE_MANIFEST_TTL, plugin_ttl)) {
return 1;
}
lilv_world_load_specifications(env->world);
lilv_world_load_bundle(env->world, env->test_bundle_uri);
const LilvPlugins* plugins = lilv_world_get_all_plugins(world);
assert(lilv_plugins_size(plugins) > 0);

5
test/test_get_symbol.c

@ -40,10 +40,13 @@ main(void)
LilvTestEnv* const env = lilv_test_env_new();
LilvWorld* const world = env->world;
if (start_bundle(env, manifest_ttl, plugin_ttl)) {
if (create_bundle(env, "get_symbol.lv2", manifest_ttl, plugin_ttl)) {
return 1;
}
lilv_world_load_specifications(env->world);
lilv_world_load_bundle(env->world, env->test_bundle_uri);
LilvNode* plug_sym = lilv_world_get_symbol(world, env->plugin1_uri);
LilvNode* path = lilv_new_uri(world, "http://example.org/foo");
LilvNode* path_sym = lilv_world_get_symbol(world, path);

5
test/test_no_author.c

@ -63,10 +63,13 @@ main(void)
LilvTestEnv* const env = lilv_test_env_new();
LilvWorld* const world = env->world;
if (start_bundle(env, SIMPLE_MANIFEST_TTL, plugin_ttl)) {
if (create_bundle(env, "no_author.lv2", SIMPLE_MANIFEST_TTL, plugin_ttl)) {
return 1;
}
lilv_world_load_specifications(env->world);
lilv_world_load_bundle(env->world, env->test_bundle_uri);
const LilvPlugins* plugins = lilv_world_get_all_plugins(world);
const LilvPlugin* plug = lilv_plugins_get_by_uri(plugins, env->plugin1_uri);
assert(plug);

5
test/test_no_verify.c

@ -30,10 +30,13 @@ main(void)
LilvTestEnv* const env = lilv_test_env_new();
LilvWorld* const world = env->world;
if (start_bundle(env, SIMPLE_MANIFEST_TTL, plugin_ttl)) {
if (create_bundle(env, "no_verify.lv2", SIMPLE_MANIFEST_TTL, plugin_ttl)) {
return 1;
}
lilv_world_load_specifications(env->world);
lilv_world_load_bundle(env->world, env->test_bundle_uri);
const LilvPlugins* plugins = lilv_world_get_all_plugins(world);
const LilvPlugin* explug = lilv_plugins_get_by_uri(plugins, env->plugin1_uri);

9
test/test_plugin.c

@ -82,10 +82,15 @@ main(void)
LilvTestEnv* const env = lilv_test_env_new();
LilvWorld* const world = env->world;
if (start_bundle(env, SIMPLE_MANIFEST_TTL, plugin_ttl)) {
lilv_world_load_all(world);
if (create_bundle(env, "plugin.lv2", SIMPLE_MANIFEST_TTL, plugin_ttl)) {
return 1;
}
lilv_world_load_specifications(env->world);
lilv_world_load_bundle(env->world, env->test_bundle_uri);
const LilvPlugins* plugins = lilv_world_get_all_plugins(world);
const LilvPlugin* plug = lilv_plugins_get_by_uri(plugins, env->plugin1_uri);
assert(plug);
@ -104,7 +109,7 @@ main(void)
assert(!lilv_plugin_get_related(plug, NULL));
const LilvNode* plug_bundle_uri = lilv_plugin_get_bundle_uri(plug);
assert(!strcmp(lilv_node_as_string(plug_bundle_uri), env->test_bundle_uri));
assert(lilv_node_equals(plug_bundle_uri, env->test_bundle_uri));
const LilvNodes* data_uris = lilv_plugin_get_data_uris(plug);
assert(lilv_nodes_size(data_uris) == 2);

5
test/test_port.c

@ -80,10 +80,13 @@ main(void)
LilvTestEnv* const env = lilv_test_env_new();
LilvWorld* const world = env->world;
if (start_bundle(env, SIMPLE_MANIFEST_TTL, plugin_ttl)) {
if (create_bundle(env, "port.lv2", SIMPLE_MANIFEST_TTL, plugin_ttl)) {
return 1;
}
lilv_world_load_specifications(env->world);
lilv_world_load_bundle(env->world, env->test_bundle_uri);
const LilvPlugins* plugins = lilv_world_get_all_plugins(world);
const LilvPlugin* plug = lilv_plugins_get_by_uri(plugins, env->plugin1_uri);
assert(plug);

5
test/test_preset.c

@ -70,10 +70,13 @@ main(void)
LilvTestEnv* const env = lilv_test_env_new();
LilvWorld* const world = env->world;
if (start_bundle(env, SIMPLE_MANIFEST_TTL, plugin_ttl)) {
if (create_bundle(env, "preset.lv2", SIMPLE_MANIFEST_TTL, plugin_ttl)) {
return 1;
}
lilv_world_load_specifications(env->world);
lilv_world_load_bundle(env->world, env->test_bundle_uri);
const LilvPlugins* plugins = lilv_world_get_all_plugins(world);
const LilvPlugin* plug = lilv_plugins_get_by_uri(plugins, env->plugin1_uri);
assert(plug);

5
test/test_project.c

@ -69,10 +69,13 @@ main(void)
LilvTestEnv* const env = lilv_test_env_new();
LilvWorld* const world = env->world;
if (start_bundle(env, SIMPLE_MANIFEST_TTL, plugin_ttl)) {
if (create_bundle(env, "project.lv2", SIMPLE_MANIFEST_TTL, plugin_ttl)) {
return 1;
}
lilv_world_load_specifications(env->world);
lilv_world_load_bundle(env->world, env->test_bundle_uri);
const LilvPlugins* plugins = lilv_world_get_all_plugins(world);
const LilvPlugin* plug = lilv_plugins_get_by_uri(plugins, env->plugin1_uri);
assert(plug);

6
test/test_project_no_author.c

@ -63,10 +63,14 @@ main(void)
LilvTestEnv* const env = lilv_test_env_new();
LilvWorld* const world = env->world;
if (start_bundle(env, SIMPLE_MANIFEST_TTL, plugin_ttl)) {
if (create_bundle(
env, "project_no_author.lv2", SIMPLE_MANIFEST_TTL, plugin_ttl)) {
return 1;
}
lilv_world_load_specifications(env->world);
lilv_world_load_bundle(env->world, env->test_bundle_uri);
const LilvPlugins* plugins = lilv_world_get_all_plugins(world);
const LilvPlugin* plug = lilv_plugins_get_by_uri(plugins, env->plugin1_uri);
assert(plug);

5
test/test_prototype.c

@ -76,10 +76,13 @@ main(void)
LilvTestEnv* const env = lilv_test_env_new();
LilvWorld* const world = env->world;
if (start_bundle(env, manifest_ttl, plugin_ttl)) {
if (create_bundle(env, "prototype.lv2", manifest_ttl, plugin_ttl)) {
return 1;
}
lilv_world_load_specifications(env->world);
lilv_world_load_bundle(env->world, env->test_bundle_uri);
const LilvPlugins* plugins = lilv_world_get_all_plugins(world);
const LilvPlugin* plug = lilv_plugins_get_by_uri(plugins, env->plugin1_uri);
assert(plug);

14
test/test_reload_bundle.c

@ -29,8 +29,11 @@ main(void)
LilvTestEnv* const env = lilv_test_env_new();
LilvWorld* const world = env->world;
lilv_world_load_all(world);
// Create a simple plugin bundle
create_bundle(env,
"reload_bundle.lv2",
":plug a lv2:Plugin ; lv2:binary <foo" SHLIB_EXT
"> ; rdfs:seeAlso <plugin.ttl> .\n",
":plug a lv2:Plugin ; "
@ -39,8 +42,7 @@ main(void)
lilv_world_load_specifications(world);
// Load bundle
LilvNode* bundle_uri = lilv_new_uri(world, env->test_bundle_uri);
lilv_world_load_bundle(world, bundle_uri);
lilv_world_load_bundle(world, env->test_bundle_uri);
// Check that plugin is present
const LilvPlugins* plugins = lilv_world_get_all_plugins(world);
@ -53,11 +55,12 @@ main(void)
lilv_node_free(name);
// Unload bundle from world and delete it
lilv_world_unload_bundle(world, bundle_uri);
lilv_world_unload_bundle(world, env->test_bundle_uri);
delete_bundle(env);
// Create a new version of the same bundle, but with a different name
create_bundle(env,
"test_reload_bundle.lv2",
":plug a lv2:Plugin ; lv2:binary <foo" SHLIB_EXT
"> ; rdfs:seeAlso <plugin.ttl> .\n",
":plug a lv2:Plugin ; "
@ -67,7 +70,7 @@ main(void)
assert(lilv_plugins_size(plugins) == 0);
// Load new bundle
lilv_world_load_bundle(world, bundle_uri);
lilv_world_load_bundle(world, env->test_bundle_uri);
// Check that plugin is present again and is the same LilvPlugin
const LilvPlugin* plug2 = lilv_plugins_get_by_uri(plugins, env->plugin1_uri);
@ -81,9 +84,8 @@ main(void)
lilv_node_free(name2);
// Load new bundle again (noop)
lilv_world_load_bundle(world, bundle_uri);
lilv_world_load_bundle(world, env->test_bundle_uri);
lilv_node_free(bundle_uri);
delete_bundle(env);
lilv_test_env_free(env);

6
test/test_ui.c

@ -95,9 +95,13 @@ main(void)
LilvTestEnv* const env = lilv_test_env_new();
LilvWorld* const world = env->world;
if (start_bundle(env, SIMPLE_MANIFEST_TTL, plugin_ttl)) {
if (create_bundle(env, "ui.lv2", SIMPLE_MANIFEST_TTL, plugin_ttl)) {
return 1;
}
lilv_world_load_specifications(env->world);
lilv_world_load_bundle(env->world, env->test_bundle_uri);
const LilvPlugins* plugins = lilv_world_get_all_plugins(world);
const LilvPlugin* plug = lilv_plugins_get_by_uri(plugins, env->plugin1_uri);
assert(plug);

5
test/test_value.c

@ -42,10 +42,13 @@ main(void)
LilvTestEnv* const env = lilv_test_env_new();
LilvWorld* const world = env->world;
if (start_bundle(env, SIMPLE_MANIFEST_TTL, plugin_ttl)) {
if (create_bundle(env, "value.lv2", SIMPLE_MANIFEST_TTL, plugin_ttl)) {
return 1;
}
lilv_world_load_specifications(env->world);
lilv_world_load_bundle(env->world, env->test_bundle_uri);
LilvNode* uval = lilv_new_uri(world, "http://example.org");
LilvNode* sval = lilv_new_string(world, "Foo");
LilvNode* ival = lilv_new_int(world, 42);

5
test/test_verify.c

@ -39,10 +39,13 @@ main(void)
LilvTestEnv* const env = lilv_test_env_new();
LilvWorld* const world = env->world;
if (start_bundle(env, SIMPLE_MANIFEST_TTL, plugin_ttl)) {
if (create_bundle(env, "verify.lv2", SIMPLE_MANIFEST_TTL, plugin_ttl)) {
return 1;
}
lilv_world_load_specifications(env->world);
lilv_world_load_bundle(env->world, env->test_bundle_uri);
const LilvPlugins* plugins = lilv_world_get_all_plugins(world);
const LilvPlugin* explug = lilv_plugins_get_by_uri(plugins, env->plugin1_uri);

Loading…
Cancel
Save