From ea9299c4a9120c9219d3b7953444272999df8bc3 Mon Sep 17 00:00:00 2001 From: damnkk <17611288725@163.com> Date: Wed, 11 Jan 2023 22:35:34 +0800 Subject: [PATCH] [aot] AOT compat test in workflow (#7033) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: PENGUINLIONG --- .github/workflows/scripts/unix_test.sh | 9 +++- tests/generate_compat_test_modules.py | 34 ++++++++++++ tests/run_c_api_compat_test.py | 75 ++++++++++++++++++++++++++ 3 files changed, 117 insertions(+), 1 deletion(-) create mode 100644 tests/generate_compat_test_modules.py create mode 100644 tests/run_c_api_compat_test.py diff --git a/.github/workflows/scripts/unix_test.sh b/.github/workflows/scripts/unix_test.sh index be75db53a9914..a3e79ca7463a8 100755 --- a/.github/workflows/scripts/unix_test.sh +++ b/.github/workflows/scripts/unix_test.sh @@ -5,14 +5,21 @@ set -ex export PYTHONUNBUFFERED=1 +export TAICHI_AOT_FOLDER_PATH="taichi/tests" export TI_SKIP_VERSION_CHECK=ON export TI_CI=1 export LD_LIBRARY_PATH=$PWD/build/:$LD_LIBRARY_PATH export TI_OFFLINE_CACHE_FILE_PATH=$PWD/.cache/taichi -setup_python +pip3 install -i https://pypi.taichi.graphics/simple/ taichi-nightly [[ "$IN_DOCKER" == "true" ]] && cd taichi +python3 tests/generate_compat_test_modules.py +python3 -m pip uninstall taichi-nightly -y + +setup_python + +python3 tests/run_c_api_compat_test.py if [ ! -z "$AMDGPU_TEST" ]; then sudo chmod 666 /dev/kfd diff --git a/tests/generate_compat_test_modules.py b/tests/generate_compat_test_modules.py new file mode 100644 index 0000000000000..02f937c749f25 --- /dev/null +++ b/tests/generate_compat_test_modules.py @@ -0,0 +1,34 @@ +""" +Generate AOT modules with Taichi nightly (which is definitely an older version +from this currently building one in development branch) for +`run_c_api_compat_test.py` to consume. +""" +import glob +import os +import pathlib +import subprocess + +curr_dir = os.path.dirname(os.path.abspath(__file__)) +curr_dir = os.path.dirname(curr_dir) +build_dir = os.path.join(curr_dir, 'build') +cpp_test_filename = 'taichi_cpp_tests' +capi_test_filename = 'taichi_c_api_tests' +cpp_tests_path = os.path.join(build_dir, capi_test_filename) +c_api_tests_path = os.path.join(build_dir, cpp_test_filename) + + +def generate(): + aot_files = glob.glob("tests/cpp/aot/python_scripts/*.py") + for x in aot_files: + path_name = pathlib.Path(x).name[:-3] + os.mkdir('tests/cpp/aot/python_scripts/' + path_name) + os.environ[ + "TAICHI_AOT_FOLDER_PATH"] = curr_dir + '/tests/cpp/aot/python_scripts/' + path_name + try: + subprocess.check_call(["python", x, "--arch=vulkan"]) + except subprocess.CalledProcessError: + continue + + +if __name__ == "__main__": + generate() diff --git a/tests/run_c_api_compat_test.py b/tests/run_c_api_compat_test.py new file mode 100644 index 0000000000000..2ce04113ccedf --- /dev/null +++ b/tests/run_c_api_compat_test.py @@ -0,0 +1,75 @@ +""" +Ensure AOT modules compiled by old versions of Taichi is compatible with the +latest Taichi Runtime. +""" +import glob +import json +import os +import pathlib +import subprocess + +curr_dir = os.path.dirname(os.path.abspath(__file__)) +curr_dir = os.path.dirname(curr_dir) +build_dir = os.path.join(curr_dir, 'build') +cpp_test_filename = 'taichi_cpp_tests' +capi_test_filename = 'taichi_c_api_tests' +cpp_tests_path = os.path.join(build_dir, capi_test_filename) +c_api_tests_path = os.path.join(build_dir, cpp_test_filename) + +run_dict = {} + + +def init_dict(run_dict, aot_files): + curr_dir = os.path.dirname(os.path.abspath(__file__)) + test_config_path = os.path.join(curr_dir, 'test_config.json') + with open(test_config_path, 'r') as f: + test_config = json.loads(f.read()) + + assert ("aot_test_cases" in test_config.keys()) + assert ("capi_aot_test_cases" in test_config.keys()) + + for x in aot_files: + path_name = pathlib.Path(x).name[:-3] + run_dict[path_name] = [] + for cpp_test_name, value in test_config["aot_test_cases"].items(): + if value[1] != "--arch=vulkan": + continue + test_command = [] + test_command.append(cpp_tests_path) + test_command.append(f"--gtest_filter={cpp_test_name}") + run_dict[value[0][3][:-3]].append(test_command) + + for cpp_test_name, value in test_config["capi_aot_test_cases"].items(): + if value[1] != "--arch=vulkan": + continue + test_command = [] + test_command.append(cpp_tests_path) + test_command.append(f"--gtest_filter={cpp_test_name}") + run_dict[value[0][3][:-3]].append(test_command) + + +def run(): + aot_files = glob.glob('tests/cpp/aot/python_scripts/*.py') + init_dict(run_dict, aot_files) + print(run_dict) + for x in aot_files: + path_name = pathlib.Path(x).name[:-3] + os.environ[ + "TAICHI_AOT_FOLDER_PATH"] = curr_dir + '/tests/cpp/aot/python_scripts/' + path_name + if len(os.listdir('tests/cpp/aot/python_scripts/' + path_name)) == 0: + continue + for i in run_dict[path_name]: + print(i) + try: + subprocess.check_call(i, env=os.environ.copy(), cwd=build_dir) + except subprocess.SubprocessError: + print(os.environ["TAICHI_AOT_FOLDER_PATH"]) + print(path_name) + print(os.listdir(os.environ["TAICHI_AOT_FOLDER_PATH"])) + continue + except FileNotFoundError: + continue + + +if __name__ == "__main__": + run()