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.

client_config_test.cc 3.7 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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 <chrono>
  17. #include <cstdlib>
  18. #include <cstring>
  19. #include <functional>
  20. #include <iostream>
  21. #include <memory>
  22. #include <string>
  23. #include "minddata/dataset/core/client.h"
  24. #include "gtest/gtest.h"
  25. #include "minddata/dataset/core/global_context.h"
  26. #include "minddata/dataset/util/status.h"
  27. #include "minddata/dataset/core/client.h"
  28. #include "common/common.h"
  29. #include "gtest/gtest.h"
  30. #include "utils/log_adapter.h"
  31. #include <memory>
  32. #include <vector>
  33. #include <iostream>
  34. using namespace mindspore::dataset;
  35. using mindspore::MsLogLevel::INFO;
  36. using mindspore::ExceptionType::NoExceptionType;
  37. using mindspore::LogStream;
  38. class MindDataTestClientConfig : public UT::DatasetOpTesting {
  39. protected:
  40. };
  41. TEST_F(MindDataTestClientConfig, TestClientConfig1) {
  42. std::shared_ptr<ConfigManager> my_conf = GlobalContext::config_manager();
  43. ASSERT_EQ(my_conf->num_parallel_workers(), kCfgParallelWorkers);
  44. ASSERT_EQ(my_conf->worker_connector_size(), kCfgWorkerConnectorSize);
  45. ASSERT_EQ(my_conf->op_connector_size(), kCfgOpConnectorSize);
  46. ASSERT_EQ(my_conf->seed(), kCfgDefaultSeed);
  47. my_conf->set_num_parallel_workers(2);
  48. my_conf->set_worker_connector_size(3);
  49. my_conf->set_op_connector_size(4);
  50. my_conf->set_seed(5);
  51. ASSERT_EQ(my_conf->num_parallel_workers(), 2);
  52. ASSERT_EQ(my_conf->worker_connector_size(), 3);
  53. ASSERT_EQ(my_conf->op_connector_size(), 4);
  54. ASSERT_EQ(my_conf->seed(), 5);
  55. std::string file = datasets_root_path_ + "/declient.cfg";
  56. ASSERT_TRUE(my_conf->LoadFile(file));
  57. ASSERT_EQ(my_conf->num_parallel_workers(), kCfgParallelWorkers);
  58. ASSERT_EQ(my_conf->worker_connector_size(), kCfgWorkerConnectorSize);
  59. ASSERT_EQ(my_conf->op_connector_size(), kCfgOpConnectorSize);
  60. ASSERT_EQ(my_conf->seed(), kCfgDefaultSeed);
  61. }
  62. TEST_F(MindDataTestClientConfig, TestClientConfig2) {
  63. std::shared_ptr<ConfigManager> my_conf = GlobalContext::config_manager();
  64. my_conf->set_num_parallel_workers(8);
  65. Status rc;
  66. // Start with an empty execution tree
  67. auto my_tree = std::make_shared<ExecutionTree>();
  68. // Test info:
  69. // Dataset from testDataset1 has 10 rows, 2 columns.
  70. // RowsPerBuffer buffer setting of 2 divides evenly into total rows.
  71. std::string dataset_path;
  72. dataset_path = datasets_root_path_ + "/testDataset1/testDataset1.data";
  73. std::shared_ptr<TFReaderOp> my_tfreader_op;
  74. TFReaderOp::Builder builder;
  75. builder.SetDatasetFilesList({dataset_path});
  76. rc = builder.Build(&my_tfreader_op);
  77. ASSERT_TRUE(rc.IsOk());
  78. ASSERT_EQ(my_tfreader_op->num_workers(),1);
  79. my_tree->AssociateNode(my_tfreader_op);
  80. // Set children/root layout.
  81. my_tree->AssignRoot(my_tfreader_op);
  82. my_tree->Prepare();
  83. my_tree->Launch();
  84. // Start the loop of reading tensors from our pipeline
  85. DatasetIterator di(my_tree);
  86. TensorRow tensor_list;
  87. rc = di.FetchNextTensorRow(&tensor_list);
  88. ASSERT_TRUE(rc.IsOk());
  89. int row_count = 0;
  90. while (!tensor_list.empty()) {
  91. rc = di.FetchNextTensorRow(&tensor_list);
  92. ASSERT_TRUE(rc.IsOk());
  93. row_count++;
  94. }
  95. ASSERT_EQ(row_count, 10); // Should be 10 rows fetched
  96. ASSERT_EQ(my_tfreader_op->num_workers(),1);
  97. }