Skip to content

Commit

Permalink
[aot] Apply ti_get_last_error_message() for all C-API test cases (#6195)
Browse files Browse the repository at this point in the history
Issue: #
  • Loading branch information
jim19930609 authored Sep 30, 2022
1 parent 9d65cbe commit b491cee
Show file tree
Hide file tree
Showing 13 changed files with 77 additions and 48 deletions.
1 change: 0 additions & 1 deletion c_api/src/c_api_test_utils.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#pragma once
#include <taichi/taichi_platform.h>
#include "taichi/taichi_core.h"

namespace capi {
namespace utils {

Expand Down
11 changes: 11 additions & 0 deletions c_api/src/taichi_core_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) { \
Expand Down
2 changes: 1 addition & 1 deletion c_api/src/taichi_llvm_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
13 changes: 7 additions & 6 deletions c_api/tests/c_api_aot_test.cpp
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);
Expand Down
11 changes: 6 additions & 5 deletions c_api/tests/c_api_cgraph_test.cpp
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);
Expand Down
11 changes: 6 additions & 5 deletions c_api/tests/c_api_interface_test.cpp
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -27,7 +28,7 @@ TEST(CapiDryRun, Runtime) {
}
}

TEST(CapiDryRun, MemoryAllocation) {
TEST_F(CapiTest, DryRunMemoryAllocation) {
{
// CPU Runtime
TiArch arch = TiArch::TI_ARCH_X64;
Expand Down Expand Up @@ -61,7 +62,7 @@ TEST(CapiDryRun, MemoryAllocation) {
}
}

TEST(CapiDryRun, ImageAllocation) {
TEST_F(CapiTest, DryRunImageAllocation) {
if (capi::utils::is_vulkan_available()) {
{
// Vulkan Runtime
Expand All @@ -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");

Expand All @@ -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");

Expand Down
3 changes: 2 additions & 1 deletion c_api/tests/c_api_interop_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion c_api/tests/comet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");

Expand Down
11 changes: 11 additions & 0 deletions c_api/tests/gtest_fixture.h
Original file line number Diff line number Diff line change
@@ -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);
}
};
7 changes: 4 additions & 3 deletions c_api/tests/mpm88_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include "c_api_test_utils.h"
#include "taichi/cpp/taichi.hpp"
#include "c_api/tests/gtest_fixture.h"

namespace demo {

Expand Down Expand Up @@ -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");

Expand All @@ -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");

Expand All @@ -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");

Expand Down
7 changes: 4 additions & 3 deletions c_api/tests/sph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");

Expand All @@ -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");

Expand All @@ -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");

Expand Down
3 changes: 2 additions & 1 deletion c_api/tests/taichi_sparse_test.cpp
Original file line number Diff line number Diff line change
@@ -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");
Expand Down Expand Up @@ -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);
Expand Down
Loading

0 comments on commit b491cee

Please sign in to comment.