Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0.73.0: test suite fails in assertion of the test_libdnf_main unit because use g_assert () in test units #1643

Open
kloczek opened this issue Feb 11, 2024 · 1 comment
Labels
Triaged Someone on the DNF 5 team has read the issue and determined the next steps to take

Comments

@kloczek
Copy link
Contributor

kloczek commented Feb 11, 2024

Continuation of #1620
I think that I know why this unit is failing in my env.
I'm using glib binaries compiled with disabled assertions.
Looks like libdnf test suite is using g_assert () in test units. This assertion should not be used.
From https://docs.gtk.org/glib/func.assert.html:

Debugging macro to terminate the application if the assertion fails. If the assertion fails (i.e. the expression is not true), an error message is logged and the application is terminated.

The macro can be turned off in final releases of code by defining G_DISABLE_ASSERT when compiling the application, so code must not depend on any side effects from expr. Similarly, it must not be used in unit tests, otherwise the unit tests will be ineffective if compiled with G_DISABLE_ASSERT. Use g_assert_true() and related macros in unit tests instead.

In other words instead using g_assert () other g_assert_* () assertions should be used.

List of places where g_assert () currently is used
[tkloczko@pers-jacek libdnf-0.73.0]$ grep -r g_assert -w tests/
tests/hawkey/test_sack.cpp:    g_assert(sack != NULL);
tests/hawkey/test_sack.cpp:    g_assert(repo != NULL);
tests/libdnf/dnf-self-test.c:    g_assert(lock != NULL);
tests/libdnf/dnf-self-test.c:    g_assert(!ret);
tests/libdnf/dnf-self-test.c:    g_assert(lock_id1 != 0);
tests/libdnf/dnf-self-test.c:    g_assert(lock_id2 != 0);
tests/libdnf/dnf-self-test.c:    g_assert(lock_id2 != lock_id1);
tests/libdnf/dnf-self-test.c:    g_assert(lock_id1 != 0);
tests/libdnf/dnf-self-test.c:    g_assert(ret);
tests/libdnf/dnf-self-test.c:    g_assert(ret);
tests/libdnf/dnf-self-test.c:    g_assert(ret);
tests/libdnf/dnf-self-test.c:    g_assert(!ret);
tests/libdnf/dnf-self-test.c:    g_assert(ret);
tests/libdnf/dnf-self-test.c:    g_assert(dnf_repo_setup(repo, &error));
tests/libdnf/dnf-self-test.c:    g_assert(data == NULL);
tests/libdnf/dnf-self-test.c:    g_assert(state != NULL);
tests/libdnf/dnf-self-test.c:    g_assert(dnf_state_get_allow_cancel(state));
tests/libdnf/dnf-self-test.c:    g_assert(dnf_state_get_allow_cancel(state));
tests/libdnf/dnf-self-test.c:    g_assert(!dnf_state_get_allow_cancel(state));
tests/libdnf/dnf-self-test.c:    g_assert(!dnf_state_action_stop(state));
tests/libdnf/dnf-self-test.c:    g_assert(dnf_state_action_start(state, DNF_STATE_ACTION_DOWNLOAD, NULL));
tests/libdnf/dnf-self-test.c:    g_assert(!dnf_state_action_start(state, DNF_STATE_ACTION_DOWNLOAD, NULL));
tests/libdnf/dnf-self-test.c:    g_assert(dnf_state_action_stop(state));
tests/libdnf/dnf-self-test.c:    g_assert(ret);
tests/libdnf/dnf-self-test.c:    g_assert(ret);
tests/libdnf/dnf-self-test.c:    g_assert(ret);
tests/libdnf/dnf-self-test.c:    g_assert(ret);
tests/libdnf/dnf-self-test.c:    g_assert(ret);
tests/libdnf/dnf-self-test.c:    g_assert(dnf_state_done(state, NULL));
tests/libdnf/dnf-self-test.c:    g_assert(!dnf_state_done(state, NULL));
tests/libdnf/dnf-self-test.c:    g_assert(dnf_state_get_allow_cancel(state));
tests/libdnf/dnf-self-test.c:    g_assert(state == NULL);
tests/libdnf/dnf-self-test.c:    g_assert(ret);
tests/libdnf/dnf-self-test.c:    g_assert((_updates == 1));
tests/libdnf/dnf-self-test.c:    g_assert((_last_percent == 50));
tests/libdnf/dnf-self-test.c:    g_assert(!dnf_state_get_allow_cancel(child));
tests/libdnf/dnf-self-test.c:    g_assert(!dnf_state_get_allow_cancel(state));
tests/libdnf/dnf-self-test.c:    g_assert(dnf_state_action_start(child, DNF_STATE_ACTION_LOADING_CACHE, NULL));
tests/libdnf/dnf-self-test.c:    g_assert(ret);
tests/libdnf/dnf-self-test.c:    g_assert(dnf_state_action_start(child,
tests/libdnf/dnf-self-test.c:    g_assert(ret);
tests/libdnf/dnf-self-test.c:    g_assert(dnf_state_action_stop(state));
tests/libdnf/dnf-self-test.c:    g_assert(!dnf_state_action_stop(state));
tests/libdnf/dnf-self-test.c:    g_assert(ret);
tests/libdnf/dnf-self-test.c:    g_assert(ret);
tests/libdnf/dnf-self-test.c:    g_assert(state == NULL);
tests/libdnf/dnf-self-test.c:    g_assert(_updates == 1);
tests/libdnf/dnf-self-test.c:    g_assert(_last_percent == 33);
tests/libdnf/dnf-self-test.c:    g_assert(state == NULL);
tests/libdnf/dnf-self-test.c:    g_assert(!ret);
tests/libdnf/dnf-self-test.c:    g_assert(ret);
tests/libdnf/dnf-self-test.c:    g_assert(ret);
tests/libdnf/dnf-self-test.c:    g_assert(ret);
tests/libdnf/dnf-self-test.c:    g_assert(ret);
tests/libdnf/dnf-self-test.c:    g_assert(ret);
tests/libdnf/dnf-self-test.c:    g_assert(ret);
tests/libdnf/dnf-self-test.c:    g_assert(ret);
tests/libdnf/dnf-self-test.c:    g_assert(ret);
tests/libdnf/dnf-self-test.c:    g_assert(ret);
tests/libdnf/dnf-self-test.c:    g_assert(ret);
tests/libdnf/dnf-self-test.c:    g_assert(ret);
tests/libdnf/dnf-self-test.c:    g_assert(ret);
tests/libdnf/dnf-self-test.c:    g_assert(state == NULL);
tests/libdnf/dnf-self-test.c:    g_assert(ret);
tests/libdnf/dnf-self-test.c:    g_assert(ret);
tests/libdnf/dnf-self-test.c:    g_assert(child != NULL);
tests/libdnf/dnf-self-test.c:    g_assert(ret);
tests/libdnf/dnf-self-test.c:    g_assert(ret);
tests/libdnf/dnf-self-test.c:    g_assert(state == NULL);
tests/libdnf/dnf-self-test.c:    g_assert(ret);
tests/libdnf/dnf-self-test.c:    g_assert(ret);
tests/libdnf/dnf-self-test.c:    g_assert(state == NULL);
tests/libdnf/dnf-self-test.c:    g_assert(state == NULL);
tests/libdnf/dnf-self-test.c:    g_assert(ret);
tests/libdnf/dnf-self-test.c:        g_assert(ret);
tests/libdnf/dnf-self-test.c:    g_assert(ret);
tests/libdnf/dnf-self-test.c:    g_assert(ret);
tests/libdnf/dnf-self-test.c:    g_assert(ret);
tests/libdnf/dnf-self-test.c:    g_assert(state == NULL);
tests/libdnf/dnf-self-test.c:    g_assert(ret);
tests/libdnf/dnf-self-test.c:    g_assert(ret);
tests/libdnf/dnf-self-test.c:        g_assert(ret);
tests/libdnf/dnf-self-test.c:    g_assert(ret);
tests/libdnf/dnf-self-test.c:    g_assert(repo != NULL);
tests/libdnf/dnf-self-test.c:    g_assert(dnf_repo_get_gpgcheck(repo));
tests/libdnf/dnf-self-test.c:    g_assert(!dnf_repo_get_gpgcheck_md(repo));
tests/libdnf/dnf-self-test.c:    g_assert(repo != NULL);
tests/libdnf/dnf-self-test.c:    g_assert(!dnf_repo_get_gpgcheck(repo));
tests/libdnf/dnf-self-test.c:    g_assert(!dnf_repo_get_gpgcheck_md(repo));
tests/libdnf/dnf-self-test.c:    g_assert(repo != NULL);
tests/libdnf/dnf-self-test.c:    g_assert(!dnf_repo_get_gpgcheck(repo));
tests/libdnf/dnf-self-test.c:    g_assert(!dnf_repo_get_gpgcheck_md(repo));
tests/libdnf/dnf-self-test.c:    g_assert(ret);
tests/libdnf/dnf-self-test.c:    g_assert(ret);
tests/libdnf/dnf-self-test.c:    g_assert(!ret);
tests/libdnf/dnf-self-test.c:    g_assert(ret);
tests/libdnf/dnf-self-test.c:    g_assert(dnf_context_get_check_disk_space(ctx));
tests/libdnf/dnf-self-test.c:    g_assert(dnf_context_get_check_transaction(ctx));
tests/libdnf/dnf-self-test.c:    g_assert(!dnf_context_get_keep_cache(ctx));
tests/libdnf/dnf-self-test.c:    g_assert(!ret);
tests/libdnf/dnf-self-test.c:    g_assert(ret);
tests/libdnf/dnf-self-test.c:    g_assert(repo != NULL);
tests/libdnf/dnf-self-test.c:    g_assert(!ret);
tests/libdnf/dnf-self-test.c:    g_assert(!ret);
tests/libdnf/dnf-self-test.c:    g_assert(ret);
tests/libdnf/dnf-self-test.c:    g_assert(repo != NULL);
tests/libdnf/dnf-self-test.c:    g_assert(!ret);
tests/libdnf/dnf-self-test.c:    g_assert(ret);
tests/libdnf/dnf-self-test.c:    g_assert(repo != NULL);
tests/libdnf/dnf-self-test.c:    g_assert(!ret);
tests/libdnf/dnf-self-test.c:    g_assert(ret);
tests/libdnf/dnf-self-test.c:    g_assert(ret);
tests/libdnf/dnf-self-test.c:    g_assert(repo != NULL);
tests/libdnf/dnf-self-test.c:    g_assert(g_str_has_suffix(cache_location, expected_cache_suffix));
tests/libdnf/dnf-self-test.c:    g_assert(g_file_test(filename, G_FILE_TEST_EXISTS));
tests/libdnf/dnf-self-test.c:    g_assert(ret);
tests/libdnf/dnf-self-test.c:    g_assert(file_result == 0);
tests/libdnf/dnf-self-test.c:    g_assert(file_result == 0);
tests/libdnf/dnf-self-test.c:    g_assert(ret);
tests/libdnf/dnf-self-test.c:    g_assert(!g_file_test(package_directory, G_FILE_TEST_EXISTS));
tests/libdnf/dnf-self-test.c:    g_assert(!g_file_test(repo_data_folder, G_FILE_TEST_EXISTS));
tests/libdnf/dnf-self-test.c:    g_assert(!g_file_test(xml_string, G_FILE_TEST_EXISTS));
tests/libdnf/dnf-self-test.c:    g_assert(!g_file_test(expire_cache_file, G_FILE_TEST_EXISTS));
tests/libdnf/dnf-self-test.c:    g_assert(g_file_test(non_matching_file, G_FILE_TEST_EXISTS));
tests/libdnf/dnf-self-test.c:    g_assert(g_setenv("G_MESSAGES_DEBUG", "all", FALSE));
tests/libdnf/dnf-self-test.c:    g_assert(g_setenv ("GIO_USE_VFS", "local", TRUE));
tests/libdnf/dnf-self-test.c:    g_assert(g_setenv("DNF_VAR_testdatadir", TESTDATADIR, TRUE));
tests/libdnf/module/ContextTest.cpp:    g_assert(ret);
tests/libdnf/module/ContextTest.cpp:    g_assert(repo != nullptr);
tests/libdnf/module/ContextTest.cpp:    g_assert(!dnf_context_module_install(context, module_specs, &error));
tests/libdnf/module/ContextTest.cpp:    g_assert(error);
tests/libdnf/module/ContextTest.cpp:    g_assert(strstr(error->message, "Unable to resolve argument 'nonexistent'"));
tests/libdnf/module/ContextTest.cpp:    g_assert(!dnf_context_module_install(context, module_specs, &error));
tests/libdnf/module/ContextTest.cpp:    g_assert(error);
tests/libdnf/module/ContextTest.cpp:    g_assert(strstr(error->message, "Unable to resolve argument 'httpd:nonexistent'"));
tests/libdnf/module/ContextTest.cpp:    g_assert(!dnf_context_module_install(context, module_specs, &error));
tests/libdnf/module/ContextTest.cpp:    g_assert(error);
tests/libdnf/module/ContextTest.cpp:    g_assert(strstr(error->message, "No profile found matching 'nonexistent'"));
tests/libdnf/module/ContextTest.cpp:    g_assert(dnf_context_module_disable_all(context, &error));
tests/libdnf/module/ContextTest.cpp:    g_assert(!dnf_context_install(context, "httpd-2.4.25-8.x86_64", &error));
tests/libdnf/module/ContextTest.cpp:    g_assert(error);
tests/libdnf/module/ContextTest.cpp:    g_assert(strstr(error->message, "No package matches 'httpd-2.4.25-8.x86_64'"));
tests/libdnf/module/ContextTest.cpp:    g_assert(dnf_context_reset_all_modules(context, sack, &error));
tests/libdnf/module/ContextTest.cpp:    g_assert(dnf_context_module_install(context, module_specs, &error));
tests/libdnf/module/ContextTest.cpp:    g_assert(pkgs);
tests/libdnf/module/ContextTest.cpp:    g_assert(pkglist_has_nevra(pkgs, "httpd-2.4.25-8.x86_64"));
tests/libdnf/module/ContextTest.cpp:    g_assert(pkglist_has_nevra(pkgs, "libnghttp2-1.21.1-1.x86_64"));
tests/libdnf/module/ContextTest.cpp:    g_assert(dnf_context_module_install(context, module_specs, &error));
@jan-kolarik
Copy link
Member

Hi, thanks for the report. I agree we should fix that and replace the g_assert occurrences by other assertions.

@jan-kolarik jan-kolarik added the Triaged Someone on the DNF 5 team has read the issue and determined the next steps to take label Mar 11, 2024
@github-project-automation github-project-automation bot moved this to Backlog in DNF team Mar 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Triaged Someone on the DNF 5 team has read the issue and determined the next steps to take
Projects
Status: Backlog
Development

No branches or pull requests

2 participants