diff options
Diffstat (limited to 'test/674-hiddenapi')
| -rw-r--r-- | test/674-hiddenapi/build.py (renamed from test/674-hiddenapi/build) | 27 | ||||
| -rw-r--r-- | test/674-hiddenapi/check | 30 | ||||
| -rw-r--r-- | test/674-hiddenapi/hiddenapi.cc | 14 | ||||
| -rw-r--r--[-rwxr-xr-x] | test/674-hiddenapi/run.py (renamed from test/674-hiddenapi/run) | 17 |
4 files changed, 28 insertions, 60 deletions
diff --git a/test/674-hiddenapi/build b/test/674-hiddenapi/build.py index 330a6def29..c3ebb50de5 100644 --- a/test/674-hiddenapi/build +++ b/test/674-hiddenapi/build.py @@ -1,6 +1,5 @@ -#!/bin/bash # -# Copyright 2018 The Android Open Source Project +# Copyright (C) 2022 The Android Open Source Project # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -14,7 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -set -e +import os # Build the jars twice. First with applying hiddenapi, creating a boot jar, then # a second time without to create a normal jar. We need to do this because we @@ -23,16 +22,18 @@ set -e # hidden API access flags in dex files. DexFileVerifier is not invoked on boot # class path dex files, so the boot jar loads fine in the latter case. -export USE_HIDDENAPI=true -./default-build "$@" -# Move the jar file into the resource folder to be bundled with the test. -mkdir res -mv ${TEST_NAME}.jar res/boot.jar +def build(ctx): + if ctx.jvm: + return # The test does not build on JVM + ctx.default_build(use_hiddenapi=True) -# Clear all intermediate files otherwise default-build would either skip -# compilation or fail rebuilding. -rm -rf classes* + # Move the jar file into the resource folder to be bundled with the test. + os.mkdir(ctx.test_dir / "res") + os.rename(ctx.test_dir / "674-hiddenapi.jar", ctx.test_dir / "res/boot.jar") -export USE_HIDDENAPI=false -./default-build "$@" + # Clear all intermediate files otherwise default-build would either skip + # compilation or fail rebuilding. + ctx.bash("rm -rf classes*") + + ctx.default_build(use_hiddenapi=False) diff --git a/test/674-hiddenapi/check b/test/674-hiddenapi/check deleted file mode 100644 index c8afc229c2..0000000000 --- a/test/674-hiddenapi/check +++ /dev/null @@ -1,30 +0,0 @@ -#!/bin/bash -# -# Copyright (C) 2018 The Android Open Source Project -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Inputs: -# $1: Test's expected standard output -# $2: Test's actual standard output -# $3: Test's expected standard error -# $4: Test's actual standard error - -# Remove pid and date from the log messages. -grep -v JNI_OnLoad "$2" \ - | grep -v JNI_OnUnload \ - > "$2.tmp" -grep -vE '^dalvikvm(32|64) E [^]]+]' "$4" \ - > "$4.tmp" - -./default-check "$1" "$2.tmp" "$3" "$4.tmp" diff --git a/test/674-hiddenapi/hiddenapi.cc b/test/674-hiddenapi/hiddenapi.cc index ebe9d10c47..f1b0c18c27 100644 --- a/test/674-hiddenapi/hiddenapi.cc +++ b/test/674-hiddenapi/hiddenapi.cc @@ -15,13 +15,10 @@ */ #include "base/sdk_version.h" -#include "class_linker.h" #include "dex/art_dex_file_loader.h" #include "hidden_api.h" #include "jni.h" #include "runtime.h" -#include "scoped_thread_state_change-inl.h" -#include "thread.h" #include "ti-agent/scoped_utf_chars.h" namespace art { @@ -62,12 +59,10 @@ extern "C" JNIEXPORT jint JNICALL Java_Main_appendToBootClassLoader( const jint int_index = static_cast<jint>(index); opened_dex_files.push_back(std::vector<std::unique_ptr<const DexFile>>()); - ArtDexFileLoader dex_loader; + DexFileLoader dex_loader(path); std::string error_msg; - if (!dex_loader.Open(path, - path, - /* verify */ false, + if (!dex_loader.Open(/* verify */ false, /* verify_checksum */ true, &error_msg, &opened_dex_files[index])) { @@ -77,10 +72,7 @@ extern "C" JNIEXPORT jint JNICALL Java_Main_appendToBootClassLoader( Java_Main_setDexDomain(env, klass, int_index, is_core_platform); - ScopedObjectAccess soa(Thread::Current()); - for (std::unique_ptr<const DexFile>& dex_file : opened_dex_files[index]) { - Runtime::Current()->GetClassLinker()->AppendToBootClassPath(Thread::Current(), dex_file.get()); - } + Runtime::Current()->AppendToBootClassPath(path, path, opened_dex_files[index]); return int_index; } diff --git a/test/674-hiddenapi/run b/test/674-hiddenapi/run.py index 0ab4763884..1e364faf15 100755..100644 --- a/test/674-hiddenapi/run +++ b/test/674-hiddenapi/run.py @@ -14,9 +14,14 @@ # See the License for the specific language governing permissions and # limitations under the License. -# Make verification soft fail so that we can re-verify boot classpath -# methods at runtime. -# -# N.B. Compilation of secondary dexes can prevent hidden API checks, e.g. if -# a blocklisted field get is inlined. -exec ${RUN} $@ --verify-soft-fail --no-secondary-compilation + +def run(ctx, args): + # Make verification soft fail so that we can re-verify boot classpath + # methods at runtime. + # + # N.B. Compilation of secondary dexes can prevent hidden API checks, e.g. if + # a blocklisted field get is inlined. + ctx.default_run(args, verify_soft_fail=True, secondary_compilation=False) + + ctx.run(fr"sed -i -E '/(JNI_OnLoad|JNI_OnUnload)/d' '{args.stdout_file}'") + ctx.run(fr"sed -i -E '/^dalvikvm(32|64) E [^]]+]/d' '{args.stderr_file}'") |