Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,39 @@ jobs:
# # objdirs are big; don't hold on to them too long.
# retention-days: 5

build_linux_otns:
name: Build on Linux (otns)

runs-on: ubuntu-latest
if: github.actor != 'restyled-io[bot]' && inputs.run-codeql != true

container:
image: ghcr.io/project-chip/chip-build:181

steps:
- name: Dump GitHub context
env:
GITHUB_CONTEXT: ${{ toJSON(github) }}
run: echo "$GITHUB_CONTEXT"
- name: Dump Concurrency context
env:
CONCURRENCY_CONTEXT: ${{ github.ref }}-${{ github.workflow }}-${{ (github.event_name == 'pull_request' && github.event.number) || (github.event_name == 'workflow_dispatch' && github.run_number) || github.sha }}
run: echo "$CONCURRENCY_CONTEXT"
- name: Checkout
uses: actions/checkout@v5
- name: Checkout submodules & Bootstrap
uses: ./.github/actions/checkout-submodules-and-bootstrap
with:
platform: linux

- name: Setup Build, Run Build and Run Tests
run: |
scripts/run_in_build_env.sh \
"./scripts/build/build_examples.py \
--target linux-x64-all-clusters-no-wifi-openthread-endpoint-otns-clang \
build
"

build_linux_python_lib:
name: Build on Linux (python_lib)

Expand Down
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,10 @@
url = https://github.com/openthread/ot-commissioner.git
platforms = linux
recursive = true
[submodule "third_party/ot-ns/repo"]
path = third_party/ot-ns/repo
url = https://github.com/openthread/ot-ns.git
platforms = linux
[submodule "third_party/uriparser/repo"]
path = third_party/uriparser/repo
url = https://github.com/uriparser/uriparser.git
Expand Down
33 changes: 33 additions & 0 deletions examples/all-clusters-app/linux/AppOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
#include <app/server/Server.h>
#include <system/SystemClock.h>

#if CHIP_ENABLE_OTNS
#include <openthread/platform/time.h>
#endif

#include <string>

using namespace chip::ArgParser;
Expand All @@ -44,6 +48,34 @@ constexpr uint16_t kOptionCrashFilePath = 0xFF05;
constexpr uint16_t kOptionUseMockClock = 0xFF06;

namespace {
#if CHIP_ENABLE_OTNS
struct MockClock : public ClockBase
{
public:
MockClock() : mRealClock(SystemClock()) { Clock::Internal::SetSystemClockForTesting(this); }
~MockClock() { Clock::Internal::SetSystemClockForTesting(&mRealClock); }

void SetUTCTime(Microseconds64 aOverride) { }

Microseconds64 GetMonotonicMicroseconds64() override { return Microseconds64(otPlatTimeGet()); }
Milliseconds64 GetMonotonicMilliseconds64() override { return std::chrono::duration_cast<Milliseconds64>(Microseconds64(otPlatTimeGet())); }

CHIP_ERROR GetClock_RealTime(Microseconds64 & aCurTime) override
{
aCurTime = Microseconds64(otPlatTimeGet());
return CHIP_NO_ERROR;
}
CHIP_ERROR GetClock_RealTimeMS(Milliseconds64 & aCurTime) override
{
aCurTime = std::chrono::duration_cast<Milliseconds64>(Microseconds64(otPlatTimeGet()));
return CHIP_NO_ERROR;
}
Comment on lines +60 to +72

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

There's some code duplication in the MockClock implementation. The same call to otPlatTimeGet() and the same duration_cast logic are repeated across multiple methods. You can improve readability and maintainability by reusing the GetMonotonic... methods within the GetClock_RealTime... methods.

    Microseconds64 GetMonotonicMicroseconds64() override { return Microseconds64(otPlatTimeGet()); }
    Milliseconds64 GetMonotonicMilliseconds64() override { return std::chrono::duration_cast<Milliseconds64>(GetMonotonicMicroseconds64()); }

