diff --git a/Jenkinsfile b/Jenkinsfile index 6d85a6f7d1..fa237b4824 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -54,7 +54,7 @@ def cmake_build(Map conf=[:]){ def package_build = (conf.get("package_build","") == "true") if (package_build == true) { - make_targets = "miopen_gtest package" + make_targets = "miopen_gtest package miopen_gtest_check" setup_args = " -DMIOPEN_TEST_DISCRETE=OFF " + setup_args } @@ -557,7 +557,7 @@ pipeline { NOMLIR_flags = " -DMIOPEN_USE_MLIR=Off" } triggers{ - + cron(env.BRANCH_NAME == env.NIGHTLY_BRANCH ? env.NIGHTLY_SCHEDULE : '') } stages{ diff --git a/test/gtest/CMakeLists.txt b/test/gtest/CMakeLists.txt index a6adc051b9..83ef61f18f 100644 --- a/test/gtest/CMakeLists.txt +++ b/test/gtest/CMakeLists.txt @@ -38,7 +38,7 @@ function(add_gtest TEST_NAME TEST_CPP) if(hipblaslt_FOUND) target_link_libraries( ${TEST_NAME} roc::hipblaslt ) endif() - # Workaround : change in rocm-cmake was causing linking error so had to add ${CMAKE_DL_LIBS} + # Workaround : change in rocm-cmake was causing linking error so had to add ${CMAKE_DL_LIBS} # We can remove ${CMAKE_DL_LIBS} once root cause is identified. target_link_libraries(${TEST_NAME} ${CMAKE_DL_LIBS} GTest::gtest GTest::gtest_main MIOpen ${Boost_LIBRARIES} hip::host $ ) if(NOT MIOPEN_EMBED_DB STREQUAL "") @@ -107,6 +107,20 @@ else() add_gtest(miopen_gtest "${TESTS_CPP}") + add_custom_command( + OUTPUT test_list + COMMAND miopen_gtest --gtest_list_tests > test_list + COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/check_names.py --list test_list + DEPENDS miopen_gtest ${CMAKE_CURRENT_SOURCE_DIR}/check_names.py + COMMENT "Checking test names" + VERBATIM + ) + + add_custom_target( + miopen_gtest_check + DEPENDS test_list + ) + if( NOT ENABLE_ASAN_PACKAGING ) install(TARGETS miopen_gtest PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE diff --git a/test/gtest/check_names.py b/test/gtest/check_names.py new file mode 100755 index 0000000000..9762970db0 --- /dev/null +++ b/test/gtest/check_names.py @@ -0,0 +1,110 @@ +#!/usr/bin/env python3 +############################################################################### +# +# MIT License +# +# Copyright (c) 2024 Advanced Micro Devices, Inc. +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +# +################################################################################# + +"""gtest name linter""" +import re +import sys +import argparse +from collections import defaultdict +import logging + +logging.basicConfig(level=logging.WARNING) +logger = logging.getLogger("GTest name checker") + +"""regexp based on https://github.com/ROCm/MIOpen/wiki/GTest-development#naming""" +re_prefix = re.compile(r"^((Smoke)|(Full)|(Perf)|(Unit.*))$") +re_hw = re.compile(r"^((CPU)|(GPU))$") +re_datatype = re.compile( + r"^((FP((8)|(16)|(32)|(64)))|(BFP((8)|(16)))|(I((8)|(32)))|(NONE))\.$" +) + + +def parse_args(): + """Function to parse cmd line arguments""" + parser = argparse.ArgumentParser() + + parser.add_argument( + "--list", + dest="list", + type=str, + required=True, + help="Specify gtest test list file", + ) + args = parser.parse_args() + + return args + + +def parse_tests(args): + + mismatches = defaultdict(str) + + with open(args.list) as fp: + for line in fp.readlines()[2:]: + if not line.strip(): + continue + if line[0] == " ": + continue + line = line.split("#")[0].strip() + + full_name = line.split("/") + + if len(full_name) == 2: + prefix = re.search(re_prefix, full_name[0]) + name = full_name[1].split("_") + else: + prefix = ["empty"] + name = full_name[0].split("_") + + hw = re.search(re_hw, name[0]) + datatype = re.search(re_datatype, name[-1]) + if not prefix: + mismatches[line] += " Prefix" + if not hw: + mismatches[line] += " Hw" + if not datatype: + mismatches[line] += " Datatype" + + for l, k in mismatches.items(): + logger.warning("Name: " + l + " Mismatch types:" + k) + + if mismatches: + logger.critical( + "Tests do not match to the test naming scheme (see https://github.com/ROCm/MIOpen/wiki/GTest-development#naming )" + ) + # return -1 # uncomment when all the tests will be renamed + return 0 + + +def main(): + """Main function""" + args = parse_args() + return parse_tests(args) + + +if __name__ == "__main__": + sys.exit(main())