Skip to content

Commit b38328f

Browse files
committed
Add non-headless java.desktop integration test
1 parent 59c41b3 commit b38328f

2 files changed

Lines changed: 81 additions & 5 deletions

File tree

substratevm/mx.substratevm/mx_substratevm.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ def _is_post_merge_or_weekly_job():
255255
return 'post-merge' in build_name or 'weekly' in build_name
256256

257257

258-
def _should_run_headless_java_desktop_integration():
258+
def _should_run_java_desktop_integration():
259259
tags = tuple(Task.tags or ())
260260
return _is_post_merge_or_weekly_job() or any(tag == GraalTags.headless_java_desktop_integration for tag in tags)
261261

@@ -523,13 +523,13 @@ def svm_gate_body(args, tasks):
523523
with native_image_context(IMAGE_ASSERTION_FLAGS):
524524
native_unittests_task(args.extra_image_builder_arguments)
525525

526-
with Task('Headless java.desktop integration test', tasks, tags=[GraalTags.headless_java_desktop_integration]) as t:
527-
if t and _should_run_headless_java_desktop_integration():
526+
with Task('java.desktop integration tests', tasks, tags=[GraalTags.headless_java_desktop_integration]) as t:
527+
if t and _should_run_java_desktop_integration():
528528
if mx.is_windows():
529529
mx.warn('Headless java.desktop integration test does not run on Windows')
530530
else:
531531
with native_image_context(IMAGE_ASSERTION_FLAGS):
532-
headless_java_desktop_integration_task(args.extra_image_builder_arguments)
532+
java_desktop_integration_task(args.extra_image_builder_arguments)
533533

534534
with Task('conditional configuration tests', tasks, tags=[GraalTags.condconfig]) as t:
535535
if t:
@@ -757,12 +757,13 @@ def native_unittests_task(extra_build_args=None):
757757
native_image_context_run(_native_unittest, computed)
758758

759759

760-
def headless_java_desktop_integration_task(extra_build_args=None):
760+
def java_desktop_integration_task(extra_build_args=None):
761761
extra_build_args = list(extra_build_args or [])
762762
build_args = extra_build_args + svm_experimental_options(['-H:Preserve=module=java.desktop'])
763763
native_unittest([
764764
'--test-classes-per-run', '1',
765765
'com.oracle.svm.integrationtest.HeadlessJavaDesktopTest',
766+
'com.oracle.svm.integrationtest.NonHeadlessJavaDesktopTest',
766767
'--build-args',
767768
] + build_args)
768769

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
* Copyright (c) 2026, 2026, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation. Oracle designates this
8+
* particular file as subject to the "Classpath" exception as provided
9+
* by Oracle in the LICENSE file that accompanied this code.
10+
*
11+
* This code is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
* version 2 for more details (a copy is included in the LICENSE file that
15+
* accompanied this code).
16+
*
17+
* You should have received a copy of the GNU General Public License version
18+
* 2 along with this work; if not, write to the Free Software Foundation,
19+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+
*
21+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+
* or visit www.oracle.com if you need additional information or have any
23+
* questions.
24+
*/
25+
package com.oracle.svm.integrationtest;
26+
27+
import java.awt.AWTError;
28+
import java.awt.Dimension;
29+
import java.awt.GraphicsEnvironment;
30+
import java.awt.HeadlessException;
31+
import java.awt.Toolkit;
32+
import java.awt.image.BufferedImage;
33+
import java.io.ByteArrayOutputStream;
34+
35+
import javax.imageio.ImageIO;
36+
37+
import org.junit.Assert;
38+
import org.junit.Assume;
39+
import org.junit.Test;
40+
41+
public class NonHeadlessJavaDesktopTest {
42+
@Test
43+
public void nonHeadlessJavaDesktopSmokeTest() throws Exception {
44+
String osName = System.getProperty("os.name", "");
45+
Assume.assumeTrue(osName.startsWith("Linux"));
46+
47+
String display = System.getenv("DISPLAY");
48+
Assume.assumeTrue(display != null && !display.isEmpty());
49+
50+
System.clearProperty("java.awt.headless");
51+
Toolkit toolkit;
52+
Dimension screenSize;
53+
try {
54+
Assume.assumeFalse(GraphicsEnvironment.isHeadless());
55+
toolkit = Toolkit.getDefaultToolkit();
56+
screenSize = toolkit.getScreenSize();
57+
} catch (AWTError | HeadlessException e) {
58+
Assume.assumeNoException(e);
59+
return;
60+
}
61+
Assert.assertTrue("Invalid screen width: " + screenSize.width, screenSize.width > 0);
62+
Assert.assertTrue("Invalid screen height: " + screenSize.height, screenSize.height > 0);
63+
64+
BufferedImage image = new BufferedImage(4, 4, BufferedImage.TYPE_INT_ARGB);
65+
ByteArrayOutputStream output = new ByteArrayOutputStream();
66+
Assert.assertTrue("No PNG writer available", ImageIO.write(image, "png", output));
67+
68+
byte[] bytes = output.toByteArray();
69+
Assert.assertTrue("PNG output is empty", bytes.length > 8);
70+
Assert.assertEquals((byte) 0x89, bytes[0]);
71+
Assert.assertEquals((byte) 'P', bytes[1]);
72+
Assert.assertEquals((byte) 'N', bytes[2]);
73+
Assert.assertEquals((byte) 'G', bytes[3]);
74+
}
75+
}

0 commit comments

Comments
 (0)