test/jdk/java/net/SctpSanity.java
author chegar
Thu, 21 Nov 2019 12:14:26 +0000
changeset 59203 696e6a7e3b6a
permissions -rw-r--r--
8232101: (sctp) Add minimal sanity tests for SCTP Reviewed-by: alanb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
59203
696e6a7e3b6a 8232101: (sctp) Add minimal sanity tests for SCTP
chegar
parents:
diff changeset
     1
/*
696e6a7e3b6a 8232101: (sctp) Add minimal sanity tests for SCTP
chegar
parents:
diff changeset
     2
 * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
696e6a7e3b6a 8232101: (sctp) Add minimal sanity tests for SCTP
chegar
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
696e6a7e3b6a 8232101: (sctp) Add minimal sanity tests for SCTP
chegar
parents:
diff changeset
     4
 *
696e6a7e3b6a 8232101: (sctp) Add minimal sanity tests for SCTP
chegar
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
696e6a7e3b6a 8232101: (sctp) Add minimal sanity tests for SCTP
chegar
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
696e6a7e3b6a 8232101: (sctp) Add minimal sanity tests for SCTP
chegar
parents:
diff changeset
     7
 * published by the Free Software Foundation.
696e6a7e3b6a 8232101: (sctp) Add minimal sanity tests for SCTP
chegar
parents:
diff changeset
     8
 *
696e6a7e3b6a 8232101: (sctp) Add minimal sanity tests for SCTP
chegar
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
696e6a7e3b6a 8232101: (sctp) Add minimal sanity tests for SCTP
chegar
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
696e6a7e3b6a 8232101: (sctp) Add minimal sanity tests for SCTP
chegar
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
696e6a7e3b6a 8232101: (sctp) Add minimal sanity tests for SCTP
chegar
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
696e6a7e3b6a 8232101: (sctp) Add minimal sanity tests for SCTP
chegar
parents:
diff changeset
    13
 * accompanied this code).
696e6a7e3b6a 8232101: (sctp) Add minimal sanity tests for SCTP
chegar
parents:
diff changeset
    14
 *
696e6a7e3b6a 8232101: (sctp) Add minimal sanity tests for SCTP
chegar
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
696e6a7e3b6a 8232101: (sctp) Add minimal sanity tests for SCTP
chegar
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
696e6a7e3b6a 8232101: (sctp) Add minimal sanity tests for SCTP
chegar
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
696e6a7e3b6a 8232101: (sctp) Add minimal sanity tests for SCTP
chegar
parents:
diff changeset
    18
 *
696e6a7e3b6a 8232101: (sctp) Add minimal sanity tests for SCTP
chegar
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
696e6a7e3b6a 8232101: (sctp) Add minimal sanity tests for SCTP
chegar
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
696e6a7e3b6a 8232101: (sctp) Add minimal sanity tests for SCTP
chegar
parents:
diff changeset
    21
 * questions.
696e6a7e3b6a 8232101: (sctp) Add minimal sanity tests for SCTP
chegar
parents:
diff changeset
    22
 */
696e6a7e3b6a 8232101: (sctp) Add minimal sanity tests for SCTP
chegar
parents:
diff changeset
    23
696e6a7e3b6a 8232101: (sctp) Add minimal sanity tests for SCTP
chegar
parents:
diff changeset
    24
/* @test
696e6a7e3b6a 8232101: (sctp) Add minimal sanity tests for SCTP
chegar
parents:
diff changeset
    25
 * @bug 8232097
696e6a7e3b6a 8232101: (sctp) Add minimal sanity tests for SCTP
chegar
parents:
diff changeset
    26
 * @summary Basic sanity for creation of SCTP channels
696e6a7e3b6a 8232101: (sctp) Add minimal sanity tests for SCTP
chegar
parents:
diff changeset
    27
 * @modules jdk.sctp
696e6a7e3b6a 8232101: (sctp) Add minimal sanity tests for SCTP
chegar
parents:
diff changeset
    28
 * @run main/othervm SctpSanity 1
696e6a7e3b6a 8232101: (sctp) Add minimal sanity tests for SCTP
chegar
parents:
diff changeset
    29
 * @run main/othervm SctpSanity 2
696e6a7e3b6a 8232101: (sctp) Add minimal sanity tests for SCTP
chegar
parents:
diff changeset
    30
 * @run main/othervm SctpSanity 3
696e6a7e3b6a 8232101: (sctp) Add minimal sanity tests for SCTP
chegar
parents:
diff changeset
    31
 */
