From e4375196d650f68ad486e2202699c98f9342d616 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Mon, 21 Oct 2013 17:09:52 -0700 Subject: [PATCH] Fix the system property tests to use $ANDROID_DATA. This lets them work on the host. Change-Id: I771ccc67652ae37451b45859c7831116cd830086 --- tests/system_properties_test.cpp | 26 +++++++++++++++++++------- 1 file 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 #include +#include #include #include @@ -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