Skip to content

Commit 23a4bba

Browse files
author
Menooker
authored
[tests] Enable MLIR C++ unittest with lit (#50)
1 parent 629c3df commit 23a4bba

File tree

9 files changed

+110
-1
lines changed

9 files changed

+110
-1
lines changed

.github/workflows/build-llvm.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
run: |
2727
mkdir llvm-install
2828
cmake -G Ninja llvm -B build -DCMAKE_INSTALL_PREFIX=llvm-install \
29-
-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
29+
-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
3030
cmake --build build --target install
3131
cd llvm-install
3232
tar -zcf ../llvm.tgz .

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,5 @@ set(GC_LIB_LINKED_LIBS
5656
)
5757
target_link_libraries(graph_compiler PRIVATE ${GC_LIB_LINKED_LIBS})
5858

59+
add_subdirectory(unittests)
5960
add_subdirectory(test)

test/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,18 @@ configure_lit_site_cfg(
1818
${CMAKE_CURRENT_SOURCE_DIR}/lit.cfg.py
1919
)
2020

21+
configure_lit_site_cfg(
22+
${CMAKE_CURRENT_SOURCE_DIR}/gc/Unit/lit.site.cfg.py.in
23+
${CMAKE_CURRENT_BINARY_DIR}/gc/Unit/lit.site.cfg.py
24+
MAIN_CONFIG
25+
${CMAKE_CURRENT_SOURCE_DIR}/gc/Unit/lit.cfg.py
26+
)
27+
2128
set(GC_OPT_TEST_DEPENDS
2229
FileCheck count not
2330
# mlir-gen
2431
gc-opt
32+
GCUnitTests
2533
)
2634

2735
add_lit_testsuite(gc-check "Running the regression tests"

test/gc/Unit/lit.cfg.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# -*- Python -*-
2+
3+
# Configuration file for the 'lit' test runner.
4+
5+
import os
6+
import subprocess
7+
8+
import lit.formats
9+
10+
# name: The name of this test suite.
11+
config.name = "GC-Unit"
12+
13+
# suffixes: A list of file extensions to treat as test files.
14+
config.suffixes = []
15+
16+
# test_source_root: The root path where tests are located.
17+
# test_exec_root: The root path where tests should be run.
18+
config.test_exec_root = os.path.join(config.gc_obj_root, "unittests")
19+
config.test_source_root = config.test_exec_root
20+
21+
# testFormat: The test format to use to interpret tests.
22+
config.test_format = lit.formats.GoogleTest(config.llvm_build_mode, "Tests")
23+
24+
# Propagate the temp directory. Windows requires this because it uses \Windows\
25+
# if none of these are present.
26+
if "TMP" in os.environ:
27+
config.environment["TMP"] = os.environ["TMP"]
28+
if "TEMP" in os.environ:
29+
config.environment["TEMP"] = os.environ["TEMP"]
30+
31+
# Propagate HOME as it can be used to override incorrect homedir in passwd
32+
# that causes the tests to fail.
33+
if "HOME" in os.environ:
34+
config.environment["HOME"] = os.environ["HOME"]
35+
36+
# Propagate sanitizer options.
37+
for var in [
38+
"ASAN_SYMBOLIZER_PATH",
39+
"HWASAN_SYMBOLIZER_PATH",
40+
"MSAN_SYMBOLIZER_PATH",
41+
"TSAN_SYMBOLIZER_PATH",
42+
"UBSAN_SYMBOLIZER_PATH",
43+
"ASAN_OPTIONS",
44+
"HWASAN_OPTIONS",
45+
"MSAN_OPTIONS",
46+
"TSAN_OPTIONS",
47+
"UBSAN_OPTIONS",
48+
]:
49+
if var in os.environ:
50+
config.environment[var] = os.environ[var]

test/gc/Unit/lit.site.cfg.py.in

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
@LIT_SITE_CFG_IN_HEADER@
2+
3+
import sys
4+
5+
config.llvm_tools_dir = lit_config.substitute("@LLVM_TOOLS_DIR@")
6+
config.llvm_build_mode = lit_config.substitute("@LLVM_BUILD_MODE@")
7+
config.mlir_obj_root = "@MLIR_BINARY_DIR@"
8+
config.gc_src_root = "@CMAKE_SOURCE_DIR@"
9+
config.gc_obj_root = "@CMAKE_BINARY_DIR@"
10+
11+
# Let the main config do the real work.
12+
lit_config.load_config(config, "@CMAKE_SOURCE_DIR@/test/gc/Unit/lit.cfg.py")

unittests/CMakeLists.txt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
if (NOT GC_TEST_ENABLE)
2+
message(STATUS "The unittests are not enabled.")
3+
return()
4+
endif ()
5+
6+
add_definitions(-DMLIR_INCLUDE_TESTS)
7+
add_custom_target(GCUnitTests)
8+
set_target_properties(GCUnitTests PROPERTIES FOLDER "MLIR GC Tests")
9+
10+
# To silence warning caused by Wundef.
11+
add_definitions(-DGTEST_NO_LLVM_SUPPORT=0)
12+
13+
function(add_mlir_unittest test_dirname)
14+
add_unittest(GCUnitTests ${test_dirname} ${ARGN})
15+
endfunction()
16+
17+
add_subdirectory(Example)
18+

unittests/Example/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
add_mlir_unittest(GCExampleTests
2+
Example.cpp
3+
)
4+
target_link_libraries(GCExampleTests
5+
PRIVATE
6+
MLIRLinalgx)

unittests/Example/Example.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//===- Example.cpp - Tests for Example ------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "gc/Dialect/Linalgx/LinalgxDialect.h"
10+
#include "gtest/gtest.h"
11+
12+
TEST(example, HelloWorld) {
13+
ASSERT_EQ(mlir::linalgx::LinalgxDialect::getDialectNamespace(), "linalgx");
14+
}

0 commit comments

Comments
 (0)