blob: d4893923d6ba364d6e87b660f49757351fe17b33 [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 Gampe46ee31b2016-12-14 10:11:49 -080025#include "android-base/stringprintf.h"
26
Andreas Gampebda1d602016-08-29 17:43:45 -070027#include "base/logging.h"
Ian Rogersd582fa42014-11-05 23:46:43 -080028
29namespace art {
30
Andreas Gampe46ee31b2016-12-14 10:11:49 -080031using android::base::StringPrintf;
32
Bilyan Borisovbb661c02016-04-04 16:27:32 +010033#ifdef ART_TARGET_ANDROID
Ian Rogersd9df6702014-11-17 16:43:15 -080034#if defined(__aarch64__)
35TEST(InstructionSetFeaturesTest, DISABLED_FeaturesFromSystemPropertyVariant) {
36 LOG(WARNING) << "Test disabled due to no CPP define for A53 erratum 835769";
37#else
Ian Rogersd582fa42014-11-05 23:46:43 -080038TEST(InstructionSetFeaturesTest, FeaturesFromSystemPropertyVariant) {
Ian Rogersd9df6702014-11-17 16:43:15 -080039#endif
Ian Rogersd582fa42014-11-05 23:46:43 -080040 // Take the default set of instruction features from the build.
41 std::unique_ptr<const InstructionSetFeatures> instruction_set_features(
42 InstructionSetFeatures::FromCppDefines());
43
Ian Rogersd9df6702014-11-17 16:43:15 -080044 // Read the variant property.
Ian Rogersd582fa42014-11-05 23:46:43 -080045 std::string key = StringPrintf("dalvik.vm.isa.%s.variant", GetInstructionSetString(kRuntimeISA));
Dimitry Ivanov9642b1b2016-09-28 02:44:00 -070046 std::string dex2oat_isa_variant = android::base::GetProperty(key, "");
47 if (!dex2oat_isa_variant.empty()) {
Ian Rogersd582fa42014-11-05 23:46:43 -080048 // 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 Rogersd9df6702014-11-17 16:43:15 -080061#if defined(__aarch64__)
62TEST(InstructionSetFeaturesTest, DISABLED_FeaturesFromSystemPropertyString) {
63 LOG(WARNING) << "Test disabled due to no CPP define for A53 erratum 835769";
64#else
Ian Rogersd582fa42014-11-05 23:46:43 -080065TEST(InstructionSetFeaturesTest, FeaturesFromSystemPropertyString) {
Ian Rogersd9df6702014-11-17 16:43:15 -080066#endif
Ian Rogersd582fa42014-11-05 23:46:43 -080067 // Take the default set of instruction features from the build.
68 std::unique_ptr<const InstructionSetFeatures> instruction_set_features(
69 InstructionSetFeatures::FromCppDefines());
70
Ian Rogersd9df6702014-11-17 16:43:15 -080071 // Read the variant property.
72 std::string variant_key = StringPrintf("dalvik.vm.isa.%s.variant",
73 GetInstructionSetString(kRuntimeISA));
Dimitry Ivanov9642b1b2016-09-28 02:44:00 -070074 std::string dex2oat_isa_variant = android::base::GetProperty(variant_key, "");
75 if (!dex2oat_isa_variant.empty()) {
Ian Rogersd9df6702014-11-17 16:43:15 -080076 // Read the features property.
77 std::string features_key = StringPrintf("dalvik.vm.isa.%s.features",
78 GetInstructionSetString(kRuntimeISA));
Dimitry Ivanov9642b1b2016-09-28 02:44:00 -070079 std::string dex2oat_isa_features = android::base::GetProperty(features_key, "");
80 if (!dex2oat_isa_features.empty()) {
Ian Rogersd9df6702014-11-17 16:43:15 -080081 // 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 Rogersd582fa42014-11-05 23:46:43 -080087
Ian Rogersd9df6702014-11-17 16:43:15 -080088 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 Rogersd582fa42014-11-05 23:46:43 -080091
Ian Rogersd9df6702014-11-17 16:43:15 -080092 EXPECT_TRUE(property_features->Equals(instruction_set_features.get()))
Ian Rogersd582fa42014-11-05 23:46:43 -080093 << "System property features: " << *property_features.get()
94 << "\nFeatures from build: " << *instruction_set_features.get();
Ian Rogersd9df6702014-11-17 16:43:15 -080095 }
Ian Rogersd582fa42014-11-05 23:46:43 -080096 }
97}
98
99#if defined(__arm__)
100TEST(InstructionSetFeaturesTest, DISABLED_FeaturesFromCpuInfo) {
101 LOG(WARNING) << "Test disabled due to buggy ARM kernels";
102#else
103TEST(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 Borisovbb661c02016-04-04 16:27:32 +0100118#ifndef ART_TARGET_ANDROID
Ian Rogersd582fa42014-11-05 23:46:43 -0800119TEST(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__)
134TEST(InstructionSetFeaturesTest, DISABLED_FeaturesFromHwcap) {
135 LOG(WARNING) << "Test disabled due to buggy ARM kernels";
136#else
137TEST(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 Rogersd582fa42014-11-05 23:46:43 -0800151TEST(InstructionSetFeaturesTest, FeaturesFromAssembly) {
Ian Rogersd582fa42014-11-05 23:46:43 -0800152 // 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