Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Add generated test extension
  • Loading branch information
nikic committed Mar 10, 2017
commit 6f3a11d75b38a8e385bf2538dec279e4248d68d2
35 changes: 35 additions & 0 deletions ext/test/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
.deps
*.lo
*.la
.libs
acinclude.m4
aclocal.m4
autom4te.cache
build
config.guess
config.h
config.h.in
config.log
config.nice
config.status
config.sub
configure
configure.ac
include
install-sh
libtool
ltmain.sh
Makefile
Makefile.fragments
Makefile.global
Makefile.objects
missing
mkinstalldirs
modules
run-tests.php
tests/*/*.diff
tests/*/*.out
tests/*/*.php
tests/*/*.exp
tests/*/*.log
tests/*/*.sh
1 change: 1 addition & 0 deletions ext/test/CREDITS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test
Empty file added ext/test/EXPERIMENTAL
Empty file.
63 changes: 63 additions & 0 deletions ext/test/config.m4
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
dnl $Id$
dnl config.m4 for extension test

dnl Comments in this file start with the string 'dnl'.
dnl Remove where necessary. This file will not work
dnl without editing.

dnl If your extension references something external, use with:

dnl PHP_ARG_WITH(test, for test support,
dnl Make sure that the comment is aligned:
dnl [ --with-test Include test support])

dnl Otherwise use enable:

dnl PHP_ARG_ENABLE(test, whether to enable test support,
dnl Make sure that the comment is aligned:
dnl [ --enable-test Enable test support])

if test "$PHP_TEST" != "no"; then
dnl Write more examples of tests here...

dnl # --with-test -> check with-path
dnl SEARCH_PATH="/usr/local /usr" # you might want to change this
dnl SEARCH_FOR="/include/test.h" # you most likely want to change this
dnl if test -r $PHP_TEST/$SEARCH_FOR; then # path given as parameter
dnl TEST_DIR=$PHP_TEST
dnl else # search default path list
dnl AC_MSG_CHECKING([for test files in default path])
dnl for i in $SEARCH_PATH ; do
dnl if test -r $i/$SEARCH_FOR; then
dnl TEST_DIR=$i
dnl AC_MSG_RESULT(found in $i)
dnl fi
dnl done
dnl fi
dnl
dnl if test -z "$TEST_DIR"; then
dnl AC_MSG_RESULT([not found])
dnl AC_MSG_ERROR([Please reinstall the test distribution])
dnl fi

dnl # --with-test -> add include path
dnl PHP_ADD_INCLUDE($TEST_DIR/include)

dnl # --with-test -> check for lib and symbol presence
dnl LIBNAME=test # you may want to change this
dnl LIBSYMBOL=test # you most likely want to change this

dnl PHP_CHECK_LIBRARY($LIBNAME,$LIBSYMBOL,
dnl [
dnl PHP_ADD_LIBRARY_WITH_PATH($LIBNAME, $TEST_DIR/$PHP_LIBDIR, TEST_SHARED_LIBADD)
dnl AC_DEFINE(HAVE_TESTLIB,1,[ ])
dnl ],[
dnl AC_MSG_ERROR([wrong test lib version or lib not found])
dnl ],[
dnl -L$TEST_DIR/$PHP_LIBDIR -lm
dnl ])
dnl
dnl PHP_SUBST(TEST_SHARED_LIBADD)

PHP_NEW_EXTENSION(test, test.c, $ext_shared,, -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1)
fi
13 changes: 13 additions & 0 deletions ext/test/config.w32
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// $Id$
// vim:ft=javascript

// If your extension references something external, use ARG_WITH
// ARG_WITH("test", "for test support", "no");

// Otherwise, use ARG_ENABLE
// ARG_ENABLE("test", "enable test support", "no");

if (PHP_TEST != "no") {
EXTENSION("test", "test.c", PHP_EXTNAME_SHARED, "/DZEND_ENABLE_STATIC_TSRMLS_CACHE=1");
}

58 changes: 58 additions & 0 deletions ext/test/php_test.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
+----------------------------------------------------------------------+
| PHP Version 7 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2017 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: |
+----------------------------------------------------------------------+
*/

/* $Id$ */

#ifndef PHP_TEST_H
#define PHP_TEST_H

extern zend_module_entry test_module_entry;
#define phpext_test_ptr &test_module_entry

#define PHP_TEST_VERSION "0.1.0"

#ifdef PHP_WIN32
# define PHP_TEST_API __declspec(dllexport)
#elif defined(__GNUC__) && __GNUC__ >= 4
# define PHP_TEST_API __attribute__ ((visibility("default")))
#else
# define PHP_TEST_API
#endif

#ifdef ZTS
#include "TSRM.h"
#endif


#define TEST_G(v) ZEND_MODULE_GLOBALS_ACCESSOR(test, v)

#if defined(ZTS) && defined(COMPILE_DL_TEST)
ZEND_TSRMLS_CACHE_EXTERN()
#endif

#endif


/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/
103 changes: 103 additions & 0 deletions ext/test/test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/*
+----------------------------------------------------------------------+
| PHP Version 7 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2017 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: |
+----------------------------------------------------------------------+
*/

/* $Id$ */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include "php.h"
#include "php_ini.h"
#include "ext/standard/info.h"
#include "php_test.h"



static int le_test;







PHP_MINIT_FUNCTION(test)
{
return SUCCESS;
}


PHP_MSHUTDOWN_FUNCTION(test)
{
return SUCCESS;
}



PHP_RINIT_FUNCTION(test)
{
#if defined(COMPILE_DL_TEST) && defined(ZTS)
ZEND_TSRMLS_CACHE_UPDATE();
#endif
return SUCCESS;
}



PHP_RSHUTDOWN_FUNCTION(test)
{
return SUCCESS;
}


PHP_MINFO_FUNCTION(test)
{
php_info_print_table_start();
php_info_print_table_header(2, "test support", "enabled");
php_info_print_table_end();

}


const zend_function_entry test_functions[] = {
PHP_FE_END
};


zend_module_entry test_module_entry = {
STANDARD_MODULE_HEADER,
"test",
test_functions,
PHP_MINIT(test),
PHP_MSHUTDOWN(test),
PHP_RINIT(test),
PHP_RSHUTDOWN(test),
PHP_MINFO(test),
PHP_TEST_VERSION,
STANDARD_MODULE_PROPERTIES
};


#ifdef COMPILE_DL_TEST
#ifdef ZTS
ZEND_TSRMLS_CACHE_DEFINE()
#endif
ZEND_GET_MODULE(test)
#endif

21 changes: 21 additions & 0 deletions ext/test/tests/001.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
--TEST--
Check for test presence
--SKIPIF--
<?php if (!extension_loaded("test")) print "skip"; ?>
--FILE--
<?php
echo "test extension is available";
/*
you can add regression tests for your extension here

the output of your test code has to be equal to the
text in the --EXPECT-- section below for the tests
to pass, differences between the output and the
expected text are interpreted as failure

see php7/README.TESTING for further information on
writing regression tests
*/
?>
--EXPECT--
test extension is available