Skip to content

Commit

Permalink
Enable ubsan in darwin unit tests. (#26467)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bzbarsky-apple authored and pull[bot] committed Oct 27, 2023
1 parent 3f12e53 commit 2430488
Show file tree
Hide file tree
Showing 9 changed files with 20,190 additions and 19,444 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

NS_ASSUME_NONNULL_BEGIN

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

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@

NS_ASSUME_NONNULL_BEGIN

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

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,12 @@
using namespace chip;
using namespace chip::app;

id MTRDecodeAttributeValue(const ConcreteAttributePath & aPath, TLV::TLVReader & aReader, CHIP_ERROR * aError)
{{#zcl_clusters}}
{{#if (isSupported (asUpperCamelCase name preserveAcronyms=true))}}
static id _Nullable DecodeAttributeValueFor{{asUpperCamelCase name preserveAcronyms=true}}Cluster(AttributeId aAttributeId, TLV::TLVReader & aReader, CHIP_ERROR * aError)
{
switch (aPath.mClusterId)
{
{{#zcl_clusters}}
{{#if (isSupported (asUpperCamelCase name preserveAcronyms=true))}}
case Clusters::{{asUpperCamelCase name}}::Id: {
using namespace Clusters::{{asUpperCamelCase name}};
switch (aPath.mAttributeId)
{
using namespace Clusters::{{asUpperCamelCase name}};
switch (aAttributeId) {
{{#zcl_attributes_server removeKeys='isOptional'}}
{{#if (isSupported (asUpperCamelCase ../name preserveAcronyms=true) attribute=(asUpperCamelCase name preserveAcronyms=true))}}
case Attributes::{{asUpperCamelCase name}}::Id: {
Expand All @@ -40,18 +36,31 @@ id MTRDecodeAttributeValue(const ConcreteAttributePath & aPath, TLV::TLVReader &
}
{{/if}}
{{/zcl_attributes_server}}
default:
*aError = CHIP_ERROR_IM_MALFORMED_ATTRIBUTE_PATH_IB;
break;
default: {
break;
}
break;
}
{{/if}}
{{/zcl_clusters}}
default: {
*aError = CHIP_ERROR_IM_MALFORMED_ATTRIBUTE_PATH_IB;
break;
}

*aError = CHIP_ERROR_IM_MALFORMED_ATTRIBUTE_PATH_IB;
return nil;
}
{{/if}}
{{/zcl_clusters}}

id _Nullable MTRDecodeAttributeValue(const ConcreteAttributePath & aPath, TLV::TLVReader & aReader, CHIP_ERROR * aError)
{
switch (aPath.mClusterId) {
{{#zcl_clusters}}
{{#if (isSupported (asUpperCamelCase name preserveAcronyms=true))}}
case Clusters::{{asUpperCamelCase name}}::Id: {
return DecodeAttributeValueFor{{asUpperCamelCase name preserveAcronyms=true}}Cluster(aPath.mAttributeId, aReader, aError);
}
{{/if}}
{{/zcl_clusters}}
default: {
break;
}
}
*aError = CHIP_ERROR_IM_MALFORMED_ATTRIBUTE_PATH_IB;
return nil;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,14 @@
using namespace chip;
using namespace chip::app;

id MTRDecodeEventPayload(const ConcreteEventPath & aPath, TLV::TLVReader & aReader, CHIP_ERROR * aError)
{{#zcl_clusters}}
{{#if (isSupported (asUpperCamelCase name preserveAcronyms=true))}}
static id _Nullable DecodeEventPayloadFor{{asUpperCamelCase name preserveAcronyms=true}}Cluster(EventId aEventId, TLV::TLVReader & aReader, CHIP_ERROR * aError)
{
switch (aPath.mClusterId)
{
{{#zcl_clusters}}
{{#if (isSupported (asUpperCamelCase name preserveAcronyms=true))}}
case Clusters::{{asUpperCamelCase name}}::Id: {
using namespace Clusters::{{asUpperCamelCase name}};
switch (aPath.mEventId)
{
using namespace Clusters::{{asUpperCamelCase name}};
switch (aEventId) {
{{#zcl_events}}
{{#if (isSupported (asUpperCamelCase ../name preserveAcronyms=true) event=(asUpperCamelCase name preserveAcronyms=true))}}

case Events::{{asUpperCamelCase name}}::Id: {
Events::{{asUpperCamelCase name}}::DecodableType cppValue;
*aError = DataModel::Decode(aReader, cppValue);
Expand All @@ -52,22 +47,33 @@ id MTRDecodeEventPayload(const ConcreteEventPath & aPath, TLV::TLVReader & aRead

return value;
}

{{/if}}
{{/zcl_events}}

default:
*aError = CHIP_ERROR_IM_MALFORMED_EVENT_PATH_IB;
break;
default: {
break;
}
break;
}
{{/if}}
{{/zcl_clusters}}
default: {
*aError = CHIP_ERROR_IM_MALFORMED_EVENT_PATH_IB;
break;
}

*aError = CHIP_ERROR_IM_MALFORMED_EVENT_PATH_IB;
return nil;
}
{{/if}}
{{/zcl_clusters}}

id _Nullable MTRDecodeEventPayload(const ConcreteEventPath & aPath, TLV::TLVReader & aReader, CHIP_ERROR * aError)
{
switch (aPath.mClusterId) {
{{#zcl_clusters}}
{{#if (isSupported (asUpperCamelCase name preserveAcronyms=true))}}
case Clusters::{{asUpperCamelCase name}}::Id: {
return DecodeEventPayloadFor{{asUpperCamelCase name preserveAcronyms=true}}Cluster(aPath.mEventId, aReader, aError);
}
{{/if}}
{{/zcl_clusters}}
default: {
break;
}
}
*aError = CHIP_ERROR_IM_MALFORMED_EVENT_PATH_IB;
return nil;
}
Loading

0 comments on commit 2430488

Please sign in to comment.