1 /*
2 * Copyright (C) 2019 The Android Open Source Project
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
17 #include "palette/palette.h"
18
19 #include <unistd.h>
20 #include <sys/syscall.h>
21
22 #include "gtest/gtest.h"
23
24 namespace {
25
GetTid()26 pid_t GetTid() {
27 #ifdef __BIONIC__
28 return gettid();
29 #else // __BIONIC__
30 return syscall(__NR_gettid);
31 #endif // __BIONIC__
32 }
33
34 } // namespace
35
36 class PaletteClientTest : public testing::Test {};
37
TEST_F(PaletteClientTest,GetVersion)38 TEST_F(PaletteClientTest, GetVersion) {
39 int32_t version = -1;
40 PaletteStatus status = PaletteGetVersion(&version);
41 ASSERT_EQ(PaletteStatus::kOkay, status);
42 ASSERT_GE(version, 1);
43 }
44
TEST_F(PaletteClientTest,SchedPriority)45 TEST_F(PaletteClientTest, SchedPriority) {
46 int32_t tid = GetTid();
47 int32_t saved_priority;
48 EXPECT_EQ(PaletteStatus::kOkay, PaletteSchedGetPriority(tid, &saved_priority));
49
50 EXPECT_EQ(PaletteStatus::kInvalidArgument, PaletteSchedSetPriority(tid, /*java_priority=*/ 0));
51 EXPECT_EQ(PaletteStatus::kInvalidArgument, PaletteSchedSetPriority(tid, /*java_priority=*/ -1));
52 EXPECT_EQ(PaletteStatus::kInvalidArgument, PaletteSchedSetPriority(tid, /*java_priority=*/ 11));
53
54 EXPECT_EQ(PaletteStatus::kOkay, PaletteSchedSetPriority(tid, /*java_priority=*/ 1));
55 EXPECT_EQ(PaletteStatus::kOkay, PaletteSchedSetPriority(tid, saved_priority));
56 }
57
TEST_F(PaletteClientTest,Trace)58 TEST_F(PaletteClientTest, Trace) {
59 int32_t enabled;
60 EXPECT_EQ(PaletteStatus::kOkay, PaletteTraceEnabled(&enabled));
61 EXPECT_EQ(PaletteStatus::kOkay, PaletteTraceBegin("Hello world!"));
62 EXPECT_EQ(PaletteStatus::kOkay, PaletteTraceEnd());
63 EXPECT_EQ(PaletteStatus::kOkay, PaletteTraceIntegerValue("Beans", /*value=*/ 3));
64 }
65