Skip to content

Commit 236eb49

Browse files
committed
support hotspot gtest
1 parent 6607390 commit 236eb49

6 files changed

Lines changed: 257 additions & 33 deletions

File tree

.github/workflows/build-linux.yml

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -101,18 +101,16 @@ jobs:
101101
shell: bash
102102

103103
- name: 'Pack bundles'
104-
if: matrix.debug-level == 'release'
105104
run: |
106-
tar czf CompoundVM_${{ steps.version.outputs.version }}_${{ inputs.platform }}.tar.gz -C output CompoundVM_${{ steps.version.outputs.version }}_${{ inputs.platform }}
107-
tar czf CompoundVM_${{ steps.version.outputs.version }}_jvm_patch_${{ inputs.platform }}.tar.gz -C output/CompoundVM_${{ steps.version.outputs.version }}_jvm_patch_${{ inputs.platform }} .
105+
tar czf CompoundVM_${{ steps.version.outputs.version }}_${{ inputs.platform }}_${{ matrix.debug-level }}.tar.gz -C output CompoundVM_${{ steps.version.outputs.version }}_${{ inputs.platform }}
106+
tar czf CompoundVM_${{ steps.version.outputs.version }}_jvm_patch_${{ inputs.platform }}_${{ matrix.debug-level }}.tar.gz -C output/CompoundVM_${{ steps.version.outputs.version }}_jvm_patch_${{ inputs.platform }} .
108107
shell: bash
109108

110109
- name: 'Upload bundles'
111110
uses: actions/upload-artifact@v4
112-
if: matrix.debug-level == 'release'
113111
with:
114-
name: CompoundVM_${{ steps.version.outputs.version }}_${{ inputs.platform }}.tar.gz
115-
path: CompoundVM_${{ steps.version.outputs.version }}_${{ inputs.platform }}.tar.gz
112+
name: CompoundVM_${{ steps.version.outputs.version }}_${{ inputs.platform }}_${{ matrix.debug-level }}.tar.gz
113+
path: CompoundVM_${{ steps.version.outputs.version }}_${{ inputs.platform }}_${{ matrix.debug-level }}.tar.gz
116114
retention-days: 1
117115
if-no-files-found: error
118116
overwrite: true
@@ -121,8 +119,8 @@ jobs:
121119
uses: actions/upload-artifact@v4
122120
if: matrix.debug-level == 'release'
123121
with:
124-
name: CompoundVM_${{ steps.version.outputs.version }}_jvm_patch_${{ inputs.platform }}.tar.gz
125-
path: CompoundVM_${{ steps.version.outputs.version }}_jvm_patch_${{ inputs.platform }}.tar.gz
122+
name: CompoundVM_${{ steps.version.outputs.version }}_jvm_patch_${{ inputs.platform }}_${{ matrix.debug-level }}.tar.gz
123+
path: CompoundVM_${{ steps.version.outputs.version }}_jvm_patch_${{ inputs.platform }}_${{ matrix.debug-level }}.tar.gz
126124
retention-days: 1
127125
if-no-files-found: error
128126
overwrite: true

