def create_config_files():
    global_temp = autotemp.tempfile("global", ".ini", text=True)
    os.write(global_temp.fd, global_config_ini_contents)

    shadow_temp = autotemp.tempfile("shadow", ".ini", text=True)
    fd = shadow_temp.fd
    os.write(shadow_temp.fd, shadow_config_ini_contents)

    return (global_temp, shadow_temp)
    def run_once(self, measurements=5, size=1, min_speed=300.0):
        """
        @param measurements: (int) the number of measurements to do.
                For the test to fail at least one measurement needs to be
                below |min_speed|
        @param size: (int) size of the file to be copied for testing the
                transfer rate, it represent the size in megabytes.
                Generally speaking, the bigger is the file used for
                |measurements| the slower the test will run and the more
                accurate it will be.
                e.g.: 10 is 10MB, 101 is 101MB
        @param min_speed: (float) in Mbit/sec. It's the min throughput a USB 3.0
                device should perform to be accepted. Conceptually it's the max
                USB 3.0 throughput minus a tollerance.
                Defaults to 300Mbit/sec (ie 350Mbits/sec minus ~15% tollerance)
        """
        volume_filter = {'bus': 'usb'}
        storage = self.wait_for_device(volume_filter,
                                       cycles=1,
                                       mount_volume=True)[0]

        # in Megabytes (power of 10, to be consistent with the throughput unit)
        size *= 1000 * 1000

        self._autosrc = autotemp.tempfile(unique_id='autotest.src',
                                          dir=storage['mountpoint'])
        self._autodst = autotemp.tempfile(unique_id='autotest.dst',
                                          dir=self.tmpdir)

        # Create random file
        storage_mod.create_file(self._autosrc.name, size)

        num_failures = 0
        for measurement in range(measurements):
            xfer_rate = get_xfer_rate(self._autosrc.name, self._autodst.name)
            key = 'Mbit_per_sec_measurement_%d' % measurement
            self.results[key] = xfer_rate
            logging.debug('xfer rate (measurement %d) %.2f (min=%.2f)',
                          measurement, xfer_rate, min_speed)

            if xfer_rate < min_speed:
                num_failures += 1

        # Apparently self.postprocess_iteration is not called on TestFail
        # so we need to process data here in order to have some performance log
        # even on TestFail
        self.results['Mbit_per_sec_average'] = (sum(self.results.values()) /
                                                len(self.results))
        self.write_perf_keyval(self.results)

        if num_failures > 0:
            msg = ('%d/%d measured transfer rates under performed '
                   '(min_speed=%.2fMbit/sec)' %
                   (num_failures, measurements, min_speed))
            raise error.TestFail(msg)
def create_config_files():
    global_temp = autotemp.tempfile("global", ".ini",
                                            text=True)
    os.write(global_temp.fd, global_config_ini_contents)

    shadow_temp = autotemp.tempfile("shadow", ".ini",
                                           text=True)
    fd = shadow_temp.fd
    os.write(shadow_temp.fd, shadow_config_ini_contents)

    return (global_temp, shadow_temp)
def create_config_files():
    """Create config files to be used for test."""
    global_temp = autotemp.tempfile("global", ".ini", text=True)
    os.write(global_temp.fd, global_config_ini_contents)

    moblab_temp = autotemp.tempfile("moblab", ".ini", text=True)
    os.write(moblab_temp.fd, moblab_config_ini_contents)

    shadow_temp = autotemp.tempfile("shadow", ".ini", text=True)
    os.write(shadow_temp.fd, shadow_config_ini_contents)

    return (global_temp, shadow_temp, moblab_temp)
 def test_clean(self):
     temp = autotemp.tempfile(unique_id="clean")
     # clean up sets name to None so we preserve it this way
     name = temp.name
     self.assertTrue(os.path.exists(name))
     temp.clean()
     self.assertFalse(os.path.exists(name))
 def test_clean(self):
     temp = autotemp.tempfile(unique_id='clean')
     # clean up sets name to None so we preserve it this way
     name = temp.name
     self.assertTrue(os.path.exists(name))
     temp.clean()
     self.assertFalse(os.path.exists(name))
