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.
23 #define CHECK_STATUS(status, correct) do { \
24 if (!NT_STATUS_EQUAL(status, correct)) { \
25 printf("(%d) Incorrect status %s - should be %s\n", \
26 __LINE__, nt_errstr(status), nt_errstr(correct)); \
31 #define CHECK_VALUE(v, correct) do { \
32 if ((v) != (correct)) { \
33 printf("(%d) Incorrect value %s=%d - should be %d\n", \
34 __LINE__, #v, v, correct); \
39 #define CHECK_BUFFER(buf, seed, len) do { \
40 if (!check_buffer(buf, seed, len, __LINE__)) { \
45 #define BASEDIR "\\testread"
49 setup a random buffer based on a seed
51 static void setup_buffer(char *buf, uint_t seed, int len)
55 for (i=0;i<len;i++) buf[i] = random();
59 check a random buffer based on a seed
61 static BOOL check_buffer(char *buf, uint_t seed, int len, int line)
68 printf("Buffer incorrect at line %d! ofs=%d v1=0x%x v2=0x%x\n",
79 static BOOL test_read(struct cli_state *cli, TALLOC_CTX *mem_ctx)
86 const int maxsize = 90000;
87 const char *fname = BASEDIR "\\test.txt";
88 const char *test_data = "TEST DATA";
89 uint_t seed = time(NULL);
91 buf = talloc_zero(mem_ctx, maxsize);
93 if (cli_deltree(cli->tree, BASEDIR) == -1 ||
94 NT_STATUS_IS_ERR(cli_mkdir(cli->tree, BASEDIR))) {
95 printf("Unable to setup %s - %s\n", BASEDIR, cli_errstr(cli->tree));
99 printf("Testing RAW_READ_READ\n");
100 io.generic.level = RAW_READ_READ;
102 fnum = cli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
104 printf("Failed to create %s - %s\n", fname, cli_errstr(cli->tree));
109 printf("Trying empty file read\n");
110 io.read.in.fnum = fnum;
111 io.read.in.count = 1;
112 io.read.in.offset = 0;
113 io.read.in.remaining = 0;
114 io.read.out.data = buf;
115 status = smb_raw_read(cli->tree, &io);
117 CHECK_STATUS(status, NT_STATUS_OK);
118 CHECK_VALUE(io.read.out.nread, 0);
120 printf("Trying zero file read\n");
121 io.read.in.count = 0;
122 status = smb_raw_read(cli->tree, &io);
123 CHECK_STATUS(status, NT_STATUS_OK);
124 CHECK_VALUE(io.read.out.nread, 0);
126 printf("Trying bad fnum\n");
127 io.read.in.fnum = fnum+1;
128 status = smb_raw_read(cli->tree, &io);
129 CHECK_STATUS(status, NT_STATUS_INVALID_HANDLE);
130 io.read.in.fnum = fnum;
132 cli_write(cli->tree, fnum, 0, test_data, 0, strlen(test_data));
134 printf("Trying small read\n");
135 io.read.in.fnum = fnum;
136 io.read.in.offset = 0;
137 io.read.in.remaining = 0;
138 io.read.in.count = strlen(test_data);
139 status = smb_raw_read(cli->tree, &io);
140 CHECK_STATUS(status, NT_STATUS_OK);
141 CHECK_VALUE(io.read.out.nread, strlen(test_data));
142 if (memcmp(buf, test_data, strlen(test_data)) != 0) {
144 printf("incorrect data at %d!? (%s:%s)\n", __LINE__, test_data, buf);
148 printf("Trying short read\n");
149 io.read.in.offset = 1;
150 io.read.in.count = strlen(test_data);
151 status = smb_raw_read(cli->tree, &io);
152 CHECK_STATUS(status, NT_STATUS_OK);
153 CHECK_VALUE(io.read.out.nread, strlen(test_data)-1);
154 if (memcmp(buf, test_data+1, strlen(test_data)-1) != 0) {
156 printf("incorrect data at %d!? (%s:%s)\n", __LINE__, test_data+1, buf);
160 printf("Trying max offset\n");
161 io.read.in.offset = ~0;
162 io.read.in.count = strlen(test_data);
163 status = smb_raw_read(cli->tree, &io);
164 CHECK_STATUS(status, NT_STATUS_OK);
165 CHECK_VALUE(io.read.out.nread, 0);
167 setup_buffer(buf, seed, maxsize);
168 cli_write(cli->tree, fnum, 0, buf, 0, maxsize);
169 memset(buf, 0, maxsize);
171 printf("Trying large read\n");
172 io.read.in.offset = 0;
173 io.read.in.count = ~0;
174 status = smb_raw_read(cli->tree, &io);
175 CHECK_STATUS(status, NT_STATUS_OK);
176 CHECK_BUFFER(buf, seed, io.read.out.nread);
179 printf("Trying locked region\n");
181 if (NT_STATUS_IS_ERR(cli_lock(cli->tree, fnum, 103, 1, 0, WRITE_LOCK))) {
182 printf("Failed to lock file at %d\n", __LINE__);
187 memset(buf, 0, maxsize);
188 io.read.in.offset = 0;
189 io.read.in.count = ~0;
190 status = smb_raw_read(cli->tree, &io);
191 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
195 cli_close(cli->tree, fnum);
196 smb_raw_exit(cli->session);
197 cli_deltree(cli->tree, BASEDIR);
205 static BOOL test_lockread(struct cli_state *cli, TALLOC_CTX *mem_ctx)
212 const int maxsize = 90000;
213 const char *fname = BASEDIR "\\test.txt";
214 const char *test_data = "TEST DATA";
215 uint_t seed = time(NULL);
217 buf = talloc_zero(mem_ctx, maxsize);
219 if (cli_deltree(cli->tree, BASEDIR) == -1 ||
220 NT_STATUS_IS_ERR(cli_mkdir(cli->tree, BASEDIR))) {
221 printf("Unable to setup %s - %s\n", BASEDIR, cli_errstr(cli->tree));
225 printf("Testing RAW_READ_LOCKREAD\n");
226 io.generic.level = RAW_READ_LOCKREAD;
228 fnum = cli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
230 printf("Failed to create %s - %s\n", fname, cli_errstr(cli->tree));
235 printf("Trying empty file read\n");
236 io.lockread.in.fnum = fnum;
237 io.lockread.in.count = 1;
238 io.lockread.in.offset = 0;
239 io.lockread.in.remaining = 0;
240 io.lockread.out.data = buf;
241 status = smb_raw_read(cli->tree, &io);
243 CHECK_STATUS(status, NT_STATUS_OK);
244 CHECK_VALUE(io.lockread.out.nread, 0);
246 status = smb_raw_read(cli->tree, &io);
247 CHECK_STATUS(status, NT_STATUS_LOCK_NOT_GRANTED);
249 status = smb_raw_read(cli->tree, &io);
250 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
252 printf("Trying zero file read\n");
253 io.lockread.in.count = 0;
254 status = smb_raw_read(cli->tree, &io);
255 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
257 printf("Trying bad fnum\n");
258 io.lockread.in.fnum = fnum+1;
259 status = smb_raw_read(cli->tree, &io);
260 CHECK_STATUS(status, NT_STATUS_INVALID_HANDLE);
261 io.lockread.in.fnum = fnum;
263 cli_write(cli->tree, fnum, 0, test_data, 0, strlen(test_data));
265 printf("Trying small read\n");
266 io.lockread.in.fnum = fnum;
267 io.lockread.in.offset = 0;
268 io.lockread.in.remaining = 0;
269 io.lockread.in.count = strlen(test_data);
270 status = smb_raw_read(cli->tree, &io);
271 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
273 cli_unlock(cli->tree, fnum, 0, 1);
275 status = smb_raw_read(cli->tree, &io);
276 CHECK_STATUS(status, NT_STATUS_OK);
277 CHECK_VALUE(io.lockread.out.nread, strlen(test_data));
278 if (memcmp(buf, test_data, strlen(test_data)) != 0) {
280 printf("incorrect data at %d!? (%s:%s)\n", __LINE__, test_data, buf);
284 printf("Trying short read\n");
285 io.lockread.in.offset = 1;
286 io.lockread.in.count = strlen(test_data);
287 status = smb_raw_read(cli->tree, &io);
288 CHECK_STATUS(status, NT_STATUS_LOCK_NOT_GRANTED);
289 cli_unlock(cli->tree, fnum, 0, strlen(test_data));
290 status = smb_raw_read(cli->tree, &io);
291 CHECK_STATUS(status, NT_STATUS_OK);
293 CHECK_VALUE(io.lockread.out.nread, strlen(test_data)-1);
294 if (memcmp(buf, test_data+1, strlen(test_data)-1) != 0) {
296 printf("incorrect data at %d!? (%s:%s)\n", __LINE__, test_data+1, buf);
300 printf("Trying max offset\n");
301 io.lockread.in.offset = ~0;
302 io.lockread.in.count = strlen(test_data);
303 status = smb_raw_read(cli->tree, &io);
304 CHECK_STATUS(status, NT_STATUS_OK);
305 CHECK_VALUE(io.lockread.out.nread, 0);
307 setup_buffer(buf, seed, maxsize);
308 cli_write(cli->tree, fnum, 0, buf, 0, maxsize);
309 memset(buf, 0, maxsize);
311 printf("Trying large read\n");
312 io.lockread.in.offset = 0;
313 io.lockread.in.count = ~0;
314 status = smb_raw_read(cli->tree, &io);
315 CHECK_STATUS(status, NT_STATUS_LOCK_NOT_GRANTED);
316 cli_unlock(cli->tree, fnum, 1, strlen(test_data));
317 status = smb_raw_read(cli->tree, &io);
318 CHECK_STATUS(status, NT_STATUS_OK);
319 CHECK_BUFFER(buf, seed, io.lockread.out.nread);
320 cli_unlock(cli->tree, fnum, 0, 0xFFFF);
323 printf("Trying locked region\n");
325 if (NT_STATUS_IS_ERR(cli_lock(cli->tree, fnum, 103, 1, 0, WRITE_LOCK))) {
326 printf("Failed to lock file at %d\n", __LINE__);
331 memset(buf, 0, maxsize);
332 io.lockread.in.offset = 0;
333 io.lockread.in.count = ~0;
334 status = smb_raw_read(cli->tree, &io);
335 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
339 cli_close(cli->tree, fnum);
340 cli_deltree(cli->tree, BASEDIR);
348 static BOOL test_readx(struct cli_state *cli, TALLOC_CTX *mem_ctx)
355 const int maxsize = 90000;
356 const char *fname = BASEDIR "\\test.txt";
357 const char *test_data = "TEST DATA";
358 uint_t seed = time(NULL);
360 buf = talloc_zero(mem_ctx, maxsize);
362 if (cli_deltree(cli->tree, BASEDIR) == -1 ||
363 NT_STATUS_IS_ERR(cli_mkdir(cli->tree, BASEDIR))) {
364 printf("Unable to setup %s - %s\n", BASEDIR, cli_errstr(cli->tree));
368 printf("Testing RAW_READ_READX\n");
370 fnum = cli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
372 printf("Failed to create %s - %s\n", fname, cli_errstr(cli->tree));
377 printf("Trying empty file read\n");
378 io.generic.level = RAW_READ_READX;
379 io.readx.in.fnum = fnum;
380 io.readx.in.mincnt = 1;
381 io.readx.in.maxcnt = 1;
382 io.readx.in.offset = 0;
383 io.readx.in.remaining = 0;
384 io.readx.out.data = buf;
385 status = smb_raw_read(cli->tree, &io);
387 CHECK_STATUS(status, NT_STATUS_OK);
388 CHECK_VALUE(io.readx.out.nread, 0);
389 CHECK_VALUE(io.readx.out.remaining, 0xFFFF);
390 CHECK_VALUE(io.readx.out.compaction_mode, 0);
392 printf("Trying zero file read\n");
393 io.readx.in.mincnt = 0;
394 io.readx.in.maxcnt = 0;
395 status = smb_raw_read(cli->tree, &io);
396 CHECK_STATUS(status, NT_STATUS_OK);
397 CHECK_VALUE(io.readx.out.nread, 0);
398 CHECK_VALUE(io.readx.out.remaining, 0xFFFF);
399 CHECK_VALUE(io.readx.out.compaction_mode, 0);
401 printf("Trying bad fnum\n");
402 io.readx.in.fnum = fnum+1;
403 status = smb_raw_read(cli->tree, &io);
404 CHECK_STATUS(status, NT_STATUS_INVALID_HANDLE);
405 io.readx.in.fnum = fnum;
407 cli_write(cli->tree, fnum, 0, test_data, 0, strlen(test_data));
409 printf("Trying small read\n");
410 io.readx.in.fnum = fnum;
411 io.readx.in.offset = 0;
412 io.readx.in.remaining = 0;
413 io.readx.in.mincnt = strlen(test_data);
414 io.readx.in.maxcnt = strlen(test_data);
415 status = smb_raw_read(cli->tree, &io);
416 CHECK_STATUS(status, NT_STATUS_OK);
417 CHECK_VALUE(io.readx.out.nread, strlen(test_data));
418 CHECK_VALUE(io.readx.out.remaining, 0xFFFF);
419 CHECK_VALUE(io.readx.out.compaction_mode, 0);
420 if (memcmp(buf, test_data, strlen(test_data)) != 0) {
422 printf("incorrect data at %d!? (%s:%s)\n", __LINE__, test_data, buf);
426 printf("Trying short read\n");
427 io.readx.in.offset = 1;
428 io.readx.in.mincnt = strlen(test_data);
429 io.readx.in.maxcnt = strlen(test_data);
430 status = smb_raw_read(cli->tree, &io);
431 CHECK_STATUS(status, NT_STATUS_OK);
432 CHECK_VALUE(io.readx.out.nread, strlen(test_data)-1);
433 CHECK_VALUE(io.readx.out.remaining, 0xFFFF);
434 CHECK_VALUE(io.readx.out.compaction_mode, 0);
435 if (memcmp(buf, test_data+1, strlen(test_data)-1) != 0) {
437 printf("incorrect data at %d!? (%s:%s)\n", __LINE__, test_data+1, buf);
441 printf("Trying max offset\n");
442 io.readx.in.offset = 0xffffffff;
443 io.readx.in.mincnt = strlen(test_data);
444 io.readx.in.maxcnt = strlen(test_data);
445 status = smb_raw_read(cli->tree, &io);
446 CHECK_STATUS(status, NT_STATUS_OK);
447 CHECK_VALUE(io.readx.out.nread, 0);
448 CHECK_VALUE(io.readx.out.remaining, 0xFFFF);
449 CHECK_VALUE(io.readx.out.compaction_mode, 0);
451 setup_buffer(buf, seed, maxsize);
452 cli_write(cli->tree, fnum, 0, buf, 0, maxsize);
453 memset(buf, 0, maxsize);
455 printf("Trying large read\n");
456 io.readx.in.offset = 0;
457 io.readx.in.mincnt = ~0;
458 io.readx.in.maxcnt = ~0;
459 status = smb_raw_read(cli->tree, &io);
460 CHECK_STATUS(status, NT_STATUS_OK);
461 CHECK_VALUE(io.readx.out.remaining, 0xFFFF);
462 CHECK_VALUE(io.readx.out.compaction_mode, 0);
463 CHECK_VALUE(io.readx.out.nread, io.readx.in.maxcnt);
464 CHECK_BUFFER(buf, seed, io.readx.out.nread);
466 printf("Trying mincnt > maxcnt\n");
467 memset(buf, 0, maxsize);
468 io.readx.in.offset = 0;
469 io.readx.in.mincnt = 30000;
470 io.readx.in.maxcnt = 20000;
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, io.readx.in.maxcnt);
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 = 20000;
482 io.readx.in.maxcnt = 30000;
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 locked region\n");
492 if (NT_STATUS_IS_ERR(cli_lock(cli->tree, fnum, 103, 1, 0, WRITE_LOCK))) {
493 printf("Failed to lock file at %d\n", __LINE__);
498 memset(buf, 0, maxsize);
499 io.readx.in.offset = 0;
500 io.readx.in.mincnt = 100;
501 io.readx.in.maxcnt = 200;
502 status = smb_raw_read(cli->tree, &io);
503 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
505 printf("Trying large offset read\n");
506 io.readx.in.offset = ((uint64_t)0x2) << 32;
507 io.readx.in.mincnt = 10;
508 io.readx.in.maxcnt = 10;
509 status = smb_raw_read(cli->tree, &io);
510 CHECK_STATUS(status, NT_STATUS_OK);
511 CHECK_VALUE(io.readx.out.nread, 0);
513 if (NT_STATUS_IS_ERR(cli_lock64(cli->tree, fnum, io.readx.in.offset, 1, 0, WRITE_LOCK))) {
514 printf("Failed to lock file at %d\n", __LINE__);
519 status = smb_raw_read(cli->tree, &io);
520 CHECK_STATUS(status, NT_STATUS_OK);
521 CHECK_VALUE(io.readx.out.nread, 0);
524 cli_close(cli->tree, fnum);
525 cli_deltree(cli->tree, BASEDIR);
533 static BOOL test_readbraw(struct cli_state *cli, TALLOC_CTX *mem_ctx)
540 const int maxsize = 90000;
541 const char *fname = BASEDIR "\\test.txt";
542 const char *test_data = "TEST DATA";
543 uint_t seed = time(NULL);
545 buf = talloc_zero(mem_ctx, maxsize);
547 if (cli_deltree(cli->tree, BASEDIR) == -1 ||
548 NT_STATUS_IS_ERR(cli_mkdir(cli->tree, BASEDIR))) {
549 printf("Unable to setup %s - %s\n", BASEDIR, cli_errstr(cli->tree));
553 printf("Testing RAW_READ_READBRAW\n");
555 fnum = cli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
557 printf("Failed to create %s - %s\n", fname, cli_errstr(cli->tree));
562 printf("Trying empty file read\n");
563 io.generic.level = RAW_READ_READBRAW;
564 io.readbraw.in.fnum = fnum;
565 io.readbraw.in.mincnt = 1;
566 io.readbraw.in.maxcnt = 1;
567 io.readbraw.in.offset = 0;
568 io.readbraw.in.timeout = 0;
569 io.readbraw.out.data = buf;
570 status = smb_raw_read(cli->tree, &io);
572 CHECK_STATUS(status, NT_STATUS_OK);
573 CHECK_VALUE(io.readbraw.out.nread, 0);
575 printf("Trying zero file read\n");
576 io.readbraw.in.mincnt = 0;
577 io.readbraw.in.maxcnt = 0;
578 status = smb_raw_read(cli->tree, &io);
579 CHECK_STATUS(status, NT_STATUS_OK);
580 CHECK_VALUE(io.readbraw.out.nread, 0);
582 printf("Trying bad fnum\n");
583 io.readbraw.in.fnum = fnum+1;
584 status = smb_raw_read(cli->tree, &io);
585 CHECK_STATUS(status, NT_STATUS_OK);
586 CHECK_VALUE(io.readbraw.out.nread, 0);
587 io.readbraw.in.fnum = fnum;
589 cli_write(cli->tree, fnum, 0, test_data, 0, strlen(test_data));
591 printf("Trying small read\n");
592 io.readbraw.in.fnum = fnum;
593 io.readbraw.in.offset = 0;
594 io.readbraw.in.mincnt = strlen(test_data);
595 io.readbraw.in.maxcnt = strlen(test_data);
596 status = smb_raw_read(cli->tree, &io);
597 CHECK_STATUS(status, NT_STATUS_OK);
598 CHECK_VALUE(io.readbraw.out.nread, strlen(test_data));
599 if (memcmp(buf, test_data, strlen(test_data)) != 0) {
601 printf("incorrect data at %d!? (%s:%s)\n", __LINE__, test_data, buf);
605 printf("Trying short read\n");
606 io.readbraw.in.offset = 1;
607 io.readbraw.in.mincnt = strlen(test_data);
608 io.readbraw.in.maxcnt = strlen(test_data);
609 status = smb_raw_read(cli->tree, &io);
610 CHECK_STATUS(status, NT_STATUS_OK);
611 CHECK_VALUE(io.readbraw.out.nread, strlen(test_data)-1);
612 if (memcmp(buf, test_data+1, strlen(test_data)-1) != 0) {
614 printf("incorrect data at %d!? (%s:%s)\n", __LINE__, test_data+1, buf);
618 printf("Trying max offset\n");
619 io.readbraw.in.offset = ~0;
620 io.readbraw.in.mincnt = strlen(test_data);
621 io.readbraw.in.maxcnt = strlen(test_data);
622 status = smb_raw_read(cli->tree, &io);
623 CHECK_STATUS(status, NT_STATUS_OK);
624 CHECK_VALUE(io.readbraw.out.nread, 0);
626 setup_buffer(buf, seed, maxsize);
627 cli_write(cli->tree, fnum, 0, buf, 0, maxsize);
628 memset(buf, 0, maxsize);
630 printf("Trying large read\n");
631 io.readbraw.in.offset = 0;
632 io.readbraw.in.mincnt = ~0;
633 io.readbraw.in.maxcnt = ~0;
634 status = smb_raw_read(cli->tree, &io);
635 CHECK_STATUS(status, NT_STATUS_OK);
636 CHECK_VALUE(io.readbraw.out.nread, 0xFFFF);
637 CHECK_BUFFER(buf, seed, io.readbraw.out.nread);
639 printf("Trying mincnt > maxcnt\n");
640 memset(buf, 0, maxsize);
641 io.readbraw.in.offset = 0;
642 io.readbraw.in.mincnt = 30000;
643 io.readbraw.in.maxcnt = 20000;
644 status = smb_raw_read(cli->tree, &io);
645 CHECK_STATUS(status, NT_STATUS_OK);
646 CHECK_VALUE(io.readbraw.out.nread, io.readbraw.in.maxcnt);
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 = 20000;
653 io.readbraw.in.maxcnt = 30000;
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 locked region\n");
661 if (NT_STATUS_IS_ERR(cli_lock(cli->tree, fnum, 103, 1, 0, WRITE_LOCK))) {
662 printf("Failed to lock file at %d\n", __LINE__);
667 memset(buf, 0, maxsize);
668 io.readbraw.in.offset = 0;
669 io.readbraw.in.mincnt = 100;
670 io.readbraw.in.maxcnt = 200;
671 status = smb_raw_read(cli->tree, &io);
672 CHECK_STATUS(status, NT_STATUS_OK);
673 CHECK_VALUE(io.readbraw.out.nread, 0);
675 printf("Trying locked region with timeout\n");
676 memset(buf, 0, maxsize);
677 io.readbraw.in.offset = 0;
678 io.readbraw.in.mincnt = 100;
679 io.readbraw.in.maxcnt = 200;
680 io.readbraw.in.timeout = 10000;
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 large offset read\n");
686 io.readbraw.in.offset = ((uint64_t)0x2) << 32;
687 io.readbraw.in.mincnt = 10;
688 io.readbraw.in.maxcnt = 10;
689 io.readbraw.in.timeout = 0;
690 status = smb_raw_read(cli->tree, &io);
691 CHECK_STATUS(status, NT_STATUS_OK);
692 CHECK_VALUE(io.readbraw.out.nread, 0);
695 cli_close(cli->tree, fnum);
696 cli_deltree(cli->tree, BASEDIR);
702 basic testing of read calls
704 BOOL torture_raw_read(int dummy)
706 struct cli_state *cli;
710 if (!torture_open_connection(&cli)) {
714 mem_ctx = talloc_init("torture_raw_read");
716 if (!test_read(cli, mem_ctx)) {
720 if (!test_readx(cli, mem_ctx)) {
724 if (!test_lockread(cli, mem_ctx)) {
728 if (!test_readbraw(cli, mem_ctx)) {
732 torture_close_connection(cli);
733 talloc_destroy(mem_ctx);