diff options
author | Jelmer Vernooij <jelmer@samba.org> | 2006-06-26 19:30:00 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 14:09:32 -0500 |
commit | 6b749f225e8d1c910820a6576952f130e72bab84 (patch) | |
tree | 1e25d021b072638ff2528f42f08e553a534ed018 /source4/torture | |
parent | 993012bd2adaaa81d06341cdc36fccc919b0a91b (diff) | |
download | samba-6b749f225e8d1c910820a6576952f130e72bab84.tar.gz samba-6b749f225e8d1c910820a6576952f130e72bab84.tar.bz2 samba-6b749f225e8d1c910820a6576952f130e72bab84.zip |
r16526: Add torture_setup_server() with test.
(This used to be commit 6a1ed8ad756b97f61d4af9df2c7a7d889a2d09ef)
Diffstat (limited to 'source4/torture')
-rw-r--r-- | source4/torture/local/torture.c | 31 | ||||
-rw-r--r-- | source4/torture/util.c | 74 |
2 files changed, 104 insertions, 1 deletions
diff --git a/source4/torture/local/torture.c b/source4/torture/local/torture.c index ed601b663f..76581540a1 100644 --- a/source4/torture/local/torture.c +++ b/source4/torture/local/torture.c @@ -22,6 +22,7 @@ #include "includes.h" #include "torture/torture.h" +#include "system/wait.h" #include "torture/util.h" static BOOL test_tempdir(struct torture_context *torture, @@ -38,12 +39,42 @@ static BOOL test_tempdir(struct torture_context *torture, return True; } +static BOOL test_setup_server(struct torture_context *torture, + const void *_data) +{ + pid_t pid; + + torture_assert_ntstatus_ok(torture, torture_setup_server(torture, + "./script/tests/mktestsetup.sh", + "./bin/smbd", &pid), + "starting smbd failed"); + + torture_assert(torture, pid > 0, "Pid invalid"); + + torture_comment(torture, "Created smbd with pid %d", pid); + + kill(pid, SIGINT); + + waitpid(pid, NULL, 0); + + torture_assert_ntstatus_equal(torture, torture_setup_server(torture, + "./invalid-script", + "./bin/smbd", &pid), + NT_STATUS_UNSUCCESSFUL, + "invalid script specified"); + + torture_assert(torture, pid == -1, "Pid not -1 after failure"); + + return True; +} + struct torture_suite *torture_local_torture(TALLOC_CTX *mem_ctx) { struct torture_suite *suite = torture_suite_create(mem_ctx, "LOCAL-TORTURE"); torture_suite_add_simple_tcase(suite, "tempdir", test_tempdir, NULL); + torture_suite_add_simple_tcase(suite, "setup server", test_setup_server, NULL); return suite; } diff --git a/source4/torture/util.c b/source4/torture/util.c index bd2bc493c5..5df90163ad 100644 --- a/source4/torture/util.c +++ b/source4/torture/util.c @@ -20,8 +20,12 @@ #include "includes.h" #include "system/filesys.h" +#include "system/wait.h" #include "torture/torture.h" +/** + create a temporary directory. +*/ _PUBLIC_ NTSTATUS torture_temp_dir(TALLOC_CTX *mem_ctx, char **tempdir) { *tempdir = talloc_strdup(mem_ctx, "torture-tmp.XXXXXX"); @@ -33,11 +37,79 @@ _PUBLIC_ NTSTATUS torture_temp_dir(TALLOC_CTX *mem_ctx, char **tempdir) } /** - check if 2 NTTIMEs are equal + check if 2 NTTIMEs are equal. */ BOOL nt_time_equal(NTTIME *t1, NTTIME *t2) { return *t1 == *t2; } +/** + * Provision a Samba installation using @param setupdir_script and start smbd. + */ +NTSTATUS torture_setup_server(TALLOC_CTX *mem_ctx, + const char *setupdir_script, + const char *smbd_path, + pid_t *smbd_pid) +{ + char *tempdir; + NTSTATUS status; + pid_t pid; + int child_status; + char *configfile, *configparam; + pid_t closed_pid; + + *smbd_pid = -1; + + status = torture_temp_dir(mem_ctx, &tempdir); + if (NT_STATUS_IS_ERR(status)) { + return status; + } + + if ((pid = fork()) == 0) { + execl(setupdir_script, setupdir_script, tempdir, NULL); + exit(1); + } else if (pid == -1) { + DEBUG(0, ("Unable to fork()\n")); + return NT_STATUS_UNSUCCESSFUL; + } + + closed_pid = waitpid(pid, &child_status, 0); + + if (closed_pid == -1) { + DEBUG(1, ("Error waiting for child")); + return NT_STATUS_UNSUCCESSFUL; + } + + SMB_ASSERT(closed_pid == pid); + + if (!WIFEXITED(child_status) || WEXITSTATUS(child_status) != 0) { + DEBUG(1, ("Invalid return code from setup script %s: %d\n", + setupdir_script, + WEXITSTATUS(child_status))); + return NT_STATUS_UNSUCCESSFUL; + } + + configfile = talloc_asprintf(mem_ctx, "%s/etc/smb.conf", + tempdir); + if (!file_exist(configfile)) { + DEBUG(1, ("Setup script didn't create %s\n", configfile)); + return NT_STATUS_UNSUCCESSFUL; + } + + configparam = talloc_asprintf(mem_ctx, "--configfile=%s", configfile); + talloc_free(configfile); + if ((pid = fork()) == 0) { + execl(smbd_path, smbd_path, "-i", "--model=single", + configparam, NULL); + exit(1); + } else if (pid == -1) { + DEBUG(0, ("Unable to fork()\n")); + return NT_STATUS_UNSUCCESSFUL; + } + + *smbd_pid = pid; + + return NT_STATUS_OK; +} |