Beispiel #7
0
    def run_once(self, volume_filter={'bus': 'usb'}):
        storage = self.wait_for_device(volume_filter,
                                       cycles=1,
                                       mount_volume=True)[0]
        mount_point = storage['mountpoint']

        # -> Megabytes
        size = 1 * 1024 * 1024

        self._src = autotemp.tempfile(unique_id='tmpfile', dir=mount_point)
        self._dst = autotemp.tempfile(unique_id='autotest', dir=self.tmpdir)
        # Step 1: check if file creation works
        try:
            storage_mod.create_file(self._src.name, size)
        except error.CmdError, e:
            msg = ('fatal error occurred during file creation: '
                   'basic file operation failed: %s' % e)
            raise error.TestFail(msg)
Beispiel #8
0
def create_file(content):
    """Create a temporary file for testing.

    @param content: string contents for file.

    @return: Instance of autotemp.tempfile with specified contents.
    """
    file_temp = autotemp.tempfile(unique_id='cli_mock', text=True)
    os.write(file_temp.fd, content)
    return file_temp
Beispiel #9
0
 def setUp(self):
     self.control_tmp = autotemp.tempfile(unique_id='control_unit',
                                          text=True)
     self.bug_template = {
         'owner': '*****@*****.**',
         'labels': ['a', 'b'],
         'status': None,
         'summary': None,
         'title': None,
         'cc': ['a@something, b@something'],
     }
    def prompt(self, banner=">>>>>>>>>>> Achtung! <<<<<<<<<<<"):
        """prompt the user with the supplied banner,
        then wait for them to press enter

        @param banner: A [possibly multi-line] banner prompt to display
        """
        temp = autotemp.tempfile(unique_id='vtprompt', text=True)
        os.write(temp.fd, banner)
        pcmd = ("sudo openvt -s -w -- " +
                "sh -c 'clear && cat %s && read -p \"READY> \" REPLY &&" +
                " echo $REPLY'") % temp.name
        utils.system(pcmd)
        temp.clean()
Beispiel #11
0
    def create(self):
        """Creates a zero-filled image file with the specified size.

        The created image file is temporary and removed when clean()
        is called.
        """
        self.clean()
        self._image_file = autotemp.tempfile(unique_id='fsImage')
        try:
            logging.debug('Creating zero-filled image file at "%s"',
                          self._image_file.name)
            utils.run(
                'dd if=/dev/zero of=%s bs=%s count=%s' %
                (self._image_file.name, self._block_size, self._block_count))
        except error.CmdError as exc:
            self._remove_image_file()
            message = 'Failed to create filesystem image: %s' % exc
            raise RuntimeError(message)
Beispiel #12
0
 def test_del(self):
     tmp_file = autotemp.tempfile(unique_id='del')
     name = tmp_file.name
     self.assertTrue(os.path.exists(name))
     tmp_file.__del__()
     self.assertFalse(os.path.exists(name))
Beispiel #13
0
 def test_create_file(self):
     temp = autotemp.tempfile(unique_id='file')
     self.assertTrue(os.path.exists(temp.name))
Beispiel #14
0
def create_file(content):
    file_temp = autotemp.tempfile(unique_id='cli_mock', text=True)
    os.write(file_temp.fd, content)
    return file_temp
Beispiel #15
0
 def setUp(self):
     self.control_tmp = autotemp.tempfile(unique_id='control_unit',
                                          text=True)
     os.write(self.control_tmp.fd, CONTROL)
 def test_del(self):
     tmp_file = autotemp.tempfile(unique_id="del")
     name = tmp_file.name
     self.assertTrue(os.path.exists(name))
     tmp_file.__del__()
     self.assertFalse(os.path.exists(name))
Beispiel #17
0
def create_file(content):
    file_temp = autotemp.tempfile(unique_id="cli_mock", text=True)
    os.write(file_temp.fd, content)
    os.close(file_temp.fd)
    return file_temp
 def test_create_file(self):
     temp = autotemp.tempfile(unique_id="file")
     self.assertTrue(os.path.exists(temp.name))
 def setUp(self):
     self.control_tmp = autotemp.tempfile(unique_id="control_unit", text=True)
     os.write(self.control_tmp.fd, CONTROL)
     os.close(self.control_tmp.fd)
 def setUp(self):
     self.control_tmp = autotemp.tempfile(unique_id='wrapped_control_unit',
                                          text=True)
     os.write(self.control_tmp.fd, WRAPPED_CONTROL)