1 #
2 # CDDL HEADER START
3 #
4 # The contents of this file are subject to the terms of the
5 # Common Development and Distribution License (the "License").
6 # You may not use this file except in compliance with the License.
7 #
8 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 # or http://www.opensolaris.org/os/licensing.
10 # See the License for the specific language governing permissions
11 # and limitations under the License.
12 #
13 # When distributing Covered Code, include this CDDL HEADER in each
14 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 # If applicable, add the following below this CDDL HEADER, with the
16 # fields enclosed by brackets "[]" replaced with your own identifying
17 # information: Portions Copyright [yyyy] [name of copyright owner]
18 #
19 # CDDL HEADER END
20 #
21
22 #
23 # Copyright 2006 Sun Microsystems, Inc. All rights reserved.
24 # Use is subject to license terms.
25 #
26 # NFSv4 READ operation test - negative tests
27 # verify SERVER errors returned with invalid read.
28
29 # include all test enironment
30 source READ.env
31
32 # connect to the test server
33 Connect
34
35 # setting local variables
36 set TNAME $argv0
37 set bfh [get_fh "$BASEDIRS"]
38
39
40 # Start testing
41 # --------------------------------------------------------------
42 # a: Read a file w/an invalid stateid (not from Open) -
43 # expect BAD_STATEID|STALE_STATEID
44 #
45 set expcode "BAD_STATEID|STALE_STATEID"
46 set ASSERTION "Read a file w/invalid stateid (not from Open), expect $expcode"
47 set tag "$TNAME{a}"
48 putmsg stdout 0 "$tag: $ASSERTION"
49 set stateid {12345 67890}
50 set res [compound {Putfh $bfh; Lookup $env(TEXTFILE); Read $stateid 0 1024}]
51 ckres "Read" $status $expcode $res $PASS
52
53 # Open a file for a valid stateid, then check for errors:
54 set TRes 0
55 set owner "[expr int([expr [expr rand()] * 100000000])]"
56 set cid [getclientid $owner]
57 if {$cid == -1} {
58 set TRes 1
59 } else {
60 set otype 0
61 set nfh [basic_open $bfh $env(ROFILE) $otype "$cid $owner" \
62 open_sid oseqid status 1 0 600 0 1]
63 if {$nfh == -1} {
64 set TRes 2
65 }
66 }
67
68 # Now do negative READ testing:
69 if {$TRes == 0} {
70 incr oseqid
71 putmsg stderr 1 " open_sid from OPEN = ($open_sid)"
72 # b: Read a file with an invalid stateid (seqid+1) - expect BAD_STATEID
73 #
74 set expcode "BAD_STATEID"
75 set ASSERTION "Read a file w/invalid stateid (seqid+1), expect $expcode"
76 set tag "$TNAME{b}"
77 putmsg stdout 0 "$tag: $ASSERTION"
78 set bseqid [expr [lindex $open_sid 0] + 1]
79 set bopen_sid "$bseqid [lindex $open_sid 1]"
80 putmsg stderr 1 " new open_sid with trashed seqid: bopen_sid=($bopen_sid)"
81 set rres [compound {Putfh $nfh; Read "$bopen_sid" 0 512}]
82 ckres "Read" $status $expcode $rres $PASS
83
84 # c: Read a file w/invalid stateid (trash-other) -
85 # expect BAD_STATEID|STALE_STATEID
86 #
87 set expcode "BAD_STATEID|STALE_STATEID"
88 set ASSERTION "Read a file w/invalid stateid (trash-other), expect $expcode"
89 set tag "$TNAME{c}"
90 putmsg stdout 0 "$tag: $ASSERTION"
91 set newS ""
92 set oldS [lindex $open_sid 1]
93 set l [string length $oldS]
94 for {set i 0} {$i < $l} {incr i} {
95 append newS [string index $oldS end-$i]
96 }
97 set copen_sid "[lindex $open_sid 0] $newS"
98 putmsg stderr 1 " new open_sid with trashed other: copen_sid=($copen_sid)"
99 set rres [compound {Putfh $nfh; Read "$copen_sid" 1 257}]
100 ckres "Read" $status $expcode $rres $PASS
101
102 # d: Read w/open_stateid from a wrong file - expect BAD_STATEID
103 #
104 set expcode "BAD_STATEID"
105 set ASSERTION "Read w/open_stateid from wrong file, expect $expcode"
106 set tag "$TNAME{d}"
107 putmsg stdout 0 "$tag: $ASSERTION"
108 set tfh [basic_open $bfh $env(RWFILE) 0 "$cid $owner-d" osid2 oseqid2 \
109 status $oseqid 0 600 0 1]
110 if {$tfh == -1} {
111 putmsg stderr 0 "\t Test FAIL: basic_open2 failed on $env(RWFILE)"
112 putmsg stderr 0 "\t status=($status)"
113 } else {
114 incr oseqid2
115 set rres [compound {Putfh $nfh; Read "$osid2" 2 88}]
116 ckres "Read" $status $expcode $rres $PASS
117 }
118
119
120 # then close the file:
121 set res [compound {Putfh $nfh; Close $oseqid $open_sid}]
122 putmsg stdout 2 "\nClose $oseqid $open_sid ... "
123 putmsg stdout 2 "Res: $res"
124
125 # m: Read a file after file closed - expect BAD_STATEID|OLD_STATEID
126 #
127 set expcode "BAD_STATEID|OLD_STATEID"
128 set ASSERTION "Read a file after file is closed, expect $expcode"
129 set tag "$TNAME{m}"
130 putmsg stdout 0 "$tag: $ASSERTION"
131 set rres [compound {Putfh $nfh; Read "$open_sid" 16 255}]
132 ckres "Read" $status $expcode $rres $PASS
133
134
135 } elseif {$TRes == 1} {
136 putmsg stderr 0 "\t Test UNINITIATED: getclientid() failed"
137 putmsg stdout 0 "\t tests are not run.\n"
138 } elseif {$TRes == 2} {
139 putmsg stderr 0 "\t Test UNINITIATED: basic_open() failed"
140 putmsg stdout 0 "\t tests are not run.\n"
141 }
142
143
144 # --------------------------------------------------------------
145 # disconnect and exit
146 Disconnect
147 exit $PASS