Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "instruction_set_features.h" |
| 18 | |
| 19 | #include <gtest/gtest.h> |
| 20 | |
Bilyan Borisov | bb661c0 | 2016-04-04 16:27:32 +0100 | [diff] [blame] | 21 | #ifdef ART_TARGET_ANDROID |
Dimitry Ivanov | 9642b1b | 2016-09-28 02:44:00 -0700 | [diff] [blame^] | 22 | #include "android-base/properties.h" |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 23 | #endif |
| 24 | |
Andreas Gampe | bda1d60 | 2016-08-29 17:43:45 -0700 | [diff] [blame] | 25 | #include "base/logging.h" |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 26 | #include "base/stringprintf.h" |
| 27 | |
| 28 | namespace art { |
| 29 | |
Bilyan Borisov | bb661c0 | 2016-04-04 16:27:32 +0100 | [diff] [blame] | 30 | #ifdef ART_TARGET_ANDROID |
Ian Rogers | d9df670 | 2014-11-17 16:43:15 -0800 | [diff] [blame] | 31 | #if defined(__aarch64__) |
| 32 | TEST(InstructionSetFeaturesTest, DISABLED_FeaturesFromSystemPropertyVariant) { |
| 33 | LOG(WARNING) << "Test disabled due to no CPP define for A53 erratum 835769"; |
| 34 | #else |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 35 | TEST(InstructionSetFeaturesTest, FeaturesFromSystemPropertyVariant) { |
Ian Rogers | d9df670 | 2014-11-17 16:43:15 -0800 | [diff] [blame] | 36 | #endif |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 37 | // Take the default set of instruction features from the build. |
| 38 | std::unique_ptr<const InstructionSetFeatures> instruction_set_features( |
| 39 | InstructionSetFeatures::FromCppDefines()); |
| 40 | |
Ian Rogers | d9df670 | 2014-11-17 16:43:15 -0800 | [diff] [blame] | 41 | // Read the variant property. |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 42 | std::string key = StringPrintf("dalvik.vm.isa.%s.variant", GetInstructionSetString(kRuntimeISA)); |
Dimitry Ivanov | 9642b1b | 2016-09-28 02:44:00 -0700 | [diff] [blame^] | 43 | std::string dex2oat_isa_variant = android::base::GetProperty(key, ""); |
| 44 | if (!dex2oat_isa_variant.empty()) { |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 45 | // Use features from property to build InstructionSetFeatures and check against build's |
| 46 | // features. |
| 47 | std::string error_msg; |
| 48 | std::unique_ptr<const InstructionSetFeatures> property_features( |
| 49 | InstructionSetFeatures::FromVariant(kRuntimeISA, dex2oat_isa_variant, &error_msg)); |
| 50 | ASSERT_TRUE(property_features.get() != nullptr) << error_msg; |
| 51 | |
| 52 | EXPECT_TRUE(property_features->Equals(instruction_set_features.get())) |
| 53 | << "System property features: " << *property_features.get() |
| 54 | << "\nFeatures from build: " << *instruction_set_features.get(); |
| 55 | } |
| 56 | } |
| 57 | |
Ian Rogers | d9df670 | 2014-11-17 16:43:15 -0800 | [diff] [blame] | 58 | #if defined(__aarch64__) |
| 59 | TEST(InstructionSetFeaturesTest, DISABLED_FeaturesFromSystemPropertyString) { |
| 60 | LOG(WARNING) << "Test disabled due to no CPP define for A53 erratum 835769"; |
| 61 | #else |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 62 | TEST(InstructionSetFeaturesTest, FeaturesFromSystemPropertyString) { |
Ian Rogers | d9df670 | 2014-11-17 16:43:15 -0800 | [diff] [blame] | 63 | #endif |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 64 | // Take the default set of instruction features from the build. |
| 65 | std::unique_ptr<const InstructionSetFeatures> instruction_set_features( |
| 66 | InstructionSetFeatures::FromCppDefines()); |
| 67 | |
Ian Rogers | d9df670 | 2014-11-17 16:43:15 -0800 | [diff] [blame] | 68 | // Read the variant property. |
| 69 | std::string variant_key = StringPrintf("dalvik.vm.isa.%s.variant", |
| 70 | GetInstructionSetString(kRuntimeISA)); |
Dimitry Ivanov | 9642b1b | 2016-09-28 02:44:00 -0700 | [diff] [blame^] | 71 | std::string dex2oat_isa_variant = android::base::GetProperty(variant_key, ""); |
| 72 | if (!dex2oat_isa_variant.empty()) { |
Ian Rogers | d9df670 | 2014-11-17 16:43:15 -0800 | [diff] [blame] | 73 | // Read the features property. |
| 74 | std::string features_key = StringPrintf("dalvik.vm.isa.%s.features", |
| 75 | GetInstructionSetString(kRuntimeISA)); |
Dimitry Ivanov | 9642b1b | 2016-09-28 02:44:00 -0700 | [diff] [blame^] | 76 | std::string dex2oat_isa_features = android::base::GetProperty(features_key, ""); |
| 77 | if (!dex2oat_isa_features.empty()) { |
Ian Rogers | d9df670 | 2014-11-17 16:43:15 -0800 | [diff] [blame] | 78 | // Use features from property to build InstructionSetFeatures and check against build's |
| 79 | // features. |
| 80 | std::string error_msg; |
| 81 | std::unique_ptr<const InstructionSetFeatures> base_features( |
| 82 | InstructionSetFeatures::FromVariant(kRuntimeISA, dex2oat_isa_variant, &error_msg)); |
| 83 | ASSERT_TRUE(base_features.get() != nullptr) << error_msg; |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 84 | |
Ian Rogers | d9df670 | 2014-11-17 16:43:15 -0800 | [diff] [blame] | 85 | std::unique_ptr<const InstructionSetFeatures> property_features( |
| 86 | base_features->AddFeaturesFromString(dex2oat_isa_features, &error_msg)); |
| 87 | ASSERT_TRUE(property_features.get() != nullptr) << error_msg; |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 88 | |
Ian Rogers | d9df670 | 2014-11-17 16:43:15 -0800 | [diff] [blame] | 89 | EXPECT_TRUE(property_features->Equals(instruction_set_features.get())) |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 90 | << "System property features: " << *property_features.get() |
| 91 | << "\nFeatures from build: " << *instruction_set_features.get(); |
Ian Rogers | d9df670 | 2014-11-17 16:43:15 -0800 | [diff] [blame] | 92 | } |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 93 | } |
| 94 | } |
| 95 | |
| 96 | #if defined(__arm__) |
| 97 | TEST(InstructionSetFeaturesTest, DISABLED_FeaturesFromCpuInfo) { |
| 98 | LOG(WARNING) << "Test disabled due to buggy ARM kernels"; |
| 99 | #else |
| 100 | TEST(InstructionSetFeaturesTest, FeaturesFromCpuInfo) { |
| 101 | #endif |
| 102 | // Take the default set of instruction features from the build. |
| 103 | std::unique_ptr<const InstructionSetFeatures> instruction_set_features( |
| 104 | InstructionSetFeatures::FromCppDefines()); |
| 105 | |
| 106 | // Check we get the same instruction set features using /proc/cpuinfo. |
| 107 | std::unique_ptr<const InstructionSetFeatures> cpuinfo_features( |
| 108 | InstructionSetFeatures::FromCpuInfo()); |
| 109 | EXPECT_TRUE(cpuinfo_features->Equals(instruction_set_features.get())) |
| 110 | << "CPU Info features: " << *cpuinfo_features.get() |
| 111 | << "\nFeatures from build: " << *instruction_set_features.get(); |
| 112 | } |
| 113 | #endif |
| 114 | |
Bilyan Borisov | bb661c0 | 2016-04-04 16:27:32 +0100 | [diff] [blame] | 115 | #ifndef ART_TARGET_ANDROID |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 116 | TEST(InstructionSetFeaturesTest, HostFeaturesFromCppDefines) { |
| 117 | std::string error_msg; |
| 118 | std::unique_ptr<const InstructionSetFeatures> default_features( |
| 119 | InstructionSetFeatures::FromVariant(kRuntimeISA, "default", &error_msg)); |
| 120 | ASSERT_TRUE(error_msg.empty()); |
| 121 | |
| 122 | std::unique_ptr<const InstructionSetFeatures> cpp_features( |
| 123 | InstructionSetFeatures::FromCppDefines()); |
| 124 | EXPECT_TRUE(default_features->Equals(cpp_features.get())) |
| 125 | << "Default variant features: " << *default_features.get() |
| 126 | << "\nFeatures from build: " << *cpp_features.get(); |
| 127 | } |
| 128 | #endif |
| 129 | |
| 130 | #if defined(__arm__) |
| 131 | TEST(InstructionSetFeaturesTest, DISABLED_FeaturesFromHwcap) { |
| 132 | LOG(WARNING) << "Test disabled due to buggy ARM kernels"; |
| 133 | #else |
| 134 | TEST(InstructionSetFeaturesTest, FeaturesFromHwcap) { |
| 135 | #endif |
| 136 | // Take the default set of instruction features from the build. |
| 137 | std::unique_ptr<const InstructionSetFeatures> instruction_set_features( |
| 138 | InstructionSetFeatures::FromCppDefines()); |
| 139 | |
| 140 | // Check we get the same instruction set features using AT_HWCAP. |
| 141 | std::unique_ptr<const InstructionSetFeatures> hwcap_features( |
| 142 | InstructionSetFeatures::FromHwcap()); |
| 143 | EXPECT_TRUE(hwcap_features->Equals(instruction_set_features.get())) |
| 144 | << "Hwcap features: " << *hwcap_features.get() |
| 145 | << "\nFeatures from build: " << *instruction_set_features.get(); |
| 146 | } |
| 147 | |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 148 | TEST(InstructionSetFeaturesTest, FeaturesFromAssembly) { |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 149 | // Take the default set of instruction features from the build. |
| 150 | std::unique_ptr<const InstructionSetFeatures> instruction_set_features( |
| 151 | InstructionSetFeatures::FromCppDefines()); |
| 152 | |
| 153 | // Check we get the same instruction set features using assembly tests. |
| 154 | std::unique_ptr<const InstructionSetFeatures> assembly_features( |
| 155 | InstructionSetFeatures::FromAssembly()); |
| 156 | EXPECT_TRUE(assembly_features->Equals(instruction_set_features.get())) |
| 157 | << "Assembly features: " << *assembly_features.get() |
| 158 | << "\nFeatures from build: " << *instruction_set_features.get(); |
| 159 | } |
| 160 | |
| 161 | } // namespace art |