You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

rename_op_test.cc 3.6 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /**
  2. * Copyright 2019 Huawei Technologies Co., Ltd
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #include <cstring>
  17. #include <iostream>
  18. #include <memory>
  19. #include <string>
  20. #include "dataset/core/client.h"
  21. #include "dataset/core/constants.h"
  22. #include "dataset/engine/datasetops/map_op.h"
  23. #include "dataset/engine/datasetops/rename_op.h"
  24. #include "common/common.h"
  25. #include "common/utils.h"
  26. #include "dataset/engine/data_buffer.h"
  27. #include "gtest/gtest.h"
  28. #include "dataset/core/global_context.h"
  29. #include "utils/log_adapter.h"
  30. namespace common = mindspore::common;
  31. using namespace mindspore::dataset;
  32. using mindspore::MsLogLevel::INFO;
  33. using mindspore::ExceptionType::NoExceptionType;
  34. using mindspore::LogStream;
  35. class MindDataTestRenameOp : public UT::DatasetOpTesting {
  36. };
  37. TEST_F(MindDataTestRenameOp, TestRenameOpDefault) {
  38. // Tree:
  39. //
  40. //
  41. // OpId(2) RenameOp
  42. // |
  43. // OpId(0) StorageOp
  44. // Start with an empty execution tree
  45. Status rc;
  46. MS_LOG(INFO) << "UT test TestRenameBasic.";
  47. auto my_tree = std::make_shared<ExecutionTree>();
  48. // Creating StorageOp
  49. std::string dataset_path = datasets_root_path_ + "/test_tf_file_3_images_1";
  50. std::shared_ptr<StorageOp> my_storage_op;
  51. rc = StorageOp::Builder()
  52. .SetDatasetFilesDir(dataset_path)
  53. .SetRowsPerBuffer(2)
  54. .SetWorkerConnectorSize(16)
  55. .SetNumWorkers(1)
  56. .Build(&my_storage_op);
  57. EXPECT_TRUE(rc.IsOk());
  58. rc = my_tree->AssociateNode(my_storage_op);
  59. EXPECT_TRUE(rc.IsOk());
  60. // Creating DatasetOp
  61. std::vector<std::string> in_colnames = {"label"};
  62. std::vector<std::string> out_colnames = {"label1"};
  63. std::shared_ptr<RenameOp> rename_op;
  64. rc = RenameOp::Builder()
  65. .SetInColNames(in_colnames)
  66. .SetOutColNames(out_colnames)
  67. .Build(&rename_op);
  68. EXPECT_TRUE(rc.IsOk());
  69. rc = my_tree->AssociateNode(rename_op);
  70. EXPECT_TRUE(rc.IsOk());
  71. rc = rename_op->AddChild(std::move(my_storage_op));
  72. EXPECT_TRUE(rc.IsOk());
  73. rc = my_tree->AssignRoot(rename_op);
  74. EXPECT_TRUE(rc.IsOk());
  75. rc = my_tree->Prepare();
  76. EXPECT_TRUE(rc.IsOk());
  77. // Launch the tree execution to kick off threads and start running the pipeline
  78. MS_LOG(INFO) << "Launching my tree.";
  79. rc = my_tree->Launch();
  80. EXPECT_TRUE(rc.IsOk());
  81. // Simulate a parse of data from our pipeline.
  82. std::shared_ptr<DatasetOp> root_node = my_tree->root();
  83. DatasetIterator di(my_tree);
  84. TensorRow tensor_list;
  85. rc = di.FetchNextTensorRow(&tensor_list);
  86. EXPECT_TRUE(rc.IsOk());
  87. int row_count = 0;
  88. while (!tensor_list.empty()) {
  89. MS_LOG(INFO) << "Row display for row #: " << row_count << ".";
  90. // Display the tensor by calling the printer on it
  91. for (int i = 0; i < tensor_list.size(); i++) {
  92. std::ostringstream ss;
  93. ss << "(" << tensor_list[i] << "): " << *tensor_list[i] << std::endl;
  94. MS_LOG(INFO) << "Tensor print: " << ss.str() << ".";
  95. }
  96. rc = di.FetchNextTensorRow(&tensor_list);
  97. EXPECT_TRUE(rc.IsOk());
  98. row_count++;
  99. }
  100. ASSERT_EQ(row_count, 3); // Should be 3 rows fetched
  101. }