mirror of
https://github.com/danog/ext-uv.git
synced 2024-11-26 20:14:47 +01:00
add several test cases
This commit is contained in:
parent
a68592fcdd
commit
7f026cf1b2
14
config.m4
14
config.m4
@ -1,5 +1,13 @@
|
||||
PHP_ARG_ENABLE(uv, Whether to enable the "uv" extension,
|
||||
[ --enable-uv Enable "uv" extension support])
|
||||
[ --enable-uv Enable "uv" extension support])
|
||||
|
||||
if test -z "$PHP_DEBUG"; then
|
||||
AC_ARG_ENABLE(debug,
|
||||
[ --enable-debug compile with debugging symbols],[
|
||||
PHP_DEBUG=$enableval
|
||||
],[ PHP_DEBUG=no
|
||||
])
|
||||
fi
|
||||
|
||||
if test $PHP_UV != "no"; then
|
||||
PHP_NEW_EXTENSION(uv, php_uv.c uv.c, $ext_shared)
|
||||
@ -8,6 +16,10 @@ if test $PHP_UV != "no"; then
|
||||
|
||||
CFLAGS=" -g -O0 -Wunused-variable -Wpointer-sign -Wimplicit-function-declaration -Wl,libuv/uv.a"
|
||||
|
||||
dnl if test $PHP_DEBUG != "no"; then
|
||||
dnl CFLAGS="$CFLAGS -DPHP_UV_DEBUG=1"
|
||||
dnl fi
|
||||
|
||||
case $host in
|
||||
*darwin*)
|
||||
dnl these macro does not work. why?
|
||||
|
51
php_uv.c
51
php_uv.c
@ -20,7 +20,7 @@
|
||||
#include "php_uv.h"
|
||||
|
||||
#ifndef PHP_UV_DEBUG
|
||||
#define PHP_UV_DEBUG 1
|
||||
#define PHP_UV_DEBUG 0
|
||||
#endif
|
||||
|
||||
extern void php_uv_init(TSRMLS_D);
|
||||
@ -2972,7 +2972,8 @@ struct sockaddr_in {
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ */
|
||||
/* {{{ proto array uv_loadavg(void)
|
||||
*/
|
||||
PHP_FUNCTION(uv_loadavg)
|
||||
{
|
||||
zval *retval;
|
||||
@ -2990,19 +2991,16 @@ PHP_FUNCTION(uv_loadavg)
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ */
|
||||
/* {{{ proto double uv_uptime(void)
|
||||
*/
|
||||
PHP_FUNCTION(uv_uptime)
|
||||
{
|
||||
zval *retval;
|
||||
uv_err_t error;
|
||||
double uptime;
|
||||
|
||||
error = uv_uptime(&uptime);
|
||||
|
||||
MAKE_STD_ZVAL(retval);
|
||||
ZVAL_DOUBLE(retval, uptime);
|
||||
|
||||
RETURN_ZVAL(retval,0,1);
|
||||
RETURN_DOUBLE(uptime);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
@ -3020,35 +3018,39 @@ PHP_FUNCTION(uv_get_process_title)
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ */
|
||||
/* {{{ proto long uv_get_free_memory(void)
|
||||
*/
|
||||
PHP_FUNCTION(uv_get_free_memory)
|
||||
{
|
||||
RETURN_LONG(uv_get_free_memory());
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ */
|
||||
/* {{{ proto long uv_get_total_memory(void)
|
||||
*/
|
||||
PHP_FUNCTION(uv_get_total_memory)
|
||||
{
|
||||
RETURN_LONG(uv_get_total_memory());
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ */
|
||||
/* {{{ proto long uv_hrtime(void)
|
||||
*/
|
||||
PHP_FUNCTION(uv_hrtime)
|
||||
{
|
||||
/* TODO: check behavior */
|
||||
/* TODO: is this correct? */
|
||||
RETURN_LONG(uv_hrtime());
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ */
|
||||
/* {{{ proto string uv_exepath(void)
|
||||
*/
|
||||
PHP_FUNCTION(uv_exepath)
|
||||
{
|
||||
char buffer[1024] = {0};
|
||||
size_t buffer_sz = sizeof(buffer);
|
||||
size_t buffer_sz;
|
||||
|
||||
/* TODO: check behavior */
|
||||
buffer_sz = sizeof(buffer);
|
||||
uv_exepath(buffer, &buffer_sz);
|
||||
buffer[buffer_sz] = '\0';
|
||||
|
||||
@ -3070,7 +3072,8 @@ PHP_FUNCTION(uv_cwd)
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ */
|
||||
/* {{{ proto array uv_cpu_info(void)
|
||||
*/
|
||||
PHP_FUNCTION(uv_cpu_info)
|
||||
{
|
||||
zval *retval;
|
||||
@ -3085,23 +3088,25 @@ PHP_FUNCTION(uv_cpu_info)
|
||||
|
||||
for (i = 0; i < count; i++) {
|
||||
zval *tmp, *times;
|
||||
|
||||
MAKE_STD_ZVAL(tmp);
|
||||
array_init(tmp);
|
||||
MAKE_STD_ZVAL(times);
|
||||
array_init(tmp);
|
||||
array_init(times);
|
||||
|
||||
add_assoc_string_ex(tmp, "model", sizeof("model"), cpus[i].model, 1);
|
||||
add_assoc_long_ex(tmp, "speed", sizeof("speed"), cpus[i].speed);
|
||||
|
||||
add_assoc_long_ex(times, "sys", sizeof("sys"), (size_t)cpus[i].cpu_times.sys);
|
||||
add_assoc_long_ex(times, "user", sizeof("user"), (size_t)cpus[i].cpu_times.user);
|
||||
add_assoc_long_ex(times, "idle", sizeof("idle"), (size_t)cpus[i].cpu_times.idle);
|
||||
add_assoc_long_ex(times, "irq", sizeof("irq"), (size_t)cpus[i].cpu_times.irq);
|
||||
add_assoc_long_ex(times, "nice", sizeof("nice"), (size_t)cpus[i].cpu_times.nice);
|
||||
add_assoc_zval_ex(tmp,"times", sizeof("times"), times);
|
||||
add_assoc_long_ex(times, "sys", sizeof("sys"), (size_t)cpus[i].cpu_times.sys);
|
||||
add_assoc_long_ex(times, "user", sizeof("user"), (size_t)cpus[i].cpu_times.user);
|
||||
add_assoc_long_ex(times, "idle", sizeof("idle"), (size_t)cpus[i].cpu_times.idle);
|
||||
add_assoc_long_ex(times, "irq", sizeof("irq"), (size_t)cpus[i].cpu_times.irq);
|
||||
add_assoc_long_ex(times, "nice", sizeof("nice"), (size_t)cpus[i].cpu_times.nice);
|
||||
add_assoc_zval_ex(tmp, "times", sizeof("times"), times);
|
||||
|
||||
add_next_index_zval(retval,tmp);
|
||||
}
|
||||
|
||||
uv_free_cpu_info(cpus, count);
|
||||
RETURN_ZVAL(retval,0,1);
|
||||
}
|
||||
|
35
tests/999-uv_cpu_info.phpt
Normal file
35
tests/999-uv_cpu_info.phpt
Normal file
@ -0,0 +1,35 @@
|
||||
--TEST--
|
||||
Check for uv_cpuinfo
|
||||
--FILE--
|
||||
<?php
|
||||
$cpuinfo = uv_cpu_info();
|
||||
|
||||
$info = array_shift($cpuinfo);
|
||||
|
||||
if (!isset($info["model"])) {
|
||||
echo "FAILED: key `model` does not exist" . PHP_EOL;
|
||||
}
|
||||
if (!isset($info["speed"])) {
|
||||
echo "FAILED: key `speed` does not exist" . PHP_EOL;
|
||||
}
|
||||
if (!isset($info["times"])) {
|
||||
echo "FAILED: key `times` does not exist" . PHP_EOL;
|
||||
}
|
||||
|
||||
if (!isset($info["times"]["sys"])) {
|
||||
echo "FAILED: key `times.sys` does not exist" . PHP_EOL;
|
||||
}
|
||||
if (!isset($info["times"]["user"])) {
|
||||
echo "FAILED: key `times.user` does not exist" . PHP_EOL;
|
||||
}
|
||||
if (!isset($info["times"]["idle"])) {
|
||||
echo "FAILED: key `times.idle` does not exist" . PHP_EOL;
|
||||
}
|
||||
if (!isset($info["times"]["irq"])) {
|
||||
echo "FAILED: key `times.irq` does not exist" . PHP_EOL;
|
||||
}
|
||||
if (!isset($info["times"]["nice"])) {
|
||||
echo "FAILED: key `times.nice` does not exist" . PHP_EOL;
|
||||
}
|
||||
|
||||
--EXPECT--
|
35
tests/999-uv_cpuinfo.phpt
Executable file
35
tests/999-uv_cpuinfo.phpt
Executable file
@ -0,0 +1,35 @@
|
||||
--TEST--
|
||||
Check for uv_cpu_info
|
||||
--FILE--
|
||||
<?php
|
||||
$cpuinfo = uv_cpu_info();
|
||||
|
||||
$info = array_shift($cpuinfo);
|
||||
|
||||
if (!isset($info["model"])) {
|
||||
echo "FAILED: key `model` does not exist" . PHP_EOL;
|
||||
}
|
||||
if (!isset($info["speed"])) {
|
||||
echo "FAILED: key `speed` does not exist" . PHP_EOL;
|
||||
}
|
||||
if (!isset($info["times"])) {
|
||||
echo "FAILED: key `times` does not exist" . PHP_EOL;
|
||||
}
|
||||
|
||||
if (!isset($info["times"]["sys"])) {
|
||||
echo "FAILED: key `times.sys` does not exist" . PHP_EOL;
|
||||
}
|
||||
if (!isset($info["times"]["user"])) {
|
||||
echo "FAILED: key `times.user` does not exist" . PHP_EOL;
|
||||
}
|
||||
if (!isset($info["times"]["idle"])) {
|
||||
echo "FAILED: key `times.idle` does not exist" . PHP_EOL;
|
||||
}
|
||||
if (!isset($info["times"]["irq"])) {
|
||||
echo "FAILED: key `times.irq` does not exist" . PHP_EOL;
|
||||
}
|
||||
if (!isset($info["times"]["nice"])) {
|
||||
echo "FAILED: key `times.nice` does not exist" . PHP_EOL;
|
||||
}
|
||||
|
||||
--EXPECT--
|
9
tests/999-uv_exepath.phpt
Normal file
9
tests/999-uv_exepath.phpt
Normal file
@ -0,0 +1,9 @@
|
||||
--TEST--
|
||||
Check for uv_exepath
|
||||
--FILE--
|
||||
<?php
|
||||
$path = uv_exepath();
|
||||
|
||||
echo (int)preg_match("/php/",$path,$match);
|
||||
--EXPECT--
|
||||
1
|
9
tests/999-uv_get_free_memory.phpt
Normal file
9
tests/999-uv_get_free_memory.phpt
Normal file
@ -0,0 +1,9 @@
|
||||
--TEST--
|
||||
Check for uv_get_free_memory
|
||||
--FILE--
|
||||
<?php
|
||||
$free = uv_get_free_memory();
|
||||
|
||||
echo (int)is_int($free);
|
||||
--EXPECT--
|
||||
1
|
9
tests/999-uv_get_total_memory.phpt
Normal file
9
tests/999-uv_get_total_memory.phpt
Normal file
@ -0,0 +1,9 @@
|
||||
--TEST--
|
||||
Check for uv_get_total_memory
|
||||
--FILE--
|
||||
<?php
|
||||
$free = uv_get_total_memory();
|
||||
|
||||
echo (int)is_int($free);
|
||||
--EXPECT--
|
||||
1
|
8
tests/999-uv_hrtime.phpt
Normal file
8
tests/999-uv_hrtime.phpt
Normal file
@ -0,0 +1,8 @@
|
||||
--TEST--
|
||||
Check for uv_hrtime
|
||||
--FILE--
|
||||
<?php
|
||||
/* is this correct ?*/
|
||||
$hrtime = uv_hrtime();
|
||||
|
||||
--EXPECT--
|
15
tests/999-uv_loadavg.phpt
Normal file
15
tests/999-uv_loadavg.phpt
Normal file
@ -0,0 +1,15 @@
|
||||
--TEST--
|
||||
Check for uv_loadavg
|
||||
--FILE--
|
||||
<?php
|
||||
$avg = uv_loadavg();
|
||||
|
||||
echo "count: " . count($avg) . PHP_EOL;
|
||||
echo (int)is_float($avg[0]) . PHP_EOL;
|
||||
echo (int)is_float($avg[1]) . PHP_EOL;
|
||||
echo (int)is_float($avg[2]) . PHP_EOL;
|
||||
--EXPECT--
|
||||
count: 3
|
||||
1
|
||||
1
|
||||
1
|
9
tests/999-uv_uptime.phpt
Normal file
9
tests/999-uv_uptime.phpt
Normal file
@ -0,0 +1,9 @@
|
||||
--TEST--
|
||||
Check for uv_uptime
|
||||
--FILE--
|
||||
<?php
|
||||
$uptime = uv_uptime();
|
||||
|
||||
echo (int)is_float($uptime);
|
||||
--EXPECT--
|
||||
1
|
Loading…
Reference in New Issue
Block a user