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