diff options
| -rw-r--r-- | CMakeLists.txt | 2 | ||||
| -rw-r--r-- | src/lib/core/conda.c | 3 | ||||
| -rw-r--r-- | src/lib/delivery/delivery.c | 20 | ||||
| -rw-r--r-- | src/lib/delivery/delivery_build.c | 2 | ||||
| -rw-r--r-- | src/lib/delivery/delivery_test.c | 38 | ||||
| -rw-r--r-- | src/lib/delivery/include/delivery.h | 6 | ||||
| -rw-r--r-- | tests/test_conda.c | 2 | ||||
| -rw-r--r-- | tests/test_tests.c | 52 |
8 files changed, 98 insertions, 27 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index bd214ca..71e310b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,7 +9,7 @@ find_package(LibXml2) find_package(CURL) option(ASAN "Address Analyzer" OFF) -set(ASAN_OPTIONS "-fsanitize=address,leak,null,undefined") +set(ASAN_OPTIONS "-fsanitize=address,null,undefined") if (ASAN) add_compile_options(${ASAN_OPTIONS} -fno-omit-frame-pointer -g -O0) add_link_options(${ASAN_OPTIONS}) diff --git a/src/lib/core/conda.c b/src/lib/core/conda.c index de6130f..c9be7a3 100644 --- a/src/lib/core/conda.c +++ b/src/lib/core/conda.c @@ -58,6 +58,9 @@ int micromamba(const struct MicromambaInfo *info, char *command, ...) { char rcpath[PATH_MAX]; sprintf(rcpath, "%s/.condarc", info->conda_prefix); touch(rcpath); + if (errno == ENOENT) { + errno = 0; + } setenv("CONDARC", rcpath, 1); setenv("MAMBA_ROOT_PREFIX", info->conda_prefix, 1); diff --git a/src/lib/delivery/delivery.c b/src/lib/delivery/delivery.c index 11dd7b0..be6e8ff 100644 --- a/src/lib/delivery/delivery.c +++ b/src/lib/delivery/delivery.c @@ -230,25 +230,7 @@ void delivery_free(struct Delivery *ctx) { guard_strlist_free(&ctx->conda.pip_packages_purge); guard_strlist_free(&ctx->conda.wheels_packages); - for (size_t i = 0; ctx->tests && i < ctx->tests->num_used; i++) { - guard_free(ctx->tests->test[i]->name); - guard_free(ctx->tests->test[i]->version); - guard_free(ctx->tests->test[i]->repository); - guard_free(ctx->tests->test[i]->repository_info_ref); - guard_free(ctx->tests->test[i]->repository_info_tag); - guard_strlist_free(&ctx->tests->test[i]->repository_remove_tags); - guard_free(ctx->tests->test[i]->script); - guard_free(ctx->tests->test[i]->script_setup); - guard_free(ctx->tests->test[i]->build_recipe); - // test-specific runtime variables - guard_runtime_free(ctx->tests->test[i]->runtime->environ); - guard_free(ctx->tests->test[i]->runtime); - guard_free(ctx->tests->test[i]); - } - if (ctx->tests) { - guard_free(ctx->tests->test); - guard_free(ctx->tests); - } + tests_free(&ctx->tests); guard_free(ctx->rules.release_fmt); guard_free(ctx->rules.build_name_fmt); diff --git a/src/lib/delivery/delivery_build.c b/src/lib/delivery/delivery_build.c index 0013e96..1454d9a 100644 --- a/src/lib/delivery/delivery_build.c +++ b/src/lib/delivery/delivery_build.c @@ -367,7 +367,7 @@ struct StrList *delivery_build_wheels(struct Delivery *ctx) { const int use_builder_manylinux = strcmp(globals.wheel_builder, "manylinux") == 0 && on_linux && docker_usable; if (!use_builder_build && !use_builder_cibuildwheel && !use_builder_manylinux) { - msg(STASIS_MSG_WARN, "Cannot build wheel for platform using: %\n", globals.wheel_builder); + msg(STASIS_MSG_WARN, "Cannot build wheel for platform using: %s\n", globals.wheel_builder); msg(STASIS_MSG_WARN, "Falling back to native toolchain.\n", globals.wheel_builder); use_builder_build = 1; } diff --git a/src/lib/delivery/delivery_test.c b/src/lib/delivery/delivery_test.c index 3ba9d56..96dbb10 100644 --- a/src/lib/delivery/delivery_test.c +++ b/src/lib/delivery/delivery_test.c @@ -21,10 +21,10 @@ int tests_add(struct Tests *tests, struct Test *x) { #ifdef DEBUG const size_t old_alloc = tests->num_alloc; #endif - struct Test **tmp = realloc(tests->test, tests->num_alloc++ * sizeof(*tests->test)); + struct Test **tmp = realloc(tests->test, tests->num_alloc++ * sizeof(**tests->test)); SYSDEBUG("Increasing size of test array: %zu -> %zu", old_alloc, tests->num_alloc); if (!tmp) { - SYSDEBUG("Failed to allocate %zu bytes for test array", tests->num_alloc * sizeof(*tests->test)); + SYSDEBUG("Failed to allocate %zu bytes for test array", tests->num_alloc * sizeof(**tests->test)); return -1; } tests->test = tmp; @@ -37,21 +37,49 @@ int tests_add(struct Tests *tests, struct Test *x) { struct Test *test_init() { struct Test *result = calloc(1, sizeof(*result)); + if (!result) { + return NULL; + } + result->runtime = calloc(1, sizeof(*result->runtime)); + if (!result->runtime) { + return NULL; + } return result; } void test_free(struct Test **x) { struct Test *test = *x; + if (!test) { + return; + } + guard_free(test->name); + guard_free(test->version); + guard_free(test->repository); + guard_free(test->repository_info_ref); + guard_free(test->repository_info_tag); + guard_strlist_free(&test->repository_remove_tags); + guard_free(test->script); + guard_free(test->script_setup); + guard_free(test->build_recipe); + // test-specific runtime variables + guard_runtime_free(test->runtime->environ); + guard_free(test->runtime); guard_free(test); } void tests_free(struct Tests **x) { - for (size_t i = 0; i < (*x)->num_alloc; i++) { - test_free(&(*x)->test[i]); + struct Tests *tests = *x; + if (!tests) { + return; + } + + for (size_t i = 0; i < tests->num_alloc; i++) { + test_free(&tests->test[i]); } - guard_free((*x)->test); + guard_free(tests->test); + guard_free(tests); } void delivery_tests_run(struct Delivery *ctx) { diff --git a/src/lib/delivery/include/delivery.h b/src/lib/delivery/include/delivery.h index b5799ac..68f4b14 100644 --- a/src/lib/delivery/include/delivery.h +++ b/src/lib/delivery/include/delivery.h @@ -522,6 +522,12 @@ int tests_add(struct Tests *tests, struct Test *x); void test_free(struct Test **x); /** + * Free a `Tests` structure + * @param x pointer to `Tests` + */ +void tests_free(struct Tests **x); + +/** * Initialize a `Test` structure * @return an initialized `Test` structure */ diff --git a/tests/test_conda.c b/tests/test_conda.c index 4d437e4..1d05e7e 100644 --- a/tests/test_conda.c +++ b/tests/test_conda.c @@ -20,7 +20,7 @@ void test_micromamba() { struct testcase tc[] = { {.mminfo = {.micromamba_prefix = mm_prefix, .conda_prefix = c_prefix}, .cmd = "info", .result = 0}, {.mminfo = {.micromamba_prefix = mm_prefix, .conda_prefix = c_prefix}, .cmd = "env list", .result = 0}, - {.mminfo = {.micromamba_prefix = mm_prefix, .conda_prefix = c_prefix}, .cmd = "run python -V", .result = 0}, + {.mminfo = {.micromamba_prefix = mm_prefix, .conda_prefix = c_prefix}, .cmd = "run python3 -V", .result = 0}, {.mminfo = {.micromamba_prefix = mm_prefix, .conda_prefix = c_prefix}, .cmd = "no_such_option", .result = 109}, }; diff --git a/tests/test_tests.c b/tests/test_tests.c new file mode 100644 index 0000000..0f6d7ca --- /dev/null +++ b/tests/test_tests.c @@ -0,0 +1,52 @@ +#include "delivery.h" +#include "testing.h" + +static struct Test *mock_test(const int ident) { + struct Test *test = test_init(); + if (asprintf(&test->name, "test_%d", ident) < 0) { + return NULL; + } + return test; +} + +void test_tests() { + const int initial = TEST_NUM_ALLOC_INITIAL; + const int balloon = initial * 10; + struct Tests *tests = tests_init(initial); + STASIS_ASSERT_FATAL(tests != NULL, "tests structure allocation failed"); + STASIS_ASSERT(tests->num_alloc == (size_t) initial, "incorrect number of records initialized"); + STASIS_ASSERT(tests->num_used == 0, "incorrect number of records used"); + + for (int i = 0; i < balloon; i++) { + struct Test *test = mock_test(i); + if (!test) { + SYSERROR("unable to allocate memory for test %d", i); + return; + } + tests_add(tests, test); + } + + size_t errors = 0; + for (int i = 0; i < initial * 10; i++) { + struct Test *test = tests->test[i]; + if (!test) { + errors++; + continue; + } + if (!test->name) { + errors++; + } + } + STASIS_ASSERT(errors == 0, "no errors should be detected in test->name member"); + + tests_free(&tests); +} + +int main(int argc, char *argv[]) { + STASIS_TEST_BEGIN_MAIN(); + STASIS_TEST_FUNC *tests[] = { + test_tests, + }; + STASIS_TEST_RUN(tests); + STASIS_TEST_END_MAIN(); +}
\ No newline at end of file |
