Skip to content

Commit

Permalink
Merge branch 'master' into silabs/add_air_quality_app
Browse files Browse the repository at this point in the history
  • Loading branch information
Sarthak-Shaha authored Sep 11, 2024
2 parents c2b1ff6 + b2685cb commit ccc0e3d
Show file tree
Hide file tree
Showing 51 changed files with 2,126 additions and 120 deletions.
1 change: 1 addition & 0 deletions .github/.wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,7 @@ fsync
ftd
fullclean
fuzzer
fuzzers
fuzztest
FW
gbl
Expand Down
7 changes: 3 additions & 4 deletions .github/workflows/darwin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,9 @@ jobs:
run: |
scripts/examples/gn_build_example.sh examples/ota-requestor-app/linux out/debug/ota-requestor-app chip_config_network_layer_ble=false non_spec_compliant_ota_action_delay_floor=0
- name: Run Framework Tests
# For now disable unguarded-availability-new warnings because we
# internally use APIs that we are annotating as only available on
# new enough versions. Maybe we should change out deployment
# target versions instead?
# We want to ensure that our log upload runs on timeout, so use a timeout here shorter
# than the 6-hour overall job timeout. 4.5 hours should be plenty.
timeout-minutes: 270
working-directory: src/darwin/Framework
run: |
mkdir -p /tmp/darwin/framework-tests
Expand Down
54 changes: 54 additions & 0 deletions .github/workflows/examples-nxp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,60 @@ jobs:
if: ${{ !env.ACT }}
with:
platform-name: K32W1
mcxw71:
name: MCXW71

env:
BUILD_TYPE: gn_k32w

runs-on: ubuntu-latest
if: github.actor != 'restyled-io[bot]'

container:
image: ghcr.io/project-chip/chip-build-nxp:71
volumes:
- "/tmp/bloat_reports:/tmp/bloat_reports"
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Checkout submodules & Bootstrap
uses: ./.github/actions/checkout-submodules-and-bootstrap
with:
platform: nxp
extra-submodule-parameters: --recursive

- name: Set up environment for size reports
uses: ./.github/actions/setup-size-reports
if: ${{ !env.ACT }}
with:
gh-context: ${{ toJson(github) }}

- name: Build examples
run: |
scripts/run_in_build_env.sh "\
./scripts/build/build_examples.py \
--target nxp-mcxw71-freertos-lighting \
--target nxp-mcxw71-freertos-contact-sensor-low-power \
build \
--copy-artifacts-to out/artifacts \
"
- name: Get lighting app size stats
run: |
.environment/pigweed-venv/bin/python3 scripts/tools/memory/gh_sizes.py \
nxp mcxw71+release light \
out/artifacts/nxp-mcxw71-freertos-lighting/chip-mcxw71-light-example.elf \
/tmp/bloat_reports/
- name: Get contact sensor size stats
run: |
.environment/pigweed-venv/bin/python3 scripts/tools/memory/gh_sizes.py \
nxp mcxw71+release contact \
out/artifacts/nxp-mcxw71-freertos-contact-sensor-low-power/chip-mcxw71-contact-example.elf \
/tmp/bloat_reports/
- name: Uploading Size Reports
uses: ./.github/actions/upload-size-reports
if: ${{ !env.ACT }}
with:
platform-name: MCXW71
rw61x:
name: RW61X

Expand Down
16 changes: 10 additions & 6 deletions docs/guides/nxp/nxp_manufacturing_flow.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ Here is the interpretation of the **optional** parameters:
--unique_id -> Unique id used for rotating device id generation
--product_finish -> Visible finish of the product
--product_primary_color -> Representative color of the visible parts of the product
--hw_params -> Use application factory data from Hardware Parameters component
```

## 3. Write provisioning data
Expand All @@ -144,15 +145,12 @@ DK6Programmer.exe -Y -V2 -s <COM_PORT> -P 1000000 -Y -p FLASH@0x9D600="factory_d
```

For **K32W1** platform, the binary needs to be written in the internal flash at
location given by `__MATTER_FACTORY_DATA_START`, using `JLink`:
location given by **0xFE080**, using `JLink`:

```
loadfile factory_data.bin 0xf4000
loadfile factory_data.bin 0xFE080
```

where `0xf4000` is the value of `__MATTER_FACTORY_DATA_START` in the
corresponding .map file (can be different if using a custom linker script).

For **RW61X** platform, the binary needs to be written in the internal flash at
location given by `__MATTER_FACTORY_DATA_START`, using `JLink`:

Expand Down Expand Up @@ -208,7 +206,7 @@ Also, demo **DAC**, **PAI** and **PAA** certificates needed in case

Supported platforms:

- K32W1 - `src/plaftorm/nxp/k32w/k32w1/FactoryDataProviderImpl.h`
- K32W1 - `src/plaftorm/nxp/k32w1/FactoryDataProviderImpl.h`

