summaryrefslogtreecommitdiff
path: root/source4/torture/nbt/dgram.c
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2006-10-16 13:06:41 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 14:21:12 -0500
commit8773e743c518578584d07d35ffdafdd598af88b0 (patch)
tree89726232dd6ae9eca1c219e21729a9b2336ddaa9 /source4/torture/nbt/dgram.c
parent0f2347e417dec4a50f95d64353b260cd53a44a2b (diff)
downloadsamba-8773e743c518578584d07d35ffdafdd598af88b0.tar.gz
r19339: Merge my 4.0-unittest branch. This adds an API for more fine-grained
output in the testsuite rather than just True or False for a set of tests. The aim is to use this for: * known failure lists (run all tests and detect tests that started working or started failing). This would allow us to get rid of the RPC-SAMBA3-* tests * nicer torture output * simplification of the testsuite system * compatibility with other unit testing systems * easier usage of smbtorture (being able to run one test and automatically set up the environment for that) This is still a work-in-progress; expect more updates over the next couple of days. (This used to be commit 0eb6097305776325c75081356309115f445a7218)
Diffstat (limited to 'source4/torture/nbt/dgram.c')
-rw-r--r--source4/torture/nbt/dgram.c180
1 files changed, 78 insertions, 102 deletions
diff --git a/source4/torture/nbt/dgram.c b/source4/torture/nbt/dgram.c
index def8adaa48b..9183019ad4f 100644
--- a/source4/torture/nbt/dgram.c
+++ b/source4/torture/nbt/dgram.c
@@ -61,13 +61,12 @@ static void netlogon_handler(struct dgram_mailslot_handler *dgmslot,
/* test UDP/138 netlogon requests */
-static BOOL nbt_test_netlogon(TALLOC_CTX *mem_ctx,
- struct nbt_name name, const char *address)
+static bool nbt_test_netlogon(struct torture_context *tctx)
{
struct dgram_mailslot_handler *dgmslot;
- struct nbt_dgram_socket *dgmsock = nbt_dgram_socket_init(mem_ctx, NULL);
+ struct nbt_dgram_socket *dgmsock = nbt_dgram_socket_init(tctx, NULL);
struct socket_address *dest;
- const char *myaddress = talloc_strdup(dgmsock, iface_best_ip(address));
+ const char *myaddress;
struct nbt_netlogon_packet logon;
struct nbt_name myname;
NTSTATUS status;
@@ -76,11 +75,25 @@ static BOOL nbt_test_netlogon(TALLOC_CTX *mem_ctx,
struct socket_address *socket_address;
+ const char *address;
+ struct nbt_name name;
+
+ name.name = lp_workgroup();
+ name.type = NBT_NAME_LOGON;
+ name.scope = NULL;
+
+ /* do an initial name resolution to find its IP */
+ torture_assert_ntstatus_ok(tctx,
+ resolve_name(&name, tctx, &address, event_context_find(tctx)),
+ talloc_asprintf(tctx, "Failed to resolve %s", name.name));
+
+ myaddress = talloc_strdup(dgmsock, iface_best_ip(address));
+
+
socket_address = socket_address_from_strings(dgmsock, dgmsock->sock->backend_name,
myaddress, lp_dgram_port());
- if (!socket_address) {
- return False;
- }
+ torture_assert(tctx, socket_address != NULL,
+ "Error getting address");
/* try receiving replies on port 138 first, which will only
work if we are root and smbd/nmbd are not running - fall
@@ -91,9 +104,7 @@ static BOOL nbt_test_netlogon(TALLOC_CTX *mem_ctx,
talloc_free(socket_address);
socket_address = socket_address_from_strings(dgmsock, dgmsock->sock->backend_name,
myaddress, 0);
- if (!socket_address) {
- return False;
- }
+ torture_assert(tctx, socket_address != NULL, "Error getting address");
socket_listen(dgmsock->sock, socket_address, 0, 0);
}
@@ -115,38 +126,27 @@ static BOOL nbt_test_netlogon(TALLOC_CTX *mem_ctx,
dest = socket_address_from_strings(dgmsock, dgmsock->sock->backend_name,
address, 0);
- if (!dest) {
- return False;
- }
+ torture_assert(tctx, dest != NULL, "Error getting address");
status = dgram_mailslot_netlogon_send(dgmsock, &name, dest,
&myname, &logon);
- if (!NT_STATUS_IS_OK(status)) {
- printf("Failed to send netlogon request - %s\n", nt_errstr(status));
- goto failed;
- }
+ torture_assert_ntstatus_ok(tctx, status, "Failed to send netlogon request");
while (timeval_elapsed(&tv) < 5 && replies == 0) {
event_loop_once(dgmsock->event_ctx);
}
- talloc_free(dgmsock);
- return True;
-
-failed:
- talloc_free(dgmsock);
- return False;
+ return true;
}
/* test UDP/138 netlogon requests */
-static BOOL nbt_test_netlogon2(TALLOC_CTX *mem_ctx,
- struct nbt_name name, const char *address)
+static bool nbt_test_netlogon2(struct torture_context *tctx)
{
struct dgram_mailslot_handler *dgmslot;
- struct nbt_dgram_socket *dgmsock = nbt_dgram_socket_init(mem_ctx, NULL);
+ struct nbt_dgram_socket *dgmsock = nbt_dgram_socket_init(tctx, NULL);
struct socket_address *dest;
- const char *myaddress = talloc_strdup(dgmsock, iface_best_ip(address));
+ const char *myaddress;
struct nbt_netlogon_packet logon;
struct nbt_name myname;
NTSTATUS status;
@@ -155,11 +155,23 @@ static BOOL nbt_test_netlogon2(TALLOC_CTX *mem_ctx,
struct socket_address *socket_address;
+ const char *address;
+ struct nbt_name name;
+
+ name.name = lp_workgroup();
+ name.type = NBT_NAME_LOGON;
+ name.scope = NULL;
+
+ /* do an initial name resolution to find its IP */
+ torture_assert_ntstatus_ok(tctx,
+ resolve_name(&name, tctx, &address, event_context_find(tctx)),
+ talloc_asprintf(tctx, "Failed to resolve %s", name.name));
+
+ myaddress = talloc_strdup(dgmsock, iface_best_ip(address));
+
socket_address = socket_address_from_strings(dgmsock, dgmsock->sock->backend_name,
myaddress, lp_dgram_port());
- if (!socket_address) {
- return False;
- }
+ torture_assert(tctx, socket_address != NULL, "Error getting address");
/* try receiving replies on port 138 first, which will only
work if we are root and smbd/nmbd are not running - fall
@@ -170,9 +182,8 @@ static BOOL nbt_test_netlogon2(TALLOC_CTX *mem_ctx,
talloc_free(socket_address);
socket_address = socket_address_from_strings(dgmsock, dgmsock->sock->backend_name,
myaddress, 0);
- if (!socket_address) {
- return False;
- }
+
+ torture_assert(tctx, socket_address != NULL, "Error getting address");
socket_listen(dgmsock->sock, socket_address, 0, 0);
}
@@ -196,27 +207,17 @@ static BOOL nbt_test_netlogon2(TALLOC_CTX *mem_ctx,
dest = socket_address_from_strings(dgmsock, dgmsock->sock->backend_name,
address, 0);
- if (!dest) {
- goto failed;
- }
+
+ torture_assert(tctx, dest != NULL, "Error getting address");
status = dgram_mailslot_netlogon_send(dgmsock, &name, dest,
&myname, &logon);
- if (!NT_STATUS_IS_OK(status)) {
- printf("Failed to send netlogon request - %s\n", nt_errstr(status));
- goto failed;
- }
-
+ torture_assert_ntstatus_ok(tctx, status, "Failed to send netlogon request");
while (timeval_elapsed(&tv) < 5 && replies == 0) {
event_loop_once(dgmsock->event_ctx);
}
- talloc_free(dgmsock);
- return True;
-
-failed:
- talloc_free(dgmsock);
- return False;
+ return true;
}
@@ -247,17 +248,16 @@ static void ntlogon_handler(struct dgram_mailslot_handler *dgmslot,
/* test UDP/138 ntlogon requests */
-static BOOL nbt_test_ntlogon(TALLOC_CTX *mem_ctx,
- struct nbt_name name, const char *address)
+static bool nbt_test_ntlogon(struct torture_context *tctx)
{
struct dgram_mailslot_handler *dgmslot;
- struct nbt_dgram_socket *dgmsock = nbt_dgram_socket_init(mem_ctx, NULL);
+ struct nbt_dgram_socket *dgmsock = nbt_dgram_socket_init(tctx, NULL);
struct socket_address *dest;
struct test_join *join_ctx;
struct cli_credentials *machine_credentials;
const struct dom_sid *dom_sid;
- const char *myaddress = talloc_strdup(dgmsock, iface_best_ip(address));
+ const char *myaddress;
struct nbt_ntlogon_packet logon;
struct nbt_name myname;
NTSTATUS status;
@@ -265,12 +265,23 @@ static BOOL nbt_test_ntlogon(TALLOC_CTX *mem_ctx,
int replies = 0;
struct socket_address *socket_address;
+ const char *address;
+ struct nbt_name name;
+
+ name.name = lp_workgroup();
+ name.type = NBT_NAME_LOGON;
+ name.scope = NULL;
+
+ /* do an initial name resolution to find its IP */
+ torture_assert_ntstatus_ok(tctx,
+ resolve_name(&name, tctx, &address, event_context_find(tctx)),
+ talloc_asprintf(tctx, "Failed to resolve %s", name.name));
+
+ myaddress = talloc_strdup(dgmsock, iface_best_ip(address));
socket_address = socket_address_from_strings(dgmsock, dgmsock->sock->backend_name,
myaddress, lp_dgram_port());
- if (!socket_address) {
- return False;
- }
+ torture_assert(tctx, socket_address != NULL, "Error getting address");
/* try receiving replies on port 138 first, which will only
work if we are root and smbd/nmbd are not running - fall
@@ -281,20 +292,15 @@ static BOOL nbt_test_ntlogon(TALLOC_CTX *mem_ctx,
talloc_free(socket_address);
socket_address = socket_address_from_strings(dgmsock, dgmsock->sock->backend_name,
myaddress, 0);
- if (!socket_address) {
- return False;
- }
+ torture_assert(tctx, socket_address != NULL, "Error getting address");
socket_listen(dgmsock->sock, socket_address, 0, 0);
}
join_ctx = torture_join_domain(TEST_NAME,
ACB_WSTRUST, &machine_credentials);
- if (join_ctx == NULL) {
- printf("Failed to join domain %s as %s\n", lp_workgroup(), TEST_NAME);
- talloc_free(dgmsock);
- return False;
- }
+ torture_assert(tctx, join_ctx != NULL,
+ talloc_asprintf(tctx, "Failed to join domain %s as %s\n", lp_workgroup(), TEST_NAME));
dom_sid = torture_join_sid(join_ctx);
@@ -319,61 +325,31 @@ static BOOL nbt_test_ntlogon(TALLOC_CTX *mem_ctx,
dest = socket_address_from_strings(dgmsock, dgmsock->sock->backend_name,
address, 0);
- if (!dest) {
- goto failed;
- }
+ torture_assert(tctx, dest != NULL, "Error getting address");
status = dgram_mailslot_ntlogon_send(dgmsock, DGRAM_DIRECT_UNIQUE,
&name, dest, &myname, &logon);
- if (!NT_STATUS_IS_OK(status)) {
- printf("Failed to send ntlogon request - %s\n", nt_errstr(status));
- goto failed;
- }
-
+ torture_assert_ntstatus_ok(tctx, status, "Failed to send ntlogon request");
while (timeval_elapsed(&tv) < 5 && replies == 0) {
event_loop_once(dgmsock->event_ctx);
}
torture_leave_domain(join_ctx);
- talloc_free(dgmsock);
- return True;
-
-failed:
- torture_leave_domain(join_ctx);
- talloc_free(dgmsock);
- return False;
+ return true;
}
/*
test nbt dgram operations
*/
-BOOL torture_nbt_dgram(struct torture_context *torture)
+struct torture_suite *torture_nbt_dgram(void)
{
- const char *address;
- struct nbt_name name;
- TALLOC_CTX *mem_ctx = talloc_new(NULL);
- NTSTATUS status;
- BOOL ret = True;
-
- name.name = lp_workgroup();
- name.type = NBT_NAME_LOGON;
- name.scope = NULL;
-
- /* do an initial name resolution to find its IP */
- status = resolve_name(&name, mem_ctx, &address, event_context_find(mem_ctx));
- if (!NT_STATUS_IS_OK(status)) {
- printf("Failed to resolve %s - %s\n",
- name.name, nt_errstr(status));
- talloc_free(mem_ctx);
- return False;
- }
-
- ret &= nbt_test_netlogon(mem_ctx, name, address);
- ret &= nbt_test_netlogon2(mem_ctx, name, address);
- ret &= nbt_test_ntlogon(mem_ctx, name, address);
+ struct torture_suite *suite = torture_suite_create(talloc_autofree_context(),
+ "DGRAM");
- talloc_free(mem_ctx);
+ torture_suite_add_simple_test(suite, "netlogon", nbt_test_netlogon);
+ torture_suite_add_simple_test(suite, "netlogon2", nbt_test_netlogon2);
+ torture_suite_add_simple_test(suite, "ntlogon", nbt_test_ntlogon);
- return ret;
+ return suite;
}