3
|
1 |
#
|
|
2 |
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
# All rights reserved.
|
|
4 |
# This component and the accompanying materials are made available
|
|
5 |
# under the terms of "Eclipse Public License v1.0"
|
|
6 |
# which accompanies this distribution, and is available
|
|
7 |
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
#
|
|
9 |
# Initial Contributors:
|
|
10 |
# Nokia Corporation - initial contribution.
|
|
11 |
#
|
|
12 |
# Contributors:
|
|
13 |
#
|
|
14 |
# Description:
|
|
15 |
#
|
|
16 |
|
|
17 |
from cone.public import api, exceptions
|
|
18 |
from cone.validation.implmlvalidation import ImplValidatorBase
|
|
19 |
from CRMLPlugin import crml_impl
|
|
20 |
from CRMLPlugin import crml_model
|
|
21 |
|
|
22 |
class CrmlValidatorBase(ImplValidatorBase):
|
|
23 |
SUPPORTED_IMPL_CLASSES = crml_impl.CrmlImpl
|
|
24 |
|
|
25 |
class CrmlReferenceValidator(CrmlValidatorBase):
|
|
26 |
PROBLEM_TYPES = ['model.implml.crml.invalid_ref']
|
|
27 |
|
|
28 |
def validate(self):
|
|
29 |
self.dview = self.context.configuration.get_default_view()
|
|
30 |
|
|
31 |
for key in self.impl.repository.keys:
|
|
32 |
if isinstance(key, crml_model.CrmlSimpleKey):
|
|
33 |
self._check_ref(key.ref, key.line)
|
|
34 |
elif isinstance(key, crml_model.CrmlBitmaskKey):
|
|
35 |
for bit in key.bits:
|
|
36 |
self._check_ref(bit.ref, bit.line)
|
|
37 |
elif isinstance(key, crml_model.CrmlKeyRange):
|
|
38 |
for subkey in key.subkeys:
|
|
39 |
fullref = "%s.%s" % (key.ref, subkey.ref)
|
|
40 |
self._check_ref(fullref, subkey.line)
|
|
41 |
|
|
42 |
def _check_ref(self, ref, line):
|
|
43 |
self.check_feature_reference(ref, line, self.PROBLEM_TYPES[0])
|
|
44 |
|
|
45 |
class CrmlDuplicateUidValidator(CrmlValidatorBase):
|
|
46 |
PROBLEM_TYPES = ['model.implml.crml.duplicate_uid']
|
|
47 |
|
|
48 |
def validate(self):
|
|
49 |
# Collect a dictionary of CRML keys by UID
|
|
50 |
keys_by_uid = {}
|
|
51 |
for key in self.impl.repository.keys:
|
|
52 |
if isinstance(key, (crml_model.CrmlSimpleKey, crml_model.CrmlBitmaskKey)):
|
|
53 |
try:
|
|
54 |
try:
|
|
55 |
uid = long(key.int)
|
|
56 |
except ValueError:
|
|
57 |
uid = long(key.int, 16)
|
|
58 |
except ValueError:
|
|
59 |
# Silently ignore non-numeric UID values (they should be caught
|
|
60 |
# by other validation)
|
|
61 |
continue
|
|
62 |
keys = keys_by_uid.get(uid, [])
|
|
63 |
keys.append(key)
|
|
64 |
keys_by_uid[uid] = keys
|
|
65 |
|
|
66 |
# Check for duplicates
|
|
67 |
for uid, keys in keys_by_uid.iteritems():
|
|
68 |
if len(keys) > 1:
|
|
69 |
if len(keys) > 2:
|
|
70 |
key_lst = "keys on lines %s" % ', '.join([str(key.line) for key in keys[:-2]])
|
|
71 |
key_lst += ' and %s' % keys[-2].line
|
|
72 |
else:
|
|
73 |
key_lst = "key on line %s" % keys[-2].line
|
|
74 |
prob = api.Problem(
|
|
75 |
msg = "Duplicate key UID 0x%08X (duplicate with %s)" % (uid, key_lst),
|
|
76 |
type = self.PROBLEM_TYPES[0],
|
|
77 |
line = keys[-1].line,
|
|
78 |
file = self.impl.ref)
|
|
79 |
self.context.problems.append(prob)
|
|
80 |
|
|
81 |
|
|
82 |
VALIDATOR_CLASSES = [CrmlReferenceValidator, CrmlDuplicateUidValidator]
|