File: test_dsc.c

package info (click to toggle)
paflib 0.3.0-1
  • links: PTS
  • area: main
  • in suites: bookworm, bullseye, buster, forky, sid, stretch, trixie
  • size: 2,448 kB
  • ctags: 725
  • sloc: sh: 4,503; ansic: 2,320; asm: 837; makefile: 148
file content (171 lines) | stat: -rw-r--r-- 4,516 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/* libpaf-dsc test suite.
 *
 * Copyright IBM Corp. 2013
 *
 * The MIT License (MIT)
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 *
 * Contributors:
 *     IBM Corporation, Edjunior Barbosa Machado - Initial implementation.
 */

#include <stdio.h>
#include <errno.h>
#include <inttypes.h>
#include <paf/dsc.h>

int main(void)
{
  uint64_t dscr, dscr_support;
  if ((dscr_support = paf_dsc_check_support()) == 0)
    {
      if (errno == ENOSYS)
	{
          fprintf(stderr, "DSCR not available.\n");
	  return 0;
	}
      else
	{
	  perror("Error checking DSCR availability.");
	  return -1;
	}
    }
      
  if ((paf_dsc_get(&dscr)) < 0)
    {
      perror("Cannot get dscr value.");
      return -1;
    }

  dscr = DSCR_DPFD_SET(dscr, DSCR_DPFD_MAX);

  /* DSCR_DPFD is available since ISA 2.05 */
  if ((dscr_support | dscr) != dscr_support)
    {
      fprintf(stderr, "DSCR_DPFD feature was supposed to be available (it is provided since DSCR initial support on ISA 2.05).\n");
      return -1;
    }
  else
    {
      uint64_t dscr_aux;
      if (paf_dsc_set(dscr) < 0)
	{
	  perror("Cannot set DSCR_DPFD field.");
	  return -1;
	}
      if (paf_dsc_get(&dscr_aux) < 0)
	{
	  perror("Cannot get dscr value.");
	  return -1;
	}
      if (dscr != dscr_aux)
	{
	  fprintf(stderr, "DSCR_DPFD_MAX not set properly (returned 0x%" PRIx64 ").\n", dscr_aux);
	  return -1;
	}
    }
  /* DSCR_LSD is available since ISA 2.06 */
  if ((dscr_support | DSCR_LSD) != dscr_support)
      fprintf(stderr, "DSCR_LSD flag is not supported (available only in ISA 2.06 and newer).\n");
  else
    {
      if (paf_dsc_set(dscr | DSCR_LSD) < 0)
	{
	  perror("Cannot set DSCR_LSD flag.");
	  return -1;
	}
      if (paf_dsc_get(&dscr) < 0)
	{
	  perror("Cannot get dscr value.");
	  return -1;
	}
      if ((dscr & DSCR_LSD) != DSCR_LSD)
	{
	  fprintf(stderr, "DSCR_LSD not set (returned 0x%" PRIx64 ").\n", dscr);
	  return -1;
	}
    }

  dscr = DSCR_URG_SET(dscr, 7);

  /* DSCR_URG available only in ISA 2.06+ */
  if ((dscr_support | dscr) != dscr_support)
      fprintf(stderr, "DSCR_URG feature is not supported (available in ISA 2.06+ and newer).\n");
  else
    {
      uint64_t dscr_aux;
      if (paf_dsc_set(dscr) < 0)
	{
	  perror("Cannot set DSCR_URG field.");
	  return -1;
        }
      if (paf_dsc_get(&dscr_aux) < 0)
	{
	  perror("Cannot get dscr value.");
	  return -1;
	}
      if (dscr_aux != dscr)
	{
	  fprintf(stderr, "DSCR_URG not set properly (returned 0x%" PRIx64 ").\n", dscr_aux);
	  return -1;
	}
    }

  /* DSCR_HWUE available only in ISA 2.07 */
  if ((dscr_support | DSCR_HWUE) != dscr_support)
      fprintf(stderr, "DSCR_HWUE flag is not supported (available only in ISA 2.07).\n");
  else
    {
      if (paf_dsc_set(dscr | DSCR_HWUE) < 0)
	{
	  perror("Cannot set DSCR_HWUE flag (available only in ISA 2.07).\n");
          return -1;
        }
      if (paf_dsc_get(&dscr) < 0)
	{
	  perror("Cannot get dscr value.");
	  return -1;
	}
      if ((dscr & DSCR_HWUE) != DSCR_HWUE)
	{
	  fprintf(stderr, "DSCR_HWUE not set (returned 0x%" PRIx64 ").\n", dscr);
	  return -1;
	}
    }

  /* disable DSCR */
  if (paf_dsc_set(0) < 0)
    {
      fprintf(stderr, "Cannot fully disable DSCR.\n");
      return -1;
    }
  if (paf_dsc_get(&dscr) < 0)
    {
      perror("Cannot get dscr value.");
      return -1;
    }
  if (dscr != 0)
    {
      fprintf(stderr, "DSCR is not fully disabled (returned 0x%" PRIx64 ").\n", dscr);
      return -1;
    }

  return 0;
}