Skip to content

Commit

Permalink
unittest: Add testsuite for smb_probe_module()
Browse files Browse the repository at this point in the history
BUG: https://bugzilla.samba.org/show_bug.cgi?id=12780

Signed-off-by: Andreas Schneider <[email protected]>
Reviewed-by: Jeremy Allison <[email protected]>
  • Loading branch information
cryptomilk authored and jrasamba committed Jun 6, 2017
1 parent eaf8e3a commit 61f827b
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 0 deletions.
2 changes: 2 additions & 0 deletions selftest/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,5 @@
[os.path.join(bindir(), "default/testsuite/unittests/test_krb5samba")])
plantestsuite("samba.unittests.sambafs_srv_pipe", "none",
[os.path.join(bindir(), "default/testsuite/unittests/test_sambafs_srv_pipe")])
plantestsuite("samba.unittests.lib_util_modules", "none",
[os.path.join(bindir(), "default/testsuite/unittests/test_lib_util_modules")])
76 changes: 76 additions & 0 deletions testsuite/unittests/test_lib_util_modules.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>

#include <errno.h>
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
#include <unistd.h>
#include <sys/stat.h>
#include <talloc.h>

#include "include/config.h"
#include "libcli/util/ntstatus.h"
#include "lib/util/samba_modules.h"

static int teardown(void **state)
{
unsetenv("UNITTEST_DUMMY_MODULE_LOADED");

return 0;
}

static void test_samba_module_probe(void **state)
{
NTSTATUS status;

status = smb_probe_module("auth", "unix");
assert_true(NT_STATUS_IS_OK(status));
}

static void test_samba_module_probe_dummy(void **state)
{
const char *module_env;
NTSTATUS status;

status = smb_probe_module("rpc", "test_dummy_module");
assert_true(NT_STATUS_IS_OK(status));

module_env = getenv("UNITTEST_DUMMY_MODULE_LOADED");
assert_non_null(module_env);
assert_string_equal(module_env, "TRUE");
}

static void test_samba_module_probe_slash(void **state)
{
char dummy_module_path[4096] = {0};
const char *module_env;
NTSTATUS status;

snprintf(dummy_module_path,
sizeof(dummy_module_path),
"%s/bin/modules/rpc/test_dummy_module.so",
SRCDIR);

status = smb_probe_module("rpc", dummy_module_path);
assert_true(NT_STATUS_IS_ERR(status));

module_env = getenv("UNITTEST_DUMMY_MODULE_LOADED");
assert_null(module_env);
}

int main(void) {
const struct CMUnitTest tests[] = {
cmocka_unit_test_teardown(test_samba_module_probe,
teardown),
cmocka_unit_test_teardown(test_samba_module_probe_dummy,
teardown),
cmocka_unit_test_teardown(test_samba_module_probe_slash,
teardown),
};

cmocka_set_message_output(CM_OUTPUT_SUBUNIT);
return cmocka_run_group_tests(tests, NULL, NULL);
}
8 changes: 8 additions & 0 deletions testsuite/unittests/wscript
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ def build(bld):
''',
install=False)

bld.SAMBA_BINARY('test_lib_util_modules',
source='test_lib_util_modules.c',
deps='''
samba-modules
cmocka
''',
install=False)

bld.SAMBA_MODULE('rpc_test_dummy_module',
source='rpc_test_dummy_module.c',
deps='ndr',
Expand Down

0 comments on commit 61f827b

Please sign in to comment.