Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3307356

Browse files
Added unit test for virtual destructors
The purpose of this tests is to hihglight the need for a virtualdestructor through valgrind unit test execution
1 parente97e5e2 commit3307356

File tree

5 files changed

+161
-0
lines changed

5 files changed

+161
-0
lines changed

‎test/CMakeLists.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ set(TEST_SRCS
112112
src/WCharacter/test_isUpperCase.cpp
113113
src/WCharacter/test_isWhitespace.cpp
114114
src/WCharacter/test_toAscii.cpp
115+
src/Interfaces/test_virtualDestructor.cpp
115116
)
116117

117118
set(TEST_DUT_SRCS

‎test/include/TCPClientMock.h‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright (c) 2020 Arduino. All rights reserved.
3+
*
4+
* SPDX-License-Identifier: LGPL-2.1-or-later
5+
*/
6+
7+
#ifndef TCPCLIENT_MOCK_H_
8+
#defineTCPCLIENT_MOCK_H_
9+
10+
/**************************************************************************************
11+
* INCLUDE
12+
**************************************************************************************/
13+
14+
#include<api/Client.h>
15+
16+
/**************************************************************************************
17+
* CLASS DECLARATION
18+
**************************************************************************************/
19+
20+
/*
21+
* The purpose of this class is currently to highlight the effects of lacking virtual destructor
22+
*/
23+
24+
#pragma GCC diagnostic push
25+
#pragma GCC diagnostic ignored "-Wunused-parameter"
26+
27+
classTCPClientMock :publicClient {
28+
public:
29+
virtualintconnect(IPAddress ip,uint16_t port) {return0; }
30+
virtualintconnect(constchar *host,uint16_t port) {return0; }
31+
virtualsize_twrite(uint8_t) {return0; }
32+
virtualsize_twrite(constuint8_t *buf,size_t size) {return0;}
33+
virtualintavailable() {return0; }
34+
virtualintread() {return0; }
35+
virtualintread(uint8_t *buf,size_t size) {return0;}
36+
virtualintpeek() {return0; }
37+
virtualvoidflush() {}
38+
virtualvoidstop() {}
39+
virtualuint8_tconnected() {return0;}
40+
virtualoperatorbool() {returntrue; }
41+
};
42+
#pragma GCC diagnostic pop
43+
44+
45+
#endif/* TCPCLIENT_MOCK_H_*/
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright (c) 2020 Arduino. All rights reserved.
3+
*
4+
* SPDX-License-Identifier: LGPL-2.1-or-later
5+
*/
6+
7+
#include<catch2/catch_test_macros.hpp>
8+
#include<api/IPAddress.h>
9+
#include<TCPClientMock.h>
10+
11+
/*
12+
* The purpose of these tests is to highlight potential memory leaking
13+
* issues that may arise from the lack of virtual destructors.
14+
* These test cases will never fail under unit testing,
15+
* but they should trigger valgrind error reporting
16+
*/
17+
18+
TEST_CASE("Testing polymorphic IPAddress memory free","[ipaddress-delete-01]")
19+
{
20+
arduino::Printable* p =newIPAddress();
21+
22+
#pragma GCC diagnostic push
23+
#pragma GCC diagnostic ignored "-Wdelete-non-virtual-dtor"
24+
delete p;
25+
#pragma GCC diagnostic pop
26+
}
27+
28+
TEST_CASE("Testing polymorphic client memory free","[client-delete-01]")
29+
{
30+
arduino::Client* p =new TCPClientMock;
31+
32+
#pragma GCC diagnostic push
33+
#pragma GCC diagnostic ignored "-Wdelete-non-virtual-dtor"
34+
delete p;
35+
#pragma GCC diagnostic pop
36+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/bash
2+
3+
FQBNS=(
4+
arduino-git:renesas_portenta_main:unor4wifi
5+
# arduino-git:mbed:envie_m7
6+
# arduino-git:avr:uno
7+
# arduino-git:samd:mkrwifi1010
8+
# arduino-git:mbed:opta
9+
)
10+
11+
branches=(
12+
master
13+
virtual-destructors
14+
)
15+
16+
forbranchin"${branches[@]}";do
17+
git checkout$branch
18+
forfqbnin$"${FQBNS[@]}";do
19+
echo"compiling for"$fqbn.$branch
20+
# arduino-cli compile -b $fqbn | tee $fqbn.$branch.log
21+
arduino-cli compile -b$fqbn --build-property"compiler.cpp.extra_flags=\"-fdump-record-layouts\""
22+
# /home/agilardoni/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/7-2017q4/bin/arm-none-eabi-size -A /tmp/arduino/sketches/97A7C8915D2115841AF9E1023FFD9539/virtual_destructors_testing.ino.elf | tee $fqbn.$branch.size.log
23+
done
24+
done
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
2+
#if defined(ARDUINO_SAMD_MKR1000)
3+
#include<WiFi101.h>
4+
#include<WiFiUdp.h>
5+
#elif defined(ARDUINO_SAMD_MKRWIFI1010) || defined(ARDUINO_SAMD_NANO_33_IOT) || defined(ARDUINO_AVR_UNO_WIFI_REV2) || defined (ARDUINO_NANO_RP2040_CONNECT)
6+
#include<WiFiNINA.h>
7+
#include<WiFiUdp.h>
8+
#elif defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_PORTENTA_H7_M7) || \
9+
defined(ARDUINO_NICLA_VISION) || defined(ARDUINO_OPTA) || defined(ARDUINO_GIGA)
10+
#include <WiFi.h>
11+
#include<WiFiUdp.h>
12+
#elif defined(ARDUINO_PORTENTA_C33)
13+
#include<WiFiC3.h>
14+
#include<WiFiUdp.h>
15+
#elif defined(ARDUINO_ARCH_ESP8266)
16+
#include<ESP8266WiFi.h>
17+
#include<WiFiUdp.h>
18+
#elif defined(ARDUINO_ARCH_ESP32)
19+
#include<WiFi.h>
20+
#include<WiFiUdp.h>
21+
#elif defined(ARDUINO_UNOR4_WIFI)
22+
#include<WiFiS3.h>
23+
#elif defined(ARDUINO_RASPBERRY_PI_PICO_W)
24+
#include<WiFi.h>
25+
#include<WiFiUdp.h>
26+
#endif
27+
voidsetup() {
28+
Serial.begin(115200);
29+
30+
while(!Serial);
31+
32+
Serial.println("Hello world");
33+
34+
#if defined(ARDUINO_SAMD_MKR1000) || \
35+
defined(ARDUINO_SAMD_MKRWIFI1010) || \
36+
defined(ARDUINO_SAMD_NANO_33_IOT) || \
37+
defined(ARDUINO_AVR_UNO_WIFI_REV2) || \
38+
defined(ARDUINO_NANO_RP2040_CONNECT) || \
39+
defined(ARDUINO_PORTENTA_H7_M7) || \
40+
defined(ARDUINO_PORTENTA_H7_M7) || \
41+
defined(ARDUINO_NICLA_VISION) || \
42+
defined(ARDUINO_OPTA) || \
43+
defined(ARDUINO_GIGA) || \
44+
defined(ARDUINO_PORTENTA_C33) || \
45+
defined(ARDUINO_ARCH_ESP8266) || \
46+
defined(ARDUINO_ARCH_ESP32) || \
47+
defined(ARDUINO_UNOR4_WIFI) || \
48+
defined(ARDUINO_RASPBERRY_PI_PICO_W)
49+
Client *c =newWiFiClient();// sizeof // as global variable
50+
delete c;
51+
#endif
52+
}
53+
54+
voidloop() {
55+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp