1*29949e86Sstevel# 2*29949e86Sstevel# Copyright 2005 Sun Microsystems, Inc. All rights reserved. 3*29949e86Sstevel# Use is subject to license terms. 4*29949e86Sstevel# 5*29949e86Sstevel# CDDL HEADER START 6*29949e86Sstevel# 7*29949e86Sstevel# The contents of this file are subject to the terms of the 8*29949e86Sstevel# Common Development and Distribution License, Version 1.0 only 9*29949e86Sstevel# (the "License"). You may not use this file except in compliance 10*29949e86Sstevel# with the License. 11*29949e86Sstevel# 12*29949e86Sstevel# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 13*29949e86Sstevel# or http://www.opensolaris.org/os/licensing. 14*29949e86Sstevel# See the License for the specific language governing permissions 15*29949e86Sstevel# and limitations under the License. 16*29949e86Sstevel# 17*29949e86Sstevel# When distributing Covered Code, include this CDDL HEADER in each 18*29949e86Sstevel# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 19*29949e86Sstevel# If applicable, add the following below this CDDL HEADER, with the 20*29949e86Sstevel# fields enclosed by brackets "[]" replaced with your own identifying 21*29949e86Sstevel# information: Portions Copyright [yyyy] [name of copyright owner] 22*29949e86Sstevel# 23*29949e86Sstevel# CDDL HEADER END 24*29949e86Sstevel# 25*29949e86Sstevel#ident "%Z%%M% %I% %E% SMI" 26*29949e86Sstevel# 27*29949e86Sstevel# test script for Sun::Solaris::Kstat 28*29949e86Sstevel# 29*29949e86Sstevel 30*29949e86Ssteveluse strict; 31*29949e86Sstevel 32*29949e86Sstevel# Visit all the leaf nodes - 33*29949e86Sstevel# will generate a die if there are any structure mismatches 34*29949e86Sstevelsub visit_all($) 35*29949e86Sstevel{ 36*29949e86Sstevel my ($ks) = @_; 37*29949e86Sstevel foreach my $m (sort(keys(%$ks))) { 38*29949e86Sstevel foreach my $i (sort(keys(%{$ks->{$m}}))) { 39*29949e86Sstevel foreach my $n (sort(keys(%{$ks->{$m}->{$i}}))) { 40*29949e86Sstevel foreach my $k (sort( 41*29949e86Sstevel keys(%{$ks->{$m}->{$i}->{$n}}))) { 42*29949e86Sstevel my $v = $ks->{$m}->{$i}->{$n}->{$k}; 43*29949e86Sstevel } 44*29949e86Sstevel } 45*29949e86Sstevel } 46*29949e86Sstevel } 47*29949e86Sstevel return(1); 48*29949e86Sstevel} 49*29949e86Sstevel 50*29949e86SstevelBEGIN { $| = 1; print "1..15\n"; } 51*29949e86Sstevelmy $loaded; 52*29949e86SstevelEND {print "not ok 1\n" unless $loaded;} 53*29949e86Ssteveluse Sun::Solaris::Kstat; 54*29949e86Sstevel$loaded = 1; 55*29949e86Sstevelprint "ok 1\n"; 56*29949e86Sstevel 57*29949e86Sstevel# Check we can create a Kstat object OK 58*29949e86Sstevelmy ($test, $ks); 59*29949e86Sstevel$test = 2; 60*29949e86Sstevelif (! eval { $ks = Sun::Solaris::Kstat->new() }) { 61*29949e86Sstevel print("not ok $test: $@"); 62*29949e86Sstevel} else { 63*29949e86Sstevel print("ok $test\n"); 64*29949e86Sstevel} 65*29949e86Sstevel$test++; 66*29949e86Sstevel 67*29949e86Sstevel# Check FIRSTKEY/NEXTKEY/FETCH and for structure mismatches 68*29949e86Sstevelif (! eval { visit_all($ks) }) { 69*29949e86Sstevel print("not ok $test: $@"); 70*29949e86Sstevel} else { 71*29949e86Sstevel print("ok $test\n"); 72*29949e86Sstevel} 73*29949e86Sstevel$test++; 74*29949e86Sstevel 75*29949e86Sstevel# Find a cpu number 76*29949e86Sstevelmy $cpu = (keys(%{$ks->{cpu_info}}))[0]; 77*29949e86Sstevelmy $cpu_info = "cpu_info$cpu"; 78*29949e86Sstevel 79*29949e86Sstevel# Check EXISTS 80*29949e86Sstevelif (exists($ks->{cpu_info}{$cpu}{$cpu_info}{state})) { 81*29949e86Sstevel print("ok $test\n"); 82*29949e86Sstevel} else { 83*29949e86Sstevel print("not ok $test\n"); 84*29949e86Sstevel} 85*29949e86Sstevel$test++; 86*29949e86Sstevel 87*29949e86Sstevel# Check DELETE 88*29949e86Sstevelmy $val = delete($ks->{cpu_info}{$cpu}{$cpu_info}{state}); 89*29949e86Sstevelif (defined($val) && ($val =~ /^on-line/ || $val =~ /^off-line/)) { 90*29949e86Sstevel print("ok $test\n"); 91*29949e86Sstevel} else { 92*29949e86Sstevel print("not ok $test ($val)\n"); 93*29949e86Sstevel} 94*29949e86Sstevel$test++; 95*29949e86Sstevel 96*29949e86Sstevel# 5.004_04 has a broken hv_delete 97*29949e86Sstevelif ($] < 5.00405) { 98*29949e86Sstevel print("ok $test\n"); 99*29949e86Sstevel $test++; 100*29949e86Sstevel print("ok $test\n"); 101*29949e86Sstevel $test++; 102*29949e86Sstevel} else { 103*29949e86Sstevel if (! exists($ks->{cpu_info}{$cpu}{$cpu_info}{state})) { 104*29949e86Sstevel print("ok $test\n"); 105*29949e86Sstevel } else { 106*29949e86Sstevel print("not ok $test\n"); 107*29949e86Sstevel } 108*29949e86Sstevel $test++; 109*29949e86Sstevel $val = $ks->{cpu_info}{$cpu}{$cpu_info}{state}; 110*29949e86Sstevel if (! defined($val)) { 111*29949e86Sstevel print("ok $test\n"); 112*29949e86Sstevel } else { 113*29949e86Sstevel print("not ok $test\n"); 114*29949e86Sstevel } 115*29949e86Sstevel $test++; 116*29949e86Sstevel} 117*29949e86Sstevel 118*29949e86Sstevel# Check STORE 119*29949e86Sstevel$ks->{cpu_info}{$cpu}{$cpu_info}{state} = "california"; 120*29949e86Sstevelif ($ks->{cpu_info}{$cpu}{$cpu_info}{state} eq "california") { 121*29949e86Sstevel print("ok $test\n"); 122*29949e86Sstevel} else { 123*29949e86Sstevel print("not ok $test\n"); 124*29949e86Sstevel} 125*29949e86Sstevel$test++; 126*29949e86Sstevel 127*29949e86Sstevel# Check CLEAR 128*29949e86Sstevelmy @bvals = sort(keys(%{$ks->{cpu_info}{$cpu}{$cpu_info}})); 129*29949e86Sstevel%{$ks->{cpu_info}{$cpu}{$cpu_info}} = (); 130*29949e86Sstevelmy @avals = sort(keys(%{$ks->{cpu_info}{$cpu}{$cpu_info}})); 131*29949e86Sstevelwhile (@bvals || @avals) { 132*29949e86Sstevel my $a = shift(@avals); 133*29949e86Sstevel my $b = shift(@bvals); 134*29949e86Sstevel if ($a ne $b) { print("not ok $test ($a ne $b)\n"); last; } 135*29949e86Sstevel} 136*29949e86Sstevelprint("ok $test\n") if (! @avals && ! @bvals); 137*29949e86Sstevel$test++; 138*29949e86Sstevel 139*29949e86Sstevel# Check updates 140*29949e86Sstevelif (! defined(eval { $ks->update() })) { 141*29949e86Sstevel print("not ok $test: $@"); 142*29949e86Sstevel} else { 143*29949e86Sstevel print("ok $test\n"); 144*29949e86Sstevel} 145*29949e86Sstevel$test++; 146*29949e86Sstevel 147*29949e86Sstevel# Check readonly-ness of hash structure 148*29949e86Ssteveleval { $ks->{cpu_info}{$cpu}{$cpu_info} = {}; }; 149*29949e86Sstevelprint($@ =~ /^Modification of a read-only/i ? "ok $test\n" : "not ok $test\n"); 150*29949e86Sstevel$test++; 151*29949e86Sstevel 152*29949e86Ssteveleval { $ks->{cpu_info}{$cpu} = {}; }; 153*29949e86Sstevelprint($@ =~ /^Modification of a read-only/i ? "ok $test\n" : "not ok $test\n"); 154*29949e86Sstevel$test++; 155*29949e86Sstevel 156*29949e86Ssteveleval { $ks->{cpu_info} = {}; }; 157*29949e86Sstevelprint($@ =~ /^Modification of a read-only/i ? "ok $test\n" : "not ok $test\n"); 158*29949e86Sstevel$test++; 159*29949e86Sstevel 160*29949e86Sstevel# Check timestamps 161*29949e86Sstevelmy $then = $ks->{cpu_info}{$cpu}{$cpu_info}{snaptime}; 162*29949e86Sstevelsleep(3); 163*29949e86Sstevelif (! defined(eval { $ks->update() })) { 164*29949e86Sstevel print("not ok $test: $@"); 165*29949e86Sstevel} else { 166*29949e86Sstevel print("ok $test\n"); 167*29949e86Sstevel} 168*29949e86Sstevel$test++; 169*29949e86Sstevelmy $interval = $ks->{cpu_info}{$cpu}{$cpu_info}{snaptime} - $then; 170*29949e86Sstevelif ($interval >= 2.5 && $interval <= 3.5) { 171*29949e86Sstevel print("ok $test\n"); 172*29949e86Sstevel} else { 173*29949e86Sstevel print("not ok $test\n"); 174*29949e86Sstevel} 175*29949e86Sstevel$test++; 176*29949e86Sstevel 177*29949e86Sstevelexit(0); 178