Skip to content

Commit c53dc35

Browse files
committed
[libclc] Add initial LIT tests
1 parent 92e96c7 commit c53dc35

File tree

13 files changed

+163
-12
lines changed

13 files changed

+163
-12
lines changed

libclc/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,3 +411,7 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
411411
endif()
412412
endforeach( d )
413413
endforeach( t )
414+
415+
if( NOT LIBCLC_STANDALONE_BUILD )
416+
add_subdirectory( test )
417+
endif()

libclc/test/CMakeLists.txt

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
set(LIBCLC_TEST_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
2+
3+
configure_lit_site_cfg(
4+
${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in
5+
${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg.py
6+
MAIN_CONFIG
7+
${CMAKE_CURRENT_SOURCE_DIR}/lit.cfg.py
8+
)
9+
10+
list(APPEND LIBCLC_TEST_DEPS
11+
libclc::clang
12+
FileCheck count not
13+
)
14+
15+
add_custom_target(check-libclc)
16+
17+
foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
18+
foreach( d ${${t}_devices} )
19+
20+
get_libclc_device_info(
21+
TRIPLE ${t}
22+
DEVICE ${d}
23+
CPU cpu
24+
ARCH_SUFFIX arch_suffix
25+
CLANG_TRIPLE clang_triple
26+
)
27+
28+
add_lit_testsuite(check-libclc-${arch_suffix}
29+
"Running libclc ${arch_suffix} regression tests"
30+
${CMAKE_CURRENT_BINARY_DIR}
31+
PARAMS "target=${clang_triple}" cpu=${cpu} "builtins=${arch_suffix}.bc"
32+
DEPENDS prepare-${arch_suffix}.bc ${LIBCLC_TEST_DEPS}
33+
)
34+
35+
add_dependencies( check-libclc check-libclc-${arch_suffix} )
36+
37+
endforeach()
38+
endforeach()

libclc/test/add_sat.cl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// RUN: %clang -emit-llvm -S -o - %s | FileCheck %s
2+
3+
// CHECK: foo
14
__kernel void foo(__global char *a, __global char *b, __global char *c) {
25
*a = add_sat(*b, *c);
36
}

libclc/test/as_type.cl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1-
__kernel void foo(int4 *x, float4 *y) {
1+
// RUN: %clang -emit-llvm -S -o - %s | FileCheck %s
2+
3+
// CHECK: foo
4+
__kernel void foo(__global int4 *x, __global float4 *y) {
25
*x = as_int4(*y);
36
}

libclc/test/convert.cl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1-
__kernel void foo(int4 *x, float4 *y) {
1+
// RUN: %clang -emit-llvm -S -o - %s | FileCheck %s
2+
3+
// CHECK: foo
4+
__kernel void foo(__global int4 *x, __global float4 *y) {
25
*x = convert_int4(*y);
36
}

libclc/test/cos.cl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1-
__kernel void foo(float4 *f) {
1+
// RUN: %clang -emit-llvm -S -o - %s | FileCheck %s
2+
3+
// CHECK: foo
4+
__kernel void foo(__global float4 *f) {
25
*f = cos(*f);
36
}

libclc/test/cross.cl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1-
__kernel void foo(float4 *f) {
1+
// RUN: %clang -emit-llvm -S -o - %s | FileCheck %s
2+
3+
// CHECK: foo
4+
__kernel void foo(__global float4 *f) {
25
*f = cross(f[0], f[1]);
36
}

libclc/test/fabs.cl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1-
__kernel void foo(float *f) {
1+
// RUN: %clang -emit-llvm -S -o - %s | FileCheck %s
2+
3+
// CHECK: foo
4+
__kernel void foo(__global float *f) {
25
*f = fabs(*f);
36
}

libclc/test/get_group_id.cl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1-
__kernel void foo(int *i) {
1+
// RUN: %clang -emit-llvm -S -o - %s | FileCheck %s
2+
3+
// CHECK: foo
4+
__kernel void foo(__global int *i) {
25
i[get_group_id(0)] = 1;
36
}

libclc/test/lit.cfg.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import os
2+
3+
import lit.formats
4+
import lit.util
5+
6+
from lit.llvm import llvm_config
7+
from lit.llvm.subst import ToolSubst
8+
from lit.llvm.subst import FindTool
9+
10+
# Configuration file for the 'lit' test runner.
11+
12+
# name: The name of this test suite.
13+
config.name = "libclc"
14+
15+
# testFormat: The test format to use to interpret tests.
16+
config.test_format = lit.formats.ShTest(not llvm_config.use_lit_shell)
17+
18+
# suffixes: A list of file extensions to treat as test files.
19+
config.suffixes = [
20+
".cl",
21+
]
22+
23+
# test_source_root: The root path where tests are located.
24+
config.test_source_root = os.path.join(os.path.dirname(__file__))
25+
26+
# test_exec_root: The root path where tests should be run.
27+
config.test_exec_root = os.path.join(config.test_run_dir, "test")
28+
29+
llvm_config.use_default_substitutions()
30+
31+
target = lit_config.params.get("target", "")
32+
builtins = lit_config.params.get("builtins", "")
33+
34+
clang_flags = [
35+
"-fno-builtin",
36+
"-target",
37+
target,
38+
"-Xclang",
39+
"-mlink-builtin-bitcode",
40+
"-Xclang",
41+
os.path.join(config.libclc_lib_dir, builtins),
42+
"-nogpulib",
43+
]
44+
45+
cpu = lit_config.params.get("cpu", "")
46+
if cpu:
47+
clang_flags.append(f"-mcpu={cpu}")
48+
49+
llvm_config.use_clang(additional_flags=clang_flags)
50+
51+
tools = [
52+
"llvm-dis",
53+
"not",
54+
]
55+
tool_dirs = [config.llvm_tools_dir]
56+
57+
llvm_config.add_tool_substitutions(tools, tool_dirs)

0 commit comments

Comments
 (0)