696e6a7e3b6a 8232101: (sctp) Add minimal sanity tests for SCTP
chegar
parents:
diff changeset
    32
696e6a7e3b6a 8232101: (sctp) Add minimal sanity tests for SCTP
chegar
parents:
diff changeset
    33
import java.io.IOException;
696e6a7e3b6a 8232101: (sctp) Add minimal sanity tests for SCTP
chegar
parents:
diff changeset
    34
import com.sun.nio.sctp.SctpChannel;
696e6a7e3b6a 8232101: (sctp) Add minimal sanity tests for SCTP
chegar
parents:
diff changeset
    35
import com.sun.nio.sctp.SctpMultiChannel;
696e6a7e3b6a 8232101: (sctp) Add minimal sanity tests for SCTP
chegar
parents:
diff changeset
    36
import com.sun.nio.sctp.SctpServerChannel;
696e6a7e3b6a 8232101: (sctp) Add minimal sanity tests for SCTP
chegar
parents:
diff changeset
    37
import static java.lang.System.out;
696e6a7e3b6a 8232101: (sctp) Add minimal sanity tests for SCTP
chegar
parents:
diff changeset
    38
696e6a7e3b6a 8232101: (sctp) Add minimal sanity tests for SCTP
chegar
parents:
diff changeset
    39
/**
696e6a7e3b6a 8232101: (sctp) Add minimal sanity tests for SCTP
chegar
parents:
diff changeset
    40
 * Tests creation of SCTP channels. The channels should either be created
696e6a7e3b6a 8232101: (sctp) Add minimal sanity tests for SCTP
chegar
parents:
diff changeset
    41
 * or not. The latter throwing an UnsupportedOperationException. No other
696e6a7e3b6a 8232101: (sctp) Add minimal sanity tests for SCTP
chegar
parents:
diff changeset
    42
 * behavior is acceptable. Minimally, exercises the JDK's native library
696e6a7e3b6a 8232101: (sctp) Add minimal sanity tests for SCTP
chegar
parents:
diff changeset
    43
 * loading on operating systems that provide an implementation, even if
696e6a7e3b6a 8232101: (sctp) Add minimal sanity tests for SCTP
chegar
parents:
diff changeset
    44
 * the system-level support is not configured.
696e6a7e3b6a 8232101: (sctp) Add minimal sanity tests for SCTP
chegar
parents:
diff changeset
    45
 */
696e6a7e3b6a 8232101: (sctp) Add minimal sanity tests for SCTP
chegar
parents:
diff changeset
    46
