chromium/third_party/crashpad/crashpad/util/linux/memory_map_test.cc

// Copyright 2017 The Crashpad Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "util/linux/memory_map.h"

#include <errno.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <unistd.h>

#include "base/files/file_path.h"
#include "base/strings/stringprintf.h"
#include "build/build_config.h"
#include "gtest/gtest.h"
#include "partition_alloc/buildflags.h"
#include "test/errors.h"
#include "test/file.h"
#include "test/linux/fake_ptrace_connection.h"
#include "test/multiprocess.h"
#include "test/scoped_temp_dir.h"
#include "third_party/lss/lss.h"
#include "util/file/file_io.h"
#include "util/file/scoped_remove_file.h"
#include "util/linux/direct_ptrace_connection.h"
#include "util/misc/clock.h"
#include "util/misc/from_pointer_cast.h"
#include "util/posix/scoped_mmap.h"

namespace crashpad {
namespace test {
namespace {

// TODO(tasak): Disable SelfLargeFiles when PartitionAlloc is used as malloc.
// Because malloc() will cause new mmap() in the case. So while
// reading /proc/self/maps, any memory allocation will update the maps file and
// will cause "format_error". (e.g. GetDelim uses std::string. If std::string
// allocates memory internally (e.g. append and so on), map.Initialize() will
// fail.) To avoid this failue, firstly allocate a large buffer and read entire
// /proc/self/maps into the buffer. Next will parse data from the buffer and
// initialize MemoryMap. crbug.com/1163794.
#if PA_BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC)
#define MAYBE_SelfLargeFiles
#else
#define MAYBE_SelfLargeFiles
#endif
TEST(MemoryMap, MAYBE_SelfLargeFiles) {}

// TODO(tasak): Disable SelfBasic when PartitionAlloc is used as malloc.
// crbug.com/1163794. See SelfLargeFiles' comment.
#if PA_BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC)
#define MAYBE_SelfBasic
#else
#define MAYBE_SelfBasic
#endif
TEST(MemoryMap, MAYBE_SelfBasic) {}

void InitializeFile(const base::FilePath& path,
                    size_t size,
                    ScopedFileHandle* handle) {}

class MapChildTest : public Multiprocess {};

TEST(MemoryMap, MapChild) {}

// Some systems optimize mappings by allocating new mappings inside existing
// mappings with matching permissions. Work around this by allocating one large
// mapping and then switching up the permissions of individual pages to force
// populating more entries in the maps file.
void InitializeMappings(ScopedMmap* mappings,
                        size_t num_mappings,
                        size_t mapping_size) {}

void ExpectMappings(const MemoryMap& map,
                    LinuxVMAddress region_addr,
                    size_t num_mappings,
                    size_t mapping_size) {}

// TODO(tasak): Disable SelfLargeMapFile when PartitionAlloc is used as malloc.
// crbug.com/1163794. See SelfLargeFiles' comment.
#if PA_BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC)
#define MAYBE_SelfLargeMapFile
#else
#define MAYBE_SelfLargeMapFile
#endif
TEST(MemoryMap, MAYBE_SelfLargeMapFile) {}

class MapRunningChildTest : public Multiprocess {};

TEST(MemoryMap, MapRunningChild) {}

// Expects first and third pages from mapping_start to refer to the same mapped
// file. The second page should not.
void ExpectFindFilePossibleMmapStarts(LinuxVMAddress mapping_start,
                                      LinuxVMSize page_size) {}

TEST(MemoryMap, FindFilePossibleMmapStarts) {}

TEST(MemoryMap, FindFilePossibleMmapStarts_MultipleStarts) {}

}  // namespace
}  // namespace test
}  // namespace crashpad