From b7ef7e7aff81893d327cbb14d2c803ac7c5e65e5 Mon Sep 17 00:00:00 2001 From: Tom Cherry Date: Tue, 20 Feb 2018 10:40:26 -0800 Subject: [PATCH] Fix intermittent crash in property_service_test There is a race in the very_long_name_35166374 test of property_service. The test first sends a size value that is beyond the limit that init will handle, then sends a dummy data value. However, init closes the socket upon seeing the faulty size, and if this happens before the test sends the dummy data, the test will crash due to SIGPIPE. Since there is no reason to send the dummy data at all, this change no longer sends it to prevent the crash. It also now checks explicitly that init returns an error through the socket. Bug: 73619375 Test: the unit test in question Change-Id: I2565a69fa54910cee0e15fc798445e18c91156ec --- init/property_service_test.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/init/property_service_test.cpp b/init/property_service_test.cpp index 95dd34084..c038aff40 100644 --- a/init/property_service_test.cpp +++ b/init/property_service_test.cpp @@ -45,11 +45,13 @@ TEST(property_service, very_long_name_35166374) { // ...so we can send it a malformed request. uint32_t msg = PROP_MSG_SETPROP2; uint32_t size = 0xffffffff; - uint32_t data = 0xdeadbeef; ASSERT_EQ(static_cast(sizeof(msg)), send(fd, &msg, sizeof(msg), 0)); ASSERT_EQ(static_cast(sizeof(size)), send(fd, &size, sizeof(size), 0)); - ASSERT_EQ(static_cast(sizeof(data)), send(fd, &data, sizeof(data), 0)); + uint32_t result = 0; + ASSERT_EQ(static_cast(sizeof(result)), + TEMP_FAILURE_RETRY(recv(fd, &result, sizeof(result), MSG_WAITALL))); + EXPECT_EQ(static_cast(PROP_ERROR_READ_DATA), result); ASSERT_EQ(0, close(fd)); }