libmpm

morphux C package management library
Log | Files | Refs | Submodules | README | LICENSE | git clone https://git.ne02ptzero.me/git/libmpm

commit 48e4bac3941698ae69d3c708fe35f5ee7dfe5424
parent 0c4b170bee3a1797d9a289a4faa60d04835cf972
Author: Ne02ptzero <louis@ne02ptzero.me>
Date:   Tue,  4 Jul 2017 12:26:00 +0200

Fix(Test & Compile): Full coverage and clean valgrind

Diffstat:
Minc/compile.h | 3++-
Msrc/compile.c | 24++++++++++++------------
Mtests/test_compile.c | 34+++++++++++++++++-----------------
Mtests/test_packer.c | 3+++
4 files changed, 34 insertions(+), 30 deletions(-)

diff --git a/inc/compile.h b/inc/compile.h @@ -131,10 +131,11 @@ bool after_package(compile_t *ctx); * \brief Extract and Install an .mpx archive * * \param[in] ctx Archive to install + * \param[in] ptr Pointer to compile_t pointer * * \return true on success, false on failure */ -bool install_archive(packer_t *ctx, compile_t *ptr); +bool install_archive(packer_t *ctx, compile_t **ptr); /*! * \brief install_state_t to human readable string diff --git a/src/compile.c b/src/compile.c @@ -313,7 +313,7 @@ end: return true; } -bool install_archive(packer_t *ctx, compile_t *ptr) { +bool install_archive(packer_t *ctx, compile_t **ptr) { bool ret = false; /* Extract the given archive */ @@ -324,8 +324,8 @@ bool install_archive(packer_t *ctx, compile_t *ptr) { } /* Init the installation process */ - ptr = package_install_init(ctx); - if (ptr == NULL) + *ptr = package_install_init(ctx); + if (*ptr == NULL) { SET_ERR(ERR_MEMORY); recursive_delete(ctx->out_dir); @@ -333,39 +333,39 @@ bool install_archive(packer_t *ctx, compile_t *ptr) { return ret; } - if (before_package(ptr) == false) + if (before_package(*ptr) == false) goto end; - if (patch_package(ptr) == false) + if (patch_package(*ptr) == false) goto end; - if (configure_package(ptr) == false) + if (configure_package(*ptr) == false) goto end; - if (make_package(ptr) == false) + if (make_package(*ptr) == false) goto end; - if (install_package(ptr) == false) + if (install_package(*ptr) == false) goto end; - if (after_package(ptr) == false) + if (after_package(*ptr) == false) goto end; ret = true; end: - /* Installation as failed */ + /* Installation has failed */ if (ret != true) { SET_ERR_STR_FMT("Installation failed at step: %s", - install_state_to_str(ptr->state)); + install_state_to_str((*ptr)->state)); SET_ERR(ERR_INSTALLATION_FAILED); } /* All good, we clean up the installation directory */ else { recursive_delete(ctx->out_dir); - package_install_cleanup(ptr); + package_install_cleanup(*ptr); } return ret; } diff --git a/tests/test_compile.c b/tests/test_compile.c @@ -88,6 +88,7 @@ TEST(configure_package) { set_fork_fail(0); TEST_ASSERT(configure_package(ptr) == false, "Bad return"); + package_install_cleanup(ptr); chdir("/tmp/test-2.0"); recursive_delete(OUTPUT_DIR); return TEST_SUCCESS; @@ -212,7 +213,7 @@ TEST(full_install) { compile_t *ptr = NULL; chdir(g_old_pwd); - TEST_ASSERT_FMT(install_archive(ctx, ptr) == true, "An error happened: %s", GET_ERR_STR()); + TEST_ASSERT_FMT(install_archive(ctx, &ptr) == true, "An error happened: %s", GET_ERR_STR()); return TEST_SUCCESS; } @@ -229,56 +230,55 @@ TEST(full_install_2) { TEST_ASSERT(ctx != NULL, "Cannot create archive"); set_malloc_fail(18); - TEST_ASSERT(install_archive(ctx, ptr) == false, "Error did not raise"); + TEST_ASSERT(install_archive(ctx, &ptr) == false, "Error did not raise"); package_install_cleanup(ptr); recursive_delete(DEFAULT_EXTRACT_DIR "/test-2.0"); chdir(g_old_pwd); ctx = packer_init_archive(PACKAGE_OUTPUT_FN); set_fork_fail(0); - TEST_ASSERT(install_archive(ctx, ptr) == false, "Error did not raise"); - package_install_cleanup(ptr); + TEST_ASSERT(install_archive(ctx, &ptr) == false, "Error did not raise"); + TEST_ASSERT(package_install_cleanup(ptr) == true, "Cannot cleanup package"); recursive_delete(DEFAULT_EXTRACT_DIR "/test-2.0"); chdir(g_old_pwd); - system("ls -la"); ctx = packer_init_archive(PACKAGE_OUTPUT_FN); set_fork_fail(1); - TEST_ASSERT(install_archive(ctx, ptr) == false, "Error did not raise"); - package_install_cleanup(ptr); + TEST_ASSERT(install_archive(ctx, &ptr) == false, "Error did not raise"); + TEST_ASSERT(package_install_cleanup(ptr) == true, "Cannot cleanup package"); recursive_delete(DEFAULT_EXTRACT_DIR "/test-2.0"); chdir(g_old_pwd); ctx = packer_init_archive(PACKAGE_OUTPUT_FN); set_fork_fail(2); - TEST_ASSERT(install_archive(ctx, ptr) == false, "Error did not raise"); - package_install_cleanup(ptr); + TEST_ASSERT(install_archive(ctx, &ptr) == false, "Error did not raise"); + TEST_ASSERT(package_install_cleanup(ptr) == true, "Cannot cleanup package"); recursive_delete(DEFAULT_EXTRACT_DIR "/test-2.0"); chdir(g_old_pwd); ctx = packer_init_archive(PACKAGE_OUTPUT_FN); set_fork_fail(3); - TEST_ASSERT(install_archive(ctx, ptr) == false, "Error did not raise"); - package_install_cleanup(ptr); + TEST_ASSERT(install_archive(ctx, &ptr) == false, "Error did not raise"); + TEST_ASSERT(package_install_cleanup(ptr) == true, "Cannot cleanup package"); recursive_delete(DEFAULT_EXTRACT_DIR "/test-2.0"); chdir(g_old_pwd); ctx = packer_init_archive(PACKAGE_OUTPUT_FN); set_fork_fail(4); - TEST_ASSERT(install_archive(ctx, ptr) == false, "Error did not raise"); - package_install_cleanup(ptr); + TEST_ASSERT(install_archive(ctx, &ptr) == false, "Error did not raise"); + TEST_ASSERT(package_install_cleanup(ptr) == true, "Cannot cleanup package"); recursive_delete(DEFAULT_EXTRACT_DIR "/test-2.0"); chdir(g_old_pwd); ctx = packer_init_archive(PACKAGE_OUTPUT_FN); set_fork_fail(5); - TEST_ASSERT(install_archive(ctx, ptr) == false, "Error did not raise"); - package_install_cleanup(ptr); + TEST_ASSERT(install_archive(ctx, &ptr) == false, "Error did not raise"); + TEST_ASSERT(package_install_cleanup(ptr) == true, "Cannot cleanup package"); recursive_delete(DEFAULT_EXTRACT_DIR "/test-2.0"); ctx = packer_init_archive(PACKAGE_OUTPUT_FN); - TEST_ASSERT(install_archive(ctx, ptr) == false, "Error did not raise"); - package_install_cleanup(ptr); + set_malloc_fail(0); + TEST_ASSERT(install_archive(ctx, &ptr) == false, "Error did not raise"); return TEST_SUCCESS; } diff --git a/tests/test_packer.c b/tests/test_packer.c @@ -480,6 +480,7 @@ TEST(packer_read_package_header_package) { TEST_ASSERT(read_package_header_package(tmp, ctx) == 0, "Wrong return"); set_malloc_fail(-1); + packer_free(ctx); return TEST_SUCCESS; } MPX_STATIC bool read_package_header(char *file_content, packer_t *ctx, int *s_ret); @@ -678,6 +679,8 @@ TEST(packer_inlines_frees) { list_add(ptr.compilation.env, str2, sizeof(*str2)); packer_header_comp_free(&ptr); + free(str); + free(str2); return TEST_SUCCESS; }