1 //
2 // Copyright (C) 2023 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 #include <sys/stat.h>
17 #include <unistd.h>
18
19 #include <string>
20 #include <vector>
21
22 #include <gtest/gtest.h>
23
24 #include "common/libs/utils/contains.h"
25 #include "common/libs/utils/proc_file_utils.h"
26
27 namespace cuttlefish {
28
TEST(ProcFileUid,SelfUidTest)29 TEST(ProcFileUid, SelfUidTest) {
30 auto my_pid = getpid();
31 auto login_uid_of_my_pid = OwnerUid(my_pid);
32
33 ASSERT_TRUE(login_uid_of_my_pid.ok()) << login_uid_of_my_pid.error().Trace();
34 ASSERT_EQ(getuid(), *login_uid_of_my_pid);
35 }
36
TEST(ProcFilePid,CurrentPidCollected)37 TEST(ProcFilePid, CurrentPidCollected) {
38 auto pids_result = CollectPids(getuid());
39 auto this_pid = getpid();
40
41 // verify if the pids returned are really owned by getuid()
42 ASSERT_TRUE(pids_result.ok());
43 ASSERT_TRUE(Contains(*pids_result, this_pid));
44 }
45
46 } // namespace cuttlefish
47