Skip to content

Commit

Permalink
Various googletest related fixes (ROCm#210)
Browse files Browse the repository at this point in the history
* Explicitly setting gtest to point to local install vs system installation

* Recovering install script

* Correcting check for googletest via cmake

* Fix typo

* Make GTest check not quiet

* Temp force download

* Setting appropriate compiler override for gtest on windows

* Disabling compiler override for linux

* Cleanup of code, use cmake for centos ci pipeline

* make cento use ctest, not ctest3. revert cmake3 change

* Updating check for gtest

* Simplifying GTest check

* Updating gtest check for Windows

* Updating hipCUB tests to use Gtest targets
  • Loading branch information
stanleytsang-amd authored Sep 9, 2022
1 parent a33f31c commit 548ed26
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 59 deletions.
7 changes: 3 additions & 4 deletions .jenkins/common.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
def runCompileCommand(platform, project, jobName, boolean debug=false, boolean sameOrg=true)
{
project.paths.construct_build_prefix()

String buildTypeArg = debug ? '-DCMAKE_BUILD_TYPE=Debug' : '-DCMAKE_BUILD_TYPE=Release'
String buildTypeDir = debug ? 'debug' : 'release'
String cmake = platform.jenkinsLabel.contains('centos') ? 'cmake3' : 'cmake'
Expand All @@ -22,17 +22,16 @@ def runCompileCommand(platform, project, jobName, boolean debug=false, boolean s
${cmake} -DCMAKE_CXX_COMPILER=/opt/rocm/bin/hipcc ${buildTypeArg} ${amdgpuTargets} -DBUILD_TEST=ON -DBUILD_BENCHMARK=ON ../..
make -j\$(nproc)
"""

platform.runCommand(this, command)
}


def runTestCommand (platform, project)
{
String sudo = auxiliary.sudo(platform.jenkinsLabel)
String centos = platform.jenkinsLabel.contains('centos') ? '3' : ''

def testCommand = "ctest${centos} --output-on-failure"
def testCommand = "ctest --output-on-failure"
def command = """#!/usr/bin/env bash
set -x
cd ${project.paths.project_build_prefix}
Expand Down
11 changes: 5 additions & 6 deletions cmake/Dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,14 @@ endif()
if(BUILD_TEST)
if(NOT DEPENDENCIES_FORCE_DOWNLOAD)
# Google Test (https://github.com/google/googletest)
find_package(GTest QUIET)
find_package(GTest 1.11.0 CONFIG)
endif()

if(NOT TARGET GTest::GTest AND NOT TARGET GTest::gtest)
if(NOT GTest_FOUND)
message(STATUS "GTest not found or force download GTest on. Downloading and building GTest.")
# Google Test (https://github.com/google/googletest)
if(NOT (CMAKE_CXX_COMPILER_ID STREQUAL "GNU"))
# hip-clang cannot compile googletest for some reason
set(COMPILER_OVERRIDE "-DCMAKE_CXX_COMPILER=g++")
if(WIN32)
set(COMPILER_OVERRIDE "-DCMAKE_CXX_COMPILER=cl")
endif()
set(GTEST_ROOT ${CMAKE_CURRENT_BINARY_DIR}/gtest CACHE PATH "")
download_project(
Expand All @@ -143,7 +142,7 @@ if(BUILD_TEST)
BUILD_PROJECT TRUE
UPDATE_DISCONNECTED TRUE # Never update automatically from the remote repository
)
find_package(GTest REQUIRED)
find_package(GTest 1.11.0 EXACT REQUIRED MODULE)
endif()
endif()

Expand Down
78 changes: 39 additions & 39 deletions install
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ function display_help()
echo " [-i|--install] install after build"
echo " [-p|--package build package"
echo " [-r]--relocatable] create a package to support relocatable ROCm"
#Not implemented yet
# echo " [-d|--dependencies] install build dependencies"
echo " [-d|--dependencies] install build dependencies"
echo " [-c|--clients] build library clients too (combines with -i & -d)"
echo " [-g|--debug] -DCMAKE_BUILD_TYPE=Debug (default is =Release)"
echo " [--hip-clang] build library for amdgpu backend using hip-clang"
Expand All @@ -33,6 +32,7 @@ build_hip_clang=false
run_tests=false
rocm_path=/opt/rocm
build_relocatable=false
install_dependencies=false
build_address_sanitizer=false
build_freorg_bkwdcomp=true

Expand All @@ -43,7 +43,7 @@ build_freorg_bkwdcomp=true
# check if we have a modern version of getopt that can handle whitespace and long parameters
getopt -T
if [[ $? -eq 4 ]]; then
GETOPT_PARSE=$(getopt --name "${0}" --longoptions help,install,clients,debug,hip-clang,test,package,relocatable,address-sanitizer,rm-legacy-include-dir --options hicdtpr -- "$@")
GETOPT_PARSE=$(getopt --name "${0}" --longoptions help,install,clients,debug,hip-clang,test,package,relocatable,dependencies,address-sanitizer,rm-legacy-include-dir --options hicdtpr -- "$@")
else
echo "Need a new version of getopt"
exit 1
Expand All @@ -65,41 +65,44 @@ check_exit_code( )

while true; do
case "${1}" in
-h|--help)
display_help
exit 0
;;
-i|--install)
install_package=true
shift ;;
-p|--package)
build_package=true
shift ;;
-c|--clients)
build_clients=true
shift ;;
-r|--relocatable)
build_relocatable=true
shift ;;
-g|--debug)
build_release=false
shift ;;
-t|--test)
run_tests=true
shift ;;
--hip-clang)
build_hip_clang=true
shift ;;
-h|--help)
display_help
exit 0
;;
-i|--install)
install_package=true
shift ;;
-p|--package)
build_package=true
shift ;;
-c|--clients)
build_clients=true
shift ;;
-r|--relocatable)
build_relocatable=true
shift ;;
-g|--debug)
build_release=false
shift ;;
-t|--test)
run_tests=true
shift ;;
-d|--dependencies)
install_dependencies=true
shift ;;
--hip-clang)
build_hip_clang=true
shift ;;
--address-sanitizer)
build_address_sanitizer=true
shift ;;
--rm-legacy-include-dir)
--rm-legacy-include-dir)
build_freorg_bkwdcomp=false
shift ;;
--) shift ; break ;;
*) echo "Unexpected command line parameter received; aborting";
exit 1
;;
--) shift ; break ;;
*) echo "Unexpected command line parameter received; aborting";
exit 1
;;
esac
done

