Skip to content

Commit 9048dbc

Browse files
committed
[libclc] Add initial LIT tests
These tests aren't very meaningful and aren't immune to false positives, but they do get the project building when running 'check-all' and so enable libclc testing in CI.
1 parent 45eabd1 commit 9048dbc

File tree

13 files changed

+180
-15
lines changed

13 files changed

+180
-15
lines changed

libclc/CMakeLists.txt

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,10 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
366366
COMMAND ${LLVM_SPIRV} ${spvflags} -o ${spv_suffix} ${builtins_link_lib}
367367
DEPENDS ${builtins_link_lib}
368368
)
369-
add_custom_target( "prepare-${spv_suffix}" ALL DEPENDS "${spv_suffix}" )
369+
add_custom_target( prepare-${arch_suffix} ALL DEPENDS ${spv_suffix} )
370+
set_target_properties( prepare-${arch_suffix}
371+
PROPERTIES TARGET_FILE ${spv_suffix}
372+
)
370373
install( FILES ${CMAKE_CURRENT_BINARY_DIR}/${spv_suffix}
371374
DESTINATION "${CMAKE_INSTALL_DATADIR}/clc" )
372375
else()
@@ -392,7 +395,10 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
392395
add_custom_command( OUTPUT ${obj_suffix}
393396
COMMAND prepare_builtins -o ${obj_suffix} ${builtins_opt_lib}
394397
DEPENDS ${builtins_opt_lib} prepare_builtins )
395-
add_custom_target( prepare-${obj_suffix} ALL DEPENDS ${obj_suffix} )
398+
add_custom_target( prepare-${arch_suffix} ALL DEPENDS ${obj_suffix} )
399+
set_target_properties( prepare-${arch_suffix}
400+
PROPERTIES TARGET_FILE ${obj_suffix}
401+
)
396402

397403
# nvptx-- targets don't include workitem builtins
398404
if( NOT clang_triple MATCHES ".*ptx.*--$" )
@@ -406,9 +412,13 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
406412
set( alias_suffix "${a}-${clang_triple}.bc" )
407413
add_custom_target( ${alias_suffix} ALL
408414
COMMAND ${CMAKE_COMMAND} -E create_symlink ${obj_suffix} ${alias_suffix}
409-
DEPENDS prepare-${obj_suffix} )
415+
DEPENDS prepare-${arch_suffix} )
410416
install( FILES ${CMAKE_CURRENT_BINARY_DIR}/${alias_suffix} DESTINATION "${CMAKE_INSTALL_DATADIR}/clc" )
411417
endforeach( a )
412418
endif()
413419
endforeach( d )
414420
endforeach( t )
421+
422+
if( NOT LIBCLC_STANDALONE_BUILD )
423+
add_subdirectory( test )
424+
endif()

libclc/test/CMakeLists.txt

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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+
# The tests use LLVM IR, so we can't test SPIR-V libraries here.
21+
string( REPLACE "-" ";" TRIPLE ${t} )
22+
list( GET TRIPLE 0 ARCH )
23+
if( ARCH STREQUAL spirv OR ARCH STREQUAL spirv64 )
24+
continue()
25+
endif()
26+
27+
get_libclc_device_info(
28+
TRIPLE ${t}
29+
DEVICE ${d}
30+
CPU cpu
31+
ARCH_SUFFIX arch_suffix
32+
CLANG_TRIPLE clang_triple
33+
)
34+
35+
add_lit_testsuite(check-libclc-${arch_suffix}
36+
"Running libclc ${arch_suffix} regression tests"
37+
${CMAKE_CURRENT_BINARY_DIR}
38+
PARAMS "target=${clang_triple}" cpu=${cpu}
39+
"builtins=$<TARGET_PROPERTY:prepare-${arch_suffix},TARGET_FILE>"
40+
DEPENDS prepare-${arch_suffix} ${LIBCLC_TEST_DEPS}
41+
)
42+
43+
add_dependencies( check-libclc check-libclc-${arch_suffix} )
44+
45+
endforeach()
46+
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)