Add pigweed support for openiotsdk (#32488)
* Add pigweed support for openiotsdk
* Review fixes
diff --git a/config/openiotsdk/chip-gn/.gn b/config/openiotsdk/chip-gn/.gn
index 4b9894b..f240423 100644
--- a/config/openiotsdk/chip-gn/.gn
+++ b/config/openiotsdk/chip-gn/.gn
@@ -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"
@@ -26,4 +27,14 @@
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",
+ ]
}
diff --git a/config/openiotsdk/chip-gn/BUILD.gn b/config/openiotsdk/chip-gn/BUILD.gn
index 6e6fb51..94e2f28 100644
--- a/config/openiotsdk/chip-gn/BUILD.gn
+++ b/config/openiotsdk/chip-gn/BUILD.gn
@@ -19,7 +19,10 @@
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",
+ ]
}
}
diff --git a/scripts/examples/openiotsdk_example.sh b/scripts/examples/openiotsdk_example.sh
index 36c748c..a4bfd93 100755
--- a/scripts/examples/openiotsdk_example.sh
+++ b/scripts/examples/openiotsdk_example.sh
@@ -53,6 +53,8 @@
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
diff --git a/src/BUILD.gn b/src/BUILD.gn
index 9b9e993..65614c6 100644
--- a/src/BUILD.gn
+++ b/src/BUILD.gn
@@ -144,7 +144,8 @@
# 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
diff --git a/src/test_driver/openiotsdk/unit-tests/CMakeLists.txt b/src/test_driver/openiotsdk/unit-tests/CMakeLists.txt
index 1cde881..10e55de 100644
--- a/src/test_driver/openiotsdk/unit-tests/CMakeLists.txt
+++ b/src/test_driver/openiotsdk/unit-tests/CMakeLists.txt
@@ -34,6 +34,7 @@
project(chip-open-iot-sdk-unit-tests LANGUAGES C CXX ASM)
+
include(sdk)
include(chip)
include(linker)
@@ -41,13 +42,16 @@
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}
@@ -58,6 +62,34 @@
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
)
@@ -70,6 +102,7 @@
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})
diff --git a/src/test_driver/openiotsdk/unit-tests/main/main_ns.cpp b/src/test_driver/openiotsdk/unit-tests/main/main_ns.cpp
index a819655..ec45046 100644
--- a/src/test_driver/openiotsdk/unit-tests/main/main_ns.cpp
+++ b/src/test_driver/openiotsdk/unit-tests/main/main_ns.cpp
@@ -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()
@@ -36,8 +33,6 @@
return EXIT_FAILURE;
}
- nlTestSetLogger(&NlTestLogger::nl_test_logger);
-
ChipLogAutomation("Open IoT SDK unit-tests start");
if (openiotsdk_network_init(true))
@@ -47,7 +42,7 @@
}
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");
diff --git a/src/test_driver/openiotsdk/unit-tests/main/main_ns_nl.cpp b/src/test_driver/openiotsdk/unit-tests/main/main_ns_nl.cpp
new file mode 100644
index 0000000..f7e511b
--- /dev/null
+++ b/src/test_driver/openiotsdk/unit-tests/main/main_ns_nl.cpp
@@ -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;
+}
diff --git a/src/test_driver/openiotsdk/unit-tests/test_components.txt b/src/test_driver/openiotsdk/unit-tests/test_components.txt
index 03fa4ae..e69de29 100644
--- a/src/test_driver/openiotsdk/unit-tests/test_components.txt
+++ b/src/test_driver/openiotsdk/unit-tests/test_components.txt
@@ -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
diff --git a/src/test_driver/openiotsdk/unit-tests/test_components_nl.txt b/src/test_driver/openiotsdk/unit-tests/test_components_nl.txt
new file mode 100644
index 0000000..03fa4ae
--- /dev/null
+++ b/src/test_driver/openiotsdk/unit-tests/test_components_nl.txt
@@ -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