.github/workflows/gtest-linux.yml

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
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+
permissions:
31+
contents: read
32+
pull-requests: write
33+
34+
on:
35+
workflow_call:
36+
inputs:
37+
platform:
38+
required: true
39+
type: string
40+
runs-on:
41+
required: true
42+
type: string
43+
debug-levels:
44+
required: false
45+
type: string
46+
default: '[ "fastdebug", "release" ]'
47+
apt-gcc-version:
48+
required: true
49+
type: string
50+
apt-architecture:
51+
required: false
52+
type: string
53+
apt-extra-packages:
54+
required: false
55+
type: string
56+
57+
jobs:
58+
gtest-linux:
59+
name: gtest
60+
runs-on: ${{ inputs.runs-on }}
61+
62+
strategy:
63+
fail-fast: false
64+
matrix:
65+
debug-level: ${{ fromJSON(inputs.debug-levels) }}
66+
67+
steps:
68+
- name: 'Checkout the JDK source'
69+
uses: actions/checkout@v3
70+
71+
- name: 'Determine version'
72+
id: version
73+
run: echo "::set-output name=version::$(cat ./cvm/conf/version)"
74+
75+
- name: 'Set architecture'
76+
id: arch
77+
run: |
78+
# Set a proper suffix for packages if using a different architecture
79+
if [[ '${{ inputs.apt-architecture }}' != '' ]]; then
80+
echo 'suffix=:${{ inputs.apt-architecture }}' >> $GITHUB_OUTPUT
81+
fi
82+
83+
# Upgrading apt to solve libc6 installation bugs, see JDK-8260460.
84+
- name: 'Install toolchain and dependencies'
85+
run: |
86+
# Install dependencies using apt-get
87+
if [[ '${{ inputs.apt-architecture }}' != '' ]]; then
88+
sudo dpkg --add-architecture ${{ inputs.apt-architecture }}
89+
fi
90+
sudo apt-get update
91+
sudo apt-get install --only-upgrade apt
92+
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 }}
93+
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 }}
94+
95+
- name: 'Build'
96+
run: |
97+
make -f cvm.mk build_gtest_hotspot17 MODE=${{ matrix.debug-level}} SKIP_BUILD=true
98+
shell: bash
99+
100+
- name: 'Get bundles'
101+
uses: actions/download-artifact@v4
102+
with:
103+
name: CompoundVM_${{ steps.version.outputs.version }}_${{ inputs.platform }}_${{ matrix.debug-level }}.tar.gz
104+
path: .
105+
106+
- name: 'Unpack bundles'
107+
run: |
108+
rm -rf gtest-jdk
109+
mkdir gtest-jdk
110+
tar xzvf CompoundVM_${{ steps.version.outputs.version }}_${{ inputs.platform }}_${{ matrix.debug-level }}.tar.gz -C gtest-jdk --strip-components=1
111+
shell: bash
112+
113+
- name: 'Run gtests'
114+
run: |
115+
make -f cvm.mk test_gtest_hotspot17 MODE=${{ matrix.debug-level}} SKIP_BUILD=true HOTSPOT_GTEST_JDKDIR=${PWD}/gtest-jdk
116+
shell: bash

.github/workflows/main.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,30 @@ 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:
142+
- build-linux-x64
143+
uses: ./.github/workflows/gtest-linux.yml
144+
with:
145+
platform: linux_x64
146+
apt-gcc-version: '9'
147+
runs-on: ubuntu-22.04
148+
149+
gtest-linux-aarch64:
150+
name: linux-aarch64
151+
needs:
152+
- build-linux-aarch64
153+
uses: ./.github/workflows/gtest-linux.yml
154+
with:
155+
platform: linux_aarch64
156+
apt-gcc-version: '9'
157+
runs-on: ubuntu-22.04-arm
158+
135159
###
136160
### Test jobs
137161
###
@@ -165,8 +189,10 @@ jobs:
165189
if: always()
166190
needs:
167191
- build-linux-x64
192+
- gtest-linux-x64
168193
- test-linux-x64
169194
- build-linux-aarch64
195+
- gtest-linux-aarch64
170196
- test-linux-aarch64
171197

172198
steps:

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,14 @@ jobs:
8181
- name: 'Get bundles'
8282
uses: actions/download-artifact@v4
8383
with:
84-
name: CompoundVM_${{ steps.version.outputs.version }}_${{ inputs.platform }}.tar.gz
84+
name: CompoundVM_${{ steps.version.outputs.version }}_${{ inputs.platform }}_${{ inputs.debug-level }}.tar.gz
8585
path: .
8686

8787
- name: 'Unpack bundles'
8888
run: |
8989
rm -rf cvm/build/jdk8
9090
mkdir -p cvm/build/jdk8
91-
tar xzvf CompoundVM_${{ steps.version.outputs.version }}_${{ inputs.platform }}.tar.gz -C cvm/build/jdk8 --strip-components=1
91+
tar xzvf CompoundVM_${{ steps.version.outputs.version }}_${{ inputs.platform }}_${{ inputs.debug-level }}.tar.gz -C cvm/build/jdk8 --strip-components=1
9292
shell: bash
9393

9494
- name: 'Run tests'
@@ -100,13 +100,13 @@ jobs:
100100
- name: 'Get bundles jvm patch'
101101
uses: actions/download-artifact@v4
102102
with:
103-
name: CompoundVM_${{ steps.version.outputs.version }}_jvm_patch_${{ inputs.platform }}.tar.gz
103+
name: CompoundVM_${{ steps.version.outputs.version }}_jvm_patch_${{ inputs.platform }}_${{ inputs.debug-level }}.tar.gz
104104
path: .
105105

106106
- name: 'Run sanity test jvm patch'
107107
run: |
108108
wget -nc https://github.com/adoptium/temurin8-binaries/releases/download/jdk8u372-b07/OpenJDK8U-jdk_${{ inputs.arch }}_linux_hotspot_8u372b07.tar.gz
109109
tar xzf OpenJDK8U-jdk_${{ inputs.arch }}_linux_hotspot_8u372b07.tar.gz
110-
tar xzf CompoundVM_${{ steps.version.outputs.version }}_jvm_patch_${{ inputs.platform }}.tar.gz -C jdk8u372-b07/
110+
tar xzf CompoundVM_${{ steps.version.outputs.version }}_jvm_patch_${{ inputs.platform }}_${{ inputs.debug-level }}.tar.gz -C jdk8u372-b07/
111111
jdk8u372-b07/bin/java -version 2>&1 | grep "CompoundVM"
112112
shell: bash

