Skip to content

Commit

Permalink
Merge branch 'master' into idm-4.2-troubleshoot
Browse files Browse the repository at this point in the history
  • Loading branch information
raul-marquez-csa authored May 21, 2024
2 parents 9e2c7d9 + 70dc5a8 commit 8b6725d
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 6 deletions.
2 changes: 1 addition & 1 deletion examples/kotlin-matter-controller/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ the top Matter directory:
```

The Java executable file `kotlin-matter-controller` will be generated at
`out/android-x86-kotlin-matter-controller/bin/`
`out/linux-x64-kotlin-matter-controller/bin/`

Run the kotlin-matter-controller

Expand Down
4 changes: 2 additions & 2 deletions src/lib/support/static_support_smart_ptr.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ template <class T>
class CheckedGlobalInstanceReference
{
public:
CheckedGlobalInstanceReference<T>() = default;
CheckedGlobalInstanceReference() = default;
CheckedGlobalInstanceReference(T * e) { VerifyOrDie(e == GlobalInstanceProvider<T>::InstancePointer()); }
CheckedGlobalInstanceReference & operator=(T * value)
{
Expand Down Expand Up @@ -89,7 +89,7 @@ template <class T>
class SimpleInstanceReference
{
public:
SimpleInstanceReference<T>() = default;
SimpleInstanceReference() = default;
SimpleInstanceReference(T * e) : mValue(e) {}
SimpleInstanceReference & operator=(T * value)
{
Expand Down
57 changes: 56 additions & 1 deletion src/python_testing/TestConformanceSupport.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import xml.etree.ElementTree as ElementTree

from conformance_support import ConformanceDecision, ConformanceParseParameters, parse_callable_from_xml
from conformance_support import ConformanceDecision, ConformanceException, ConformanceParseParameters, parse_callable_from_xml
from matter_testing_support import MatterBaseTest, async_test_body, default_matter_test_main
from mobly import asserts

Expand Down Expand Up @@ -616,6 +616,61 @@ def test_conformance_otherwise(self):
asserts.assert_equal(xml_callable(f, [], []), ConformanceDecision.PROVISIONAL)
asserts.assert_equal(str(xml_callable), 'AB & !CD, P')

def test_conformance_greater(self):
# AB, [CD]
xml = ('<mandatoryConform>'
'<greaterTerm>'
'<attribute name="attr1" />'
'<literal value="1" />'
'</greaterTerm>'
'</mandatoryConform>')
et = ElementTree.fromstring(xml)
xml_callable = parse_callable_from_xml(et, self.params)
# TODO: switch this to check greater than once the update to the base is done (#33422)
asserts.assert_equal(xml_callable(0x00, [], []), ConformanceDecision.OPTIONAL)
asserts.assert_equal(str(xml_callable), 'attr1 > 1')

# Ensure that we can only have greater terms with exactly 2 value
xml = ('<mandatoryConform>'
'<greaterTerm>'
'<attribute name="attr1" />'
'<attribute name="attr2" />'
'<literal value="1" />'
'</greaterTerm>'
'</mandatoryConform>')
et = ElementTree.fromstring(xml)
try:
xml_callable = parse_callable_from_xml(et, self.params)
asserts.fail("Incorrectly parsed bad greaterTerm XML with > 2 values")
except ConformanceException:
pass

xml = ('<mandatoryConform>'
'<greaterTerm>'
'<attribute name="attr1" />'
'</greaterTerm>'
'</mandatoryConform>')
et = ElementTree.fromstring(xml)
try:
xml_callable = parse_callable_from_xml(et, self.params)
asserts.fail("Incorrectly parsed bad greaterTerm XML with < 2 values")
except ConformanceException:
pass

# Only attributes and literals allowed because arithmetic operations require values
xml = ('<mandatoryConform>'
'<greaterTerm>'
'<feature name="AB" />'
'<literal value="1" />'
'</greaterTerm>'
'</mandatoryConform>')
et = ElementTree.fromstring(xml)
try:
xml_callable = parse_callable_from_xml(et, self.params)
asserts.fail("Incorrectly parsed greater term with feature value")
except ConformanceException:
pass


if __name__ == "__main__":
default_matter_test_main()
41 changes: 39 additions & 2 deletions src/python_testing/conformance_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@
AND_TERM = 'andTerm'
OR_TERM = 'orTerm'
NOT_TERM = 'notTerm'
GREATER_TERM = 'greaterTerm'
FEATURE_TAG = 'feature'
ATTRIBUTE_TAG = 'attribute'
COMMAND_TAG = 'command'
CONDITION_TAG = 'condition'
LITERAL_TAG = 'literal'


class ConformanceException(Exception):
Expand Down Expand Up @@ -123,6 +125,18 @@ def __str__(self):
return 'P'


class literal:
def __init__(self, value: str):
self.value = int(value)

def __call__(self):
# This should never be called
raise ConformanceException('Literal conformance function should not be called - this is simply a value holder')

def __str__(self):
return str(self.value)


class feature:
def __init__(self, requiredFeature: uint, code: str):
self.requiredFeature = requiredFeature
Expand Down Expand Up @@ -267,8 +281,25 @@ def __str__(self):
op_strs = [str(op) for op in self.op_list]
return f'({" | ".join(op_strs)})'

# TODO: add xor operation once it's required
# TODO: how would equal and unequal operations work here?

class greater_operation:
def _type_ok(self, op: Callable):
return type(op) == attribute or type(op) == literal

def __init__(self, op1: Callable, op2: Callable):
if not self._type_ok(op1) or not self._type_ok(op2):
raise ConformanceException('Arithmetic operations can only have attribute or literal value children')
self.op1 = op1
self.op2 = op2

def __call__(self, feature_map: uint, attribute_list: list[uint], all_command_list: list[uint]) -> ConformanceDecision:
# For now, this is fully optional, need to implement this properly later, but it requires access to the actual attribute values
# We need to reach into the attribute, but can't use it directly because the attribute callable is an EXISTENCE check and
# the arithmetic functions require a value.
return ConformanceDecision.OPTIONAL

def __str__(self):
return f'{str(self.op1)} > {str(self.op2)}'


class otherwise:
Expand Down Expand Up @@ -325,6 +356,8 @@ def parse_callable_from_xml(element: ElementTree.Element, params: ConformancePar
return command(params.command_map[element.get('name')], element.get('name'))
elif element.tag == CONDITION_TAG and element.get('name').lower() == 'zigbee':
return zigbee()
elif element.tag == LITERAL_TAG:
return literal(element.get('value'))
else:
raise ConformanceException(
f'Unexpected xml conformance element with no children {str(element.tag)} {str(element.attrib)}')
Expand Down Expand Up @@ -354,5 +387,9 @@ def parse_callable_from_xml(element: ElementTree.Element, params: ConformancePar
return not_operation(ops[0])
elif element.tag == OTHERWISE_CONFORM:
return otherwise(ops)
elif element.tag == GREATER_TERM:
if len(ops) != 2:
raise ConformanceException(f'Greater than term found with more than two subelements {list(element)}')
return greater_operation(ops[0], ops[1])
else:
raise ConformanceException(f'Unexpected conformance tag with children {element}')

0 comments on commit 8b6725d

Please sign in to comment.