2 Unix SMB/CIFS implementation.
3 test suite for various read operations
4 Copyright (C) Andrew Tridgell 2003
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include "torture/torture.h"
23 #include "libcli/raw/libcliraw.h"
24 #include "system/time.h"
25 #include "system/filesys.h"
26 #include "libcli/libcli.h"
28 #define CHECK_STATUS(status, correct) do { \
29 if (!NT_STATUS_EQUAL(status, correct)) { \
30 printf("(%s) Incorrect status %s - should be %s\n", \
31 __location__, nt_errstr(status), nt_errstr(correct)); \
36 #define CHECK_VALUE(v, correct) do { \
37 if ((v) != (correct)) { \
38 printf("(%s) Incorrect value %s=%ld - should be %ld\n", \
39 __location__, #v, (long)v, (long)correct); \
44 #define CHECK_BUFFER(buf, seed, len) do { \
45 if (!check_buffer(buf, seed, len, __LINE__)) { \
50 #define BASEDIR "\\testread"
54 setup a random buffer based on a seed
56 static void setup_buffer(uint8_t *buf, uint_t seed, int len)
60 for (i=0;i<len;i++) buf[i] = random();
64 check a random buffer based on a seed
66 static BOOL check_buffer(uint8_t *buf, uint_t seed, int len, int line)
73 printf("Buffer incorrect at line %d! ofs=%d v1=0x%x v2=0x%x\n",
84 static BOOL test_read(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
91 const int maxsize = 90000;
92 const char *fname = BASEDIR "\\test.txt";
93 const char *test_data = "TEST DATA";
94 uint_t seed = time(NULL);
96 buf = talloc_zero_size(mem_ctx, maxsize);
98 if (!torture_setup_dir(cli, BASEDIR)) {
102 printf("Testing RAW_READ_READ\n");
103 io.generic.level = RAW_READ_READ;
105 fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
107 printf("Failed to create %s - %s\n", fname, smbcli_errstr(cli->tree));
112 printf("Trying empty file read\n");
113 io.read.file.fnum = fnum;
114 io.read.in.count = 1;
115 io.read.in.offset = 0;
116 io.read.in.remaining = 0;
117 io.read.out.data = buf;
118 status = smb_raw_read(cli->tree, &io);
120 CHECK_STATUS(status, NT_STATUS_OK);
121 CHECK_VALUE(io.read.out.nread, 0);
123 printf("Trying zero file read\n");
124 io.read.in.count = 0;
125 status = smb_raw_read(cli->tree, &io);
126 CHECK_STATUS(status, NT_STATUS_OK);
127 CHECK_VALUE(io.read.out.nread, 0);
129 printf("Trying bad fnum\n");
130 io.read.file.fnum = fnum+1;
131 status = smb_raw_read(cli->tree, &io);
132 CHECK_STATUS(status, NT_STATUS_INVALID_HANDLE);
133 io.read.file.fnum = fnum;
135 smbcli_write(cli->tree, fnum, 0, test_data, 0, strlen(test_data));
137 printf("Trying small read\n");
138 io.read.file.fnum = fnum;
139 io.read.in.offset = 0;
140 io.read.in.remaining = 0;
141 io.read.in.count = strlen(test_data);
142 status = smb_raw_read(cli->tree, &io);
143 CHECK_STATUS(status, NT_STATUS_OK);
144 CHECK_VALUE(io.read.out.nread, strlen(test_data));
145 if (memcmp(buf, test_data, strlen(test_data)) != 0) {
147 printf("incorrect data at %d!? (%s:%s)\n", __LINE__, test_data, buf);
151 printf("Trying short read\n");
152 io.read.in.offset = 1;
153 io.read.in.count = strlen(test_data);
154 status = smb_raw_read(cli->tree, &io);
155 CHECK_STATUS(status, NT_STATUS_OK);
156 CHECK_VALUE(io.read.out.nread, strlen(test_data)-1);
157 if (memcmp(buf, test_data+1, strlen(test_data)-1) != 0) {
159 printf("incorrect data at %d!? (%s:%s)\n", __LINE__, test_data+1, buf);
163 printf("Trying max offset\n");
164 io.read.in.offset = ~0;
165 io.read.in.count = strlen(test_data);
166 status = smb_raw_read(cli->tree, &io);
167 CHECK_STATUS(status, NT_STATUS_OK);
168 CHECK_VALUE(io.read.out.nread, 0);
170 setup_buffer(buf, seed, maxsize);
171 smbcli_write(cli->tree, fnum, 0, buf, 0, maxsize);
172 memset(buf, 0, maxsize);
174 printf("Trying large read\n");
175 io.read.in.offset = 0;
176 io.read.in.count = ~0;
177 status = smb_raw_read(cli->tree, &io);
178 CHECK_STATUS(status, NT_STATUS_OK);
179 CHECK_BUFFER(buf, seed, io.read.out.nread);
182 printf("Trying locked region\n");
184 if (NT_STATUS_IS_ERR(smbcli_lock(cli->tree, fnum, 103, 1, 0, WRITE_LOCK))) {
185 printf("Failed to lock file at %d\n", __LINE__);
190 memset(buf, 0, maxsize);
191 io.read.in.offset = 0;
192 io.read.in.count = ~0;
193 status = smb_raw_read(cli->tree, &io);
194 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
198 smbcli_close(cli->tree, fnum);
199 smb_raw_exit(cli->session);
200 smbcli_deltree(cli->tree, BASEDIR);
208 static BOOL test_lockread(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
215 const int maxsize = 90000;
216 const char *fname = BASEDIR "\\test.txt";
217 const char *test_data = "TEST DATA";
218 uint_t seed = time(NULL);
220 buf = talloc_zero_size(mem_ctx, maxsize);
222 if (!torture_setup_dir(cli, BASEDIR)) {
226 printf("Testing RAW_READ_LOCKREAD\n");
227 io.generic.level = RAW_READ_LOCKREAD;
229 fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
231 printf("Failed to create %s - %s\n", fname, smbcli_errstr(cli->tree));
236 printf("Trying empty file read\n");
237 io.lockread.file.fnum = fnum;
238 io.lockread.in.count = 1;
239 io.lockread.in.offset = 1;
240 io.lockread.in.remaining = 0;
241 io.lockread.out.data = buf;
242 status = smb_raw_read(cli->tree, &io);
244 CHECK_STATUS(status, NT_STATUS_OK);
245 CHECK_VALUE(io.lockread.out.nread, 0);
247 status = smb_raw_read(cli->tree, &io);
248 CHECK_STATUS(status, NT_STATUS_LOCK_NOT_GRANTED);
250 status = smb_raw_read(cli->tree, &io);
251 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
253 printf("Trying zero file read\n");
254 io.lockread.in.count = 0;
255 status = smb_raw_read(cli->tree, &io);
256 CHECK_STATUS(status, NT_STATUS_OK);
258 smbcli_unlock(cli->tree, fnum, 1, 1);
260 printf("Trying bad fnum\n");
261 io.lockread.file.fnum = fnum+1;
262 status = smb_raw_read(cli->tree, &io);
263 CHECK_STATUS(status, NT_STATUS_INVALID_HANDLE);
264 io.lockread.file.fnum = fnum;
266 smbcli_write(cli->tree, fnum, 0, test_data, 0, strlen(test_data));
268 printf("Trying small read\n");
269 io.lockread.file.fnum = fnum;
270 io.lockread.in.offset = 0;
271 io.lockread.in.remaining = 0;
272 io.lockread.in.count = strlen(test_data);
273 status = smb_raw_read(cli->tree, &io);
274 CHECK_STATUS(status, NT_STATUS_LOCK_NOT_GRANTED);
276 smbcli_unlock(cli->tree, fnum, 1, 0);
278 status = smb_raw_read(cli->tree, &io);
279 CHECK_STATUS(status, NT_STATUS_OK);
280 CHECK_VALUE(io.lockread.out.nread, strlen(test_data));
281 if (memcmp(buf, test_data, strlen(test_data)) != 0) {
283 printf("incorrect data at %d!? (%s:%s)\n", __LINE__, test_data, buf);
287 printf("Trying short read\n");
288 io.lockread.in.offset = 1;
289 io.lockread.in.count = strlen(test_data);
290 status = smb_raw_read(cli->tree, &io);
291 CHECK_STATUS(status, NT_STATUS_LOCK_NOT_GRANTED);
292 smbcli_unlock(cli->tree, fnum, 0, strlen(test_data));
293 status = smb_raw_read(cli->tree, &io);
294 CHECK_STATUS(status, NT_STATUS_OK);
296 CHECK_VALUE(io.lockread.out.nread, strlen(test_data)-1);
297 if (memcmp(buf, test_data+1, strlen(test_data)-1) != 0) {
299 printf("incorrect data at %d!? (%s:%s)\n", __LINE__, test_data+1, buf);
303 printf("Trying max offset\n");
304 io.lockread.in.offset = ~0;
305 io.lockread.in.count = strlen(test_data);
306 status = smb_raw_read(cli->tree, &io);
307 CHECK_STATUS(status, NT_STATUS_OK);
308 CHECK_VALUE(io.lockread.out.nread, 0);
310 setup_buffer(buf, seed, maxsize);
311 smbcli_write(cli->tree, fnum, 0, buf, 0, maxsize);
312 memset(buf, 0, maxsize);
314 printf("Trying large read\n");
315 io.lockread.in.offset = 0;
316 io.lockread.in.count = ~0;
317 status = smb_raw_read(cli->tree, &io);
318 CHECK_STATUS(status, NT_STATUS_LOCK_NOT_GRANTED);
319 smbcli_unlock(cli->tree, fnum, 1, strlen(test_data));
320 status = smb_raw_read(cli->tree, &io);
321 CHECK_STATUS(status, NT_STATUS_OK);
322 CHECK_BUFFER(buf, seed, io.lockread.out.nread);
323 smbcli_unlock(cli->tree, fnum, 0, 0xFFFF);
326 printf("Trying locked region\n");
328 if (NT_STATUS_IS_ERR(smbcli_lock(cli->tree, fnum, 103, 1, 0, WRITE_LOCK))) {
329 printf("Failed to lock file at %d\n", __LINE__);
334 memset(buf, 0, maxsize);
335 io.lockread.in.offset = 0;
336 io.lockread.in.count = ~0;
337 status = smb_raw_read(cli->tree, &io);
338 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
342 smbcli_close(cli->tree, fnum);
343 smbcli_deltree(cli->tree, BASEDIR);
351 static BOOL test_readx(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
358 const int maxsize = 90000;
359 const char *fname = BASEDIR "\\test.txt";
360 const char *test_data = "TEST DATA";
361 uint_t seed = time(NULL);
363 buf = talloc_zero_size(mem_ctx, maxsize);
365 if (!torture_setup_dir(cli, BASEDIR)) {
369 printf("Testing RAW_READ_READX\n");
371 fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
373 printf("Failed to create %s - %s\n", fname, smbcli_errstr(cli->tree));
378 printf("Trying empty file read\n");
379 io.generic.level = RAW_READ_READX;
380 io.readx.file.fnum = fnum;
381 io.readx.in.mincnt = 1;
382 io.readx.in.maxcnt = 1;
383 io.readx.in.offset = 0;
384 io.readx.in.remaining = 0;
385 io.readx.out.data = buf;
386 status = smb_raw_read(cli->tree, &io);
388 CHECK_STATUS(status, NT_STATUS_OK);
389 CHECK_VALUE(io.readx.out.nread, 0);
390 CHECK_VALUE(io.readx.out.remaining, 0xFFFF);
391 CHECK_VALUE(io.readx.out.compaction_mode, 0);
393 printf("Trying zero file read\n");
394 io.readx.in.mincnt = 0;
395 io.readx.in.maxcnt = 0;
396 status = smb_raw_read(cli->tree, &io);
397 CHECK_STATUS(status, NT_STATUS_OK);
398 CHECK_VALUE(io.readx.out.nread, 0);
399 CHECK_VALUE(io.readx.out.remaining, 0xFFFF);
400 CHECK_VALUE(io.readx.out.compaction_mode, 0);
402 printf("Trying bad fnum\n");
403 io.readx.file.fnum = fnum+1;
404 status = smb_raw_read(cli->tree, &io);
405 CHECK_STATUS(status, NT_STATUS_INVALID_HANDLE);
406 io.readx.file.fnum = fnum;
408 smbcli_write(cli->tree, fnum, 0, test_data, 0, strlen(test_data));
410 printf("Trying small read\n");
411 io.readx.file.fnum = fnum;
412 io.readx.in.offset = 0;
413 io.readx.in.remaining = 0;
414 io.readx.in.mincnt = strlen(test_data);
415 io.readx.in.maxcnt = strlen(test_data);
416 status = smb_raw_read(cli->tree, &io);
417 CHECK_STATUS(status, NT_STATUS_OK);
418 CHECK_VALUE(io.readx.out.nread, strlen(test_data));
419 CHECK_VALUE(io.readx.out.remaining, 0xFFFF);
420 CHECK_VALUE(io.readx.out.compaction_mode, 0);
421 if (memcmp(buf, test_data, strlen(test_data)) != 0) {
423 printf("incorrect data at %d!? (%s:%s)\n", __LINE__, test_data, buf);
427 printf("Trying short read\n");
428 io.readx.in.offset = 1;
429 io.readx.in.mincnt = strlen(test_data);
430 io.readx.in.maxcnt = strlen(test_data);
431 status = smb_raw_read(cli->tree, &io);
432 CHECK_STATUS(status, NT_STATUS_OK);
433 CHECK_VALUE(io.readx.out.nread, strlen(test_data)-1);
434 CHECK_VALUE(io.readx.out.remaining, 0xFFFF);
435 CHECK_VALUE(io.readx.out.compaction_mode, 0);
436 if (memcmp(buf, test_data+1, strlen(test_data)-1) != 0) {
438 printf("incorrect data at %d!? (%s:%s)\n", __LINE__, test_data+1, buf);
442 printf("Trying max offset\n");
443 io.readx.in.offset = 0xffffffff;
444 io.readx.in.mincnt = strlen(test_data);
445 io.readx.in.maxcnt = strlen(test_data);
446 status = smb_raw_read(cli->tree, &io);
447 CHECK_STATUS(status, NT_STATUS_OK);
448 CHECK_VALUE(io.readx.out.nread, 0);
449 CHECK_VALUE(io.readx.out.remaining, 0xFFFF);
450 CHECK_VALUE(io.readx.out.compaction_mode, 0);
452 setup_buffer(buf, seed, maxsize);
453 smbcli_write(cli->tree, fnum, 0, buf, 0, maxsize);
454 memset(buf, 0, maxsize);
456 printf("Trying large read\n");
457 io.readx.in.offset = 0;
458 io.readx.in.mincnt = 0xFFFF;
459 io.readx.in.maxcnt = 0xFFFF;
460 status = smb_raw_read(cli->tree, &io);
461 CHECK_STATUS(status, NT_STATUS_OK);
462 CHECK_VALUE(io.readx.out.remaining, 0xFFFF);
463 CHECK_VALUE(io.readx.out.compaction_mode, 0);
464 CHECK_VALUE(io.readx.out.nread, io.readx.in.maxcnt);
465 CHECK_BUFFER(buf, seed, io.readx.out.nread);
467 printf("Trying extra large read\n");
468 io.readx.in.offset = 0;
469 io.readx.in.mincnt = 100;
470 io.readx.in.maxcnt = 80000;
471 status = smb_raw_read(cli->tree, &io);
472 CHECK_STATUS(status, NT_STATUS_OK);
473 CHECK_VALUE(io.readx.out.remaining, 0xFFFF);
474 CHECK_VALUE(io.readx.out.compaction_mode, 0);
475 CHECK_VALUE(io.readx.out.nread, 0);
476 CHECK_BUFFER(buf, seed, io.readx.out.nread);
478 printf("Trying mincnt > maxcnt\n");
479 memset(buf, 0, maxsize);
480 io.readx.in.offset = 0;
481 io.readx.in.mincnt = 30000;
482 io.readx.in.maxcnt = 20000;
483 status = smb_raw_read(cli->tree, &io);
484 CHECK_STATUS(status, NT_STATUS_OK);
485 CHECK_VALUE(io.readx.out.remaining, 0xFFFF);
486 CHECK_VALUE(io.readx.out.compaction_mode, 0);
487 CHECK_VALUE(io.readx.out.nread, io.readx.in.maxcnt);
488 CHECK_BUFFER(buf, seed, io.readx.out.nread);
490 printf("Trying mincnt < maxcnt\n");
491 memset(buf, 0, maxsize);
492 io.readx.in.offset = 0;
493 io.readx.in.mincnt = 20000;
494 io.readx.in.maxcnt = 30000;
495 status = smb_raw_read(cli->tree, &io);
496 CHECK_STATUS(status, NT_STATUS_OK);
497 CHECK_VALUE(io.readx.out.remaining, 0xFFFF);
498 CHECK_VALUE(io.readx.out.compaction_mode, 0);
499 CHECK_VALUE(io.readx.out.nread, io.readx.in.maxcnt);
500 CHECK_BUFFER(buf, seed, io.readx.out.nread);
502 printf("Trying locked region\n");
504 if (NT_STATUS_IS_ERR(smbcli_lock(cli->tree, fnum, 103, 1, 0, WRITE_LOCK))) {
505 printf("Failed to lock file at %d\n", __LINE__);
510 memset(buf, 0, maxsize);
511 io.readx.in.offset = 0;
512 io.readx.in.mincnt = 100;
513 io.readx.in.maxcnt = 200;
514 status = smb_raw_read(cli->tree, &io);
515 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
517 printf("Trying large offset read\n");
518 io.readx.in.offset = ((uint64_t)0x2) << 32;
519 io.readx.in.mincnt = 10;
520 io.readx.in.maxcnt = 10;
521 status = smb_raw_read(cli->tree, &io);
522 CHECK_STATUS(status, NT_STATUS_OK);
523 CHECK_VALUE(io.readx.out.nread, 0);
525 if (NT_STATUS_IS_ERR(smbcli_lock64(cli->tree, fnum, io.readx.in.offset, 1, 0, WRITE_LOCK))) {
526 printf("Failed to lock file at %d\n", __LINE__);
531 status = smb_raw_read(cli->tree, &io);
532 CHECK_STATUS(status, NT_STATUS_OK);
533 CHECK_VALUE(io.readx.out.nread, 0);
536 smbcli_close(cli->tree, fnum);
537 smbcli_deltree(cli->tree, BASEDIR);
545 static BOOL test_readbraw(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
552 const int maxsize = 90000;
553 const char *fname = BASEDIR "\\test.txt";
554 const char *test_data = "TEST DATA";
555 uint_t seed = time(NULL);
557 buf = talloc_zero_size(mem_ctx, maxsize);
559 if (!torture_setup_dir(cli, BASEDIR)) {
563 printf("Testing RAW_READ_READBRAW\n");
565 fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
567 printf("Failed to create %s - %s\n", fname, smbcli_errstr(cli->tree));
572 printf("Trying empty file read\n");
573 io.generic.level = RAW_READ_READBRAW;
574 io.readbraw.file.fnum = fnum;
575 io.readbraw.in.mincnt = 1;
576 io.readbraw.in.maxcnt = 1;
577 io.readbraw.in.offset = 0;
578 io.readbraw.in.timeout = 0;
579 io.readbraw.out.data = buf;
580 status = smb_raw_read(cli->tree, &io);
582 CHECK_STATUS(status, NT_STATUS_OK);
583 CHECK_VALUE(io.readbraw.out.nread, 0);
585 printf("Trying zero file read\n");
586 io.readbraw.in.mincnt = 0;
587 io.readbraw.in.maxcnt = 0;
588 status = smb_raw_read(cli->tree, &io);
589 CHECK_STATUS(status, NT_STATUS_OK);
590 CHECK_VALUE(io.readbraw.out.nread, 0);
592 printf("Trying bad fnum\n");
593 io.readbraw.file.fnum = fnum+1;
594 status = smb_raw_read(cli->tree, &io);
595 CHECK_STATUS(status, NT_STATUS_OK);
596 CHECK_VALUE(io.readbraw.out.nread, 0);
597 io.readbraw.file.fnum = fnum;
599 smbcli_write(cli->tree, fnum, 0, test_data, 0, strlen(test_data));
601 printf("Trying small read\n");
602 io.readbraw.file.fnum = fnum;
603 io.readbraw.in.offset = 0;
604 io.readbraw.in.mincnt = strlen(test_data);
605 io.readbraw.in.maxcnt = strlen(test_data);
606 status = smb_raw_read(cli->tree, &io);
607 CHECK_STATUS(status, NT_STATUS_OK);
608 CHECK_VALUE(io.readbraw.out.nread, strlen(test_data));
609 if (memcmp(buf, test_data, strlen(test_data)) != 0) {
611 printf("incorrect data at %d!? (%s:%s)\n", __LINE__, test_data, buf);
615 printf("Trying short read\n");
616 io.readbraw.in.offset = 1;
617 io.readbraw.in.mincnt = strlen(test_data);
618 io.readbraw.in.maxcnt = strlen(test_data);
619 status = smb_raw_read(cli->tree, &io);
620 CHECK_STATUS(status, NT_STATUS_OK);
621 CHECK_VALUE(io.readbraw.out.nread, strlen(test_data)-1);
622 if (memcmp(buf, test_data+1, strlen(test_data)-1) != 0) {
624 printf("incorrect data at %d!? (%s:%s)\n", __LINE__, test_data+1, buf);
628 printf("Trying max offset\n");
629 io.readbraw.in.offset = ~0;
630 io.readbraw.in.mincnt = strlen(test_data);
631 io.readbraw.in.maxcnt = strlen(test_data);
632 status = smb_raw_read(cli->tree, &io);
633 CHECK_STATUS(status, NT_STATUS_OK);
634 CHECK_VALUE(io.readbraw.out.nread, 0);
636 setup_buffer(buf, seed, maxsize);
637 smbcli_write(cli->tree, fnum, 0, buf, 0, maxsize);
638 memset(buf, 0, maxsize);
640 printf("Trying large read\n");
641 io.readbraw.in.offset = 0;
642 io.readbraw.in.mincnt = ~0;
643 io.readbraw.in.maxcnt = ~0;
644 status = smb_raw_read(cli->tree, &io);
645 CHECK_STATUS(status, NT_STATUS_OK);
646 CHECK_VALUE(io.readbraw.out.nread, 0xFFFF);
647 CHECK_BUFFER(buf, seed, io.readbraw.out.nread);
649 printf("Trying mincnt > maxcnt\n");
650 memset(buf, 0, maxsize);
651 io.readbraw.in.offset = 0;
652 io.readbraw.in.mincnt = 30000;
653 io.readbraw.in.maxcnt = 20000;
654 status = smb_raw_read(cli->tree, &io);
655 CHECK_STATUS(status, NT_STATUS_OK);
656 CHECK_VALUE(io.readbraw.out.nread, io.readbraw.in.maxcnt);
657 CHECK_BUFFER(buf, seed, io.readbraw.out.nread);
659 printf("Trying mincnt < maxcnt\n");
660 memset(buf, 0, maxsize);
661 io.readbraw.in.offset = 0;
662 io.readbraw.in.mincnt = 20000;
663 io.readbraw.in.maxcnt = 30000;
664 status = smb_raw_read(cli->tree, &io);
665 CHECK_STATUS(status, NT_STATUS_OK);
666 CHECK_VALUE(io.readbraw.out.nread, io.readbraw.in.maxcnt);
667 CHECK_BUFFER(buf, seed, io.readbraw.out.nread);
669 printf("Trying locked region\n");
671 if (NT_STATUS_IS_ERR(smbcli_lock(cli->tree, fnum, 103, 1, 0, WRITE_LOCK))) {
672 printf("Failed to lock file at %d\n", __LINE__);
677 memset(buf, 0, maxsize);
678 io.readbraw.in.offset = 0;
679 io.readbraw.in.mincnt = 100;
680 io.readbraw.in.maxcnt = 200;
681 status = smb_raw_read(cli->tree, &io);
682 CHECK_STATUS(status, NT_STATUS_OK);
683 CHECK_VALUE(io.readbraw.out.nread, 0);
685 printf("Trying locked region with timeout\n");
686 memset(buf, 0, maxsize);
687 io.readbraw.in.offset = 0;
688 io.readbraw.in.mincnt = 100;
689 io.readbraw.in.maxcnt = 200;
690 io.readbraw.in.timeout = 10000;
691 status = smb_raw_read(cli->tree, &io);
692 CHECK_STATUS(status, NT_STATUS_OK);
693 CHECK_VALUE(io.readbraw.out.nread, 0);
695 printf("Trying large offset read\n");
696 io.readbraw.in.offset = ((uint64_t)0x2) << 32;
697 io.readbraw.in.mincnt = 10;
698 io.readbraw.in.maxcnt = 10;
699 io.readbraw.in.timeout = 0;
700 status = smb_raw_read(cli->tree, &io);
701 CHECK_STATUS(status, NT_STATUS_OK);
702 CHECK_VALUE(io.readbraw.out.nread, 0);
705 smbcli_close(cli->tree, fnum);
706 smbcli_deltree(cli->tree, BASEDIR);
712 basic testing of read calls
714 BOOL torture_raw_read(void)
716 struct smbcli_state *cli;
720 if (!torture_open_connection(&cli)) {
724 mem_ctx = talloc_init("torture_raw_read");
726 if (!test_read(cli, mem_ctx)) {
730 if (!test_readx(cli, mem_ctx)) {
734 if (!test_lockread(cli, mem_ctx)) {
738 if (!test_readbraw(cli, mem_ctx)) {
742 torture_close_connection(cli);
743 talloc_free(mem_ctx);