[PATCHES] improve smb2.connect test

Jeremy Allison jra at samba.org
Tue Feb 23 00:41:01 UTC 2016


On Tue, Feb 23, 2016 at 12:31:49AM +0100, Michael Adam wrote:
> review appreciated!
> 
> Thanks - Michael

LGTM. Pushed !

> From 8e24cfe07e4f57baf039d9e289edcd29264a2845 Mon Sep 17 00:00:00 2001
> From: Michael Adam <obnox at samba.org>
> Date: Mon, 22 Feb 2016 14:32:44 +0100
> Subject: [PATCH 1/4] torture:smb2: rewrite connect test to use torture_asserts
> 
> Signed-off-by: Michael Adam <obnox at samba.org>
> ---
>  source4/torture/smb2/connect.c | 63 ++++++++++++++----------------------------
>  1 file changed, 20 insertions(+), 43 deletions(-)
> 
> diff --git a/source4/torture/smb2/connect.c b/source4/torture/smb2/connect.c
> index 0067de0..6fd331a 100644
> --- a/source4/torture/smb2/connect.c
> +++ b/source4/torture/smb2/connect.c
> @@ -194,74 +194,51 @@ bool torture_smb2_connect(struct torture_context *torture)
>  	struct smb2_request *req;
>  	struct smb2_handle h1, h2;
>  	NTSTATUS status;
> +	bool ok;
>  
> -	if (!torture_smb2_connection(torture, &tree)) {
> -		return false;
> -	}
> +	ok = torture_smb2_connection(torture, &tree);
> +	torture_assert(torture, ok, "torture_smb2_connection failed");
>  
>  	smb2_util_unlink(tree, "test9.dat");
>  
>  	h1 = torture_smb2_createfile(tree, "test9.dat");
>  	h2 = torture_smb2_createfile(tree, "test9.dat");
> +
>  	status = torture_smb2_write(torture, tree, h1);
> -	if (!NT_STATUS_IS_OK(status)) {
> -		printf("Write failed - %s\n", nt_errstr(status));
> -		return false;
> -	}
> +	torture_assert_ntstatus_ok(torture, status, "write failed");
> +
>  	status = torture_smb2_close(tree, h1);
> -	if (!NT_STATUS_IS_OK(status)) {
> -		printf("Close failed - %s\n", nt_errstr(status));
> -		return false;
> -	}
> +	torture_assert_ntstatus_ok(torture, status, "close failed");
> +
>  	status = torture_smb2_close(tree, h2);
> -	if (!NT_STATUS_IS_OK(status)) {
> -		printf("Close failed - %s\n", nt_errstr(status));
> -		return false;
> -	}
> +	torture_assert_ntstatus_ok(torture, status, "close failed");
>  
>  	status = smb2_util_close(tree, h1);
> -	if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_CLOSED)) {
> -		printf("close should have closed the handle - %s\n", nt_errstr(status));
> -		return false;
> -	}
> +	torture_assert_ntstatus_equal(torture, status, NT_STATUS_FILE_CLOSED,
> +				      "close should have closed the handle");
>  
>  	status = smb2_tdis(tree);
> -	if (!NT_STATUS_IS_OK(status)) {
> -		printf("tdis failed - %s\n", nt_errstr(status));
> -		return false;
> -	}
> +	torture_assert_ntstatus_ok(torture, status, "tdis failed");
>  
>  	status = smb2_tdis(tree);
> -	if (!NT_STATUS_EQUAL(status, NT_STATUS_NETWORK_NAME_DELETED)) {
> -		printf("tdis should have disabled session - %s\n", nt_errstr(status));
> -		return false;
> -	}
> +	torture_assert_ntstatus_equal(torture, status,
> +				      NT_STATUS_NETWORK_NAME_DELETED,
> +				      "tdis should have closed the tcon");
>  
>   	status = smb2_logoff(tree->session);
> -	if (!NT_STATUS_IS_OK(status)) {
> -		printf("Logoff failed - %s\n", nt_errstr(status));
> -		return false;
> -	}
> +	torture_assert_ntstatus_ok(torture, status, "logoff failed");
>  
>  	req = smb2_logoff_send(tree->session);
> -	if (!req) {
> -		printf("smb2_logoff_send() failed\n");
> -		return false;
> -	}
> +	torture_assert_not_null(torture, req, "smb2_logoff_send failed");
>  
>  	req->session = NULL;
>  
>  	status = smb2_logoff_recv(req);
> -	if (!NT_STATUS_EQUAL(status, NT_STATUS_USER_SESSION_DELETED)) {
> -		printf("Logoff should have disabled session - %s\n", nt_errstr(status));
> -		return false;
> -	}
> +	torture_assert_ntstatus_equal(torture, status, NT_STATUS_USER_SESSION_DELETED,
> +				      "logoff should have disabled session");
>  
>  	status = smb2_keepalive(tree->session->transport);
> -	if (!NT_STATUS_IS_OK(status)) {
> -		printf("keepalive failed? - %s\n", nt_errstr(status));
> -		return false;
> -	}
> +	torture_assert_ntstatus_ok(torture, status, "keepalive failed");
>  
>  	talloc_free(mem_ctx);
>  
> -- 
> 2.5.0
> 
> 
> From e122d9e425a978295be2ea07baa2dd294c900ff4 Mon Sep 17 00:00:00 2001
> From: Michael Adam <obnox at samba.org>
> Date: Mon, 22 Feb 2016 16:22:14 +0100
> Subject: [PATCH 2/4] torture:smb2: rewrite connect test to use torture_asserts
>  for create errors
> 
> let torture_smb2_createfile propagate errors
> 
> Signed-off-by: Michael Adam <obnox at samba.org>
> ---
>  source4/torture/smb2/connect.c | 21 +++++++++++++--------
>  1 file changed, 13 insertions(+), 8 deletions(-)
> 
> diff --git a/source4/torture/smb2/connect.c b/source4/torture/smb2/connect.c
> index 6fd331a..f68c34f 100644
> --- a/source4/torture/smb2/connect.c
> +++ b/source4/torture/smb2/connect.c
> @@ -137,8 +137,9 @@ static NTSTATUS torture_smb2_write(struct torture_context *tctx, struct smb2_tre
>  /*
>    send a create
>  */
> -static struct smb2_handle torture_smb2_createfile(struct smb2_tree *tree, 
> -					      const char *fname)
> +static NTSTATUS torture_smb2_createfile(struct smb2_tree *tree,
> +					const char *fname,
> +					struct smb2_handle *handle)
>  {
>  	struct smb2_create io;
>  	NTSTATUS status;
> @@ -158,8 +159,7 @@ static struct smb2_handle torture_smb2_createfile(struct smb2_tree *tree,
>  
>  	status = smb2_create(tree, tmp_ctx, &io);
>  	if (!NT_STATUS_IS_OK(status)) {
> -		printf("create1 failed - %s\n", nt_errstr(status));
> -		return io.out.file.handle;
> +		return status;
>  	}
>  
>  	if (DEBUGLVL(1)) {
> @@ -179,8 +179,10 @@ static struct smb2_handle torture_smb2_createfile(struct smb2_tree *tree,
>  	}
>  
>  	talloc_free(tmp_ctx);
> -	
> -	return io.out.file.handle;
> +
> +	*handle = io.out.file.handle;
> +
> +	return NT_STATUS_OK;
>  }
>  
>  
> @@ -201,8 +203,11 @@ bool torture_smb2_connect(struct torture_context *torture)
>  
>  	smb2_util_unlink(tree, "test9.dat");
>  
> -	h1 = torture_smb2_createfile(tree, "test9.dat");
> -	h2 = torture_smb2_createfile(tree, "test9.dat");
> +	status = torture_smb2_createfile(tree, "test9.dat", &h1);
> +	torture_assert_ntstatus_ok(torture, status, "create failed");
> +
> +	status = torture_smb2_createfile(tree, "test9.dat", &h2);
> +	torture_assert_ntstatus_ok(torture, status, "create failed");
>  
>  	status = torture_smb2_write(torture, tree, h1);
>  	torture_assert_ntstatus_ok(torture, status, "write failed");
> -- 
> 2.5.0
> 
> 
> From 80d69b3bf85b4e1899e6d25c2de48d65be9b8e57 Mon Sep 17 00:00:00 2001
> From: Michael Adam <obnox at samba.org>
> Date: Mon, 22 Feb 2016 23:23:13 +0100
> Subject: [PATCH 3/4] torture:smb2: fix memory leak in connect test.
> 
> Signed-off-by: Michael Adam <obnox at samba.org>
> ---
>  source4/torture/smb2/connect.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/source4/torture/smb2/connect.c b/source4/torture/smb2/connect.c
> index f68c34f..e3716be 100644
> --- a/source4/torture/smb2/connect.c
> +++ b/source4/torture/smb2/connect.c
> @@ -159,6 +159,7 @@ static NTSTATUS torture_smb2_createfile(struct smb2_tree *tree,
>  
>  	status = smb2_create(tree, tmp_ctx, &io);
>  	if (!NT_STATUS_IS_OK(status)) {
> +		TALLOC_FREE(tmp_ctx);
>  		return status;
>  	}
>  
> -- 
> 2.5.0
> 
> 
> From f43937f8f98b6060d896fb237a6bb03dbd992306 Mon Sep 17 00:00:00 2001
> From: Michael Adam <obnox at samba.org>
> Date: Tue, 23 Feb 2016 00:27:11 +0100
> Subject: [PATCH 4/4] torture:smb2: improve torture_comments in connect test
> 
> Signed-off-by: Michael Adam <obnox at samba.org>
> ---
>  source4/torture/smb2/connect.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/source4/torture/smb2/connect.c b/source4/torture/smb2/connect.c
> index e3716be..6340430 100644
> --- a/source4/torture/smb2/connect.c
> +++ b/source4/torture/smb2/connect.c
> @@ -90,7 +90,7 @@ static NTSTATUS torture_smb2_write(struct torture_context *tctx, struct smb2_tre
>  
>  	status = smb2_write(tree, &w);
>  	if (!NT_STATUS_IS_OK(status)) {
> -		printf("write failed - %s\n", nt_errstr(status));
> +		printf("write 1 failed - %s\n", nt_errstr(status));
>  		return status;
>  	}
>  
> @@ -98,7 +98,7 @@ static NTSTATUS torture_smb2_write(struct torture_context *tctx, struct smb2_tre
>  
>  	status = smb2_write(tree, &w);
>  	if (!NT_STATUS_IS_OK(status)) {
> -		printf("write failed - %s\n", nt_errstr(status));
> +		printf("write 2 failed - %s\n", nt_errstr(status));
>  		return status;
>  	}
>  
> -- 
> 2.5.0
> 






More information about the samba-technical mailing list