Skip to content

Commit dc4cb74

Browse files
committed
support hotspot gtest
1 parent 6607390 commit dc4cb74

5 files changed

Lines changed: 220 additions & 6 deletions

File tree

.github/workflows/gtest-linux.yml

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
# This project is a modified version of OpenJDK, licensed under GPL v2.
2+
# Modifications Copyright (C) 2025 ByteDance Inc.
3+
#
4+
# Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
5+
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6+
#
7+
# This code is free software; you can redistribute it and/or modify it
8+
# under the terms of the GNU General Public License version 2 only, as
9+
# published by the Free Software Foundation. Oracle designates this
10+
# particular file as subject to the "Classpath" exception as provided
11+
# by Oracle in the LICENSE file that accompanied this code.
12+
#
13+
# This code is distributed in the hope that it will be useful, but WITHOUT
14+
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15+
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16+
# version 2 for more details (a copy is included in the LICENSE file that
17+
# accompanied this code).
18+
#
19+
# You should have received a copy of the GNU General Public License version
20+
# 2 along with this work; if not, write to the Free Software Foundation,
21+
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
22+
#
23+
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
24+
# or visit www.oracle.com if you need additional information or have any
25+
# questions.
26+
#
27+
28+
name: 'GTest (linux)'
29+
30+
on:
31+
workflow_call:
32+
inputs:
33+
platform:
34+
required: true
35+
type: string
36+
runs-on:
37+
required: true
38+
type: string
39+
debug-levels:
40+
required: false
41+
type: string
42+
default: '[ "fastdebug", "release" ]'
43+
apt-gcc-version:
44+
required: true
45+
type: string
46+
apt-architecture:
47+
required: false
48+
type: string
49+
apt-extra-packages:
50+
required: false
51+
type: string
52+
53+
jobs:
54+
gtest-linux:
55+
name: gtest
56+
runs-on: ${{ inputs.runs-on }}
57+
58+
strategy:
59+
fail-fast: false
60+
matrix:
61+
debug-level: ${{ fromJSON(inputs.debug-levels) }}
62+
63+
steps:
64+
- name: 'Checkout the JDK source'
65+
uses: actions/checkout@v3
66+
67+
- name: 'Determine version'
68+
id: version
69+
run: echo "::set-output name=version::$(cat ./cvm/conf/version)"
70+
71+
- name: 'Set architecture'
72+
id: arch
73+
run: |
74+
# Set a proper suffix for packages if using a different architecture
75+
if [[ '${{ inputs.apt-architecture }}' != '' ]]; then
76+
echo 'suffix=:${{ inputs.apt-architecture }}' >> $GITHUB_OUTPUT
77+
fi
78+
79+
# Upgrading apt to solve libc6 installation bugs, see JDK-8260460.
80+
- name: 'Install toolchain and dependencies'
81+
run: |
82+
# Install dependencies using apt-get
83+
if [[ '${{ inputs.apt-architecture }}' != '' ]]; then
84+
sudo dpkg --add-architecture ${{ inputs.apt-architecture }}
85+
fi
86+
sudo apt-get update
87+
sudo apt-get install --only-upgrade apt
88+
sudo apt-get install gcc-${{ inputs.apt-gcc-version }} g++-${{ inputs.apt-gcc-version }} libxrandr-dev${{ steps.arch.outputs.suffix }} libxtst-dev${{ steps.arch.outputs.suffix }} libcups2-dev${{ steps.arch.outputs.suffix }} libasound2-dev${{ steps.arch.outputs.suffix }} ${{ inputs.apt-extra-packages }}
89+
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-${{ inputs.apt-gcc-version }} 100 --slave /usr/bin/g++ g++ /usr/bin/g++-${{ inputs.apt-gcc-version }}
90+
91+
- name: 'Build'
92+
run: |
93+
make -f cvm.mk build_hotspot_gtest MODE=${{ matrix.debug-level}}
94+
shell: bash
95+
96+
- name: 'Run gtests'
97+
run: |
98+
make -f cvm.mk test_hotspot_gtest MODE=${{ matrix.debug-level}} SKIP_BUILD=true
99+
shell: bash

