aboutsummaryrefslogtreecommitdiff
path: root/client/site_tests/platform_LogNonKernelKmsg/platform_LogNonKernelKmsg.py
blob: e26a77ffa7e5342230cb66a7113553655cefcdfc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# Copyright 2014 The Chromium OS Authors. All rights reserved.  Use of
# this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import time

from autotest_lib.client.bin import test
from autotest_lib.client.common_lib import error
from autotest_lib.client.common_lib import utils

class platform_LogNonKernelKmsg(test.test):
    """Test that we log non-kernel messages via /dev/kmsg"""
    KLOG_PATH = '/dev/kmsg'
    SYSLOG_BIN = 'rsyslogd'
    SYSLOG_JOB = 'syslog'
    SYSTEM_LOG_PATH = '/var/log/messages'
    version = 1


    def run_once(self):
        utils.run('truncate -s 0 %s' % self.SYSTEM_LOG_PATH)
        our_message = 'non-kernel message generated at %d\n' % time.time()
        with open(self.KLOG_PATH, 'w') as outfile:
            outfile.write(our_message)

        cmd_result = utils.run(
            'grep "%s" %s' % (our_message, self.SYSTEM_LOG_PATH),
            ignore_status=True)
        if cmd_result.exit_status:
            raise error.TestFail(
                'our log message did not appear in %s' % self.SYSTEM_LOG_PATH)