Skip to content

Commit 1363826

Browse files
bzbarsky-applepull[bot]
authored andcommitted
Enable ubsan in darwin unit tests. (#26467)
1) Fix some ids that should have been marked _Nullable to say that. 2) Change the attribute/event decoder codegen to not generate a single huge function: with both asan and ubsan enabled, this caused the function to use too much stack for some of the instrumentation and run out of stack space in the thread. 3) Remove some commented-out debugging code that crept into MTRDeviceTests. 4) Enable UndefinedBehaviorSanitizer in the Xcode test scheme. 5) Lay the groundwork for also building libCHIP with ubsan when doing these tests. Not enabled yet because it runs into some issues so far.
1 parent ade63e1 commit 1363826

9 files changed

+20190
-19444
lines changed

src/darwin/Framework/CHIP/MTRAttributeTLVValueDecoder_Internal.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
NS_ASSUME_NONNULL_BEGIN
2828

29-
id MTRDecodeAttributeValue(const chip::app::ConcreteAttributePath & aPath, chip::TLV::TLVReader & aReader, CHIP_ERROR * aError);
29+
id _Nullable MTRDecodeAttributeValue(const chip::app::ConcreteAttributePath & aPath, chip::TLV::TLVReader & aReader,
30+
CHIP_ERROR * aError);
3031

3132
NS_ASSUME_NONNULL_END

src/darwin/Framework/CHIP/MTREventTLVValueDecoder_Internal.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@
2727

2828
NS_ASSUME_NONNULL_BEGIN
2929

30-
id MTRDecodeEventPayload(const chip::app::ConcreteEventPath & aPath, chip::TLV::TLVReader & aReader, CHIP_ERROR * aError);
30+
id _Nullable MTRDecodeEventPayload(const chip::app::ConcreteEventPath & aPath, chip::TLV::TLVReader & aReader, CHIP_ERROR * aError);
3131

3232
NS_ASSUME_NONNULL_END

src/darwin/Framework/CHIP/templates/MTRAttributeTLVValueDecoder-src.zapt

+28-19
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,12 @@
1414
using namespace chip;
1515
using namespace chip::app;
1616

