From 295c00ac39aacd8cb61b182fd5985ad249349576 Mon Sep 17 00:00:00 2001 From: Jonathan Yan Date: Mon, 30 Mar 2020 11:02:08 -0400 Subject: [PATCH] Replace std::cout with MS_LOG in dataset unit test Signed-off-by: Jonathan Yan --- tests/ut/cpp/dataset/arena_test.cc | 2 +- tests/ut/cpp/dataset/btree_test.cc | 2 +- tests/ut/cpp/dataset/cifar_op_test.cc | 12 ++++-- tests/ut/cpp/dataset/circular_pool_test.cc | 6 +-- tests/ut/cpp/dataset/image_folder_op_test.cc | 33 ++++++++++----- tests/ut/cpp/dataset/manifest_op_test.cc | 12 ++++-- tests/ut/cpp/dataset/map_op_test.cc | 4 +- tests/ut/cpp/dataset/memory_pool_test.cc | 4 +- tests/ut/cpp/dataset/mind_record_op_test.cc | 12 +++--- tests/ut/cpp/dataset/mnist_op_test.cc | 6 ++- tests/ut/cpp/dataset/normalize_op_test.cc | 2 +- tests/ut/cpp/dataset/one_hot_op_test.cc | 4 +- tests/ut/cpp/dataset/path_test.cc | 4 +- tests/ut/cpp/dataset/queue_test.cc | 2 +- .../random_crop_decode_resizeOp_test.cc | 4 +- .../cpp/dataset/stand_alone_samplers_test.cc | 2 +- tests/ut/cpp/dataset/status_test.cc | 8 ++-- tests/ut/cpp/dataset/task_manager_test.cc | 2 +- tests/ut/cpp/dataset/tensor_test.cc | 2 +- tests/ut/cpp/dataset/type_cast_op_test.cc | 2 +- .../cpp/mindrecord/ut_shard_operator_test.cc | 42 ++++++++++++------- tests/ut/cpp/runtest.sh | 1 + 22 files changed, 102 insertions(+), 66 deletions(-) diff --git a/tests/ut/cpp/dataset/arena_test.cc b/tests/ut/cpp/dataset/arena_test.cc index 4b5f50c47f..0809c40ee3 100644 --- a/tests/ut/cpp/dataset/arena_test.cc +++ b/tests/ut/cpp/dataset/arena_test.cc @@ -45,5 +45,5 @@ TEST_F(MindDataTestArena, TestALLFunction) { for (int i = 0; i < 1000; i++) { mp->Deallocate(v.at(i)); } - std::cout << *mp; + MS_LOG(DEBUG) << *mp; } diff --git a/tests/ut/cpp/dataset/btree_test.cc b/tests/ut/cpp/dataset/btree_test.cc index 993f8f465f..3e0a867fba 100644 --- a/tests/ut/cpp/dataset/btree_test.cc +++ b/tests/ut/cpp/dataset/btree_test.cc @@ -196,6 +196,6 @@ TEST_F(MindDataTestBPlusTree, Test3) { EXPECT_EQ(it.value(), "b"); MS_LOG(INFO) << "Dump all the values using [] operator."; for (uint64_t i = min; i <= max; i++) { - std::cout << ai[i] << std::endl; + MS_LOG(DEBUG) << ai[i] << std::endl; } } diff --git a/tests/ut/cpp/dataset/cifar_op_test.cc b/tests/ut/cpp/dataset/cifar_op_test.cc index 48c332bc13..0cd1db65b5 100644 --- a/tests/ut/cpp/dataset/cifar_op_test.cc +++ b/tests/ut/cpp/dataset/cifar_op_test.cc @@ -81,7 +81,8 @@ TEST_F(MindDataTestCifarOp, TestSequentialSamplerCifar10) { uint32_t label = 0; while (tensor_map.size() != 0) { tensor_map["label"]->GetItemAt(&label, {}); - std::cout << "row: " << i++ << "\t" << tensor_map["image"]->shape() << "label:" << label << "\n"; + MS_LOG(DEBUG) << "row: " << i << "\t" << tensor_map["image"]->shape() << "label:" << label << "\n"; + i++; di.GetNextAsMap(&tensor_map); } EXPECT_TRUE(i == 100); @@ -108,7 +109,8 @@ TEST_F(MindDataTestCifarOp, TestRandomSamplerCifar10) { uint32_t label = 0; while (tensor_map.size() != 0) { tensor_map["label"]->GetItemAt(&label, {}); - std::cout << "row: " << i++ << "\t" << tensor_map["image"]->shape() << "label:" << label << "\n"; + MS_LOG(DEBUG) << "row: " << i << "\t" << tensor_map["image"]->shape() << "label:" << label << "\n"; + i++; di.GetNextAsMap(&tensor_map); } EXPECT_TRUE(i == 12); @@ -133,7 +135,8 @@ TEST_F(MindDataTestCifarOp, TestCifar10NumSample) { uint32_t label = 0; while (tensor_map.size() != 0) { tensor_map["label"]->GetItemAt(&label, {}); - std::cout << "row: " << i++ << "\t" << tensor_map["image"]->shape() << "label:" << label << "\n"; + MS_LOG(DEBUG) << "row: " << i << "\t" << tensor_map["image"]->shape() << "label:" << label << "\n"; + i++; di.GetNextAsMap(&tensor_map); } EXPECT_TRUE(i == 100); @@ -159,8 +162,9 @@ TEST_F(MindDataTestCifarOp, TestSequentialSamplerCifar100) { while (tensor_map.size() != 0) { tensor_map["coarse_label"]->GetItemAt(&coarse, {}); tensor_map["fine_label"]->GetItemAt(&fine, {}); - std::cout << "row: " << i++ << "\t" << tensor_map["image"]->shape() << " coarse:" + MS_LOG(DEBUG) << "row: " << i << "\t" << tensor_map["image"]->shape() << " coarse:" << coarse << " fine:" << fine << "\n"; + i++; di.GetNextAsMap(&tensor_map); } EXPECT_TRUE(i == 100); diff --git a/tests/ut/cpp/dataset/circular_pool_test.cc b/tests/ut/cpp/dataset/circular_pool_test.cc index 47ceae5930..c42b08ddcd 100644 --- a/tests/ut/cpp/dataset/circular_pool_test.cc +++ b/tests/ut/cpp/dataset/circular_pool_test.cc @@ -52,7 +52,7 @@ Status TestMem(MindDataTestCircularPool *tp, int32_t num_iterations) { uint64_t new_sz = dist(gen); std::string str = "Allocate " + std::to_string(old_sz) + " bytes of memory and then resize to " + std::to_string(new_sz); - std::cout << str << std::endl; + MS_LOG(DEBUG) << str << std::endl; std::string id = Services::GetUniqueID(); void *p; RETURN_IF_NOT_OK(tp->mp_->Allocate(old_sz, &p)); @@ -76,9 +76,9 @@ TEST_F(MindDataTestCircularPool, TestALLFunction) { vg_.CreateAsyncTask("TestMem", f); } vg_.join_all(); - std::cout << vg_.GetTaskErrorIfAny() << std::endl; + MS_LOG(DEBUG) << vg_.GetTaskErrorIfAny() << std::endl; ASSERT_TRUE(vg_.GetTaskErrorIfAny().IsOk()); CircularPool *cp = dynamic_cast(mp_.get()); - std::cout << *cp << std::endl; + MS_LOG(DEBUG) << *cp << std::endl; } diff --git a/tests/ut/cpp/dataset/image_folder_op_test.cc b/tests/ut/cpp/dataset/image_folder_op_test.cc index 82513a29a5..5b118a629a 100644 --- a/tests/ut/cpp/dataset/image_folder_op_test.cc +++ b/tests/ut/cpp/dataset/image_folder_op_test.cc @@ -102,7 +102,8 @@ TEST_F(MindDataTestImageFolderSampler, TestSequentialImageFolderWithRepeat) { while (tensor_map.size() != 0) { tensor_map["label"]->GetItemAt(&label, {}); EXPECT_TRUE(res[(i % 44) / 11] == label); - std::cout << "row: " << i++ << "\t" << tensor_map["image"]->shape() << "label:" << label << "\n"; + MS_LOG(DEBUG) << "row: " << i << "\t" << tensor_map["image"]->shape() << "label:" << label << "\n"; + i++; di.GetNextAsMap(&tensor_map); } EXPECT_TRUE(i == 88); @@ -126,7 +127,8 @@ TEST_F(MindDataTestImageFolderSampler, TestRandomImageFolder) { int32_t label = 0; while (tensor_map.size() != 0) { tensor_map["label"]->GetItemAt(&label, {}); - std::cout << "row: " << i++ << "\t" << tensor_map["image"]->shape() << "label:" << label << "\n"; + MS_LOG(DEBUG) << "row: " << i << "\t" << tensor_map["image"]->shape() << "label:" << label << "\n"; + i++; di.GetNextAsMap(&tensor_map); } EXPECT_TRUE(i == 44); @@ -155,7 +157,8 @@ TEST_F(MindDataTestImageFolderSampler, TestRandomSamplerImageFolder) { while (tensor_map.size() != 0) { tensor_map["label"]->GetItemAt(&label, {}); EXPECT_TRUE(res[i] == label); - std::cout << "row: " << i++ << "\t" << tensor_map["image"]->shape() << "label:" << label << "\n"; + MS_LOG(DEBUG) << "row: " << i << "\t" << tensor_map["image"]->shape() << "label:" << label << "\n"; + i++; di.GetNextAsMap(&tensor_map); } EXPECT_TRUE(i == 12); @@ -185,8 +188,9 @@ TEST_F(MindDataTestImageFolderSampler, TestSequentialImageFolderWithRepeatBatch) std::shared_ptr label; Create1DTensor(&label, 11, reinterpret_cast(res[i % 4]), DataType::DE_INT32); EXPECT_TRUE((*label) == (*tensor_map["label"])); - std::cout << "row: " << i++ << " " << tensor_map["image"]->shape() << " (*label):" << (*label) + MS_LOG(DEBUG) << "row: " << i << " " << tensor_map["image"]->shape() << " (*label):" << (*label) << " *tensor_map[label]: " << *tensor_map["label"] << std::endl; + i++; di.GetNextAsMap(&tensor_map); } EXPECT_TRUE(i == 8); @@ -282,7 +286,8 @@ TEST_F(MindDataTestImageFolderSampler, TestImageFolderClassIndex) { while (tensor_map.size() != 0) { tensor_map["label"]->GetItemAt(&label, {}); EXPECT_TRUE(label == res[i / 11]); - std::cout << "row: " << i++ << "\t" << tensor_map["image"]->shape() << "label:" << label << "\n"; + MS_LOG(DEBUG) << "row: " << i << "\t" << tensor_map["image"]->shape() << "label:" << label << "\n"; + i++; di.GetNextAsMap(&tensor_map); } EXPECT_TRUE(i == 22); @@ -308,7 +313,8 @@ TEST_F(MindDataTestImageFolderSampler, TestDistributedSampler) { while (tensor_map.size() != 0) { tensor_map["label"]->GetItemAt(&label, {}); EXPECT_EQ(i % 4, label); - std::cout << "row:" << i++ << "\tlabel:" << label << "\n"; + MS_LOG(DEBUG) << "row:" << i << "\tlabel:" << label << "\n"; + i++; di.GetNextAsMap(&tensor_map); } EXPECT_TRUE(i == 16); @@ -335,7 +341,8 @@ TEST_F(MindDataTestImageFolderSampler, TestPKSamplerImageFolder) { while (tensor_map.size() != 0) { tensor_map["label"]->GetItemAt(&label, {}); EXPECT_TRUE(res[i] == label); - std::cout << "row: " << i++ << "\t" << tensor_map["image"]->shape() << "label:" << label << "\n"; + MS_LOG(DEBUG) << "row: " << i << "\t" << tensor_map["image"]->shape() << "label:" << label << "\n"; + i++; di.GetNextAsMap(&tensor_map); } EXPECT_TRUE(i == 12); @@ -360,7 +367,8 @@ TEST_F(MindDataTestImageFolderSampler, TestImageFolderNumSamples) { while (tensor_map.size() != 0) { tensor_map["label"]->GetItemAt(&label, {}); EXPECT_TRUE(0 == label); - std::cout << "row: " << i++ << "\t" << tensor_map["image"]->shape() << "label:" << label << "\n"; + MS_LOG(DEBUG) << "row: " << i << "\t" << tensor_map["image"]->shape() << "label:" << label << "\n"; + i++; di.GetNextAsMap(&tensor_map); } EXPECT_TRUE(i == 22); @@ -392,7 +400,8 @@ TEST_F(MindDataTestImageFolderSampler, TestImageFolderDecode) { EXPECT_TRUE(label == res[i / 11]); EXPECT_TRUE( tensor_map["image"]->shape() == TensorShape({2268, 4032, 3})); // verify shapes are correct after decode - std::cout << "row: " << i++ << "\t" << tensor_map["image"]->shape() << "label:" << label << "\n"; + MS_LOG(DEBUG) << "row: " << i << "\t" << tensor_map["image"]->shape() << "label:" << label << "\n"; + i++; di.GetNextAsMap(&tensor_map); } EXPECT_TRUE(i == 20); @@ -442,7 +451,8 @@ TEST_F(MindDataTestImageFolderSampler, TestImageFolderSharding1) { while (tensor_map.size() != 0) { tensor_map["label"]->GetItemAt(&label, {}); EXPECT_EQ(labels[i], label); - std::cout << "row:" << i++ << "\tlabel:" << label << "\n"; + MS_LOG(DEBUG) << "row:" << i << "\tlabel:" << label << "\n"; + i++; di.GetNextAsMap(&tensor_map); } EXPECT_TRUE(i == 5); @@ -470,7 +480,8 @@ TEST_F(MindDataTestImageFolderSampler, TestImageFolderSharding2) { while (tensor_map.size() != 0) { tensor_map["label"]->GetItemAt(&label, {}); EXPECT_EQ(labels[i], label); - std::cout << "row:" << i++ << "\tlabel:" << label << "\n"; + MS_LOG(DEBUG) << "row:" << i << "\tlabel:" << label << "\n"; + i++; di.GetNextAsMap(&tensor_map); } EXPECT_TRUE(i == 11); diff --git a/tests/ut/cpp/dataset/manifest_op_test.cc b/tests/ut/cpp/dataset/manifest_op_test.cc index e062335fa6..9e36f8c747 100644 --- a/tests/ut/cpp/dataset/manifest_op_test.cc +++ b/tests/ut/cpp/dataset/manifest_op_test.cc @@ -76,7 +76,8 @@ TEST_F(MindDataTestManifest, TestSequentialManifestWithRepeat) { while (tensor_map.size() != 0) { tensor_map["label"]->GetItemAt(&label, {}); EXPECT_TRUE(res[i] == label); - std::cout << "row: " << i++ << "\t" << tensor_map["image"]->shape() << "label:" << label << "\n"; + MS_LOG(DEBUG) << "row: " << i << "\t" << tensor_map["image"]->shape() << "label:" << label << "\n"; + i++; di.GetNextAsMap(&tensor_map); } EXPECT_TRUE(i == 4); @@ -134,7 +135,8 @@ TEST_F(MindDataTestManifest, MindDataTestManifestClassIndex) { while (tensor_map.size() != 0) { tensor_map["label"]->GetItemAt(&label, {}); EXPECT_TRUE(label == res[i]); - std::cout << "row: " << i++ << "\t" << tensor_map["image"]->shape() << "label:" << label << "\n"; + MS_LOG(DEBUG) << "row: " << i << "\t" << tensor_map["image"]->shape() << "label:" << label << "\n"; + i++; di.GetNextAsMap(&tensor_map); } EXPECT_TRUE(i == 2); @@ -159,7 +161,8 @@ TEST_F(MindDataTestManifest, MindDataTestManifestNumSamples) { while (tensor_map.size() != 0) { tensor_map["label"]->GetItemAt(&label, {}); EXPECT_TRUE(0 == label); - std::cout << "row: " << i++ << "\t" << tensor_map["image"]->shape() << "label:" << label << "\n"; + MS_LOG(DEBUG) << "row: " << i << "\t" << tensor_map["image"]->shape() << "label:" << label << "\n"; + i++; di.GetNextAsMap(&tensor_map); } EXPECT_TRUE(i == 4); @@ -184,7 +187,8 @@ TEST_F(MindDataTestManifest, MindDataTestManifestEval) { while (tensor_map.size() != 0) { tensor_map["label"]->GetItemAt(&label, {}); EXPECT_TRUE(0 == label); - std::cout << "row: " << i++ << "\t" << tensor_map["image"]->shape() << "label:" << label << "\n"; + MS_LOG(DEBUG) << "row: " << i << "\t" << tensor_map["image"]->shape() << "label:" << label << "\n"; + i++; di.GetNextAsMap(&tensor_map); } EXPECT_TRUE(i == 1); diff --git a/tests/ut/cpp/dataset/map_op_test.cc b/tests/ut/cpp/dataset/map_op_test.cc index 746c1e8d5f..271cbbe190 100644 --- a/tests/ut/cpp/dataset/map_op_test.cc +++ b/tests/ut/cpp/dataset/map_op_test.cc @@ -697,7 +697,7 @@ TEST_F(MindDataTestMapOp, ImageFolder_Decode_Repeat_Resize) { std::string result; while (tensor_map.size() != 0) { tensor_map["label"]->GetItemAt(&label, {}); - std::cout << "row:" << i << "\tlabel:" << label << "\n"; + MS_LOG(DEBUG) << "row:" << i << "\tlabel:" << label << "\n"; EXPECT_TRUE(img_class[(i % 44) / 11] == label); // Dump all the image into string, to be used as a comparison later. result.append((char *) tensor_map["image"]->StartAddr(), (int64_t) tensor_map["image"]->Size()); @@ -743,7 +743,7 @@ TEST_F(MindDataTestMapOp, ImageFolder_Decode_Repeat_Resize) { std::string result2; while (tensor_map.size() != 0) { tensor_map["label"]->GetItemAt(&label, {}); - std::cout << "row:" << i << "\tlabel:" << label << "\n"; + MS_LOG(DEBUG) << "row:" << i << "\tlabel:" << label << "\n"; EXPECT_TRUE(img_class[(i % 44) / 11] == label); result2.append((char *) tensor_map["image"]->StartAddr(), (int64_t) tensor_map["image"]->Size()); di2.GetNextAsMap(&tensor_map); diff --git a/tests/ut/cpp/dataset/memory_pool_test.cc b/tests/ut/cpp/dataset/memory_pool_test.cc index c988a09e89..136f3fe1b8 100644 --- a/tests/ut/cpp/dataset/memory_pool_test.cc +++ b/tests/ut/cpp/dataset/memory_pool_test.cc @@ -35,7 +35,7 @@ class MindDataTestMemoryPool : public UT::Common { }; TEST_F(MindDataTestMemoryPool, DumpPoolInfo) { - std::cout << *(std::dynamic_pointer_cast(mp_)) << std::endl; + MS_LOG(DEBUG) << *(std::dynamic_pointer_cast(mp_)) << std::endl; } TEST_F(MindDataTestMemoryPool, TestOperator1) { @@ -72,5 +72,5 @@ TEST_F(MindDataTestMemoryPool, TestAllocator) { std::shared_ptr obj_a = std::allocate_shared(alloc, 3); int v = obj_a->val_a(); ASSERT_EQ(v, 3); - std::cout << *(std::dynamic_pointer_cast(mp_)) << std::endl; + MS_LOG(DEBUG) << *(std::dynamic_pointer_cast(mp_)) << std::endl; } diff --git a/tests/ut/cpp/dataset/mind_record_op_test.cc b/tests/ut/cpp/dataset/mind_record_op_test.cc index 9664b66ecb..abe7faef14 100644 --- a/tests/ut/cpp/dataset/mind_record_op_test.cc +++ b/tests/ut/cpp/dataset/mind_record_op_test.cc @@ -69,7 +69,7 @@ TEST_F(MindDataTestMindRecordOp, TestMindRecordBasic) { rc = builder.Build(&my_mindrecord_op); ASSERT_TRUE(rc.IsOk()); - std::cout << (*my_mindrecord_op); + MS_LOG(DEBUG) << (*my_mindrecord_op); my_tree->AssociateNode(my_mindrecord_op); @@ -140,7 +140,7 @@ TEST_F(MindDataTestMindRecordOp, TestMindRecordSample) { rc = builder.Build(&my_mindrecord_op); ASSERT_TRUE(rc.IsOk()); - std::cout << (*my_mindrecord_op); + MS_LOG(DEBUG) << (*my_mindrecord_op); my_tree->AssociateNode(my_mindrecord_op); @@ -211,7 +211,7 @@ TEST_F(MindDataTestMindRecordOp, TestMindRecordShuffle) { rc = builder.Build(&my_mindrecord_op); ASSERT_TRUE(rc.IsOk()); - std::cout << (*my_mindrecord_op); + MS_LOG(DEBUG) << (*my_mindrecord_op); my_tree->AssociateNode(my_mindrecord_op); @@ -285,7 +285,7 @@ TEST_F(MindDataTestMindRecordOp, TestMindRecordCategory) { rc = builder.Build(&my_mindrecord_op); ASSERT_TRUE(rc.IsOk()); - std::cout << (*my_mindrecord_op); + MS_LOG(DEBUG) << (*my_mindrecord_op); my_tree->AssociateNode(my_mindrecord_op); @@ -352,7 +352,7 @@ TEST_F(MindDataTestMindRecordOp, TestMindRecordRepeat) { rc = builder.Build(&my_mindrecord_op); ASSERT_TRUE(rc.IsOk()); - std::cout << (*my_mindrecord_op); + MS_LOG(DEBUG) << (*my_mindrecord_op); rc = my_tree->AssociateNode(my_mindrecord_op); EXPECT_TRUE(rc.IsOk()); @@ -434,7 +434,7 @@ TEST_F(MindDataTestMindRecordOp, TestMindRecordBlockReaderRepeat) { rc = builder.Build(&my_mindrecord_op); ASSERT_TRUE(rc.IsOk()); - std::cout << (*my_mindrecord_op); + MS_LOG(DEBUG) << (*my_mindrecord_op); rc = my_tree->AssociateNode(my_mindrecord_op); EXPECT_TRUE(rc.IsOk()); diff --git a/tests/ut/cpp/dataset/mnist_op_test.cc b/tests/ut/cpp/dataset/mnist_op_test.cc index 3d5c4b05ca..2733597b35 100644 --- a/tests/ut/cpp/dataset/mnist_op_test.cc +++ b/tests/ut/cpp/dataset/mnist_op_test.cc @@ -91,7 +91,8 @@ TEST_F(MindDataTestMnistSampler, TestSequentialMnistWithRepeat) { while (tensor_map.size() != 0) { tensor_map["label"]->GetItemAt(&label, {}); EXPECT_TRUE(res[i % 10] == label); - std::cout << "row: " << i++ << "\t" << tensor_map["image"]->shape() << "label:" << label << "\n"; + MS_LOG(DEBUG) << "row: " << i << "\t" << tensor_map["image"]->shape() << "label:" << label << "\n"; + i++; di.GetNextAsMap(&tensor_map); } EXPECT_TRUE(i == 20); @@ -120,7 +121,8 @@ TEST_F(MindDataTestMnistSampler, TestSequentialImageFolderWithRepeatBatch) { std::shared_ptr label; Create1DTensor(&label, 5, reinterpret_cast(res[i % 4])); EXPECT_TRUE((*label) == (*tensor_map["label"])); - std::cout << "row: " << i++ << "\t" << tensor_map["image"]->shape() << "label:" << *tensor_map["label"] << "\n"; + MS_LOG(DEBUG) << "row: " << i << "\t" << tensor_map["image"]->shape() << "label:" << *tensor_map["label"] << "\n"; + i++; di.GetNextAsMap(&tensor_map); } EXPECT_TRUE(i == 4); diff --git a/tests/ut/cpp/dataset/normalize_op_test.cc b/tests/ut/cpp/dataset/normalize_op_test.cc index 373669a473..05ac3f6289 100644 --- a/tests/ut/cpp/dataset/normalize_op_test.cc +++ b/tests/ut/cpp/dataset/normalize_op_test.cc @@ -51,7 +51,7 @@ TEST_F(MindDataTestNormalizeOP, TestOp) { cv::Mat cv_output_image; cv_output_image = p->mat(); - std::cout << "Storing output file to : " << output_filename << std::endl; + MS_LOG(DEBUG) << "Storing output file to : " << output_filename << std::endl; cv::FileStorage file(output_filename, cv::FileStorage::WRITE); file << "imageData" << cv_output_image; } diff --git a/tests/ut/cpp/dataset/one_hot_op_test.cc b/tests/ut/cpp/dataset/one_hot_op_test.cc index 3928aeffd4..4b8bbc1bdd 100644 --- a/tests/ut/cpp/dataset/one_hot_op_test.cc +++ b/tests/ut/cpp/dataset/one_hot_op_test.cc @@ -47,8 +47,8 @@ TEST_F(MindDataTestOneHotOp, TestOp) { EXPECT_TRUE(s.IsOk()); ASSERT_TRUE(output->shape() == expected->shape()); ASSERT_TRUE(output->type() == expected->type()); - std::cout << *output << std::endl; - std::cout << *expected << std::endl; + MS_LOG(DEBUG) << *output << std::endl; + MS_LOG(DEBUG) << *expected << std::endl; ASSERT_TRUE(*output == *expected); MS_LOG(INFO) << "MindDataTestOneHotOp end."; diff --git a/tests/ut/cpp/dataset/path_test.cc b/tests/ut/cpp/dataset/path_test.cc index 7bd2abe7e5..3839d659aa 100644 --- a/tests/ut/cpp/dataset/path_test.cc +++ b/tests/ut/cpp/dataset/path_test.cc @@ -38,7 +38,7 @@ TEST_F(MindDataTestPath, Test1) { int i = 0; while (dir_it->hasNext()) { Path v = dir_it->next(); - std::cout << v.toString() << "\n"; + MS_LOG(DEBUG) << v.toString() << "\n"; i++; if (i == 10) { break; @@ -46,7 +46,7 @@ TEST_F(MindDataTestPath, Test1) { } // Test extension. Path g("file.jpeg"); - std::cout << g.Extension() << "\n"; + MS_LOG(DEBUG) << g.Extension() << "\n"; ASSERT_EQ(g.Extension(), ".jpeg"); } diff --git a/tests/ut/cpp/dataset/queue_test.cc b/tests/ut/cpp/dataset/queue_test.cc index 37560e5dfb..00366fcafd 100644 --- a/tests/ut/cpp/dataset/queue_test.cc +++ b/tests/ut/cpp/dataset/queue_test.cc @@ -44,7 +44,7 @@ class RefCount { explicit RefCount(int x) : v_(std::make_shared(x)) {} explicit RefCount(const RefCount &o) : v_(o.v_) {} ~RefCount() { - std::cout << "Destructor of RefCount called" << std::endl; + MS_LOG(DEBUG) << "Destructor of RefCount called" << std::endl; gRefCountDestructorCalled++; } RefCount& operator=(const RefCount &o) { diff --git a/tests/ut/cpp/dataset/random_crop_decode_resizeOp_test.cc b/tests/ut/cpp/dataset/random_crop_decode_resizeOp_test.cc index a4c4fbfdff..facd35c4f7 100644 --- a/tests/ut/cpp/dataset/random_crop_decode_resizeOp_test.cc +++ b/tests/ut/cpp/dataset/random_crop_decode_resizeOp_test.cc @@ -78,7 +78,7 @@ TEST_F(MindDataTestRandomCropDecodeResizeOp, TestOp2) { } else { mse = mse_sum; } - std::cout << "mse: " << mse << std::endl; + MS_LOG(DEBUG) << "mse: " << mse << std::endl; } MS_LOG(INFO) << "MindDataTestRandomCropDecodeResizeOp end!"; } @@ -150,7 +150,7 @@ TEST_F(MindDataTestRandomCropDecodeResizeOp, TestOp1) { } mse = (count == 0) ? mse_sum : static_cast(mse_sum) / count; - std::cout << "mse: " << mse << std::endl; + MS_LOG(DEBUG) << "mse: " << mse << std::endl; } MS_LOG(INFO) << "MindDataTestRandomCropDecodeResizeOp end!"; } diff --git a/tests/ut/cpp/dataset/stand_alone_samplers_test.cc b/tests/ut/cpp/dataset/stand_alone_samplers_test.cc index 2626add22e..c686a9486b 100644 --- a/tests/ut/cpp/dataset/stand_alone_samplers_test.cc +++ b/tests/ut/cpp/dataset/stand_alone_samplers_test.cc @@ -78,7 +78,7 @@ TEST_F(MindDataTestStandAloneSampler, TestDistributedSampler) { sampler->Init(&mock); sampler->GetNextBuffer(&db); db->GetTensor(&tensor, 0, 0); - std::cout << (*tensor); + MS_LOG(DEBUG) << (*tensor); if(i < 3) { // This is added due to std::shuffle() EXPECT_TRUE((*tensor) == (*row[i])); } diff --git a/tests/ut/cpp/dataset/status_test.cc b/tests/ut/cpp/dataset/status_test.cc index 835e6303b0..30bbd1e909 100644 --- a/tests/ut/cpp/dataset/status_test.cc +++ b/tests/ut/cpp/dataset/status_test.cc @@ -43,19 +43,19 @@ TEST_F(MindDataTestStatus, Test1) { Status rc; ASSERT_TRUE(rc.IsOk()); Status err1(StatusCode::kOutOfMemory, __LINE__, __FILE__); - std::cout << err1; + MS_LOG(DEBUG) << err1; ASSERT_TRUE(err1.IsOutofMemory()); ASSERT_TRUE(err1.IsError()); Status err2(StatusCode::kUnexpectedError, __LINE__, __FILE__, "Oops"); - std::cout << err2; + MS_LOG(DEBUG) << err2; } TEST_F(MindDataTestStatus, Test2) { Status rc = f1(); - std::cout << rc; + MS_LOG(DEBUG) << rc; } TEST_F(MindDataTestStatus, Test3) { Status rc = f3(); - std::cout << rc; + MS_LOG(DEBUG) << rc; } diff --git a/tests/ut/cpp/dataset/task_manager_test.cc b/tests/ut/cpp/dataset/task_manager_test.cc index 182eee1882..c6fccd51cb 100644 --- a/tests/ut/cpp/dataset/task_manager_test.cc +++ b/tests/ut/cpp/dataset/task_manager_test.cc @@ -36,7 +36,7 @@ Status f(TaskGroup &vg){ RETURN_IF_NOT_OK(vg.CreateAsyncTask("Infinity", [&]() -> Status { TaskManager::FindMe()->Post(); int a = v.fetch_add(1); - std::cout << a << std::endl; + MS_LOG(DEBUG) << a << std::endl; return f(vg); })); } diff --git a/tests/ut/cpp/dataset/tensor_test.cc b/tests/ut/cpp/dataset/tensor_test.cc index 6686be15be..7437b3d942 100644 --- a/tests/ut/cpp/dataset/tensor_test.cc +++ b/tests/ut/cpp/dataset/tensor_test.cc @@ -311,7 +311,7 @@ TEST_F(MindDataTestTensorDE, CVTensorAs) { m = 2 * m; ASSERT_EQ(ctv->StartAddr(), addr); ASSERT_TRUE(*t2 == *ctv); - std::cout << *t2 << std::endl << *ctv; + MS_LOG(DEBUG) << *t2 << std::endl << *ctv; } TEST_F(MindDataTestTensorDE, CVTensorMatSlice) { diff --git a/tests/ut/cpp/dataset/type_cast_op_test.cc b/tests/ut/cpp/dataset/type_cast_op_test.cc index 0bd1e90eae..f5fa035579 100644 --- a/tests/ut/cpp/dataset/type_cast_op_test.cc +++ b/tests/ut/cpp/dataset/type_cast_op_test.cc @@ -54,7 +54,7 @@ void testCast(std::vector values, const DataType &from, const DataType &to EXPECT_TRUE(op->Compute(t, &output)); ASSERT_TRUE(t->shape() == output->shape()); ASSERT_TRUE(DataType(to)==output->type()); - std::cout << *output << std::endl; + MS_LOG(DEBUG) << *output << std::endl; auto out = output->begin(); auto v = values.begin(); for (; out != output->end(); out++, v++) { diff --git a/tests/ut/cpp/mindrecord/ut_shard_operator_test.cc b/tests/ut/cpp/mindrecord/ut_shard_operator_test.cc index acea1cefae..46ea1712b2 100644 --- a/tests/ut/cpp/mindrecord/ut_shard_operator_test.cc +++ b/tests/ut/cpp/mindrecord/ut_shard_operator_test.cc @@ -58,7 +58,8 @@ TEST_F(TestShardOperator, TestShardSampleBasic) { while (true) { auto x = dataset.GetNext(); if (x.empty()) break; - MS_LOG(INFO) << "index: " << i++ << ", filename: " << common::SafeCStr((std::get<1>(x[0]))["file_name"]); + MS_LOG(INFO) << "index: " << i << ", filename: " << common::SafeCStr((std::get<1>(x[0]))["file_name"]); + i++; } dataset.Finish(); ASSERT_TRUE(i <= kSampleCount); @@ -83,7 +84,8 @@ TEST_F(TestShardOperator, TestShardSampleWrongNumber) { while (true) { auto x = dataset.GetNext(); if (x.empty()) break; - MS_LOG(INFO) << "index: " << i++ << ", filename: " << common::SafeCStr((std::get<1>(x[0]))["file_name"]); + MS_LOG(INFO) << "index: " << i << ", filename: " << common::SafeCStr((std::get<1>(x[0]))["file_name"]); + i++; } dataset.Finish(); ASSERT_TRUE(i <= 5); @@ -108,7 +110,8 @@ TEST_F(TestShardOperator, TestShardSampleRatio) { while (true) { auto x = dataset.GetNext(); if (x.empty()) break; - MS_LOG(INFO) << "index: " << i++ << ", filename: " << common::SafeCStr((std::get<1>(x[0]))["file_name"]); + MS_LOG(INFO) << "index: " << i << ", filename: " << common::SafeCStr((std::get<1>(x[0]))["file_name"]); + i++; } dataset.Finish(); ASSERT_TRUE(i <= 10); @@ -137,7 +140,8 @@ TEST_F(TestShardOperator, TestShardSamplePartition) { while (true) { auto x = dataset.GetNext(); if (x.empty()) break; - MS_LOG(INFO) << "index: " << i++ << ", filename: " << common::SafeCStr((std::get<1>(x[0]))["file_name"]); + MS_LOG(INFO) << "index: " << i << ", filename: " << common::SafeCStr((std::get<1>(x[0]))["file_name"]); + i++; } dataset.Finish(); ASSERT_TRUE(i <= 10); @@ -166,8 +170,9 @@ TEST_F(TestShardOperator, TestShardCategory) { auto x = dataset.GetNext(); if (x.empty()) break; - MS_LOG(INFO) << "index: " << i++ << ", filename: " << common::SafeCStr((std::get<1>(x[0]))["file_name"]) << + MS_LOG(INFO) << "index: " << i << ", filename: " << common::SafeCStr((std::get<1>(x[0]))["file_name"]) << ", label: " << common::SafeCStr((std::get<1>(x[0]))["label"].dump()); + i++; ASSERT_TRUE((std::get<1>(x[0]))["label"] == categories[category_no].second); @@ -194,8 +199,9 @@ TEST_F(TestShardOperator, TestShardShuffle) { while (true) { auto x = dataset.GetNext(); if (x.empty()) break; - MS_LOG(INFO) << "index: " << i++ << ", filename: " << common::SafeCStr((std::get<1>(x[0]))["file_name"]) << + MS_LOG(INFO) << "index: " << i << ", filename: " << common::SafeCStr((std::get<1>(x[0]))["file_name"]) << ", label: " << common::SafeCStr((std::get<1>(x[0]))["label"].dump()); + i++; } dataset.Finish(); } @@ -218,8 +224,9 @@ TEST_F(TestShardOperator, TestShardSampleShuffle) { while (true) { auto x = dataset.GetNext(); if (x.empty()) break; - MS_LOG(INFO) << "index: " << i++ << ", filename: " << common::SafeCStr((std::get<1>(x[0]))["file_name"]) << + MS_LOG(INFO) << "index: " << i << ", filename: " << common::SafeCStr((std::get<1>(x[0]))["file_name"]) << ", label: " << common::SafeCStr((std::get<1>(x[0]))["label"].dump()); + i++; } dataset.Finish(); ASSERT_LE(i, 35); @@ -244,8 +251,9 @@ TEST_F(TestShardOperator, TestShardShuffleSample) { while (true) { auto x = dataset.GetNext(); if (x.empty()) break; - MS_LOG(INFO) << "index: " << i++ << ", filename: " << common::SafeCStr((std::get<1>(x[0]))["file_name"]) << + MS_LOG(INFO) << "index: " << i << ", filename: " << common::SafeCStr((std::get<1>(x[0]))["file_name"]) << ", label: " << common::SafeCStr((std::get<1>(x[0]))["label"].dump()); + i++; } dataset.Finish(); ASSERT_TRUE(i <= kSampleSize); @@ -270,8 +278,9 @@ TEST_F(TestShardOperator, TestShardSampleShuffleSample) { while (true) { auto x = dataset.GetNext(); if (x.empty()) break; - MS_LOG(INFO) << "index: " << i++ << ", filename: " << common::SafeCStr((std::get<1>(x[0]))["file_name"]) << + MS_LOG(INFO) << "index: " << i << ", filename: " << common::SafeCStr((std::get<1>(x[0]))["file_name"]) << ", label: " << common::SafeCStr((std::get<1>(x[0]))["label"].dump()); + i++; } dataset.Finish(); ASSERT_LE(i, 35); @@ -298,8 +307,9 @@ TEST_F(TestShardOperator, TestShardShuffleCompare) { while (true) { auto x = dataset.GetNext(); if (x.empty()) break; - MS_LOG(INFO) << "index: " << i++ << ", filename: " << common::SafeCStr((std::get<1>(x[0]))["file_name"]) << + MS_LOG(INFO) << "index: " << i << ", filename: " << common::SafeCStr((std::get<1>(x[0]))["file_name"]) << ", label: " << common::SafeCStr((std::get<1>(x[0]))["label"].dump()); + i++; auto y = compare_dataset.GetNext(); if ((std::get<1>(x[0]))["file_name"] != (std::get<1>(y[0]))["file_name"]) different = true; @@ -332,8 +342,9 @@ TEST_F(TestShardOperator, TestShardCategoryShuffle1) { while (true) { auto x = dataset.GetNext(); if (x.empty()) break; - MS_LOG(INFO) << "index: " << i++ << ", filename: " << common::SafeCStr((std::get<1>(x[0]))["file_name"]) << + MS_LOG(INFO) << "index: " << i << ", filename: " << common::SafeCStr((std::get<1>(x[0]))["file_name"]) << ", label: " << common::SafeCStr((std::get<1>(x[0]))["label"].dump()); + i++; ASSERT_TRUE((std::get<1>(x[0]))["label"] == categories[category_no].second); category_no++; @@ -365,8 +376,9 @@ TEST_F(TestShardOperator, TestShardCategoryShuffle2) { while (true) { auto x = dataset.GetNext(); if (x.empty()) break; - MS_LOG(INFO) << "index: " << i++ << ", filename: " << common::SafeCStr((std::get<1>(x[0]))["file_name"]) << + MS_LOG(INFO) << "index: " << i << ", filename: " << common::SafeCStr((std::get<1>(x[0]))["file_name"]) << ", label: " << common::SafeCStr((std::get<1>(x[0]))["label"].dump()); + i++; ASSERT_TRUE((std::get<1>(x[0]))["label"] == categories[category_no].second); category_no++; category_no %= static_cast(categories.size()); @@ -398,8 +410,9 @@ TEST_F(TestShardOperator, TestShardCategorySample) { while (true) { auto x = dataset.GetNext(); if (x.empty()) break; - MS_LOG(INFO) << "index: " << i++ << ", filename: " << common::SafeCStr((std::get<1>(x[0]))["file_name"]) << + MS_LOG(INFO) << "index: " << i << ", filename: " << common::SafeCStr((std::get<1>(x[0]))["file_name"]) << ", label: " << common::SafeCStr((std::get<1>(x[0]))["label"].dump()); + i++; ASSERT_TRUE((std::get<1>(x[0]))["label"] == categories[category_no].second); category_no++; @@ -435,8 +448,9 @@ TEST_F(TestShardOperator, TestShardCategorySampleShuffle) { while (true) { auto x = dataset.GetNext(); if (x.empty()) break; - MS_LOG(INFO) << "index: " << i++ << ", filename: " << common::SafeCStr((std::get<1>(x[0]))["file_name"]) << + MS_LOG(INFO) << "index: " << i << ", filename: " << common::SafeCStr((std::get<1>(x[0]))["file_name"]) << ", label: " << common::SafeCStr((std::get<1>(x[0]))["label"].dump()); + i++; ASSERT_TRUE((std::get<1>(x[0]))["label"] == categories[category_no].second); category_no++; diff --git a/tests/ut/cpp/runtest.sh b/tests/ut/cpp/runtest.sh index a50e1d4933..283d6bc639 100755 --- a/tests/ut/cpp/runtest.sh +++ b/tests/ut/cpp/runtest.sh @@ -28,6 +28,7 @@ cd ${BUILD_PATH}/mindspore/tests/ut/cpp export LD_LIBRARY_PATH=${BUILD_PATH}/mindspore/googletest/googlemock/gtest:${PROJECT_PATH}/mindspore:${PROJECT_PATH}/mindspore/lib:$LD_LIBRARY_PATH export PYTHONPATH=${PROJECT_PATH}/tests/ut/cpp/python_input:$PYTHONPATH:${PROJECT_PATH} +export GLOG_v=2 ## prepare data for dataset & mindrecord cp -fr $PROJECT_PATH/tests/ut/data ${PROJECT_PATH}/build/mindspore/tests/ut/cpp/