.github/workflows/main.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,31 @@ jobs:
132132
# The linux-aarch64 jdk bundle is used as buildjdk for the cross-compile job
133133
if: needs.select.outputs.linux-aarch64 == 'true' || needs.select.outputs.linux-cross-compile == 'true'
134134

135+
###
136+
### GTest jobs
137+
###
138+
139+
gtest-linux-x64:
140+
name: linux-x64
141+
needs: select
142+
uses: ./.github/workflows/gtest-linux.yml
143+
with:
144+
platform: linux_x64
145+
apt-gcc-version: '9'
146+
runs-on: ubuntu-22.04
147+
make-target: 'test_hotspot_gtest'
148+
149+
gtest-linux-aarch64:
150+
name: linux-aarch64
151+
needs: select
152+
uses: ./.github/workflows/gtest-linux.yml
153+
with:
154+
platform: linux_aarch64
155+
apt-gcc-version: '9'
156+
runs-on: ubuntu-22.04-arm
157+
make-target: 'test_hotspot_gtest'
158+
159+
135160
###
136161
### Test jobs
137162
###

.github/workflows/test-cvm8+17.yml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ jobs:
5656
- 'langtools'
5757
- 'cvm8'
5858
- 'hotspot8'
59+
- 'hotspot-gtest'
5960

6061
include:
6162
- test-name: 'jdk/tier1'
@@ -70,6 +71,12 @@ jobs:
7071
- test-name: 'hotspot8'
7172
test-suite: 'hotspot8'
7273

74+
- test-name: 'hotspot-gtest'
75+
test-suite: 'hotspot_gtest'
76+
77+
- test-name: 'hotspot-gtest'
78+
test-suite: 'hotspot_gtest'
79+
7380
steps:
7481
- name: 'Checkout the JDK source'
7582
uses: actions/checkout@v3
@@ -91,12 +98,6 @@ jobs:
9198
tar xzvf CompoundVM_${{ steps.version.outputs.version }}_${{ inputs.platform }}.tar.gz -C cvm/build/jdk8 --strip-components=1
9299
shell: bash
93100

94-
- name: 'Run tests'
95-
id: run-tests
96-
run: |
97-
make -f cvm.mk test_jtreg8_${{ matrix.test-suite }} SKIP_BUILD=true MODE=${{ inputs.debug-level }}
98-
shell: bash
99-
100101
- name: 'Get bundles jvm patch'
101102
uses: actions/download-artifact@v4
102103
with:

cvm.mk

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,22 @@ SRC_BUILDDIR_8 :=
5353
SRC_BUILDDIR_17 :=
5454
SCRIPTS_DIR ?= $(WORKSPACE)/scripts
5555
SKIP_BUILD ?= false
56+
GTEST_VERSION ?= $(shell sed -n 's/^GTEST_VERSION=//p' $(WORKSPACE)/make/conf/github-actions.conf | head -n 1)
57+
GTEST_ROOT := $(WORKSPACE)/.gtest
58+
GTEST_ARCHIVE := $(GTEST_ROOT)/release-$(GTEST_VERSION).tar.gz
59+
GTEST_URL := https://github.com/google/googletest/archive/refs/tags/v$(GTEST_VERSION).tar.gz
60+
GTEST_DIR := $(GTEST_ROOT)/googletest-$(GTEST_VERSION)
61+
GTEST_HEADER := $(GTEST_DIR)/googletest/include/gtest/gtest.h
62+
HOTSPOT_GTEST_CONF := linux-$(CVM_ARCH)-server-$(MODE)
63+
HOTSPOT_GTEST_BUILD_DIR := $(JDK17_SRCROOT)/build/$(HOTSPOT_GTEST_CONF)
64+
HOTSPOT_GTEST_LAUNCHER := $(HOTSPOT_GTEST_BUILD_DIR)/images/test/hotspot/gtest/server/gtestLauncher
65+
HOTSPOT_GTEST_TEST ?= gtest:all
66+
HOTSPOT_GTEST_SELECTOR := $(patsubst %/server,%,$(patsubst gtest:%,%,$(HOTSPOT_GTEST_TEST)))
67+
HOTSPOT_GTEST_FILTER := $(if $(filter all,$(HOTSPOT_GTEST_SELECTOR)),,--gtest_filter=$(HOTSPOT_GTEST_SELECTOR)*)
68+
HOTSPOT_GTEST_JDKDIR := $(OUTPUTDIR)/$(DISTRO_NAME)
69+
HOTSPOT_GTEST_WORKDIR := $(BUILDDIR)/gtest-manual
70+
HOTSPOT_GTEST_RESULT_DIR := $(BUILDDIR)/gtest-results
71+
HOTSPOT_GTEST_EXITCODE := $(HOTSPOT_GTEST_RESULT_DIR)/exitcode.txt
5672

