Skip to content

Commit 4d02c01

Browse files
arkqaustina-csa
authored andcommitted
Adopt ESP32 test driver to pw_unit_test output (project-chip#34114)
* Adopt ESP32 test driver to pw_unit_test output * Link ESP32 tests with ToString(CHIP_ERROR, ...) wrapper * Fix segfault * Fix CHIP stack initialization when running tests * [ESP32] Do not delete default event loop The PlatformManagerImpl::_InitChipStack() does not create default event loop, so the PlatformManagerImpl::_Shutdown() shall not delete it. * Fix MultiBufferEncode test with pool allocator * Include TestWriterReserve test only for heap allocator * Disable buffer use check for LWIP pool
1 parent 3fe169d commit 4d02c01

15 files changed

+71
-36
lines changed

src/lib/support/BUILD.gn

+1
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,7 @@ pw_static_library("pw_tests_wrapper") {
350350
"$dir_pw_log:impl",
351351
"$dir_pw_unit_test",
352352
"$dir_pw_unit_test:logging",
353+
"${chip_root}/src/lib/core:string-builder-adapters",
353354
]
354355
sources = [
355356
"UnitTest.cpp",

src/platform/ESP32/PlatformManagerImpl.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ void PlatformManagerImpl::_Shutdown()
107107

108108
Internal::GenericPlatformManagerImpl_FreeRTOS<PlatformManagerImpl>::_Shutdown();
109109

110-
esp_event_loop_delete_default();
110+
esp_event_handler_unregister(IP_EVENT, ESP_EVENT_ANY_ID, PlatformManagerImpl::HandleESPSystemEvent);
111111
}
112112

113113
void PlatformManagerImpl::HandleESPSystemEvent(void * arg, esp_event_base_t eventBase, int32_t eventId, void * eventData)

src/system/SystemPacketBuffer.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,8 @@ PacketBufferHandle PacketBufferHandle::New(size_t aAvailableSize, uint16_t aRese
581581

582582
if (lAllocSize > PacketBuffer::kMaxAllocSize)
583583
{
584-
ChipLogError(chipSystemLayer, "PacketBuffer: allocation exceeding buffer capacity limits.");
584+
ChipLogError(chipSystemLayer, "PacketBuffer: allocation exceeding buffer capacity limits: %lu > %lu",
585+
static_cast<unsigned long>(lAllocSize), static_cast<unsigned long>(PacketBuffer::kMaxAllocSize));
585586
return PacketBufferHandle();
586587
}
587588

src/system/tests/BUILD.gn

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ chip_test_suite("tests") {
4646

4747
public_deps = [
4848
"${chip_root}/src/inet",
49+
"${chip_root}/src/lib/core:string-builder-adapters",
4950
"${chip_root}/src/lib/support/tests:pw-test-macros",
5051
"${chip_root}/src/platform",
5152
"${chip_root}/src/system",

src/system/tests/TestSystemClock.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@
1515
* limitations under the License.
1616
*/
1717

18-
#include <gtest/gtest.h>
18+
#include <pw_unit_test/framework.h>
1919

2020
#include <lib/core/ErrorStr.h>
21+
#include <lib/core/StringBuilderAdapters.h>
2122
#include <lib/support/CodeUtils.h>
2223
#include <lib/support/TimeUtils.h>
2324
#include <system/SystemClock.h>

src/system/tests/TestSystemErrorStr.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,11 @@
2828
#include <stdint.h>
2929
#include <string.h>
3030

31-
#include <gtest/gtest.h>
31+
#include <pw_unit_test/framework.h>
3232

3333
#include <inet/InetError.h>
3434
#include <lib/core/ErrorStr.h>
35+
#include <lib/core/StringBuilderAdapters.h>
3536
#include <lib/support/CodeUtils.h>
3637

3738
using namespace chip;

src/system/tests/TestSystemPacketBuffer.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@
3030
#include <utility>
3131
#include <vector>
3232

33-
#include <gtest/gtest.h>
33+
#include <pw_unit_test/framework.h>
3434

35+
#include <lib/core/StringBuilderAdapters.h>
3536
#include <lib/support/CHIPMem.h>
3637
#include <lib/support/CodeUtils.h>
3738
#include <lib/support/SafeInt.h>
@@ -323,6 +324,7 @@ TEST_F_FROM_FIXTURE(TestSystemPacketBuffer, CheckNew)
323324
}
324325
}
325326

327+
#if 0 // TODO: Fix this check on ESP32 (issue #34145)
326328
#if CHIP_SYSTEM_PACKETBUFFER_FROM_LWIP_POOL || CHIP_SYSTEM_PACKETBUFFER_FROM_CHIP_POOL
327329
// Use the rest of the buffer space
328330
std::vector<PacketBufferHandle> allocate_all_the_things;
@@ -337,6 +339,7 @@ TEST_F_FROM_FIXTURE(TestSystemPacketBuffer, CheckNew)
337339
allocate_all_the_things.push_back(std::move(buffer));
338340
}
339341
#endif // CHIP_SYSTEM_PACKETBUFFER_FROM_LWIP_POOL || CHIP_SYSTEM_PACKETBUFFER_FROM_CHIP_POOL
342+
#endif
340343
}
341344

