Skip to content

[tests] Enable MLIR C++ unittest with lit #50

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

Merged
merged 6 commits into from
May 11, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion .github/workflows/build-llvm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
run: |
mkdir llvm-install
cmake -G Ninja llvm -B build -DCMAKE_INSTALL_PREFIX=llvm-install \
-DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_ASSERTIONS=true -DLLVM_ENABLE_PROJECTS="mlir" -DLLVM_TARGETS_TO_BUILD="X86" -DLLVM_INSTALL_UTILS=true -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
-DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_ASSERTIONS=true -DLLVM_ENABLE_PROJECTS="mlir" -DLLVM_TARGETS_TO_BUILD="X86" -DLLVM_INSTALL_UTILS=true -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DLLVM_INSTALL_GTEST=ON
cmake --build build --target install
cd llvm-install
tar -zcf ../llvm.tgz .
Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,5 @@ set(GC_LIB_LINKED_LIBS
)
target_link_libraries(graph_compiler PRIVATE ${GC_LIB_LINKED_LIBS})

add_subdirectory(unittests)
add_subdirectory(test)
8 changes: 8 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,18 @@ configure_lit_site_cfg(
${CMAKE_CURRENT_SOURCE_DIR}/lit.cfg.py
)

configure_lit_site_cfg(
${CMAKE_CURRENT_SOURCE_DIR}/gc/Unit/lit.site.cfg.py.in
${CMAKE_CURRENT_BINARY_DIR}/gc/Unit/lit.site.cfg.py
MAIN_CONFIG
${CMAKE_CURRENT_SOURCE_DIR}/gc/Unit/lit.cfg.py
)

set(GC_OPT_TEST_DEPENDS
FileCheck count not
# mlir-gen
gc-opt
GCUnitTests
)

add_lit_testsuite(gc-check "Running the regression tests"
Expand Down
50 changes: 50 additions & 0 deletions test/gc/Unit/lit.cfg.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# -*- Python -*-

# Configuration file for the 'lit' test runner.

import os
import subprocess

import lit.formats

# name: The name of this test suite.
config.name = "GC-Unit"

# suffixes: A list of file extensions to treat as test files.
config.suffixes = []

# test_source_root: The root path where tests are located.
# test_exec_root: The root path where tests should be run.
config.test_exec_root = os.path.join(config.gc_obj_root, "unittests")
config.test_source_root = config.test_exec_root

# testFormat: The test format to use to interpret tests.
config.test_format = lit.formats.GoogleTest(config.llvm_build_mode, "Tests")

# Propagate the temp directory. Windows requires this because it uses \Windows\
# if none of these are present.
if "TMP" in os.environ:
config.environment["TMP"] = os.environ["TMP"]
if "TEMP" in os.environ:
config.environment["TEMP"] = os.environ["TEMP"]

# Propagate HOME as it can be used to override incorrect homedir in passwd
# that causes the tests to fail.
if "HOME" in os.environ:
config.environment["HOME"] = os.environ["HOME"]

# Propagate sanitizer options.
for var in [
"ASAN_SYMBOLIZER_PATH",
"HWASAN_SYMBOLIZER_PATH",
"MSAN_SYMBOLIZER_PATH",
"TSAN_SYMBOLIZER_PATH",
"UBSAN_SYMBOLIZER_PATH",
"ASAN_OPTIONS",
"HWASAN_OPTIONS",
"MSAN_OPTIONS",
"TSAN_OPTIONS",
"UBSAN_OPTIONS",
]:
if var in os.environ:
config.environment[var] = os.environ[var]
12 changes: 12 additions & 0 deletions test/gc/Unit/lit.site.cfg.py.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
@LIT_SITE_CFG_IN_HEADER@

import sys

config.llvm_tools_dir = lit_config.substitute("@LLVM_TOOLS_DIR@")
config.llvm_build_mode = lit_config.substitute("@LLVM_BUILD_MODE@")
config.mlir_obj_root = "@MLIR_BINARY_DIR@"
config.gc_src_root = "@CMAKE_SOURCE_DIR@"
config.gc_obj_root = "@CMAKE_BINARY_DIR@"

# Let the main config do the real work.
lit_config.load_config(config, "@CMAKE_SOURCE_DIR@/test/gc/Unit/lit.cfg.py")
18 changes: 18 additions & 0 deletions unittests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
if (NOT GC_TEST_ENABLE)
message(STATUS "The unittests are not enabled.")
return()
endif ()

add_definitions(-DMLIR_INCLUDE_TESTS)
add_custom_target(GCUnitTests)
set_target_properties(GCUnitTests PROPERTIES FOLDER "MLIR GC Tests")

# To silence warning caused by Wundef.
add_definitions(-DGTEST_NO_LLVM_SUPPORT=0)

function(add_mlir_unittest test_dirname)
add_unittest(GCUnitTests ${test_dirname} ${ARGN})
endfunction()

add_subdirectory(Example)

6 changes: 6 additions & 0 deletions unittests/Example/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
add_mlir_unittest(GCExampleTests
Example.cpp
)
target_link_libraries(GCExampleTests
PRIVATE
MLIRLinalgx)
14 changes: 14 additions & 0 deletions unittests/Example/Example.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//===- Example.cpp - Tests for Example ------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "gc/Dialect/Linalgx/LinalgxDialect.h"
#include "gtest/gtest.h"

TEST(example, HelloWorld) {
ASSERT_EQ(mlir::linalgx::LinalgxDialect::getDialectNamespace(), "linalgx");
}