changeset 1464:976903c2e02e

2009-04-06 Omair Majid <omajid@redhat.com> * patches/icedtea-jtreg-jrunscript.patch: New patch. Replaces jrunscriptTest.sh with a java version that isnt picky about int vs double changes. * Makefile.am (ICEDTEA_PATCHES): Apply the above. * HACKING: Document the above.
author Omair Majid <omajid@redhat.com>
date Mon, 06 Apr 2009 16:50:53 -0400
parents 5b9c566ab513
children 953caf041bef
files ChangeLog HACKING Makefile.am patches/icedtea-jtreg-jrunscript.patch
diffstat 4 files changed, 363 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Fri Apr 03 13:49:06 2009 -0400
+++ b/ChangeLog	Mon Apr 06 16:50:53 2009 -0400
@@ -1,3 +1,11 @@
+2009-04-06  Omair Majid  <omajid@redhat.com>
+
+	* patches/icedtea-jtreg-jrunscript.patch: New patch. Replaces 
+	jrunscriptTest.sh with a java version that isnt picky about int vs double
+	changes.
+	* Makefile.am (ICEDTEA_PATCHES): Apply the above.
+	* HACKING: Document the above.
+
 2009-04-03  Lillian Angel  <langel@redhat.com>
 
 	* patches/icedtea-lcms.patch: Updated. Re-added _cmsModifyTag data
--- a/HACKING	Fri Apr 03 13:49:06 2009 -0400
+++ b/HACKING	Mon Apr 06 16:50:53 2009 -0400
@@ -93,6 +93,7 @@
 * icedtea-jtreg-printjob-multiple-end.patch: Fix test to not require any user interaction.
 * icedtea-network-unreachable.patch: Check for ENETUNREACH and EHOSTUNREACH early on when doing a Socket.connect().
 * icedtea-jtreg-printjob-edgetest-manual.patch: Mark test that requires user interaction as manual.
+* icedtea-jtreg-jrunscript.patch: Fix jrunscript test so it works with newer versions of rhino (by comparing the actual numbers).
 
 The following patches are only applied to OpenJDK6 in IcedTea6:
 
--- a/Makefile.am	Fri Apr 03 13:49:06 2009 -0400
+++ b/Makefile.am	Mon Apr 06 16:50:53 2009 -0400
@@ -691,6 +691,7 @@
 	patches/icedtea-jtreg-colortest.patch \
 	patches/icedtea-jtreg-printjob-multiple-end.patch \
 	patches/icedtea-jtreg-printjob-edgetest-manual.patch \
