1 #!/usr/bin/expect
   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 2008 Sun Microsystems, Inc.  All rights reserved.
  25 # Use is subject to license terms.
  26 #
  27 
  28 # 
  29 # This expect script contains tests for setprop_003 - setprop_007
  30 #
  31 
  32 source $env(STF_TOOLS)/include/stf.explib
  33 
  34 set RESULT $STF_PASS
  35 
  36 
  37 set service [lindex $argv 0]
  38 
  39 set argc [llength $argv]
  40 
  41 if {$argc == 2} {
  42         set instance [lindex $argv 1]
  43         set prompt $service:$instance
  44         set test_type "instance"
  45 } else {
  46         set prompt $service
  47         set test_type "service"
  48 }
  49 
  50 set usage "Usage:*Set the name property of the pg property group of the currently selected*" 
  51 
  52 set timeout 5
  53 
  54 spawn svccfg
  55 expect {
  56         timeout {
  57                 send_user "\n"
  58                 send_user "Failed to get svccfg prompt\n"
  59                 send_user "RSLT (setup): UNRESOLVED\n"
  60                 exit $STF_UNRESOLVED
  61         }
  62         "svc:> " 
  63 }
  64 
  65 
  66 send "select $service\r"
  67 expect  {
  68         timeout {
  69                 send_user "\n"
  70                 send_user "Failed to select service $service\n"
  71                 send_user "RSLT (setup): UNRESOLVED\n"
  72                 exit $STF_UNRESOLVED
  73         }
  74         "svc:/$service> " 
  75 }
  76 
  77 
  78 if {$argc == 2} {
  79         send "select $instance\r"
  80         expect  {
  81                 timeout {
  82                         send_user "\n"
  83                         send_user "Failed to select instance $instance\n"
  84                         send_user "RSLT (setup): UNRESOLVED\n"
  85                         exit $STF_UNRESOLVED
  86                 }
  87         "svc:/$prompt> " 
  88         }
  89 }
  90 
  91 
  92 set assertion svccfg_setprop_003
  93 
  94 send_user "\n\n"
  95 send_user "INFO: Testing assertion $assertion ($test_type)\n"
  96 send "setprop foobar = integer (3)\r"
  97 expect  {
  98         timeout {
  99                 send_user "\n"
 100                 send_user "Expected error message not issued.\n"
 101                 send_user "RSLT: FAIL\n"
 102                 set RESULT $STF_FAIL
 103         }
 104         "Property names must contain a `/'." {
 105                 send_user "RSLT: PASS\n"
 106         }
 107 }
 108 
 109 send "listprop\r"
 110 expect  {
 111         timeout {
 112                 send_user "\n"
 113                 send_user "Expected listprop to display no properties"
 114                 send_user "RSLT: FAIL\n"
 115                 set RESULT  $STF_FAIL
 116 
 117         }
 118         "svc:/$prompt> "
 119 }
 120 
 121 
 122 set assertion svccfg_setprop_004
 123 
 124 send_user "\n\n"
 125 send_user "INFO: Testing assertion $assertion ($test_type)\n"
 126 send "setprop foo/new_prop = invalid_type (foo)\r"
 127 expect  {
 128         timeout {
 129                 send_user "\n"
 130                 send_user "Expected error message not issued.\n"
 131                 send_user "RSLT: FAIL\n"
 132                 set RESULT $STF_FAIL
 133         }
 134         "Unknown type `invalid_type'."  {
 135                 send_user "RSLT: PASS\n"
 136         }
 137 }
 138 
 139 send "listprop\r"
 140 expect  {
 141         timeout {
 142                 send_user "\n"
 143                 send_user "Expected listprop to display no properties"
 144                 send_user "RSLT: FAIL\n"
 145                 set RESULT  $STF_FAIL
 146 
 147         }
 148         "svc:/$prompt> "
 149 }
 150 
 151 # Setup for svccfg_setuprop_005
 152 
 153 send "addpg foo framework\r"
 154 expect  {
 155         timeout {
 156                 send_user "\n"
 157                 send_user "Failed to create pg foo\n"
 158                 send_user "RSLT ($assertion): UNRESOLVED\n"
 159                 exit $STF_UNRESOLVED
 160         }
 161         "svc:/$prompt> " 
 162 }
 163 
 164 
 165 send "listprop\r"
 166 expect  {
 167         timeout {
 168                 send_user "\n"
 169                 send_user "Expected listprop to display no properties"
 170                 send_user "RSLT: FAIL\n"
 171                 exit $STF_UNRESOLVED
 172 
 173         }
 174         "foo  framework\r\nsvc:/$prompt> " 
 175 }
 176 
 177 
 178 
 179 set assertion svccfg_setprop_005
 180 
 181 #
 182 # For each test of a bad value the type must be defined in "type_array"
 183 # and the bad value must be defined in the "badvalue_array"
 184 #
 185 set total 3
 186 set count 0
 187 
 188 set type_array(0)       "integer"
 189 set badvalue_array(0)   "badinteger"
 190 set type_array(1)       "boolean"
 191 set badvalue_array(1)   "badboolean"
 192 set type_array(2)       "count"
 193 set badvalue_array(2)   "badcount"
 194 
 195 while {$count < $total} {
 196 
 197         send_user "\n\n"
 198         send_user "INFO: Testing assertion $assertion, test $count ($test_type)\n"
 199         send "setprop foo/bad = $type_array($count) ($badvalue_array($count))\r"
 200         expect  {
 201                 timeout {
 202                         send_user "\n"
 203                         send_user "Expected error message not issued.\n"
 204                         send_user "RSLT: FAIL\n"
 205                         set RESULT $STF_FAIL
 206                 }
 207                 "Invalid $type_array($count) value `$badvalue_array($count)'." {
 208                         send_user "RSLT: PASS\n"
 209                 }
 210         }
 211 
 212         set count [ expr $count + 1]
 213 }
 214 
 215 
 216 set assertion svccfg_setprop_006
 217 
 218 send_user "\n\n"
 219 send_user "INFO: Testing assertion $assertion ($test_type)\n"
 220 send "setprop foo/bar = integer 3\r"
 221 expect  {
 222         timeout {
 223                 send_user "\n"
 224                 send_user "Expected error message not issued.\n"
 225                 send_user "RSLT: FAIL\n"
 226                 set RESULT $STF_FAIL
 227         }
 228         $usage {
 229                 send_user "RSLT: PASS\n"
 230         }
 231 }
 232 
 233 send "listprop\r"
 234 expect  {
 235         timeout {
 236                 send_user "\n"
 237                 send_user "Expected listprop to display no properties"
 238                 send_user "RSLT: FAIL\n"
 239                 set RESULT  $STF_FAIL
 240 
 241         }
 242         "svc:/$prompt> "
 243 }
 244 
 245 set assertion svccfg_setprop_007
 246 
 247 
 248 set total 5
 249 set count 0
 250 
 251 set command(0)  "setprop\r"
 252 set command(1)  "setprop foo/bar integer (3)\r" 
 253 set command(2)  "setprop foo/bar=integer(3) \"extraoption\"\r" 
 254 set command(3)  "setprop foo/bar=integer(3) 12000\r" 
 255 set command(4)  "setprop foo/bar=integer(3) one two three four five six seven eight nine ten eleven twelve thirteen fourteen fifteen sixteen seventeen eighteen nineteen twenty\r" 
 256 
 257 while {$count < $total} {
 258 
 259         send_user "\n\n"
 260         send_user "INFO: Testing assertion $assertion, test $count ($test_type)\n"
 261         send $command($count)
 262 
 263         expect  {
 264                 timeout {
 265                         send_user "\n"
 266                         send_user "Expected error message not issued.\n"
 267                         send_user "RSLT: FAIL\n"
 268                         set RESULT $STF_FAIL
 269                 }
 270                 $usage {
 271                         send_user "RSLT: PASS\n"
 272                 }
 273         }
 274 
 275         set count [ expr $count + 1]
 276 }
 277 
 278 
 279 send "listprop\r"
 280 expect  {
 281         timeout {
 282                 send_user "\n"
 283                 send_user "Expected listprop to display no properties"
 284                 send_user "RSLT: FAIL\n"
 285                 set RESULT  $STF_FAIL
 286 
 287         }
 288         "svc:/$prompt> "
 289 }
 290 
 291 send "delpg foo\r"
 292 expect  {
 293         timeout {
 294                 send_user "\n"
 295                 send_user "Failed to create pg foo\n"
 296                 send_user "RSLT ($assertion): UNRESOLVED\n"
 297                 exit $STF_UNRESOLVED
 298         }
 299         "svc:/$prompt> " 
 300 }
 301 
 302 
 303 send "listprop\r"
 304 expect  {
 305         timeout {
 306                 send_user "\n"
 307                 send_user "Expected listprop to display no properties"
 308                 send_user "RSLT: FAIL\n"
 309                 exit $STF_UNRESOLVED
 310 
 311         }
 312         "svc:/$prompt> " 
 313 }
 314 
 315 set assertion svccfg_setprop_008
 316 
 317 send_user "\n\n"
 318 send_user "INFO: Testing assertion $assertion ($test_type)\n"
 319 send "setprop foo/new_prop = (foo)\r"
 320 expect  {
 321         timeout {
 322                 send_user "\n"
 323                 send_user "Expected error message not issued.\n"
 324                 send_user "RSLT: FAIL\n"
 325                 set RESULT $STF_FAIL
 326         }
 327         $usage  {
 328                 send_user "RSLT: PASS\n"
 329         }
 330 }
 331 
 332 send "listprop\r"
 333 expect  {
 334         timeout {
 335                 send_user "\n"
 336                 send_user "Expected listprop to display no properties"
 337                 send_user "RSLT: FAIL\n"
 338                 set RESULT  $STF_FAIL
 339 
 340         }
 341         "svc:/$prompt> "
 342 }
 343 
 344 exit $RESULT
 345 
 346