From faf10136819a48c26ed25519861d948e8044b7e8 Mon Sep 17 00:00:00 2001 From: krakjoe Date: Fri, 6 Dec 2013 20:56:16 +0000 Subject: [PATCH] more tests add phpdbg_exec userland function --- Changelog.md | 2 ++ phpdbg.c | 50 ++++++++++++++++++++++++++++++++ tests/commands/0104_clean.test | 15 ++++++++++ tests/commands/0105_clear.test | 15 ++++++++++ tests/commands/0106_compile.test | 19 ++++++++++++ 5 files changed, 101 insertions(+) create mode 100644 tests/commands/0104_clean.test create mode 100644 tests/commands/0105_clear.test create mode 100644 tests/commands/0106_compile.test diff --git a/Changelog.md b/Changelog.md index 308b68c4c8..b49390f636 100644 --- a/Changelog.md +++ b/Changelog.md @@ -11,6 +11,8 @@ Version 0.3.0 2013-00-00 5. Fix crash when loading .phpdbginit with command line switch 6. Fix crash on startup errors 7. Added init.d for remote console (redhat) +8. Added phpdbg_exec userland function +9. Added testing facilities Version 0.2.0 2013-11-31 ------------------------ diff --git a/phpdbg.c b/phpdbg.c index 2a8726520c..1bd79bbd5f 100644 --- a/phpdbg.c +++ b/phpdbg.c @@ -199,6 +199,51 @@ static PHP_RSHUTDOWN_FUNCTION(phpdbg) /* {{{ */ return SUCCESS; } /* }}} */ +/* {{{ proto mixed phpdbg_exec(string context) + Attempt to set the execution context for phpdbg + If the execution context was set previously it is returned + If the execution context was not set previously boolean true is returned + If the request to set the context fails, boolean false is returned, and an E_WARNING raised */ +static PHP_FUNCTION(phpdbg_exec) +{ + char *exec = NULL; + zend_ulong exec_len = 0L; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &exec, &exec_len) == FAILURE) { + return; + } + + { + struct stat sb; + zend_bool result = 1; + + if (VCWD_STAT(exec, &sb) != FAILURE) { + if (sb.st_mode & (S_IFREG|S_IFLNK)) { + if (PHPDBG_G(exec)) { + ZVAL_STRINGL(return_value, PHPDBG_G(exec), PHPDBG_G(exec_len), 1); + efree(PHPDBG_G(exec)); + result = 0; + } + + PHPDBG_G(exec) = estrndup(exec, exec_len); + PHPDBG_G(exec_len) = exec_len; + + if (result) + ZVAL_BOOL(return_value, 1); + } else { + zend_error( + E_WARNING, "Failed to set execution context (%s), not a regular file or symlink", exec); + ZVAL_BOOL(return_value, 0); + } + } else { + zend_error( + E_WARNING, "Failed to set execution context (%s) the file does not exist", exec); + + ZVAL_BOOL(return_value, 0); + } + } +} /* }}} */ + /* {{{ proto void phpdbg_break([integer type, string expression]) instructs phpdbg to insert a breakpoint at the next opcode */ static PHP_FUNCTION(phpdbg_break) @@ -307,12 +352,17 @@ ZEND_BEGIN_ARG_INFO_EX(phpdbg_prompt_arginfo, 0, 0, 0) ZEND_ARG_INFO(0, string) ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_INFO_EX(phpdbg_exec_arginfo, 0, 0, 0) + ZEND_ARG_INFO(0, context) +ZEND_END_ARG_INFO() + ZEND_BEGIN_ARG_INFO_EX(phpdbg_clear_arginfo, 0, 0, 0) ZEND_END_ARG_INFO() zend_function_entry phpdbg_user_functions[] = { PHP_FE(phpdbg_clear, phpdbg_clear_arginfo) PHP_FE(phpdbg_break, phpdbg_break_arginfo) + PHP_FE(phpdbg_exec, phpdbg_exec_arginfo) PHP_FE(phpdbg_color, phpdbg_color_arginfo) PHP_FE(phpdbg_prompt, phpdbg_prompt_arginfo) #ifdef PHP_FE_END diff --git a/tests/commands/0104_clean.test b/tests/commands/0104_clean.test new file mode 100644 index 0000000000..c7a579be17 --- /dev/null +++ b/tests/commands/0104_clean.test @@ -0,0 +1,15 @@ +################################################# +# name: clean +# purpose: test cleaning environment +# expect: TEST::FORMAT +# options: -rr +################################################# +#[Cleaning Execution Environment] +#Classes %d +#Functions %d +#Constants %d +#Includes %d +#[Nothing to execute!] +################################################# +clean +quit diff --git a/tests/commands/0105_clear.test b/tests/commands/0105_clear.test new file mode 100644 index 0000000000..1ac3c3b809 --- /dev/null +++ b/tests/commands/0105_clear.test @@ -0,0 +1,15 @@ +################################################# +# name: clear +# purpose: test clearing breakpoints +# expect: TEST::FORMAT +# options: -rr +################################################# +#[Clearing Breakpoints] +#File 0 +#Functions 0 +#Methods 0 +#Oplines 0 +#Conditionals 0 +################################################# +clear +quit diff --git a/tests/commands/0106_compile.test b/tests/commands/0106_compile.test new file mode 100644 index 0000000000..d79211ddf7 --- /dev/null +++ b/tests/commands/0106_compile.test @@ -0,0 +1,19 @@ +################################################# +# name: compile +# purpose: test compiling code +# expect: TEST::FORMAT +# options: -rr +################################################# +#[Attempting compilation of %s] +#[Success] +#Hello World +################################################# +<: +define('OUT', + tempnam(null, "phpdbg")); +file_put_contents(OUT, ""); +phpdbg_exec(OUT); +:> +compile +run +quit -- 2.40.0