4.7. My test only applies to one platform and it will fail/not run in others. How do I prevent the harness from running it on the wrong platform?

The tag specification provides no way to indicate any platform requirements. If the test only applies to a single platform, then the test itself must determine the current platform and decide whether the test should be run there. If the test suite is running on the wrong platform, the test should pass (i.e. just return) otherwise, the test should proceed. A significant benefit to this approach is that the same number of tests in a testsuite will always be run if the same arguments are given to jtreg regardless of the particular platform.

For tests that are written in Java code (i.e. applet and main tests), you may determine the platform via the system properties. The following code fragment may be used to distinguish between SunOS sparc, SunOS x86, Windows, etc.

                    String arch = System.getProperty("os.arch");
                    String name = System.getProperty("os.name");
                    if (arch.equals("sparc")) {
                        System.out.println("SunOS, sparc");
                    } else if (arch.equals("x86")) {
                        if (name.equals("SunOS"))
                            System.out.println("SunOS, x86");
                        else if (name.startsWith("Windows"))
                            System.out.println("windows");
                        else
                            throw new RuntimeException("unrecognized OS:" +
                                " os.arch == " + arch +
                                " os.name == " + name);
                    } else if (arch.equals("i386")) {
                        System.out.println("Linux, i386");
                    } else {
                        throw new RuntimeException("unrecognized system:" +
                            " os.arch == " + arch);
                    }
                

This approach is not suitable for shell tests. In this case, you can determine the platform via uname. The following code accomplishes the same task as above.

                    OS=`uname -s`
                    case "$OS" in
                        Linux )
                            echo "Linux" ;;
                        SunOS )
                            HARDWARE=`uname -m`
                            case "$HARDWARE" in
                                sun4u )
                                    echo "SunOS, sparc" ;;
                                i86pc )
                                    echo "SunOS, x86" ;;
                                * )
                                    echo "unrecognized SunOS: $HARDWARE" ;;
                            esac ;;
                        Windows_* )
                            echo "windows" ;;
                        * )
                            echo "unrecognized system: $OS" ;;
                    esac

                    exit $?