Revert "Revert "Remove limit of system property name length""
This reverts commit 489f58b5eaedd5a80635bb3a7b39e97037c585f6.
Bug: http://b/33926793
Bug: http://b/34670529
Test: Run bionic-unit-tests --gtest_filter=prop*
Change-Id: Id4e94652dc2310a21f5b7bd3af098bf79df3f380
diff --git a/tests/system_properties_test.cpp b/tests/system_properties_test.cpp
index 70482f0..6b037d8 100644
--- a/tests/system_properties_test.cpp
+++ b/tests/system_properties_test.cpp
@@ -69,7 +69,7 @@
static void foreach_test_callback(const prop_info *pi, void* cookie) {
size_t *count = static_cast<size_t *>(cookie);
- ASSERT_NE((prop_info *)NULL, pi);
+ ASSERT_TRUE(pi != nullptr);
(*count)++;
}
@@ -98,16 +98,15 @@
ok[name_i][name_j][name_k] = true;
}
-static void *PropertyWaitHelperFn(void *arg) {
- int *flag = (int *)arg;
- prop_info *pi;
- pi = (prop_info *)__system_property_find("property");
+static void* PropertyWaitHelperFn(void* arg) {
+ int* flag = static_cast<int*>(arg);
+ prop_info* pi = const_cast<prop_info*>(__system_property_find("property"));
usleep(100000);
*flag = 1;
__system_property_update(pi, "value3", 6);
- return NULL;
+ return nullptr;
}
#endif // __BIONIC__
@@ -123,6 +122,16 @@
ASSERT_EQ(0, __system_property_add("other_property", 14, "value2", 6));
ASSERT_EQ(0, __system_property_add("property_other", 14, "value3", 6));
+ // 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));
+
ASSERT_EQ(6, __system_property_get("property", propvalue));
ASSERT_STREQ(propvalue, "value1");
@@ -131,6 +140,9 @@
ASSERT_EQ(6, __system_property_get("property_other", propvalue));
ASSERT_STREQ(propvalue, "value3");
+
+ ASSERT_EQ(5, __system_property_get(name, propvalue));
+ ASSERT_STREQ(propvalue, "value");
#else // __BIONIC__
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif // __BIONIC__
@@ -323,7 +335,6 @@
ASSERT_EQ(0, __system_property_find("property1"));
ASSERT_EQ(0, __system_property_get("property1", prop_value));
- ASSERT_EQ(-1, __system_property_add("name", PROP_NAME_MAX, "value", 5));
ASSERT_EQ(-1, __system_property_add("name", 4, "value", PROP_VALUE_MAX));
ASSERT_EQ(-1, __system_property_update(NULL, "value", PROP_VALUE_MAX));
#else // __BIONIC__
@@ -359,12 +370,13 @@
ASSERT_EQ(0, __system_property_add("property", 8, "value1", 6));
serial = __system_property_wait_any(0);
- pi = (prop_info *)__system_property_find("property");
- ASSERT_NE((prop_info *)NULL, pi);
+
+ pi = const_cast<prop_info*>(__system_property_find("property"));
+ ASSERT_TRUE(pi != nullptr);
__system_property_update(pi, "value2", 6);
serial = __system_property_wait_any(serial);
- ASSERT_EQ(0, pthread_create(&t, NULL, PropertyWaitHelperFn, &flag));
+ ASSERT_EQ(0, pthread_create(&t, nullptr, PropertyWaitHelperFn, &flag));
ASSERT_EQ(flag, 0);
serial = __system_property_wait_any(serial);
ASSERT_EQ(flag, 1);
@@ -396,9 +408,7 @@
// This test only makes sense if we're talking to the real system property service.
struct stat sb;
- if (stat(PROP_FILENAME, &sb) == -1 && errno == ENOENT) {
- return;
- }
+ ASSERT_FALSE(stat(PROP_FILENAME, &sb) == -1 && errno == ENOENT);
ASSERT_EXIT(__system_property_add("property", 8, "value", 5), KilledByFault(), "");
#else // __BIONIC__