From c3b27c2e63b4885b06bfa64c01c858544fef9a28 Mon Sep 17 00:00:00 2001 From: Christopher Dombroski Date: Fri, 6 Oct 2023 12:24:32 -0700 Subject: Clean up malloc debug properties Bug: 303635846 Test: atest com.android.sts.common.MallocDebugTest Change-Id: Ica2df3fe32e119b0a2c47e1e3ed9eb069ef0dd59 Merged-In: Ica2df3fe32e119b0a2c47e1e3ed9eb069ef0dd59 --- .../com/android/sts/common/MallocDebugTest.java | 38 +++++++++++++++++++--- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/libraries/sts-common-util/host-side/tests/src/com/android/sts/common/MallocDebugTest.java b/libraries/sts-common-util/host-side/tests/src/com/android/sts/common/MallocDebugTest.java index 8e16f1b06..97bac1bac 100644 --- a/libraries/sts-common-util/host-side/tests/src/com/android/sts/common/MallocDebugTest.java +++ b/libraries/sts-common-util/host-side/tests/src/com/android/sts/common/MallocDebugTest.java @@ -23,13 +23,17 @@ import static org.junit.Assert.assertTrue; import com.android.tradefed.testtype.DeviceJUnit4ClassRunner; import com.android.tradefed.testtype.junit4.BaseHostJUnit4Test; -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; + +import org.junit.After; +import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + /** Unit tests for {@link MallocDebug}. */ @RunWith(DeviceJUnit4ClassRunner.class) public class MallocDebugTest extends BaseHostJUnit4Test { @@ -66,6 +70,26 @@ public class MallocDebugTest extends BaseHostJUnit4Test { } } + @Before + public void setUp() throws Exception { + assertWithMessage("libc.debug.malloc.options not empty before test") + .that(getDevice().getProperty("libc.debug.malloc.options")) + .isNull(); + assertWithMessage("libc.debug.malloc.programs not empty before test") + .that(getDevice().getProperty("libc.debug.malloc.programs")) + .isNull(); + } + + @After + public void tearDown() throws Exception { + assertWithMessage("libc.debug.malloc.options not empty after test") + .that(getDevice().getProperty("libc.debug.malloc.options")) + .isNull(); + assertWithMessage("libc.debug.malloc.programs not empty after test") + .that(getDevice().getProperty("libc.debug.malloc.programs")) + .isNull(); + } + @Test(expected = Test.None.class /* no exception expected */) public void testMallocDebugNoErrors() throws Exception { MallocDebug.assertNoMallocDebugErrors(logcatWithoutErrors); @@ -115,7 +139,7 @@ public class MallocDebugTest extends BaseHostJUnit4Test { final String oldValue = "TEST_VALUE_OLD"; final String newValue = "TEST_VALUE_NEW"; assertTrue( - "could not set property", + "could not set libc.debug.malloc.options", getDevice().setProperty("libc.debug.malloc.options", oldValue)); assertWithMessage("test property was not properly set on device") .that(getDevice().getProperty("libc.debug.malloc.options")) @@ -126,8 +150,12 @@ public class MallocDebugTest extends BaseHostJUnit4Test { .that(getDevice().getProperty("libc.debug.malloc.options")) .isEqualTo(newValue); } + String afterValue = getDevice().getProperty("libc.debug.malloc.options"); + assertTrue( + "could not clear libc.debug.malloc.options", + getDevice().setProperty("libc.debug.malloc.options", "")); assertWithMessage("prior property was not restored after test") - .that(getDevice().getProperty("libc.debug.malloc.options")) + .that(afterValue) .isEqualTo(oldValue); } } -- cgit v1.2.3