342345
/**

src/system/tests/TestSystemScheduleLambda.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@
1414
* limitations under the License.
1515
*/
1616

17-
#include <gtest/gtest.h>
17+
#include <pw_unit_test/framework.h>
1818

1919
#include <lib/core/ErrorStr.h>
20+
#include <lib/core/StringBuilderAdapters.h>
2021
#include <lib/support/CodeUtils.h>
2122
#include <platform/CHIPDeviceLayer.h>
2223
#include <system/SystemConfig.h>

src/system/tests/TestSystemScheduleWork.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@
1414
* limitations under the License.
1515
*/
1616

17-
#include <gtest/gtest.h>
17+
#include <pw_unit_test/framework.h>
1818

1919
#include <lib/core/ErrorStr.h>
20+
#include <lib/core/StringBuilderAdapters.h>
2021
#include <lib/support/CodeUtils.h>
2122
#include <platform/CHIPDeviceLayer.h>
2223
#include <system/SystemConfig.h>

src/system/tests/TestSystemTimer.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@
2727
#include <stdint.h>
2828
#include <string.h>
2929

30-
#include <gtest/gtest.h>
30+
#include <pw_unit_test/framework.h>
3131

3232
#include <lib/core/ErrorStr.h>
33+
#include <lib/core/StringBuilderAdapters.h>
3334
#include <lib/support/CodeUtils.h>
3435
#include <system/SystemConfig.h>
3536
#include <system/SystemError.h>

src/system/tests/TestSystemWakeEvent.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@
2121
*
2222
*/
2323

24-
#include <gtest/gtest.h>
24+
#include <pw_unit_test/framework.h>
2525

2626
#include <lib/core/ErrorStr.h>
27+
#include <lib/core/StringBuilderAdapters.h>
2728
#include <lib/support/CodeUtils.h>
2829
#include <system/SystemConfig.h>
2930
#include <system/SystemError.h>

src/system/tests/TestTLVPacketBufferBackingStore.cpp

+26-12
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@
1818
#include <stdlib.h>
1919
#include <string.h>
2020

21-
#include <gtest/gtest.h>
21+
#include <pw_unit_test/framework.h>
2222

23+
#include <lib/core/StringBuilderAdapters.h>
2324
#include <lib/support/CHIPMem.h>
2425
#include <lib/support/ScopedBuffer.h>
2526
#include <lib/support/Span.h>
@@ -161,17 +162,28 @@ TEST_F(TestTLVPacketBufferBackingStore, MultiBufferEncode)
161162
// Third entry is 1 control byte, 2 length bytes, 2000 bytes of data,
162163
// for a total of 2009 bytes.
163164
constexpr size_t totalSize = 2009;
164-
EXPECT_TRUE(buffer->HasChainedBuffer());
165-
EXPECT_EQ(buffer->TotalLength(), totalSize);
166-
EXPECT_EQ(buffer->DataLength(), static_cast<size_t>(2));
167-
auto nextBuffer = buffer->Next();
168-
EXPECT_TRUE(nextBuffer->HasChainedBuffer());
169-
EXPECT_EQ(nextBuffer->TotalLength(), totalSize - 2);
170-
EXPECT_EQ(nextBuffer->DataLength(), PacketBuffer::kMaxSizeWithoutReserve);
171-
nextBuffer = nextBuffer->Next();
172-
EXPECT_FALSE(nextBuffer->HasChainedBuffer());
173-
EXPECT_EQ(nextBuffer->TotalLength(), nextBuffer->DataLength());
174-
EXPECT_EQ(nextBuffer->DataLength(), totalSize - 2 - PacketBuffer::kMaxSizeWithoutReserve);
165+
#if CHIP_SYSTEM_PACKETBUFFER_FROM_LWIP_STANDARD_POOL || CHIP_SYSTEM_PACKETBUFFER_FROM_CHIP_POOL
166+
// In case of pool allocation, the buffer size is always the maximum size.
167+
constexpr size_t bufferSizes[] = { PacketBuffer::kMaxSizeWithoutReserve, totalSize - PacketBuffer::kMaxSizeWithoutReserve };
168+
#elif CHIP_SYSTEM_PACKETBUFFER_FROM_CHIP_HEAP
169+
constexpr size_t bufferSizes[] = { 2, PacketBuffer::kMaxSizeWithoutReserve,
170+
totalSize - 2 - PacketBuffer::kMaxSizeWithoutReserve };
171+
#else
172+
// Skipping the test for other configurations because the allocation method is unknown.
173+
GTEST_SKIP();
174+
#endif
175+
size_t checkedSize = 0;
176+
auto bufferTmp = buffer.Retain();
177+
for (const auto size : bufferSizes)
178+
{
179+
ASSERT_FALSE(bufferTmp.IsNull());
180+
EXPECT_EQ(bufferTmp->TotalLength(), totalSize - checkedSize);
181+
EXPECT_EQ(bufferTmp->DataLength(), size);
182+
bufferTmp = bufferTmp->Next();
183+
checkedSize += size;
184+
}
185+
// There should be no more buffers.
186+
ASSERT_TRUE(bufferTmp.IsNull());
175187

