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"
24 #define CHECK_STATUS(status, correct) do { \
25 if (!NT_STATUS_EQUAL(status, correct)) { \
26 printf("(%s) Incorrect status %s - should be %s\n", \
27 __location__, nt_errstr(status), nt_errstr(correct)); \
32 #define CHECK_VALUE(v, correct) do { \
33 if ((v) != (correct)) { \
34 printf("(%s) Incorrect value %s=%d - should be %d\n", \
35 __location__, #v, v, correct); \
40 #define CHECK_BUFFER(buf, seed, len) do { \
41 if (!check_buffer(buf, seed, len, __LINE__)) { \
46 #define BASEDIR "\\testread"
50 setup a random buffer based on a seed
52 static void setup_buffer(char *buf, uint_t seed, int len)
56 for (i=0;i<len;i++) buf[i] = random();
60 check a random buffer based on a seed
62 static BOOL check_buffer(char *buf, uint_t seed, int len, int line)
69 printf("Buffer incorrect at line %d! ofs=%d v1=0x%x v2=0x%x\n",
80 static BOOL test_read(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
87 const int maxsize = 90000;
88 const char *fname = BASEDIR "\\test.txt";
89 const char *test_data = "TEST DATA";
90 uint_t seed = time(NULL);
92 buf = talloc_zero(mem_ctx, maxsize);
94 if (smbcli_deltree(cli->tree, BASEDIR) == -1 ||
95 NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, BASEDIR))) {
96 printf("Unable to setup %s - %s\n", BASEDIR, smbcli_errstr(cli->tree));
100 printf("Testing RAW_READ_READ\n");
101 io.generic.level = RAW_READ_READ;
103 fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
105 printf("Failed to create %s - %s\n", fname, smbcli_errstr(cli->tree));
110 printf("Trying empty file read\n");
111 io.read.in.fnum = fnum;
112 io.read.in.count = 1;
113 io.read.in.offset = 0;
114 io.read.in.remaining = 0;
115 io.read.out.data = buf;
116 status = smb_raw_read(cli->tree, &io);
118 CHECK_STATUS(status, NT_STATUS_OK);
119 CHECK_VALUE(io.read.out.nread, 0);
121 printf("Trying zero file read\n");
122 io.read.in.count = 0;
123 status = smb_raw_read(cli->tree, &io);
124 CHECK_STATUS(status, NT_STATUS_OK);
125 CHECK_VALUE(io.read.out.nread, 0);
127 printf("Trying bad fnum\n");
128 io.read.in.fnum = fnum+1;
129 status = smb_raw_read(cli->tree, &io);
130 CHECK_STATUS(status, NT_STATUS_INVALID_HANDLE);
131 io.read.in.fnum = fnum;
133 smbcli_write(cli->tree, fnum, 0, test_data, 0, strlen(test_data));
135 printf("Trying small read\n");
136 io.read.in.fnum = fnum;
137 io.read.in.offset = 0;
138 io.read.in.remaining = 0;
139 io.read.in.count = strlen(test_data);
140 status = smb_raw_read(cli->tree, &io);
141 CHECK_STATUS(status, NT_STATUS_OK);
142 CHECK_VALUE(io.read.out.nread, strlen(test_data));
143 if (memcmp(buf, test_data, strlen(test_data)) != 0) {
145 printf("incorrect data at %d!? (%s:%s)\n", __LINE__, test_data, buf);
149 printf("Trying short read\n");
150 io.read.in.offset = 1;
151 io.read.in.count = strlen(test_data);
152 status = smb_raw_read(cli->tree, &io);
153 CHECK_STATUS(status, NT_STATUS_OK);
154 CHECK_VALUE(io.read.out.nread, strlen(test_data)-1);
155 if (memcmp(buf, test_data+1, strlen(test_data)-1) != 0) {
157 printf("incorrect data at %d!? (%s:%s)\n", __LINE__, test_data+1, buf);
161 printf("Trying max offset\n");
162 io.read.in.offset = ~0;
163 io.read.in.count = strlen(test_data);
164 status = smb_raw_read(cli->tree, &io);
165 CHECK_STATUS(status, NT_STATUS_OK);
166 CHECK_VALUE(io.read.out.nread, 0);
168 setup_buffer(buf, seed, maxsize);
169 smbcli_write(cli->tree, fnum, 0, buf, 0, maxsize);
170 memset(buf, 0, maxsize);
172 printf("Trying large read\n");
173 io.read.in.offset = 0;
174 io.read.in.count = ~0;
175 status = smb_raw_read(cli->tree, &io);
176 CHECK_STATUS(status, NT_STATUS_OK);
177 CHECK_BUFFER(buf, seed, io.read.out.nread);
180 printf("Trying locked region\n");
182 if (NT_STATUS_IS_ERR(smbcli_lock(cli->tree, fnum, 103, 1, 0, WRITE_LOCK))) {
183 printf("Failed to lock file at %d\n", __LINE__);
188 memset(buf, 0, maxsize);
189 io.read.in.offset = 0;
190 io.read.in.count = ~0;
191 status = smb_raw_read(cli->tree, &io);
192 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
196 smbcli_close(cli->tree, fnum);
197 smb_raw_exit(cli->session);
198 smbcli_deltree(cli->tree, BASEDIR);
206 static BOOL test_lockread(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
213 const int maxsize = 90000;
214 const char *fname = BASEDIR "\\test.txt";
215 const char *test_data = "TEST DATA";
216 uint_t seed = time(NULL);
218 buf = talloc_zero(mem_ctx, maxsize);
220 if (smbcli_deltree(cli->tree, BASEDIR) == -1 ||
221 NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, BASEDIR))) {
222 printf("Unable to setup %s - %s\n", BASEDIR, smbcli_errstr(cli->tree));
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.in.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.in.fnum = fnum+1;
262 status = smb_raw_read(cli->tree, &io);
263 CHECK_STATUS(status, NT_STATUS_INVALID_HANDLE);
264 io.lockread.in.fnum = fnum;
266 smbcli_write(cli->tree, fnum, 0, test_data, 0, strlen(test_data));
268 printf("Trying small read\n");
269 io.lockread.in.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(mem_ctx, maxsize);
365 if (smbcli_deltree(cli->tree, BASEDIR) == -1 ||
366 NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, BASEDIR))) {
367 printf("Unable to setup %s - %s\n", BASEDIR, smbcli_errstr(cli->tree));
371 printf("Testing RAW_READ_READX\n");
373 fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
375 printf("Failed to create %s - %s\n", fname, smbcli_errstr(cli->tree));
380 printf("Trying empty file read\n");
381 io.generic.level = RAW_READ_READX;
382 io.readx.in.fnum = fnum;
383 io.readx.in.mincnt = 1;
384 io.readx.in.maxcnt = 1;
385 io.readx.in.offset = 0;
386 io.readx.in.remaining = 0;
387 io.readx.out.data = buf;
388 status = smb_raw_read(cli->tree, &io);
390 CHECK_STATUS(status, NT_STATUS_OK);
391 CHECK_VALUE(io.readx.out.nread, 0);
392 CHECK_VALUE(io.readx.out.remaining, 0xFFFF);
393 CHECK_VALUE(io.readx.out.compaction_mode, 0);
395 printf("Trying zero file read\n");
396 io.readx.in.mincnt = 0;
397 io.readx.in.maxcnt = 0;
398 status = smb_raw_read(cli->tree, &io);
399 CHECK_STATUS(status, NT_STATUS_OK);
400 CHECK_VALUE(io.readx.out.nread, 0);
401 CHECK_VALUE(io.readx.out.remaining, 0xFFFF);
402 CHECK_VALUE(io.readx.out.compaction_mode, 0);
404 printf("Trying bad fnum\n");
405 io.readx.in.fnum = fnum+1;
406 status = smb_raw_read(cli->tree, &io);
407 CHECK_STATUS(status, NT_STATUS_INVALID_HANDLE);
408 io.readx.in.fnum = fnum;
410 smbcli_write(cli->tree, fnum, 0, test_data, 0, strlen(test_data));
412 printf("Trying small read\n");
413 io.readx.in.fnum = fnum;
414 io.readx.in.offset = 0;
415 io.readx.in.remaining = 0;
416 io.readx.in.mincnt = strlen(test_data);
417 io.readx.in.maxcnt = strlen(test_data);
418 status = smb_raw_read(cli->tree, &io);
419 CHECK_STATUS(status, NT_STATUS_OK);
420 CHECK_VALUE(io.readx.out.nread, strlen(test_data));
421 CHECK_VALUE(io.readx.out.remaining, 0xFFFF);
422 CHECK_VALUE(io.readx.out.compaction_mode, 0);
423 if (memcmp(buf, test_data, strlen(test_data)) != 0) {
425 printf("incorrect data at %d!? (%s:%s)\n", __LINE__, test_data, buf);
429 printf("Trying short read\n");
430 io.readx.in.offset = 1;
431 io.readx.in.mincnt = strlen(test_data);
432 io.readx.in.maxcnt = strlen(test_data);
433 status = smb_raw_read(cli->tree, &io);
434 CHECK_STATUS(status, NT_STATUS_OK);
435 CHECK_VALUE(io.readx.out.nread, strlen(test_data)-1);
436 CHECK_VALUE(io.readx.out.remaining, 0xFFFF);
437 CHECK_VALUE(io.readx.out.compaction_mode, 0);
438 if (memcmp(buf, test_data+1, strlen(test_data)-1) != 0) {
440 printf("incorrect data at %d!? (%s:%s)\n", __LINE__, test_data+1, buf);
444 printf("Trying max offset\n");
445 io.readx.in.offset = 0xffffffff;
446 io.readx.in.mincnt = strlen(test_data);
447 io.readx.in.maxcnt = strlen(test_data);
448 status = smb_raw_read(cli->tree, &io);
449 CHECK_STATUS(status, NT_STATUS_OK);
450 CHECK_VALUE(io.readx.out.nread, 0);
451 CHECK_VALUE(io.readx.out.remaining, 0xFFFF);
452 CHECK_VALUE(io.readx.out.compaction_mode, 0);
454 setup_buffer(buf, seed, maxsize);
455 smbcli_write(cli->tree, fnum, 0, buf, 0, maxsize);
456 memset(buf, 0, maxsize);
458 printf("Trying large read\n");
459 io.readx.in.offset = 0;
460 io.readx.in.mincnt = 0xFFFF;
461 io.readx.in.maxcnt = 0xFFFF;
462 status = smb_raw_read(cli->tree, &io);
463 CHECK_STATUS(status, NT_STATUS_OK);
464 CHECK_VALUE(io.readx.out.remaining, 0xFFFF);
465 CHECK_VALUE(io.readx.out.compaction_mode, 0);
466 CHECK_VALUE(io.readx.out.nread, io.readx.in.maxcnt);
467 CHECK_BUFFER(buf, seed, io.readx.out.nread);
469 printf("Trying extra large read\n");
470 io.readx.in.offset = 0;
471 io.readx.in.mincnt = 100;
472 io.readx.in.maxcnt = 80000;
473 status = smb_raw_read(cli->tree, &io);
474 CHECK_STATUS(status, NT_STATUS_OK);
475 CHECK_VALUE(io.readx.out.remaining, 0xFFFF);
476 CHECK_VALUE(io.readx.out.compaction_mode, 0);
477 CHECK_VALUE(io.readx.out.nread, 0);
478 CHECK_BUFFER(buf, seed, io.readx.out.nread);
480 printf("Trying mincnt > maxcnt\n");
481 memset(buf, 0, maxsize);
482 io.readx.in.offset = 0;
483 io.readx.in.mincnt = 30000;
484 io.readx.in.maxcnt = 20000;
485 status = smb_raw_read(cli->tree, &io);
486 CHECK_STATUS(status, NT_STATUS_OK);
487 CHECK_VALUE(io.readx.out.remaining, 0xFFFF);
488 CHECK_VALUE(io.readx.out.compaction_mode, 0);
489 CHECK_VALUE(io.readx.out.nread, io.readx.in.maxcnt);
490 CHECK_BUFFER(buf, seed, io.readx.out.nread);
492 printf("Trying mincnt < maxcnt\n");
493 memset(buf, 0, maxsize);
494 io.readx.in.offset = 0;
495 io.readx.in.mincnt = 20000;
496 io.readx.in.maxcnt = 30000;
497 status = smb_raw_read(cli->tree, &io);
498 CHECK_STATUS(status, NT_STATUS_OK);
499 CHECK_VALUE(io.readx.out.remaining, 0xFFFF);
500 CHECK_VALUE(io.readx.out.compaction_mode, 0);
501 CHECK_VALUE(io.readx.out.nread, io.readx.in.maxcnt);
502 CHECK_BUFFER(buf, seed, io.readx.out.nread);
504 printf("Trying locked region\n");
506 if (NT_STATUS_IS_ERR(smbcli_lock(cli->tree, fnum, 103, 1, 0, WRITE_LOCK))) {
507 printf("Failed to lock file at %d\n", __LINE__);
512 memset(buf, 0, maxsize);
513 io.readx.in.offset = 0;
514 io.readx.in.mincnt = 100;
515 io.readx.in.maxcnt = 200;
516 status = smb_raw_read(cli->tree, &io);
517 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
519 printf("Trying large offset read\n");
520 io.readx.in.offset = ((uint64_t)0x2) << 32;
521 io.readx.in.mincnt = 10;
522 io.readx.in.maxcnt = 10;
523 status = smb_raw_read(cli->tree, &io);
524 CHECK_STATUS(status, NT_STATUS_OK);
525 CHECK_VALUE(io.readx.out.nread, 0);
527 if (NT_STATUS_IS_ERR(smbcli_lock64(cli->tree, fnum, io.readx.in.offset, 1, 0, WRITE_LOCK))) {
528 printf("Failed to lock file at %d\n", __LINE__);
533 status = smb_raw_read(cli->tree, &io);
534 CHECK_STATUS(status, NT_STATUS_OK);
535 CHECK_VALUE(io.readx.out.nread, 0);
538 smbcli_close(cli->tree, fnum);
539 smbcli_deltree(cli->tree, BASEDIR);
547 static BOOL test_readbraw(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
554 const int maxsize = 90000;
555 const char *fname = BASEDIR "\\test.txt";
556 const char *test_data = "TEST DATA";
557 uint_t seed = time(NULL);
559 buf = talloc_zero(mem_ctx, maxsize);
561 if (smbcli_deltree(cli->tree, BASEDIR) == -1 ||
562 NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, BASEDIR))) {
563 printf("Unable to setup %s - %s\n", BASEDIR, smbcli_errstr(cli->tree));
567 printf("Testing RAW_READ_READBRAW\n");
569 fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
571 printf("Failed to create %s - %s\n", fname, smbcli_errstr(cli->tree));
576 printf("Trying empty file read\n");
577 io.generic.level = RAW_READ_READBRAW;
578 io.readbraw.in.fnum = fnum;
579 io.readbraw.in.mincnt = 1;
580 io.readbraw.in.maxcnt = 1;
581 io.readbraw.in.offset = 0;
582 io.readbraw.in.timeout = 0;
583 io.readbraw.out.data = buf;
584 status = smb_raw_read(cli->tree, &io);
586 CHECK_STATUS(status, NT_STATUS_OK);
587 CHECK_VALUE(io.readbraw.out.nread, 0);
589 printf("Trying zero file read\n");
590 io.readbraw.in.mincnt = 0;
591 io.readbraw.in.maxcnt = 0;
592 status = smb_raw_read(cli->tree, &io);
593 CHECK_STATUS(status, NT_STATUS_OK);
594 CHECK_VALUE(io.readbraw.out.nread, 0);
596 printf("Trying bad fnum\n");
597 io.readbraw.in.fnum = fnum+1;
598 status = smb_raw_read(cli->tree, &io);
599 CHECK_STATUS(status, NT_STATUS_OK);
600 CHECK_VALUE(io.readbraw.out.nread, 0);
601 io.readbraw.in.fnum = fnum;
603 smbcli_write(cli->tree, fnum, 0, test_data, 0, strlen(test_data));
605 printf("Trying small read\n");
606 io.readbraw.in.fnum = fnum;
607 io.readbraw.in.offset = 0;
608 io.readbraw.in.mincnt = strlen(test_data);
609 io.readbraw.in.maxcnt = strlen(test_data);
610 status = smb_raw_read(cli->tree, &io);
611 CHECK_STATUS(status, NT_STATUS_OK);
612 CHECK_VALUE(io.readbraw.out.nread, strlen(test_data));
613 if (memcmp(buf, test_data, strlen(test_data)) != 0) {
615 printf("incorrect data at %d!? (%s:%s)\n", __LINE__, test_data, buf);
619 printf("Trying short read\n");
620 io.readbraw.in.offset = 1;
621 io.readbraw.in.mincnt = strlen(test_data);
622 io.readbraw.in.maxcnt = strlen(test_data);
623 status = smb_raw_read(cli->tree, &io);
624 CHECK_STATUS(status, NT_STATUS_OK);
625 CHECK_VALUE(io.readbraw.out.nread, strlen(test_data)-1);
626 if (memcmp(buf, test_data+1, strlen(test_data)-1) != 0) {
628 printf("incorrect data at %d!? (%s:%s)\n", __LINE__, test_data+1, buf);
632 printf("Trying max offset\n");
633 io.readbraw.in.offset = ~0;
634 io.readbraw.in.mincnt = strlen(test_data);
635 io.readbraw.in.maxcnt = strlen(test_data);
636 status = smb_raw_read(cli->tree, &io);
637 CHECK_STATUS(status, NT_STATUS_OK);
638 CHECK_VALUE(io.readbraw.out.nread, 0);
640 setup_buffer(buf, seed, maxsize);
641 smbcli_write(cli->tree, fnum, 0, buf, 0, maxsize);
642 memset(buf, 0, maxsize);
644 printf("Trying large read\n");
645 io.readbraw.in.offset = 0;
646 io.readbraw.in.mincnt = ~0;
647 io.readbraw.in.maxcnt = ~0;
648 status = smb_raw_read(cli->tree, &io);
649 CHECK_STATUS(status, NT_STATUS_OK);
650 CHECK_VALUE(io.readbraw.out.nread, 0xFFFF);
651 CHECK_BUFFER(buf, seed, io.readbraw.out.nread);
653 printf("Trying mincnt > maxcnt\n");
654 memset(buf, 0, maxsize);
655 io.readbraw.in.offset = 0;
656 io.readbraw.in.mincnt = 30000;
657 io.readbraw.in.maxcnt = 20000;
658 status = smb_raw_read(cli->tree, &io);
659 CHECK_STATUS(status, NT_STATUS_OK);
660 CHECK_VALUE(io.readbraw.out.nread, io.readbraw.in.maxcnt);
661 CHECK_BUFFER(buf, seed, io.readbraw.out.nread);
663 printf("Trying mincnt < maxcnt\n");
664 memset(buf, 0, maxsize);
665 io.readbraw.in.offset = 0;
666 io.readbraw.in.mincnt = 20000;
667 io.readbraw.in.maxcnt = 30000;
668 status = smb_raw_read(cli->tree, &io);
669 CHECK_STATUS(status, NT_STATUS_OK);
670 CHECK_VALUE(io.readbraw.out.nread, io.readbraw.in.maxcnt);
671 CHECK_BUFFER(buf, seed, io.readbraw.out.nread);
673 printf("Trying locked region\n");
675 if (NT_STATUS_IS_ERR(smbcli_lock(cli->tree, fnum, 103, 1, 0, WRITE_LOCK))) {
676 printf("Failed to lock file at %d\n", __LINE__);
681 memset(buf, 0, maxsize);
682 io.readbraw.in.offset = 0;
683 io.readbraw.in.mincnt = 100;
684 io.readbraw.in.maxcnt = 200;
685 status = smb_raw_read(cli->tree, &io);
686 CHECK_STATUS(status, NT_STATUS_OK);
687 CHECK_VALUE(io.readbraw.out.nread, 0);
689 printf("Trying locked region with timeout\n");
690 memset(buf, 0, maxsize);
691 io.readbraw.in.offset = 0;
692 io.readbraw.in.mincnt = 100;
693 io.readbraw.in.maxcnt = 200;
694 io.readbraw.in.timeout = 10000;
695 status = smb_raw_read(cli->tree, &io);
696 CHECK_STATUS(status, NT_STATUS_OK);
697 CHECK_VALUE(io.readbraw.out.nread, 0);
699 printf("Trying large offset read\n");
700 io.readbraw.in.offset = ((uint64_t)0x2) << 32;
701 io.readbraw.in.mincnt = 10;
702 io.readbraw.in.maxcnt = 10;
703 io.readbraw.in.timeout = 0;
704 status = smb_raw_read(cli->tree, &io);
705 CHECK_STATUS(status, NT_STATUS_OK);
706 CHECK_VALUE(io.readbraw.out.nread, 0);
709 smbcli_close(cli->tree, fnum);
710 smbcli_deltree(cli->tree, BASEDIR);
716 basic testing of read calls
718 BOOL torture_raw_read(void)
720 struct smbcli_state *cli;
724 if (!torture_open_connection(&cli)) {
728 mem_ctx = talloc_init("torture_raw_read");
730 if (!test_read(cli, mem_ctx)) {
734 if (!test_readx(cli, mem_ctx)) {
738 if (!test_lockread(cli, mem_ctx)) {
742 if (!test_readbraw(cli, mem_ctx)) {
746 torture_close_connection(cli);
747 talloc_destroy(mem_ctx);