public class SctpSanity {
696e6a7e3b6a 8232101: (sctp) Add minimal sanity tests for SCTP
chegar
parents:
diff changeset
    47
696e6a7e3b6a 8232101: (sctp) Add minimal sanity tests for SCTP
chegar
parents:
diff changeset
    48
    public static void main(String... args) throws IOException {
696e6a7e3b6a 8232101: (sctp) Add minimal sanity tests for SCTP
chegar
parents:
diff changeset
    49
        switch (Integer.valueOf(args[0])) {
696e6a7e3b6a 8232101: (sctp) Add minimal sanity tests for SCTP
chegar
parents:
diff changeset
    50
            case 1: testSctpChannel();        break;
696e6a7e3b6a 8232101: (sctp) Add minimal sanity tests for SCTP
chegar
parents:
diff changeset
    51
            case 2: testSctpServerChannel();  break;
696e6a7e3b6a 8232101: (sctp) Add minimal sanity tests for SCTP
chegar
parents:
diff changeset
    52
            case 3: testSctpMultiChannel();   break;
696e6a7e3b6a 8232101: (sctp) Add minimal sanity tests for SCTP
chegar
parents:
diff changeset
    53
            default: throw new AssertionError("should not reach here");
696e6a7e3b6a 8232101: (sctp) Add minimal sanity tests for SCTP
chegar
parents:
diff changeset
    54
        }
696e6a7e3b6a 8232101: (sctp) Add minimal sanity tests for SCTP
chegar
parents:
diff changeset
    55
    }
696e6a7e3b6a 8232101: (sctp) Add minimal sanity tests for SCTP
chegar
parents:
diff changeset
    56
696e6a7e3b6a 8232101: (sctp) Add minimal sanity tests for SCTP
chegar
parents:
diff changeset
    57
    static void testSctpChannel() throws IOException {
696e6a7e3b6a 8232101: (sctp) Add minimal sanity tests for SCTP
chegar
parents:
diff changeset
    58
        try (SctpChannel channel = SctpChannel.open()) {
696e6a7e3b6a 8232101: (sctp) Add minimal sanity tests for SCTP
chegar
parents:
diff changeset
    59
            out.println("created SctpChannel:" + channel);
696e6a7e3b6a 8232101: (sctp) Add minimal sanity tests for SCTP
chegar
parents:
diff changeset
    60
        } catch (UnsupportedOperationException uoe) {
696e6a7e3b6a 8232101: (sctp) Add minimal sanity tests for SCTP
chegar
parents:
diff changeset
    61
            // ok - the platform does not support SCTP
696e6a7e3b6a 8232101: (sctp) Add minimal sanity tests for SCTP
chegar
parents:
diff changeset
    62
            out.println("ok, caught:" + uoe);
696e6a7e3b6a 8232101: (sctp) Add minimal sanity tests for SCTP
chegar
parents:
diff changeset
    63
        }
696e6a7e3b6a 8232101: (sctp) Add minimal sanity tests for SCTP
chegar
parents:
diff changeset
    64
    }
696e6a7e3b6a 8232101: (sctp) Add minimal sanity tests for SCTP
chegar
parents:
diff changeset
    65
696e6a7e3b6a 8232101: (sctp) Add minimal sanity tests for SCTP
chegar
parents:
diff changeset
    66
    static void testSctpServerChannel() throws IOException {
696e6a7e3b6a 8232101: (sctp) Add minimal sanity tests for SCTP
chegar
parents:
diff changeset
    67
        try (SctpServerChannel channel = SctpServerChannel.open()) {
696e6a7e3b6a 8232101: (sctp) Add minimal sanity tests for SCTP
chegar
parents:
diff changeset
    68
            out.println("created SctpServerChannel:" + channel);
696e6a7e3b6a 8232101: (sctp) Add minimal sanity tests for SCTP
chegar
parents:
diff changeset
    69
        } catch (UnsupportedOperationException uoe) {
696e6a7e3b6a 8232101: (sctp) Add minimal sanity tests for SCTP
chegar
parents:
diff changeset
    70
            // ok - the platform does not support SCTP
696e6a7e3b6a 8232101: (sctp) Add minimal sanity tests for SCTP
chegar
parents:
diff changeset
    71
            out.println("ok, caught:" + uoe);
696e6a7e3b6a 8232101: (sctp) Add minimal sanity tests for SCTP
chegar
parents:
diff changeset
    72
        }
696e6a7e3b6a 8232101: (sctp) Add minimal sanity tests for SCTP
chegar
parents:
diff changeset
    73
    }
696e6a7e3b6a 8232101: (sctp) Add minimal sanity tests for SCTP
chegar
parents:
diff changeset
    74
696e6a7e3b6a 8232101: (sctp) Add minimal sanity tests for SCTP
chegar
parents:
diff changeset
    75
    static void testSctpMultiChannel() throws IOException {
696e6a7e3b6a 8232101: (sctp) Add minimal sanity tests for SCTP
chegar
parents:
diff changeset
    76
        try (SctpMultiChannel channel = SctpMultiChannel.open()) {
696e6a7e3b6a 8232101: (sctp) Add minimal sanity tests for SCTP
chegar
parents:
diff changeset
    77
            out.println("created SctpMultiChannel:" + channel);
696e6a7e3b6a 8232101: (sctp) Add minimal sanity tests for SCTP
chegar
parents:
diff changeset
    78
        } catch (UnsupportedOperationException uoe) {
696e6a7e3b6a 8232101: (sctp) Add minimal sanity tests for SCTP
chegar
parents:
diff changeset
    79
            // ok - the platform does not support SCTP
696e6a7e3b6a 8232101: (sctp) Add minimal sanity tests for SCTP
chegar
parents:
diff changeset
    80
            out.println("ok, caught:" + uoe);
696e6a7e3b6a 8232101: (sctp) Add minimal sanity tests for SCTP
chegar
parents:
diff changeset
    81
        }
696e6a7e3b6a 8232101: (sctp) Add minimal sanity tests for SCTP
chegar
parents:
diff changeset
    82
    }
696e6a7e3b6a 8232101: (sctp) Add minimal sanity tests for SCTP
chegar
parents:
diff changeset
    83
}
696e6a7e3b6a 8232101: (sctp) Add minimal sanity tests for SCTP
chegar
parents:
diff changeset
    84