[PATCH 2/6] torture: split pattern write into helper function
Jelmer Vernooij
jelmer at samba.org
Tue Sep 2 14:35:04 MDT 2014
On Tue, Sep 02, 2014 at 08:07:16PM +0200, David Disseldorp wrote:
> This allows for patterned writes after file creation, as needed for
> sparse file integrity testing.
>
> Signed-off-by: David Disseldorp <ddiss at samba.org>
> ---
> source4/torture/smb2/ioctl.c | 55 ++++++++++++++++++++++++++++++--------------
> 1 file changed, 38 insertions(+), 17 deletions(-)
>
> diff --git a/source4/torture/smb2/ioctl.c b/source4/torture/smb2/ioctl.c
> index 3f87958..df380a8 100644
> --- a/source4/torture/smb2/ioctl.c
> +++ b/source4/torture/smb2/ioctl.c
> @@ -119,6 +119,42 @@ static uint64_t patt_hash(uint64_t off)
> return off;
> }
>
> +static bool write_pattern(struct torture_context *torture,
> + struct smb2_tree *tree, TALLOC_CTX *mem_ctx,
> + struct smb2_handle h, uint64_t off, uint64_t len,
> + uint64_t patt_off)
> +{
> + NTSTATUS status;
> + uint64_t i;
> + uint8_t *buf;
> + uint64_t buf_off = 0;
> +
> + if (len == 0) {
> + return true;
> + }
> +
> + buf = talloc_zero_size(mem_ctx, len);
> + torture_assert(torture, (buf != NULL), "no memory for file data buf");
> +
> + for (i = 0; i <= len - 8; i += 8) {
> + SBVAL(buf, i, patt_hash(patt_off));
> + patt_off += 8;
> + }
> +
> + while (len > 0) {
> + uint64_t io_sz = MIN(1024 * 1024, len);
> + status = smb2_util_write(tree, h,
> + buf + buf_off, off, io_sz);
> + torture_assert_ntstatus_ok(torture, status, "file write");
> +
> + len -= io_sz;
> + buf_off += io_sz;
> + off += io_sz;
> + }
> +
> + return true;
> +}
> +
> static bool check_pattern(struct torture_context *torture,
> struct smb2_tree *tree, TALLOC_CTX *mem_ctx,
> struct smb2_handle h, uint64_t off, uint64_t len,
> @@ -189,11 +225,7 @@ static bool test_setup_create_fill(struct torture_context *torture,
> uint32_t desired_access,
> uint32_t file_attributes)
> {
> - NTSTATUS status;
> bool ok;
> - uint64_t i;
> - uint8_t *buf = talloc_zero_size(mem_ctx, size);
> - torture_assert(torture, (buf != NULL), "no memory for file data buf");
>
> smb2_util_unlink(tree, fname);
>
> @@ -205,19 +237,8 @@ static bool test_setup_create_fill(struct torture_context *torture,
> torture_assert(torture, ok, "file open");
>
> if (size > 0) {
> - uint64_t cur_off = 0;
> - for (i = 0; i <= size - 8; i += 8) {
> - SBVAL(buf, i, patt_hash(i));
> - }
> - while (size > 0) {
> - uint64_t io_sz = MIN(1024 * 1024, size);
> - status = smb2_util_write(tree, *fh,
> - buf + cur_off, cur_off, io_sz);
> - torture_assert_ntstatus_ok(torture, status, "file write");
> -
> - size -= io_sz;
> - cur_off += io_sz;
> - }
> + ok = write_pattern(torture, tree, mem_ctx, *fh, 0, size, 0);
> + torture_assert(torture, ok, "write pattern");
You probably don't want to call torture_assert() here, but just return
false if "ok" is false.
Otherwise, torture_assert() will overwrite whatever failure reason was
set by write_pattern().
Cheers,
Jelmer
--
Jelmer Vernooij <jelmer at samba.org> - https://jelmer.uk/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.samba.org/pipermail/samba-technical/attachments/20140902/c5f2167c/attachment.pgp>
More information about the samba-technical
mailing list