Android 4.3_r2 CTS com.android.cts.aadb.TestDeviceFuncTest#testSyncFiles_normal FAIL

1.4k views Asked by At

com.android.cts.aadb.TestDeviceFuncTest#testSyncFiles_normal FAIL

junit.framework.AssertionFailedError
at junit.framework.Assert.fail(Assert.java:48)
at junit.framework.Assert.assertTrue(Assert.java:20)
at junit.framework.Assert.assertTrue(Assert.java:27)
at com.android.cts.aadb.TestDeviceFuncTest.doTestSyncFiles(TestDeviceFuncTest.java:290)
at com.android.cts.aadb.TestDeviceFuncTest.testSyncFiles_normal(TestDeviceFuncTest.java:234)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)

Source code:

[http://androidxref.com/4.3_r2.1/xref/cts/hostsidetests/aadb/src/com/android/cts/aadb/TestDeviceFuncTest.java][1]

Base on my debug, content of tempFile doesn't synced to device, although return value of syncFiles is true.

http://source.android.com/reference/com/android/tradefed/device/ITestDevice.html#syncFiles(java.io.File, java.lang.String)

Any body could give me some advise? Thanks very much.

1

There are 1 answers

0
Jacob Stevens On

Yep, this is an active, unresolved defect with CTS 4.3 r2, r3, and 4.4. It's a flaky test that uses a 10-minute timestamp modification to trigger the expected file sync (see below). If phone & host time zone settings aren't the same, this will fail. You should be able to circumvent by setting your phone to match your host's GMT time zone.

/**
 * Test syncing a single file using {@link TestDevice#syncFiles(File, String)}.
 */
public void doTestSyncFiles(String externalStorePath) throws Exception {
    String expectedDeviceFilePath = null;

    // create temp dir with one temp file
    File tmpDir = FileUtil.createTempDir("tmp");
    try {
        File tmpFile = createTempTestFile(tmpDir);
        // set last modified to 10 minutes ago
        tmpFile.setLastModified(System.currentTimeMillis() - 10*60*1000);
        assertNotNull(externalStorePath);
        expectedDeviceFilePath = String.format("%s/%s/%s", externalStorePath,
                tmpDir.getName(), tmpFile.getName());

        assertTrue(mTestDevice.syncFiles(tmpDir, externalStorePath));
        assertTrue(mTestDevice.doesFileExist(expectedDeviceFilePath));

        // get 'ls -l' attributes of file which includes timestamp
        String origTmpFileStamp = mTestDevice.executeShellCommand(String.format("ls -l %s",
                expectedDeviceFilePath));
        // now create another file and verify that is synced
        File tmpFile2 = createTempTestFile(tmpDir);
        tmpFile2.setLastModified(System.currentTimeMillis() - 10*60*1000);
        assertTrue(mTestDevice.syncFiles(tmpDir, externalStorePath));
        String expectedDeviceFilePath2 = String.format("%s/%s/%s", externalStorePath,
                tmpDir.getName(), tmpFile2.getName());
        assertTrue(mTestDevice.doesFileExist(expectedDeviceFilePath2));

        // verify 1st file timestamp did not change
        String unchangedTmpFileStamp = mTestDevice.executeShellCommand(String.format("ls -l %s",
                expectedDeviceFilePath));
        assertEquals(origTmpFileStamp, unchangedTmpFileStamp);

        // now modify 1st file and verify it does change remotely
        String testString = "blah";
        FileOutputStream stream = new FileOutputStream(tmpFile);
        stream.write(testString.getBytes());
        stream.close();

        assertTrue(mTestDevice.syncFiles(tmpDir, externalStorePath));
        String tmpFileContents = mTestDevice.executeShellCommand(String.format("cat %s",
                expectedDeviceFilePath));
        assertTrue(tmpFileContents.contains(testString));
    } finally {
        if (expectedDeviceFilePath != null && externalStorePath != null) {
            // note that expectedDeviceFilePath has externalStorePath prepended at definition
            mTestDevice.executeShellCommand(String.format("rm -r %s", expectedDeviceFilePath));
        }
        FileUtil.recursiveDelete(tmpDir);
    }
}