Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Initial checkin with s390 CPU support patch

  • Loading branch information...
commit 10e32f077aaa73fe0ca85045f02b521749d1856b 1 parent ad32196
Matt Sanford authored November 07, 2012
72  CPU.pm
... ...
@@ -0,0 +1,72 @@
  1
+package Sys::CPU;
  2
+
  3
+use strict;
  4
+
  5
+use vars qw(@ISA %EXPORT_TAGS @EXPORT_OK $VERSION);
  6
+require Exporter;
  7
+require DynaLoader;
  8
+
  9
+our @ISA = qw(Exporter DynaLoader);
  10
+
  11
+# This allows declaration	use Sys::CPU ':all';
  12
+# If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
  13
+# will save memory.
  14
+our %EXPORT_TAGS = ( 'all' => [ qw(
  15
+	cpu_count
  16
+        cpu_clock
  17
+        cpu_type
  18
+) ] );
  19
+
  20
+our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
  21
+
  22
+our $VERSION = '0.52';
  23
+
  24
+bootstrap Sys::CPU $VERSION;
  25
+
  26
+# Preloaded methods go here.
  27
+
  28
+1;
  29
+__END__
  30
+# Below is stub documentation for your module. You better edit it!
  31
+
  32
+=head1 NAME
  33
+
  34
+Sys::CPU - Perl extension for getting CPU information. Currently only number of CPU's supported.
  35
+
  36
+=head1 SYNOPSIS
  37
+
  38
+  use Sys::CPU;
  39
+  
  40
+  $number_of_cpus = Sys::CPU::cpu_count();
  41
+  printf("I have %d CPU's\n",$number_of_cpus);
  42
+  print "  Speed : ",Sys::CPU::cpu_clock(),"\n";
  43
+  print "  Type  : ",Sys::CPU::cpu_type(),"\n";
  44
+
  45
+=head1 DESCRIPTION
  46
+
  47
+In responce to a post on perlmonks.org, a module for counting the number of CPU's on a 
  48
+system. Support has now also been added for type of CPU and clock speed. While much of the
  49
+code is from UNIX::Processors, win32 support has been added (but not tested).
  50
+
  51
+v0.45 - Corrected solaris support (Thanks Cloyce)
  52
+
  53
+=head2 EXPORT
  54
+
  55
+None by default.
  56
+
  57
+=head1 AUTHOR
  58
+
  59
+MZSanford
  60
+
  61
+=head1 MAINTENANCE
  62
+
  63
+Marc Koderer
  64
+
  65
+=head1 LICENSE
  66
+
  67
+
  68
+=head1 SEE ALSO
  69
+
  70
+perl(1), sysconf(3)
  71
+
  72
+=cut
408  CPU.xs
... ...
@@ -0,0 +1,408 @@
  1
+#include "EXTERN.h"
  2
+#include "perl.h"
  3
+#include "XSUB.h"
  4
+#include <sys/types.h>
  5
+
  6
+/**************************************************************************************
  7
+* some of the code for the CPU information was copied and modilefied from             *
  8
+*  the source for Unix::Processors. All code contained herein in free to use and edit *
  9
+*  under the same licence as Perl itself.                                             *
  10
+*                                                                                     *
  11
+**************************************************************************************/
  12
+
  13
+#define MAX_IDENT_SIZE 256
  14
+#if defined(_WIN32) || defined(WIN32) 
  15
+  #define _have_cpu_type
  16
+  #define _have_cpu_clock
  17
+  #define WINDOWS
  18
+#endif
  19
+
  20
+#ifdef WINDOWS /* WINDOWS */
  21
+ #include <stdlib.h>
  22
+ #include <windows.h>                                  
  23
+ #include <winbase.h>
  24
+ #include <winreg.h>
  25
+#else                /* other (try unix) */
  26
+ #include <unistd.h>
  27
+ #include <sys/unistd.h>
  28
+#endif
  29
+#if defined(__sun) || defined(__sun__) 
  30
+ #include <sys/processor.h>
  31
+#endif
  32
+#ifdef _HPUX_SOURCE
  33
+ #include <pthread.h>
  34
+ #include <sys/pstat.h>
  35
+ #define _have_cpu_clock
  36
+ #define _have_cpu_type
  37
+#endif
  38
+#ifdef __APPLE__
  39
+ #include <sys/sysctl.h>
  40
+ #define _have_cpu_clock
  41
+ #define _have_cpu_type
  42
+#endif
  43
+#ifdef WINDOWS
  44