    CHIP_ERROR GetClock_RealTime(Microseconds64 & aCurTime) override
    {
        aCurTime = GetMonotonicMicroseconds64();
        return CHIP_NO_ERROR;
    }
    CHIP_ERROR GetClock_RealTimeMS(Milliseconds64 & aCurTime) override
    {
        aCurTime = GetMonotonicMilliseconds64();
        return CHIP_NO_ERROR;
    }
References
  1. To improve maintainability and reduce code duplication, extract common logic from similar methods into private helper functions.

CHIP_ERROR SetClock_RealTime(Microseconds64 aNewCurTime) override { return CHIP_ERROR_NOT_IMPLEMENTED; }

private:
ClockBase & mRealClock;
};
#else
struct MockClock : public ClockBase
{
private:
Expand Down Expand Up @@ -95,6 +127,7 @@ struct MockClock : public ClockBase
ClockBase & mRealClock;
Offset mOffset;
};
#endif

} // namespace

Expand Down
19 changes: 19 additions & 0 deletions examples/chip-tool/args.gni
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,23 @@ matter_log_json_payload_decode_full = true
# make chip-tool very strict by default
chip_tlv_validate_char_string_on_read = true
chip_tlv_validate_char_string_on_write = true

_openthread_config_file =
rebase_path(
get_path_info("${chip_root}/third_party/openthread/openthread-config.h",
"abspath"))
openthread_config_file = "\"$_openthread_config_file\""
openthread_config_ecdsa_enable = true
openthread_config_ip6_slaac_enable = true
openthread_config_full_logs = true
openthread_config_joiner_enable = true
openthread_config_log_output = "platform_defined"
openthread_config_srp_client_enable = true
openthread_config_tcp_enable = false
openthread_config_tmf_netdata_service_enable = true
openthread_enable_core_config_args = true
openthread_project_core_config_file = rebase_path(
get_path_info(
"${chip_root}/third_party/openthread/repo/examples/platforms/simulation/openthread-core-simulation-config.h",
"abspath"))
chip_support_thread_meshcop = true
9 changes: 9 additions & 0 deletions examples/chip-tool/commands/common/Command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ static bool ParseAddressWithInterface(const char * addressString, Command::Addre
return false;
}

#if CHIP_SYSTEM_CONFIG_USE_SOCKETS || CHIP_SYSTEM_CONFIG_USE_NETWORK_FRAMEWORK
if (result->ai_family == AF_INET6)
{
struct sockaddr_in6 * addr = reinterpret_cast<struct sockaddr_in6 *>(result->ai_addr);
Expand All @@ -201,6 +202,14 @@ static bool ParseAddressWithInterface(const char * addressString, Command::Addre
}

return true;
#else
if (!::chip::Inet::IPAddress::FromString(addressString, address->address))
{
return false;
}
address->interfaceId = chip::Inet::InterfaceId::Null();
return true;
#endif
}

// The callback should return whether the argument is valid, for the non-null
Expand Down
22 changes: 15 additions & 7 deletions examples/platform/linux/AppMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
* limitations under the License.
*/

#include <sstream>
#include <string>
#include <vector>

#include <platform/CHIPDeviceLayer.h>
#include <platform/PlatformManager.h>
Expand Down Expand Up @@ -153,6 +155,7 @@
#include <inet/EndPointStateOpenThread.h>
#include <openthread-system.h>
#include <openthread/instance.h>
extern "C" void otAppCliInit(otInstance * aInstance);
#endif

