Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8223543

[TESTBUG] Regression test java/awt/Graphics2D/DrawString/LCDTextSrcEa.java has issues

    XMLWordPrintable

Details

    • 2d
    • b19
    • x86_64
    • windows_10

    Backports

      Description

        ADDITIONAL SYSTEM INFORMATION :
        all OS-es (issues 1-3) / macOS 10.14+ (issue 4)
        jdk1.8.0_212 / jdk-11.0.3 / jdk-12.0.1

        A DESCRIPTION OF THE PROBLEM :
        Regression test java/awt/Graphics2D/DrawString/LCDTextSrcEa.java has the following issues:

        (all OS-es)

        1) LCDTextSrcEa paint(Graphics gx) method must be invoked for proper testing, but it cannot always be so when running under jtreg. LCDTextSrcEa main() method may finish before the actual paint(Graphics gx) execution. And jtreg immediately calls System.exit() when test method main() has finished. Jtreg won't wait for EDT to complete. So some check is needed in the test main() method to ensure paint(Graphics gx) has been completed. Otherwise the test may erroneously pass under jtreg.

        2) It is not good to throw exception from the test paint(Graphics gx) / EDT. Jtreg handles uncaught exceptions even from EDT because it launches tests in a separate ThreadGroup overriding uncaughtException(Thread t,Throwable e) method. But the test cannot properly work using command "java <test>". RuntimeException("No LCD text found") thrown from EDT won't stop the test execution in this case.

        3) Also the test Frame is not disposed at the end, so the test cannot finish when running under java as "java <test>". It is not a problem for jtreg though, because, as noted above, it finishes the test execution immediately after the test method main() finishes.

        (macOS Mojave)

        4) The following command should be applied on macOS 10.14+ Mojave for the proper test run:
        "defaults write -g CGFontRenderingFontSmoothingDisabled -bool NO", otherwise the test fails.
        It is because LCD shader cannot be used on macOS 10.14+ in font rendering unless it is explicitly specified by CGFontRenderingFontSmoothingDisabled system property.

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        Run the following commands for the test execution simply using java:

        cd <jdk_test_src>
        <jdk_home>/bin/javac java/awt/Graphics2D/DrawString/LCDTextSrcEa.java
        <jdk_home>/bin/java -cp java/awt/Graphics2D/DrawString LCDTextSrcEa.java

        Run the following commands for the test execution using jtreg:

        cd <jdk_test_src>
        <jtreg_home>/bin/jtreg -testjdk:<jdk_home> java/awt/Graphics2D/DrawString/LCDTextSrcEa.java

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        Correct test execution
        ACTUAL -
        Test may erroneously pass under jtreg
        Test cannot finish when run as "java <test>"
        Test always fails on macOS 10.14+

        ---------- BEGIN SOURCE ----------
        /**
         * @test
         * @key headful
         * @bug 6996867
         * @summary Render as LCD Text in SrcEa composite mode.
         */

        import java.awt.*;
        import java.awt.event.*;
        import java.awt.image.*;

        public class LCDTextSrcEa extends Component {

            static int SZ=150;
            BufferedImage target =
                new BufferedImage(SZ, SZ, BufferedImage.TYPE_INT_RGB);

            public static void main(String args[]) {
                Frame f = new Frame("LCD Text SrcEa Test");
                f.addWindowListener(new WindowAdapter() {
                    @Override
                    public void windowClosing(WindowEvent e) {
                        System.exit(0);
                    }
                });
                LCDTextSrcEa td = new LCDTextSrcEa();
                f.add("Center", td);
                f.pack();
                f.setVisible(true);
            }

            public Dimension getPreferredSize() {
                return new Dimension(SZ,SZ);
            }

            public void paint(Graphics gx) {

                Graphics2D g2d = (Graphics2D) target.getGraphics();
                g2d.setColor(Color.white);
                g2d.fillRect(0, 0, getWidth(), getHeight());

                g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC, 0.01f));
                g2d.setRenderingHint(
                        RenderingHints.KEY_TEXT_ANTIALIASING,
                        RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_VBGR);
                g2d.setRenderingHint(
                       RenderingHints.KEY_ANTIALIASING,
                       RenderingHints.VALUE_ANTIALIAS_ON);

                g2d.setColor(Color.black);
                g2d.drawString("Some sample text.", 10, 20);
                gx.drawImage(target, 0, 0, null);
                boolean nongrey = false;
                //Test BI: should be some non-greyscale color
                for (int px=0;px<SZ;px++) {
                    for (int py=0;py<SZ;py++) {
                        int rgb = target.getRGB(px, py);
                        int r = (rgb & 0xff0000) >> 16;
                        int g = (rgb & 0x00ff00) >> 8;
                        int b = (rgb & 0x0000ff);
                        if (r != g || r !=b || g != b) {
                             nongrey=true;
                             break;
                        }
                    }
                }
                if (!nongrey) {
                    throw new RuntimeException("No LCD text found");
                }
            }
        }
        ---------- END SOURCE ----------

        CUSTOMER SUBMITTED WORKAROUND :
        Here is the modified test with the possible fixes for issues 1)-3).

        /**
         * @test
         * @key headful
         * @bug 6996867
         * @summary Render as LCD Text in SrcEa composite mode.
         */

        import java.awt.*;
        import java.awt.event.*;
        import java.awt.image.*;
        import java.util.concurrent.CountDownLatch;
        import java.util.concurrent.TimeUnit;

        public class LCDTextSrcEa extends Component {

            private static final int TIMEOUT = 20000;
            private static volatile boolean nongrey = false;
            private static CountDownLatch latch = new CountDownLatch(1);

            static int SZ=150;
            BufferedImage target =
                new BufferedImage(SZ, SZ, BufferedImage.TYPE_INT_RGB);

            public static void main(String args[]) throws InterruptedException {
                Frame f = new Frame("LCD Text SrcEa Test");
                f.addWindowListener(new WindowAdapter() {
                    @Override
                    public void windowClosing(WindowEvent e) {
                        System.exit(0);
                    }
                });
                LCDTextSrcEa td = new LCDTextSrcEa();
                f.add("Center", td);
                f.pack();
                f.setVisible(true);

                if(!latch.await(TIMEOUT, TimeUnit.MILLISECONDS)) {
                    throw new RuntimeException("ERROR: Test paint method has not finished for " + TIMEOUT + "msec");
                }

                f.dispose();

                if (!nongrey) {
                    throw new RuntimeException("No LCD text found");
                }
            }

            public Dimension getPreferredSize() {
                return new Dimension(SZ,SZ);
            }

            public void paint(Graphics gx) {

                Graphics2D g2d = (Graphics2D) target.getGraphics();
                g2d.setColor(Color.white);
                g2d.fillRect(0, 0, getWidth(), getHeight());

                g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC, 0.01f));
                g2d.setRenderingHint(
                        RenderingHints.KEY_TEXT_ANTIALIASING,
                        RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_VBGR);
                g2d.setRenderingHint(
                       RenderingHints.KEY_ANTIALIASING,
                       RenderingHints.VALUE_ANTIALIAS_ON);

                g2d.setColor(Color.black);
                g2d.drawString("Some sample text.", 10, 20);
                gx.drawImage(target, 0, 0, null);

                //Test BI: should be some non-greyscale color
                for (int px=0;px<SZ;px++) {
                    for (int py=0;py<SZ;py++) {
                        int rgb = target.getRGB(px, py);
                        int r = (rgb & 0xff0000) >> 16;
                        int g = (rgb & 0x00ff00) >> 8;
                        int b = (rgb & 0x0000ff);
                        if (r != g || r !=b || g != b) {
                             nongrey=true;
                             break;
                        }
                    }
                }
                latch.countDown();
            }
        }

        FREQUENCY : always


        Attachments

          Issue Links

            Activity

              People

                prr Philip Race
                webbuggrp Webbug Group
                Votes:
                0 Vote for this issue
                Watchers:
                7 Start watching this issue

                Dates

                  Created:
                  Updated:
                  Resolved: