Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split out java/kotlin unit tests #26897

Merged
merged 28 commits into from
May 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
724f129
Add JAVA_PATH to our dockerfile environment variables
andreilitvin May 25, 2023
2e13896
Use matter_enable_java_compilation instead of build_java_matter_contr…
andreilitvin May 25, 2023
cf83c33
Remove useless bit
andreilitvin May 25, 2023
11e928b
Fix unit tests once we have java available
andreilitvin May 25, 2023
f928299
Fix seting up java deps if files already there ... this now runs in 5…
andreilitvin May 25, 2023
6d0c86b
Merge branch 'master' into java_test_run
andreilitvin May 26, 2023
d2bd022
Do not re-download java dependencies every time.
andreilitvin May 26, 2023
17a3aaf
Restyled by shellharden
restyled-commits May 26, 2023
07d3ea1
Restyled by shfmt
restyled-commits May 26, 2023
b9af9fc
Merge branch 'faster_java_deps_setup' into java_test_run
andreilitvin May 26, 2023
03ece95
Prepare for unit tests
andreilitvin May 26, 2023
d7af877
Make output class directory unique for java
andreilitvin May 26, 2023
04c777a
Restyled by gn
restyled-commits May 26, 2023
5a90fbc
Undo unintentional change
andreilitvin May 26, 2023
e403bb2
Allow separate unit test runs for java
andreilitvin May 26, 2023
c23cce7
Restyled by gn
restyled-commits May 26, 2023
31e4840
Restyled by shellharden
restyled-commits May 26, 2023
20e0c4c
Restyled by shfmt
restyled-commits May 26, 2023
3ce0001
Undo unintentional change in test name
andreilitvin May 26, 2023
b97fc8d
Fix yaml file
andreilitvin May 26, 2023
d9fec5e
Force java path
andreilitvin May 26, 2023
909b1f8
Attempt to fix the run path ... again
andreilitvin May 26, 2023
e9f8bcb
Update to not use run_in_build_env and switch to multi-line run script
andreilitvin May 26, 2023
d0dfa8e
Do not attempt to compile pure java variant for android (keep only li…
andreilitvin May 26, 2023
9c83e76
Fix required jar: tlv now needs copy as the tlv content is not part o…
andreilitvin May 26, 2023
bec3c24
Merge branch 'unique_target_class_output' into java_test_run
andreilitvin May 26, 2023
86b3960
Merge branch 'master' into java_test_run
andy31415 May 29, 2023
60c2906
Ensure unit tests pretend java path is set
andy31415 May 29, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions .github/workflows/java-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,12 @@ jobs:

env:
TSAN_OPTIONS: "halt_on_error=1 suppressions=scripts/tests/chiptest/tsan-linux-suppressions.txt"
JAVA_PATH: /usr/lib/jvm/java-8-openjdk-amd64

if: github.actor != 'restyled-io[bot]'
runs-on: ubuntu-latest

container:
image: connectedhomeip/chip-build-java:0.7.3
image: connectedhomeip/chip-build-java:0.7.15
options: --privileged --sysctl "net.ipv6.conf.all.disable_ipv6=0
net.ipv4.conf.all.forwarding=0 net.ipv6.conf.all.forwarding=0"

Expand Down Expand Up @@ -79,7 +78,30 @@ jobs:
path: |
.environment/gn_out/.ninja_log
.environment/pigweed-venv/*.log
- name: Generate unit tests
timeout-minutes: 1
run: |
scripts/run_in_build_env.sh \
'./scripts/build/build_examples.py \
--target linux-x64-tests \
gen \
'
- name: Build unit tests
timeout-minutes: 25
run: scripts/run_in_build_env.sh 'ninja -C out/linux-x64-tests src:java_controller_tests'

- name: Run unit tests
timeout-minutes: 10
# TODO: this direct path loading is not maintainable. Our build system should define and
# support test classes.
run: |
$JAVA_PATH/bin/java \
-cp 'third_party/java_deps/artifacts/*:out/linux-x64-tests/lib/src/controller/java/*' \
org.junit.runner.JUnitCore \
chip.tlv.TlvWriterTest \
chip.tlv.TlvReadWriteTest \
chip.tlv.TlvReaderTest \
chip.jsontlv.JsonToTlvToJsonTest
- name: Build Java Matter Controller and all clusters app
timeout-minutes: 50
run: |
Expand Down
4 changes: 2 additions & 2 deletions build/chip/java/config.gni
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
java_path = getenv("JAVA_PATH")
declare_args() {
java_matter_controller_dependent_paths = []
build_java_matter_controller = false
matter_enable_java_compilation = false
if (java_path != "" && current_os != "android") {
java_matter_controller_dependent_paths += [ "${java_path}/include/" ]

Expand All @@ -27,6 +27,6 @@ declare_args() {
[ "${java_path}/include/linux/" ]
}

build_java_matter_controller = true
matter_enable_java_compilation = true
}
}
4 changes: 2 additions & 2 deletions build/chip/java/rules.gni
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ kotlinc_runner = "${chip_root}/build/chip/java/kotlinc_runner.py"
jar_runner = "${chip_root}/build/chip/java/jar_runner.py"
write_build_config = "${chip_root}/build/chip/java/write_build_config.py"

assert(android_sdk_root != "" || build_java_matter_controller,
"android_sdk_root or java_path must be specified")
assert(android_sdk_root != "" || matter_enable_java_compilation,
"android_sdk_root must be specified or JAVA_PATH must be set.")

# Declare a java library target
#
Expand Down
2 changes: 1 addition & 1 deletion build/config/compiler/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ config("strict_warnings") {
cflags += [ "-Wconversion" ]
}

if (build_java_matter_controller) {
if (matter_enable_java_compilation) {
cflags -= [ "-Wshadow" ]
}

Expand Down
4 changes: 0 additions & 4 deletions examples/java-matter-controller/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,7 @@ kotlin_binary("java-matter-controller") {
output_name = "java-matter-controller"
deps = [
":java",
"${chip_root}/src/controller/java:json_to_tlv_to_json_test",
"${chip_root}/src/controller/java:onboarding_payload",
"${chip_root}/src/controller/java:tlv_read_write_test",
"${chip_root}/src/controller/java:tlv_reader_test",
"${chip_root}/src/controller/java:tlv_writer_test",
"${chip_root}/third_party/java_deps:kotlin-stdlib",
]

Expand Down
1 change: 1 addition & 0 deletions scripts/build/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def build_actual_output(root: str, out: str, args: List[str]) -> List[str]:
'NXP_K32W0_SDK_ROOT': 'TEST_NXP_K32W0_SDK_ROOT',
'IMX_SDK_ROOT': 'IMX_SDK_ROOT',
'TI_SYSCONFIG_ROOT': 'TEST_TI_SYSCONFIG_ROOT',
'JAVA_PATH': 'TEST_JAVA_PATH',
})

retval = subprocess.run([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ bash -c '
PKG_CONFIG_PATH="SYSROOT_AARCH64/lib/aarch64-linux-gnu/pkgconfig" \
gn gen --check --fail-on-unused-args --export-compile-commands --root={root}/examples/chip-tool '"'"'--args=chip_inet_config_enable_ipv4=false is_clang=true target_cpu="arm64" sysroot="SYSROOT_AARCH64"'"'"' {out}/linux-arm64-chip-tool-ipv6only-clang'

# Setting up Java deps
third_party/java_deps/set_up_java_deps.sh

# Building linux-arm64-chip-tool-ipv6only-clang
bash -c '
PKG_CONFIG_PATH="SYSROOT_AARCH64/lib/aarch64-linux-gnu/pkgconfig" \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ bash -c '
PKG_CONFIG_PATH="SYSROOT_AARCH64/lib/aarch64-linux-gnu/pkgconfig" \
gn gen --check --fail-on-unused-args --export-compile-commands --root={root}/examples/ota-requestor-app/linux '"'"'--args=chip_inet_config_enable_ipv4=false chip_config_network_layer_ble=false chip_enable_wifi=false chip_enable_openthread=false is_clang=true chip_crypto="mbedtls" target_cpu="arm64" sysroot="SYSROOT_AARCH64"'"'"' {out}/linux-arm64-ota-requestor-nodeps-ipv6only'

# Setting up Java deps
third_party/java_deps/set_up_java_deps.sh

# Building linux-arm64-ota-requestor-nodeps-ipv6only
bash -c '
PKG_CONFIG_PATH="SYSROOT_AARCH64/lib/aarch64-linux-gnu/pkgconfig" \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,8 @@ cd "{root}"
# Generating linux-x64-all-clusters-coverage
gn gen --check --fail-on-unused-args --export-compile-commands --root={root}/examples/all-clusters-app/linux --args=use_coverage=true {out}/linux-x64-all-clusters-coverage

# Setting up Java deps
third_party/java_deps/set_up_java_deps.sh

# Building linux-x64-all-clusters-coverage
ninja -C {out}/linux-x64-all-clusters-coverage
7 changes: 7 additions & 0 deletions src/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import("//build_overrides/build.gni")
import("//build_overrides/chip.gni")

import("${build_root}/config/compiler/compiler.gni")
import("${chip_root}/build/chip/java/config.gni")
import("${chip_root}/build/chip/tests.gni")
import("${chip_root}/src/ble/ble.gni")
import("${chip_root}/src/lwip/lwip.gni")
Expand Down Expand Up @@ -147,4 +148,10 @@ if (chip_build_tests) {
"${chip_root}/src/crypto/tests",
]
}

if (matter_enable_java_compilation) {
group("java_controller_tests") {
deps = [ "${chip_root}/src/controller/java:unit_tests" ]
}
}
}
6 changes: 3 additions & 3 deletions src/controller/data_model/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ chip_data_model("data_model") {
allow_circular_includes_from = [ "${chip_root}/src/controller" ]
}

if (current_os == "android" || build_java_matter_controller) {
if (current_os == "android" || matter_enable_java_compilation) {
config("java-build-config") {
if (build_java_matter_controller) {
if (matter_enable_java_compilation) {
include_dirs = java_matter_controller_dependent_paths
}
}
Expand Down Expand Up @@ -324,7 +324,7 @@ if (current_os == "android" || build_java_matter_controller) {
"${chip_root}/src/platform",
]

if (build_java_matter_controller) {
if (matter_enable_java_compilation) {
if (current_os == "mac") {
deps += [ "${chip_root}/src/platform/Darwin" ]
} else {
Expand Down
27 changes: 18 additions & 9 deletions src/controller/java/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import("${chip_root}/build/chip/java/config.gni")
import("${chip_root}/build/chip/java/rules.gni")
import("${chip_root}/build/chip/tests.gni")

if (!build_java_matter_controller) {
if (!matter_enable_java_compilation) {
import("${build_root}/config/android_abi.gni")
}

Expand Down Expand Up @@ -76,7 +76,7 @@ shared_library("jni") {
"${chip_root}/src/platform",
]

if (build_java_matter_controller) {
if (matter_enable_java_compilation) {
defines = [ "JAVA_MATTER_CONTROLLER_TEST" ]

sources += [
Expand Down Expand Up @@ -123,7 +123,7 @@ if (chip_link_tests) {
"${chip_root}/src/messaging/tests:helpers",
]

if (build_java_matter_controller) {
if (matter_enable_java_compilation) {
defines = [ "JAVA_MATTER_CONTROLLER_TEST" ]
include_dirs = java_matter_controller_dependent_paths
if (current_os == "mac") {
Expand Down Expand Up @@ -240,7 +240,7 @@ kotlin_library("json_to_tlv_to_json_test") {

shared_library("jni_for_onboarding_payload") {
output_name = "libOnboardingPayload"
if (build_java_matter_controller) {
if (matter_enable_java_compilation) {
include_dirs = java_matter_controller_dependent_paths
output_dir = "${root_out_dir}/lib/jni"
} else {
Expand All @@ -260,7 +260,7 @@ kotlin_library("onboarding_payload") {

data_deps = [ ":jni_for_onboarding_payload" ]

if (!build_java_matter_controller) {
if (!matter_enable_java_compilation) {
data_deps += [ "${chip_root}/build/chip/java:shared_cpplib" ]
}

Expand All @@ -272,6 +272,15 @@ kotlin_library("onboarding_payload") {
]
}

group("unit_tests") {
deps = [
":json_to_tlv_to_json_test",
":tlv_read_write_test",
":tlv_reader_test",
":tlv_writer_test",
]
}

android_library("java") {
output_name = "CHIPController.jar"

Expand Down Expand Up @@ -337,7 +346,7 @@ android_library("java") {
"zap-generated/chip/devicecontroller/ClusterInfoMapping.java",
]

if (build_java_matter_controller) {
if (matter_enable_java_compilation) {
deps += [
"${chip_root}/third_party/java_deps:json",
"${chip_root}/third_party/java_deps/stub_src",
Expand Down Expand Up @@ -372,7 +381,7 @@ if (chip_link_tests) {
"src/chip/devicecontroller/GetConnectedDeviceCallbackForTestJni.java",
]

if (build_java_matter_controller) {
if (matter_enable_java_compilation) {
deps += [
"${chip_root}/third_party/java_deps:json",
"${chip_root}/third_party/java_deps/stub_src",
Expand Down Expand Up @@ -407,7 +416,7 @@ if (chip_link_tests) {
sources =
[ "tests/chip/devicecontroller/GetConnectedDeviceCallbackJniTest.java" ]

if (build_java_matter_controller) {
if (matter_enable_java_compilation) {
deps += [
"${chip_root}/third_party/java_deps:json",
"${chip_root}/third_party/java_deps/stub_src",
Expand All @@ -425,7 +434,7 @@ if (chip_link_tests) {
}
}

if (!build_java_matter_controller) {
if (!matter_enable_java_compilation) {
java_prebuilt("android") {
jar_path = "${android_sdk_root}/platforms/android-26/android.jar"
}
Expand Down
4 changes: 2 additions & 2 deletions src/lib/support/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ static_library("support") {
"verhoeff/Verhoeff36.cpp",
]

if (current_os == "android" || build_java_matter_controller) {
if (build_java_matter_controller) {
if (current_os == "android" || matter_enable_java_compilation) {
if (matter_enable_java_compilation) {
include_dirs = java_matter_controller_dependent_paths
}

Expand Down
8 changes: 4 additions & 4 deletions src/messaging/tests/java/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import("//build_overrides/chip.gni")
import("${chip_root}/build/chip/java/config.gni")
import("${chip_root}/build/chip/java/rules.gni")

if (!build_java_matter_controller) {
if (!matter_enable_java_compilation) {
import("${build_root}/config/android_abi.gni")
}

Expand All @@ -29,7 +29,7 @@ shared_library("jni") {

public_configs = [ "${chip_root}/src:includes" ]

if (build_java_matter_controller) {
if (matter_enable_java_compilation) {
defines = [ "JAVA_MATTER_CONTROLLER_TEST" ]
include_dirs = java_matter_controller_dependent_paths

Expand All @@ -56,7 +56,7 @@ android_library("java") {

sources = [ "src/chip/testing/MessagingContext.java" ]

if (build_java_matter_controller) {
if (matter_enable_java_compilation) {
deps += [
"${chip_root}/third_party/java_deps:json",
"${chip_root}/third_party/java_deps/stub_src",
Expand All @@ -73,7 +73,7 @@ android_library("java") {
# ..../platforms/android-26/android.jar to access BLE items)
}

if (!build_java_matter_controller) {
if (!matter_enable_java_compilation) {
java_prebuilt("android") {
jar_path = "${android_sdk_root}/platforms/android-26/android.jar"
}
Expand Down
6 changes: 3 additions & 3 deletions src/setup_payload/java/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ import("//build_overrides/chip.gni")
import("${chip_root}/build/chip/java/config.gni")
import("${chip_root}/build/chip/java/rules.gni")

if (!build_java_matter_controller) {
if (!matter_enable_java_compilation) {
import("${build_root}/config/android_abi.gni")
}

shared_library("jni") {
output_name = "libSetupPayloadParser"
if (build_java_matter_controller) {
if (matter_enable_java_compilation) {
include_dirs = java_matter_controller_dependent_paths
output_dir = "${root_out_dir}/lib/jni"
} else {
Expand All @@ -43,7 +43,7 @@ android_library("java") {

data_deps = [ ":jni" ]

if (!build_java_matter_controller) {
if (!matter_enable_java_compilation) {
data_deps += [ "${chip_root}/build/chip/java:shared_cpplib" ]
}

Expand Down
29 changes: 17 additions & 12 deletions third_party/java_deps/set_up_java_deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,27 @@ set -e

mkdir -p third_party/java_deps/artifacts

function download_maven_jar() {
_MAVEN_PATH=$1
_JAR_NAME=$2
function download_jar() {
_HOST=$1
_MAVEN_PATH=$2
_JAR_NAME=$3

if [ ! -f "third_party/java_deps/artifacts/$_JAR_NAME" ]; then
curl --fail --location --silent --show-error \
"https://repo1.maven.org/maven2/$_MAVEN_PATH/$_JAR_NAME" \
"https://$_HOST/maven2/$_MAVEN_PATH/$_JAR_NAME" \
-o "third_party/java_deps/artifacts/$_JAR_NAME"
fi
}

download_maven_jar "com/google/code/findbugs/jsr305/3.0.2" "jsr305-3.0.2.jar"
download_maven_jar "org/json/json/20220924" "json-20220924.jar"
download_maven_jar "org/jetbrains/kotlin/kotlin-stdlib/1.8.10" "kotlin-stdlib-1.8.10.jar"
download_maven_jar "org/jetbrains/kotlin/kotlin-test/1.8.10" "kotlin-test-1.8.10.jar"
download_maven_jar "com/google/protobuf/protobuf-java/3.22.0" "protobuf-java-3.22.0.jar"
download_maven_jar "com/google/truth/truth/1.1.3" "truth-1.1.3.jar"
download_maven_jar "junit/junit/4.13.2" "junit-4.13.2.jar"
download_maven_jar "com/google/code/gson/gson/2.9.1" "gson-2.9.1.jar"
download_jar "repo1.maven.org" "com/google/code/findbugs/jsr305/3.0.2" "jsr305-3.0.2.jar"
download_jar "repo1.maven.org" "com/google/code/gson/gson/2.9.1" "gson-2.9.1.jar"
download_jar "repo1.maven.org" "com/google/protobuf/protobuf-java/3.22.0" "protobuf-java-3.22.0.jar"
download_jar "repo1.maven.org" "com/google/truth/truth/1.1.3" "truth-1.1.3.jar"
download_jar "repo1.maven.org" "junit/junit/4.13.2" "junit-4.13.2.jar"
download_jar "repo1.maven.org" "org/jetbrains/kotlin/kotlin-stdlib/1.8.10" "kotlin-stdlib-1.8.10.jar"
download_jar "repo1.maven.org" "org/jetbrains/kotlin/kotlin-test/1.8.10" "kotlin-test-1.8.10.jar"
download_jar "repo1.maven.org" "org/json/json/20220924" "json-20220924.jar"

# Unit test requirements
download_jar "repo1.maven.org" "org/hamcrest/hamcrest-all/1.3" "hamcrest-all-1.3.jar"
download_jar "dist.wso2.org" "com/google/common/google-collect/1.0-rc1/" "google-collect-1.0-rc1.jar"