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

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