Merge "Remove global skip for redefine-stress"
diff --git a/profman/profile_assistant_test.cc b/profman/profile_assistant_test.cc
index 188d0b0..1dd1a4a 100644
--- a/profman/profile_assistant_test.cc
+++ b/profman/profile_assistant_test.cc
@@ -75,31 +75,34 @@
const ScratchFile& profile,
ProfileCompilationInfo* info,
uint16_t start_method_index = 0,
- bool reverse_dex_write_order = false) {
+ bool reverse_dex_write_order = false,
+ uint32_t number_of_methods1 = kMaxMethodIds,
+ uint32_t number_of_methods2 = kMaxMethodIds) {
for (uint16_t i = start_method_index; i < start_method_index + number_of_methods; i++) {
// reverse_dex_write_order controls the order in which the dex files will be added to
// the profile and thus written to disk.
ProfileCompilationInfo::OfflineProfileMethodInfo pmi =
GetOfflineProfileMethodInfo(dex_location1, dex_location_checksum1,
- dex_location2, dex_location_checksum2);
+ dex_location2, dex_location_checksum2,
+ number_of_methods1, number_of_methods2);
Hotness::Flag flags = Hotness::kFlagPostStartup;
if (reverse_dex_write_order) {
ASSERT_TRUE(info->AddMethod(
- dex_location2, dex_location_checksum2, i, kMaxMethodIds, pmi, flags));
+ dex_location2, dex_location_checksum2, i, number_of_methods2, pmi, flags));
ASSERT_TRUE(info->AddMethod(
- dex_location1, dex_location_checksum1, i, kMaxMethodIds, pmi, flags));
+ dex_location1, dex_location_checksum1, i, number_of_methods1, pmi, flags));
} else {
ASSERT_TRUE(info->AddMethod(
- dex_location1, dex_location_checksum1, i, kMaxMethodIds, pmi, flags));
+ dex_location1, dex_location_checksum1, i, number_of_methods1, pmi, flags));
ASSERT_TRUE(info->AddMethod(
- dex_location2, dex_location_checksum2, i, kMaxMethodIds, pmi, flags));
+ dex_location2, dex_location_checksum2, i, number_of_methods2, pmi, flags));
}
}
for (uint16_t i = 0; i < number_of_classes; i++) {
ASSERT_TRUE(info->AddClassIndex(dex_location1,
dex_location_checksum1,
dex::TypeIndex(i),
- kMaxMethodIds));
+ number_of_methods1));
}
ASSERT_TRUE(info->Save(GetFd(profile)));
@@ -143,11 +146,12 @@
ProfileCompilationInfo::OfflineProfileMethodInfo GetOfflineProfileMethodInfo(
const std::string& dex_location1, uint32_t dex_checksum1,
- const std::string& dex_location2, uint32_t dex_checksum2) {
+ const std::string& dex_location2, uint32_t dex_checksum2,
+ uint32_t number_of_methods1 = kMaxMethodIds, uint32_t number_of_methods2 = kMaxMethodIds) {
ProfileCompilationInfo::InlineCacheMap* ic_map = CreateInlineCacheMap();
ProfileCompilationInfo::OfflineProfileMethodInfo pmi(ic_map);
- pmi.dex_references.emplace_back(dex_location1, dex_checksum1, kMaxMethodIds);
- pmi.dex_references.emplace_back(dex_location2, dex_checksum2, kMaxMethodIds);
+ pmi.dex_references.emplace_back(dex_location1, dex_checksum1, number_of_methods1);
+ pmi.dex_references.emplace_back(dex_location2, dex_checksum2, number_of_methods2);
// Monomorphic
for (uint16_t dex_pc = 0; dex_pc < 11; dex_pc++) {
@@ -1242,4 +1246,61 @@
ASSERT_TRUE(expected.Equals(result));
}
+TEST_F(ProfileAssistantTest, CopyAndUpdateProfileKey) {
+ ScratchFile profile1;
+ ScratchFile reference_profile;
+
+ // Use a real dex file to generate profile test data. During the copy-and-update the
+ // matching is done based on checksum so we have to match with the real thing.
+ std::vector<std::unique_ptr<const DexFile>> dex_files = OpenTestDexFiles("ProfileTestMultiDex");
+ const DexFile& d1 = *dex_files[0];
+ const DexFile& d2 = *dex_files[1];
+
+ ProfileCompilationInfo info1;
+ uint16_t num_methods_to_add = std::min(d1.NumMethodIds(), d2.NumMethodIds());
+ SetupProfile("fake-location1",
+ d1.GetLocationChecksum(),
+ "fake-location2",
+ d2.GetLocationChecksum(),
+ num_methods_to_add,
+ /*num_classes*/ 0,
+ profile1,
+ &info1,
+ /*start_method_index*/ 0,
+ /*reverse_dex_write_order*/ false,
+ /*number_of_methods1*/ d1.NumMethodIds(),
+ /*number_of_methods2*/ d2.NumMethodIds());
+
+ // Run profman and pass the dex file with --apk-fd.
+ android::base::unique_fd apk_fd(
+ open(GetTestDexFileName("ProfileTestMultiDex").c_str(), O_RDONLY));
+ ASSERT_GE(apk_fd.get(), 0);
+
+ std::string profman_cmd = GetProfmanCmd();
+ std::vector<std::string> argv_str;
+ argv_str.push_back(profman_cmd);
+ argv_str.push_back("--profile-file-fd=" + std::to_string(profile1.GetFd()));
+ argv_str.push_back("--reference-profile-file-fd=" + std::to_string(reference_profile.GetFd()));
+ argv_str.push_back("--apk-fd=" + std::to_string(apk_fd.get()));
+ argv_str.push_back("--copy-and-update-profile-key");
+ std::string error;
+
+ ASSERT_EQ(ExecAndReturnCode(argv_str, &error), 0) << error;
+
+ // Verify that we can load the result.
+ ProfileCompilationInfo result;
+ ASSERT_TRUE(reference_profile.GetFile()->ResetOffset());
+ ASSERT_TRUE(result.Load(reference_profile.GetFd()));
+
+ // Verify that the renaming was done.
+ for (uint16_t i = 0; i < num_methods_to_add; i ++) {
+ std::unique_ptr<ProfileCompilationInfo::OfflineProfileMethodInfo> pmi;
+ ASSERT_TRUE(result.GetMethod(d1.GetLocation(), d1.GetLocationChecksum(), i) != nullptr) << i;
+ ASSERT_TRUE(result.GetMethod(d2.GetLocation(), d2.GetLocationChecksum(), i) != nullptr) << i;
+
+ ASSERT_TRUE(result.GetMethod("fake-location1", d1.GetLocationChecksum(), i) == nullptr);
+ ASSERT_TRUE(result.GetMethod("fake-location2", d2.GetLocationChecksum(), i) == nullptr);
+ }
+}
+
} // namespace art
diff --git a/profman/profman.cc b/profman/profman.cc
index efb7fcf..5551c34 100644
--- a/profman/profman.cc
+++ b/profman/profman.cc
@@ -280,6 +280,8 @@
Usage);
} else if (option.starts_with("--generate-test-profile-seed=")) {
ParseUintOption(option, "--generate-test-profile-seed", &test_profile_seed_, Usage);
+ } else if (option.starts_with("--copy-and-update-profile-key")) {
+ copy_and_update_profile_key_ = true;
} else {
Usage("Unknown argument '%s'", option.data());
}
@@ -405,9 +407,12 @@
}
}
} else if (!apk_files_.empty()) {
- if (dex_locations_.size() != apk_files_.size()) {
- Usage("The number of apk-fds must match the number of dex-locations.");
- }
+ if (dex_locations_.empty()) {
+ // If no dex locations are specified use the apk names as locations.
+ dex_locations_ = apk_files_;
+ } else if (dex_locations_.size() != apk_files_.size()) {
+ Usage("The number of apk-fds must match the number of dex-locations.");
+ }
} else {
// No APKs were specified.
CHECK(dex_locations_.empty());
@@ -1178,7 +1183,7 @@
return copy_and_update_profile_key_;
}
- bool CopyAndUpdateProfileKey() {
+ int32_t CopyAndUpdateProfileKey() {
// Validate that at least one profile file was passed, as well as a reference profile.
if (!(profile_files_.size() == 1 ^ profile_files_fd_.size() == 1)) {
Usage("Only one profile file should be specified.");
@@ -1191,22 +1196,30 @@
Usage("No apk files specified");
}
+ static constexpr int32_t kErrorFailedToUpdateProfile = -1;
+ static constexpr int32_t kErrorFailedToSaveProfile = -2;
+ static constexpr int32_t kErrorFailedToLoadProfile = -3;
+
bool use_fds = profile_files_fd_.size() == 1;
ProfileCompilationInfo profile;
// Do not clear if invalid. The input might be an archive.
- if (profile.Load(profile_files_[0], /*clear_if_invalid*/ false)) {
+ bool load_ok = use_fds
+ ? profile.Load(profile_files_fd_[0])
+ : profile.Load(profile_files_[0], /*clear_if_invalid*/ false);
+ if (load_ok) {
// Open the dex files to look up classes and methods.
std::vector<std::unique_ptr<const DexFile>> dex_files;
OpenApkFilesFromLocations(&dex_files);
if (!profile.UpdateProfileKeys(dex_files)) {
- return false;
+ return kErrorFailedToUpdateProfile;
}
- return use_fds
- ? profile.Save(reference_profile_file_fd_)
- : profile.Save(reference_profile_file_, /*bytes_written*/ nullptr);
+ bool result = use_fds
+ ? profile.Save(reference_profile_file_fd_)
+ : profile.Save(reference_profile_file_, /*bytes_written*/ nullptr);
+ return result ? 0 : kErrorFailedToSaveProfile;
} else {
- return false;
+ return kErrorFailedToLoadProfile;
}
}
@@ -1285,6 +1298,11 @@
if (profman.ShouldCreateBootProfile()) {
return profman.CreateBootProfile();
}
+
+ if (profman.ShouldCopyAndUpdateProfileKey()) {
+ return profman.CopyAndUpdateProfileKey();
+ }
+
// Process profile information and assess if we need to do a profile guided compilation.
// This operation involves I/O.
return profman.ProcessProfiles();
diff --git a/test/912-classes/src-art/art/Test912.java b/test/912-classes/src-art/art/Test912.java
index ddfadf3..1a60185 100644
--- a/test/912-classes/src-art/art/Test912.java
+++ b/test/912-classes/src-art/art/Test912.java
@@ -398,6 +398,7 @@
public static double dummy = Math.random(); // So it can't be compile-time initialized.
}
+ @SuppressWarnings("RandomCast")
private static class TestForInitFail {
public static int dummy = ((int)Math.random())/0; // So it throws when initializing.
}
diff --git a/test/983-source-transform-verify/source_transform.cc b/test/983-source-transform-verify/source_transform.cc
index 26c5668..9e65a99 100644
--- a/test/983-source-transform-verify/source_transform.cc
+++ b/test/983-source-transform-verify/source_transform.cc
@@ -14,25 +14,14 @@
* limitations under the License.
*/
-#include <inttypes.h>
+#include "source_transform.h"
-#include <cstdio>
-#include <cstring>
-#include <iostream>
-#include <sstream>
-#include <vector>
+#include "jni.h"
#include "android-base/stringprintf.h"
-#include "jni.h"
#include "jvmti.h"
#include "scoped_local_ref.h"
-#include "dex/code_item_accessors-inl.h"
-#include "dex/dex_file_loader.h"
-#include "dex/dex_file.h"
-#include "dex/dex_file_loader.h"
-#include "dex/dex_instruction.h"
-
// Test infrastructure
#include "jvmti_helper.h"
#include "test_env.h"
@@ -42,13 +31,12 @@
constexpr bool kSkipInitialLoad = true;
-static void Println(JNIEnv* env, std::ostringstream msg_stream) {
- std::string msg = msg_stream.str();
+static void Println(JNIEnv* env, const char* msg) {
ScopedLocalRef<jclass> test_klass(env, env->FindClass("art/Test983"));
jmethodID println_method = env->GetStaticMethodID(test_klass.get(),
"doPrintln",
"(Ljava/lang/String;)V");
- ScopedLocalRef<jstring> data(env, env->NewStringUTF(msg.c_str()));
+ ScopedLocalRef<jstring> data(env, env->NewStringUTF(msg));
env->CallStaticVoidMethod(test_klass.get(), println_method, data.get());
}
@@ -68,58 +56,12 @@
// repeatable we only care about things that come from RetransformClasses.
return;
}
- Println(env, std::ostringstream() << "Dex file hook for " << name);
+ Println(env, android::base::StringPrintf("Dex file hook for %s", name).c_str());
if (IsJVM()) {
return;
}
- // Due to b/72402467 the class_data_len might just be an estimate.
- CHECK_GE(static_cast<size_t>(class_data_len), sizeof(DexFile::Header));
- const DexFile::Header* header = reinterpret_cast<const DexFile::Header*>(class_data);
- uint32_t header_file_size = header->file_size_;
- CHECK_LE(static_cast<jint>(header_file_size), class_data_len);
- class_data_len = static_cast<jint>(header_file_size);
-
- const DexFileLoader dex_file_loader;
- std::string error;
- std::unique_ptr<const DexFile> dex(dex_file_loader.Open(class_data,
- class_data_len,
- "fake_location.dex",
- /*location_checksum*/ 0,
- /*oat_dex_file*/ nullptr,
- /*verify*/ true,
- /*verify_checksum*/ true,
- &error));
- if (dex.get() == nullptr) {
- Println(env, std::ostringstream() << "Failed to verify dex file for "
- << name << " because " << error);
- return;
- }
- for (uint32_t i = 0; i < dex->NumClassDefs(); i++) {
- const DexFile::ClassDef& def = dex->GetClassDef(i);
- const uint8_t* data_item = dex->GetClassData(def);
- if (data_item == nullptr) {
- continue;
- }
- for (ClassDataItemIterator it(*dex, data_item); it.HasNext(); it.Next()) {
- if (!it.IsAtMethod() || it.GetMethodCodeItem() == nullptr) {
- continue;
- }
- for (const DexInstructionPcPair& pair :
- art::CodeItemInstructionAccessor(*dex, it.GetMethodCodeItem())) {
- const Instruction& inst = pair.Inst();
- int forbiden_flags = (Instruction::kVerifyError | Instruction::kVerifyRuntimeOnly);
- if (inst.Opcode() == Instruction::RETURN_VOID_NO_BARRIER ||
- (inst.GetVerifyExtraFlags() & forbiden_flags) != 0) {
- Println(env, std::ostringstream() << "Unexpected instruction found in "
- << dex->PrettyMethod(it.GetMemberIndex())
- << " [Dex PC: 0x" << std::hex << pair.DexPc()
- << std::dec << "] : " << inst.DumpString(dex.get()));
- continue;
- }
- }
- }
- }
+ VerifyClassData(class_data_len, class_data);
}
// Get all capabilities except those related to retransformation.
diff --git a/test/983-source-transform-verify/source_transform.h b/test/983-source-transform-verify/source_transform.h
new file mode 100644
index 0000000..2206498
--- /dev/null
+++ b/test/983-source-transform-verify/source_transform.h
@@ -0,0 +1,30 @@
+/*
+ * Copyright (C) 2016 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.
+ */
+
+#ifndef ART_TEST_983_SOURCE_TRANSFORM_VERIFY_SOURCE_TRANSFORM_H_
+#define ART_TEST_983_SOURCE_TRANSFORM_VERIFY_SOURCE_TRANSFORM_H_
+
+#include <jni.h>
+
+namespace art {
+namespace Test983SourceTransformVerify {
+
+void VerifyClassData(jint class_data_len, const unsigned char* class_data);
+
+} // namespace Test983SourceTransformVerify
+} // namespace art
+
+#endif // ART_TEST_983_SOURCE_TRANSFORM_VERIFY_SOURCE_TRANSFORM_H_
diff --git a/test/983-source-transform-verify/source_transform_art.cc b/test/983-source-transform-verify/source_transform_art.cc
new file mode 100644
index 0000000..5353370
--- /dev/null
+++ b/test/983-source-transform-verify/source_transform_art.cc
@@ -0,0 +1,80 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+
+#include "source_transform.h"
+
+#include <inttypes.h>
+
+#include <memory>
+
+#include <android-base/logging.h>
+
+#include "dex/code_item_accessors-inl.h"
+#include "dex/art_dex_file_loader.h"
+#include "dex/dex_file.h"
+#include "dex/dex_file_loader.h"
+#include "dex/dex_instruction.h"
+
+namespace art {
+namespace Test983SourceTransformVerify {
+
+// The hook we are using.
+void VerifyClassData(jint class_data_len, const unsigned char* class_data) {
+ // Due to b/72402467 the class_data_len might just be an estimate.
+ CHECK_GE(static_cast<size_t>(class_data_len), sizeof(DexFile::Header));
+ const DexFile::Header* header = reinterpret_cast<const DexFile::Header*>(class_data);
+ uint32_t header_file_size = header->file_size_;
+ CHECK_LE(static_cast<jint>(header_file_size), class_data_len);
+ class_data_len = static_cast<jint>(header_file_size);
+
+ const ArtDexFileLoader dex_file_loader;
+ std::string error;
+ std::unique_ptr<const DexFile> dex(dex_file_loader.Open(class_data,
+ class_data_len,
+ "fake_location.dex",
+ /*location_checksum*/ 0,
+ /*oat_dex_file*/ nullptr,
+ /*verify*/ true,
+ /*verify_checksum*/ true,
+ &error));
+ CHECK(dex.get() != nullptr) << "Failed to verify dex: " << error;
+ for (uint32_t i = 0; i < dex->NumClassDefs(); i++) {
+ const DexFile::ClassDef& def = dex->GetClassDef(i);
+ const uint8_t* data_item = dex->GetClassData(def);
+ if (data_item == nullptr) {
+ continue;
+ }
+ for (ClassDataItemIterator it(*dex, data_item); it.HasNext(); it.Next()) {
+ if (!it.IsAtMethod() || it.GetMethodCodeItem() == nullptr) {
+ continue;
+ }
+ for (const DexInstructionPcPair& pair :
+ art::CodeItemInstructionAccessor(*dex, it.GetMethodCodeItem())) {
+ const Instruction& inst = pair.Inst();
+ int forbidden_flags = (Instruction::kVerifyError | Instruction::kVerifyRuntimeOnly);
+ if (inst.Opcode() == Instruction::RETURN_VOID_NO_BARRIER ||
+ (inst.GetVerifyExtraFlags() & forbidden_flags) != 0) {
+ LOG(FATAL) << "Unexpected instruction found in " << dex->PrettyMethod(it.GetMemberIndex())
+ << " [Dex PC: 0x" << std::hex << pair.DexPc() << std::dec << "] : "
+ << inst.DumpString(dex.get()) << std::endl;
+ }
+ }
+ }
+ }
+}
+
+} // namespace Test983SourceTransformVerify
+} // namespace art
diff --git a/test/983-source-transform-verify/source_transform_slicer.cc b/test/983-source-transform-verify/source_transform_slicer.cc
new file mode 100644
index 0000000..abf32e7
--- /dev/null
+++ b/test/983-source-transform-verify/source_transform_slicer.cc
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+
+#include "source_transform.h"
+
+#pragma clang diagnostic push
+// slicer defines its own CHECK. b/65422458
+#pragma push_macro("CHECK")
+#undef CHECK
+
+// Slicer's headers have code that triggers these warnings. b/65298177
+#pragma clang diagnostic ignored "-Wsign-compare"
+#include "reader.h"
+
+#pragma pop_macro("CHECK")
+#pragma clang diagnostic pop
+
+namespace art {
+namespace Test983SourceTransformVerify {
+
+// The hook we are using.
+void VerifyClassData(jint class_data_len, const unsigned char* class_data) {
+ dex::Reader reader(class_data, class_data_len);
+ reader.CreateFullIr(); // This will verify all bytecode.
+}
+
+} // namespace Test983SourceTransformVerify
+} // namespace art
diff --git a/test/Android.bp b/test/Android.bp
index 25556ad..9d44e09 100644
--- a/test/Android.bp
+++ b/test/Android.bp
@@ -289,6 +289,7 @@
"909-attach-agent/attach.cc",
"912-classes/classes_art.cc",
"936-search-onload/search_onload.cc",
+ "983-source-transform-verify/source_transform_art.cc",
"1940-ddms-ext/ddm_ext.cc",
"1944-sudden-exit/sudden_exit.cc",
],
@@ -318,21 +319,19 @@
],
}
-art_cc_test_library {
+cc_library_static {
name: "libctstiagent",
defaults: ["libtiagent-base-defaults"],
+ host_supported: false,
+ srcs: [
+ "983-source-transform-verify/source_transform_slicer.cc",
+ ],
whole_static_libs: [
- "libdexfile",
- "libz",
- "libziparchive",
+ "slicer",
+ "libz", // for slicer (using adler32).
],
static_libs: [
"libbase",
- "libcutils",
- "libutils",
- ],
- shared_libs: [
- "liblog",
],
header_libs: [
// This is needed to resolve the base/ header file in libdexfile. Unfortunately there are
diff --git a/test/testrunner/testrunner.py b/test/testrunner/testrunner.py
index 3d173f5..4329ad4 100755
--- a/test/testrunner/testrunner.py
+++ b/test/testrunner/testrunner.py
@@ -110,6 +110,7 @@
total_test_count = 0
verbose = False
dry_run = False
+ignore_skips = False
build = False
gdb = False
gdb_arg = ''
@@ -710,6 +711,8 @@
return True
if test in env.EXTRA_DISABLED_TESTS:
return True
+ if ignore_skips:
+ return False
variants_list = DISABLED_TEST_CONTAINER.get(test, {})
for variants in variants_list:
variants_present = True
@@ -878,6 +881,7 @@
def parse_option():
global verbose
global dry_run
+ global ignore_skips
global n_thread
global build
global gdb
@@ -897,6 +901,8 @@
parser.add_argument('--dry-run', action='store_true', dest='dry_run')
parser.add_argument("--skip", action="append", dest="skips", default=[],
help="Skip the given test in all circumstances.")
+ parser.add_argument("--no-skips", dest="ignore_skips", action="store_true", default=False,
+ help="Don't skip any run-test configurations listed in knownfailures.json.")
parser.add_argument('--no-build-dependencies',
action='store_false', dest='build',
help="Don't build dependencies under any circumstances. This is the " +
@@ -935,6 +941,7 @@
verbose = True
if options['n_thread']:
n_thread = max(1, options['n_thread'])
+ ignore_skips = options['ignore_skips']
if options['dry_run']:
dry_run = True
verbose = True