From f6da6a10de7d7f101f6485f4a34ef4ef5b6ab6c0 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 17 Oct 2004 02:52:37 +0000 Subject: r3011: separated the locktest code into a separate module in smbtorture (This used to be commit f4a91be63502c0bb32c52c0558dfc7d4d0a21fae) --- source4/torture/basic/locking.c | 907 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 907 insertions(+) create mode 100644 source4/torture/basic/locking.c (limited to 'source4/torture/basic/locking.c') diff --git a/source4/torture/basic/locking.c b/source4/torture/basic/locking.c new file mode 100644 index 0000000000..4708415937 --- /dev/null +++ b/source4/torture/basic/locking.c @@ -0,0 +1,907 @@ +/* + Unix SMB/CIFS implementation. + + basic locking tests + + Copyright (C) Andrew Tridgell 2000-2004 + Copyright (C) Jeremy Allison 2000-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" + +/* + This test checks for two things: + + 1) correct support for retaining locks over a close (ie. the server + must not use posix semantics) + 2) support for lock timeouts + */ +BOOL torture_locktest1(int dummy) +{ + struct smbcli_state *cli1, *cli2; + const char *fname = "\\lockt1.lck"; + int fnum1, fnum2, fnum3; + time_t t1, t2; + uint_t lock_timeout; + + if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) { + return False; + } + + printf("starting locktest1\n"); + + smbcli_unlink(cli1->tree, fname); + + fnum1 = smbcli_open(cli1->tree, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE); + if (fnum1 == -1) { + printf("open of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree)); + return False; + } + fnum2 = smbcli_open(cli1->tree, fname, O_RDWR, DENY_NONE); + if (fnum2 == -1) { + printf("open2 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree)); + return False; + } + fnum3 = smbcli_open(cli2->tree, fname, O_RDWR, DENY_NONE); + if (fnum3 == -1) { + printf("open3 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree)); + return False; + } + + if (NT_STATUS_IS_ERR(smbcli_lock(cli1->tree, fnum1, 0, 4, 0, WRITE_LOCK))) { + printf("lock1 failed (%s)\n", smbcli_errstr(cli1->tree)); + return False; + } + + + if (NT_STATUS_IS_OK(smbcli_lock(cli2->tree, fnum3, 0, 4, 0, WRITE_LOCK))) { + printf("lock2 succeeded! This is a locking bug\n"); + return False; + } else { + if (!check_error(__location__, cli2, ERRDOS, ERRlock, + NT_STATUS_LOCK_NOT_GRANTED)) return False; + } + + + lock_timeout = (6 + (random() % 20)); + printf("Testing lock timeout with timeout=%u\n", lock_timeout); + t1 = time(NULL); + if (NT_STATUS_IS_OK(smbcli_lock(cli2->tree, fnum3, 0, 4, lock_timeout * 1000, WRITE_LOCK))) { + printf("lock3 succeeded! This is a locking bug\n"); + return False; + } else { + if (!check_error(__location__, cli2, ERRDOS, ERRlock, + NT_STATUS_FILE_LOCK_CONFLICT)) return False; + } + t2 = time(NULL); + + if (t2 - t1 < 5) { + printf("error: This server appears not to support timed lock requests\n"); + } + printf("server slept for %u seconds for a %u second timeout\n", + (uint_t)(t2-t1), lock_timeout); + + if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum2))) { + printf("close1 failed (%s)\n", smbcli_errstr(cli1->tree)); + return False; + } + + if (NT_STATUS_IS_OK(smbcli_lock(cli2->tree, fnum3, 0, 4, 0, WRITE_LOCK))) { + printf("lock4 succeeded! This is a locking bug\n"); + return False; + } else { + if (!check_error(__location__, cli2, ERRDOS, ERRlock, + NT_STATUS_FILE_LOCK_CONFLICT)) return False; + } + + if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) { + printf("close2 failed (%s)\n", smbcli_errstr(cli1->tree)); + return False; + } + + if (NT_STATUS_IS_ERR(smbcli_close(cli2->tree, fnum3))) { + printf("close3 failed (%s)\n", smbcli_errstr(cli2->tree)); + return False; + } + + if (NT_STATUS_IS_ERR(smbcli_unlink(cli1->tree, fname))) { + printf("unlink failed (%s)\n", smbcli_errstr(cli1->tree)); + return False; + } + + + if (!torture_close_connection(cli1)) { + return False; + } + + if (!torture_close_connection(cli2)) { + return False; + } + + printf("Passed locktest1\n"); + return True; +} + + +/* + This test checks that + + 1) the server supports multiple locking contexts on the one SMB + connection, distinguished by PID. + + 2) the server correctly fails overlapping locks made by the same PID (this + goes against POSIX behaviour, which is why it is tricky to implement) + + 3) the server denies unlock requests by an incorrect client PID +*/ +BOOL torture_locktest2(int dummy) +{ + struct smbcli_state *cli; + const char *fname = "\\lockt2.lck"; + int fnum1, fnum2, fnum3; + BOOL correct = True; + + if (!torture_open_connection(&cli)) { + return False; + } + + printf("starting locktest2\n"); + + smbcli_unlink(cli->tree, fname); + + printf("Testing pid context\n"); + + cli->session->pid = 1; + + fnum1 = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE); + if (fnum1 == -1) { + printf("open of %s failed (%s)\n", fname, smbcli_errstr(cli->tree)); + return False; + } + + fnum2 = smbcli_open(cli->tree, fname, O_RDWR, DENY_NONE); + if (fnum2 == -1) { + printf("open2 of %s failed (%s)\n", fname, smbcli_errstr(cli->tree)); + return False; + } + + cli->session->pid = 2; + + fnum3 = smbcli_open(cli->tree, fname, O_RDWR, DENY_NONE); + if (fnum3 == -1) { + printf("open3 of %s failed (%s)\n", fname, smbcli_errstr(cli->tree)); + return False; + } + + cli->session->pid = 1; + + if (NT_STATUS_IS_ERR(smbcli_lock(cli->tree, fnum1, 0, 4, 0, WRITE_LOCK))) { + printf("lock1 failed (%s)\n", smbcli_errstr(cli->tree)); + return False; + } + + if (NT_STATUS_IS_OK(smbcli_lock(cli->tree, fnum1, 0, 4, 0, WRITE_LOCK))) { + printf("WRITE lock1 succeeded! This is a locking bug\n"); + correct = False; + } else { + if (!check_error(__location__, cli, ERRDOS, ERRlock, + NT_STATUS_LOCK_NOT_GRANTED)) return False; + } + + if (NT_STATUS_IS_OK(smbcli_lock(cli->tree, fnum2, 0, 4, 0, WRITE_LOCK))) { + printf("WRITE lock2 succeeded! This is a locking bug\n"); + correct = False; + } else { + if (!check_error(__location__, cli, ERRDOS, ERRlock, + NT_STATUS_LOCK_NOT_GRANTED)) return False; + } + + if (NT_STATUS_IS_OK(smbcli_lock(cli->tree, fnum2, 0, 4, 0, READ_LOCK))) { + printf("READ lock2 succeeded! This is a locking bug\n"); + correct = False; + } else { + if (!check_error(__location__, cli, ERRDOS, ERRlock, + NT_STATUS_FILE_LOCK_CONFLICT)) return False; + } + + if (NT_STATUS_IS_ERR(smbcli_lock(cli->tree, fnum1, 100, 4, 0, WRITE_LOCK))) { + printf("lock at 100 failed (%s)\n", smbcli_errstr(cli->tree)); + } + + cli->session->pid = 2; + + if (NT_STATUS_IS_OK(smbcli_unlock(cli->tree, fnum1, 100, 4))) { + printf("unlock at 100 succeeded! This is a locking bug\n"); + correct = False; + } + + if (NT_STATUS_IS_OK(smbcli_unlock(cli->tree, fnum1, 0, 4))) { + printf("unlock1 succeeded! This is a locking bug\n"); + correct = False; + } else { + if (!check_error(__location__, cli, + ERRDOS, ERRlock, + NT_STATUS_RANGE_NOT_LOCKED)) return False; + } + + if (NT_STATUS_IS_OK(smbcli_unlock(cli->tree, fnum1, 0, 8))) { + printf("unlock2 succeeded! This is a locking bug\n"); + correct = False; + } else { + if (!check_error(__location__, cli, + ERRDOS, ERRlock, + NT_STATUS_RANGE_NOT_LOCKED)) return False; + } + + if (NT_STATUS_IS_OK(smbcli_lock(cli->tree, fnum3, 0, 4, 0, WRITE_LOCK))) { + printf("lock3 succeeded! This is a locking bug\n"); + correct = False; + } else { + if (!check_error(__location__, cli, ERRDOS, ERRlock, NT_STATUS_LOCK_NOT_GRANTED)) return False; + } + + cli->session->pid = 1; + + if (NT_STATUS_IS_ERR(smbcli_close(cli->tree, fnum1))) { + printf("close1 failed (%s)\n", smbcli_errstr(cli->tree)); + return False; + } + + if (NT_STATUS_IS_ERR(smbcli_close(cli->tree, fnum2))) { + printf("close2 failed (%s)\n", smbcli_errstr(cli->tree)); + return False; + } + + if (NT_STATUS_IS_ERR(smbcli_close(cli->tree, fnum3))) { + printf("close3 failed (%s)\n", smbcli_errstr(cli->tree)); + return False; + } + + if (!torture_close_connection(cli)) { + correct = False; + } + + printf("locktest2 finished\n"); + + return correct; +} + + +/* + This test checks that + + 1) the server supports the full offset range in lock requests +*/ +BOOL torture_locktest3(int dummy) +{ + struct smbcli_state *cli1, *cli2; + const char *fname = "\\lockt3.lck"; + int fnum1, fnum2, i; + uint32_t offset; + BOOL correct = True; + extern int torture_numops; + +#define NEXT_OFFSET offset += (~(uint32_t)0) / torture_numops + + if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) { + return False; + } + + printf("starting locktest3\n"); + + printf("Testing 32 bit offset ranges\n"); + + smbcli_unlink(cli1->tree, fname); + + fnum1 = smbcli_open(cli1->tree, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE); + if (fnum1 == -1) { + printf("open of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree)); + return False; + } + fnum2 = smbcli_open(cli2->tree, fname, O_RDWR, DENY_NONE); + if (fnum2 == -1) { + printf("open2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree)); + return False; + } + + printf("Establishing %d locks\n", torture_numops); + + for (offset=i=0;itree, fnum1, offset-1, 1, 0, WRITE_LOCK))) { + printf("lock1 %d failed (%s)\n", + i, + smbcli_errstr(cli1->tree)); + return False; + } + + if (NT_STATUS_IS_ERR(smbcli_lock(cli2->tree, fnum2, offset-2, 1, 0, WRITE_LOCK))) { + printf("lock2 %d failed (%s)\n", + i, + smbcli_errstr(cli1->tree)); + return False; + } + } + + printf("Testing %d locks\n", torture_numops); + + for (offset=i=0;itree, fnum1, offset-2, 1, 0, WRITE_LOCK))) { + printf("error: lock1 %d succeeded!\n", i); + return False; + } + + if (NT_STATUS_IS_OK(smbcli_lock(cli2->tree, fnum2, offset-1, 1, 0, WRITE_LOCK))) { + printf("error: lock2 %d succeeded!\n", i); + return False; + } + + if (NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, offset-1, 1, 0, WRITE_LOCK))) { + printf("error: lock3 %d succeeded!\n", i); + return False; + } + + if (NT_STATUS_IS_OK(smbcli_lock(cli2->tree, fnum2, offset-2, 1, 0, WRITE_LOCK))) { + printf("error: lock4 %d succeeded!\n", i); + return False; + } + } + + printf("Removing %d locks\n", torture_numops); + + for (offset=i=0;itree, fnum1, offset-1, 1))) { + printf("unlock1 %d failed (%s)\n", + i, + smbcli_errstr(cli1->tree)); + return False; + } + + if (NT_STATUS_IS_ERR(smbcli_unlock(cli2->tree, fnum2, offset-2, 1))) { + printf("unlock2 %d failed (%s)\n", + i, + smbcli_errstr(cli1->tree)); + return False; + } + } + + if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) { + printf("close1 failed (%s)\n", smbcli_errstr(cli1->tree)); + return False; + } + + if (NT_STATUS_IS_ERR(smbcli_close(cli2->tree, fnum2))) { + printf("close2 failed (%s)\n", smbcli_errstr(cli2->tree)); + return False; + } + + if (NT_STATUS_IS_ERR(smbcli_unlink(cli1->tree, fname))) { + printf("unlink failed (%s)\n", smbcli_errstr(cli1->tree)); + return False; + } + + if (!torture_close_connection(cli1)) { + correct = False; + } + + if (!torture_close_connection(cli2)) { + correct = False; + } + + printf("finished locktest3\n"); + + return correct; +} + +#define EXPECTED(ret, v) if ((ret) != (v)) { \ + printf("** "); correct = False; \ + } + +/* + looks at overlapping locks +*/ +BOOL torture_locktest4(int dummy) +{ + struct smbcli_state *cli1, *cli2; + const char *fname = "\\lockt4.lck"; + int fnum1, fnum2, f; + BOOL ret; + char buf[1000]; + BOOL correct = True; + + if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) { + return False; + } + + printf("starting locktest4\n"); + + smbcli_unlink(cli1->tree, fname); + + fnum1 = smbcli_open(cli1->tree, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE); + fnum2 = smbcli_open(cli2->tree, fname, O_RDWR, DENY_NONE); + + memset(buf, 0, sizeof(buf)); + + if (smbcli_write(cli1->tree, fnum1, 0, buf, 0, sizeof(buf)) != sizeof(buf)) { + printf("Failed to create file\n"); + correct = False; + goto fail; + } + + ret = NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 0, 4, 0, WRITE_LOCK)) && + NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 2, 4, 0, WRITE_LOCK)); + EXPECTED(ret, False); + printf("the same process %s set overlapping write locks\n", ret?"can":"cannot"); + + ret = NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 10, 4, 0, READ_LOCK)) && + NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 12, 4, 0, READ_LOCK)); + EXPECTED(ret, True); + printf("the same process %s set overlapping read locks\n", ret?"can":"cannot"); + + ret = NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 20, 4, 0, WRITE_LOCK)) && + NT_STATUS_IS_OK(smbcli_lock(cli2->tree, fnum2, 22, 4, 0, WRITE_LOCK)); + EXPECTED(ret, False); + printf("a different connection %s set overlapping write locks\n", ret?"can":"cannot"); + + ret = NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 30, 4, 0, READ_LOCK)) && + NT_STATUS_IS_OK(smbcli_lock(cli2->tree, fnum2, 32, 4, 0, READ_LOCK)); + EXPECTED(ret, True); + printf("a different connection %s set overlapping read locks\n", ret?"can":"cannot"); + + ret = NT_STATUS_IS_OK((cli1->session->pid = 1, smbcli_lock(cli1->tree, fnum1, 40, 4, 0, WRITE_LOCK))) && + NT_STATUS_IS_OK((cli1->session->pid = 2, smbcli_lock(cli1->tree, fnum1, 42, 4, 0, WRITE_LOCK))); + EXPECTED(ret, False); + printf("a different pid %s set overlapping write locks\n", ret?"can":"cannot"); + + ret = NT_STATUS_IS_OK((cli1->session->pid = 1, smbcli_lock(cli1->tree, fnum1, 50, 4, 0, READ_LOCK))) && + NT_STATUS_IS_OK((cli1->session->pid = 2, smbcli_lock(cli1->tree, fnum1, 52, 4, 0, READ_LOCK))); + EXPECTED(ret, True); + printf("a different pid %s set overlapping read locks\n", ret?"can":"cannot"); + + ret = NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 60, 4, 0, READ_LOCK)) && + NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 60, 4, 0, READ_LOCK)); + EXPECTED(ret, True); + printf("the same process %s set the same read lock twice\n", ret?"can":"cannot"); + + ret = NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 70, 4, 0, WRITE_LOCK)) && + NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 70, 4, 0, WRITE_LOCK)); + EXPECTED(ret, False); + printf("the same process %s set the same write lock twice\n", ret?"can":"cannot"); + + ret = NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 80, 4, 0, READ_LOCK)) && + NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 80, 4, 0, WRITE_LOCK)); + EXPECTED(ret, False); + printf("the same process %s overlay a read lock with a write lock\n", ret?"can":"cannot"); + + ret = NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 90, 4, 0, WRITE_LOCK)) && + NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 90, 4, 0, READ_LOCK)); + EXPECTED(ret, True); + printf("the same process %s overlay a write lock with a read lock\n", ret?"can":"cannot"); + + ret = NT_STATUS_IS_OK((cli1->session->pid = 1, smbcli_lock(cli1->tree, fnum1, 100, 4, 0, WRITE_LOCK))) && + NT_STATUS_IS_OK((cli1->session->pid = 2, smbcli_lock(cli1->tree, fnum1, 100, 4, 0, READ_LOCK))); + EXPECTED(ret, False); + printf("a different pid %s overlay a write lock with a read lock\n", ret?"can":"cannot"); + + ret = NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 110, 4, 0, READ_LOCK)) && + NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 112, 4, 0, READ_LOCK)) && + NT_STATUS_IS_OK(smbcli_unlock(cli1->tree, fnum1, 110, 6)); + EXPECTED(ret, False); + printf("the same process %s coalesce read locks\n", ret?"can":"cannot"); + + + ret = NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 120, 4, 0, WRITE_LOCK)) && + (smbcli_read(cli2->tree, fnum2, buf, 120, 4) == 4); + EXPECTED(ret, False); + printf("this server %s strict write locking\n", ret?"doesn't do":"does"); + + ret = NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 130, 4, 0, READ_LOCK)) && + (smbcli_write(cli2->tree, fnum2, 0, buf, 130, 4) == 4); + EXPECTED(ret, False); + printf("this server %s strict read locking\n", ret?"doesn't do":"does"); + + + ret = NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 140, 4, 0, READ_LOCK)) && + NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 140, 4, 0, READ_LOCK)) && + NT_STATUS_IS_OK(smbcli_unlock(cli1->tree, fnum1, 140, 4)) && + NT_STATUS_IS_OK(smbcli_unlock(cli1->tree, fnum1, 140, 4)); + EXPECTED(ret, True); + printf("this server %s do recursive read locking\n", ret?"does":"doesn't"); + + + ret = NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 150, 4, 0, WRITE_LOCK)) && + NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 150, 4, 0, READ_LOCK)) && + NT_STATUS_IS_OK(smbcli_unlock(cli1->tree, fnum1, 150, 4)) && + (smbcli_read(cli2->tree, fnum2, buf, 150, 4) == 4) && + !(smbcli_write(cli2->tree, fnum2, 0, buf, 150, 4) == 4) && + NT_STATUS_IS_OK(smbcli_unlock(cli1->tree, fnum1, 150, 4)); + EXPECTED(ret, True); + printf("this server %s do recursive lock overlays\n", ret?"does":"doesn't"); + + ret = NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 160, 4, 0, READ_LOCK)) && + NT_STATUS_IS_OK(smbcli_unlock(cli1->tree, fnum1, 160, 4)) && + (smbcli_write(cli2->tree, fnum2, 0, buf, 160, 4) == 4) && + (smbcli_read(cli2->tree, fnum2, buf, 160, 4) == 4); + EXPECTED(ret, True); + printf("the same process %s remove a read lock using write locking\n", ret?"can":"cannot"); + + ret = NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 170, 4, 0, WRITE_LOCK)) && + NT_STATUS_IS_OK(smbcli_unlock(cli1->tree, fnum1, 170, 4)) && + (smbcli_write(cli2->tree, fnum2, 0, buf, 170, 4) == 4) && + (smbcli_read(cli2->tree, fnum2, buf, 170, 4) == 4); + EXPECTED(ret, True); + printf("the same process %s remove a write lock using read locking\n", ret?"can":"cannot"); + + ret = NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 190, 4, 0, WRITE_LOCK)) && + NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 190, 4, 0, READ_LOCK)) && + NT_STATUS_IS_OK(smbcli_unlock(cli1->tree, fnum1, 190, 4)) && + !(smbcli_write(cli2->tree, fnum2, 0, buf, 190, 4) == 4) && + (smbcli_read(cli2->tree, fnum2, buf, 190, 4) == 4); + EXPECTED(ret, True); + printf("the same process %s remove the first lock first\n", ret?"does":"doesn't"); + + smbcli_close(cli1->tree, fnum1); + smbcli_close(cli2->tree, fnum2); + fnum1 = smbcli_open(cli1->tree, fname, O_RDWR, DENY_NONE); + f = smbcli_open(cli1->tree, fname, O_RDWR, DENY_NONE); + ret = NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 0, 8, 0, READ_LOCK)) && + NT_STATUS_IS_OK(smbcli_lock(cli1->tree, f, 0, 1, 0, READ_LOCK)) && + NT_STATUS_IS_OK(smbcli_close(cli1->tree, fnum1)) && + ((fnum1 = smbcli_open(cli1->tree, fname, O_RDWR, DENY_NONE)) != -1) && + NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 7, 1, 0, WRITE_LOCK)); + smbcli_close(cli1->tree, f); + smbcli_close(cli1->tree, fnum1); + EXPECTED(ret, True); + printf("the server %s have the NT byte range lock bug\n", !ret?"does":"doesn't"); + + fail: + smbcli_close(cli1->tree, fnum1); + smbcli_close(cli2->tree, fnum2); + smbcli_unlink(cli1->tree, fname); + torture_close_connection(cli1); + torture_close_connection(cli2); + + printf("finished locktest4\n"); + return correct; +} + +/* + looks at lock upgrade/downgrade. +*/ +BOOL torture_locktest5(int dummy) +{ + struct smbcli_state *cli1, *cli2; + const char *fname = "\\lockt5.lck"; + int fnum1, fnum2, fnum3; + BOOL ret; + char buf[1000]; + BOOL correct = True; + + if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) { + return False; + } + + printf("starting locktest5\n"); + + smbcli_unlink(cli1->tree, fname); + + fnum1 = smbcli_open(cli1->tree, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE); + fnum2 = smbcli_open(cli2->tree, fname, O_RDWR, DENY_NONE); + fnum3 = smbcli_open(cli1->tree, fname, O_RDWR, DENY_NONE); + + memset(buf, 0, sizeof(buf)); + + if (smbcli_write(cli1->tree, fnum1, 0, buf, 0, sizeof(buf)) != sizeof(buf)) { + printf("Failed to create file\n"); + correct = False; + goto fail; + } + + /* Check for NT bug... */ + ret = NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 0, 8, 0, READ_LOCK)) && + NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum3, 0, 1, 0, READ_LOCK)); + smbcli_close(cli1->tree, fnum1); + fnum1 = smbcli_open(cli1->tree, fname, O_RDWR, DENY_NONE); + ret = NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 7, 1, 0, WRITE_LOCK)); + EXPECTED(ret, True); + printf("this server %s the NT locking bug\n", ret ? "doesn't have" : "has"); + smbcli_close(cli1->tree, fnum1); + fnum1 = smbcli_open(cli1->tree, fname, O_RDWR, DENY_NONE); + smbcli_unlock(cli1->tree, fnum3, 0, 1); + + ret = NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 0, 4, 0, WRITE_LOCK)) && + NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 1, 1, 0, READ_LOCK)); + EXPECTED(ret, True); + printf("the same process %s overlay a write with a read lock\n", ret?"can":"cannot"); + + ret = NT_STATUS_IS_OK(smbcli_lock(cli2->tree, fnum2, 0, 4, 0, READ_LOCK)); + EXPECTED(ret, False); + + printf("a different processs %s get a read lock on the first process lock stack\n", ret?"can":"cannot"); + + /* Unlock the process 2 lock. */ + smbcli_unlock(cli2->tree, fnum2, 0, 4); + + ret = NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum3, 0, 4, 0, READ_LOCK)); + EXPECTED(ret, False); + + printf("the same processs on a different fnum %s get a read lock\n", ret?"can":"cannot"); + + /* Unlock the process 1 fnum3 lock. */ + smbcli_unlock(cli1->tree, fnum3, 0, 4); + + /* Stack 2 more locks here. */ + ret = NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 0, 4, 0, READ_LOCK)) && + NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 0, 4, 0, READ_LOCK)); + + EXPECTED(ret, True); + printf("the same process %s stack read locks\n", ret?"can":"cannot"); + + /* Unlock the first process lock, then check this was the WRITE lock that was + removed. */ + +ret = NT_STATUS_IS_OK(smbcli_unlock(cli1->tree, fnum1, 0, 4)) && + NT_STATUS_IS_OK(smbcli_lock(cli2->tree, fnum2, 0, 4, 0, READ_LOCK)); + + EXPECTED(ret, True); + printf("the first unlock removes the %s lock\n", ret?"WRITE":"READ"); + + /* Unlock the process 2 lock. */ + smbcli_unlock(cli2->tree, fnum2, 0, 4); + + /* We should have 3 stacked locks here. Ensure we need to do 3 unlocks. */ + + ret = NT_STATUS_IS_OK(smbcli_unlock(cli1->tree, fnum1, 1, 1)) && + NT_STATUS_IS_OK(smbcli_unlock(cli1->tree, fnum1, 0, 4)) && + NT_STATUS_IS_OK(smbcli_unlock(cli1->tree, fnum1, 0, 4)); + + EXPECTED(ret, True); + printf("the same process %s unlock the stack of 4 locks\n", ret?"can":"cannot"); + + /* Ensure the next unlock fails. */ + ret = NT_STATUS_IS_OK(smbcli_unlock(cli1->tree, fnum1, 0, 4)); + EXPECTED(ret, False); + printf("the same process %s count the lock stack\n", !ret?"can":"cannot"); + + /* Ensure connection 2 can get a write lock. */ + ret = NT_STATUS_IS_OK(smbcli_lock(cli2->tree, fnum2, 0, 4, 0, WRITE_LOCK)); + EXPECTED(ret, True); + + printf("a different processs %s get a write lock on the unlocked stack\n", ret?"can":"cannot"); + + + fail: + smbcli_close(cli1->tree, fnum1); + smbcli_close(cli2->tree, fnum2); + smbcli_unlink(cli1->tree, fname); + if (!torture_close_connection(cli1)) { + correct = False; + } + if (!torture_close_connection(cli2)) { + correct = False; + } + + printf("finished locktest5\n"); + + return correct; +} + +/* + tries the unusual lockingX locktype bits +*/ +BOOL torture_locktest6(int dummy) +{ + struct smbcli_state *cli; + const char *fname[1] = { "\\lock6.txt" }; + int i; + int fnum; + NTSTATUS status; + + if (!torture_open_connection(&cli)) { + return False; + } + + printf("starting locktest6\n"); + + for (i=0;i<1;i++) { + printf("Testing %s\n", fname[i]); + + smbcli_unlink(cli->tree, fname[i]); + + fnum = smbcli_open(cli->tree, fname[i], O_RDWR|O_CREAT|O_EXCL, DENY_NONE); + status = smbcli_locktype(cli->tree, fnum, 0, 8, 0, LOCKING_ANDX_CHANGE_LOCKTYPE); + smbcli_close(cli->tree, fnum); + printf("CHANGE_LOCKTYPE gave %s\n", nt_errstr(status)); + + fnum = smbcli_open(cli->tree, fname[i], O_RDWR, DENY_NONE); + status = smbcli_locktype(cli->tree, fnum, 0, 8, 0, LOCKING_ANDX_CANCEL_LOCK); + smbcli_close(cli->tree, fnum); + printf("CANCEL_LOCK gave %s\n", nt_errstr(status)); + + smbcli_unlink(cli->tree, fname[i]); + } + + torture_close_connection(cli); + + printf("finished locktest6\n"); + return True; +} + +BOOL torture_locktest7(int dummy) +{ + struct smbcli_state *cli1; + const char *fname = "\\lockt7.lck"; + int fnum1; + int fnum2; + size_t size; + char buf[200]; + BOOL correct = False; + + if (!torture_open_connection(&cli1)) { + return False; + } + + printf("starting locktest7\n"); + + smbcli_unlink(cli1->tree, fname); + + fnum1 = smbcli_open(cli1->tree, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE); + + memset(buf, 0, sizeof(buf)); + + if (smbcli_write(cli1->tree, fnum1, 0, buf, 0, sizeof(buf)) != sizeof(buf)) { + printf("Failed to create file\n"); + goto fail; + } + + cli1->session->pid = 1; + + if (NT_STATUS_IS_ERR(smbcli_lock(cli1->tree, fnum1, 130, 4, 0, READ_LOCK))) { + printf("Unable to apply read lock on range 130:4, error was %s\n", smbcli_errstr(cli1->tree)); + goto fail; + } else { + printf("pid1 successfully locked range 130:4 for READ\n"); + } + + if (smbcli_read(cli1->tree, fnum1, buf, 130, 4) != 4) { + printf("pid1 unable to read the range 130:4, error was %s\n", smbcli_errstr(cli1->tree)); + goto fail; + } else { + printf("pid1 successfully read the range 130:4\n"); + } + + if (smbcli_write(cli1->tree, fnum1, 0, buf, 130, 4) != 4) { + printf("pid1 unable to write to the range 130:4, error was %s\n", smbcli_errstr(cli1->tree)); + if (NT_STATUS_V(smbcli_nt_error(cli1->tree)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT)) { + printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n"); + goto fail; + } + } else { + printf("pid1 successfully wrote to the range 130:4 (should be denied)\n"); + goto fail; + } + + cli1->session->pid = 2; + + if (smbcli_read(cli1->tree, fnum1, buf, 130, 4) != 4) { + printf("pid2 unable to read the range 130:4, error was %s\n", smbcli_errstr(cli1->tree)); + } else { + printf("pid2 successfully read the range 130:4\n"); + } + + if (smbcli_write(cli1->tree, fnum1, 0, buf, 130, 4) != 4) { + printf("pid2 unable to write to the range 130:4, error was %s\n", smbcli_errstr(cli1->tree)); + if (NT_STATUS_V(smbcli_nt_error(cli1->tree)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT)) { + printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n"); + goto fail; + } + } else { + printf("pid2 successfully wrote to the range 130:4 (should be denied)\n"); + goto fail; + } + + cli1->session->pid = 1; + smbcli_unlock(cli1->tree, fnum1, 130, 4); + + if (NT_STATUS_IS_ERR(smbcli_lock(cli1->tree, fnum1, 130, 4, 0, WRITE_LOCK))) { + printf("Unable to apply write lock on range 130:4, error was %s\n", smbcli_errstr(cli1->tree)); + goto fail; + } else { + printf("pid1 successfully locked range 130:4 for WRITE\n"); + } + + if (smbcli_read(cli1->tree, fnum1, buf, 130, 4) != 4) { + printf("pid1 unable to read the range 130:4, error was %s\n", smbcli_errstr(cli1->tree)); + goto fail; + } else { + printf("pid1 successfully read the range 130:4\n"); + } + + if (smbcli_write(cli1->tree, fnum1, 0, buf, 130, 4) != 4) { + printf("pid1 unable to write to the range 130:4, error was %s\n", smbcli_errstr(cli1->tree)); + goto fail; + } else { + printf("pid1 successfully wrote to the range 130:4\n"); + } + + cli1->session->pid = 2; + + if (smbcli_read(cli1->tree, fnum1, buf, 130, 4) != 4) { + printf("pid2 unable to read the range 130:4, error was %s\n", smbcli_errstr(cli1->tree)); + if (NT_STATUS_V(smbcli_nt_error(cli1->tree)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT)) { + printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n"); + goto fail; + } + } else { + printf("pid2 successfully read the range 130:4 (should be denied)\n"); + goto fail; + } + + if (smbcli_write(cli1->tree, fnum1, 0, buf, 130, 4) != 4) { + printf("pid2 unable to write to the range 130:4, error was %s\n", smbcli_errstr(cli1->tree)); + if (NT_STATUS_V(smbcli_nt_error(cli1->tree)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT)) { + printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n"); + goto fail; + } + } else { + printf("pid2 successfully wrote to the range 130:4 (should be denied)\n"); + goto fail; + } + + printf("Testing truncate of locked file.\n"); + + fnum2 = smbcli_open(cli1->tree, fname, O_RDWR|O_TRUNC, DENY_NONE); + + if (fnum2 == -1) { + printf("Unable to truncate locked file.\n"); + correct = False; + goto fail; + } else { + printf("Truncated locked file.\n"); + } + + if (NT_STATUS_IS_ERR(smbcli_getatr(cli1->tree, fname, NULL, &size, NULL))) { + printf("getatr failed (%s)\n", smbcli_errstr(cli1->tree)); + correct = False; + goto fail; + } + + if (size != 0) { + printf("Unable to truncate locked file. Size was %u\n", size); + correct = False; + goto fail; + } + + cli1->session->pid = 1; + + smbcli_unlock(cli1->tree, fnum1, 130, 4); + correct = True; + +fail: + smbcli_close(cli1->tree, fnum1); + smbcli_close(cli1->tree, fnum2); + smbcli_unlink(cli1->tree, fname); + torture_close_connection(cli1); + + printf("finished locktest7\n"); + return correct; +} + -- cgit From d0cc571e30bf49443ac7d1b1a0b896ee72d7d9a6 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 18 Oct 2004 07:40:17 +0000 Subject: r3029: implemented byte range lock timeouts. This adds a pvfs_wait_message() routine which uses the new messaging system, event timers and talloc destructors to give a nice generic async event handling system with a easy to use interface. The extensions to pvfs_lock.c are based on calls to pvfs_wait_message() routines. We now pass all of our smbtorture locking tests, although while writing this code I have thought of some additonal tests that should be added, particularly for lock cancel operations. I'll work on that soon. This commit also extends the smbtorture lock tests to test the rather weird 0xEEFFFFFF locking semantics that I have discovered in win2003. Win2003 treats the 0xEEFFFFFF boundary as special, and will give different error codes on either side of it. Locks on both sides are allowed, the only difference is which error code is given when a lock is denied. Anyone like to hazard a guess as to why? It has me stumped. (This used to be commit 4395c0557ab175d6a8dd99df03c266325949ffa5) --- source4/torture/basic/locking.c | 89 ++++++++++++++++++++++++++++++++--------- 1 file changed, 70 insertions(+), 19 deletions(-) (limited to 'source4/torture/basic/locking.c') diff --git a/source4/torture/basic/locking.c b/source4/torture/basic/locking.c index 4708415937..387daa3101 100644 --- a/source4/torture/basic/locking.c +++ b/source4/torture/basic/locking.c @@ -76,6 +76,42 @@ BOOL torture_locktest1(int dummy) NT_STATUS_LOCK_NOT_GRANTED)) return False; } + if (NT_STATUS_IS_OK(smbcli_lock(cli2->tree, fnum3, 0, 4, 0, WRITE_LOCK))) { + printf("lock2 succeeded! This is a locking bug\n"); + return False; + } else { + if (!check_error(__location__, cli2, ERRDOS, ERRlock, + NT_STATUS_FILE_LOCK_CONFLICT)) return False; + } + + if (NT_STATUS_IS_ERR(smbcli_lock(cli1->tree, fnum1, 5, 9, 0, WRITE_LOCK))) { + printf("lock1 failed (%s)\n", smbcli_errstr(cli1->tree)); + return False; + } + + if (NT_STATUS_IS_OK(smbcli_lock(cli2->tree, fnum3, 5, 9, 0, WRITE_LOCK))) { + printf("lock2 succeeded! This is a locking bug\n"); + return False; + } else { + if (!check_error(__location__, cli2, ERRDOS, ERRlock, + NT_STATUS_LOCK_NOT_GRANTED)) return False; + } + + if (NT_STATUS_IS_OK(smbcli_lock(cli2->tree, fnum3, 0, 4, 0, WRITE_LOCK))) { + printf("lock2 succeeded! This is a locking bug\n"); + return False; + } else { + if (!check_error(__location__, cli2, ERRDOS, ERRlock, + NT_STATUS_LOCK_NOT_GRANTED)) return False; + } + + if (NT_STATUS_IS_OK(smbcli_lock(cli2->tree, fnum3, 0, 4, 0, WRITE_LOCK))) { + printf("lock2 succeeded! This is a locking bug\n"); + return False; + } else { + if (!check_error(__location__, cli2, ERRDOS, ERRlock, + NT_STATUS_FILE_LOCK_CONFLICT)) return False; + } lock_timeout = (6 + (random() % 20)); printf("Testing lock timeout with timeout=%u\n", lock_timeout); @@ -768,21 +804,23 @@ BOOL torture_locktest7(int dummy) memset(buf, 0, sizeof(buf)); if (smbcli_write(cli1->tree, fnum1, 0, buf, 0, sizeof(buf)) != sizeof(buf)) { - printf("Failed to create file\n"); + printf("Failed to create file (%s)\n", __location__); goto fail; } cli1->session->pid = 1; if (NT_STATUS_IS_ERR(smbcli_lock(cli1->tree, fnum1, 130, 4, 0, READ_LOCK))) { - printf("Unable to apply read lock on range 130:4, error was %s\n", smbcli_errstr(cli1->tree)); + printf("Unable to apply read lock on range 130:4, error was %s (%s)\n", + smbcli_errstr(cli1->tree), __location__); goto fail; } else { printf("pid1 successfully locked range 130:4 for READ\n"); } if (smbcli_read(cli1->tree, fnum1, buf, 130, 4) != 4) { - printf("pid1 unable to read the range 130:4, error was %s\n", smbcli_errstr(cli1->tree)); + printf("pid1 unable to read the range 130:4, error was %s (%s)\n", + smbcli_errstr(cli1->tree), __location__); goto fail; } else { printf("pid1 successfully read the range 130:4\n"); @@ -791,11 +829,13 @@ BOOL torture_locktest7(int dummy) if (smbcli_write(cli1->tree, fnum1, 0, buf, 130, 4) != 4) { printf("pid1 unable to write to the range 130:4, error was %s\n", smbcli_errstr(cli1->tree)); if (NT_STATUS_V(smbcli_nt_error(cli1->tree)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT)) { - printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n"); + printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT) (%s)\n", + __location__); goto fail; } } else { - printf("pid1 successfully wrote to the range 130:4 (should be denied)\n"); + printf("pid1 successfully wrote to the range 130:4 (should be denied) (%s)\n", + __location__); goto fail; } @@ -810,11 +850,13 @@ BOOL torture_locktest7(int dummy) if (smbcli_write(cli1->tree, fnum1, 0, buf, 130, 4) != 4) { printf("pid2 unable to write to the range 130:4, error was %s\n", smbcli_errstr(cli1->tree)); if (NT_STATUS_V(smbcli_nt_error(cli1->tree)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT)) { - printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n"); + printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT) (%s)\n", + __location__); goto fail; } } else { - printf("pid2 successfully wrote to the range 130:4 (should be denied)\n"); + printf("pid2 successfully wrote to the range 130:4 (should be denied) (%s)\n", + __location__); goto fail; } @@ -822,21 +864,24 @@ BOOL torture_locktest7(int dummy) smbcli_unlock(cli1->tree, fnum1, 130, 4); if (NT_STATUS_IS_ERR(smbcli_lock(cli1->tree, fnum1, 130, 4, 0, WRITE_LOCK))) { - printf("Unable to apply write lock on range 130:4, error was %s\n", smbcli_errstr(cli1->tree)); + printf("Unable to apply write lock on range 130:4, error was %s (%s)\n", + smbcli_errstr(cli1->tree), __location__); goto fail; } else { printf("pid1 successfully locked range 130:4 for WRITE\n"); } if (smbcli_read(cli1->tree, fnum1, buf, 130, 4) != 4) { - printf("pid1 unable to read the range 130:4, error was %s\n", smbcli_errstr(cli1->tree)); + printf("pid1 unable to read the range 130:4, error was %s (%s)\n", + smbcli_errstr(cli1->tree), __location__); goto fail; } else { printf("pid1 successfully read the range 130:4\n"); } if (smbcli_write(cli1->tree, fnum1, 0, buf, 130, 4) != 4) { - printf("pid1 unable to write to the range 130:4, error was %s\n", smbcli_errstr(cli1->tree)); + printf("pid1 unable to write to the range 130:4, error was %s (%s)\n", + smbcli_errstr(cli1->tree), __location__); goto fail; } else { printf("pid1 successfully wrote to the range 130:4\n"); @@ -845,24 +890,30 @@ BOOL torture_locktest7(int dummy) cli1->session->pid = 2; if (smbcli_read(cli1->tree, fnum1, buf, 130, 4) != 4) { - printf("pid2 unable to read the range 130:4, error was %s\n", smbcli_errstr(cli1->tree)); + printf("pid2 unable to read the range 130:4, error was %s\n", + smbcli_errstr(cli1->tree)); if (NT_STATUS_V(smbcli_nt_error(cli1->tree)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT)) { - printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n"); + printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT) (%s)\n", + __location__); goto fail; } } else { - printf("pid2 successfully read the range 130:4 (should be denied)\n"); + printf("pid2 successfully read the range 130:4 (should be denied) (%s)\n", + __location__); goto fail; } if (smbcli_write(cli1->tree, fnum1, 0, buf, 130, 4) != 4) { - printf("pid2 unable to write to the range 130:4, error was %s\n", smbcli_errstr(cli1->tree)); + printf("pid2 unable to write to the range 130:4, error was %s\n", + smbcli_errstr(cli1->tree)); if (NT_STATUS_V(smbcli_nt_error(cli1->tree)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT)) { - printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n"); + printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT) (%s)\n", + __location__); goto fail; } } else { - printf("pid2 successfully wrote to the range 130:4 (should be denied)\n"); + printf("pid2 successfully wrote to the range 130:4 (should be denied) (%s)\n", + __location__); goto fail; } @@ -871,7 +922,7 @@ BOOL torture_locktest7(int dummy) fnum2 = smbcli_open(cli1->tree, fname, O_RDWR|O_TRUNC, DENY_NONE); if (fnum2 == -1) { - printf("Unable to truncate locked file.\n"); + printf("Unable to truncate locked file (%s)\n", __location__); correct = False; goto fail; } else { @@ -879,13 +930,13 @@ BOOL torture_locktest7(int dummy) } if (NT_STATUS_IS_ERR(smbcli_getatr(cli1->tree, fname, NULL, &size, NULL))) { - printf("getatr failed (%s)\n", smbcli_errstr(cli1->tree)); + printf("getatr failed (%s) (%s)\n", smbcli_errstr(cli1->tree), __location__); correct = False; goto fail; } if (size != 0) { - printf("Unable to truncate locked file. Size was %u\n", size); + printf("Unable to truncate locked file. Size was %u (%s)\n", size, __location__); correct = False; goto fail; } -- cgit From ba6d5fcb97b9831dddf7dfe09fb02fbb23d864b4 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 28 Oct 2004 13:40:50 +0000 Subject: r3324: made the smbtorture code completely warning free (This used to be commit 7067bb9b52223cafa28470f264f0b60646a07a01) --- source4/torture/basic/locking.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'source4/torture/basic/locking.c') diff --git a/source4/torture/basic/locking.c b/source4/torture/basic/locking.c index 387daa3101..9683557ca8 100644 --- a/source4/torture/basic/locking.c +++ b/source4/torture/basic/locking.c @@ -30,7 +30,7 @@ must not use posix semantics) 2) support for lock timeouts */ -BOOL torture_locktest1(int dummy) +BOOL torture_locktest1(void) { struct smbcli_state *cli1, *cli2; const char *fname = "\\lockt1.lck"; @@ -184,7 +184,7 @@ BOOL torture_locktest1(int dummy) 3) the server denies unlock requests by an incorrect client PID */ -BOOL torture_locktest2(int dummy) +BOOL torture_locktest2(void) { struct smbcli_state *cli; const char *fname = "\\lockt2.lck"; @@ -322,7 +322,7 @@ BOOL torture_locktest2(int dummy) 1) the server supports the full offset range in lock requests */ -BOOL torture_locktest3(int dummy) +BOOL torture_locktest3(void) { struct smbcli_state *cli1, *cli2; const char *fname = "\\lockt3.lck"; @@ -454,7 +454,7 @@ BOOL torture_locktest3(int dummy) /* looks at overlapping locks */ -BOOL torture_locktest4(int dummy) +BOOL torture_locktest4(void) { struct smbcli_state *cli1, *cli2; const char *fname = "\\lockt4.lck"; @@ -622,7 +622,7 @@ BOOL torture_locktest4(int dummy) /* looks at lock upgrade/downgrade. */ -BOOL torture_locktest5(int dummy) +BOOL torture_locktest5(void) { struct smbcli_state *cli1, *cli2; const char *fname = "\\lockt5.lck"; @@ -743,7 +743,7 @@ ret = NT_STATUS_IS_OK(smbcli_unlock(cli1->tree, fnum1, 0, 4)) && /* tries the unusual lockingX locktype bits */ -BOOL torture_locktest6(int dummy) +BOOL torture_locktest6(void) { struct smbcli_state *cli; const char *fname[1] = { "\\lock6.txt" }; @@ -781,7 +781,7 @@ BOOL torture_locktest6(int dummy) return True; } -BOOL torture_locktest7(int dummy) +BOOL torture_locktest7(void) { struct smbcli_state *cli1; const char *fname = "\\lockt7.lck"; -- cgit From 9f1210a243654fd6d94acdef83f468a33c1b3b3f Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 1 Nov 2004 01:03:22 +0000 Subject: r3419: moved the libcli/raw structures into libcli/raw/libcliraw.h and made them private (This used to be commit 386ac565c452ede1d74e06acb401ca9db99d3ff3) --- source4/torture/basic/locking.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source4/torture/basic/locking.c') diff --git a/source4/torture/basic/locking.c b/source4/torture/basic/locking.c index 9683557ca8..00187cbeac 100644 --- a/source4/torture/basic/locking.c +++ b/source4/torture/basic/locking.c @@ -22,6 +22,7 @@ */ #include "includes.h" +#include "libcli/raw/libcliraw.h" /* This test checks for two things: -- cgit From ead3508ac81ff3ed2a48753f3b5e23537ba6ec73 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 2 Nov 2004 00:24:21 +0000 Subject: r3447: more include/system/XXX.h include files (This used to be commit 264ce9181089922547e8f6f67116f2d7277a5105) --- source4/torture/basic/locking.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source4/torture/basic/locking.c') diff --git a/source4/torture/basic/locking.c b/source4/torture/basic/locking.c index 00187cbeac..aea94bd5a1 100644 --- a/source4/torture/basic/locking.c +++ b/source4/torture/basic/locking.c @@ -23,6 +23,7 @@ #include "includes.h" #include "libcli/raw/libcliraw.h" +#include "system/time.h" /* This test checks for two things: -- cgit From a9158e0d47636e25ce374391cd9b02df3d27b390 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 6 Nov 2004 09:12:53 +0000 Subject: r3574: the RAW-OPEN test changes broke a couple of the other tests. This fixes most of them, although RAW-SEARCH still fails (due to an interaction with the new xattr code) (This used to be commit 09b4652b40c4cfca027765178bd5a0adbaa666c2) --- source4/torture/basic/locking.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'source4/torture/basic/locking.c') diff --git a/source4/torture/basic/locking.c b/source4/torture/basic/locking.c index aea94bd5a1..c1dd598018 100644 --- a/source4/torture/basic/locking.c +++ b/source4/torture/basic/locking.c @@ -55,7 +55,8 @@ BOOL torture_locktest1(void) } fnum2 = smbcli_open(cli1->tree, fname, O_RDWR, DENY_NONE); if (fnum2 == -1) { - printf("open2 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree)); + printf("(%s) open2 of %s failed (%s)\n", + __location__, fname, smbcli_errstr(cli1->tree)); return False; } fnum3 = smbcli_open(cli2->tree, fname, O_RDWR, DENY_NONE); @@ -213,7 +214,8 @@ BOOL torture_locktest2(void) fnum2 = smbcli_open(cli->tree, fname, O_RDWR, DENY_NONE); if (fnum2 == -1) { - printf("open2 of %s failed (%s)\n", fname, smbcli_errstr(cli->tree)); + printf("(%s) open2 of %s failed (%s)\n", + __location__, fname, smbcli_errstr(cli->tree)); return False; } -- cgit From 4183b2ac3832cdc2055d7eb3ed7121a9ea91085c Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 2 Dec 2004 04:51:56 +0000 Subject: r4037: fixed a bunch of "might be uninitialised" warnings after enabling -O1 in my compile (This used to be commit 0928b1f5b68c858922c3ea6c27ed03b5091c6221) --- source4/torture/basic/locking.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/torture/basic/locking.c') diff --git a/source4/torture/basic/locking.c b/source4/torture/basic/locking.c index c1dd598018..ba7d568706 100644 --- a/source4/torture/basic/locking.c +++ b/source4/torture/basic/locking.c @@ -790,7 +790,7 @@ BOOL torture_locktest7(void) struct smbcli_state *cli1; const char *fname = "\\lockt7.lck"; int fnum1; - int fnum2; + int fnum2 = -1; size_t size; char buf[200]; BOOL correct = False; -- cgit From 9112a632f6791ffc3c3c1aadd214cbaba8fe816e Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Sat, 4 Dec 2004 13:56:25 +0000 Subject: r4063: - change char * -> uint8_t in struct request_buffer - change smbcli_read/write to take void * for the buffers to match read(2)/write(2) all this fixes a lot of gcc-4 warnings metze (This used to be commit b94f92bc6637f748d6f7049f4f9a30b0b8d18a7a) --- source4/torture/basic/locking.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source4/torture/basic/locking.c') diff --git a/source4/torture/basic/locking.c b/source4/torture/basic/locking.c index ba7d568706..7a1a13762b 100644 --- a/source4/torture/basic/locking.c +++ b/source4/torture/basic/locking.c @@ -464,7 +464,7 @@ BOOL torture_locktest4(void) const char *fname = "\\lockt4.lck"; int fnum1, fnum2, f; BOOL ret; - char buf[1000]; + uint8_t buf[1000]; BOOL correct = True; if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) { @@ -632,7 +632,7 @@ BOOL torture_locktest5(void) const char *fname = "\\lockt5.lck"; int fnum1, fnum2, fnum3; BOOL ret; - char buf[1000]; + uint8_t buf[1000]; BOOL correct = True; if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) { @@ -792,7 +792,7 @@ BOOL torture_locktest7(void) int fnum1; int fnum2 = -1; size_t size; - char buf[200]; + uint8_t buf[200]; BOOL correct = False; if (!torture_open_connection(&cli1)) { -- cgit From e0a40dec0956ae08fa7bc11f9be9a036f8d6dedf Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 31 Dec 2004 04:17:03 +0000 Subject: r4430: - fixed the BASE-LOCK* tests to use a subdirectory, and properly setup the directory before each test, thus avoiding errors due to previous failures (This used to be commit a44fa5319d87e57f4b904334d9ea65cc6807b789) --- source4/torture/basic/locking.c | 42 +++++++++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 12 deletions(-) (limited to 'source4/torture/basic/locking.c') diff --git a/source4/torture/basic/locking.c b/source4/torture/basic/locking.c index 7a1a13762b..00310e5405 100644 --- a/source4/torture/basic/locking.c +++ b/source4/torture/basic/locking.c @@ -25,6 +25,8 @@ #include "libcli/raw/libcliraw.h" #include "system/time.h" +#define BASEDIR "\\locktest" + /* This test checks for two things: @@ -35,7 +37,7 @@ BOOL torture_locktest1(void) { struct smbcli_state *cli1, *cli2; - const char *fname = "\\lockt1.lck"; + const char *fname = BASEDIR "\\lockt1.lck"; int fnum1, fnum2, fnum3; time_t t1, t2; uint_t lock_timeout; @@ -46,7 +48,9 @@ BOOL torture_locktest1(void) printf("starting locktest1\n"); - smbcli_unlink(cli1->tree, fname); + if (!torture_setup_dir(cli1, BASEDIR)) { + return False; + } fnum1 = smbcli_open(cli1->tree, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE); if (fnum1 == -1) { @@ -190,7 +194,7 @@ BOOL torture_locktest1(void) BOOL torture_locktest2(void) { struct smbcli_state *cli; - const char *fname = "\\lockt2.lck"; + const char *fname = BASEDIR "\\lockt2.lck"; int fnum1, fnum2, fnum3; BOOL correct = True; @@ -200,7 +204,9 @@ BOOL torture_locktest2(void) printf("starting locktest2\n"); - smbcli_unlink(cli->tree, fname); + if (!torture_setup_dir(cli, BASEDIR)) { + return False; + } printf("Testing pid context\n"); @@ -329,7 +335,7 @@ BOOL torture_locktest2(void) BOOL torture_locktest3(void) { struct smbcli_state *cli1, *cli2; - const char *fname = "\\lockt3.lck"; + const char *fname = BASEDIR "\\lockt3.lck"; int fnum1, fnum2, i; uint32_t offset; BOOL correct = True; @@ -345,7 +351,9 @@ BOOL torture_locktest3(void) printf("Testing 32 bit offset ranges\n"); - smbcli_unlink(cli1->tree, fname); + if (!torture_setup_dir(cli1, BASEDIR)) { + return False; + } fnum1 = smbcli_open(cli1->tree, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE); if (fnum1 == -1) { @@ -461,7 +469,7 @@ BOOL torture_locktest3(void) BOOL torture_locktest4(void) { struct smbcli_state *cli1, *cli2; - const char *fname = "\\lockt4.lck"; + const char *fname = BASEDIR "\\lockt4.lck"; int fnum1, fnum2, f; BOOL ret; uint8_t buf[1000]; @@ -473,7 +481,9 @@ BOOL torture_locktest4(void) printf("starting locktest4\n"); - smbcli_unlink(cli1->tree, fname); + if (!torture_setup_dir(cli1, BASEDIR)) { + return False; + } fnum1 = smbcli_open(cli1->tree, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE); fnum2 = smbcli_open(cli2->tree, fname, O_RDWR, DENY_NONE); @@ -629,7 +639,7 @@ BOOL torture_locktest4(void) BOOL torture_locktest5(void) { struct smbcli_state *cli1, *cli2; - const char *fname = "\\lockt5.lck"; + const char *fname = BASEDIR "\\lockt5.lck"; int fnum1, fnum2, fnum3; BOOL ret; uint8_t buf[1000]; @@ -641,7 +651,9 @@ BOOL torture_locktest5(void) printf("starting locktest5\n"); - smbcli_unlink(cli1->tree, fname); + if (!torture_setup_dir(cli1, BASEDIR)) { + return False; + } fnum1 = smbcli_open(cli1->tree, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE); fnum2 = smbcli_open(cli2->tree, fname, O_RDWR, DENY_NONE); @@ -759,6 +771,10 @@ BOOL torture_locktest6(void) return False; } + if (!torture_setup_dir(cli, BASEDIR)) { + return False; + } + printf("starting locktest6\n"); for (i=0;i<1;i++) { @@ -788,7 +804,7 @@ BOOL torture_locktest6(void) BOOL torture_locktest7(void) { struct smbcli_state *cli1; - const char *fname = "\\lockt7.lck"; + const char *fname = BASEDIR "\\lockt7.lck"; int fnum1; int fnum2 = -1; size_t size; @@ -801,7 +817,9 @@ BOOL torture_locktest7(void) printf("starting locktest7\n"); - smbcli_unlink(cli1->tree, fname); + if (!torture_setup_dir(cli1, BASEDIR)) { + return False; + } fnum1 = smbcli_open(cli1->tree, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE); -- 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/locking.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source4/torture/basic/locking.c') diff --git a/source4/torture/basic/locking.c b/source4/torture/basic/locking.c index 00310e5405..c3feaae2eb 100644 --- a/source4/torture/basic/locking.c +++ b/source4/torture/basic/locking.c @@ -24,6 +24,7 @@ #include "includes.h" #include "libcli/raw/libcliraw.h" #include "system/time.h" +#include "system/filesys.h" #define BASEDIR "\\locktest" -- cgit From fee56ea90040a020cfe1938a3678effa00b772d4 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 4 Jul 2005 05:05:28 +0000 Subject: r8117: fixed a bunch more dos error code handing. The biggest change was fixing the RAW-CONTEXT test. It was forcing capabilities to zero in an attempt to not negotiated extended security, but as a side effect it was forcing negotiation of dos error codes. This confused the hell out of the test code! Also fixed a bunch of places incorrectly using NT_STATUS_V() instead of NT_STATUS_EQUAL() and several places that had the wrong dos status codes (This used to be commit 0b22744f40804a0d6dc94bfc40ec09306f584f7e) --- source4/torture/basic/locking.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'source4/torture/basic/locking.c') diff --git a/source4/torture/basic/locking.c b/source4/torture/basic/locking.c index c3feaae2eb..3f395f3907 100644 --- a/source4/torture/basic/locking.c +++ b/source4/torture/basic/locking.c @@ -281,7 +281,7 @@ BOOL torture_locktest2(void) correct = False; } else { if (!check_error(__location__, cli, - ERRDOS, ERRlock, + ERRDOS, ERRnotlocked, NT_STATUS_RANGE_NOT_LOCKED)) return False; } @@ -290,7 +290,7 @@ BOOL torture_locktest2(void) correct = False; } else { if (!check_error(__location__, cli, - ERRDOS, ERRlock, + ERRDOS, ERRnotlocked, NT_STATUS_RANGE_NOT_LOCKED)) return False; } @@ -851,7 +851,7 @@ BOOL torture_locktest7(void) if (smbcli_write(cli1->tree, fnum1, 0, buf, 130, 4) != 4) { printf("pid1 unable to write to the range 130:4, error was %s\n", smbcli_errstr(cli1->tree)); - if (NT_STATUS_V(smbcli_nt_error(cli1->tree)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT)) { + if (!NT_STATUS_EQUAL(smbcli_nt_error(cli1->tree), NT_STATUS_FILE_LOCK_CONFLICT)) { printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT) (%s)\n", __location__); goto fail; @@ -872,7 +872,7 @@ BOOL torture_locktest7(void) if (smbcli_write(cli1->tree, fnum1, 0, buf, 130, 4) != 4) { printf("pid2 unable to write to the range 130:4, error was %s\n", smbcli_errstr(cli1->tree)); - if (NT_STATUS_V(smbcli_nt_error(cli1->tree)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT)) { + if (!NT_STATUS_EQUAL(smbcli_nt_error(cli1->tree), NT_STATUS_FILE_LOCK_CONFLICT)) { printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT) (%s)\n", __location__); goto fail; @@ -915,7 +915,7 @@ BOOL torture_locktest7(void) if (smbcli_read(cli1->tree, fnum1, buf, 130, 4) != 4) { printf("pid2 unable to read the range 130:4, error was %s\n", smbcli_errstr(cli1->tree)); - if (NT_STATUS_V(smbcli_nt_error(cli1->tree)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT)) { + if (!NT_STATUS_EQUAL(smbcli_nt_error(cli1->tree), NT_STATUS_FILE_LOCK_CONFLICT)) { printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT) (%s)\n", __location__); goto fail; @@ -929,7 +929,7 @@ BOOL torture_locktest7(void) if (smbcli_write(cli1->tree, fnum1, 0, buf, 130, 4) != 4) { printf("pid2 unable to write to the range 130:4, error was %s\n", smbcli_errstr(cli1->tree)); - if (NT_STATUS_V(smbcli_nt_error(cli1->tree)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT)) { + if (!NT_STATUS_EQUAL(smbcli_nt_error(cli1->tree), NT_STATUS_FILE_LOCK_CONFLICT)) { printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT) (%s)\n", __location__); goto fail; -- 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/locking.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source4/torture/basic/locking.c') diff --git a/source4/torture/basic/locking.c b/source4/torture/basic/locking.c index 3f395f3907..3ab26c3879 100644 --- a/source4/torture/basic/locking.c +++ b/source4/torture/basic/locking.c @@ -959,7 +959,8 @@ BOOL torture_locktest7(void) } if (size != 0) { - printf("Unable to truncate locked file. Size was %u (%s)\n", size, __location__); + printf("Unable to truncate locked file. Size was %u (%s)\n", + (unsigned)size, __location__); correct = False; goto fail; } -- 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/locking.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source4/torture/basic/locking.c') diff --git a/source4/torture/basic/locking.c b/source4/torture/basic/locking.c index 3ab26c3879..e07d0648a7 100644 --- a/source4/torture/basic/locking.c +++ b/source4/torture/basic/locking.c @@ -22,6 +22,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/locking.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source4/torture/basic/locking.c') diff --git a/source4/torture/basic/locking.c b/source4/torture/basic/locking.c index e07d0648a7..307bb0fafc 100644 --- a/source4/torture/basic/locking.c +++ b/source4/torture/basic/locking.c @@ -24,6 +24,7 @@ #include "includes.h" #include "torture/torture.h" #include "libcli/raw/libcliraw.h" +#include "libcli/libcli.h" #include "system/time.h" #include "system/filesys.h" -- cgit From eefe30b7d8e17ed744318417954669bacf2b3ac0 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 14 Mar 2006 15:02:05 +0000 Subject: r14379: Build torture/rpc/ as a seperate smbtorture module. Move helper functions for rpc out of torture/torture.c (This used to be commit 1d2d970f3b8aef3f36c2befb94b5dd72c0086639) --- source4/torture/basic/locking.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/torture/basic/locking.c') diff --git a/source4/torture/basic/locking.c b/source4/torture/basic/locking.c index 307bb0fafc..9a00ab3efa 100644 --- a/source4/torture/basic/locking.c +++ b/source4/torture/basic/locking.c @@ -22,9 +22,9 @@ */ #include "includes.h" -#include "torture/torture.h" #include "libcli/raw/libcliraw.h" #include "libcli/libcli.h" +#include "torture/torture.h" #include "system/time.h" #include "system/filesys.h" -- 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/locking.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source4/torture/basic/locking.c') diff --git a/source4/torture/basic/locking.c b/source4/torture/basic/locking.c index 9a00ab3efa..65f2dbac31 100644 --- a/source4/torture/basic/locking.c +++ b/source4/torture/basic/locking.c @@ -24,6 +24,7 @@ #include "includes.h" #include "libcli/raw/libcliraw.h" #include "libcli/libcli.h" +#include "torture/util.h" #include "torture/torture.h" #include "system/time.h" #include "system/filesys.h" -- 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/locking.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'source4/torture/basic/locking.c') diff --git a/source4/torture/basic/locking.c b/source4/torture/basic/locking.c index 65f2dbac31..1ee7572967 100644 --- a/source4/torture/basic/locking.c +++ b/source4/torture/basic/locking.c @@ -38,7 +38,7 @@ must not use posix semantics) 2) support for lock timeouts */ -BOOL torture_locktest1(void) +BOOL torture_locktest1(struct torture_context *torture) { struct smbcli_state *cli1, *cli2; const char *fname = BASEDIR "\\lockt1.lck"; @@ -195,7 +195,7 @@ BOOL torture_locktest1(void) 3) the server denies unlock requests by an incorrect client PID */ -BOOL torture_locktest2(void) +BOOL torture_locktest2(struct torture_context *torture) { struct smbcli_state *cli; const char *fname = BASEDIR "\\lockt2.lck"; @@ -336,7 +336,7 @@ BOOL torture_locktest2(void) 1) the server supports the full offset range in lock requests */ -BOOL torture_locktest3(void) +BOOL torture_locktest3(struct torture_context *torture) { struct smbcli_state *cli1, *cli2; const char *fname = BASEDIR "\\lockt3.lck"; @@ -470,7 +470,7 @@ BOOL torture_locktest3(void) /* looks at overlapping locks */ -BOOL torture_locktest4(void) +BOOL torture_locktest4(struct torture_context *torture) { struct smbcli_state *cli1, *cli2; const char *fname = BASEDIR "\\lockt4.lck"; @@ -640,7 +640,7 @@ BOOL torture_locktest4(void) /* looks at lock upgrade/downgrade. */ -BOOL torture_locktest5(void) +BOOL torture_locktest5(struct torture_context *torture) { struct smbcli_state *cli1, *cli2; const char *fname = BASEDIR "\\lockt5.lck"; @@ -763,7 +763,7 @@ ret = NT_STATUS_IS_OK(smbcli_unlock(cli1->tree, fnum1, 0, 4)) && /* tries the unusual lockingX locktype bits */ -BOOL torture_locktest6(void) +BOOL torture_locktest6(struct torture_context *torture) { struct smbcli_state *cli; const char *fname[1] = { "\\lock6.txt" }; @@ -805,7 +805,7 @@ BOOL torture_locktest6(void) return True; } -BOOL torture_locktest7(void) +BOOL torture_locktest7(struct torture_context *torture) { struct smbcli_state *cli1; const char *fname = BASEDIR "\\lockt7.lck"; -- 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/locking.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'source4/torture/basic/locking.c') diff --git a/source4/torture/basic/locking.c b/source4/torture/basic/locking.c index 1ee7572967..c4aae64ca8 100644 --- a/source4/torture/basic/locking.c +++ b/source4/torture/basic/locking.c @@ -46,7 +46,8 @@ BOOL torture_locktest1(struct torture_context *torture) time_t t1, t2; uint_t lock_timeout; - if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) { + if (!torture_open_connection(&cli1, 0) || + !torture_open_connection(&cli2, 1)) { return False; } @@ -202,7 +203,7 @@ BOOL torture_locktest2(struct torture_context *torture) int fnum1, fnum2, fnum3; BOOL correct = True; - if (!torture_open_connection(&cli)) { + if (!torture_open_connection(&cli, 0)) { return False; } @@ -347,7 +348,8 @@ BOOL torture_locktest3(struct torture_context *torture) #define NEXT_OFFSET offset += (~(uint32_t)0) / torture_numops - if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) { + if (!torture_open_connection(&cli1, 0) || + !torture_open_connection(&cli2, 1)) { return False; } @@ -479,7 +481,8 @@ BOOL torture_locktest4(struct torture_context *torture) uint8_t buf[1000]; BOOL correct = True; - if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) { + if (!torture_open_connection(&cli1, 0) || + !torture_open_connection(&cli2, 1)) { return False; } @@ -649,7 +652,8 @@ BOOL torture_locktest5(struct torture_context *torture) uint8_t buf[1000]; BOOL correct = True; - if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) { + if (!torture_open_connection(&cli1, 0) || + !torture_open_connection(&cli2, 1)) { return False; } @@ -771,7 +775,7 @@ BOOL torture_locktest6(struct torture_context *torture) int fnum; NTSTATUS status; - if (!torture_open_connection(&cli)) { + if (!torture_open_connection(&cli, 0)) { return False; } @@ -815,7 +819,7 @@ BOOL torture_locktest7(struct torture_context *torture) uint8_t buf[200]; BOOL correct = False; - if (!torture_open_connection(&cli1)) { + if (!torture_open_connection(&cli1, 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/locking.c | 751 +++++++++++++++------------------------- 1 file changed, 287 insertions(+), 464 deletions(-) (limited to 'source4/torture/basic/locking.c') diff --git a/source4/torture/basic/locking.c b/source4/torture/basic/locking.c index c4aae64ca8..c966c667e6 100644 --- a/source4/torture/basic/locking.c +++ b/source4/torture/basic/locking.c @@ -24,6 +24,7 @@ #include "includes.h" #include "libcli/raw/libcliraw.h" #include "libcli/libcli.h" +#include "torture/ui.h" #include "torture/util.h" #include "torture/torture.h" #include "system/time.h" @@ -38,150 +39,113 @@ must not use posix semantics) 2) support for lock timeouts */ -BOOL torture_locktest1(struct torture_context *torture) +bool torture_locktest1(struct torture_context *tctx, + struct smbcli_state *cli1, + struct smbcli_state *cli2) { - struct smbcli_state *cli1, *cli2; const char *fname = BASEDIR "\\lockt1.lck"; int fnum1, fnum2, fnum3; time_t t1, t2; uint_t lock_timeout; - if (!torture_open_connection(&cli1, 0) || - !torture_open_connection(&cli2, 1)) { - return False; - } - - printf("starting locktest1\n"); - if (!torture_setup_dir(cli1, BASEDIR)) { return False; } fnum1 = smbcli_open(cli1->tree, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE); - if (fnum1 == -1) { - printf("open of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree)); - return False; - } + torture_assert(tctx, fnum1 != -1, + talloc_asprintf(tctx, + "open of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree))); fnum2 = smbcli_open(cli1->tree, fname, O_RDWR, DENY_NONE); - if (fnum2 == -1) { - printf("(%s) open2 of %s failed (%s)\n", - __location__, fname, smbcli_errstr(cli1->tree)); - return False; - } + torture_assert(tctx, fnum2 != -1, talloc_asprintf(tctx, + "open2 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree))); fnum3 = smbcli_open(cli2->tree, fname, O_RDWR, DENY_NONE); - if (fnum3 == -1) { - printf("open3 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree)); - return False; - } + torture_assert(tctx, fnum3 != -1, talloc_asprintf(tctx, + "open3 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree))); - if (NT_STATUS_IS_ERR(smbcli_lock(cli1->tree, fnum1, 0, 4, 0, WRITE_LOCK))) { - printf("lock1 failed (%s)\n", smbcli_errstr(cli1->tree)); - return False; - } + torture_assert_ntstatus_ok(tctx, + smbcli_lock(cli1->tree, fnum1, 0, 4, 0, WRITE_LOCK), + talloc_asprintf(tctx, "lock1 failed (%s)", smbcli_errstr(cli1->tree))); + torture_assert(tctx, + !NT_STATUS_IS_OK(smbcli_lock(cli2->tree, fnum3, 0, 4, 0, WRITE_LOCK)), + "lock2 succeeded! This is a locking bug\n"); - if (NT_STATUS_IS_OK(smbcli_lock(cli2->tree, fnum3, 0, 4, 0, WRITE_LOCK))) { - printf("lock2 succeeded! This is a locking bug\n"); - return False; - } else { - if (!check_error(__location__, cli2, ERRDOS, ERRlock, - NT_STATUS_LOCK_NOT_GRANTED)) return False; - } + if (!check_error(__location__, cli2, ERRDOS, ERRlock, + NT_STATUS_LOCK_NOT_GRANTED)) return False; - if (NT_STATUS_IS_OK(smbcli_lock(cli2->tree, fnum3, 0, 4, 0, WRITE_LOCK))) { - printf("lock2 succeeded! This is a locking bug\n"); - return False; - } else { - if (!check_error(__location__, cli2, ERRDOS, ERRlock, + torture_assert(tctx, + !NT_STATUS_IS_OK(smbcli_lock(cli2->tree, fnum3, 0, 4, 0, WRITE_LOCK)), + "lock2 succeeded! This is a locking bug\n"); + + if (!check_error(__location__, cli2, ERRDOS, ERRlock, NT_STATUS_FILE_LOCK_CONFLICT)) return False; - } - if (NT_STATUS_IS_ERR(smbcli_lock(cli1->tree, fnum1, 5, 9, 0, WRITE_LOCK))) { - printf("lock1 failed (%s)\n", smbcli_errstr(cli1->tree)); - return False; - } + torture_assert_ntstatus_ok(tctx, + smbcli_lock(cli1->tree, fnum1, 5, 9, 0, WRITE_LOCK), + talloc_asprintf(tctx, + "lock1 failed (%s)", smbcli_errstr(cli1->tree))); - if (NT_STATUS_IS_OK(smbcli_lock(cli2->tree, fnum3, 5, 9, 0, WRITE_LOCK))) { - printf("lock2 succeeded! This is a locking bug\n"); - return False; - } else { - if (!check_error(__location__, cli2, ERRDOS, ERRlock, + torture_assert(tctx, + !NT_STATUS_IS_OK(smbcli_lock(cli2->tree, fnum3, 5, 9, 0, WRITE_LOCK)), + "lock2 succeeded! This is a locking bug"); + + if (!check_error(__location__, cli2, ERRDOS, ERRlock, NT_STATUS_LOCK_NOT_GRANTED)) return False; - } - if (NT_STATUS_IS_OK(smbcli_lock(cli2->tree, fnum3, 0, 4, 0, WRITE_LOCK))) { - printf("lock2 succeeded! This is a locking bug\n"); - return False; - } else { - if (!check_error(__location__, cli2, ERRDOS, ERRlock, + torture_assert(tctx, + !NT_STATUS_IS_OK(smbcli_lock(cli2->tree, fnum3, 0, 4, 0, WRITE_LOCK)), + "lock2 succeeded! This is a locking bug"); + + if (!check_error(__location__, cli2, ERRDOS, ERRlock, NT_STATUS_LOCK_NOT_GRANTED)) return False; - } - if (NT_STATUS_IS_OK(smbcli_lock(cli2->tree, fnum3, 0, 4, 0, WRITE_LOCK))) { - printf("lock2 succeeded! This is a locking bug\n"); - return False; - } else { - if (!check_error(__location__, cli2, ERRDOS, ERRlock, - NT_STATUS_FILE_LOCK_CONFLICT)) return False; - } + torture_assert(tctx, + !NT_STATUS_IS_OK(smbcli_lock(cli2->tree, fnum3, 0, 4, 0, WRITE_LOCK)), + "lock2 succeeded! This is a locking bug"); + + if (!check_error(__location__, cli2, ERRDOS, ERRlock, + NT_STATUS_FILE_LOCK_CONFLICT)) return False; lock_timeout = (6 + (random() % 20)); - printf("Testing lock timeout with timeout=%u\n", lock_timeout); + torture_comment(tctx, "Testing lock timeout with timeout=%u\n", + lock_timeout); t1 = time(NULL); - if (NT_STATUS_IS_OK(smbcli_lock(cli2->tree, fnum3, 0, 4, lock_timeout * 1000, WRITE_LOCK))) { - printf("lock3 succeeded! This is a locking bug\n"); - return False; - } else { - if (!check_error(__location__, cli2, ERRDOS, ERRlock, + torture_assert(tctx, + !NT_STATUS_IS_OK(smbcli_lock(cli2->tree, fnum3, 0, 4, lock_timeout * 1000, WRITE_LOCK)), + "lock3 succeeded! This is a locking bug\n"); + + if (!check_error(__location__, cli2, ERRDOS, ERRlock, NT_STATUS_FILE_LOCK_CONFLICT)) return False; - } t2 = time(NULL); if (t2 - t1 < 5) { - printf("error: This server appears not to support timed lock requests\n"); + torture_fail(tctx, + "error: This server appears not to support timed lock requests"); } - printf("server slept for %u seconds for a %u second timeout\n", + torture_comment(tctx, "server slept for %u seconds for a %u second timeout\n", (uint_t)(t2-t1), lock_timeout); - if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum2))) { - printf("close1 failed (%s)\n", smbcli_errstr(cli1->tree)); - return False; - } + torture_assert_ntstatus_ok(tctx, smbcli_close(cli1->tree, fnum2), + talloc_asprintf(tctx, "close1 failed (%s)", smbcli_errstr(cli1->tree))); - if (NT_STATUS_IS_OK(smbcli_lock(cli2->tree, fnum3, 0, 4, 0, WRITE_LOCK))) { - printf("lock4 succeeded! This is a locking bug\n"); - return False; - } else { - if (!check_error(__location__, cli2, ERRDOS, ERRlock, - NT_STATUS_FILE_LOCK_CONFLICT)) return False; - } - - if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) { - printf("close2 failed (%s)\n", smbcli_errstr(cli1->tree)); - return False; - } - - if (NT_STATUS_IS_ERR(smbcli_close(cli2->tree, fnum3))) { - printf("close3 failed (%s)\n", smbcli_errstr(cli2->tree)); - return False; - } + torture_assert(tctx, + !NT_STATUS_IS_OK(smbcli_lock(cli2->tree, fnum3, 0, 4, 0, WRITE_LOCK)), + "lock4 succeeded! This is a locking bug"); + + if (!check_error(__location__, cli2, ERRDOS, ERRlock, + NT_STATUS_FILE_LOCK_CONFLICT)) return False; - if (NT_STATUS_IS_ERR(smbcli_unlink(cli1->tree, fname))) { - printf("unlink failed (%s)\n", smbcli_errstr(cli1->tree)); - return False; - } + torture_assert_ntstatus_ok(tctx, smbcli_close(cli1->tree, fnum1), + talloc_asprintf(tctx, "close2 failed (%s)", smbcli_errstr(cli1->tree))); + torture_assert_ntstatus_ok(tctx, smbcli_close(cli2->tree, fnum3), + talloc_asprintf(tctx, "close3 failed (%s)", smbcli_errstr(cli2->tree))); - if (!torture_close_connection(cli1)) { - return False; - } - - if (!torture_close_connection(cli2)) { - return False; - } + torture_assert_ntstatus_ok(tctx, smbcli_unlink(cli1->tree, fname), + talloc_asprintf(tctx, "unlink failed (%s)", smbcli_errstr(cli1->tree))); - printf("Passed locktest1\n"); - return True; + return true; } @@ -196,139 +160,110 @@ BOOL torture_locktest1(struct torture_context *torture) 3) the server denies unlock requests by an incorrect client PID */ -BOOL torture_locktest2(struct torture_context *torture) +bool torture_locktest2(struct torture_context *tctx, + struct smbcli_state *cli) { - struct smbcli_state *cli; const char *fname = BASEDIR "\\lockt2.lck"; int fnum1, fnum2, fnum3; - BOOL correct = True; - - if (!torture_open_connection(&cli, 0)) { - return False; - } - - printf("starting locktest2\n"); if (!torture_setup_dir(cli, BASEDIR)) { return False; } - printf("Testing pid context\n"); + torture_comment(tctx, "Testing pid context\n"); cli->session->pid = 1; fnum1 = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE); - if (fnum1 == -1) { - printf("open of %s failed (%s)\n", fname, smbcli_errstr(cli->tree)); - return False; - } + torture_assert(tctx, fnum1 != -1, + talloc_asprintf(tctx, + "open of %s failed (%s)", fname, smbcli_errstr(cli->tree))); fnum2 = smbcli_open(cli->tree, fname, O_RDWR, DENY_NONE); - if (fnum2 == -1) { - printf("(%s) open2 of %s failed (%s)\n", - __location__, fname, smbcli_errstr(cli->tree)); - return False; - } + torture_assert(tctx, fnum2 != -1, + talloc_asprintf(tctx, "open2 of %s failed (%s)", + fname, smbcli_errstr(cli->tree))); cli->session->pid = 2; fnum3 = smbcli_open(cli->tree, fname, O_RDWR, DENY_NONE); - if (fnum3 == -1) { - printf("open3 of %s failed (%s)\n", fname, smbcli_errstr(cli->tree)); - return False; - } + torture_assert(tctx, fnum3 != -1, + talloc_asprintf(tctx, + "open3 of %s failed (%s)\n", fname, smbcli_errstr(cli->tree))); cli->session->pid = 1; - if (NT_STATUS_IS_ERR(smbcli_lock(cli->tree, fnum1, 0, 4, 0, WRITE_LOCK))) { - printf("lock1 failed (%s)\n", smbcli_errstr(cli->tree)); - return False; - } + torture_assert_ntstatus_ok(tctx, + smbcli_lock(cli->tree, fnum1, 0, 4, 0, WRITE_LOCK), + talloc_asprintf(tctx, + "lock1 failed (%s)", smbcli_errstr(cli->tree))); - if (NT_STATUS_IS_OK(smbcli_lock(cli->tree, fnum1, 0, 4, 0, WRITE_LOCK))) { - printf("WRITE lock1 succeeded! This is a locking bug\n"); - correct = False; - } else { - if (!check_error(__location__, cli, ERRDOS, ERRlock, - NT_STATUS_LOCK_NOT_GRANTED)) return False; - } + torture_assert(tctx, + !NT_STATUS_IS_OK(smbcli_lock(cli->tree, fnum1, 0, 4, 0, WRITE_LOCK)), + "WRITE lock1 succeeded! This is a locking bug"); + + if (!check_error(__location__, cli, ERRDOS, ERRlock, + NT_STATUS_LOCK_NOT_GRANTED)) return False; - if (NT_STATUS_IS_OK(smbcli_lock(cli->tree, fnum2, 0, 4, 0, WRITE_LOCK))) { - printf("WRITE lock2 succeeded! This is a locking bug\n"); - correct = False; - } else { - if (!check_error(__location__, cli, ERRDOS, ERRlock, - NT_STATUS_LOCK_NOT_GRANTED)) return False; - } + torture_assert(tctx, + !NT_STATUS_IS_OK(smbcli_lock(cli->tree, fnum2, 0, 4, 0, WRITE_LOCK)), + "WRITE lock2 succeeded! This is a locking bug"); - if (NT_STATUS_IS_OK(smbcli_lock(cli->tree, fnum2, 0, 4, 0, READ_LOCK))) { - printf("READ lock2 succeeded! This is a locking bug\n"); - correct = False; - } else { - if (!check_error(__location__, cli, ERRDOS, ERRlock, - NT_STATUS_FILE_LOCK_CONFLICT)) return False; - } + if (!check_error(__location__, cli, ERRDOS, ERRlock, + NT_STATUS_LOCK_NOT_GRANTED)) return False; - if (NT_STATUS_IS_ERR(smbcli_lock(cli->tree, fnum1, 100, 4, 0, WRITE_LOCK))) { - printf("lock at 100 failed (%s)\n", smbcli_errstr(cli->tree)); - } + torture_assert(tctx, + !NT_STATUS_IS_OK(smbcli_lock(cli->tree, fnum2, 0, 4, 0, READ_LOCK)), + "READ lock2 succeeded! This is a locking bug"); + + if (!check_error(__location__, cli, ERRDOS, ERRlock, + NT_STATUS_FILE_LOCK_CONFLICT)) return False; + + torture_assert_ntstatus_ok(tctx, + smbcli_lock(cli->tree, fnum1, 100, 4, 0, WRITE_LOCK), + talloc_asprintf(tctx, + "lock at 100 failed (%s)", smbcli_errstr(cli->tree))); cli->session->pid = 2; - if (NT_STATUS_IS_OK(smbcli_unlock(cli->tree, fnum1, 100, 4))) { - printf("unlock at 100 succeeded! This is a locking bug\n"); - correct = False; - } + torture_assert(tctx, + !NT_STATUS_IS_OK(smbcli_unlock(cli->tree, fnum1, 100, 4)), + "unlock at 100 succeeded! This is a locking bug"); - if (NT_STATUS_IS_OK(smbcli_unlock(cli->tree, fnum1, 0, 4))) { - printf("unlock1 succeeded! This is a locking bug\n"); - correct = False; - } else { - if (!check_error(__location__, cli, - ERRDOS, ERRnotlocked, - NT_STATUS_RANGE_NOT_LOCKED)) return False; - } + torture_assert(tctx, + !NT_STATUS_IS_OK(smbcli_unlock(cli->tree, fnum1, 0, 4)), + "unlock1 succeeded! This is a locking bug"); - if (NT_STATUS_IS_OK(smbcli_unlock(cli->tree, fnum1, 0, 8))) { - printf("unlock2 succeeded! This is a locking bug\n"); - correct = False; - } else { - if (!check_error(__location__, cli, + if (!check_error(__location__, cli, ERRDOS, ERRnotlocked, NT_STATUS_RANGE_NOT_LOCKED)) return False; - } - if (NT_STATUS_IS_OK(smbcli_lock(cli->tree, fnum3, 0, 4, 0, WRITE_LOCK))) { - printf("lock3 succeeded! This is a locking bug\n"); - correct = False; - } else { - if (!check_error(__location__, cli, ERRDOS, ERRlock, NT_STATUS_LOCK_NOT_GRANTED)) return False; - } + torture_assert(tctx, + !NT_STATUS_IS_OK(smbcli_unlock(cli->tree, fnum1, 0, 8)), + "unlock2 succeeded! This is a locking bug"); - cli->session->pid = 1; + if (!check_error(__location__, cli, + ERRDOS, ERRnotlocked, + NT_STATUS_RANGE_NOT_LOCKED)) return False; - if (NT_STATUS_IS_ERR(smbcli_close(cli->tree, fnum1))) { - printf("close1 failed (%s)\n", smbcli_errstr(cli->tree)); - return False; - } + torture_assert(tctx, + !NT_STATUS_IS_OK(smbcli_lock(cli->tree, fnum3, 0, 4, 0, WRITE_LOCK)), + "lock3 succeeded! This is a locking bug"); - if (NT_STATUS_IS_ERR(smbcli_close(cli->tree, fnum2))) { - printf("close2 failed (%s)\n", smbcli_errstr(cli->tree)); - return False; - } + if (!check_error(__location__, cli, ERRDOS, ERRlock, NT_STATUS_LOCK_NOT_GRANTED)) return False; - if (NT_STATUS_IS_ERR(smbcli_close(cli->tree, fnum3))) { - printf("close3 failed (%s)\n", smbcli_errstr(cli->tree)); - return False; - } + cli->session->pid = 1; - if (!torture_close_connection(cli)) { - correct = False; - } + torture_assert_ntstatus_ok(tctx, smbcli_close(cli->tree, fnum1), + talloc_asprintf(tctx, "close1 failed (%s)", smbcli_errstr(cli->tree))); - printf("locktest2 finished\n"); + torture_assert_ntstatus_ok(tctx, smbcli_close(cli->tree, fnum2), + talloc_asprintf(tctx, "close2 failed (%s)", smbcli_errstr(cli->tree))); - return correct; + torture_assert_ntstatus_ok(tctx, smbcli_close(cli->tree, fnum3), + talloc_asprintf(tctx, "close3 failed (%s)", smbcli_errstr(cli->tree))); + + return true; } @@ -337,157 +272,113 @@ BOOL torture_locktest2(struct torture_context *torture) 1) the server supports the full offset range in lock requests */ -BOOL torture_locktest3(struct torture_context *torture) +bool torture_locktest3(struct torture_context *tctx, + struct smbcli_state *cli1, + struct smbcli_state *cli2) { - struct smbcli_state *cli1, *cli2; const char *fname = BASEDIR "\\lockt3.lck"; int fnum1, fnum2, i; uint32_t offset; - BOOL correct = True; extern int torture_numops; #define NEXT_OFFSET offset += (~(uint32_t)0) / torture_numops - if (!torture_open_connection(&cli1, 0) || - !torture_open_connection(&cli2, 1)) { - return False; - } - - printf("starting locktest3\n"); - - printf("Testing 32 bit offset ranges\n"); + torture_comment(tctx, "Testing 32 bit offset ranges"); if (!torture_setup_dir(cli1, BASEDIR)) { return False; } fnum1 = smbcli_open(cli1->tree, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE); - if (fnum1 == -1) { - printf("open of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree)); - return False; - } + torture_assert(tctx, fnum1 != -1, + talloc_asprintf(tctx, "open of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree))); fnum2 = smbcli_open(cli2->tree, fname, O_RDWR, DENY_NONE); - if (fnum2 == -1) { - printf("open2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree)); - return False; - } + torture_assert(tctx, fnum2 != -1, + talloc_asprintf(tctx, "open2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree))); - printf("Establishing %d locks\n", torture_numops); + torture_comment(tctx, "Establishing %d locks\n", torture_numops); for (offset=i=0;itree, fnum1, offset-1, 1, 0, WRITE_LOCK))) { - printf("lock1 %d failed (%s)\n", - i, - smbcli_errstr(cli1->tree)); - return False; - } + torture_assert_ntstatus_ok(tctx, + smbcli_lock(cli1->tree, fnum1, offset-1, 1, 0, WRITE_LOCK), + talloc_asprintf(tctx, "lock1 %d failed (%s)", i, smbcli_errstr(cli1->tree))); - if (NT_STATUS_IS_ERR(smbcli_lock(cli2->tree, fnum2, offset-2, 1, 0, WRITE_LOCK))) { - printf("lock2 %d failed (%s)\n", - i, - smbcli_errstr(cli1->tree)); - return False; - } + torture_assert_ntstatus_ok(tctx, + smbcli_lock(cli2->tree, fnum2, offset-2, 1, 0, WRITE_LOCK), + talloc_asprintf(tctx, "lock2 %d failed (%s)", + i, smbcli_errstr(cli1->tree))); } - printf("Testing %d locks\n", torture_numops); + torture_comment(tctx, "Testing %d locks\n", torture_numops); for (offset=i=0;itree, fnum1, offset-2, 1, 0, WRITE_LOCK))) { - printf("error: lock1 %d succeeded!\n", i); - return False; - } + torture_assert(tctx, + !NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, offset-2, 1, 0, WRITE_LOCK)), + talloc_asprintf(tctx, "error: lock1 %d succeeded!", i)); - if (NT_STATUS_IS_OK(smbcli_lock(cli2->tree, fnum2, offset-1, 1, 0, WRITE_LOCK))) { - printf("error: lock2 %d succeeded!\n", i); - return False; - } + torture_assert(tctx, + !NT_STATUS_IS_OK(smbcli_lock(cli2->tree, fnum2, offset-1, 1, 0, WRITE_LOCK)), + talloc_asprintf(tctx, "error: lock2 %d succeeded!", i)); - if (NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, offset-1, 1, 0, WRITE_LOCK))) { - printf("error: lock3 %d succeeded!\n", i); - return False; - } + torture_assert(tctx, + !NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, offset-1, 1, 0, WRITE_LOCK)), + talloc_asprintf(tctx, "error: lock3 %d succeeded!", i)); - if (NT_STATUS_IS_OK(smbcli_lock(cli2->tree, fnum2, offset-2, 1, 0, WRITE_LOCK))) { - printf("error: lock4 %d succeeded!\n", i); - return False; - } + torture_assert(tctx, + !NT_STATUS_IS_OK(smbcli_lock(cli2->tree, fnum2, offset-2, 1, 0, WRITE_LOCK)), + talloc_asprintf(tctx, "error: lock4 %d succeeded!", i)); } - printf("Removing %d locks\n", torture_numops); + torture_comment(tctx, "Removing %d locks\n", torture_numops); for (offset=i=0;itree, fnum1, offset-1, 1))) { - printf("unlock1 %d failed (%s)\n", + torture_assert_ntstatus_ok(tctx, + smbcli_unlock(cli1->tree, fnum1, offset-1, 1), + talloc_asprintf(tctx, "unlock1 %d failed (%s)", i, - smbcli_errstr(cli1->tree)); - return False; - } + smbcli_errstr(cli1->tree))); - if (NT_STATUS_IS_ERR(smbcli_unlock(cli2->tree, fnum2, offset-2, 1))) { - printf("unlock2 %d failed (%s)\n", + torture_assert_ntstatus_ok(tctx, + smbcli_unlock(cli2->tree, fnum2, offset-2, 1), + talloc_asprintf(tctx, "unlock2 %d failed (%s)", i, - smbcli_errstr(cli1->tree)); - return False; - } - } - - if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) { - printf("close1 failed (%s)\n", smbcli_errstr(cli1->tree)); - return False; - } - - if (NT_STATUS_IS_ERR(smbcli_close(cli2->tree, fnum2))) { - printf("close2 failed (%s)\n", smbcli_errstr(cli2->tree)); - return False; + smbcli_errstr(cli1->tree))); } - if (NT_STATUS_IS_ERR(smbcli_unlink(cli1->tree, fname))) { - printf("unlink failed (%s)\n", smbcli_errstr(cli1->tree)); - return False; - } + torture_assert_ntstatus_ok(tctx, smbcli_close(cli1->tree, fnum1), + talloc_asprintf(tctx, "close1 failed (%s)", smbcli_errstr(cli1->tree))); - if (!torture_close_connection(cli1)) { - correct = False; - } - - if (!torture_close_connection(cli2)) { - correct = False; - } + torture_assert_ntstatus_ok(tctx, smbcli_close(cli2->tree, fnum2), + talloc_asprintf(tctx, "close2 failed (%s)", smbcli_errstr(cli2->tree))); - printf("finished locktest3\n"); + torture_assert_ntstatus_ok(tctx, smbcli_unlink(cli1->tree, fname), + talloc_asprintf(tctx, "unlink failed (%s)", smbcli_errstr(cli1->tree))); - return correct; + return true; } #define EXPECTED(ret, v) if ((ret) != (v)) { \ - printf("** "); correct = False; \ + torture_comment(tctx, "** "); correct = False; \ } /* looks at overlapping locks */ -BOOL torture_locktest4(struct torture_context *torture) +BOOL torture_locktest4(struct torture_context *tctx, + struct smbcli_state *cli1, + struct smbcli_state *cli2) { - struct smbcli_state *cli1, *cli2; const char *fname = BASEDIR "\\lockt4.lck"; int fnum1, fnum2, f; BOOL ret; uint8_t buf[1000]; BOOL correct = True; - if (!torture_open_connection(&cli1, 0) || - !torture_open_connection(&cli2, 1)) { - return False; - } - - printf("starting locktest4\n"); - if (!torture_setup_dir(cli1, BASEDIR)) { return False; } @@ -498,7 +389,7 @@ BOOL torture_locktest4(struct torture_context *torture) memset(buf, 0, sizeof(buf)); if (smbcli_write(cli1->tree, fnum1, 0, buf, 0, sizeof(buf)) != sizeof(buf)) { - printf("Failed to create file\n"); + torture_comment(tctx, "Failed to create file\n"); correct = False; goto fail; } @@ -506,74 +397,74 @@ BOOL torture_locktest4(struct torture_context *torture) ret = NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 0, 4, 0, WRITE_LOCK)) && NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 2, 4, 0, WRITE_LOCK)); EXPECTED(ret, False); - printf("the same process %s set overlapping write locks\n", ret?"can":"cannot"); + torture_comment(tctx, "the same process %s set overlapping write locks\n", ret?"can":"cannot"); ret = NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 10, 4, 0, READ_LOCK)) && NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 12, 4, 0, READ_LOCK)); EXPECTED(ret, True); - printf("the same process %s set overlapping read locks\n", ret?"can":"cannot"); + torture_comment(tctx, "the same process %s set overlapping read locks\n", ret?"can":"cannot"); ret = NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 20, 4, 0, WRITE_LOCK)) && NT_STATUS_IS_OK(smbcli_lock(cli2->tree, fnum2, 22, 4, 0, WRITE_LOCK)); EXPECTED(ret, False); - printf("a different connection %s set overlapping write locks\n", ret?"can":"cannot"); + torture_comment(tctx, "a different connection %s set overlapping write locks\n", ret?"can":"cannot"); ret = NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 30, 4, 0, READ_LOCK)) && NT_STATUS_IS_OK(smbcli_lock(cli2->tree, fnum2, 32, 4, 0, READ_LOCK)); EXPECTED(ret, True); - printf("a different connection %s set overlapping read locks\n", ret?"can":"cannot"); + torture_comment(tctx, "a different connection %s set overlapping read locks\n", ret?"can":"cannot"); ret = NT_STATUS_IS_OK((cli1->session->pid = 1, smbcli_lock(cli1->tree, fnum1, 40, 4, 0, WRITE_LOCK))) && NT_STATUS_IS_OK((cli1->session->pid = 2, smbcli_lock(cli1->tree, fnum1, 42, 4, 0, WRITE_LOCK))); EXPECTED(ret, False); - printf("a different pid %s set overlapping write locks\n", ret?"can":"cannot"); + torture_comment(tctx, "a different pid %s set overlapping write locks\n", ret?"can":"cannot"); ret = NT_STATUS_IS_OK((cli1->session->pid = 1, smbcli_lock(cli1->tree, fnum1, 50, 4, 0, READ_LOCK))) && NT_STATUS_IS_OK((cli1->session->pid = 2, smbcli_lock(cli1->tree, fnum1, 52, 4, 0, READ_LOCK))); EXPECTED(ret, True); - printf("a different pid %s set overlapping read locks\n", ret?"can":"cannot"); + torture_comment(tctx, "a different pid %s set overlapping read locks\n", ret?"can":"cannot"); ret = NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 60, 4, 0, READ_LOCK)) && NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 60, 4, 0, READ_LOCK)); EXPECTED(ret, True); - printf("the same process %s set the same read lock twice\n", ret?"can":"cannot"); + torture_comment(tctx, "the same process %s set the same read lock twice\n", ret?"can":"cannot"); ret = NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 70, 4, 0, WRITE_LOCK)) && NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 70, 4, 0, WRITE_LOCK)); EXPECTED(ret, False); - printf("the same process %s set the same write lock twice\n", ret?"can":"cannot"); + torture_comment(tctx, "the same process %s set the same write lock twice\n", ret?"can":"cannot"); ret = NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 80, 4, 0, READ_LOCK)) && NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 80, 4, 0, WRITE_LOCK)); EXPECTED(ret, False); - printf("the same process %s overlay a read lock with a write lock\n", ret?"can":"cannot"); + torture_comment(tctx, "the same process %s overlay a read lock with a write lock\n", ret?"can":"cannot"); ret = NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 90, 4, 0, WRITE_LOCK)) && NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 90, 4, 0, READ_LOCK)); EXPECTED(ret, True); - printf("the same process %s overlay a write lock with a read lock\n", ret?"can":"cannot"); + torture_comment(tctx, "the same process %s overlay a write lock with a read lock\n", ret?"can":"cannot"); ret = NT_STATUS_IS_OK((cli1->session->pid = 1, smbcli_lock(cli1->tree, fnum1, 100, 4, 0, WRITE_LOCK))) && NT_STATUS_IS_OK((cli1->session->pid = 2, smbcli_lock(cli1->tree, fnum1, 100, 4, 0, READ_LOCK))); EXPECTED(ret, False); - printf("a different pid %s overlay a write lock with a read lock\n", ret?"can":"cannot"); + torture_comment(tctx, "a different pid %s overlay a write lock with a read lock\n", ret?"can":"cannot"); ret = NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 110, 4, 0, READ_LOCK)) && NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 112, 4, 0, READ_LOCK)) && NT_STATUS_IS_OK(smbcli_unlock(cli1->tree, fnum1, 110, 6)); EXPECTED(ret, False); - printf("the same process %s coalesce read locks\n", ret?"can":"cannot"); + torture_comment(tctx, "the same process %s coalesce read locks\n", ret?"can":"cannot"); ret = NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 120, 4, 0, WRITE_LOCK)) && (smbcli_read(cli2->tree, fnum2, buf, 120, 4) == 4); EXPECTED(ret, False); - printf("this server %s strict write locking\n", ret?"doesn't do":"does"); + torture_comment(tctx, "this server %s strict write locking\n", ret?"doesn't do":"does"); ret = NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 130, 4, 0, READ_LOCK)) && (smbcli_write(cli2->tree, fnum2, 0, buf, 130, 4) == 4); EXPECTED(ret, False); - printf("this server %s strict read locking\n", ret?"doesn't do":"does"); + torture_comment(tctx, "this server %s strict read locking\n", ret?"doesn't do":"does"); ret = NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 140, 4, 0, READ_LOCK)) && @@ -581,7 +472,7 @@ BOOL torture_locktest4(struct torture_context *torture) NT_STATUS_IS_OK(smbcli_unlock(cli1->tree, fnum1, 140, 4)) && NT_STATUS_IS_OK(smbcli_unlock(cli1->tree, fnum1, 140, 4)); EXPECTED(ret, True); - printf("this server %s do recursive read locking\n", ret?"does":"doesn't"); + torture_comment(tctx, "this server %s do recursive read locking\n", ret?"does":"doesn't"); ret = NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 150, 4, 0, WRITE_LOCK)) && @@ -591,21 +482,21 @@ BOOL torture_locktest4(struct torture_context *torture) !(smbcli_write(cli2->tree, fnum2, 0, buf, 150, 4) == 4) && NT_STATUS_IS_OK(smbcli_unlock(cli1->tree, fnum1, 150, 4)); EXPECTED(ret, True); - printf("this server %s do recursive lock overlays\n", ret?"does":"doesn't"); + torture_comment(tctx, "this server %s do recursive lock overlays\n", ret?"does":"doesn't"); ret = NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 160, 4, 0, READ_LOCK)) && NT_STATUS_IS_OK(smbcli_unlock(cli1->tree, fnum1, 160, 4)) && (smbcli_write(cli2->tree, fnum2, 0, buf, 160, 4) == 4) && (smbcli_read(cli2->tree, fnum2, buf, 160, 4) == 4); EXPECTED(ret, True); - printf("the same process %s remove a read lock using write locking\n", ret?"can":"cannot"); + torture_comment(tctx, "the same process %s remove a read lock using write locking\n", ret?"can":"cannot"); ret = NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 170, 4, 0, WRITE_LOCK)) && NT_STATUS_IS_OK(smbcli_unlock(cli1->tree, fnum1, 170, 4)) && (smbcli_write(cli2->tree, fnum2, 0, buf, 170, 4) == 4) && (smbcli_read(cli2->tree, fnum2, buf, 170, 4) == 4); EXPECTED(ret, True); - printf("the same process %s remove a write lock using read locking\n", ret?"can":"cannot"); + torture_comment(tctx, "the same process %s remove a write lock using read locking\n", ret?"can":"cannot"); ret = NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 190, 4, 0, WRITE_LOCK)) && NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 190, 4, 0, READ_LOCK)) && @@ -613,7 +504,7 @@ BOOL torture_locktest4(struct torture_context *torture) !(smbcli_write(cli2->tree, fnum2, 0, buf, 190, 4) == 4) && (smbcli_read(cli2->tree, fnum2, buf, 190, 4) == 4); EXPECTED(ret, True); - printf("the same process %s remove the first lock first\n", ret?"does":"doesn't"); + torture_comment(tctx, "the same process %s remove the first lock first\n", ret?"does":"doesn't"); smbcli_close(cli1->tree, fnum1); smbcli_close(cli2->tree, fnum2); @@ -627,38 +518,28 @@ BOOL torture_locktest4(struct torture_context *torture) smbcli_close(cli1->tree, f); smbcli_close(cli1->tree, fnum1); EXPECTED(ret, True); - printf("the server %s have the NT byte range lock bug\n", !ret?"does":"doesn't"); + torture_comment(tctx, "the server %s have the NT byte range lock bug\n", !ret?"does":"doesn't"); fail: smbcli_close(cli1->tree, fnum1); smbcli_close(cli2->tree, fnum2); smbcli_unlink(cli1->tree, fname); - torture_close_connection(cli1); - torture_close_connection(cli2); - printf("finished locktest4\n"); return correct; } /* looks at lock upgrade/downgrade. */ -BOOL torture_locktest5(struct torture_context *torture) +BOOL torture_locktest5(struct torture_context *tctx, struct smbcli_state *cli1, + struct smbcli_state *cli2) { - struct smbcli_state *cli1, *cli2; const char *fname = BASEDIR "\\lockt5.lck"; int fnum1, fnum2, fnum3; BOOL ret; uint8_t buf[1000]; BOOL correct = True; - if (!torture_open_connection(&cli1, 0) || - !torture_open_connection(&cli2, 1)) { - return False; - } - - printf("starting locktest5\n"); - if (!torture_setup_dir(cli1, BASEDIR)) { return False; } @@ -669,11 +550,8 @@ BOOL torture_locktest5(struct torture_context *torture) memset(buf, 0, sizeof(buf)); - if (smbcli_write(cli1->tree, fnum1, 0, buf, 0, sizeof(buf)) != sizeof(buf)) { - printf("Failed to create file\n"); - correct = False; - goto fail; - } + torture_assert(tctx, smbcli_write(cli1->tree, fnum1, 0, buf, 0, sizeof(buf)) == sizeof(buf), + "Failed to create file"); /* Check for NT bug... */ ret = NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 0, 8, 0, READ_LOCK)) && @@ -682,7 +560,7 @@ BOOL torture_locktest5(struct torture_context *torture) fnum1 = smbcli_open(cli1->tree, fname, O_RDWR, DENY_NONE); ret = NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 7, 1, 0, WRITE_LOCK)); EXPECTED(ret, True); - printf("this server %s the NT locking bug\n", ret ? "doesn't have" : "has"); + torture_comment(tctx, "this server %s the NT locking bug\n", ret ? "doesn't have" : "has"); smbcli_close(cli1->tree, fnum1); fnum1 = smbcli_open(cli1->tree, fname, O_RDWR, DENY_NONE); smbcli_unlock(cli1->tree, fnum3, 0, 1); @@ -690,12 +568,12 @@ BOOL torture_locktest5(struct torture_context *torture) ret = NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 0, 4, 0, WRITE_LOCK)) && NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 1, 1, 0, READ_LOCK)); EXPECTED(ret, True); - printf("the same process %s overlay a write with a read lock\n", ret?"can":"cannot"); + torture_comment(tctx, "the same process %s overlay a write with a read lock\n", ret?"can":"cannot"); ret = NT_STATUS_IS_OK(smbcli_lock(cli2->tree, fnum2, 0, 4, 0, READ_LOCK)); EXPECTED(ret, False); - printf("a different processs %s get a read lock on the first process lock stack\n", ret?"can":"cannot"); + torture_comment(tctx, "a different processs %s get a read lock on the first process lock stack\n", ret?"can":"cannot"); /* Unlock the process 2 lock. */ smbcli_unlock(cli2->tree, fnum2, 0, 4); @@ -703,7 +581,7 @@ BOOL torture_locktest5(struct torture_context *torture) ret = NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum3, 0, 4, 0, READ_LOCK)); EXPECTED(ret, False); - printf("the same processs on a different fnum %s get a read lock\n", ret?"can":"cannot"); + torture_comment(tctx, "the same processs on a different fnum %s get a read lock\n", ret?"can":"cannot"); /* Unlock the process 1 fnum3 lock. */ smbcli_unlock(cli1->tree, fnum3, 0, 4); @@ -713,7 +591,7 @@ BOOL torture_locktest5(struct torture_context *torture) NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 0, 4, 0, READ_LOCK)); EXPECTED(ret, True); - printf("the same process %s stack read locks\n", ret?"can":"cannot"); + torture_comment(tctx, "the same process %s stack read locks\n", ret?"can":"cannot"); /* Unlock the first process lock, then check this was the WRITE lock that was removed. */ @@ -722,7 +600,7 @@ ret = NT_STATUS_IS_OK(smbcli_unlock(cli1->tree, fnum1, 0, 4)) && NT_STATUS_IS_OK(smbcli_lock(cli2->tree, fnum2, 0, 4, 0, READ_LOCK)); EXPECTED(ret, True); - printf("the first unlock removes the %s lock\n", ret?"WRITE":"READ"); + torture_comment(tctx, "the first unlock removes the %s lock\n", ret?"WRITE":"READ"); /* Unlock the process 2 lock. */ smbcli_unlock(cli2->tree, fnum2, 0, 4); @@ -734,32 +612,23 @@ ret = NT_STATUS_IS_OK(smbcli_unlock(cli1->tree, fnum1, 0, 4)) && NT_STATUS_IS_OK(smbcli_unlock(cli1->tree, fnum1, 0, 4)); EXPECTED(ret, True); - printf("the same process %s unlock the stack of 4 locks\n", ret?"can":"cannot"); + torture_comment(tctx, "the same process %s unlock the stack of 4 locks\n", ret?"can":"cannot"); /* Ensure the next unlock fails. */ ret = NT_STATUS_IS_OK(smbcli_unlock(cli1->tree, fnum1, 0, 4)); EXPECTED(ret, False); - printf("the same process %s count the lock stack\n", !ret?"can":"cannot"); + torture_comment(tctx, "the same process %s count the lock stack\n", !ret?"can":"cannot"); /* Ensure connection 2 can get a write lock. */ ret = NT_STATUS_IS_OK(smbcli_lock(cli2->tree, fnum2, 0, 4, 0, WRITE_LOCK)); EXPECTED(ret, True); - printf("a different processs %s get a write lock on the unlocked stack\n", ret?"can":"cannot"); + torture_comment(tctx, "a different processs %s get a write lock on the unlocked stack\n", ret?"can":"cannot"); - fail: smbcli_close(cli1->tree, fnum1); smbcli_close(cli2->tree, fnum2); smbcli_unlink(cli1->tree, fname); - if (!torture_close_connection(cli1)) { - correct = False; - } - if (!torture_close_connection(cli2)) { - correct = False; - } - - printf("finished locktest5\n"); return correct; } @@ -767,51 +636,42 @@ ret = NT_STATUS_IS_OK(smbcli_unlock(cli1->tree, fnum1, 0, 4)) && /* tries the unusual lockingX locktype bits */ -BOOL torture_locktest6(struct torture_context *torture) +BOOL torture_locktest6(struct torture_context *tctx, + struct smbcli_state *cli) { - struct smbcli_state *cli; const char *fname[1] = { "\\lock6.txt" }; int i; int fnum; NTSTATUS status; - if (!torture_open_connection(&cli, 0)) { - return False; - } - if (!torture_setup_dir(cli, BASEDIR)) { return False; } - printf("starting locktest6\n"); - for (i=0;i<1;i++) { - printf("Testing %s\n", fname[i]); + torture_comment(tctx, "Testing %s\n", fname[i]); smbcli_unlink(cli->tree, fname[i]); fnum = smbcli_open(cli->tree, fname[i], O_RDWR|O_CREAT|O_EXCL, DENY_NONE); status = smbcli_locktype(cli->tree, fnum, 0, 8, 0, LOCKING_ANDX_CHANGE_LOCKTYPE); smbcli_close(cli->tree, fnum); - printf("CHANGE_LOCKTYPE gave %s\n", nt_errstr(status)); + torture_comment(tctx, "CHANGE_LOCKTYPE gave %s\n", nt_errstr(status)); fnum = smbcli_open(cli->tree, fname[i], O_RDWR, DENY_NONE); status = smbcli_locktype(cli->tree, fnum, 0, 8, 0, LOCKING_ANDX_CANCEL_LOCK); smbcli_close(cli->tree, fnum); - printf("CANCEL_LOCK gave %s\n", nt_errstr(status)); + torture_comment(tctx, "CANCEL_LOCK gave %s\n", nt_errstr(status)); smbcli_unlink(cli->tree, fname[i]); } - torture_close_connection(cli); - - printf("finished locktest6\n"); return True; } -BOOL torture_locktest7(struct torture_context *torture) +BOOL torture_locktest7(struct torture_context *tctx, + struct smbcli_state *cli1) { - struct smbcli_state *cli1; const char *fname = BASEDIR "\\lockt7.lck"; int fnum1; int fnum2 = -1; @@ -819,158 +679,109 @@ BOOL torture_locktest7(struct torture_context *torture) uint8_t buf[200]; BOOL correct = False; - if (!torture_open_connection(&cli1, 0)) { - return False; - } - - printf("starting locktest7\n"); - - if (!torture_setup_dir(cli1, BASEDIR)) { - return False; - } + torture_assert(tctx, torture_setup_dir(cli1, BASEDIR), + talloc_asprintf(tctx, "Unable to set up %s", BASEDIR)); fnum1 = smbcli_open(cli1->tree, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE); memset(buf, 0, sizeof(buf)); - if (smbcli_write(cli1->tree, fnum1, 0, buf, 0, sizeof(buf)) != sizeof(buf)) { - printf("Failed to create file (%s)\n", __location__); - goto fail; - } + torture_assert(tctx, smbcli_write(cli1->tree, fnum1, 0, buf, 0, sizeof(buf)) == sizeof(buf), + "Failed to create file"); cli1->session->pid = 1; - if (NT_STATUS_IS_ERR(smbcli_lock(cli1->tree, fnum1, 130, 4, 0, READ_LOCK))) { - printf("Unable to apply read lock on range 130:4, error was %s (%s)\n", - smbcli_errstr(cli1->tree), __location__); - goto fail; - } else { - printf("pid1 successfully locked range 130:4 for READ\n"); - } + torture_assert_ntstatus_ok(tctx, smbcli_lock(cli1->tree, fnum1, 130, 4, 0, READ_LOCK), + talloc_asprintf(tctx, "Unable to apply read lock on range 130:4, error was %s", + smbcli_errstr(cli1->tree))); - if (smbcli_read(cli1->tree, fnum1, buf, 130, 4) != 4) { - printf("pid1 unable to read the range 130:4, error was %s (%s)\n", - smbcli_errstr(cli1->tree), __location__); - goto fail; - } else { - printf("pid1 successfully read the range 130:4\n"); - } + torture_comment(tctx, "pid1 successfully locked range 130:4 for READ\n"); + + torture_assert(tctx, smbcli_read(cli1->tree, fnum1, buf, 130, 4) == 4, + talloc_asprintf(tctx, "pid1 unable to read the range 130:4, error was %s)", + smbcli_errstr(cli1->tree))); + + torture_comment(tctx, "pid1 successfully read the range 130:4\n"); if (smbcli_write(cli1->tree, fnum1, 0, buf, 130, 4) != 4) { - printf("pid1 unable to write to the range 130:4, error was %s\n", smbcli_errstr(cli1->tree)); - if (!NT_STATUS_EQUAL(smbcli_nt_error(cli1->tree), NT_STATUS_FILE_LOCK_CONFLICT)) { - printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT) (%s)\n", - __location__); - goto fail; - } + torture_comment(tctx, "pid1 unable to write to the range 130:4, error was %s\n", smbcli_errstr(cli1->tree)); + torture_assert_ntstatus_equal(tctx, smbcli_nt_error(cli1->tree), NT_STATUS_FILE_LOCK_CONFLICT, + "Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)"); } else { - printf("pid1 successfully wrote to the range 130:4 (should be denied) (%s)\n", - __location__); - goto fail; + torture_fail(tctx, "pid1 successfully wrote to the range 130:4 (should be denied)"); } cli1->session->pid = 2; if (smbcli_read(cli1->tree, fnum1, buf, 130, 4) != 4) { - printf("pid2 unable to read the range 130:4, error was %s\n", smbcli_errstr(cli1->tree)); + torture_comment(tctx, "pid2 unable to read the range 130:4, error was %s\n", smbcli_errstr(cli1->tree)); } else { - printf("pid2 successfully read the range 130:4\n"); + torture_comment(tctx, "pid2 successfully read the range 130:4\n"); } if (smbcli_write(cli1->tree, fnum1, 0, buf, 130, 4) != 4) { - printf("pid2 unable to write to the range 130:4, error was %s\n", smbcli_errstr(cli1->tree)); - if (!NT_STATUS_EQUAL(smbcli_nt_error(cli1->tree), NT_STATUS_FILE_LOCK_CONFLICT)) { - printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT) (%s)\n", - __location__); - goto fail; - } + torture_comment(tctx, "pid2 unable to write to the range 130:4, error was %s\n", smbcli_errstr(cli1->tree)); + torture_assert_ntstatus_equal(tctx, smbcli_nt_error(cli1->tree), NT_STATUS_FILE_LOCK_CONFLICT, + "Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)"); } else { - printf("pid2 successfully wrote to the range 130:4 (should be denied) (%s)\n", - __location__); - goto fail; + torture_fail(tctx, "pid2 successfully wrote to the range 130:4 (should be denied)"); } cli1->session->pid = 1; smbcli_unlock(cli1->tree, fnum1, 130, 4); - if (NT_STATUS_IS_ERR(smbcli_lock(cli1->tree, fnum1, 130, 4, 0, WRITE_LOCK))) { - printf("Unable to apply write lock on range 130:4, error was %s (%s)\n", - smbcli_errstr(cli1->tree), __location__); - goto fail; - } else { - printf("pid1 successfully locked range 130:4 for WRITE\n"); - } + torture_assert_ntstatus_ok(tctx, smbcli_lock(cli1->tree, fnum1, 130, 4, 0, WRITE_LOCK), + talloc_asprintf(tctx, "Unable to apply write lock on range 130:4, error was %s", + smbcli_errstr(cli1->tree))); + torture_comment(tctx, "pid1 successfully locked range 130:4 for WRITE\n"); - if (smbcli_read(cli1->tree, fnum1, buf, 130, 4) != 4) { - printf("pid1 unable to read the range 130:4, error was %s (%s)\n", - smbcli_errstr(cli1->tree), __location__); - goto fail; - } else { - printf("pid1 successfully read the range 130:4\n"); - } + torture_assert(tctx, smbcli_read(cli1->tree, fnum1, buf, 130, 4) == 4, + talloc_asprintf(tctx, "pid1 unable to read the range 130:4, error was %s", + smbcli_errstr(cli1->tree))); + torture_comment(tctx, "pid1 successfully read the range 130:4\n"); - if (smbcli_write(cli1->tree, fnum1, 0, buf, 130, 4) != 4) { - printf("pid1 unable to write to the range 130:4, error was %s (%s)\n", - smbcli_errstr(cli1->tree), __location__); - goto fail; - } else { - printf("pid1 successfully wrote to the range 130:4\n"); - } + torture_assert(tctx, smbcli_write(cli1->tree, fnum1, 0, buf, 130, 4) == 4, + talloc_asprintf(tctx, "pid1 unable to write to the range 130:4, error was %s", + smbcli_errstr(cli1->tree))); + torture_comment(tctx, "pid1 successfully wrote to the range 130:4\n"); cli1->session->pid = 2; if (smbcli_read(cli1->tree, fnum1, buf, 130, 4) != 4) { - printf("pid2 unable to read the range 130:4, error was %s\n", + torture_comment(tctx, "pid2 unable to read the range 130:4, error was %s\n", smbcli_errstr(cli1->tree)); - if (!NT_STATUS_EQUAL(smbcli_nt_error(cli1->tree), NT_STATUS_FILE_LOCK_CONFLICT)) { - printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT) (%s)\n", - __location__); - goto fail; - } + torture_assert_ntstatus_equal(tctx, smbcli_nt_error(cli1->tree), NT_STATUS_FILE_LOCK_CONFLICT, + "Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)"); } else { - printf("pid2 successfully read the range 130:4 (should be denied) (%s)\n", - __location__); - goto fail; + torture_fail(tctx, "pid2 successfully read the range 130:4 (should be denied)"); } if (smbcli_write(cli1->tree, fnum1, 0, buf, 130, 4) != 4) { - printf("pid2 unable to write to the range 130:4, error was %s\n", + torture_comment(tctx, "pid2 unable to write to the range 130:4, error was %s\n", smbcli_errstr(cli1->tree)); if (!NT_STATUS_EQUAL(smbcli_nt_error(cli1->tree), NT_STATUS_FILE_LOCK_CONFLICT)) { - printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT) (%s)\n", + torture_comment(tctx, "Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT) (%s)\n", __location__); goto fail; } } else { - printf("pid2 successfully wrote to the range 130:4 (should be denied) (%s)\n", + torture_comment(tctx, "pid2 successfully wrote to the range 130:4 (should be denied) (%s)\n", __location__); goto fail; } - printf("Testing truncate of locked file.\n"); + torture_comment(tctx, "Testing truncate of locked file.\n"); fnum2 = smbcli_open(cli1->tree, fname, O_RDWR|O_TRUNC, DENY_NONE); - if (fnum2 == -1) { - printf("Unable to truncate locked file (%s)\n", __location__); - correct = False; - goto fail; - } else { - printf("Truncated locked file.\n"); - } + torture_assert(tctx, fnum2 != -1, "Unable to truncate locked file"); - if (NT_STATUS_IS_ERR(smbcli_getatr(cli1->tree, fname, NULL, &size, NULL))) { - printf("getatr failed (%s) (%s)\n", smbcli_errstr(cli1->tree), __location__); - correct = False; - goto fail; - } + torture_comment(tctx, "Truncated locked file.\n"); - if (size != 0) { - printf("Unable to truncate locked file. Size was %u (%s)\n", - (unsigned)size, __location__); - correct = False; - goto fail; - } + torture_assert_ntstatus_ok(tctx, smbcli_getatr(cli1->tree, fname, NULL, &size, NULL), + talloc_asprintf(tctx, "getatr failed (%s)", smbcli_errstr(cli1->tree))); + + torture_assert(tctx, size == 0, talloc_asprintf(tctx, "Unable to truncate locked file. Size was %u", (unsigned)size)); cli1->session->pid = 1; @@ -981,9 +792,21 @@ fail: smbcli_close(cli1->tree, fnum1); smbcli_close(cli1->tree, fnum2); smbcli_unlink(cli1->tree, fname); - torture_close_connection(cli1); - printf("finished locktest7\n"); return correct; } +struct torture_suite *torture_base_locktest(void) +{ + struct torture_suite *suite = torture_suite_create(talloc_autofree_context(), + "LOCK"); + torture_suite_add_2smb_test(suite, "LOCK1", torture_locktest1); + torture_suite_add_1smb_test(suite, "LOCK2", torture_locktest2); + torture_suite_add_2smb_test(suite, "LOCK3", torture_locktest3); + torture_suite_add_2smb_test(suite, "LOCK4", torture_locktest4); + torture_suite_add_2smb_test(suite, "LOCK5", torture_locktest5); + torture_suite_add_1smb_test(suite, "LOCK6", torture_locktest6); + torture_suite_add_1smb_test(suite, "LOCK7", torture_locktest7); + + return suite; +} -- 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/locking.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'source4/torture/basic/locking.c') diff --git a/source4/torture/basic/locking.c b/source4/torture/basic/locking.c index c966c667e6..5570af17d6 100644 --- a/source4/torture/basic/locking.c +++ b/source4/torture/basic/locking.c @@ -8,7 +8,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, @@ -17,8 +17,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 a87dea2a0894015cf4a3140995791f5468c40038 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Tue, 10 Jul 2007 11:37:30 +0000 Subject: r23810: Make things static, and remove unsued code. This includes some of the original ildap ldap client API. ldb provides a much easier abstraction on this to use, and doesn't use these functions. Andrew Bartlett (This used to be commit dc27a7e41c297472675e8c251bb14327a1af3902) --- source4/torture/basic/locking.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'source4/torture/basic/locking.c') diff --git a/source4/torture/basic/locking.c b/source4/torture/basic/locking.c index 5570af17d6..aa3168fb08 100644 --- a/source4/torture/basic/locking.c +++ b/source4/torture/basic/locking.c @@ -38,9 +38,9 @@ must not use posix semantics) 2) support for lock timeouts */ -bool torture_locktest1(struct torture_context *tctx, - struct smbcli_state *cli1, - struct smbcli_state *cli2) +static bool torture_locktest1(struct torture_context *tctx, + struct smbcli_state *cli1, + struct smbcli_state *cli2) { const char *fname = BASEDIR "\\lockt1.lck"; int fnum1, fnum2, fnum3; @@ -159,8 +159,8 @@ bool torture_locktest1(struct torture_context *tctx, 3) the server denies unlock requests by an incorrect client PID */ -bool torture_locktest2(struct torture_context *tctx, - struct smbcli_state *cli) +static bool torture_locktest2(struct torture_context *tctx, + struct smbcli_state *cli) { const char *fname = BASEDIR "\\lockt2.lck"; int fnum1, fnum2, fnum3; @@ -271,9 +271,9 @@ bool torture_locktest2(struct torture_context *tctx, 1) the server supports the full offset range in lock requests */ -bool torture_locktest3(struct torture_context *tctx, - struct smbcli_state *cli1, - struct smbcli_state *cli2) +static bool torture_locktest3(struct torture_context *tctx, + struct smbcli_state *cli1, + struct smbcli_state *cli2) { const char *fname = BASEDIR "\\lockt3.lck"; int fnum1, fnum2, i; @@ -368,9 +368,9 @@ bool torture_locktest3(struct torture_context *tctx, /* looks at overlapping locks */ -BOOL torture_locktest4(struct torture_context *tctx, - struct smbcli_state *cli1, - struct smbcli_state *cli2) +static bool torture_locktest4(struct torture_context *tctx, + struct smbcli_state *cli1, + struct smbcli_state *cli2) { const char *fname = BASEDIR "\\lockt4.lck"; int fnum1, fnum2, f; @@ -530,8 +530,8 @@ BOOL torture_locktest4(struct torture_context *tctx, /* looks at lock upgrade/downgrade. */ -BOOL torture_locktest5(struct torture_context *tctx, struct smbcli_state *cli1, - struct smbcli_state *cli2) +static bool torture_locktest5(struct torture_context *tctx, struct smbcli_state *cli1, + struct smbcli_state *cli2) { const char *fname = BASEDIR "\\lockt5.lck"; int fnum1, fnum2, fnum3; @@ -635,8 +635,8 @@ ret = NT_STATUS_IS_OK(smbcli_unlock(cli1->tree, fnum1, 0, 4)) && /* tries the unusual lockingX locktype bits */ -BOOL torture_locktest6(struct torture_context *tctx, - struct smbcli_state *cli) +static bool torture_locktest6(struct torture_context *tctx, + struct smbcli_state *cli) { const char *fname[1] = { "\\lock6.txt" }; int i; @@ -668,8 +668,8 @@ BOOL torture_locktest6(struct torture_context *tctx, return True; } -BOOL torture_locktest7(struct torture_context *tctx, - struct smbcli_state *cli1) +static bool torture_locktest7(struct torture_context *tctx, + struct smbcli_state *cli1) { const char *fname = BASEDIR "\\lockt7.lck"; int fnum1; -- cgit From cd962355abad90a2161765a7be7d26e63572cab7 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 7 Sep 2007 15:08:14 +0000 Subject: r25000: Fix some more C++ compatibility warnings. (This used to be commit 08bb1ef643ab906f1645cf6f32763dc73b1884e4) --- source4/torture/basic/locking.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'source4/torture/basic/locking.c') diff --git a/source4/torture/basic/locking.c b/source4/torture/basic/locking.c index aa3168fb08..0d66ecf30b 100644 --- a/source4/torture/basic/locking.c +++ b/source4/torture/basic/locking.c @@ -795,10 +795,9 @@ fail: return correct; } -struct torture_suite *torture_base_locktest(void) +struct torture_suite *torture_base_locktest(TALLOC_CTX *mem_ctx) { - struct torture_suite *suite = torture_suite_create(talloc_autofree_context(), - "LOCK"); + struct torture_suite *suite = torture_suite_create(mem_ctx, "LOCK"); torture_suite_add_2smb_test(suite, "LOCK1", torture_locktest1); torture_suite_add_1smb_test(suite, "LOCK2", torture_locktest2); torture_suite_add_2smb_test(suite, "LOCK3", torture_locktest3); -- 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/locking.c | 114 ++++++++++++++++++++-------------------- 1 file changed, 57 insertions(+), 57 deletions(-) (limited to 'source4/torture/basic/locking.c') diff --git a/source4/torture/basic/locking.c b/source4/torture/basic/locking.c index 0d66ecf30b..2e2585b976 100644 --- a/source4/torture/basic/locking.c +++ b/source4/torture/basic/locking.c @@ -48,7 +48,7 @@ static bool torture_locktest1(struct torture_context *tctx, uint_t lock_timeout; if (!torture_setup_dir(cli1, BASEDIR)) { - return False; + return false; } fnum1 = smbcli_open(cli1->tree, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE); @@ -71,14 +71,14 @@ static bool torture_locktest1(struct torture_context *tctx, "lock2 succeeded! This is a locking bug\n"); if (!check_error(__location__, cli2, ERRDOS, ERRlock, - NT_STATUS_LOCK_NOT_GRANTED)) return False; + NT_STATUS_LOCK_NOT_GRANTED)) return false; torture_assert(tctx, !NT_STATUS_IS_OK(smbcli_lock(cli2->tree, fnum3, 0, 4, 0, WRITE_LOCK)), "lock2 succeeded! This is a locking bug\n"); if (!check_error(__location__, cli2, ERRDOS, ERRlock, - NT_STATUS_FILE_LOCK_CONFLICT)) return False; + NT_STATUS_FILE_LOCK_CONFLICT)) return false; torture_assert_ntstatus_ok(tctx, smbcli_lock(cli1->tree, fnum1, 5, 9, 0, WRITE_LOCK), @@ -90,21 +90,21 @@ static bool torture_locktest1(struct torture_context *tctx, "lock2 succeeded! This is a locking bug"); if (!check_error(__location__, cli2, ERRDOS, ERRlock, - NT_STATUS_LOCK_NOT_GRANTED)) return False; + NT_STATUS_LOCK_NOT_GRANTED)) return false; torture_assert(tctx, !NT_STATUS_IS_OK(smbcli_lock(cli2->tree, fnum3, 0, 4, 0, WRITE_LOCK)), "lock2 succeeded! This is a locking bug"); if (!check_error(__location__, cli2, ERRDOS, ERRlock, - NT_STATUS_LOCK_NOT_GRANTED)) return False; + NT_STATUS_LOCK_NOT_GRANTED)) return false; torture_assert(tctx, !NT_STATUS_IS_OK(smbcli_lock(cli2->tree, fnum3, 0, 4, 0, WRITE_LOCK)), "lock2 succeeded! This is a locking bug"); if (!check_error(__location__, cli2, ERRDOS, ERRlock, - NT_STATUS_FILE_LOCK_CONFLICT)) return False; + NT_STATUS_FILE_LOCK_CONFLICT)) return false; lock_timeout = (6 + (random() % 20)); torture_comment(tctx, "Testing lock timeout with timeout=%u\n", @@ -115,7 +115,7 @@ static bool torture_locktest1(struct torture_context *tctx, "lock3 succeeded! This is a locking bug\n"); if (!check_error(__location__, cli2, ERRDOS, ERRlock, - NT_STATUS_FILE_LOCK_CONFLICT)) return False; + NT_STATUS_FILE_LOCK_CONFLICT)) return false; t2 = time(NULL); if (t2 - t1 < 5) { @@ -133,7 +133,7 @@ static bool torture_locktest1(struct torture_context *tctx, "lock4 succeeded! This is a locking bug"); if (!check_error(__location__, cli2, ERRDOS, ERRlock, - NT_STATUS_FILE_LOCK_CONFLICT)) return False; + NT_STATUS_FILE_LOCK_CONFLICT)) return false; torture_assert_ntstatus_ok(tctx, smbcli_close(cli1->tree, fnum1), talloc_asprintf(tctx, "close2 failed (%s)", smbcli_errstr(cli1->tree))); @@ -166,7 +166,7 @@ static bool torture_locktest2(struct torture_context *tctx, int fnum1, fnum2, fnum3; if (!torture_setup_dir(cli, BASEDIR)) { - return False; + return false; } torture_comment(tctx, "Testing pid context\n"); @@ -202,21 +202,21 @@ static bool torture_locktest2(struct torture_context *tctx, "WRITE lock1 succeeded! This is a locking bug"); if (!check_error(__location__, cli, ERRDOS, ERRlock, - NT_STATUS_LOCK_NOT_GRANTED)) return False; + NT_STATUS_LOCK_NOT_GRANTED)) return false; torture_assert(tctx, !NT_STATUS_IS_OK(smbcli_lock(cli->tree, fnum2, 0, 4, 0, WRITE_LOCK)), "WRITE lock2 succeeded! This is a locking bug"); if (!check_error(__location__, cli, ERRDOS, ERRlock, - NT_STATUS_LOCK_NOT_GRANTED)) return False; + NT_STATUS_LOCK_NOT_GRANTED)) return false; torture_assert(tctx, !NT_STATUS_IS_OK(smbcli_lock(cli->tree, fnum2, 0, 4, 0, READ_LOCK)), "READ lock2 succeeded! This is a locking bug"); if (!check_error(__location__, cli, ERRDOS, ERRlock, - NT_STATUS_FILE_LOCK_CONFLICT)) return False; + NT_STATUS_FILE_LOCK_CONFLICT)) return false; torture_assert_ntstatus_ok(tctx, smbcli_lock(cli->tree, fnum1, 100, 4, 0, WRITE_LOCK), @@ -235,7 +235,7 @@ static bool torture_locktest2(struct torture_context *tctx, if (!check_error(__location__, cli, ERRDOS, ERRnotlocked, - NT_STATUS_RANGE_NOT_LOCKED)) return False; + NT_STATUS_RANGE_NOT_LOCKED)) return false; torture_assert(tctx, !NT_STATUS_IS_OK(smbcli_unlock(cli->tree, fnum1, 0, 8)), @@ -243,13 +243,13 @@ static bool torture_locktest2(struct torture_context *tctx, if (!check_error(__location__, cli, ERRDOS, ERRnotlocked, - NT_STATUS_RANGE_NOT_LOCKED)) return False; + NT_STATUS_RANGE_NOT_LOCKED)) return false; torture_assert(tctx, !NT_STATUS_IS_OK(smbcli_lock(cli->tree, fnum3, 0, 4, 0, WRITE_LOCK)), "lock3 succeeded! This is a locking bug"); - if (!check_error(__location__, cli, ERRDOS, ERRlock, NT_STATUS_LOCK_NOT_GRANTED)) return False; + if (!check_error(__location__, cli, ERRDOS, ERRlock, NT_STATUS_LOCK_NOT_GRANTED)) return false; cli->session->pid = 1; @@ -285,7 +285,7 @@ static bool torture_locktest3(struct torture_context *tctx, torture_comment(tctx, "Testing 32 bit offset ranges"); if (!torture_setup_dir(cli1, BASEDIR)) { - return False; + return false; } fnum1 = smbcli_open(cli1->tree, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE); @@ -362,7 +362,7 @@ static bool torture_locktest3(struct torture_context *tctx, } #define EXPECTED(ret, v) if ((ret) != (v)) { \ - torture_comment(tctx, "** "); correct = False; \ + torture_comment(tctx, "** "); correct = false; \ } /* @@ -374,12 +374,12 @@ static bool torture_locktest4(struct torture_context *tctx, { const char *fname = BASEDIR "\\lockt4.lck"; int fnum1, fnum2, f; - BOOL ret; + bool ret; uint8_t buf[1000]; - BOOL correct = True; + bool correct = true; if (!torture_setup_dir(cli1, BASEDIR)) { - return False; + return false; } fnum1 = smbcli_open(cli1->tree, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE); @@ -389,80 +389,80 @@ static bool torture_locktest4(struct torture_context *tctx, if (smbcli_write(cli1->tree, fnum1, 0, buf, 0, sizeof(buf)) != sizeof(buf)) { torture_comment(tctx, "Failed to create file\n"); - correct = False; + correct = false; goto fail; } ret = NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 0, 4, 0, WRITE_LOCK)) && NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 2, 4, 0, WRITE_LOCK)); - EXPECTED(ret, False); + EXPECTED(ret, false); torture_comment(tctx, "the same process %s set overlapping write locks\n", ret?"can":"cannot"); ret = NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 10, 4, 0, READ_LOCK)) && NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 12, 4, 0, READ_LOCK)); - EXPECTED(ret, True); + EXPECTED(ret, true); torture_comment(tctx, "the same process %s set overlapping read locks\n", ret?"can":"cannot"); ret = NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 20, 4, 0, WRITE_LOCK)) && NT_STATUS_IS_OK(smbcli_lock(cli2->tree, fnum2, 22, 4, 0, WRITE_LOCK)); - EXPECTED(ret, False); + EXPECTED(ret, false); torture_comment(tctx, "a different connection %s set overlapping write locks\n", ret?"can":"cannot"); ret = NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 30, 4, 0, READ_LOCK)) && NT_STATUS_IS_OK(smbcli_lock(cli2->tree, fnum2, 32, 4, 0, READ_LOCK)); - EXPECTED(ret, True); + EXPECTED(ret, true); torture_comment(tctx, "a different connection %s set overlapping read locks\n", ret?"can":"cannot"); ret = NT_STATUS_IS_OK((cli1->session->pid = 1, smbcli_lock(cli1->tree, fnum1, 40, 4, 0, WRITE_LOCK))) && NT_STATUS_IS_OK((cli1->session->pid = 2, smbcli_lock(cli1->tree, fnum1, 42, 4, 0, WRITE_LOCK))); - EXPECTED(ret, False); + EXPECTED(ret, false); torture_comment(tctx, "a different pid %s set overlapping write locks\n", ret?"can":"cannot"); ret = NT_STATUS_IS_OK((cli1->session->pid = 1, smbcli_lock(cli1->tree, fnum1, 50, 4, 0, READ_LOCK))) && NT_STATUS_IS_OK((cli1->session->pid = 2, smbcli_lock(cli1->tree, fnum1, 52, 4, 0, READ_LOCK))); - EXPECTED(ret, True); + EXPECTED(ret, true); torture_comment(tctx, "a different pid %s set overlapping read locks\n", ret?"can":"cannot"); ret = NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 60, 4, 0, READ_LOCK)) && NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 60, 4, 0, READ_LOCK)); - EXPECTED(ret, True); + EXPECTED(ret, true); torture_comment(tctx, "the same process %s set the same read lock twice\n", ret?"can":"cannot"); ret = NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 70, 4, 0, WRITE_LOCK)) && NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 70, 4, 0, WRITE_LOCK)); - EXPECTED(ret, False); + EXPECTED(ret, false); torture_comment(tctx, "the same process %s set the same write lock twice\n", ret?"can":"cannot"); ret = NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 80, 4, 0, READ_LOCK)) && NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 80, 4, 0, WRITE_LOCK)); - EXPECTED(ret, False); + EXPECTED(ret, false); torture_comment(tctx, "the same process %s overlay a read lock with a write lock\n", ret?"can":"cannot"); ret = NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 90, 4, 0, WRITE_LOCK)) && NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 90, 4, 0, READ_LOCK)); - EXPECTED(ret, True); + EXPECTED(ret, true); torture_comment(tctx, "the same process %s overlay a write lock with a read lock\n", ret?"can":"cannot"); ret = NT_STATUS_IS_OK((cli1->session->pid = 1, smbcli_lock(cli1->tree, fnum1, 100, 4, 0, WRITE_LOCK))) && NT_STATUS_IS_OK((cli1->session->pid = 2, smbcli_lock(cli1->tree, fnum1, 100, 4, 0, READ_LOCK))); - EXPECTED(ret, False); + EXPECTED(ret, false); torture_comment(tctx, "a different pid %s overlay a write lock with a read lock\n", ret?"can":"cannot"); ret = NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 110, 4, 0, READ_LOCK)) && NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 112, 4, 0, READ_LOCK)) && NT_STATUS_IS_OK(smbcli_unlock(cli1->tree, fnum1, 110, 6)); - EXPECTED(ret, False); + EXPECTED(ret, false); torture_comment(tctx, "the same process %s coalesce read locks\n", ret?"can":"cannot"); ret = NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 120, 4, 0, WRITE_LOCK)) && (smbcli_read(cli2->tree, fnum2, buf, 120, 4) == 4); - EXPECTED(ret, False); + EXPECTED(ret, false); torture_comment(tctx, "this server %s strict write locking\n", ret?"doesn't do":"does"); ret = NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 130, 4, 0, READ_LOCK)) && (smbcli_write(cli2->tree, fnum2, 0, buf, 130, 4) == 4); - EXPECTED(ret, False); + EXPECTED(ret, false); torture_comment(tctx, "this server %s strict read locking\n", ret?"doesn't do":"does"); @@ -470,7 +470,7 @@ static bool torture_locktest4(struct torture_context *tctx, NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 140, 4, 0, READ_LOCK)) && NT_STATUS_IS_OK(smbcli_unlock(cli1->tree, fnum1, 140, 4)) && NT_STATUS_IS_OK(smbcli_unlock(cli1->tree, fnum1, 140, 4)); - EXPECTED(ret, True); + EXPECTED(ret, true); torture_comment(tctx, "this server %s do recursive read locking\n", ret?"does":"doesn't"); @@ -480,21 +480,21 @@ static bool torture_locktest4(struct torture_context *tctx, (smbcli_read(cli2->tree, fnum2, buf, 150, 4) == 4) && !(smbcli_write(cli2->tree, fnum2, 0, buf, 150, 4) == 4) && NT_STATUS_IS_OK(smbcli_unlock(cli1->tree, fnum1, 150, 4)); - EXPECTED(ret, True); + EXPECTED(ret, true); torture_comment(tctx, "this server %s do recursive lock overlays\n", ret?"does":"doesn't"); ret = NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 160, 4, 0, READ_LOCK)) && NT_STATUS_IS_OK(smbcli_unlock(cli1->tree, fnum1, 160, 4)) && (smbcli_write(cli2->tree, fnum2, 0, buf, 160, 4) == 4) && (smbcli_read(cli2->tree, fnum2, buf, 160, 4) == 4); - EXPECTED(ret, True); + EXPECTED(ret, true); torture_comment(tctx, "the same process %s remove a read lock using write locking\n", ret?"can":"cannot"); ret = NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 170, 4, 0, WRITE_LOCK)) && NT_STATUS_IS_OK(smbcli_unlock(cli1->tree, fnum1, 170, 4)) && (smbcli_write(cli2->tree, fnum2, 0, buf, 170, 4) == 4) && (smbcli_read(cli2->tree, fnum2, buf, 170, 4) == 4); - EXPECTED(ret, True); + EXPECTED(ret, true); torture_comment(tctx, "the same process %s remove a write lock using read locking\n", ret?"can":"cannot"); ret = NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 190, 4, 0, WRITE_LOCK)) && @@ -502,7 +502,7 @@ static bool torture_locktest4(struct torture_context *tctx, NT_STATUS_IS_OK(smbcli_unlock(cli1->tree, fnum1, 190, 4)) && !(smbcli_write(cli2->tree, fnum2, 0, buf, 190, 4) == 4) && (smbcli_read(cli2->tree, fnum2, buf, 190, 4) == 4); - EXPECTED(ret, True); + EXPECTED(ret, true); torture_comment(tctx, "the same process %s remove the first lock first\n", ret?"does":"doesn't"); smbcli_close(cli1->tree, fnum1); @@ -516,7 +516,7 @@ static bool torture_locktest4(struct torture_context *tctx, NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 7, 1, 0, WRITE_LOCK)); smbcli_close(cli1->tree, f); smbcli_close(cli1->tree, fnum1); - EXPECTED(ret, True); + EXPECTED(ret, true); torture_comment(tctx, "the server %s have the NT byte range lock bug\n", !ret?"does":"doesn't"); fail: @@ -535,12 +535,12 @@ static bool torture_locktest5(struct torture_context *tctx, struct smbcli_state { const char *fname = BASEDIR "\\lockt5.lck"; int fnum1, fnum2, fnum3; - BOOL ret; + bool ret; uint8_t buf[1000]; - BOOL correct = True; + bool correct = true; if (!torture_setup_dir(cli1, BASEDIR)) { - return False; + return false; } fnum1 = smbcli_open(cli1->tree, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE); @@ -558,7 +558,7 @@ static bool torture_locktest5(struct torture_context *tctx, struct smbcli_state smbcli_close(cli1->tree, fnum1); fnum1 = smbcli_open(cli1->tree, fname, O_RDWR, DENY_NONE); ret = NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 7, 1, 0, WRITE_LOCK)); - EXPECTED(ret, True); + EXPECTED(ret, true); torture_comment(tctx, "this server %s the NT locking bug\n", ret ? "doesn't have" : "has"); smbcli_close(cli1->tree, fnum1); fnum1 = smbcli_open(cli1->tree, fname, O_RDWR, DENY_NONE); @@ -566,11 +566,11 @@ static bool torture_locktest5(struct torture_context *tctx, struct smbcli_state ret = NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 0, 4, 0, WRITE_LOCK)) && NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 1, 1, 0, READ_LOCK)); - EXPECTED(ret, True); + EXPECTED(ret, true); torture_comment(tctx, "the same process %s overlay a write with a read lock\n", ret?"can":"cannot"); ret = NT_STATUS_IS_OK(smbcli_lock(cli2->tree, fnum2, 0, 4, 0, READ_LOCK)); - EXPECTED(ret, False); + EXPECTED(ret, false); torture_comment(tctx, "a different processs %s get a read lock on the first process lock stack\n", ret?"can":"cannot"); @@ -578,7 +578,7 @@ static bool torture_locktest5(struct torture_context *tctx, struct smbcli_state smbcli_unlock(cli2->tree, fnum2, 0, 4); ret = NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum3, 0, 4, 0, READ_LOCK)); - EXPECTED(ret, False); + EXPECTED(ret, false); torture_comment(tctx, "the same processs on a different fnum %s get a read lock\n", ret?"can":"cannot"); @@ -589,7 +589,7 @@ static bool torture_locktest5(struct torture_context *tctx, struct smbcli_state ret = NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 0, 4, 0, READ_LOCK)) && NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 0, 4, 0, READ_LOCK)); - EXPECTED(ret, True); + EXPECTED(ret, true); torture_comment(tctx, "the same process %s stack read locks\n", ret?"can":"cannot"); /* Unlock the first process lock, then check this was the WRITE lock that was @@ -598,7 +598,7 @@ static bool torture_locktest5(struct torture_context *tctx, struct smbcli_state ret = NT_STATUS_IS_OK(smbcli_unlock(cli1->tree, fnum1, 0, 4)) && NT_STATUS_IS_OK(smbcli_lock(cli2->tree, fnum2, 0, 4, 0, READ_LOCK)); - EXPECTED(ret, True); + EXPECTED(ret, true); torture_comment(tctx, "the first unlock removes the %s lock\n", ret?"WRITE":"READ"); /* Unlock the process 2 lock. */ @@ -610,17 +610,17 @@ ret = NT_STATUS_IS_OK(smbcli_unlock(cli1->tree, fnum1, 0, 4)) && NT_STATUS_IS_OK(smbcli_unlock(cli1->tree, fnum1, 0, 4)) && NT_STATUS_IS_OK(smbcli_unlock(cli1->tree, fnum1, 0, 4)); - EXPECTED(ret, True); + EXPECTED(ret, true); torture_comment(tctx, "the same process %s unlock the stack of 4 locks\n", ret?"can":"cannot"); /* Ensure the next unlock fails. */ ret = NT_STATUS_IS_OK(smbcli_unlock(cli1->tree, fnum1, 0, 4)); - EXPECTED(ret, False); + EXPECTED(ret, false); torture_comment(tctx, "the same process %s count the lock stack\n", !ret?"can":"cannot"); /* Ensure connection 2 can get a write lock. */ ret = NT_STATUS_IS_OK(smbcli_lock(cli2->tree, fnum2, 0, 4, 0, WRITE_LOCK)); - EXPECTED(ret, True); + EXPECTED(ret, true); torture_comment(tctx, "a different processs %s get a write lock on the unlocked stack\n", ret?"can":"cannot"); @@ -644,7 +644,7 @@ static bool torture_locktest6(struct torture_context *tctx, NTSTATUS status; if (!torture_setup_dir(cli, BASEDIR)) { - return False; + return false; } for (i=0;i<1;i++) { @@ -665,7 +665,7 @@ static bool torture_locktest6(struct torture_context *tctx, smbcli_unlink(cli->tree, fname[i]); } - return True; + return true; } static bool torture_locktest7(struct torture_context *tctx, @@ -676,7 +676,7 @@ static bool torture_locktest7(struct torture_context *tctx, int fnum2 = -1; size_t size; uint8_t buf[200]; - BOOL correct = False; + bool correct = false; torture_assert(tctx, torture_setup_dir(cli1, BASEDIR), talloc_asprintf(tctx, "Unable to set up %s", BASEDIR)); @@ -785,7 +785,7 @@ static bool torture_locktest7(struct torture_context *tctx, cli1->session->pid = 1; smbcli_unlock(cli1->tree, fnum1, 130, 4); - correct = True; + correct = true; fail: smbcli_close(cli1->tree, fnum1); -- cgit From 1e973565b6c0cb738b25a2d9439d5acb441701f4 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 27 Apr 2008 14:02:46 +0100 Subject: Move subunit infrastructure code into lib/torture. (This used to be commit 5b44d8121de7735d69e6238a1442aff034a8ebd3) --- source4/torture/basic/locking.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source4/torture/basic/locking.c') diff --git a/source4/torture/basic/locking.c b/source4/torture/basic/locking.c index 2e2585b976..3f399c97ef 100644 --- a/source4/torture/basic/locking.c +++ b/source4/torture/basic/locking.c @@ -23,9 +23,8 @@ #include "includes.h" #include "libcli/raw/libcliraw.h" #include "libcli/libcli.h" -#include "torture/ui.h" +#include "torture/smbtorture.h" #include "torture/util.h" -#include "torture/torture.h" #include "system/time.h" #include "system/filesys.h" -- cgit