+	patches/icedtea-jtreg-jrunscript.patch \
 	patches/icedtea-network-unreachable.patch \
 	$(DISTRIBUTION_PATCHES)
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/patches/icedtea-jtreg-jrunscript.patch	Mon Apr 06 16:50:53 2009 -0400
@@ -0,0 +1,353 @@
+diff -uNr openjdk/jdk/test/sun/tools/jrunscript.orig/CheckEngine.java openjdk/jdk/test/sun/tools/jrunscript/CheckEngine.java
+--- openjdk/jdk/test/sun/tools/jrunscript.orig/CheckEngine.java	2009-04-01 14:23:50.000000000 -0400
++++ openjdk/jdk/test/sun/tools/jrunscript/CheckEngine.java	2009-04-01 16:23:26.000000000 -0400
+@@ -39,7 +39,8 @@
+  * passed.
+  */
+ public class CheckEngine {
+-    public static void main(String... args) {
++    
++    public static int checkEngine() {
+         int exitCode = 0;
+         ScriptEngine engine =
+             (new ScriptEngineManager()).getEngineByName("js");
+@@ -48,7 +49,11 @@
+             !(System.getProperty("java.runtime.name").startsWith("Java(TM)"))) {
+             exitCode = 2;
+         }
+-
++        return exitCode;
++    }
++    
++    public static void main(String... args) {
++        int exitCode = checkEngine();
+         System.exit(exitCode);
+     }
+ }
+diff -uNr openjdk/jdk/test/sun/tools/jrunscript.orig/jrunscriptTest.sh openjdk/jdk/test/sun/tools/jrunscript/jrunscriptTest.sh
+--- openjdk/jdk/test/sun/tools/jrunscript.orig/jrunscriptTest.sh	2009-04-01 14:23:50.000000000 -0400
++++ openjdk/jdk/test/sun/tools/jrunscript/jrunscriptTest.sh	1969-12-31 19:00:00.000000000 -0500
+@@ -1,80 +0,0 @@
+-#!/bin/sh
+-
+-#
+-# Copyright 2005-2006 Sun Microsystems, Inc.  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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+-# CA 95054 USA or visit www.sun.com if you need additional information or
+-# have any questions.
+-#
+-
+-
+-# @test
+-# @bug 6265810 6705893
+-# @build CheckEngine
+-# @run shell jrunscriptTest.sh
+-# @summary Test that output of 'jrunscript' interactive matches the repl.out file
+-
+-. ${TESTSRC-.}/common.sh
+-
+-setup
+-${JAVA} -cp ${TESTCLASSES} CheckEngine
+-if [ $? -eq 2 ]; then
+-    echo "No js engine found and engine not required; test vacuously passes."
+-    exit 0
+-fi
+-
+-rm -f jrunscriptTest.out 2>/dev/null
+-${JRUNSCRIPT} > jrunscriptTest.out 2>&1 <<EOF
+-v = 2 + 5;
+-v *= 5;
+-v = v + " is the value";
+-if (v != 0) { println('yes v != 0'); }
+-java.lang.System.out.println('hello world from script');
+-new java.lang.Runnable() { run: function() { println('I am runnable'); }}.run();
+-EOF
+-
+-diff jrunscriptTest.out ${TESTSRC}/repl.out
+-if [ $? != 0 ]
+-then
+-  echo "Output of jrunscript session differ from expected output. Failed."
+-  rm -f jrunscriptTest.out 2>/dev/null
+-  exit 1
+-fi
+-
+-rm -f jrunscriptTest.out 2>/dev/null
+-${JRUNSCRIPT} -l js > jrunscriptTest.out 2>&1 <<EOF
+-v = 2 + 5;
+-v *= 5;
+-v = v + " is the value";
+-if (v != 0) { println('yes v != 0'); }
+-java.lang.System.out.println('hello world from script');
+-new java.lang.Runnable() { run: function() { println('I am runnable'); }}.run();
+-EOF
+-
+-diff jrunscriptTest.out ${TESTSRC}/repl.out
+-if [ $? != 0 ]
+-then
+-  echo "Output of jrunscript -l js differ from expected output. Failed."
+-  rm -f jrunscriptTest.out 2>/dev/null
+-  exit 1
+-fi
+-
+-rm -f jrunscriptTest.out
+-echo "Passed"
+-exit 0
+diff -uNr openjdk/jdk/test/sun/tools/jrunscript.orig/Testjrunscript.java openjdk/jdk/test/sun/tools/jrunscript/Testjrunscript.java
+--- openjdk/jdk/test/sun/tools/jrunscript.orig/Testjrunscript.java	1969-12-31 19:00:00.000000000 -0500
++++ openjdk/jdk/test/sun/tools/jrunscript/Testjrunscript.java	2009-04-01 16:52:36.000000000 -0400
+@@ -0,0 +1,239 @@
++/*
++ * Copyright 2009 Red Hat, Inc. 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.
++ */
++ 
++
++/*
++@test
++@bug 6265810 6705893
++@build CheckEngine
++@run main Testjrunscript
++@summary Test that output of 'jrunscript' interactive matches the expected output
++*/
++
++import java.io.BufferedReader;
++import java.io.File;
++import java.io.FileNotFoundException;
++import java.io.IOException;
++import java.io.InputStream;
++import java.io.InputStreamReader;
++import java.util.LinkedList;
++import java.util.List;
++
++
++
++class OutputMismatchException extends RuntimeException {
++
++    private String actualLine;
++    private String expectedLine;
++
++    public OutputMismatchException(String actualLine, String expectedLine) {
++        this.expectedLine = expectedLine;
++        this.actualLine = actualLine;
++    }
++
++    public String toString() {
++        return "Output mismatch:\n" + "Expected: " + expectedLine + "\n"
++                + "Got     : " + actualLine;
++    }
++
++};
++
++public class Testjrunscript {
++
++    public static final String[] jrunscriptInput = new String[] {
++            "v = 2 + 5;",
++            "v *= 5;",
++            "v = v + \" is the value\";",
++            "if (v != 0) { println('yes v != 0'); }",
++            "java.lang.System.out.println('hello world from script');",
++            "new java.lang.Runnable() { run: function() { println('I am runnable'); }}.run();" };
++
++    public static final String INTERPRETER_PROMPT = "js> ";
++
++    public static final String[] expectedOutput = new String[] {
++            INTERPRETER_PROMPT + "7.0", 
++            INTERPRETER_PROMPT + "35.0",
++            INTERPRETER_PROMPT + "35 is the value",
++            INTERPRETER_PROMPT + "yes v != 0",
++            INTERPRETER_PROMPT + "hello world from script",
++            INTERPRETER_PROMPT + "I am runnable", 
++            INTERPRETER_PROMPT, };
++
++    public static final double EPSILON = 0.000001;
++
++    /**
++     * Compares the expected output as stored in expectedOutput against the
++     * actual output read in from processOutput
++     * 
++     * @param processOutput
++     * @throws IOException
++     */
++    private static void checkOutput(InputStream processOutput)
++            throws IOException {
++
++        BufferedReader lineReader = new BufferedReader(new InputStreamReader(
++                processOutput));
++
++        String actualLine;
++        String expectedLine;
++        for (int i = 0; i < expectedOutput.length; i++) {
++            expectedLine = expectedOutput[i];
++            actualLine = lineReader.readLine();
++            if (actualLine == null) {
++                throw new OutputMismatchException("", expectedLine);
++            }
++            checkLinesMatch(actualLine, expectedLine);
++        }
++
++        actualLine = lineReader.readLine();
++        if (actualLine != null) {
++            throw new OutputMismatchException(actualLine, "");
++        }
++    }
++
++    /**
++     * Compares two lines and throws {@link OutputMismatchException} if they
++     * dont match. Allows for different representations of numbers.
++     * 
++     * @param actualLine
++     *            the actual output
++     * @param expectedLine
++     *            the expected output
++     */
++    private static void checkLinesMatch(String actualLine, String expectedLine) {
++        String delimiter = "[ ]+";
++        String[] actualTokens = actualLine.split(delimiter);
++        String[] expectedTokens = expectedLine.split(delimiter);
++        if (actualTokens.length != expectedTokens.length) {
++            throw new OutputMismatchException(actualLine, expectedLine);
++        }
++
++        String actualToken;
++        String expectedToken;
++        for (int i = 0; i < expectedTokens.length; i++) {
++            actualToken = actualTokens[i];
++            expectedToken = expectedTokens[i];
++            if (actualToken.equals(expectedToken)) {
++                continue;
++            }
++
++            // if tokens dont match exactly, try converting them both to doubles
++            // and then comparing. some versions of rhino return int for some
++            // operations, while others return floats/doubles
++            try {
++                Double actualDouble = Double.valueOf(actualToken);
++                Double expectedDouble = Double.valueOf(expectedToken);
++                if (Math.abs(expectedDouble - actualDouble) < EPSILON) {
++                    continue;
++                } else {
++                    throw new OutputMismatchException(actualLine, expectedLine);
++                }
++            } catch (NumberFormatException nfe) {
++                throw new OutputMismatchException(actualLine, expectedLine);
++            }
++        }
++
++    }
++
++    /**
++     * @return the path to the jrunscript binary
++     */
++    public static String getPathToJrunscript() throws FileNotFoundException {
++
++        File jreDir = new File(System.getProperty("java.home"));
++        if (!jreDir.isDirectory()) {
++            throw new RuntimeException("java.home doesnt point to a directory");
++        }
++
++        String jdkDir = jreDir.getParent();
++        String pathToJrunscript = jdkDir + File.separatorChar + "bin"
++                + File.separatorChar + "jrunscript";
++        File jrunscriptBinary = new File(pathToJrunscript);
++        if (!jrunscriptBinary.exists()) {
++            throw new FileNotFoundException("File "
++                    + jrunscriptBinary.getAbsolutePath());
++        }
++        return pathToJrunscript;
++
++    }
++
++    /**
++     * Runs the given command to execute jrunscript and checks to make sure it
++     * works
++     */
++    public static void checkJrunscript(List<String> command) throws IOException {
++        System.out.print("Testing jrunscript:");
++        for (String cmd : command) {
++            System.out.print(" " + cmd);
++        }
++        System.out.println();
++        
++        
++        ProcessBuilder pb = new ProcessBuilder(command);
++        pb.redirectErrorStream(true);
++
++        Process jrunscript = pb.start();
++
++        InputStream input = jrunscript.getInputStream();
++        String inputLine;
++        for (int i = 0; i < jrunscriptInput.length; i++) {
++            inputLine = jrunscriptInput[i];
++            jrunscript.getOutputStream().write(inputLine.getBytes());
++            jrunscript.getOutputStream().write(new byte[] { '\n' });
++        }
++        jrunscript.getOutputStream().close();
++
++        checkOutput(input);
++
++        try {
++            jrunscript.waitFor();
++        } catch (InterruptedException e) {
++            throw new RuntimeException(e);
++        }
++
++        if (jrunscript.exitValue() != 0) {
++            throw new RuntimeException("jrunscript failed");
++        }
++    }
++
++    /**
++     * test if jrunscript works properly
++     */
++    public static void main(String[] args) throws IOException,
++            InterruptedException {
++
++        if (CheckEngine.checkEngine() == 2) {
++            System.out
++                    .println("No js engine found and engine not required; test vacuously passes.");
++        }
++
++        // check jrunscript without any other args
++        List<String> command = new LinkedList<String>();
++        command.add(getPathToJrunscript());
++        checkJrunscript(command);
++
++        // check jrunscript -l js
++        command.add("-l");
++        command.add("js");
++        checkJrunscript(command);
++
++        System.out.println("Passed");
++
++    }
++}