• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2014 The Chromium OS Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5import dbus
6import os
7import shutil
8import tarfile
9import tempfile
10
11from autotest_lib.client.bin import test
12from autotest_lib.client.common_lib import error
13
14class platform_DebugDaemonDumpDebugLogs(test.test):
15    version = 1
16
17    def runDump(self, compressed):
18        filename = 'compressed_dump.tgz' if compressed else 'uncompressed_dump.tar'
19        tmp_file = os.path.join(self.tmp_dir, filename)
20        try:
21            fh = os.open(tmp_file, os.O_TRUNC | os.O_CREAT | os.O_WRONLY)
22            self.iface.DumpDebugLogs(compressed, fh, signature="bh")
23        except:
24            raise
25        finally:
26            os.close(fh)
27
28        mode = 'r:gz' if compressed else 'r:'
29        with tarfile.open(tmp_file, mode) as tar_file:
30            if len(tar_file.getmembers()) == 0:
31                raise error.TestFail("%s log file list is empty." %
32                       "compressed" if compressed else "uncompressed")
33
34
35    def run_once(self, *args, **kwargs):
36        bus = dbus.SystemBus()
37        proxy = bus.get_object('org.chromium.debugd', '/org/chromium/debugd')
38        self.iface = dbus.Interface(proxy,
39                                    dbus_interface='org.chromium.debugd')
40        self.tmp_dir = tempfile.mkdtemp()
41        self.runDump(True)
42        self.runDump(False)
43        if os.path.exists(self.tmp_dir):
44            shutil.rmtree(self.tmp_dir)
45
46