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 numbered attributes:
  27 #
  28 # a: Test set/get attr FATTR4_SIZE of file object, expect OK    
  29 # b: Test set/get attr FATTR4_MODE of file object, expect OK
  30 # c: Test set/get attr FATTR4_TIME_ACCESS_SET of last access to file object,
  31 #    expect OK
  32 # d: Test set/get attr FATTR4_TIME_MODIFY_SET of a file object, expect OK
  33 # e: Test set/get attr FATTR4_SIZE of directory object, expect OK
  34 #
  35 
  36 set TESTROOT $env(TESTROOT)
  37 set delm $env(DELM)
  38 
  39 # include common code and init section
  40 source ${TESTROOT}${delm}tcl.init
  41 source ${TESTROOT}${delm}testproc
  42 
  43 # connect to the test server
  44 Connect
  45 
  46 # setting local variables
  47 set TNAME $argv0
  48 set bfh [get_fh "$BASEDIRS"]
  49 set expcode "OK"
  50 
  51 # Start testing
  52 # ----------------------------------------------------------
  53 # a: Test set/get attr FATTR4_SIZE of file object, expect OK 
  54 
  55 set ASSERTION "Test set/get attr FATTR4_SIZE of file object, expect OK"
  56 set tag "$TNAME{a}"
  57 putmsg stdout 0 "$tag: $ASSERTION"
  58 
  59 # Open file in creat mode to obtain stateid
  60 global NULL env OPEN4_RESULT_CONFIRM
  61 
  62 # set string id (this is unique for each exec to avoid problems
  63 #       with the seqid).
  64 set id_string \
  65         "[clock clicks] [expr int([expr [expr rand()] * 100000000])]]"
  66 
  67 # negotiate clientid
  68 set seqid 1
  69 set clientid [getclientid $id_string]
  70 if {$clientid < 0} {
  71         putmsg stderr 0 "getclientid failed."
  72         return $NULL
  73 }
  74 
  75 # try open with create on <pathdir>
  76 set filename "newfile.[pid]"
  77 set opentype    1
  78 set createmode  0
  79 set mode        664
  80 set claim       0
  81 incr seqid
  82 set size        0
  83 set res [compound {Putfh $bfh;
  84         Open $seqid 3 0 {$clientid $id_string} \
  85         {$opentype $createmode {{mode $mode} {size $size}}} \
  86         {$claim $filename}; Getfh}]
  87 if {$status != "OK"} { 
  88         set cont "false"
  89         putmsg stderr 1 "\t    res=($res)."
  90         putmsg stdout 0 "\t Test UNRESOLVED: Open op failed unexpectedly, status=($status)"
  91 } else {
  92 
  93 #store all open info
  94 set stateid [lindex [lindex $res 1] 2]
  95 set rflags [lindex [lindex $res 1] 4]
  96 set nfh [lindex [lindex $res 2] 2]
  97 
  98 # check open_confirm
  99 if {[expr $rflags & $OPEN4_RESULT_CONFIRM] != 0} {
 100         incr seqid
 101         set res [compound {Putfh $nfh; Open_confirm $stateid $seqid}]
 102         putmsg stdout 1 $res
 103         if {$status != "OK"} {
 104                 putmsg stderr 0 \
 105                 "Can not open confirm $filename under $pathdir"
 106                 return $NULL
 107         }
 108         set stateid [lindex [lindex $res 1] 2]
 109 }
 110 
 111 
 112 # Var for attributes for all tests below   
 113 set attrs {size mode owner time_access time_modify}
 114 
 115 #Get the filehandle of the new file 
 116 set res2 [compound { Putfh $bfh; Lookup $filename; Getfh; Getattr $attrs }]
 117 set cont [ckres "Getattr" $status $expcode $res2 $FAIL]
 118 
 119 if { ![string equal $cont "false"] } {
 120 set fh [lindex [lindex $res2 2] 2]
 121 
 122 set origtime_modify [ extract_attr [lindex [lindex $res2 3] 2] "time_modify" ]
 123 
 124 set chgsize 444
 125 set chgmode 444
 126 set nta "[clock seconds] 0"
 127 set tmod 0
 128 
 129 # Generate a compound request to change the attributes
 130 set res3 [compound { Putfh $nfh;
 131         Setattr $stateid {{size {$chgsize}} {mode {$chgmode}}
 132         {time_access_set {$nta}} {time_modify_set {$tmod}} };
 133         Getattr $attrs;
 134 }]
 135 prn_attrs [lindex [lindex $res3 2] 2]
 136 ckres "Setattr" $status $expcode $res3 $PASS
 137 
 138 }
 139 
 140 #finally close the file
 141 incr seqid
 142 set res [compound {Putfh $bfh; Close $seqid $stateid}]
 143 putmsg stdout 1 " "
 144 putmsg stdout 1 "Making Close call with seqid=$seqid, stateid=$stateid"
 145 
 146 }
 147 
 148 
 149 
 150 # ----------------------------------------------------------
 151 # b: Test set/get attr FATTR4_MODE of file object, expect OK
 152 
 153 set ASSERTION "Test set/get attr FATTR4_MODE of file object, expect $expcode"
 154 set tag "$TNAME{b}"
 155 putmsg stdout 0 "$tag: $ASSERTION"
 156 
 157 if { ![string equal $cont "false"] } {
 158 
 159 set newmode [ extract_attr [lindex [lindex $res3 2] 2] "mode" ]
 160 if {[string compare $chgmode $newmode] == 0} {
 161         putmsg stdout 0 "\t Test PASS"
 162 } else {
 163         putmsg stderr 0 "\t Test FAIL: mode $chgmode did not get set"
 164 }
 165 
 166 } else {
 167         putmsg stderr 0 "\t Test UNRESOLVED: Open create failed unexpectedly in test case a" 
 168 }
 169 
 170 # -----------------------------------------------------------------
 171 # c: Test set/get attr FATTR4_TIME_ACCESS of file object, expect OK
 172 
 173 set ASSERTION "Test set/get attr FATTR4_TIME_ACCESS of file object, expect $expcode"
 174 set tag "$TNAME{c}"
 175 putmsg stdout 0 "$tag: $ASSERTION"
 176 
 177 if { ![string equal $cont "false"] } {
 178 
 179 set newtime_access [ extract_attr [lindex [lindex $res3 2] 2] "time_access" ]
 180 if {[string compare $nta $newtime_access] == 0} {
 181         putmsg stdout 0 "\t Test PASS"
 182 } else {
 183         putmsg stderr 0 "\t Test FAIL: time_access did not get set"
 184 }
 185 
 186 } else {
 187         putmsg stderr 0 "\t Test UNRESOLVED: Open create failed unexpectedly in test case a"
 188 }
 189 
 190 # -----------------------------------------------------------------
 191 # d: Test set/get attr FATTR4_TIME_MODIFY of file object, expect OK
 192 
 193 set ASSERTION "Test set/get attr FATTR4_TIME_MODIFY of file object, expect $expcode"
 194 set tag "$TNAME{d}"
 195 putmsg stdout 0 "$tag: $ASSERTION"
 196 
 197 if { ![string equal $cont "false"] } {
 198 
 199 set newtime_modify [ extract_attr [lindex [lindex $res3 2] 2] "time_modify" ]
 200 if { $newtime_modify != $origtime_modify } {
 201         putmsg stdout 0 "\t Test PASS"
 202 } else {
 203         putmsg stderr 0 "\t Test FAIL: time_modify did not get set"
 204 }
 205 
 206 } else {
 207         putmsg stderr 0 "\t Test UNRESOLVED: Open create failed unexpectedly in test case a" 
 208 }
 209 
 210 set res [compound {Putfh $bfh; Remove $filename}]
 211 if {$status != "OK"} {
 212     putmsg stderr 0 "\tERROR, compound{} return status=$status"
 213 }
 214 
 215 Disconnect 
 216 exit $PASS