root/branches/libffado-2.0/support/tools/ffado_diag_helpers.py

Revision 1665, 4.1 kB (checked in by arnonym, 14 years ago)

Backport r1993 and fix #232.

  • Property svn:mergeinfo set to
Line 
1 #!/usr/bin/python
2 #
3
4 #
5 # Copyright (C) 2008 Pieter Palmers
6 #
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, version 3 of the License.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 #
19
20 #
21 # Test for common FFADO problems
22 #
23
24 import sys
25
26 import os
27 import commands
28 import re
29 import logging
30
31 ## logging setup
32 logging.basicConfig()
33 log = logging.getLogger('diag')
34
35 ## helper routines
36
37 # kernel
38 def get_kernel_version():
39     (exitstatus, outtext) = commands.getstatusoutput('uname -r')
40     log.debug("uname -r outputs: %s" % outtext)
41     return outtext
42
43 def get_kernel_rt_patched():
44     print "FIXME: implement test for RT kernel"
45     return False
46
47 # modules
48 def check_for_module_loaded(modulename):
49     log.info("Checking if module '%s' is loaded... " % modulename)
50     f = open('/proc/modules')
51     lines = f.readlines()
52     f.close()
53     for l in lines:
54         mod = l.split()[0]
55         if mod == modulename or mod == modulename.replace('-', '_'):
56             log.info(" found")
57             return True
58     log.info(" not found")
59     return False
60
61 def check_for_module_present(modulename):
62     log.info("Checking if module '%s' is present... " % modulename)
63     kver = get_kernel_version()
64     (exitstatus, outtext) = commands.getstatusoutput("find \"/lib/modules/%s/\" -name '%s.ko' | grep '%s'" % \
65                                                      (kver, modulename, modulename) )
66     log.debug("find outputs: %s" % outtext)
67     if outtext == "":
68         log.info(" not found")
69         return False
70     else:
71         log.info(" found")
72         return True
73
74 def check_1394oldstack_loaded():
75     retval = True
76     if not check_for_module_loaded('ieee1394'):
77         retval = False
78     if not check_for_module_loaded('ohci1394'):
79         retval = False
80     if not check_for_module_loaded('raw1394'):
81         retval = False
82     return retval
83
84 def check_1394oldstack_present():
85     retval = True
86     if not check_for_module_present('ieee1394'):
87         retval = False
88     if not check_for_module_present('ohci1394'):
89         retval = False
90     if not check_for_module_present('raw1394'):
91         retval = False
92     return retval
93
94 def check_1394newstack_loaded():
95     retval = True
96     if not check_for_module_loaded('firewire-core'):
97         retval = False
98     if not check_for_module_loaded('firewire-ohci'):
99         retval = False
100     return retval
101
102 def check_1394newstack_present():
103     retval = True
104     if not check_for_module_present('firewire-core'):
105         retval = False
106     if not check_for_module_present('firewire-ohci'):
107         retval = False
108     return retval
109
110 def check_1394oldstack_devnode_present():
111     return os.path.exists('/dev/raw1394')
112
113 def check_1394oldstack_devnode_permissions():
114     f = open('/dev/raw1394','w')
115     if f:
116         f.close()
117         return True
118     else:
119         return False
120
121 def run_command(cmd):
122     (exitstatus, outtext) = commands.getstatusoutput(cmd)
123     log.debug("%s outputs: %s" % (cmd, outtext))
124     return outtext
125
126 # package versions
127 def get_package_version(name):
128     cmd = "pkg-config --modversion %s" % name
129     return run_command(cmd)
130
131 def get_package_flags(name):
132     cmd = "pkg-config --cflags --libs %s" % name
133     return run_command(cmd)
134
135 def get_command_path(name):
136     cmd = "which %s" % name
137     return run_command(cmd)
138
139 def get_version_first_line(cmd):
140     ver = run_command(cmd).split("\n")
141     if len(ver) == 0:
142         ver = ["None"]
143     return ver[0]
144
145
146 def list_host_controllers():
147     cmd = "lspci | grep 1394"
148     controllers = run_command(cmd).split("\n")
149     log.debug("lspci | grep 1394: %s" % controllers)
150     for c in controllers:
151         tmp = c.split()
152         if len(tmp) > 0:
153             tmp
154             cmd = "lspci -vv -nn -s %s" % tmp[0]
155             print run_command(cmd)
156
Note: See TracBrowser for help on using the browser.