Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sl/google test #1611

Merged
merged 15 commits into from
Aug 30, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
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
39 changes: 39 additions & 0 deletions cmake/googletest.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
include(FetchContent)

set(GOOGLETEST_DIR "" CACHE STRING "Location of local GoogleTest repo to build against")

if(GOOGLETEST_DIR)
set(FETCHCONTENT_SOURCE_DIR_GOOGLETEST ${GOOGLETEST_DIR} CACHE STRING "GoogleTest source directory override")
endif()

message(STATUS "Fetching GoogleTest")

list(APPEND GTEST_CMAKE_CXX_FLAGS
-Wno-undef
-Wno-reserved-identifier
-Wno-global-constructors
-Wno-missing-noreturn
-Wno-disabled-macro-expansion
-Wno-used-but-marked-unused
-Wno-switch-enum
-Wno-zero-as-null-pointer-constant
-Wno-unused-member-function
-Wno-comma
-Wno-old-style-cast
)
message(STATUS "Suppressing googltest warnings with flags: ${GTEST_CMAKE_CXX_FLAGS}")

FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG e2239ee6043f73722e7aa812a459f54a28552929
)
xinlipn marked this conversation as resolved.
Show resolved Hide resolved

# Will be necessary for windows build
# set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)

target_compile_options(gtest PRIVATE ${GTEST_CMAKE_CXX_FLAGS})
target_compile_options(gtest_main PRIVATE ${GTEST_CMAKE_CXX_FLAGS})
target_compile_options(gmock PRIVATE ${GTEST_CMAKE_CXX_FLAGS})
target_compile_options(gmock_main PRIVATE ${GTEST_CMAKE_CXX_FLAGS})
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1737,3 +1737,4 @@ add_custom_test(test_regression_half_mi200 GFX900_DISABLED GFX906_DISABLED GFX90
# Issue-internal #4
COMMAND ${ENVS_FIND_ONLY_HIP_IGEMM_V4R4XDLOPS} $<TARGET_FILE:test_conv2d> ${MIOPEN_TEST_FLOAT_ARG} --cmode conv --pmode default --input 120 64 75 75 --weights 128 64 1 1 --pads_strides_dilations 0 0 2 2 1 1 ${ARGS_ENABLE_FORWARD_ONLY}
)
add_subdirectory(gtest)
23 changes: 23 additions & 0 deletions test/gtest/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
include(googletest) #include googletest.cmake
enable_testing()
include(GoogleTest)

#add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure -C ${CMAKE_CFG_INTDIR})
#add_custom_target(tests)

function(add_gtest TEST_NAME)
message("Adding Test: " ${TEST_NAME})
add_executable(test_${TEST_NAME} ${TEST_NAME}.cpp )
add_dependencies(tests test_${TEST_NAME})
add_dependencies(check test_${TEST_NAME})
target_compile_options(test_${TEST_NAME} PRIVATE -Wno-global-constructors -Wno-undef)
JehandadKhan marked this conversation as resolved.
Show resolved Hide resolved
target_link_libraries(test_${TEST_NAME} gtest_main MIOpen ${Boost_LIBRARIES} hip::host $<BUILD_INTERFACE:roc::rocblas>)
#Enable CMake to discover the test binary
gtest_discover_tests(test_${TEST_NAME})
endfunction()

file(GLOB TESTS *.cpp)
foreach(TEST ${TESTS})
get_filename_component(BASE_NAME ${TEST} NAME_WE)
add_gtest(${BASE_NAME})
endforeach()
25 changes: 19 additions & 6 deletions test/activation.cpp → test/gtest/activation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* SOFTWARE.
*
*******************************************************************************/
#include "test.hpp"
#include "../test.hpp"
#include <array>
#include <iostream>
#include <iterator>
Expand All @@ -35,10 +35,12 @@
#include <miopen/tensor.hpp>
#include <utility>

#include "driver.hpp"
#include "get_handle.hpp"
#include "tensor_holder.hpp"
#include "verify.hpp"
#include "../driver.hpp"
#include "../get_handle.hpp"
#include "../tensor_holder.hpp"
#include "../verify.hpp"

#include <gtest/gtest.h>

std::string to_name(miopenActivationMode_t m)
{
Expand Down Expand Up @@ -315,4 +317,15 @@ struct activation_driver : test_driver
}
};

int main(int argc, const char* argv[]) { test_drive<activation_driver>(argc, argv); }
//GoogleTest for activation
TEST(TestActivation, BasicAssertions)
{
auto marker = 0;
int argc = 2;
const char* argv[] = {"test_activation", "--float"};

test_drive<activation_driver>(argc, argv);

++marker;
EXPECT_TRUE(marker == 1) << "test_activation failed";
}
18 changes: 13 additions & 5 deletions test/cache.cpp → test/gtest/cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@
#include <miopen/temp_file.hpp>

#include <miopen/md5.hpp>
#include "test.hpp"
#include "random.hpp"
#include "../test.hpp"
#include "../random.hpp"

#include <gtest/gtest.h>

#if MIOPEN_ENABLE_SQLITE
std::string random_string(size_t length)
Expand Down Expand Up @@ -145,13 +147,19 @@ void check_cache_str()
CHECK(p.filename().string() == name + ".o");
}

int main()
//Google Test
TEST(TestCache, BasicAssertions)
{
auto marker = 0;
check_cache_file();
check_cache_str();
++marker;
EXPECT_TRUE(marker == 1) << "Check_cache_file or check_cache_str failed ";
#if MIOPEN_ENABLE_SQLITE
check_bz2_compress();
check_bz2_decompress();
check_bz2_compress();
check_bz2_decompress();
check_kern_db();
++marker;
EXPECT_TRUE(marker == 2) << "check_bz2_compress or check_bz2_decompress or check_kern_db failed ";
#endif
}
29 changes: 29 additions & 0 deletions test/gtest/hello_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <gtest/gtest.h>
#include <miopen/miopen.h>
#include <miopen/solver_id.hpp>

//Todo: Reduced duplicated code from cache.cpp
//E.g. declare extern check_cache() in cache. cpp and declare dependency on cache.cpp?

// Demonstrate some basic assertions.
//Todo: Include a simple task
//TEST_F()?: use the same data configuration for multiple tests

TEST(HelloTest, BasicAssertions)
{

// Expect two strings not to be equal.
EXPECT_STRNE("hello", "world");
// Expect equality.
EXPECT_EQ(7 * 6, 42);

// Check if we can access MIOpen internals
auto idx = 0;
for(const auto& solver_id :
miopen::solver::GetSolversByPrimitive(miopen::solver::Primitive::Convolution))
{
std::ignore = solver_id;
++idx;
}
EXPECT_GT(idx, 0);
xinlipn marked this conversation as resolved.
Show resolved Hide resolved
}