[PATCH mptcp-next 7/7] Add test cases for MPTCP socket functionality

Geliang Tang posted 7 patches 1 month, 3 weeks ago
There is a newer version of this series
[PATCH mptcp-next 7/7] Add test cases for MPTCP socket functionality
Posted by Geliang Tang 1 month, 3 weeks ago
This patch introduces comprehensive test coverage for the newly added
MPTCP socket support by:

1. Adding MPTCPServer.java - A test server that:
   - Creates an MPTCP-enabled ServerSocket
   - Accepts client connections
   - Echoes received messages back to clients
   - Handles graceful shutdown

2. Adding MPTCPClient.java - A test client that:
   - Connects to the MPTCP server
   - Sends user input to server
   - Displays server responses
   - Supports graceful termination

The tests verify:
- Basic MPTCP socket creation and connection
- Bidirectional communication
- Proper stream handling
- Error conditions
- Clean resource management

Both test programs demonstrate the usage of the new MPTCP-enabled
constructors added in previous patches.

Co-Developed-by: Gang Yan <yangang@kylinos.cn>
Signed-off-by: Gang Yan <yangang@kylinos.cn>
Signed-off-by: Geliang Tang <geliang@kernel.org>
---
 .../java/net/ServerSocket/MPTCPServer.java    | 58 +++++++++++++++++
 test/jdk/java/net/Socket/MPTCPClient.java     | 62 +++++++++++++++++++
 2 files changed, 120 insertions(+)
 create mode 100644 test/jdk/java/net/ServerSocket/MPTCPServer.java
 create mode 100644 test/jdk/java/net/Socket/MPTCPClient.java

diff --git a/test/jdk/java/net/ServerSocket/MPTCPServer.java b/test/jdk/java/net/ServerSocket/MPTCPServer.java
new file mode 100644
index 00000000000..a28e4963943
--- /dev/null
+++ b/test/jdk/java/net/ServerSocket/MPTCPServer.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.io.*;
+import java.net.*;
+
+public class MPTCPServer {
+	public static void main(String[] args) {
+		final int PORT = 12345;
+
+		try (ServerSocket serverSocket = new ServerSocket(PORT, 50, null, true)) {
+			System.out.println("Server started, waiting for client connection ...");
+
+			Socket clientSocket = serverSocket.accept();
+			System.out.println("Client connected: " + clientSocket.getInetAddress());
+
+			BufferedReader in = new BufferedReader(
+					new InputStreamReader(clientSocket.getInputStream()));
+			PrintWriter out = new PrintWriter(
+					clientSocket.getOutputStream(), true);
+
+			String inputLine;
+			while ((inputLine = in.readLine()) != null) {
+				System.out.println("Received from client: " + inputLine);
+				out.println("Server response: " + inputLine);
+
+				if ("exit".equalsIgnoreCase(inputLine)) {
+					break;
+				}
+			}
+
+			clientSocket.close();
+			System.out.println("Connection closed");
+		} catch (IOException e) {
+			System.err.println("Server exception: " + e.getMessage());
+		}
+	}
+}
diff --git a/test/jdk/java/net/Socket/MPTCPClient.java b/test/jdk/java/net/Socket/MPTCPClient.java
new file mode 100644
index 00000000000..18d815c39e7
--- /dev/null
+++ b/test/jdk/java/net/Socket/MPTCPClient.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.io.*;
+import java.net.*;
+
+public class MPTCPClient {
+    public static void main(String[] args) {
+        final String HOST = "localhost";
+        final int PORT = 12345;
+        
+        try (Socket socket = new Socket(HOST, PORT, true, true)) {
+            System.out.println("Connected to server");
+            
+            BufferedReader in = new BufferedReader(
+                new InputStreamReader(socket.getInputStream()));
+            PrintWriter out = new PrintWriter(
+                socket.getOutputStream(), true);
+            
+            BufferedReader stdIn = new BufferedReader(
+                new InputStreamReader(System.in));
+            
+            String userInput;
+            System.out.println("Enter message (type 'exit' to quit):");
+            while ((userInput = stdIn.readLine()) != null) {
+                out.println(userInput);
+                
+                System.out.println("Server response: " + in.readLine());
+                
+                if ("exit".equalsIgnoreCase(userInput)) {
+                    break;
+                }
+            }
+            
+            System.out.println("Connection closed");
+        } catch (UnknownHostException e) {
+            System.err.println("Host not found: " + HOST);
+        } catch (IOException e) {
+            System.err.println("Client I/O error: " + e.getMessage());
+        }
+    }
+}
-- 
2.48.1
Re: [PATCH mptcp-next 7/7] Add test cases for MPTCP socket functionality
Posted by Matthieu Baerts 1 month, 2 weeks ago
Hi Geliang,

On 23/07/2025 07:16, Geliang Tang wrote:
> This patch introduces comprehensive test coverage for the newly added
> MPTCP socket support by:
> 
> 1. Adding MPTCPServer.java - A test server that:
>    - Creates an MPTCP-enabled ServerSocket
>    - Accepts client connections
>    - Echoes received messages back to clients
>    - Handles graceful shutdown
> 
> 2. Adding MPTCPClient.java - A test client that:
>    - Connects to the MPTCP server
>    - Sends user input to server
>    - Displays server responses
>    - Supports graceful termination
> 
> The tests verify:
> - Basic MPTCP socket creation and connection
> - Bidirectional communication
> - Proper stream handling
> - Error conditions
> - Clean resource management
> 
> Both test programs demonstrate the usage of the new MPTCP-enabled
> constructors added in previous patches.

I don't know what is usually being done here, but these tests will not
be used by a CI I guess. Is it an issue?
If that's normal, no need to add something like a README to explain how
to test that?

Also, these tests don't check if MPTCP is being used, nor have pre-check
to see if the system supports MPTCP (otherwise the test will fail).

Cheers,
Matt
-- 
Sponsored by the NGI0 Core fund.