Expand Down Expand Up @@ -149,11 +152,8 @@ if [[ "${build_address_sanitizer}" == true ]]; then
cmake_common_options="$cmake_common_options -DBUILD_ADDRESS_SANITIZER=ON"
fi

#Enable backward compatibility wrappers
if [[ "${build_freorg_bkwdcomp}" == true ]]; then
cmake_common_options="${cmake_common_options} -DBUILD_FILE_REORG_BACKWARD_COMPATIBILITY=ON"
else
cmake_common_options="${cmake_common_options} -DBUILD_FILE_REORG_BACKWARD_COMPATIBILITY=OFF"
if ($install_dependencies); then
cmake_common_options="${cmake_common_options} -DDEPENDENCIES_FORCE_DOWNLOAD=ON"
fi

if [[ "${build_relocatable}" == true ]]; then
Expand Down Expand Up @@ -188,4 +188,4 @@ if ($build_package); then
# Package
make package -j$(nproc)
check_exit_code "$?"
fi
fi
21 changes: 11 additions & 10 deletions test/hipcub/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,12 @@ function(add_hipcub_test_internal TEST_NAME TEST_SOURCES TEST_TARGET)
add_executable(${TEST_TARGET} ${TEST_SOURCES})
target_include_directories(${TEST_TARGET} SYSTEM BEFORE
PUBLIC
$<BUILD_INTERFACE:${GTEST_INCLUDE_DIRS}>
GoogleTest>
)
target_link_libraries(${TEST_TARGET}
PRIVATE
${GTEST_BOTH_LIBRARIES}
GTest::gtest
GTest::gtest_main
hipcub
)

Expand Down Expand Up @@ -103,9 +104,9 @@ endfunction()
# Replacement for add_hipcub_test that splits up test cases allowing them to be compiled in parallel.
# A single .cpp.in file is provided containing valid C++ code with the addition of slice definitions.
# The slice definitions HIPCUB_TEST_SLICE, HIPCUB_TEST_SUITE_SLICE, and HIPCUB_TEST_TYPE_SLICE demarkate
# slices of non-typed tests, typed test suites, and test types respectively. The slice cases must be
# marked with an "(el)if" statement (no "else") that has a unique value to ensure that the correct slice
# gets enabled. This function will generate a separate .cpp file for all non-typed test slices and the
# slices of non-typed tests, typed test suites, and test types respectively. The slice cases must be
# marked with an "(el)if" statement (no "else") that has a unique value to ensure that the correct slice
# gets enabled. This function will generate a separate .cpp file for all non-typed test slices and the
# product of the typed test suites and test types.
#
# This example will generate five files:
Expand All @@ -118,18 +119,18 @@ endfunction()
# DEFINE_NAMED_TEST(TestSuiteName, NonTypedTest)
# #endif
# #if HIPCUB_TEST_SUITE_SLICE == 0
# REGISTER_TYPED_TEST(TestSuiteName, TestZero, test_zero)
# REGISTER_TYPED_TEST(TestSuiteName, TestZero, test_zero)
# REGISTER_TYPED_TEST_SUITE(TestSuiteName, TestZero)
# #elif HIPCUB_TEST_SUITE_SLICE == 1
# REGISTER_TYPED_TEST(TestSuiteName, TestOne, test_one)
# REGISTER_TYPED_TEST(TestSuiteName, TestTwo, test_two)
# REGISTER_TYPED_TEST(TestSuiteName, TestOne, test_one)
# REGISTER_TYPED_TEST(TestSuiteName, TestTwo, test_two)
# REGISTER_TYPED_TEST_SUITE(TestSuiteName, TestOne, TestTwo)
# #endif
# #if HIPCUB_TEST_TYPE_SLICE == 0
# INSTANTIATE_TYPED_TEST(TestSuiteName, double)
# #elif HIPCUB_TEST_TYPE_SLICE == 1
# INSTANTIATE_TYPED_TEST(TestSuiteName, float)
# INSTANTIATE_TYPED_TEST(TestSuiteName, int)
# INSTANTIATE_TYPED_TEST(TestSuiteName, float)
# INSTANTIATE_TYPED_TEST(TestSuiteName, int)
# #endif
function(add_hipcub_test_parallel TEST_NAME TEST_SOURCE)
get_hipcub_test_target(${TEST_SOURCE} TEST_TARGET)
Expand Down

0 comments on commit 548ed26

Please sign in to comment.