diff options
author | Elliott Hughes <enh@google.com> | 2013-10-21 17:09:52 -0700 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2013-10-21 17:40:15 -0700 |
commit | e4375196d650f68ad486e2202699c98f9342d616 (patch) | |
tree | 4e62b6b03aea5a78845c309a148642a81c72e367 /tests/system_properties_test.cpp | |
parent | f4ac8ba566d80679ccc346b3b0af4b46d394319b (diff) | |
download | android_bionic-e4375196d650f68ad486e2202699c98f9342d616.tar.gz android_bionic-e4375196d650f68ad486e2202699c98f9342d616.tar.bz2 android_bionic-e4375196d650f68ad486e2202699c98f9342d616.zip |
Fix the system property tests to use $ANDROID_DATA.
This lets them work on the host.
Change-Id: I771ccc67652ae37451b45859c7831116cd830086
Diffstat (limited to 'tests/system_properties_test.cpp')
-rw-r--r-- | tests/system_properties_test.cpp | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/tests/system_properties_test.cpp b/tests/system_properties_test.cpp index ba73c68c5..adc63d636 100644 --- a/tests/system_properties_test.cpp +++ b/tests/system_properties_test.cpp @@ -16,6 +16,7 @@ #include <gtest/gtest.h> #include <sys/wait.h> +#include <errno.h> #include <unistd.h> #include <string> @@ -28,10 +29,13 @@ extern void *__system_property_area__; struct LocalPropertyTestState { LocalPropertyTestState() : valid(false) { - char dir_template[] = "/data/local/tmp/prop-XXXXXX"; - char *dirname = mkdtemp(dir_template); + 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); if (!dirname) { - perror("making temp file for test state failed (is /data/local/tmp writable?)"); + fprintf(stderr, "making temp file for test state failed (is %s writable?): %s", + dir_template, strerror(errno)); return; } @@ -47,8 +51,9 @@ struct LocalPropertyTestState { } ~LocalPropertyTestState() { - if (!valid) + if (!valid) { return; + } __system_property_area__ = old_pa; @@ -279,8 +284,15 @@ bool KilledByFault::operator()(int exit_status) const { } TEST(properties_DeathTest, read_only) { - ::testing::FLAGS_gtest_death_test_style = "threadsafe"; - ASSERT_EXIT(__system_property_add("property", 8, "value", 5), - KilledByFault(), ""); + ::testing::FLAGS_gtest_death_test_style = "threadsafe"; + + // 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_EXIT(__system_property_add("property", 8, "value", 5), KilledByFault(), ""); } + #endif |