| 10 | #include <thread> |
| 11 | |
| 12 | TEST(TestCapiTensor, Basic) { |
| 13 | LiteTensor c_tensor0, c_tensor1; |
| 14 | LiteTensorDesc description = default_desc; |
| 15 | LITE_make_tensor(description, &c_tensor0); |
| 16 | int is_pinned_host = false; |
| 17 | LITE_is_pinned_host(c_tensor0, &is_pinned_host); |
| 18 | ASSERT_FALSE(is_pinned_host); |
| 19 | LiteDeviceType device_type; |
| 20 | LITE_get_tensor_device_type(c_tensor0, &device_type); |
| 21 | ASSERT_EQ(device_type, LiteDeviceType::LITE_CPU); |
| 22 | size_t length = 0; |
| 23 | LITE_get_tensor_total_size_in_byte(c_tensor0, &length); |
| 24 | ASSERT_EQ(length, 0); |
| 25 | |
| 26 | LiteLayout layout{{1, 3, 224, 224}, 4, LiteDataType::LITE_FLOAT}; |
| 27 | description.device_type = LiteDeviceType::LITE_CPU; |
| 28 | description.layout = layout; |
| 29 | description.is_pinned_host = true; |
| 30 | LITE_make_tensor(description, &c_tensor1); |
| 31 | LITE_is_pinned_host(c_tensor1, &is_pinned_host); |
| 32 | ASSERT_TRUE(is_pinned_host); |
| 33 | LITE_get_tensor_total_size_in_byte(c_tensor1, &length); |
| 34 | ASSERT_EQ(length, 1 * 3 * 224 * 224 * 4); |
| 35 | |
| 36 | LiteLayout get_layout; |
| 37 | LITE_get_tensor_layout(c_tensor1, &get_layout); |
| 38 | ASSERT_EQ(get_layout.ndim, layout.ndim); |
| 39 | ASSERT_EQ(get_layout.data_type, layout.data_type); |
| 40 | ASSERT_EQ(get_layout.shapes[0], layout.shapes[0]); |
| 41 | ASSERT_EQ(get_layout.shapes[1], layout.shapes[1]); |
| 42 | ASSERT_EQ(get_layout.shapes[2], layout.shapes[2]); |
| 43 | ASSERT_EQ(get_layout.shapes[3], layout.shapes[3]); |
| 44 | |
| 45 | //! test error |
| 46 | ASSERT_EQ(LITE_is_pinned_host(c_tensor0, nullptr), -1); |
| 47 | ASSERT_NE(strlen(LITE_get_last_error()), 0); |
| 48 | ASSERT_EQ(LITE_get_last_error_code(), ErrorCode::LITE_INTERNAL_ERROR); |
| 49 | printf("The last error is: %s\n", LITE_get_last_error()); |
| 50 | LITE_clear_last_error(); |
| 51 | ASSERT_EQ(strlen(LITE_get_last_error()), 0); |
| 52 | ASSERT_EQ(LITE_get_last_error_code(), ErrorCode::OK); |
| 53 | |
| 54 | LITE_destroy_tensor(c_tensor0); |
| 55 | LITE_destroy_tensor(c_tensor1); |
| 56 | } |
| 57 | |
| 58 | TEST(TestCapiTensor, SetLayoutReAlloc) { |
| 59 | LiteTensor c_tensor0; |
nothing calls this directly
no test coverage detected