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

Geliang Tang posted 3 patches 2 weeks, 6 days ago
[PATCH mptcp-next v2 3/3] Add test cases for MPTCP socket functionality
Posted by Geliang Tang 2 weeks, 6 days ago
This patch adds comprehensive test coverage for the MPTCP socket
implementation by introducing two test programs:

1. MPTCPServer.java - an echo server that uses MPTCP-enabled ServerSocket
2. MPTCPClient.java - a client that connects to the server using MPTCP
   Socket

The tests verify:
- MPTCP socket creation and connection establishment
- Bidirectional communication over MPTCP subflows
- Proper stream handling and error conditions
- Graceful shutdown and resource cleanup

These tests demonstrate the usage of the new MPTCP-enabled constructors and
provide a functional validation of the MPTCP implementation.

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