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_011
  30 #
  31 
  32 source $env(STF_TOOLS)/include/stf.explib
  33 
  34 set RESULT $STF_PASS
  35 
  36 set service [lindex $argv 0]
  37 
  38 set argc [llength $argv]
  39 
  40 if {$argc == 2} {
  41         set instance [lindex $argv 1]
  42         set prompt $service:$instance
  43         set test_type "instance"
  44 } else {
  45         set prompt $service
  46         set test_type "service"
  47 }
  48 
  49 set timeout 5
  50 
  51 
  52 send_user "\n\n"
  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 if {$argc == 2} {
  78         send "select $instance\r"
  79         expect  {
  80                 timeout {
  81                         send_user "\n"
  82                         send_user "Failed to select instance $instance\n"
  83                         send_user "RSLT (setup): UNRESOLVED\n"
  84                         exit $STF_UNRESOLVED
  85                 }
  86         "svc:/$prompt> " 
  87         }
  88 }
  89 
  90 # Setup by adding property group
  91 
  92 send "addpg foo framework\r"
  93 expect  {
  94         timeout {
  95                 send_user "\n"
  96                 send_user "Failed to create pg foo\n"
  97                 send_user "RSLT ($assertion): UNRESOLVED\n"
  98                 exit $STF_UNRESOLVED
  99         }
 100         "svc:/$prompt> "
 101 }
 102 
 103 
 104 set assertion svccfg_setprop_011
 105 
 106 send_user "\n\n"
 107 send_user "INFO: Testing assertion $assertion\n"
 108 
 109 set total 13
 110 set count 0
 111 
 112 set good_array(0) "true"
 113 set bad_array(0) "bogus"
 114 set type_array(0) "boolean"
 115 set good_array(1) "true"
 116 set bad_array(1) "bogus_data"
 117 set type_array(1) "boolean"
 118 set good_array(2) "true"
 119 set bad_array(2) "12345"
 120 set type_array(2) "boolean"
 121 
 122 set good_array(3) "100"
 123 set bad_array(3) bogus
 124 set type_array(3) "integer"
 125 set good_array(4) "100"
 126 set bad_array(4) "bogus"
 127 set type_array(4) "integer"
 128 set good_array(5) "100"
 129 set bad_array(5) "bogus data"
 130 set type_array(5) "integer"
 131 set good_array(6) "100"
 132 set bad_array(6) 12:45
 133 set type_array(6) "integer"
 134 set good_array(7) "100"
 135 set bad_array(7) 123.456
 136 set type_array(7) "integer"
 137 
 138 set good_array(8) "100"
 139 set bad_array(8) bogus
 140 set type_array(8) "count"
 141 set good_array(9) "100"
 142 set bad_array(9) "bogus"
 143 set type_array(9) "count"
 144 set good_array(10) "100"
 145 set bad_array(10) "bogus data"
 146 set type_array(10) "count"
 147 set good_array(11) "100"
 148 set bad_array(11) 12:45
 149 set type_array(11) "count"
 150 set good_array(12) "100"
 151 set bad_array(12) 123.456
 152 set type_array(12) "count"
 153 
 154 
 155 
 156 while {$count < $total} {
 157 
 158         send "setprop foo/good_$count = $type_array($count) ($good_array($count))\r"
 159         expect  {
 160                 timeout {
 161                         send_user "\n"
 162                         send_user "Failed to set property foo/good_$count\n"
 163                         send_user "RSLT: FAIL\n"
 164                         set RESULT $STF_FAIL
 165                 }
 166                 "svc:/$prompt> "
 167         }
 168         set count [ expr $count + 1 ]
 169 }
 170 
 171 set count 0
 172 
 173 while {$count < $total} {
 174 
 175         send "setprop foo/good_$count = $type_array($count) ($bad_array($count))\r"
 176         expect  {
 177                 timeout {
 178                         send_user "\n"
 179                         send_user "Failed to get expected error message when attempting setprop on good_$count\n"
 180                         send_user "RSLT: FAIL\n"
 181                         set RESULT  $STF_FAIL
 182                 }
 183                 "Invalid $type_array($count) value *\r\nsvc:/$prompt> "
 184         }
 185 
 186         send "listprop foo/good_$count\r"
 187         expect  {
 188                 timeout {
 189                         send_user "\n"
 190                         send_user "Unexpected value of prop foo/good_$count given\n" 
 191                         send_user "RSLT: FAIL\n"
 192                         set RESULT  $STF_FAIL
 193                 }
 194                 "*foo/good_$count * $type_array($count) * $good_array($count)*"
 195         }
 196 
 197         set count [ expr $count + 1 ]
 198 }
 199 
 200 exit $RESULT