Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/serverinfo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDaniel Kesselberg <mail@danielkesselberg.de>2020-04-18 00:05:29 +0300
committerDaniel Kesselberg <mail@danielkesselberg.de>2020-04-18 22:13:18 +0300
commitdd50612bfbffa51e092f9bcb70bcd114240c25df (patch)
treecd22d3c3f079c07193cd02f184d65293bc40d475 /tests
parentefeed3479fd048b403c6a72ebf74241a971a065c (diff)
Add more tests for getMemory, getCPUName and getUptime
Signed-off-by: Daniel Kesselberg <mail@danielkesselberg.de>
Diffstat (limited to 'tests')
-rw-r--r--tests/data/cpuinfo_one_core26
-rw-r--r--tests/lib/DefaultOsTest.php52
2 files changed, 78 insertions, 0 deletions
diff --git a/tests/data/cpuinfo_one_core b/tests/data/cpuinfo_one_core
new file mode 100644
index 0000000..1be32f4
--- /dev/null
+++ b/tests/data/cpuinfo_one_core
@@ -0,0 +1,26 @@
+processor : 0
+vendor_id : GenuineIntel
+cpu family : 6
+model : 94
+model name : Intel(R) Core(TM) i5-6500 CPU @ 3.20GHz
+stepping : 3
+microcode : 0xd6
+cpu MHz : 800.022
+cache size : 6144 KB
+physical id : 0
+siblings : 4
+core id : 0
+cpu cores : 4
+apicid : 0
+initial apicid : 0
+fpu : yes
+fpu_exception : yes
+cpuid level : 22
+wp : yes
+flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb invpcid_single pti ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm mpx rdseed adx smap clflushopt intel_pt xsaveopt xsavec xgetbv1 xsaves dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp md_clear flush_l1d
+bugs : cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf mds swapgs taa itlb_multihit
+bogomips : 6399.96
+clflush size : 64
+cache_alignment : 64
+address sizes : 39 bits physical, 48 bits virtual
+power management:
diff --git a/tests/lib/DefaultOsTest.php b/tests/lib/DefaultOsTest.php
index 32aa8e1..5415e3a 100644
--- a/tests/lib/DefaultOsTest.php
+++ b/tests/lib/DefaultOsTest.php
@@ -69,6 +69,22 @@ class DefaultOsTest extends TestCase {
$this->assertEquals(917756 * 1024, $memory['SwapFree']);
}
+ public function testGetMemoryNoData(): void {
+ $this->os->method('readContent')
+ ->with('/proc/meminfo')
+ ->willThrowException(new \RuntimeException('Unable to read: "/proc/meminfo"'));
+
+ $this->assertSame(['MemTotal' => -1, 'MemFree' => -1, 'MemAvailable' => -1, 'SwapTotal' => -1, 'SwapFree' => -1], $this->os->getMemory());
+ }
+
+ public function testGetMemoryInvalidData(): void {
+ $this->os->method('readContent')
+ ->with('/proc/meminfo')
+ ->willReturn('invalid_data');
+
+ $this->assertSame(['MemTotal' => -1, 'MemFree' => -1, 'MemAvailable' => -1, 'SwapTotal' => -1, 'SwapFree' => -1], $this->os->getMemory());
+ }
+
public function testGetCPUName(): void {
$this->os->method('readContent')
->with('/proc/cpuinfo')
@@ -77,6 +93,30 @@ class DefaultOsTest extends TestCase {
$this->assertEquals('Intel(R) Core(TM) i5-6500 CPU @ 3.20GHz (4 cores)', $this->os->getCPUName());
}
+ public function testGetCPUNameOneCore(): void {
+ $this->os->method('readContent')
+ ->with('/proc/cpuinfo')
+ ->willReturn(file_get_contents(__DIR__ . '/../data/cpuinfo_one_core'));
+
+ $this->assertEquals('Intel(R) Core(TM) i5-6500 CPU @ 3.20GHz (1 core)', $this->os->getCPUName());
+ }
+
+ public function testGetCPUNameNoData(): void {
+ $this->os->method('readContent')
+ ->with('/proc/cpuinfo')
+ ->willThrowException(new \RuntimeException('Unable to read: "/proc/cpuinfo"'));
+
+ $this->assertEquals('Unknown Processor', $this->os->getCPUName());
+ }
+
+ public function testGetCPUNameInvalidData(): void {
+ $this->os->method('readContent')
+ ->with('/proc/cpuinfo')
+ ->willReturn('invalid_data');
+
+ $this->assertEquals('Unknown Processor', $this->os->getCPUName());
+ }
+
public function testGetUptime(): void {
$this->os->method('readContent')
->with('/proc/uptime')
@@ -85,6 +125,14 @@ class DefaultOsTest extends TestCase {
$this->assertEquals(13278, $this->os->getUptime());
}
+ public function testGetUptimeNoData(): void {
+ $this->os->method('readContent')
+ ->with('/proc/uptime')
+ ->willThrowException(new \RuntimeException('Unable to read: "/proc/uptime"'));
+
+ $this->assertEquals(-1, $this->os->getUptime());
+ }
+
public function testGetDiskInfo(): void {
$this->os->method('executeCommand')
->with('df -TP')
@@ -143,4 +191,8 @@ class DefaultOsTest extends TestCase {
$this->assertSame([], $this->os->getDiskInfo());
}
+
+ public function testSupported(): void {
+ $this->assertTrue($this->os->supported());
+ }
}