system_properties_test.cpp revision c6ff844d75dddfb19fc804b8add2d6a79947b101
1b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross/* 2b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross * Copyright (C) 2013 The Android Open Source Project 3b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross * 4b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross * Licensed under the Apache License, Version 2.0 (the "License"); 5b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross * you may not use this file except in compliance with the License. 6b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross * You may obtain a copy of the License at 7b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross * 8b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross * http://www.apache.org/licenses/LICENSE-2.0 9b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross * 10b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross * Unless required by applicable law or agreed to in writing, software 11b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross * distributed under the License is distributed on an "AS IS" BASIS, 12b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross * See the License for the specific language governing permissions and 14b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross * limitations under the License. 15b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross */ 16b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross 17b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross#include <gtest/gtest.h> 18b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross#include <sys/wait.h> 19b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross 20b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross#if __BIONIC__ 21b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross 22b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross#define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_ 23b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross#include <sys/_system_properties.h> 24b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross 25b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Crossextern void *__system_property_area__; 26b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross 27b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Crossstruct LocalPropertyTestState { 28b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross LocalPropertyTestState() { 29b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross old_pa = __system_property_area__; 30b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross pa = malloc(PA_SIZE); 31b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross __system_property_area_init(pa); 32b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross } 33b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross 34b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ~LocalPropertyTestState() { 35b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross __system_property_area__ = old_pa; 36b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross free(pa); 37b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross } 38b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Crossprivate: 39b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross void *pa; 40b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross void *old_pa; 41b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross}; 42b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross 43b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin CrossTEST(properties, add) { 44b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross LocalPropertyTestState pa; 45b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross 46b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross char propvalue[PROP_VALUE_MAX]; 47b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross 48b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_EQ(0, __system_property_add("property", 8, "value1", 6)); 49b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_EQ(0, __system_property_add("other_property", 14, "value2", 6)); 50b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_EQ(0, __system_property_add("property_other", 14, "value3", 6)); 51b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross 52b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_EQ(6, __system_property_get("property", propvalue)); 53b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_STREQ(propvalue, "value1"); 54b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross 55b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_EQ(6, __system_property_get("other_property", propvalue)); 56b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_STREQ(propvalue, "value2"); 57b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross 58b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_EQ(6, __system_property_get("property_other", propvalue)); 59b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_STREQ(propvalue, "value3"); 60b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross} 61b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross 62b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin CrossTEST(properties, update) { 63b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross LocalPropertyTestState pa; 64b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross 65b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross char propvalue[PROP_VALUE_MAX]; 66b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross prop_info *pi; 67b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross 68b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_EQ(0, __system_property_add("property", 8, "oldvalue1", 9)); 69b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_EQ(0, __system_property_add("other_property", 14, "value2", 6)); 70b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_EQ(0, __system_property_add("property_other", 14, "value3", 6)); 71b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross 72b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross pi = (prop_info *)__system_property_find("property"); 73b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_NE((prop_info *)NULL, pi); 74b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross __system_property_update(pi, "value4", 6); 75b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross 76b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross pi = (prop_info *)__system_property_find("other_property"); 77b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_NE((prop_info *)NULL, pi); 78b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross __system_property_update(pi, "newvalue5", 9); 79b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross 80b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross pi = (prop_info *)__system_property_find("property_other"); 81b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_NE((prop_info *)NULL, pi); 82b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross __system_property_update(pi, "value6", 6); 83b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross 84b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_EQ(6, __system_property_get("property", propvalue)); 85b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_STREQ(propvalue, "value4"); 86b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross 87b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_EQ(9, __system_property_get("other_property", propvalue)); 88b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_STREQ(propvalue, "newvalue5"); 89b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross 90b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_EQ(6, __system_property_get("property_other", propvalue)); 91b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_STREQ(propvalue, "value6"); 92b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross} 93b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross 94b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross// 247 = max # of properties supported by current implementation 95b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross// (this should never go down) 96b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin CrossTEST(properties, fill_247) { 97b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross LocalPropertyTestState pa; 98b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross char prop_name[PROP_NAME_MAX]; 99b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross char prop_value[PROP_VALUE_MAX]; 100b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross char prop_value_ret[PROP_VALUE_MAX]; 101b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross int ret; 102b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross 103b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross for (int i = 0; i < 247; i++) { 104b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ret = snprintf(prop_name, PROP_NAME_MAX - 1, "property_%d", i); 105b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross memset(prop_name + ret, 'a', PROP_NAME_MAX - 1 - ret); 106b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ret = snprintf(prop_value, PROP_VALUE_MAX - 1, "value_%d", i); 107b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross memset(prop_value + ret, 'b', PROP_VALUE_MAX - 1 - ret); 108b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross prop_name[PROP_NAME_MAX - 1] = 0; 109b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross prop_value[PROP_VALUE_MAX - 1] = 0; 110b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross 111b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_EQ(0, __system_property_add(prop_name, PROP_NAME_MAX - 1, prop_value, PROP_VALUE_MAX - 1)); 112b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross } 113b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross 114b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross for (int i = 0; i < 247; i++) { 115b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ret = snprintf(prop_name, PROP_NAME_MAX - 1, "property_%d", i); 116b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross memset(prop_name + ret, 'a', PROP_NAME_MAX - 1 - ret); 117b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ret = snprintf(prop_value, PROP_VALUE_MAX - 1, "value_%d", i); 118b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross memset(prop_value + ret, 'b', PROP_VALUE_MAX - 1 - ret); 119b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross prop_name[PROP_NAME_MAX - 1] = 0; 120b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross prop_value[PROP_VALUE_MAX - 1] = 0; 121b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross memset(prop_value_ret, '\0', PROP_VALUE_MAX); 122b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross 123b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_EQ(PROP_VALUE_MAX - 1, __system_property_get(prop_name, prop_value_ret)); 124b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_EQ(0, memcmp(prop_value, prop_value_ret, PROP_VALUE_MAX)); 125b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross } 126b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross} 127b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross 128c6ff844d75dddfb19fc804b8add2d6a79947b101Greg Hackmannstatic void foreach_test_callback(const prop_info *pi, void* cookie) { 129c6ff844d75dddfb19fc804b8add2d6a79947b101Greg Hackmann size_t *count = static_cast<size_t *>(cookie); 130c6ff844d75dddfb19fc804b8add2d6a79947b101Greg Hackmann 131c6ff844d75dddfb19fc804b8add2d6a79947b101Greg Hackmann ASSERT_NE((prop_info *)NULL, pi); 132c6ff844d75dddfb19fc804b8add2d6a79947b101Greg Hackmann (*count)++; 133c6ff844d75dddfb19fc804b8add2d6a79947b101Greg Hackmann} 134c6ff844d75dddfb19fc804b8add2d6a79947b101Greg Hackmann 135c6ff844d75dddfb19fc804b8add2d6a79947b101Greg HackmannTEST(properties, foreach) { 136c6ff844d75dddfb19fc804b8add2d6a79947b101Greg Hackmann LocalPropertyTestState pa; 137c6ff844d75dddfb19fc804b8add2d6a79947b101Greg Hackmann size_t count = 0; 138c6ff844d75dddfb19fc804b8add2d6a79947b101Greg Hackmann 139c6ff844d75dddfb19fc804b8add2d6a79947b101Greg Hackmann ASSERT_EQ(0, __system_property_add("property", 8, "value1", 6)); 140c6ff844d75dddfb19fc804b8add2d6a79947b101Greg Hackmann ASSERT_EQ(0, __system_property_add("other_property", 14, "value2", 6)); 141c6ff844d75dddfb19fc804b8add2d6a79947b101Greg Hackmann ASSERT_EQ(0, __system_property_add("property_other", 14, "value3", 6)); 142c6ff844d75dddfb19fc804b8add2d6a79947b101Greg Hackmann 143c6ff844d75dddfb19fc804b8add2d6a79947b101Greg Hackmann ASSERT_EQ(0, __system_property_foreach(foreach_test_callback, &count)); 144c6ff844d75dddfb19fc804b8add2d6a79947b101Greg Hackmann ASSERT_EQ(3U, count); 145c6ff844d75dddfb19fc804b8add2d6a79947b101Greg Hackmann} 146c6ff844d75dddfb19fc804b8add2d6a79947b101Greg Hackmann 147b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin CrossTEST(properties, find_nth) { 148b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross LocalPropertyTestState pa; 149b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross 150b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_EQ(0, __system_property_add("property", 8, "value1", 6)); 151b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_EQ(0, __system_property_add("other_property", 14, "value2", 6)); 152b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_EQ(0, __system_property_add("property_other", 14, "value3", 6)); 153b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross 154b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_NE((const prop_info *)NULL, __system_property_find_nth(0)); 155b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_NE((const prop_info *)NULL, __system_property_find_nth(1)); 156b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_NE((const prop_info *)NULL, __system_property_find_nth(2)); 157b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross 158b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_EQ((const prop_info *)NULL, __system_property_find_nth(3)); 159b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_EQ((const prop_info *)NULL, __system_property_find_nth(4)); 160b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_EQ((const prop_info *)NULL, __system_property_find_nth(5)); 161b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_EQ((const prop_info *)NULL, __system_property_find_nth(100)); 162b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_EQ((const prop_info *)NULL, __system_property_find_nth(200)); 163b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_EQ((const prop_info *)NULL, __system_property_find_nth(247)); 164b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross} 165b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross 166b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin CrossTEST(properties, errors) { 167b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross LocalPropertyTestState pa; 168b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross char prop_value[PROP_NAME_MAX]; 169b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross 170b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_EQ(0, __system_property_add("property", 8, "value1", 6)); 171b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_EQ(0, __system_property_add("other_property", 14, "value2", 6)); 172b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_EQ(0, __system_property_add("property_other", 14, "value3", 6)); 173b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross 174b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_EQ(0, __system_property_find("property1")); 175b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_EQ(0, __system_property_get("property1", prop_value)); 176b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross 177b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_EQ(-1, __system_property_add("name", PROP_NAME_MAX, "value", 5)); 178b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_EQ(-1, __system_property_add("name", 4, "value", PROP_VALUE_MAX)); 179b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_EQ(-1, __system_property_update(NULL, "value", PROP_VALUE_MAX)); 180b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross} 181b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross 182b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin CrossTEST(properties, serial) { 183b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross LocalPropertyTestState pa; 184b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross const prop_info *pi; 185b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross unsigned int serial; 186b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross 187b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_EQ(0, __system_property_add("property", 8, "value1", 6)); 188b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_NE((const prop_info *)NULL, pi = __system_property_find("property")); 189b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross serial = __system_property_serial(pi); 190b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_EQ(0, __system_property_update((prop_info *)pi, "value2", 6)); 191b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_NE(serial, __system_property_serial(pi)); 192b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross} 193b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross 194b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Crossstatic void *PropertyWaitHelperFn(void *arg) 195b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross{ 196b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross int *flag = (int *)arg; 197b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross prop_info *pi; 198b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross pi = (prop_info *)__system_property_find("property"); 199b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross usleep(100000); 200b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross 201b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross *flag = 1; 202b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross __system_property_update(pi, "value3", 6); 203b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross 204b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross return NULL; 205b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross} 206b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross 207b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin CrossTEST(properties, wait) { 208b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross LocalPropertyTestState pa; 209b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross unsigned int serial; 210b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross prop_info *pi; 211b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross pthread_t t; 212b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross int flag = 0; 213b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross 214b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_EQ(0, __system_property_add("property", 8, "value1", 6)); 215b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross serial = __system_property_wait_any(0); 216b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross pi = (prop_info *)__system_property_find("property"); 217b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_NE((prop_info *)NULL, pi); 218b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross __system_property_update(pi, "value2", 6); 219b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross serial = __system_property_wait_any(serial); 220b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross 221b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_EQ(0, pthread_create(&t, NULL, PropertyWaitHelperFn, &flag)); 222b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_EQ(flag, 0); 223b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross serial = __system_property_wait_any(serial); 224b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_EQ(flag, 1); 225b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross 226b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross void* result; 227b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_EQ(0, pthread_join(t, &result)); 228b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross} 229b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross 230b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Crossclass KilledByFault { 231b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross public: 232b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross explicit KilledByFault() {}; 233b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross bool operator()(int exit_status) const; 234b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross}; 235b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross 236b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Crossbool KilledByFault::operator()(int exit_status) const { 237b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross return WIFSIGNALED(exit_status) && 238b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross (WTERMSIG(exit_status) == SIGSEGV || 239b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross WTERMSIG(exit_status) == SIGBUS || 240b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross WTERMSIG(exit_status) == SIGABRT); 241b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross} 242b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross 243b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin CrossTEST(properties_DeathTest, read_only) { 244b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ::testing::FLAGS_gtest_death_test_style = "threadsafe"; 245b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_EXIT(__system_property_add("property", 8, "value", 5), 246b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross KilledByFault(), ""); 247b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross} 248b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross#endif 249