• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
23 using namespace mindspore::dataset;
24 using mindspore::MsLogLevel::INFO;
25 using mindspore::ExceptionType::NoExceptionType;
26 using mindspore::LogStream;
27 
28 class MindDataTestIntrpService : public UT::Common {
29  public:
MindDataTestIntrpService()30     MindDataTestIntrpService() {}
31 
SetUp()32     void SetUp() {}
33 
34     TaskGroup vg_;
35 };
36 
TEST_F(MindDataTestIntrpService,Test1)37 TEST_F(MindDataTestIntrpService, Test1) {
38   Status rc;
39   Queue<int> q(3);
40   q.Register(&vg_);
41   vg_.CreateAsyncTask("Test1", [&]() -> Status {
42     TaskManager::FindMe()->Post();
43       int v;
44       Status rc;
45       rc = q.PopFront(&v);
46       EXPECT_TRUE(rc == StatusCode::kMDInterrupted);
47       return rc;
48   });
49   vg_.GetIntrpService()->InterruptAll();
50   vg_.join_all(Task::WaitFlag::kNonBlocking);
51 }
52 
TEST_F(MindDataTestIntrpService,Test2)53 TEST_F(MindDataTestIntrpService, Test2) {
54   MS_LOG(INFO) << "Test Semaphore";
55   Status rc;
56   WaitPost wp;
57   rc = wp.Register(&vg_);
58   EXPECT_TRUE(rc.IsOk());
59   vg_.CreateAsyncTask("Test1", [&]() -> Status {
60     TaskManager::FindMe()->Post();
61       Status rc = wp.Wait();
62       EXPECT_TRUE(rc == StatusCode::kMDInterrupted);
63       return rc;
64   });
65   vg_.GetIntrpService()->InterruptAll();
66   vg_.join_all(Task::WaitFlag::kNonBlocking);
67 }