+/* Registry Functions */
  45
+
  46
+int GetSysInfoKey(char *key_name,char *output) {
  47
+	// Get values from registry, use REGEDIT to see how data is stored while sample is running
  48
+	int ret;
  49
+	HKEY hTestKey, hSubKey;
  50
+	DWORD dwRegType, dwBuffSize;
  51
+	 
  52
+	// Access using preferred 'Ex' functions
  53
+	if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Hardware\\Description\\System\\CentralProcessor", 0, KEY_READ,  &hTestKey) == ERROR_SUCCESS) {
  54
+		if (RegOpenKey(hTestKey, "0",  &hSubKey) == ERROR_SUCCESS) {
  55
+			dwBuffSize = MAX_IDENT_SIZE;
  56
+			ret = RegQueryValueEx(hSubKey, key_name, NULL,  &dwRegType,  output,  &dwBuffSize);
  57
+			if (ret != ERROR_SUCCESS) {
  58
+				sprintf(output,"Failed to get Value for key : %d\n",GetLastError());
  59
+				return(1);
  60
+			}
  61
+			RegCloseKey(hSubKey);
  62
+		} else {
  63
+			sprintf(output,"Failed to open sub-key : %d\n",GetLastError());
  64
+			return(1);
  65
+		}		 
  66
+		RegCloseKey(hTestKey);
  67
+	}
  68
+	else 
  69
+	{
  70
+		sprintf(output,"Failed to open test key : %d\n",GetLastError());
  71
+		return(1);
  72
+	}
  73
+	return(0);
  74
+}
  75
+
  76
+#endif /* WINDOWS */
  77
+
  78
+#ifdef _HPUX_SOURCE
  79
+
  80
+/*
  81
+ * HP specific function to return the clock-speed of a specified CPU in MHz.
  82
+ */
  83
+int proc_get_mhz(int id) {
  84
+    struct pst_processor st;
  85
+    int result = 0;
  86
+    if( !(result = pstat_getprocessor(&st, sizeof(st), (size_t)1, id)) ) {
  87
+
  88
+        /* Maybe the CPU id too high, so try for CPU 0, instead. */
  89
+        result = pstat_getprocessor(&st, sizeof(st), (size_t)1, 0);
  90
+    }
  91
+
  92
+    if( result ) {
  93
+        return st.psp_iticksperclktick * sysconf(_SC_CLK_TCK) / 1000000;
  94
+    }
  95
+
  96
+    /* Call failed - return 0 for unknown clock speed. */
  97
+    return 0;
  98
+}
  99
+
  100
+/*
  101
+ * Depending on your version of HP-UX, you may or may not already have these
  102
+ * but we need them, so make sure that they are defined.
  103
+ */
  104
+#ifndef CPU_PA_RISC1_0
  105
+#define CPU_PA_RISC1_0      0x20B    /* HP PA-RISC1.0 */
  106
+#endif
  107
+
  108
+#ifndef CPU_PA_RISC1_1
  109
+#define CPU_PA_RISC1_1      0x210    /* HP PA-RISC1.1 */
  110
+#endif
  111
+
  112
+#ifndef CPU_PA_RISC1_2
  113
+#define CPU_PA_RISC1_2      0x211    /* HP PA-RISC1.2 */
  114
+#endif
  115
+
  116
+#ifndef CPU_PA_RISC2_0
  117
+#define CPU_PA_RISC2_0      0x214    /* HP PA-RISC2.0 */
  118
+#endif
  119
+
  120
+#ifndef CPU_PA_RISC_MAX
  121
+#define CPU_PA_RISC_MAX     0x2FF    /* Maximum for HP PA-RISC systems. */
  122
+#endif
  123
+
  124
+#ifndef CPU_IA64_ARCHREV_0
  125
+#define CPU_IA64_ARCHREV_0  0x300    /* IA-64 archrev 0 */
  126
+#endif
  127
+
  128
+const char *proc_get_type_name () {
  129
+    long cpuvers = sysconf(_SC_CPU_VERSION);
  130
+
  131
+    switch(cpuvers) {
  132
+        case CPU_PA_RISC1_0:
  133
+            return "HP PA-RISC1.0";
  134
+        case CPU_PA_RISC1_1:
  135
+            return "HP PA-RISC1.1";
  136
+        case CPU_PA_RISC1_2:
  137
+            return "HP PA-RISC1.2";
  138
+        case CPU_PA_RISC2_0:
  139
+            return "HP PA-RISC2.0";
  140
+        case CPU_IA64_ARCHREV_0:
  141
+            return "IA-64 archrev 0";
  142
+        default:
  143
+            if( CPU_IS_PA_RISC(cpuvers) ) {
  144
+	        return "HP PA-RISC";
  145
+	    }
  146
+    }
  147
+
  148
+    return "UNKNOWN HP-UX";
  149
+}
  150
