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.

interrupt_test.cc 1.9 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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 "common/common.h"
  17. #include "utils/log_adapter.h"
  18. #include "minddata/dataset/util/services.h"
  19. #include "minddata/dataset/util/intrp_service.h"
  20. #include "minddata/dataset/util/task_manager.h"
  21. #include "minddata/dataset/util/queue.h"
  22. using namespace mindspore::dataset;
  23. using mindspore::MsLogLevel::INFO;
  24. using mindspore::ExceptionType::NoExceptionType;
  25. using mindspore::LogStream;
  26. class MindDataTestIntrpService : public UT::Common {
  27. public:
  28. MindDataTestIntrpService() {}
  29. void SetUp() {}
  30. TaskGroup vg_;
  31. };
  32. TEST_F(MindDataTestIntrpService, Test1) {
  33. Status rc;
  34. Queue<int> q(3);
  35. q.Register(&vg_);
  36. vg_.CreateAsyncTask("Test1", [&]() -> Status {
  37. TaskManager::FindMe()->Post();
  38. int v;
  39. Status rc;
  40. rc = q.PopFront(&v);
  41. EXPECT_TRUE(rc.IsInterrupted());
  42. return rc;
  43. });
  44. vg_.GetIntrpService()->InterruptAll();
  45. vg_.join_all(Task::WaitFlag::kNonBlocking);
  46. }
  47. TEST_F(MindDataTestIntrpService, Test2) {
  48. MS_LOG(INFO) << "Test Semaphore";
  49. Status rc;
  50. WaitPost wp;
  51. rc = wp.Register(&vg_);
  52. EXPECT_TRUE(rc.IsOk());
  53. vg_.CreateAsyncTask("Test1", [&]() -> Status {
  54. TaskManager::FindMe()->Post();
  55. Status rc = wp.Wait();
  56. EXPECT_TRUE(rc.IsInterrupted());
  57. return rc;
  58. });
  59. vg_.GetIntrpService()->InterruptAll();
  60. vg_.join_all(Task::WaitFlag::kNonBlocking);
  61. }