Merge changes Ibcd45e9b,I1ff5c0fa
* changes: Do not munmap in MmapFile::~MmapFile Build bionic/tests with cpp_std experimental.
This commit is contained in:
commit
44c7b6ad0a
5 changed files with 35 additions and 8 deletions
|
@ -193,10 +193,13 @@ MmapFile::MmapFile(const char* filename) : filename_(filename) {
|
|||
lock_.init(false);
|
||||
}
|
||||
|
||||
MmapFile::~MmapFile() {
|
||||
void MmapFile::Unmap() {
|
||||
if (status_ == FileStatus::Initialized) {
|
||||
size_t size = end_ - start_ + 1;
|
||||
munmap(const_cast<char*>(start_), size);
|
||||
status_ = FileStatus::Uninitialized;
|
||||
start_ = nullptr;
|
||||
end_ = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -38,12 +38,12 @@
|
|||
class MmapFile {
|
||||
public:
|
||||
MmapFile(const char* filename);
|
||||
~MmapFile();
|
||||
|
||||
template <typename Line>
|
||||
bool FindById(uid_t uid, Line* line);
|
||||
template <typename Line>
|
||||
bool FindByName(const char* name, Line* line);
|
||||
void Unmap();
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(MmapFile);
|
||||
|
||||
|
@ -73,6 +73,9 @@ class PasswdFile {
|
|||
|
||||
bool FindById(uid_t id, passwd_state_t* passwd_state);
|
||||
bool FindByName(const char* name, passwd_state_t* passwd_state);
|
||||
void Unmap() {
|
||||
mmap_file_.Unmap();
|
||||
}
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(PasswdFile);
|
||||
|
||||
|
@ -86,6 +89,9 @@ class GroupFile {
|
|||
|
||||
bool FindById(gid_t id, group_state_t* group_state);
|
||||
bool FindByName(const char* name, group_state_t* group_state);
|
||||
void Unmap() {
|
||||
mmap_file_.Unmap();
|
||||
}
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(GroupFile);
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
cc_defaults {
|
||||
name: "bionic_tests_defaults",
|
||||
host_supported: true,
|
||||
cpp_std: "experimental",
|
||||
target: {
|
||||
darwin: {
|
||||
enabled: false,
|
||||
|
|
|
@ -23,6 +23,19 @@
|
|||
#if defined(__BIONIC__)
|
||||
#include "../libc/bionic/grp_pwd_file.cpp"
|
||||
|
||||
template <typename T>
|
||||
class FileUnmapper {
|
||||
public:
|
||||
FileUnmapper(T& file) : file_(file) {
|
||||
}
|
||||
~FileUnmapper() {
|
||||
file_.Unmap();
|
||||
}
|
||||
|
||||
private:
|
||||
T& file_;
|
||||
};
|
||||
|
||||
void FindAndCheckPasswdEntry(PasswdFile* file, const char* name, uid_t uid, gid_t gid,
|
||||
const char* dir, const char* shell) {
|
||||
passwd_state_t name_passwd_state;
|
||||
|
@ -82,6 +95,7 @@ TEST(grp_pwd_file, passwd_file_one_entry) {
|
|||
write(file.fd, test_string, sizeof(test_string) - 1);
|
||||
|
||||
PasswdFile passwd_file(file.filename);
|
||||
FileUnmapper unmapper(passwd_file);
|
||||
|
||||
FindAndCheckPasswdEntry(&passwd_file, "name", 1, 2, "dir", "shell");
|
||||
|
||||
|
@ -101,6 +115,7 @@ TEST(grp_pwd_file, group_file_one_entry) {
|
|||
write(file.fd, test_string, sizeof(test_string) - 1);
|
||||
|
||||
GroupFile group_file(file.filename);
|
||||
FileUnmapper unmapper(group_file);
|
||||
|
||||
FindAndCheckGroupEntry(&group_file, "name", 1);
|
||||
|
||||
|
@ -136,6 +151,7 @@ TEST(grp_pwd_file, passwd_file_many_entries) {
|
|||
write(file.fd, test_string, sizeof(test_string) - 1);
|
||||
|
||||
PasswdFile passwd_file(file.filename);
|
||||
FileUnmapper unmapper(passwd_file);
|
||||
|
||||
FindAndCheckPasswdEntry(&passwd_file, "first", 1, 2, "dir", "shell");
|
||||
FindAndCheckPasswdEntry(&passwd_file, "middle-ish", 13, 4, "/", "/system/bin/sh");
|
||||
|
@ -171,6 +187,7 @@ TEST(grp_pwd_file, group_file_many_entries) {
|
|||
write(file.fd, test_string, sizeof(test_string) - 1);
|
||||
|
||||
GroupFile group_file(file.filename);
|
||||
FileUnmapper unmapper(group_file);
|
||||
|
||||
FindAndCheckGroupEntry(&group_file, "first", 1);
|
||||
FindAndCheckGroupEntry(&group_file, "middle-ish", 6);
|
||||
|
|
|
@ -914,7 +914,7 @@ static void test_pthread_rwlock_reader_wakeup_writer(std::function<int (pthread_
|
|||
ASSERT_EQ(0, pthread_rwlock_rdlock(&wakeup_arg.lock));
|
||||
wakeup_arg.progress = RwlockWakeupHelperArg::LOCK_INITIALIZED;
|
||||
wakeup_arg.tid = 0;
|
||||
wakeup_arg.trylock_function = pthread_rwlock_trywrlock;
|
||||
wakeup_arg.trylock_function = &pthread_rwlock_trywrlock;
|
||||
wakeup_arg.lock_function = lock_function;
|
||||
|
||||
pthread_t thread;
|
||||
|
@ -950,7 +950,7 @@ static void test_pthread_rwlock_writer_wakeup_reader(std::function<int (pthread_
|
|||
ASSERT_EQ(0, pthread_rwlock_wrlock(&wakeup_arg.lock));
|
||||
wakeup_arg.progress = RwlockWakeupHelperArg::LOCK_INITIALIZED;
|
||||
wakeup_arg.tid = 0;
|
||||
wakeup_arg.trylock_function = pthread_rwlock_tryrdlock;
|
||||
wakeup_arg.trylock_function = &pthread_rwlock_tryrdlock;
|
||||
wakeup_arg.lock_function = lock_function;
|
||||
|
||||
pthread_t thread;
|
||||
|
@ -1010,8 +1010,8 @@ TEST(pthread, pthread_rwlock_timedrdlock_timeout) {
|
|||
ASSERT_EQ(0, pthread_rwlock_wrlock(&wakeup_arg.lock));
|
||||
wakeup_arg.progress = RwlockWakeupHelperArg::LOCK_INITIALIZED;
|
||||
wakeup_arg.tid = 0;
|
||||
wakeup_arg.trylock_function = pthread_rwlock_tryrdlock;
|
||||
wakeup_arg.timed_lock_function = pthread_rwlock_timedrdlock;
|
||||
wakeup_arg.trylock_function = &pthread_rwlock_tryrdlock;
|
||||
wakeup_arg.timed_lock_function = &pthread_rwlock_timedrdlock;
|
||||
|
||||
pthread_t thread;
|
||||
ASSERT_EQ(0, pthread_create(&thread, nullptr,
|
||||
|
@ -1031,8 +1031,8 @@ TEST(pthread, pthread_rwlock_timedwrlock_timeout) {
|
|||
ASSERT_EQ(0, pthread_rwlock_rdlock(&wakeup_arg.lock));
|
||||
wakeup_arg.progress = RwlockWakeupHelperArg::LOCK_INITIALIZED;
|
||||
wakeup_arg.tid = 0;
|
||||
wakeup_arg.trylock_function = pthread_rwlock_trywrlock;
|
||||
wakeup_arg.timed_lock_function = pthread_rwlock_timedwrlock;
|
||||
wakeup_arg.trylock_function = &pthread_rwlock_trywrlock;
|
||||
wakeup_arg.timed_lock_function = &pthread_rwlock_timedwrlock;
|
||||
|
||||
pthread_t thread;
|
||||
ASSERT_EQ(0, pthread_create(&thread, nullptr,
|
||||
|
|
Loading…
Reference in a new issue