From 84022933947e07b5d0694e19ed1acba3b91085ac Mon Sep 17 00:00:00 2001 From: Justin Wood Date: Fri, 4 Jun 2021 16:54:13 -0700 Subject: [PATCH] Create Tests workflow, will house certification tests (#7381) * Initial stab * Adding test runs * Removing this * Making this +x * Oops * Running all tests * Delete storage just inc ase * Trying to run this in darwin too * Moving darwin into tests * Testing out mbedtls * Fixing gStorage * Fixing quoting * Wait for pairing * next * Trying 0.0.0.0 * ::1 * Testing cache * Removing cache * IPv6 localhost for today * IPv6 localhost * Moving to this pin code * check validity of mTransportMgr * collect core dump * remove controller shutdown * delay controller shutdown in the test * restyled * Removing this, not needed anymore * Empty defines * Update scripts/tests/test_suites.sh Co-authored-by: Boris Zbarsky * Adding todos Co-authored-by: Pankaj Garg Co-authored-by: Boris Zbarsky --- .github/workflows/darwin.yaml | 5 +- .github/workflows/tests.yaml | 92 +++++++++++++++++++ .../chip-tool/commands/common/Commands.cpp | 9 +- .../chip-tool/commands/tests/TestCommand.cpp | 19 ++++ scripts/tests/test_suites.sh | 46 ++++++++++ src/transport/AdminPairingTable.h | 4 +- src/transport/SecureSessionMgr.cpp | 7 +- 7 files changed, 171 insertions(+), 11 deletions(-) create mode 100644 .github/workflows/tests.yaml create mode 100755 scripts/tests/test_suites.sh diff --git a/.github/workflows/darwin.yaml b/.github/workflows/darwin.yaml index d4539b652a5910..e6c3b803594cb6 100644 --- a/.github/workflows/darwin.yaml +++ b/.github/workflows/darwin.yaml @@ -84,12 +84,9 @@ jobs: - name: Delete Defaults run: defaults delete com.apple.dt.xctest.tool continue-on-error: true - - name: Run Tests + - name: Run Framework Tests timeout-minutes: 5 run: | ../../../out/debug/chip-all-clusters-app & xcodebuild test -target "CHIP" -scheme "CHIP Framework Tests" -sdk macosx working-directory: src/darwin/Framework - - name: Delete Defaults - run: defaults delete com.apple.dt.xctest.tool - continue-on-error: true diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml new file mode 100644 index 00000000000000..f1441f4fcd2b08 --- /dev/null +++ b/.github/workflows/tests.yaml @@ -0,0 +1,92 @@ +# Copyright (c) 2020-2021 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. + +name: Tests + +on: + push: + pull_request: + +jobs: + test_suites_linux: + name: Test Suites - Linux + timeout-minutes: 60 + + if: github.actor != 'restyled-io[bot]' + runs-on: ubuntu-latest + + container: + image: connectedhomeip/chip-build:latest + options: + --privileged --sysctl "net.ipv6.conf.all.disable_ipv6=0 + net.ipv4.conf.all.forwarding=1 net.ipv6.conf.all.forwarding=1" + + steps: + - name: Checkout + uses: actions/checkout@v2 + with: + submodules: true + - name: Bootstrap + timeout-minutes: 3 + run: scripts/build/gn_bootstrap.sh + - name: Build all clusters app + timeout-minutes: 5 + run: | + scripts/examples/gn_build_example.sh examples/all-clusters-app/linux out/debug chip_config_network_layer_ble=false + - name: Build chip-tool + timeout-minutes: 5 + run: | + scripts/examples/gn_build_example.sh examples/chip-tool out/debug/standalone/ + - name: Run Tests + timeout-minutes: 5 + run: | + ifconfig -a + scripts/tests/test_suites.sh + test_suites_darwin: + name: Test Suites - Darwin + timeout-minutes: 60 + + if: github.actor != 'restyled-io[bot]' + runs-on: macos-latest + + steps: + - name: Checkout + uses: actions/checkout@v2 + with: + submodules: true + - name: Setup Environment + run: brew install openssl pkg-config + - name: Fix pkgconfig link + working-directory: /usr/local/lib/pkgconfig + run: | + pwd + ls -la /usr/local/Cellar/ + ls -la /usr/local/Cellar/openssl@1.1 + OPEN_SSL_VERSION=`ls -la /usr/local/Cellar/openssl@1.1 | cat | tail -n1 | awk '{print $NF}'` + ln -s /usr/local/Cellar/openssl@1.1/$OPEN_SSL_VERSION/lib/pkgconfig/* . + - name: Bootstrap + timeout-minutes: 3 + run: scripts/build/gn_bootstrap.sh + - name: Run Build Test Server + timeout-minutes: 5 + run: | + scripts/examples/gn_build_example.sh examples/all-clusters-app/linux out/debug chip_config_network_layer_ble=false + - name: Build chip-tool + timeout-minutes: 5 + run: | + scripts/examples/gn_build_example.sh examples/chip-tool out/debug/standalone/ + - name: Run Test Suites + timeout-minutes: 5 + run: | + scripts/tests/test_suites.sh \ No newline at end of file diff --git a/examples/chip-tool/commands/common/Commands.cpp b/examples/chip-tool/commands/common/Commands.cpp index 604ded8655af05..89c4d46f74b5e9 100644 --- a/examples/chip-tool/commands/common/Commands.cpp +++ b/examples/chip-tool/commands/common/Commands.cpp @@ -38,10 +38,11 @@ void Commands::Register(const char * clusterName, commands_list commandsList) } } +// TODO: Remove this work around due to crashes when storage is accessed from multiple threads and passed around +static PersistentStorage gStorage; int Commands::Run(NodeId localId, NodeId remoteId, int argc, char ** argv) { CHIP_ERROR err = CHIP_NO_ERROR; - PersistentStorage storage; err = chip::Platform::MemoryInit(); VerifyOrExit(err == CHIP_NO_ERROR, ChipLogError(Controller, "Init Memory failure: %s", chip::ErrorStr(err))); @@ -51,12 +52,12 @@ int Commands::Run(NodeId localId, NodeId remoteId, int argc, char ** argv) SuccessOrExit(err = chip::DeviceLayer::Internal::BLEMgrImpl().ConfigureBle(/* BLE adapter ID */ 0, /* BLE central */ true)); #endif - err = storage.Init(); + err = gStorage.Init(); VerifyOrExit(err == CHIP_NO_ERROR, ChipLogError(Controller, "Init Storage failure: %s", chip::ErrorStr(err))); - chip::Logging::SetLogFilter(storage.GetLoggingLevel()); + chip::Logging::SetLogFilter(gStorage.GetLoggingLevel()); - err = RunCommand(storage, localId, remoteId, argc, argv); + err = RunCommand(gStorage, localId, remoteId, argc, argv); SuccessOrExit(err); exit: diff --git a/examples/chip-tool/commands/tests/TestCommand.cpp b/examples/chip-tool/commands/tests/TestCommand.cpp index 51b5192226c981..6550549af08c28 100644 --- a/examples/chip-tool/commands/tests/TestCommand.cpp +++ b/examples/chip-tool/commands/tests/TestCommand.cpp @@ -20,8 +20,22 @@ constexpr uint16_t kWaitDurationInSeconds = 30; +static void test_os_sleep_ms(uint64_t millisecs) +{ + struct timespec sleep_time; + uint64_t s = millisecs / 1000; + + millisecs -= s * 1000; + sleep_time.tv_sec = static_cast(s); + sleep_time.tv_nsec = static_cast(millisecs * 1000000); + + nanosleep(&sleep_time, nullptr); +} + CHIP_ERROR TestCommand::Run(PersistentStorage & storage, NodeId localId, NodeId remoteId) { + ReturnErrorOnFailure(mOpCredsIssuer.Initialize(storage)); + chip::Controller::CommissionerInitParams params; params.storageDelegate = &storage; @@ -38,6 +52,11 @@ CHIP_ERROR TestCommand::Run(PersistentStorage & storage, NodeId localId, NodeId WaitForResponse(kWaitDurationInSeconds); mCommissioner.ServiceEventSignal(); + + // Give some time for all the pending messages to flush before shutting down + // Note: This is working around racy code in message queues during shutdown + // TODO: Remove this workaround once we understand the message queue and shutdown race + test_os_sleep_ms(1000); mCommissioner.Shutdown(); VerifyOrReturnError(GetCommandExitStatus(), CHIP_ERROR_INTERNAL); diff --git a/scripts/tests/test_suites.sh b/scripts/tests/test_suites.sh new file mode 100755 index 00000000000000..e79da76be583e6 --- /dev/null +++ b/scripts/tests/test_suites.sh @@ -0,0 +1,46 @@ +#!/usr/bin/env bash + +# +# Copyright (c) 2020 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. +# + +set -e + +declare -a test_array="($(find src/app/tests/suites -type f -name "*.yaml" -exec basename {} .yaml \;))" + +echo "Found tests:" +for i in "${test_array[@]}"; do + echo " $i" +done +echo "" +echo "" + +for i in "${test_array[@]}"; do + echo " ===== Running test: $i" + echo " * Starting cluster server" + rm -rf /tmp/chip_tool_config.ini + sleep 1 + out/debug/chip-all-clusters-app & + background_pid=$! + sleep 1 + echo " * Pairing to device" + out/debug/standalone/chip-tool pairing onnetwork 1 20202021 3840 ::1 11097 + sleep 1 + echo " * Starting test run: $i" + out/debug/standalone/chip-tool tests "$i" + kill -9 "$background_pid" || true + echo " ===== Test complete: $i" + sleep 2 +done diff --git a/src/transport/AdminPairingTable.h b/src/transport/AdminPairingTable.h index 45079ef948e96b..98db42ab4134be 100644 --- a/src/transport/AdminPairingTable.h +++ b/src/transport/AdminPairingTable.h @@ -189,14 +189,14 @@ class DLL_EXPORT AdminPairingInfo uint64_t mFabricId; /* This field is serialized in LittleEndian byte order */ uint16_t mVendorId; /* This field is serialized in LittleEndian byte order */ - char mFabricLabel[kFabricLabelMaxLengthInBytes + 1] = { '\0' }; - uint16_t mRootCertLen; /* This field is serialized in LittleEndian byte order */ uint16_t mOpCertLen; /* This field is serialized in LittleEndian byte order */ Crypto::P256SerializedKeypair mOperationalKey; uint8_t mRootCert[kMaxChipCertSize]; uint8_t mOperationalCert[kMaxChipCertSize]; + + char mFabricLabel[kFabricLabelMaxLengthInBytes + 1] = { '\0' }; }; }; diff --git a/src/transport/SecureSessionMgr.cpp b/src/transport/SecureSessionMgr.cpp index d15a1b40fcc4d2..b94af40e5d32c4 100644 --- a/src/transport/SecureSessionMgr.cpp +++ b/src/transport/SecureSessionMgr.cpp @@ -202,11 +202,16 @@ CHIP_ERROR SecureSessionMgr::SendMessage(SecureSessionHandle session, PayloadHea ChipLogProgress(Inet, "Sending secure msg on connection specific transport"); err = state->GetTransport()->SendMessage(state->GetPeerAddress(), std::move(msgBuf)); } - else + else if (mTransportMgr != nullptr) { ChipLogProgress(Inet, "Sending secure msg on generic transport"); err = mTransportMgr->SendMessage(state->GetPeerAddress(), std::move(msgBuf)); } + else + { + ChipLogError(Inet, "The transport manager is not initialized. Unable to send the message"); + err = CHIP_ERROR_INCORRECT_STATE; + } ChipLogProgress(Inet, "Secure msg send status %s", ErrorStr(err)); SuccessOrExit(err);