Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ARMV7 and ARMV8 differentiators #23

Merged
merged 8 commits into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,14 @@
<testsuite name="PPC">
<file>tests/System/SystemTestPPC.php</file>
</testsuite>
<testsuite name="ARM">
<file>tests/System/SystemTestARM.php</file>
<testsuite name="ARM64">
<file>tests/System/SystemTestARM64.php</file>
</testsuite>
<testsuite name="ARMV7">
<file>tests/System/SystemTestARMV7.php</file>
</testsuite>
<testsuite name="ARMV8">
<file>tests/System/SystemTestARMV8.php</file>
</testsuite>
</testsuites>
</phpunit>
56 changes: 47 additions & 9 deletions src/System/System.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,19 @@ class System

public const PPC = 'ppc';

public const ARM = 'arm';
public const ARM64 = 'arm64';

public const ARMV7 = 'armv7';

public const ARMV8 = 'armv8';

private const RegExX86 = '/(x86*|i386|i686)/';

private const RegExARM = '/(aarch*|arm*)/';
private const RegexARM64 = '/(aarch64)/';

private const RegexARMV7 = '/(armv7)/';

private const RegexARMV8 = '/(armv8)/';

private const RegExPPC = '/(ppc*)/';

Expand Down Expand Up @@ -96,8 +104,12 @@ public static function getArchEnum(): string
case preg_match(self::RegExPPC, $arch):
return System::PPC;
break;
case preg_match(self::RegExARM, $arch):
return System::ARM;
case preg_match(self::RegexARM64, $arch):
return System::ARM64;
case preg_match(self::ARMV7, $arch):
return System::ARMV7;
case preg_match(self::ARMV8, $arch):
return System::ARMV8;
break;

default:
Expand All @@ -117,13 +129,33 @@ public static function getHostname(): string
}

/**
* Checks if the system is running on an ARM architecture.
* Checks if the system is running on an ARM64 architecture.
*
* @return bool
*/
public static function isArm64(): bool
{
return (bool) preg_match(self::RegexARM64, self::getArch());
}

/**
* Checks if the system is running on an ARMV7 architecture.
*
* @return bool
*/
public static function isArmV7(): bool
{
return (bool) preg_match(self::RegexARMV7, self::getArch());
}

/**
* Checks if the system is running on an ARM64 architecture.
*
* @return bool
*/
public static function isArm(): bool
public static function isArmV8(): bool
{
return (bool) preg_match(self::RegExARM, self::getArch());
return (bool) preg_match(self::RegexARMV8, self::getArch());
}

/**
Expand Down Expand Up @@ -164,8 +196,14 @@ public static function isArch(string $arch): bool
case self::PPC:
return self::isPPC();
break;
case self::ARM:
return self::isArm();
case self::ARM64:
return self::isArm64();
break;
case self::ARMV7:
return self::isArmV7();
break;
case self::ARMV8:
return self::isArmV8();
break;

default:
Expand Down
8 changes: 6 additions & 2 deletions tests/System/SystemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,14 @@ public function testOs()
$this->assertIsString(System::getArch());
$this->assertIsString(System::getArchEnum());
$this->assertIsString(System::getHostname());
$this->assertIsBool(System::isArm());
$this->assertIsBool(System::isArm64());
$this->assertIsBool(System::isArmV7());
$this->assertIsBool(System::isArmV8());
$this->assertIsBool(System::isPPC());
$this->assertIsBool(System::isX86());
$this->assertIsBool(System::isArch(System::ARM));
$this->assertIsBool(System::isArch(System::ARM64));
$this->assertIsBool(System::isArch(System::ARMV7));
$this->assertIsBool(System::isArch(System::ARMV8));
$this->assertIsBool(System::isArch(System::X86));
$this->assertIsBool(System::isArch(System::PPC));
$this->expectException('Exception');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
use PHPUnit\Framework\TestCase;
use Utopia\System\System;

class SystemTestARM extends TestCase
class SystemTestARM64 extends TestCase
{
public function setUp(): void
{
Expand All @@ -30,14 +30,18 @@ public function tearDown(): void

public function testOs()
{
$this->assertTrue(System::isArm());
$this->assertTrue(System::isArm64());
$this->assertFalse(System::isArmV7());
$this->assertFalse(System::isArmV8());
$this->assertFalse(System::isPPC());
$this->assertFalse(System::isX86());

$this->assertTrue(System::isArch(System::ARM));
$this->assertTrue(System::isArch(System::ARM64));
$this->assertFalse(System::isArch(System::ARMV7));
$this->assertFalse(System::isArch(System::ARMV8));
$this->assertFalse(System::isArch(System::PPC));
$this->assertFalse(System::isArch(System::X86));

$this->assertEquals(System::ARM, System::getArchEnum());
$this->assertEquals(System::ARM64, System::getArchEnum());
}
}
47 changes: 47 additions & 0 deletions tests/System/SystemTestARMV7.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

/**
* Utopia PHP Framework
*
*
* @link https://github.com/utopia-php/framework
*
* @author Eldad Fux <[email protected]>
*
* @version 1.0 RC4
*
* @license The MIT License (MIT) <http://www.opensource.org/licenses/mit-license.php>
*/

