Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/google/cpu_features.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorGuillaume Chatelet <gchatelet@google.com>2020-10-12 12:50:35 +0300
committerGitHub <noreply@github.com>2020-10-12 12:50:35 +0300
commit9a8f04b24c9cca452b62ec1877a18f2e7678742b (patch)
tree0667f40d58849b849dd5f9432b507ff989e6cacb /test
parent3cc8f310d950b44cc6d2ead8057cf43330a726fd (diff)
[NFC] Generate separate tables via macro (#137)
This is a non functional change, it allows: - Getting rid of `unix_features_aggregator` - Have a single blob describing the features - Fix wrong mocking of `hwcaps` Downside: abuse of macros makes the code slightly magical and harder to understand. It think it's still an improvement over the current situation as there's less repetition and less chances to get something wrong.
Diffstat (limited to 'test')
-rw-r--r--test/CMakeLists.txt8
-rw-r--r--test/unix_features_aggregator_test.cc105
2 files changed, 1 insertions, 112 deletions
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index 834eec1..c10e617 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -12,7 +12,6 @@ add_library(filesystem_for_testing filesystem_for_testing.cc)
target_compile_definitions(filesystem_for_testing PUBLIC CPU_FEATURES_MOCK_FILESYSTEM)
##------------------------------------------------------------------------------
add_library(hwcaps_for_testing hwcaps_for_testing.cc)
-target_compile_definitions(hwcaps_for_testing PUBLIC CPU_FEATURES_MOCK_GET_ELF_HWCAP_FROM_GETAUXVAL)
target_link_libraries(hwcaps_for_testing filesystem_for_testing)
##------------------------------------------------------------------------------
add_library(stack_line_reader ../src/stack_line_reader.c)
@@ -23,7 +22,7 @@ add_library(stack_line_reader_for_test ../src/stack_line_reader.c)
target_compile_definitions(stack_line_reader_for_test PUBLIC STACK_LINE_READER_BUFFER_SIZE=16)
target_link_libraries(stack_line_reader_for_test string_view filesystem_for_testing)
##------------------------------------------------------------------------------
-add_library(all_libraries ../src/stack_line_reader.c ../src/unix_features_aggregator.c)
+add_library(all_libraries ../src/hwcaps.c ../src/stack_line_reader.c)
target_link_libraries(all_libraries hwcaps_for_testing stack_line_reader string_view)
#
@@ -46,11 +45,6 @@ add_executable(stack_line_reader_test stack_line_reader_test.cc)
target_link_libraries(stack_line_reader_test stack_line_reader_for_test)
add_test(NAME stack_line_reader_test COMMAND stack_line_reader_test)
##------------------------------------------------------------------------------
-## unix_features_aggregator_test
-add_executable(unix_features_aggregator_test unix_features_aggregator_test.cc)
-target_link_libraries(unix_features_aggregator_test all_libraries)
-add_test(NAME unix_features_aggregator_test COMMAND unix_features_aggregator_test)
-##------------------------------------------------------------------------------
## cpuinfo_x86_test
if(PROCESSOR_IS_X86)
add_executable(cpuinfo_x86_test cpuinfo_x86_test.cc ../src/cpuinfo_x86.c)
diff --git a/test/unix_features_aggregator_test.cc b/test/unix_features_aggregator_test.cc
deleted file mode 100644
index 3a36804..0000000
--- a/test/unix_features_aggregator_test.cc
+++ /dev/null
@@ -1,105 +0,0 @@
-// Copyright 2017 Google LLC
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#include "internal/unix_features_aggregator.h"
-
-#include <array>
-
-#include "gtest/gtest.h"
-
-namespace cpu_features {
-
-namespace {
-
-struct Features {
- bool a = false;
- bool b = false;
- bool c = false;
-};
-
-enum eFeatures { TEST_a, TEST_b, TEST_c };
-
-DECLARE_SETTER_AND_GETTER(Features, a)
-DECLARE_SETTER_AND_GETTER(Features, b)
-DECLARE_SETTER_AND_GETTER(Features, c)
-
-class LinuxFeatureAggregatorTest : public testing::Test {
- public:
- const std::array<CapabilityConfig, 3> kConfigs = {
- {{{0b0001, 0b0000}, "a", &set_a, &get_a},
- {{0b0010, 0b0000}, "b", &set_b, &get_b},
- {{0b0000, 0b1100}, "c", &set_c, &get_c}}};
-};
-
-TEST_F(LinuxFeatureAggregatorTest, FromFlagsEmpty) {
- Features features;
- CpuFeatures_SetFromFlags(kConfigs.size(), kConfigs.data(), str(""),
- &features);
- EXPECT_FALSE(features.a);
- EXPECT_FALSE(features.b);
- EXPECT_FALSE(features.c);
-
- EXPECT_FALSE(kConfigs[TEST_a].get_bit(&features));
-}
-
-TEST_F(LinuxFeatureAggregatorTest, FromFlagsAllSet) {
- Features features;
- CpuFeatures_SetFromFlags(kConfigs.size(), kConfigs.data(), str("a c b"),
- &features);
- EXPECT_TRUE(features.a);
- EXPECT_TRUE(features.b);
- EXPECT_TRUE(features.c);
-
- EXPECT_TRUE(kConfigs[TEST_a].get_bit(&features));
-}
-
-TEST_F(LinuxFeatureAggregatorTest, FromFlagsOnlyA) {
- Features features;
- CpuFeatures_SetFromFlags(kConfigs.size(), kConfigs.data(), str("a"),
- &features);
- EXPECT_TRUE(features.a);
- EXPECT_FALSE(features.b);
- EXPECT_FALSE(features.c);
-
- EXPECT_TRUE(kConfigs[TEST_a].get_bit(&features));
- EXPECT_FALSE(kConfigs[TEST_b].get_bit(&features));
- EXPECT_FALSE(kConfigs[TEST_c].get_bit(&features));
-}
-
-TEST_F(LinuxFeatureAggregatorTest, FromHwcapsNone) {
- HardwareCapabilities capability;
- capability.hwcaps = 0; // matches none
- capability.hwcaps2 = 0; // matches none
- Features features;
- CpuFeatures_OverrideFromHwCaps(kConfigs.size(), kConfigs.data(), capability,
- &features);
- EXPECT_FALSE(features.a);
- EXPECT_FALSE(features.b);
- EXPECT_FALSE(features.c);
-}
-
-TEST_F(LinuxFeatureAggregatorTest, FromHwcapsSet) {
- HardwareCapabilities capability;
- capability.hwcaps = 0b0010; // matches b but not a
- capability.hwcaps2 = 0b1111; // matches c
- Features features;
- CpuFeatures_OverrideFromHwCaps(kConfigs.size(), kConfigs.data(), capability,
- &features);
- EXPECT_FALSE(features.a);
- EXPECT_TRUE(features.b);
- EXPECT_TRUE(features.c);
-}
-
-} // namespace
-} // namespace cpu_features