+
  151
+#endif /* _HPUX_SOURCE */
  152
+
  153
+#ifdef __APPLE__
  154
+
  155
+#ifndef POWERPC_G3
  156
+#define POWERPC_G3 0xcee41549
  157
+#endif
  158
+
  159
+#ifndef POWERPC_G4
  160
+#define POWERPC_G4 0x77c184ae 
  161
+#endif
  162
+
  163
+#ifndef POWERPC_G5
  164
+#define POWERPC_G5 0xed76d8aa
  165
+#endif
  166
+
  167
+#ifndef INTEL_6_13 
  168
+#define INTEL_6_13 0xaa33392b 
  169
+#endif 
  170
+#ifndef ARM_9 
  171
+#define ARM_9 0xe73283ae 
  172
+#endif
  173
+
  174
+#ifndef ARM_11 
  175
+#define ARM_11 0x8ff620d8 
  176
+#endif
  177
+
  178
+#ifndef INTEL_PENRYN 
  179
+#define INTEL_PENRYN 0x78ea4fbc 
  180
+#endif
  181
+
  182
+#ifndef INTEL_NEHALEM 
  183
+#define INTEL_NEHALEM 0x6b5a4cd2 
  184
+#endif
  185
+
  186
+#ifndef INTEL_CORE 
  187
+#define INTEL_CORE 0x73d67300 
  188
+#endif
  189
+
  190
+#ifndef INTEL_CORE2 
  191
+#define INTEL_CORE2 0x426f69ef 
  192
+#endif
  193
+
  194
+char *apple_get_type_name() {
  195
+        int mib[2];
  196
+        size_t len=2;
  197
+	int kp;
  198
+        sysctlnametomib ("hw.cpufamily", mib, &len);
  199
+	sysctl(mib, 2, NULL, &len, NULL, 0);
  200
+        sysctl(mib, 2, &kp, &len, NULL, 0);
  201
+   	switch (kp) {
  202
+                case POWERPC_G3:            
  203
+                   return "POWERPC_G3";
  204
+                case POWERPC_G4:
  205
+                   return "POWERPC_G4";
  206
+                case POWERPC_G5:
  207
+                   return "POWERPC_G5";
  208
+                case INTEL_6_13:
  209
+                   return "INTEL_6_13";
  210
+                case ARM_9:
  211
+                   return "ARM_9";
  212
+                case ARM_11:
  213
+                   return "ARM_11";
  214
+                case INTEL_PENRYN:
  215
+                   return "INTEL_PENRYN";                
  216
+                case INTEL_NEHALEM:
  217
+                   return "INTEL_NEHALEM";               
  218
+                case INTEL_CORE:
  219
+                   return "INTEL_CORE";
  220
+                case INTEL_CORE2:
  221
+                   return "INTEL_CORE2";
  222
+		default:
  223
+                    return "UNKNOWN"; 
  224
+        }
  225
+}
  226
+#endif /* __APPLE__ */
  227
+/* the following few functions were shamlessly taken from UNIX::Processors *
  228
+ * to make this linux compatable. No linux machine to test on, so had to   *
  229
+ * use existing code                                                       */
  230
+
  231
+#ifdef __linux__
  232
+
  233
+#define _have_cpu_type
  234
+#define _have_cpu_clock
  235
+
  236
+/* Return string from a field of /proc/cpuinfo, NULL if not found */
  237
+/* Comparison is case insensitive */
  238
+char *proc_cpuinfo_field (const char *field) {
  239
+    FILE *fp;
  240
+    static char line[1000];
  241
+    int len = strlen(field);
  242
+    char *result = NULL;
  243
+    if (NULL!=(fp = fopen ("/proc/cpuinfo", "r"))) {
  244
+	while (!feof(fp) && result==NULL) {
  245
+	    fgets (line, 990, fp);
  246
+	    if (0==strncasecmp (field, line, len)) {
  247
+		char *loc = strchr (line, ':');
  248
+		if (loc) {
  249
+		    result = loc+2;
  250
+		    loc = strchr (result, '\n');
  251
+		    if (loc) *loc = '\0';
  252
+		}
  253
+	    }
  254
+	}
  255
+	fclose(fp);
  256
+    }
  257
+    return (result);
  258
+}
  259