17-
id MTRDecodeAttributeValue(const ConcreteAttributePath & aPath, TLV::TLVReader & aReader, CHIP_ERROR * aError)
17+
{{#zcl_clusters}}
18+
{{#if (isSupported (asUpperCamelCase name preserveAcronyms=true))}}
19+
static id _Nullable DecodeAttributeValueFor{{asUpperCamelCase name preserveAcronyms=true}}Cluster(AttributeId aAttributeId, TLV::TLVReader & aReader, CHIP_ERROR * aError)
1820
{
19-
switch (aPath.mClusterId)
20-
{
21-
{{#zcl_clusters}}
22-
{{#if (isSupported (asUpperCamelCase name preserveAcronyms=true))}}
23-
case Clusters::{{asUpperCamelCase name}}::Id: {
24-
using namespace Clusters::{{asUpperCamelCase name}};
25-
switch (aPath.mAttributeId)
26-
{
21+
using namespace Clusters::{{asUpperCamelCase name}};
22+
switch (aAttributeId) {
2723
{{#zcl_attributes_server removeKeys='isOptional'}}
2824
{{#if (isSupported (asUpperCamelCase ../name preserveAcronyms=true) attribute=(asUpperCamelCase name preserveAcronyms=true))}}
2925
case Attributes::{{asUpperCamelCase name}}::Id: {
@@ -40,18 +36,31 @@ id MTRDecodeAttributeValue(const ConcreteAttributePath & aPath, TLV::TLVReader &
4036
}
4137
{{/if}}
4238
{{/zcl_attributes_server}}
43-
default:
44-
*aError = CHIP_ERROR_IM_MALFORMED_ATTRIBUTE_PATH_IB;
45-
break;
39+
default: {
40+
break;
4641
}
47-
break;
48-
}
49-
{{/if}}
50-
{{/zcl_clusters}}
51-
default: {
52-
*aError = CHIP_ERROR_IM_MALFORMED_ATTRIBUTE_PATH_IB;
53-
break;
5442
}
43+
44+
*aError = CHIP_ERROR_IM_MALFORMED_ATTRIBUTE_PATH_IB;
45+
return nil;
46+
}
47+
{{/if}}
48+
{{/zcl_clusters}}
49+
50+
id _Nullable MTRDecodeAttributeValue(const ConcreteAttributePath & aPath, TLV::TLVReader & aReader, CHIP_ERROR * aError)
51+
{
52+
switch (aPath.mClusterId) {
53+
{{#zcl_clusters}}
54+
{{#if (isSupported (asUpperCamelCase name preserveAcronyms=true))}}
55+
case Clusters::{{asUpperCamelCase name}}::Id: {
56+
return DecodeAttributeValueFor{{asUpperCamelCase name preserveAcronyms=true}}Cluster(aPath.mAttributeId, aReader, aError);
57+
}
58+
{{/if}}
59+
{{/zcl_clusters}}
60+
default: {
61+
break;
62+
}
5563
}
64+
*aError = CHIP_ERROR_IM_MALFORMED_ATTRIBUTE_PATH_IB;
5665
return nil;
5766
}

src/darwin/Framework/CHIP/templates/MTREventTLVValueDecoder-src.zapt

+28-22
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,14 @@
1717
using namespace chip;
1818
using namespace chip::app;
1919

20-
id MTRDecodeEventPayload(const ConcreteEventPath & aPath, TLV::TLVReader & aReader, CHIP_ERROR * aError)
20+
{{#zcl_clusters}}
21+
{{#if (isSupported (asUpperCamelCase name preserveAcronyms=true))}}
22+
static id _Nullable DecodeEventPayloadFor{{asUpperCamelCase name preserveAcronyms=true}}Cluster(EventId aEventId, TLV::TLVReader & aReader, CHIP_ERROR * aError)
2123
{
22-
switch (aPath.mClusterId)
23-
{
24-
{{#zcl_clusters}}
25-
{{#if (isSupported (asUpperCamelCase name preserveAcronyms=true))}}
26-
case Clusters::{{asUpperCamelCase name}}::Id: {
27-
using namespace Clusters::{{asUpperCamelCase name}};
28-
switch (aPath.mEventId)
29-
{
24+
using namespace Clusters::{{asUpperCamelCase name}};
25+
switch (aEventId) {
3026
{{#zcl_events}}
3127
{{#if (isSupported (asUpperCamelCase ../name preserveAcronyms=true) event=(asUpperCamelCase name preserveAcronyms=true))}}
32-
3328
case Events::{{asUpperCamelCase name}}::Id: {
3429
Events::{{asUpperCamelCase name}}::DecodableType cppValue;
3530
*aError = DataModel::Decode(aReader, cppValue);
@@ -52,22 +47,33 @@ id MTRDecodeEventPayload(const ConcreteEventPath & aPath, TLV::TLVReader & aRead
5247

5348
return value;
5449
}
55-
5650
{{/if}}
5751
{{/zcl_events}}
58-
59-
default:
60-
*aError = CHIP_ERROR_IM_MALFORMED_EVENT_PATH_IB;
61-
break;
52+
default: {
53+
break;
6254
}
63-
break;
64-
}
65-
{{/if}}
66-
{{/zcl_clusters}}
67-
default: {
68-
*aError = CHIP_ERROR_IM_MALFORMED_EVENT_PATH_IB;
69-
break;
7055
}
56+
57+
*aError = CHIP_ERROR_IM_MALFORMED_EVENT_PATH_IB;
58+
return nil;
59+
}
60+
{{/if}}
61+
{{/zcl_clusters}}
62+
63+
id _Nullable MTRDecodeEventPayload(const ConcreteEventPath & aPath, TLV::TLVReader & aReader, CHIP_ERROR * aError)
64+
{
65+
switch (aPath.mClusterId) {
66+
{{#zcl_clusters}}
67+
{{#if (isSupported (asUpperCamelCase name preserveAcronyms=true))}}
68+
case Clusters::{{asUpperCamelCase name}}::Id: {
69+
return DecodeEventPayloadFor{{asUpperCamelCase name preserveAcronyms=true}}Cluster(aPath.mEventId, aReader, aError);
70+
}
71+
{{/if}}
72+
{{/zcl_clusters}}
73+
default: {
74+
break;
75+
}
7176
}
77+
*aError = CHIP_ERROR_IM_MALFORMED_EVENT_PATH_IB;
7278
return nil;
7379
}

0 commit comments

Comments
 (0)