using namespace chip;
Expand Down Expand Up @@ -257,7 +260,7 @@ void InitNetworkCommissioning()
bool isThreadEnabled = false;
#if CHIP_APP_MAIN_HAS_THREAD_DRIVER
#if CHIP_SYSTEM_CONFIG_USE_OPENTHREAD_ENDPOINT
isThreadEnabled = LinuxDeviceOptions::GetInstance().mThreadNodeId > 0;
isThreadEnabled = LinuxDeviceOptions::GetInstance().mThreadArgs.size() > 0;
#else
isThreadEnabled = LinuxDeviceOptions::GetInstance().mThread;
#endif
Expand Down Expand Up @@ -739,15 +742,20 @@ int ChipLinuxAppInit(int argc, char * const argv[], OptionSet * customOptions,

#if CHIP_ENABLE_OPENTHREAD
#if CHIP_SYSTEM_CONFIG_USE_OPENTHREAD_ENDPOINT
if (LinuxDeviceOptions::GetInstance().mThreadNodeId)
if (LinuxDeviceOptions::GetInstance().mThreadArgs.size())
{
std::string nodeid = std::to_string(LinuxDeviceOptions::GetInstance().mThreadNodeId);
std::string logfile = "--log-file=thread.log";
char * args[] = { argv[0], logfile.data(), nodeid.data() };

otSysInit(MATTER_ARRAY_SIZE(args), args);
std::vector<char *> args;
args.push_back(argv[0]);
for (auto & arg : LinuxDeviceOptions::GetInstance().mThreadArgs)
{
args.push_back(arg.data());
}
otSysInit(static_cast<int>(args.size()), args.data());
SuccessOrExit(err = DeviceLayer::ThreadStackMgrImpl().InitThreadStack());
SuccessOrExit(err = DeviceLayer::ThreadStackMgrImpl().StartThreadTask());
#if CHIP_ENABLE_OTNS
otAppCliInit(otInstanceGetSingle());
#endif
ChipLogProgress(NotSpecified, "Thread initialized.");
}
#else
Expand Down
12 changes: 11 additions & 1 deletion examples/platform/linux/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@
# limitations under the License.

import("//build_overrides/chip.gni")
import("//build_overrides/openthread.gni")
import("${chip_root}/examples/common/pigweed/pigweed_rpcs.gni")
import("${chip_root}/src/app/common_flags.gni")
import("${chip_root}/src/app/icd/icd.gni")
import("${chip_root}/src/crypto/crypto.gni")
import("${chip_root}/src/lib/core/core.gni")
import("${chip_root}/src/lib/lib.gni")
import("${chip_root}/src/platform/device.gni")
import("${chip_root}/src/system/system.gni")
import("${chip_root}/src/tracing/tracing_args.gni")

Expand Down Expand Up @@ -253,7 +255,15 @@ source_set("app-main") {
]

if (chip_system_config_use_openthread_inet_endpoints) {
deps += [ "${chip_root}/third_party/openthread/platforms/simulation" ]
if (chip_enable_otns) {
deps += [
"${chip_root}/third_party/openthread:openthread_cli",
"${chip_root}/third_party/openthread/platforms/otns",
"${openthread_root}/examples/apps/cli:cli_uart",
]
} else {
deps += [ "${chip_root}/third_party/openthread/platforms/simulation" ]
}
}
public_configs = [ ":app-main-config" ]
}
Expand Down
15 changes: 6 additions & 9 deletions examples/platform/linux/Options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ enum
kDeviceOption_Command,
kDeviceOption_PICS,
kDeviceOption_KVS,
kDeviceOption_ThreadArgs,
kDeviceOption_InterfaceId,
kDeviceOption_AppPipe,
kDeviceOption_AppPipeOut,
Expand Down Expand Up @@ -177,7 +178,7 @@ OptionDef sDeviceOptionDefs[] = {
#endif // CHIP_DEVICE_CONFIG_ENABLE_WIFI
#if CHIP_ENABLE_OPENTHREAD
#if CHIP_SYSTEM_CONFIG_USE_OPENTHREAD_ENDPOINT
{ "thread-node-id", kArgumentRequired, kDeviceOption_ThreadNodeId },
{ "thread-args", kArgumentRequired, kDeviceOption_ThreadArgs },
#else
{ "thread", kNoArgument, kDeviceOption_Thread },
#endif
Expand Down Expand Up @@ -292,8 +293,8 @@ const char * sDeviceOptionHelp =
#if CHIP_ENABLE_OPENTHREAD
#if CHIP_SYSTEM_CONFIG_USE_OPENTHREAD_ENDPOINT
"\n"
" --thread-node-id <node id>\n"
" Enable Thread Simulation with the specified node id.\n"
" --thread-args <arg>\n"
" Enable Thread with the specified arguments.\n"
#else
" --thread\n"
" Enable Thread management via ot-agent.\n"
Expand Down Expand Up @@ -568,12 +569,8 @@ bool HandleOption(const char * aProgram, OptionSet * aOptions, int aIdentifier,

#if CHIP_ENABLE_OPENTHREAD
#if CHIP_SYSTEM_CONFIG_USE_OPENTHREAD_ENDPOINT
case kDeviceOption_ThreadNodeId:
if (!ParseInt(aValue, LinuxDeviceOptions::GetInstance().mThreadNodeId))
{
PrintArgError("%s: invalid value specified for Thread node id: %s\n", aProgram, aValue);
retval = false;
}
case kDeviceOption_ThreadArgs:
LinuxDeviceOptions::GetInstance().mThreadArgs.push_back(aValue);
break;
#else
case kDeviceOption_Thread:
Expand Down
2 changes: 1 addition & 1 deletion examples/platform/linux/Options.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ struct LinuxDeviceOptions
bool mWiFi = false;
#if CHIP_ENABLE_OPENTHREAD
#if CHIP_SYSTEM_CONFIG_USE_OPENTHREAD_ENDPOINT
uint16_t mThreadNodeId = 0;
std::vector<std::string> mThreadArgs;
#else
bool mThread = false;
#endif
Expand Down
1 change: 1 addition & 0 deletions scripts/build/build/targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ def BuildHostTarget():
target.AppendModifier("no-wifi", enable_wifi=False)
target.AppendModifier("no-thread", enable_thread=False)
target.AppendModifier("openthread-endpoint", openthread_endpoint=True)
target.AppendModifier("otns", enable_otns=True)
target.AppendModifier('nfc-commission', chip_enable_nfc_based_commissioning=True)
target.AppendModifier('no-shell', disable_shell=True)
target.AppendModifier(
Expand Down
16 changes: 15 additions & 1 deletion scripts/build/builders/host.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,8 +412,9 @@ def __init__(self, root, runner, app: HostApp, board=HostBoard.NATIVE,
enable_webrtc=False,
terms_and_conditions_required: Optional[bool] = None, chip_enable_nfc_based_commissioning=None,
openthread_endpoint=False,
unified=False,
enable_otns=False,
chip_enable_endpoint_unique_id: Optional[bool] = None,
unified=False
):
"""
Construct a host builder.
Expand Down Expand Up @@ -589,6 +590,19 @@ def __init__(self, root, runner, app: HostApp, board=HostBoard.NATIVE,

self.extra_gn_options.append('chip_system_config_use_openthread_inet_endpoints=true')

if enable_otns:
if not openthread_endpoint:
raise Exception("OpenThread EndPoint mode is required")

# if enable_ble:
# raise Exception("OTNS mode does not support BLE")

self.extra_gn_options.append('chip_logging_backend="syslog"')
self.extra_gn_options.append('chip_enable_otns=true')
self.extra_gn_options.append('import("//build_overrides/chip.gni")')
self.extra_gn_options.append(
'openthread_project_core_config_file=rebase_path(get_path_info("${chip_root}/third_party/ot-ns/repo/ot-rfsim/src/openthread-core-rfsim-config.h", "abspath"))')

if self.board == HostBoard.ARM64:
if not use_clang:
raise Exception("Cross compile only supported using clang")
Expand Down
2 changes: 1 addition & 1 deletion scripts/build/testdata/all_targets_linux_x64.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ efr32-{brd2601b,brd2605a,brd2703a,brd2704b,brd2708a,brd2911a,brd4186a,brd4186c,b
esp32-{c3devkit,devkitc,m5stack,p4functionev,qemu}-{all-clusters,all-clusters-minimal,all-devices,bridge,energy-gateway,evse,light,lock,ota-provider,ota-requestor,ota-requestor,shell,temperature-measurement,tests,water-heater}[-ipv6only][-rpc][-tracing]
genio-lighting-app
linux-fake-tests[-asan][-boringssl][-clang][-coverage][-dmalloc][-libfuzzer][-mbedtls][-ossfuzz][-pw-fuzztest][-tsan][-ubsan]
linux-{arm64,x64}-{address-resolve-tool,air-purifier,air-quality-sensor,all-clusters,all-clusters-minimal,all-devices,bridge,camera,camera-controller,chip-cert,chip-tool,closure,contact-sensor,dishwasher,energy-gateway,evse,fabric-admin,fabric-bridge,fabric-sync,java-matter-controller,jf-admin-app,jf-control-app,kotlin-matter-controller,light,light-data-model-no-unique-id,lit-icd,lock,microwave-oven,minmdns,network-manager,ota-provider,ota-requestor,python-bindings,refrigerator,rpc-console,rvc,shell,simulated-app1,simulated-app2,terms-and-conditions,tests,thermostat,tv-app,tv-casting-app,water-heater,water-leak-detector}[-asan][-boringssl][-chip-casting-simplified][-clang][-coverage][-disable-dnssd-tests][-dmalloc][-enable-dnssd-tests][-endpoint-unique-id][-evse-test-event][-googletest][-ipv6only][-libfuzzer][-libnl][-mbedtls][-minmdns-verbose][-nfc-commission][-nlfaultinject][-no-ble][-no-interactive][-no-shell][-no-thread][-no-wifi][-no-wifipaf][-nodeps][-openthread-endpoint][-ossfuzz][-platform-mdns][-pw-fuzztest][-rpc][-same-event-loop][-terms-and-conditions][-test][-tsan][-ubsan][-unified][-webrtc][-with-ui]
linux-{arm64,x64}-{address-resolve-tool,air-purifier,air-quality-sensor,all-clusters,all-clusters-minimal,all-devices,bridge,camera,camera-controller,chip-cert,chip-tool,closure,contact-sensor,dishwasher,energy-gateway,evse,fabric-admin,fabric-bridge,fabric-sync,java-matter-controller,jf-admin-app,jf-control-app,kotlin-matter-controller,light,light-data-model-no-unique-id,lit-icd,lock,microwave-oven,minmdns,network-manager,ota-provider,ota-requestor,python-bindings,refrigerator,rpc-console,rvc,shell,simulated-app1,simulated-app2,terms-and-conditions,tests,thermostat,tv-app,tv-casting-app,water-leak-detector}[-asan][-boringssl][-chip-casting-simplified][-clang][-coverage][-disable-dnssd-tests][-dmalloc][-enable-dnssd-tests][-evse-test-event][-googletest][-ipv6only][-libfuzzer][-libnl][-mbedtls][-minmdns-verbose][-nfc-commission][-nlfaultinject][-no-ble][-no-interactive][-no-shell][-no-thread][-no-wifi][-no-wifipaf][-nodeps][-openthread-endpoint][-ossfuzz][-otns][-platform-mdns][-pw-fuzztest][-rpc][-same-event-loop][-terms-and-conditions][-test][-tsan][-ubsan][-unified][-webrtc][-with-ui]
linux-x64-efr32-test-runner[-clang]
imx-{all-clusters-app,all-clusters-minimal-app,chip-tool,lighting-app,ota-provider-app,thermostat}[-ele][-release][-trusty]
infineon-psoc6-{all-clusters,all-clusters-minimal,light,lock}[-ota][-trustm][-updateimage]
Expand Down
4 changes: 2 additions & 2 deletions scripts/tests/chiptest/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

with python_path.PythonPath('../../../src/python_testing/matter_testing_infrastructure', relative_to=__file__):
# Import all symbols used downstream not only those we use ourselves
from matter.testing.tasks import SubprocessInfo, SubprocessKind # noqa: F401
from matter.testing.tasks import SubprocessInfo, SubprocessKind, ProcessConfigurator # noqa: F401


class LogPipe(threading.Thread):
Expand Down Expand Up @@ -200,7 +200,7 @@ def RunSubprocess(self, subproc: SubprocessInfo, name: str, wait: bool = True,
timeout_seconds: int | None = None,
stdin: IO[Any] | None = None) -> tuple[subprocess.Popen[bytes], LogPipe, LogPipe]:
cmd = subproc.to_cmd()
log.info('RunSubprocess starting application %s', " ".join(cmd))
log.error('RunSubprocess starting application %s', " ".join(cmd))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This log message appears to have been changed to error level, likely for debugging. This should be reverted to info or debug to avoid flooding the logs with errors during normal test execution.

Suggested change
log.error('RunSubprocess starting application %s', " ".join(cmd))
log.info('RunSubprocess starting application %s', " ".join(cmd))


outpipe = LogPipe(
logging.DEBUG, capture_delegate=self.capture_delegate,
Expand Down
Loading
Loading