2013-01-29 02:19:43 +01:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2013 The Android Open Source Project
|
|
|
|
*
|
|
|
|
* 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 <gtest/gtest.h>
|
2014-11-06 03:01:01 +01:00
|
|
|
|
2013-10-22 02:09:52 +02:00
|
|
|
#include <errno.h>
|
2014-11-06 03:01:01 +01:00
|
|
|
#include <sys/wait.h>
|
2013-02-13 23:41:48 +01:00
|
|
|
#include <unistd.h>
|
2017-02-11 03:13:46 +01:00
|
|
|
|
2013-02-13 23:41:48 +01:00
|
|
|
#include <string>
|
2017-02-11 03:13:46 +01:00
|
|
|
#include <thread>
|
2013-01-29 02:19:43 +01:00
|
|
|
|
2018-11-15 00:19:53 +01:00
|
|
|
#include <android-base/file.h>
|
2021-04-10 02:13:09 +02:00
|
|
|
#include <android-base/silent_death_test.h>
|
2023-08-29 01:46:39 +02:00
|
|
|
#include <android-base/stringprintf.h>
|
|
|
|
|
|
|
|
#include "utils.h"
|
2017-12-12 08:31:33 +01:00
|
|
|
|
2017-10-09 22:49:17 +02:00
|
|
|
using namespace std::literals;
|
|
|
|
|
2013-12-21 03:43:21 +01:00
|
|
|
#if defined(__BIONIC__)
|
2013-01-29 02:19:43 +01:00
|
|
|
|
|
|
|
#define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_
|
2023-10-20 01:50:59 +02:00
|
|
|
#include <stdlib.h>
|
2013-01-29 02:19:43 +01:00
|
|
|
#include <sys/_system_properties.h>
|
2023-08-29 01:46:39 +02:00
|
|
|
#include <sys/mount.h>
|
2013-01-29 02:19:43 +01:00
|
|
|
|
2017-12-12 08:31:33 +01:00
|
|
|
#include <system_properties/system_properties.h>
|
2013-02-13 23:41:48 +01:00
|
|
|
|
2017-12-12 08:31:33 +01:00
|
|
|
class SystemPropertiesTest : public SystemProperties {
|
|
|
|
public:
|
|
|
|
SystemPropertiesTest() : SystemProperties(false) {
|
2023-08-29 01:46:39 +02:00
|
|
|
appcompat_path = android::base::StringPrintf("%s/appcompat_override", dir_.path);
|
2023-10-20 01:50:59 +02:00
|
|
|
mount_path = android::base::StringPrintf("%s/__properties__", dir_.path);
|
2023-08-29 01:46:39 +02:00
|
|
|
mkdir(appcompat_path.c_str(), S_IRWXU | S_IXGRP | S_IXOTH);
|
|
|
|
valid_ = AreaInit(dir_.path, nullptr, true);
|
2017-12-12 08:31:33 +01:00
|
|
|
}
|
|
|
|
~SystemPropertiesTest() {
|
|
|
|
if (valid_) {
|
2018-02-22 00:01:22 +01:00
|
|
|
contexts_->FreeAndUnmap();
|
2013-01-29 02:19:43 +01:00
|
|
|
}
|
2023-10-20 01:50:59 +02:00
|
|
|
umount2(dir_.path, MNT_DETACH);
|
|
|
|
umount2(real_sysprop_dir.c_str(), MNT_DETACH);
|
2017-12-12 08:31:33 +01:00
|
|
|
}
|
2013-01-29 02:19:43 +01:00
|
|
|
|
2017-12-12 08:31:33 +01:00
|
|
|
bool valid() const {
|
|
|
|
return valid_;
|
|
|
|
}
|
2013-02-13 23:41:48 +01:00
|
|
|
|
2023-08-29 01:46:39 +02:00
|
|
|
const char* get_path() const { return dir_.path; }
|
|
|
|
|
|
|
|
const char* get_appcompat_path() const { return appcompat_path.c_str(); }
|
|
|
|
|
2023-10-20 01:50:59 +02:00
|
|
|
const char* get_mount_path() const { return mount_path.c_str(); }
|
|
|
|
|
|
|
|
const char* get_real_sysprop_dir() const { return real_sysprop_dir.c_str(); }
|
|
|
|
|
2023-08-29 01:46:39 +02:00
|
|
|
std::string appcompat_path;
|
2023-10-20 01:50:59 +02:00
|
|
|
std::string mount_path;
|
|
|
|
std::string real_sysprop_dir = "/dev/__properties__";
|
2023-08-29 01:46:39 +02:00
|
|
|
|
2017-12-12 08:31:33 +01:00
|
|
|
private:
|
|
|
|
TemporaryDir dir_;
|
|
|
|
bool valid_;
|
2013-01-29 02:19:43 +01:00
|
|
|
};
|
|
|
|
|
2013-12-21 03:43:21 +01:00
|
|
|
static void foreach_test_callback(const prop_info *pi, void* cookie) {
|
|
|
|
size_t *count = static_cast<size_t *>(cookie);
|
|
|
|
|
2017-01-24 21:43:29 +01:00
|
|
|
ASSERT_TRUE(pi != nullptr);
|
2013-12-21 03:43:21 +01:00
|
|
|
(*count)++;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void hierarchical_test_callback(const prop_info *pi, void *cookie) {
|
|
|
|
bool (*ok)[8][8] = static_cast<bool (*)[8][8]>(cookie);
|
|
|
|
|
|
|
|
char name[PROP_NAME_MAX];
|
|
|
|
char value[PROP_VALUE_MAX];
|
|
|
|
|
|
|
|
__system_property_read(pi, name, value);
|
|
|
|
|
|
|
|
int name_i, name_j, name_k;
|
|
|
|
int value_i, value_j, value_k;
|
|
|
|
ASSERT_EQ(3, sscanf(name, "property_%d.%d.%d", &name_i, &name_j, &name_k));
|
|
|
|
ASSERT_EQ(3, sscanf(value, "value_%d.%d.%d", &value_i, &value_j, &value_k));
|
|
|
|
ASSERT_EQ(name_i, value_i);
|
|
|
|
ASSERT_GE(name_i, 0);
|
|
|
|
ASSERT_LT(name_i, 8);
|
|
|
|
ASSERT_EQ(name_j, value_j);
|
|
|
|
ASSERT_GE(name_j, 0);
|
|
|
|
ASSERT_LT(name_j, 8);
|
|
|
|
ASSERT_EQ(name_k, value_k);
|
|
|
|
ASSERT_GE(name_k, 0);
|
|
|
|
ASSERT_LT(name_k, 8);
|
|
|
|
|
|
|
|
ok[name_i][name_j][name_k] = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // __BIONIC__
|
|
|
|
|
2017-02-11 03:13:46 +01:00
|
|
|
TEST(properties, __system_property_add) {
|
2013-12-21 03:43:21 +01:00
|
|
|
#if defined(__BIONIC__)
|
2017-12-12 08:31:33 +01:00
|
|
|
SystemPropertiesTest system_properties;
|
|
|
|
ASSERT_TRUE(system_properties.valid());
|
2013-01-29 02:19:43 +01:00
|
|
|
|
2017-12-12 08:31:33 +01:00
|
|
|
ASSERT_EQ(0, system_properties.Add("property", 8, "value1", 6));
|
|
|
|
ASSERT_EQ(0, system_properties.Add("other_property", 14, "value2", 6));
|
|
|
|
ASSERT_EQ(0, system_properties.Add("property_other", 14, "value3", 6));
|
2013-01-29 02:19:43 +01:00
|
|
|
|
2017-01-24 21:43:29 +01:00
|
|
|
// check that there is no limit on property name length
|
|
|
|
char name[PROP_NAME_MAX + 11];
|
|
|
|
name[0] = 'p';
|
|
|
|
for (size_t i = 1; i < sizeof(name); i++) {
|
|
|
|
name[i] = 'x';
|
|
|
|
}
|
|
|
|
|
|
|
|
name[sizeof(name)-1] = '\0';
|
2017-12-12 08:31:33 +01:00
|
|
|
ASSERT_EQ(0, system_properties.Add(name, strlen(name), "value", 5));
|
2017-01-24 21:43:29 +01:00
|
|
|
|
2017-02-11 03:13:46 +01:00
|
|
|
char propvalue[PROP_VALUE_MAX];
|
2017-12-12 08:31:33 +01:00
|
|
|
ASSERT_EQ(6, system_properties.Get("property", propvalue));
|
2013-01-29 02:19:43 +01:00
|
|
|
ASSERT_STREQ(propvalue, "value1");
|
|
|
|
|
2017-12-12 08:31:33 +01:00
|
|
|
ASSERT_EQ(6, system_properties.Get("other_property", propvalue));
|
2013-01-29 02:19:43 +01:00
|
|
|
ASSERT_STREQ(propvalue, "value2");
|
|
|
|
|
2017-12-12 08:31:33 +01:00
|
|
|
ASSERT_EQ(6, system_properties.Get("property_other", propvalue));
|
2013-01-29 02:19:43 +01:00
|
|
|
ASSERT_STREQ(propvalue, "value3");
|
2017-01-24 21:43:29 +01:00
|
|
|
|
2017-12-12 08:31:33 +01:00
|
|
|
ASSERT_EQ(5, system_properties.Get(name, propvalue));
|
2017-01-24 21:43:29 +01:00
|
|
|
ASSERT_STREQ(propvalue, "value");
|
2013-12-21 03:43:21 +01:00
|
|
|
#else // __BIONIC__
|
2019-03-09 00:20:23 +01:00
|
|
|
GTEST_SKIP() << "bionic-only test";
|
2013-12-21 03:43:21 +01:00
|
|
|
#endif // __BIONIC__
|
2013-01-29 02:19:43 +01:00
|
|
|
}
|
|
|
|
|
2023-08-29 01:46:39 +02:00
|
|
|
TEST(properties, __system_property_add_appcompat) {
|
|
|
|
#if defined(__BIONIC__)
|
|
|
|
if (getuid() != 0) GTEST_SKIP() << "test requires root";
|
|
|
|
SystemPropertiesTest system_properties;
|
|
|
|
ASSERT_TRUE(system_properties.valid());
|
|
|
|
|
|
|
|
char name[] = "ro.property";
|
|
|
|
char override_name[] = "ro.appcompat_override.ro.property";
|
|
|
|
char name_not_written[] = "ro.property_other";
|
|
|
|
char override_with_no_real[] = "ro.appcompat_override.ro.property_other";
|
|
|
|
ASSERT_EQ(0, system_properties.Add(name, strlen(name), "value1", 6));
|
|
|
|
ASSERT_EQ(0, system_properties.Add(override_name, strlen(override_name), "value2", 6));
|
|
|
|
ASSERT_EQ(0, system_properties.Add(override_with_no_real, strlen(override_with_no_real),
|
|
|
|
"value3", 6));
|
|
|
|
|
|
|
|
char propvalue[PROP_VALUE_MAX];
|
|
|
|
ASSERT_EQ(6, system_properties.Get(name, propvalue));
|
|
|
|
ASSERT_STREQ(propvalue, "value1");
|
|
|
|
|
|
|
|
ASSERT_EQ(6, system_properties.Get(override_name, propvalue));
|
|
|
|
ASSERT_STREQ(propvalue, "value2");
|
|
|
|
|
|
|
|
ASSERT_EQ(0, system_properties.Get(name_not_written, propvalue));
|
|
|
|
ASSERT_STREQ(propvalue, "");
|
|
|
|
|
|
|
|
ASSERT_EQ(6, system_properties.Get(override_with_no_real, propvalue));
|
|
|
|
ASSERT_STREQ(propvalue, "value3");
|
|
|
|
|
|
|
|
int ret = mount(system_properties.get_appcompat_path(), system_properties.get_path(), nullptr,
|
|
|
|
MS_BIND | MS_REC, nullptr);
|
|
|
|
if (ret != 0) {
|
|
|
|
ASSERT_ERRNO(0);
|
|
|
|
}
|
|
|
|
system_properties.Reload(true);
|
|
|
|
|
|
|
|
ASSERT_EQ(6, system_properties.Get(name, propvalue));
|
|
|
|
ASSERT_STREQ(propvalue, "value2");
|
|
|
|
|
|
|
|
ASSERT_EQ(0, system_properties.Get(override_name, propvalue));
|
|
|
|
ASSERT_STREQ(propvalue, "");
|
|
|
|
|
|
|
|
ASSERT_EQ(6, system_properties.Get(name_not_written, propvalue));
|
|
|
|
ASSERT_STREQ(propvalue, "value3");
|
|
|
|
|
|
|
|
ASSERT_EQ(0, system_properties.Get(override_with_no_real, propvalue));
|
|
|
|
ASSERT_STREQ(propvalue, "");
|
|
|
|
|
|
|
|
#else // __BIONIC__
|
|
|
|
GTEST_SKIP() << "bionic-only test";
|
|
|
|
#endif // __BIONIC__
|
|
|
|
}
|
|
|
|
|
2017-02-11 03:13:46 +01:00
|
|
|
TEST(properties, __system_property_update) {
|
2013-12-21 03:43:21 +01:00
|
|
|
#if defined(__BIONIC__)
|
2017-12-12 08:31:33 +01:00
|
|
|
SystemPropertiesTest system_properties;
|
|
|
|
ASSERT_TRUE(system_properties.valid());
|
2013-01-29 02:19:43 +01:00
|
|
|
|
2017-12-12 08:31:33 +01:00
|
|
|
ASSERT_EQ(0, system_properties.Add("property", 8, "oldvalue1", 9));
|
|
|
|
ASSERT_EQ(0, system_properties.Add("other_property", 14, "value2", 6));
|
|
|
|
ASSERT_EQ(0, system_properties.Add("property_other", 14, "value3", 6));
|
2013-01-29 02:19:43 +01:00
|
|
|
|
2017-12-12 08:31:33 +01:00
|
|
|
const prop_info* pi = system_properties.Find("property");
|
2017-02-11 03:13:46 +01:00
|
|
|
ASSERT_TRUE(pi != nullptr);
|
2017-12-12 08:31:33 +01:00
|
|
|
system_properties.Update(const_cast<prop_info*>(pi), "value4", 6);
|
2013-01-29 02:19:43 +01:00
|
|
|
|
2017-12-12 08:31:33 +01:00
|
|
|
pi = system_properties.Find("other_property");
|
2017-02-11 03:13:46 +01:00
|
|
|
ASSERT_TRUE(pi != nullptr);
|
2017-12-12 08:31:33 +01:00
|
|
|
system_properties.Update(const_cast<prop_info*>(pi), "newvalue5", 9);
|
2013-01-29 02:19:43 +01:00
|
|
|
|
2017-12-12 08:31:33 +01:00
|
|
|
pi = system_properties.Find("property_other");
|
2017-02-11 03:13:46 +01:00
|
|
|
ASSERT_TRUE(pi != nullptr);
|
2017-12-12 08:31:33 +01:00
|
|
|
system_properties.Update(const_cast<prop_info*>(pi), "value6", 6);
|
2013-01-29 02:19:43 +01:00
|
|
|
|
2017-02-11 03:13:46 +01:00
|
|
|
char propvalue[PROP_VALUE_MAX];
|
2017-12-12 08:31:33 +01:00
|
|
|
ASSERT_EQ(6, system_properties.Get("property", propvalue));
|
2013-01-29 02:19:43 +01:00
|
|
|
ASSERT_STREQ(propvalue, "value4");
|
|
|
|
|
2017-12-12 08:31:33 +01:00
|
|
|
ASSERT_EQ(9, system_properties.Get("other_property", propvalue));
|
2013-01-29 02:19:43 +01:00
|
|
|
ASSERT_STREQ(propvalue, "newvalue5");
|
|
|
|
|
2017-12-12 08:31:33 +01:00
|
|
|
ASSERT_EQ(6, system_properties.Get("property_other", propvalue));
|
2013-01-29 02:19:43 +01:00
|
|
|
ASSERT_STREQ(propvalue, "value6");
|
2013-12-21 03:43:21 +01:00
|
|
|
#else // __BIONIC__
|
2019-03-09 00:20:23 +01:00
|
|
|
GTEST_SKIP() << "bionic-only test";
|
2013-12-21 03:43:21 +01:00
|
|
|
#endif // __BIONIC__
|
2013-01-29 02:19:43 +01:00
|
|
|
}
|
|
|
|
|
2013-02-13 23:41:48 +01:00
|
|
|
TEST(properties, fill) {
|
2013-12-21 03:43:21 +01:00
|
|
|
#if defined(__BIONIC__)
|
2017-12-12 08:31:33 +01:00
|
|
|
SystemPropertiesTest system_properties;
|
|
|
|
ASSERT_TRUE(system_properties.valid());
|
|
|
|
|
2013-01-29 02:19:43 +01:00
|
|
|
char prop_name[PROP_NAME_MAX];
|
|
|
|
char prop_value[PROP_VALUE_MAX];
|
|
|
|
char prop_value_ret[PROP_VALUE_MAX];
|
2013-02-13 23:41:48 +01:00
|
|
|
int count = 0;
|
2013-01-29 02:19:43 +01:00
|
|
|
int ret;
|
|
|
|
|
2013-02-13 23:41:48 +01:00
|
|
|
while (true) {
|
|
|
|
ret = snprintf(prop_name, PROP_NAME_MAX - 1, "property_%d", count);
|
2013-01-29 02:19:43 +01:00
|
|
|
memset(prop_name + ret, 'a', PROP_NAME_MAX - 1 - ret);
|
2013-02-13 23:41:48 +01:00
|
|
|
ret = snprintf(prop_value, PROP_VALUE_MAX - 1, "value_%d", count);
|
2013-01-29 02:19:43 +01:00
|
|
|
memset(prop_value + ret, 'b', PROP_VALUE_MAX - 1 - ret);
|
|
|
|
prop_name[PROP_NAME_MAX - 1] = 0;
|
|
|
|
prop_value[PROP_VALUE_MAX - 1] = 0;
|
|
|
|
|
2017-12-12 08:31:33 +01:00
|
|
|
ret = system_properties.Add(prop_name, PROP_NAME_MAX - 1, prop_value, PROP_VALUE_MAX - 1);
|
2013-02-13 23:41:48 +01:00
|
|
|
if (ret < 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
count++;
|
2013-01-29 02:19:43 +01:00
|
|
|
}
|
|
|
|
|
2013-02-13 23:41:48 +01:00
|
|
|
// For historical reasons at least 247 properties must be supported
|
|
|
|
ASSERT_GE(count, 247);
|
|
|
|
|
|
|
|
for (int i = 0; i < count; i++) {
|
2013-01-29 02:19:43 +01:00
|
|
|
ret = snprintf(prop_name, PROP_NAME_MAX - 1, "property_%d", i);
|
|
|
|
memset(prop_name + ret, 'a', PROP_NAME_MAX - 1 - ret);
|
|
|
|
ret = snprintf(prop_value, PROP_VALUE_MAX - 1, "value_%d", i);
|
|
|
|
memset(prop_value + ret, 'b', PROP_VALUE_MAX - 1 - ret);
|
|
|
|
prop_name[PROP_NAME_MAX - 1] = 0;
|
|
|
|
prop_value[PROP_VALUE_MAX - 1] = 0;
|
|
|
|
memset(prop_value_ret, '\0', PROP_VALUE_MAX);
|
|
|
|
|
2017-12-12 08:31:33 +01:00
|
|
|
ASSERT_EQ(PROP_VALUE_MAX - 1, system_properties.Get(prop_name, prop_value_ret));
|
2013-01-29 02:19:43 +01:00
|
|
|
ASSERT_EQ(0, memcmp(prop_value, prop_value_ret, PROP_VALUE_MAX));
|
|
|
|
}
|
2013-12-21 03:43:21 +01:00
|
|
|
#else // __BIONIC__
|
2019-03-09 00:20:23 +01:00
|
|
|
GTEST_SKIP() << "bionic-only test";
|
2013-12-21 03:43:21 +01:00
|
|
|
#endif // __BIONIC__
|
2013-02-13 01:39:31 +01:00
|
|
|
}
|
|
|
|
|
2017-02-11 03:13:46 +01:00
|
|
|
TEST(properties, __system_property_foreach) {
|
2013-12-21 03:43:21 +01:00
|
|
|
#if defined(__BIONIC__)
|
2017-12-12 08:31:33 +01:00
|
|
|
SystemPropertiesTest system_properties;
|
|
|
|
ASSERT_TRUE(system_properties.valid());
|
2013-02-13 01:39:31 +01:00
|
|
|
|
2017-12-12 08:31:33 +01:00
|
|
|
ASSERT_EQ(0, system_properties.Add("property", 8, "value1", 6));
|
|
|
|
ASSERT_EQ(0, system_properties.Add("other_property", 14, "value2", 6));
|
|
|
|
ASSERT_EQ(0, system_properties.Add("property_other", 14, "value3", 6));
|
2013-02-13 01:39:31 +01:00
|
|
|
|
2017-02-11 03:13:46 +01:00
|
|
|
size_t count = 0;
|
2017-12-12 08:31:33 +01:00
|
|
|
ASSERT_EQ(0, system_properties.Foreach(foreach_test_callback, &count));
|
2013-02-13 01:39:31 +01:00
|
|
|
ASSERT_EQ(3U, count);
|
2013-12-21 03:43:21 +01:00
|
|
|
#else // __BIONIC__
|
2019-03-09 00:20:23 +01:00
|
|
|
GTEST_SKIP() << "bionic-only test";
|
2013-12-21 03:43:21 +01:00
|
|
|
#endif // __BIONIC__
|
2013-02-13 01:39:31 +01:00
|
|
|
}
|
|
|
|
|
2017-02-11 03:13:46 +01:00
|
|
|
TEST(properties, __system_property_find_nth) {
|
2013-12-21 03:43:21 +01:00
|
|
|
#if defined(__BIONIC__)
|
2017-12-12 08:31:33 +01:00
|
|
|
SystemPropertiesTest system_properties;
|
|
|
|
ASSERT_TRUE(system_properties.valid());
|
2013-01-29 02:19:43 +01:00
|
|
|
|
2017-12-12 08:31:33 +01:00
|
|
|
ASSERT_EQ(0, system_properties.Add("property", 8, "value1", 6));
|
|
|
|
ASSERT_EQ(0, system_properties.Add("other_property", 14, "value2", 6));
|
|
|
|
ASSERT_EQ(0, system_properties.Add("property_other", 14, "value3", 6));
|
2013-01-29 02:19:43 +01:00
|
|
|
|
2017-04-17 23:53:07 +02:00
|
|
|
char name[PROP_NAME_MAX];
|
|
|
|
char value[PROP_VALUE_MAX];
|
2017-12-12 08:31:33 +01:00
|
|
|
EXPECT_EQ(6, system_properties.Read(system_properties.FindNth(0), name, value));
|
2017-04-17 23:53:07 +02:00
|
|
|
EXPECT_STREQ("property", name);
|
|
|
|
EXPECT_STREQ("value1", value);
|
2017-12-12 08:31:33 +01:00
|
|
|
EXPECT_EQ(6, system_properties.Read(system_properties.FindNth(1), name, value));
|
2017-04-17 23:53:07 +02:00
|
|
|
EXPECT_STREQ("other_property", name);
|
|
|
|
EXPECT_STREQ("value2", value);
|
2017-12-12 08:31:33 +01:00
|
|
|
EXPECT_EQ(6, system_properties.Read(system_properties.FindNth(2), name, value));
|
2017-04-17 23:53:07 +02:00
|
|
|
EXPECT_STREQ("property_other", name);
|
|
|
|
EXPECT_STREQ("value3", value);
|
|
|
|
|
|
|
|
for (unsigned i = 3; i < 1024; ++i) {
|
2017-12-12 08:31:33 +01:00
|
|
|
ASSERT_TRUE(system_properties.FindNth(i) == nullptr);
|
2017-04-17 23:53:07 +02:00
|
|
|
}
|
2013-12-21 03:43:21 +01:00
|
|
|
#else // __BIONIC__
|
2019-03-09 00:20:23 +01:00
|
|
|
GTEST_SKIP() << "bionic-only test";
|
2013-12-21 03:43:21 +01:00
|
|
|
#endif // __BIONIC__
|
2013-06-17 21:37:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(properties, fill_hierarchical) {
|
2013-12-21 03:43:21 +01:00
|
|
|
#if defined(__BIONIC__)
|
2017-12-12 08:31:33 +01:00
|
|
|
SystemPropertiesTest system_properties;
|
|
|
|
ASSERT_TRUE(system_properties.valid());
|
|
|
|
|
2013-06-17 21:37:09 +02:00
|
|
|
char prop_name[PROP_NAME_MAX];
|
|
|
|
char prop_value[PROP_VALUE_MAX];
|
|
|
|
char prop_value_ret[PROP_VALUE_MAX];
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
for (int i = 0; i < 8; i++) {
|
|
|
|
for (int j = 0; j < 8; j++) {
|
|
|
|
for (int k = 0; k < 8; k++) {
|
|
|
|
ret = snprintf(prop_name, PROP_NAME_MAX - 1, "property_%d.%d.%d", i, j, k);
|
|
|
|
memset(prop_name + ret, 'a', PROP_NAME_MAX - 1 - ret);
|
|
|
|
ret = snprintf(prop_value, PROP_VALUE_MAX - 1, "value_%d.%d.%d", i, j, k);
|
|
|
|
memset(prop_value + ret, 'b', PROP_VALUE_MAX - 1 - ret);
|
|
|
|
prop_name[PROP_NAME_MAX - 1] = 0;
|
|
|
|
prop_value[PROP_VALUE_MAX - 1] = 0;
|
|
|
|
|
2017-12-12 08:31:33 +01:00
|
|
|
ASSERT_EQ(0, system_properties.Add(
|
|
|
|
prop_name, PROP_NAME_MAX - 1, prop_value, PROP_VALUE_MAX - 1));
|
2013-06-17 21:37:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < 8; i++) {
|
|
|
|
for (int j = 0; j < 8; j++) {
|
|
|
|
for (int k = 0; k < 8; k++) {
|
|
|
|
ret = snprintf(prop_name, PROP_NAME_MAX - 1, "property_%d.%d.%d", i, j, k);
|
|
|
|
memset(prop_name + ret, 'a', PROP_NAME_MAX - 1 - ret);
|
|
|
|
ret = snprintf(prop_value, PROP_VALUE_MAX - 1, "value_%d.%d.%d", i, j, k);
|
|
|
|
memset(prop_value + ret, 'b', PROP_VALUE_MAX - 1 - ret);
|
|
|
|
prop_name[PROP_NAME_MAX - 1] = 0;
|
|
|
|
prop_value[PROP_VALUE_MAX - 1] = 0;
|
|
|
|
memset(prop_value_ret, '\0', PROP_VALUE_MAX);
|
|
|
|
|
2017-12-12 08:31:33 +01:00
|
|
|
ASSERT_EQ(PROP_VALUE_MAX - 1, system_properties.Get(prop_name, prop_value_ret));
|
2013-06-17 21:37:09 +02:00
|
|
|
ASSERT_EQ(0, memcmp(prop_value, prop_value_ret, PROP_VALUE_MAX));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ok[8][8][8];
|
|
|
|
memset(ok, 0, sizeof(ok));
|
2017-12-12 08:31:33 +01:00
|
|
|
system_properties.Foreach(hierarchical_test_callback, ok);
|
2013-06-17 21:37:09 +02:00
|
|
|
|
|
|
|
for (int i = 0; i < 8; i++) {
|
|
|
|
for (int j = 0; j < 8; j++) {
|
|
|
|
for (int k = 0; k < 8; k++) {
|
|
|
|
ASSERT_TRUE(ok[i][j][k]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-12-21 03:43:21 +01:00
|
|
|
#else // __BIONIC__
|
2019-03-09 00:20:23 +01:00
|
|
|
GTEST_SKIP() << "bionic-only test";
|
2013-12-21 03:43:21 +01:00
|
|
|
#endif // __BIONIC__
|
2013-06-17 21:37:09 +02:00
|
|
|
}
|
|
|
|
|
2013-01-29 02:19:43 +01:00
|
|
|
TEST(properties, errors) {
|
2013-12-21 03:43:21 +01:00
|
|
|
#if defined(__BIONIC__)
|
2017-12-12 08:31:33 +01:00
|
|
|
SystemPropertiesTest system_properties;
|
|
|
|
ASSERT_TRUE(system_properties.valid());
|
|
|
|
|
2013-01-29 02:19:43 +01:00
|
|
|
char prop_value[PROP_NAME_MAX];
|
|
|
|
|
2017-12-12 08:31:33 +01:00
|
|
|
ASSERT_EQ(0, system_properties.Add("property", 8, "value1", 6));
|
|
|
|
ASSERT_EQ(0, system_properties.Add("other_property", 14, "value2", 6));
|
|
|
|
ASSERT_EQ(0, system_properties.Add("property_other", 14, "value3", 6));
|
2013-01-29 02:19:43 +01:00
|
|
|
|
2017-12-12 08:31:33 +01:00
|
|
|
ASSERT_EQ(0, system_properties.Find("property1"));
|
|
|
|
ASSERT_EQ(0, system_properties.Get("property1", prop_value));
|
2013-01-29 02:19:43 +01:00
|
|
|
|
2017-12-12 08:31:33 +01:00
|
|
|
ASSERT_EQ(-1, system_properties.Add("name", 4, "value", PROP_VALUE_MAX));
|
|
|
|
ASSERT_EQ(-1, system_properties.Update(NULL, "value", PROP_VALUE_MAX));
|
2013-12-21 03:43:21 +01:00
|
|
|
#else // __BIONIC__
|
2019-03-09 00:20:23 +01:00
|
|
|
GTEST_SKIP() << "bionic-only test";
|
2013-12-21 03:43:21 +01:00
|
|
|
#endif // __BIONIC__
|
2013-01-29 02:19:43 +01:00
|
|
|
}
|
|
|
|
|
2017-02-11 03:13:46 +01:00
|
|
|
TEST(properties, __system_property_serial) {
|
2013-12-21 03:43:21 +01:00
|
|
|
#if defined(__BIONIC__)
|
2017-12-12 08:31:33 +01:00
|
|
|
SystemPropertiesTest system_properties;
|
|
|
|
ASSERT_TRUE(system_properties.valid());
|
2013-01-29 02:19:43 +01:00
|
|
|
|
2017-12-12 08:31:33 +01:00
|
|
|
ASSERT_EQ(0, system_properties.Add("property", 8, "value1", 6));
|
|
|
|
const prop_info* pi = system_properties.Find("property");
|
2017-02-11 03:13:46 +01:00
|
|
|
ASSERT_TRUE(pi != nullptr);
|
2019-11-12 21:41:55 +01:00
|
|
|
unsigned serial = __system_property_serial(pi);
|
2017-12-12 08:31:33 +01:00
|
|
|
ASSERT_EQ(0, system_properties.Update(const_cast<prop_info*>(pi), "value2", 6));
|
2019-11-12 21:41:55 +01:00
|
|
|
ASSERT_NE(serial, __system_property_serial(pi));
|
2013-12-21 03:43:21 +01:00
|
|
|
#else // __BIONIC__
|
2019-03-09 00:20:23 +01:00
|
|
|
GTEST_SKIP() << "bionic-only test";
|
2013-12-21 03:43:21 +01:00
|
|
|
#endif // __BIONIC__
|
2013-01-29 02:19:43 +01:00
|
|
|
}
|
|
|
|
|
2017-02-11 03:13:46 +01:00
|
|
|
TEST(properties, __system_property_wait_any) {
|
2013-12-21 03:43:21 +01:00
|
|
|
#if defined(__BIONIC__)
|
2017-12-12 08:31:33 +01:00
|
|
|
SystemPropertiesTest system_properties;
|
|
|
|
ASSERT_TRUE(system_properties.valid());
|
2013-01-29 02:19:43 +01:00
|
|
|
|
2017-12-12 08:31:33 +01:00
|
|
|
ASSERT_EQ(0, system_properties.Add("property", 8, "value1", 6));
|
|
|
|
unsigned serial = system_properties.WaitAny(0);
|
2017-01-24 21:43:29 +01:00
|
|
|
|
2017-12-12 08:31:33 +01:00
|
|
|
prop_info* pi = const_cast<prop_info*>(system_properties.Find("property"));
|
2017-01-24 21:43:29 +01:00
|
|
|
ASSERT_TRUE(pi != nullptr);
|
2017-12-12 08:31:33 +01:00
|
|
|
system_properties.Update(pi, "value2", 6);
|
|
|
|
serial = system_properties.WaitAny(serial);
|
2013-01-29 02:19:43 +01:00
|
|
|
|
2017-02-11 03:13:46 +01:00
|
|
|
int flag = 0;
|
2017-12-12 08:31:33 +01:00
|
|
|
std::thread thread([&system_properties, &flag]() {
|
|
|
|
prop_info* pi = const_cast<prop_info*>(system_properties.Find("property"));
|
|
|
|
usleep(100000);
|
|
|
|
|
|
|
|
flag = 1;
|
|
|
|
system_properties.Update(pi, "value3", 6);
|
|
|
|
});
|
2013-01-29 02:19:43 +01:00
|
|
|
ASSERT_EQ(flag, 0);
|
2017-12-12 08:31:33 +01:00
|
|
|
serial = system_properties.WaitAny(serial);
|
2013-01-29 02:19:43 +01:00
|
|
|
ASSERT_EQ(flag, 1);
|
|
|
|
|
2017-12-12 08:31:33 +01:00
|
|
|
thread.join();
|
2017-02-11 03:13:46 +01:00
|
|
|
#else // __BIONIC__
|
2019-03-09 00:20:23 +01:00
|
|
|
GTEST_SKIP() << "bionic-only test";
|
2017-02-11 03:13:46 +01:00
|
|
|
#endif // __BIONIC__
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(properties, __system_property_wait) {
|
|
|
|
#if defined(__BIONIC__)
|
2017-12-12 08:31:33 +01:00
|
|
|
SystemPropertiesTest system_properties;
|
|
|
|
ASSERT_TRUE(system_properties.valid());
|
2017-02-11 03:13:46 +01:00
|
|
|
|
2017-12-12 08:31:33 +01:00
|
|
|
ASSERT_EQ(0, system_properties.Add("property", 8, "value1", 6));
|
2017-02-11 03:13:46 +01:00
|
|
|
|
2017-12-12 08:31:33 +01:00
|
|
|
prop_info* pi = const_cast<prop_info*>(system_properties.Find("property"));
|
2017-02-11 03:13:46 +01:00
|
|
|
ASSERT_TRUE(pi != nullptr);
|
|
|
|
|
2019-11-12 21:41:55 +01:00
|
|
|
unsigned serial = __system_property_serial(pi);
|
2017-02-11 03:13:46 +01:00
|
|
|
|
2017-12-12 08:31:33 +01:00
|
|
|
std::thread thread([&system_properties]() {
|
|
|
|
prop_info* pi = const_cast<prop_info*>(system_properties.Find("property"));
|
2017-02-11 03:13:46 +01:00
|
|
|
ASSERT_TRUE(pi != nullptr);
|
|
|
|
|
2017-12-12 08:31:33 +01:00
|
|
|
system_properties.Update(pi, "value2", 6);
|
2017-02-11 03:13:46 +01:00
|
|
|
});
|
|
|
|
|
2017-02-17 02:13:04 +01:00
|
|
|
uint32_t new_serial;
|
2017-12-12 08:31:33 +01:00
|
|
|
system_properties.Wait(pi, serial, &new_serial, nullptr);
|
2017-02-17 02:13:04 +01:00
|
|
|
ASSERT_GT(new_serial, serial);
|
2017-02-11 03:13:46 +01:00
|
|
|
|
|
|
|
char value[PROP_VALUE_MAX];
|
2017-12-12 08:31:33 +01:00
|
|
|
ASSERT_EQ(6, system_properties.Get("property", value));
|
2017-02-11 03:13:46 +01:00
|
|
|
ASSERT_STREQ("value2", value);
|
|
|
|
|
|
|
|
thread.join();
|
2013-12-21 03:43:21 +01:00
|
|
|
#else // __BIONIC__
|
2019-03-09 00:20:23 +01:00
|
|
|
GTEST_SKIP() << "bionic-only test";
|
2013-12-21 03:43:21 +01:00
|
|
|
#endif // __BIONIC__
|
2013-01-29 02:19:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
class KilledByFault {
|
|
|
|
public:
|
|
|
|
explicit KilledByFault() {};
|
|
|
|
bool operator()(int exit_status) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
bool KilledByFault::operator()(int exit_status) const {
|
|
|
|
return WIFSIGNALED(exit_status) &&
|
|
|
|
(WTERMSIG(exit_status) == SIGSEGV ||
|
|
|
|
WTERMSIG(exit_status) == SIGBUS ||
|
|
|
|
WTERMSIG(exit_status) == SIGABRT);
|
|
|
|
}
|
|
|
|
|
2021-04-10 02:13:09 +02:00
|
|
|
using properties_DeathTest = SilentDeathTest;
|
2014-11-06 03:01:01 +01:00
|
|
|
|
|
|
|
TEST_F(properties_DeathTest, read_only) {
|
2013-12-21 03:43:21 +01:00
|
|
|
#if defined(__BIONIC__)
|
2013-10-22 02:09:52 +02:00
|
|
|
|
|
|
|
// This test only makes sense if we're talking to the real system property service.
|
|
|
|
struct stat sb;
|
2023-08-29 01:46:39 +02:00
|
|
|
ASSERT_FALSE(stat(PROP_DIRNAME, &sb) == -1 && errno == ENOENT);
|
2013-10-22 02:09:52 +02:00
|
|
|
|
|
|
|
ASSERT_EXIT(__system_property_add("property", 8, "value", 5), KilledByFault(), "");
|
2013-12-21 03:43:21 +01:00
|
|
|
#else // __BIONIC__
|
2019-03-09 00:20:23 +01:00
|
|
|
GTEST_SKIP() << "bionic-only test";
|
2013-12-21 03:43:21 +01:00
|
|
|
#endif // __BIONIC__
|
2013-01-29 02:19:43 +01:00
|
|
|
}
|
2017-10-09 22:49:17 +02:00
|
|
|
|
|
|
|
TEST(properties, __system_property_extra_long_read_only) {
|
|
|
|
#if defined(__BIONIC__)
|
2017-12-12 08:31:33 +01:00
|
|
|
SystemPropertiesTest system_properties;
|
|
|
|
ASSERT_TRUE(system_properties.valid());
|
2017-10-09 22:49:17 +02:00
|
|
|
|
|
|
|
std::vector<std::pair<std::string, std::string>> short_properties = {
|
|
|
|
{ "ro.0char", std::string() },
|
|
|
|
{ "ro.50char", std::string(50, 'x') },
|
|
|
|
{ "ro.91char", std::string(91, 'x') },
|
|
|
|
};
|
|
|
|
|
|
|
|
std::vector<std::pair<std::string, std::string>> long_properties = {
|
|
|
|
{ "ro.92char", std::string(92, 'x') },
|
|
|
|
{ "ro.93char", std::string(93, 'x') },
|
|
|
|
{ "ro.1000char", std::string(1000, 'x') },
|
|
|
|
};
|
|
|
|
|
|
|
|
for (const auto& property : short_properties) {
|
|
|
|
const std::string& name = property.first;
|
|
|
|
const std::string& value = property.second;
|
2017-12-12 08:31:33 +01:00
|
|
|
ASSERT_EQ(0, system_properties.Add(name.c_str(), name.size(), value.c_str(), value.size()));
|
2017-10-09 22:49:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
for (const auto& property : long_properties) {
|
|
|
|
const std::string& name = property.first;
|
|
|
|
const std::string& value = property.second;
|
2017-12-12 08:31:33 +01:00
|
|
|
ASSERT_EQ(0, system_properties.Add(name.c_str(), name.size(), value.c_str(), value.size()));
|
2017-10-09 22:49:17 +02:00
|
|
|
}
|
|
|
|
|
2017-12-12 08:31:33 +01:00
|
|
|
auto check_with_legacy_read = [&system_properties](const std::string& name,
|
|
|
|
const std::string& expected_value) {
|
2017-10-09 22:49:17 +02:00
|
|
|
char value[PROP_VALUE_MAX];
|
2017-12-12 08:31:33 +01:00
|
|
|
EXPECT_EQ(static_cast<int>(expected_value.size()), system_properties.Get(name.c_str(), value))
|
2017-10-09 22:49:17 +02:00
|
|
|
<< name;
|
|
|
|
EXPECT_EQ(expected_value, value) << name;
|
|
|
|
};
|
|
|
|
|
2017-12-12 08:31:33 +01:00
|
|
|
auto check_with_read_callback = [&system_properties](const std::string& name,
|
|
|
|
const std::string& expected_value) {
|
|
|
|
const prop_info* pi = system_properties.Find(name.c_str());
|
2017-10-09 22:49:17 +02:00
|
|
|
ASSERT_NE(nullptr, pi);
|
|
|
|
std::string value;
|
2017-12-12 08:31:33 +01:00
|
|
|
system_properties.ReadCallback(pi,
|
|
|
|
[](void* cookie, const char*, const char* value, uint32_t) {
|
|
|
|
auto* out_value = reinterpret_cast<std::string*>(cookie);
|
|
|
|
*out_value = value;
|
|
|
|
},
|
|
|
|
&value);
|
2017-10-09 22:49:17 +02:00
|
|
|
EXPECT_EQ(expected_value, value) << name;
|
|
|
|
};
|
|
|
|
|
|
|
|
for (const auto& property : short_properties) {
|
|
|
|
const std::string& name = property.first;
|
|
|
|
const std::string& value = property.second;
|
|
|
|
check_with_legacy_read(name, value);
|
|
|
|
check_with_read_callback(name, value);
|
|
|
|
}
|
|
|
|
|
2023-09-14 20:35:11 +02:00
|
|
|
static constexpr const char* kExtraLongLegacyError =
|
2017-10-09 22:49:17 +02:00
|
|
|
"Must use __system_property_read_callback() to read";
|
|
|
|
for (const auto& property : long_properties) {
|
|
|
|
const std::string& name = property.first;
|
|
|
|
const std::string& value = property.second;
|
|
|
|
check_with_legacy_read(name, kExtraLongLegacyError);
|
|
|
|
check_with_read_callback(name, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
#else // __BIONIC__
|
2019-03-09 00:20:23 +01:00
|
|
|
GTEST_SKIP() << "bionic-only test";
|
2017-10-09 22:49:17 +02:00
|
|
|
#endif // __BIONIC__
|
|
|
|
}
|
|
|
|
|
|
|
|
// pa_size is 128 * 1024 currently, if a property is longer then we expect it to fail gracefully.
|
|
|
|
TEST(properties, __system_property_extra_long_read_only_too_long) {
|
|
|
|
#if defined(__BIONIC__)
|
2017-12-12 08:31:33 +01:00
|
|
|
SystemPropertiesTest system_properties;
|
|
|
|
ASSERT_TRUE(system_properties.valid());
|
2017-10-09 22:49:17 +02:00
|
|
|
|
|
|
|
auto name = "ro.super_long_property"s;
|
2023-12-21 20:57:13 +01:00
|
|
|
|
|
|
|
#ifdef LARGE_SYSTEM_PROPERTY_NODE
|
|
|
|
auto value = std::string(1024 * 1024 + 1, 'x');
|
|
|
|
#else
|
2024-01-04 15:18:38 +01:00
|
|
|
auto value = std::string(128 * 1024 + 1, 'x');
|
2023-12-21 20:57:13 +01:00
|
|
|
#endif
|
|
|
|
|
2017-12-12 08:31:33 +01:00
|
|
|
ASSERT_NE(0, system_properties.Add(name.c_str(), name.size(), value.c_str(), value.size()));
|
2017-10-09 22:49:17 +02:00
|
|
|
|
|
|
|
#else // __BIONIC__
|
2019-03-09 00:20:23 +01:00
|
|
|
GTEST_SKIP() << "bionic-only test";
|
2017-10-09 22:49:17 +02:00
|
|
|
#endif // __BIONIC__
|
|
|
|
}
|
2023-10-20 01:50:59 +02:00
|
|
|
|
|
|
|
// Note that this test affects global state of the system
|
|
|
|
// this tests tries to mitigate this by using utime+pid
|
|
|
|
// prefix for the property name. It is still results in
|
|
|
|
// pollution of property service since properties cannot
|
|
|
|
// be removed.
|
|
|
|
//
|
|
|
|
// Note that there is also possibility to run into "out-of-memory"
|
|
|
|
// if this test if it is executed often enough without reboot.
|
|
|
|
TEST(properties, __system_property_reload_no_op) {
|
|
|
|
#if defined(__BIONIC__)
|
|
|
|
std::string property_name =
|
|
|
|
android::base::StringPrintf("debug.test.%d.%" PRId64 ".property", getpid(), NanoTime());
|
|
|
|
ASSERT_EQ(0, __system_property_find(property_name.c_str()));
|
|
|
|
ASSERT_EQ(0, __system_property_set(property_name.c_str(), "test value"));
|
|
|
|
ASSERT_EQ(0, __system_properties_zygote_reload());
|
|
|
|
const prop_info* readptr = __system_property_find(property_name.c_str());
|
|
|
|
std::string expected_name = property_name;
|
|
|
|
__system_property_read_callback(
|
|
|
|
readptr,
|
|
|
|
[](void*, const char*, const char* value, unsigned) { ASSERT_STREQ("test value", value); },
|
|
|
|
&expected_name);
|
|
|
|
#else // __BIONIC__
|
|
|
|
GTEST_SKIP() << "bionic-only test";
|
|
|
|
#endif // __BIONIC__
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(properties, __system_property_reload_invalid) {
|
|
|
|
#if defined(__BIONIC__)
|
|
|
|
if (getuid() != 0) GTEST_SKIP() << "test requires root";
|
|
|
|
SystemPropertiesTest system_properties;
|
|
|
|
|
|
|
|
// Create an invalid property_info file, so the system will attempt to initialize a
|
|
|
|
// ContextSerialized
|
|
|
|
std::string property_info_file =
|
|
|
|
android::base::StringPrintf("%s/property_info", system_properties.get_path());
|
|
|
|
fclose(fopen(property_info_file.c_str(), "w"));
|
|
|
|
int ret = mount(system_properties.get_path(), system_properties.get_real_sysprop_dir(), nullptr,
|
|
|
|
MS_BIND | MS_REC, nullptr);
|
|
|
|
if (ret != 0) {
|
|
|
|
ASSERT_ERRNO(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
ASSERT_EQ(-1, __system_properties_zygote_reload());
|
|
|
|
#else // __BIONIC__
|
|
|
|
GTEST_SKIP() << "bionic-only test";
|
|
|
|
#endif // __BIONIC__
|
|
|
|
}
|
|
|
|
|
|
|
|
// Note that this test affects global state of the system
|
|
|
|
// this tests tries to mitigate this by using utime+pid
|
|
|
|
// prefix for the property name. It is still results in
|
|
|
|
// pollution of property service since properties cannot
|
|
|
|
// be removed.
|
|
|
|
//
|
|
|
|
// Note that there is also possibility to run into "out-of-memory"
|
|
|
|
// if this test if it is executed often enough without reboot.
|
|
|
|
TEST(properties, __system_property_reload_valid) {
|
|
|
|
#if defined(__BIONIC__)
|
|
|
|
if (getuid() != 0) GTEST_SKIP() << "test requires root";
|
|
|
|
SystemPropertiesTest system_properties;
|
|
|
|
|
|
|
|
// Copy the system properties files into the temp directory
|
|
|
|
std::string shell_cmd = android::base::StringPrintf(
|
|
|
|
"cp -r %s %s", system_properties.get_real_sysprop_dir(), system_properties.get_path());
|
|
|
|
system(shell_cmd.c_str());
|
|
|
|
|
|
|
|
// Write a system property to the current set of system properties
|
|
|
|
std::string property_name =
|
|
|
|
android::base::StringPrintf("debug.test.%d.%" PRId64 ".property", getpid(), NanoTime());
|
|
|
|
ASSERT_EQ(0, __system_property_find(property_name.c_str()));
|
|
|
|
ASSERT_EQ(0, __system_property_set(property_name.c_str(), "test value"));
|
|
|
|
|
|
|
|
// Mount the temp directory (which doesn't have the property we just wrote) in place of the
|
|
|
|
// real one
|
|
|
|
int ret = mount(system_properties.get_mount_path(), system_properties.get_real_sysprop_dir(),
|
|
|
|
nullptr, MS_BIND | MS_REC, nullptr);
|
|
|
|
if (ret != 0) {
|
|
|
|
ASSERT_ERRNO(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
// reload system properties in the new dir, and verify the property we wrote after we copied the
|
|
|
|
// files isn't there
|
|
|
|
ASSERT_EQ(0, __system_properties_zygote_reload());
|
|
|
|
ASSERT_EQ(0, __system_property_find(property_name.c_str()));
|
|
|
|
|
|
|
|
#else // __BIONIC__
|
|
|
|
GTEST_SKIP() << "bionic-only test";
|
|
|
|
#endif // __BIONIC__
|
|
|
|
}
|