For platforms that have a secure subsystem (`SSS`), the DAC private key can be
converted to an encrypted blob. This blob will overwrite the DAC private key in
Expand All @@ -219,6 +217,12 @@ The application will check at initialization whether the DAC private key has
been converted or not and convert it if needed. However, the conversion process
should be done at manufacturing time for security reasons.

Reference factory data generation command:

```shell
python3 ./scripts/tools/nxp/factory_data_generator/generate.py -i 10000 -s UXKLzwHdN3DZZLBaL2iVGhQi/OoQwIwJRQV4rpEalbA= -p 14014 -d 1000 --vid "0x1037" --pid "0xA221" --vendor_name "NXP Semiconductors" --product_name "Lighting app" --serial_num "12345678" --date "2023-01-01" --hw_version 1 --hw_version_str "1.0" --cert_declaration ./Chip-Test-CD-1037-A221.der --dac_cert ./Chip-DAC-NXP-1037-A221-Cert.der --dac_key ./Chip-DAC-NXP-1037-A221-Key.der --pai_cert ./Chip-PAI-NXP-1037-A221-Cert.der --spake2p_path ./out/spake2p --unique_id "00112233445566778899aabbccddeeff" --hw_params --out ./factory_data.bin
```

There is no need for an extra binary.

- Write factory data binary.
Expand Down
108 changes: 107 additions & 1 deletion docs/testing/fuzz_testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,119 @@
thousands of different inputs.
- Fuzz testing is often done with sanitizers enabled; to catch memory errors
and undefined behavior.
- The most commonly used fuzz testing frameworks for C/C++ are LibFuzzer and
- The most commonly used fuzz testing frameworks for C/C++ are libFuzzer and
AFL.
- [Google's FuzzTest](https://github.com/google/fuzztest) is a newer framework
that simplifies writing fuzz tests with user-friendly APIs and offers more
control over input generation. It also integrates seamlessly with Google
Test (GTest).

## Fuzz testing with libFuzzer

The following example demonstrates how to use libFuzzer to write a simple fuzz
test. Each fuzzer function is defined using
`LLVMFuzzerTestOneInput(const uint8_t * data, size_t len)`.

The Fuzzer must be located in a Test Folder : `src/some_directory/tests/`

```
#include <cstddef>
#include <cstdint>
/**
* @file
* This file describes a Fuzzer for ...
*/
extern "C" int LLVMFuzzerTestOneInput(const uint8_t * data, size_t len)
{
// Instantiate values as needed
// Call target function for the fuzzer with the fuzzing input (data and len)
return 0;
}
```

See
[FuzzBase38Decode.cpp](https://github.com/project-chip/connectedhomeip/blob/master/src/setup_payload/tests/FuzzBase38Decode.cpp)
for an example of a simple fuzz test.

### Compiling and running

- Add to `src/some_directory/tests/BUILD.gn`

- Example

```
import("${chip_root}/build/chip/fuzz_test.gni")
if (enable_fuzz_test_targets) {
chip_fuzz_target("FuzzTargetName1") {
sources = [ "Fuzzer1.cpp" ]
public_deps = [
// Dependencies go here.
]
}
chip_fuzz_target("FuzzTargetName2") {
sources = [ "Fuzzer2.cpp" ]
public_deps = [
// Dependencies go here.
]
}
}
```

- CHIP_FUZZ_TARGET : the name of the fuzz target
- SOURCES : file in the test folder containing the fuzzer
implementation
- PUBLIC_DEPS : Code Dependencies needed to build fuzzer

- Another example:
[src/setup_payload/tests/BUILD.gn](https://github.com/project-chip/connectedhomeip/blob/b367512f519e5e109346e81a0d84fd85cd9192f7/src/setup_payload/tests/BUILD.gn#L43)

- Add to `src/BUILD.gn`

- Add the Fuzzing Target in this part of the code :
[src/BUILD.gn](https://github.com/project-chip/connectedhomeip/blob/b367512f519e5e109346e81a0d84fd85cd9192f7/BUILD.gn#L52)

- Add Fuzzing Target like that

```
if (enable_fuzz_test_targets) {
group("fuzz_tests") {
deps = [
"${chip_root}/src/credentials/tests:fuzz-chip-cert",
"${chip_root}/src/lib/core/tests:fuzz-tlv-reader",
"${chip_root}/src/lib/dnssd/minimal_mdns/tests:fuzz-minmdns-packet-parsing",
"${chip_root}/src/lib/format/tests:fuzz-payload-decoder",
"${chip_root}/src/setup_payload/tests:fuzz-setup-payload-base38",
"${chip_root}/src/setup_payload/tests:fuzz-setup-payload-base38-decode",
// ADD HERE YOUR FUZZING TARGET
"${chip_root}/some_directory/tests:FuzzTargetName"
]
}
}
```

- Build all fuzzers
```
./scripts/build/build_examples.py --target <host>-<compiler>-tests-asan-libfuzzer-clang build
```
e.g.
```
./scripts/build/build_examples.py --target darwin-arm64-tests-asan-libfuzzer-clang build
```
\*\* Make sure to put the right host and compiler
- Fuzzers binaries are compiled into:

- `out/<host>-<compiler>-tests-asan-libfuzzer-clang/tests`
- e.g. `darwin-arm64-tests-asan-libfuzzer-clang`

- Running the fuzzer with a corpus
- `path_to_fuzzer_in_test_folder path_to_corpus`

## `Google's FuzzTest`

- Google FuzzTest is integrated through Pigweed
Expand Down
15 changes: 15 additions & 0 deletions examples/chef/common/chef-operational-state-delegate-impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ void GenericOperationalStateDelegateImpl::HandlePauseStateCallback(GenericOperat
auto error = GetInstance()->SetOperationalState(to_underlying(OperationalState::OperationalStateEnum::kPaused));
if (error == CHIP_NO_ERROR)
{
GetInstance()->UpdateCountdownTimeFromDelegate();
err.Set(to_underlying(ErrorStateEnum::kNoError));
}
else
Expand All @@ -72,6 +73,7 @@ void GenericOperationalStateDelegateImpl::HandleResumeStateCallback(GenericOpera
auto error = GetInstance()->SetOperationalState(to_underlying(OperationalStateEnum::kRunning));
if (error == CHIP_NO_ERROR)
{
GetInstance()->UpdateCountdownTimeFromDelegate();
err.Set(to_underlying(ErrorStateEnum::kNoError));
}
else
Expand All @@ -95,6 +97,7 @@ void GenericOperationalStateDelegateImpl::HandleStartStateCallback(GenericOperat
auto error = GetInstance()->SetOperationalState(to_underlying(OperationalStateEnum::kRunning));
if (error == CHIP_NO_ERROR)
{
GetInstance()->UpdateCountdownTimeFromDelegate();
(void) DeviceLayer::SystemLayer().StartTimer(System::Clock::Seconds16(1), onOperationalStateTimerTick, this);
err.Set(to_underlying(ErrorStateEnum::kNoError));
}
Expand All @@ -112,6 +115,8 @@ void GenericOperationalStateDelegateImpl::HandleStopStateCallback(GenericOperati
{
(void) DeviceLayer::SystemLayer().CancelTimer(onOperationalStateTimerTick, this);

GetInstance()->UpdateCountdownTimeFromDelegate();

OperationalState::GenericOperationalError current_err(to_underlying(OperationalState::ErrorStateEnum::kNoError));
GetInstance()->GetCurrentOperationalError(current_err);

Expand Down Expand Up @@ -151,6 +156,11 @@ static void onOperationalStateTimerTick(System::Layer * systemLayer, void * data
delegate->mPausedTime++;
}
}
else if (!countdown_time.IsNull() && countdown_time.Value() <= 0)
{
OperationalState::GenericOperationalError noError(to_underlying(OperationalState::ErrorStateEnum::kNoError));
delegate->HandleStopStateCallback(noError);
}

if (state == OperationalState::OperationalStateEnum::kRunning || state == OperationalState::OperationalStateEnum::kPaused)
{
Expand All @@ -172,6 +182,11 @@ OperationalState::Instance * OperationalState::GetOperationalStateInstance()
return gOperationalStateInstance;
}

OperationalStateDelegate * OperationalState::GetOperationalStateDelegate()
{
return gOperationalStateDelegate;
}

void OperationalState::Shutdown()
{
if (gOperationalStateInstance != nullptr)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ class OperationalStateDelegate : public GenericOperationalStateDelegateImpl
};

Instance * GetOperationalStateInstance();
OperationalStateDelegate * GetOperationalStateDelegate();

void Shutdown();

Expand Down
1 change: 1 addition & 0 deletions examples/contact-sensor-app/nxp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ The example is based on:
## Supported devices

- [k32w1](k32w1/README.md)
- [mcxw71](mcxw71/README.md)

## Introduction

Expand Down
31 changes: 31 additions & 0 deletions examples/contact-sensor-app/nxp/mcxw71/.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Copyright (c) 2020-2024 Project CHIP Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import("//build_overrides/build.gni")

# The location of the build configuration file.
buildconfig = "${build_root}/config/BUILDCONFIG.gn"

# CHIP uses angle bracket includes.
check_system_includes = true

default_args = {
target_cpu = "arm"
target_os = "freertos"

import("//args.gni")

# Import default platform configs
import("${chip_root}/src/platform/nxp/mcxw71_k32w1/args.gni")
}
Loading

0 comments on commit ccc0e3d

Please sign in to comment.