Skip to content

Commit

Permalink
Enable runtime/test build for OSS.
Browse files Browse the repository at this point in the history
Summary:
The GTest based tests under hphp/runtime/test were previously not
built under the OSS build. This patch adds the CMake support which
is enabled with -DRUNTIME_TEST_BIN=on. The results is a binary,
hphp_runtime_test.

Additionally the tests were ported to ARM.
Closes facebook#7793

Differential Revision: D4949257

Pulled By: Orvid

fbshipit-source-id: 7b257f0948db63f2148a534f9f20af72895072f8
  • Loading branch information
dave-estes-QCOM authored and hhvm-bot committed May 2, 2017
1 parent 1a1273d commit 0877fc4
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ hphp.log
/hphp/runtime/ext/*/CMakeLists.txt
/hphp/runtime/ext/*/*.so

/hphp/runtime/test/hphp_runtime_test

/hphp/runtime/tmp/string

/hphp/hhvm/gen
Expand Down
7 changes: 7 additions & 0 deletions hphp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,13 @@ add_subdirectory(parser)

add_subdirectory(runtime)
add_subdirectory(runtime/ext)

# The runtime/test binary require GTest and GMock to be installed globally
option(RUNTIME_TEST_BIN "Create the HHVM runtime/test binary" OFF)
if (RUNTIME_TEST_BIN)
add_subdirectory(runtime/test)
endif ()

if (ENABLE_ZEND_COMPAT)
add_subdirectory(runtime/ext_zend_compat)
endif()
Expand Down
23 changes: 23 additions & 0 deletions hphp/runtime/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
find_package(GTest REQUIRED)
include_directories(${GTEST_INCLUDE_DIRS})

set(CXX_SOURCES)
auto_sources(files "*.cpp" "RECURSE" "${CMAKE_CURRENT_SOURCE_DIR}")
list(APPEND CXX_SOURCES ${files} "${CMAKE_CURRENT_SOURCE_DIR}/../../hhvm/process-init.cpp")

set(HEADER_SOURCES)
auto_sources(files "*.h" "RECURSE" "${CMAKE_CURRENT_SOURCE_DIR}")
list(APPEND HEADER_SOURCES ${files})

add_executable(hphp_runtime_test ${CXX_SOURCES} ${HEADER_SOURCES})
link_object_libraries(hphp_runtime_test ${HHVM_WHOLE_ARCHIVE_LIBRARIES})
target_link_libraries(hphp_runtime_test ${HHVM_LINK_LIBRARIES} gtest gmock)
embed_all_systemlibs(hphp_runtime_test "${CMAKE_CURRENT_BINARY_DIR}/../.."
"${CMAKE_CURRENT_BINARY_DIR}/hphp_runtime_test")

auto_source_group("hphp_runtime_test" "${CMAKE_CURRENT_SOURCE_DIR}"
${CXX_SOURCES} ${HEADER_SOURCES})
add_dependencies(hphp_runtime_test hphp_system)
if (ENABLE_COTIRE)
cotire(hphp_runtime_test)
endif()
29 changes: 21 additions & 8 deletions hphp/runtime/test/vasm-xls-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

#include "hphp/runtime/vm/jit/abi.h"
#include "hphp/runtime/vm/jit/abi-arm.h"
#include "hphp/runtime/vm/jit/abi-x64.h"
#include "hphp/runtime/vm/jit/containers.h"
#include "hphp/runtime/vm/jit/vasm.h"
Expand All @@ -32,7 +33,15 @@ using namespace reg;

template<class T> uint64_t test_const(T val) {
using testfunc = double (*)();
static const Abi test_abi = {
static const Abi test_abi_arm = {
.gpUnreserved = RegSet{},
.gpReserved = arm::abi().gp(),
.simdUnreserved = RegSet{vixl::d0},
.simdReserved = arm::abi().simd() - RegSet{vixl::d0},
.calleeSaved = arm::abi().calleeSaved,
.sf = arm::abi().sf
};
static const Abi test_abi_x64 = {
.gpUnreserved = RegSet{},
.gpReserved = x64::abi().gp(),
.simdUnreserved = RegSet{xmm0},
Expand Down Expand Up @@ -67,13 +76,17 @@ template<class T> uint64_t test_const(T val) {
v << copy{v.cns(val), Vreg{xmm0}};
v << ret{RegSet{xmm0}};

optimizeX64(vasm.unit(), test_abi, true /* regalloc */);
CGMeta fixups;

emitX64(unit, text, fixups, nullptr);
// The above code might use fixups.literals but shouldn't use anything else.
fixups.literals.clear();
EXPECT_TRUE(fixups.empty());
CGMeta meta;
if (arch() == Arch::ARM) {
optimizeARM(vasm.unit(), test_abi_arm, true /* regalloc */);
emitARM(unit, text, meta, nullptr);
} else if (arch() == Arch::X64) {
optimizeX64(vasm.unit(), test_abi_x64, true /* regalloc */);
emitX64(unit, text, meta, nullptr);
}
// The above code might use meta.literals but shouldn't use anything else.
meta.literals.clear();
EXPECT_TRUE(meta.empty());

union { double d; uint64_t c; } u;
u.d = ((testfunc)code)();
Expand Down

0 comments on commit 0877fc4

Please sign in to comment.