Skip to content

Commit 152436d

Browse files
committed
src/corelibs: Test for beginMulticast.
Signed-off-by: IFX-Anusha <Anusha.TR@infineon.com>
1 parent a9c89ab commit 152436d

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

src/corelibs/wifi/test_wifi_udp_client.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* - Peek and flush the socket.
1515
* - Check the senders ip
1616
* - Check the senders port
17+
* - Sends a packet to a multicast group.
1718
* - Disconnect from the server and stop the UDP client.
1819
*
1920
* This test is paired with the "test_wifi_udp_server.cpp" test, which needs to be executed in another
@@ -131,6 +132,19 @@ TEST_IFX(wifi_udp_client, remote_port)
131132
TEST_ASSERT_EQUAL(expectedPort, remotePort);
132133
}
133134

135+
TEST_IFX(wifi_udp_client, udp_multicast_send){
136+
IPAddress multicastIP(239, 0, 0, 1); // Example multicast IP address
137+
uint16_t port = 1234;
138+
139+
TEST_ASSERT_TRUE(udpClient.beginPacket(multicastIP, port));
140+
const char *message = "Hello, Multicast!";
141+
size_t bytes_written = udpClient.write(message);
142+
TEST_ASSERT_EQUAL_INT(strlen(message), bytes_written);
143+
144+
TEST_ASSERT_TRUE(udpClient.endPacket());
145+
delay(100); // Wait for the packet to be sent
146+
}
147+
134148
TEST_IFX(wifi_udp_client, udp_client_end) {
135149
udpClient.stop();
136150
}
@@ -156,6 +170,7 @@ TEST_GROUP_RUNNER(wifi_udp_client) {
156170
RUN_TEST_CASE(wifi_udp_client, client_peek_flush);
157171
RUN_TEST_CASE(wifi_udp_client, remote_ip);
158172
RUN_TEST_CASE(wifi_udp_client, remote_port);
173+
RUN_TEST_CASE(wifi_udp_client, udp_multicast_send);
159174
RUN_TEST_CASE(wifi_udp_client, udp_client_end);
160175
RUN_TEST_CASE(wifi_udp_client, wifi_disconnect);
161176
RUN_TEST_CASE(wifi_udp_client, wifi_end);

src/corelibs/wifi/test_wifi_udp_server.cpp

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99
* - Starts processing the next available incoming packet, checks for the presence of a UDP packet
1010
* - Reads the packet and checks if the data is correct.
1111
* - Receives multiple packets from different senders and checks if the data and IP are correct.
12-
* - Handles packet loss by not sending a packet
1312
* - Writes a packet to the client
13+
* - Handles packet loss by not sending a packet
14+
* - Joins a multicast group and receives a packet from it
1415
* - Stops the UDP server
1516
* - Disconnect from the client and stop the access point.
1617
*
@@ -121,6 +122,25 @@ TEST_IFX(wifi_udp_server, handle_packet_loss)
121122
TEST_ASSERT_EQUAL_INT(0, udpServer.parsePacket());
122123
}
123124

125+
TEST_IFX(wifi_udp_server, joinmulticast_receive)
126+
{
127+
IPAddress multicastIP(239, 0, 0, 1);
128+
uint16_t port = 1234;
129+
130+
udpServer.stop(); // Stop any previous instance
131+
TEST_ASSERT_TRUE(udpServer.beginMulticast(multicastIP, port));
132+
133+
const char* expected_msg = "Hello, Multicast!";
134+
char rcvd_msg[50] = {0};
135+
136+
int packetSize = 0;
137+
while ((packetSize = udpServer.parsePacket()) != (int)strlen(expected_msg)) {}
138+
TEST_ASSERT_EQUAL_INT(strlen(expected_msg), packetSize);
139+
udpServer.read((uint8_t *)rcvd_msg, packetSize);
140+
TEST_ASSERT_EQUAL_STRING(expected_msg, rcvd_msg);
141+
}
142+
143+
124144
TEST_IFX(wifi_udp_server, udp_server_end)
125145
{
126146
udpServer.stop();
@@ -144,6 +164,7 @@ TEST_GROUP_RUNNER(wifi_udp_server) {
144164
RUN_TEST_CASE(wifi_udp_server, receive_multiple_packets);
145165
RUN_TEST_CASE(wifi_udp_server, udp_server_write);
146166
RUN_TEST_CASE(wifi_udp_server, handle_packet_loss);
167+
RUN_TEST_CASE(wifi_udp_server, joinmulticast_receive);
147168
RUN_TEST_CASE(wifi_udp_server, udp_server_end);
148169
RUN_TEST_CASE(wifi_udp_server, wifi_disconnect);
149170
RUN_TEST_CASE(wifi_udp_server, wifi_end);

0 commit comments

Comments
 (0)