1 /* glibc-hwcaps subdirectory test.  s390x version.
2    Copyright (C) 2020-2021 Free Software Foundation, Inc.
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
17    <https://www.gnu.org/licenses/>.  */
18 
19 #include <stdio.h>
20 #include <string.h>
21 #include <support/check.h>
22 #include <sys/auxv.h>
23 #include <sys/param.h>
24 
25 extern int marker2 (void);
26 extern int marker3 (void);
27 extern int marker4 (void);
28 
29 /* Return the arch level, 10 for the baseline libmarkermod*.so's.  */
30 static int
compute_level(void)31 compute_level (void)
32 {
33   const char *platform = (const char *) getauxval (AT_PLATFORM);
34 
35   /* The arch* versions refer to the edition of the Principles of
36      Operation, and they are off by two when compared with the recent
37      product names.  (The code below should not be considered an
38      accurate mapping to Principles of Operation editions for earlier
39      AT_PLATFORM strings).  */
40   if (strcmp (platform, "z900") == 0)
41     return 10;
42   if (strcmp (platform, "z990") == 0)
43     return 10;
44   if (strcmp (platform, "z9-109") == 0)
45     return 10;
46   if (strcmp (platform, "z10") == 0)
47     return 10;
48   if (strcmp (platform, "z196") == 0)
49     return 10;
50   if (strcmp (platform, "zEC12") == 0)
51     return 10;
52 
53   /* If we are running on z13 or newer and the kernel was booted with novx,
54      then AT_PLATFORM is z13 or newer, but _dl_hwcaps_subdirs_active will
55      return zero and the _dl_hwcaps_subdirs are not searched.  */
56   const unsigned long int hwcap = getauxval (AT_HWCAP);
57   if ((hwcap & HWCAP_S390_VX) == 0)
58     return 10;
59 
60   if (strcmp (platform, "z13") == 0)
61     return 11;
62   if (strcmp (platform, "z14") == 0)
63     return 12;
64   if (strcmp (platform, "z15") == 0)
65     return 13;
66   printf ("warning: unrecognized AT_PLATFORM value: %s\n", platform);
67   /* Assume that the new platform supports z15.  */
68   return 13;
69 }
70 
71 static int
do_test(void)72 do_test (void)
73 {
74   int level = compute_level ();
75   printf ("info: detected architecture level: arch%d\n", level);
76   TEST_COMPARE (marker2 (), MIN (level - 9, 2));
77   TEST_COMPARE (marker3 (), MIN (level - 9, 3));
78   TEST_COMPARE (marker4 (), MIN (level - 9, 4));
79   return 0;
80 }
81 
82 #include <support/test-driver.c>
83