+
  260
+/* Return clock frequency */
  261
+int proc_cpuinfo_clock (void) {
  262
+    char *value;
  263
+    value = proc_cpuinfo_field ("cpu MHz");
  264
+    if (value) return (atoi(value));
  265
+    value = proc_cpuinfo_field ("clock");
  266
+    if (value) return (atoi(value));
  267
+    value = proc_cpuinfo_field ("bogomips");
  268
+    if (value) return (atoi(value));
  269
+    return (0);
  270
+}
  271
+
  272
+#ifdef __s390__ || __s390x__
  273
+
  274
+/* Return machine value from s390 processor line, NULL if not found */
  275
+char *processor_machine_field (char *processor) {
  276
+    char *machine = NULL;
  277
+    if (NULL == processor) {
  278
+      return NULL;
  279
+    }
  280
+    if (NULL != (machine = strstr(processor, "machine = "))) {
  281
+      machine += 10;
  282
+    }
  283
+    return machine;
  284
+}
  285
+#endif
  286
+
  287
+#endif
  288
+
  289
+int get_cpu_count() {
  290
+    int ret;
  291
+    char buffer[255];
  292
+    char *p = buffer;
  293
+
  294
+#ifdef WINDOWS /* WINDOWS */                                  
  295
+   SYSTEM_INFO info;                                                         
  296
+                                                       
  297
+   GetSystemInfo(&info);                              
  298
+   ret = info.dwNumberOfProcessors;                  
  299
+#else               /*other (try *nix)*/
  300
+#ifdef _HPUX_SOURCE /* HP-UX */
  301
+    ret = pthread_num_processors_np();
  302
+#else               /*other unix - try sysconf*/
  303
+    ret = (int )sysconf(_SC_NPROCESSORS_ONLN);
  304
+#endif  /* HP-UX */
  305
+#endif  /* WINDOWS */
  306
+    return ret;
  307
+}
  308
+MODULE = Sys::CPU		PACKAGE = Sys::CPU		
  309
+
  310
+int
  311
+cpu_count()
  312
+CODE:
  313
+{
  314
+    int i = 0;
  315
+    i = get_cpu_count();
  316
+    if (i) {
  317
+	    ST(0) = sv_newmortal();
  318
+	    sv_setiv (ST(0), i);
  319
+    } else {
  320
+	    ST(0) = &PL_sv_undef;
  321
+    }   
  322
+}
  323
+
  324
+
  325
+int
  326
+cpu_clock()
  327
+CODE:
  328
+{
  329
+    int clock = 0;
  330
+    int retcode = 0;
  331
+#ifdef __linux__
  332
+    int value = proc_cpuinfo_clock();
  333
+    if (value) clock = value;
  334
+#endif
  335
+#ifdef WINDOWS
  336
+    char *clock_str = malloc(MAX_IDENT_SIZE); 
  337
+    /*!! untested !!*/
  338
+    retcode = GetSysInfoKey("~MHz",clock_str);
  339
+    if (retcode != 0) {
  340
+        clock = 0;
  341
+    } else {
  342
+        clock = atoi(clock_str);
  343
+    }     
  344
+#endif /* not linux, not windows, not hpux */
  345
+#ifdef _HPUX_SOURCE
  346
+    /* Try to get the clock speed for processor 0 - assume all the same. */
  347
+    clock = proc_get_mhz(0);
  348
+#endif
  349
+#ifdef __APPLE__
  350
+    clock = CurrentProcessorSpeed();
  351
+#endif
  352
+#ifndef _have_cpu_clock
  353
+    processor_info_t info, *infop=&info;
  354
+    if ( processor_info(0, infop) == 0 && infop->pi_state == P_ONLINE) {
  355
+        if (clock < infop->pi_clock) {
  356
+            clock = infop->pi_clock;
  357
+        }
  358
+    }
  359
+#endif
  360
+    if (clock) {
  361
+	    ST(0) = sv_newmortal();
  362
+	    sv_setiv (ST(0), clock);
  363
+    } else {
  364
+	    ST(0) = &PL_sv_undef;
  365
+    }   
  366
+}
  367
+
  368
+SV *
  369
+cpu_type()
  370
+CODE:
  371
