mirror of
https://github.com/google/cpu_features.git
synced 2025-04-28 15:33:37 +02:00
Reformat files
This commit is contained in:
parent
235d57c591
commit
d968991caa
@ -43,8 +43,10 @@ typedef struct {
|
|||||||
// For every config, looks into flags_line for the presence of the
|
// For every config, looks into flags_line for the presence of the
|
||||||
// corresponding proc_cpuinfo_flag, calls `set_bit` accordingly.
|
// corresponding proc_cpuinfo_flag, calls `set_bit` accordingly.
|
||||||
// Note: features is a pointer to the underlying Feature struct.
|
// Note: features is a pointer to the underlying Feature struct.
|
||||||
void CpuFeatures_SetFromFlags(const size_t configs_size, const CapabilityConfig* configs,
|
void CpuFeatures_SetFromFlags(const size_t configs_size,
|
||||||
const StringView flags_line, void* const features);
|
const CapabilityConfig* configs,
|
||||||
|
const StringView flags_line,
|
||||||
|
void* const features);
|
||||||
|
|
||||||
// For every config, looks into hwcaps for the presence of the feature. Calls
|
// For every config, looks into hwcaps for the presence of the feature. Calls
|
||||||
// `set_bit` with true if the hardware capability is found.
|
// `set_bit` with true if the hardware capability is found.
|
||||||
|
@ -50,7 +50,8 @@ int CpuFeatures_StringView_IndexOfChar(const StringView view, char c);
|
|||||||
|
|
||||||
// Returns the index of the first occurrence of sub_view in view or -1 if not
|
// Returns the index of the first occurrence of sub_view in view or -1 if not
|
||||||
// found.
|
// found.
|
||||||
int CpuFeatures_StringView_IndexOf(const StringView view, const StringView sub_view);
|
int CpuFeatures_StringView_IndexOf(const StringView view,
|
||||||
|
const StringView sub_view);
|
||||||
|
|
||||||
// Returns whether a is equal to b (same content).
|
// Returns whether a is equal to b (same content).
|
||||||
bool CpuFeatures_StringView_IsEquals(const StringView a, const StringView b);
|
bool CpuFeatures_StringView_IsEquals(const StringView a, const StringView b);
|
||||||
@ -64,11 +65,13 @@ StringView CpuFeatures_StringView_PopFront(const StringView view, size_t count);
|
|||||||
|
|
||||||
// Removes count characters from the end of view or kEmptyStringView if count if
|
// Removes count characters from the end of view or kEmptyStringView if count if
|
||||||
// greater than view.size.
|
// greater than view.size.
|
||||||
StringView CpuFeatures_StringView_PopBack(const StringView str_view, size_t count);
|
StringView CpuFeatures_StringView_PopBack(const StringView str_view,
|
||||||
|
size_t count);
|
||||||
|
|
||||||
// Keeps the count first characters of view or view if count if greater than
|
// Keeps the count first characters of view or view if count if greater than
|
||||||
// view.size.
|
// view.size.
|
||||||
StringView CpuFeatures_StringView_KeepFront(const StringView view, size_t count);
|
StringView CpuFeatures_StringView_KeepFront(const StringView view,
|
||||||
|
size_t count);
|
||||||
|
|
||||||
// Retrieves the first character of view. If view is empty the behavior is
|
// Retrieves the first character of view. If view is empty the behavior is
|
||||||
// undefined.
|
// undefined.
|
||||||
@ -86,14 +89,17 @@ StringView CpuFeatures_StringView_TrimWhitespace(StringView view);
|
|||||||
int CpuFeatures_StringView_ParsePositiveNumber(const StringView view);
|
int CpuFeatures_StringView_ParsePositiveNumber(const StringView view);
|
||||||
|
|
||||||
// Copies src StringView to dst buffer.
|
// Copies src StringView to dst buffer.
|
||||||
void CpuFeatures_StringView_CopyString(const StringView src, char* dst, size_t dst_size);
|
void CpuFeatures_StringView_CopyString(const StringView src, char* dst,
|
||||||
|
size_t dst_size);
|
||||||
|
|
||||||
// Checks if line contains the specified whitespace separated word.
|
// Checks if line contains the specified whitespace separated word.
|
||||||
bool CpuFeatures_StringView_HasWord(const StringView line, const char* const word);
|
bool CpuFeatures_StringView_HasWord(const StringView line,
|
||||||
|
const char* const word);
|
||||||
|
|
||||||
// Get key/value from line. key and value are separated by ": ".
|
// Get key/value from line. key and value are separated by ": ".
|
||||||
// key and value are cleaned up from leading and trailing whitespaces.
|
// key and value are cleaned up from leading and trailing whitespaces.
|
||||||
bool CpuFeatures_StringView_GetAttributeKeyValue(const StringView line, StringView* key,
|
bool CpuFeatures_StringView_GetAttributeKeyValue(const StringView line,
|
||||||
|
StringView* key,
|
||||||
StringView* value);
|
StringView* value);
|
||||||
|
|
||||||
CPU_FEATURES_END_CPP_NAMESPACE
|
CPU_FEATURES_END_CPP_NAMESPACE
|
||||||
|
@ -85,7 +85,8 @@ Aarch64Info GetAarch64Info(void) {
|
|||||||
Aarch64Info info = kEmptyAarch64Info;
|
Aarch64Info info = kEmptyAarch64Info;
|
||||||
|
|
||||||
FillProcCpuInfoData(&info);
|
FillProcCpuInfoData(&info);
|
||||||
CpuFeatures_OverrideFromHwCaps(kConfigsSize, kConfigs, CpuFeatures_GetHardwareCapabilities(),
|
CpuFeatures_OverrideFromHwCaps(kConfigsSize, kConfigs,
|
||||||
|
CpuFeatures_GetHardwareCapabilities(),
|
||||||
&info.features);
|
&info.features);
|
||||||
|
|
||||||
return info;
|
return info;
|
||||||
|
@ -87,12 +87,15 @@ static bool HandleArmLine(const LineResult result, ArmInfo* const info,
|
|||||||
} else if (CpuFeatures_StringView_IsEquals(key, str("CPU architecture"))) {
|
} else if (CpuFeatures_StringView_IsEquals(key, str("CPU architecture"))) {
|
||||||
// CPU architecture is a number that may be followed by letters. e.g.
|
// CPU architecture is a number that may be followed by letters. e.g.
|
||||||
// "6TEJ", "7".
|
// "6TEJ", "7".
|
||||||
const StringView digits = CpuFeatures_StringView_KeepFront(value, IndexOfNonDigit(value));
|
const StringView digits =
|
||||||
|
CpuFeatures_StringView_KeepFront(value, IndexOfNonDigit(value));
|
||||||
info->architecture = CpuFeatures_StringView_ParsePositiveNumber(digits);
|
info->architecture = CpuFeatures_StringView_ParsePositiveNumber(digits);
|
||||||
} else if (CpuFeatures_StringView_IsEquals(key, str("Processor"))) {
|
} else if (CpuFeatures_StringView_IsEquals(key, str("Processor"))) {
|
||||||
proc_info->processor_reports_armv6 = CpuFeatures_StringView_IndexOf(value, str("(v6l)")) >= 0;
|
proc_info->processor_reports_armv6 =
|
||||||
|
CpuFeatures_StringView_IndexOf(value, str("(v6l)")) >= 0;
|
||||||
} else if (CpuFeatures_StringView_IsEquals(key, str("Hardware"))) {
|
} else if (CpuFeatures_StringView_IsEquals(key, str("Hardware"))) {
|
||||||
proc_info->hardware_reports_goldfish = CpuFeatures_StringView_IsEquals(value, str("Goldfish"));
|
proc_info->hardware_reports_goldfish =
|
||||||
|
CpuFeatures_StringView_IsEquals(value, str("Goldfish"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return !result.eof;
|
return !result.eof;
|
||||||
@ -174,7 +177,8 @@ ArmInfo GetArmInfo(void) {
|
|||||||
ProcCpuInfoData proc_cpu_info_data = kEmptyProcCpuInfoData;
|
ProcCpuInfoData proc_cpu_info_data = kEmptyProcCpuInfoData;
|
||||||
|
|
||||||
FillProcCpuInfoData(&info, &proc_cpu_info_data);
|
FillProcCpuInfoData(&info, &proc_cpu_info_data);
|
||||||
CpuFeatures_OverrideFromHwCaps(kConfigsSize, kConfigs, CpuFeatures_GetHardwareCapabilities(),
|
CpuFeatures_OverrideFromHwCaps(kConfigsSize, kConfigs,
|
||||||
|
CpuFeatures_GetHardwareCapabilities(),
|
||||||
&info.features);
|
&info.features);
|
||||||
|
|
||||||
FixErrors(&info, &proc_cpu_info_data);
|
FixErrors(&info, &proc_cpu_info_data);
|
||||||
|
@ -63,7 +63,8 @@ MipsInfo GetMipsInfo(void) {
|
|||||||
MipsInfo info = kEmptyMipsInfo;
|
MipsInfo info = kEmptyMipsInfo;
|
||||||
|
|
||||||
FillProcCpuInfoData(&info.features);
|
FillProcCpuInfoData(&info.features);
|
||||||
CpuFeatures_OverrideFromHwCaps(kConfigsSize, kConfigs, CpuFeatures_GetHardwareCapabilities(),
|
CpuFeatures_OverrideFromHwCaps(kConfigsSize, kConfigs,
|
||||||
|
CpuFeatures_GetHardwareCapabilities(),
|
||||||
&info.features);
|
&info.features);
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
|
@ -21,11 +21,14 @@
|
|||||||
|
|
||||||
#if defined(_MSC_VER)
|
#if defined(_MSC_VER)
|
||||||
#include <io.h>
|
#include <io.h>
|
||||||
int CpuFeatures_OpenFile(const char* filename) { return _open(filename, _O_RDONLY); }
|
int CpuFeatures_OpenFile(const char* filename) {
|
||||||
|
return _open(filename, _O_RDONLY);
|
||||||
|
}
|
||||||
|
|
||||||
void CpuFeatures_CloseFile(int file_descriptor) { _close(file_descriptor); }
|
void CpuFeatures_CloseFile(int file_descriptor) { _close(file_descriptor); }
|
||||||
|
|
||||||
int CpuFeatures_ReadFile(int file_descriptor, void* buffer, size_t buffer_size) {
|
int CpuFeatures_ReadFile(int file_descriptor, void* buffer,
|
||||||
|
size_t buffer_size) {
|
||||||
return _read(file_descriptor, buffer, buffer_size);
|
return _read(file_descriptor, buffer, buffer_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -42,7 +45,8 @@ int CpuFeatures_OpenFile(const char* filename) {
|
|||||||
|
|
||||||
void CpuFeatures_CloseFile(int file_descriptor) { close(file_descriptor); }
|
void CpuFeatures_CloseFile(int file_descriptor) { close(file_descriptor); }
|
||||||
|
|
||||||
int CpuFeatures_ReadFile(int file_descriptor, void* buffer, size_t buffer_size) {
|
int CpuFeatures_ReadFile(int file_descriptor, void* buffer,
|
||||||
|
size_t buffer_size) {
|
||||||
int result;
|
int result;
|
||||||
do {
|
do {
|
||||||
result = read(file_descriptor, buffer, buffer_size);
|
result = read(file_descriptor, buffer, buffer_size);
|
||||||
|
@ -15,12 +15,15 @@
|
|||||||
#include "internal/linux_features_aggregator.h"
|
#include "internal/linux_features_aggregator.h"
|
||||||
#include "internal/string_view.h"
|
#include "internal/string_view.h"
|
||||||
|
|
||||||
void CpuFeatures_SetFromFlags(const size_t configs_size, const CapabilityConfig* configs,
|
void CpuFeatures_SetFromFlags(const size_t configs_size,
|
||||||
const StringView flags_line, void* const features) {
|
const CapabilityConfig* configs,
|
||||||
|
const StringView flags_line,
|
||||||
|
void* const features) {
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
for (; i < configs_size; ++i) {
|
for (; i < configs_size; ++i) {
|
||||||
const CapabilityConfig config = configs[i];
|
const CapabilityConfig config = configs[i];
|
||||||
config.set_bit(features, CpuFeatures_StringView_HasWord(flags_line, config.proc_cpuinfo_flag));
|
config.set_bit(features, CpuFeatures_StringView_HasWord(
|
||||||
|
flags_line, config.proc_cpuinfo_flag));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,8 +28,8 @@ void StackLineReader_Initialize(StackLineReader* reader, int fd) {
|
|||||||
|
|
||||||
// Replaces the content of buffer with bytes from the file.
|
// Replaces the content of buffer with bytes from the file.
|
||||||
static int LoadFullBuffer(StackLineReader* reader) {
|
static int LoadFullBuffer(StackLineReader* reader) {
|
||||||
const int read =
|
const int read = CpuFeatures_ReadFile(reader->fd, reader->buffer,
|
||||||
CpuFeatures_ReadFile(reader->fd, reader->buffer, STACK_LINE_READER_BUFFER_SIZE);
|
STACK_LINE_READER_BUFFER_SIZE);
|
||||||
assert(read >= 0);
|
assert(read >= 0);
|
||||||
reader->view.ptr = reader->buffer;
|
reader->view.ptr = reader->buffer;
|
||||||
reader->view.size = read;
|
reader->view.size = read;
|
||||||
@ -71,7 +71,8 @@ static void SkipToNextLine(StackLineReader* reader) {
|
|||||||
} else {
|
} else {
|
||||||
const int eol_index = IndexOfEol(reader);
|
const int eol_index = IndexOfEol(reader);
|
||||||
if (eol_index >= 0) {
|
if (eol_index >= 0) {
|
||||||
reader->view = CpuFeatures_StringView_PopFront(reader->view, eol_index + 1);
|
reader->view =
|
||||||
|
CpuFeatures_StringView_PopFront(reader->view, eol_index + 1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -120,8 +121,10 @@ LineResult StackLineReader_NextLine(StackLineReader* reader) {
|
|||||||
return CreateTruncatedLineResult(reader->view);
|
return CreateTruncatedLineResult(reader->view);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
StringView line = CpuFeatures_StringView_KeepFront(reader->view, eol_index);
|
StringView line =
|
||||||
reader->view = CpuFeatures_StringView_PopFront(reader->view, eol_index + 1);
|
CpuFeatures_StringView_KeepFront(reader->view, eol_index);
|
||||||
|
reader->view =
|
||||||
|
CpuFeatures_StringView_PopFront(reader->view, eol_index + 1);
|
||||||
return CreateValidLineResult(line);
|
return CreateValidLineResult(line);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,11 +28,13 @@ int CpuFeatures_StringView_IndexOfChar(const StringView view, char c) {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int CpuFeatures_StringView_IndexOf(const StringView view, const StringView sub_view) {
|
int CpuFeatures_StringView_IndexOf(const StringView view,
|
||||||
|
const StringView sub_view) {
|
||||||
if (sub_view.size) {
|
if (sub_view.size) {
|
||||||
StringView remainder = view;
|
StringView remainder = view;
|
||||||
while (remainder.size >= sub_view.size) {
|
while (remainder.size >= sub_view.size) {
|
||||||
const int found_index = CpuFeatures_StringView_IndexOfChar(remainder, sub_view.ptr[0]);
|
const int found_index =
|
||||||
|
CpuFeatures_StringView_IndexOfChar(remainder, sub_view.ptr[0]);
|
||||||
if (found_index < 0) break;
|
if (found_index < 0) break;
|
||||||
remainder = CpuFeatures_StringView_PopFront(remainder, found_index);
|
remainder = CpuFeatures_StringView_PopFront(remainder, found_index);
|
||||||
if (CpuFeatures_StringView_StartsWith(remainder, sub_view)) {
|
if (CpuFeatures_StringView_StartsWith(remainder, sub_view)) {
|
||||||
@ -57,21 +59,24 @@ bool CpuFeatures_StringView_StartsWith(const StringView a, const StringView b) {
|
|||||||
: false;
|
: false;
|
||||||
}
|
}
|
||||||
|
|
||||||
StringView CpuFeatures_StringView_PopFront(const StringView str_view, size_t count) {
|
StringView CpuFeatures_StringView_PopFront(const StringView str_view,
|
||||||
|
size_t count) {
|
||||||
if (count > str_view.size) {
|
if (count > str_view.size) {
|
||||||
return kEmptyStringView;
|
return kEmptyStringView;
|
||||||
}
|
}
|
||||||
return view(str_view.ptr + count, str_view.size - count);
|
return view(str_view.ptr + count, str_view.size - count);
|
||||||
}
|
}
|
||||||
|
|
||||||
StringView CpuFeatures_StringView_PopBack(const StringView str_view, size_t count) {
|
StringView CpuFeatures_StringView_PopBack(const StringView str_view,
|
||||||
|
size_t count) {
|
||||||
if (count > str_view.size) {
|
if (count > str_view.size) {
|
||||||
return kEmptyStringView;
|
return kEmptyStringView;
|
||||||
}
|
}
|
||||||
return view(str_view.ptr, str_view.size - count);
|
return view(str_view.ptr, str_view.size - count);
|
||||||
}
|
}
|
||||||
|
|
||||||
StringView CpuFeatures_StringView_KeepFront(const StringView str_view, size_t count) {
|
StringView CpuFeatures_StringView_KeepFront(const StringView str_view,
|
||||||
|
size_t count) {
|
||||||
return count <= str_view.size ? view(str_view.ptr, count) : str_view;
|
return count <= str_view.size ? view(str_view.ptr, count) : str_view;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,8 +92,10 @@ char CpuFeatures_StringView_Back(const StringView view) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
StringView CpuFeatures_StringView_TrimWhitespace(StringView view) {
|
StringView CpuFeatures_StringView_TrimWhitespace(StringView view) {
|
||||||
while (view.size && isspace(CpuFeatures_StringView_Front(view))) view = CpuFeatures_StringView_PopFront(view, 1);
|
while (view.size && isspace(CpuFeatures_StringView_Front(view)))
|
||||||
while (view.size && isspace(CpuFeatures_StringView_Back(view))) view = CpuFeatures_StringView_PopBack(view, 1);
|
view = CpuFeatures_StringView_PopFront(view, 1);
|
||||||
|
while (view.size && isspace(CpuFeatures_StringView_Back(view)))
|
||||||
|
view = CpuFeatures_StringView_PopBack(view, 1);
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -103,7 +110,8 @@ static int HexValue(const char c) {
|
|||||||
static int ParsePositiveNumberWithBase(const StringView view, int base) {
|
static int ParsePositiveNumberWithBase(const StringView view, int base) {
|
||||||
int result = 0;
|
int result = 0;
|
||||||
StringView remainder = view;
|
StringView remainder = view;
|
||||||
for (; remainder.size; remainder = CpuFeatures_StringView_PopFront(remainder, 1)) {
|
for (; remainder.size;
|
||||||
|
remainder = CpuFeatures_StringView_PopFront(remainder, 1)) {
|
||||||
const int value = HexValue(CpuFeatures_StringView_Front(remainder));
|
const int value = HexValue(CpuFeatures_StringView_Front(remainder));
|
||||||
if (value < 0 || value >= base) return -1;
|
if (value < 0 || value >= base) return -1;
|
||||||
result = (result * base) + value;
|
result = (result * base) + value;
|
||||||
@ -115,7 +123,8 @@ int CpuFeatures_StringView_ParsePositiveNumber(const StringView view) {
|
|||||||
if (view.size) {
|
if (view.size) {
|
||||||
const StringView hex_prefix = str("0x");
|
const StringView hex_prefix = str("0x");
|
||||||
if (CpuFeatures_StringView_StartsWith(view, hex_prefix)) {
|
if (CpuFeatures_StringView_StartsWith(view, hex_prefix)) {
|
||||||
const StringView span_no_prefix = CpuFeatures_StringView_PopFront(view, hex_prefix.size);
|
const StringView span_no_prefix =
|
||||||
|
CpuFeatures_StringView_PopFront(view, hex_prefix.size);
|
||||||
return ParsePositiveNumberWithBase(span_no_prefix, 16);
|
return ParsePositiveNumberWithBase(span_no_prefix, 16);
|
||||||
}
|
}
|
||||||
return ParsePositiveNumberWithBase(view, 10);
|
return ParsePositiveNumberWithBase(view, 10);
|
||||||
@ -123,7 +132,8 @@ int CpuFeatures_StringView_ParsePositiveNumber(const StringView view) {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CpuFeatures_StringView_CopyString(const StringView src, char* dst, size_t dst_size) {
|
void CpuFeatures_StringView_CopyString(const StringView src, char* dst,
|
||||||
|
size_t dst_size) {
|
||||||
if (dst_size > 0) {
|
if (dst_size > 0) {
|
||||||
const size_t max_copy_size = dst_size - 1;
|
const size_t max_copy_size = dst_size - 1;
|
||||||
const size_t copy_size =
|
const size_t copy_size =
|
||||||
@ -133,7 +143,8 @@ void CpuFeatures_StringView_CopyString(const StringView src, char* dst, size_t d
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CpuFeatures_StringView_HasWord(const StringView line, const char* const word_str) {
|
bool CpuFeatures_StringView_HasWord(const StringView line,
|
||||||
|
const char* const word_str) {
|
||||||
const StringView word = str(word_str);
|
const StringView word = str(word_str);
|
||||||
StringView remainder = line;
|
StringView remainder = line;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
@ -141,23 +152,31 @@ bool CpuFeatures_StringView_HasWord(const StringView line, const char* const wor
|
|||||||
if (index_of_word < 0) {
|
if (index_of_word < 0) {
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
const StringView before = CpuFeatures_StringView_KeepFront(line, index_of_word);
|
const StringView before =
|
||||||
const StringView after = CpuFeatures_StringView_PopFront(line, index_of_word + word.size);
|
CpuFeatures_StringView_KeepFront(line, index_of_word);
|
||||||
const bool valid_before = before.size == 0 || CpuFeatures_StringView_Back(before) == ' ';
|
const StringView after =
|
||||||
const bool valid_after = after.size == 0 || CpuFeatures_StringView_Front(after) == ' ';
|
CpuFeatures_StringView_PopFront(line, index_of_word + word.size);
|
||||||
|
const bool valid_before =
|
||||||
|
before.size == 0 || CpuFeatures_StringView_Back(before) == ' ';
|
||||||
|
const bool valid_after =
|
||||||
|
after.size == 0 || CpuFeatures_StringView_Front(after) == ' ';
|
||||||
if (valid_before && valid_after) return true;
|
if (valid_before && valid_after) return true;
|
||||||
remainder = CpuFeatures_StringView_PopFront(remainder, index_of_word + word.size);
|
remainder =
|
||||||
|
CpuFeatures_StringView_PopFront(remainder, index_of_word + word.size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CpuFeatures_StringView_GetAttributeKeyValue(const StringView line, StringView* key,
|
bool CpuFeatures_StringView_GetAttributeKeyValue(const StringView line,
|
||||||
|
StringView* key,
|
||||||
StringView* value) {
|
StringView* value) {
|
||||||
const StringView sep = str(": ");
|
const StringView sep = str(": ");
|
||||||
const int index_of_separator = CpuFeatures_StringView_IndexOf(line, sep);
|
const int index_of_separator = CpuFeatures_StringView_IndexOf(line, sep);
|
||||||
if (index_of_separator < 0) return false;
|
if (index_of_separator < 0) return false;
|
||||||
*value = CpuFeatures_StringView_TrimWhitespace(CpuFeatures_StringView_PopFront(line, index_of_separator + sep.size));
|
*value = CpuFeatures_StringView_TrimWhitespace(
|
||||||
*key = CpuFeatures_StringView_TrimWhitespace(CpuFeatures_StringView_KeepFront(line, index_of_separator));
|
CpuFeatures_StringView_PopFront(line, index_of_separator + sep.size));
|
||||||
|
*key = CpuFeatures_StringView_TrimWhitespace(
|
||||||
|
CpuFeatures_StringView_KeepFront(line, index_of_separator));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -94,7 +94,8 @@ extern "C" void CpuFeatures_CloseFile(int file_descriptor) {
|
|||||||
kFilesystem->FindFileOrDie(file_descriptor)->Close();
|
kFilesystem->FindFileOrDie(file_descriptor)->Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" int CpuFeatures_ReadFile(int file_descriptor, void* buf, size_t count) {
|
extern "C" int CpuFeatures_ReadFile(int file_descriptor, void* buf,
|
||||||
|
size_t count) {
|
||||||
return kFilesystem->FindFileOrDie(file_descriptor)
|
return kFilesystem->FindFileOrDie(file_descriptor)
|
||||||
->Read(file_descriptor, buf, count);
|
->Read(file_descriptor, buf, count);
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,8 @@ class LinuxFeatureAggregatorTest : public testing::Test {
|
|||||||
|
|
||||||
TEST_F(LinuxFeatureAggregatorTest, FromFlagsEmpty) {
|
TEST_F(LinuxFeatureAggregatorTest, FromFlagsEmpty) {
|
||||||
Features features;
|
Features features;
|
||||||
CpuFeatures_SetFromFlags(kConfigs.size(), kConfigs.data(), str(""), &features);
|
CpuFeatures_SetFromFlags(kConfigs.size(), kConfigs.data(), str(""),
|
||||||
|
&features);
|
||||||
EXPECT_FALSE(features.a);
|
EXPECT_FALSE(features.a);
|
||||||
EXPECT_FALSE(features.b);
|
EXPECT_FALSE(features.b);
|
||||||
EXPECT_FALSE(features.c);
|
EXPECT_FALSE(features.c);
|
||||||
@ -50,7 +51,8 @@ TEST_F(LinuxFeatureAggregatorTest, FromFlagsEmpty) {
|
|||||||
|
|
||||||
TEST_F(LinuxFeatureAggregatorTest, FromFlagsAllSet) {
|
TEST_F(LinuxFeatureAggregatorTest, FromFlagsAllSet) {
|
||||||
Features features;
|
Features features;
|
||||||
CpuFeatures_SetFromFlags(kConfigs.size(), kConfigs.data(), str("a c b"), &features);
|
CpuFeatures_SetFromFlags(kConfigs.size(), kConfigs.data(), str("a c b"),
|
||||||
|
&features);
|
||||||
EXPECT_TRUE(features.a);
|
EXPECT_TRUE(features.a);
|
||||||
EXPECT_TRUE(features.b);
|
EXPECT_TRUE(features.b);
|
||||||
EXPECT_TRUE(features.c);
|
EXPECT_TRUE(features.c);
|
||||||
@ -58,7 +60,8 @@ TEST_F(LinuxFeatureAggregatorTest, FromFlagsAllSet) {
|
|||||||
|
|
||||||
TEST_F(LinuxFeatureAggregatorTest, FromFlagsOnlyA) {
|
TEST_F(LinuxFeatureAggregatorTest, FromFlagsOnlyA) {
|
||||||
Features features;
|
Features features;
|
||||||
CpuFeatures_SetFromFlags(kConfigs.size(), kConfigs.data(), str("a"), &features);
|
CpuFeatures_SetFromFlags(kConfigs.size(), kConfigs.data(), str("a"),
|
||||||
|
&features);
|
||||||
EXPECT_TRUE(features.a);
|
EXPECT_TRUE(features.a);
|
||||||
EXPECT_FALSE(features.b);
|
EXPECT_FALSE(features.b);
|
||||||
EXPECT_FALSE(features.c);
|
EXPECT_FALSE(features.c);
|
||||||
@ -69,7 +72,8 @@ TEST_F(LinuxFeatureAggregatorTest, FromHwcapsNone) {
|
|||||||
capability.hwcaps = 0; // matches none
|
capability.hwcaps = 0; // matches none
|
||||||
capability.hwcaps2 = 0; // matches none
|
capability.hwcaps2 = 0; // matches none
|
||||||
Features features;
|
Features features;
|
||||||
CpuFeatures_OverrideFromHwCaps(kConfigs.size(), kConfigs.data(), capability, &features);
|
CpuFeatures_OverrideFromHwCaps(kConfigs.size(), kConfigs.data(), capability,
|
||||||
|
&features);
|
||||||
EXPECT_FALSE(features.a);
|
EXPECT_FALSE(features.a);
|
||||||
EXPECT_FALSE(features.b);
|
EXPECT_FALSE(features.b);
|
||||||
EXPECT_FALSE(features.c);
|
EXPECT_FALSE(features.c);
|
||||||
@ -80,7 +84,8 @@ TEST_F(LinuxFeatureAggregatorTest, FromHwcapsSet) {
|
|||||||
capability.hwcaps = 0b0010; // matches b but not a
|
capability.hwcaps = 0b0010; // matches b but not a
|
||||||
capability.hwcaps2 = 0b1111; // matches c
|
capability.hwcaps2 = 0b1111; // matches c
|
||||||
Features features;
|
Features features;
|
||||||
CpuFeatures_OverrideFromHwCaps(kConfigs.size(), kConfigs.data(), capability, &features);
|
CpuFeatures_OverrideFromHwCaps(kConfigs.size(), kConfigs.data(), capability,
|
||||||
|
&features);
|
||||||
EXPECT_FALSE(features.a);
|
EXPECT_FALSE(features.a);
|
||||||
EXPECT_TRUE(features.b);
|
EXPECT_TRUE(features.b);
|
||||||
EXPECT_TRUE(features.c);
|
EXPECT_TRUE(features.c);
|
||||||
|
@ -57,12 +57,15 @@ TEST(StringViewTest, CpuFeatures_StringView_IndexOf) {
|
|||||||
TEST(StringViewTest, CpuFeatures_StringView_StartsWith) {
|
TEST(StringViewTest, CpuFeatures_StringView_StartsWith) {
|
||||||
EXPECT_TRUE(CpuFeatures_StringView_StartsWith(str("test"), str("te")));
|
EXPECT_TRUE(CpuFeatures_StringView_StartsWith(str("test"), str("te")));
|
||||||
EXPECT_FALSE(CpuFeatures_StringView_StartsWith(str("test"), str("")));
|
EXPECT_FALSE(CpuFeatures_StringView_StartsWith(str("test"), str("")));
|
||||||
EXPECT_FALSE(CpuFeatures_StringView_StartsWith(str("test"), kEmptyStringView));
|
EXPECT_FALSE(
|
||||||
EXPECT_FALSE(CpuFeatures_StringView_StartsWith(kEmptyStringView, str("test")));
|
CpuFeatures_StringView_StartsWith(str("test"), kEmptyStringView));
|
||||||
|
EXPECT_FALSE(
|
||||||
|
CpuFeatures_StringView_StartsWith(kEmptyStringView, str("test")));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(StringViewTest, CpuFeatures_StringView_IsEquals) {
|
TEST(StringViewTest, CpuFeatures_StringView_IsEquals) {
|
||||||
EXPECT_TRUE(CpuFeatures_StringView_IsEquals(kEmptyStringView, kEmptyStringView));
|
EXPECT_TRUE(
|
||||||
|
CpuFeatures_StringView_IsEquals(kEmptyStringView, kEmptyStringView));
|
||||||
EXPECT_TRUE(CpuFeatures_StringView_IsEquals(kEmptyStringView, str("")));
|
EXPECT_TRUE(CpuFeatures_StringView_IsEquals(kEmptyStringView, str("")));
|
||||||
EXPECT_TRUE(CpuFeatures_StringView_IsEquals(str(""), kEmptyStringView));
|
EXPECT_TRUE(CpuFeatures_StringView_IsEquals(str(""), kEmptyStringView));
|
||||||
EXPECT_TRUE(CpuFeatures_StringView_IsEquals(str("a"), str("a")));
|
EXPECT_TRUE(CpuFeatures_StringView_IsEquals(str("a"), str("a")));
|
||||||
@ -111,11 +114,14 @@ TEST(StringViewTest, CpuFeatures_StringView_CopyString) {
|
|||||||
|
|
||||||
TEST(StringViewTest, CpuFeatures_StringView_HasWord) {
|
TEST(StringViewTest, CpuFeatures_StringView_HasWord) {
|
||||||
// Find flags at beginning, middle and end.
|
// Find flags at beginning, middle and end.
|
||||||
EXPECT_TRUE(CpuFeatures_StringView_HasWord(str("first middle last"), "first"));
|
EXPECT_TRUE(
|
||||||
EXPECT_TRUE(CpuFeatures_StringView_HasWord(str("first middle last"), "middle"));
|
CpuFeatures_StringView_HasWord(str("first middle last"), "first"));
|
||||||
|
EXPECT_TRUE(
|
||||||
|
CpuFeatures_StringView_HasWord(str("first middle last"), "middle"));
|
||||||
EXPECT_TRUE(CpuFeatures_StringView_HasWord(str("first middle last"), "last"));
|
EXPECT_TRUE(CpuFeatures_StringView_HasWord(str("first middle last"), "last"));
|
||||||
// Do not match partial flags
|
// Do not match partial flags
|
||||||
EXPECT_FALSE(CpuFeatures_StringView_HasWord(str("first middle last"), "irst"));
|
EXPECT_FALSE(
|
||||||
|
CpuFeatures_StringView_HasWord(str("first middle last"), "irst"));
|
||||||
EXPECT_FALSE(CpuFeatures_StringView_HasWord(str("first middle last"), "mid"));
|
EXPECT_FALSE(CpuFeatures_StringView_HasWord(str("first middle last"), "mid"));
|
||||||
EXPECT_FALSE(CpuFeatures_StringView_HasWord(str("first middle last"), "las"));
|
EXPECT_FALSE(CpuFeatures_StringView_HasWord(str("first middle last"), "las"));
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user