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> 189df70403d95f5cfe6824e38a9a6c35f9b9bbc76aYabin Cui#include "BionicDeathTest.h" 199df70403d95f5cfe6824e38a9a6c35f9b9bbc76aYabin Cui 20e4375196d650f68ad486e2202699c98f9342d616Elliott Hughes#include <errno.h> 219df70403d95f5cfe6824e38a9a6c35f9b9bbc76aYabin Cui#include <sys/wait.h> 22cb215a7e9ecec9feb5aae9d9a5b1c89f392208e7Greg Hackmann#include <unistd.h> 23cb215a7e9ecec9feb5aae9d9a5b1c89f392208e7Greg Hackmann#include <string> 24b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross 25f04935c85e0b466f0d30d2cd4c0fa2fff62e7d6dChristopher Ferris#if defined(__BIONIC__) 26b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross 27b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross#define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_ 28b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross#include <sys/_system_properties.h> 29b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross 301540f601be32bdd4af8e8c13bdf2bc06bdaa76f1Greg Hackmannextern void *__system_property_area__; 31b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross 32b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Crossstruct LocalPropertyTestState { 33cb215a7e9ecec9feb5aae9d9a5b1c89f392208e7Greg Hackmann LocalPropertyTestState() : valid(false) { 34e4375196d650f68ad486e2202699c98f9342d616Elliott Hughes const char* ANDROID_DATA = getenv("ANDROID_DATA"); 35e4375196d650f68ad486e2202699c98f9342d616Elliott Hughes char dir_template[PATH_MAX]; 36e4375196d650f68ad486e2202699c98f9342d616Elliott Hughes snprintf(dir_template, sizeof(dir_template), "%s/local/tmp/prop-XXXXXX", ANDROID_DATA); 37e4375196d650f68ad486e2202699c98f9342d616Elliott Hughes char* dirname = mkdtemp(dir_template); 38cb215a7e9ecec9feb5aae9d9a5b1c89f392208e7Greg Hackmann if (!dirname) { 39e4375196d650f68ad486e2202699c98f9342d616Elliott Hughes fprintf(stderr, "making temp file for test state failed (is %s writable?): %s", 40e4375196d650f68ad486e2202699c98f9342d616Elliott Hughes dir_template, strerror(errno)); 41cb215a7e9ecec9feb5aae9d9a5b1c89f392208e7Greg Hackmann return; 42cb215a7e9ecec9feb5aae9d9a5b1c89f392208e7Greg Hackmann } 43cb215a7e9ecec9feb5aae9d9a5b1c89f392208e7Greg Hackmann 441540f601be32bdd4af8e8c13bdf2bc06bdaa76f1Greg Hackmann old_pa = __system_property_area__; 451540f601be32bdd4af8e8c13bdf2bc06bdaa76f1Greg Hackmann __system_property_area__ = NULL; 46cb215a7e9ecec9feb5aae9d9a5b1c89f392208e7Greg Hackmann 47cb215a7e9ecec9feb5aae9d9a5b1c89f392208e7Greg Hackmann pa_dirname = dirname; 48cb215a7e9ecec9feb5aae9d9a5b1c89f392208e7Greg Hackmann pa_filename = pa_dirname + "/__properties__"; 49cb215a7e9ecec9feb5aae9d9a5b1c89f392208e7Greg Hackmann 50cb215a7e9ecec9feb5aae9d9a5b1c89f392208e7Greg Hackmann __system_property_set_filename(pa_filename.c_str()); 51cb215a7e9ecec9feb5aae9d9a5b1c89f392208e7Greg Hackmann __system_property_area_init(); 52cb215a7e9ecec9feb5aae9d9a5b1c89f392208e7Greg Hackmann valid = true; 53b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross } 54b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross 55b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ~LocalPropertyTestState() { 56e4375196d650f68ad486e2202699c98f9342d616Elliott Hughes if (!valid) { 57cb215a7e9ecec9feb5aae9d9a5b1c89f392208e7Greg Hackmann return; 58e4375196d650f68ad486e2202699c98f9342d616Elliott Hughes } 59cb215a7e9ecec9feb5aae9d9a5b1c89f392208e7Greg Hackmann 601540f601be32bdd4af8e8c13bdf2bc06bdaa76f1Greg Hackmann __system_property_area__ = old_pa; 61cb215a7e9ecec9feb5aae9d9a5b1c89f392208e7Greg Hackmann 62cb215a7e9ecec9feb5aae9d9a5b1c89f392208e7Greg Hackmann __system_property_set_filename(PROP_FILENAME); 63cb215a7e9ecec9feb5aae9d9a5b1c89f392208e7Greg Hackmann unlink(pa_filename.c_str()); 64cb215a7e9ecec9feb5aae9d9a5b1c89f392208e7Greg Hackmann rmdir(pa_dirname.c_str()); 65b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross } 66cb215a7e9ecec9feb5aae9d9a5b1c89f392208e7Greg Hackmannpublic: 67cb215a7e9ecec9feb5aae9d9a5b1c89f392208e7Greg Hackmann bool valid; 68b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Crossprivate: 69cb215a7e9ecec9feb5aae9d9a5b1c89f392208e7Greg Hackmann std::string pa_dirname; 70cb215a7e9ecec9feb5aae9d9a5b1c89f392208e7Greg Hackmann std::string pa_filename; 711540f601be32bdd4af8e8c13bdf2bc06bdaa76f1Greg Hackmann void *old_pa; 72b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross}; 73b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross 74f04935c85e0b466f0d30d2cd4c0fa2fff62e7d6dChristopher Ferrisstatic void foreach_test_callback(const prop_info *pi, void* cookie) { 75f04935c85e0b466f0d30d2cd4c0fa2fff62e7d6dChristopher Ferris size_t *count = static_cast<size_t *>(cookie); 76f04935c85e0b466f0d30d2cd4c0fa2fff62e7d6dChristopher Ferris 77f04935c85e0b466f0d30d2cd4c0fa2fff62e7d6dChristopher Ferris ASSERT_NE((prop_info *)NULL, pi); 78f04935c85e0b466f0d30d2cd4c0fa2fff62e7d6dChristopher Ferris (*count)++; 79f04935c85e0b466f0d30d2cd4c0fa2fff62e7d6dChristopher Ferris} 80f04935c85e0b466f0d30d2cd4c0fa2fff62e7d6dChristopher Ferris 81f04935c85e0b466f0d30d2cd4c0fa2fff62e7d6dChristopher Ferrisstatic void hierarchical_test_callback(const prop_info *pi, void *cookie) { 82f04935c85e0b466f0d30d2cd4c0fa2fff62e7d6dChristopher Ferris bool (*ok)[8][8] = static_cast<bool (*)[8][8]>(cookie); 83f04935c85e0b466f0d30d2cd4c0fa2fff62e7d6dChristopher Ferris 84f04935c85e0b466f0d30d2cd4c0fa2fff62e7d6dChristopher Ferris char name[PROP_NAME_MAX]; 85f04935c85e0b466f0d30d2cd4c0fa2fff62e7d6dChristopher Ferris char value[PROP_VALUE_MAX]; 86f04935c85e0b466f0d30d2cd4c0fa2fff62e7d6dChristopher Ferris 87f04935c85e0b466f0d30d2cd4c0fa2fff62e7d6dChristopher Ferris __system_property_read(pi, name, value); 88f04935c85e0b466f0d30d2cd4c0fa2fff62e7d6dChristopher Ferris 89f04935c85e0b466f0d30d2cd4c0fa2fff62e7d6dChristopher Ferris int name_i, name_j, name_k; 90f04935c85e0b466f0d30d2cd4c0fa2fff62e7d6dChristopher Ferris int value_i, value_j, value_k; 91f04935c85e0b466f0d30d2cd4c0fa2fff62e7d6dChristopher Ferris ASSERT_EQ(3, sscanf(name, "property_%d.%d.%d", &name_i, &name_j, &name_k)); 92f04935c85e0b466f0d30d2cd4c0fa2fff62e7d6dChristopher Ferris ASSERT_EQ(3, sscanf(value, "value_%d.%d.%d", &value_i, &value_j, &value_k)); 93f04935c85e0b466f0d30d2cd4c0fa2fff62e7d6dChristopher Ferris ASSERT_EQ(name_i, value_i); 94f04935c85e0b466f0d30d2cd4c0fa2fff62e7d6dChristopher Ferris ASSERT_GE(name_i, 0); 95f04935c85e0b466f0d30d2cd4c0fa2fff62e7d6dChristopher Ferris ASSERT_LT(name_i, 8); 96f04935c85e0b466f0d30d2cd4c0fa2fff62e7d6dChristopher Ferris ASSERT_EQ(name_j, value_j); 97f04935c85e0b466f0d30d2cd4c0fa2fff62e7d6dChristopher Ferris ASSERT_GE(name_j, 0); 98f04935c85e0b466f0d30d2cd4c0fa2fff62e7d6dChristopher Ferris ASSERT_LT(name_j, 8); 99f04935c85e0b466f0d30d2cd4c0fa2fff62e7d6dChristopher Ferris ASSERT_EQ(name_k, value_k); 100f04935c85e0b466f0d30d2cd4c0fa2fff62e7d6dChristopher Ferris ASSERT_GE(name_k, 0); 101f04935c85e0b466f0d30d2cd4c0fa2fff62e7d6dChristopher Ferris ASSERT_LT(name_k, 8); 102f04935c85e0b466f0d30d2cd4c0fa2fff62e7d6dChristopher Ferris 103f04935c85e0b466f0d30d2cd4c0fa2fff62e7d6dChristopher Ferris ok[name_i][name_j][name_k] = true; 104f04935c85e0b466f0d30d2cd4c0fa2fff62e7d6dChristopher Ferris} 105f04935c85e0b466f0d30d2cd4c0fa2fff62e7d6dChristopher Ferris 106f04935c85e0b466f0d30d2cd4c0fa2fff62e7d6dChristopher Ferrisstatic void *PropertyWaitHelperFn(void *arg) { 107f04935c85e0b466f0d30d2cd4c0fa2fff62e7d6dChristopher Ferris int *flag = (int *)arg; 108f04935c85e0b466f0d30d2cd4c0fa2fff62e7d6dChristopher Ferris prop_info *pi; 109f04935c85e0b466f0d30d2cd4c0fa2fff62e7d6dChristopher Ferris pi = (prop_info *)__system_property_find("property"); 110f04935c85e0b466f0d30d2cd4c0fa2fff62e7d6dChristopher Ferris usleep(100000); 111f04935c85e0b466f0d30d2cd4c0fa2fff62e7d6dChristopher Ferris 112f04935c85e0b466f0d30d2cd4c0fa2fff62e7d6dChristopher Ferris *flag = 1; 113f04935c85e0b466f0d30d2cd4c0fa2fff62e7d6dChristopher Ferris __system_property_update(pi, "value3", 6); 114f04935c85e0b466f0d30d2cd4c0fa2fff62e7d6dChristopher Ferris 115f04935c85e0b466f0d30d2cd4c0fa2fff62e7d6dChristopher Ferris return NULL; 116f04935c85e0b466f0d30d2cd4c0fa2fff62e7d6dChristopher Ferris} 117f04935c85e0b466f0d30d2cd4c0fa2fff62e7d6dChristopher Ferris 118f04935c85e0b466f0d30d2cd4c0fa2fff62e7d6dChristopher Ferris#endif // __BIONIC__ 119f04935c85e0b466f0d30d2cd4c0fa2fff62e7d6dChristopher Ferris 120b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin CrossTEST(properties, add) { 121f04935c85e0b466f0d30d2cd4c0fa2fff62e7d6dChristopher Ferris#if defined(__BIONIC__) 122b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross LocalPropertyTestState pa; 123cb215a7e9ecec9feb5aae9d9a5b1c89f392208e7Greg Hackmann ASSERT_TRUE(pa.valid); 124b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross 125b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross char propvalue[PROP_VALUE_MAX]; 126b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross 127b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_EQ(0, __system_property_add("property", 8, "value1", 6)); 128b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_EQ(0, __system_property_add("other_property", 14, "value2", 6)); 129b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_EQ(0, __system_property_add("property_other", 14, "value3", 6)); 130b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross 131b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_EQ(6, __system_property_get("property", propvalue)); 132b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_STREQ(propvalue, "value1"); 133b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross 134b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_EQ(6, __system_property_get("other_property", propvalue)); 135b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_STREQ(propvalue, "value2"); 136b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross 137b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_EQ(6, __system_property_get("property_other", propvalue)); 138b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_STREQ(propvalue, "value3"); 139f04935c85e0b466f0d30d2cd4c0fa2fff62e7d6dChristopher Ferris#else // __BIONIC__ 140f04935c85e0b466f0d30d2cd4c0fa2fff62e7d6dChristopher Ferris GTEST_LOG_(INFO) << "This test does nothing.\n"; 141f04935c85e0b466f0d30d2cd4c0fa2fff62e7d6dChristopher Ferris#endif // __BIONIC__ 142b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross} 143b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross 144b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin CrossTEST(properties, update) { 145f04935c85e0b466f0d30d2cd4c0fa2fff62e7d6dChristopher Ferris#if defined(__BIONIC__) 146b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross LocalPropertyTestState pa; 147cb215a7e9ecec9feb5aae9d9a5b1c89f392208e7Greg Hackmann ASSERT_TRUE(pa.valid); 148b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross 149b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross char propvalue[PROP_VALUE_MAX]; 150b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross prop_info *pi; 151b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross 152b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_EQ(0, __system_property_add("property", 8, "oldvalue1", 9)); 153b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_EQ(0, __system_property_add("other_property", 14, "value2", 6)); 154b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_EQ(0, __system_property_add("property_other", 14, "value3", 6)); 155b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross 156b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross pi = (prop_info *)__system_property_find("property"); 157b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_NE((prop_info *)NULL, pi); 158b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross __system_property_update(pi, "value4", 6); 159b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross 160b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross pi = (prop_info *)__system_property_find("other_property"); 161b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_NE((prop_info *)NULL, pi); 162b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross __system_property_update(pi, "newvalue5", 9); 163b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross 164b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross pi = (prop_info *)__system_property_find("property_other"); 165b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_NE((prop_info *)NULL, pi); 166b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross __system_property_update(pi, "value6", 6); 167b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross 168b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_EQ(6, __system_property_get("property", propvalue)); 169b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_STREQ(propvalue, "value4"); 170b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross 171b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_EQ(9, __system_property_get("other_property", propvalue)); 172b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_STREQ(propvalue, "newvalue5"); 173b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross 174b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_EQ(6, __system_property_get("property_other", propvalue)); 175b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_STREQ(propvalue, "value6"); 176f04935c85e0b466f0d30d2cd4c0fa2fff62e7d6dChristopher Ferris#else // __BIONIC__ 177f04935c85e0b466f0d30d2cd4c0fa2fff62e7d6dChristopher Ferris GTEST_LOG_(INFO) << "This test does nothing.\n"; 178f04935c85e0b466f0d30d2cd4c0fa2fff62e7d6dChristopher Ferris#endif // __BIONIC__ 179b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross} 180b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross 181cb215a7e9ecec9feb5aae9d9a5b1c89f392208e7Greg HackmannTEST(properties, fill) { 182f04935c85e0b466f0d30d2cd4c0fa2fff62e7d6dChristopher Ferris#if defined(__BIONIC__) 183b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross LocalPropertyTestState pa; 184cb215a7e9ecec9feb5aae9d9a5b1c89f392208e7Greg Hackmann ASSERT_TRUE(pa.valid); 185b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross char prop_name[PROP_NAME_MAX]; 186b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross char prop_value[PROP_VALUE_MAX]; 187b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross char prop_value_ret[PROP_VALUE_MAX]; 188cb215a7e9ecec9feb5aae9d9a5b1c89f392208e7Greg Hackmann int count = 0; 189b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross int ret; 190b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross 191cb215a7e9ecec9feb5aae9d9a5b1c89f392208e7Greg Hackmann while (true) { 192cb215a7e9ecec9feb5aae9d9a5b1c89f392208e7Greg Hackmann ret = snprintf(prop_name, PROP_NAME_MAX - 1, "property_%d", count); 193b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross memset(prop_name + ret, 'a', PROP_NAME_MAX - 1 - ret); 194cb215a7e9ecec9feb5aae9d9a5b1c89f392208e7Greg Hackmann ret = snprintf(prop_value, PROP_VALUE_MAX - 1, "value_%d", count); 195b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross memset(prop_value + ret, 'b', PROP_VALUE_MAX - 1 - ret); 196b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross prop_name[PROP_NAME_MAX - 1] = 0; 197b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross prop_value[PROP_VALUE_MAX - 1] = 0; 198b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross 199cb215a7e9ecec9feb5aae9d9a5b1c89f392208e7Greg Hackmann ret = __system_property_add(prop_name, PROP_NAME_MAX - 1, prop_value, PROP_VALUE_MAX - 1); 200cb215a7e9ecec9feb5aae9d9a5b1c89f392208e7Greg Hackmann if (ret < 0) 201cb215a7e9ecec9feb5aae9d9a5b1c89f392208e7Greg Hackmann break; 202cb215a7e9ecec9feb5aae9d9a5b1c89f392208e7Greg Hackmann 203cb215a7e9ecec9feb5aae9d9a5b1c89f392208e7Greg Hackmann count++; 204b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross } 205b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross 206cb215a7e9ecec9feb5aae9d9a5b1c89f392208e7Greg Hackmann // For historical reasons at least 247 properties must be supported 207cb215a7e9ecec9feb5aae9d9a5b1c89f392208e7Greg Hackmann ASSERT_GE(count, 247); 208cb215a7e9ecec9feb5aae9d9a5b1c89f392208e7Greg Hackmann 209cb215a7e9ecec9feb5aae9d9a5b1c89f392208e7Greg Hackmann for (int i = 0; i < count; i++) { 210b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ret = snprintf(prop_name, PROP_NAME_MAX - 1, "property_%d", i); 211b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross memset(prop_name + ret, 'a', PROP_NAME_MAX - 1 - ret); 212b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ret = snprintf(prop_value, PROP_VALUE_MAX - 1, "value_%d", i); 213b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross memset(prop_value + ret, 'b', PROP_VALUE_MAX - 1 - ret); 214b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross prop_name[PROP_NAME_MAX - 1] = 0; 215b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross prop_value[PROP_VALUE_MAX - 1] = 0; 216b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross memset(prop_value_ret, '\0', PROP_VALUE_MAX); 217b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross 218b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_EQ(PROP_VALUE_MAX - 1, __system_property_get(prop_name, prop_value_ret)); 219b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_EQ(0, memcmp(prop_value, prop_value_ret, PROP_VALUE_MAX)); 220b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross } 221f04935c85e0b466f0d30d2cd4c0fa2fff62e7d6dChristopher Ferris#else // __BIONIC__ 222f04935c85e0b466f0d30d2cd4c0fa2fff62e7d6dChristopher Ferris GTEST_LOG_(INFO) << "This test does nothing.\n"; 223f04935c85e0b466f0d30d2cd4c0fa2fff62e7d6dChristopher Ferris#endif // __BIONIC__ 224c6ff844d75dddfb19fc804b8add2d6a79947b101Greg Hackmann} 225c6ff844d75dddfb19fc804b8add2d6a79947b101Greg Hackmann 226c6ff844d75dddfb19fc804b8add2d6a79947b101Greg HackmannTEST(properties, foreach) { 227f04935c85e0b466f0d30d2cd4c0fa2fff62e7d6dChristopher Ferris#if defined(__BIONIC__) 228c6ff844d75dddfb19fc804b8add2d6a79947b101Greg Hackmann LocalPropertyTestState pa; 229cb215a7e9ecec9feb5aae9d9a5b1c89f392208e7Greg Hackmann ASSERT_TRUE(pa.valid); 230c6ff844d75dddfb19fc804b8add2d6a79947b101Greg Hackmann size_t count = 0; 231c6ff844d75dddfb19fc804b8add2d6a79947b101Greg Hackmann 232c6ff844d75dddfb19fc804b8add2d6a79947b101Greg Hackmann ASSERT_EQ(0, __system_property_add("property", 8, "value1", 6)); 233c6ff844d75dddfb19fc804b8add2d6a79947b101Greg Hackmann ASSERT_EQ(0, __system_property_add("other_property", 14, "value2", 6)); 234c6ff844d75dddfb19fc804b8add2d6a79947b101Greg Hackmann ASSERT_EQ(0, __system_property_add("property_other", 14, "value3", 6)); 235c6ff844d75dddfb19fc804b8add2d6a79947b101Greg Hackmann 236c6ff844d75dddfb19fc804b8add2d6a79947b101Greg Hackmann ASSERT_EQ(0, __system_property_foreach(foreach_test_callback, &count)); 237c6ff844d75dddfb19fc804b8add2d6a79947b101Greg Hackmann ASSERT_EQ(3U, count); 238f04935c85e0b466f0d30d2cd4c0fa2fff62e7d6dChristopher Ferris#else // __BIONIC__ 239f04935c85e0b466f0d30d2cd4c0fa2fff62e7d6dChristopher Ferris GTEST_LOG_(INFO) << "This test does nothing.\n"; 240f04935c85e0b466f0d30d2cd4c0fa2fff62e7d6dChristopher Ferris#endif // __BIONIC__ 241c6ff844d75dddfb19fc804b8add2d6a79947b101Greg Hackmann} 242c6ff844d75dddfb19fc804b8add2d6a79947b101Greg Hackmann 243b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin CrossTEST(properties, find_nth) { 244f04935c85e0b466f0d30d2cd4c0fa2fff62e7d6dChristopher Ferris#if defined(__BIONIC__) 245b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross LocalPropertyTestState pa; 246cb215a7e9ecec9feb5aae9d9a5b1c89f392208e7Greg Hackmann ASSERT_TRUE(pa.valid); 247b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross 248b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_EQ(0, __system_property_add("property", 8, "value1", 6)); 249b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_EQ(0, __system_property_add("other_property", 14, "value2", 6)); 250b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_EQ(0, __system_property_add("property_other", 14, "value3", 6)); 251b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross 252b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_NE((const prop_info *)NULL, __system_property_find_nth(0)); 253b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_NE((const prop_info *)NULL, __system_property_find_nth(1)); 254b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_NE((const prop_info *)NULL, __system_property_find_nth(2)); 255b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross 256b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_EQ((const prop_info *)NULL, __system_property_find_nth(3)); 257b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_EQ((const prop_info *)NULL, __system_property_find_nth(4)); 258b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_EQ((const prop_info *)NULL, __system_property_find_nth(5)); 259b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_EQ((const prop_info *)NULL, __system_property_find_nth(100)); 260b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_EQ((const prop_info *)NULL, __system_property_find_nth(200)); 261b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_EQ((const prop_info *)NULL, __system_property_find_nth(247)); 262f04935c85e0b466f0d30d2cd4c0fa2fff62e7d6dChristopher Ferris#else // __BIONIC__ 263f04935c85e0b466f0d30d2cd4c0fa2fff62e7d6dChristopher Ferris GTEST_LOG_(INFO) << "This test does nothing.\n"; 264f04935c85e0b466f0d30d2cd4c0fa2fff62e7d6dChristopher Ferris#endif // __BIONIC__ 265d5276422ca9f1f4d45e91c189a1655521e91962dGreg Hackmann} 266d5276422ca9f1f4d45e91c189a1655521e91962dGreg Hackmann 267d5276422ca9f1f4d45e91c189a1655521e91962dGreg HackmannTEST(properties, fill_hierarchical) { 268f04935c85e0b466f0d30d2cd4c0fa2fff62e7d6dChristopher Ferris#if defined(__BIONIC__) 269d5276422ca9f1f4d45e91c189a1655521e91962dGreg Hackmann LocalPropertyTestState pa; 270d5276422ca9f1f4d45e91c189a1655521e91962dGreg Hackmann ASSERT_TRUE(pa.valid); 271d5276422ca9f1f4d45e91c189a1655521e91962dGreg Hackmann char prop_name[PROP_NAME_MAX]; 272d5276422ca9f1f4d45e91c189a1655521e91962dGreg Hackmann char prop_value[PROP_VALUE_MAX]; 273d5276422ca9f1f4d45e91c189a1655521e91962dGreg Hackmann char prop_value_ret[PROP_VALUE_MAX]; 274d5276422ca9f1f4d45e91c189a1655521e91962dGreg Hackmann int ret; 275d5276422ca9f1f4d45e91c189a1655521e91962dGreg Hackmann 276d5276422ca9f1f4d45e91c189a1655521e91962dGreg Hackmann for (int i = 0; i < 8; i++) { 277d5276422ca9f1f4d45e91c189a1655521e91962dGreg Hackmann for (int j = 0; j < 8; j++) { 278d5276422ca9f1f4d45e91c189a1655521e91962dGreg Hackmann for (int k = 0; k < 8; k++) { 279d5276422ca9f1f4d45e91c189a1655521e91962dGreg Hackmann ret = snprintf(prop_name, PROP_NAME_MAX - 1, "property_%d.%d.%d", i, j, k); 280d5276422ca9f1f4d45e91c189a1655521e91962dGreg Hackmann memset(prop_name + ret, 'a', PROP_NAME_MAX - 1 - ret); 281d5276422ca9f1f4d45e91c189a1655521e91962dGreg Hackmann ret = snprintf(prop_value, PROP_VALUE_MAX - 1, "value_%d.%d.%d", i, j, k); 282d5276422ca9f1f4d45e91c189a1655521e91962dGreg Hackmann memset(prop_value + ret, 'b', PROP_VALUE_MAX - 1 - ret); 283d5276422ca9f1f4d45e91c189a1655521e91962dGreg Hackmann prop_name[PROP_NAME_MAX - 1] = 0; 284d5276422ca9f1f4d45e91c189a1655521e91962dGreg Hackmann prop_value[PROP_VALUE_MAX - 1] = 0; 285d5276422ca9f1f4d45e91c189a1655521e91962dGreg Hackmann 286d5276422ca9f1f4d45e91c189a1655521e91962dGreg Hackmann ASSERT_EQ(0, __system_property_add(prop_name, PROP_NAME_MAX - 1, prop_value, PROP_VALUE_MAX - 1)); 287d5276422ca9f1f4d45e91c189a1655521e91962dGreg Hackmann } 288d5276422ca9f1f4d45e91c189a1655521e91962dGreg Hackmann } 289d5276422ca9f1f4d45e91c189a1655521e91962dGreg Hackmann } 290d5276422ca9f1f4d45e91c189a1655521e91962dGreg Hackmann 291d5276422ca9f1f4d45e91c189a1655521e91962dGreg Hackmann for (int i = 0; i < 8; i++) { 292d5276422ca9f1f4d45e91c189a1655521e91962dGreg Hackmann for (int j = 0; j < 8; j++) { 293d5276422ca9f1f4d45e91c189a1655521e91962dGreg Hackmann for (int k = 0; k < 8; k++) { 294d5276422ca9f1f4d45e91c189a1655521e91962dGreg Hackmann ret = snprintf(prop_name, PROP_NAME_MAX - 1, "property_%d.%d.%d", i, j, k); 295d5276422ca9f1f4d45e91c189a1655521e91962dGreg Hackmann memset(prop_name + ret, 'a', PROP_NAME_MAX - 1 - ret); 296d5276422ca9f1f4d45e91c189a1655521e91962dGreg Hackmann ret = snprintf(prop_value, PROP_VALUE_MAX - 1, "value_%d.%d.%d", i, j, k); 297d5276422ca9f1f4d45e91c189a1655521e91962dGreg Hackmann memset(prop_value + ret, 'b', PROP_VALUE_MAX - 1 - ret); 298d5276422ca9f1f4d45e91c189a1655521e91962dGreg Hackmann prop_name[PROP_NAME_MAX - 1] = 0; 299d5276422ca9f1f4d45e91c189a1655521e91962dGreg Hackmann prop_value[PROP_VALUE_MAX - 1] = 0; 300d5276422ca9f1f4d45e91c189a1655521e91962dGreg Hackmann memset(prop_value_ret, '\0', PROP_VALUE_MAX); 301d5276422ca9f1f4d45e91c189a1655521e91962dGreg Hackmann 302d5276422ca9f1f4d45e91c189a1655521e91962dGreg Hackmann ASSERT_EQ(PROP_VALUE_MAX - 1, __system_property_get(prop_name, prop_value_ret)); 303d5276422ca9f1f4d45e91c189a1655521e91962dGreg Hackmann ASSERT_EQ(0, memcmp(prop_value, prop_value_ret, PROP_VALUE_MAX)); 304d5276422ca9f1f4d45e91c189a1655521e91962dGreg Hackmann } 305d5276422ca9f1f4d45e91c189a1655521e91962dGreg Hackmann } 306d5276422ca9f1f4d45e91c189a1655521e91962dGreg Hackmann } 307d5276422ca9f1f4d45e91c189a1655521e91962dGreg Hackmann 308d5276422ca9f1f4d45e91c189a1655521e91962dGreg Hackmann bool ok[8][8][8]; 309d5276422ca9f1f4d45e91c189a1655521e91962dGreg Hackmann memset(ok, 0, sizeof(ok)); 310d5276422ca9f1f4d45e91c189a1655521e91962dGreg Hackmann __system_property_foreach(hierarchical_test_callback, ok); 311d5276422ca9f1f4d45e91c189a1655521e91962dGreg Hackmann 312d5276422ca9f1f4d45e91c189a1655521e91962dGreg Hackmann for (int i = 0; i < 8; i++) { 313d5276422ca9f1f4d45e91c189a1655521e91962dGreg Hackmann for (int j = 0; j < 8; j++) { 314d5276422ca9f1f4d45e91c189a1655521e91962dGreg Hackmann for (int k = 0; k < 8; k++) { 315d5276422ca9f1f4d45e91c189a1655521e91962dGreg Hackmann ASSERT_TRUE(ok[i][j][k]); 316d5276422ca9f1f4d45e91c189a1655521e91962dGreg Hackmann } 317d5276422ca9f1f4d45e91c189a1655521e91962dGreg Hackmann } 318d5276422ca9f1f4d45e91c189a1655521e91962dGreg Hackmann } 319f04935c85e0b466f0d30d2cd4c0fa2fff62e7d6dChristopher Ferris#else // __BIONIC__ 320f04935c85e0b466f0d30d2cd4c0fa2fff62e7d6dChristopher Ferris GTEST_LOG_(INFO) << "This test does nothing.\n"; 321f04935c85e0b466f0d30d2cd4c0fa2fff62e7d6dChristopher Ferris#endif // __BIONIC__ 322d5276422ca9f1f4d45e91c189a1655521e91962dGreg Hackmann} 323d5276422ca9f1f4d45e91c189a1655521e91962dGreg Hackmann 324b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin CrossTEST(properties, errors) { 325f04935c85e0b466f0d30d2cd4c0fa2fff62e7d6dChristopher Ferris#if defined(__BIONIC__) 326b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross LocalPropertyTestState pa; 327cb215a7e9ecec9feb5aae9d9a5b1c89f392208e7Greg Hackmann ASSERT_TRUE(pa.valid); 328b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross char prop_value[PROP_NAME_MAX]; 329b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross 330b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_EQ(0, __system_property_add("property", 8, "value1", 6)); 331b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_EQ(0, __system_property_add("other_property", 14, "value2", 6)); 332b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_EQ(0, __system_property_add("property_other", 14, "value3", 6)); 333b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross 334b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_EQ(0, __system_property_find("property1")); 335b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_EQ(0, __system_property_get("property1", prop_value)); 336b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross 337b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_EQ(-1, __system_property_add("name", PROP_NAME_MAX, "value", 5)); 338b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_EQ(-1, __system_property_add("name", 4, "value", PROP_VALUE_MAX)); 339b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_EQ(-1, __system_property_update(NULL, "value", PROP_VALUE_MAX)); 340f04935c85e0b466f0d30d2cd4c0fa2fff62e7d6dChristopher Ferris#else // __BIONIC__ 341f04935c85e0b466f0d30d2cd4c0fa2fff62e7d6dChristopher Ferris GTEST_LOG_(INFO) << "This test does nothing.\n"; 342f04935c85e0b466f0d30d2cd4c0fa2fff62e7d6dChristopher Ferris#endif // __BIONIC__ 343b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross} 344b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross 345b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin CrossTEST(properties, serial) { 346f04935c85e0b466f0d30d2cd4c0fa2fff62e7d6dChristopher Ferris#if defined(__BIONIC__) 347b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross LocalPropertyTestState pa; 348cb215a7e9ecec9feb5aae9d9a5b1c89f392208e7Greg Hackmann ASSERT_TRUE(pa.valid); 349b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross const prop_info *pi; 350b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross unsigned int serial; 351b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross 352b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_EQ(0, __system_property_add("property", 8, "value1", 6)); 353b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_NE((const prop_info *)NULL, pi = __system_property_find("property")); 354b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross serial = __system_property_serial(pi); 355b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_EQ(0, __system_property_update((prop_info *)pi, "value2", 6)); 356b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_NE(serial, __system_property_serial(pi)); 357f04935c85e0b466f0d30d2cd4c0fa2fff62e7d6dChristopher Ferris#else // __BIONIC__ 358f04935c85e0b466f0d30d2cd4c0fa2fff62e7d6dChristopher Ferris GTEST_LOG_(INFO) << "This test does nothing.\n"; 359f04935c85e0b466f0d30d2cd4c0fa2fff62e7d6dChristopher Ferris#endif // __BIONIC__ 360b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross} 361b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross 362b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin CrossTEST(properties, wait) { 363f04935c85e0b466f0d30d2cd4c0fa2fff62e7d6dChristopher Ferris#if defined(__BIONIC__) 364b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross LocalPropertyTestState pa; 365cb215a7e9ecec9feb5aae9d9a5b1c89f392208e7Greg Hackmann ASSERT_TRUE(pa.valid); 366b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross unsigned int serial; 367b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross prop_info *pi; 368b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross pthread_t t; 369b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross int flag = 0; 370b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross 371b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_EQ(0, __system_property_add("property", 8, "value1", 6)); 372b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross serial = __system_property_wait_any(0); 373b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross pi = (prop_info *)__system_property_find("property"); 374b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_NE((prop_info *)NULL, pi); 375b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross __system_property_update(pi, "value2", 6); 376b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross serial = __system_property_wait_any(serial); 377b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross 378b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_EQ(0, pthread_create(&t, NULL, PropertyWaitHelperFn, &flag)); 379b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_EQ(flag, 0); 380b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross serial = __system_property_wait_any(serial); 381b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_EQ(flag, 1); 382b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross 383b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross void* result; 384b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross ASSERT_EQ(0, pthread_join(t, &result)); 385f04935c85e0b466f0d30d2cd4c0fa2fff62e7d6dChristopher Ferris#else // __BIONIC__ 386f04935c85e0b466f0d30d2cd4c0fa2fff62e7d6dChristopher Ferris GTEST_LOG_(INFO) << "This test does nothing.\n"; 387f04935c85e0b466f0d30d2cd4c0fa2fff62e7d6dChristopher Ferris#endif // __BIONIC__ 388b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross} 389b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross 390b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Crossclass KilledByFault { 391b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross public: 392b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross explicit KilledByFault() {}; 393b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross bool operator()(int exit_status) const; 394b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross}; 395b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross 396b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Crossbool KilledByFault::operator()(int exit_status) const { 397b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross return WIFSIGNALED(exit_status) && 398b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross (WTERMSIG(exit_status) == SIGSEGV || 399b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross WTERMSIG(exit_status) == SIGBUS || 400b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross WTERMSIG(exit_status) == SIGABRT); 401b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross} 402b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross 4039df70403d95f5cfe6824e38a9a6c35f9b9bbc76aYabin Cuiclass properties_DeathTest : public BionicDeathTest {}; 4049df70403d95f5cfe6824e38a9a6c35f9b9bbc76aYabin Cui 4059df70403d95f5cfe6824e38a9a6c35f9b9bbc76aYabin CuiTEST_F(properties_DeathTest, read_only) { 406f04935c85e0b466f0d30d2cd4c0fa2fff62e7d6dChristopher Ferris#if defined(__BIONIC__) 407e4375196d650f68ad486e2202699c98f9342d616Elliott Hughes 408e4375196d650f68ad486e2202699c98f9342d616Elliott Hughes // This test only makes sense if we're talking to the real system property service. 409e4375196d650f68ad486e2202699c98f9342d616Elliott Hughes struct stat sb; 410e4375196d650f68ad486e2202699c98f9342d616Elliott Hughes if (stat(PROP_FILENAME, &sb) == -1 && errno == ENOENT) { 411e4375196d650f68ad486e2202699c98f9342d616Elliott Hughes return; 412e4375196d650f68ad486e2202699c98f9342d616Elliott Hughes } 413e4375196d650f68ad486e2202699c98f9342d616Elliott Hughes 414e4375196d650f68ad486e2202699c98f9342d616Elliott Hughes ASSERT_EXIT(__system_property_add("property", 8, "value", 5), KilledByFault(), ""); 415f04935c85e0b466f0d30d2cd4c0fa2fff62e7d6dChristopher Ferris#else // __BIONIC__ 416f04935c85e0b466f0d30d2cd4c0fa2fff62e7d6dChristopher Ferris GTEST_LOG_(INFO) << "This test does nothing.\n"; 417f04935c85e0b466f0d30d2cd4c0fa2fff62e7d6dChristopher Ferris#endif // __BIONIC__ 418b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross} 419