Skip to content

Commit 11c0af3

Browse files
authored
Add pigweed support for openiotsdk (project-chip#32488)
* Add pigweed support for openiotsdk * Review fixes
1 parent a6f3b37 commit 11c0af3

File tree

9 files changed

+134
-34
lines changed

9 files changed

+134
-34
lines changed

config/openiotsdk/chip-gn/.gn

+11
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import("//build_overrides/build.gni")
1616
import("//build_overrides/chip.gni")
17+
import("//build_overrides/pigweed.gni")
1718

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

2829
import("${chip_root}/config/openiotsdk/chip-gn/args.gni")
30+
31+
pw_sys_io_BACKEND = dir_pw_sys_io_stdio
32+
33+
pw_assert_BACKEND = dir_pw_assert_log
34+
pw_log_BACKEND = dir_pw_log_basic
35+
36+
pw_build_LINK_DEPS = [
37+
"$dir_pw_assert:impl",
38+
"$dir_pw_log:impl",
39+
]
2940
}

config/openiotsdk/chip-gn/BUILD.gn

+4-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ group("openiotsdk") {
1919
deps = [ "${chip_root}/src/lib" ]
2020

2121
if (chip_build_tests) {
22-
deps += [ "${chip_root}/src:tests" ]
22+
deps += [
23+
"${chip_root}/src:tests",
24+
"${chip_root}/src/lib/support:pw_tests_wrapper",
25+
]
2326
}
2427
}
2528

scripts/examples/openiotsdk_example.sh

+2
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ readarray -t SUPPORTED_APP_NAMES <"$CHIP_ROOT"/examples/platform/openiotsdk/supp
5353
SUPPORTED_APP_NAMES+=("unit-tests")
5454

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

