blob: 83571cf2b1e494c372e5885f83a98fee4e5f69c9 [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
21#ifdef HAVE_ANDROID_OS
22#include "cutils/properties.h"
23#endif
24
25#include "base/stringprintf.h"
26
27namespace art {
28
29#ifdef HAVE_ANDROID_OS
30TEST(InstructionSetFeaturesTest, FeaturesFromSystemPropertyVariant) {
31 // Take the default set of instruction features from the build.
32 std::unique_ptr<const InstructionSetFeatures> instruction_set_features(
33 InstructionSetFeatures::FromCppDefines());
34
35 // Read the features property.
36 std::string key = StringPrintf("dalvik.vm.isa.%s.variant", GetInstructionSetString(kRuntimeISA));
37 char dex2oat_isa_variant[PROPERTY_VALUE_MAX];
38 if (property_get(key.c_str(), dex2oat_isa_variant, nullptr) > 0) {
39 // Use features from property to build InstructionSetFeatures and check against build's
40 // features.
41 std::string error_msg;
42 std::unique_ptr<const InstructionSetFeatures> property_features(
43 InstructionSetFeatures::FromVariant(kRuntimeISA, dex2oat_isa_variant, &error_msg));
44 ASSERT_TRUE(property_features.get() != nullptr) << error_msg;
45
46 EXPECT_TRUE(property_features->Equals(instruction_set_features.get()))
47 << "System property features: " << *property_features.get()
48 << "\nFeatures from build: " << *instruction_set_features.get();
49 }
50}
51
52TEST(InstructionSetFeaturesTest, FeaturesFromSystemPropertyString) {
53 // Take the default set of instruction features from the build.
54 std::unique_ptr<const InstructionSetFeatures> instruction_set_features(
55 InstructionSetFeatures::FromCppDefines());
56
57 // Read the features property.
58 std::string key = StringPrintf("dalvik.vm.isa.%s.features", GetInstructionSetString(kRuntimeISA));
59 char dex2oat_isa_features[PROPERTY_VALUE_MAX];
60 if (property_get(key.c_str(), dex2oat_isa_features, nullptr) > 0) {
61 // Use features from property to build InstructionSetFeatures and check against build's
62 // features.
63 std::string error_msg;
64 std::unique_ptr<const InstructionSetFeatures> base_features(
65 InstructionSetFeatures::FromVariant(kRuntimeISA, "default", &error_msg));
66 ASSERT_TRUE(base_features.get() != nullptr) << error_msg;
67
68 std::unique_ptr<const InstructionSetFeatures> property_features(
69 base_features->AddFeaturesFromString(dex2oat_isa_features, &error_msg));
70 ASSERT_TRUE(property_features.get() != nullptr) << error_msg;
71
72 EXPECT_TRUE(property_features->Equals(instruction_set_features.get()))
73 << "System property features: " << *property_features.get()
74 << "\nFeatures from build: " << *instruction_set_features.get();
75 }
76}
77
78#if defined(__arm__)
79TEST(InstructionSetFeaturesTest, DISABLED_FeaturesFromCpuInfo) {
80 LOG(WARNING) << "Test disabled due to buggy ARM kernels";
81#else
82TEST(InstructionSetFeaturesTest, FeaturesFromCpuInfo) {
83#endif
84 // Take the default set of instruction features from the build.
85 std::unique_ptr<const InstructionSetFeatures> instruction_set_features(
86 InstructionSetFeatures::FromCppDefines());
87
88 // Check we get the same instruction set features using /proc/cpuinfo.
89 std::unique_ptr<const InstructionSetFeatures> cpuinfo_features(
90 InstructionSetFeatures::FromCpuInfo());
91 EXPECT_TRUE(cpuinfo_features->Equals(instruction_set_features.get()))
92 << "CPU Info features: " << *cpuinfo_features.get()
93 << "\nFeatures from build: " << *instruction_set_features.get();
94}
95#endif
96
97#ifndef HAVE_ANDROID_OS
98TEST(InstructionSetFeaturesTest, HostFeaturesFromCppDefines) {
99 std::string error_msg;
100 std::unique_ptr<const InstructionSetFeatures> default_features(
101 InstructionSetFeatures::FromVariant(kRuntimeISA, "default", &error_msg));
102 ASSERT_TRUE(error_msg.empty());
103
104 std::unique_ptr<const InstructionSetFeatures> cpp_features(
105 InstructionSetFeatures::FromCppDefines());
106 EXPECT_TRUE(default_features->Equals(cpp_features.get()))
107 << "Default variant features: " << *default_features.get()
108 << "\nFeatures from build: " << *cpp_features.get();
109}
110#endif
111
112#if defined(__arm__)
113TEST(InstructionSetFeaturesTest, DISABLED_FeaturesFromHwcap) {
114 LOG(WARNING) << "Test disabled due to buggy ARM kernels";
115#else
116TEST(InstructionSetFeaturesTest, FeaturesFromHwcap) {
117#endif
118 // Take the default set of instruction features from the build.
119 std::unique_ptr<const InstructionSetFeatures> instruction_set_features(
120 InstructionSetFeatures::FromCppDefines());
121
122 // Check we get the same instruction set features using AT_HWCAP.
123 std::unique_ptr<const InstructionSetFeatures> hwcap_features(
124 InstructionSetFeatures::FromHwcap());
125 EXPECT_TRUE(hwcap_features->Equals(instruction_set_features.get()))
126 << "Hwcap features: " << *hwcap_features.get()
127 << "\nFeatures from build: " << *instruction_set_features.get();
128}
129
130
131#if defined(__arm__)
132TEST(InstructionSetFeaturesTest, DISABLED_FeaturesFromAssembly) {
133 LOG(WARNING) << "Test disabled due to buggy ARM kernels";
134#else
135TEST(InstructionSetFeaturesTest, FeaturesFromAssembly) {
136#endif
137 // Take the default set of instruction features from the build.
138 std::unique_ptr<const InstructionSetFeatures> instruction_set_features(
139 InstructionSetFeatures::FromCppDefines());
140
141 // Check we get the same instruction set features using assembly tests.
142 std::unique_ptr<const InstructionSetFeatures> assembly_features(
143 InstructionSetFeatures::FromAssembly());
144 EXPECT_TRUE(assembly_features->Equals(instruction_set_features.get()))
145 << "Assembly features: " << *assembly_features.get()
146 << "\nFeatures from build: " << *instruction_set_features.get();
147}
148
149} // namespace art