Added test-ffi target, use it in CI (#9)

* Added test-ffi target, use it in CI

* Added clang-format config, fixed RETURN_STRING API mismatch

* Skip installing php and packages on the PHP docker images

* Removed al2 job that was never going to work, and compiler tests

* Fixed basic test for extension loading

* Cleaned up lib structure, fixed tests

* use test-ci target to conditionally test in GitHub

* Use v0.8.1 of builder
This commit is contained in:
Justin Boswell
2021-02-15 09:47:32 -08:00
committed by GitHub
parent 7b5ccfd55a
commit aee57a929d
18 changed files with 354 additions and 232 deletions
+3 -39
View File
@@ -12,7 +12,7 @@ final class CRT {
function __construct() {
if (is_null(self::$ffi)) {
try {
self::$ffi = FFI::cdef(file_get_contents(__DIR__ . "/api.h"), __DIR__ . "/libaws-crt-ffi.so");
self::$ffi = FFI::cdef(file_get_contents(__DIR__ . "/../api.h"), __DIR__ . "/../libaws-crt-ffi.so");
self::init();
} catch (Exception $e) {
echo 'Exception while initializing CRT via FFI: ', $e->getMessage(), "\n";
@@ -59,47 +59,11 @@ final class CRT {
return self::$ffi->aws_crt_error_name((int) $error);
}
function event_loop_group_new($options) {
return self::$ffi->aws_crt_event_loop_group_new($options->num_threads);
function event_loop_group_new($num_threads) {
return self::$ffi->aws_crt_event_loop_group_new($num_threads);
}
function event_loop_group_release($elg) {
return self::$ffi->aws_crt_event_loop_group_release($elg);
}
}
/**
* Base class for all native resources, tracks all outstanding resources
* and provides basic leak checking
*/
abstract class NativeResource {
protected static $crt = null;
protected static $resources = [];
protected $native = null;
function __construct() {
if (is_null(self::$crt)) {
try {
self::$crt = new CRT();
} catch (Exception $e) {
echo 'Exception while loading CRT: ', $e->getMessage(), "\n";
}
}
self::$resources[spl_object_hash($this)] = 1;
}
protected function acquire($handle) {
$this->native = $handle;
}
protected function release() {
$this->native = null;
}
function __destruct() {
// Should have been destroyed and released by derived resource
assert($this->native == null);
unset(self::$resources[spl_object_hash($this)]);
}
}
@@ -1,22 +1,26 @@
<?php
require_once('crt.php');
final class EventLoopGroupOptions {
/**
* @var int $num_threads - Number of worker threads in the EventLoopGroup. Defaults to 0/1 per logical core.
*/
public $num_threads = 0;
}
/**
* Represents 1 or more event loops (1 per thread) for doing I/O and background tasks.
* Typically, every application has one EventLoopGroup.
*
* @param array options:
* - int num_threads - Number of worker threads in the EventLoopGroup. Defaults to 0/1 per logical core.
*/
final class EventLoopGroup extends NativeResource {
function __construct($options) {
static function defaults() {
return array(
'num_threads' => 0,
);
}
function __construct(array $options = array()) {
parent::__construct();
$this->acquire(self::$crt->event_loop_group_new($options->num_threads));
if (count($options) == 0) {
$options = self::defaults();
}
$this->acquire(self::$crt->event_loop_group_new($options['num_threads']));
}
function __destruct() {
+37
View File
@@ -0,0 +1,37 @@
<?php
/**
* Base class for all native resources, tracks all outstanding resources
* and provides basic leak checking
*/
abstract class NativeResource {
protected static $crt = null;
protected static $resources = [];
protected $native = null;
function __construct() {
if (is_null(self::$crt)) {
try {
self::$crt = new CRT();
} catch (Exception $e) {
echo 'Exception while loading CRT: ', $e->getMessage(), "\n";
}
}
self::$resources[spl_object_hash($this)] = 1;
}
protected function acquire($handle) {
$this->native = $handle;
}
protected function release() {
$this->native = null;
}
function __destruct() {
// Should have been destroyed and released by derived resource
assert($this->native == null);
unset(self::$resources[spl_object_hash($this)]);
}
}
-7
View File
@@ -1,7 +0,0 @@
<?php
// Entry point to the CRT library. This file should be preloaded.
// Import all of the library modules
require_once('crt.php');
require_once('io.php');
-7
View File
@@ -1,7 +0,0 @@
<?php
// php.ini
// ffi.enable=preload
// opcache.preload=preload.php
if (function_exists("opcache_compile_file")) {
opcache_compile_file(__DIR__ . "/lib.php");
}
-7
View File
@@ -1,7 +0,0 @@
<?php
require_once('crt.php');
$crt = new CRT();
$crt->init();
var_dump($crt->error_name(0));
$crt->clean_up();
-2
View File
@@ -1,7 +1,5 @@
<?php
require_once('tests.inc');
final class ErrorTest extends PHPUnit_Framework_TestCase {
private static $crt = null;
public static function setUpBeforeClass() {
+3 -5
View File
@@ -1,17 +1,15 @@
<?php
require_once('tests.inc');
final class EventLoopGroupTest extends PHPUnit_Framework_TestCase {
public function testLifetime() {
$elg = new EventLoopGroup(new EventLoopGroupOptions());
$elg = new EventLoopGroup();
$elg = null;
}
public function testConstructionWithOptions() {
$options = new EventLoopGroupOptions();
$options->num_threads = 1;
$options = EventLoopGroup::defaults();
$options['num_threads'] = 1;
$elg = new EventLoopGroup($options);
$elg = null;
}
-9
View File
@@ -1,9 +0,0 @@
<?php
// Ensure any version of PHPUnit works, since phpunit5 is the last one that
// works with PHP5.6
if (!class_exists('PHPUnit_Framework_TestCase') &&
class_exists('\\PHPUnit\\Framework\\TestCase')) {
abstract class PHPUnit_Framework_TestCase extends \PHPUnit\Framework\TestCase {
}
}