1 #!nfsh
2 #
3 # CDDL HEADER START
4 #
5 # The contents of this file are subject to the terms of the
6 # Common Development and Distribution License (the "License").
7 # You may not use this file except in compliance with the License.
8 #
9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 # or http://www.opensolaris.org/os/licensing.
11 # See the License for the specific language governing permissions
12 # and limitations under the License.
13 #
14 # When distributing Covered Code, include this CDDL HEADER in each
15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 # If applicable, add the following below this CDDL HEADER, with the
17 # fields enclosed by brackets "[]" replaced with your own identifying
18 # information: Portions Copyright [yyyy] [name of copyright owner]
19 #
20 # CDDL HEADER END
21 #
22
23 #
24 # Copyright 2006 Sun Microsystems, Inc. All rights reserved.
25 # Use is subject to license terms.
26 #
27
28 #
29 # Test script for NFS TCL
30 #
31 # This script is to check server's responses to errors
32 # with different operations, including Lookup, Link,
33 # Rename, Remove, etc.
34 #
35
36 if { $argc != 2 } {
37 puts "Usage: $argv0 <hostname> <pathname>"
38 puts " note: <pathname> must be a file, and"
39 puts " it's parent directory must be writable"
40 exit 1
41 }
42
43 set host [lindex $argv 0]
44 set path [ path2comp [lindex $argv 1] "/" ]
45 set pathlen [expr [llength $path] - 1]
46
47 set dir [lrange $path 0 [expr $pathlen - 1]]
48 set fname [lindex $path $pathlen]
49
50 #connect -t udp -p 9999 $host
51 connect $host
52 puts "connected to $host ..."
53 set dfh [get_fh $dir]
54
55 # 1. Check for NOFILEHANDLE :
56 set result [compound { Lookup $fname }]
57 if { $status != "NOFILEHANDLE" } {
58 puts "compound {Lookup $path}"
59 puts " FAILED: expect it to return NOFILEHANDLE"
60 puts ""
61 puts $result
62 exit 2
63 }
64 puts "checking Lookup NOFILEHANDLE OK"
65
66 # 2. Check for NOENT :
67 set result [compound { Putfh $dfh; Lookup enoent }]
68 if { $status != "NOENT" } {
69 puts "compound {Putfh $dfh; Lookup enoent }"
70 puts " FAILED: expect it to return NOENT"
71 puts ""
72 puts $result
73 exit 2
74 }
75 puts "checking Lookup NOENT OK"
76
77 # 3. Check for <sfh> is dir in Link :
78 # first verify pathname to be a file.
79 set result [compound { Putrootfh; foreach c $path {Lookup $c}; Getattr type}]
80 set ftype [lindex [lindex [lindex [lindex $result end] 2] 0] 1]
81 if { $ftype != "reg" } {
82 puts "($path) is not a file"
83 puts "Link requires a file to be linked"
84 exit 2
85 }
86
87 set result [compound { Putfh $dfh; Savefh; Lookup $fname; Link linkfile}]
88 if { ($status != "ISDIR") && ($status != "NOTDIR")} {
89 puts "compound {Putrootfh; Lookup {$dir}; Savefh;"
90 puts " Lookup {$fname}; Link linkfile}"
91 puts " FAILED: expect it to return ISDIR/NOTDIR"
92 puts ""
93 puts $result
94 # exit 2
95 }
96 puts "checking Link ISDIR/NOTDIR OK"
97
98 # Check for <sfh> is not saved in Rename :
99 set result [compound { Putfh $dfh; Rename $fname "NewFile"}]
100 if { $status != "NOFILEHANDLE" } {
101 puts "compound {Putfh $dfh; Rename $fname NewFile}"
102 puts " FAILED: expect it to return NOFILEHANDLE"
103 puts ""
104 puts $result
105 exit 2
106 }
107 # make sure $fname still exists (since operation failed):
108 set result [compound { Putfh $dfh; Lookup $fname }]
109 if { $status == "NOENT" } {
110 puts " after rename failed, \[$fname\] should still exist."
111 }
112
113 puts "checking Rename NOFILEHANDLE OK"
114
115 # Check for directory is not empty in Remove :
116 set dname [lindex $dir [expr [llength $dir] - 1]]
117 set result [compound { Putfh $dfh; Lookupp; Remove $dname}]
118 if { $status != "NOTEMPTY" } {
119 puts "compound {Putfh $dfh; Lookupp; Remove $dname}"
120 puts " FAILED: expect it to return NOTEMPTY"
121 puts ""
122 puts $result
123 exit 2
124 }
125 # make sure $dir still exists (since operation failed):
126 set result [compound { Putrootfh; foreach c $dir {Lookup $c} }]
127 if { $status == "NOENT" } {
128 puts " after rename failed, \[$dir\] should still exist."
129 }
130
131 puts "checking Remove NOTEMPTY OK"
132
133 exit 0