+{
  372
+    char *value = NULL;
  373
+    int retcode = 0;
  374
+#ifdef __linux__
  375
+#ifdef __s390__ || __s390x__
  376
+    value = processor_machine_field (proc_cpuinfo_field ("processor") );
  377
+#endif
  378
+    if (!value) value = proc_cpuinfo_field ("model name");
  379
+    if (!value) value = proc_cpuinfo_field ("machine");
  380
+    if (!value) value = proc_cpuinfo_field ("vendor_id");
  381
+#endif
  382
+#ifdef WINDOWS
  383
+    retcode = GetSysInfoKey("Identifier",value);
  384
+    if (retcode != 0) {
  385
+        value = NULL;
  386
+    }                                                                           
  387
+#endif 
  388
+#ifdef _HPUX_SOURCE
  389
+    value = proc_get_type_name();
  390
+#endif
  391
+#ifdef __APPLE__
  392
+    value = apple_get_type_name();
  393
+#endif
  394
+#ifndef _have_cpu_type  /* not linux, not windows */
  395
+    processor_info_t info, *infop=&info;
  396
+    if (processor_info (0, infop)==0) {
  397
+	value = infop->pi_processor_type;
  398
+    }
  399
+#endif
  400
+    if (value) {
  401
+	    ST(0) = sv_newmortal();
  402
+	    sv_setpv (ST(0), value);
  403
+    } else {
  404
+	    ST(0) = &PL_sv_undef;
  405
+    }
  406
+}
  407
+
  408
+
37  Changes
... ...
@@ -0,0 +1,37 @@
  1
+Revision history for Perl extension Sys::CPU.
  2
+
  3
+0.01  Wed Jun 27 16:43:58 2001
  4
+	- original version; created by h2xs 1.20 with options -A -n Sys::CPU
  5
+
  6
+0.10
  7
+        - Added cpu_type and cpu_clock functions
  8
+        - Changed to better win32 suppport (untested)
  9
+
  10
+0.20
  11
+        - Fixed linux support
  12
+
  13
+0.25
  14
+        - Fixed dist tar problem
  15
+                
  16
+0.30
  17
+        - Fixed win32 supprot to work with Windows 2000 (thanks Gary)
  18
+        - Changed interface to eliminate cpu numbers
  19
+
  20
+0.35
  21
+        - Fixed linux support (thanks Peter)
  22
+
  23
+0.40
  24
+        - Fixed HP-UX support (thanks Brett Gersekowski)
  25
+
  26
+0.45
  27
+        - Fixed Solaris support
  28
+
  29
+0.50
  30
+        - Fixed Darwin/Mac Os support (Marc Koderer)
  31
+
  32
+0.51
  33
+	- Fixed hidden mac os files
  34
+
  35
+0.52
  36
+	- fixed bug 50933 and 25253
  37
+        - added licence info (Fedora bug 585336)
8  MANIFEST
... ...
@@ -0,0 +1,8 @@
  1
+CPU.pm
  2
+CPU.xs
  3
+Changes
  4
+MANIFEST
  5
+Makefile.PL
  6
+t/Sys-CPU.t
  7
+README
  8
+META.yml                                 Module meta-data (added by MakeMaker)
16  Makefile.PL
... ...
@@ -0,0 +1,16 @@
  1
+use ExtUtils::MakeMaker;
  2
+# See lib/ExtUtils/MakeMaker.pm for details of how to influence
  3
+# the contents of the Makefile that is written.
  4
+if ($^O eq 'darwin'){
  5
+	$extra_arg = '-framework Carbon';
  6
+}
  7
+
  8
+
  9
+WriteMakefile(
  10
+    'NAME'		=> 'Sys::CPU',
  11
+    'VERSION_FROM'      => 'CPU.pm',
  12
+    'LIBS'		=> [''], # e.g., '-lm'
  13
+    'DEFINE'		=> '', # e.g., '-DHAVE_SOMETHING'
  14
+    'INC'		=> '', # e.g., '-I/usr/include/other'
  15
+    'dynamic_lib'       => {OTHERLDFLAGS => $extra_arg},
  16
+);
77  README
... ...
@@ -0,0 +1,77 @@
  1
+Sys::CPU is Copyright (c) 2001-2010, MZSanford
  2
+
  3
+This module is free software; you
  4
+can redistribute it and/or modify it under the same terms
  5
+as Perl itself. For more details, see the full text of the
  6
+licenses in the directory LICENSES.
  7
+
  8
+NAME
  9
+    Sys::CPU - Perl extension for getting CPU information. Currently only
  10
+    number of CPU's supported.
  11
+
  12
+SYNOPSIS
  13
+      use Sys::CPU;
  14
+  
  15
