1#!perl 2# Copyright (C) 2008-2014, Parrot Foundation. 3 4# initial work by Brad Gilbert b2gills <at> gmail <dot> com 5 6use strict; 7use warnings; 8use lib qw( . lib ../lib ../../lib ); 9 10use Test::More; 11use Config; 12 13use Parrot::Test tests => 17; 14use Parrot::Config; 15 16 17=head1 NAME 18 19t/op/sysinfo.t - System Info 20 21=head1 SYNOPSIS 22 23 % prove t/op/sysinfo.t 24 25=head1 DESCRIPTION 26 27Tests for basic system information. 28 29=over 4 30 31=item 1 The size of a platform integer 32 33=item 2 The size of a platform float 34 35=item 3 The size of a platform pointer. (Largest possible data pointer) 36 37=item 4 The OS name 38 39=item 5 The OS version string 40 41=item 6 The OS version number string 42 43=item 7 The CPU architecture 44 45=item 8 The CPU model 46 47=item 9, 10 The min and max INTVAL values 48 49=back 50 51=cut 52 53#define PARROT_INTSIZE 16 54#define PARROT_FLOATSIZE 17 55#define PARROT_POINTERSIZE 18 56#define PARROT_OS 30 57#define PARROT_OS_VERSION 31 58#define PARROT_OS_VERSION_NUMBER 32 59#define CPU_ARCH 33 60#define CPU_TYPE 34 61#define PARROT_INTMAX 19 62#define PARROT_INTMIN 20 63 64my @setup = ( 65 { pconfig_key => 'intvalsize', 66 pasm_key => 16, 67 pir_key => 'SYSINFO_PARROT_INTSIZE', 68 desc => 'integer size', 69 reg_type => 'I', 70 }, 71 { pconfig_key => 'numvalsize', 72 pasm_key => 17, 73 pir_key => 'SYSINFO_PARROT_FLOATSIZE', 74 desc => 'float size', 75 reg_type => 'I', 76 }, 77 { pconfig_key => 'ptrsize', 78 pasm_key => 18, 79 pir_key => 'SYSINFO_PARROT_POINTERSIZE', 80 desc => 'pointer size', 81 reg_type => 'I', 82 }, 83 { pconfig_key => 'osname', 84 pasm_key => 30, 85 pir_key => 'SYSINFO_PARROT_OS', 86 desc => 'osname', 87 reg_type => 'S', 88 }, 89 { pconfig_key => 'cpuarch', 90 pasm_key => 33, 91 pir_key => 'SYSINFO_CPU_ARCH', 92 desc => 'CPU Arch Family', 93 reg_type => 'S', 94 }, 95 { pconfig_key => 'cputype', 96 pasm_key => 34, 97 pir_key => 'SYSINFO_CPU_TYPE', 98 desc => 'CPU Model', 99 reg_type => 'S', 100 }, 101); 102 103foreach ( @setup ) { 104 if ( $_->{reg_type} eq 'I' ) { 105 pasm_output_is( <<"CODE", "$PConfig{$_->{pconfig_key}}$PConfig{$_->{pconfig_key}}\n", "PASM sysinfo $_->{desc}" ); 106 .pcc_sub :main main: 107 .loadlib 'sys_ops' 108 sysinfo_i_ic I1, $_->{pasm_key} 109 print I1 110 set I3, $_->{pasm_key} 111 sysinfo_i_i I2, I3 112 say I2 113end 114CODE 115 pir_output_is( <<"CODE", "$PConfig{$_->{pconfig_key}}$PConfig{$_->{pconfig_key}}\n", "PIR sysinfo $_->{desc}" ); 116.loadlib 'sys_ops' 117.include 'sysinfo.pasm' 118.sub main :main 119 \$I0 = sysinfo .$_->{pir_key} 120 print \$I0 121 \$I3 = .$_->{pir_key} 122 \$I2 = sysinfo \$I3 123 say \$I2 124.end 125CODE 126 } 127 else { 128 pasm_output_is( <<"CODE", "$PConfig{$_->{pconfig_key}}$PConfig{$_->{pconfig_key}}\n", "PASM sysinfo $_->{desc}" ); 129 .pcc_sub :main main: 130 .loadlib 'sys_ops' 131 sysinfo_s_ic S1, $_->{pasm_key} 132 print S1 133 set I1, $_->{pasm_key} 134 sysinfo_s_i S2, I1 135 say S2 136end 137CODE 138 pir_output_is( <<"CODE", "$PConfig{$_->{pconfig_key}}$PConfig{$_->{pconfig_key}}\n", "PIR sysinfo $_->{desc}" ); 139.loadlib 'sys_ops' 140.include 'sysinfo.pasm' 141.sub main :main 142 \$S0 = sysinfo .$_->{pir_key} 143 print \$S0 144 \$I1 = .$_->{pir_key} 145 \$S1 = sysinfo \$I1 146 say \$S1 147.end 148CODE 149 } 150} 151 152SKIP: 153{ 154 $PConfig{osname} eq 'MSWin32' 155 or skip "Tests only meaningful on Win32", 2; 156 SKIP: 157 { 158 eval { require Win32; } or 159 skip "requires package Win32 for these tests", 2; 160 161 my $osname = Win32::GetOSName(); 162 $osname = 'WinXP' if $osname =~ m/^WinXP/; 163 TODO: { 164 local $TODO = "Not Currently Implemented"; 165 pasm_output_is( <<'CODE', "$osname$osname\n", "sysinfo OS version string" ); 166 .pcc_sub :main main: 167 .loadlib 'sys_ops' 168 sysinfo_s_ic S1, 5 169 print S1 170 set I0, 5 171 sysinfo_s_i S2, 5 172 say S2 173end 174CODE 175 176 my ( $osvername, $major, $minor, $id ) = Win32::GetOSVersion(); 177 178 pasm_output_is( <<'CODE', "$major.$minor$major.$minor\n", "sysinfo OS version number string" ); 179 .pcc_sub :main main: 180 .loadlib 'sys_ops' 181 sysinfo_s_ic S1, 6 182 print S1 183 set I0, 6 184 sysinfo_s_i S2, 6 185 say S2 186end 187CODE 188 } # END todo block 189 } # END inner SKIP block 190} # END outer SKIP block 191 192# 9, 10 193 194SKIP: 195{ 196 skip 'Testing only in some known platforms', 1 197 unless $PConfig{osname} eq 'linux'; 198 199 pir_output_like( <<'CODE', '/^-[1-9][0-9]*\n[1-9][0-9]*\n-[1-9][0-9]*\n[1-9][0-9]*\n$/', 'INTVAL min and max values'); 200.loadlib 'sys_ops' 201.include 'sysinfo.pasm' 202.sub main :main 203 $I0 = sysinfo .SYSINFO_PARROT_INTMIN 204 say $I0 205 $I0 = sysinfo .SYSINFO_PARROT_INTMAX 206 say $I0 207 $I1 = .SYSINFO_PARROT_INTMIN 208 $I0 = sysinfo $I1 209 say $I0 210 $I1 = .SYSINFO_PARROT_INTMAX 211 $I0 = sysinfo $I1 212 say $I0 213.end 214CODE 215} 216 217pir_output_is(<<'CODE', <<OUTPUT, 'INTVAL min and max coherence'); 218.loadlib 'sys_ops' 219.include 'sysinfo.pasm' 220.sub 'main' :main 221 # assumes 2's compliment integer math 222 .include 'test_more.pir' 223 .local int min, max 224 max = sysinfo .SYSINFO_PARROT_INTMAX 225 neg max 226 min = sysinfo .SYSINFO_PARROT_INTMIN 227 inc min 228 is(max, min) 229.end 230CODE 231ok 1 232OUTPUT 233 234pir_output_is(<<'CODE', <<OUTPUT, 'bad sysinfo codes'); 235.loadlib 'sys_ops' 236.sub 'main' :main 237 $I0 = sysinfo -1 238 say $I0 239 240 $I1 = sysinfo $I0 241 say $I1 242.end 243CODE 244-1 245-1 246OUTPUT 247 248# Local Variables: 249# mode: cperl 250# cperl-indent-level: 4 251# fill-column: 100 252# End: 253# vim: expandtab shiftwidth=4: 254