5759
function show_usage() {
5860
cat <<EOF

src/BUILD.gn

+2-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,8 @@ if (chip_build_tests) {
144144
# TODO [PW_MIGRATION] Remove this if after migartion to PW_TEST is completed for all platforms
145145
# TODO [PW_MIGRATION] There will be a list of already migrated platforms
146146
if (chip_device_platform == "esp32" ||
147-
chip_device_platform == "nrfconnect") {
147+
chip_device_platform == "nrfconnect" ||
148+
chip_device_platform == "openiotsdk") {
148149
deps += [ "${chip_root}/src/lib/support:pw_tests_wrapper" ]
149150
}
150151
build_monolithic_library = true

src/test_driver/openiotsdk/unit-tests/CMakeLists.txt

+34-1
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,24 @@ include(toolchain)
3434

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

37+
3738
include(sdk)
3839
include(chip)
3940
include(linker)
4041

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

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

4548
target_compile_definitions(openiotsdk-startup
4649
PRIVATE
4750
IOT_SDK_APP_MAIN_STACK_SIZE=20480
4851
)
4952

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

63+
target_sources(${APP_TARGET}
64+
PRIVATE
65+
main/main_ns_nl.cpp
66+
)
67+
68+
target_link_libraries(${APP_TARGET}
69+
openiotsdk-startup
70+
openiotsdk-app
71+
)
72+
73+
# Link the *whole-archives* to keep the static test objects.
74+
target_link_options(${APP_TARGET}
75+
PUBLIC
76+
-Wl,--whole-archive "${CMAKE_CURRENT_BINARY_DIR}/chip_build/lib/lib${TEST_NAME}.a"
77+
-Wl,--no-whole-archive)
78+
79+
set_target_link(${APP_TARGET})
80+
sdk_post_build(${APP_TARGET})
81+
endforeach()
82+
83+
foreach(TEST_NAME IN LISTS TEST_NAMES_FROM_FILE)
84+
set(APP_TARGET ${TEST_NAME}_ns)
85+
add_executable(${APP_TARGET})
86+
target_include_directories(${APP_TARGET}
87+
PRIVATE
88+
main/include
89+
)
90+
5991
target_sources(${APP_TARGET}
6092
PRIVATE
6193
main/main_ns.cpp
@@ -70,6 +102,7 @@ foreach(TEST_NAME IN LISTS TEST_NAMES_FROM_FILE)
70102
target_link_options(${APP_TARGET}
71103
PUBLIC
72104
-Wl,--whole-archive "${CMAKE_CURRENT_BINARY_DIR}/chip_build/lib/lib${TEST_NAME}.a"
105+
"${CMAKE_CURRENT_BINARY_DIR}/chip_build/lib/libPWTestsWrapper.a"
73106
-Wl,--no-whole-archive)
74107

75108
set_target_link(${APP_TARGET})

src/test_driver/openiotsdk/unit-tests/main/main_ns.cpp

+2-7
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,9 @@
2020
#include <stdlib.h>
2121

2222
#include "openiotsdk_platform.h"
23-
#include <NlTestLogger.h>
24-
#include <lib/support/UnitTestRegistration.h>
23+
#include <lib/support/UnitTest.h>
2524
#include <platform/CHIPDeviceLayer.h>
2625

27-
constexpr nl_test_output_logger_t NlTestLogger::nl_test_logger;
28-
2926
using namespace ::chip;
3027

3128
int main()
@@ -36,8 +33,6 @@ int main()
3633
return EXIT_FAILURE;
3734
}
3835

39-
nlTestSetLogger(&NlTestLogger::nl_test_logger);
40-
4136
ChipLogAutomation("Open IoT SDK unit-tests start");
4237

4338
if (openiotsdk_network_init(true))
@@ -47,7 +42,7 @@ int main()
4742
}
4843

4944
ChipLogAutomation("Open IoT SDK unit-tests run...");
50-
int status = RunRegisteredUnitTests();
45+
int status = chip::test::RunAllTests();
5146
ChipLogAutomation("Test status: %d", status);
5247
ChipLogAutomation("Open IoT SDK unit-tests completed");
5348

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
*
3+
* Copyright (c) 2024 Project CHIP Authors
4+
* All rights reserved.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
#include <cstdio>
20+
#include <cstdlib>
21+
22+
#include "openiotsdk_platform.h"
23+
#include <NlTestLogger.h>
24+
#include <lib/support/UnitTestRegistration.h>
25+
#include <platform/CHIPDeviceLayer.h>
26+
27+
constexpr nl_test_output_logger_t NlTestLogger::nl_test_logger;
28+
29+
using namespace ::chip;
30+
31+
int main()
32+
{
33+
if (openiotsdk_platform_init())
34+
{
35+
ChipLogAutomation("ERROR: Open IoT SDK platform initialization failed");
36+
return EXIT_FAILURE;
37+
}
38+
39+
nlTestSetLogger(&NlTestLogger::nl_test_logger);
40+
41+
ChipLogAutomation("Open IoT SDK unit-tests start");
42+
43+
if (openiotsdk_network_init(true))
44+
{
45+
ChipLogAutomation("ERROR: Network initialization failed");
46+
return EXIT_FAILURE;
47+
}
48+
49+
ChipLogAutomation("Open IoT SDK unit-tests run...");
50+
int status = RunRegisteredUnitTests();
51+
ChipLogAutomation("Test status: %d", status);
52+
ChipLogAutomation("Open IoT SDK unit-tests completed");
53+
54+
return EXIT_SUCCESS;
55+
}
Original file line numberDiff line numberDiff line change
@@ -1,24 +0,0 @@
1-
accesstest
2-
AppTests
3-
ASN1Tests
4-
BDXTests
5-
ChipCryptoTests
6-
CoreTests
7-
CredentialsTest
8-
DataModelTests
9-
InetLayerTests
10-
MdnsTests
11-
MessagingLayerTests
12-
MinimalMdnsCoreTests
13-
MinimalMdnsRecordsTests
14-
MinimalMdnsRespondersTests
15-
PlatformTests
16-
RawTransportTests
17-
RetransmitTests
18-
SecureChannelTests
19-
SetupPayloadTests
20-
SupportTests
21-
SystemLayerTests
22-
TestShell
23-
TransportLayerTests
24-
UserDirectedCommissioningTests
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
accesstest
2+
AppTests
3+
ASN1Tests
4+
BDXTests
5+
ChipCryptoTests
6+
CoreTests
7+
CredentialsTest
8+
DataModelTests
9+
InetLayerTests
10+
MdnsTests
11+
MessagingLayerTests
12+
MinimalMdnsCoreTests
13+
MinimalMdnsRecordsTests
14+
MinimalMdnsRespondersTests
15+
PlatformTests
16+
RawTransportTests
17+
RetransmitTests
18+
SecureChannelTests
19+
SetupPayloadTests
20+
SupportTests
21+
SystemLayerTests
22+
TestShell
23+
TransportLayerTests
24+
UserDirectedCommissioningTests

0 commit comments

Comments
 (0)