]>
Commit | Line | Data |
---|---|---|
cdfbe503 | 1 | /* Check use of sysconf() for cache geometries. |
6d7e8eda | 2 | Copyright (C) 2017-2023 Free Software Foundation, Inc. |
cdfbe503 PC |
3 | This file is part of the GNU C Library. |
4 | ||
5 | The GNU C Library is free software; you can redistribute it and/or | |
6 | modify it under the terms of the GNU Lesser General Public | |
7 | License as published by the Free Software Foundation; either | |
8 | version 2.1 of the License, or (at your option) any later version. | |
9 | ||
10 | The GNU C Library is distributed in the hope that it will be useful, | |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 | Lesser General Public License for more details. | |
14 | ||
15 | You should have received a copy of the GNU Lesser General Public | |
16 | License along with the GNU C Library; if not, see | |
5a82c748 | 17 | <https://www.gnu.org/licenses/>. */ |
cdfbe503 PC |
18 | |
19 | /* Test use of sysconf() to get cache sizes, cache set associativity | |
20 | and cache line sizes. */ | |
21 | ||
22 | #include <errno.h> | |
23 | #include <stdio.h> | |
24 | #include <stdlib.h> | |
25 | #include <unistd.h> | |
26 | ||
27 | #include <support/test-driver.h> | |
28 | ||
29 | #define call_str(f, name) f(name, #name) | |
30 | ||
31 | long | |
32 | do_sysconf (int name, const char * str) | |
33 | { | |
34 | int rc = 0; | |
35 | long val; | |
36 | errno = 0; | |
37 | val = sysconf (name); | |
38 | if (val == -1) { | |
39 | if (errno != EINVAL) { | |
40 | printf("error: sysconf(%s): unexpected errno(%d)\n", str, errno); | |
41 | exit (1); | |
42 | } | |
43 | printf ("info: sysconf(%s): unsupported\n", str); | |
44 | rc = 1; | |
45 | } else | |
46 | printf ("sysconf(%s) = 0x%lx (%ld)\n", str, val, val); | |
47 | return rc; | |
48 | } | |
49 | ||
50 | static int | |
51 | do_test (void) | |
52 | { | |
53 | int rc = 0; | |
54 | ||
55 | rc += call_str (do_sysconf, _SC_LEVEL1_ICACHE_SIZE); | |
56 | rc += call_str (do_sysconf, _SC_LEVEL1_ICACHE_ASSOC); | |
57 | rc += call_str (do_sysconf, _SC_LEVEL1_ICACHE_LINESIZE); | |
58 | rc += call_str (do_sysconf, _SC_LEVEL1_DCACHE_SIZE); | |
59 | rc += call_str (do_sysconf, _SC_LEVEL1_DCACHE_ASSOC); | |
60 | rc += call_str (do_sysconf, _SC_LEVEL1_DCACHE_LINESIZE); | |
61 | rc += call_str (do_sysconf, _SC_LEVEL2_CACHE_SIZE); | |
62 | rc += call_str (do_sysconf, _SC_LEVEL2_CACHE_ASSOC); | |
63 | rc += call_str (do_sysconf, _SC_LEVEL2_CACHE_LINESIZE); | |
64 | rc += call_str (do_sysconf, _SC_LEVEL3_CACHE_SIZE); | |
65 | rc += call_str (do_sysconf, _SC_LEVEL3_CACHE_ASSOC); | |
66 | rc += call_str (do_sysconf, _SC_LEVEL3_CACHE_LINESIZE); | |
67 | ||
68 | if (rc) | |
69 | return EXIT_UNSUPPORTED; | |
70 | return 0; | |
71 | } | |
72 | ||
73 | #include <support/test-driver.c> |