xref: /aosp_15_r20/external/cpu_features/test/hwcaps_for_testing.cc (revision eca53ba6d2e951e174b64682eaf56a36b8204c89)
1 // Copyright 2017 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //    http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include "hwcaps_for_testing.h"
16 
17 #include <string.h>
18 
19 #include "internal/string_view.h"
20 
21 namespace cpu_features {
22 
23 namespace {
24 static auto* const g_hardware_capabilities = new HardwareCapabilities();
25 static const char* g_platform_pointer = nullptr;
26 static const char* g_base_platform_pointer = nullptr;
27 }  // namespace
28 
SetHardwareCapabilities(uint32_t hwcaps,uint32_t hwcaps2)29 void SetHardwareCapabilities(uint32_t hwcaps, uint32_t hwcaps2) {
30   g_hardware_capabilities->hwcaps = hwcaps;
31   g_hardware_capabilities->hwcaps2 = hwcaps2;
32 }
SetPlatformPointer(const char * string)33 void SetPlatformPointer(const char* string) { g_platform_pointer = string; }
SetBasePlatformPointer(const char * string)34 void SetBasePlatformPointer(const char* string) {
35   g_base_platform_pointer = string;
36 }
37 
ResetHwcaps()38 void ResetHwcaps() {
39   SetHardwareCapabilities(0, 0);
40   SetPlatformPointer(nullptr);
41   SetBasePlatformPointer(nullptr);
42 }
43 
CpuFeatures_GetHardwareCapabilities(void)44 HardwareCapabilities CpuFeatures_GetHardwareCapabilities(void) {
45   return *g_hardware_capabilities;
46 }
CpuFeatures_GetPlatformPointer(void)47 const char* CpuFeatures_GetPlatformPointer(void) { return g_platform_pointer; }
CpuFeatures_GetBasePlatformPointer(void)48 const char* CpuFeatures_GetBasePlatformPointer(void) {
49   return g_base_platform_pointer;
50 }
51 
52 }  // namespace cpu_features
53