Exemplo n.º 1
0
def sysctl_kernel(key, value=None):
    """(Very) partial implementation of sysctl, for kernel params"""
    if value:
        # write
        utils.write_one_line("/proc/sys/kernel/%s" % key, str(value))
    else:
        # read
        out = utils.read_one_line("/proc/sys/kernel/%s" % key)
        return int(re.search(r"\d+", out).group(0))
Exemplo n.º 2
0
def sysctl_kernel(key, value=None):
    """(Very) partial implementation of sysctl, for kernel params"""
    if value is not None:
        # write
        utils.write_one_line('/proc/sys/kernel/%s' % key, str(value))
    else:
        # read
        out = utils.read_one_line('/proc/sys/kernel/%s' % key)
        return int(re.search(r'\d+', out).group(0))
    def _set_kernel_fw_update(self, disable=0):
        """Disable the FW update driver.

        @param disable: 1 for disable, 0 for enable.
        """
        utils.write_one_line(self.FW_UP_DISABLE_PATH, disable)
        if not disable:
            # Allow kernel driver time quiesce
            time.sleep(2)
Exemplo n.º 4
0
def sysctl(key, value=None):
    """Generic implementation of sysctl, to read and write.

    @param key: A location under /proc/sys
    @param value: If not None, a value to write into the sysctl.

    @return The single-line sysctl value as a string.
    """
    path = '/proc/sys/%s' % key
    if value is not None:
        utils.write_one_line(path, str(value))
    return utils.read_one_line(path)
Exemplo n.º 5
0
def sysctl(key, value=None):
    """Generic implementation of sysctl, to read and write.

    @param key: A location under /proc/sys
    @param value: If not None, a value to write into the sysctl.

    @return The single-line sysctl value as a string.
    """
    path = '/proc/sys/%s' % key
    if value is not None:
        utils.write_one_line(path, str(value))
    return utils.read_one_line(path)
Exemplo n.º 6
0
    def initialize(self):
        cpufreq_path = '/sys/devices/system/cpu/cpu*/cpufreq'

        dirs = glob.glob(cpufreq_path)
        if not dirs:
            raise error.TestFail('cpufreq not supported')

        self._cpufreq_dirs = dirs
        self._cpus = [cpufreq(dirname) for dirname in dirs]
        for cpu in self._cpus:
            cpu.save_state()

        # Store the setting if the system has CPUQuiet feature
        if os.path.exists(SYSFS_CPUQUIET_ENABLE):
            self.is_cpuquiet_enabled = utils.read_file(SYSFS_CPUQUIET_ENABLE)
            utils.write_one_line(SYSFS_CPUQUIET_ENABLE, '0')
Exemplo n.º 7
0
    def _test_check_product_id(self):
        """
        metrics_daemon should set the product id when it is specified.

        The product id can be set through the GOOGLE_METRICS_PRODUCT_ID file in
        /etc/os-release.d/.
        """

        # The product id must be an integer, declared in the upstream UMA
        # backend protobuf.
        EXPECTED_PRODUCT_ID = 3

        sys.path.append(self.srcdir)
        from chrome_user_metrics_extension_pb2 import ChromeUserMetricsExtension

        self._create_one_sample()

        self.server = FakeServer()
        self.server.Start()
        osreleased_path = os.path.join(self._tempdir.name, 'etc',
                                       'os-release.d')
        file_utils.make_leaf_dir(osreleased_path)
        utils.write_one_line(os.path.join(osreleased_path,
                                          'GOOGLE_METRICS_PRODUCT_ID'),
                             str(EXPECTED_PRODUCT_ID))

        utils.system_output('metrics_daemon -uploader_test '
                            '-server="%s" '
                            '-config_root="%s"' % (SERVER_ADDRESS,
                                                   self._tempdir.name),
                            retain_output=True)

        self.server.Stop()

        if len(self.server.messages) != 1:
            raise error.TestFail('should have received 1 message. Received: '
                               + str(len(self.server.messages)))

        proto = ChromeUserMetricsExtension.FromString(self.server.messages[0])
        logging.debug('Proto received is: ' + str(proto))
        if proto.product != EXPECTED_PRODUCT_ID:
            raise error.TestFail('Product id should be set to 3. Was: '
                                 + str(proto.product))
Exemplo n.º 8
0
 def get_write_one_line_output(self, content):
     test_file = mock.SaveDataAfterCloseStringIO()
     utils.open.expect_call("filename", "w").and_return(test_file)
     utils.write_one_line("filename", content)
     self.god.check_playback()
     return test_file.final_data
Exemplo n.º 9
0
def set_power_state(state):
    """
    Set the system power state to 'state'.
    """
    utils.write_one_line('/sys/power/state', state)
Exemplo n.º 10
0
def set_wake_alarm(alarm_time):
    """
    Set the hardware RTC-based wake alarm to 'alarm_time'.
    """
    utils.write_one_line('/sys/class/rtc/rtc0/wakealarm', str(alarm_time))
 def get_write_one_line_output(self, content):
     test_file = mock.SaveDataAfterCloseStringIO()
     utils.open.expect_call("filename", "w").and_return(test_file)
     utils.write_one_line("filename", content)
     self.god.check_playback()
     return test_file.final_data
Exemplo n.º 12
0
def set_power_state(state):
    """
    Set the system power state to 'state'.
    """
    utils.write_one_line('/sys/power/state', state)
Exemplo n.º 13
0
def set_wake_alarm(alarm_time):
    """
    Set the hardware RTC-based wake alarm to 'alarm_time'.
    """
    utils.write_one_line('/sys/class/rtc/rtc0/wakealarm', str(alarm_time))
 def initialize(self):
     # Store the setting if the system has CPUQuiet feature
     if os.path.exists(SYSFS_CPUQUIET_ENABLE):
         self.is_cpuquiet_enabled = utils.read_file(SYSFS_CPUQUIET_ENABLE)
         utils.write_one_line(SYSFS_CPUQUIET_ENABLE, '0')