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)

libclc/test/lit.site.cfg.py.in

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
@LIT_SITE_CFG_IN_HEADER@
2+
3+
import sys
4+
5+
config.llvm_src_root = path(r"@LLVM_SOURCE_DIR@")
6+
config.llvm_obj_root = path(r"@LLVM_BINARY_DIR@")
7+
config.llvm_tools_dir = lit_config.substitute(path(r"@LLVM_TOOLS_DIR@"))
8+
config.llvm_libs_dir = lit_config.substitute(path(r"@LLVM_LIBS_DIR@"))
9+
config.llvm_shlib_dir = lit_config.substitute(path(r"@SHLIBDIR@"))
10+
config.lit_tools_dir = path(r"@LLVM_LIT_TOOLS_DIR@")
11+
config.host_triple = "@LLVM_HOST_TRIPLE@"
12+
config.target_triple = "@LLVM_TARGET_TRIPLE@"
13+
config.host_arch = "@HOST_ARCH@"
14+
config.python_executable = "@Python3_EXECUTABLE@"
15+
config.libclc_src_dir = path(r"@LIBCLC_SOURCE_DIR@")
16+
config.libclc_lib_dir = path(r"@LIBCLC_BINARY_DIR@")
17+
config.test_run_dir = path(r"@LIBCLC_BINARY_DIR@")
18+
19+
import lit.llvm
20+
lit.llvm.initialize(lit_config, config)
21+
22+
# Let the main config do the real work.
23+
lit_config.load_config(
24+
config, os.path.join(config.libclc_src_dir, "test/lit.cfg.py"))

libclc/test/rsqrt.cl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
#pragma OPENCL EXTENSION cl_khr_fp64 : enable
1+
// RUN: %clang -emit-llvm -S %s
22

3-
__kernel void foo(float4 *x, double4 *y) {
3+
#if defined(cl_khr_fp64)
4+
5+
__kernel void foo(__global float4 *x, __global double4 *y) {
46
x[1] = rsqrt(x[0]);
57
y[1] = rsqrt(y[0]);
68
}
9+
10+
#endif

libclc/test/subsat.cl

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
1-
__kernel void test_subsat_char(char *a, char x, char y) {
1+
// RUN: %clang -emit-llvm -S -o - %s | FileCheck %s
2+
3+
// CHECK: test_subsat_char
4+
__kernel void test_subsat_char(__global char *a, char x, char y) {
25
*a = sub_sat(x, y);
36
return;
47
}
58

6-
__kernel void test_subsat_uchar(uchar *a, uchar x, uchar y) {
9+
__kernel void test_subsat_uchar(__global uchar *a, uchar x, uchar y) {
710
*a = sub_sat(x, y);
811
return;
912
}
1013

11-
__kernel void test_subsat_long(long *a, long x, long y) {
14+
__kernel void test_subsat_long(__global long *a, long x, long y) {
1215
*a = sub_sat(x, y);
1316
return;
1417
}
1518

16-
__kernel void test_subsat_ulong(ulong *a, ulong x, ulong y) {
19+
__kernel void test_subsat_ulong(__global ulong *a, ulong x, ulong y) {
1720
*a = sub_sat(x, y);
1821
return;
1922
}

0 commit comments

Comments
 (0)