Skip to content

Commit

Permalink
tests: allow to run single pam-srv-tests tests
Browse files Browse the repository at this point in the history
Since each pam-srv-test will remove the test directory the --no-cleanup
option only makes sense if a test can be run individually.

Resolves: #6081

Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
Reviewed-by: Tomáš Halman <thalman@redhat.com>
  • Loading branch information
sumit-bose authored and pbrezina committed Apr 6, 2022
1 parent 34829d3 commit 5c5a6b8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
1 change: 1 addition & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -2573,6 +2573,7 @@ EXTRA_pam_srv_tests_DEPENDENCIES += p11_child
pam_srv_tests_SOURCES = \
$(TEST_MOCK_RESP_OBJ) \
src/tests/cmocka/test_pam_srv.c \
src/tests/cmocka/common_utils.c \
src/sss_client/pam_message.c \
src/responder/pam/pamsrv_cmd.c \
src/responder/pam/pamsrv_p11.c \
Expand Down
37 changes: 28 additions & 9 deletions src/tests/cmocka/test_pam_srv.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@
#define TEST5_KEY_ID "1195833C424AB00297F582FC43FFFFAB47A64CC9"
#define TEST5_LABEL "SSSD test cert 0005"

int no_cleanup;

static char CACHED_AUTH_TIMEOUT_STR[] = "4";
static const int CACHED_AUTH_TIMEOUT = 4;

Expand Down Expand Up @@ -393,7 +395,9 @@ static int pam_test_teardown(void **state)
pam_test_ctx->wrong_user_fqdn, 0);
assert_int_equal(ret, EOK);

test_dom_suite_cleanup(TESTS_PATH, TEST_CONF_DB, TEST_DOM_NAME);
if (!no_cleanup) {
test_dom_suite_cleanup(TESTS_PATH, TEST_CONF_DB, TEST_DOM_NAME);
}

talloc_free(pam_test_ctx);
return 0;
Expand Down Expand Up @@ -3839,15 +3843,18 @@ void test_pam_prompting_2fa_single_and_service_srv(void **state)

int main(int argc, const char *argv[])
{
int rv;
int no_cleanup = 0;
poptContext pc;
int opt;
const char *single = NULL;
struct poptOption long_options[] = {
POPT_AUTOHELP
SSSD_DEBUG_OPTS
{ "no-cleanup", 'n', POPT_ARG_NONE, &no_cleanup, 0,
_("Do not delete the test database after a test run"), NULL },
_("Do not delete the test database after a single test is run"),
NULL },
{ "list-tests", 'l', POPT_ARG_NONE, NULL, 'l',
_("Show all available tests"),
NULL },
POPT_TABLEEND
};

Expand Down Expand Up @@ -4053,15 +4060,30 @@ int main(int argc, const char *argv[])
debug_level = SSSDBG_INVALID;

pc = poptGetContext(argv[0], argc, argv, long_options, 0);
poptSetOtherOptionHelp(pc, "[OPTION...] [name_of_a_single_test]");
while ((opt = poptGetNextOpt(pc)) != -1) {
switch (opt) {
case 'l':
fprintf(stderr, "\nAvailable tests:\n");
list_tests(stderr, " -", tests, sizeof(tests)/sizeof(tests[0]));
return 0;
default:
fprintf(stderr, "\nInvalid option %s: %s\n\n",
poptBadOption(pc, 0), poptStrerror(opt));
poptPrintUsage(pc, stderr, 0);
return 1;
}
}

single = poptGetArg(pc);

if (single == NULL && no_cleanup) {
fprintf(stderr, "\nThe --no-cleanup makes only sense when running "
"a single test.\n\n");
poptPrintUsage(pc, stderr, 0);
return 1;
}

poptFreeContext(pc);

DEBUG_CLI_INIT(debug_level);
Expand All @@ -4071,10 +4093,7 @@ int main(int argc, const char *argv[])
tests_set_cwd();
test_dom_suite_cleanup(TESTS_PATH, TEST_CONF_DB, TEST_DOM_NAME);

rv = cmocka_run_group_tests(tests, NULL, NULL);
if (rv == 0 && !no_cleanup) {
test_dom_suite_cleanup(TESTS_PATH, TEST_CONF_DB, TEST_DOM_NAME);
}
return sss_cmocka_run_group_tests(tests, sizeof(tests)/sizeof(tests[0]),
single);

return rv;
}

0 comments on commit 5c5a6b8

Please sign in to comment.