Skip to content
Snippets Groups Projects
Commit 133bbc89 authored by Tibo's avatar Tibo
Browse files

freebsd : extract vCores from cpu-dmi

parent a0b93e40
No related branches found
No related tags found
No related merge requests found
Pipeline #19793 passed
<?php
namespace App\Sensor;
use App\SensorConfig;
use App\ServerInfo;
/**
* Description of ServerInfoCPU
*
* @author tibo
*/
class ServerInfoFreeBSDCPU extends ServerInfoParser
{
public function analyzeString(string $string, ServerInfo $info)
{
// count the number of vCores
$REGEX = "/^ Thread Count: (\d+)/m";
$count = 0;
$matches = [];
$cpuinfo = $info->cpuinfo;
preg_match_all($REGEX, $string, $matches);
var_dump($matches);
foreach ($matches[1] as $match) {
$count += $match[0];
}
$cpuinfo["threads"] = $count;
$info->cpuinfo = $cpuinfo;
}
public function config(): SensorConfig
{
return new SensorConfig("ServerInfoFreeBSDCPU", "cpu-dmi");
}
}
<?php
namespace Tests\Unit;
use App\ServerInfoParser;
/**
* Description of ServerInfoParserTest
*
* @author tibo
*/
class ServerInfoParserTest
{
public function testMeminfo()
{
$string = file_get_contents(__DIR__ . "/meminfo");
$mem_total = (new ServerInfoParser())->parseMeminfo($string);
$this->assertEquals("15954328", $mem_total);
}
/**
* @group cpuinfo
*/
public function testCpuinfo()
{
$string = file_get_contents(__DIR__ . "/cpuinfo");
$cpuinfo = (new ServerInfoParser())->parseCpuinfo($string);
$this->assertEquals(8, $cpuinfo["threads"]);
$this->assertEquals("Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz", $cpuinfo["cpu"]);
}
/**
* @group cpuinfo
*/
public function testCpuinfoRaspberry()
{
$string = file_get_contents(__DIR__ . "/cpuinfo-raspberry");
$cpuinfo = (new ServerInfoParser())->parseCpuinfo($string);
$this->assertEquals(4, $cpuinfo["threads"]);
$this->assertEquals("Raspberry Pi 4 Model B Rev 1.1", $cpuinfo["cpu"]);
}
/**
* @group cpuinfo
*/
public function testCpuinfoSingleCPU()
{
$string = file_get_contents(__DIR__ . "/cpuinfo_1cpu");
$cpuinfo = (new ServerInfoParser())->parseCpuinfo($string);
$this->assertEquals(1, $cpuinfo["threads"]);
$this->assertEquals("Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz", $cpuinfo["cpu"]);
}
/**
* @group uptime
*/
public function testUptime()
{
$string = "24439.45 190434.65";
$uptime = (new ServerInfoParser())->parseUptime($string);
$this->assertEquals("6 hours", $uptime);
}
public function testUUID()
{
$uuid = (new ServerInfoParser())->parseUUID(file_get_contents(__DIR__ . "/system"));
$this->assertEquals("74F7C34C-2924-11B2-A85C-DC427DCA7109", $uuid);
}
public function testManufacturer()
{
$string = file_get_contents(__DIR__ . "/system");
$manufacturer = (new ServerInfoParser())->parseManufacturer($string);
$this->assertEquals("LENOVO", $manufacturer);
}
public function testProductName()
{
$string = file_get_contents(__DIR__ . "/system");
$manufacturer = (new ServerInfoParser())->parseProductName($string);
$this->assertEquals("20J60018MB", $manufacturer);
}
}
......@@ -3,6 +3,8 @@
namespace Tests\Unit;
use App\Sensor\MemoryTypes;
use App\ServerInfo;
use App\Sensor\ServerInfoFreeBSDCPU;
use Tests\TestCase;
......@@ -12,10 +14,9 @@ use Tests\TestCase;
* @group memory
* @author tibo
*/
class MemoryTest extends TestCase
class ServerinfoTest extends TestCase
{
/**
* @group ifconfig
* @group sensors
*/
public function testMemoryTypes()
......@@ -23,6 +24,22 @@ class MemoryTest extends TestCase
$string = file_get_contents(__DIR__ . "/memory-dmi");
$sensor = new MemoryTypes();
var_dump($sensor->parse($string));
$dims = $sensor->parse($string);
$this->assertEquals(4, count($dims));
$this->assertEquals(32, $dims[0]->size);
}
/**
* @group freebsd
* @group cpu
* @group freebsd-cpu
*/
public function testThreadsFreeBSD()
{
$string = file_get_contents(__DIR__ . "/freebsd-dmi-cpu");
$sensor = new ServerInfoFreeBSDCPU();
$info = new ServerInfo();
$sensor->analyzeString($string, $info);
$this->assertEquals(4, $info->vCores());
}
}
# dmidecode 3.6
# SMBIOS entry point at 0x75cc4000
Found SMBIOS entry point in EFI, reading table from /dev/mem.
SMBIOS 3.5 present.
Handle 0x004A, DMI type 4, 48 bytes
Processor Information
Socket Designation: U3E1
Type: Central Processor
Family: Other
Manufacturer: Intel(R) Corporation
ID: E0 06 0B 00 FF FB EB BF
Version: Intel(R) N100
Voltage: 1.0 V
External Clock: 100 MHz
Max Speed: 3400 MHz
Current Speed: 2871 MHz
Status: Populated, Enabled
Upgrade: Other
L1 Cache Handle: 0x0047
L2 Cache Handle: 0x0048
L3 Cache Handle: 0x0049
Serial Number: To Be Filled By O.E.M.
Asset Tag: To Be Filled By O.E.M.
Part Number: To Be Filled By O.E.M.
Core Count: 4
Core Enabled: 4
Thread Count: 4
Characteristics:
64-bit capable
Multi-Core
Execute Protection
Enhanced Virtualization
Power/Performance Control
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment