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 "libcli/raw/libcliraw.h"
23 #include "system/time.h"
25 #define CHECK_STATUS(status, correct) do { \
26 if (!NT_STATUS_EQUAL(status, correct)) { \
27 printf("(%s) Incorrect status %s - should be %s\n", \
28 __location__, nt_errstr(status), nt_errstr(correct)); \
33 #define CHECK_VALUE(v, correct) do { \
34 if ((v) != (correct)) { \
35 printf("(%s) Incorrect value %s=%d - should be %d\n", \
36 __location__, #v, v, correct); \
41 #define CHECK_BUFFER(buf, seed, len) do { \
42 if (!check_buffer(buf, seed, len, __LINE__)) { \
47 #define BASEDIR "\\testread"
51 setup a random buffer based on a seed
53 static void setup_buffer(char *buf, uint_t seed, int len)
57 for (i=0;i<len;i++) buf[i] = random();
61 check a random buffer based on a seed
63 static BOOL check_buffer(char *buf, uint_t seed, int len, int line)
70 printf("Buffer incorrect at line %d! ofs=%d v1=0x%x v2=0x%x\n",
81 static BOOL test_read(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
88 const int maxsize = 90000;
89 const char *fname = BASEDIR "\\test.txt";
90 const char *test_data = "TEST DATA";
91 uint_t seed = time(NULL);
93 buf = talloc_zero(mem_ctx, maxsize);
95 if (smbcli_deltree(cli->tree, BASEDIR) == -1 ||
96 NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, BASEDIR))) {
97 printf("Unable to setup %s - %s\n", BASEDIR, smbcli_errstr(cli->tree));
101 printf("Testing RAW_READ_READ\n");
102 io.generic.level = RAW_READ_READ;
104 fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
106 printf("Failed to create %s - %s\n", fname, smbcli_errstr(cli->tree));
111 printf("Trying empty file read\n");
112 io.read.in.fnum = fnum;
113 io.read.in.count = 1;
114 io.read.in.offset = 0;
115 io.read.in.remaining = 0;
116 io.read.out.data = buf;
117 status = smb_raw_read(cli->tree, &io);
119 CHECK_STATUS(status, NT_STATUS_OK);
120 CHECK_VALUE(io.read.out.nread, 0);
122 printf("Trying zero file read\n");
123 io.read.in.count = 0;
124 status = smb_raw_read(cli->tree, &io);
125 CHECK_STATUS(status, NT_STATUS_OK);
126 CHECK_VALUE(io.read.out.nread, 0);
128 printf("Trying bad fnum\n");
129 io.read.in.fnum = fnum+1;
130 status = smb_raw_read(cli->tree, &io);
131 CHECK_STATUS(status, NT_STATUS_INVALID_HANDLE);
132 io.read.in.fnum = fnum;
134 smbcli_write(cli->tree, fnum, 0, test_data, 0, strlen(test_data));
136 printf("Trying small read\n");
137 io.read.in.fnum = fnum;
138 io.read.in.offset = 0;
139 io.read.in.remaining = 0;
140 io.read.in.count = strlen(test_data);
141 status = smb_raw_read(cli->tree, &io);
142 CHECK_STATUS(status, NT_STATUS_OK);
143 CHECK_VALUE(io.read.out.nread, strlen(test_data));
144 if (memcmp(buf, test_data, strlen(test_data)) != 0) {
146 printf("incorrect data at %d!? (%s:%s)\n", __LINE__, test_data, buf);
150 printf("Trying short read\n");
151 io.read.in.offset = 1;
152 io.read.in.count = strlen(test_data);
153 status = smb_raw_read(cli->tree, &io);
154 CHECK_STATUS(status, NT_STATUS_OK);
155 CHECK_VALUE(io.read.out.nread, strlen(test_data)-1);
156 if (memcmp(buf, test_data+1, strlen(test_data)-1) != 0) {
158 printf("incorrect data at %d!? (%s:%s)\n", __LINE__, test_data+1, buf);
162 printf("Trying max offset\n");
163 io.read.in.offset = ~0;
164 io.read.in.count = strlen(test_data);
165 status = smb_raw_read(cli->tree, &io);
166 CHECK_STATUS(status, NT_STATUS_OK);
167 CHECK_VALUE(io.read.out.nread, 0);
169 setup_buffer(buf, seed, maxsize);
170 smbcli_write(cli->tree, fnum, 0, buf, 0, maxsize);
171 memset(buf, 0, maxsize);
173 printf("Trying large read\n");
174 io.read.in.offset = 0;
175 io.read.in.count = ~0;
176 status = smb_raw_read(cli->tree, &io);
177 CHECK_STATUS(status, NT_STATUS_OK);
178 CHECK_BUFFER(buf, seed, io.read.out.nread);
181 printf("Trying locked region\n");
183 if (NT_STATUS_IS_ERR(smbcli_lock(cli->tree, fnum, 103, 1, 0, WRITE_LOCK))) {
184 printf("Failed to lock file at %d\n", __LINE__);
189 memset(buf, 0, maxsize);
190 io.read.in.offset = 0;
191 io.read.in.count = ~0;
192 status = smb_raw_read(cli->tree, &io);
193 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
197 smbcli_close(cli->tree, fnum);
198 smb_raw_exit(cli->session);
199 smbcli_deltree(cli->tree, BASEDIR);
207 static BOOL test_lockread(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
214 const int maxsize = 90000;
215 const char *fname = BASEDIR "\\test.txt";
216 const char *test_data = "TEST DATA";
217 uint_t seed = time(NULL);
219 buf = talloc_zero(mem_ctx, maxsize);
221 if (smbcli_deltree(cli->tree, BASEDIR) == -1 ||
222 NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, BASEDIR))) {
223 printf("Unable to setup %s - %s\n", BASEDIR, smbcli_errstr(cli->tree));
227 printf("Testing RAW_READ_LOCKREAD\n");
228 io.generic.level = RAW_READ_LOCKREAD;
230 fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
232 printf("Failed to create %s - %s\n", fname, smbcli_errstr(cli->tree));
237 printf("Trying empty file read\n");
238 io.lockread.in.fnum = fnum;
239 io.lockread.in.count = 1;
240 io.lockread.in.offset = 1;
241 io.lockread.in.remaining = 0;
242 io.lockread.out.data = buf;
243 status = smb_raw_read(cli->tree, &io);
245 CHECK_STATUS(status, NT_STATUS_OK);
246 CHECK_VALUE(io.lockread.out.nread, 0);
248 status = smb_raw_read(cli->tree, &io);
249 CHECK_STATUS(status, NT_STATUS_LOCK_NOT_GRANTED);
251 status = smb_raw_read(cli->tree, &io);
252 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
254 printf("Trying zero file read\n");
255 io.lockread.in.count = 0;
256 status = smb_raw_read(cli->tree, &io);
257 CHECK_STATUS(status, NT_STATUS_OK);
259 smbcli_unlock(cli->tree, fnum, 1, 1);
261 printf("Trying bad fnum\n");
262 io.lockread.in.fnum = fnum+1;
263 status = smb_raw_read(cli->tree, &io);
264 CHECK_STATUS(status, NT_STATUS_INVALID_HANDLE);
265 io.lockread.in.fnum = fnum;
267 smbcli_write(cli->tree, fnum, 0, test_data, 0, strlen(test_data));
269 printf("Trying small read\n");
270 io.lockread.in.fnum = fnum;
271 io.lockread.in.offset = 0;
272 io.lockread.in.remaining = 0;
273 io.lockread.in.count = strlen(test_data);
274 status = smb_raw_read(cli->tree, &io);
275 CHECK_STATUS(status, NT_STATUS_LOCK_NOT_GRANTED);
277 smbcli_unlock(cli->tree, fnum, 1, 0);
279 status = smb_raw_read(cli->tree, &io);
280 CHECK_STATUS(status, NT_STATUS_OK);
281 CHECK_VALUE(io.lockread.out.nread, strlen(test_data));
282 if (memcmp(buf, test_data, strlen(test_data)) != 0) {
284 printf("incorrect data at %d!? (%s:%s)\n", __LINE__, test_data, buf);
288 printf("Trying short read\n");
289 io.lockread.in.offset = 1;
290 io.lockread.in.count = strlen(test_data);
291 status = smb_raw_read(cli->tree, &io);
292 CHECK_STATUS(status, NT_STATUS_LOCK_NOT_GRANTED);
293 smbcli_unlock(cli->tree, fnum, 0, strlen(test_data));
294 status = smb_raw_read(cli->tree, &io);
295 CHECK_STATUS(status, NT_STATUS_OK);
297 CHECK_VALUE(io.lockread.out.nread, strlen(test_data)-1);
298 if (memcmp(buf, test_data+1, strlen(test_data)-1) != 0) {
300 printf("incorrect data at %d!? (%s:%s)\n", __LINE__, test_data+1, buf);
304 printf("Trying max offset\n");
305 io.lockread.in.offset = ~0;
306 io.lockread.in.count = strlen(test_data);
307 status = smb_raw_read(cli->tree, &io);
308 CHECK_STATUS(status, NT_STATUS_OK);
309 CHECK_VALUE(io.lockread.out.nread, 0);
311 setup_buffer(buf, seed, maxsize);
312 smbcli_write(cli->tree, fnum, 0, buf, 0, maxsize);
313 memset(buf, 0, maxsize);
315 printf("Trying large read\n");
316 io.lockread.in.offset = 0;
317 io.lockread.in.count = ~0;
318 status = smb_raw_read(cli->tree, &io);
319 CHECK_STATUS(status, NT_STATUS_LOCK_NOT_GRANTED);
320 smbcli_unlock(cli->tree, fnum, 1, strlen(test_data));
321 status = smb_raw_read(cli->tree, &io);
322 CHECK_STATUS(status, NT_STATUS_OK);
323 CHECK_BUFFER(buf, seed, io.lockread.out.nread);
324 smbcli_unlock(cli->tree, fnum, 0, 0xFFFF);
327 printf("Trying locked region\n");
329 if (NT_STATUS_IS_ERR(smbcli_lock(cli->tree, fnum, 103, 1, 0, WRITE_LOCK))) {
330 printf("Failed to lock file at %d\n", __LINE__);
335 memset(buf, 0, maxsize);
336 io.lockread.in.offset = 0;
337 io.lockread.in.count = ~0;
338 status = smb_raw_read(cli->tree, &io);
339 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
343 smbcli_close(cli->tree, fnum);
344 smbcli_deltree(cli->tree, BASEDIR);
352 static BOOL test_readx(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
359 const int maxsize = 90000;
360 const char *fname = BASEDIR "\\test.txt";
361 const char *test_data = "TEST DATA";
362 uint_t seed = time(NULL);
364 buf = talloc_zero(mem_ctx, maxsize);
366 if (smbcli_deltree(cli->tree, BASEDIR) == -1 ||
367 NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, BASEDIR))) {
368 printf("Unable to setup %s - %s\n", BASEDIR, smbcli_errstr(cli->tree));
372 printf("Testing RAW_READ_READX\n");
374 fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
376 printf("Failed to create %s - %s\n", fname, smbcli_errstr(cli->tree));
381 printf("Trying empty file read\n");
382 io.generic.level = RAW_READ_READX;
383 io.readx.in.fnum = fnum;
384 io.readx.in.mincnt = 1;
385 io.readx.in.maxcnt = 1;
386 io.readx.in.offset = 0;
387 io.readx.in.remaining = 0;
388 io.readx.out.data = buf;
389 status = smb_raw_read(cli->tree, &io);
391 CHECK_STATUS(status, NT_STATUS_OK);
392 CHECK_VALUE(io.readx.out.nread, 0);
393 CHECK_VALUE(io.readx.out.remaining, 0xFFFF);
394 CHECK_VALUE(io.readx.out.compaction_mode, 0);
396 printf("Trying zero file read\n");
397 io.readx.in.mincnt = 0;
398 io.readx.in.maxcnt = 0;
399 status = smb_raw_read(cli->tree, &io);
400 CHECK_STATUS(status, NT_STATUS_OK);
401 CHECK_VALUE(io.readx.out.nread, 0);
402 CHECK_VALUE(io.readx.out.remaining, 0xFFFF);
403 CHECK_VALUE(io.readx.out.compaction_mode, 0);
405 printf("Trying bad fnum\n");
406 io.readx.in.fnum = fnum+1;
407 status = smb_raw_read(cli->tree, &io);
408 CHECK_STATUS(status, NT_STATUS_INVALID_HANDLE);
409 io.readx.in.fnum = fnum;
411 smbcli_write(cli->tree, fnum, 0, test_data, 0, strlen(test_data));
413 printf("Trying small read\n");
414 io.readx.in.fnum = fnum;
415 io.readx.in.offset = 0;
416 io.readx.in.remaining = 0;
417 io.readx.in.mincnt = strlen(test_data);
418 io.readx.in.maxcnt = strlen(test_data);
419 status = smb_raw_read(cli->tree, &io);
420 CHECK_STATUS(status, NT_STATUS_OK);
421 CHECK_VALUE(io.readx.out.nread, strlen(test_data));
422 CHECK_VALUE(io.readx.out.remaining, 0xFFFF);
423 CHECK_VALUE(io.readx.out.compaction_mode, 0);
424 if (memcmp(buf, test_data, strlen(test_data)) != 0) {
426 printf("incorrect data at %d!? (%s:%s)\n", __LINE__, test_data, buf);
430 printf("Trying short read\n");
431 io.readx.in.offset = 1;
432 io.readx.in.mincnt = strlen(test_data);
433 io.readx.in.maxcnt = strlen(test_data);
434 status = smb_raw_read(cli->tree, &io);
435 CHECK_STATUS(status, NT_STATUS_OK);
436 CHECK_VALUE(io.readx.out.nread, strlen(test_data)-1);
437 CHECK_VALUE(io.readx.out.remaining, 0xFFFF);
438 CHECK_VALUE(io.readx.out.compaction_mode, 0);
439 if (memcmp(buf, test_data+1, strlen(test_data)-1) != 0) {
441 printf("incorrect data at %d!? (%s:%s)\n", __LINE__, test_data+1, buf);
445 printf("Trying max offset\n");
446 io.readx.in.offset = 0xffffffff;
447 io.readx.in.mincnt = strlen(test_data);
448 io.readx.in.maxcnt = strlen(test_data);
449 status = smb_raw_read(cli->tree, &io);
450 CHECK_STATUS(status, NT_STATUS_OK);
451 CHECK_VALUE(io.readx.out.nread, 0);
452 CHECK_VALUE(io.readx.out.remaining, 0xFFFF);
453 CHECK_VALUE(io.readx.out.compaction_mode, 0);
455 setup_buffer(buf, seed, maxsize);
456 smbcli_write(cli->tree, fnum, 0, buf, 0, maxsize);
457 memset(buf, 0, maxsize);
459 printf("Trying large read\n");
460 io.readx.in.offset = 0;
461 io.readx.in.mincnt = 0xFFFF;
462 io.readx.in.maxcnt = 0xFFFF;
463 status = smb_raw_read(cli->tree, &io);
464 CHECK_STATUS(status, NT_STATUS_OK);
465 CHECK_VALUE(io.readx.out.remaining, 0xFFFF);
466 CHECK_VALUE(io.readx.out.compaction_mode, 0);
467 CHECK_VALUE(io.readx.out.nread, io.readx.in.maxcnt);
468 CHECK_BUFFER(buf, seed, io.readx.out.nread);
470 printf("Trying extra large read\n");
471 io.readx.in.offset = 0;
472 io.readx.in.mincnt = 100;
473 io.readx.in.maxcnt = 80000;
474 status = smb_raw_read(cli->tree, &io);
475 CHECK_STATUS(status, NT_STATUS_OK);
476 CHECK_VALUE(io.readx.out.remaining, 0xFFFF);
477 CHECK_VALUE(io.readx.out.compaction_mode, 0);
478 CHECK_VALUE(io.readx.out.nread, 0);
479 CHECK_BUFFER(buf, seed, io.readx.out.nread);
481 printf("Trying mincnt > maxcnt\n");
482 memset(buf, 0, maxsize);
483 io.readx.in.offset = 0;
484 io.readx.in.mincnt = 30000;
485 io.readx.in.maxcnt = 20000;
486 status = smb_raw_read(cli->tree, &io);
487 CHECK_STATUS(status, NT_STATUS_OK);
488 CHECK_VALUE(io.readx.out.remaining, 0xFFFF);
489 CHECK_VALUE(io.readx.out.compaction_mode, 0);
490 CHECK_VALUE(io.readx.out.nread, io.readx.in.maxcnt);
491 CHECK_BUFFER(buf, seed, io.readx.out.nread);
493 printf("Trying mincnt < maxcnt\n");
494 memset(buf, 0, maxsize);
495 io.readx.in.offset = 0;
496 io.readx.in.mincnt = 20000;
497 io.readx.in.maxcnt = 30000;
498 status = smb_raw_read(cli->tree, &io);
499 CHECK_STATUS(status, NT_STATUS_OK);
500 CHECK_VALUE(io.readx.out.remaining, 0xFFFF);
501 CHECK_VALUE(io.readx.out.compaction_mode, 0);
502 CHECK_VALUE(io.readx.out.nread, io.readx.in.maxcnt);
503 CHECK_BUFFER(buf, seed, io.readx.out.nread);
505 printf("Trying locked region\n");
507 if (NT_STATUS_IS_ERR(smbcli_lock(cli->tree, fnum, 103, 1, 0, WRITE_LOCK))) {
508 printf("Failed to lock file at %d\n", __LINE__);
513 memset(buf, 0, maxsize);
514 io.readx.in.offset = 0;
515 io.readx.in.mincnt = 100;
516 io.readx.in.maxcnt = 200;
517 status = smb_raw_read(cli->tree, &io);
518 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
520 printf("Trying large offset read\n");
521 io.readx.in.offset = ((uint64_t)0x2) << 32;
522 io.readx.in.mincnt = 10;
523 io.readx.in.maxcnt = 10;
524 status = smb_raw_read(cli->tree, &io);
525 CHECK_STATUS(status, NT_STATUS_OK);
526 CHECK_VALUE(io.readx.out.nread, 0);
528 if (NT_STATUS_IS_ERR(smbcli_lock64(cli->tree, fnum, io.readx.in.offset, 1, 0, WRITE_LOCK))) {
529 printf("Failed to lock file at %d\n", __LINE__);
534 status = smb_raw_read(cli->tree, &io);
535 CHECK_STATUS(status, NT_STATUS_OK);
536 CHECK_VALUE(io.readx.out.nread, 0);
539 smbcli_close(cli->tree, fnum);
540 smbcli_deltree(cli->tree, BASEDIR);
548 static BOOL test_readbraw(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
555 const int maxsize = 90000;
556 const char *fname = BASEDIR "\\test.txt";
557 const char *test_data = "TEST DATA";
558 uint_t seed = time(NULL);
560 buf = talloc_zero(mem_ctx, maxsize);
562 if (smbcli_deltree(cli->tree, BASEDIR) == -1 ||
563 NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, BASEDIR))) {
564 printf("Unable to setup %s - %s\n", BASEDIR, smbcli_errstr(cli->tree));
568 printf("Testing RAW_READ_READBRAW\n");
570 fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
572 printf("Failed to create %s - %s\n", fname, smbcli_errstr(cli->tree));
577 printf("Trying empty file read\n");
578 io.generic.level = RAW_READ_READBRAW;
579 io.readbraw.in.fnum = fnum;
580 io.readbraw.in.mincnt = 1;
581 io.readbraw.in.maxcnt = 1;
582 io.readbraw.in.offset = 0;
583 io.readbraw.in.timeout = 0;
584 io.readbraw.out.data = buf;
585 status = smb_raw_read(cli->tree, &io);
587 CHECK_STATUS(status, NT_STATUS_OK);
588 CHECK_VALUE(io.readbraw.out.nread, 0);
590 printf("Trying zero file read\n");
591 io.readbraw.in.mincnt = 0;
592 io.readbraw.in.maxcnt = 0;
593 status = smb_raw_read(cli->tree, &io);
594 CHECK_STATUS(status, NT_STATUS_OK);
595 CHECK_VALUE(io.readbraw.out.nread, 0);
597 printf("Trying bad fnum\n");
598 io.readbraw.in.fnum = fnum+1;
599 status = smb_raw_read(cli->tree, &io);
600 CHECK_STATUS(status, NT_STATUS_OK);
601 CHECK_VALUE(io.readbraw.out.nread, 0);
602 io.readbraw.in.fnum = fnum;
604 smbcli_write(cli->tree, fnum, 0, test_data, 0, strlen(test_data));
606 printf("Trying small read\n");
607 io.readbraw.in.fnum = fnum;
608 io.readbraw.in.offset = 0;
609 io.readbraw.in.mincnt = strlen(test_data);
610 io.readbraw.in.maxcnt = strlen(test_data);
611 status = smb_raw_read(cli->tree, &io);
612 CHECK_STATUS(status, NT_STATUS_OK);
613 CHECK_VALUE(io.readbraw.out.nread, strlen(test_data));
614 if (memcmp(buf, test_data, strlen(test_data)) != 0) {
616 printf("incorrect data at %d!? (%s:%s)\n", __LINE__, test_data, buf);
620 printf("Trying short read\n");
621 io.readbraw.in.offset = 1;
622 io.readbraw.in.mincnt = strlen(test_data);
623 io.readbraw.in.maxcnt = strlen(test_data);
624 status = smb_raw_read(cli->tree, &io);
625 CHECK_STATUS(status, NT_STATUS_OK);
626 CHECK_VALUE(io.readbraw.out.nread, strlen(test_data)-1);
627 if (memcmp(buf, test_data+1, strlen(test_data)-1) != 0) {
629 printf("incorrect data at %d!? (%s:%s)\n", __LINE__, test_data+1, buf);
633 printf("Trying max offset\n");
634 io.readbraw.in.offset = ~0;
635 io.readbraw.in.mincnt = strlen(test_data);
636 io.readbraw.in.maxcnt = strlen(test_data);
637 status = smb_raw_read(cli->tree, &io);
638 CHECK_STATUS(status, NT_STATUS_OK);
639 CHECK_VALUE(io.readbraw.out.nread, 0);
641 setup_buffer(buf, seed, maxsize);
642 smbcli_write(cli->tree, fnum, 0, buf, 0, maxsize);
643 memset(buf, 0, maxsize);
645 printf("Trying large read\n");
646 io.readbraw.in.offset = 0;
647 io.readbraw.in.mincnt = ~0;
648 io.readbraw.in.maxcnt = ~0;
649 status = smb_raw_read(cli->tree, &io);
650 CHECK_STATUS(status, NT_STATUS_OK);
651 CHECK_VALUE(io.readbraw.out.nread, 0xFFFF);
652 CHECK_BUFFER(buf, seed, io.readbraw.out.nread);
654 printf("Trying mincnt > maxcnt\n");
655 memset(buf, 0, maxsize);
656 io.readbraw.in.offset = 0;
657 io.readbraw.in.mincnt = 30000;
658 io.readbraw.in.maxcnt = 20000;
659 status = smb_raw_read(cli->tree, &io);
660 CHECK_STATUS(status, NT_STATUS_OK);
661 CHECK_VALUE(io.readbraw.out.nread, io.readbraw.in.maxcnt);
662 CHECK_BUFFER(buf, seed, io.readbraw.out.nread);
664 printf("Trying mincnt < maxcnt\n");
665 memset(buf, 0, maxsize);
666 io.readbraw.in.offset = 0;
667 io.readbraw.in.mincnt = 20000;
668 io.readbraw.in.maxcnt = 30000;
669 status = smb_raw_read(cli->tree, &io);
670 CHECK_STATUS(status, NT_STATUS_OK);
671 CHECK_VALUE(io.readbraw.out.nread, io.readbraw.in.maxcnt);
672 CHECK_BUFFER(buf, seed, io.readbraw.out.nread);
674 printf("Trying locked region\n");
676 if (NT_STATUS_IS_ERR(smbcli_lock(cli->tree, fnum, 103, 1, 0, WRITE_LOCK))) {
677 printf("Failed to lock file at %d\n", __LINE__);
682 memset(buf, 0, maxsize);
683 io.readbraw.in.offset = 0;
684 io.readbraw.in.mincnt = 100;
685 io.readbraw.in.maxcnt = 200;
686 status = smb_raw_read(cli->tree, &io);
687 CHECK_STATUS(status, NT_STATUS_OK);
688 CHECK_VALUE(io.readbraw.out.nread, 0);
690 printf("Trying locked region with timeout\n");
691 memset(buf, 0, maxsize);
692 io.readbraw.in.offset = 0;
693 io.readbraw.in.mincnt = 100;
694 io.readbraw.in.maxcnt = 200;
695 io.readbraw.in.timeout = 10000;
696 status = smb_raw_read(cli->tree, &io);
697 CHECK_STATUS(status, NT_STATUS_OK);
698 CHECK_VALUE(io.readbraw.out.nread, 0);
700 printf("Trying large offset read\n");
701 io.readbraw.in.offset = ((uint64_t)0x2) << 32;
702 io.readbraw.in.mincnt = 10;
703 io.readbraw.in.maxcnt = 10;
704 io.readbraw.in.timeout = 0;
705 status = smb_raw_read(cli->tree, &io);
706 CHECK_STATUS(status, NT_STATUS_OK);
707 CHECK_VALUE(io.readbraw.out.nread, 0);
710 smbcli_close(cli->tree, fnum);
711 smbcli_deltree(cli->tree, BASEDIR);
717 basic testing of read calls
719 BOOL torture_raw_read(void)
721 struct smbcli_state *cli;
725 if (!torture_open_connection(&cli)) {
729 mem_ctx = talloc_init("torture_raw_read");
731 if (!test_read(cli, mem_ctx)) {
735 if (!test_readx(cli, mem_ctx)) {
739 if (!test_lockread(cli, mem_ctx)) {
743 if (!test_readbraw(cli, mem_ctx)) {
747 torture_close_connection(cli);
748 talloc_destroy(mem_ctx);