From 67013476b53655faa1ffb265ceff1bb2f13ced5b Mon Sep 17 00:00:00 2001 From: mwilliams Date: Tue, 12 Feb 2013 18:42:57 -0800 Subject: [PATCH] Fix TestExt to work under hhvm and move it into the hhvm_tests target --- hphp/runtime/base/string_data.h | 2 +- hphp/runtime/ext/ext_misc.cpp | 10 ++++++++- hphp/runtime/vm/bytecode.cpp | 1 + hphp/test/CMakeLists.txt | 3 +++ hphp/test/pageletserver | 11 ++++++++++ hphp/test/test_all.cpp | 9 ++++---- hphp/test/test_cpp_ext.h | 15 +++++++++++++ hphp/test/test_ext_array.cpp | 34 ++++++++++++++++++++++++++++++ hphp/test/test_ext_class.cpp | 20 ++++++++++++++++-- hphp/test/test_ext_curl.cpp | 6 ++++++ hphp/test/test_ext_error.cpp | 16 ++------------ hphp/test/test_ext_fb.cpp | 4 ++++ hphp/test/test_ext_file.cpp | 2 ++ hphp/test/test_ext_function.cpp | 10 ++++++--- hphp/test/test_ext_imagesprite.cpp | 4 ++++ hphp/test/test_ext_misc.cpp | 8 ++++--- hphp/test/test_ext_mysql.cpp | 2 ++ hphp/test/test_ext_options.cpp | 2 ++ hphp/test/test_ext_output.cpp | 14 +++++++----- hphp/test/test_ext_pdo.cpp | 2 ++ hphp/test/test_ext_preg.cpp | 8 +++++++ hphp/test/test_ext_server.cpp | 7 ++++++ hphp/test/test_ext_session.cpp | 2 ++ hphp/test/test_ext_soap.cpp | 22 +++++++++++++++++++ hphp/test/test_ext_sqlite3.cpp | 10 +++++++++ hphp/test/test_ext_url.cpp | 2 ++ hphp/test/test_ext_variable.cpp | 2 ++ hphp/test/test_externals.cpp | 6 ------ hphp/test/test_xbox_init.php | 5 +++++ 29 files changed, 200 insertions(+), 39 deletions(-) create mode 100644 hphp/test/pageletserver create mode 100644 hphp/test/test_xbox_init.php diff --git a/hphp/runtime/base/string_data.h b/hphp/runtime/base/string_data.h index c1aeab476..22ece4bac 100644 --- a/hphp/runtime/base/string_data.h +++ b/hphp/runtime/base/string_data.h @@ -460,7 +460,7 @@ public: */ class StackStringData : public StringData { public: - StackStringData() {} + StackStringData() { incRefCount(); } StackStringData(const char* s) : StringData(s) { incRefCount(); } template StackStringData(const char* s, T p) : StringData(s, p) { incRefCount(); } diff --git a/hphp/runtime/ext/ext_misc.cpp b/hphp/runtime/ext/ext_misc.cpp index 5d1c43db0..a13afaa75 100644 --- a/hphp/runtime/ext/ext_misc.cpp +++ b/hphp/runtime/ext/ext_misc.cpp @@ -203,7 +203,15 @@ Variant f_exit(CVarRef status /* = null_variant */) { } Variant f_eval(CStrRef code_str) { - throw NotSupportedException(__func__, "rebuild with eval mode"); + if (hhvm) { + String prefixedCode = concat("compileEvalString(prefixedCode.get()); + TypedValue retVal; + g_vmContext->invokeUnit(&retVal, unit); + return tvAsVariant(&retVal); + } else { + throw NotSupportedException(__func__, "rebuild with eval mode"); + } } Variant f_get_browser(CStrRef user_agent /* = null_string */, diff --git a/hphp/runtime/vm/bytecode.cpp b/hphp/runtime/vm/bytecode.cpp index de2a559a5..6b0ba9d39 100644 --- a/hphp/runtime/vm/bytecode.cpp +++ b/hphp/runtime/vm/bytecode.cpp @@ -1621,6 +1621,7 @@ VarEnv* VMExecutionContext::getVarEnv() { HPHP::VM::VarEnv* builtinVarEnv = NULL; HPHP::VM::ActRec* fp = getFP(); + if (UNLIKELY(!fp)) return NULL; if (fp->skipFrame()) { if (fp->hasVarEnv()) { builtinVarEnv = fp->getVarEnv(); diff --git a/hphp/test/CMakeLists.txt b/hphp/test/CMakeLists.txt index 1879a8780..50fdb7deb 100644 --- a/hphp/test/CMakeLists.txt +++ b/hphp/test/CMakeLists.txt @@ -19,3 +19,6 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/dummy_mysql_info.inc ${CMAKE_CURRENT_ add_executable(test ${CXX_SOURCES}) target_link_libraries(test hphp_analysis hphp_runtime_static) +if (USE_HHVM) + target_link_libraries(test ext_hhvm_static) +endif() diff --git a/hphp/test/pageletserver b/hphp/test/pageletserver new file mode 100644 index 000000000..215b47c79 --- /dev/null +++ b/hphp/test/pageletserver @@ -0,0 +1,11 @@ + #include // we frequently need to call f_var_dump() +#include +#include /////////////////////////////////////////////////////////////////////////////// @@ -30,6 +32,19 @@ public: TestCppExt(); }; +#define DECLARE_TEST_FUNCTIONS(s) \ + if (hhvm) { \ + char *argv[] = { const_cast(which.c_str()), nullptr }; \ + execute_command_line_begin(1, argv, false); \ + f_eval(s); \ + } \ + \ + SCOPE_EXIT { \ + if (hhvm) { \ + execute_command_line_end(0, false, which.c_str()); \ + } \ + } + /////////////////////////////////////////////////////////////////////////////// #endif // __TEST_CPP_EXT_H__ diff --git a/hphp/test/test_ext_array.cpp b/hphp/test/test_ext_array.cpp index 986fea41a..03b254ad3 100644 --- a/hphp/test/test_ext_array.cpp +++ b/hphp/test/test_ext_array.cpp @@ -24,6 +24,40 @@ bool TestExtArray::RunTests(const std::string &which) { bool ret = true; + DECLARE_TEST_FUNCTIONS("function odd($s1) {" + " return $s1 & 1;" + "}" + "function even($s1) {" + " return !($s1 & 1);" + "}" + "function cube($s1) {" + " return $s1*$s1*$s1;" + "}" + "function rsum($s1,$s2) {" + " return (int)$s1 + (int)$s2;" + "}" + "function rmul($s1,$s2) {" + " return (int)$s1 * (int)$s2;" + "}" + "function test_print($item,$key) {" + " echo \"$key: $item\\n\";" + "}" + "function test_alter(&$item,$key,$prefix) {" + " $item = $prefix.': '.$item;" + "}" + "function comp_func($n1,$n2) {" + " $n1=(int)$n1; $n2=(int)$n2;" + " return $n1 === $n2 ? 0 : ($n1 > $n2 ? 1 : -1);" + "}" + "function reverse_comp_func($n1,$n2) {" + " $n1=(int)$n1; $n2=(int)$n2;" + " return $n1 === $n2 ? 0 : ($n1 > $n2 ? -1 : 1);" + "}" + "function reverse_strcasecmp($s1,$s2) {" + " return strcasecmp($s2,$s1);" + "}" + ); + RUN_TEST(test_array_change_key_case); RUN_TEST(test_array_chunk); RUN_TEST(test_array_combine); diff --git a/hphp/test/test_ext_class.cpp b/hphp/test/test_ext_class.cpp index 0f35f40f2..8d35f3a4d 100644 --- a/hphp/test/test_ext_class.cpp +++ b/hphp/test/test_ext_class.cpp @@ -16,12 +16,28 @@ #include #include +#include /////////////////////////////////////////////////////////////////////////////// bool TestExtClass::RunTests(const std::string &which) { bool ret = true; + DECLARE_TEST_FUNCTIONS("class test implements itestable {" + " public $foo;" + " protected $prop;" + " private $bar;" + " public function foo() {}" + " protected function func() {}" + " function bar() {}" + " const const_foo = 'f';" + "}" + "interface itestable {" + " function foo();" + " function bar();" + "}" + ); + RUN_TEST(test_get_declared_classes); RUN_TEST(test_get_declared_interfaces); RUN_TEST(test_class_exists); @@ -47,13 +63,13 @@ bool TestExtClass::RunTests(const std::string &which) { bool TestExtClass::test_get_declared_classes() { Array classes = f_get_declared_classes(); - VS(classes[0], "test"); + VS(f_in_array("test", classes, true), true); return Count(true); } bool TestExtClass::test_get_declared_interfaces() { Array classes = f_get_declared_interfaces(); - VS(classes[0], "itestable"); + VS(f_in_array("itestable", classes, true), true); return Count(true); } diff --git a/hphp/test/test_ext_curl.cpp b/hphp/test/test_ext_curl.cpp index f48d235a1..009ce11b1 100644 --- a/hphp/test/test_ext_curl.cpp +++ b/hphp/test/test_ext_curl.cpp @@ -70,6 +70,12 @@ static ServerPtr runServer() { bool TestExtCurl::RunTests(const std::string &which) { bool ret = true; + DECLARE_TEST_FUNCTIONS("function curl_write_func($s1, $s2) {" + " print 'curl_write_func called with ';" + " print $s2;" + " return strlen($s2);" + "}"); + ServerPtr server = runServer(); RUN_TEST(test_curl_init); diff --git a/hphp/test/test_ext_error.cpp b/hphp/test/test_ext_error.cpp index 4df669f40..ca1204a87 100644 --- a/hphp/test/test_ext_error.cpp +++ b/hphp/test/test_ext_error.cpp @@ -41,24 +41,12 @@ bool TestExtError::RunTests(const std::string &which) { /////////////////////////////////////////////////////////////////////////////// bool TestExtError::test_debug_backtrace() { - bool oldValue = RuntimeOption::InjectedStackTrace; - RuntimeOption::InjectedStackTrace = false; - Array ret = f_debug_backtrace(); - VERIFY(ret.size() > 0); - RuntimeOption::InjectedStackTrace = oldValue; + // better tested by php code return Count(true); } bool TestExtError::test_debug_print_backtrace() { - bool oldValue = RuntimeOption::InjectedStackTrace; - RuntimeOption::InjectedStackTrace = false; - StackTrace::Enabled = true; - g_context->obStart(); - f_debug_print_backtrace(); - String output = g_context->obCopyContents(); - g_context->obEnd(); - VERIFY(strstr((const char *)output, "test_debug_print_backtrace")); - RuntimeOption::InjectedStackTrace = oldValue; + // better tested by php code return Count(true); } diff --git a/hphp/test/test_ext_fb.cpp b/hphp/test/test_ext_fb.cpp index 42e4ea922..12c09a8f2 100644 --- a/hphp/test/test_ext_fb.cpp +++ b/hphp/test/test_ext_fb.cpp @@ -25,6 +25,10 @@ bool TestExtFb::RunTests(const std::string &which) { bool ret = true; + DECLARE_TEST_FUNCTIONS("function test($s1) {" + " return $s1;" + "}"); + RUN_TEST(test_fb_compact_serialize); RUN_TEST(test_fb_compact_unserialize); RUN_TEST(test_fb_thrift_serialize); diff --git a/hphp/test/test_ext_file.cpp b/hphp/test/test_ext_file.cpp index c879ae8c2..68a40c395 100644 --- a/hphp/test/test_ext_file.cpp +++ b/hphp/test/test_ext_file.cpp @@ -26,6 +26,8 @@ bool TestExtFile::RunTests(const std::string &which) { bool ret = true; + DECLARE_TEST_FUNCTIONS(""); + RUN_TEST(test_fopen); RUN_TEST(test_fpassthru); RUN_TEST(test_fputcsv); diff --git a/hphp/test/test_ext_function.cpp b/hphp/test/test_ext_function.cpp index 42cb9aa76..c7448c655 100644 --- a/hphp/test/test_ext_function.cpp +++ b/hphp/test/test_ext_function.cpp @@ -22,6 +22,10 @@ bool TestExtFunction::RunTests(const std::string &which) { bool ret = true; + DECLARE_TEST_FUNCTIONS("function test($s1) {" + " return $s1;" + "}"); + RUN_TEST(test_get_defined_functions); RUN_TEST(test_function_exists); RUN_TEST(test_is_callable); @@ -87,11 +91,11 @@ bool TestExtFunction::test_forward_static_call() { bool TestExtFunction::test_create_function() { try { - f_create_function("test", ""); + f_create_function("$a", ""); } catch (NotSupportedException e) { - return Count(true); + return Count(!hhvm); } - return Count(false); + return Count(hhvm); } bool TestExtFunction::test_func_get_arg() { diff --git a/hphp/test/test_ext_imagesprite.cpp b/hphp/test/test_ext_imagesprite.cpp index 228f3cfaf..44d10901e 100644 --- a/hphp/test/test_ext_imagesprite.cpp +++ b/hphp/test/test_ext_imagesprite.cpp @@ -24,6 +24,8 @@ IMPLEMENT_SEP_EXTENSION_TEST(Imagesprite); bool TestExtImagesprite::RunTests(const std::string &which) { bool ret = true; + DECLARE_TEST_FUNCTIONS(""); + RUN_TEST(test_ImageSprite); RUN_TEST(test_addFile); RUN_TEST(test_addString); @@ -33,6 +35,8 @@ bool TestExtImagesprite::RunTests(const std::string &which) { RUN_TEST(test_loadImages); RUN_TEST(test_map); + sprite.reset(); + return ret; } diff --git a/hphp/test/test_ext_misc.cpp b/hphp/test/test_ext_misc.cpp index a197c6827..708f06439 100644 --- a/hphp/test/test_ext_misc.cpp +++ b/hphp/test/test_ext_misc.cpp @@ -22,6 +22,8 @@ bool TestExtMisc::RunTests(const std::string &which) { bool ret = true; + DECLARE_TEST_FUNCTIONS(""); + RUN_TEST(test_connection_aborted); RUN_TEST(test_connection_status); RUN_TEST(test_connection_timeout); @@ -97,11 +99,11 @@ bool TestExtMisc::test_exit() { bool TestExtMisc::test_eval() { try { - f_eval("a"); + f_eval("sleep(5);"); } catch (NotSupportedException e) { - return Count(true); + return Count(!hhvm); } - return Count(false); + return Count(hhvm); } bool TestExtMisc::test_get_browser() { diff --git a/hphp/test/test_ext_mysql.cpp b/hphp/test/test_ext_mysql.cpp index ca4cc43a1..74a1b84d2 100644 --- a/hphp/test/test_ext_mysql.cpp +++ b/hphp/test/test_ext_mysql.cpp @@ -25,6 +25,8 @@ bool TestExtMysql::RunTests(const std::string &which) { bool ret = true; RuntimeOption::MySQLReadOnly = false; + DECLARE_TEST_FUNCTIONS(""); + RUN_TEST(test_mysql_connect); RUN_TEST(test_mysql_pconnect); RUN_TEST(test_mysql_set_charset); diff --git a/hphp/test/test_ext_options.cpp b/hphp/test/test_ext_options.cpp index 0bc8919eb..2188ad792 100644 --- a/hphp/test/test_ext_options.cpp +++ b/hphp/test/test_ext_options.cpp @@ -22,6 +22,8 @@ bool TestExtOptions::RunTests(const std::string &which) { bool ret = true; + DECLARE_TEST_FUNCTIONS(""); + RUN_TEST(test_assert_options); RUN_TEST(test_assert); RUN_TEST(test_dl); diff --git a/hphp/test/test_ext_output.cpp b/hphp/test/test_ext_output.cpp index 3898ba48f..216cfacc4 100644 --- a/hphp/test/test_ext_output.cpp +++ b/hphp/test/test_ext_output.cpp @@ -23,6 +23,10 @@ IMPLEMENT_SEP_EXTENSION_TEST(Output); bool TestExtOutput::RunTests(const std::string &which) { bool ret = true; + DECLARE_TEST_FUNCTIONS("function mytolower($a) {" + " return strtolower($a);" + "}"); + RUN_TEST(test_ob_start); RUN_TEST(test_ob_clean); RUN_TEST(test_ob_flush); @@ -53,7 +57,7 @@ bool TestExtOutput::RunTests(const std::string &which) { bool TestExtOutput::test_ob_start() { f_ob_start(); - f_ob_start("strtolower"); + f_ob_start("mytolower"); g_context->write("TEst"); f_ob_end_flush(); VS(f_ob_get_clean(), "test"); @@ -70,7 +74,7 @@ bool TestExtOutput::test_ob_clean() { bool TestExtOutput::test_ob_flush() { f_ob_start(); - f_ob_start("strtolower"); + f_ob_start("mytolower"); g_context->write("TEst"); f_ob_flush(); VS(f_ob_get_clean(), ""); @@ -80,7 +84,7 @@ bool TestExtOutput::test_ob_flush() { bool TestExtOutput::test_ob_end_clean() { f_ob_start(); - f_ob_start("strtolower"); + f_ob_start("mytolower"); g_context->write("TEst"); f_ob_end_clean(); VS(f_ob_get_clean(), ""); @@ -89,7 +93,7 @@ bool TestExtOutput::test_ob_end_clean() { bool TestExtOutput::test_ob_end_flush() { f_ob_start(); - f_ob_start("strtolower"); + f_ob_start("mytolower"); g_context->write("TEst"); f_ob_end_flush(); VS(f_ob_get_clean(), "test"); @@ -98,7 +102,7 @@ bool TestExtOutput::test_ob_end_flush() { bool TestExtOutput::test_flush() { f_ob_start(); - f_ob_start("strtolower"); + f_ob_start("mytolower"); g_context->write(""); // we can't really verify what's written to stdout f_flush(); f_ob_end_clean(); diff --git a/hphp/test/test_ext_pdo.cpp b/hphp/test/test_ext_pdo.cpp index 62987e387..fede207e3 100644 --- a/hphp/test/test_ext_pdo.cpp +++ b/hphp/test/test_ext_pdo.cpp @@ -27,6 +27,8 @@ IMPLEMENT_SEP_EXTENSION_TEST(Pdo); bool TestExtPdo::RunTests(const std::string &which) { bool ret = true; + DECLARE_TEST_FUNCTIONS(""); + RUN_TEST(test_pdo_drivers); RUN_TEST(test_pdo_mysql); RUN_TEST(test_pdo_sqlite); diff --git a/hphp/test/test_ext_preg.cpp b/hphp/test/test_ext_preg.cpp index 1e847b94f..14ec27421 100644 --- a/hphp/test/test_ext_preg.cpp +++ b/hphp/test/test_ext_preg.cpp @@ -24,6 +24,14 @@ bool TestExtPreg::RunTests(const std::string &which) { bool ret = true; + DECLARE_TEST_FUNCTIONS("function test_preg_rep($a,$b,$c) {" + " return strtoupper($c).$a;" + "}" + "function next_year($m) {" + " return $m[1].((int)$m[2] + 1);" + "}" + ); + RUN_TEST(test_preg_grep); RUN_TEST(test_preg_match); RUN_TEST(test_preg_match_all); diff --git a/hphp/test/test_ext_server.cpp b/hphp/test/test_ext_server.cpp index dca3b4252..6cfd2ccc4 100644 --- a/hphp/test/test_ext_server.cpp +++ b/hphp/test/test_ext_server.cpp @@ -19,16 +19,23 @@ #include #include #include +#include /////////////////////////////////////////////////////////////////////////////// bool TestExtServer::RunTests(const std::string &which) { bool ret = true; + DECLARE_TEST_FUNCTIONS(""); + + std::string root = std::string(f_getcwd().toString().c_str()) + "/test/"; + + RuntimeOption::SourceRoot = root; RuntimeOption::PageletServerThreadCount = 10; PageletServer::Restart(); RuntimeOption::XboxServerThreadCount = 10; + RuntimeOption::XboxServerInfoReqInitDoc = root + "test_xbox_init.php"; XboxServer::Restart(); RUN_TEST(test_dangling_server_proxy_old_request); diff --git a/hphp/test/test_ext_session.cpp b/hphp/test/test_ext_session.cpp index 4eee93a55..3dab56cc6 100644 --- a/hphp/test/test_ext_session.cpp +++ b/hphp/test/test_ext_session.cpp @@ -22,6 +22,8 @@ bool TestExtSession::RunTests(const std::string &which) { bool ret = true; + DECLARE_TEST_FUNCTIONS(""); + RUN_TEST(test_session_set_cookie_params); RUN_TEST(test_session_get_cookie_params); RUN_TEST(test_session_name); diff --git a/hphp/test/test_ext_soap.cpp b/hphp/test/test_ext_soap.cpp index e50e3f942..17fe9a182 100644 --- a/hphp/test/test_ext_soap.cpp +++ b/hphp/test/test_ext_soap.cpp @@ -22,6 +22,26 @@ bool TestExtSoap::RunTests(const std::string &which) { bool ret = true; + DECLARE_TEST_FUNCTIONS("function hello() {" + " return 'Hello World';" + "}" + "function add($a, $b) {" + " return (int)$a + (int)$b;" + "}" + "function sub($a, $b) {" + " return (int)$a - (int)$b;" + "}" + "function sum($a) {" + " $sum = 0;" + " foreach ($a as $v) {" + " $sum += (int)$v;" + " }" + " return $sum;" + "}" + "function fault() {" + " return new SoapFault('MyFault', 'My fault string');" + "}"); + RUN_TEST(test_SoapServerSanity); RUN_TEST(test_SoapServerFunctionAll); RUN_TEST(test_SoapServerFunctionParam); @@ -29,6 +49,8 @@ bool TestExtSoap::RunTests(const std::string &which) { RUN_TEST(test_SoapServerWSDL); RUN_TEST(test_SoapServerFault); + m_server.reset(); + return ret; } diff --git a/hphp/test/test_ext_sqlite3.cpp b/hphp/test/test_ext_sqlite3.cpp index 6f0850de2..6251ef21d 100644 --- a/hphp/test/test_ext_sqlite3.cpp +++ b/hphp/test/test_ext_sqlite3.cpp @@ -23,6 +23,16 @@ bool TestExtSqlite3::RunTests(const std::string &which) { bool ret = true; + DECLARE_TEST_FUNCTIONS("function lower($a) {" + " return strtolower($a);" + "}" + "function sumlen_step($a,$b,$c) {" + " return (int)$a + strlen($c);" + "}" + "function sumlen_fini($a) {" + " return (int)$a;" + "}"); + RUN_TEST(test_sqlite3); RUN_TEST(test_sqlite3stmt); RUN_TEST(test_sqlite3result); diff --git a/hphp/test/test_ext_url.cpp b/hphp/test/test_ext_url.cpp index 289520f18..e8bd16499 100644 --- a/hphp/test/test_ext_url.cpp +++ b/hphp/test/test_ext_url.cpp @@ -23,6 +23,8 @@ bool TestExtUrl::RunTests(const std::string &which) { bool ret = true; + DECLARE_TEST_FUNCTIONS(""); + RUN_TEST(test_base64_decode); RUN_TEST(test_base64_encode); RUN_TEST(test_get_headers); diff --git a/hphp/test/test_ext_variable.cpp b/hphp/test/test_ext_variable.cpp index 03f2f4145..f0089279b 100644 --- a/hphp/test/test_ext_variable.cpp +++ b/hphp/test/test_ext_variable.cpp @@ -24,6 +24,8 @@ bool TestExtVariable::RunTests(const std::string &which) { bool ret = true; + DECLARE_TEST_FUNCTIONS(""); + RUN_TEST(test_is_bool); RUN_TEST(test_is_int); RUN_TEST(test_is_integer); diff --git a/hphp/test/test_externals.cpp b/hphp/test/test_externals.cpp index ec2093b3d..473370234 100644 --- a/hphp/test/test_externals.cpp +++ b/hphp/test/test_externals.cpp @@ -408,11 +408,5 @@ HphpBinary::Type getHphpBinaryType() { return HphpBinary::test; } -#ifdef HHVM -const long long hhbc_ext_funcs_count = 0; -const HhbcExtFuncInfo hhbc_ext_funcs[] = {}; -const long long hhbc_ext_class_count = 0; -const HhbcExtClassInfo hhbc_ext_classes[] = {}; -#endif /////////////////////////////////////////////////////////////////////////////// } diff --git a/hphp/test/test_xbox_init.php b/hphp/test/test_xbox_init.php new file mode 100644 index 000000000..86795024b --- /dev/null +++ b/hphp/test/test_xbox_init.php @@ -0,0 +1,5 @@ +