176188
// PacketBufferTLVReader cannot handle non-contiguous buffers, and our
177189
// buffers are too big to stick into a single packet buffer.
@@ -298,6 +310,7 @@ TEST_F(TestTLVPacketBufferBackingStore, TestWriterReserveUnreserveDoesNotOverflo
298310
EXPECT_EQ(error, CHIP_ERROR_INCORRECT_STATE);
299311
}
300312

313+
#if CHIP_SYSTEM_PACKETBUFFER_FROM_CHIP_HEAP
301314
TEST_F(TestTLVPacketBufferBackingStore, TestWriterReserve)
302315
{
303316
// Start with a too-small buffer.
@@ -321,3 +334,4 @@ TEST_F(TestTLVPacketBufferBackingStore, TestWriterReserve)
321334
error = writer.Put(TLV::AnonymousTag(), static_cast<uint8_t>(7));
322335
EXPECT_EQ(error, CHIP_NO_ERROR);
323336
}
337+
#endif

src/system/tests/TestTimeSource.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@
2121
* the ability to compile and use the test implementation of the time source.
2222
*/
2323

24-
#include <gtest/gtest.h>
24+
#include <pw_unit_test/framework.h>
2525

2626
#include <lib/core/ErrorStr.h>
27+
#include <lib/core/StringBuilderAdapters.h>
2728
#include <lib/support/CodeUtils.h>
2829
#include <system/SystemConfig.h>
2930
#include <system/TimeSource.h>

src/test_driver/esp32/main/main_app.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,12 @@ extern "C" void app_main()
5656
exit(err);
5757
}
5858

59+
err = esp_event_loop_create_default();
60+
if (err != ESP_OK)
61+
{
62+
ESP_LOGE(TAG, "esp_event_loop_create_default() failed: %s", esp_err_to_name(err));
63+
exit(err);
64+
}
65+
5966
tester_task(nullptr);
6067
}

src/test_driver/esp32/run_qemu_image.py

+15-14
Original file line numberDiff line numberDiff line change
@@ -106,31 +106,32 @@ def main(log_level, no_log_timestamps, image, file_image_list, qemu, verbose):
106106

107107
# Parse output of the unit test. Generally expect things like:
108108
# I (3034) CHIP-tests: Starting CHIP tests!
109+
# INF [==========] Running all tests.
110+
# INF [ RUN ] TestASN1.NullWriter
111+
# INF [ OK ] TestASN1.NullWriter
109112
# ...
110-
# Various test lines, none ending with "] : FAILED"
111-
# ...
112-
# Failed Tests: 0 / 5
113-
# Failed Asserts: 0 / 77
114-
# I (3034) CHIP-tests: CHIP test status: 0
113+
# INF [ RUN ] TestASN1.ASN1UniversalTime
114+
# ERR src/lib/asn1/tests/TestASN1.cpp:366: Failure
115+
# ERR Expected: 1 == 5
116+
# ERR Actual: 1 == 5
117+
# ERR [ FAILED ] TestASN1.ASN1UniversalTime
118+
# INF [==========] Done running all tests.
119+
# INF [ PASSED ] 5 test(s).
120+
# ERR [ FAILED ] 1 test(s).
121+
# I (3034) CHIP-tests: CHIP test status: 1
115122
in_test = False
116123
for line in output.split('\n'):
117-
if line.endswith('CHIP-tests: Starting CHIP tests!'):
124+
if 'CHIP-tests: Starting CHIP tests!' in line:
118125
in_test = True
119126

120-
if line.startswith('Failed Tests:') and not line.startswith('Failed Tests: 0 /'):
121-
raise Exception("Tests seem failed: %s" % line)
122-
123-
if line.startswith('Failed Asserts:') and not line.startswith('Failed Asserts: 0 /'):
124-
raise Exception("Asserts seem failed: %s" % line)
125-
126127
if 'CHIP-tests: CHIP test status: 0' in line:
127128
in_test = False
128129
elif 'CHIP-tests: CHIP test status: ' in line:
129130
raise Exception("CHIP test status is NOT 0: %s" % line)
130131

131132
# Ignore FAILED messages not in the middle of a test, to reduce
132-
# the chance of false posisitves from other logging.
133-
if in_test and re.match('.*] : FAILED$', line):
133+
# the chance of false positives from other logging.
134+
if in_test and re.search(r' \[ FAILED \] ', line):
134135
raise Exception("Step failed: %s" % line)
135136

136137
# TODO: Figure out why exit(0) in man_app.cpp's tester_task is aborting and fix that.

0 commit comments

Comments
 (0)