diff --git a/src/test/testcommon.c b/src/test/testcommon.c index 130dcbe1..df7dd7a6 100644 --- a/src/test/testcommon.c +++ b/src/test/testcommon.c @@ -128,9 +128,10 @@ void test_common_init() { } int test_setup_boot_disk(const char *fileName, int readonly) { - char *disk = NULL; int err = 0; -#ifdef __APPLE__ + char **path = NULL; + +#if defined(__APPLE__) CFBundleRef mainBundle = CFBundleGetMainBundle(); CFStringRef fileString = CFStringCreateWithCString(/*allocator*/NULL, fileName, CFStringGetSystemEncoding()); CFURLRef fileURL = CFBundleCopyResourceURL(mainBundle, fileString, NULL, NULL); @@ -144,15 +145,48 @@ int test_setup_boot_disk(const char *fileName, int readonly) { FREE(disk); } CFRELEASE(filePath); + + char *paths[] = { + disk, + NULL, + }; #else - asprintf(&disk, "%s/disks/%s", data_dir, fileName); + char *paths[] = { + NULL, + NULL, + NULL, + NULL, + }; + asprintf(&paths[0], "%s/disks/%s", data_dir, fileName); + asprintf(&paths[1], "%s/disks/demo/%s", data_dir, fileName); + asprintf(&paths[2], "%s/disks/blanks/%s", data_dir, fileName); #endif - if (disk6_insert(0, disk, readonly)) { + + path = &paths[0]; + while (*path) { + char *disk = *path; + ++path; + + err = disk6_insert(0, disk, readonly) != NULL; + if (!err) { + break; + } + int len = strlen(disk); disk[len-3] = '\0'; // try again without '.gz' extension - err = (disk6_insert(0, disk, readonly) != NULL); + err = disk6_insert(0, disk, readonly) != NULL; + if (!err) { + break; + } } - FREE(disk); + + path = &paths[0]; + while (*path) { + char *disk = *path; + ++path; + FREE(disk); + } + return err; }