namespace Utopia\Tests;

use PHPUnit\Framework\TestCase;
use Utopia\System\System;

class SystemTestARMV7 extends TestCase
{
public function setUp(): void
{
}

public function tearDown(): void
{
}

public function testOs()
{
$this->assertFalse(System::isArm64());
$this->assertTrue(System::isArmV7());
$this->assertFalse(System::isArmV8());
$this->assertFalse(System::isPPC());
$this->assertFalse(System::isX86());

$this->assertFalse(System::isArch(System::ARM64));
$this->assertTrue(System::isArch(System::ARMV7));
$this->assertFalse(System::isArch(System::ARMV8));
$this->assertFalse(System::isArch(System::PPC));
$this->assertFalse(System::isArch(System::X86));

$this->assertEquals(System::ARMV7, System::getArchEnum());
}
}
47 changes: 47 additions & 0 deletions tests/System/SystemTestARMV8.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

/**
* Utopia PHP Framework
*
*
* @link https://github.com/utopia-php/framework
*
* @author Eldad Fux <[email protected]>
*
* @version 1.0 RC4
*
* @license The MIT License (MIT) <http://www.opensource.org/licenses/mit-license.php>
*/

namespace Utopia\Tests;

use PHPUnit\Framework\TestCase;
use Utopia\System\System;

class SystemTestARMV8 extends TestCase
{
public function setUp(): void
{
}

public function tearDown(): void
{
}

public function testOs()
{
$this->assertFalse(System::isArm64());
$this->assertFalse(System::isArmV7());
$this->assertTrue(System::isArmV8());
$this->assertFalse(System::isPPC());
$this->assertFalse(System::isX86());

$this->assertFalse(System::isArch(System::ARM64));
$this->assertFalse(System::isArch(System::ARMV7));
$this->assertTrue(System::isArch(System::ARMV8));
$this->assertFalse(System::isArch(System::PPC));
$this->assertFalse(System::isArch(System::X86));

$this->assertEquals(System::ARMV8, System::getArchEnum());
}
}
8 changes: 6 additions & 2 deletions tests/System/SystemTestPPC.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,15 @@ public function tearDown(): void

public function testOs()
{
$this->assertFalse(System::isArm());
$this->assertFalse(System::isArm64());
$this->assertFalse(System::isArmV7());
$this->assertFalse(System::isArmV8());
$this->assertTrue(System::isPPC());
$this->assertFalse(System::isX86());

$this->assertFalse(System::isArch(System::ARM));
$this->assertFalse(System::isArch(System::ARM64));
$this->assertFalse(System::isArch(System::ARMV7));
$this->assertFalse(System::isArch(System::ARMV8));
$this->assertTrue(System::isArch(System::PPC));
$this->assertFalse(System::isArch(System::X86));

Expand Down
8 changes: 6 additions & 2 deletions tests/System/SystemTestX86.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,15 @@ public function tearDown(): void

public function testOs()
{
$this->assertFalse(System::isArm());
$this->assertFalse(System::isArm64());
$this->assertFalse(System::isArmV7());
$this->assertFalse(System::isArmV8());
$this->assertFalse(System::isPPC());
$this->assertTrue(System::isX86());

$this->assertFalse(System::isArch(System::ARM));
$this->assertFalse(System::isArch(System::ARM64));
$this->assertFalse(System::isArch(System::ARMV7));
$this->assertFalse(System::isArch(System::ARMV8));
$this->assertFalse(System::isArch(System::PPC));
$this->assertTrue(System::isArch(System::X86));

Expand Down