| 653 | } |
| 654 | |
| 655 | void TensorHandleCopyBetweenDevicesError(bool async) { |
| 656 | std::unique_ptr<TF_Status, decltype(&TF_DeleteStatus)> status( |
| 657 | TF_NewStatus(), TF_DeleteStatus); |
| 658 | TFE_ContextOptions* opts = TFE_NewContextOptions(); |
| 659 | TFE_ContextOptionsSetAsync(opts, static_cast<unsigned char>(async)); |
| 660 | TFE_Context* ctx = TFE_NewContext(opts, status.get()); |
| 661 | TFE_DeleteContextOptions(opts); |
| 662 | ASSERT_EQ(TF_OK, TF_GetCode(status.get())) << TF_Message(status.get()); |
| 663 | TFE_TensorHandle* hcpu = TestMatrixTensorHandle(); |
| 664 | const char* kErrorDevice = "NoSuchDevice:0"; |
| 665 | TFE_TensorHandle* hdevice = |
| 666 | TFE_TensorHandleCopyToDevice(hcpu, ctx, kErrorDevice, status.get()); |
| 667 | EXPECT_NE(TF_OK, TF_GetCode(status.get())); |
| 668 | const char* msg = "NoSuchDevice:0 unknown device"; |
| 669 | EXPECT_TRUE(strstr(TF_Message(status.get()), msg) != nullptr) |
| 670 | << TF_Message(status.get()); |
| 671 | TF_SetStatus(status.get(), TF_OK, ""); |
| 672 | const char* kCPUDevice = "CPU:0"; |
| 673 | TFE_TensorHandle* hcopy = |
| 674 | TFE_TensorHandleCopyToDevice(hcpu, ctx, kCPUDevice, status.get()); |
| 675 | EXPECT_EQ(TF_OK, TF_GetCode(status.get())) << TF_Message(status.get()); |
| 676 | |
| 677 | TFE_Executor* executor = TFE_ContextGetExecutorForThread(ctx); |
| 678 | TFE_ExecutorWaitForAllPendingNodes(executor, status.get()); |
| 679 | EXPECT_EQ(TF_OK, TF_GetCode(status.get())) << TF_Message(status.get()); |
| 680 | TFE_DeleteExecutor(executor); |
| 681 | TFE_DeleteTensorHandle(hcopy); |
| 682 | TFE_DeleteTensorHandle(hcpu); |
| 683 | if (hdevice != nullptr) TFE_DeleteTensorHandle(hdevice); |
| 684 | TFE_DeleteContext(ctx); |
| 685 | } |
| 686 | |
| 687 | TEST(CAPI, TensorHandleCopyBetweenDevicesError) { |
| 688 | TensorHandleCopyBetweenDevicesError(false); |
no test coverage detected