blob: 0b8e53189615d4cc24aeb174d3a0e6b8f16c94d1 [file] [log] [blame]
Ian Rogersd582fa42014-11-05 23:46:43 -08001/*
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 Borisovbb661c02016-04-04 16:27:32 +010021#ifdef ART_TARGET_ANDROID
Dimitry Ivanov9642b1b2016-09-28 02:44:00 -070022#include "android-base/properties.h"
Ian Rogersd582fa42014-11-05 23:46:43 -080023#endif
24
Andreas Gampebda1d602016-08-29 17:43:45 -070025#include "base/logging.h"
Ian Rogersd582fa42014-11-05 23:46:43 -080026#include "base/stringprintf.h"
27
28namespace art {
29
Bilyan Borisovbb661c02016-04-04 16:27:32 +010030#ifdef ART_TARGET_ANDROID
Ian Rogersd9df6702014-11-17 16:43:15 -080031#if defined(__aarch64__)
32TEST(InstructionSetFeaturesTest, DISABLED_FeaturesFromSystemPropertyVariant) {
33 LOG(WARNING) << "Test disabled due to no CPP define for A53 erratum 835769";
34#else
Ian Rogersd582fa42014-11-05 23:46:43 -080035TEST(InstructionSetFeaturesTest, FeaturesFromSystemPropertyVariant) {
Ian Rogersd9df6702014-11-17 16:43:15 -080036#endif
Ian Rogersd582fa42014-11-05 23:46:43 -080037 // Take the default set of instruction features from the build.
38 std::unique_ptr<const InstructionSetFeatures> instruction_set_features(
39 InstructionSetFeatures::FromCppDefines());
40
Ian Rogersd9df6702014-11-17 16:43:15 -080041 // Read the variant property.
Ian Rogersd582fa42014-11-05 23:46:43 -080042 std::string key = StringPrintf("dalvik.vm.isa.%s.variant", GetInstructionSetString(kRuntimeISA));
Dimitry Ivanov9642b1b2016-09-28 02:44:00 -070043 std::string dex2oat_isa_variant = android::base::GetProperty(key, "");
44 if (!dex2oat_isa_variant.empty()) {
Ian Rogersd582fa42014-11-05 23:46:43 -080045 // 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 Rogersd9df6702014-11-17 16:43:15 -080058#if defined(__aarch64__)
59TEST(InstructionSetFeaturesTest, DISABLED_FeaturesFromSystemPropertyString) {
60 LOG(WARNING) << "Test disabled due to no CPP define for A53 erratum 835769";
61#else
Ian Rogersd582fa42014-11-05 23:46:43 -080062TEST(InstructionSetFeaturesTest, FeaturesFromSystemPropertyString) {
Ian Rogersd9df6702014-11-17 16:43:15 -080063#endif
Ian Rogersd582fa42014-11-05 23:46:43 -080064 // Take the default set of instruction features from the build.
65 std::unique_ptr<const InstructionSetFeatures> instruction_set_features(
66 InstructionSetFeatures::FromCppDefines());
67
Ian Rogersd9df6702014-11-17 16:43:15 -080068 // Read the variant property.
69 std::string variant_key = StringPrintf("dalvik.vm.isa.%s.variant",
70 GetInstructionSetString(kRuntimeISA));
Dimitry Ivanov9642b1b2016-09-28 02:44:00 -070071 std::string dex2oat_isa_variant = android::base::GetProperty(variant_key, "");
72 if (!dex2oat_isa_variant.empty()) {
Ian Rogersd9df6702014-11-17 16:43:15 -080073 // Read the features property.
74 std::string features_key = StringPrintf("dalvik.vm.isa.%s.features",
75 GetInstructionSetString(kRuntimeISA));
Dimitry Ivanov9642b1b2016-09-28 02:44:00 -070076 std::string dex2oat_isa_features = android::base::GetProperty(features_key, "");
77 if (!dex2oat_isa_features.empty()) {
Ian Rogersd9df6702014-11-17 16:43:15 -080078 // 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 Rogersd582fa42014-11-05 23:46:43 -080084
Ian Rogersd9df6702014-11-17 16:43:15 -080085 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 Rogersd582fa42014-11-05 23:46:43 -080088
Ian Rogersd9df6702014-11-17 16:43:15 -080089 EXPECT_TRUE(property_features->Equals(instruction_set_features.get()))
Ian Rogersd582fa42014-11-05 23:46:43 -080090 << "System property features: " << *property_features.get()
91 << "\nFeatures from build: " << *instruction_set_features.get();
Ian Rogersd9df6702014-11-17 16:43:15 -080092 }
Ian Rogersd582fa42014-11-05 23:46:43 -080093 }
94}
95
96#if defined(__arm__)
97TEST(InstructionSetFeaturesTest, DISABLED_FeaturesFromCpuInfo) {
98 LOG(WARNING) << "Test disabled due to buggy ARM kernels";
99#else
100TEST(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 Borisovbb661c02016-04-04 16:27:32 +0100115#ifndef ART_TARGET_ANDROID
Ian Rogersd582fa42014-11-05 23:46:43 -0800116TEST(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__)
131TEST(InstructionSetFeaturesTest, DISABLED_FeaturesFromHwcap) {
132 LOG(WARNING) << "Test disabled due to buggy ARM kernels";
133#else
134TEST(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 Rogersd582fa42014-11-05 23:46:43 -0800148TEST(InstructionSetFeaturesTest, FeaturesFromAssembly) {
Ian Rogersd582fa42014-11-05 23:46:43 -0800149 // 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