From bf529b756a6340f57c33cdd0cbb48f8c1c28cb1b Mon Sep 17 00:00:00 2001 From: tomflinda Date: Wed, 11 Oct 2023 09:57:30 +0800 Subject: [PATCH] [SYCLomatic #1311]Add behavior test for incorrect compilation database generation when source file builds with "-optf" of intercept-build tool (#474) Signed-off-by: chenwei.sun --- behavior_tests/behavior_tests.xml | 1 + .../src/process_optf_option/do_test.py | 40 +++++++++++++++++++ .../use_optf_option_case/Makefile | 14 +++++++ .../use_optf_option_case/inc/inc1/foo1.h | 0 .../use_optf_option_case/inc/inc2/foo2.h | 0 .../use_optf_option_case/inc/inc3/foo3.h | 0 .../use_optf_option_case/inc/inc4/foo4.h | 0 .../use_optf_option_case/includes1.rsp | 1 + .../use_optf_option_case/includes2.rsp | 1 + .../use_optf_option_case/includes3.rsp | 1 + .../use_optf_option_case/includes4.rsp | 1 + .../use_optf_option_case/test1.cu | 33 +++++++++++++++ .../use_optf_option_case/test2.cu | 12 ++++++ 13 files changed, 104 insertions(+) create mode 100644 behavior_tests/src/process_optf_option/do_test.py create mode 100644 behavior_tests/src/process_optf_option/use_optf_option_case/Makefile create mode 100644 behavior_tests/src/process_optf_option/use_optf_option_case/inc/inc1/foo1.h create mode 100644 behavior_tests/src/process_optf_option/use_optf_option_case/inc/inc2/foo2.h create mode 100644 behavior_tests/src/process_optf_option/use_optf_option_case/inc/inc3/foo3.h create mode 100644 behavior_tests/src/process_optf_option/use_optf_option_case/inc/inc4/foo4.h create mode 100644 behavior_tests/src/process_optf_option/use_optf_option_case/includes1.rsp create mode 100644 behavior_tests/src/process_optf_option/use_optf_option_case/includes2.rsp create mode 100644 behavior_tests/src/process_optf_option/use_optf_option_case/includes3.rsp create mode 100644 behavior_tests/src/process_optf_option/use_optf_option_case/includes4.rsp create mode 100644 behavior_tests/src/process_optf_option/use_optf_option_case/test1.cu create mode 100644 behavior_tests/src/process_optf_option/use_optf_option_case/test2.cu diff --git a/behavior_tests/behavior_tests.xml b/behavior_tests/behavior_tests.xml index 759309dad..491dbbc4a 100644 --- a/behavior_tests/behavior_tests.xml +++ b/behavior_tests/behavior_tests.xml @@ -61,6 +61,7 @@ + diff --git a/behavior_tests/src/process_optf_option/do_test.py b/behavior_tests/src/process_optf_option/do_test.py new file mode 100644 index 000000000..1e8ac5e56 --- /dev/null +++ b/behavior_tests/src/process_optf_option/do_test.py @@ -0,0 +1,40 @@ +# ====------ do_test.py---------- *- Python -* ----===## +# +# 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 +# +# +# ===----------------------------------------------------------------------===# +import subprocess +import platform +import os +import sys + +from test_utils import * + +def setup_test(): + return True + +def migrate_test(): + change_dir('process_optf_option/use_optf_option_case') + call_subprocess('intercept-build /usr/bin/make') + call_subprocess(test_config.CT_TOOL + ' -in-root ./ -out-root out -gen-build-script -p ./compile_commands.json --cuda-include-path=' + \ + os.environ['CUDA_INCLUDE_PATH']) + change_dir("./out") + call_subprocess("make -f Makefile.dpct -B") + + + if os.path.isfile("./test1.dp.o") and os.path.isfile("./test1.dp.o"): + print("process_optf_option migrate pass") + return True + else: + print("process_optf_option migrate failed") + return False + + +def build_test(): + return True + +def run_test(): + return True diff --git a/behavior_tests/src/process_optf_option/use_optf_option_case/Makefile b/behavior_tests/src/process_optf_option/use_optf_option_case/Makefile new file mode 100644 index 000000000..1f3c2011d --- /dev/null +++ b/behavior_tests/src/process_optf_option/use_optf_option_case/Makefile @@ -0,0 +1,14 @@ +all:test + +test:test1.o test2.o + +test1.o:test1.cu + nvcc -c test1.cu --options-file=./includes1.rsp -optf=./includes2.rsp --options-file ./includes3.rsp -optf ./includes4.rsp + +test2.o:test2.cu + cd inner && nvcc -c ../test2.cu + + + +clean: + -rm inner/test2.o test1.o \ No newline at end of file diff --git a/behavior_tests/src/process_optf_option/use_optf_option_case/inc/inc1/foo1.h b/behavior_tests/src/process_optf_option/use_optf_option_case/inc/inc1/foo1.h new file mode 100644 index 000000000..e69de29bb diff --git a/behavior_tests/src/process_optf_option/use_optf_option_case/inc/inc2/foo2.h b/behavior_tests/src/process_optf_option/use_optf_option_case/inc/inc2/foo2.h new file mode 100644 index 000000000..e69de29bb diff --git a/behavior_tests/src/process_optf_option/use_optf_option_case/inc/inc3/foo3.h b/behavior_tests/src/process_optf_option/use_optf_option_case/inc/inc3/foo3.h new file mode 100644 index 000000000..e69de29bb diff --git a/behavior_tests/src/process_optf_option/use_optf_option_case/inc/inc4/foo4.h b/behavior_tests/src/process_optf_option/use_optf_option_case/inc/inc4/foo4.h new file mode 100644 index 000000000..e69de29bb diff --git a/behavior_tests/src/process_optf_option/use_optf_option_case/includes1.rsp b/behavior_tests/src/process_optf_option/use_optf_option_case/includes1.rsp new file mode 100644 index 000000000..a17edc4e0 --- /dev/null +++ b/behavior_tests/src/process_optf_option/use_optf_option_case/includes1.rsp @@ -0,0 +1 @@ +-D__FOO1__ -I"./inc/inc1" diff --git a/behavior_tests/src/process_optf_option/use_optf_option_case/includes2.rsp b/behavior_tests/src/process_optf_option/use_optf_option_case/includes2.rsp new file mode 100644 index 000000000..fce54408e --- /dev/null +++ b/behavior_tests/src/process_optf_option/use_optf_option_case/includes2.rsp @@ -0,0 +1 @@ +-D__FOO2__ -I"./inc/inc2" diff --git a/behavior_tests/src/process_optf_option/use_optf_option_case/includes3.rsp b/behavior_tests/src/process_optf_option/use_optf_option_case/includes3.rsp new file mode 100644 index 000000000..21be3e454 --- /dev/null +++ b/behavior_tests/src/process_optf_option/use_optf_option_case/includes3.rsp @@ -0,0 +1 @@ +-D__FOO3__ -I"./inc/inc3" diff --git a/behavior_tests/src/process_optf_option/use_optf_option_case/includes4.rsp b/behavior_tests/src/process_optf_option/use_optf_option_case/includes4.rsp new file mode 100644 index 000000000..ef20c6f55 --- /dev/null +++ b/behavior_tests/src/process_optf_option/use_optf_option_case/includes4.rsp @@ -0,0 +1 @@ +-D__FOO4__ -I"./inc/inc4" diff --git a/behavior_tests/src/process_optf_option/use_optf_option_case/test1.cu b/behavior_tests/src/process_optf_option/use_optf_option_case/test1.cu new file mode 100644 index 000000000..59b91985c --- /dev/null +++ b/behavior_tests/src/process_optf_option/use_optf_option_case/test1.cu @@ -0,0 +1,33 @@ +// ====------ test1.cu---------------------------------- *- CUDA -* ----===//// +// +// 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 + +#ifdef __FOO1__ +__global__ void foo1() {} +#endif + +#ifdef __FOO2__ +__global__ void foo2() {} +#endif + +#ifdef __FOO3__ +__global__ void foo3() {} +#endif + +#ifdef __FOO4__ +__global__ void foo4() {} +#endif + +#include "foo1.h" +#include "foo2.h" +#include "foo3.h" +#include "foo4.h" + +int main() { return 0; } diff --git a/behavior_tests/src/process_optf_option/use_optf_option_case/test2.cu b/behavior_tests/src/process_optf_option/use_optf_option_case/test2.cu new file mode 100644 index 000000000..6601c369a --- /dev/null +++ b/behavior_tests/src/process_optf_option/use_optf_option_case/test2.cu @@ -0,0 +1,12 @@ +// ====------ test2.cu---------------------------------- *- CUDA -* ----===//// +// +// 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 +// +// +// ===----------------------------------------------------------------------===// + +#ifdef __FOO__ +__global__ void foo() {} +#endif