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

Revision 1934, 4.4 kB (checked in by adi, 10 years ago)

Shebang-line cleanup. Closes: #292

Patch provided by Orcan Ogetbil (Fedora).

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