def run_once(self):
        kernel_ver = os.uname()[2]
        if utils.compare_versions(kernel_ver, self.MIN_KERNEL_VER) < 0:
            logging.info(
                'skipping test: old kernel %s (min %s) missing module %s',
                kernel_ver, self.MIN_KERNEL_VER, self.MODULE_NAME)
            return

        utils.load_module(self.MODULE_NAME)

        self._governor_paths = glob.glob(self.GOVERNOR_GLOB)
        self._setspeed_paths = glob.glob(self.SETSPEED_GLOB)
        self._cur_freq_paths = glob.glob(self.CUR_FREQ_GLOB)
        initial_governors = self._get_governors()
        initial_quiet_governor = self._get_quiet_governor()

        with open(self.CPUFREQ_AVAIL_PATH, 'r') as f:
            available_freqs = [int(x) for x in f.readline().split()]

        max_freq = max(available_freqs)
        min_freq = min(available_freqs)
        logging.info('cpu frequency max %d min %d', max_freq, min_freq)

        freqs = [min_freq, max_freq]
        try:
            for freq in freqs:
                self._set_freq(freq)
                for usecs in self.DELAYS:
                    self._test_udelay(usecs)
                self._check_freq(freq)
        finally:
            self._reset_freq(initial_governors, initial_quiet_governor)
            utils.unload_module(self.MODULE_NAME)
    def run_once(self):
        kernel_ver = os.uname()[2]
        if utils.compare_versions(kernel_ver, self.MIN_KERNEL_VER) < 0:
            logging.info(
                'skipping test: old kernel %s (min %s) missing module %s',
                kernel_ver, self.MIN_KERNEL_VER, self.OLD_MODULE_NAME)
            return

        if utils.compare_versions(kernel_ver, self.NEW_KERNEL_VER) < 0:
            module_name = self.OLD_MODULE_NAME
        else:
            module_name = self.NEW_MODULE_NAME

        utils.load_module(module_name)

        self._governor_paths = glob.glob(self.GOVERNOR_GLOB)
        self._setspeed_paths = glob.glob(self.SETSPEED_GLOB)
        self._cur_freq_paths = glob.glob(self.CUR_FREQ_GLOB)
        initial_governors = self._get_governors()
        initial_quiet_governor = self._get_quiet_governor()

        with open(self.CPUFREQ_AVAIL_GOVERNORS_PATH, 'r') as f:
            available_governors = set(f.readline().split())
        logging.info('governors: %s', ' '.join(available_governors))

        try:
            if 'userspace' in available_governors:
                self._test_userspace()
            else:
                logging.warning('testing with existing governor')
                self._test_all_delays()
        finally:
            self._reset_freq(initial_governors, initial_quiet_governor)
            utils.unload_module(module_name)
 def _unload_modules(self, mod_list=None):
     """
     Just unload the KVM modules, without trying to kill Qemu
     """
     if mod_list is None:
         mod_list = self.full_module_list()
     logging.info("Unloading previously loaded KVM modules")
     for module in reversed(mod_list):
         utils.unload_module(module)
Exemple #4
0
 def _unload_modules(self, mod_list=None):
     """
     Just unload the KVM modules, without trying to kill Qemu
     """
     if mod_list is None:
         mod_list = self.full_module_list()
     logging.info("Unloading previously loaded KVM modules")
     for module in reversed(mod_list):
         utils.unload_module(module)
Exemple #5
0
    def unload_modules(self, module_list=None):
        '''
        Unloads kernel modules

        By default, if no module list is explicitly provided, the list on
        params (coming from the configuration file) will be used.
        '''
        if module_list is None:
            module_list = self.module_list
        module_list = reversed(module_list)
        logging.info("Unloading kernel modules: %s" % ",".join(module_list))
        for module in module_list:
            utils.unload_module(module)
    def try_load_mod(self, module):
        """
        Try to load a (non-crypto) module using the crypto UAPI
        @param module: name of the kernel module to try to load
        """
        if utils.module_is_loaded(module):
            utils.unload_module(module)

        path = os.path.join(self.srcdir, 'crypto_load_mod ')
        utils.system(path + module)

        if utils.module_is_loaded(module):
            utils.unload_module(module)
            raise error.TestFail('Able to load module "%s" using crypto UAPI' %
                                 module)
    def run_once(self):
        """
        This test will run the firmware request kernel self test (from
        upstream). This tests that the request_firmware() and
        request_firmware_nowait() kernel APIs are somewhat sane. It tries to
        load the empty filename ("") as well as a small toy firmware, and
        checks that it matches. It also makes sure a non-existent firmware
        cannot be found.

        We rerun the same test several times to increase the probability of
        catching errors.

        Needs to disable module locking so we can load test firmwares from
        non-standard locations (e.g., /tmp)
        """

        num_loops = 50
        module_name = "test_firmware"

        if not self.test_is_valid():
            raise error.TestNAError(
                "FW test module is not available for this test")

        utils.load_module(module_name)
        if not utils.module_is_loaded(module_name):
            raise error.TestNAError(
                "FW test module is not available for this test")

        try:
            self.set_module_locking(False)

            logging.info("iterations: %d", num_loops)

            for i in range(0, num_loops):
                self.do_fw_test()

        finally:
            self.set_module_locking(True)
            utils.unload_module(module_name)