cvm.mk

Lines changed: 97 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,44 @@ 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 := $(HOTSPOT_GTEST_BUILD_DIR)/gtest-manual
70+
HOTSPOT_GTEST_RESULT_DIR := $(HOTSPOT_GTEST_BUILD_DIR)/gtest-results
71+
HOTSPOT_GTEST_EXITCODE := $(HOTSPOT_GTEST_RESULT_DIR)/exitcode.txt
72+
CVM_CONFIGURE_URL := \
73+
--with-vendor-url="https://github.com/bytedance/CompoundVM" \
74+
--with-vendor-bug-url="https://github.com/bytedance/CompoundVM/issues" \
75+
--with-vendor-vm-bug-url="https://github.com/bytedance/CompoundVM/issues"
76+
JDK8_CONFIGURE_OPTIONS = \
77+
--with-debug-level=$(MODE) \
78+
--with-boot-jdk=$(BOOTJDK8) \
79+
--with-milestone=fcs \
80+
--with-user-release-suffix="cvm" \
81+
--with-vendor-name="ByteDance" \
82+
$(CVM_CONFIGURE_URL)
83+
JDK17_CONFIGURE_OPTIONS = \
84+
--with-debug-level=$(MODE) \
85+
--with-boot-jdk=$(BOOTJDK17) \
86+
--with-hotspot-target-classlib=8 \
87+
--with-vendor-name="ByteDance" \
88+
$(CVM_CONFIGURE_URL) \
89+
--without-version-pre \
90+
--without-version-opt \
91+
--with-cvm-version-string=$(VERSION) \
92+
--with-vendor-name="CompoundVM"
93+
JDK17_GTEST_CONFIGURE_OPTIONS = --with-gtest=$(GTEST_DIR)
5694

5795
# compile set of alternative kernel/application classes
5896
# $1 source directory
@@ -154,6 +192,18 @@ $(JDK8_JDK_SRC):
154192
wget -nc -O $(JDK8_SRC_TAR) $(JDK8_SRC_TAR_URL)
155193
[[ -d $(JDK8_SRCROOT) ]] || (mkdir -p $(JDK8_SRCROOT) && tar -xzf $(JDK8_SRC_TAR) -C $(JDK8_SRCROOT) --strip-components=1)
156194

195+
$(GTEST_HEADER):
196+
@echo "Installing googletest $(GTEST_VERSION) to $(GTEST_DIR)"
197+
{ \
198+
set -e; \
199+
[[ -d $(GTEST_ROOT) ]] || mkdir -p $(GTEST_ROOT); \
200+
rm -f $(GTEST_ARCHIVE); \
201+
wget -q $(GTEST_URL) -O $(GTEST_ARCHIVE); \
202+
rm -fr $(GTEST_DIR); \
203+
tar xf $(GTEST_ARCHIVE) -C $(GTEST_ROOT); \
204+
rm -f $(GTEST_ARCHIVE); \
205+
}
206+
157207
cvm8: jdk8vm17
158208

