forked from libvirt/libvirt
-
Notifications
You must be signed in to change notification settings - Fork 11
/
check-drivername.py
111 lines (98 loc) · 3.81 KB
/
check-drivername.py
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
#!/usr/bin/env python3
#
# Copyright (C) 2013-2019 Red Hat, Inc.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library 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
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library. If not, see
# <http://www.gnu.org/licenses/>.
#
import re
import sys
drvfiles = []
symfiles = []
for arg in sys.argv:
if arg.endswith(".h"):
drvfiles.append(arg)
else:
symfiles.append(arg)
symbols = {}
for symfile in symfiles:
with open(symfile, "r") as fh:
for line in fh:
m = re.search(r'''^\s*(vir\w+)\s*;\s*$''', line)
if m is not None:
symbols[m.group(1)] = True
status = 0
for drvfile in drvfiles:
with open(drvfile, "r") as fh:
for line in fh:
m = re.search(r'''\*(virDrv\w+)\s*\)''', line)
if m is not None:
drv = m.group(1)
skip = [
"virDrvStateInitialize",
"virDrvStateCleanup",
"virDrvStateReload",
"virDrvStateStop",
"virDrvConnectSupportsFeature",
"virDrvConnectURIProbe",
"virDrvDomainMigratePrepare",
"virDrvDomainMigratePrepare2",
"virDrvDomainMigratePrepare3",
"virDrvDomainMigratePrepare3Params",
"virDrvDomainMigratePrepareTunnel",
"virDrvDomainMigratePrepareTunnelParams",
"virDrvDomainMigratePrepareTunnel3",
"virDrvDomainMigratePrepareTunnel3Params",
"virDrvDomainMigratePerform",
"virDrvDomainMigratePerform3",
"virDrvDomainMigratePerform3Params",
"virDrvDomainMigrateConfirm",
"virDrvDomainMigrateConfirm3",
"virDrvDomainMigrateConfirm3Params",
"virDrvDomainMigrateBegin",
"virDrvDomainMigrateBegin3",
"virDrvDomainMigrateBegin3Params",
"virDrvDomainMigrateFinish",
"virDrvDomainMigrateFinish2",
"virDrvDomainMigrateFinish3",
"virDrvDomainMigrateFinish3Params",
"virDrvStreamInData",
]
if drv in skip:
continue
sym = drv.replace("virDrv", "vir")
if sym not in symbols:
print("Driver method name %s doesn't match public API" %
drv)
status = 1
continue
m = re.search(r'''(\*vir\w+)\s*\)''', line)
if m is not None:
name = m.group(1)
print("Bogus name %s" % name)
status = 1
continue
m = re.search(r'''^\s*(virDrv\w+)\s+(\w+);\s*''', line)
if m is not None:
drv = m.group(1)
field = m.group(2)
tmp = drv.replace("virDrv", "")
if tmp.startswith("NWFilter"):
tmp = "nwfilter" + tmp[8:]
tmp = tmp[0:1].lower() + tmp[1:]
if tmp != field:
print("Driver struct field %s should be named %s" %
(field, tmp))
status = 1
sys.exit(status)