Skip to content

Commit 1b12155

Browse files
committed
support hotspot gtest
1 parent 6607390 commit 1b12155

6 files changed

Lines changed: 251 additions & 24 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: 91 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -238,26 +238,102 @@ build_jdk8u: -bootstrap $(JDK8_JDK_SRC)
238238
[[ $$? -eq 0 ]] || exit 127; \
239239
}
240240

241+
# configure for jdk17u
242+
# $1 extra configure options
243+
define configure_jdk17u
244+
bash configure \
245+
--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+
$(1)
257+
endef
258+
241259
# compile hotspot and java.base from jdk17u
242260
build_jdk17u: -bootstrap
243261
{ \
244262
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-
; \
263+
$(call configure_jdk17u) ; \
257264
fi; \
258265
}
259266
make $(JDK_MAKE_OPTS) CONF=linux-$(CVM_ARCH)-server-$(MODE) hotspot jdk.jdwp.agent
260267

268+
GTEST_VERSION ?= $(shell sed -n 's/^GTEST_VERSION=//p' $(WORKSPACE)/make/conf/github-actions.conf | head -n 1)
269+
GTEST_ROOT := $(WORKSPACE)/.gtest
270+
GTEST_ARCHIVE := $(GTEST_ROOT)/release-$(GTEST_VERSION).tar.gz
271+
GTEST_URL := https://github.com/google/googletest/archive/refs/tags/v$(GTEST_VERSION).tar.gz
272+
GTEST_DIR := $(GTEST_ROOT)/googletest-$(GTEST_VERSION)
273+
GTEST_HEADER := $(GTEST_DIR)/googletest/include/gtest/gtest.h
274+
275+
$(GTEST_HEADER):
276+
@echo "Installing googletest $(GTEST_VERSION) to $(GTEST_DIR)"
277+
{ \
278+
set -e; \
279+
[[ -d $(GTEST_ROOT) ]] || mkdir -p $(GTEST_ROOT); \
280+
rm -f $(GTEST_ARCHIVE); \
281+
wget -q $(GTEST_URL) -O $(GTEST_ARCHIVE); \
282+
rm -fr $(GTEST_DIR); \
283+
tar xf $(GTEST_ARCHIVE) -C $(GTEST_ROOT); \
284+
rm -f $(GTEST_ARCHIVE); \
285+
}
286+
287+
HOTSPOT_GTEST_BUILD_DIR := $(JDK17_SRCROOT)/build/linux-$(CVM_ARCH)-server-$(MODE)
288+
HOTSPOT_GTEST_LAUNCHER := $(HOTSPOT_GTEST_BUILD_DIR)/images/test/hotspot/gtest/server/gtestLauncher
289+
HOTSPOT_GTEST_TEST ?= gtest:all
290+
HOTSPOT_GTEST_SELECTOR := $(patsubst %/server,%,$(patsubst gtest:%,%,$(HOTSPOT_GTEST_TEST)))
291+
HOTSPOT_GTEST_FILTER := $(if $(filter all,$(HOTSPOT_GTEST_SELECTOR)),,--gtest_filter=$(HOTSPOT_GTEST_SELECTOR)*)
292+
HOTSPOT_GTEST_JDKDIR := $(OUTPUTDIR)/$(DISTRO_NAME)
293+
HOTSPOT_GTEST_WORKDIR := $(HOTSPOT_GTEST_BUILD_DIR)/gtest-manual
294+
HOTSPOT_GTEST_RESULT_DIR := $(HOTSPOT_GTEST_BUILD_DIR)/gtest-results
295+
296+
ifeq ($(SKIP_BUILD), true)
297+
-configure_jdk17u_gtest: $(GTEST_HEADER) -bootstrap
298+
else
299+
-configure_jdk17u_gtest: $(GTEST_HEADER) cvm8default17
300+
endif
301+
{ \
302+
if [[ ! -f $(HOTSPOT_GTEST_BUILD_DIR)/spec.gmk ]] || \
303+
! grep -Fqx 'GTEST_FRAMEWORK_SRC := $(GTEST_DIR)' $(HOTSPOT_GTEST_BUILD_DIR)/spec.gmk 2>/dev/null; then \
304+
$(call configure_jdk17u,--with-gtest=$(GTEST_DIR)) ; \
305+
fi; \
306+
}
307+
308+
build_gtest_hotspot17: -configure_jdk17u_gtest
309+
$(MAKE) $(JDK_MAKE_OPTS) CONF=linux-$(CVM_ARCH)-server-$(MODE) test-image-hotspot-gtest
310+
311+
ifeq ($(SKIP_BUILD), true)
312+
test_gtest_hotspot17:
313+
else
314+
test_gtest_hotspot17: build_gtest_hotspot17
315+
endif
316+
@echo
317+
@echo "Running hotspot gtest \"$(HOTSPOT_GTEST_TEST)\""
318+
@echo " Launcher: $(HOTSPOT_GTEST_LAUNCHER)"
319+
@echo " JDK under test: $(HOTSPOT_GTEST_JDKDIR)"
320+
@echo " Work dir: $(HOTSPOT_GTEST_WORKDIR)"
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+
$(HOTSPOT_GTEST_LAUNCHER) \
327+
-jdk $(HOTSPOT_GTEST_JDKDIR) \
328+
$(HOTSPOT_GTEST_FILTER) \
329+
--gtest_output=xml:$(HOTSPOT_GTEST_RESULT_DIR)/gtest.xml \
330+
--gtest_catch_exceptions=0 \
331+
> >(tee $(HOTSPOT_GTEST_RESULT_DIR)/gtest.txt); \
332+
exit_code=$$?; \
333+
echo $$exit_code > $(HOTSPOT_GTEST_RESULT_DIR)/exitcode.txt; \
334+
exit $$exit_code; \
335+
}
336+
261337
################ alternative kernel classes ########
262338
# here we copy the JDK17 kernel classes to separate diretory,
263339
# and tweak the code to fit into JDK8's boots.
@@ -400,3 +476,6 @@ help:
400476
@echo " Run CVM8 jtreg8 tests in directory $(CVM8_SRCROOT)/hotspot/test"
401477
@echo " make test_cvm8 JT_TEST=<test selection>"
402478
@echo " Run additional jtreg8 tests for CVM8 in directory test"
479+
@echo " make test_gtest_hotspot17 HOTSPOT_GTEST_TEST=<gtest selection>"
480+
@echo " Run hotspot gtests directly against the CVM output image"
481+
@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)