159209
cvm8default17: jdk8vm17
@@ -224,15 +274,7 @@ endif
224274
build_jdk8u: -bootstrap $(JDK8_JDK_SRC)
225275
{ cd $(JDK8_SRCROOT); \
226276
if [[ "x$$(find ./build -type f -name config.log | grep $(MODE))" = "x" ]]; then \
227-
bash configure --with-debug-level=$(MODE) \
228-
--with-boot-jdk=$(BOOTJDK8) \
229-
--with-milestone=fcs \
230-
--with-user-release-suffix="cvm" \
231-
--with-vendor-name="ByteDance" \
232-
--with-vendor-url="https://github.com/bytedance/CompoundVM" \
233-
--with-vendor-bug-url="https://github.com/bytedance/CompoundVM/issues" \
234-
--with-vendor-vm-bug-url="https://github.com/bytedance/CompoundVM/issues" \
235-
;\
277+
bash configure $(JDK8_CONFIGURE_OPTIONS) ; \
236278
fi; \
237279
make $(JDK_MAKE_OPTS) CONF=linux-$(CVM_ARCH)-normal-server-$(MODE) images; \
238280
[[ $$? -eq 0 ]] || exit 127; \
@@ -242,22 +284,53 @@ build_jdk8u: -bootstrap $(JDK8_JDK_SRC)
242284
build_jdk17u: -bootstrap
243285
{ \
244286
if [[ "x$$(find ./build -type f -name config.log | grep $(MODE))" = "x" ]]; then \
245-
bash configure --with-debug-level=$(MODE) \
246-
--with-boot-jdk=$(BOOTJDK17) \
247-
--with-hotspot-target-classlib=8 \
248-
--with-vendor-name="ByteDance" \
249-
--with-vendor-url="https://github.com/bytedance/CompoundVM" \
250-
--with-vendor-bug-url="https://github.com/bytedance/CompoundVM/issues" \
251-
--with-vendor-vm-bug-url="https://github.com/bytedance/CompoundVM/issues" \
252-
--without-version-pre \
253-
--without-version-opt \
254-
--with-cvm-version-string=$(VERSION) \
255-
--with-vendor-name="CompoundVM" \
256-
; \
287+
bash configure $(JDK17_CONFIGURE_OPTIONS) ; \
257288
fi; \
258289
}
259290
make $(JDK_MAKE_OPTS) CONF=linux-$(CVM_ARCH)-server-$(MODE) hotspot jdk.jdwp.agent
260291

292+
ifeq ($(SKIP_BUILD), true)
293+
-configure_jdk17u_gtest: $(GTEST_HEADER) -bootstrap
294+
else
295+
-configure_jdk17u_gtest: $(GTEST_HEADER) cvm8default17
296+
endif
297+
{ \
298+
if [[ ! -f $(HOTSPOT_GTEST_BUILD_DIR)/spec.gmk ]] || \
299+
! grep -Fqx 'GTEST_FRAMEWORK_SRC := $(GTEST_DIR)' $(HOTSPOT_GTEST_BUILD_DIR)/spec.gmk 2>/dev/null; then \
300+
bash configure $(JDK17_CONFIGURE_OPTIONS) $(JDK17_GTEST_CONFIGURE_OPTIONS) ; \
301+
fi; \
302+
}
303+
304+
build_gtest_hotspot17: -configure_jdk17u_gtest
305+
$(MAKE) $(JDK_MAKE_OPTS) CONF=$(HOTSPOT_GTEST_CONF) test-image-hotspot-gtest
306+
307+
ifeq ($(SKIP_BUILD), true)
308+
test_gtest_hotspot17:
309+
else
310+
test_gtest_hotspot17: build_gtest_hotspot17
311+
endif
312+
@echo
313+
@echo "Running hotspot gtest \"$(HOTSPOT_GTEST_TEST)\""
314+
@echo " Launcher: $(HOTSPOT_GTEST_LAUNCHER)"
315+
@echo " JDK under test: $(HOTSPOT_GTEST_JDKDIR)"
316+
@echo " Work dir: $(HOTSPOT_GTEST_WORKDIR)"
317+
@echo " Test report: $(HOTSPOT_GTEST_RESULT_DIR)"
318+
@echo
319+
@{ \
320+
mkdir -p $(HOTSPOT_GTEST_WORKDIR) $(HOTSPOT_GTEST_RESULT_DIR) && \
321+
cd $(HOTSPOT_GTEST_WORKDIR) && \
322+
set +e; \
323+
$(HOTSPOT_GTEST_LAUNCHER) \
324+
-jdk $(HOTSPOT_GTEST_JDKDIR) \
325+
$(HOTSPOT_GTEST_FILTER) \
326+
--gtest_output=xml:$(HOTSPOT_GTEST_RESULT_DIR)/gtest.xml \
327+
--gtest_catch_exceptions=0 \
328+
> >(tee $(HOTSPOT_GTEST_RESULT_DIR)/gtest.txt); \
329+
exit_code=$$?; \
330+
echo $$exit_code > $(HOTSPOT_GTEST_EXITCODE); \
331+
exit $$exit_code; \
332+
}
333+
261334
################ alternative kernel classes ########
262335
# here we copy the JDK17 kernel classes to separate diretory,
263336
# and tweak the code to fit into JDK8's boots.
@@ -400,3 +473,6 @@ help:
400473
@echo " Run CVM8 jtreg8 tests in directory $(CVM8_SRCROOT)/hotspot/test"
401474
@echo " make test_cvm8 JT_TEST=<test selection>"
402475
@echo " Run additional jtreg8 tests for CVM8 in directory test"
476+
@echo " make test_gtest_hotspot17 HOTSPOT_GTEST_TEST=<gtest selection>"
477+
@echo " Run hotspot gtests directly against the CVM output image"
478+
@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)