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.

common.h 3.8 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /**
  2. * Copyright 2019-2021 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. #ifndef TESTS_UT_CPP_DATASET_COMMON_COMMON_H_
  17. #define TESTS_UT_CPP_DATASET_COMMON_COMMON_H_
  18. #include "gtest/gtest.h"
  19. #include "include/api/status.h"
  20. #include "include/api/types.h"
  21. #include "minddata/dataset/core/tensor_shape.h"
  22. #include "minddata/dataset/include/type_id.h"
  23. #include "utils/log_adapter.h"
  24. using mindspore::Status;
  25. using mindspore::StatusCode;
  26. #define ASSERT_OK(_s) \
  27. do { \
  28. Status __rc = (_s); \
  29. if (__rc.IsError()) { \
  30. MS_LOG(ERROR) << __rc.ToString() << "."; \
  31. ASSERT_TRUE(false); \
  32. } \
  33. } while (false)
  34. #define EXPECT_OK(_s) \
  35. do { \
  36. Status __rc = (_s); \
  37. if (__rc.IsError()) { \
  38. MS_LOG(ERROR) << __rc.ToString() << "."; \
  39. EXPECT_TRUE(false); \
  40. } \
  41. } while (false)
  42. #define ASSERT_ERROR(_s) \
  43. do { \
  44. Status __rc = (_s); \
  45. if (__rc.IsOk()) { \
  46. MS_LOG(ERROR) << __rc.ToString() << "."; \
  47. ASSERT_TRUE(false); \
  48. } \
  49. } while (false)
  50. #define EXPECT_ERROR(_s) \
  51. do { \
  52. Status __rc = (_s); \
  53. if (__rc.IsOk()) { \
  54. MS_LOG(ERROR) << __rc.ToString() << "."; \
  55. EXPECT_TRUE(false); \
  56. } \
  57. } while (false)
  58. // Macro to compare 2 MSTensors; compare shape-size and data
  59. #define EXPECT_MSTENSOR_EQ(_mstensor1, _mstensor2) \
  60. do { \
  61. EXPECT_EQ(_mstensor1.Shape().size(), _mstensor2.Shape().size()); \
  62. EXPECT_EQ(_mstensor1.DataSize(), _mstensor2.DataSize()); \
  63. EXPECT_EQ(std::memcmp((const void *)_mstensor1.Data().get(), (const void *)_mstensor2.Data().get(), \
  64. _mstensor2.DataSize()), 0); \
  65. } while (false)
  66. namespace UT {
  67. class Common : public testing::Test {
  68. public:
  69. // every TEST_F macro will enter one
  70. virtual void SetUp();
  71. virtual void TearDown();
  72. };
  73. class DatasetOpTesting : public Common {
  74. public:
  75. std::vector<mindspore::dataset::TensorShape> ToTensorShapeVec(const std::vector<std::vector<int64_t>> &v);
  76. std::vector<mindspore::dataset::DataType> ToDETypes(const std::vector<mindspore::DataType> &t);
  77. mindspore::MSTensor ReadFileToTensor(const std::string &file);
  78. std::string datasets_root_path_;
  79. std::string mindrecord_root_path_;
  80. void SetUp() override;
  81. };
  82. } // namespace UT
  83. #endif // TESTS_UT_CPP_DATASET_COMMON_COMMON_H_