From 0e255bb542b1f79c32e9295617199ea8d60753d4 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 12 Nov 2004 09:37:59 +0000 Subject: r3699: - split the delayed write testing out of RAW-WRITE, as it is not yet clear what the correct behaviour is for delayed stat info update. - use a common torture_setup_dir() function for setting up a test directory in torture tests. (This used to be commit f7fb34715b7d6ea3c35ddd684cfb27459a420339) --- source4/torture/basic/delaywrite.c | 284 +++++++++++++++++++++++++++++++++++++ 1 file changed, 284 insertions(+) create mode 100644 source4/torture/basic/delaywrite.c (limited to 'source4/torture/basic/delaywrite.c') diff --git a/source4/torture/basic/delaywrite.c b/source4/torture/basic/delaywrite.c new file mode 100644 index 0000000000..3a632c49ea --- /dev/null +++ b/source4/torture/basic/delaywrite.c @@ -0,0 +1,284 @@ +/* + Unix SMB/CIFS implementation. + + test suite for delayed write update + + Copyright (C) Volker Lendecke 2004 + Copyright (C) Andrew Tridgell 2004 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" +#include "libcli/raw/libcliraw.h" +#include "system/time.h" + +#define BASEDIR "\\delaywrite" + +static BOOL test_delayed_write_update(struct smbcli_state *cli, TALLOC_CTX *mem_ctx) +{ + union smb_fileinfo finfo1, finfo2; + const char *fname = BASEDIR "\\torture_file.txt"; + NTSTATUS status; + int fnum1 = -1; + BOOL ret = True; + ssize_t written; + time_t t; + + printf("Testing delayed update of write time\n"); + + if (!torture_setup_dir(cli, BASEDIR)) { + return False; + } + + fnum1 = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE); + if (fnum1 == -1) { + printf("Failed to open %s\n", fname); + return False; + } + + finfo1.basic_info.level = RAW_FILEINFO_BASIC_INFO; + finfo1.basic_info.in.fnum = fnum1; + finfo2 = finfo1; + + status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo1); + + if (!NT_STATUS_IS_OK(status)) { + DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status))); + return False; + } + + printf("Initial write time %s\n", + nt_time_string(mem_ctx, finfo1.basic_info.out.write_time)); + + /* 3 second delay to ensure we get past any 2 second time + granularity (older systems may have that) */ + sleep(3); + + written = smbcli_write(cli->tree, fnum1, 0, "x", 0, 1); + + if (written != 1) { + printf("write failed - wrote %d bytes (%s)\n", written, __location__); + return False; + } + + t = time(NULL); + + while (time(NULL) < t+120) { + status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo2); + + if (!NT_STATUS_IS_OK(status)) { + DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status))); + ret = False; + break; + } + printf("write time %s\n", + nt_time_string(mem_ctx, finfo2.basic_info.out.write_time)); + if (finfo1.basic_info.out.write_time != finfo2.basic_info.out.write_time) { + printf("Server updated write_time after %d seconds\n", + (int)(time(NULL) - t)); + break; + } + sleep(1); + fflush(stdout); + } + + if (finfo1.basic_info.out.write_time == finfo2.basic_info.out.write_time) { + printf("Server did not update write time?!\n"); + ret = False; + } + + + if (fnum1 != -1) + smbcli_close(cli->tree, fnum1); + smbcli_unlink(cli->tree, fname); + smbcli_deltree(cli->tree, BASEDIR); + + return ret; +} + + +/* Windows does obviously not update the stat info during a write call. I + * *think* this is the problem causing a spurious Excel 2003 on XP error + * message when saving a file. Excel does a setfileinfo, writes, and then does + * a getpath(!)info. Or so... For Samba sometimes it displays an error message + * that the file might have been changed in between. What i've been able to + * trace down is that this happens if the getpathinfo after the write shows a + * different last write time than the setfileinfo showed. This is really + * nasty.... + */ + +static BOOL test_finfo_after_write(struct smbcli_state *cli, TALLOC_CTX *mem_ctx) +{ + union smb_fileinfo finfo1, finfo2; + const char *fname = BASEDIR "\\torture_file.txt"; + NTSTATUS status; + int fnum1 = -1; + int fnum2; + BOOL ret = True; + ssize_t written; + struct smbcli_state *cli2=NULL; + + printf("Testing finfo update on close\n"); + + if (!torture_setup_dir(cli, BASEDIR)) { + return False; + } + + fnum1 = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE); + if (fnum1 == -1) { + ret = False; + goto done; + } + + finfo1.basic_info.level = RAW_FILEINFO_BASIC_INFO; + finfo1.basic_info.in.fnum = fnum1; + + status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo1); + + if (!NT_STATUS_IS_OK(status)) { + DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status))); + ret = False; + goto done; + } + + msleep(1000); + + written = smbcli_write(cli->tree, fnum1, 0, "x", 0, 1); + + if (written != 1) { + printf("(%s) written gave %d - should have been 1\n", + __location__, written); + ret = False; + goto done; + } + + if (!torture_open_connection(&cli2)) { + return False; + } + + fnum2 = smbcli_open(cli2->tree, fname, O_RDWR, DENY_NONE); + if (fnum2 == -1) { + printf("(%s) failed to open 2nd time - %s\n", + __location__, smbcli_errstr(cli2->tree)); + ret = False; + goto done; + } + + written = smbcli_write(cli2->tree, fnum2, 0, "x", 0, 1); + + if (written != 1) { + printf("(%s) written gave %d - should have been 1\n", + __location__, written); + ret = False; + goto done; + } + + finfo2.basic_info.level = RAW_FILEINFO_BASIC_INFO; + finfo2.basic_info.in.fname = fname; + + status = smb_raw_pathinfo(cli2->tree, mem_ctx, &finfo2); + + if (!NT_STATUS_IS_OK(status)) { + DEBUG(0, ("(%s) fileinfo failed: %s\n", + __location__, nt_errstr(status))); + ret = False; + goto done; + } + + if (finfo1.basic_info.out.create_time != + finfo2.basic_info.out.create_time) { + printf("(%s) create_time changed\n", __location__); + ret = False; + goto done; + } + + if (finfo1.basic_info.out.access_time != + finfo2.basic_info.out.access_time) { + printf("(%s) access_time changed\n", __location__); + ret = False; + goto done; + } + + if (finfo1.basic_info.out.write_time != + finfo2.basic_info.out.write_time) { + printf("(%s) write_time changed\n", __location__); + ret = False; + goto done; + } + + if (finfo1.basic_info.out.change_time != + finfo2.basic_info.out.change_time) { + printf("(%s) change_time changed\n", __location__); + ret = False; + goto done; + } + + /* One of the two following calls updates the qpathinfo. */ + + /* If you had skipped the smbcli_write on fnum2, it would + * *not* have updated the stat on disk */ + + smbcli_close(cli2->tree, fnum2); + torture_close_connection(cli2); + cli2 = NULL; + + /* This call is only for the people looking at ethereal :-) */ + finfo2.basic_info.level = RAW_FILEINFO_BASIC_INFO; + finfo2.basic_info.in.fname = fname; + + status = smb_raw_pathinfo(cli->tree, mem_ctx, &finfo2); + + if (!NT_STATUS_IS_OK(status)) { + DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status))); + ret = False; + goto done; + } + + done: + if (fnum1 != -1) + smbcli_close(cli->tree, fnum1); + smbcli_unlink(cli->tree, fname); + smbcli_deltree(cli->tree, BASEDIR); + if (cli2 != NULL) { + torture_close_connection(cli2); + } + + return ret; +} + + +/* + testing of delayed update of write_time +*/ +BOOL torture_delay_write(void) +{ + struct smbcli_state *cli; + BOOL ret = True; + TALLOC_CTX *mem_ctx; + + if (!torture_open_connection(&cli)) { + return False; + } + + mem_ctx = talloc_init("torture_delay_write"); + + ret &= test_finfo_after_write(cli, mem_ctx); + ret &= test_delayed_write_update(cli, mem_ctx); + + torture_close_connection(cli); + talloc_destroy(mem_ctx); + return ret; +} -- cgit From 96ecdf3a334f7b473ad590dbc41474d2173474c6 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 20 Nov 2004 01:09:25 +0000 Subject: r3886: Trying to understand delayed file write update times. Added another test that uses 2 connections and queries the time via pathinfo, not fileinfo. MSDN states : "When writing to a file, the last write time is not fully updated until all handles used for writing have been closed." - but this is obviously untrue. W2K3 seems to use a 2 second granularity for this. Next I'll try using SetFileTime equivalent to see if this takes the same time to take effect. Jeremy. (This used to be commit 2e47e241f98c3dba8be346cea726def38399eb97) --- source4/torture/basic/delaywrite.c | 97 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) (limited to 'source4/torture/basic/delaywrite.c') diff --git a/source4/torture/basic/delaywrite.c b/source4/torture/basic/delaywrite.c index 3a632c49ea..4ffd398c17 100644 --- a/source4/torture/basic/delaywrite.c +++ b/source4/torture/basic/delaywrite.c @@ -109,6 +109,102 @@ static BOOL test_delayed_write_update(struct smbcli_state *cli, TALLOC_CTX *mem_ return ret; } +/* + * Do as above, but using 2 connections. + */ + +static BOOL test_delayed_write_update2(struct smbcli_state *cli, TALLOC_CTX *mem_ctx) +{ + struct smbcli_state *cli2=NULL; + union smb_fileinfo finfo1, finfo2; + const char *fname = BASEDIR "\\torture_file.txt"; + NTSTATUS status; + int fnum1 = -1; + BOOL ret = True; + ssize_t written; + time_t t; + + printf("Testing delayed update of write time using 2 connections\n"); + + if (!torture_open_connection(&cli2)) { + return False; + } + + if (!torture_setup_dir(cli, BASEDIR)) { + return False; + } + + fnum1 = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE); + if (fnum1 == -1) { + printf("Failed to open %s\n", fname); + return False; + } + + finfo1.basic_info.level = RAW_FILEINFO_BASIC_INFO; + finfo1.basic_info.in.fnum = fnum1; + finfo2 = finfo1; + + status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo1); + + if (!NT_STATUS_IS_OK(status)) { + DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status))); + return False; + } + + printf("Initial write time %s\n", + nt_time_string(mem_ctx, finfo1.basic_info.out.write_time)); + + /* 3 second delay to ensure we get past any 2 second time + granularity (older systems may have that) */ + sleep(3); + + written = smbcli_write(cli->tree, fnum1, 0, "x", 0, 1); + + if (written != 1) { + printf("write failed - wrote %d bytes (%s)\n", written, __location__); + return False; + } + + t = time(NULL); + + while (time(NULL) < t+120) { + finfo2.basic_info.in.fname = fname; + + status = smb_raw_pathinfo(cli2->tree, mem_ctx, &finfo2); + + if (!NT_STATUS_IS_OK(status)) { + DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status))); + ret = False; + break; + } + printf("write time %s\n", + nt_time_string(mem_ctx, finfo2.basic_info.out.write_time)); + if (finfo1.basic_info.out.write_time != finfo2.basic_info.out.write_time) { + printf("Server updated write_time after %d seconds\n", + (int)(time(NULL) - t)); + break; + } + sleep(1); + fflush(stdout); + } + + if (finfo1.basic_info.out.write_time == finfo2.basic_info.out.write_time) { + printf("Server did not update write time?!\n"); + ret = False; + } + + + if (cli2 != NULL) { + torture_close_connection(cli2); + } + if (fnum1 != -1) + smbcli_close(cli->tree, fnum1); + smbcli_unlink(cli->tree, fname); + smbcli_deltree(cli->tree, BASEDIR); + + return ret; +} + /* Windows does obviously not update the stat info during a write call. I * *think* this is the problem causing a spurious Excel 2003 on XP error @@ -277,6 +373,7 @@ BOOL torture_delay_write(void) ret &= test_finfo_after_write(cli, mem_ctx); ret &= test_delayed_write_update(cli, mem_ctx); + ret &= test_delayed_write_update2(cli, mem_ctx); torture_close_connection(cli); talloc_destroy(mem_ctx); -- cgit From c760b8b969f550b0fe3d61f089c133994af2dd60 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 20 Nov 2004 01:51:32 +0000 Subject: r3887: Much better understanding of delayed write time, and the interaction with setfileinfo modifying the write time. I have some ideas on how to emulate this in the Samba server now but the commented case will be very hard... Jeremy. (This used to be commit c9211d084719a16f671b315a9c0bc6ed59fa8c8e) --- source4/torture/basic/delaywrite.c | 84 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 80 insertions(+), 4 deletions(-) (limited to 'source4/torture/basic/delaywrite.c') diff --git a/source4/torture/basic/delaywrite.c b/source4/torture/basic/delaywrite.c index 4ffd398c17..0566e26cb9 100644 --- a/source4/torture/basic/delaywrite.c +++ b/source4/torture/basic/delaywrite.c @@ -5,6 +5,7 @@ Copyright (C) Volker Lendecke 2004 Copyright (C) Andrew Tridgell 2004 + Copyright (C) Jeremy Allison 2004 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -158,11 +159,31 @@ static BOOL test_delayed_write_update2(struct smbcli_state *cli, TALLOC_CTX *mem granularity (older systems may have that) */ sleep(3); - written = smbcli_write(cli->tree, fnum1, 0, "x", 0, 1); + { + /* Try using setfileinfo instead of write to update write time. */ + union smb_setfileinfo sfinfo; + time_t t_set = time(NULL); + sfinfo.basic_info.level = RAW_SFILEINFO_BASIC_INFO; + sfinfo.basic_info.file.fnum = fnum1; + sfinfo.basic_info.in.create_time = finfo1.basic_info.out.create_time; + sfinfo.basic_info.in.access_time = finfo1.basic_info.out.access_time; + + /* I tried this with both + and - ve to see if it makes a different. + It doesn't - once the filetime is set via setfileinfo it stays that way. */ +#if 1 + unix_to_nt_time(&sfinfo.basic_info.in.write_time, t_set - 30000); +#else + unix_to_nt_time(&sfinfo.basic_info.in.write_time, t_set + 30000); +#endif + sfinfo.basic_info.in.change_time = finfo1.basic_info.out.change_time; + sfinfo.basic_info.in.attrib = finfo1.basic_info.out.attrib; + + status = smb_raw_setfileinfo(cli->tree, &sfinfo); - if (written != 1) { - printf("write failed - wrote %d bytes (%s)\n", written, __location__); - return False; + if (!NT_STATUS_IS_OK(status)) { + DEBUG(0, ("sfileinfo failed: %s\n", nt_errstr(status))); + return False; + } } t = time(NULL); @@ -193,6 +214,61 @@ static BOOL test_delayed_write_update2(struct smbcli_state *cli, TALLOC_CTX *mem ret = False; } + /* Now try a write to see if the write time gets reset. */ + + finfo1.basic_info.level = RAW_FILEINFO_BASIC_INFO; + finfo1.basic_info.in.fnum = fnum1; + finfo2 = finfo1; + + status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo1); + + if (!NT_STATUS_IS_OK(status)) { + DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status))); + return False; + } + + printf("Modified write time %s\n", + nt_time_string(mem_ctx, finfo1.basic_info.out.write_time)); + + + written = smbcli_write(cli->tree, fnum1, 0, "x", 0, 1); + + if (written != 1) { + printf("write failed - wrote %d bytes (%s)\n", written, __location__); + return False; + } + + t = time(NULL); + + /* Once the time was set using setfileinfo then it stays set - writes + don't have any effect. But make sure. */ + + while (time(NULL) < t+40) { + status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo2); + + if (!NT_STATUS_IS_OK(status)) { + DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status))); + ret = False; + break; + } + printf("write time %s\n", + nt_time_string(mem_ctx, finfo2.basic_info.out.write_time)); + if (finfo1.basic_info.out.write_time != finfo2.basic_info.out.write_time) { + printf("Server updated write_time after %d seconds\n", + (int)(time(NULL) - t)); + break; + } + sleep(1); + fflush(stdout); + } + + if (finfo1.basic_info.out.write_time == finfo2.basic_info.out.write_time) { + printf("Server did not update write time?!\n"); + } + + /* One more test to do. We should read the filetime via findfirst on the + second connection to ensure it's the same. This is very easy for a Windows + server but a bastard to get right on a POSIX server. JRA. */ if (cli2 != NULL) { torture_close_connection(cli2); -- cgit From f55ee60575576e2213b234f4690d7a300a8e362e Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 20 Nov 2004 02:33:12 +0000 Subject: r3888: Just proving :-) to tridge that a Setfileinfo with a modified write time is sticky, and causes any subsequent writes not to update the last write time. Added write that extends the file followed by fnum specific smbflush. It stays the same time :-). Jeremy. (This used to be commit a2ea2166dcb7044d7b9e53417e53febea2f81e20) --- source4/torture/basic/delaywrite.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'source4/torture/basic/delaywrite.c') diff --git a/source4/torture/basic/delaywrite.c b/source4/torture/basic/delaywrite.c index 0566e26cb9..51fe2814e2 100644 --- a/source4/torture/basic/delaywrite.c +++ b/source4/torture/basic/delaywrite.c @@ -124,6 +124,7 @@ static BOOL test_delayed_write_update2(struct smbcli_state *cli, TALLOC_CTX *mem BOOL ret = True; ssize_t written; time_t t; + struct smb_flush flsh; printf("Testing delayed update of write time using 2 connections\n"); @@ -231,13 +232,27 @@ static BOOL test_delayed_write_update2(struct smbcli_state *cli, TALLOC_CTX *mem nt_time_string(mem_ctx, finfo1.basic_info.out.write_time)); - written = smbcli_write(cli->tree, fnum1, 0, "x", 0, 1); + printf("Doing a 10 byte write to extend the file and see if this changes the last write time.\n"); - if (written != 1) { + written = smbcli_write(cli->tree, fnum1, 0, "0123456789", 1, 10); + + if (written != 10) { printf("write failed - wrote %d bytes (%s)\n", written, __location__); return False; } + /* Just to prove to tridge that the an smbflush has no effect on + the write time :-). The setfileinfo IS STICKY. JRA. */ + + printf("Doing flush after write\n"); + + flsh.in.fnum = fnum1; + status = smb_raw_flush(cli->tree, &flsh); + if (!NT_STATUS_IS_OK(status)) { + DEBUG(0, ("smbflush failed: %s\n", nt_errstr(status))); + return False; + } + t = time(NULL); /* Once the time was set using setfileinfo then it stays set - writes -- cgit From 759da3b915e2006d4c87b5ace47f399accd9ce91 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 27 Jan 2005 07:08:20 +0000 Subject: r5037: got rid of all of the TALLOC_DEPRECATED stuff. My apologies for the large commit. I thought this was worthwhile to get done for consistency. (This used to be commit ec32b22ed5ec224f6324f5e069d15e92e38e15c0) --- source4/torture/basic/delaywrite.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/torture/basic/delaywrite.c') diff --git a/source4/torture/basic/delaywrite.c b/source4/torture/basic/delaywrite.c index 51fe2814e2..27a7c92eed 100644 --- a/source4/torture/basic/delaywrite.c +++ b/source4/torture/basic/delaywrite.c @@ -467,6 +467,6 @@ BOOL torture_delay_write(void) ret &= test_delayed_write_update2(cli, mem_ctx); torture_close_connection(cli); - talloc_destroy(mem_ctx); + talloc_free(mem_ctx); return ret; } -- cgit From e82aad1ce39a6b7a2e51b9e2cb494d74ec70e158 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 10 Feb 2005 05:09:35 +0000 Subject: r5298: - got rid of pstring.h from includes.h. This at least makes it a bit less likely that anyone will use pstring for new code - got rid of winbind_client.h from includes.h. This one triggered a huge change, as winbind_client.h was including system/filesys.h and defining the old uint32 and uint16 types, as well as its own pstring and fstring. (This used to be commit 9db6c79e902ec538108d6b7d3324039aabe1704f) --- source4/torture/basic/delaywrite.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source4/torture/basic/delaywrite.c') diff --git a/source4/torture/basic/delaywrite.c b/source4/torture/basic/delaywrite.c index 27a7c92eed..b0d92d005d 100644 --- a/source4/torture/basic/delaywrite.c +++ b/source4/torture/basic/delaywrite.c @@ -25,6 +25,7 @@ #include "includes.h" #include "libcli/raw/libcliraw.h" #include "system/time.h" +#include "system/filesys.h" #define BASEDIR "\\delaywrite" -- cgit From f52643c23c50e68c149b5e6726ca1c10c9e3fd27 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 10 Mar 2005 21:42:20 +0000 Subject: r5730: More fun with delayed write semantics with multiple file handles open on the same file on the same connection. Jeremy. (This used to be commit 23733abfa201347265f54232989b608b11ad7a85) --- source4/torture/basic/delaywrite.c | 170 ++++++++++++++++++++++++++++++++++++- 1 file changed, 168 insertions(+), 2 deletions(-) (limited to 'source4/torture/basic/delaywrite.c') diff --git a/source4/torture/basic/delaywrite.c b/source4/torture/basic/delaywrite.c index b0d92d005d..7839581caa 100644 --- a/source4/torture/basic/delaywrite.c +++ b/source4/torture/basic/delaywrite.c @@ -122,6 +122,7 @@ static BOOL test_delayed_write_update2(struct smbcli_state *cli, TALLOC_CTX *mem const char *fname = BASEDIR "\\torture_file.txt"; NTSTATUS status; int fnum1 = -1; + int fnum2 = -1; BOOL ret = True; ssize_t written; time_t t; @@ -259,7 +260,7 @@ static BOOL test_delayed_write_update2(struct smbcli_state *cli, TALLOC_CTX *mem /* Once the time was set using setfileinfo then it stays set - writes don't have any effect. But make sure. */ - while (time(NULL) < t+40) { + while (time(NULL) < t+15) { status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo2); if (!NT_STATUS_IS_OK(status)) { @@ -279,9 +280,171 @@ static BOOL test_delayed_write_update2(struct smbcli_state *cli, TALLOC_CTX *mem } if (finfo1.basic_info.out.write_time == finfo2.basic_info.out.write_time) { - printf("Server did not update write time?!\n"); + printf("Server did not update write time\n"); + } + + fnum2 = smbcli_open(cli->tree, fname, O_RDWR, DENY_NONE); + if (fnum2 == -1) { + printf("Failed to open %s\n", fname); + return False; + } + + printf("Doing a 10 byte write to extend the file via second fd and see if this changes the last write time.\n"); + + written = smbcli_write(cli->tree, fnum2, 0, "0123456789", 11, 10); + + if (written != 10) { + printf("write failed - wrote %d bytes (%s)\n", written, __location__); + return False; + } + + status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo2); + + if (!NT_STATUS_IS_OK(status)) { + DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status))); + return False; + } + printf("write time %s\n", + nt_time_string(mem_ctx, finfo2.basic_info.out.write_time)); + if (finfo1.basic_info.out.write_time != finfo2.basic_info.out.write_time) { + printf("Server updated write_time\n"); + } + + printf("Closing the first fd to see if write time updated.\n"); + smbcli_close(cli->tree, fnum1); + fnum1 = -1; + + printf("Doing a 10 byte write to extend the file via second fd and see if this changes the last write time.\n"); + + written = smbcli_write(cli->tree, fnum2, 0, "0123456789", 21, 10); + + if (written != 10) { + printf("write failed - wrote %d bytes (%s)\n", written, __location__); + return False; + } + + finfo1.basic_info.level = RAW_FILEINFO_BASIC_INFO; + finfo1.basic_info.in.fnum = fnum2; + finfo2 = finfo1; + status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo2); + + if (!NT_STATUS_IS_OK(status)) { + DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status))); + return False; + } + printf("write time %s\n", + nt_time_string(mem_ctx, finfo2.basic_info.out.write_time)); + if (finfo1.basic_info.out.write_time != finfo2.basic_info.out.write_time) { + printf("Server updated write_time\n"); + } + + t = time(NULL); + + /* Once the time was set using setfileinfo then it stays set - writes + don't have any effect. But make sure. */ + + while (time(NULL) < t+15) { + status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo2); + + if (!NT_STATUS_IS_OK(status)) { + DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status))); + ret = False; + break; + } + printf("write time %s\n", + nt_time_string(mem_ctx, finfo2.basic_info.out.write_time)); + if (finfo1.basic_info.out.write_time != finfo2.basic_info.out.write_time) { + printf("Server updated write_time after %d seconds\n", + (int)(time(NULL) - t)); + break; + } + sleep(1); + fflush(stdout); + } + + if (finfo1.basic_info.out.write_time == finfo2.basic_info.out.write_time) { + printf("Server did not update write time\n"); + } + + printf("Closing both fd's to see if write time updated.\n"); + + smbcli_close(cli->tree, fnum2); + fnum2 = -1; + + fnum1 = smbcli_open(cli->tree, fname, O_RDWR, DENY_NONE); + if (fnum1 == -1) { + printf("Failed to open %s\n", fname); + return False; + } + + finfo1.basic_info.level = RAW_FILEINFO_BASIC_INFO; + finfo1.basic_info.in.fnum = fnum1; + finfo2 = finfo1; + + status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo1); + + if (!NT_STATUS_IS_OK(status)) { + DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status))); + return False; + } + + printf("Second open initial write time %s\n", + nt_time_string(mem_ctx, finfo1.basic_info.out.write_time)); + + sleep(10); + printf("Doing a 10 byte write to extend the file to see if this changes the last write time.\n"); + + written = smbcli_write(cli->tree, fnum1, 0, "0123456789", 31, 10); + + if (written != 10) { + printf("write failed - wrote %d bytes (%s)\n", written, __location__); + return False; + } + + finfo1.basic_info.level = RAW_FILEINFO_BASIC_INFO; + finfo1.basic_info.in.fnum = fnum1; + finfo2 = finfo1; + status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo2); + + if (!NT_STATUS_IS_OK(status)) { + DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status))); + return False; + } + printf("write time %s\n", + nt_time_string(mem_ctx, finfo2.basic_info.out.write_time)); + if (finfo1.basic_info.out.write_time != finfo2.basic_info.out.write_time) { + printf("Server updated write_time\n"); + } + + t = time(NULL); + + /* Once the time was set using setfileinfo then it stays set - writes + don't have any effect. But make sure. */ + + while (time(NULL) < t+15) { + status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo2); + + if (!NT_STATUS_IS_OK(status)) { + DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status))); + ret = False; + break; + } + printf("write time %s\n", + nt_time_string(mem_ctx, finfo2.basic_info.out.write_time)); + if (finfo1.basic_info.out.write_time != finfo2.basic_info.out.write_time) { + printf("Server updated write_time after %d seconds\n", + (int)(time(NULL) - t)); + break; + } + sleep(1); + fflush(stdout); + } + + if (finfo1.basic_info.out.write_time == finfo2.basic_info.out.write_time) { + printf("Server did not update write time\n"); } + /* One more test to do. We should read the filetime via findfirst on the second connection to ensure it's the same. This is very easy for a Windows server but a bastard to get right on a POSIX server. JRA. */ @@ -403,6 +566,9 @@ static BOOL test_finfo_after_write(struct smbcli_state *cli, TALLOC_CTX *mem_ctx if (finfo1.basic_info.out.write_time != finfo2.basic_info.out.write_time) { printf("(%s) write_time changed\n", __location__); + printf("write time conn 1 = %s, conn 2 = %s\n", + nt_time_string(mem_ctx, finfo1.basic_info.out.write_time), + nt_time_string(mem_ctx, finfo2.basic_info.out.write_time)); ret = False; goto done; } -- cgit From e835621799647ee70630b389fb53d15b15d68355 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 17 Jul 2005 09:20:52 +0000 Subject: r8520: fixed a pile of warnings from the build farm gcc -Wall output on S390. This is an attempt to avoid the panic we're seeing in the automatic builds. The main fixes are: - assumptions that sizeof(size_t) == sizeof(int), mostly in printf formats - use of NULL format statements to perform dn searches. - assumption that sizeof() returns an int (This used to be commit a58ea6b3854973b694d2b1e22323ed7eb00e3a3f) --- source4/torture/basic/delaywrite.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'source4/torture/basic/delaywrite.c') diff --git a/source4/torture/basic/delaywrite.c b/source4/torture/basic/delaywrite.c index 7839581caa..ebce013170 100644 --- a/source4/torture/basic/delaywrite.c +++ b/source4/torture/basic/delaywrite.c @@ -72,7 +72,8 @@ static BOOL test_delayed_write_update(struct smbcli_state *cli, TALLOC_CTX *mem_ written = smbcli_write(cli->tree, fnum1, 0, "x", 0, 1); if (written != 1) { - printf("write failed - wrote %d bytes (%s)\n", written, __location__); + printf("write failed - wrote %d bytes (%s)\n", + (int)written, __location__); return False; } @@ -239,7 +240,8 @@ static BOOL test_delayed_write_update2(struct smbcli_state *cli, TALLOC_CTX *mem written = smbcli_write(cli->tree, fnum1, 0, "0123456789", 1, 10); if (written != 10) { - printf("write failed - wrote %d bytes (%s)\n", written, __location__); + printf("write failed - wrote %d bytes (%s)\n", + (int)written, __location__); return False; } @@ -294,7 +296,8 @@ static BOOL test_delayed_write_update2(struct smbcli_state *cli, TALLOC_CTX *mem written = smbcli_write(cli->tree, fnum2, 0, "0123456789", 11, 10); if (written != 10) { - printf("write failed - wrote %d bytes (%s)\n", written, __location__); + printf("write failed - wrote %d bytes (%s)\n", + (int)written, __location__); return False; } @@ -319,7 +322,8 @@ static BOOL test_delayed_write_update2(struct smbcli_state *cli, TALLOC_CTX *mem written = smbcli_write(cli->tree, fnum2, 0, "0123456789", 21, 10); if (written != 10) { - printf("write failed - wrote %d bytes (%s)\n", written, __location__); + printf("write failed - wrote %d bytes (%s)\n", + (int)written, __location__); return False; } @@ -397,7 +401,8 @@ static BOOL test_delayed_write_update2(struct smbcli_state *cli, TALLOC_CTX *mem written = smbcli_write(cli->tree, fnum1, 0, "0123456789", 31, 10); if (written != 10) { - printf("write failed - wrote %d bytes (%s)\n", written, __location__); + printf("write failed - wrote %d bytes (%s)\n", + (int)written, __location__); return False; } @@ -511,7 +516,7 @@ static BOOL test_finfo_after_write(struct smbcli_state *cli, TALLOC_CTX *mem_ctx if (written != 1) { printf("(%s) written gave %d - should have been 1\n", - __location__, written); + __location__, (int)written); ret = False; goto done; } @@ -532,7 +537,7 @@ static BOOL test_finfo_after_write(struct smbcli_state *cli, TALLOC_CTX *mem_ctx if (written != 1) { printf("(%s) written gave %d - should have been 1\n", - __location__, written); + __location__, (int)written); ret = False; goto done; } -- cgit From 25bb00fbcd409572e1c19c05fdc42c883936780b Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 3 Jan 2006 13:41:17 +0000 Subject: r12693: Move core data structures out of smb.h into core.h torture prototypes in seperate header (This used to be commit 73610639b23ca3743077193fa0b1de7c7f65944d) --- source4/torture/basic/delaywrite.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source4/torture/basic/delaywrite.c') diff --git a/source4/torture/basic/delaywrite.c b/source4/torture/basic/delaywrite.c index ebce013170..5523e1bb41 100644 --- a/source4/torture/basic/delaywrite.c +++ b/source4/torture/basic/delaywrite.c @@ -23,6 +23,7 @@ */ #include "includes.h" +#include "torture/torture.h" #include "libcli/raw/libcliraw.h" #include "system/time.h" #include "system/filesys.h" -- cgit From 78c50015bb8bd5a1d831a6e7ec796b3367c73145 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 3 Jan 2006 15:40:05 +0000 Subject: r12694: Move some headers to the directory of the subsystem they belong to. (This used to be commit c722f665c90103f3ed57621c460e32ad33e7a8a3) --- source4/torture/basic/delaywrite.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source4/torture/basic/delaywrite.c') diff --git a/source4/torture/basic/delaywrite.c b/source4/torture/basic/delaywrite.c index 5523e1bb41..2c26f21ddc 100644 --- a/source4/torture/basic/delaywrite.c +++ b/source4/torture/basic/delaywrite.c @@ -27,6 +27,7 @@ #include "libcli/raw/libcliraw.h" #include "system/time.h" #include "system/filesys.h" +#include "libcli/libcli.h" #define BASEDIR "\\delaywrite" -- cgit From 307e43bb5628e8b53a930c2928279af994281ba5 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 10 Mar 2006 20:49:20 +0000 Subject: r14173: change smb interface structures to always use a union smb_file, to abtract - const char *path fot qpathinfo and setpathinfo - uint16_t fnum for SMB - smb2_handle handle for SMB2 the idea is to later add a struct ntvfs_handle *ntvfs so that the ntvfs subsystem don't need to know the difference between SMB and SMB2 metze (This used to be commit 2ef3f5970901b5accdb50f0d0115b5d46b0c788f) --- source4/torture/basic/delaywrite.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'source4/torture/basic/delaywrite.c') diff --git a/source4/torture/basic/delaywrite.c b/source4/torture/basic/delaywrite.c index 2c26f21ddc..2a41508bcc 100644 --- a/source4/torture/basic/delaywrite.c +++ b/source4/torture/basic/delaywrite.c @@ -54,7 +54,7 @@ static BOOL test_delayed_write_update(struct smbcli_state *cli, TALLOC_CTX *mem_ } finfo1.basic_info.level = RAW_FILEINFO_BASIC_INFO; - finfo1.basic_info.in.fnum = fnum1; + finfo1.basic_info.file.fnum = fnum1; finfo2 = finfo1; status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo1); @@ -129,7 +129,7 @@ static BOOL test_delayed_write_update2(struct smbcli_state *cli, TALLOC_CTX *mem BOOL ret = True; ssize_t written; time_t t; - struct smb_flush flsh; + union smb_flush flsh; printf("Testing delayed update of write time using 2 connections\n"); @@ -148,7 +148,7 @@ static BOOL test_delayed_write_update2(struct smbcli_state *cli, TALLOC_CTX *mem } finfo1.basic_info.level = RAW_FILEINFO_BASIC_INFO; - finfo1.basic_info.in.fnum = fnum1; + finfo1.basic_info.file.fnum = fnum1; finfo2 = finfo1; status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo1); @@ -195,7 +195,7 @@ static BOOL test_delayed_write_update2(struct smbcli_state *cli, TALLOC_CTX *mem t = time(NULL); while (time(NULL) < t+120) { - finfo2.basic_info.in.fname = fname; + finfo2.basic_info.file.path = fname; status = smb_raw_pathinfo(cli2->tree, mem_ctx, &finfo2); @@ -223,7 +223,7 @@ static BOOL test_delayed_write_update2(struct smbcli_state *cli, TALLOC_CTX *mem /* Now try a write to see if the write time gets reset. */ finfo1.basic_info.level = RAW_FILEINFO_BASIC_INFO; - finfo1.basic_info.in.fnum = fnum1; + finfo1.basic_info.file.fnum = fnum1; finfo2 = finfo1; status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo1); @@ -252,7 +252,7 @@ static BOOL test_delayed_write_update2(struct smbcli_state *cli, TALLOC_CTX *mem printf("Doing flush after write\n"); - flsh.in.fnum = fnum1; + flsh.flush.file.fnum = fnum1; status = smb_raw_flush(cli->tree, &flsh); if (!NT_STATUS_IS_OK(status)) { DEBUG(0, ("smbflush failed: %s\n", nt_errstr(status))); @@ -330,7 +330,7 @@ static BOOL test_delayed_write_update2(struct smbcli_state *cli, TALLOC_CTX *mem } finfo1.basic_info.level = RAW_FILEINFO_BASIC_INFO; - finfo1.basic_info.in.fnum = fnum2; + finfo1.basic_info.file.fnum = fnum2; finfo2 = finfo1; status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo2); @@ -384,7 +384,7 @@ static BOOL test_delayed_write_update2(struct smbcli_state *cli, TALLOC_CTX *mem } finfo1.basic_info.level = RAW_FILEINFO_BASIC_INFO; - finfo1.basic_info.in.fnum = fnum1; + finfo1.basic_info.file.fnum = fnum1; finfo2 = finfo1; status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo1); @@ -409,7 +409,7 @@ static BOOL test_delayed_write_update2(struct smbcli_state *cli, TALLOC_CTX *mem } finfo1.basic_info.level = RAW_FILEINFO_BASIC_INFO; - finfo1.basic_info.in.fnum = fnum1; + finfo1.basic_info.file.fnum = fnum1; finfo2 = finfo1; status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo2); @@ -502,7 +502,7 @@ static BOOL test_finfo_after_write(struct smbcli_state *cli, TALLOC_CTX *mem_ctx } finfo1.basic_info.level = RAW_FILEINFO_BASIC_INFO; - finfo1.basic_info.in.fnum = fnum1; + finfo1.basic_info.file.fnum = fnum1; status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo1); @@ -545,7 +545,7 @@ static BOOL test_finfo_after_write(struct smbcli_state *cli, TALLOC_CTX *mem_ctx } finfo2.basic_info.level = RAW_FILEINFO_BASIC_INFO; - finfo2.basic_info.in.fname = fname; + finfo2.basic_info.file.path = fname; status = smb_raw_pathinfo(cli2->tree, mem_ctx, &finfo2); @@ -598,7 +598,7 @@ static BOOL test_finfo_after_write(struct smbcli_state *cli, TALLOC_CTX *mem_ctx /* This call is only for the people looking at ethereal :-) */ finfo2.basic_info.level = RAW_FILEINFO_BASIC_INFO; - finfo2.basic_info.in.fname = fname; + finfo2.basic_info.file.path = fname; status = smb_raw_pathinfo(cli->tree, mem_ctx, &finfo2); -- cgit From a1b295ed4823ce8d06f830b8db9a5d965c934b54 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Sun, 12 Mar 2006 22:48:25 +0000 Subject: r14256: - rename smb_file -> smb_handle - move it into the in/out substructs again - allow file.path only on smb_fileinfo/smb_setfileinfo metze (This used to be commit be6d5298a2cdb7e7c61d70471bad445645af5963) --- source4/torture/basic/delaywrite.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'source4/torture/basic/delaywrite.c') diff --git a/source4/torture/basic/delaywrite.c b/source4/torture/basic/delaywrite.c index 2a41508bcc..37a9528f97 100644 --- a/source4/torture/basic/delaywrite.c +++ b/source4/torture/basic/delaywrite.c @@ -54,7 +54,7 @@ static BOOL test_delayed_write_update(struct smbcli_state *cli, TALLOC_CTX *mem_ } finfo1.basic_info.level = RAW_FILEINFO_BASIC_INFO; - finfo1.basic_info.file.fnum = fnum1; + finfo1.basic_info.in.file.fnum = fnum1; finfo2 = finfo1; status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo1); @@ -148,7 +148,7 @@ static BOOL test_delayed_write_update2(struct smbcli_state *cli, TALLOC_CTX *mem } finfo1.basic_info.level = RAW_FILEINFO_BASIC_INFO; - finfo1.basic_info.file.fnum = fnum1; + finfo1.basic_info.in.file.fnum = fnum1; finfo2 = finfo1; status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo1); @@ -170,7 +170,7 @@ static BOOL test_delayed_write_update2(struct smbcli_state *cli, TALLOC_CTX *mem union smb_setfileinfo sfinfo; time_t t_set = time(NULL); sfinfo.basic_info.level = RAW_SFILEINFO_BASIC_INFO; - sfinfo.basic_info.file.fnum = fnum1; + sfinfo.basic_info.in.file.fnum = fnum1; sfinfo.basic_info.in.create_time = finfo1.basic_info.out.create_time; sfinfo.basic_info.in.access_time = finfo1.basic_info.out.access_time; @@ -195,7 +195,7 @@ static BOOL test_delayed_write_update2(struct smbcli_state *cli, TALLOC_CTX *mem t = time(NULL); while (time(NULL) < t+120) { - finfo2.basic_info.file.path = fname; + finfo2.basic_info.in.file.path = fname; status = smb_raw_pathinfo(cli2->tree, mem_ctx, &finfo2); @@ -223,7 +223,7 @@ static BOOL test_delayed_write_update2(struct smbcli_state *cli, TALLOC_CTX *mem /* Now try a write to see if the write time gets reset. */ finfo1.basic_info.level = RAW_FILEINFO_BASIC_INFO; - finfo1.basic_info.file.fnum = fnum1; + finfo1.basic_info.in.file.fnum = fnum1; finfo2 = finfo1; status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo1); @@ -252,7 +252,7 @@ static BOOL test_delayed_write_update2(struct smbcli_state *cli, TALLOC_CTX *mem printf("Doing flush after write\n"); - flsh.flush.file.fnum = fnum1; + flsh.flush.in.file.fnum = fnum1; status = smb_raw_flush(cli->tree, &flsh); if (!NT_STATUS_IS_OK(status)) { DEBUG(0, ("smbflush failed: %s\n", nt_errstr(status))); @@ -330,7 +330,7 @@ static BOOL test_delayed_write_update2(struct smbcli_state *cli, TALLOC_CTX *mem } finfo1.basic_info.level = RAW_FILEINFO_BASIC_INFO; - finfo1.basic_info.file.fnum = fnum2; + finfo1.basic_info.in.file.fnum = fnum2; finfo2 = finfo1; status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo2); @@ -384,7 +384,7 @@ static BOOL test_delayed_write_update2(struct smbcli_state *cli, TALLOC_CTX *mem } finfo1.basic_info.level = RAW_FILEINFO_BASIC_INFO; - finfo1.basic_info.file.fnum = fnum1; + finfo1.basic_info.in.file.fnum = fnum1; finfo2 = finfo1; status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo1); @@ -409,7 +409,7 @@ static BOOL test_delayed_write_update2(struct smbcli_state *cli, TALLOC_CTX *mem } finfo1.basic_info.level = RAW_FILEINFO_BASIC_INFO; - finfo1.basic_info.file.fnum = fnum1; + finfo1.basic_info.in.file.fnum = fnum1; finfo2 = finfo1; status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo2); @@ -502,7 +502,7 @@ static BOOL test_finfo_after_write(struct smbcli_state *cli, TALLOC_CTX *mem_ctx } finfo1.basic_info.level = RAW_FILEINFO_BASIC_INFO; - finfo1.basic_info.file.fnum = fnum1; + finfo1.basic_info.in.file.fnum = fnum1; status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo1); @@ -545,7 +545,7 @@ static BOOL test_finfo_after_write(struct smbcli_state *cli, TALLOC_CTX *mem_ctx } finfo2.basic_info.level = RAW_FILEINFO_BASIC_INFO; - finfo2.basic_info.file.path = fname; + finfo2.basic_info.in.file.path = fname; status = smb_raw_pathinfo(cli2->tree, mem_ctx, &finfo2); @@ -598,7 +598,7 @@ static BOOL test_finfo_after_write(struct smbcli_state *cli, TALLOC_CTX *mem_ctx /* This call is only for the people looking at ethereal :-) */ finfo2.basic_info.level = RAW_FILEINFO_BASIC_INFO; - finfo2.basic_info.file.path = fname; + finfo2.basic_info.in.file.path = fname; status = smb_raw_pathinfo(cli->tree, mem_ctx, &finfo2); -- cgit From d09b70c98b8222eb293bc9d8713ec071188ed01d Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 17 Mar 2006 17:59:58 +0000 Subject: r14527: Fix build problems. (This used to be commit 863ca4014d9b821706ee90f58ab5d5cf3899a4c7) --- source4/torture/basic/delaywrite.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source4/torture/basic/delaywrite.c') diff --git a/source4/torture/basic/delaywrite.c b/source4/torture/basic/delaywrite.c index 37a9528f97..2f1c4b98c7 100644 --- a/source4/torture/basic/delaywrite.c +++ b/source4/torture/basic/delaywrite.c @@ -28,6 +28,7 @@ #include "system/time.h" #include "system/filesys.h" #include "libcli/libcli.h" +#include "torture/util.h" #define BASEDIR "\\delaywrite" -- cgit From 909b111f587705a45f63540b39968f1af58a9b5d Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 25 Mar 2006 16:01:28 +0000 Subject: r14720: Add torture_context argument to all torture tests (This used to be commit 3c7a5ce29108dd82210dc3e1f00414f545949e1d) --- source4/torture/basic/delaywrite.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/torture/basic/delaywrite.c') diff --git a/source4/torture/basic/delaywrite.c b/source4/torture/basic/delaywrite.c index 2f1c4b98c7..7708e1c76d 100644 --- a/source4/torture/basic/delaywrite.c +++ b/source4/torture/basic/delaywrite.c @@ -625,7 +625,7 @@ static BOOL test_finfo_after_write(struct smbcli_state *cli, TALLOC_CTX *mem_ctx /* testing of delayed update of write_time */ -BOOL torture_delay_write(void) +BOOL torture_delay_write(struct torture_context *torture) { struct smbcli_state *cli; BOOL ret = True; -- cgit From 7f0e17e9030ad734977f66c2cc27faec501154a2 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 19 May 2006 15:10:39 +0000 Subject: r15718: - split the SMBflush with the 0xFFFF wildcard fnum into a different level metze (This used to be commit 95bf41b4d4ec96349802955e364fe44ef85f9077) --- source4/torture/basic/delaywrite.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source4/torture/basic/delaywrite.c') diff --git a/source4/torture/basic/delaywrite.c b/source4/torture/basic/delaywrite.c index 7708e1c76d..4063eda6f2 100644 --- a/source4/torture/basic/delaywrite.c +++ b/source4/torture/basic/delaywrite.c @@ -253,6 +253,7 @@ static BOOL test_delayed_write_update2(struct smbcli_state *cli, TALLOC_CTX *mem printf("Doing flush after write\n"); + flsh.flush.level = RAW_FLUSH_FLUSH; flsh.flush.in.file.fnum = fnum1; status = smb_raw_flush(cli->tree, &flsh); if (!NT_STATUS_IS_OK(status)) { -- cgit From b7c5bc522b286e8e478b6f74a68bc68829e64c3c Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Mon, 10 Jul 2006 08:00:06 +0000 Subject: r16907: Add an index parameter to torture_open_connection. Next step is to enable the unclist parameter for all tests that do two connections, to enable cluster testing. Volker (This used to be commit a5d6db09244d444986f8fded3fc6e72c74c8ca1f) --- source4/torture/basic/delaywrite.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source4/torture/basic/delaywrite.c') diff --git a/source4/torture/basic/delaywrite.c b/source4/torture/basic/delaywrite.c index 4063eda6f2..e42ca1239d 100644 --- a/source4/torture/basic/delaywrite.c +++ b/source4/torture/basic/delaywrite.c @@ -134,7 +134,7 @@ static BOOL test_delayed_write_update2(struct smbcli_state *cli, TALLOC_CTX *mem printf("Testing delayed update of write time using 2 connections\n"); - if (!torture_open_connection(&cli2)) { + if (!torture_open_connection(&cli2, 1)) { return False; } @@ -525,7 +525,7 @@ static BOOL test_finfo_after_write(struct smbcli_state *cli, TALLOC_CTX *mem_ctx goto done; } - if (!torture_open_connection(&cli2)) { + if (!torture_open_connection(&cli2, 1)) { return False; } @@ -632,7 +632,7 @@ BOOL torture_delay_write(struct torture_context *torture) BOOL ret = True; TALLOC_CTX *mem_ctx; - if (!torture_open_connection(&cli)) { + if (!torture_open_connection(&cli, 0)) { return False; } -- cgit From 8773e743c518578584d07d35ffdafdd598af88b0 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 16 Oct 2006 13:06:41 +0000 Subject: 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) --- source4/torture/basic/delaywrite.c | 209 ++++++++++++++++--------------------- 1 file changed, 89 insertions(+), 120 deletions(-) (limited to 'source4/torture/basic/delaywrite.c') diff --git a/source4/torture/basic/delaywrite.c b/source4/torture/basic/delaywrite.c index e42ca1239d..4c2a511721 100644 --- a/source4/torture/basic/delaywrite.c +++ b/source4/torture/basic/delaywrite.c @@ -32,7 +32,7 @@ #define BASEDIR "\\delaywrite" -static BOOL test_delayed_write_update(struct smbcli_state *cli, TALLOC_CTX *mem_ctx) +static BOOL test_delayed_write_update(struct torture_context *tctx, struct smbcli_state *cli) { union smb_fileinfo finfo1, finfo2; const char *fname = BASEDIR "\\torture_file.txt"; @@ -42,15 +42,13 @@ static BOOL test_delayed_write_update(struct smbcli_state *cli, TALLOC_CTX *mem_ ssize_t written; time_t t; - printf("Testing delayed update of write time\n"); - if (!torture_setup_dir(cli, BASEDIR)) { return False; } fnum1 = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE); if (fnum1 == -1) { - printf("Failed to open %s\n", fname); + torture_comment(tctx, "Failed to open %s\n", fname); return False; } @@ -58,15 +56,15 @@ static BOOL test_delayed_write_update(struct smbcli_state *cli, TALLOC_CTX *mem_ finfo1.basic_info.in.file.fnum = fnum1; finfo2 = finfo1; - status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo1); + status = smb_raw_fileinfo(cli->tree, tctx, &finfo1); if (!NT_STATUS_IS_OK(status)) { DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status))); return False; } - printf("Initial write time %s\n", - nt_time_string(mem_ctx, finfo1.basic_info.out.write_time)); + torture_comment(tctx, "Initial write time %s\n", + nt_time_string(tctx, finfo1.basic_info.out.write_time)); /* 3 second delay to ensure we get past any 2 second time granularity (older systems may have that) */ @@ -75,7 +73,7 @@ static BOOL test_delayed_write_update(struct smbcli_state *cli, TALLOC_CTX *mem_ written = smbcli_write(cli->tree, fnum1, 0, "x", 0, 1); if (written != 1) { - printf("write failed - wrote %d bytes (%s)\n", + torture_comment(tctx, "write failed - wrote %d bytes (%s)\n", (int)written, __location__); return False; } @@ -83,17 +81,17 @@ static BOOL test_delayed_write_update(struct smbcli_state *cli, TALLOC_CTX *mem_ t = time(NULL); while (time(NULL) < t+120) { - status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo2); + status = smb_raw_fileinfo(cli->tree, tctx, &finfo2); if (!NT_STATUS_IS_OK(status)) { DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status))); ret = False; break; } - printf("write time %s\n", - nt_time_string(mem_ctx, finfo2.basic_info.out.write_time)); + torture_comment(tctx, "write time %s\n", + nt_time_string(tctx, finfo2.basic_info.out.write_time)); if (finfo1.basic_info.out.write_time != finfo2.basic_info.out.write_time) { - printf("Server updated write_time after %d seconds\n", + torture_comment(tctx, "Server updated write_time after %d seconds\n", (int)(time(NULL) - t)); break; } @@ -102,7 +100,7 @@ static BOOL test_delayed_write_update(struct smbcli_state *cli, TALLOC_CTX *mem_ } if (finfo1.basic_info.out.write_time == finfo2.basic_info.out.write_time) { - printf("Server did not update write time?!\n"); + torture_comment(tctx, "Server did not update write time?!\n"); ret = False; } @@ -119,9 +117,9 @@ static BOOL test_delayed_write_update(struct smbcli_state *cli, TALLOC_CTX *mem_ * Do as above, but using 2 connections. */ -static BOOL test_delayed_write_update2(struct smbcli_state *cli, TALLOC_CTX *mem_ctx) +static BOOL test_delayed_write_update2(struct torture_context *tctx, struct smbcli_state *cli, + struct smbcli_state *cli2) { - struct smbcli_state *cli2=NULL; union smb_fileinfo finfo1, finfo2; const char *fname = BASEDIR "\\torture_file.txt"; NTSTATUS status; @@ -132,19 +130,13 @@ static BOOL test_delayed_write_update2(struct smbcli_state *cli, TALLOC_CTX *mem time_t t; union smb_flush flsh; - printf("Testing delayed update of write time using 2 connections\n"); - - if (!torture_open_connection(&cli2, 1)) { - return False; - } - if (!torture_setup_dir(cli, BASEDIR)) { return False; } fnum1 = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE); if (fnum1 == -1) { - printf("Failed to open %s\n", fname); + torture_comment(tctx, "Failed to open %s\n", fname); return False; } @@ -152,15 +144,15 @@ static BOOL test_delayed_write_update2(struct smbcli_state *cli, TALLOC_CTX *mem finfo1.basic_info.in.file.fnum = fnum1; finfo2 = finfo1; - status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo1); + status = smb_raw_fileinfo(cli->tree, tctx, &finfo1); if (!NT_STATUS_IS_OK(status)) { DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status))); return False; } - printf("Initial write time %s\n", - nt_time_string(mem_ctx, finfo1.basic_info.out.write_time)); + torture_comment(tctx, "Initial write time %s\n", + nt_time_string(tctx, finfo1.basic_info.out.write_time)); /* 3 second delay to ensure we get past any 2 second time granularity (older systems may have that) */ @@ -198,17 +190,17 @@ static BOOL test_delayed_write_update2(struct smbcli_state *cli, TALLOC_CTX *mem while (time(NULL) < t+120) { finfo2.basic_info.in.file.path = fname; - status = smb_raw_pathinfo(cli2->tree, mem_ctx, &finfo2); + status = smb_raw_pathinfo(cli2->tree, tctx, &finfo2); if (!NT_STATUS_IS_OK(status)) { DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status))); ret = False; break; } - printf("write time %s\n", - nt_time_string(mem_ctx, finfo2.basic_info.out.write_time)); + torture_comment(tctx, "write time %s\n", + nt_time_string(tctx, finfo2.basic_info.out.write_time)); if (finfo1.basic_info.out.write_time != finfo2.basic_info.out.write_time) { - printf("Server updated write_time after %d seconds\n", + torture_comment(tctx, "Server updated write_time after %d seconds\n", (int)(time(NULL) - t)); break; } @@ -217,7 +209,7 @@ static BOOL test_delayed_write_update2(struct smbcli_state *cli, TALLOC_CTX *mem } if (finfo1.basic_info.out.write_time == finfo2.basic_info.out.write_time) { - printf("Server did not update write time?!\n"); + torture_comment(tctx, "Server did not update write time?!\n"); ret = False; } @@ -227,23 +219,23 @@ static BOOL test_delayed_write_update2(struct smbcli_state *cli, TALLOC_CTX *mem finfo1.basic_info.in.file.fnum = fnum1; finfo2 = finfo1; - status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo1); + status = smb_raw_fileinfo(cli->tree, tctx, &finfo1); if (!NT_STATUS_IS_OK(status)) { DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status))); return False; } - printf("Modified write time %s\n", - nt_time_string(mem_ctx, finfo1.basic_info.out.write_time)); + torture_comment(tctx, "Modified write time %s\n", + nt_time_string(tctx, finfo1.basic_info.out.write_time)); - printf("Doing a 10 byte write to extend the file and see if this changes the last write time.\n"); + torture_comment(tctx, "Doing a 10 byte write to extend the file and see if this changes the last write time.\n"); written = smbcli_write(cli->tree, fnum1, 0, "0123456789", 1, 10); if (written != 10) { - printf("write failed - wrote %d bytes (%s)\n", + torture_comment(tctx, "write failed - wrote %d bytes (%s)\n", (int)written, __location__); return False; } @@ -251,7 +243,7 @@ static BOOL test_delayed_write_update2(struct smbcli_state *cli, TALLOC_CTX *mem /* Just to prove to tridge that the an smbflush has no effect on the write time :-). The setfileinfo IS STICKY. JRA. */ - printf("Doing flush after write\n"); + torture_comment(tctx, "Doing flush after write\n"); flsh.flush.level = RAW_FLUSH_FLUSH; flsh.flush.in.file.fnum = fnum1; @@ -267,17 +259,17 @@ static BOOL test_delayed_write_update2(struct smbcli_state *cli, TALLOC_CTX *mem don't have any effect. But make sure. */ while (time(NULL) < t+15) { - status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo2); + status = smb_raw_fileinfo(cli->tree, tctx, &finfo2); if (!NT_STATUS_IS_OK(status)) { DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status))); ret = False; break; } - printf("write time %s\n", - nt_time_string(mem_ctx, finfo2.basic_info.out.write_time)); + torture_comment(tctx, "write time %s\n", + nt_time_string(tctx, finfo2.basic_info.out.write_time)); if (finfo1.basic_info.out.write_time != finfo2.basic_info.out.write_time) { - printf("Server updated write_time after %d seconds\n", + torture_comment(tctx, "Server updated write_time after %d seconds\n", (int)(time(NULL) - t)); break; } @@ -286,47 +278,47 @@ static BOOL test_delayed_write_update2(struct smbcli_state *cli, TALLOC_CTX *mem } if (finfo1.basic_info.out.write_time == finfo2.basic_info.out.write_time) { - printf("Server did not update write time\n"); + torture_comment(tctx, "Server did not update write time\n"); } fnum2 = smbcli_open(cli->tree, fname, O_RDWR, DENY_NONE); if (fnum2 == -1) { - printf("Failed to open %s\n", fname); + torture_comment(tctx, "Failed to open %s\n", fname); return False; } - printf("Doing a 10 byte write to extend the file via second fd and see if this changes the last write time.\n"); + torture_comment(tctx, "Doing a 10 byte write to extend the file via second fd and see if this changes the last write time.\n"); written = smbcli_write(cli->tree, fnum2, 0, "0123456789", 11, 10); if (written != 10) { - printf("write failed - wrote %d bytes (%s)\n", + torture_comment(tctx, "write failed - wrote %d bytes (%s)\n", (int)written, __location__); return False; } - status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo2); + status = smb_raw_fileinfo(cli->tree, tctx, &finfo2); if (!NT_STATUS_IS_OK(status)) { DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status))); return False; } - printf("write time %s\n", - nt_time_string(mem_ctx, finfo2.basic_info.out.write_time)); + torture_comment(tctx, "write time %s\n", + nt_time_string(tctx, finfo2.basic_info.out.write_time)); if (finfo1.basic_info.out.write_time != finfo2.basic_info.out.write_time) { - printf("Server updated write_time\n"); + torture_comment(tctx, "Server updated write_time\n"); } - printf("Closing the first fd to see if write time updated.\n"); + torture_comment(tctx, "Closing the first fd to see if write time updated.\n"); smbcli_close(cli->tree, fnum1); fnum1 = -1; - printf("Doing a 10 byte write to extend the file via second fd and see if this changes the last write time.\n"); + torture_comment(tctx, "Doing a 10 byte write to extend the file via second fd and see if this changes the last write time.\n"); written = smbcli_write(cli->tree, fnum2, 0, "0123456789", 21, 10); if (written != 10) { - printf("write failed - wrote %d bytes (%s)\n", + torture_comment(tctx, "write failed - wrote %d bytes (%s)\n", (int)written, __location__); return False; } @@ -334,16 +326,16 @@ static BOOL test_delayed_write_update2(struct smbcli_state *cli, TALLOC_CTX *mem finfo1.basic_info.level = RAW_FILEINFO_BASIC_INFO; finfo1.basic_info.in.file.fnum = fnum2; finfo2 = finfo1; - status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo2); + status = smb_raw_fileinfo(cli->tree, tctx, &finfo2); if (!NT_STATUS_IS_OK(status)) { DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status))); return False; } - printf("write time %s\n", - nt_time_string(mem_ctx, finfo2.basic_info.out.write_time)); + torture_comment(tctx, "write time %s\n", + nt_time_string(tctx, finfo2.basic_info.out.write_time)); if (finfo1.basic_info.out.write_time != finfo2.basic_info.out.write_time) { - printf("Server updated write_time\n"); + torture_comment(tctx, "Server updated write_time\n"); } t = time(NULL); @@ -352,17 +344,17 @@ static BOOL test_delayed_write_update2(struct smbcli_state *cli, TALLOC_CTX *mem don't have any effect. But make sure. */ while (time(NULL) < t+15) { - status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo2); + status = smb_raw_fileinfo(cli->tree, tctx, &finfo2); if (!NT_STATUS_IS_OK(status)) { DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status))); ret = False; break; } - printf("write time %s\n", - nt_time_string(mem_ctx, finfo2.basic_info.out.write_time)); + torture_comment(tctx, "write time %s\n", + nt_time_string(tctx, finfo2.basic_info.out.write_time)); if (finfo1.basic_info.out.write_time != finfo2.basic_info.out.write_time) { - printf("Server updated write_time after %d seconds\n", + torture_comment(tctx, "Server updated write_time after %d seconds\n", (int)(time(NULL) - t)); break; } @@ -371,17 +363,17 @@ static BOOL test_delayed_write_update2(struct smbcli_state *cli, TALLOC_CTX *mem } if (finfo1.basic_info.out.write_time == finfo2.basic_info.out.write_time) { - printf("Server did not update write time\n"); + torture_comment(tctx, "Server did not update write time\n"); } - printf("Closing both fd's to see if write time updated.\n"); + torture_comment(tctx, "Closing both fd's to see if write time updated.\n"); smbcli_close(cli->tree, fnum2); fnum2 = -1; fnum1 = smbcli_open(cli->tree, fname, O_RDWR, DENY_NONE); if (fnum1 == -1) { - printf("Failed to open %s\n", fname); + torture_comment(tctx, "Failed to open %s\n", fname); return False; } @@ -389,23 +381,23 @@ static BOOL test_delayed_write_update2(struct smbcli_state *cli, TALLOC_CTX *mem finfo1.basic_info.in.file.fnum = fnum1; finfo2 = finfo1; - status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo1); + status = smb_raw_fileinfo(cli->tree, tctx, &finfo1); if (!NT_STATUS_IS_OK(status)) { DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status))); return False; } - printf("Second open initial write time %s\n", - nt_time_string(mem_ctx, finfo1.basic_info.out.write_time)); + torture_comment(tctx, "Second open initial write time %s\n", + nt_time_string(tctx, finfo1.basic_info.out.write_time)); sleep(10); - printf("Doing a 10 byte write to extend the file to see if this changes the last write time.\n"); + torture_comment(tctx, "Doing a 10 byte write to extend the file to see if this changes the last write time.\n"); written = smbcli_write(cli->tree, fnum1, 0, "0123456789", 31, 10); if (written != 10) { - printf("write failed - wrote %d bytes (%s)\n", + torture_comment(tctx, "write failed - wrote %d bytes (%s)\n", (int)written, __location__); return False; } @@ -413,16 +405,16 @@ static BOOL test_delayed_write_update2(struct smbcli_state *cli, TALLOC_CTX *mem finfo1.basic_info.level = RAW_FILEINFO_BASIC_INFO; finfo1.basic_info.in.file.fnum = fnum1; finfo2 = finfo1; - status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo2); + status = smb_raw_fileinfo(cli->tree, tctx, &finfo2); if (!NT_STATUS_IS_OK(status)) { DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status))); return False; } - printf("write time %s\n", - nt_time_string(mem_ctx, finfo2.basic_info.out.write_time)); + torture_comment(tctx, "write time %s\n", + nt_time_string(tctx, finfo2.basic_info.out.write_time)); if (finfo1.basic_info.out.write_time != finfo2.basic_info.out.write_time) { - printf("Server updated write_time\n"); + torture_comment(tctx, "Server updated write_time\n"); } t = time(NULL); @@ -431,17 +423,17 @@ static BOOL test_delayed_write_update2(struct smbcli_state *cli, TALLOC_CTX *mem don't have any effect. But make sure. */ while (time(NULL) < t+15) { - status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo2); + status = smb_raw_fileinfo(cli->tree, tctx, &finfo2); if (!NT_STATUS_IS_OK(status)) { DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status))); ret = False; break; } - printf("write time %s\n", - nt_time_string(mem_ctx, finfo2.basic_info.out.write_time)); + torture_comment(tctx, "write time %s\n", + nt_time_string(tctx, finfo2.basic_info.out.write_time)); if (finfo1.basic_info.out.write_time != finfo2.basic_info.out.write_time) { - printf("Server updated write_time after %d seconds\n", + torture_comment(tctx, "Server updated write_time after %d seconds\n", (int)(time(NULL) - t)); break; } @@ -450,7 +442,7 @@ static BOOL test_delayed_write_update2(struct smbcli_state *cli, TALLOC_CTX *mem } if (finfo1.basic_info.out.write_time == finfo2.basic_info.out.write_time) { - printf("Server did not update write time\n"); + torture_comment(tctx, "Server did not update write time\n"); } @@ -458,9 +450,6 @@ static BOOL test_delayed_write_update2(struct smbcli_state *cli, TALLOC_CTX *mem second connection to ensure it's the same. This is very easy for a Windows server but a bastard to get right on a POSIX server. JRA. */ - if (cli2 != NULL) { - torture_close_connection(cli2); - } if (fnum1 != -1) smbcli_close(cli->tree, fnum1); smbcli_unlink(cli->tree, fname); @@ -480,7 +469,8 @@ static BOOL test_delayed_write_update2(struct smbcli_state *cli, TALLOC_CTX *mem * nasty.... */ -static BOOL test_finfo_after_write(struct smbcli_state *cli, TALLOC_CTX *mem_ctx) +static BOOL test_finfo_after_write(struct torture_context *tctx, struct smbcli_state *cli, + struct smbcli_state *cli2) { union smb_fileinfo finfo1, finfo2; const char *fname = BASEDIR "\\torture_file.txt"; @@ -489,9 +479,6 @@ static BOOL test_finfo_after_write(struct smbcli_state *cli, TALLOC_CTX *mem_ctx int fnum2; BOOL ret = True; ssize_t written; - struct smbcli_state *cli2=NULL; - - printf("Testing finfo update on close\n"); if (!torture_setup_dir(cli, BASEDIR)) { return False; @@ -506,7 +493,7 @@ static BOOL test_finfo_after_write(struct smbcli_state *cli, TALLOC_CTX *mem_ctx finfo1.basic_info.level = RAW_FILEINFO_BASIC_INFO; finfo1.basic_info.in.file.fnum = fnum1; - status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo1); + status = smb_raw_fileinfo(cli->tree, tctx, &finfo1); if (!NT_STATUS_IS_OK(status)) { DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status))); @@ -519,19 +506,15 @@ static BOOL test_finfo_after_write(struct smbcli_state *cli, TALLOC_CTX *mem_ctx written = smbcli_write(cli->tree, fnum1, 0, "x", 0, 1); if (written != 1) { - printf("(%s) written gave %d - should have been 1\n", + torture_comment(tctx, "(%s) written gave %d - should have been 1\n", __location__, (int)written); ret = False; goto done; } - if (!torture_open_connection(&cli2, 1)) { - return False; - } - fnum2 = smbcli_open(cli2->tree, fname, O_RDWR, DENY_NONE); if (fnum2 == -1) { - printf("(%s) failed to open 2nd time - %s\n", + torture_comment(tctx, "(%s) failed to open 2nd time - %s\n", __location__, smbcli_errstr(cli2->tree)); ret = False; goto done; @@ -540,7 +523,7 @@ static BOOL test_finfo_after_write(struct smbcli_state *cli, TALLOC_CTX *mem_ctx written = smbcli_write(cli2->tree, fnum2, 0, "x", 0, 1); if (written != 1) { - printf("(%s) written gave %d - should have been 1\n", + torture_comment(tctx, "(%s) written gave %d - should have been 1\n", __location__, (int)written); ret = False; goto done; @@ -549,7 +532,7 @@ static BOOL test_finfo_after_write(struct smbcli_state *cli, TALLOC_CTX *mem_ctx finfo2.basic_info.level = RAW_FILEINFO_BASIC_INFO; finfo2.basic_info.in.file.path = fname; - status = smb_raw_pathinfo(cli2->tree, mem_ctx, &finfo2); + status = smb_raw_pathinfo(cli2->tree, tctx, &finfo2); if (!NT_STATUS_IS_OK(status)) { DEBUG(0, ("(%s) fileinfo failed: %s\n", @@ -560,31 +543,31 @@ static BOOL test_finfo_after_write(struct smbcli_state *cli, TALLOC_CTX *mem_ctx if (finfo1.basic_info.out.create_time != finfo2.basic_info.out.create_time) { - printf("(%s) create_time changed\n", __location__); + torture_comment(tctx, "(%s) create_time changed\n", __location__); ret = False; goto done; } if (finfo1.basic_info.out.access_time != finfo2.basic_info.out.access_time) { - printf("(%s) access_time changed\n", __location__); + torture_comment(tctx, "(%s) access_time changed\n", __location__); ret = False; goto done; } if (finfo1.basic_info.out.write_time != finfo2.basic_info.out.write_time) { - printf("(%s) write_time changed\n", __location__); - printf("write time conn 1 = %s, conn 2 = %s\n", - nt_time_string(mem_ctx, finfo1.basic_info.out.write_time), - nt_time_string(mem_ctx, finfo2.basic_info.out.write_time)); + torture_comment(tctx, "(%s) write_time changed\n", __location__); + torture_comment(tctx, "write time conn 1 = %s, conn 2 = %s\n", + nt_time_string(tctx, finfo1.basic_info.out.write_time), + nt_time_string(tctx, finfo2.basic_info.out.write_time)); ret = False; goto done; } if (finfo1.basic_info.out.change_time != finfo2.basic_info.out.change_time) { - printf("(%s) change_time changed\n", __location__); + torture_comment(tctx, "(%s) change_time changed\n", __location__); ret = False; goto done; } @@ -595,14 +578,13 @@ static BOOL test_finfo_after_write(struct smbcli_state *cli, TALLOC_CTX *mem_ctx * *not* have updated the stat on disk */ smbcli_close(cli2->tree, fnum2); - torture_close_connection(cli2); cli2 = NULL; /* This call is only for the people looking at ethereal :-) */ finfo2.basic_info.level = RAW_FILEINFO_BASIC_INFO; finfo2.basic_info.in.file.path = fname; - status = smb_raw_pathinfo(cli->tree, mem_ctx, &finfo2); + status = smb_raw_pathinfo(cli->tree, tctx, &finfo2); if (!NT_STATUS_IS_OK(status)) { DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status))); @@ -615,9 +597,6 @@ static BOOL test_finfo_after_write(struct smbcli_state *cli, TALLOC_CTX *mem_ctx smbcli_close(cli->tree, fnum1); smbcli_unlink(cli->tree, fname); smbcli_deltree(cli->tree, BASEDIR); - if (cli2 != NULL) { - torture_close_connection(cli2); - } return ret; } @@ -626,23 +605,13 @@ static BOOL test_finfo_after_write(struct smbcli_state *cli, TALLOC_CTX *mem_ctx /* testing of delayed update of write_time */ -BOOL torture_delay_write(struct torture_context *torture) +struct torture_suite *torture_delay_write(void) { - struct smbcli_state *cli; - BOOL ret = True; - TALLOC_CTX *mem_ctx; - - if (!torture_open_connection(&cli, 0)) { - return False; - } + struct torture_suite *suite = torture_suite_create(talloc_autofree_context(), "DELAYWRITE"); - mem_ctx = talloc_init("torture_delay_write"); + torture_suite_add_2smb_test(suite, "finfo update on close", test_finfo_after_write); + torture_suite_add_1smb_test(suite, "delayed update of write time", test_delayed_write_update); + torture_suite_add_2smb_test(suite, "delayed update of write time using 2 connections", test_delayed_write_update2); - ret &= test_finfo_after_write(cli, mem_ctx); - ret &= test_delayed_write_update(cli, mem_ctx); - ret &= test_delayed_write_update2(cli, mem_ctx); - - torture_close_connection(cli); - talloc_free(mem_ctx); - return ret; + return suite; } -- cgit From 72d88d158a6e82392116bab09ce8704115072d07 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 5 Mar 2007 21:28:55 +0000 Subject: r21707: Finally merge my (long-living) perlselftest branch. This changes the main selftest code to be in perl rather than in shell script. The selftest script is now no longer a black box but a regular executable that takes --help. This adds the following features: * "make test TESTS=foo" will run only the tests that match the regex "foo" * ability to deal with expected failures. the suite will not warn about tests that fail and are known to fail, but will warn about other failing tests and tests that are succeeding tests but incorrectly marked as failing. * ability to print a summary with all failures at the end of the run It also opens up the way to the following features, which I hope to implement later: * "environments", for example having a complete domains with DCs and domain members in a testenvironment * only set up smbd if necessary (not when running LOCAL tests, for example) * different mktestsetup scripts per target. except for the mktestsetup script, we can use the same infrastructure for samba 3 or windows. (This used to be commit 38f867880beb40c691e9713f854426031310629c) --- source4/torture/basic/delaywrite.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'source4/torture/basic/delaywrite.c') diff --git a/source4/torture/basic/delaywrite.c b/source4/torture/basic/delaywrite.c index 4c2a511721..072f15c623 100644 --- a/source4/torture/basic/delaywrite.c +++ b/source4/torture/basic/delaywrite.c @@ -487,6 +487,7 @@ static BOOL test_finfo_after_write(struct torture_context *tctx, struct smbcli_s fnum1 = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE); if (fnum1 == -1) { ret = False; + torture_result(tctx, TORTURE_FAIL, __location__": unable to open %s", fname); goto done; } @@ -496,8 +497,8 @@ static BOOL test_finfo_after_write(struct torture_context *tctx, struct smbcli_s status = smb_raw_fileinfo(cli->tree, tctx, &finfo1); if (!NT_STATUS_IS_OK(status)) { - DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status))); ret = False; + torture_result(tctx, TORTURE_FAIL, __location__": fileinfo failed: %s", nt_errstr(status)); goto done; } @@ -506,16 +507,15 @@ static BOOL test_finfo_after_write(struct torture_context *tctx, struct smbcli_s written = smbcli_write(cli->tree, fnum1, 0, "x", 0, 1); if (written != 1) { - torture_comment(tctx, "(%s) written gave %d - should have been 1\n", - __location__, (int)written); + torture_result(tctx, TORTURE_FAIL, __location__": written gave %d - should have been 1", (int)written); ret = False; goto done; } fnum2 = smbcli_open(cli2->tree, fname, O_RDWR, DENY_NONE); if (fnum2 == -1) { - torture_comment(tctx, "(%s) failed to open 2nd time - %s\n", - __location__, smbcli_errstr(cli2->tree)); + torture_result(tctx, TORTURE_FAIL, __location__": failed to open 2nd time - %s", + smbcli_errstr(cli2->tree)); ret = False; goto done; } @@ -523,8 +523,8 @@ static BOOL test_finfo_after_write(struct torture_context *tctx, struct smbcli_s written = smbcli_write(cli2->tree, fnum2, 0, "x", 0, 1); if (written != 1) { - torture_comment(tctx, "(%s) written gave %d - should have been 1\n", - __location__, (int)written); + torture_result(tctx, TORTURE_FAIL, __location__": written gave %d - should have been 1", + (int)written); ret = False; goto done; } @@ -535,30 +535,30 @@ static BOOL test_finfo_after_write(struct torture_context *tctx, struct smbcli_s status = smb_raw_pathinfo(cli2->tree, tctx, &finfo2); if (!NT_STATUS_IS_OK(status)) { - DEBUG(0, ("(%s) fileinfo failed: %s\n", - __location__, nt_errstr(status))); + torture_result(tctx, TORTURE_FAIL, __location__": fileinfo failed: %s", + nt_errstr(status)); ret = False; goto done; } if (finfo1.basic_info.out.create_time != finfo2.basic_info.out.create_time) { - torture_comment(tctx, "(%s) create_time changed\n", __location__); + torture_result(tctx, TORTURE_FAIL, __location__": create_time changed"); ret = False; goto done; } if (finfo1.basic_info.out.access_time != finfo2.basic_info.out.access_time) { - torture_comment(tctx, "(%s) access_time changed\n", __location__); + torture_result(tctx, TORTURE_FAIL, __location__": access_time changed"); ret = False; goto done; } if (finfo1.basic_info.out.write_time != finfo2.basic_info.out.write_time) { - torture_comment(tctx, "(%s) write_time changed\n", __location__); - torture_comment(tctx, "write time conn 1 = %s, conn 2 = %s\n", + torture_result(tctx, TORTURE_FAIL, __location__": write_time changed:\n" + "write time conn 1 = %s, conn 2 = %s", nt_time_string(tctx, finfo1.basic_info.out.write_time), nt_time_string(tctx, finfo2.basic_info.out.write_time)); ret = False; @@ -567,7 +567,7 @@ static BOOL test_finfo_after_write(struct torture_context *tctx, struct smbcli_s if (finfo1.basic_info.out.change_time != finfo2.basic_info.out.change_time) { - torture_comment(tctx, "(%s) change_time changed\n", __location__); + torture_result(tctx, TORTURE_FAIL, __location__": change_time changed"); ret = False; goto done; } @@ -587,7 +587,7 @@ static BOOL test_finfo_after_write(struct torture_context *tctx, struct smbcli_s status = smb_raw_pathinfo(cli->tree, tctx, &finfo2); if (!NT_STATUS_IS_OK(status)) { - DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status))); + torture_result(tctx, TORTURE_FAIL, __location__": fileinfo failed: %s", nt_errstr(status)); ret = False; goto done; } -- cgit From 0479a2f1cbae51fcd8dbdc3c148c808421fb4d25 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 02:07:03 +0000 Subject: r23792: convert Samba4 to GPLv3 There are still a few tidyups of old FSF addresses to come (in both s3 and s4). More commits soon. (This used to be commit fcf38a38ac691abd0fa51b89dc951a08e89fdafa) --- source4/torture/basic/delaywrite.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'source4/torture/basic/delaywrite.c') diff --git a/source4/torture/basic/delaywrite.c b/source4/torture/basic/delaywrite.c index 072f15c623..289e08ae59 100644 --- a/source4/torture/basic/delaywrite.c +++ b/source4/torture/basic/delaywrite.c @@ -9,7 +9,7 @@ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -18,8 +18,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ #include "includes.h" -- cgit From 2151cde58014ea2e822c13d2f8a369b45dc19ca8 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 6 Oct 2007 22:28:14 +0000 Subject: r25554: Convert last instances of BOOL, True and False to the standard types. (This used to be commit 566aa14139510788548a874e9213d91317f83ca9) --- source4/torture/basic/delaywrite.c | 90 +++++++++++++++++++------------------- 1 file changed, 45 insertions(+), 45 deletions(-) (limited to 'source4/torture/basic/delaywrite.c') diff --git a/source4/torture/basic/delaywrite.c b/source4/torture/basic/delaywrite.c index 289e08ae59..8928754e1a 100644 --- a/source4/torture/basic/delaywrite.c +++ b/source4/torture/basic/delaywrite.c @@ -31,24 +31,24 @@ #define BASEDIR "\\delaywrite" -static BOOL test_delayed_write_update(struct torture_context *tctx, struct smbcli_state *cli) +static bool test_delayed_write_update(struct torture_context *tctx, struct smbcli_state *cli) { union smb_fileinfo finfo1, finfo2; const char *fname = BASEDIR "\\torture_file.txt"; NTSTATUS status; int fnum1 = -1; - BOOL ret = True; + bool ret = true; ssize_t written; time_t t; if (!torture_setup_dir(cli, BASEDIR)) { - return False; + return false; } fnum1 = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE); if (fnum1 == -1) { torture_comment(tctx, "Failed to open %s\n", fname); - return False; + return false; } finfo1.basic_info.level = RAW_FILEINFO_BASIC_INFO; @@ -59,7 +59,7 @@ static BOOL test_delayed_write_update(struct torture_context *tctx, struct smbcl if (!NT_STATUS_IS_OK(status)) { DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status))); - return False; + return false; } torture_comment(tctx, "Initial write time %s\n", @@ -74,7 +74,7 @@ static BOOL test_delayed_write_update(struct torture_context *tctx, struct smbcl if (written != 1) { torture_comment(tctx, "write failed - wrote %d bytes (%s)\n", (int)written, __location__); - return False; + return false; } t = time(NULL); @@ -84,7 +84,7 @@ static BOOL test_delayed_write_update(struct torture_context *tctx, struct smbcl if (!NT_STATUS_IS_OK(status)) { DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status))); - ret = False; + ret = false; break; } torture_comment(tctx, "write time %s\n", @@ -100,7 +100,7 @@ static BOOL test_delayed_write_update(struct torture_context *tctx, struct smbcl if (finfo1.basic_info.out.write_time == finfo2.basic_info.out.write_time) { torture_comment(tctx, "Server did not update write time?!\n"); - ret = False; + ret = false; } @@ -116,7 +116,7 @@ static BOOL test_delayed_write_update(struct torture_context *tctx, struct smbcl * Do as above, but using 2 connections. */ -static BOOL test_delayed_write_update2(struct torture_context *tctx, struct smbcli_state *cli, +static bool test_delayed_write_update2(struct torture_context *tctx, struct smbcli_state *cli, struct smbcli_state *cli2) { union smb_fileinfo finfo1, finfo2; @@ -124,19 +124,19 @@ static BOOL test_delayed_write_update2(struct torture_context *tctx, struct smbc NTSTATUS status; int fnum1 = -1; int fnum2 = -1; - BOOL ret = True; + bool ret = true; ssize_t written; time_t t; union smb_flush flsh; if (!torture_setup_dir(cli, BASEDIR)) { - return False; + return false; } fnum1 = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE); if (fnum1 == -1) { torture_comment(tctx, "Failed to open %s\n", fname); - return False; + return false; } finfo1.basic_info.level = RAW_FILEINFO_BASIC_INFO; @@ -147,7 +147,7 @@ static BOOL test_delayed_write_update2(struct torture_context *tctx, struct smbc if (!NT_STATUS_IS_OK(status)) { DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status))); - return False; + return false; } torture_comment(tctx, "Initial write time %s\n", @@ -180,7 +180,7 @@ static BOOL test_delayed_write_update2(struct torture_context *tctx, struct smbc if (!NT_STATUS_IS_OK(status)) { DEBUG(0, ("sfileinfo failed: %s\n", nt_errstr(status))); - return False; + return false; } } @@ -193,7 +193,7 @@ static BOOL test_delayed_write_update2(struct torture_context *tctx, struct smbc if (!NT_STATUS_IS_OK(status)) { DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status))); - ret = False; + ret = false; break; } torture_comment(tctx, "write time %s\n", @@ -209,7 +209,7 @@ static BOOL test_delayed_write_update2(struct torture_context *tctx, struct smbc if (finfo1.basic_info.out.write_time == finfo2.basic_info.out.write_time) { torture_comment(tctx, "Server did not update write time?!\n"); - ret = False; + ret = false; } /* Now try a write to see if the write time gets reset. */ @@ -222,7 +222,7 @@ static BOOL test_delayed_write_update2(struct torture_context *tctx, struct smbc if (!NT_STATUS_IS_OK(status)) { DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status))); - return False; + return false; } torture_comment(tctx, "Modified write time %s\n", @@ -236,7 +236,7 @@ static BOOL test_delayed_write_update2(struct torture_context *tctx, struct smbc if (written != 10) { torture_comment(tctx, "write failed - wrote %d bytes (%s)\n", (int)written, __location__); - return False; + return false; } /* Just to prove to tridge that the an smbflush has no effect on @@ -249,7 +249,7 @@ static BOOL test_delayed_write_update2(struct torture_context *tctx, struct smbc status = smb_raw_flush(cli->tree, &flsh); if (!NT_STATUS_IS_OK(status)) { DEBUG(0, ("smbflush failed: %s\n", nt_errstr(status))); - return False; + return false; } t = time(NULL); @@ -262,7 +262,7 @@ static BOOL test_delayed_write_update2(struct torture_context *tctx, struct smbc if (!NT_STATUS_IS_OK(status)) { DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status))); - ret = False; + ret = false; break; } torture_comment(tctx, "write time %s\n", @@ -283,7 +283,7 @@ static BOOL test_delayed_write_update2(struct torture_context *tctx, struct smbc fnum2 = smbcli_open(cli->tree, fname, O_RDWR, DENY_NONE); if (fnum2 == -1) { torture_comment(tctx, "Failed to open %s\n", fname); - return False; + return false; } torture_comment(tctx, "Doing a 10 byte write to extend the file via second fd and see if this changes the last write time.\n"); @@ -293,14 +293,14 @@ static BOOL test_delayed_write_update2(struct torture_context *tctx, struct smbc if (written != 10) { torture_comment(tctx, "write failed - wrote %d bytes (%s)\n", (int)written, __location__); - return False; + return false; } status = smb_raw_fileinfo(cli->tree, tctx, &finfo2); if (!NT_STATUS_IS_OK(status)) { DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status))); - return False; + return false; } torture_comment(tctx, "write time %s\n", nt_time_string(tctx, finfo2.basic_info.out.write_time)); @@ -319,7 +319,7 @@ static BOOL test_delayed_write_update2(struct torture_context *tctx, struct smbc if (written != 10) { torture_comment(tctx, "write failed - wrote %d bytes (%s)\n", (int)written, __location__); - return False; + return false; } finfo1.basic_info.level = RAW_FILEINFO_BASIC_INFO; @@ -329,7 +329,7 @@ static BOOL test_delayed_write_update2(struct torture_context *tctx, struct smbc if (!NT_STATUS_IS_OK(status)) { DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status))); - return False; + return false; } torture_comment(tctx, "write time %s\n", nt_time_string(tctx, finfo2.basic_info.out.write_time)); @@ -347,7 +347,7 @@ static BOOL test_delayed_write_update2(struct torture_context *tctx, struct smbc if (!NT_STATUS_IS_OK(status)) { DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status))); - ret = False; + ret = false; break; } torture_comment(tctx, "write time %s\n", @@ -373,7 +373,7 @@ static BOOL test_delayed_write_update2(struct torture_context *tctx, struct smbc fnum1 = smbcli_open(cli->tree, fname, O_RDWR, DENY_NONE); if (fnum1 == -1) { torture_comment(tctx, "Failed to open %s\n", fname); - return False; + return false; } finfo1.basic_info.level = RAW_FILEINFO_BASIC_INFO; @@ -384,7 +384,7 @@ static BOOL test_delayed_write_update2(struct torture_context *tctx, struct smbc if (!NT_STATUS_IS_OK(status)) { DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status))); - return False; + return false; } torture_comment(tctx, "Second open initial write time %s\n", @@ -398,7 +398,7 @@ static BOOL test_delayed_write_update2(struct torture_context *tctx, struct smbc if (written != 10) { torture_comment(tctx, "write failed - wrote %d bytes (%s)\n", (int)written, __location__); - return False; + return false; } finfo1.basic_info.level = RAW_FILEINFO_BASIC_INFO; @@ -408,7 +408,7 @@ static BOOL test_delayed_write_update2(struct torture_context *tctx, struct smbc if (!NT_STATUS_IS_OK(status)) { DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status))); - return False; + return false; } torture_comment(tctx, "write time %s\n", nt_time_string(tctx, finfo2.basic_info.out.write_time)); @@ -426,7 +426,7 @@ static BOOL test_delayed_write_update2(struct torture_context *tctx, struct smbc if (!NT_STATUS_IS_OK(status)) { DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status))); - ret = False; + ret = false; break; } torture_comment(tctx, "write time %s\n", @@ -468,7 +468,7 @@ static BOOL test_delayed_write_update2(struct torture_context *tctx, struct smbc * nasty.... */ -static BOOL test_finfo_after_write(struct torture_context *tctx, struct smbcli_state *cli, +static bool test_finfo_after_write(struct torture_context *tctx, struct smbcli_state *cli, struct smbcli_state *cli2) { union smb_fileinfo finfo1, finfo2; @@ -476,16 +476,16 @@ static BOOL test_finfo_after_write(struct torture_context *tctx, struct smbcli_s NTSTATUS status; int fnum1 = -1; int fnum2; - BOOL ret = True; + bool ret = true; ssize_t written; if (!torture_setup_dir(cli, BASEDIR)) { - return False; + return false; } fnum1 = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE); if (fnum1 == -1) { - ret = False; + ret = false; torture_result(tctx, TORTURE_FAIL, __location__": unable to open %s", fname); goto done; } @@ -496,7 +496,7 @@ static BOOL test_finfo_after_write(struct torture_context *tctx, struct smbcli_s status = smb_raw_fileinfo(cli->tree, tctx, &finfo1); if (!NT_STATUS_IS_OK(status)) { - ret = False; + ret = false; torture_result(tctx, TORTURE_FAIL, __location__": fileinfo failed: %s", nt_errstr(status)); goto done; } @@ -507,7 +507,7 @@ static BOOL test_finfo_after_write(struct torture_context *tctx, struct smbcli_s if (written != 1) { torture_result(tctx, TORTURE_FAIL, __location__": written gave %d - should have been 1", (int)written); - ret = False; + ret = false; goto done; } @@ -515,7 +515,7 @@ static BOOL test_finfo_after_write(struct torture_context *tctx, struct smbcli_s if (fnum2 == -1) { torture_result(tctx, TORTURE_FAIL, __location__": failed to open 2nd time - %s", smbcli_errstr(cli2->tree)); - ret = False; + ret = false; goto done; } @@ -524,7 +524,7 @@ static BOOL test_finfo_after_write(struct torture_context *tctx, struct smbcli_s if (written != 1) { torture_result(tctx, TORTURE_FAIL, __location__": written gave %d - should have been 1", (int)written); - ret = False; + ret = false; goto done; } @@ -536,21 +536,21 @@ static BOOL test_finfo_after_write(struct torture_context *tctx, struct smbcli_s if (!NT_STATUS_IS_OK(status)) { torture_result(tctx, TORTURE_FAIL, __location__": fileinfo failed: %s", nt_errstr(status)); - ret = False; + ret = false; goto done; } if (finfo1.basic_info.out.create_time != finfo2.basic_info.out.create_time) { torture_result(tctx, TORTURE_FAIL, __location__": create_time changed"); - ret = False; + ret = false; goto done; } if (finfo1.basic_info.out.access_time != finfo2.basic_info.out.access_time) { torture_result(tctx, TORTURE_FAIL, __location__": access_time changed"); - ret = False; + ret = false; goto done; } @@ -560,14 +560,14 @@ static BOOL test_finfo_after_write(struct torture_context *tctx, struct smbcli_s "write time conn 1 = %s, conn 2 = %s", nt_time_string(tctx, finfo1.basic_info.out.write_time), nt_time_string(tctx, finfo2.basic_info.out.write_time)); - ret = False; + ret = false; goto done; } if (finfo1.basic_info.out.change_time != finfo2.basic_info.out.change_time) { torture_result(tctx, TORTURE_FAIL, __location__": change_time changed"); - ret = False; + ret = false; goto done; } @@ -587,7 +587,7 @@ static BOOL test_finfo_after_write(struct torture_context *tctx, struct smbcli_s if (!NT_STATUS_IS_OK(status)) { torture_result(tctx, TORTURE_FAIL, __location__": fileinfo failed: %s", nt_errstr(status)); - ret = False; + ret = false; goto done; } -- cgit From c555c3fa389070154e7b1d4b03a846223ed4973d Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Sat, 1 Dec 2007 11:39:39 +0100 Subject: r26219: BASE-DELAYWRITE: make the tests more strict about the write time update metze (This used to be commit c1335651d32a2b48bcf8c117a5bc16fe453170bc) --- source4/torture/basic/delaywrite.c | 87 +++++++++++++++++++++----------------- 1 file changed, 49 insertions(+), 38 deletions(-) (limited to 'source4/torture/basic/delaywrite.c') diff --git a/source4/torture/basic/delaywrite.c b/source4/torture/basic/delaywrite.c index 8928754e1a..fd21a68b44 100644 --- a/source4/torture/basic/delaywrite.c +++ b/source4/torture/basic/delaywrite.c @@ -90,8 +90,16 @@ static bool test_delayed_write_update(struct torture_context *tctx, struct smbcl torture_comment(tctx, "write time %s\n", nt_time_string(tctx, finfo2.basic_info.out.write_time)); if (finfo1.basic_info.out.write_time != finfo2.basic_info.out.write_time) { - torture_comment(tctx, "Server updated write_time after %d seconds\n", - (int)(time(NULL) - t)); + int diff = time(NULL) - t; + if (diff < 2) { + torture_comment(tctx, "Server updated write_time after %d seconds (wrong!)\n", + diff); + ret = false; + break; + } + + torture_comment(tctx, "Server updated write_time after %d seconds (correct)\n", + diff); break; } sleep(1); @@ -99,7 +107,7 @@ static bool test_delayed_write_update(struct torture_context *tctx, struct smbcl } if (finfo1.basic_info.out.write_time == finfo2.basic_info.out.write_time) { - torture_comment(tctx, "Server did not update write time?!\n"); + torture_comment(tctx, "Server did not update write time (wrong!)\n"); ret = false; } @@ -184,31 +192,21 @@ static bool test_delayed_write_update2(struct torture_context *tctx, struct smbc } } - t = time(NULL); - - while (time(NULL) < t+120) { - finfo2.basic_info.in.file.path = fname; + finfo2.basic_info.in.file.path = fname; - status = smb_raw_pathinfo(cli2->tree, tctx, &finfo2); + status = smb_raw_pathinfo(cli2->tree, tctx, &finfo2); - if (!NT_STATUS_IS_OK(status)) { - DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status))); - ret = false; - break; - } - torture_comment(tctx, "write time %s\n", - nt_time_string(tctx, finfo2.basic_info.out.write_time)); - if (finfo1.basic_info.out.write_time != finfo2.basic_info.out.write_time) { - torture_comment(tctx, "Server updated write_time after %d seconds\n", - (int)(time(NULL) - t)); - break; - } - sleep(1); - fflush(stdout); + if (!NT_STATUS_IS_OK(status)) { + DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status))); + return false; } - - if (finfo1.basic_info.out.write_time == finfo2.basic_info.out.write_time) { - torture_comment(tctx, "Server did not update write time?!\n"); + torture_comment(tctx, "write time %s\n", + nt_time_string(tctx, finfo2.basic_info.out.write_time)); + + if (finfo1.basic_info.out.write_time != finfo2.basic_info.out.write_time) { + torture_comment(tctx, "Server updated write_time (correct)\n"); + } else { + torture_comment(tctx, "Server did not update write time (wrong!)\n"); ret = false; } @@ -268,8 +266,9 @@ static bool test_delayed_write_update2(struct torture_context *tctx, struct smbc torture_comment(tctx, "write time %s\n", nt_time_string(tctx, finfo2.basic_info.out.write_time)); if (finfo1.basic_info.out.write_time != finfo2.basic_info.out.write_time) { - torture_comment(tctx, "Server updated write_time after %d seconds\n", + torture_comment(tctx, "Server updated write_time after %d seconds (wrong!)\n", (int)(time(NULL) - t)); + ret = false; break; } sleep(1); @@ -277,7 +276,7 @@ static bool test_delayed_write_update2(struct torture_context *tctx, struct smbc } if (finfo1.basic_info.out.write_time == finfo2.basic_info.out.write_time) { - torture_comment(tctx, "Server did not update write time\n"); + torture_comment(tctx, "Server did not update write time (correct)\n"); } fnum2 = smbcli_open(cli->tree, fname, O_RDWR, DENY_NONE); @@ -305,7 +304,8 @@ static bool test_delayed_write_update2(struct torture_context *tctx, struct smbc torture_comment(tctx, "write time %s\n", nt_time_string(tctx, finfo2.basic_info.out.write_time)); if (finfo1.basic_info.out.write_time != finfo2.basic_info.out.write_time) { - torture_comment(tctx, "Server updated write_time\n"); + torture_comment(tctx, "Server updated write_time (wrong!)\n"); + ret = false; } torture_comment(tctx, "Closing the first fd to see if write time updated.\n"); @@ -334,7 +334,8 @@ static bool test_delayed_write_update2(struct torture_context *tctx, struct smbc torture_comment(tctx, "write time %s\n", nt_time_string(tctx, finfo2.basic_info.out.write_time)); if (finfo1.basic_info.out.write_time != finfo2.basic_info.out.write_time) { - torture_comment(tctx, "Server updated write_time\n"); + torture_comment(tctx, "Server updated write_time (wrong!)\n"); + ret = false; } t = time(NULL); @@ -353,8 +354,9 @@ static bool test_delayed_write_update2(struct torture_context *tctx, struct smbc torture_comment(tctx, "write time %s\n", nt_time_string(tctx, finfo2.basic_info.out.write_time)); if (finfo1.basic_info.out.write_time != finfo2.basic_info.out.write_time) { - torture_comment(tctx, "Server updated write_time after %d seconds\n", + torture_comment(tctx, "Server updated write_time after %d seconds (wrong!)\n", (int)(time(NULL) - t)); + ret = false; break; } sleep(1); @@ -362,10 +364,10 @@ static bool test_delayed_write_update2(struct torture_context *tctx, struct smbc } if (finfo1.basic_info.out.write_time == finfo2.basic_info.out.write_time) { - torture_comment(tctx, "Server did not update write time\n"); + torture_comment(tctx, "Server did not update write time (correct)\n"); } - torture_comment(tctx, "Closing both fd's to see if write time updated.\n"); + torture_comment(tctx, "Closing second fd to see if write time updated.\n"); smbcli_close(cli->tree, fnum2); fnum2 = -1; @@ -413,13 +415,13 @@ static bool test_delayed_write_update2(struct torture_context *tctx, struct smbc torture_comment(tctx, "write time %s\n", nt_time_string(tctx, finfo2.basic_info.out.write_time)); if (finfo1.basic_info.out.write_time != finfo2.basic_info.out.write_time) { - torture_comment(tctx, "Server updated write_time\n"); + torture_comment(tctx, "Server updated write_time (wrong!)\n"); + ret = false; } t = time(NULL); - /* Once the time was set using setfileinfo then it stays set - writes - don't have any effect. But make sure. */ + /* Now the write time should be updated again */ while (time(NULL) < t+15) { status = smb_raw_fileinfo(cli->tree, tctx, &finfo2); @@ -432,8 +434,16 @@ static bool test_delayed_write_update2(struct torture_context *tctx, struct smbc torture_comment(tctx, "write time %s\n", nt_time_string(tctx, finfo2.basic_info.out.write_time)); if (finfo1.basic_info.out.write_time != finfo2.basic_info.out.write_time) { - torture_comment(tctx, "Server updated write_time after %d seconds\n", - (int)(time(NULL) - t)); + int diff = time(NULL) - t; + if (diff < 2) { + torture_comment(tctx, "Server updated write_time after %d seconds (wrong!)\n", + diff); + ret = false; + break; + } + + torture_comment(tctx, "Server updated write_time after %d seconds (correct)\n", + diff); break; } sleep(1); @@ -441,7 +451,8 @@ static bool test_delayed_write_update2(struct torture_context *tctx, struct smbc } if (finfo1.basic_info.out.write_time == finfo2.basic_info.out.write_time) { - torture_comment(tctx, "Server did not update write time\n"); + torture_comment(tctx, "Server did not update write time (wrong!)\n"); + ret = false; } -- cgit From 4ab0b47ffd812350dce0255d4c654c16da102717 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Sat, 1 Dec 2007 11:43:38 +0100 Subject: r26220: BASE-DELAYWRITE: add more subtests to explore write time update details metze (This used to be commit 92dcc85e3a8798910eb0a9059f3a2944fa51cbd1) --- source4/torture/basic/delaywrite.c | 679 +++++++++++++++++++++++++++++++++++++ 1 file changed, 679 insertions(+) (limited to 'source4/torture/basic/delaywrite.c') diff --git a/source4/torture/basic/delaywrite.c b/source4/torture/basic/delaywrite.c index fd21a68b44..9043e499a8 100644 --- a/source4/torture/basic/delaywrite.c +++ b/source4/torture/basic/delaywrite.c @@ -611,6 +611,681 @@ static bool test_finfo_after_write(struct torture_context *tctx, struct smbcli_s return ret; } +#define COMPARE_WRITE_TIME_CMP(given, correct, cmp) do { \ + NTTIME g = (given).basic_info.out.write_time; \ + NTTIME c = (correct).basic_info.out.write_time; \ + if (g cmp c) { \ + torture_result(tctx, TORTURE_FAIL, __location__": wrong write_time (%s)%s %s (%s)%s", \ + #given, nt_time_string(tctx, g), \ + #cmp, #correct, nt_time_string(tctx, c)); \ + ret = false; \ + goto done; \ + } \ +} while (0) +#define COMPARE_WRITE_TIME_EQUAL(given,correct) \ + COMPARE_WRITE_TIME_CMP(given,correct,!=) +#define COMPARE_WRITE_TIME_GREATER(given,correct) \ + COMPARE_WRITE_TIME_CMP(given,correct,<=) +#define COMPARE_WRITE_TIME_LESS(given,correct) \ + COMPARE_WRITE_TIME_CMP(given,correct,>=) + +#define GET_INFO_FILE(finfo) do { \ + NTSTATUS _status; \ + _status = smb_raw_fileinfo(cli->tree, tctx, &finfo); \ + if (!NT_STATUS_IS_OK(_status)) { \ + ret = false; \ + torture_result(tctx, TORTURE_FAIL, __location__": fileinfo failed: %s", \ + nt_errstr(_status)); \ + goto done; \ + } \ + torture_comment(tctx, "fileinfo: Write time (%s)\n", \ + nt_time_string(tctx, finfo.basic_info.out.write_time)); \ +} while (0) +#define GET_INFO_PATH(pinfo) do { \ + NTSTATUS _status; \ + _status = smb_raw_pathinfo(cli2->tree, tctx, &pinfo); \ + if (!NT_STATUS_IS_OK(_status)) { \ + torture_result(tctx, TORTURE_FAIL, __location__": pathinfo failed: %s", \ + nt_errstr(_status)); \ + ret = false; \ + goto done; \ + } \ + torture_comment(tctx, "pathinfo: Write time (%s)\n", \ + nt_time_string(tctx, pinfo.basic_info.out.write_time)); \ +} while (0) +#define GET_INFO_BOTH(finfo,pinfo) do { \ + GET_INFO_FILE(finfo); \ + GET_INFO_PATH(pinfo); \ + COMPARE_WRITE_TIME_EQUAL(finfo,pinfo); \ +} while (0) + +#define SET_INFO_FILE_EX(finfo, wrtime, tree, tfnum) do { \ + NTSTATUS _status; \ + union smb_setfileinfo sfinfo; \ + sfinfo.basic_info.level = RAW_SFILEINFO_BASIC_INFO; \ + sfinfo.basic_info.in.file.fnum = tfnum; \ + sfinfo.basic_info.in.create_time = (finfo).basic_info.out.create_time; \ + sfinfo.basic_info.in.access_time = (finfo).basic_info.out.access_time; \ + unix_to_nt_time(&sfinfo.basic_info.in.write_time, (wrtime)); \ + sfinfo.basic_info.in.change_time = finfo1.basic_info.out.change_time; \ + sfinfo.basic_info.in.attrib = finfo1.basic_info.out.attrib; \ + _status = smb_raw_setfileinfo(tree, &sfinfo); \ + if (!NT_STATUS_IS_OK(_status)) { \ + torture_result(tctx, TORTURE_FAIL, __location__": setfileinfo failed: %s", \ + nt_errstr(_status)); \ + ret = false; \ + goto done; \ + } \ +} while (0) +#define SET_INFO_FILE(finfo, wrtime) \ + SET_INFO_FILE_EX(finfo, wrtime, cli->tree, fnum1) + +static bool test_delayed_write_update3(struct torture_context *tctx, + struct smbcli_state *cli, + struct smbcli_state *cli2) +{ + union smb_fileinfo finfo0, finfo1, finfo2, finfo3, finfo4; + union smb_fileinfo pinfo0, pinfo1, pinfo2, pinfo3, pinfo4, pinfo5; + const char *fname = BASEDIR "\\torture_file.txt"; + int fnum1 = -1; + bool ret = true; + ssize_t written; + time_t t; + + if (!torture_setup_dir(cli, BASEDIR)) { + return false; + } + + torture_comment(tctx, "Open the file handle\n"); + fnum1 = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE); + if (fnum1 == -1) { + ret = false; + torture_result(tctx, TORTURE_FAIL, __location__": unable to open %s", fname); + goto done; + } + + finfo0.basic_info.level = RAW_FILEINFO_BASIC_INFO; + finfo0.basic_info.in.file.fnum = fnum1; + finfo1 = finfo0; + finfo2 = finfo0; + finfo3 = finfo0; + finfo4 = finfo0; + pinfo0.basic_info.level = RAW_FILEINFO_BASIC_INFO; + pinfo0.basic_info.in.file.path = fname; + pinfo1 = pinfo0; + pinfo2 = pinfo0; + pinfo3 = pinfo0; + pinfo4 = pinfo0; + pinfo5 = pinfo0; + + /* get the initial times */ + GET_INFO_BOTH(finfo0,pinfo0); + + /* + * make sure the write time is updated 2 seconds later + * calcuated from the first write + * (but expect upto 5 seconds extra time for a busy server) + */ + t = time(NULL); + while (time(NULL) < t+7) { + /* do a write */ + torture_comment(tctx, "Do a write on the file handle\n"); + written = smbcli_write(cli->tree, fnum1, 0, "x", 0, 1); + if (written != 1) { + torture_result(tctx, TORTURE_FAIL, __location__": written gave %d - should have been 1", (int)written); + ret = false; + goto done; + } + /* get the times after the write */ + GET_INFO_FILE(finfo1); + + if (finfo1.basic_info.out.write_time > finfo0.basic_info.out.write_time) { + int diff = time(NULL) - t; + if (diff < 2) { + torture_comment(tctx, "Server updated write_time after %d seconds (wrong!)\n", + diff); + ret = false; + break; + } + + torture_comment(tctx, "Server updated write_time after %d seconds (correct)\n", + diff); + break; + } + msleep(500); + } + + GET_INFO_BOTH(finfo1,pinfo1); + + /* sure any further write doesn't update the write time */ + t = time(NULL); + while (time(NULL) < t+15) { + /* do a write */ + torture_comment(tctx, "Do a write on the file handle\n"); + written = smbcli_write(cli->tree, fnum1, 0, "x", 0, 1); + if (written != 1) { + torture_result(tctx, TORTURE_FAIL, __location__": written gave %d - should have been 1", (int)written); + ret = false; + goto done; + } + /* get the times after the write */ + GET_INFO_BOTH(finfo2,pinfo2); + + if (finfo2.basic_info.out.write_time > finfo1.basic_info.out.write_time) { + torture_comment(tctx, "Server updated write_time after %d seconds (wrong!)\n", + (int)(time(NULL) - t)); + ret = false; + break; + } + msleep(2000); + } + + GET_INFO_BOTH(finfo2,pinfo2); + COMPARE_WRITE_TIME_EQUAL(finfo2, finfo1); + if (finfo2.basic_info.out.write_time == finfo1.basic_info.out.write_time) { + torture_comment(tctx, "Server did not update write_time (correct)\n"); + } + + /* sleep */ + msleep(5000); + + GET_INFO_BOTH(finfo3,pinfo3); + COMPARE_WRITE_TIME_EQUAL(finfo3, finfo2); + + /* + * the close updates the write time to the time of the close + * and not to the time of the last write! + */ + torture_comment(tctx, "Close the file handle\n"); + smbcli_close(cli->tree, fnum1); + fnum1 = -1; + + GET_INFO_PATH(pinfo4); + COMPARE_WRITE_TIME_GREATER(pinfo4, pinfo3); + + if (pinfo4.basic_info.out.write_time > pinfo3.basic_info.out.write_time) { + torture_comment(tctx, "Server updated the write_time on close (correct)\n"); + } + + done: + if (fnum1 != -1) + smbcli_close(cli->tree, fnum1); + smbcli_unlink(cli->tree, fname); + smbcli_deltree(cli->tree, BASEDIR); + + return ret; +} + +static bool test_delayed_write_update4(struct torture_context *tctx, + struct smbcli_state *cli, + struct smbcli_state *cli2) +{ + union smb_fileinfo finfo0, finfo1, finfo2, finfo3, finfo4; + union smb_fileinfo pinfo0, pinfo1, pinfo2, pinfo3, pinfo4, pinfo5; + const char *fname = BASEDIR "\\torture_file.txt"; + int fnum1 = -1; + bool ret = true; + ssize_t written; + time_t t; + + if (!torture_setup_dir(cli, BASEDIR)) { + return false; + } + + torture_comment(tctx, "Open the file handle\n"); + fnum1 = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE); + if (fnum1 == -1) { + ret = false; + torture_result(tctx, TORTURE_FAIL, __location__": unable to open %s", fname); + goto done; + } + + finfo0.basic_info.level = RAW_FILEINFO_BASIC_INFO; + finfo0.basic_info.in.file.fnum = fnum1; + finfo1 = finfo0; + finfo2 = finfo0; + finfo3 = finfo0; + finfo4 = finfo0; + pinfo0.basic_info.level = RAW_FILEINFO_BASIC_INFO; + pinfo0.basic_info.in.file.path = fname; + pinfo1 = pinfo0; + pinfo2 = pinfo0; + pinfo3 = pinfo0; + pinfo4 = pinfo0; + pinfo5 = pinfo0; + + /* get the initial times */ + GET_INFO_BOTH(finfo0,pinfo0); + + /* sleep a bit */ + msleep(5000); + + /* do a write */ + torture_comment(tctx, "Do a write on the file handle\n"); + written = smbcli_write(cli->tree, fnum1, 0, "x", 0, 1); + if (written != 1) { + torture_result(tctx, TORTURE_FAIL, __location__": written gave %d - should have been 1", (int)written); + ret = false; + goto done; + } + + GET_INFO_BOTH(finfo1,pinfo1); + COMPARE_WRITE_TIME_EQUAL(finfo1,finfo0); + + /* + * make sure the write time is updated 2 seconds later + * calcuated from the first write + * (but expect upto 3 seconds extra time for a busy server) + */ + t = time(NULL); + while (time(NULL) < t+5) { + /* get the times after the first write */ + GET_INFO_FILE(finfo1); + + if (finfo1.basic_info.out.write_time > finfo0.basic_info.out.write_time) { + int diff = time(NULL) - t; + if (diff < 2) { + torture_comment(tctx, "Server updated write_time after %d seconds (wrong!)\n", + diff); + ret = false; + break; + } + + torture_comment(tctx, "Server updated write_time after %d seconds (correct)\n", + diff); + break; + } + msleep(500); + } + + GET_INFO_BOTH(finfo1,pinfo1); + + /* sure any further write doesn't update the write time */ + t = time(NULL); + while (time(NULL) < t+15) { + /* do a write */ + torture_comment(tctx, "Do a write on the file handle\n"); + written = smbcli_write(cli->tree, fnum1, 0, "x", 0, 1); + if (written != 1) { + torture_result(tctx, TORTURE_FAIL, __location__": written gave %d - should have been 1", (int)written); + ret = false; + goto done; + } + /* get the times after the write */ + GET_INFO_BOTH(finfo2,pinfo2); + + if (finfo2.basic_info.out.write_time > finfo1.basic_info.out.write_time) { + torture_comment(tctx, "Server updated write_time after %d seconds (wrong!)\n", + (int)(time(NULL) - t)); + ret = false; + break; + } + msleep(2000); + } + + GET_INFO_BOTH(finfo2,pinfo2); + COMPARE_WRITE_TIME_EQUAL(finfo2, finfo1); + if (finfo2.basic_info.out.write_time == finfo1.basic_info.out.write_time) { + torture_comment(tctx, "Server did not updatewrite_time (correct)\n"); + } + + /* sleep */ + msleep(5000); + + GET_INFO_BOTH(finfo3,pinfo3); + COMPARE_WRITE_TIME_EQUAL(finfo3, finfo2); + + /* + * the close updates the write time to the time of the close + * and not to the time of the last write! + */ + torture_comment(tctx, "Close the file handle\n"); + smbcli_close(cli->tree, fnum1); + fnum1 = -1; + + GET_INFO_PATH(pinfo4); + COMPARE_WRITE_TIME_GREATER(pinfo4, pinfo3); + + if (pinfo4.basic_info.out.write_time > pinfo3.basic_info.out.write_time) { + torture_comment(tctx, "Server updated the write_time on close (correct)\n"); + } + + done: + if (fnum1 != -1) + smbcli_close(cli->tree, fnum1); + smbcli_unlink(cli->tree, fname); + smbcli_deltree(cli->tree, BASEDIR); + + return ret; +} + +static bool test_delayed_write_update5(struct torture_context *tctx, + struct smbcli_state *cli, + struct smbcli_state *cli2) +{ + union smb_fileinfo finfo0, finfo1, finfo2, finfo3, finfo4, finfo5; + union smb_fileinfo pinfo0, pinfo1, pinfo2, pinfo3, pinfo4, pinfo5, pinfo6; + const char *fname = BASEDIR "\\torture_file.txt"; + int fnum1 = -1; + bool ret = true; + ssize_t written; + time_t t; + + if (!torture_setup_dir(cli, BASEDIR)) { + return false; + } + + torture_comment(tctx, "Open the file handle\n"); + fnum1 = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE); + if (fnum1 == -1) { + ret = false; + torture_result(tctx, TORTURE_FAIL, __location__": unable to open %s", fname); + goto done; + } + + finfo0.basic_info.level = RAW_FILEINFO_BASIC_INFO; + finfo0.basic_info.in.file.fnum = fnum1; + finfo1 = finfo0; + finfo2 = finfo0; + finfo3 = finfo0; + finfo4 = finfo0; + finfo5 = finfo0; + pinfo0.basic_info.level = RAW_FILEINFO_BASIC_INFO; + pinfo0.basic_info.in.file.path = fname; + pinfo1 = pinfo0; + pinfo2 = pinfo0; + pinfo3 = pinfo0; + pinfo4 = pinfo0; + pinfo5 = pinfo0; + pinfo6 = pinfo0; + + /* get the initial times */ + GET_INFO_BOTH(finfo0,pinfo0); + + /* do a write */ + torture_comment(tctx, "Do a write on the file handle\n"); + written = smbcli_write(cli->tree, fnum1, 0, "x", 0, 1); + if (written != 1) { + torture_result(tctx, TORTURE_FAIL, __location__": written gave %d - should have been 1", (int)written); + ret = false; + goto done; + } + + GET_INFO_BOTH(finfo1,pinfo1); + COMPARE_WRITE_TIME_EQUAL(finfo1, finfo0); + + torture_comment(tctx, "Set write time in the future on the file handle\n"); + SET_INFO_FILE(finfo0, time(NULL) + 86400); + GET_INFO_BOTH(finfo2,pinfo2); + COMPARE_WRITE_TIME_GREATER(finfo2, finfo1); + + torture_comment(tctx, "Set write time in the past on the file handle\n"); + SET_INFO_FILE(finfo0, time(NULL) - 86400); + GET_INFO_BOTH(finfo2,pinfo2); + COMPARE_WRITE_TIME_LESS(finfo2, finfo1); + + /* make sure the 2 second delay from the first write are canceled */ + t = time(NULL); + while (time(NULL) < t+15) { + + /* get the times after the first write */ + GET_INFO_BOTH(finfo3,pinfo3); + + if (finfo3.basic_info.out.write_time > finfo2.basic_info.out.write_time) { + torture_comment(tctx, "Server updated write_time after %d seconds (wrong!)\n", + (int)(time(NULL) - t)); + ret = false; + break; + } + msleep(2000); + } + + GET_INFO_BOTH(finfo3,pinfo3); + COMPARE_WRITE_TIME_EQUAL(finfo3, finfo2); + if (finfo3.basic_info.out.write_time == finfo3.basic_info.out.write_time) { + torture_comment(tctx, "Server did not update write_time (correct)\n"); + } + + /* sure any further write doesn't update the write time */ + t = time(NULL); + while (time(NULL) < t+15) { + /* do a write */ + torture_comment(tctx, "Do a write on the file handle\n"); + written = smbcli_write(cli->tree, fnum1, 0, "x", 0, 1); + if (written != 1) { + torture_result(tctx, TORTURE_FAIL, __location__": written gave %d - should have been 1", (int)written); + ret = false; + goto done; + } + /* get the times after the write */ + GET_INFO_BOTH(finfo4,pinfo4); + + if (finfo4.basic_info.out.write_time > finfo3.basic_info.out.write_time) { + torture_comment(tctx, "Server updated write_time after %d seconds (wrong!)\n", + (int)(time(NULL) - t)); + ret = false; + break; + } + msleep(2000); + } + + GET_INFO_BOTH(finfo4,pinfo4); + COMPARE_WRITE_TIME_EQUAL(finfo4, finfo3); + if (finfo4.basic_info.out.write_time == finfo3.basic_info.out.write_time) { + torture_comment(tctx, "Server did not update write_time (correct)\n"); + } + + /* sleep */ + msleep(5000); + + GET_INFO_BOTH(finfo5,pinfo5); + COMPARE_WRITE_TIME_EQUAL(finfo5, finfo4); + + /* + * the close doesn't update the write time + */ + torture_comment(tctx, "Close the file handle\n"); + smbcli_close(cli->tree, fnum1); + fnum1 = -1; + + GET_INFO_PATH(pinfo6); + COMPARE_WRITE_TIME_EQUAL(pinfo6, pinfo5); + + if (pinfo6.basic_info.out.write_time == pinfo5.basic_info.out.write_time) { + torture_comment(tctx, "Server did not update the write_time on close (correct)\n"); + } + + done: + if (fnum1 != -1) + smbcli_close(cli->tree, fnum1); + smbcli_unlink(cli->tree, fname); + smbcli_deltree(cli->tree, BASEDIR); + + return ret; +} + +static bool test_delayed_write_update6(struct torture_context *tctx, + struct smbcli_state *cli, + struct smbcli_state *cli2) +{ + union smb_fileinfo finfo0, finfo1, finfo2, finfo3, finfo4, finfo5; + union smb_fileinfo pinfo0, pinfo1, pinfo2, pinfo3, pinfo4, pinfo5, pinfo6, pinfo7; + const char *fname = BASEDIR "\\torture_file.txt"; + int fnum1 = -1; + int fnum2 = -1; + bool ret = true; + ssize_t written; + time_t t; + bool first = true; + + if (!torture_setup_dir(cli, BASEDIR)) { + return false; + } +again: + torture_comment(tctx, "Open the file handle\n"); + fnum1 = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE); + if (fnum1 == -1) { + ret = false; + torture_result(tctx, TORTURE_FAIL, __location__": unable to open %s", fname); + goto done; + } + + if (fnum2 == -1) { + torture_comment(tctx, "Open the 2nd file handle on 2nd connection\n"); + fnum2 = smbcli_open(cli2->tree, fname, O_RDWR|O_CREAT, DENY_NONE); + if (fnum2 == -1) { + ret = false; + torture_result(tctx, TORTURE_FAIL, __location__": unable to open %s", fname); + goto done; + } + } + + finfo0.basic_info.level = RAW_FILEINFO_BASIC_INFO; + finfo0.basic_info.in.file.fnum = fnum1; + finfo1 = finfo0; + finfo2 = finfo0; + finfo3 = finfo0; + finfo4 = finfo0; + finfo5 = finfo0; + pinfo0.basic_info.level = RAW_FILEINFO_BASIC_INFO; + pinfo0.basic_info.in.file.path = fname; + pinfo1 = pinfo0; + pinfo2 = pinfo0; + pinfo3 = pinfo0; + pinfo4 = pinfo0; + pinfo5 = pinfo0; + pinfo6 = pinfo0; + pinfo7 = pinfo0; + + /* get the initial times */ + GET_INFO_BOTH(finfo0,pinfo0); + + /* do a write */ + torture_comment(tctx, "Do a write on the file handle\n"); + written = smbcli_write(cli->tree, fnum1, 0, "x", 0, 1); + if (written != 1) { + torture_result(tctx, TORTURE_FAIL, __location__": written gave %d - should have been 1", (int)written); + ret = false; + goto done; + } + + GET_INFO_BOTH(finfo1,pinfo1); + COMPARE_WRITE_TIME_EQUAL(finfo1, finfo0); + + torture_comment(tctx, "Set write time in the future on the 2nd file handle\n"); + SET_INFO_FILE_EX(finfo0, time(NULL) + 86400, cli2->tree, fnum2); + GET_INFO_BOTH(finfo2,pinfo2); + COMPARE_WRITE_TIME_GREATER(finfo2, finfo1); + + torture_comment(tctx, "Set write time in the past on the 2nd file handle\n"); + SET_INFO_FILE_EX(finfo0, time(NULL) - 86400, cli2->tree, fnum2); + GET_INFO_BOTH(finfo2,pinfo2); + COMPARE_WRITE_TIME_LESS(finfo2, finfo1); + + /* make sure the 2 second delay from the first write are canceled */ + t = time(NULL); + while (time(NULL) < t+15) { + + /* get the times after the first write */ + GET_INFO_BOTH(finfo3,pinfo3); + + if (finfo3.basic_info.out.write_time > finfo2.basic_info.out.write_time) { + torture_comment(tctx, "Server updated write_time after %d seconds (wrong!)\n", + (int)(time(NULL) - t)); + ret = false; + break; + } + msleep(2000); + } + + GET_INFO_BOTH(finfo3,pinfo3); + COMPARE_WRITE_TIME_EQUAL(finfo3, finfo2); + if (finfo3.basic_info.out.write_time == finfo3.basic_info.out.write_time) { + torture_comment(tctx, "Server did not update write_time (correct)\n"); + } + + /* sure any further write doesn't update the write time */ + t = time(NULL); + while (time(NULL) < t+15) { + /* do a write */ + torture_comment(tctx, "Do a write on the file handle\n"); + written = smbcli_write(cli->tree, fnum1, 0, "x", 0, 1); + if (written != 1) { + torture_result(tctx, TORTURE_FAIL, __location__": written gave %d - should have been 1", (int)written); + ret = false; + goto done; + } + /* get the times after the write */ + GET_INFO_BOTH(finfo4,pinfo4); + + if (finfo4.basic_info.out.write_time > finfo3.basic_info.out.write_time) { + torture_comment(tctx, "Server updated write_time after %d seconds (wrong!)\n", + (int)(time(NULL) - t)); + ret = false; + break; + } + msleep(2000); + } + + GET_INFO_BOTH(finfo4,pinfo4); + COMPARE_WRITE_TIME_EQUAL(finfo4, finfo3); + if (finfo4.basic_info.out.write_time == finfo3.basic_info.out.write_time) { + torture_comment(tctx, "Server did not update write_time (correct)\n"); + } + + /* sleep */ + msleep(5000); + + GET_INFO_BOTH(finfo5,pinfo5); + COMPARE_WRITE_TIME_EQUAL(finfo5, finfo4); + + /* + * the close updates the write time to the time of the close + * as the write time was set on the 2nd handle + */ + torture_comment(tctx, "Close the file handle\n"); + smbcli_close(cli->tree, fnum1); + fnum1 = -1; + + GET_INFO_PATH(pinfo6); + COMPARE_WRITE_TIME_GREATER(pinfo6, pinfo5); + + if (pinfo6.basic_info.out.write_time > pinfo5.basic_info.out.write_time) { + torture_comment(tctx, "Server updated the write_time on close (correct)\n"); + } + + /* keep the 2nd handle open and rerun tests */ + if (first) { + first = false; + goto again; + } + + /* + * closing the 2nd handle will cause no write time update + * as the write time was explicit set on this handle + */ + torture_comment(tctx, "Close the 2nd file handle\n"); + smbcli_close(cli2->tree, fnum2); + fnum2 = -1; + + GET_INFO_PATH(pinfo7); + COMPARE_WRITE_TIME_EQUAL(pinfo7, pinfo6); + + if (pinfo7.basic_info.out.write_time == pinfo6.basic_info.out.write_time) { + torture_comment(tctx, "Server did not update the write_time on close (correct)\n"); + } + + done: + if (fnum1 != -1) + smbcli_close(cli->tree, fnum1); + if (fnum2 != -1) + smbcli_close(cli2->tree, fnum2); + smbcli_unlink(cli->tree, fname); + smbcli_deltree(cli->tree, BASEDIR); + + return ret; +} + /* testing of delayed update of write_time @@ -622,6 +1297,10 @@ struct torture_suite *torture_delay_write(void) torture_suite_add_2smb_test(suite, "finfo update on close", test_finfo_after_write); torture_suite_add_1smb_test(suite, "delayed update of write time", test_delayed_write_update); torture_suite_add_2smb_test(suite, "delayed update of write time using 2 connections", test_delayed_write_update2); + torture_suite_add_2smb_test(suite, "delayed update of write time 3", test_delayed_write_update3); + torture_suite_add_2smb_test(suite, "delayed update of write time 4", test_delayed_write_update4); + torture_suite_add_2smb_test(suite, "delayed update of write time 5", test_delayed_write_update5); + torture_suite_add_2smb_test(suite, "delayed update of write time 6", test_delayed_write_update6); return suite; } -- cgit From 8036dbcf7fbd19bd5f8ad3fd2d29010442e43f29 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Thu, 6 Dec 2007 13:17:34 +0100 Subject: r26306: BASE-DELAYWRITE: print access time stamps and test fileinfo and pathinfo match metze (This used to be commit 58bc21a3f849ef7200733450dbd68f15658ff8f6) --- source4/torture/basic/delaywrite.c | 39 +++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) (limited to 'source4/torture/basic/delaywrite.c') diff --git a/source4/torture/basic/delaywrite.c b/source4/torture/basic/delaywrite.c index 9043e499a8..94e322c800 100644 --- a/source4/torture/basic/delaywrite.c +++ b/source4/torture/basic/delaywrite.c @@ -629,6 +629,37 @@ static bool test_finfo_after_write(struct torture_context *tctx, struct smbcli_s #define COMPARE_WRITE_TIME_LESS(given,correct) \ COMPARE_WRITE_TIME_CMP(given,correct,>=) +#define COMPARE_ACCESS_TIME_CMP(given, correct, cmp) do { \ + NTTIME g = (given).basic_info.out.access_time; \ + NTTIME c = (correct).basic_info.out.access_time; \ + if (g cmp c) { \ + torture_result(tctx, TORTURE_FAIL, __location__": wrong access_time (%s)%s %s (%s)%s", \ + #given, nt_time_string(tctx, g), \ + #cmp, #correct, nt_time_string(tctx, c)); \ + ret = false; \ + goto done; \ + } \ +} while (0) +#define COMPARE_ACCESS_TIME_EQUAL(given,correct) \ + COMPARE_ACCESS_TIME_CMP(given,correct,!=) +#define COMPARE_ACCESS_TIME_GREATER(given,correct) \ + COMPARE_ACCESS_TIME_CMP(given,correct,<=) +#define COMPARE_ACCESS_TIME_LESS(given,correct) \ + COMPARE_ACCESS_TIME_CMP(given,correct,>=) + +#define COMPARE_BOTH_TIMES_EQUAL(given,correct) do { \ + COMPARE_ACCESS_TIME_EQUAL(given,correct); \ + COMPARE_WRITE_TIME_EQUAL(given,correct); \ +} while (0) +#define COMPARE_BOTH_TIMES_GEATER(given,correct) do { \ + COMPARE_ACCESS_TIME_GREATER(given,correct); \ + COMPARE_WRITE_TIME_GREATER(given,correct); \ +} while (0) +#define COMPARE_BOTH_TIMES_LESS(given,correct) do { \ + COMPARE_ACCESS_TIME_LESS(given,correct); \ + COMPARE_WRITE_TIME_LESS(given,correct); \ +} while (0) + #define GET_INFO_FILE(finfo) do { \ NTSTATUS _status; \ _status = smb_raw_fileinfo(cli->tree, tctx, &finfo); \ @@ -638,7 +669,8 @@ static bool test_finfo_after_write(struct torture_context *tctx, struct smbcli_s nt_errstr(_status)); \ goto done; \ } \ - torture_comment(tctx, "fileinfo: Write time (%s)\n", \ + torture_comment(tctx, "fileinfo: Access(%s) Write(%s)\n", \ + nt_time_string(tctx, finfo.basic_info.out.access_time), \ nt_time_string(tctx, finfo.basic_info.out.write_time)); \ } while (0) #define GET_INFO_PATH(pinfo) do { \ @@ -650,13 +682,14 @@ static bool test_finfo_after_write(struct torture_context *tctx, struct smbcli_s ret = false; \ goto done; \ } \ - torture_comment(tctx, "pathinfo: Write time (%s)\n", \ + torture_comment(tctx, "pathinfo: Access(%s) Write(%s)\n", \ + nt_time_string(tctx, pinfo.basic_info.out.access_time), \ nt_time_string(tctx, pinfo.basic_info.out.write_time)); \ } while (0) #define GET_INFO_BOTH(finfo,pinfo) do { \ GET_INFO_FILE(finfo); \ GET_INFO_PATH(pinfo); \ - COMPARE_WRITE_TIME_EQUAL(finfo,pinfo); \ + COMPARE_BOTH_TIMES_EQUAL(finfo,pinfo); \ } while (0) #define SET_INFO_FILE_EX(finfo, wrtime, tree, tfnum) do { \ -- cgit From 1fbe268ec9a4d7367befd21e88f53781cd82cf1a Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Thu, 6 Dec 2007 15:06:36 +0100 Subject: r26307: BASE-DELAYWRITE: only set the write time metze (This used to be commit b7d7a58b2399627c37d8b79e6282a44d50f8c68e) --- source4/torture/basic/delaywrite.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source4/torture/basic/delaywrite.c') diff --git a/source4/torture/basic/delaywrite.c b/source4/torture/basic/delaywrite.c index 94e322c800..8644c656eb 100644 --- a/source4/torture/basic/delaywrite.c +++ b/source4/torture/basic/delaywrite.c @@ -697,10 +697,10 @@ static bool test_finfo_after_write(struct torture_context *tctx, struct smbcli_s union smb_setfileinfo sfinfo; \ sfinfo.basic_info.level = RAW_SFILEINFO_BASIC_INFO; \ sfinfo.basic_info.in.file.fnum = tfnum; \ - sfinfo.basic_info.in.create_time = (finfo).basic_info.out.create_time; \ - sfinfo.basic_info.in.access_time = (finfo).basic_info.out.access_time; \ + sfinfo.basic_info.in.create_time = 0; \ + sfinfo.basic_info.in.access_time = 0; \ unix_to_nt_time(&sfinfo.basic_info.in.write_time, (wrtime)); \ - sfinfo.basic_info.in.change_time = finfo1.basic_info.out.change_time; \ + sfinfo.basic_info.in.change_time = 0; \ sfinfo.basic_info.in.attrib = finfo1.basic_info.out.attrib; \ _status = smb_raw_setfileinfo(tree, &sfinfo); \ if (!NT_STATUS_IS_OK(_status)) { \ -- cgit From afe3e8172ddaa5e4aa811faceecda4f943d6e2ef Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 2 Apr 2008 04:53:27 +0200 Subject: Install public header files again and include required prototypes. (This used to be commit 47ffbbf67435904754469544390b67d34c958343) --- source4/torture/basic/delaywrite.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source4/torture/basic/delaywrite.c') diff --git a/source4/torture/basic/delaywrite.c b/source4/torture/basic/delaywrite.c index 8644c656eb..e3d63c09ec 100644 --- a/source4/torture/basic/delaywrite.c +++ b/source4/torture/basic/delaywrite.c @@ -24,6 +24,7 @@ #include "includes.h" #include "torture/torture.h" #include "libcli/raw/libcliraw.h" +#include "libcli/raw/raw_proto.h" #include "system/time.h" #include "system/filesys.h" #include "libcli/libcli.h" -- cgit From edb3a83a069d39e123f18de098cfaab6deb16729 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Tue, 8 Apr 2008 10:25:51 +0200 Subject: BASE-DELAYWRITE: use timeval_* and make it possible to spefic the writetime update delay metze (This used to be commit 751ab2992afd13548af6e67a03d3ced566cb136f) --- source4/torture/basic/delaywrite.c | 265 +++++++++++++++++++++++-------------- 1 file changed, 164 insertions(+), 101 deletions(-) (limited to 'source4/torture/basic/delaywrite.c') diff --git a/source4/torture/basic/delaywrite.c b/source4/torture/basic/delaywrite.c index e3d63c09ec..bc1cdbca96 100644 --- a/source4/torture/basic/delaywrite.c +++ b/source4/torture/basic/delaywrite.c @@ -40,7 +40,12 @@ static bool test_delayed_write_update(struct torture_context *tctx, struct smbcl int fnum1 = -1; bool ret = true; ssize_t written; - time_t t; + struct timeval start; + struct timeval end; + int used_delay = torture_setting_int(tctx, "writetimeupdatedelay", 2000000); + int normal_delay = 2000000; + double sec = ((double)used_delay) / ((double)normal_delay); + int msec = 1000 * sec; if (!torture_setup_dir(cli, BASEDIR)) { return false; @@ -68,7 +73,7 @@ static bool test_delayed_write_update(struct torture_context *tctx, struct smbcl /* 3 second delay to ensure we get past any 2 second time granularity (older systems may have that) */ - sleep(3); + msleep(3 * msec); written = smbcli_write(cli->tree, fnum1, 0, "x", 0, 1); @@ -78,9 +83,9 @@ static bool test_delayed_write_update(struct torture_context *tctx, struct smbcl return false; } - t = time(NULL); - - while (time(NULL) < t+120) { + start = timeval_current(); + end = timeval_add(&start, (120*sec), 0); + while (!timeval_expired(&end)) { status = smb_raw_fileinfo(cli->tree, tctx, &finfo2); if (!NT_STATUS_IS_OK(status)) { @@ -91,20 +96,22 @@ static bool test_delayed_write_update(struct torture_context *tctx, struct smbcl torture_comment(tctx, "write time %s\n", nt_time_string(tctx, finfo2.basic_info.out.write_time)); if (finfo1.basic_info.out.write_time != finfo2.basic_info.out.write_time) { - int diff = time(NULL) - t; - if (diff < 2) { - torture_comment(tctx, "Server updated write_time after %d seconds (wrong!)\n", - diff); + double diff = timeval_elapsed(&start); + if (diff < (2 * sec * 0.75)) { /* 0.75 to cope with vmware timing */ + torture_comment(tctx, "Server updated write_time after %.2f seconds" + "(1 sec == %.2f)(wrong!)\n", + diff, sec); ret = false; break; } - torture_comment(tctx, "Server updated write_time after %d seconds (correct)\n", - diff); + torture_comment(tctx, "Server updated write_time after %.2f seconds" + "(1 sec == %.2f)(correct)\n", + diff, sec); break; } - sleep(1); fflush(stdout); + msleep(1 * msec); } if (finfo1.basic_info.out.write_time == finfo2.basic_info.out.write_time) { @@ -135,7 +142,12 @@ static bool test_delayed_write_update2(struct torture_context *tctx, struct smbc int fnum2 = -1; bool ret = true; ssize_t written; - time_t t; + struct timeval start; + struct timeval end; + int used_delay = torture_setting_int(tctx, "writetimeupdatedelay", 2000000); + int normal_delay = 2000000; + double sec = ((double)used_delay) / ((double)normal_delay); + int msec = 1000 * sec; union smb_flush flsh; if (!torture_setup_dir(cli, BASEDIR)) { @@ -164,7 +176,7 @@ static bool test_delayed_write_update2(struct torture_context *tctx, struct smbc /* 3 second delay to ensure we get past any 2 second time granularity (older systems may have that) */ - sleep(3); + msleep(3 * msec); { /* Try using setfileinfo instead of write to update write time. */ @@ -251,12 +263,11 @@ static bool test_delayed_write_update2(struct torture_context *tctx, struct smbc return false; } - t = time(NULL); - /* Once the time was set using setfileinfo then it stays set - writes don't have any effect. But make sure. */ - - while (time(NULL) < t+15) { + start = timeval_current(); + end = timeval_add(&start, (15*sec), 0); + while (!timeval_expired(&end)) { status = smb_raw_fileinfo(cli->tree, tctx, &finfo2); if (!NT_STATUS_IS_OK(status)) { @@ -267,13 +278,15 @@ static bool test_delayed_write_update2(struct torture_context *tctx, struct smbc torture_comment(tctx, "write time %s\n", nt_time_string(tctx, finfo2.basic_info.out.write_time)); if (finfo1.basic_info.out.write_time != finfo2.basic_info.out.write_time) { - torture_comment(tctx, "Server updated write_time after %d seconds (wrong!)\n", - (int)(time(NULL) - t)); + double diff = timeval_elapsed(&start); + torture_comment(tctx, "Server updated write_time after %.2f seconds" + "(1sec == %.2f) (wrong!)\n", + diff, sec); ret = false; break; } - sleep(1); fflush(stdout); + msleep(1 * msec); } if (finfo1.basic_info.out.write_time == finfo2.basic_info.out.write_time) { @@ -339,12 +352,11 @@ static bool test_delayed_write_update2(struct torture_context *tctx, struct smbc ret = false; } - t = time(NULL); - /* Once the time was set using setfileinfo then it stays set - writes don't have any effect. But make sure. */ - - while (time(NULL) < t+15) { + start = timeval_current(); + end = timeval_add(&start, (15*sec), 0); + while (!timeval_expired(&end)) { status = smb_raw_fileinfo(cli->tree, tctx, &finfo2); if (!NT_STATUS_IS_OK(status)) { @@ -355,13 +367,15 @@ static bool test_delayed_write_update2(struct torture_context *tctx, struct smbc torture_comment(tctx, "write time %s\n", nt_time_string(tctx, finfo2.basic_info.out.write_time)); if (finfo1.basic_info.out.write_time != finfo2.basic_info.out.write_time) { - torture_comment(tctx, "Server updated write_time after %d seconds (wrong!)\n", - (int)(time(NULL) - t)); + double diff = timeval_elapsed(&start); + torture_comment(tctx, "Server updated write_time after %.2f seconds " + "(1sec == %.2f) (wrong!)\n", + diff, sec); ret = false; break; } - sleep(1); fflush(stdout); + msleep(1 * msec); } if (finfo1.basic_info.out.write_time == finfo2.basic_info.out.write_time) { @@ -393,7 +407,7 @@ static bool test_delayed_write_update2(struct torture_context *tctx, struct smbc torture_comment(tctx, "Second open initial write time %s\n", nt_time_string(tctx, finfo1.basic_info.out.write_time)); - sleep(10); + msleep(10 * msec); torture_comment(tctx, "Doing a 10 byte write to extend the file to see if this changes the last write time.\n"); written = smbcli_write(cli->tree, fnum1, 0, "0123456789", 31, 10); @@ -420,11 +434,10 @@ static bool test_delayed_write_update2(struct torture_context *tctx, struct smbc ret = false; } - t = time(NULL); - /* Now the write time should be updated again */ - - while (time(NULL) < t+15) { + start = timeval_current(); + end = timeval_add(&start, (15*sec), 0); + while (!timeval_expired(&end)) { status = smb_raw_fileinfo(cli->tree, tctx, &finfo2); if (!NT_STATUS_IS_OK(status)) { @@ -435,20 +448,22 @@ static bool test_delayed_write_update2(struct torture_context *tctx, struct smbc torture_comment(tctx, "write time %s\n", nt_time_string(tctx, finfo2.basic_info.out.write_time)); if (finfo1.basic_info.out.write_time != finfo2.basic_info.out.write_time) { - int diff = time(NULL) - t; - if (diff < 2) { - torture_comment(tctx, "Server updated write_time after %d seconds (wrong!)\n", - diff); + double diff = timeval_elapsed(&start); + if (diff < (2 * sec * 0.75)) { /* 0.75 to cope with vmware timing */ + torture_comment(tctx, "Server updated write_time after %.2f seconds" + "(1sec == %.2f) (wrong!)\n", + diff, sec); ret = false; break; } - torture_comment(tctx, "Server updated write_time after %d seconds (correct)\n", - diff); + torture_comment(tctx, "Server updated write_time after %.2f seconds" + "(1sec == %.2f) (correct)\n", + diff, sec); break; } - sleep(1); fflush(stdout); + msleep(1*msec); } if (finfo1.basic_info.out.write_time == finfo2.basic_info.out.write_time) { @@ -490,6 +505,10 @@ static bool test_finfo_after_write(struct torture_context *tctx, struct smbcli_s int fnum2; bool ret = true; ssize_t written; + int used_delay = torture_setting_int(tctx, "writetimeupdatedelay", 2000000); + int normal_delay = 2000000; + double sec = ((double)used_delay) / ((double)normal_delay); + int msec = 1000 * sec; if (!torture_setup_dir(cli, BASEDIR)) { return false; @@ -513,7 +532,7 @@ static bool test_finfo_after_write(struct torture_context *tctx, struct smbcli_s goto done; } - msleep(1000); + msleep(1 * msec); written = smbcli_write(cli->tree, fnum1, 0, "x", 0, 1); @@ -616,9 +635,9 @@ static bool test_finfo_after_write(struct torture_context *tctx, struct smbcli_s NTTIME g = (given).basic_info.out.write_time; \ NTTIME c = (correct).basic_info.out.write_time; \ if (g cmp c) { \ - torture_result(tctx, TORTURE_FAIL, __location__": wrong write_time (%s)%s %s (%s)%s", \ - #given, nt_time_string(tctx, g), \ - #cmp, #correct, nt_time_string(tctx, c)); \ + torture_result(tctx, TORTURE_FAIL, __location__": wrong write_time (%s)%s(%llu) %s (%s)%s(%llu)", \ + #given, nt_time_string(tctx, g), (unsigned long long)g, \ + #cmp, #correct, nt_time_string(tctx, c), (unsigned long long)c); \ ret = false; \ goto done; \ } \ @@ -724,7 +743,12 @@ static bool test_delayed_write_update3(struct torture_context *tctx, int fnum1 = -1; bool ret = true; ssize_t written; - time_t t; + struct timeval start; + struct timeval end; + int used_delay = torture_setting_int(tctx, "writetimeupdatedelay", 2000000); + int normal_delay = 2000000; + double sec = ((double)used_delay) / ((double)normal_delay); + int msec = 1000 * sec; if (!torture_setup_dir(cli, BASEDIR)) { return false; @@ -760,8 +784,9 @@ static bool test_delayed_write_update3(struct torture_context *tctx, * calcuated from the first write * (but expect upto 5 seconds extra time for a busy server) */ - t = time(NULL); - while (time(NULL) < t+7) { + start = timeval_current(); + end = timeval_add(&start, 7 * sec, 0); + while (!timeval_expired(&end)) { /* do a write */ torture_comment(tctx, "Do a write on the file handle\n"); written = smbcli_write(cli->tree, fnum1, 0, "x", 0, 1); @@ -774,26 +799,29 @@ static bool test_delayed_write_update3(struct torture_context *tctx, GET_INFO_FILE(finfo1); if (finfo1.basic_info.out.write_time > finfo0.basic_info.out.write_time) { - int diff = time(NULL) - t; - if (diff < 2) { - torture_comment(tctx, "Server updated write_time after %d seconds (wrong!)\n", - diff); + double diff = timeval_elapsed(&start); + if (diff < (2 * sec * 0.75)) { /* 0.75 to cope with vmware timing */ + torture_comment(tctx, "Server updated write_time after %.2f seconds " + "(1sec == %.2f) (wrong!)\n", + diff, sec); ret = false; break; } - torture_comment(tctx, "Server updated write_time after %d seconds (correct)\n", - diff); + torture_comment(tctx, "Server updated write_time after %.2f seconds " + "(1sec == %.2f) (correct)\n", + diff, sec); break; } - msleep(500); + msleep(0.5 * msec); } GET_INFO_BOTH(finfo1,pinfo1); /* sure any further write doesn't update the write time */ - t = time(NULL); - while (time(NULL) < t+15) { + start = timeval_current(); + end = timeval_add(&start, 15 * sec, 0); + while (!timeval_expired(&end)) { /* do a write */ torture_comment(tctx, "Do a write on the file handle\n"); written = smbcli_write(cli->tree, fnum1, 0, "x", 0, 1); @@ -806,12 +834,14 @@ static bool test_delayed_write_update3(struct torture_context *tctx, GET_INFO_BOTH(finfo2,pinfo2); if (finfo2.basic_info.out.write_time > finfo1.basic_info.out.write_time) { - torture_comment(tctx, "Server updated write_time after %d seconds (wrong!)\n", - (int)(time(NULL) - t)); + double diff = timeval_elapsed(&start); + torture_comment(tctx, "Server updated write_time after %.2f seconds " + "(1sec == %.2f) (wrong!)\n", + diff, sec); ret = false; break; } - msleep(2000); + msleep(2 * msec); } GET_INFO_BOTH(finfo2,pinfo2); @@ -821,7 +851,7 @@ static bool test_delayed_write_update3(struct torture_context *tctx, } /* sleep */ - msleep(5000); + msleep(5 * msec); GET_INFO_BOTH(finfo3,pinfo3); COMPARE_WRITE_TIME_EQUAL(finfo3, finfo2); @@ -860,7 +890,12 @@ static bool test_delayed_write_update4(struct torture_context *tctx, int fnum1 = -1; bool ret = true; ssize_t written; - time_t t; + struct timeval start; + struct timeval end; + int used_delay = torture_setting_int(tctx, "writetimeupdatedelay", 2000000); + int normal_delay = 2000000; + double sec = ((double)used_delay) / ((double)normal_delay); + int msec = 1000 * sec; if (!torture_setup_dir(cli, BASEDIR)) { return false; @@ -892,7 +927,7 @@ static bool test_delayed_write_update4(struct torture_context *tctx, GET_INFO_BOTH(finfo0,pinfo0); /* sleep a bit */ - msleep(5000); + msleep(5 * msec); /* do a write */ torture_comment(tctx, "Do a write on the file handle\n"); @@ -911,32 +946,36 @@ static bool test_delayed_write_update4(struct torture_context *tctx, * calcuated from the first write * (but expect upto 3 seconds extra time for a busy server) */ - t = time(NULL); - while (time(NULL) < t+5) { + start = timeval_current(); + end = timeval_add(&start, 5 * sec, 0); + while (!timeval_expired(&end)) { /* get the times after the first write */ GET_INFO_FILE(finfo1); if (finfo1.basic_info.out.write_time > finfo0.basic_info.out.write_time) { - int diff = time(NULL) - t; - if (diff < 2) { - torture_comment(tctx, "Server updated write_time after %d seconds (wrong!)\n", - diff); + double diff = timeval_elapsed(&start); + if (diff < (2 * sec * 0.75)) { /* 0.75 to cope with vmware timing */ + torture_comment(tctx, "Server updated write_time after %.2f seconds " + "(1sec == %.2f) (wrong!)\n", + diff, sec); ret = false; break; } - torture_comment(tctx, "Server updated write_time after %d seconds (correct)\n", - diff); + torture_comment(tctx, "Server updated write_time after %.2f seconds " + "(1sec == %.2f) (correct)\n", + diff, sec); break; } - msleep(500); + msleep(0.5 * msec); } GET_INFO_BOTH(finfo1,pinfo1); /* sure any further write doesn't update the write time */ - t = time(NULL); - while (time(NULL) < t+15) { + start = timeval_current(); + end = timeval_add(&start, 15 * sec, 0); + while (!timeval_expired(&end)) { /* do a write */ torture_comment(tctx, "Do a write on the file handle\n"); written = smbcli_write(cli->tree, fnum1, 0, "x", 0, 1); @@ -949,12 +988,14 @@ static bool test_delayed_write_update4(struct torture_context *tctx, GET_INFO_BOTH(finfo2,pinfo2); if (finfo2.basic_info.out.write_time > finfo1.basic_info.out.write_time) { - torture_comment(tctx, "Server updated write_time after %d seconds (wrong!)\n", - (int)(time(NULL) - t)); + double diff = timeval_elapsed(&start); + torture_comment(tctx, "Server updated write_time after %.2f seconds " + "(1sec == %.2f) (wrong!)\n", + diff, sec); ret = false; break; } - msleep(2000); + msleep(2 * msec); } GET_INFO_BOTH(finfo2,pinfo2); @@ -964,7 +1005,7 @@ static bool test_delayed_write_update4(struct torture_context *tctx, } /* sleep */ - msleep(5000); + msleep(5 * msec); GET_INFO_BOTH(finfo3,pinfo3); COMPARE_WRITE_TIME_EQUAL(finfo3, finfo2); @@ -1003,7 +1044,12 @@ static bool test_delayed_write_update5(struct torture_context *tctx, int fnum1 = -1; bool ret = true; ssize_t written; - time_t t; + struct timeval start; + struct timeval end; + int used_delay = torture_setting_int(tctx, "writetimeupdatedelay", 2000000); + int normal_delay = 2000000; + double sec = ((double)used_delay) / ((double)normal_delay); + int msec = 1000 * sec; if (!torture_setup_dir(cli, BASEDIR)) { return false; @@ -1059,19 +1105,22 @@ static bool test_delayed_write_update5(struct torture_context *tctx, COMPARE_WRITE_TIME_LESS(finfo2, finfo1); /* make sure the 2 second delay from the first write are canceled */ - t = time(NULL); - while (time(NULL) < t+15) { + start = timeval_current(); + end = timeval_add(&start, 15 * sec, 0); + while (!timeval_expired(&end)) { /* get the times after the first write */ GET_INFO_BOTH(finfo3,pinfo3); if (finfo3.basic_info.out.write_time > finfo2.basic_info.out.write_time) { - torture_comment(tctx, "Server updated write_time after %d seconds (wrong!)\n", - (int)(time(NULL) - t)); + double diff = timeval_elapsed(&start); + torture_comment(tctx, "Server updated write_time after %.2f seconds " + "(1sec == %.2f) (wrong!)\n", + diff, sec); ret = false; break; } - msleep(2000); + msleep(2 * msec); } GET_INFO_BOTH(finfo3,pinfo3); @@ -1081,8 +1130,9 @@ static bool test_delayed_write_update5(struct torture_context *tctx, } /* sure any further write doesn't update the write time */ - t = time(NULL); - while (time(NULL) < t+15) { + start = timeval_current(); + end = timeval_add(&start, 15 * sec, 0); + while (!timeval_expired(&end)) { /* do a write */ torture_comment(tctx, "Do a write on the file handle\n"); written = smbcli_write(cli->tree, fnum1, 0, "x", 0, 1); @@ -1095,12 +1145,14 @@ static bool test_delayed_write_update5(struct torture_context *tctx, GET_INFO_BOTH(finfo4,pinfo4); if (finfo4.basic_info.out.write_time > finfo3.basic_info.out.write_time) { - torture_comment(tctx, "Server updated write_time after %d seconds (wrong!)\n", - (int)(time(NULL) - t)); + double diff = timeval_elapsed(&start); + torture_comment(tctx, "Server updated write_time after %.2f seconds " + "(1sec == %.2f) (wrong!)\n", + diff, sec); ret = false; break; } - msleep(2000); + msleep(2 * msec); } GET_INFO_BOTH(finfo4,pinfo4); @@ -1110,7 +1162,7 @@ static bool test_delayed_write_update5(struct torture_context *tctx, } /* sleep */ - msleep(5000); + msleep(5 * msec); GET_INFO_BOTH(finfo5,pinfo5); COMPARE_WRITE_TIME_EQUAL(finfo5, finfo4); @@ -1149,7 +1201,12 @@ static bool test_delayed_write_update6(struct torture_context *tctx, int fnum2 = -1; bool ret = true; ssize_t written; - time_t t; + struct timeval start; + struct timeval end; + int used_delay = torture_setting_int(tctx, "writetimeupdatedelay", 2000000); + int normal_delay = 2000000; + double sec = ((double)used_delay) / ((double)normal_delay); + int msec = 1000 * sec; bool first = true; if (!torture_setup_dir(cli, BASEDIR)) { @@ -1217,19 +1274,22 @@ again: COMPARE_WRITE_TIME_LESS(finfo2, finfo1); /* make sure the 2 second delay from the first write are canceled */ - t = time(NULL); - while (time(NULL) < t+15) { + start = timeval_current(); + end = timeval_add(&start, 15 * sec, 0); + while (!timeval_expired(&end)) { /* get the times after the first write */ GET_INFO_BOTH(finfo3,pinfo3); if (finfo3.basic_info.out.write_time > finfo2.basic_info.out.write_time) { - torture_comment(tctx, "Server updated write_time after %d seconds (wrong!)\n", - (int)(time(NULL) - t)); + double diff = timeval_elapsed(&start); + torture_comment(tctx, "Server updated write_time after %.2f seconds " + "(1sec == %.2f) (wrong!)\n", + diff, sec); ret = false; break; } - msleep(2000); + msleep(2 * msec); } GET_INFO_BOTH(finfo3,pinfo3); @@ -1239,8 +1299,9 @@ again: } /* sure any further write doesn't update the write time */ - t = time(NULL); - while (time(NULL) < t+15) { + start = timeval_current(); + end = timeval_add(&start, 15 * sec, 0); + while (!timeval_expired(&end)) { /* do a write */ torture_comment(tctx, "Do a write on the file handle\n"); written = smbcli_write(cli->tree, fnum1, 0, "x", 0, 1); @@ -1253,12 +1314,14 @@ again: GET_INFO_BOTH(finfo4,pinfo4); if (finfo4.basic_info.out.write_time > finfo3.basic_info.out.write_time) { - torture_comment(tctx, "Server updated write_time after %d seconds (wrong!)\n", - (int)(time(NULL) - t)); + double diff = timeval_elapsed(&start); + torture_comment(tctx, "Server updated write_time after %.2f seconds " + "(1sec == %.2f) (wrong!)\n", + diff, sec); ret = false; break; } - msleep(2000); + msleep(2 * msec); } GET_INFO_BOTH(finfo4,pinfo4); @@ -1268,7 +1331,7 @@ again: } /* sleep */ - msleep(5000); + msleep(5 * msec); GET_INFO_BOTH(finfo5,pinfo5); COMPARE_WRITE_TIME_EQUAL(finfo5, finfo4); -- cgit From 4677ac6e70769bcc7f0c8bacdf000cdeb8c8089f Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Tue, 8 Apr 2008 19:04:44 +0200 Subject: BASE-DELAYWRITE: be more friendly to filesystems without high resolution timestamps metze (This used to be commit 9c18cf670889c9eb8c12b505c3b9ce5f9a516839) --- source4/torture/basic/delaywrite.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'source4/torture/basic/delaywrite.c') diff --git a/source4/torture/basic/delaywrite.c b/source4/torture/basic/delaywrite.c index bc1cdbca96..84adfef61a 100644 --- a/source4/torture/basic/delaywrite.c +++ b/source4/torture/basic/delaywrite.c @@ -632,9 +632,20 @@ static bool test_finfo_after_write(struct torture_context *tctx, struct smbcli_s } #define COMPARE_WRITE_TIME_CMP(given, correct, cmp) do { \ + uint64_t r = 10*1000*1000; \ NTTIME g = (given).basic_info.out.write_time; \ + NTTIME gr = (g / r) * r; \ NTTIME c = (correct).basic_info.out.write_time; \ - if (g cmp c) { \ + NTTIME cr = (c / r) * r; \ + bool strict = torture_setting_bool(tctx, "strict mode", false); \ + bool err = false; \ + if (strict && (g cmp c)) { \ + err = true; \ + } else if (gr cmp cr) { \ + /* handle filesystem without high resolution timestamps */ \ + err = true; \ + } \ + if (err) { \ torture_result(tctx, TORTURE_FAIL, __location__": wrong write_time (%s)%s(%llu) %s (%s)%s(%llu)", \ #given, nt_time_string(tctx, g), (unsigned long long)g, \ #cmp, #correct, nt_time_string(tctx, c), (unsigned long long)c); \ -- cgit From e7b30f023bd8b1003f5283ffc1bf1d2edb6fb281 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 2 Jun 2008 11:04:36 +1000 Subject: remove unused macros (This used to be commit 7a1877db15e6a57f0f057dcf5da6609b9bdeef51) --- source4/torture/basic/delaywrite.c | 12 ------------ 1 file changed, 12 deletions(-) (limited to 'source4/torture/basic/delaywrite.c') diff --git a/source4/torture/basic/delaywrite.c b/source4/torture/basic/delaywrite.c index 84adfef61a..ac4f565a2b 100644 --- a/source4/torture/basic/delaywrite.c +++ b/source4/torture/basic/delaywrite.c @@ -673,23 +673,11 @@ static bool test_finfo_after_write(struct torture_context *tctx, struct smbcli_s } while (0) #define COMPARE_ACCESS_TIME_EQUAL(given,correct) \ COMPARE_ACCESS_TIME_CMP(given,correct,!=) -#define COMPARE_ACCESS_TIME_GREATER(given,correct) \ - COMPARE_ACCESS_TIME_CMP(given,correct,<=) -#define COMPARE_ACCESS_TIME_LESS(given,correct) \ - COMPARE_ACCESS_TIME_CMP(given,correct,>=) #define COMPARE_BOTH_TIMES_EQUAL(given,correct) do { \ COMPARE_ACCESS_TIME_EQUAL(given,correct); \ COMPARE_WRITE_TIME_EQUAL(given,correct); \ } while (0) -#define COMPARE_BOTH_TIMES_GEATER(given,correct) do { \ - COMPARE_ACCESS_TIME_GREATER(given,correct); \ - COMPARE_WRITE_TIME_GREATER(given,correct); \ -} while (0) -#define COMPARE_BOTH_TIMES_LESS(given,correct) do { \ - COMPARE_ACCESS_TIME_LESS(given,correct); \ - COMPARE_WRITE_TIME_LESS(given,correct); \ -} while (0) #define GET_INFO_FILE(finfo) do { \ NTSTATUS _status; \ -- cgit From fb4c9dd5ebed4af38b3e2f6022770a7586e39926 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Mon, 5 May 2008 15:05:41 +0200 Subject: BASE-DELAYWRITE: add missing time checks to make sure the server has updated the write time metze (This used to be commit 9c004df8910c07d75bb3f75d7c3cfba9f9c94f51) --- source4/torture/basic/delaywrite.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source4/torture/basic/delaywrite.c') diff --git a/source4/torture/basic/delaywrite.c b/source4/torture/basic/delaywrite.c index 84adfef61a..0e226b788d 100644 --- a/source4/torture/basic/delaywrite.c +++ b/source4/torture/basic/delaywrite.c @@ -828,6 +828,7 @@ static bool test_delayed_write_update3(struct torture_context *tctx, } GET_INFO_BOTH(finfo1,pinfo1); + COMPARE_WRITE_TIME_GREATER(pinfo1, pinfo0); /* sure any further write doesn't update the write time */ start = timeval_current(); @@ -982,6 +983,7 @@ static bool test_delayed_write_update4(struct torture_context *tctx, } GET_INFO_BOTH(finfo1,pinfo1); + COMPARE_WRITE_TIME_GREATER(pinfo1, pinfo0); /* sure any further write doesn't update the write time */ start = timeval_current(); -- cgit From 6610a6c49a2140747aa8e36c26f855953471140d Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Tue, 3 Jun 2008 14:01:02 +0200 Subject: BASE-DELAYWRITE: fix test on filesystem without high resolution timestamps metze (This used to be commit fde9880f9943897549859037b0fc9341d3a032f7) --- source4/torture/basic/delaywrite.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/torture/basic/delaywrite.c') diff --git a/source4/torture/basic/delaywrite.c b/source4/torture/basic/delaywrite.c index 0e226b788d..c7bccae08f 100644 --- a/source4/torture/basic/delaywrite.c +++ b/source4/torture/basic/delaywrite.c @@ -641,7 +641,7 @@ static bool test_finfo_after_write(struct torture_context *tctx, struct smbcli_s bool err = false; \ if (strict && (g cmp c)) { \ err = true; \ - } else if (gr cmp cr) { \ + } else if ((g cmp c) && (gr cmp cr)) { \ /* handle filesystem without high resolution timestamps */ \ err = true; \ } \ -- cgit From 0d0fddf8ae856efd7ffb07ba8fa32d2f55d3f9c0 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 5 Sep 2008 14:24:36 -0700 Subject: Added tests that show that write time update is immediate when changing file size using SMBwrite of size zero, SET_END_OF_FILE, or SET_ALLOCATION_SIZE - no 2 second delay in these cases. Jeremy. (This used to be commit 3aa7523d7750fe30d1e6bb5a75ac42b681b9e493) --- source4/torture/basic/delaywrite.c | 348 ++++++++++++++++++++++++++++++++++++- 1 file changed, 347 insertions(+), 1 deletion(-) (limited to 'source4/torture/basic/delaywrite.c') diff --git a/source4/torture/basic/delaywrite.c b/source4/torture/basic/delaywrite.c index c03e89d36e..6dfe410386 100644 --- a/source4/torture/basic/delaywrite.c +++ b/source4/torture/basic/delaywrite.c @@ -128,7 +128,350 @@ static bool test_delayed_write_update(struct torture_context *tctx, struct smbcl return ret; } -/* +/* Updating with a SMBwrite of zero length + * changes the write time immediately - even on expand. */ + +static bool test_delayed_write_update1a(struct torture_context *tctx, struct smbcli_state *cli) +{ + union smb_fileinfo finfo1, finfo2; + const char *fname = BASEDIR "\\torture_file1a.txt"; + NTSTATUS status; + int fnum1 = -1; + bool ret = true; + ssize_t written; + struct timeval start; + struct timeval end; + int used_delay = torture_setting_int(tctx, "writetimeupdatedelay", 2000000); + int normal_delay = 2000000; + double sec = ((double)used_delay) / ((double)normal_delay); + int msec = 1000 * sec; + char buf[2048]; + + if (!torture_setup_dir(cli, BASEDIR)) { + return false; + } + + fnum1 = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE); + if (fnum1 == -1) { + torture_comment(tctx, "Failed to open %s\n", fname); + return false; + } + + memset(buf, 'x', 2048); + written = smbcli_write(cli->tree, fnum1, 0, buf, 0, 2048); + + /* 3 second delay to ensure we get past any 2 second time + granularity (older systems may have that) */ + msleep(3 * msec); + + finfo1.all_info.level = RAW_FILEINFO_ALL_INFO; + finfo1.all_info.in.file.fnum = fnum1; + finfo2 = finfo1; + + status = smb_raw_fileinfo(cli->tree, tctx, &finfo1); + + if (!NT_STATUS_IS_OK(status)) { + DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status))); + return false; + } + + torture_comment(tctx, "Initial write time %s\n", + nt_time_string(tctx, finfo1.all_info.out.write_time)); + + /* Do a zero length SMBwrite call to truncate. */ + written = smbcli_smbwrite(cli->tree, fnum1, "x", 10240, 0); + + if (written != 0) { + torture_comment(tctx, "write failed - wrote %d bytes (%s)\n", + (int)written, __location__); + return false; + } + + start = timeval_current(); + end = timeval_add(&start, (120*sec), 0); + while (!timeval_expired(&end)) { + status = smb_raw_fileinfo(cli->tree, tctx, &finfo2); + + if (!NT_STATUS_IS_OK(status)) { + DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status))); + ret = false; + break; + } + + if (finfo2.all_info.out.size != 10240) { + DEBUG(0, ("file not truncated\n")); + ret = false; + break; + } + + torture_comment(tctx, "write time %s\n", + nt_time_string(tctx, finfo2.all_info.out.write_time)); + if (finfo1.all_info.out.write_time != finfo2.all_info.out.write_time) { + double diff = timeval_elapsed(&start); + if (diff > (0.25 * sec * 0.75)) { /* 0.75 to cope with vmware timing */ + torture_comment(tctx, "After SMBwrite truncate " + "server updated write_time after %.2f seconds" + "(1 sec == %.2f)(wrong!)\n", + diff, sec); + ret = false; + break; + } + + torture_comment(tctx, "After SMBwrite truncate " + "server updated write_time after %.2f seconds" + "(1 sec == %.2f)(correct)\n", + diff, sec); + break; + } + fflush(stdout); + msleep(1 * msec); + } + + if (finfo1.all_info.out.write_time == finfo2.all_info.out.write_time) { + torture_comment(tctx, "Server did not update write time (wrong!)\n"); + ret = false; + } + + + if (fnum1 != -1) + smbcli_close(cli->tree, fnum1); + smbcli_unlink(cli->tree, fname); + smbcli_deltree(cli->tree, BASEDIR); + + return ret; +} + +/* Updating with a SET_FILE_END_OF_FILE_INFO + * changes the write time immediately - even on expand. */ + +static bool test_delayed_write_update1b(struct torture_context *tctx, struct smbcli_state *cli) +{ + union smb_fileinfo finfo1, finfo2; + const char *fname = BASEDIR "\\torture_file1b.txt"; + NTSTATUS status; + int fnum1 = -1; + bool ret = true; + ssize_t written; + struct timeval start; + struct timeval end; + int used_delay = torture_setting_int(tctx, "writetimeupdatedelay", 2000000); + int normal_delay = 2000000; + double sec = ((double)used_delay) / ((double)normal_delay); + int msec = 1000 * sec; + char buf[2048]; + + if (!torture_setup_dir(cli, BASEDIR)) { + return false; + } + + fnum1 = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE); + if (fnum1 == -1) { + torture_comment(tctx, "Failed to open %s\n", fname); + return false; + } + + memset(buf, 'x', 2048); + written = smbcli_write(cli->tree, fnum1, 0, buf, 0, 2048); + + /* 3 second delay to ensure we get past any 2 second time + granularity (older systems may have that) */ + msleep(3 * msec); + + finfo1.all_info.level = RAW_FILEINFO_ALL_INFO; + finfo1.all_info.in.file.fnum = fnum1; + finfo2 = finfo1; + + status = smb_raw_fileinfo(cli->tree, tctx, &finfo1); + + if (!NT_STATUS_IS_OK(status)) { + DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status))); + return false; + } + + torture_comment(tctx, "Initial write time %s\n", + nt_time_string(tctx, finfo1.all_info.out.write_time)); + + /* Do a SET_END_OF_FILE_INFO call to truncate. */ + status = smbcli_ftruncate(cli->tree, fnum1, (uint64_t)10240); + + if (!NT_STATUS_IS_OK(status)) { + torture_comment(tctx, "SET_END_OF_FILE failed (%s)\n", + nt_errstr(status)); + return false; + } + + start = timeval_current(); + end = timeval_add(&start, (120*sec), 0); + while (!timeval_expired(&end)) { + status = smb_raw_fileinfo(cli->tree, tctx, &finfo2); + + if (!NT_STATUS_IS_OK(status)) { + DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status))); + ret = false; + break; + } + + if (finfo2.all_info.out.size != 10240) { + DEBUG(0, ("file not truncated\n")); + ret = false; + break; + } + + torture_comment(tctx, "write time %s\n", + nt_time_string(tctx, finfo2.all_info.out.write_time)); + if (finfo1.all_info.out.write_time != finfo2.all_info.out.write_time) { + double diff = timeval_elapsed(&start); + if (diff > (0.25 * sec * 0.75)) { /* 0.75 to cope with vmware timing */ + torture_comment(tctx, "After SET_END_OF_FILE truncate " + "server updated write_time after %.2f seconds" + "(1 sec == %.2f)(wrong!)\n", + diff, sec); + ret = false; + break; + } + + torture_comment(tctx, "After SET_END_OF_FILE truncate " + "server updated write_time after %.2f seconds" + "(1 sec == %.2f)(correct)\n", + diff, sec); + break; + } + fflush(stdout); + msleep(1 * msec); + } + + if (finfo1.all_info.out.write_time == finfo2.all_info.out.write_time) { + torture_comment(tctx, "Server did not update write time (wrong!)\n"); + ret = false; + } + + + if (fnum1 != -1) + smbcli_close(cli->tree, fnum1); + smbcli_unlink(cli->tree, fname); + smbcli_deltree(cli->tree, BASEDIR); + + return ret; +} + +/* Updating with a SET_ALLOCATION_INFO (truncate) does so immediately. */ + +static bool test_delayed_write_update1c(struct torture_context *tctx, struct smbcli_state *cli) +{ + union smb_setfileinfo parms; + union smb_fileinfo finfo1, finfo2; + const char *fname = BASEDIR "\\torture_file1c.txt"; + NTSTATUS status; + int fnum1 = -1; + bool ret = true; + ssize_t written; + struct timeval start; + struct timeval end; + int used_delay = torture_setting_int(tctx, "writetimeupdatedelay", 2000000); + int normal_delay = 2000000; + double sec = ((double)used_delay) / ((double)normal_delay); + int msec = 1000 * sec; + char buf[2048]; + + if (!torture_setup_dir(cli, BASEDIR)) { + return false; + } + + fnum1 = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE); + if (fnum1 == -1) { + torture_comment(tctx, "Failed to open %s\n", fname); + return false; + } + + memset(buf, 'x', 2048); + written = smbcli_write(cli->tree, fnum1, 0, buf, 0, 2048); + + /* 3 second delay to ensure we get past any 2 second time + granularity (older systems may have that) */ + msleep(3 * msec); + + finfo1.all_info.level = RAW_FILEINFO_ALL_INFO; + finfo1.all_info.in.file.fnum = fnum1; + finfo2 = finfo1; + + status = smb_raw_fileinfo(cli->tree, tctx, &finfo1); + + if (!NT_STATUS_IS_OK(status)) { + DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status))); + return false; + } + + torture_comment(tctx, "Initial write time %s\n", + nt_time_string(tctx, finfo1.all_info.out.write_time)); + + /* Do a SET_ALLOCATION_SIZE call to truncate. */ + parms.allocation_info.level = RAW_SFILEINFO_ALLOCATION_INFO; + parms.allocation_info.in.file.fnum = fnum1; + parms.allocation_info.in.alloc_size = 0; + + status = smb_raw_setfileinfo(cli->tree, &parms); + + if (!NT_STATUS_IS_OK(status)) { + torture_comment(tctx, "RAW_SFILEINFO_ALLOCATION_INFO failed (%s)\n", + nt_errstr(status)); + return false; + } + + start = timeval_current(); + end = timeval_add(&start, (120*sec), 0); + while (!timeval_expired(&end)) { + status = smb_raw_fileinfo(cli->tree, tctx, &finfo2); + + if (!NT_STATUS_IS_OK(status)) { + DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status))); + ret = false; + break; + } + + if (finfo2.all_info.out.size != 0) { + DEBUG(0, ("file not truncated\n")); + ret = false; + break; + } + + torture_comment(tctx, "write time %s\n", + nt_time_string(tctx, finfo2.all_info.out.write_time)); + if (finfo1.all_info.out.write_time != finfo2.all_info.out.write_time) { + double diff = timeval_elapsed(&start); + if (diff > (0.25 * sec * 0.75)) { /* 0.75 to cope with vmware timing */ + torture_comment(tctx, "After SET_ALLOCATION_INFO truncate " + "server updated write_time after %.2f seconds" + "(1 sec == %.2f)(wrong!)\n", + diff, sec); + ret = false; + break; + } + + torture_comment(tctx, "After SET_ALLOCATION_INFO truncate " + "server updated write_time after %.2f seconds" + "(1 sec == %.2f)(correct)\n", + diff, sec); + break; + } + fflush(stdout); + msleep(1 * msec); + } + + if (finfo1.all_info.out.write_time == finfo2.all_info.out.write_time) { + torture_comment(tctx, "Server did not update write time (wrong!)\n"); + ret = false; + } + + + if (fnum1 != -1) + smbcli_close(cli->tree, fnum1); + smbcli_unlink(cli->tree, fname); + smbcli_deltree(cli->tree, BASEDIR); + + return ret; +} + +/* * Do as above, but using 2 connections. */ @@ -1394,6 +1737,9 @@ struct torture_suite *torture_delay_write(void) torture_suite_add_2smb_test(suite, "finfo update on close", test_finfo_after_write); torture_suite_add_1smb_test(suite, "delayed update of write time", test_delayed_write_update); + torture_suite_add_1smb_test(suite, "update of write time and SMBread truncate", test_delayed_write_update1a); + torture_suite_add_1smb_test(suite, "update of write time using SET_END_OF_FILE", test_delayed_write_update1b); + torture_suite_add_1smb_test(suite, "update of write time using SET_ALLOCATION_SIZE", test_delayed_write_update1c); torture_suite_add_2smb_test(suite, "delayed update of write time using 2 connections", test_delayed_write_update2); torture_suite_add_2smb_test(suite, "delayed update of write time 3", test_delayed_write_update3); torture_suite_add_2smb_test(suite, "delayed update of write time 4", test_delayed_write_update4); -- cgit From 56b6b4a68f51be8845afd024a45843331c0810ed Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 5 Sep 2008 21:47:06 -0700 Subject: Don't compare identity, it'll never be different. Jeremy. (This used to be commit 840369b5534eee21818b9d3677404b0fc60a0219) --- source4/torture/basic/delaywrite.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/torture/basic/delaywrite.c') diff --git a/source4/torture/basic/delaywrite.c b/source4/torture/basic/delaywrite.c index 6dfe410386..52505fa5d1 100644 --- a/source4/torture/basic/delaywrite.c +++ b/source4/torture/basic/delaywrite.c @@ -1469,7 +1469,7 @@ static bool test_delayed_write_update5(struct torture_context *tctx, GET_INFO_BOTH(finfo3,pinfo3); COMPARE_WRITE_TIME_EQUAL(finfo3, finfo2); - if (finfo3.basic_info.out.write_time == finfo3.basic_info.out.write_time) { + if (finfo3.basic_info.out.write_time == finfo2.basic_info.out.write_time) { torture_comment(tctx, "Server did not update write_time (correct)\n"); } @@ -1638,7 +1638,7 @@ again: GET_INFO_BOTH(finfo3,pinfo3); COMPARE_WRITE_TIME_EQUAL(finfo3, finfo2); - if (finfo3.basic_info.out.write_time == finfo3.basic_info.out.write_time) { + if (finfo3.basic_info.out.write_time == finfo2.basic_info.out.write_time) { torture_comment(tctx, "Server did not update write_time (correct)\n"); } -- cgit From 3ca48b015f1ae30015f8ec61b075052390f054ca Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Mon, 8 Sep 2008 08:31:34 +0200 Subject: BASE-DELAYWRITE: test more details of the truncate write time update behavior metze (This used to be commit 39367ef15fabbb52cd2c05be7ca59b25dc4aff71) --- source4/torture/basic/delaywrite.c | 375 ++++++++++++++++++++++++++++++++++++- 1 file changed, 371 insertions(+), 4 deletions(-) (limited to 'source4/torture/basic/delaywrite.c') diff --git a/source4/torture/basic/delaywrite.c b/source4/torture/basic/delaywrite.c index 52505fa5d1..6e718a11df 100644 --- a/source4/torture/basic/delaywrite.c +++ b/source4/torture/basic/delaywrite.c @@ -128,12 +128,186 @@ static bool test_delayed_write_update(struct torture_context *tctx, struct smbcl return ret; } +static bool test_delayed_write_update1(struct torture_context *tctx, struct smbcli_state *cli) +{ + union smb_fileinfo finfo1, finfo2, finfo3, pinfo4; + const char *fname = BASEDIR "\\torture_file1.txt"; + NTSTATUS status; + int fnum1 = -1; + bool ret = true; + ssize_t written; + struct timeval start; + struct timeval end; + int used_delay = torture_setting_int(tctx, "writetimeupdatedelay", 2000000); + int normal_delay = 2000000; + double sec = ((double)used_delay) / ((double)normal_delay); + int msec = 1000 * sec; + char buf[2048]; + + if (!torture_setup_dir(cli, BASEDIR)) { + return false; + } + + fnum1 = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE); + if (fnum1 == -1) { + torture_comment(tctx, "Failed to open %s\n", fname); + return false; + } + + memset(buf, 'x', 2048); + written = smbcli_write(cli->tree, fnum1, 0, buf, 0, 2048); + + /* 3 second delay to ensure we get past any 2 second time + granularity (older systems may have that) */ + msleep(3 * msec); + + finfo1.all_info.level = RAW_FILEINFO_ALL_INFO; + finfo1.all_info.in.file.fnum = fnum1; + finfo2 = finfo1; + finfo3 = finfo1; + pinfo4.all_info.level = RAW_FILEINFO_ALL_INFO; + pinfo4.all_info.in.file.path = fname; + + status = smb_raw_fileinfo(cli->tree, tctx, &finfo1); + + if (!NT_STATUS_IS_OK(status)) { + DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status))); + return false; + } + + torture_comment(tctx, "Initial write time %s\n", + nt_time_string(tctx, finfo1.all_info.out.write_time)); + + /* Do a zero length SMBwrite call to truncate. */ + written = smbcli_smbwrite(cli->tree, fnum1, "x", 1024, 0); + + if (written != 0) { + torture_comment(tctx, "write failed - wrote %d bytes (%s)\n", + (int)written, __location__); + return false; + } + + start = timeval_current(); + end = timeval_add(&start, (120*sec), 0); + while (!timeval_expired(&end)) { + status = smb_raw_fileinfo(cli->tree, tctx, &finfo2); + + if (!NT_STATUS_IS_OK(status)) { + DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status))); + ret = false; + break; + } + + if (finfo2.all_info.out.size != 1024) { + DEBUG(0, ("file not truncated\n")); + ret = false; + break; + } + + torture_comment(tctx, "write time %s\n", + nt_time_string(tctx, finfo2.all_info.out.write_time)); + if (finfo1.all_info.out.write_time != finfo2.all_info.out.write_time) { + double diff = timeval_elapsed(&start); + if (diff > (0.25 * sec * 0.75)) { /* 0.75 to cope with vmware timing */ + torture_comment(tctx, "After SMBwrite truncate " + "server updated write_time after %.2f seconds" + "(1 sec == %.2f)(wrong!)\n", + diff, sec); + ret = false; + break; + } + + torture_comment(tctx, "After SMBwrite truncate " + "server updated write_time after %.2f seconds" + "(1 sec == %.2f)(correct)\n", + diff, sec); + break; + } + fflush(stdout); + msleep(1 * msec); + } + + if (finfo1.all_info.out.write_time == finfo2.all_info.out.write_time) { + torture_comment(tctx, "Server did not update write time (wrong!)\n"); + ret = false; + } + + /* Do a non-zero length SMBwrite and make sure it doesn't update the write time. */ + written = smbcli_smbwrite(cli->tree, fnum1, "x", 0, 1); + + if (written != 1) { + torture_comment(tctx, "write failed - wrote %d bytes (%s)\n", + (int)written, __location__); + return false; + } + + start = timeval_current(); + end = timeval_add(&start, (10*sec), 0); + while (!timeval_expired(&end)) { + status = smb_raw_fileinfo(cli->tree, tctx, &finfo3); + + if (!NT_STATUS_IS_OK(status)) { + DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status))); + ret = false; + break; + } + + if (finfo3.all_info.out.size != 1024) { + DEBUG(0, ("file not truncated\n")); + ret = false; + break; + } + + torture_comment(tctx, "write time %s\n", + nt_time_string(tctx, finfo3.all_info.out.write_time)); + if (finfo2.all_info.out.write_time != finfo3.all_info.out.write_time) { + double diff = timeval_elapsed(&start); + + torture_comment(tctx, "server updated write_time after %.2f seconds" + "(1 sec == %.2f)(correct)\n", + diff, sec); + break; + } + fflush(stdout); + msleep(1 * msec); + } + + if (finfo2.all_info.out.write_time != finfo3.all_info.out.write_time) { + torture_comment(tctx, "Server updated write time (wrong!)\n"); + ret = false; + } + + /* the close should trigger an write time update */ + smbcli_close(cli->tree, fnum1); + fnum1 = -1; + + status = smb_raw_pathinfo(cli->tree, tctx, &pinfo4); + if (!NT_STATUS_IS_OK(status)) { + DEBUG(0, ("pathinfo failed: %s\n", nt_errstr(status))); + return false; + } + + if (finfo3.all_info.out.write_time == pinfo4.all_info.out.write_time) { + torture_comment(tctx, "Server did not update write time on close (wrong!)\n"); + ret = false; + } else if (finfo3.all_info.out.write_time < pinfo4.all_info.out.write_time) { + torture_comment(tctx, "Server updated write time on close (correct)\n"); + } + + if (fnum1 != -1) + smbcli_close(cli->tree, fnum1); + smbcli_unlink(cli->tree, fname); + smbcli_deltree(cli->tree, BASEDIR); + + return ret; +} + /* Updating with a SMBwrite of zero length * changes the write time immediately - even on expand. */ static bool test_delayed_write_update1a(struct torture_context *tctx, struct smbcli_state *cli) { - union smb_fileinfo finfo1, finfo2; + union smb_fileinfo finfo1, finfo2, finfo3, pinfo4; const char *fname = BASEDIR "\\torture_file1a.txt"; NTSTATUS status; int fnum1 = -1; @@ -167,6 +341,9 @@ static bool test_delayed_write_update1a(struct torture_context *tctx, struct smb finfo1.all_info.level = RAW_FILEINFO_ALL_INFO; finfo1.all_info.in.file.fnum = fnum1; finfo2 = finfo1; + finfo3 = finfo1; + pinfo4.all_info.level = RAW_FILEINFO_ALL_INFO; + pinfo4.all_info.in.file.path = fname; status = smb_raw_fileinfo(cli->tree, tctx, &finfo1); @@ -232,6 +409,67 @@ static bool test_delayed_write_update1a(struct torture_context *tctx, struct smb ret = false; } + /* Do a non-zero length SMBwrite and make sure it doesn't update the write time. */ + written = smbcli_smbwrite(cli->tree, fnum1, "x", 0, 1); + + if (written != 1) { + torture_comment(tctx, "write failed - wrote %d bytes (%s)\n", + (int)written, __location__); + return false; + } + + start = timeval_current(); + end = timeval_add(&start, (10*sec), 0); + while (!timeval_expired(&end)) { + status = smb_raw_fileinfo(cli->tree, tctx, &finfo3); + + if (!NT_STATUS_IS_OK(status)) { + DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status))); + ret = false; + break; + } + + if (finfo3.all_info.out.size != 10240) { + DEBUG(0, ("file not truncated\n")); + ret = false; + break; + } + + torture_comment(tctx, "write time %s\n", + nt_time_string(tctx, finfo3.all_info.out.write_time)); + if (finfo2.all_info.out.write_time != finfo3.all_info.out.write_time) { + double diff = timeval_elapsed(&start); + + torture_comment(tctx, "server updated write_time after %.2f seconds" + "(1 sec == %.2f)(correct)\n", + diff, sec); + break; + } + fflush(stdout); + msleep(1 * msec); + } + + if (finfo2.all_info.out.write_time != finfo3.all_info.out.write_time) { + torture_comment(tctx, "Server updated write time (wrong!)\n"); + ret = false; + } + + /* the close should trigger an write time update */ + smbcli_close(cli->tree, fnum1); + fnum1 = -1; + + status = smb_raw_pathinfo(cli->tree, tctx, &pinfo4); + if (!NT_STATUS_IS_OK(status)) { + DEBUG(0, ("pathinfo failed: %s\n", nt_errstr(status))); + return false; + } + + if (finfo3.all_info.out.write_time == pinfo4.all_info.out.write_time) { + torture_comment(tctx, "Server did not update write time on close (wrong!)\n"); + ret = false; + } else if (finfo3.all_info.out.write_time < pinfo4.all_info.out.write_time) { + torture_comment(tctx, "Server updated write time on close (correct)\n"); + } if (fnum1 != -1) smbcli_close(cli->tree, fnum1); @@ -246,7 +484,7 @@ static bool test_delayed_write_update1a(struct torture_context *tctx, struct smb static bool test_delayed_write_update1b(struct torture_context *tctx, struct smbcli_state *cli) { - union smb_fileinfo finfo1, finfo2; + union smb_fileinfo finfo1, finfo2, finfo3, pinfo4; const char *fname = BASEDIR "\\torture_file1b.txt"; NTSTATUS status; int fnum1 = -1; @@ -280,6 +518,9 @@ static bool test_delayed_write_update1b(struct torture_context *tctx, struct smb finfo1.all_info.level = RAW_FILEINFO_ALL_INFO; finfo1.all_info.in.file.fnum = fnum1; finfo2 = finfo1; + finfo3 = finfo1; + pinfo4.all_info.level = RAW_FILEINFO_ALL_INFO; + pinfo4.all_info.in.file.path = fname; status = smb_raw_fileinfo(cli->tree, tctx, &finfo1); @@ -345,6 +586,67 @@ static bool test_delayed_write_update1b(struct torture_context *tctx, struct smb ret = false; } + /* Do a non-zero length SMBwrite and make sure it doesn't update the write time. */ + written = smbcli_smbwrite(cli->tree, fnum1, "x", 0, 1); + + if (written != 1) { + torture_comment(tctx, "write failed - wrote %d bytes (%s)\n", + (int)written, __location__); + return false; + } + + start = timeval_current(); + end = timeval_add(&start, (10*sec), 0); + while (!timeval_expired(&end)) { + status = smb_raw_fileinfo(cli->tree, tctx, &finfo3); + + if (!NT_STATUS_IS_OK(status)) { + DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status))); + ret = false; + break; + } + + if (finfo3.all_info.out.size != 10240) { + DEBUG(0, ("file not truncated\n")); + ret = false; + break; + } + + torture_comment(tctx, "write time %s\n", + nt_time_string(tctx, finfo3.all_info.out.write_time)); + if (finfo2.all_info.out.write_time != finfo3.all_info.out.write_time) { + double diff = timeval_elapsed(&start); + + torture_comment(tctx, "server updated write_time after %.2f seconds" + "(1 sec == %.2f)(correct)\n", + diff, sec); + break; + } + fflush(stdout); + msleep(1 * msec); + } + + if (finfo2.all_info.out.write_time != finfo3.all_info.out.write_time) { + torture_comment(tctx, "Server updated write time (wrong!)\n"); + ret = false; + } + + /* the close should trigger an write time update */ + smbcli_close(cli->tree, fnum1); + fnum1 = -1; + + status = smb_raw_pathinfo(cli->tree, tctx, &pinfo4); + if (!NT_STATUS_IS_OK(status)) { + DEBUG(0, ("pathinfo failed: %s\n", nt_errstr(status))); + return false; + } + + if (finfo3.all_info.out.write_time == pinfo4.all_info.out.write_time) { + torture_comment(tctx, "Server did not update write time on close (wrong!)\n"); + ret = false; + } else if (finfo3.all_info.out.write_time < pinfo4.all_info.out.write_time) { + torture_comment(tctx, "Server updated write time on close (correct)\n"); + } if (fnum1 != -1) smbcli_close(cli->tree, fnum1); @@ -359,7 +661,7 @@ static bool test_delayed_write_update1b(struct torture_context *tctx, struct smb static bool test_delayed_write_update1c(struct torture_context *tctx, struct smbcli_state *cli) { union smb_setfileinfo parms; - union smb_fileinfo finfo1, finfo2; + union smb_fileinfo finfo1, finfo2, finfo3, pinfo4; const char *fname = BASEDIR "\\torture_file1c.txt"; NTSTATUS status; int fnum1 = -1; @@ -393,6 +695,9 @@ static bool test_delayed_write_update1c(struct torture_context *tctx, struct smb finfo1.all_info.level = RAW_FILEINFO_ALL_INFO; finfo1.all_info.in.file.fnum = fnum1; finfo2 = finfo1; + finfo3 = finfo1; + pinfo4.all_info.level = RAW_FILEINFO_ALL_INFO; + pinfo4.all_info.in.file.path = fname; status = smb_raw_fileinfo(cli->tree, tctx, &finfo1); @@ -462,6 +767,67 @@ static bool test_delayed_write_update1c(struct torture_context *tctx, struct smb ret = false; } + /* Do a non-zero length SMBwrite and make sure it doesn't update the write time. */ + written = smbcli_smbwrite(cli->tree, fnum1, "x", 0, 1); + + if (written != 1) { + torture_comment(tctx, "write failed - wrote %d bytes (%s)\n", + (int)written, __location__); + return false; + } + + start = timeval_current(); + end = timeval_add(&start, (10*sec), 0); + while (!timeval_expired(&end)) { + status = smb_raw_fileinfo(cli->tree, tctx, &finfo3); + + if (!NT_STATUS_IS_OK(status)) { + DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status))); + ret = false; + break; + } + + if (finfo3.all_info.out.size != 1) { + DEBUG(0, ("file not expanded\n")); + ret = false; + break; + } + + torture_comment(tctx, "write time %s\n", + nt_time_string(tctx, finfo3.all_info.out.write_time)); + if (finfo2.all_info.out.write_time != finfo3.all_info.out.write_time) { + double diff = timeval_elapsed(&start); + + torture_comment(tctx, "server updated write_time after %.2f seconds" + "(1 sec == %.2f)(correct)\n", + diff, sec); + break; + } + fflush(stdout); + msleep(1 * msec); + } + + if (finfo2.all_info.out.write_time != finfo3.all_info.out.write_time) { + torture_comment(tctx, "Server updated write time (wrong!)\n"); + ret = false; + } + + /* the close should trigger an write time update */ + smbcli_close(cli->tree, fnum1); + fnum1 = -1; + + status = smb_raw_pathinfo(cli->tree, tctx, &pinfo4); + if (!NT_STATUS_IS_OK(status)) { + DEBUG(0, ("pathinfo failed: %s\n", nt_errstr(status))); + return false; + } + + if (finfo3.all_info.out.write_time == pinfo4.all_info.out.write_time) { + torture_comment(tctx, "Server did not update write time on close (wrong!)\n"); + ret = false; + } else if (finfo3.all_info.out.write_time < pinfo4.all_info.out.write_time) { + torture_comment(tctx, "Server updated write time on close (correct)\n"); + } if (fnum1 != -1) smbcli_close(cli->tree, fnum1); @@ -1737,7 +2103,8 @@ struct torture_suite *torture_delay_write(void) torture_suite_add_2smb_test(suite, "finfo update on close", test_finfo_after_write); torture_suite_add_1smb_test(suite, "delayed update of write time", test_delayed_write_update); - torture_suite_add_1smb_test(suite, "update of write time and SMBread truncate", test_delayed_write_update1a); + torture_suite_add_1smb_test(suite, "update of write time and SMBwrite truncate ", test_delayed_write_update1); + torture_suite_add_1smb_test(suite, "update of write time and SMBwrite truncate expand", test_delayed_write_update1a); torture_suite_add_1smb_test(suite, "update of write time using SET_END_OF_FILE", test_delayed_write_update1b); torture_suite_add_1smb_test(suite, "update of write time using SET_ALLOCATION_SIZE", test_delayed_write_update1c); torture_suite_add_2smb_test(suite, "delayed update of write time using 2 connections", test_delayed_write_update2); -- cgit From a626b011930f5112e01715d653a6ac8655a28333 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Mon, 8 Sep 2008 12:12:25 +0200 Subject: BASE-DELAYWRITE: demonstrate that the time between the open and the first write doesn't matter metze (This used to be commit 13d051cd633f4a4152d360453fe5297ad53cc7b5) --- source4/torture/basic/delaywrite.c | 159 +++++++++++++++++++++++++++++++++++++ 1 file changed, 159 insertions(+) (limited to 'source4/torture/basic/delaywrite.c') diff --git a/source4/torture/basic/delaywrite.c b/source4/torture/basic/delaywrite.c index 6e718a11df..53018f30b5 100644 --- a/source4/torture/basic/delaywrite.c +++ b/source4/torture/basic/delaywrite.c @@ -1589,6 +1589,164 @@ static bool test_delayed_write_update3(struct torture_context *tctx, return ret; } +static bool test_delayed_write_update3b(struct torture_context *tctx, + struct smbcli_state *cli, + struct smbcli_state *cli2) +{ + union smb_fileinfo finfo0, finfo1, finfo2, finfo3, finfo4; + union smb_fileinfo pinfo0, pinfo1, pinfo2, pinfo3, pinfo4, pinfo5; + const char *fname = BASEDIR "\\torture_file.txt"; + int fnum1 = -1; + bool ret = true; + ssize_t written; + struct timeval start; + struct timeval end; + int used_delay = torture_setting_int(tctx, "writetimeupdatedelay", 2000000); + int normal_delay = 2000000; + double sec = ((double)used_delay) / ((double)normal_delay); + int msec = 1000 * sec; + + if (!torture_setup_dir(cli, BASEDIR)) { + return false; + } + + torture_comment(tctx, "Open the file handle\n"); + fnum1 = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE); + if (fnum1 == -1) { + ret = false; + torture_result(tctx, TORTURE_FAIL, __location__": unable to open %s", fname); + goto done; + } + + finfo0.basic_info.level = RAW_FILEINFO_BASIC_INFO; + finfo0.basic_info.in.file.fnum = fnum1; + finfo1 = finfo0; + finfo2 = finfo0; + finfo3 = finfo0; + finfo4 = finfo0; + pinfo0.basic_info.level = RAW_FILEINFO_BASIC_INFO; + pinfo0.basic_info.in.file.path = fname; + pinfo1 = pinfo0; + pinfo2 = pinfo0; + pinfo3 = pinfo0; + pinfo4 = pinfo0; + pinfo5 = pinfo0; + + /* get the initial times */ + GET_INFO_BOTH(finfo0,pinfo0); + + /* + * sleep some time, to demonstrate the handling of write times + * doesn't depend on the time since the open + */ + msleep(5 * msec); + + /* get the initial times */ + GET_INFO_BOTH(finfo1,pinfo1); + COMPARE_WRITE_TIME_EQUAL(finfo1, finfo0); + + /* + * make sure the write time is updated 2 seconds later + * calcuated from the first write + * (but expect upto 5 seconds extra time for a busy server) + */ + start = timeval_current(); + end = timeval_add(&start, 7 * sec, 0); + while (!timeval_expired(&end)) { + /* do a write */ + torture_comment(tctx, "Do a write on the file handle\n"); + written = smbcli_write(cli->tree, fnum1, 0, "x", 0, 1); + if (written != 1) { + torture_result(tctx, TORTURE_FAIL, __location__": written gave %d - should have been 1", (int)written); + ret = false; + goto done; + } + /* get the times after the write */ + GET_INFO_FILE(finfo1); + + if (finfo1.basic_info.out.write_time > finfo0.basic_info.out.write_time) { + double diff = timeval_elapsed(&start); + if (diff < (2 * sec * 0.75)) { /* 0.75 to cope with vmware timing */ + torture_comment(tctx, "Server updated write_time after %.2f seconds " + "(1sec == %.2f) (wrong!)\n", + diff, sec); + ret = false; + break; + } + + torture_comment(tctx, "Server updated write_time after %.2f seconds " + "(1sec == %.2f) (correct)\n", + diff, sec); + break; + } + msleep(0.5 * msec); + } + + GET_INFO_BOTH(finfo1,pinfo1); + COMPARE_WRITE_TIME_GREATER(pinfo1, pinfo0); + + /* sure any further write doesn't update the write time */ + start = timeval_current(); + end = timeval_add(&start, 15 * sec, 0); + while (!timeval_expired(&end)) { + /* do a write */ + torture_comment(tctx, "Do a write on the file handle\n"); + written = smbcli_write(cli->tree, fnum1, 0, "x", 0, 1); + if (written != 1) { + torture_result(tctx, TORTURE_FAIL, __location__": written gave %d - should have been 1", (int)written); + ret = false; + goto done; + } + /* get the times after the write */ + GET_INFO_BOTH(finfo2,pinfo2); + + if (finfo2.basic_info.out.write_time > finfo1.basic_info.out.write_time) { + double diff = timeval_elapsed(&start); + torture_comment(tctx, "Server updated write_time after %.2f seconds " + "(1sec == %.2f) (wrong!)\n", + diff, sec); + ret = false; + break; + } + msleep(2 * msec); + } + + GET_INFO_BOTH(finfo2,pinfo2); + COMPARE_WRITE_TIME_EQUAL(finfo2, finfo1); + if (finfo2.basic_info.out.write_time == finfo1.basic_info.out.write_time) { + torture_comment(tctx, "Server did not update write_time (correct)\n"); + } + + /* sleep */ + msleep(5 * msec); + + GET_INFO_BOTH(finfo3,pinfo3); + COMPARE_WRITE_TIME_EQUAL(finfo3, finfo2); + + /* + * the close updates the write time to the time of the close + * and not to the time of the last write! + */ + torture_comment(tctx, "Close the file handle\n"); + smbcli_close(cli->tree, fnum1); + fnum1 = -1; + + GET_INFO_PATH(pinfo4); + COMPARE_WRITE_TIME_GREATER(pinfo4, pinfo3); + + if (pinfo4.basic_info.out.write_time > pinfo3.basic_info.out.write_time) { + torture_comment(tctx, "Server updated the write_time on close (correct)\n"); + } + + done: + if (fnum1 != -1) + smbcli_close(cli->tree, fnum1); + smbcli_unlink(cli->tree, fname); + smbcli_deltree(cli->tree, BASEDIR); + + return ret; +} + static bool test_delayed_write_update4(struct torture_context *tctx, struct smbcli_state *cli, struct smbcli_state *cli2) @@ -2109,6 +2267,7 @@ struct torture_suite *torture_delay_write(void) torture_suite_add_1smb_test(suite, "update of write time using SET_ALLOCATION_SIZE", test_delayed_write_update1c); torture_suite_add_2smb_test(suite, "delayed update of write time using 2 connections", test_delayed_write_update2); torture_suite_add_2smb_test(suite, "delayed update of write time 3", test_delayed_write_update3); + torture_suite_add_2smb_test(suite, "delayed update of write time 3b", test_delayed_write_update3b); torture_suite_add_2smb_test(suite, "delayed update of write time 4", test_delayed_write_update4); torture_suite_add_2smb_test(suite, "delayed update of write time 5", test_delayed_write_update5); torture_suite_add_2smb_test(suite, "delayed update of write time 6", test_delayed_write_update6); -- cgit From 1cf9d7e078305dd96d564ccb6ecdaa376f438b27 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Mon, 8 Sep 2008 12:27:43 +0200 Subject: BASE-DELAYWRITE: demonstrate that a truncate write doesn't update the write time after SET_FILE_INFO metze (This used to be commit f81014db9d5afbf9e0b1c007bc56fc1d3a201309) --- source4/torture/basic/delaywrite.c | 157 +++++++++++++++++++++++++++++++++++++ 1 file changed, 157 insertions(+) (limited to 'source4/torture/basic/delaywrite.c') diff --git a/source4/torture/basic/delaywrite.c b/source4/torture/basic/delaywrite.c index 53018f30b5..24c9770e12 100644 --- a/source4/torture/basic/delaywrite.c +++ b/source4/torture/basic/delaywrite.c @@ -2058,6 +2058,162 @@ static bool test_delayed_write_update5(struct torture_context *tctx, return ret; } +static bool test_delayed_write_update5b(struct torture_context *tctx, + struct smbcli_state *cli, + struct smbcli_state *cli2) +{ + union smb_fileinfo finfo0, finfo1, finfo2, finfo3, finfo4, finfo5; + union smb_fileinfo pinfo0, pinfo1, pinfo2, pinfo3, pinfo4, pinfo5, pinfo6; + const char *fname = BASEDIR "\\torture_file.txt"; + int fnum1 = -1; + bool ret = true; + ssize_t written; + struct timeval start; + struct timeval end; + int used_delay = torture_setting_int(tctx, "writetimeupdatedelay", 2000000); + int normal_delay = 2000000; + double sec = ((double)used_delay) / ((double)normal_delay); + int msec = 1000 * sec; + + if (!torture_setup_dir(cli, BASEDIR)) { + return false; + } + + torture_comment(tctx, "Open the file handle\n"); + fnum1 = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE); + if (fnum1 == -1) { + ret = false; + torture_result(tctx, TORTURE_FAIL, __location__": unable to open %s", fname); + goto done; + } + + finfo0.basic_info.level = RAW_FILEINFO_BASIC_INFO; + finfo0.basic_info.in.file.fnum = fnum1; + finfo1 = finfo0; + finfo2 = finfo0; + finfo3 = finfo0; + finfo4 = finfo0; + finfo5 = finfo0; + pinfo0.basic_info.level = RAW_FILEINFO_BASIC_INFO; + pinfo0.basic_info.in.file.path = fname; + pinfo1 = pinfo0; + pinfo2 = pinfo0; + pinfo3 = pinfo0; + pinfo4 = pinfo0; + pinfo5 = pinfo0; + pinfo6 = pinfo0; + + /* get the initial times */ + GET_INFO_BOTH(finfo0,pinfo0); + + /* do a write */ + torture_comment(tctx, "Do a write on the file handle\n"); + written = smbcli_write(cli->tree, fnum1, 0, "x", 0, 1); + if (written != 1) { + torture_result(tctx, TORTURE_FAIL, __location__": written gave %d - should have been 1", (int)written); + ret = false; + goto done; + } + + GET_INFO_BOTH(finfo1,pinfo1); + COMPARE_WRITE_TIME_EQUAL(finfo1, finfo0); + + torture_comment(tctx, "Set write time in the future on the file handle\n"); + SET_INFO_FILE(finfo0, time(NULL) + 86400); + GET_INFO_BOTH(finfo2,pinfo2); + COMPARE_WRITE_TIME_GREATER(finfo2, finfo1); + + torture_comment(tctx, "Set write time in the past on the file handle\n"); + SET_INFO_FILE(finfo0, time(NULL) - 86400); + GET_INFO_BOTH(finfo2,pinfo2); + COMPARE_WRITE_TIME_LESS(finfo2, finfo1); + + /* make sure the 2 second delay from the first write are canceled */ + start = timeval_current(); + end = timeval_add(&start, 15 * sec, 0); + while (!timeval_expired(&end)) { + + /* get the times after the first write */ + GET_INFO_BOTH(finfo3,pinfo3); + + if (finfo3.basic_info.out.write_time > finfo2.basic_info.out.write_time) { + double diff = timeval_elapsed(&start); + torture_comment(tctx, "Server updated write_time after %.2f seconds " + "(1sec == %.2f) (wrong!)\n", + diff, sec); + ret = false; + break; + } + msleep(2 * msec); + } + + GET_INFO_BOTH(finfo3,pinfo3); + COMPARE_WRITE_TIME_EQUAL(finfo3, finfo2); + if (finfo3.basic_info.out.write_time == finfo2.basic_info.out.write_time) { + torture_comment(tctx, "Server did not update write_time (correct)\n"); + } + + /* sure any further write (truncates) update the write time */ + start = timeval_current(); + end = timeval_add(&start, 15 * sec, 0); + while (!timeval_expired(&end)) { + /* do a write */ + torture_comment(tctx, "Do a truncate write on the file handle\n"); + written = smbcli_write(cli->tree, fnum1, 0, "x", 0, 0); + if (written != 0) { + torture_result(tctx, TORTURE_FAIL, __location__": written gave %d - should have been 1", (int)written); + ret = false; + goto done; + } + /* get the times after the write */ + GET_INFO_BOTH(finfo4,pinfo4); + + if (finfo4.basic_info.out.write_time > finfo3.basic_info.out.write_time) { + double diff = timeval_elapsed(&start); + torture_comment(tctx, "Server updated write_time after %.2f seconds " + "(1sec == %.2f) (wrong!)\n", + diff, sec); + ret = false; + break; + } + msleep(2 * msec); + } + + GET_INFO_BOTH(finfo4,pinfo4); + COMPARE_WRITE_TIME_EQUAL(finfo4, finfo3); + if (finfo4.basic_info.out.write_time == finfo3.basic_info.out.write_time) { + torture_comment(tctx, "Server did not update write_time (correct)\n"); + } + + /* sleep */ + msleep(5 * msec); + + GET_INFO_BOTH(finfo5,pinfo5); + COMPARE_WRITE_TIME_EQUAL(finfo5, finfo4); + + /* + * the close doesn't update the write time + */ + torture_comment(tctx, "Close the file handle\n"); + smbcli_close(cli->tree, fnum1); + fnum1 = -1; + + GET_INFO_PATH(pinfo6); + COMPARE_WRITE_TIME_EQUAL(pinfo6, pinfo5); + + if (pinfo6.basic_info.out.write_time == pinfo5.basic_info.out.write_time) { + torture_comment(tctx, "Server did not update the write_time on close (correct)\n"); + } + + done: + if (fnum1 != -1) + smbcli_close(cli->tree, fnum1); + smbcli_unlink(cli->tree, fname); + smbcli_deltree(cli->tree, BASEDIR); + + return ret; +} + static bool test_delayed_write_update6(struct torture_context *tctx, struct smbcli_state *cli, struct smbcli_state *cli2) @@ -2270,6 +2426,7 @@ struct torture_suite *torture_delay_write(void) torture_suite_add_2smb_test(suite, "delayed update of write time 3b", test_delayed_write_update3b); torture_suite_add_2smb_test(suite, "delayed update of write time 4", test_delayed_write_update4); torture_suite_add_2smb_test(suite, "delayed update of write time 5", test_delayed_write_update5); + torture_suite_add_2smb_test(suite, "delayed update of write time 5b", test_delayed_write_update5b); torture_suite_add_2smb_test(suite, "delayed update of write time 6", test_delayed_write_update6); return suite; -- cgit From f009e78864436b22fa0bb17b2eae3dbdf3f043b4 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Mon, 8 Sep 2008 13:59:51 +0200 Subject: BASE-DELAYWRITE: test behavior of writeX, SMBwrite truncate, writeX and SMBwrite again metze (This used to be commit 051164ba0a69d54aa706ffa876059e8dbbeacb36) --- source4/torture/basic/delaywrite.c | 206 +++++++++++++++++++++++++++++++++++++ 1 file changed, 206 insertions(+) (limited to 'source4/torture/basic/delaywrite.c') diff --git a/source4/torture/basic/delaywrite.c b/source4/torture/basic/delaywrite.c index 24c9770e12..55aac872a9 100644 --- a/source4/torture/basic/delaywrite.c +++ b/source4/torture/basic/delaywrite.c @@ -1589,6 +1589,211 @@ static bool test_delayed_write_update3(struct torture_context *tctx, return ret; } +static bool test_delayed_write_update3a(struct torture_context *tctx, + struct smbcli_state *cli, + struct smbcli_state *cli2) +{ + union smb_fileinfo finfo0, finfo1, finfo2, finfo3, finfo4; + union smb_fileinfo pinfo0, pinfo1, pinfo2, pinfo3, pinfo4, pinfo5; + const char *fname = BASEDIR "\\torture_file.txt"; + int fnum1 = -1; + bool ret = true; + ssize_t written; + int i; + struct timeval start; + struct timeval end; + int used_delay = torture_setting_int(tctx, "writetimeupdatedelay", 2000000); + int normal_delay = 2000000; + double sec = ((double)used_delay) / ((double)normal_delay); + int msec = 1000 * sec; + + if (!torture_setup_dir(cli, BASEDIR)) { + return false; + } + + torture_comment(tctx, "Open the file handle\n"); + fnum1 = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE); + if (fnum1 == -1) { + ret = false; + torture_result(tctx, TORTURE_FAIL, __location__": unable to open %s", fname); + goto done; + } + + finfo0.basic_info.level = RAW_FILEINFO_BASIC_INFO; + finfo0.basic_info.in.file.fnum = fnum1; + finfo1 = finfo0; + finfo2 = finfo0; + finfo3 = finfo0; + finfo4 = finfo0; + pinfo0.basic_info.level = RAW_FILEINFO_BASIC_INFO; + pinfo0.basic_info.in.file.path = fname; + pinfo1 = pinfo0; + pinfo2 = pinfo0; + pinfo3 = pinfo0; + pinfo4 = pinfo0; + pinfo5 = pinfo0; + + /* get the initial times */ + GET_INFO_BOTH(finfo0,pinfo0); + + /* + * sleep some time, to demonstrate the handling of write times + * doesn't depend on the time since the open + */ + msleep(5 * msec); + + /* get the initial times */ + GET_INFO_BOTH(finfo1,pinfo1); + COMPARE_WRITE_TIME_EQUAL(finfo1, finfo0); + + /* + * make sure the write time is updated 2 seconds later + * calcuated from the first write + * (but expect upto 5 seconds extra time for a busy server) + */ + start = timeval_current(); + end = timeval_add(&start, 7 * sec, 0); + while (!timeval_expired(&end)) { + /* do a write */ + torture_comment(tctx, "Do a write on the file handle\n"); + written = smbcli_write(cli->tree, fnum1, 0, "x", 0, 1); + if (written != 1) { + torture_result(tctx, TORTURE_FAIL, __location__": written gave %d - should have been 1", (int)written); + ret = false; + goto done; + } + /* get the times after the write */ + GET_INFO_FILE(finfo1); + + if (finfo1.basic_info.out.write_time > finfo0.basic_info.out.write_time) { + double diff = timeval_elapsed(&start); + if (diff < (2 * sec * 0.75)) { /* 0.75 to cope with vmware timing */ + torture_comment(tctx, "Server updated write_time after %.2f seconds " + "(1sec == %.2f) (wrong!)\n", + diff, sec); + ret = false; + break; + } + + torture_comment(tctx, "Server updated write_time after %.2f seconds " + "(1sec == %.2f) (correct)\n", + diff, sec); + break; + } + msleep(0.5 * msec); + } + + GET_INFO_BOTH(finfo1,pinfo1); + COMPARE_WRITE_TIME_GREATER(pinfo1, pinfo0); + + /* + * demonstrate that a truncate write always + * updates the write time immediately + */ + for (i=0; i < 3; i++) { + msleep(1 * msec); + /* do a write */ + torture_comment(tctx, "Do a truncate SMBwrite [%d] on the file handle\n", i); + written = smbcli_smbwrite(cli->tree, fnum1, "x", 10240, 0); + if (written != 0) { + torture_result(tctx, TORTURE_FAIL, __location__": written gave %d - should have been 0", (int)written); + ret = false; + goto done; + } + /* get the times after the write */ + GET_INFO_BOTH(finfo2,pinfo2); + COMPARE_WRITE_TIME_GREATER(finfo2, finfo1); + finfo1 = finfo2; + } + + /* sure any further write doesn't update the write time */ + start = timeval_current(); + end = timeval_add(&start, 15 * sec, 0); + while (!timeval_expired(&end)) { + /* do a write */ + torture_comment(tctx, "Do a write on the file handle\n"); + written = smbcli_write(cli->tree, fnum1, 0, "x", 0, 1); + if (written != 1) { + torture_result(tctx, TORTURE_FAIL, __location__": written gave %d - should have been 1", (int)written); + ret = false; + goto done; + } + /* get the times after the write */ + GET_INFO_BOTH(finfo2,pinfo2); + + if (finfo2.basic_info.out.write_time > finfo1.basic_info.out.write_time) { + double diff = timeval_elapsed(&start); + torture_comment(tctx, "Server updated write_time after %.2f seconds " + "(1sec == %.2f) (wrong!)\n", + diff, sec); + ret = false; + break; + } + msleep(2 * msec); + } + + GET_INFO_BOTH(finfo2,pinfo2); + COMPARE_WRITE_TIME_EQUAL(finfo2, finfo1); + if (finfo2.basic_info.out.write_time == finfo1.basic_info.out.write_time) { + torture_comment(tctx, "Server did not update write_time (correct)\n"); + } + + /* sleep */ + msleep(5 * msec); + + /* get the initial times */ + GET_INFO_BOTH(finfo1,pinfo1); + COMPARE_WRITE_TIME_EQUAL(finfo1, finfo2); + + /* + * demonstrate that a truncate write always + * updates the write time immediately + */ + for (i=0; i < 3; i++) { + msleep(1 * msec); + /* do a write */ + torture_comment(tctx, "Do a truncate SMBwrite [%d] on the file handle\n", i); + written = smbcli_smbwrite(cli->tree, fnum1, "x", 512, 0); + if (written != 0) { + torture_result(tctx, TORTURE_FAIL, __location__": written gave %d - should have been 0", (int)written); + ret = false; + goto done; + } + /* get the times after the write */ + GET_INFO_BOTH(finfo2,pinfo2); + COMPARE_WRITE_TIME_GREATER(finfo2, finfo1); + finfo1 = finfo2; + } + + /* sleep */ + msleep(5 * msec); + + GET_INFO_BOTH(finfo3,pinfo3); + COMPARE_WRITE_TIME_EQUAL(finfo3, finfo2); + + /* + * the close doesn't update the write time + */ + torture_comment(tctx, "Close the file handle\n"); + smbcli_close(cli->tree, fnum1); + fnum1 = -1; + + GET_INFO_PATH(pinfo4); + COMPARE_WRITE_TIME_EQUAL(pinfo4, pinfo3); + + if (pinfo4.basic_info.out.write_time == pinfo3.basic_info.out.write_time) { + torture_comment(tctx, "Server did not update the write_time on close (correct)\n"); + } + + done: + if (fnum1 != -1) + smbcli_close(cli->tree, fnum1); + smbcli_unlink(cli->tree, fname); + smbcli_deltree(cli->tree, BASEDIR); + + return ret; +} + static bool test_delayed_write_update3b(struct torture_context *tctx, struct smbcli_state *cli, struct smbcli_state *cli2) @@ -2423,6 +2628,7 @@ struct torture_suite *torture_delay_write(void) torture_suite_add_1smb_test(suite, "update of write time using SET_ALLOCATION_SIZE", test_delayed_write_update1c); torture_suite_add_2smb_test(suite, "delayed update of write time using 2 connections", test_delayed_write_update2); torture_suite_add_2smb_test(suite, "delayed update of write time 3", test_delayed_write_update3); + torture_suite_add_2smb_test(suite, "delayed update of write time 3a", test_delayed_write_update3a); torture_suite_add_2smb_test(suite, "delayed update of write time 3b", test_delayed_write_update3b); torture_suite_add_2smb_test(suite, "delayed update of write time 4", test_delayed_write_update4); torture_suite_add_2smb_test(suite, "delayed update of write time 5", test_delayed_write_update5); -- cgit From ad340347974dc5f5f18074941e2537f4ee27a658 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Mon, 8 Sep 2008 14:11:17 +0200 Subject: BASE-DELAYWRITE: test behavior of SMBwrite truncate, writeX, SMBwrite truncate and writeX again metze (This used to be commit 66b8c8d80e1c8e45ab6ca38cabebea07aa122c40) --- source4/torture/basic/delaywrite.c | 204 +++++++++++++++++++++++++++++++++++++ 1 file changed, 204 insertions(+) (limited to 'source4/torture/basic/delaywrite.c') diff --git a/source4/torture/basic/delaywrite.c b/source4/torture/basic/delaywrite.c index 55aac872a9..4f6d4fda0c 100644 --- a/source4/torture/basic/delaywrite.c +++ b/source4/torture/basic/delaywrite.c @@ -1952,6 +1952,209 @@ static bool test_delayed_write_update3b(struct torture_context *tctx, return ret; } +static bool test_delayed_write_update3c(struct torture_context *tctx, + struct smbcli_state *cli, + struct smbcli_state *cli2) +{ + union smb_fileinfo finfo0, finfo1, finfo2, finfo3, finfo4; + union smb_fileinfo pinfo0, pinfo1, pinfo2, pinfo3, pinfo4, pinfo5; + const char *fname = BASEDIR "\\torture_file.txt"; + int fnum1 = -1; + bool ret = true; + ssize_t written; + int i; + struct timeval start; + struct timeval end; + int used_delay = torture_setting_int(tctx, "writetimeupdatedelay", 2000000); + int normal_delay = 2000000; + double sec = ((double)used_delay) / ((double)normal_delay); + int msec = 1000 * sec; + + if (!torture_setup_dir(cli, BASEDIR)) { + return false; + } + + torture_comment(tctx, "Open the file handle\n"); + fnum1 = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE); + if (fnum1 == -1) { + ret = false; + torture_result(tctx, TORTURE_FAIL, __location__": unable to open %s", fname); + goto done; + } + + finfo0.basic_info.level = RAW_FILEINFO_BASIC_INFO; + finfo0.basic_info.in.file.fnum = fnum1; + finfo1 = finfo0; + finfo2 = finfo0; + finfo3 = finfo0; + finfo4 = finfo0; + pinfo0.basic_info.level = RAW_FILEINFO_BASIC_INFO; + pinfo0.basic_info.in.file.path = fname; + pinfo1 = pinfo0; + pinfo2 = pinfo0; + pinfo3 = pinfo0; + pinfo4 = pinfo0; + pinfo5 = pinfo0; + + /* get the initial times */ + GET_INFO_BOTH(finfo0,pinfo0); + + /* + * sleep some time, to demonstrate the handling of write times + * doesn't depend on the time since the open + */ + msleep(5 * msec); + + /* get the initial times */ + GET_INFO_BOTH(finfo1,pinfo1); + COMPARE_WRITE_TIME_EQUAL(finfo1, finfo0); + + /* + * demonstrate that a truncate write always + * updates the write time immediately + */ + for (i=0; i < 3; i++) { + msleep(1 * msec); + /* do a write */ + torture_comment(tctx, "Do a truncate SMBwrite [%d] on the file handle\n", i); + written = smbcli_smbwrite(cli->tree, fnum1, "x", 512, 0); + if (written != 0) { + torture_result(tctx, TORTURE_FAIL, __location__": written gave %d - should have been 0", (int)written); + ret = false; + goto done; + } + /* get the times after the write */ + GET_INFO_BOTH(finfo2,pinfo2); + COMPARE_WRITE_TIME_GREATER(finfo2, finfo1); + finfo1 = finfo2; + } + + start = timeval_current(); + end = timeval_add(&start, 7 * sec, 0); + while (!timeval_expired(&end)) { + /* do a write */ + torture_comment(tctx, "Do a write on the file handle\n"); + written = smbcli_write(cli->tree, fnum1, 0, "x", 0, 1); + if (written != 1) { + torture_result(tctx, TORTURE_FAIL, __location__": written gave %d - should have been 1", (int)written); + ret = false; + goto done; + } + /* get the times after the write */ + GET_INFO_FILE(finfo2); + + if (finfo2.basic_info.out.write_time > finfo1.basic_info.out.write_time) { + double diff = timeval_elapsed(&start); + torture_comment(tctx, "Server updated write_time after %.2f seconds " + "(1sec == %.2f) (wrong!)\n", + diff, sec); + ret = false; + break; + } + msleep(2 * msec); + } + + GET_INFO_BOTH(finfo2,pinfo2); + COMPARE_WRITE_TIME_EQUAL(finfo2, finfo1); + if (finfo2.basic_info.out.write_time == finfo1.basic_info.out.write_time) { + torture_comment(tctx, "Server did not update write_time (correct)\n"); + } + + /* sleep */ + msleep(5 * msec); + + /* get the initial times */ + GET_INFO_BOTH(finfo1,pinfo1); + COMPARE_WRITE_TIME_EQUAL(finfo1, finfo2); + + /* + * demonstrate that a truncate write always + * updates the write time immediately + */ + for (i=0; i < 3; i++) { + msleep(1 * msec); + /* do a write */ + torture_comment(tctx, "Do a truncate write [%d] on the file handle\n", i); + written = smbcli_smbwrite(cli->tree, fnum1, "x", 512, 0); + if (written != 0) { + torture_result(tctx, TORTURE_FAIL, __location__": written gave %d - should have been 0", (int)written); + ret = false; + goto done; + } + /* get the times after the write */ + GET_INFO_BOTH(finfo2,pinfo2); + COMPARE_WRITE_TIME_GREATER(finfo2, finfo1); + finfo1 = finfo2; + } + + /* sleep */ + msleep(5 * msec); + + GET_INFO_BOTH(finfo2,pinfo2); + COMPARE_WRITE_TIME_EQUAL(finfo2, finfo1); + + /* sure any further write doesn't update the write time */ + start = timeval_current(); + end = timeval_add(&start, 15 * sec, 0); + while (!timeval_expired(&end)) { + /* do a write */ + torture_comment(tctx, "Do a write on the file handle\n"); + written = smbcli_write(cli->tree, fnum1, 0, "x", 0, 1); + if (written != 1) { + torture_result(tctx, TORTURE_FAIL, __location__": written gave %d - should have been 1", (int)written); + ret = false; + goto done; + } + /* get the times after the write */ + GET_INFO_BOTH(finfo2,pinfo2); + + if (finfo2.basic_info.out.write_time > finfo1.basic_info.out.write_time) { + double diff = timeval_elapsed(&start); + torture_comment(tctx, "Server updated write_time after %.2f seconds " + "(1sec == %.2f) (wrong!)\n", + diff, sec); + ret = false; + break; + } + msleep(2 * msec); + } + + GET_INFO_BOTH(finfo2,pinfo2); + COMPARE_WRITE_TIME_EQUAL(finfo2, finfo1); + if (finfo2.basic_info.out.write_time == finfo1.basic_info.out.write_time) { + torture_comment(tctx, "Server did not update write_time (correct)\n"); + } + + /* sleep */ + msleep(5 * msec); + + GET_INFO_BOTH(finfo3,pinfo3); + COMPARE_WRITE_TIME_EQUAL(finfo3, finfo2); + + /* + * the close updates the write time to the time of the close + * and not to the time of the last write! + */ + torture_comment(tctx, "Close the file handle\n"); + smbcli_close(cli->tree, fnum1); + fnum1 = -1; + + GET_INFO_PATH(pinfo4); + COMPARE_WRITE_TIME_GREATER(pinfo4, pinfo3); + + if (pinfo4.basic_info.out.write_time > pinfo3.basic_info.out.write_time) { + torture_comment(tctx, "Server updated the write_time on close (correct)\n"); + } + + done: + if (fnum1 != -1) + smbcli_close(cli->tree, fnum1); + smbcli_unlink(cli->tree, fname); + smbcli_deltree(cli->tree, BASEDIR); + + return ret; +} + static bool test_delayed_write_update4(struct torture_context *tctx, struct smbcli_state *cli, struct smbcli_state *cli2) @@ -2630,6 +2833,7 @@ struct torture_suite *torture_delay_write(void) torture_suite_add_2smb_test(suite, "delayed update of write time 3", test_delayed_write_update3); torture_suite_add_2smb_test(suite, "delayed update of write time 3a", test_delayed_write_update3a); torture_suite_add_2smb_test(suite, "delayed update of write time 3b", test_delayed_write_update3b); + torture_suite_add_2smb_test(suite, "delayed update of write time 3c", test_delayed_write_update3c); torture_suite_add_2smb_test(suite, "delayed update of write time 4", test_delayed_write_update4); torture_suite_add_2smb_test(suite, "delayed update of write time 5", test_delayed_write_update5); torture_suite_add_2smb_test(suite, "delayed update of write time 5b", test_delayed_write_update5b); -- cgit From 2c2a79eefa1783225df100b50af84d549597469c Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 8 Sep 2008 14:58:58 -0700 Subject: Make it easier to see when tests start/end. Jeremy. (This used to be commit 6f89e728272ca14f0ed9557485e21647c0731ef2) --- source4/torture/basic/delaywrite.c | 67 +++++++++++++++++++++++++++++--------- 1 file changed, 52 insertions(+), 15 deletions(-) (limited to 'source4/torture/basic/delaywrite.c') diff --git a/source4/torture/basic/delaywrite.c b/source4/torture/basic/delaywrite.c index 4f6d4fda0c..70560235ea 100644 --- a/source4/torture/basic/delaywrite.c +++ b/source4/torture/basic/delaywrite.c @@ -47,6 +47,8 @@ static bool test_delayed_write_update(struct torture_context *tctx, struct smbcl double sec = ((double)used_delay) / ((double)normal_delay); int msec = 1000 * sec; + torture_comment(tctx, "\nRunning test_delayed_write_update\n"); + if (!torture_setup_dir(cli, BASEDIR)) { return false; } @@ -144,6 +146,8 @@ static bool test_delayed_write_update1(struct torture_context *tctx, struct smbc int msec = 1000 * sec; char buf[2048]; + torture_comment(tctx, "\nRunning test_delayed_write_update1\n"); + if (!torture_setup_dir(cli, BASEDIR)) { return false; } @@ -199,7 +203,8 @@ static bool test_delayed_write_update1(struct torture_context *tctx, struct smbc } if (finfo2.all_info.out.size != 1024) { - DEBUG(0, ("file not truncated\n")); + DEBUG(0, ("file not truncated, size = %u (should be 1024)\n", + (unsigned int)finfo2.all_info.out.size)); ret = false; break; } @@ -253,7 +258,8 @@ static bool test_delayed_write_update1(struct torture_context *tctx, struct smbc } if (finfo3.all_info.out.size != 1024) { - DEBUG(0, ("file not truncated\n")); + DEBUG(0, ("file not truncated, size = %u (should be 1024)\n", + (unsigned int)finfo3.all_info.out.size)); ret = false; break; } @@ -321,6 +327,8 @@ static bool test_delayed_write_update1a(struct torture_context *tctx, struct smb int msec = 1000 * sec; char buf[2048]; + torture_comment(tctx, "\nRunning test_delayed_write_update1a\n"); + if (!torture_setup_dir(cli, BASEDIR)) { return false; } @@ -376,7 +384,8 @@ static bool test_delayed_write_update1a(struct torture_context *tctx, struct smb } if (finfo2.all_info.out.size != 10240) { - DEBUG(0, ("file not truncated\n")); + DEBUG(0, ("file not truncated, size = %u (should be 10240)\n", + (unsigned int)finfo2.all_info.out.size)); ret = false; break; } @@ -430,7 +439,8 @@ static bool test_delayed_write_update1a(struct torture_context *tctx, struct smb } if (finfo3.all_info.out.size != 10240) { - DEBUG(0, ("file not truncated\n")); + DEBUG(0, ("file not truncated, size = %u (should be 10240)\n", + (unsigned int)finfo3.all_info.out.size)); ret = false; break; } @@ -498,6 +508,8 @@ static bool test_delayed_write_update1b(struct torture_context *tctx, struct smb int msec = 1000 * sec; char buf[2048]; + torture_comment(tctx, "\nRunning test_delayed_write_update1b\n"); + if (!torture_setup_dir(cli, BASEDIR)) { return false; } @@ -553,7 +565,8 @@ static bool test_delayed_write_update1b(struct torture_context *tctx, struct smb } if (finfo2.all_info.out.size != 10240) { - DEBUG(0, ("file not truncated\n")); + DEBUG(0, ("file not truncated (size = %u, should be 10240)\n", + (unsigned int)finfo2.all_info.out.size )); ret = false; break; } @@ -607,7 +620,8 @@ static bool test_delayed_write_update1b(struct torture_context *tctx, struct smb } if (finfo3.all_info.out.size != 10240) { - DEBUG(0, ("file not truncated\n")); + DEBUG(0, ("file not truncated (size = %u, should be 10240)\n", + (unsigned int)finfo3.all_info.out.size )); ret = false; break; } @@ -675,6 +689,8 @@ static bool test_delayed_write_update1c(struct torture_context *tctx, struct smb int msec = 1000 * sec; char buf[2048]; + torture_comment(tctx, "\nRunning test_delayed_write_update1c\n"); + if (!torture_setup_dir(cli, BASEDIR)) { return false; } @@ -734,7 +750,8 @@ static bool test_delayed_write_update1c(struct torture_context *tctx, struct smb } if (finfo2.all_info.out.size != 0) { - DEBUG(0, ("file not truncated\n")); + DEBUG(0, ("file not truncated (size = %u, should be 10240)\n", + (unsigned int)finfo2.all_info.out.size )); ret = false; break; } @@ -859,6 +876,8 @@ static bool test_delayed_write_update2(struct torture_context *tctx, struct smbc int msec = 1000 * sec; union smb_flush flsh; + torture_comment(tctx, "\nRunning test_delayed_write_update2\n"); + if (!torture_setup_dir(cli, BASEDIR)) { return false; } @@ -1219,6 +1238,8 @@ static bool test_finfo_after_write(struct torture_context *tctx, struct smbcli_s double sec = ((double)used_delay) / ((double)normal_delay); int msec = 1000 * sec; + torture_comment(tctx, "\nRunning test_finfo_after_write\n"); + if (!torture_setup_dir(cli, BASEDIR)) { return false; } @@ -1447,7 +1468,7 @@ static bool test_delayed_write_update3(struct torture_context *tctx, { union smb_fileinfo finfo0, finfo1, finfo2, finfo3, finfo4; union smb_fileinfo pinfo0, pinfo1, pinfo2, pinfo3, pinfo4, pinfo5; - const char *fname = BASEDIR "\\torture_file.txt"; + const char *fname = BASEDIR "\\torture_file3.txt"; int fnum1 = -1; bool ret = true; ssize_t written; @@ -1458,6 +1479,8 @@ static bool test_delayed_write_update3(struct torture_context *tctx, double sec = ((double)used_delay) / ((double)normal_delay); int msec = 1000 * sec; + torture_comment(tctx, "\nRunning test_delayed_write_update3\n"); + if (!torture_setup_dir(cli, BASEDIR)) { return false; } @@ -1595,7 +1618,7 @@ static bool test_delayed_write_update3a(struct torture_context *tctx, { union smb_fileinfo finfo0, finfo1, finfo2, finfo3, finfo4; union smb_fileinfo pinfo0, pinfo1, pinfo2, pinfo3, pinfo4, pinfo5; - const char *fname = BASEDIR "\\torture_file.txt"; + const char *fname = BASEDIR "\\torture_file3a.txt"; int fnum1 = -1; bool ret = true; ssize_t written; @@ -1607,6 +1630,8 @@ static bool test_delayed_write_update3a(struct torture_context *tctx, double sec = ((double)used_delay) / ((double)normal_delay); int msec = 1000 * sec; + torture_comment(tctx, "\nRunning test_delayed_write_update3a\n"); + if (!torture_setup_dir(cli, BASEDIR)) { return false; } @@ -1800,7 +1825,7 @@ static bool test_delayed_write_update3b(struct torture_context *tctx, { union smb_fileinfo finfo0, finfo1, finfo2, finfo3, finfo4; union smb_fileinfo pinfo0, pinfo1, pinfo2, pinfo3, pinfo4, pinfo5; - const char *fname = BASEDIR "\\torture_file.txt"; + const char *fname = BASEDIR "\\torture_file3b.txt"; int fnum1 = -1; bool ret = true; ssize_t written; @@ -1811,6 +1836,8 @@ static bool test_delayed_write_update3b(struct torture_context *tctx, double sec = ((double)used_delay) / ((double)normal_delay); int msec = 1000 * sec; + torture_comment(tctx, "\nRunning test_delayed_write_update3b\n"); + if (!torture_setup_dir(cli, BASEDIR)) { return false; } @@ -1958,7 +1985,7 @@ static bool test_delayed_write_update3c(struct torture_context *tctx, { union smb_fileinfo finfo0, finfo1, finfo2, finfo3, finfo4; union smb_fileinfo pinfo0, pinfo1, pinfo2, pinfo3, pinfo4, pinfo5; - const char *fname = BASEDIR "\\torture_file.txt"; + const char *fname = BASEDIR "\\torture_file3c.txt"; int fnum1 = -1; bool ret = true; ssize_t written; @@ -1970,6 +1997,8 @@ static bool test_delayed_write_update3c(struct torture_context *tctx, double sec = ((double)used_delay) / ((double)normal_delay); int msec = 1000 * sec; + torture_comment(tctx, "\nRunning test_delayed_write_update3c\n"); + if (!torture_setup_dir(cli, BASEDIR)) { return false; } @@ -2161,7 +2190,7 @@ static bool test_delayed_write_update4(struct torture_context *tctx, { union smb_fileinfo finfo0, finfo1, finfo2, finfo3, finfo4; union smb_fileinfo pinfo0, pinfo1, pinfo2, pinfo3, pinfo4, pinfo5; - const char *fname = BASEDIR "\\torture_file.txt"; + const char *fname = BASEDIR "\\torture_file4.txt"; int fnum1 = -1; bool ret = true; ssize_t written; @@ -2172,6 +2201,8 @@ static bool test_delayed_write_update4(struct torture_context *tctx, double sec = ((double)used_delay) / ((double)normal_delay); int msec = 1000 * sec; + torture_comment(tctx, "\nRunning test_delayed_write_update4\n"); + if (!torture_setup_dir(cli, BASEDIR)) { return false; } @@ -2316,7 +2347,7 @@ static bool test_delayed_write_update5(struct torture_context *tctx, { union smb_fileinfo finfo0, finfo1, finfo2, finfo3, finfo4, finfo5; union smb_fileinfo pinfo0, pinfo1, pinfo2, pinfo3, pinfo4, pinfo5, pinfo6; - const char *fname = BASEDIR "\\torture_file.txt"; + const char *fname = BASEDIR "\\torture_file5.txt"; int fnum1 = -1; bool ret = true; ssize_t written; @@ -2327,6 +2358,8 @@ static bool test_delayed_write_update5(struct torture_context *tctx, double sec = ((double)used_delay) / ((double)normal_delay); int msec = 1000 * sec; + torture_comment(tctx, "\nRunning test_delayed_write_update5\n"); + if (!torture_setup_dir(cli, BASEDIR)) { return false; } @@ -2472,7 +2505,7 @@ static bool test_delayed_write_update5b(struct torture_context *tctx, { union smb_fileinfo finfo0, finfo1, finfo2, finfo3, finfo4, finfo5; union smb_fileinfo pinfo0, pinfo1, pinfo2, pinfo3, pinfo4, pinfo5, pinfo6; - const char *fname = BASEDIR "\\torture_file.txt"; + const char *fname = BASEDIR "\\torture_fileb.txt"; int fnum1 = -1; bool ret = true; ssize_t written; @@ -2483,6 +2516,8 @@ static bool test_delayed_write_update5b(struct torture_context *tctx, double sec = ((double)used_delay) / ((double)normal_delay); int msec = 1000 * sec; + torture_comment(tctx, "\nRunning test_delayed_write_update5b\n"); + if (!torture_setup_dir(cli, BASEDIR)) { return false; } @@ -2628,7 +2663,7 @@ static bool test_delayed_write_update6(struct torture_context *tctx, { union smb_fileinfo finfo0, finfo1, finfo2, finfo3, finfo4, finfo5; union smb_fileinfo pinfo0, pinfo1, pinfo2, pinfo3, pinfo4, pinfo5, pinfo6, pinfo7; - const char *fname = BASEDIR "\\torture_file.txt"; + const char *fname = BASEDIR "\\torture_file6.txt"; int fnum1 = -1; int fnum2 = -1; bool ret = true; @@ -2641,6 +2676,8 @@ static bool test_delayed_write_update6(struct torture_context *tctx, int msec = 1000 * sec; bool first = true; + torture_comment(tctx, "\nRunning test_delayed_write_update6\n"); + if (!torture_setup_dir(cli, BASEDIR)) { return false; } -- cgit From bc731db85423a1f2d8dd8d205c702e49ea9347f3 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 9 Sep 2008 21:24:34 -0700 Subject: A truncate write must be a smbcli_smbwrite, not a smbcli_write. Jeremy. (This used to be commit 8cebd4d36c862dcdc6551dc6bf4dda2342dfede7) --- source4/torture/basic/delaywrite.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/torture/basic/delaywrite.c') diff --git a/source4/torture/basic/delaywrite.c b/source4/torture/basic/delaywrite.c index 70560235ea..13319681bd 100644 --- a/source4/torture/basic/delaywrite.c +++ b/source4/torture/basic/delaywrite.c @@ -2602,7 +2602,7 @@ static bool test_delayed_write_update5b(struct torture_context *tctx, while (!timeval_expired(&end)) { /* do a write */ torture_comment(tctx, "Do a truncate write on the file handle\n"); - written = smbcli_write(cli->tree, fnum1, 0, "x", 0, 0); + written = smbcli_smbwrite(cli->tree, fnum1, "x", 1024, 0); if (written != 0) { torture_result(tctx, TORTURE_FAIL, __location__": written gave %d - should have been 1", (int)written); ret = false; -- cgit From 6ce1c893fa8f2987db6572458a540cf359b46e11 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 12 Sep 2008 14:59:32 -0700 Subject: Comment the delay write time tests so I know what they're testing. Jeremy. (This used to be commit 2bf9074c7751324483744f55b02cfb044bb0b2dd) --- source4/torture/basic/delaywrite.c | 44 +++++++++++++++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 3 deletions(-) (limited to 'source4/torture/basic/delaywrite.c') diff --git a/source4/torture/basic/delaywrite.c b/source4/torture/basic/delaywrite.c index 13319681bd..af42beb535 100644 --- a/source4/torture/basic/delaywrite.c +++ b/source4/torture/basic/delaywrite.c @@ -1612,6 +1612,11 @@ static bool test_delayed_write_update3(struct torture_context *tctx, return ret; } +/* + * Show that a truncate write always updates the write time even + * if an initial write has already updated the write time. + */ + static bool test_delayed_write_update3a(struct torture_context *tctx, struct smbcli_state *cli, struct smbcli_state *cli2) @@ -1819,6 +1824,11 @@ static bool test_delayed_write_update3a(struct torture_context *tctx, return ret; } +/* + * Show a close after write updates the write timestamp to + * the close time, not the last write time. + */ + static bool test_delayed_write_update3b(struct torture_context *tctx, struct smbcli_state *cli, struct smbcli_state *cli2) @@ -1979,6 +1989,13 @@ static bool test_delayed_write_update3b(struct torture_context *tctx, return ret; } +/* + * Check that a write after a truncate write doesn't update + * the timestamp, but a truncate write after a write does. + * Also prove that a close after a truncate write updates the + * timestamp to current, not the time of last write. + */ + static bool test_delayed_write_update3c(struct torture_context *tctx, struct smbcli_state *cli, struct smbcli_state *cli2) @@ -2184,6 +2201,12 @@ static bool test_delayed_write_update3c(struct torture_context *tctx, return ret; } +/* + * Show only the first write updates the timestamp, and a close + * after writes updates to current (I think this is the same + * as test 3b. JRA). + */ + static bool test_delayed_write_update4(struct torture_context *tctx, struct smbcli_state *cli, struct smbcli_state *cli2) @@ -2341,6 +2364,10 @@ static bool test_delayed_write_update4(struct torture_context *tctx, return ret; } +/* + * Show writes and closes have no effect on updating times once a SETWRITETIME is done. + */ + static bool test_delayed_write_update5(struct torture_context *tctx, struct smbcli_state *cli, struct smbcli_state *cli2) @@ -2499,6 +2526,10 @@ static bool test_delayed_write_update5(struct torture_context *tctx, return ret; } +/* + * Show truncate writes and closes have no effect on updating times once a SETWRITETIME is done. + */ + static bool test_delayed_write_update5b(struct torture_context *tctx, struct smbcli_state *cli, struct smbcli_state *cli2) @@ -2596,7 +2627,7 @@ static bool test_delayed_write_update5b(struct torture_context *tctx, torture_comment(tctx, "Server did not update write_time (correct)\n"); } - /* sure any further write (truncates) update the write time */ + /* Do any further write (truncates) update the write time ? */ start = timeval_current(); end = timeval_add(&start, 15 * sec, 0); while (!timeval_expired(&end)) { @@ -2657,6 +2688,14 @@ static bool test_delayed_write_update5b(struct torture_context *tctx, return ret; } +/* + * Open 2 handles on a file. Write one one and then set the + * WRITE TIME explicitly on the other. Ensure the write time + * update is cancelled. Ensure the write time is updated to + * the close time when the non-explicit set handle is closed. + * + */ + static bool test_delayed_write_update6(struct torture_context *tctx, struct smbcli_state *cli, struct smbcli_state *cli2) @@ -2852,8 +2891,7 @@ again: return ret; } - -/* +/* testing of delayed update of write_time */ struct torture_suite *torture_delay_write(void) -- cgit