Ejemplo n.º 1
0
def _create_fake_numa_container_directly(name, parent, mbytes, cpus):
    need_fake_numa()
    lockfile = my_lock('inner')  # serialize race between parallel tests
    try:
        # Pick specific mem nodes for new cpuset's exclusive use
        # For now, arbitrarily pick highest available node numbers
        needed_kbytes = mbytes * 1024
        nodes = sorted(list(available_exclusive_mem_nodes(parent)))
        kbytes = 0
        nodecnt = 0
        while kbytes < needed_kbytes and nodecnt < len(nodes):
            nodecnt += 1
            kbytes += node_avail_kbytes(nodes[-nodecnt])
        if kbytes < needed_kbytes:
            parent_mbytes = container_mbytes(parent)
            if mbytes > parent_mbytes:
                raise error.AutotestError("New container's %d Mbytes exceeds "
                                          "parent container's %d Mbyte size" %
                                          (mbytes, parent_mbytes))
            else:
                raise error.AutotestError("Existing sibling containers hold "
                                          "%d Mbytes needed by new container" %
                                          ((needed_kbytes - kbytes) // 1024))
        mems = nodes[-nodecnt:]

        create_container_with_specific_mems_cpus(name, mems, cpus)
    finally:
        my_unlock(lockfile)
Ejemplo n.º 2
0
    def setup(self,
              tarball='oprofile-0.9.4.tar.bz2',
              local=None,
              *args,
              **dargs):
        if local == True:
            return

        try:
            self.tarball = utils.unmap_url(self.bindir, tarball, self.tmpdir)
            utils.extract_tarball_to_dir(self.tarball, self.srcdir)
            os.chdir(self.srcdir)

            patch = os.path.join(self.bindir, "oprofile-69455.patch")
            utils.system('patch -p1 < %s' % patch)
            utils.configure('--with-kernel-support --prefix=' + \
                                                    self.srcdir)
            utils.make('-j %d' % utils.count_cpus())
            utils.make('install')
        except Exception:
            # Build from source failed.
            # But maybe can still use the local copy
            local_opcontrol = os.path.exists('/usr/bin/opcontrol')
            local_opreport = os.path.exists('/usr/bin/opreport')
            if local == False or not local_opcontrol or not local_opreport:
                raise error.AutotestError('No oprofile available')
        else:
            # if we managed to build, try again to pick binaries
            self._pick_binaries(True)
def _validate_args(args, dargs, *funcs):
    """Verify that arguments are appropriate for at least one callable.

    Given a list of callables as additional parameters, verify that
    the proposed keyword arguments in dargs will each be accepted by at least
    one of the callables.

    NOTE: args is currently not supported and must be empty.

    Args:
      args: A tuple of proposed positional arguments.
      dargs: A dictionary of proposed keyword arguments.
      *funcs: Callables to be searched for acceptance of args and dargs.
    Raises:
      error.AutotestError: if an arg won't be accepted by any of *funcs.
    """
    all_co_flags = 0
    all_varnames = ()
    for func in funcs:
        all_co_flags |= func.func_code.co_flags
        all_varnames += func.func_code.co_varnames[:func.func_code.co_argcount]

    # Check if given args belongs to at least one of the methods below.
    if len(args) > 0:
        # Current implementation doesn't allow the use of args.
        raise error.TestError('Unnamed arguments not accepted. Please '
                              'call job.run_test with named args only')

    # Check if given dargs belongs to at least one of the methods below.
    if len(dargs) > 0:
        if not all_co_flags & 0x08:
            # no func accepts *dargs, so:
            for param in dargs:
                if not param in all_varnames:
                    raise error.AutotestError('Unknown parameter: %s' % param)
Ejemplo n.º 4
0
    def initialize(self):
        self.job.require_gcc()

        try:
            utils.system('grep -iq " profile=" /proc/cmdline')
        except error.CmdError:
            raise error.AutotestError('readprofile not enabled')

        self.cmd = self.srcdir + '/sys-utils/readprofile'
Ejemplo n.º 5
0
    def stop(self, test):
        ret_code = self._process.poll()
        if ret_code is not None:
            raise error.AutotestError(
                'perf terminated early with return code: '
                '%d. Please check your logs.' % ret_code)

        os.killpg(os.getpgid(self._process.pid), signal.SIGINT)
        self._process.wait()
Ejemplo n.º 6
0
 def _remove_disk_img(self):
     """
     Removes the disk image.
     """
     logging.debug('Removing disk image %s', self.img)
     try:
         os.remove(self.img)
     except:
         e_msg = 'Error removing image file %s' % self.img
         raise error.AutotestError(e_msg)
Ejemplo n.º 7
0
 def raise_error(self, msg):
     """Raise an error related to the last line returned by get_next_line()
     """
     if self.line_index == 0:  # nothing was read. shouldn't happen, but...
         line_id = 'BEGIN'
     elif self.line_index >= len(self.lines):  # past EOF
         line_id = 'EOF'
     else:
         # line_index is the _next_ line. get the previous one
         line_id = str(self.real_number[self.line_index - 1])
     raise error.AutotestError("%s:%s: %s" % (self.filename, line_id, msg))
Ejemplo n.º 8
0
    def _get_command(self, timestamp):
        file_name = 'perf-%s.data' % (int(timestamp))

        path = os.path.join(self.test.profdir, file_name)

        if self.profile_type == 'record':
            return ['perf', 'record', '-e', 'cycles', '-g', '--output', path]
        elif self.profile_type == 'stat':
            return ['perf', 'stat', 'record', '-a', '--output', path]
        else:
            raise error.AutotestError('Unknown profile type: %s' %
                                      (self.profile_type))
Ejemplo n.º 9
0
def create_container_with_mbytes_and_specific_cpus(name,
                                                   mbytes,
                                                   cpus=None,
                                                   root=SUPER_ROOT,
                                                   io={},
                                                   move_in=True,
                                                   timeout=0):
    """\
    Create a cpuset container and move job's current pid into it
    Allocate the list "cpus" of cpus to that container

            name = arbitrary string tag
            mbytes = reqested memory for job in megabytes
            cpus = list of cpu indicies to associate with the cpuset
                  defaults to all cpus avail with given root
            root = the parent cpuset to nest this new set within
                   '': unnested top-level container
            io = arguments for proportional IO containers
            move_in = True: Move current process into the new container now.
            timeout = must be 0: persist until explicitly deleted.
    """
    need_mem_containers()
    if not container_exists(root):
        raise error.AutotestError('Parent container "%s" does not exist' %
                                  root)
    if cpus is None:
        # default to biggest container we can make under root
        cpus = get_cpus(root)
    else:
        cpus = set(cpus)  # interface uses list
    if not cpus:
        raise error.AutotestError('Creating container with no cpus')
    name = os.path.join(root, name)  # path relative to super_root
    if os.path.exists(full_path(name)):
        raise error.AutotestError('Container %s already exists' % name)
    create_container_directly(name, mbytes, cpus)
    set_io_controls(name, **io)
    if move_in:
        move_self_into_container(name)
    return name
Ejemplo n.º 10
0
 def _detach_img_loop(self):
     """
     Detaches the image file from the loopback device.
     """
     logging.debug('Detaching image %s from loop device %s', self.img,
                   self.loop)
     try:
         cmd = 'losetup -d %s' % self.loop
         utils.run(cmd)
     except error.CmdError, e:
         e_msg = ('Error detaching image %s from loop device %s: %s' %
                 (self.img, self.loop, e))
         raise error.AutotestError(e_msg)
Ejemplo n.º 11
0
 def initialize(self):
     """
     Gets path of kvm_stat and verifies if debugfs needs to be mounted.
     """
     self.stat_path = os_dep.command('kvm_stat')
     try:
         utils.system_output("%s --batch" % self.stat_path)
     except error.CmdError, e:
         if 'debugfs' in str(e):
             utils.system('mount -t debugfs debugfs /sys/kernel/debug')
         else:
             raise error.AutotestError('kvm_stat failed due to an '
                                       'unknown reason: %s' % str(e))
Ejemplo n.º 12
0
 def _remove_entries_partition(self):
     """
     Removes the entries under /dev/mapper for the partition associated
     to the loopback device.
     """
     logging.debug('Removing the entry on /dev/mapper for %s loop dev',
                   self.loop)
     try:
         cmd = 'kpartx -d %s' % self.loop
         utils.run(cmd)
     except error.CmdError, e:
         e_msg = 'Error removing entries for loop %s: %s' % (self.loop, e)
         raise error.AutotestError(e_msg)
Ejemplo n.º 13
0
    def _create_disk_img(self, img_path, size):
        """
        Creates a disk image using dd.

        @param img_path: Path to the desired image file.
        @param size: Size of the desired image in Bytes.
        @returns: Path of the image created.
        """
        logging.debug('Creating disk image %s, size = %d Bytes', img_path, size)
        try:
            cmd = 'dd if=/dev/zero of=%s bs=1024 count=%d' % (img_path, size)
            utils.run(cmd)
        except error.CmdError, e:
            e_msg = 'Error creating disk image %s: %s' % (img_path, e)
            raise error.AutotestError(e_msg)
 def _attach_img_loop(self):
     """
     Attaches a file image to a loopback device using losetup.
     @returns: Path of the loopback device associated.
     """
     logging.debug('Attaching image %s to a loop device', self.img)
     try:
         cmd = 'losetup -f'
         loop_path = utils.system_output(cmd)
         cmd = 'losetup -f %s' % self.img
         utils.run(cmd)
     except error.CmdError, e:
         e_msg = ('Error attaching image %s to a loop device: %s' %
                  (self.img, e))
         raise error.AutotestError(e_msg)
Ejemplo n.º 15
0
    def __init__(self, file_img, file_size):
        """
        Creates a virtual partition, keeping record of the device created
        under /dev/mapper (device attribute) so test writers can use it
        on their filesystem tests.

        @param file_img: Path to the desired disk image file.
        @param file_size: Size of the desired image in Bytes.
        """
        logging.debug('Sanity check before attempting to create virtual '
                      'partition')
        try:
            os_dep.commands('sfdisk', 'losetup', 'kpartx')
        except ValueError, e:
            e_msg = 'Unable to create virtual partition: %s' % e
            raise error.AutotestError(e_msg)
    def _create_disk_img(self, img_path):
        """
        Creates a disk image using dd.

        @param img_path: Path to the desired image file.
        @param size: Size of the desired image in MB.
        @returns: Path of the image created.
        """
        logging.debug('Creating disk image %s, size = %d MB', img_path,
                      self.size)
        try:
            cmd = 'truncate %s --size %dM' % (img_path, self.size)
            utils.run(cmd)
        except error.CmdError, e:
            e_msg = 'Error creating disk image %s: %s' % (img_path, e)
            raise error.AutotestError(e_msg)
Ejemplo n.º 17
0
    def _create_single_partition(self, loop_path):
        """
        Creates a single partition encompassing the whole 'disk' using cfdisk.

        @param loop_path: Path to the loopback device.
        """
        logging.debug('Creating single partition on %s', loop_path)
        try:
            single_part_cmd = '0,,c\n'
            sfdisk_file_path = '/tmp/create_partition.sfdisk'
            sfdisk_cmd_file = open(sfdisk_file_path, 'w')
            sfdisk_cmd_file.write(single_part_cmd)
            sfdisk_cmd_file.close()
            utils.run('sfdisk %s < %s' % (loop_path, sfdisk_file_path))
        except error.CmdError, e:
            e_msg = 'Error partitioning device %s: %s' % (loop_path, e)
            raise error.AutotestError(e_msg)
Ejemplo n.º 18
0
    def _setup_devserver_telemetry(self):
        """Setup Telemetry to use the devserver."""
        logging.debug('Setting up telemetry for devserver testing')
        logging.debug('Grabbing build from AFE.')

        build = afe_utils.get_build(self._host)
        if not build:
            logging.error('Unable to locate build label for host: %s.',
                          self._host.hostname)
            raise error.AutotestError('Failed to grab build for host %s.' %
                                      self._host.hostname)

        logging.debug('Setting up telemetry for build: %s', build)

        self._devserver = dev_server.ImageServer.resolve(build)
        self._devserver.stage_artifacts(build, ['autotest_packages'])
        self._telemetry_path = self._devserver.setup_telemetry(build=build)
Ejemplo n.º 19
0
    def initialize(self, interval=120, duration=10, profile_type='record'):
        """Initializes the cros perf profiler.

        Args:
            interval (int): How often to start the profiler
            duration (int): How long the profiler will run per interval. Set to
                None to run for the full duration of the test.
            profile_type (str): Profile type to run.
                Valid options: record, and stat.
        """
        self.interval = interval
        self.duration = duration
        self.profile_type = profile_type

        if self.profile_type not in ['record', 'stat']:
            raise error.AutotestError('Unknown profile type: %s' %
                                      (profile_type))
Ejemplo n.º 20
0
    def _attach_img_loop(self, img_path):
        """
        Attaches a file image to a loopback device using losetup.

        @param img_path: Path of the image file that will be attached to a
                loopback device
        @returns: Path of the loopback device associated.
        """
        logging.debug('Attaching image %s to a loop device', img_path)
        try:
            cmd = 'losetup -f'
            loop_path = utils.system_output(cmd)
            cmd = 'losetup -f %s' % img_path
            utils.run(cmd)
        except error.CmdError, e:
            e_msg = ('Error attaching image %s to a loop device: %s' %
                     (img_path, e))
            raise error.AutotestError(e_msg)
Ejemplo n.º 21
0
    def _create_entries_partition(self, loop_path):
        """
        Takes the newly created partition table on the loopback device and
        makes all its devices available under /dev/mapper. As we previously
        have partitioned it using a single partition, only one partition
        will be returned.

        @param loop_path: Path to the loopback device.
        """
        logging.debug('Creating entries under /dev/mapper for %s loop dev',
                      loop_path)
        try:
            cmd = 'kpartx -a %s' % loop_path
            utils.run(cmd)
            l_cmd = 'kpartx -l %s | cut -f1 -d " "' % loop_path
            device = utils.system_output(l_cmd)
        except error.CmdError, e:
            e_msg = 'Error creating entries for %s: %s' % (loop_path, e)
            raise error.AutotestError(e_msg)
Ejemplo n.º 22
0
def set_io_controls(container_name,
                    disks=[],
                    ioprio_classes=[PROPIO_NORMAL],
                    io_shares=[95],
                    io_limits=[0]):
    # set the propio controls for one container, for selected disks
    # writing directly to /dev/cgroup/container_name/io.io_service_level
    #    without using containerd or container.py
    # See wiki ProportionalIOScheduler for definitions
    # ioprio_classes: list of service classes, one per disk
    #    using numeric propio service classes as used by kernel API, namely
    #       1: RT, Real Time, aka PROPIO_PRIO
    #       2: BE, Best Effort, aka PROPIO_NORMAL
    #       3: PROPIO_IDLE
    # io_shares: list of disk-time-fractions, one per disk,
    #       as percentage integer 0..100
    # io_limits: list of limit on/off, one per disk
    #       0: no limit, shares use of other containers' unused disk time
    #       1: limited, container's use of disk time is capped to given DTF
    # ioprio_classes defaults to best-effort
    # io_limit defaults to no limit, use slack time
    if not disks:  # defaults to all drives
        disks = all_drive_names()
        io_shares = [io_shares[0]] * len(disks)
        ioprio_classes = [ioprio_classes[0]] * len(disks)
        io_limits = [io_limits[0]] * len(disks)
    if not (len(disks) == len(ioprio_classes) and len(disks) == len(io_shares)
            and len(disks) == len(io_limits)):
        raise error.AutotestError('Unequal number of values for io controls')
    service_level = io_attr(container_name, 'io_service_level')
    if not os.path.exists(service_level):
        return  # kernel predates propio features
        # or io cgroup is mounted separately from cpusets
    disk_infos = []
    for disk, ioclass, limit, share in zip(disks, ioprio_classes, io_limits,
                                           io_shares):
        parts = (disk, str(ioclass), str(limit), str(share))
        disk_info = ' '.join(parts)
        utils.write_one_line(service_level, disk_info)
        disk_infos.append(disk_info)
    logging.debug('set_io_controls of %s to %s', container_name,
                  ', '.join(disk_infos))
Ejemplo n.º 23
0
    def image_to_servo_usb(self,
                           image_path=None,
                           make_image_noninteractive=False):
        """Install an image to the USB key plugged into the servo.

        This method may copy any image to the servo USB key including a
        recovery image or a test image.  These images are frequently used
        for test purposes such as restoring a corrupted image or conducting
        an upgrade of ec/fw/kernel as part of a test of a specific image part.

        @param image_path Path on the host to the recovery image.
        @param make_image_noninteractive Make the recovery image
                                   noninteractive, therefore the DUT
                                   will reboot automatically after
                                   installation.
        """
        # We're about to start plugging/unplugging the USB key.  We
        # don't know the state of the DUT, or what it might choose
        # to do to the device after hotplug.  To avoid surprises,
        # force the DUT to be off.
        self._server.hwinit()
        self._power_state.power_off()

        # Set up Servo's usb mux.
        self.switch_usbkey('host')
        if image_path:
            logging.info('Searching for usb device and copying image to it. '
                         'Please wait a few minutes...')
            if not self._server.download_image_to_usb(image_path):
                logging.error('Failed to transfer requested image to USB. '
                              'Please take a look at Servo Logs.')
                raise error.AutotestError('Download image to usb failed.')
            if make_image_noninteractive:
                logging.info('Making image noninteractive')
                if not self._server.make_image_noninteractive():
                    logging.error('Failed to make image noninteractive. '
                                  'Please take a look at Servo Logs.')
Ejemplo n.º 24
0
def need_fake_numa():
    discover_container_style()
    if not fake_numa_containers:
        raise error.AutotestError('fake=numa not enabled by latest reboot')
Ejemplo n.º 25
0
def need_mem_containers():
    discover_container_style()
    if not mem_isolation_on:
        raise error.AutotestError('Mem-isolation containers not enabled '
                                  'by latest reboot')