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,SchedPriority)38 TEST_F(PaletteClientTest, SchedPriority) {
39   int32_t tid = GetTid();
40   int32_t saved_priority;
41   EXPECT_EQ(PALETTE_STATUS_OK, PaletteSchedGetPriority(tid, &saved_priority));
42 
43   EXPECT_EQ(PALETTE_STATUS_INVALID_ARGUMENT, PaletteSchedSetPriority(tid, /*java_priority=*/ 0));
44   EXPECT_EQ(PALETTE_STATUS_INVALID_ARGUMENT, PaletteSchedSetPriority(tid, /*java_priority=*/ -1));
45   EXPECT_EQ(PALETTE_STATUS_INVALID_ARGUMENT, PaletteSchedSetPriority(tid, /*java_priority=*/ 11));
46 
47   EXPECT_EQ(PALETTE_STATUS_OK, PaletteSchedSetPriority(tid, /*java_priority=*/ 1));
48   EXPECT_EQ(PALETTE_STATUS_OK, PaletteSchedSetPriority(tid, saved_priority));
49 }
50 
TEST_F(PaletteClientTest,Trace)51 TEST_F(PaletteClientTest, Trace) {
52   bool enabled = false;
53   EXPECT_EQ(PALETTE_STATUS_OK, PaletteTraceEnabled(&enabled));
54   EXPECT_EQ(PALETTE_STATUS_OK, PaletteTraceBegin("Hello world!"));
55   EXPECT_EQ(PALETTE_STATUS_OK, PaletteTraceEnd());
56   EXPECT_EQ(PALETTE_STATUS_OK, PaletteTraceIntegerValue("Beans", /*value=*/ 3));
57 }
58