5773
# compile set of alternative kernel/application classes
5874
# $1 source directory
@@ -154,6 +170,18 @@ $(JDK8_JDK_SRC):
154170
wget -nc -O $(JDK8_SRC_TAR) $(JDK8_SRC_TAR_URL)
155171
[[ -d $(JDK8_SRCROOT) ]] || (mkdir -p $(JDK8_SRCROOT) && tar -xzf $(JDK8_SRC_TAR) -C $(JDK8_SRCROOT) --strip-components=1)
156172

173+
$(GTEST_HEADER):
174+
@echo "Installing googletest $(GTEST_VERSION) to $(GTEST_DIR)"
175+
{ \
176+
set -e; \
177+
[[ -d $(GTEST_ROOT) ]] || mkdir -p $(GTEST_ROOT); \
178+
rm -f $(GTEST_ARCHIVE); \
179+
wget -q $(GTEST_URL) -O $(GTEST_ARCHIVE); \
180+
rm -fr $(GTEST_DIR); \
181+
tar xf $(GTEST_ARCHIVE) -C $(GTEST_ROOT); \
182+
rm -f $(GTEST_ARCHIVE); \
183+
}
184+
157185
cvm8: jdk8vm17
158186

159187
cvm8default17: jdk8vm17
@@ -258,6 +286,56 @@ build_jdk17u: -bootstrap
258286
}
259287
make $(JDK_MAKE_OPTS) CONF=linux-$(CVM_ARCH)-server-$(MODE) hotspot jdk.jdwp.agent
260288

