1 /* 2 * Copyright (C) 2016 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 <stdlib.h> 18 #include <string.h> 19 #include <unistd.h> 20 21 #include <string> 22 23 #include <android-base/file.h> 24 #include <gtest/gtest.h> 25 26 #include "libdebuggerd/open_files_list.h" 27 28 // Check that we can produce a list of open files for the current process, and 29 // that it includes a known open file. TEST(OpenFilesListTest,BasicTest)30TEST(OpenFilesListTest, BasicTest) { 31 // Open a temporary file that we can check for in the list of open files. 32 TemporaryFile tf; 33 34 // Get the list of open files for this process. 35 OpenFilesList list; 36 populate_open_files_list(&list, getpid()); 37 38 // Verify our open file is in the list. 39 bool found = false; 40 for (auto& file : list) { 41 if (file.first == tf.fd) { 42 EXPECT_EQ(file.second.path.value_or(""), std::string(tf.path)); 43 found = true; 44 break; 45 } 46 } 47 EXPECT_TRUE(found); 48 } 49