+      $number_of_cpus = Sys::CPU::cpu_count();
  16
+      printf("I have %d CPU's\n",$number_of_cpus);
  17
+      print "  Speed : ",Sys::CPU::cpu_clock(),"\n";
  18
+      print "  Type  : ",Sys::CPU::cpu_type(),"\n";
  19
+
  20
+DESCRIPTION
  21
+    In responce to a post on perlmonks.org, a module for counting the number
  22
+    of CPU's on a system. Support has now also been added for type of CPU
  23
+    and clock speed. While much of the code is from UNIX::Processors, win32
  24
+    support has been added (but not tested).
  25
+
  26
+  EXPORT
  27
+
  28
+    None by default.
  29
+
  30
+AUTHOR
  31
+    MZSanford
  32
+MAINTENANCE
  33
+    Marc Koderer
  34
+
  35
+
  36
+SEE ALSO
  37
+    perl(1), sysconf(3)
  38
+
  39
+CHANGES
  40
+
  41
+Revision history for Perl extension Sys::CPU.
  42
+
  43
+0.01  Wed Jun 27 16:43:58 2001
  44
+	- original version; created by h2xs 1.20 with options -A -n Sys::CPU
  45
+
  46
+0.10
  47
+        - Added cpu_type and cpu_clock functions
  48
+        - Changed to better win32 suppport (untested)
  49
+
  50
+0.20
  51
+        - Fixed linux support
  52
+
  53
+0.25
  54
+        - Fixed dist tar problem
  55
+                
  56
+0.30
  57
+        - Fixed win32 supprot to work with Windows 2000 (thanks Gary)
  58
+        - Changed interface to eliminate cpu numbers
  59
+
  60
+0.35
  61
+        - Fixed linux support (thanks Peter)
  62
+
  63
+0.40
  64
+        - Fixed HP-UX support (thanks Brett Gersekowski)
  65
+
  66
+0.45
  67
+        - Fixed Solaris support
  68
+
  69
+0.50
  70
+        - Fixed Darwin/Mac Os support (Marc Koderer)
  71
+
  72
+0.51
  73
+	- Fixed hidden mac os files
  74
+
  75
+0.52
  76
+	- fixed bug 50933 and 25253
  77
+        - Added licence info (Fedora bug 585336)
4  README.md
Source Rendered
... ...
@@ -1,4 +0,0 @@
1  
-perl-sys-cpu
2  
-============
3  
-
4  
-Perl module for getting information about the system CPU (Sys::CPU). Maintenance Only.
43  t/Sys-CPU.t
... ...
@@ -0,0 +1,43 @@
  1
+# Before `make install' is performed this script should be runnable with
  2
+# `make test'. After `make install' it should work as `perl test.pl'
  3
+
  4
+######################### We start with some black magic to print on failure.
  5
+
  6
+# Change 1..1 below to 1..last_test_to_print .
  7
+# (It may become useful if the test is moved to ./t subdirectory.)
  8
+
  9
+BEGIN { $| = 1; print "1..4\n"; }
  10
+END {print "not ok 1\n" unless $loaded;}
  11
+use Sys::CPU;
  12
+$loaded = 1;
  13
+print "ok 1\n";
  14
+
  15
+$number = &Sys::CPU::cpu_count();
  16
+if (defined($number)) {
  17
+    print "ok 2 (CPU Count : $number)\n";
  18
+} else {
  19
+    print "not ok 2 (cpu_count failed)\n";
  20
+}
  21
+
  22
+$speed = &Sys::CPU::cpu_clock();
  23
+if (defined($speed)) {
  24
+    print "ok 3 (CPU Speed : $speed)\n";
  25
+} elsif ( $^O eq 'MSWin32'){
  26
+    print "ok 3 (CPU Speed: test skipped on MSWin32)\n";
  27
+} else  {
  28
+    print "not ok 3 (cpu_clock undefined (ok if Win9x))\n";
  29
+}
  30
+
  31
+$type = &Sys::CPU::cpu_type();
  32
+if (defined($type)) {
  33
+    print "ok 4 (CPU Type  : $type)\n";
  34
+} else {
  35
+    print "not ok 5 (cpu_type unavailable)\n";
  36
+}
  37
+
  38
+######################### End of black magic.
  39
+
  40
+# Insert your test code below (better if it prints "ok 13"
  41
+# (correspondingly "not ok 13") depending on the success of chunk 13
  42
+# of the test code):
  43
+

0 notes on commit 10e32f0

Please sign in to comment.
Something went wrong with that request. Please try again.