1 /*
2    Unix SMB/CIFS implementation.
3 
4    local testing of torture
5 
6    Copyright (C) Jelmer Vernooij 2006
7 
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 2 of the License, or
11    (at your option) any later version.
12 
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17 
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22 
23 #include "includes.h"
24 #include "torture/torture.h"
25 #include "system/wait.h"
26 #include "lib/events/events.h"
27 #include "libcli/raw/libcliraw.h"
28 #include "torture/util.h"
29 
test_tempdir(struct torture_context * tctx)30 static bool test_tempdir(struct torture_context *tctx)
31 {
32 	char *location = NULL;
33 	TALLOC_CTX *mem_ctx = tctx;
34 
35 	torture_assert_ntstatus_ok(tctx, torture_temp_dir(mem_ctx, "tempdir", &location),
36 								"torture_temp_dir should return NT_STATUS_OK" );
37 
38 	torture_assert(tctx, directory_exist(location),
39 				   "created dir doesn't exist");
40 	return true;
41 }
42 
test_setup_server(struct torture_context * tctx)43 static bool test_setup_server(struct torture_context *tctx)
44 {
45 	pid_t pid;
46 	TALLOC_CTX *mem_ctx = tctx;
47 
48 	torture_assert_ntstatus_ok(tctx, torture_setup_server(mem_ctx,
49 									"setupserver-success",
50 									"./script/tests/mktestsetup.sh",
51 									"./bin/smbd", &pid),
52 							   "starting smbd failed");
53 
54 	torture_assert(tctx, pid > 0, "Pid invalid");
55 
56 	torture_comment(tctx, "Created smbd with pid %d\n", pid);
57 
58 	kill(pid, SIGINT);
59 
60 	waitpid(pid, NULL, 0);
61 
62 	torture_assert_ntstatus_equal(tctx, torture_setup_server(mem_ctx,
63 									"setupserver-fail",
64 									"./invalid-script",
65 									"./bin/smbd", &pid),
66 								  NT_STATUS_UNSUCCESSFUL,
67 							   "invalid script specified");
68 
69 	torture_assert(tctx, pid == -1, "Pid not -1 after failure");
70 	return true;
71 }
72 
73 
torture_local_torture(TALLOC_CTX * mem_ctx)74 struct torture_suite *torture_local_torture(TALLOC_CTX *mem_ctx)
75 {
76 	struct torture_suite *suite = torture_suite_create(mem_ctx,
77 													   "TORTURE");
78 
79 	torture_suite_add_simple_test(suite, "tempdir", test_tempdir);
80 	torture_suite_add_simple_test(suite, "setup server", test_setup_server);
81 
82 	return suite;
83 }
84