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
|
|
|
#include "BionicDeathTest.h"
|
|
|
|
|
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
|
|
|
|
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_
|
|
|
|
#include <sys/_system_properties.h>
|
|
|
|
|
|
|
|
struct LocalPropertyTestState {
|
2013-02-13 23:41:48 +01:00
|
|
|
LocalPropertyTestState() : valid(false) {
|
2013-10-22 02:09:52 +02:00
|
|
|
const char* ANDROID_DATA = getenv("ANDROID_DATA");
|
|
|
|
char dir_template[PATH_MAX];
|
|
|
|
snprintf(dir_template, sizeof(dir_template), "%s/local/tmp/prop-XXXXXX", ANDROID_DATA);
|
|
|
|
char* dirname = mkdtemp(dir_template);
|
2013-02-13 23:41:48 +01:00
|
|
|
if (!dirname) {
|
2013-10-22 02:09:52 +02:00
|
|
|
fprintf(stderr, "making temp file for test state failed (is %s writable?): %s",
|
|
|
|
dir_template, strerror(errno));
|
2013-02-13 23:41:48 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
pa_dirname = dirname;
|
|
|
|
pa_filename = pa_dirname + "/__properties__";
|
|
|
|
|
|
|
|
__system_property_set_filename(pa_filename.c_str());
|
|
|
|
__system_property_area_init();
|
|
|
|
valid = true;
|
2013-01-29 02:19:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
~LocalPropertyTestState() {
|
2013-10-22 02:09:52 +02:00
|
|
|
if (!valid) {
|
2013-02-13 23:41:48 +01:00
|
|
|
return;
|
2013-10-22 02:09:52 +02:00
|
|
|
}
|
2013-02-13 23:41:48 +01:00
|
|
|
|
|
|
|
__system_property_set_filename(PROP_FILENAME);
|
2015-09-24 01:09:47 +02:00
|
|
|
__system_properties_init();
|
2013-02-13 23:41:48 +01:00
|
|
|
unlink(pa_filename.c_str());
|
|
|
|
rmdir(pa_dirname.c_str());
|
2013-01-29 02:19:43 +01:00
|
|
|
}
|
2013-02-13 23:41:48 +01:00
|
|
|
public:
|
|
|
|
bool valid;
|
2013-01-29 02:19:43 +01:00
|
|
|
private:
|
2013-02-13 23:41:48 +01:00
|
|
|
std::string pa_dirname;
|
|
|
|
std::string pa_filename;
|
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;
|
|
|
|
}
|
|
|
|
|
2017-01-24 21:43:29 +01:00
|
|
|
static void* PropertyWaitHelperFn(void* arg) {
|
|
|
|
int* flag = static_cast<int*>(arg);
|
|
|
|
prop_info* pi = const_cast<prop_info*>(__system_property_find("property"));
|
2013-12-21 03:43:21 +01:00
|
|
|
usleep(100000);
|
|
|
|
|
|
|
|
*flag = 1;
|
|
|
|
__system_property_update(pi, "value3", 6);
|
|
|
|
|
2017-01-24 21:43:29 +01:00
|
|
|
return nullptr;
|
2013-12-21 03:43:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#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__)
|
2013-01-29 02:19:43 +01:00
|
|
|
LocalPropertyTestState pa;
|
2013-02-13 23:41:48 +01:00
|
|
|
ASSERT_TRUE(pa.valid);
|
2013-01-29 02:19:43 +01:00
|
|
|
|
|
|
|
ASSERT_EQ(0, __system_property_add("property", 8, "value1", 6));
|
|
|
|
ASSERT_EQ(0, __system_property_add("other_property", 14, "value2", 6));
|
|
|
|
ASSERT_EQ(0, __system_property_add("property_other", 14, "value3", 6));
|
|
|
|
|
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';
|
|
|
|
ASSERT_EQ(0, __system_property_add(name, strlen(name), "value", 5));
|
|
|
|
|
2017-02-11 03:13:46 +01:00
|
|
|
char propvalue[PROP_VALUE_MAX];
|
2013-01-29 02:19:43 +01:00
|
|
|
ASSERT_EQ(6, __system_property_get("property", propvalue));
|
|
|
|
ASSERT_STREQ(propvalue, "value1");
|
|
|
|
|
|
|
|
ASSERT_EQ(6, __system_property_get("other_property", propvalue));
|
|
|
|
ASSERT_STREQ(propvalue, "value2");
|
|
|
|
|
|
|
|
ASSERT_EQ(6, __system_property_get("property_other", propvalue));
|
|
|
|
ASSERT_STREQ(propvalue, "value3");
|
2017-01-24 21:43:29 +01:00
|
|
|
|
|
|
|
ASSERT_EQ(5, __system_property_get(name, propvalue));
|
|
|
|
ASSERT_STREQ(propvalue, "value");
|
2013-12-21 03:43:21 +01:00
|
|
|
#else // __BIONIC__
|
|
|
|
GTEST_LOG_(INFO) << "This test does nothing.\n";
|
|
|
|
#endif // __BIONIC__
|
2013-01-29 02:19:43 +01:00
|
|
|
}
|
|
|
|
|
2017-02-11 03:13:46 +01:00
|
|
|
TEST(properties, __system_property_update) {
|
2013-12-21 03:43:21 +01:00
|
|
|
#if defined(__BIONIC__)
|
2013-01-29 02:19:43 +01:00
|
|
|
LocalPropertyTestState pa;
|
2013-02-13 23:41:48 +01:00
|
|
|
ASSERT_TRUE(pa.valid);
|
2013-01-29 02:19:43 +01:00
|
|
|
|
|
|
|
ASSERT_EQ(0, __system_property_add("property", 8, "oldvalue1", 9));
|
|
|
|
ASSERT_EQ(0, __system_property_add("other_property", 14, "value2", 6));
|
|
|
|
ASSERT_EQ(0, __system_property_add("property_other", 14, "value3", 6));
|
|
|
|
|
2017-02-11 03:13:46 +01:00
|
|
|
const prop_info* pi = __system_property_find("property");
|
|
|
|
ASSERT_TRUE(pi != nullptr);
|
|
|
|
__system_property_update(const_cast<prop_info*>(pi), "value4", 6);
|
2013-01-29 02:19:43 +01:00
|
|
|
|
2017-02-11 03:13:46 +01:00
|
|
|
pi = __system_property_find("other_property");
|
|
|
|
ASSERT_TRUE(pi != nullptr);
|
|
|
|
__system_property_update(const_cast<prop_info*>(pi), "newvalue5", 9);
|
2013-01-29 02:19:43 +01:00
|
|
|
|
2017-02-11 03:13:46 +01:00
|
|
|
pi = __system_property_find("property_other");
|
|
|
|
ASSERT_TRUE(pi != nullptr);
|
|
|
|
__system_property_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];
|
2013-01-29 02:19:43 +01:00
|
|
|
ASSERT_EQ(6, __system_property_get("property", propvalue));
|
|
|
|
ASSERT_STREQ(propvalue, "value4");
|
|
|
|
|
|
|
|
ASSERT_EQ(9, __system_property_get("other_property", propvalue));
|
|
|
|
ASSERT_STREQ(propvalue, "newvalue5");
|
|
|
|
|
|
|
|
ASSERT_EQ(6, __system_property_get("property_other", propvalue));
|
|
|
|
ASSERT_STREQ(propvalue, "value6");
|
2013-12-21 03:43:21 +01:00
|
|
|
#else // __BIONIC__
|
|
|
|
GTEST_LOG_(INFO) << "This test does nothing.\n";
|
|
|
|
#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__)
|
2013-01-29 02:19:43 +01:00
|
|
|
LocalPropertyTestState pa;
|
2013-02-13 23:41:48 +01:00
|
|
|
ASSERT_TRUE(pa.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;
|
|
|
|
|
2013-02-13 23:41:48 +01:00
|
|
|
ret = __system_property_add(prop_name, PROP_NAME_MAX - 1, prop_value, PROP_VALUE_MAX - 1);
|
|
|
|
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);
|
|
|
|
|
|
|
|
ASSERT_EQ(PROP_VALUE_MAX - 1, __system_property_get(prop_name, prop_value_ret));
|
|
|
|
ASSERT_EQ(0, memcmp(prop_value, prop_value_ret, PROP_VALUE_MAX));
|
|
|
|
}
|
2013-12-21 03:43:21 +01:00
|
|
|
#else // __BIONIC__
|
|
|
|
GTEST_LOG_(INFO) << "This test does nothing.\n";
|
|
|
|
#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__)
|
2013-02-13 01:39:31 +01:00
|
|
|
LocalPropertyTestState pa;
|
2013-02-13 23:41:48 +01:00
|
|
|
ASSERT_TRUE(pa.valid);
|
2013-02-13 01:39:31 +01:00
|
|
|
|
|
|
|
ASSERT_EQ(0, __system_property_add("property", 8, "value1", 6));
|
|
|
|
ASSERT_EQ(0, __system_property_add("other_property", 14, "value2", 6));
|
|
|
|
ASSERT_EQ(0, __system_property_add("property_other", 14, "value3", 6));
|
|
|
|
|
2017-02-11 03:13:46 +01:00
|
|
|
size_t count = 0;
|
2013-02-13 01:39:31 +01:00
|
|
|
ASSERT_EQ(0, __system_property_foreach(foreach_test_callback, &count));
|
|
|
|
ASSERT_EQ(3U, count);
|
2013-12-21 03:43:21 +01:00
|
|
|
#else // __BIONIC__
|
|
|
|
GTEST_LOG_(INFO) << "This test does nothing.\n";
|
|
|
|
#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__)
|
2013-01-29 02:19:43 +01:00
|
|
|
LocalPropertyTestState pa;
|
2013-02-13 23:41:48 +01:00
|
|
|
ASSERT_TRUE(pa.valid);
|
2013-01-29 02:19:43 +01:00
|
|
|
|
|
|
|
ASSERT_EQ(0, __system_property_add("property", 8, "value1", 6));
|
|
|
|
ASSERT_EQ(0, __system_property_add("other_property", 14, "value2", 6));
|
|
|
|
ASSERT_EQ(0, __system_property_add("property_other", 14, "value3", 6));
|
|
|
|
|
2017-01-09 20:05:52 +01:00
|
|
|
// This method is no longer supported and should result in abort
|
|
|
|
ASSERT_EXIT(__system_property_find_nth(0), testing::KilledBySignal(SIGABRT),
|
|
|
|
"__system_property_find_nth is not supported since Android O,"
|
|
|
|
" please use __system_property_foreach instead.");
|
2013-12-21 03:43:21 +01:00
|
|
|
#else // __BIONIC__
|
|
|
|
GTEST_LOG_(INFO) << "This test does nothing.\n";
|
|
|
|
#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__)
|
2013-06-17 21:37:09 +02:00
|
|
|
LocalPropertyTestState pa;
|
|
|
|
ASSERT_TRUE(pa.valid);
|
|
|
|
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;
|
|
|
|
|
|
|
|
ASSERT_EQ(0, __system_property_add(prop_name, PROP_NAME_MAX - 1, prop_value, PROP_VALUE_MAX - 1));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
ASSERT_EQ(PROP_VALUE_MAX - 1, __system_property_get(prop_name, prop_value_ret));
|
|
|
|
ASSERT_EQ(0, memcmp(prop_value, prop_value_ret, PROP_VALUE_MAX));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ok[8][8][8];
|
|
|
|
memset(ok, 0, sizeof(ok));
|
|
|
|
__system_property_foreach(hierarchical_test_callback, ok);
|
|
|
|
|
|
|
|
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__
|
|
|
|
GTEST_LOG_(INFO) << "This test does nothing.\n";
|
|
|
|
#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__)
|
2013-01-29 02:19:43 +01:00
|
|
|
LocalPropertyTestState pa;
|
2013-02-13 23:41:48 +01:00
|
|
|
ASSERT_TRUE(pa.valid);
|
2013-01-29 02:19:43 +01:00
|
|
|
char prop_value[PROP_NAME_MAX];
|
|
|
|
|
|
|
|
ASSERT_EQ(0, __system_property_add("property", 8, "value1", 6));
|
|
|
|
ASSERT_EQ(0, __system_property_add("other_property", 14, "value2", 6));
|
|
|
|
ASSERT_EQ(0, __system_property_add("property_other", 14, "value3", 6));
|
|
|
|
|
|
|
|
ASSERT_EQ(0, __system_property_find("property1"));
|
|
|
|
ASSERT_EQ(0, __system_property_get("property1", prop_value));
|
|
|
|
|
|
|
|
ASSERT_EQ(-1, __system_property_add("name", 4, "value", PROP_VALUE_MAX));
|
|
|
|
ASSERT_EQ(-1, __system_property_update(NULL, "value", PROP_VALUE_MAX));
|
2013-12-21 03:43:21 +01:00
|
|
|
#else // __BIONIC__
|
|
|
|
GTEST_LOG_(INFO) << "This test does nothing.\n";
|
|
|
|
#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__)
|
2013-01-29 02:19:43 +01:00
|
|
|
LocalPropertyTestState pa;
|
2013-02-13 23:41:48 +01:00
|
|
|
ASSERT_TRUE(pa.valid);
|
2013-01-29 02:19:43 +01:00
|
|
|
|
|
|
|
ASSERT_EQ(0, __system_property_add("property", 8, "value1", 6));
|
2017-02-11 03:13:46 +01:00
|
|
|
const prop_info* pi = __system_property_find("property");
|
|
|
|
ASSERT_TRUE(pi != nullptr);
|
|
|
|
unsigned serial = __system_property_serial(pi);
|
|
|
|
ASSERT_EQ(0, __system_property_update(const_cast<prop_info*>(pi), "value2", 6));
|
2013-01-29 02:19:43 +01:00
|
|
|
ASSERT_NE(serial, __system_property_serial(pi));
|
2013-12-21 03:43:21 +01:00
|
|
|
#else // __BIONIC__
|
|
|
|
GTEST_LOG_(INFO) << "This test does nothing.\n";
|
|
|
|
#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__)
|
2013-01-29 02:19:43 +01:00
|
|
|
LocalPropertyTestState pa;
|
2013-02-13 23:41:48 +01:00
|
|
|
ASSERT_TRUE(pa.valid);
|
2013-01-29 02:19:43 +01:00
|
|
|
|
|
|
|
ASSERT_EQ(0, __system_property_add("property", 8, "value1", 6));
|
2017-02-11 03:13:46 +01:00
|
|
|
unsigned serial = __system_property_wait_any(0);
|
2017-01-24 21:43:29 +01:00
|
|
|
|
2017-02-11 03:13:46 +01:00
|
|
|
prop_info* pi = const_cast<prop_info*>(__system_property_find("property"));
|
2017-01-24 21:43:29 +01:00
|
|
|
ASSERT_TRUE(pi != nullptr);
|
2013-01-29 02:19:43 +01:00
|
|
|
__system_property_update(pi, "value2", 6);
|
|
|
|
serial = __system_property_wait_any(serial);
|
|
|
|
|
2017-02-11 03:13:46 +01:00
|
|
|
int flag = 0;
|
|
|
|
pthread_t t;
|
2017-01-24 21:43:29 +01:00
|
|
|
ASSERT_EQ(0, pthread_create(&t, nullptr, PropertyWaitHelperFn, &flag));
|
2013-01-29 02:19:43 +01:00
|
|
|
ASSERT_EQ(flag, 0);
|
|
|
|
serial = __system_property_wait_any(serial);
|
|
|
|
ASSERT_EQ(flag, 1);
|
|
|
|
|
2017-02-11 03:13:46 +01:00
|
|
|
ASSERT_EQ(0, pthread_join(t, nullptr));
|
|
|
|
#else // __BIONIC__
|
|
|
|
GTEST_LOG_(INFO) << "This test does nothing.\n";
|
|
|
|
#endif // __BIONIC__
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(properties, __system_property_wait) {
|
|
|
|
#if defined(__BIONIC__)
|
|
|
|
LocalPropertyTestState pa;
|
|
|
|
ASSERT_TRUE(pa.valid);
|
|
|
|
|
|
|
|
ASSERT_EQ(0, __system_property_add("property", 8, "value1", 6));
|
|
|
|
|
|
|
|
prop_info* pi = const_cast<prop_info*>(__system_property_find("property"));
|
|
|
|
ASSERT_TRUE(pi != nullptr);
|
|
|
|
|
|
|
|
unsigned serial = __system_property_serial(pi);
|
|
|
|
|
|
|
|
std::thread thread([]() {
|
|
|
|
prop_info* pi = const_cast<prop_info*>(__system_property_find("property"));
|
|
|
|
ASSERT_TRUE(pi != nullptr);
|
|
|
|
|
|
|
|
__system_property_update(pi, "value2", 6);
|
|
|
|
});
|
|
|
|
|
2017-02-17 02:13:04 +01:00
|
|
|
uint32_t new_serial;
|
|
|
|
__system_property_wait(pi, serial, &new_serial, nullptr);
|
|
|
|
ASSERT_GT(new_serial, serial);
|
2017-02-11 03:13:46 +01:00
|
|
|
|
|
|
|
char value[PROP_VALUE_MAX];
|
|
|
|
ASSERT_EQ(6, __system_property_get("property", value));
|
|
|
|
ASSERT_STREQ("value2", value);
|
|
|
|
|
|
|
|
thread.join();
|
2013-12-21 03:43:21 +01:00
|
|
|
#else // __BIONIC__
|
|
|
|
GTEST_LOG_(INFO) << "This test does nothing.\n";
|
|
|
|
#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);
|
|
|
|
}
|
|
|
|
|
2014-11-06 03:01:01 +01:00
|
|
|
class properties_DeathTest : public BionicDeathTest {};
|
|
|
|
|
|
|
|
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;
|
2017-01-24 21:43:29 +01:00
|
|
|
ASSERT_FALSE(stat(PROP_FILENAME, &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__
|
|
|
|
GTEST_LOG_(INFO) << "This test does nothing.\n";
|
|
|
|
#endif // __BIONIC__
|
2013-01-29 02:19:43 +01:00
|
|
|
}
|