-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathalsa-python-coverage.py
More file actions
executable file
·365 lines (325 loc) · 12.1 KB
/
Copy pathalsa-python-coverage.py
File metadata and controls
executable file
·365 lines (325 loc) · 12.1 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
#! /usr/bin/python
# coverage.py -- python coverage of asoundlib API
# Copyright(C) 2008 by Aldrin Martoq <amartoq@dcc.uchile.cl>
# Licensed under GPL v2 (see below).
#
# Description:
# This tool aims to help in completing the python binding of the asoundlib
# API. Actually, it's being coded for the current pyalsa, but it can be
# easily modified to support other styles of codes (mainly by changing the
# pyparsing objects used to scan the source code).
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
from APICoverage import *
import APICoverage
from pprint import pprint
import time
import getpass
__author__ = "Aldrin Martoq <amartoq@dcc.uchile.cl>"
__version__ = "1.0"
__license__ = "GNU General Public License version 2"
__copyright__ = "Copyright(C) 2008 by Aldrin Martoq <amartoq@dcc.uchile.cl>"
# setup and do the work
APICoverage.source_dir = '../pyalsa'
APICoverage.api_url = 'http://www.alsa-project.org/alsa-doc/alsa-lib/'
time_start = time.time()
# common C parser
ident = Word(alphas + "_", alphanums + "_")
type_and_var = \
Optional(oneOf("const unsigned struct")) \
+ ident + Optional(Word("*")) + ident
args = OneOrMore(type_and_var) + ZeroOrMore("," + type_and_var)
function_declaration = type_and_var + "(" + Group(args) + ")"
function_define = \
"#define" + ident \
+ "(" + OneOrMore(ident) + ZeroOrMore("," + ident) + Optional("...") + ")"
function_define_block = \
"#define" + ident + "{"
# + Group(("(" + args + Optional("...") + ")") | "{")
# common asoundlib parser
snd_ = Regex("snd_[\\w_]+")
SND_ = Regex("SND_[\\w_]+")
# pyalsa/alsaseq.c parser
alsaseq_SEQ = Regex('SEQ_[\\w_]+')
alsaseq_Constant = \
"TCONSTADD(module," + alsaseq_SEQ + "," + quotedString + "," + alsaseq_SEQ
alsaseq_typedef = \
Literal("typedef") \
+ "struct" \
+ "{" \
+ "PyObject_HEAD" \
+ Optional(";") \
+ OneOrMore((type_and_var + ";") | cppStyleComment) \
+ "}" \
+ ident.setName("struct_name")
alsaseq_function = \
"static" \
+ function_declaration.setName("static_function")
alsaseq_index = function_define | function_define_block \
| alsaseq_typedef | alsaseq_function
# pyalsa/{alsacard, alsacontrol, alsahcontrol, alsamixer}.c parser
addspace = Regex("add_space[0-9]")
addspace_def = \
Suppress(addspace + "(") \
+ quotedString + Suppress(",") + ident + Suppress(");")
alsaall_Constant = \
Suppress(Literal("#define") \
+ addspace \
+ "(pname, name) { \\" \
+ "o = PyInt_FromLong(") \
+ SND_ \
+ Suppress("##name); \\") \
+ Suppress("PyDict_SetItemString(d1, pname, o); \\") \
+ Suppress("Py_DECREF(o); }") \
+ OneOrMore(Group(addspace_def)) \
+ Suppress("PyDict_SetItemString(d,") \
+ quotedString
alsaall_typedef = \
Literal("struct") \
+ "{" \
+ "PyObject_HEAD" \
+ Optional(";") \
+ OneOrMore((type_and_var + ";") | cppStyleComment) \
+ "}"
alsaall_function = \
"static" \
+ function_declaration.setName("static_function")
alsaall_index = function_define | alsaall_typedef | alsaall_function
# read all files
pyalsaseq = read_source('alsaseq.c')
pyalsacard = read_source('alsacard.c')
pyalsacontrol = read_source('alsacontrol.c')
pyalsahcontrol = read_source('alsahcontrol.c')
pyalsamixer = read_source('alsamixer.c')
# parse all files with parser
index = get_cached_parse([
(pyalsaseq, alsaseq_index),
(pyalsacard, alsaall_index),
(pyalsacontrol, alsaall_index),
(pyalsahcontrol, alsaall_index),
(pyalsamixer, alsaall_index)
], "index")
index_snd_ = get_cached_parse([
(pyalsaseq, snd_),
(pyalsacard, snd_),
(pyalsacontrol, snd_),
(pyalsahcontrol, snd_),
(pyalsamixer, snd_)
], "index_snd_")
index_SND_ = get_cached_parse([
(pyalsaseq, SND_),
(pyalsacard, SND_),
(pyalsacontrol, SND_),
(pyalsahcontrol, SND_),
(pyalsamixer, SND_)
], "index_SND_")
index_Constant_alsaseq = get_cached_parse([
(pyalsaseq, alsaseq_Constant)
], "index_Constant_alsaseq")
index_Constant_alsaall = get_cached_parse([
(pyalsacard, alsaall_Constant),
(pyalsacontrol, alsaall_Constant),
(pyalsahcontrol, alsaall_Constant),
(pyalsamixer, alsaall_Constant)
], "index_Constant_alsaall")
# urls of doxygen documentation
urls = [
# globals
"group___global.html",
# error handling
"group___error.html",
# control
"group___control.html",
"group___h_control.html",
"group___s_control.html",
# sequencer
"group___sequencer.html",
"group___seq_client.html",
"group___seq_port.html",
"group___seq_subscribe.html",
"group___seq_queue.html",
"group___seq_event.html",
"group___seq_misc.html",
"group___seq_ev_type.html",
"group___seq_events.html",
"group___seq_middle.html",
"group___m_i_d_i___event.html",
# mixer
"group___mixer.html",
"group___simple_mixer.html"
]
def look_constant(name):
"""
Look name for constant declarations.
Returns:
a list of strings with the file and python constant.
"""
nlist = []
for file in index_Constant_alsaseq:
for lc in index_Constant_alsaseq[file]:
tokens, start, end = lc
rs = "SND_" + tokens[5]
if rs == name:
nlist.append("%14s: %s" % (file, tokens[5]))
nlist.append("%14s: %s[%s]" %
(file, tokens[1].lower(), tokens[3]))
for file in index_Constant_alsaall:
for lc in index_Constant_alsaall[file]:
tokens, start, end = lc
prefix = tokens[0]
dictname = tokens[-1].split('"')[1]
for i in range(1, len(tokens)-1):
rs = prefix + tokens[i][1]
if rs == name:
nlist.append("%14s: %s[%s]" %
(file, dictname, tokens[i][0]))
return nlist
def look_usage(name):
"""
Look name for usage (appareance) in C functions, structs, etc.
Returns:
a list of strings with the file and matched function/struct/define.
"""
name = name.strip()
dict = {}
for file in index_snd_:
list = []
for lu in index_snd_[file]:
tokens, start, end = lu
rs = tokens[0]
if rs == name:
list.append(start)
dict[file] = list
for file in index_SND_:
list = []
for lu in index_SND_[file]:
tokens, start, end = lu
rs = tokens[0]
if rs == name:
list.append(start)
if file in dict:
dict[file].extend(list)
else:
dict[file] = list
nlist = []
for file in dict:
for lstart in dict[file]:
if file not in index:
continue
found = None
previous = None
for call in index[file]:
tokens, start, end = call
if start > lstart:
found = previous
break
previous = tokens[2]
if tokens[0] == 'typedef':
previous = tokens[-1]
elif tokens[0] == '#define':
previous = tokens[1]
elif previous == '*':
previous = tokens[3]
#print "%8s: %5d - %20s %s" % (file, start, name, previous)
if found != None:
nlist.append("%14s: %s" % (file, found))
#print "FOUND: %8s: %5d %s" % (file, lstart, found)
return nlist
# Following string contains excluded/commented API tokens, one per line.
# Format is:
# token comment
comments = """
SND_SEQ_DLSYM_VERSION I think there is no real use in pyalsa
snd_seq_open_lconf need a snd_config port for implementing it
snd_seq_poll_descriptors_revents no real use in pyalsa
snd_seq_system_info_copy no real use in pyalsa
snd_seq_system_info_free no real use in pyalsa
snd_seq_system_info_malloc snd_seq_system_info_alloca used instead
snd_seq_system_info_sizeof currently not used
snd_seq_client_info_copy no real use in pyalsa
snd_seq_client_info_free no real use in pyalsa
snd_seq_client_info_malloc snd_seq_client_info_alloca used instead
snd_seq_client_pool_copy no real use in pyalsa
snd_seq_client_pool_free no real use in pyalsa
snd_seq_client_pool_get_client snd_seq_client_id used instead
snd_seq_client_pool_malloc no real use in pyalsa
snd_seq_client_pool_set_input_pool snd_seq_set_client_pool_input used instead
snd_seq_client_pool_set_output_pool snd_seq_set_client_pool_output used instead
snd_seq_client_pool_set_output_room snd_seq_set_client_pool_output_room used instead
snd_seq_client_pool_sizeof currently not used
snd_seq_set_client_pool snd_seq_set_client_pool_* used instead
snd_seq_client_info_set_name snd_seq_set_client_name used instead
snd_seq_client_info_sizeof currently not used
snd_seq_get_port_info snd_seq_get_any_port_info used instead
snd_seq_port_info_copy no real use in pyalsa
snd_seq_port_info_free no real use in pyalsa
snd_seq_port_info_malloc snd_seq_port_info_alloca used instead
snd_seq_port_info_set_addr snd_seq_port_info_set_client, snd_seq_port_info_set_port used instead
snd_seq_port_info_sizeof currently not used
snd_seq_port_subscribe_copy no real use in pyalsa
snd_seq_port_subscribe_free no real use in pyalsa
snd_seq_port_subscribe_malloc snd_seq_port_subscribe_alloca used instead
snd_seq_port_subscribe_sizeof currently not used
snd_seq_query_subscribe_copy no real use in pyalsa
snd_seq_query_subscribe_free no real use in pyalsa
snd_seq_query_subscribe_get_client snd_seq_query_subscribe_get_addr used instead
snd_seq_query_subscribe_get_index currently not used
#snd_seq_query_subscribe_get_num_subs
snd_seq_query_subscribe_get_port snd_seq_query_subscribe_get_addr used instead
snd_seq_query_subscribe_get_root currently not used
snd_seq_query_subscribe_get_type currently not used
snd_seq_query_subscribe_malloc no real use in pyalsa
snd_seq_query_subscribe_set_client snd_seq_query_subscribe_set_index used instead
snd_seq_query_subscribe_set_port snd_seq_query_subscribe_set_index used instead
snd_seq_query_subscribe_sizeof currently not used
"""
print("""
*******************************
PYALSA/ASOUNDLIB COVERAGE/USAGE
*******************************
Notes:
* For re-generating this file, you need inet access (for downloading the
doxygen HTML from www.alsa-project.org site).
* Some cached information about parsing is in the 'cache' directory:
* If you change a source file, the program will regenerate the cache.
* HTML API from www.alsa-project.org is never refreshed, remove manually.
* Doxygen Modules are underlined by ======= .
* Doxygen Sections are Underlined by ------- . The parsed sections are:
* CPP #defines
* Type definitions
* Enumerations
* Functions
* The first line of each item is the "C Prototype". First 3 columns are:
* Number of times found in checked code
* N/A if the item is not being used/was not found
* EXC if the item is excluded (will not be used/implemented)
* The next line is the one-liner documentation.
* Following lines are usage/definition until next item.
* There are lines that summarizes the coverage, they start with '^STAT'.
""")
print_api_coverage(urls, look_constant, look_usage, comments)
# print end line
time_end = time.time()
time_diff = time_end - time_start
print("""%s
Generated for ALSA project by alsa-python-coverage.py %s
%s UTC (%s@%s %3.3f seconds).
""" % ("-"*72,
__version__,
time.asctime(time.gmtime(time_start)),
getpass.getuser(),
os.uname()[1],
time_diff
))
print()