diff --git a/c_api/src/c_api_test_utils.h b/c_api/src/c_api_test_utils.h index 0c13f24486990..de5c616b265d0 100644 --- a/c_api/src/c_api_test_utils.h +++ b/c_api/src/c_api_test_utils.h @@ -1,7 +1,6 @@ #pragma once #include #include "taichi/taichi_core.h" - namespace capi { namespace utils { diff --git a/c_api/src/taichi_core_impl.h b/c_api/src/taichi_core_impl.h index 5df9dfe905228..5d4bba9489cd0 100644 --- a/c_api/src/taichi_core_impl.h +++ b/c_api/src/taichi_core_impl.h @@ -11,6 +11,17 @@ #undef TI_RUNTIME_HOST // Error reporting. +#define TI_CAPI_INCOMPLETE(x) ti_set_last_error(TI_ERROR_INCOMPLETE, #x); +#define TI_CAPI_INCOMPLETE_IF(x) \ + if (x) { \ + ti_set_last_error(TI_ERROR_INCOMPLETE, #x); \ + } +#define TI_CAPI_INCOMPLETE_IF_RV(x) \ + if (x) { \ + ti_set_last_error(TI_ERROR_INCOMPLETE, #x); \ + return TI_NULL_HANDLE; \ + } + #define TI_CAPI_NOT_SUPPORTED(x) ti_set_last_error(TI_ERROR_NOT_SUPPORTED, #x); #define TI_CAPI_NOT_SUPPORTED_IF(x) \ if (x) { \ diff --git a/c_api/src/taichi_llvm_impl.cpp b/c_api/src/taichi_llvm_impl.cpp index 2918031c209a6..a069857405ec3 100644 --- a/c_api/src/taichi_llvm_impl.cpp +++ b/c_api/src/taichi_llvm_impl.cpp @@ -66,7 +66,7 @@ void LlvmRuntime::free_memory(TiMemory devmem) { // the corresponding Device::free_memory() interface has not been // implemented yet... if (taichi::arch_is_cpu(config->arch)) { - TI_CAPI_NOT_SUPPORTED_IF(taichi::arch_is_cpu(config->arch)); + TI_CAPI_INCOMPLETE_IF(taichi::arch_is_cpu(config->arch)); } Runtime::free_memory(devmem); diff --git a/c_api/tests/c_api_aot_test.cpp b/c_api/tests/c_api_aot_test.cpp index 09b7849371cc9..622d0718adfb6 100644 --- a/c_api/tests/c_api_aot_test.cpp +++ b/c_api/tests/c_api_aot_test.cpp @@ -1,6 +1,7 @@ #include "gtest/gtest.h" #include "c_api_test_utils.h" #include "taichi/cpp/taichi.hpp" +#include "c_api/tests/gtest_fixture.h" static void kernel_aot_test(TiArch arch) { uint32_t kArrLen = 32; @@ -71,38 +72,38 @@ static void field_aot_test(TiArch arch) { capi::utils::check_runtime_error(runtime); } -TEST(CapiAotTest, CpuField) { +TEST_F(CapiTest, AotTestCpuField) { TiArch arch = TiArch::TI_ARCH_X64; field_aot_test(arch); } -TEST(CapiAotTest, CudaField) { +TEST_F(CapiTest, AotTestCudaField) { if (capi::utils::is_cuda_available()) { TiArch arch = TiArch::TI_ARCH_CUDA; field_aot_test(arch); } } -TEST(CapiAotTest, CpuKernel) { +TEST_F(CapiTest, AotTestCpuKernel) { TiArch arch = TiArch::TI_ARCH_X64; kernel_aot_test(arch); } -TEST(CapiAotTest, CudaKernel) { +TEST_F(CapiTest, AotTestCudaKernel) { if (capi::utils::is_cuda_available()) { TiArch arch = TiArch::TI_ARCH_CUDA; kernel_aot_test(arch); } } -TEST(CapiAotTest, VulkanKernel) { +TEST_F(CapiTest, AotTestVulkanKernel) { if (capi::utils::is_vulkan_available()) { TiArch arch = TiArch::TI_ARCH_VULKAN; kernel_aot_test(arch); } } -TEST(CapiAotTest, OpenglKernel) { +TEST_F(CapiTest, AotTestOpenglKernel) { if (capi::utils::is_opengl_available()) { TiArch arch = TiArch::TI_ARCH_OPENGL; kernel_aot_test(arch); diff --git a/c_api/tests/c_api_cgraph_test.cpp b/c_api/tests/c_api_cgraph_test.cpp index edffb76a5dbf3..c9860a16970a6 100644 --- a/c_api/tests/c_api_cgraph_test.cpp +++ b/c_api/tests/c_api_cgraph_test.cpp @@ -1,6 +1,7 @@ #include "gtest/gtest.h" #include "c_api_test_utils.h" #include "taichi/cpp/taichi.hpp" +#include "c_api/tests/gtest_fixture.h" void graph_aot_test(TiArch arch) { uint32_t kArrLen = 100; @@ -75,32 +76,32 @@ void texture_aot_test(TiArch arch) { } } -TEST(CapiGraphTest, CpuGraph) { +TEST_F(CapiTest, GraphTestCpuGraph) { TiArch arch = TiArch::TI_ARCH_X64; graph_aot_test(arch); } -TEST(CapiGraphTest, CudaGraph) { +TEST_F(CapiTest, GraphTestCudaGraph) { if (capi::utils::is_cuda_available()) { TiArch arch = TiArch::TI_ARCH_CUDA; graph_aot_test(arch); } } -TEST(CapiGraphTest, VulkanGraph) { +TEST_F(CapiTest, GraphTestVulkanGraph) { if (capi::utils::is_vulkan_available()) { TiArch arch = TiArch::TI_ARCH_VULKAN; graph_aot_test(arch); } } -TEST(CapiGraphTest, VulkanTextureGraph) { +TEST_F(CapiTest, GraphTestVulkanTextureGraph) { if (capi::utils::is_vulkan_available()) { TiArch arch = TiArch::TI_ARCH_VULKAN; texture_aot_test(arch); } } -TEST(CapiGraphTest, OpenglGraph) { +TEST_F(CapiTest, GraphTestOpenglGraph) { if (capi::utils::is_opengl_available()) { TiArch arch = TiArch::TI_ARCH_OPENGL; graph_aot_test(arch); diff --git a/c_api/tests/c_api_interface_test.cpp b/c_api/tests/c_api_interface_test.cpp index b4110686a72d7..edf95ed98a4ba 100644 --- a/c_api/tests/c_api_interface_test.cpp +++ b/c_api/tests/c_api_interface_test.cpp @@ -1,8 +1,9 @@ #include "gtest/gtest.h" #include "c_api_test_utils.h" #include "taichi/cpp/taichi.hpp" +#include "c_api/tests/gtest_fixture.h" -TEST(CapiDryRun, Runtime) { +TEST_F(CapiTest, DryRunRuntime) { { // CPU Runtime TiArch arch = TiArch::TI_ARCH_X64; @@ -27,7 +28,7 @@ TEST(CapiDryRun, Runtime) { } } -TEST(CapiDryRun, MemoryAllocation) { +TEST_F(CapiTest, DryRunMemoryAllocation) { { // CPU Runtime TiArch arch = TiArch::TI_ARCH_X64; @@ -61,7 +62,7 @@ TEST(CapiDryRun, MemoryAllocation) { } } -TEST(CapiDryRun, ImageAllocation) { +TEST_F(CapiTest, DryRunImageAllocation) { if (capi::utils::is_vulkan_available()) { { // Vulkan Runtime @@ -73,7 +74,7 @@ TEST(CapiDryRun, ImageAllocation) { } } -TEST(CapiDryRun, VulkanAotModule) { +TEST_F(CapiTest, DryRunVulkanAotModule) { if (capi::utils::is_vulkan_available()) { const auto folder_dir = getenv("TAICHI_AOT_FOLDER_PATH"); @@ -89,7 +90,7 @@ TEST(CapiDryRun, VulkanAotModule) { } } -TEST(CapiDryRun, OpenglAotModule) { +TEST_F(CapiTest, DryRunOpenglAotModule) { if (capi::utils::is_opengl_available()) { const auto folder_dir = getenv("TAICHI_AOT_FOLDER_PATH"); diff --git a/c_api/tests/c_api_interop_test.cpp b/c_api/tests/c_api_interop_test.cpp index 6c893235b02ac..7b1efb66f4164 100644 --- a/c_api/tests/c_api_interop_test.cpp +++ b/c_api/tests/c_api_interop_test.cpp @@ -6,6 +6,7 @@ #include "gtest/gtest.h" #include "c_api_test_utils.h" #include "taichi/cpp/taichi.hpp" +#include "c_api/tests/gtest_fixture.h" #if TI_WITH_VULKAN @@ -26,7 +27,7 @@ static void texture_interop_test(TiArch arch) { EXPECT_GE(ti_get_last_error(0, nullptr), TI_ERROR_SUCCESS); } -TEST(CapiAotTest, VulkanTextureInterop) { +TEST_F(CapiTest, AotTestVulkanTextureInterop) { if (capi::utils::is_vulkan_available()) { TiArch arch = TiArch::TI_ARCH_VULKAN; texture_interop_test(arch); diff --git a/c_api/tests/comet.cpp b/c_api/tests/comet.cpp index 0d943726d82ae..2938519e166b0 100644 --- a/c_api/tests/comet.cpp +++ b/c_api/tests/comet.cpp @@ -5,6 +5,7 @@ #include "c_api_test_utils.h" #include "taichi/cpp/taichi.hpp" +#include "c_api/tests/gtest_fixture.h" constexpr int img_h = 680; constexpr int img_w = 680; @@ -33,7 +34,7 @@ static void comet_run(TiArch arch, const std::string &folder_dir) { } } -TEST(CapiCometTest, Cuda) { +TEST_F(CapiTest, CometTestCuda) { if (capi::utils::is_cuda_available()) { const auto folder_dir = getenv("TAICHI_AOT_FOLDER_PATH"); diff --git a/c_api/tests/gtest_fixture.h b/c_api/tests/gtest_fixture.h new file mode 100644 index 0000000000000..afb7e1f676efe --- /dev/null +++ b/c_api/tests/gtest_fixture.h @@ -0,0 +1,11 @@ +#include "gtest/gtest.h" + +class CapiTest : public ::testing::Test { + protected: + virtual void SetUp() { + } + + virtual void TearDown() { + EXPECT_GE(ti_get_last_error(0, nullptr), TI_ERROR_SUCCESS); + } +}; diff --git a/c_api/tests/mpm88_test.cpp b/c_api/tests/mpm88_test.cpp index 20dc2973f3395..f0ded636255b5 100644 --- a/c_api/tests/mpm88_test.cpp +++ b/c_api/tests/mpm88_test.cpp @@ -5,6 +5,7 @@ #include "c_api_test_utils.h" #include "taichi/cpp/taichi.hpp" +#include "c_api/tests/gtest_fixture.h" namespace demo { @@ -99,7 +100,7 @@ class MPM88DemoImpl { } // namespace demo -TEST(CapiMpm88Test, Cuda) { +TEST_F(CapiTest, Mpm88TestCuda) { if (capi::utils::is_cuda_available()) { const auto folder_dir = getenv("TAICHI_AOT_FOLDER_PATH"); @@ -112,7 +113,7 @@ TEST(CapiMpm88Test, Cuda) { } } -TEST(CapiMpm88Test, Vulkan) { +TEST_F(CapiTest, Mpm88TestVulkan) { if (capi::utils::is_vulkan_available()) { const auto folder_dir = getenv("TAICHI_AOT_FOLDER_PATH"); @@ -125,7 +126,7 @@ TEST(CapiMpm88Test, Vulkan) { } } -TEST(CapiMpm88Test, Opengl) { +TEST_F(CapiTest, Mpm88TestOpengl) { if (capi::utils::is_opengl_available()) { const auto folder_dir = getenv("TAICHI_AOT_FOLDER_PATH"); diff --git a/c_api/tests/sph.cpp b/c_api/tests/sph.cpp index f18e2538c283a..d76e8ace1255e 100644 --- a/c_api/tests/sph.cpp +++ b/c_api/tests/sph.cpp @@ -5,6 +5,7 @@ #include "c_api_test_utils.h" #include "taichi/cpp/taichi.hpp" +#include "c_api/tests/gtest_fixture.h" #define NR_PARTICLES 8000 constexpr int SUBSTEPS = 5; @@ -85,7 +86,7 @@ void run(TiArch arch, const std::string &folder_dir) { runtime.wait(); } -TEST(CapiSphTest, Cuda) { +TEST_F(CapiTest, SphTestCuda) { if (capi::utils::is_cuda_available()) { const auto folder_dir = getenv("TAICHI_AOT_FOLDER_PATH"); @@ -96,7 +97,7 @@ TEST(CapiSphTest, Cuda) { } } -TEST(CapiSphTest, Vulkan) { +TEST_F(CapiTest, SphTestVulkan) { if (capi::utils::is_vulkan_available()) { const auto folder_dir = getenv("TAICHI_AOT_FOLDER_PATH"); @@ -107,7 +108,7 @@ TEST(CapiSphTest, Vulkan) { } } -TEST(CapiSphTest, Opengl) { +TEST_F(CapiTest, SphTestOpengl) { if (capi::utils::is_opengl_available()) { const auto folder_dir = getenv("TAICHI_AOT_FOLDER_PATH"); diff --git a/c_api/tests/taichi_sparse_test.cpp b/c_api/tests/taichi_sparse_test.cpp index caa3009f37280..0e96af05b15a2 100644 --- a/c_api/tests/taichi_sparse_test.cpp +++ b/c_api/tests/taichi_sparse_test.cpp @@ -1,6 +1,7 @@ #include "gtest/gtest.h" #include "c_api_test_utils.h" #include "taichi/cpp/taichi.hpp" +#include "c_api/tests/gtest_fixture.h" static void taichi_sparse_test(TiArch arch) { const auto folder_dir = getenv("TAICHI_AOT_FOLDER_PATH"); @@ -38,7 +39,7 @@ static void taichi_sparse_test(TiArch arch) { capi::utils::check_runtime_error(runtime); } -TEST(CapiTaichiSparseTest, Cuda) { +TEST_F(CapiTest, TaichiSparseTestCuda) { if (capi::utils::is_cuda_available()) { TiArch arch = TiArch::TI_ARCH_CUDA; taichi_sparse_test(arch); diff --git a/tests/test_config.json b/tests/test_config.json index 10cd191721e04..14e4cace901f5 100644 --- a/tests/test_config.json +++ b/tests/test_config.json @@ -107,87 +107,87 @@ }, "capi_aot_test_cases" : { - "CapiMpm88Test.Vulkan": [ + "CapiTest.Mpm88TestVulkan": [ ["cpp", "aot", "python_scripts", "mpm88_graph_aot.py"], "--arch=vulkan" ], - "CapiMpm88Test.Opengl": [ + "CapiTest.Mpm88TestOpengl": [ ["cpp", "aot", "python_scripts", "mpm88_graph_aot.py"], "--arch=opengl" ], - "CapiMpm88Test.Cuda": [ + "CapiTest.Mpm88TestCuda": [ ["cpp", "aot", "python_scripts", "mpm88_graph_aot.py"], "--arch=cuda" ], - "CapiSphTest.Vulkan": [ + "CapiTest.SphTestVulkan": [ ["cpp", "aot", "python_scripts", "sph_aot.py"], "--arch=vulkan" ], - "CapiSphTest.Opengl": [ + "CapiTest.SphTestOpengl": [ ["cpp", "aot", "python_scripts", "sph_aot.py"], "--arch=opengl" ], - "CapiSphTest.Cuda": [ + "CapiTest.SphTestCuda": [ ["cpp", "aot", "python_scripts", "sph_aot.py"], "--arch=cuda" ], - "CapiCometTest.Cuda": [ + "CapiTest.CometTestCuda": [ ["cpp", "aot", "python_scripts", "comet_aot.py"], "--arch=cuda" ], - "CapiTaichiSparseTest.Cuda": [ + "CapiTest.TaichiSparseTestCuda": [ ["cpp", "aot", "python_scripts", "taichi_sparse_test.py"], "" ], - "CapiAotTest.CpuField": [ + "CapiTest.AotTestCpuField": [ ["cpp", "aot", "python_scripts", "field_aot_test.py"], "--arch=cpu" ], - "CapiAotTest.CudaField": [ + "CapiTest.AotTestCudaField": [ ["cpp", "aot", "python_scripts", "field_aot_test.py"], "--arch=cuda" ], - "CapiGraphTest.CpuGraph": [ + "CapiTest.GraphTestCpuGraph": [ ["cpp", "aot", "python_scripts", "graph_aot_test.py"], "--arch=cpu" ], - "CapiGraphTest.CudaGraph": [ + "CapiTest.GraphTestCudaGraph": [ ["cpp", "aot", "python_scripts", "graph_aot_test.py"], "--arch=cuda" ], - "CapiGraphTest.VulkanGraph": [ + "CapiTest.GraphTestVulkanGraph": [ ["cpp", "aot", "python_scripts", "graph_aot_test.py"], "--arch=vulkan" ], - "CapiGraphTest.VulkanTextureGraph": [ + "CapiTest.GraphTestVulkanTextureGraph": [ ["cpp", "aot", "python_scripts", "texture_aot_test.py"], "--arch=vulkan" ], - "CapiGraphTest.OpenglGraph": [ + "CapiTest.GraphTestOpenglGraph": [ ["cpp", "aot", "python_scripts", "graph_aot_test.py"], "--arch=opengl" ], - "CapiAotTest.CpuKernel": [ + "CapiTest.AotTestCpuKernel": [ ["cpp", "aot", "python_scripts", "kernel_aot_test1.py"], "--arch=cpu" ], - "CapiAotTest.CudaKernel": [ + "CapiTest.AotTestCudaKernel": [ ["cpp", "aot", "python_scripts", "kernel_aot_test1.py"], "--arch=cuda" ], - "CapiAotTest.VulkanKernel": [ + "CapiTest.AotTestVulkanKernel": [ ["cpp", "aot", "python_scripts", "kernel_aot_test1.py"], "--arch=vulkan" ], - "CapiAotTest.OpenglKernel": [ + "CapiTest.AotTestOpenglKernel": [ ["cpp", "aot", "python_scripts", "kernel_aot_test1.py"], "--arch=opengl" ], - "CapiDryRun.VulkanAotModule": [ + "CapiTest.DryRunVulkanAotModule": [ ["cpp", "aot", "python_scripts", "kernel_aot_test1.py"], "--arch=vulkan" ], - "CapiDryRun.OpenglAotModule": [ + "CapiTest.DryRunOpenglAotModule": [ ["cpp", "aot", "python_scripts", "kernel_aot_test1.py"], "--arch=opengl" ]