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 | 46ee31b | 2016-12-14 10:11:49 -0800 | [diff] [blame] | 25 | #include "android-base/stringprintf.h" |
| 26 | |
Andreas Gampe | bda1d60 | 2016-08-29 17:43:45 -0700 | [diff] [blame] | 27 | #include "base/logging.h" |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 28 | |
| 29 | namespace art { |
| 30 | |
Andreas Gampe | 46ee31b | 2016-12-14 10:11:49 -0800 | [diff] [blame] | 31 | using android::base::StringPrintf; |
| 32 | |
Bilyan Borisov | bb661c0 | 2016-04-04 16:27:32 +0100 | [diff] [blame] | 33 | #ifdef ART_TARGET_ANDROID |
Ian Rogers | d9df670 | 2014-11-17 16:43:15 -0800 | [diff] [blame] | 34 | #if defined(__aarch64__) |
| 35 | TEST(InstructionSetFeaturesTest, DISABLED_FeaturesFromSystemPropertyVariant) { |
| 36 | LOG(WARNING) << "Test disabled due to no CPP define for A53 erratum 835769"; |
| 37 | #else |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 38 | TEST(InstructionSetFeaturesTest, FeaturesFromSystemPropertyVariant) { |
Ian Rogers | d9df670 | 2014-11-17 16:43:15 -0800 | [diff] [blame] | 39 | #endif |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 40 | // Take the default set of instruction features from the build. |
| 41 | std::unique_ptr<const InstructionSetFeatures> instruction_set_features( |
| 42 | InstructionSetFeatures::FromCppDefines()); |
| 43 | |
Ian Rogers | d9df670 | 2014-11-17 16:43:15 -0800 | [diff] [blame] | 44 | // Read the variant property. |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 45 | std::string key = StringPrintf("dalvik.vm.isa.%s.variant", GetInstructionSetString(kRuntimeISA)); |
Dimitry Ivanov | 9642b1b | 2016-09-28 02:44:00 -0700 | [diff] [blame] | 46 | std::string dex2oat_isa_variant = android::base::GetProperty(key, ""); |
| 47 | if (!dex2oat_isa_variant.empty()) { |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 48 | // Use features from property to build InstructionSetFeatures and check against build's |
| 49 | // features. |
| 50 | std::string error_msg; |
| 51 | std::unique_ptr<const InstructionSetFeatures> property_features( |
| 52 | InstructionSetFeatures::FromVariant(kRuntimeISA, dex2oat_isa_variant, &error_msg)); |
| 53 | ASSERT_TRUE(property_features.get() != nullptr) << error_msg; |
| 54 | |
| 55 | EXPECT_TRUE(property_features->Equals(instruction_set_features.get())) |
| 56 | << "System property features: " << *property_features.get() |
| 57 | << "\nFeatures from build: " << *instruction_set_features.get(); |
| 58 | } |
| 59 | } |
| 60 | |
Ian Rogers | d9df670 | 2014-11-17 16:43:15 -0800 | [diff] [blame] | 61 | #if defined(__aarch64__) |
| 62 | TEST(InstructionSetFeaturesTest, DISABLED_FeaturesFromSystemPropertyString) { |
| 63 | LOG(WARNING) << "Test disabled due to no CPP define for A53 erratum 835769"; |
| 64 | #else |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 65 | TEST(InstructionSetFeaturesTest, FeaturesFromSystemPropertyString) { |
Ian Rogers | d9df670 | 2014-11-17 16:43:15 -0800 | [diff] [blame] | 66 | #endif |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 67 | // Take the default set of instruction features from the build. |
| 68 | std::unique_ptr<const InstructionSetFeatures> instruction_set_features( |
| 69 | InstructionSetFeatures::FromCppDefines()); |
| 70 | |
Ian Rogers | d9df670 | 2014-11-17 16:43:15 -0800 | [diff] [blame] | 71 | // Read the variant property. |
| 72 | std::string variant_key = StringPrintf("dalvik.vm.isa.%s.variant", |
| 73 | GetInstructionSetString(kRuntimeISA)); |
Dimitry Ivanov | 9642b1b | 2016-09-28 02:44:00 -0700 | [diff] [blame] | 74 | std::string dex2oat_isa_variant = android::base::GetProperty(variant_key, ""); |
| 75 | if (!dex2oat_isa_variant.empty()) { |
Ian Rogers | d9df670 | 2014-11-17 16:43:15 -0800 | [diff] [blame] | 76 | // Read the features property. |
| 77 | std::string features_key = StringPrintf("dalvik.vm.isa.%s.features", |
| 78 | GetInstructionSetString(kRuntimeISA)); |
Dimitry Ivanov | 9642b1b | 2016-09-28 02:44:00 -0700 | [diff] [blame] | 79 | std::string dex2oat_isa_features = android::base::GetProperty(features_key, ""); |
| 80 | if (!dex2oat_isa_features.empty()) { |
Ian Rogers | d9df670 | 2014-11-17 16:43:15 -0800 | [diff] [blame] | 81 | // Use features from property to build InstructionSetFeatures and check against build's |
| 82 | // features. |
| 83 | std::string error_msg; |
| 84 | std::unique_ptr<const InstructionSetFeatures> base_features( |
| 85 | InstructionSetFeatures::FromVariant(kRuntimeISA, dex2oat_isa_variant, &error_msg)); |
| 86 | ASSERT_TRUE(base_features.get() != nullptr) << error_msg; |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 87 | |
Ian Rogers | d9df670 | 2014-11-17 16:43:15 -0800 | [diff] [blame] | 88 | std::unique_ptr<const InstructionSetFeatures> property_features( |
| 89 | base_features->AddFeaturesFromString(dex2oat_isa_features, &error_msg)); |
| 90 | ASSERT_TRUE(property_features.get() != nullptr) << error_msg; |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 91 | |
Ian Rogers | d9df670 | 2014-11-17 16:43:15 -0800 | [diff] [blame] | 92 | EXPECT_TRUE(property_features->Equals(instruction_set_features.get())) |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 93 | << "System property features: " << *property_features.get() |
| 94 | << "\nFeatures from build: " << *instruction_set_features.get(); |
Ian Rogers | d9df670 | 2014-11-17 16:43:15 -0800 | [diff] [blame] | 95 | } |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 96 | } |
| 97 | } |
| 98 | |
| 99 | #if defined(__arm__) |
| 100 | TEST(InstructionSetFeaturesTest, DISABLED_FeaturesFromCpuInfo) { |
| 101 | LOG(WARNING) << "Test disabled due to buggy ARM kernels"; |
| 102 | #else |
| 103 | TEST(InstructionSetFeaturesTest, FeaturesFromCpuInfo) { |
| 104 | #endif |
| 105 | // Take the default set of instruction features from the build. |
| 106 | std::unique_ptr<const InstructionSetFeatures> instruction_set_features( |
| 107 | InstructionSetFeatures::FromCppDefines()); |
| 108 | |
| 109 | // Check we get the same instruction set features using /proc/cpuinfo. |
| 110 | std::unique_ptr<const InstructionSetFeatures> cpuinfo_features( |
| 111 | InstructionSetFeatures::FromCpuInfo()); |
| 112 | EXPECT_TRUE(cpuinfo_features->Equals(instruction_set_features.get())) |
| 113 | << "CPU Info features: " << *cpuinfo_features.get() |
| 114 | << "\nFeatures from build: " << *instruction_set_features.get(); |
| 115 | } |
| 116 | #endif |
| 117 | |
Bilyan Borisov | bb661c0 | 2016-04-04 16:27:32 +0100 | [diff] [blame] | 118 | #ifndef ART_TARGET_ANDROID |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 119 | TEST(InstructionSetFeaturesTest, HostFeaturesFromCppDefines) { |
| 120 | std::string error_msg; |
| 121 | std::unique_ptr<const InstructionSetFeatures> default_features( |
| 122 | InstructionSetFeatures::FromVariant(kRuntimeISA, "default", &error_msg)); |
| 123 | ASSERT_TRUE(error_msg.empty()); |
| 124 | |
| 125 | std::unique_ptr<const InstructionSetFeatures> cpp_features( |
| 126 | InstructionSetFeatures::FromCppDefines()); |
| 127 | EXPECT_TRUE(default_features->Equals(cpp_features.get())) |
| 128 | << "Default variant features: " << *default_features.get() |
| 129 | << "\nFeatures from build: " << *cpp_features.get(); |
| 130 | } |
| 131 | #endif |
| 132 | |
| 133 | #if defined(__arm__) |
| 134 | TEST(InstructionSetFeaturesTest, DISABLED_FeaturesFromHwcap) { |
| 135 | LOG(WARNING) << "Test disabled due to buggy ARM kernels"; |
| 136 | #else |
| 137 | TEST(InstructionSetFeaturesTest, FeaturesFromHwcap) { |
| 138 | #endif |
| 139 | // Take the default set of instruction features from the build. |
| 140 | std::unique_ptr<const InstructionSetFeatures> instruction_set_features( |
| 141 | InstructionSetFeatures::FromCppDefines()); |
| 142 | |
| 143 | // Check we get the same instruction set features using AT_HWCAP. |
| 144 | std::unique_ptr<const InstructionSetFeatures> hwcap_features( |
| 145 | InstructionSetFeatures::FromHwcap()); |
| 146 | EXPECT_TRUE(hwcap_features->Equals(instruction_set_features.get())) |
| 147 | << "Hwcap features: " << *hwcap_features.get() |
| 148 | << "\nFeatures from build: " << *instruction_set_features.get(); |
| 149 | } |
| 150 | |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 151 | TEST(InstructionSetFeaturesTest, FeaturesFromAssembly) { |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 152 | // Take the default set of instruction features from the build. |
| 153 | std::unique_ptr<const InstructionSetFeatures> instruction_set_features( |
| 154 | InstructionSetFeatures::FromCppDefines()); |
| 155 | |
| 156 | // Check we get the same instruction set features using assembly tests. |
| 157 | std::unique_ptr<const InstructionSetFeatures> assembly_features( |
| 158 | InstructionSetFeatures::FromAssembly()); |
| 159 | EXPECT_TRUE(assembly_features->Equals(instruction_set_features.get())) |
| 160 | << "Assembly features: " << *assembly_features.get() |
| 161 | << "\nFeatures from build: " << *instruction_set_features.get(); |
| 162 | } |
| 163 | |
| 164 | } // namespace art |