Exemple #8
0
def load_kvm_modules(module_dir=None, load_stock=False, extra_modules=None):
    """
    Unload previously loaded kvm modules, then load modules present on any
    sub directory of module_dir. Function will walk through module_dir until
    it finds the modules.

    @param module_dir: Directory where the KVM modules are located.
    @param load_stock: Whether we are going to load system kernel modules.
    @param extra_modules: List of extra modules to load.
    """
    vendor = "intel"
    if os.system("grep vmx /proc/cpuinfo 1>/dev/null") != 0:
        vendor = "amd"
    logging.debug("Detected CPU vendor as '%s'" %(vendor))

    kill_qemu_processes()

    logging.info("Unloading previously loaded KVM modules")
    utils.unload_module("kvm")
    if extra_modules:
        for module in extra_modules:
            utils.unload_module(module)

    if module_dir:
        logging.info("Loading the built KVM modules...")
        kvm_module_path = None
        kvm_vendor_module_path = None
        abort = False

        list_modules = ['kvm.ko', 'kvm-%s.ko' % vendor]
        if extra_modules:
            for extra_module in extra_modules:
                list_modules.append('%s.ko' % extra_module)

        list_module_paths = []
        for folder, subdirs, files in os.walk(module_dir):
            for module in list_modules:
                if module in files:
                    module_path = os.path.join(folder, module)
                    list_module_paths.append(module_path)

        # We might need to arrange the modules in the correct order
        # to avoid module load problems
        list_modules_load = []
        for module in list_modules:
            for module_path in list_module_paths:
                if os.path.basename(module_path) == module:
                    list_modules_load.append(module_path)

        if len(list_module_paths) != len(list_modules):
            logging.error("KVM modules not found. If you don't want to use the "
                          "modules built by this test, make sure the option "
                          "load_modules: 'no' is marked on the test control "
                          "file.")
            raise error.TestError("The modules %s were requested to be loaded, "
                                  "but the only modules found were %s" %
                                  (list_modules, list_module_paths))

        for module_path in list_modules_load:
            try:
                utils.system("insmod %s" % module_path)
            except Exception, e:
                raise error.TestFail("Failed to load KVM modules: %s" % e)
Exemple #9
0
def _unload_kvm_modules(mod_list):
    logging.info("Unloading previously loaded KVM modules")
    for module in reversed(mod_list):
        utils.unload_module(module)
def unload_zfs_modules():
    if utils.unload_module("zfs") == False:
        logging.info("zfs cannot unload module..")
    else:
        logging.info("zfs module unloaded successfully..")
    return SUCCESS
Exemple #11
0
def _unload_kvm_modules(mod_list):
    logging.info("Unloading previously loaded KVM modules")
    for module in reversed(mod_list):
        utils.unload_module(module)
    def run_once(self):
        kernel_ver = os.uname()[2]
        if utils.compare_versions(kernel_ver, self.MIN_KERNEL_VER) < 0:
            logging.info(
                    'skipping test: old kernel %s (min %s) missing module %s',
                    kernel_ver, self.MIN_KERNEL_VER, self.MODULE_NAME)
            return

        utils.load_module(self.MODULE_NAME)

        start_rtc, start_ktime, start_error = self._get_times()
        logging.info(
                'start rtc %d ktime %f error %f',
                start_rtc, start_ktime, start_error)

        recent_diffs = []
        max_diff = 0
        sum_rtc = 0
        sum_diff = 0
        sum_rtc_rtc = 0
        sum_rtc_diff = 0
        sum_diff_diff = 0
        for i in xrange(self.TEST_DURATION):
            # Sleep some amount of time to avoid busy waiting the entire time
            sleep((i % 10) * 0.1)

            current_rtc, current_ktime, current_error = self._get_times()
            elapsed_rtc = current_rtc - start_rtc
            elapsed_ktime = current_ktime - start_ktime
            elapsed_diff = float(elapsed_rtc) - elapsed_ktime

            # Allow for inaccurate ktime off ALLOWABLE_DRIFT from elapsed RTC,
            # and take into account start and current error in times gathering
            max_error = start_error + current_error
            drift_threshold = elapsed_rtc * self.ALLOWABLE_DRIFT + max_error

            # Track rolling average and maximum diff
            recent_diffs.append(elapsed_diff)
            if len(recent_diffs) > self.DIFFS_TO_AVERAGE:
                recent_diffs.pop(0)
            rolling_diff = sum(recent_diffs) / len(recent_diffs)
            if abs(elapsed_diff) > abs(max_diff):
                max_diff = elapsed_diff

            # Track linear regression
            sum_rtc += elapsed_rtc
            sum_diff += elapsed_diff
            sum_rtc_rtc += elapsed_rtc * elapsed_rtc
            sum_rtc_diff += elapsed_rtc * elapsed_diff
            sum_diff_diff += elapsed_diff * elapsed_diff

            logging.info((
                    'current rtc %d ktime %f error %f; elapsed rtc %d '
                    'ktime %f: threshold %f diff %+f rolling %+f'),
                    current_rtc, current_ktime, current_error, elapsed_rtc,
                    elapsed_ktime, drift_threshold, elapsed_diff, rolling_diff)

            if abs(elapsed_diff) > drift_threshold:
                raise error.TestFail((
                        'elapsed rtc %d and ktime %f diff %f '
                        'is greater than threshold %f') %
                        (elapsed_rtc, elapsed_ktime, elapsed_diff,
                        drift_threshold))

        # Dump final statistics
        logging.info('max_diff %f', max_diff)
        mean_rtc = sum_rtc / self.TEST_DURATION
        mean_diff = sum_diff / self.TEST_DURATION
        slope = ((sum_rtc_diff - sum_rtc * mean_diff) /
                (sum_rtc_rtc - sum_rtc * mean_rtc))
        logging.info('drift %.9f', slope)

        utils.unload_module(self.MODULE_NAME)