root/trunk/libffado/support/tools/ffado_diag_helpers.py

Revision 1685, 4.4 kB (checked in by arnonym, 14 years ago)

Implement a rather old patch from stefan richter to better check for the firewire stacks presence.

  • 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, procfile):
49     log.info("Checking if module '%s' is present in %s... " % (modulename, procfile))
50     f = open(procfile)
51     lines = f.readlines()
52     f.close()
53     for l in lines:
54         if l.find(modulename) > -1 or l.find(modulename.replace('-', '_')) > -1:
55             log.info(" found")
56             return True
57     log.info(" not found")
58     return False
59
60 def check_for_module_present(modulename):
61     log.info("Checking if module '%s' is present... " % modulename)
62     kver = get_kernel_version()
63     (exitstatus, outtext) = commands.getstatusoutput("find \"/lib/modules/%s/\" -name '%s.ko' | grep '%s'" % \
64                                                      (kver, modulename, modulename) )
65     log.debug("find outputs: %s" % outtext)
66     if outtext == "":
67         log.info(" not found")
68         return False
69     else:
70         log.info(" found")
71         return True
72
73 def check_1394oldstack_active():
74     return check_for_module_loaded('ohci1394', '/proc/interrupts')
75
76 def check_1394oldstack_linked():
77     return os.access('/sys/module/ohci1394', os.F_OK) and \
78            os.access('/sys/module/raw1394',  os.F_OK)
79
80 def check_1394oldstack_loaded():
81     retval = True
82     for modulename in ('ieee1394', 'ohci1394', 'raw1394'):
83         if not check_for_module_loaded(modulename, '/proc/modules'):
84             retval = False
85     return retval
86
87 def check_1394oldstack_present():
88     retval = True
89     for modulename in ('ieee1394', 'ohci1394', 'raw1394'):
90         if not check_for_module_present(modulename):
91             retval = False
92     return retval
93
94 def check_1394newstack_active():
95     return check_for_module_loaded('firewire_ohci', '/proc/interrupts')
96
97 def check_1394newstack_linked():
98     return os.access('/sys/module/firewire_ohci', os.F_OK)
99
100 def check_1394newstack_loaded():
101     retval = True
102     for modulename in ('firewire_core', 'firewire_ohci'):
103         if not check_for_module_loaded(modulename, '/proc/modules'):
104             retval = False
105     return retval
106
107 def check_1394newstack_present():
108     retval = True
109     for modulename in ('firewire-core', 'firewire-ohci'):
110         if not check_for_module_present(modulename):
111             retval = False
112     return retval
113
114 def check_1394oldstack_devnode_present():
115     return os.path.exists('/dev/raw1394')
116
117 def check_1394oldstack_devnode_permissions():
118     f = open('/dev/raw1394','w')
119     if f:
120         f.close()
121         return True
122     else:
123         return False
124
125 def run_command(cmd):
126     (exitstatus, outtext) = commands.getstatusoutput(cmd)
127     log.debug("%s outputs: %s" % (cmd, outtext))
128     return outtext
129
130 # package versions
131 def get_package_version(name):
132     cmd = "pkg-config --modversion %s" % name
133     return run_command(cmd)
134
135 def get_package_flags(name):
136     cmd = "pkg-config --cflags --libs %s" % name
137     return run_command(cmd)
138
139 def get_command_path(name):
140     cmd = "which %s" % name
141     return run_command(cmd)
142
143 def get_version_first_line(cmd):
144     ver = run_command(cmd).split("\n")
145     if len(ver) == 0:
146         ver = ["None"]
147     return ver[0]
148
149
150 def list_host_controllers():
151     cmd = "lspci | grep 1394"
152     controllers = run_command(cmd).split("\n")
153     log.debug("lspci | grep 1394: %s" % controllers)
154     for c in controllers:
155         tmp = c.split()
156         if len(tmp) > 0:
157             tmp
158             cmd = "lspci -vv -nn -s %s" % tmp[0]
159             print run_command(cmd)
160
Note: See TracBrowser for help on using the browser.