Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3841a9f7 authored by Elliott Hughes's avatar Elliott Hughes
Browse files

Leave the evidence lying around if an adb test fails.

Not seeing the full output from the failed adb command is probably
the biggest issue when debugging a test failure, but this doesn't
help either.

Change-Id: Ic42cbced8be252185a799b27c210a744188a4201
parent 6bf93400
Loading
Loading
Loading
Loading
+64 −75
Original line number Diff line number Diff line
@@ -333,46 +333,38 @@ class FileOperationsTest(DeviceTest):

    def _test_push(self, local_file, checksum):
        self.device.shell(['rm', '-rf', self.DEVICE_TEMP_FILE])
        try:
            self.device.push(
                local=local_file, remote=self.DEVICE_TEMP_FILE)
            dev_md5, _ = self.device.shell(
                [get_md5_prog(self.device), self.DEVICE_TEMP_FILE]).split()
        self.device.push(local=local_file, remote=self.DEVICE_TEMP_FILE)
        dev_md5, _ = self.device.shell([get_md5_prog(self.device),
                                       self.DEVICE_TEMP_FILE]).split()
        self.assertEqual(checksum, dev_md5)
        finally:
        self.device.shell(['rm', '-f', self.DEVICE_TEMP_FILE])

    def test_push(self):
        """Push a randomly generated file to specified device."""
        kbytes = 512
        tmp = tempfile.NamedTemporaryFile(mode='wb', delete=False)
        try:
        rand_str = os.urandom(1024 * kbytes)
        tmp.write(rand_str)
        tmp.close()
        self._test_push(tmp.name, compute_md5(rand_str))
        finally:
        os.remove(tmp.name)

    # TODO: write push directory test.

    def _test_pull(self, remote_file, checksum):
        tmp_write = tempfile.NamedTemporaryFile(mode='wb', delete=False)
        try:
        tmp_write.close()
        self.device.pull(remote=remote_file, local=tmp_write.name)
        with open(tmp_write.name, 'rb') as tmp_read:
            host_contents = tmp_read.read()
            host_md5 = compute_md5(host_contents)
        self.assertEqual(checksum, host_md5)
        finally:
        os.remove(tmp_write.name)

    def test_pull(self):
        """Pull a randomly generated file from specified device."""
        kbytes = 512
        self.device.shell(['rm', '-rf', self.DEVICE_TEMP_FILE])
        try:
        cmd = ['dd', 'if=/dev/urandom',
               'of={}'.format(self.DEVICE_TEMP_FILE), 'bs=1024',
               'count={}'.format(kbytes)]
@@ -380,13 +372,11 @@ class FileOperationsTest(DeviceTest):
        dev_md5, _ = self.device.shell(
            [get_md5_prog(self.device), self.DEVICE_TEMP_FILE]).split()
        self._test_pull(self.DEVICE_TEMP_FILE, dev_md5)
        finally:
        self.device.shell_nocheck(['rm', self.DEVICE_TEMP_FILE])

    def test_pull_dir(self):
        """Pull a randomly generated directory of files from the device."""
        host_dir = tempfile.mkdtemp()
        try:
        self.device.shell(['rm', '-rf', self.DEVICE_TEMP_DIR])
        self.device.shell(['mkdir', '-p', self.DEVICE_TEMP_DIR])

@@ -401,7 +391,7 @@ class FileOperationsTest(DeviceTest):
            with open(host_path, 'rb') as host_file:
                host_md5 = compute_md5(host_file.read())
                self.assertEqual(host_md5, temp_file.checksum)
        finally:

        self.device.shell(['rm', '-rf', self.DEVICE_TEMP_DIR])
        if host_dir is not None:
            shutil.rmtree(host_dir)
@@ -409,14 +399,13 @@ class FileOperationsTest(DeviceTest):
    def test_sync(self):
        """Sync a randomly generated directory of files to specified device."""
        base_dir = tempfile.mkdtemp()
        try:

        # Create mirror device directory hierarchy within base_dir.
        full_dir_path = base_dir + self.DEVICE_TEMP_DIR
        os.makedirs(full_dir_path)

        # Create 32 random files within the host mirror.
            temp_files = make_random_host_files(in_dir=full_dir_path,
                                                num_files=32)
        temp_files = make_random_host_files(in_dir=full_dir_path, num_files=32)

        # Clean up any trash on the device.
        device = adb.get_device(product=base_dir)
@@ -426,12 +415,12 @@ class FileOperationsTest(DeviceTest):

        # Confirm that every file on the device mirrors that on the host.
        for temp_file in temp_files:
                device_full_path = posixpath.join(
                    self.DEVICE_TEMP_DIR, temp_file.base_name)
            device_full_path = posixpath.join(self.DEVICE_TEMP_DIR,
                                              temp_file.base_name)
            dev_md5, _ = device.shell(
                [get_md5_prog(self.device), device_full_path]).split()
            self.assertEqual(temp_file.checksum, dev_md5)
        finally:

        self.device.shell(['rm', '-rf', self.DEVICE_TEMP_DIR])
        shutil.rmtree(base_dir + self.DEVICE_TEMP_DIR)