File: test_ebb.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 (132 lines) | stat: -rw-r--r-- 3,512 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
/* Event-Based Branch Facility Tests.
 *
 * 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, Adhemerval Zanella - Initial implementation.
 */

#include <stdio.h>
#include <inttypes.h>
#include <paf/ebb.h>


#define BESCR   806

static inline unsigned long int
get_bescr (void)
{
  unsigned long int spr;
  asm volatile ("mfspr %0, %1\n\t"
		: "=r"(spr)
		: "i"(BESCR));
  return spr;
}

static int
ebb_context_test = 0;

static void
ebb_handler_test (void *context)
{
  return;
}

static int
ebb_interface_test (void)
{
  ebbhandler_t handler;
  unsigned long int bescr;
  unsigned long int mask;
  int ret;

  /* Register an invalid function to result in an error.  */
  handler = paf_ebb_register_handler (NULL, NULL, PAF_EBB_CALLBACK_GPR_SAVE,
                                      0);
  if (handler != EBB_REG_ERR)
    {
      printf ("Error: paf_ebb_register_handler (NULL) != EBB_REG_ERR\n");
      return -1;
    }

  bescr = get_bescr ();
  printf ("Initial EBB state: bescr %lx\n", bescr);

  ret = paf_ebb_enable_branches ();
  if (ret != 0)
    {
      printf ("Error: paf_ebb_enable_branches () returned %i\n", ret);
      return -1;
    }

  /* To check agains both Global Enable (GE - bit 0) and Performance Monitor
     Event Exception Enable (PME - bit 31).  */
  mask = 1 | (1 << 31);

  /* Check if both GE (bit 0) and PME (bit 31) are set.  */
  bescr = get_bescr ();
  if (!(bescr & mask))
    {
      printf ("Error: get_descr () resulted in 0x%lx\n", bescr); 
      return -1;
    }
  printf ("Enable EBB       : bescr %lx\n", bescr);

  paf_ebb_disable_branches ();
  if (ret != 0)
    {
      printf ("Error: paf_ebb_disable_branches () returned %i\n", ret);
      return -1;
    }

  /* Check if both GE (bit 0) and PME (bit 31) are not set.  */
  bescr = get_bescr ();
  if (bescr & mask)
    {
      printf ("Error: get_bescr () resulted in 0x%lx\n", bescr);
      return -1;
    }
  printf ("Disable EBB      : bescr %lx\n", bescr);

  /* Register a valid callback and check its address.  */
  handler = paf_ebb_register_handler (ebb_handler_test, &ebb_context_test,
				     PAF_EBB_CALLBACK_GPR_SAVE, 0);
  if (handler != ebb_handler_test)
    {
      printf ("Error: paf_ebb_register_handler \
	      (ebb_handler_test) != handler\n");
      return -1;
    }

  return 0;
}

int
main (void)
{
  int ret = 0;

  ret += ebb_interface_test ();

  return ret;
}