Skip to content

Commit

Permalink
Add pigweed support for openiotsdk (project-chip#32488)
Browse files Browse the repository at this point in the history
* Add pigweed support for openiotsdk

* Review fixes
  • Loading branch information
jlatusek authored Mar 13, 2024
1 parent a6f3b37 commit 11c0af3
Show file tree
Hide file tree
Showing 9 changed files with 134 additions and 34 deletions.
11 changes: 11 additions & 0 deletions config/openiotsdk/chip-gn/.gn
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

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

# The location of the build configuration file.
buildconfig = "//build/config/BUILDCONFIG.gn"
Expand All @@ -26,4 +27,14 @@ default_args = {
target_os = "cmsis-rtos"

import("${chip_root}/config/openiotsdk/chip-gn/args.gni")

pw_sys_io_BACKEND = dir_pw_sys_io_stdio

pw_assert_BACKEND = dir_pw_assert_log
pw_log_BACKEND = dir_pw_log_basic

pw_build_LINK_DEPS = [
"$dir_pw_assert:impl",
"$dir_pw_log:impl",
]
}
5 changes: 4 additions & 1 deletion config/openiotsdk/chip-gn/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ group("openiotsdk") {
deps = [ "${chip_root}/src/lib" ]

if (chip_build_tests) {
deps += [ "${chip_root}/src:tests" ]
deps += [
"${chip_root}/src:tests",
"${chip_root}/src/lib/support:pw_tests_wrapper",
]
}
}

Expand Down
2 changes: 2 additions & 0 deletions scripts/examples/openiotsdk_example.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ readarray -t SUPPORTED_APP_NAMES <"$CHIP_ROOT"/examples/platform/openiotsdk/supp
SUPPORTED_APP_NAMES+=("unit-tests")

readarray -t TEST_NAMES <"$CHIP_ROOT"/src/test_driver/openiotsdk/unit-tests/test_components.txt
readarray -t TEST_NAMES_NL <"$CHIP_ROOT"/src/test_driver/openiotsdk/unit-tests/test_components_nl.txt
TEST_NAMES+=("${TEST_NAMES_NL[@]}")

function show_usage() {
cat <<EOF
Expand Down
3 changes: 2 additions & 1 deletion src/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ if (chip_build_tests) {
# TODO [PW_MIGRATION] Remove this if after migartion to PW_TEST is completed for all platforms
# TODO [PW_MIGRATION] There will be a list of already migrated platforms
if (chip_device_platform == "esp32" ||
chip_device_platform == "nrfconnect") {
chip_device_platform == "nrfconnect" ||
chip_device_platform == "openiotsdk") {
deps += [ "${chip_root}/src/lib/support:pw_tests_wrapper" ]
}
build_monolithic_library = true
Expand Down
35 changes: 34 additions & 1 deletion src/test_driver/openiotsdk/unit-tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,24 @@ include(toolchain)

project(chip-open-iot-sdk-unit-tests LANGUAGES C CXX ASM)


include(sdk)
include(chip)
include(linker)

add_subdirectory(${OPEN_IOT_SDK_EXAMPLE_COMMON}/app ./app_build)

file(STRINGS test_components.txt TEST_NAMES_FROM_FILE)
# TODO [PW_MIGRATION] Remove the following variable once the migration to pw_unit_test is complete.
file(STRINGS test_components_nl.txt TEST_NAMES_FROM_FILE_NL)

target_compile_definitions(openiotsdk-startup
PRIVATE
IOT_SDK_APP_MAIN_STACK_SIZE=20480
)

foreach(TEST_NAME IN LISTS TEST_NAMES_FROM_FILE)
# TODO [PW_MIGRATION] Remove the following targets once the migration to pw_unit_test is complete.
foreach(TEST_NAME IN LISTS TEST_NAMES_FROM_FILE_NL)
set(APP_TARGET ${TEST_NAME}_ns)
add_executable(${APP_TARGET})
target_include_directories(${APP_TARGET}
Expand All @@ -56,6 +60,34 @@ foreach(TEST_NAME IN LISTS TEST_NAMES_FROM_FILE)
${CHIP_ROOT}/third_party/nlunit-test/repo/src
)

target_sources(${APP_TARGET}
PRIVATE
main/main_ns_nl.cpp
)

target_link_libraries(${APP_TARGET}
openiotsdk-startup
openiotsdk-app
)

# Link the *whole-archives* to keep the static test objects.
target_link_options(${APP_TARGET}
PUBLIC
-Wl,--whole-archive "${CMAKE_CURRENT_BINARY_DIR}/chip_build/lib/lib${TEST_NAME}.a"
-Wl,--no-whole-archive)

set_target_link(${APP_TARGET})
sdk_post_build(${APP_TARGET})
endforeach()

foreach(TEST_NAME IN LISTS TEST_NAMES_FROM_FILE)
set(APP_TARGET ${TEST_NAME}_ns)
add_executable(${APP_TARGET})
target_include_directories(${APP_TARGET}
PRIVATE
main/include
)

target_sources(${APP_TARGET}
PRIVATE
main/main_ns.cpp
Expand All @@ -70,6 +102,7 @@ foreach(TEST_NAME IN LISTS TEST_NAMES_FROM_FILE)
target_link_options(${APP_TARGET}
PUBLIC
-Wl,--whole-archive "${CMAKE_CURRENT_BINARY_DIR}/chip_build/lib/lib${TEST_NAME}.a"
"${CMAKE_CURRENT_BINARY_DIR}/chip_build/lib/libPWTestsWrapper.a"
-Wl,--no-whole-archive)

set_target_link(${APP_TARGET})
Expand Down
9 changes: 2 additions & 7 deletions src/test_driver/openiotsdk/unit-tests/main/main_ns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,9 @@
#include <stdlib.h>

#include "openiotsdk_platform.h"
#include <NlTestLogger.h>
#include <lib/support/UnitTestRegistration.h>
#include <lib/support/UnitTest.h>
#include <platform/CHIPDeviceLayer.h>

constexpr nl_test_output_logger_t NlTestLogger::nl_test_logger;

using namespace ::chip;

int main()
Expand All @@ -36,8 +33,6 @@ int main()
return EXIT_FAILURE;
}

nlTestSetLogger(&NlTestLogger::nl_test_logger);

ChipLogAutomation("Open IoT SDK unit-tests start");

if (openiotsdk_network_init(true))
Expand All @@ -47,7 +42,7 @@ int main()
}

ChipLogAutomation("Open IoT SDK unit-tests run...");
int status = RunRegisteredUnitTests();
int status = chip::test::RunAllTests();
ChipLogAutomation("Test status: %d", status);
ChipLogAutomation("Open IoT SDK unit-tests completed");

Expand Down
55 changes: 55 additions & 0 deletions src/test_driver/openiotsdk/unit-tests/main/main_ns_nl.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
*
* Copyright (c) 2024 Project CHIP Authors
* All rights reserved.
*
* 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.
*/

#include <cstdio>
#include <cstdlib>

#include "openiotsdk_platform.h"
#include <NlTestLogger.h>
#include <lib/support/UnitTestRegistration.h>
#include <platform/CHIPDeviceLayer.h>

constexpr nl_test_output_logger_t NlTestLogger::nl_test_logger;

using namespace ::chip;

int main()
{
if (openiotsdk_platform_init())
{
ChipLogAutomation("ERROR: Open IoT SDK platform initialization failed");
return EXIT_FAILURE;
}

nlTestSetLogger(&NlTestLogger::nl_test_logger);

ChipLogAutomation("Open IoT SDK unit-tests start");

if (openiotsdk_network_init(true))
{
ChipLogAutomation("ERROR: Network initialization failed");
return EXIT_FAILURE;
}

ChipLogAutomation("Open IoT SDK unit-tests run...");
int status = RunRegisteredUnitTests();
ChipLogAutomation("Test status: %d", status);
ChipLogAutomation("Open IoT SDK unit-tests completed");

return EXIT_SUCCESS;
}
24 changes: 0 additions & 24 deletions src/test_driver/openiotsdk/unit-tests/test_components.txt
Original file line number Diff line number Diff line change
@@ -1,24 +0,0 @@
accesstest
AppTests
ASN1Tests
BDXTests
ChipCryptoTests
CoreTests
CredentialsTest
DataModelTests
InetLayerTests
MdnsTests
MessagingLayerTests
MinimalMdnsCoreTests
MinimalMdnsRecordsTests
MinimalMdnsRespondersTests
PlatformTests
RawTransportTests
RetransmitTests
SecureChannelTests
SetupPayloadTests
SupportTests
SystemLayerTests
TestShell
TransportLayerTests
UserDirectedCommissioningTests
24 changes: 24 additions & 0 deletions src/test_driver/openiotsdk/unit-tests/test_components_nl.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
accesstest
AppTests
ASN1Tests
BDXTests
ChipCryptoTests
CoreTests
CredentialsTest
DataModelTests
InetLayerTests
MdnsTests
MessagingLayerTests
MinimalMdnsCoreTests
MinimalMdnsRecordsTests
MinimalMdnsRespondersTests
PlatformTests
RawTransportTests
RetransmitTests
SecureChannelTests
SetupPayloadTests
SupportTests
SystemLayerTests
TestShell
TransportLayerTests
UserDirectedCommissioningTests

0 comments on commit 11c0af3

Please sign in to comment.