289+
-configure_jdk17u_gtest: $(GTEST_HEADER) cvm8default17
290+
{ \
291+
if [[ ! -f $(HOTSPOT_GTEST_BUILD_DIR)/spec.gmk ]] || \
292+
! grep -Fqx 'GTEST_FRAMEWORK_SRC := $(GTEST_DIR)' $(HOTSPOT_GTEST_BUILD_DIR)/spec.gmk 2>/dev/null; then \
293+
bash configure --with-debug-level=$(MODE) \
294+
--with-boot-jdk=$(BOOTJDK17) \
295+
--with-hotspot-target-classlib=8 \
296+
--with-vendor-name="ByteDance" \
297+
--with-vendor-url="https://github.com/bytedance/CompoundVM" \
298+
--with-vendor-bug-url="https://github.com/bytedance/CompoundVM/issues" \
299+
--with-vendor-vm-bug-url="https://github.com/bytedance/CompoundVM/issues" \
300+
--without-version-pre \
301+
--without-version-opt \
302+
--with-cvm-version-string=$(VERSION) \
303+
--with-vendor-name="CompoundVM" \
304+
--with-gtest=$(GTEST_DIR) \
305+
; \
306+
fi; \
307+
}
308+
309+
build_hotspot_gtest: -configure_jdk17u_gtest
310+
$(MAKE) $(JDK_MAKE_OPTS) CONF=$(HOTSPOT_GTEST_CONF) test-image-hotspot-gtest
311+
312+
ifeq ($(SKIP_BUILD), true)
313+
test_hotspot_gtest:
314+
else
315+
test_hotspot_gtest: build_hotspot_gtest
316+
endif
317+
@echo
318+
@echo "Running hotspot gtest \"$(HOTSPOT_GTEST_TEST)\""
319+
@echo " Launcher: $(HOTSPOT_GTEST_LAUNCHER)"
320+
@echo " JDK under test: $(HOTSPOT_GTEST_JDKDIR)"
321+
@echo " Test report: $(HOTSPOT_GTEST_RESULT_DIR)"
322+
@echo
323+
@{ \
324+
mkdir -p $(HOTSPOT_GTEST_WORKDIR) $(HOTSPOT_GTEST_RESULT_DIR) && \
325+
cd $(HOTSPOT_GTEST_WORKDIR) && \
326+
set +e; \
327+
LD_LIBRARY_PATH=$(HOTSPOT_GTEST_JDKDIR)/jre/lib:$(HOTSPOT_GTEST_JDKDIR)/jre/lib/$(ARCH_DIR):$(HOTSPOT_GTEST_JDKDIR)/jre/lib/$(ARCH_DIR)/server17 \
328+
$(HOTSPOT_GTEST_LAUNCHER) \
329+
-jdk $(HOTSPOT_GTEST_JDKDIR) \
330+
$(HOTSPOT_GTEST_FILTER) \
331+
--gtest_output=xml:$(HOTSPOT_GTEST_RESULT_DIR)/gtest.xml \
332+
--gtest_catch_exceptions=0 \
333+
> >(tee $(HOTSPOT_GTEST_RESULT_DIR)/gtest.txt); \
334+
exit_code=$$?; \
335+
echo $$exit_code > $(HOTSPOT_GTEST_EXITCODE); \
336+
exit $$exit_code; \
337+
}
338+
261339
################ alternative kernel classes ########
262340
# here we copy the JDK17 kernel classes to separate diretory,
263341
# and tweak the code to fit into JDK8's boots.
@@ -400,3 +478,6 @@ help:
400478
@echo " Run CVM8 jtreg8 tests in directory $(CVM8_SRCROOT)/hotspot/test"
401479
@echo " make test_cvm8 JT_TEST=<test selection>"
402480
@echo " Run additional jtreg8 tests for CVM8 in directory test"
481+
@echo " make test_hotspot_gtest HOTSPOT_GTEST_TEST=<gtest selection>"
482+
@echo " Run hotspot gtests directly against the CVM output image"
483+
@echo " e.g. HOTSPOT_GTEST_TEST='gtest:all'"

src/hotspot/os/linux/os_linux.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2707,10 +2707,18 @@ void os::jvm_path(char *buf, jint buflen) {
27072707
len = strlen(buf);
27082708
assert(len < buflen, "Ran out of buffer room");
27092709
jrelib_p = buf + len;
2710+
2711+
#if HOTSPOT_TARGET_CLASSLIB == 8
2712+
snprintf(jrelib_p, buflen-len, "/jre/lib/%s", HOTSPOT_LIB_ARCH);
2713+
if (0 != access(buf, F_OK)) {
2714+
snprintf(jrelib_p, buflen-len, "/lib/%s", HOTSPOT_LIB_ARCH);
2715+
}
2716+
#else
27102717
snprintf(jrelib_p, buflen-len, "/jre/lib");
27112718
if (0 != access(buf, F_OK)) {
27122719
snprintf(jrelib_p, buflen-len, "/lib");
27132720
}
2721+
#endif
27142722

27152723
if (0 == access(buf, F_OK)) {
27162724
// Use current module name "libjvm.so"

0 commit comments

Comments
 (0)