• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1  /*
2  * Copyright (c) 2025 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "audio_schedule.h"
17 #include "audio_schedule_guard.h"
18 
19 #include <pthread.h>
20 #include <sched.h>
21 #include <chrono>
22 #include <cstdint>
23 
24 #include <gtest/gtest.h>
25 #include "parameter.h"
26 
27 using namespace testing::ext;
28 using namespace std;
29 
30 namespace OHOS {
31 namespace AudioStandard {
32 
33 const int32_t HIGH_LEVEL_THREAD_PRIORITY = 4;
34 const int32_t AUDIO_DEFAULT_PRIORITY = 1;
35 
GetIntParameter(const char * key,int32_t defaultValue)36 int32_t GetIntParameter(const char* key, int32_t defaultValue)
37 {
38     return defaultValue;
39 }
40 
AudioInfoLog(const char * format,...)41 void AudioInfoLog(const char* format, ...) {}
AudioErrLog(const char * format,...)42 void AudioErrLog(const char* format, ...) {}
43 
44 class AudioScheduleUnitTest : public ::testing::Test {
45 public:
SetUpTestCase()46     static void SetUpTestCase(){};
TearDownTestCase()47     static void TearDownTestCase(){};
SetUp()48     virtual void SetUp(){};
TearDown()49     virtual void TearDown() {}
50 };
51 
52 /**
53  * @tc.name   : Test AudioScheduleUnit
54  * @tc.number : AudioScheduleUnitTest_001
55  * @tc.desc   : Test AudioScheduleUnitTest_001
56  */
57 HWTEST_F(AudioScheduleUnitTest, AudioScheduleUnitTest_001, TestSize.Level1)
58 {
59     SetProcessDataThreadPriority(1);
60     GetIntParameter("const.multimedia.audio_setPriority", AUDIO_DEFAULT_PRIORITY);
61     EXPECT_FALSE(SetEndpointThreadPriority());
62 }
63 
64 /**
65  * @tc.name   : Test AudioScheduleUnit
66  * @tc.number : AudioScheduleUnitTest_002
67  * @tc.desc   : Test AudioScheduleUnitTest_002
68  */
69 HWTEST_F(AudioScheduleUnitTest, AudioScheduleUnitTest_002, TestSize.Level1)
70 {
71     SetProcessDataThreadPriority(4);
72     GetIntParameter("const.multimedia.audio_setPriority", HIGH_LEVEL_THREAD_PRIORITY);
73     EXPECT_FALSE(SetEndpointThreadPriority());
74 }
75 
76 /**
77  * @tc.name   : Test AudioScheduleUnit
78  * @tc.number : AudioScheduleUnitTest_003
79  * @tc.desc   : Test AudioScheduleUnitTest_003
80  */
81  HWTEST_F(AudioScheduleUnitTest, AudioScheduleUnitTest_003, TestSize.Level3)
82  {
83      SetProcessDataThreadPriority(-1);
84      GetIntParameter("const.multimedia.audio_setPriority", HIGH_LEVEL_THREAD_PRIORITY);
85      EXPECT_FALSE(SetEndpointThreadPriority());
86  }
87 
88 /**
89  * @tc.name   : Test ResetProcessDataThreadPriority
90  * @tc.number : ResetProcessDataThreadPriorityTest_001
91  * @tc.desc   : Test ResetProcessDataThreadPriority
92  */
93 HWTEST_F(AudioScheduleUnitTest, ResetProcessDataThreadPriorityTest_002, TestSize.Level1)
94 {
95     ResetProcessDataThreadPriority();
96     GetIntParameter("const.multimedia.audio_setPriority", HIGH_LEVEL_THREAD_PRIORITY);
97     EXPECT_TRUE(SetEndpointThreadPriority());
98 }
99 
100 /**
101  * @tc.name   : Test ResetEndpointThreadPriority
102  * @tc.number : ResetEndpointThreadPriorityTest_001
103  * @tc.desc   : Test ResetEndpointThreadPriority
104  */
105 HWTEST_F(AudioScheduleUnitTest, ResetEndpointThreadPriorityTest_002, TestSize.Level1)
106 {
107     EXPECT_TRUE(ResetEndpointThreadPriority());
108 }
109 } // namespace AudioStandard
110 } // namespace OHOS