2 # Copyright 2005 Sun Microsystems, Inc. All rights reserved.
3 # Use is subject to license terms.
7 # The contents of this file are subject to the terms of the
8 # Common Development and Distribution License, Version 1.0 only
9 # (the "License"). You may not use this file except in compliance
12 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
13 # or http://www.opensolaris.org/os/licensing.
14 # See the License for the specific language governing permissions
15 # and limitations under the License.
17 # When distributing Covered Code, include this CDDL HEADER in each
18 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
19 # If applicable, add the following below this CDDL HEADER, with the
20 # fields enclosed by brackets "[]" replaced with your own identifying
21 # information: Portions Copyright [yyyy] [name of copyright owner]
25 #ident "%Z%%M% %I% %E% SMI"
27 # test script for Sun::Solaris::Kstat
32 # Visit all the leaf nodes -
33 # will generate a die if there are any structure mismatches
37 foreach my $m (sort(keys(%$ks))) {
38 foreach my $i (sort(keys(%{$ks->{$m}}))) {
39 foreach my $n (sort(keys(%{$ks->{$m}->{$i}}))) {
41 keys(%{$ks->{$m}->{$i}->{$n}}))) {
42 my $v = $ks->{$m}->{$i}->{$n}->{$k};
50 BEGIN { $| = 1; print "1..15\n"; }
52 END {print "not ok 1\n" unless $loaded;}
53 use Sun::Solaris::Kstat;
57 # Check we can create a Kstat object OK
60 if (! eval { $ks = Sun::Solaris::Kstat->new() }) {
61 print("not ok $test: $@");
67 # Check FIRSTKEY/NEXTKEY/FETCH and for structure mismatches
68 if (! eval { visit_all($ks) }) {
69 print("not ok $test: $@");
76 my $cpu = (keys(%{$ks->{cpu_info}}))[0];
77 my $cpu_info = "cpu_info$cpu";
80 if (exists($ks->{cpu_info}{$cpu}{$cpu_info}{state})) {
83 print("not ok $test\n");
88 my $val = delete($ks->{cpu_info}{$cpu}{$cpu_info}{state});
89 if (defined($val) && ($val =~ /^on-line/ || $val =~ /^off-line/)) {
92 print("not ok $test ($val)\n");
96 # 5.004_04 has a broken hv_delete
103 if (! exists($ks->{cpu_info}{$cpu}{$cpu_info}{state})) {
106 print("not ok $test\n");
109 $val = $ks->{cpu_info}{$cpu}{$cpu_info}{state};
110 if (! defined($val)) {
113 print("not ok $test\n");
119 $ks->{cpu_info}{$cpu}{$cpu_info}{state} = "california";
120 if ($ks->{cpu_info}{$cpu}{$cpu_info}{state} eq "california") {
123 print("not ok $test\n");
128 my @bvals = sort(keys(%{$ks->{cpu_info}{$cpu}{$cpu_info}}));
129 %{$ks->{cpu_info}{$cpu}{$cpu_info}} = ();
130 my @avals = sort(keys(%{$ks->{cpu_info}{$cpu}{$cpu_info}}));
131 while (@bvals || @avals) {
132 my $a = shift(@avals);
133 my $b = shift(@bvals);
134 if ($a ne $b) { print("not ok $test ($a ne $b)\n"); last; }
136 print("ok $test\n") if (! @avals && ! @bvals);
140 if (! defined(eval { $ks->update() })) {
141 print("not ok $test: $@");
147 # Check readonly-ness of hash structure
148 eval { $ks->{cpu_info}{$cpu}{$cpu_info} = {}; };
149 print($@ =~ /^Modification of a read-only/i ? "ok $test\n" : "not ok $test\n");
152 eval { $ks->{cpu_info}{$cpu} = {}; };
153 print($@ =~ /^Modification of a read-only/i ? "ok $test\n" : "not ok $test\n");
156 eval { $ks->{cpu_info} = {}; };
157 print($@ =~ /^Modification of a read-only/i ? "ok $test\n" : "not ok $test\n");
161 my $then = $ks->{cpu_info}{$cpu}{$cpu_info}{snaptime};
163 if (! defined(eval { $ks->update() })) {
164 print("not ok $test: $@");
169 my $interval = $ks->{cpu_info}{$cpu}{$cpu_info}{snaptime} - $then;
170 if ($interval >= 2.5 && $interval <= 3.5) {
173 print("not ok $test\n");