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.

context_test.cc 2.6 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /**
  2. * Copyright 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. #include <memory>
  17. #include "common/common_test.h"
  18. #include "include/api/context.h"
  19. namespace mindspore {
  20. class TestCxxApiContext : public UT::Common {
  21. public:
  22. TestCxxApiContext() = default;
  23. };
  24. TEST_F(TestCxxApiContext, test_context_global_context_SUCCESS) {
  25. std::string device_target = "2333";
  26. uint32_t device_id = 2333;
  27. GlobalContext::SetGlobalDeviceTarget(device_target);
  28. ASSERT_EQ(GlobalContext::GetGlobalDeviceTarget(), device_target);
  29. GlobalContext::SetGlobalDeviceID(device_id);
  30. ASSERT_EQ(GlobalContext::GetGlobalDeviceID(), device_id);
  31. }
  32. TEST_F(TestCxxApiContext, test_context_ascend310_context_SUCCESS) {
  33. std::string option_1 = "aaa";
  34. std::string option_2 = "vvv";
  35. std::string option_3 = "www";
  36. auto option_4 = DataType::kNumberTypeEnd;
  37. std::string option_5 = "rrr";
  38. std::string option_6 = "ppp";
  39. auto ctx = std::make_shared<ModelContext>();
  40. ModelContext::SetInsertOpConfigPath(ctx, option_1);
  41. ModelContext::SetInputFormat(ctx, option_2);
  42. ModelContext::SetInputShape(ctx, option_3);
  43. ModelContext::SetOutputType(ctx, option_4);
  44. ModelContext::SetPrecisionMode(ctx, option_5);
  45. ModelContext::SetOpSelectImplMode(ctx, option_6);
  46. ASSERT_EQ(ModelContext::GetInsertOpConfigPath(ctx), option_1);
  47. ASSERT_EQ(ModelContext::GetInputFormat(ctx), option_2);
  48. ASSERT_EQ(ModelContext::GetInputShape(ctx), option_3);
  49. ASSERT_EQ(ModelContext::GetOutputType(ctx), option_4);
  50. ASSERT_EQ(ModelContext::GetPrecisionMode(ctx), option_5);
  51. ASSERT_EQ(ModelContext::GetOpSelectImplMode(ctx), option_6);
  52. }
  53. TEST_F(TestCxxApiContext, test_context_ascend310_context_nullptr_FAILED) {
  54. auto ctx = std::make_shared<ModelContext>();
  55. EXPECT_ANY_THROW(ModelContext::GetInsertOpConfigPath(nullptr));
  56. }
  57. TEST_F(TestCxxApiContext, test_context_ascend310_context_default_value_SUCCESS) {
  58. auto ctx = std::make_shared<ModelContext>();
  59. ASSERT_EQ(ModelContext::GetOpSelectImplMode(ctx), "");
  60. }
  61. } // namespace mindspore