|
Packit Service |
3b0880 |
/* Test CPU feature data.
|
|
Packit Service |
3b0880 |
This file is part of the GNU C Library.
|
|
Packit Service |
3b0880 |
Copyright (C) 2012-2018 Free Software Foundation, Inc.
|
|
Packit Service |
3b0880 |
|
|
Packit Service |
3b0880 |
The GNU C Library is free software; you can redistribute it and/or
|
|
Packit Service |
3b0880 |
modify it under the terms of the GNU Lesser General Public
|
|
Packit Service |
3b0880 |
License as published by the Free Software Foundation; either
|
|
Packit Service |
3b0880 |
version 2.1 of the License, or (at your option) any later version.
|
|
Packit Service |
3b0880 |
|
|
Packit Service |
3b0880 |
The GNU C Library is distributed in the hope that it will be useful,
|
|
Packit Service |
3b0880 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
3b0880 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit Service |
3b0880 |
Lesser General Public License for more details.
|
|
Packit Service |
3b0880 |
|
|
Packit Service |
3b0880 |
You should have received a copy of the GNU Lesser General Public
|
|
Packit Service |
3b0880 |
License along with the GNU C Library; if not, see
|
|
Packit Service |
3b0880 |
<http://www.gnu.org/licenses/>. */
|
|
Packit Service |
3b0880 |
|
|
Packit Service |
3b0880 |
#include <cpu-features.h>
|
|
Packit Service |
3b0880 |
#include <stdio.h>
|
|
Packit Service |
3b0880 |
#include <stdlib.h>
|
|
Packit Service |
3b0880 |
#include <string.h>
|
|
Packit Service |
3b0880 |
|
|
Packit Service |
3b0880 |
static char *cpu_flags;
|
|
Packit Service |
3b0880 |
|
|
Packit Service |
3b0880 |
/* Search for flags in /proc/cpuinfo and store line
|
|
Packit Service |
3b0880 |
in cpu_flags. */
|
|
Packit Service |
3b0880 |
void
|
|
Packit Service |
3b0880 |
get_cpuinfo (void)
|
|
Packit Service |
3b0880 |
{
|
|
Packit Service |
3b0880 |
FILE *f;
|
|
Packit Service |
3b0880 |
char *line = NULL;
|
|
Packit Service |
3b0880 |
size_t len = 0;
|
|
Packit Service |
3b0880 |
ssize_t read;
|
|
Packit Service |
3b0880 |
|
|
Packit Service |
3b0880 |
f = fopen ("/proc/cpuinfo", "r");
|
|
Packit Service |
3b0880 |
if (f == NULL)
|
|
Packit Service |
3b0880 |
{
|
|
Packit Service |
3b0880 |
printf ("cannot open /proc/cpuinfo\n");
|
|
Packit Service |
3b0880 |
exit (1);
|
|
Packit Service |
3b0880 |
}
|
|
Packit Service |
3b0880 |
|
|
Packit Service |
3b0880 |
while ((read = getline (&line, &len, f)) != -1)
|
|
Packit Service |
3b0880 |
{
|
|
Packit Service |
3b0880 |
if (strncmp (line, "flags", 5) == 0)
|
|
Packit Service |
3b0880 |
{
|
|
Packit Service |
3b0880 |
cpu_flags = strdup (line);
|
|
Packit Service |
3b0880 |
break;
|
|
Packit Service |
3b0880 |
}
|
|
Packit Service |
3b0880 |
}
|
|
Packit Service |
3b0880 |
fclose (f);
|
|
Packit Service |
3b0880 |
free (line);
|
|
Packit Service |
3b0880 |
}
|
|
Packit Service |
3b0880 |
|
|
Packit Service |
3b0880 |
int
|
|
Packit Service |
3b0880 |
check_proc (const char *proc_name, int flag, const char *name)
|
|
Packit Service |
3b0880 |
{
|
|
Packit Service |
3b0880 |
int found = 0;
|
|
Packit Service |
3b0880 |
|
|
Packit Service |
3b0880 |
printf ("Checking %s:\n", name);
|
|
Packit Service |
3b0880 |
printf (" init-arch %d\n", flag);
|
|
Packit Service |
3b0880 |
if (strstr (cpu_flags, proc_name) != NULL)
|
|
Packit Service |
3b0880 |
found = 1;
|
|
Packit Service |
3b0880 |
printf (" cpuinfo (%s) %d\n", proc_name, found);
|
|
Packit Service |
3b0880 |
|
|
Packit Service |
3b0880 |
if (found != flag)
|
|
Packit Service |
3b0880 |
printf (" *** failure ***\n");
|
|
Packit Service |
3b0880 |
|
|
Packit Service |
3b0880 |
return (found != flag);
|
|
Packit Service |
3b0880 |
}
|
|
Packit Service |
3b0880 |
|
|
Packit Service |
3b0880 |
static int
|
|
Packit Service |
3b0880 |
do_test (int argc, char **argv)
|
|
Packit Service |
3b0880 |
{
|
|
Packit Service |
3b0880 |
int fails;
|
|
Packit Service |
3b0880 |
|
|
Packit Service |
3b0880 |
get_cpuinfo ();
|
|
Packit Service |
3b0880 |
fails = check_proc ("avx", HAS_ARCH_FEATURE (AVX_Usable),
|
|
Packit Service |
3b0880 |
"HAS_ARCH_FEATURE (AVX_Usable)");
|
|
Packit Service |
3b0880 |
fails += check_proc ("fma4", HAS_ARCH_FEATURE (FMA4_Usable),
|
|
Packit Service |
3b0880 |
"HAS_ARCH_FEATURE (FMA4_Usable)");
|
|
Packit Service |
3b0880 |
fails += check_proc ("sse4_2", HAS_CPU_FEATURE (SSE4_2),
|
|
Packit Service |
3b0880 |
"HAS_CPU_FEATURE (SSE4_2)");
|
|
Packit Service |
3b0880 |
fails += check_proc ("sse4_1", HAS_CPU_FEATURE (SSE4_1)
|
|
Packit Service |
3b0880 |
, "HAS_CPU_FEATURE (SSE4_1)");
|
|
Packit Service |
3b0880 |
fails += check_proc ("ssse3", HAS_CPU_FEATURE (SSSE3),
|
|
Packit Service |
3b0880 |
"HAS_CPU_FEATURE (SSSE3)");
|
|
Packit Service |
3b0880 |
fails += check_proc ("popcnt", HAS_CPU_FEATURE (POPCOUNT),
|
|
Packit Service |
3b0880 |
"HAS_CPU_FEATURE (POPCOUNT)");
|
|
Packit Service |
3b0880 |
|
|
Packit Service |
3b0880 |
printf ("%d differences between /proc/cpuinfo and glibc code.\n", fails);
|
|
Packit Service |
3b0880 |
|
|
Packit Service |
3b0880 |
return (fails != 0);
|
|
Packit Service |
3b0880 |
}
|
|
Packit Service |
3b0880 |
|
|
Packit Service |
3b0880 |
#include "../../../test-skeleton.c"
|