wp.c (29583dfcd2dd72c766422bd05c16f06c6b1fb356) wp.c (7d54a4acd8c1de3ea70d31424757dcdb7f0a231a)
1// SPDX-License-Identifier: GPL-2.0
2#include <stdlib.h>
3#include <string.h>
4#include <unistd.h>
5#include <errno.h>
6#include <sys/ioctl.h>
7#include <linux/compiler.h>
8#include <linux/hw_breakpoint.h>

--- 45 unchanged lines hidden (view full) ---

54static int __event(int wp_type, void *wp_addr, unsigned long wp_len)
55{
56 int fd;
57 struct perf_event_attr attr;
58
59 get__perf_event_attr(&attr, wp_type, wp_addr, wp_len);
60 fd = sys_perf_event_open(&attr, 0, -1, -1,
61 perf_event_open_cloexec_flag());
1// SPDX-License-Identifier: GPL-2.0
2#include <stdlib.h>
3#include <string.h>
4#include <unistd.h>
5#include <errno.h>
6#include <sys/ioctl.h>
7#include <linux/compiler.h>
8#include <linux/hw_breakpoint.h>

--- 45 unchanged lines hidden (view full) ---

54static int __event(int wp_type, void *wp_addr, unsigned long wp_len)
55{
56 int fd;
57 struct perf_event_attr attr;
58
59 get__perf_event_attr(&attr, wp_type, wp_addr, wp_len);
60 fd = sys_perf_event_open(&attr, 0, -1, -1,
61 perf_event_open_cloexec_flag());
62 if (fd < 0)
62 if (fd < 0) {
63 fd = -errno;
63 pr_debug("failed opening event %x\n", attr.bp_type);
64 pr_debug("failed opening event %x\n", attr.bp_type);
65 }
64
65 return fd;
66}
67#endif
68
69static int test__wp_ro(struct test_suite *test __maybe_unused,
70 int subtest __maybe_unused)
71{
72#if defined(__s390x__) || defined(__x86_64__) || defined(__i386__)
73 return TEST_SKIP;
74#else
75 int fd;
76 unsigned long tmp, tmp1 = rand();
77
78 fd = __event(HW_BREAKPOINT_R, (void *)&data1, sizeof(data1));
79 if (fd < 0)
66
67 return fd;
68}
69#endif
70
71static int test__wp_ro(struct test_suite *test __maybe_unused,
72 int subtest __maybe_unused)
73{
74#if defined(__s390x__) || defined(__x86_64__) || defined(__i386__)
75 return TEST_SKIP;
76#else
77 int fd;
78 unsigned long tmp, tmp1 = rand();
79
80 fd = __event(HW_BREAKPOINT_R, (void *)&data1, sizeof(data1));
81 if (fd < 0)
80 return -1;
82 return fd == -ENODEV ? TEST_SKIP : -1;
81
82 tmp = data1;
83 WP_TEST_ASSERT_VAL(fd, "RO watchpoint", 1);
84
85 data1 = tmp1 + tmp;
86 WP_TEST_ASSERT_VAL(fd, "RO watchpoint", 1);
87
88 close(fd);

--- 7 unchanged lines hidden (view full) ---

96#if defined(__s390x__)
97 return TEST_SKIP;
98#else
99 int fd;
100 unsigned long tmp, tmp1 = rand();
101
102 fd = __event(HW_BREAKPOINT_W, (void *)&data1, sizeof(data1));
103 if (fd < 0)
83
84 tmp = data1;
85 WP_TEST_ASSERT_VAL(fd, "RO watchpoint", 1);
86
87 data1 = tmp1 + tmp;
88 WP_TEST_ASSERT_VAL(fd, "RO watchpoint", 1);
89
90 close(fd);

--- 7 unchanged lines hidden (view full) ---

98#if defined(__s390x__)
99 return TEST_SKIP;
100#else
101 int fd;
102 unsigned long tmp, tmp1 = rand();
103
104 fd = __event(HW_BREAKPOINT_W, (void *)&data1, sizeof(data1));
105 if (fd < 0)
104 return -1;
106 return fd == -ENODEV ? TEST_SKIP : -1;
105
106 tmp = data1;
107 WP_TEST_ASSERT_VAL(fd, "WO watchpoint", 0);
108
109 data1 = tmp1 + tmp;
110 WP_TEST_ASSERT_VAL(fd, "WO watchpoint", 1);
111
112 close(fd);

--- 8 unchanged lines hidden (view full) ---

121 return TEST_SKIP;
122#else
123 int fd;
124 unsigned long tmp, tmp1 = rand();
125
126 fd = __event(HW_BREAKPOINT_R | HW_BREAKPOINT_W, (void *)&data1,
127 sizeof(data1));
128 if (fd < 0)
107
108 tmp = data1;
109 WP_TEST_ASSERT_VAL(fd, "WO watchpoint", 0);
110
111 data1 = tmp1 + tmp;
112 WP_TEST_ASSERT_VAL(fd, "WO watchpoint", 1);
113
114 close(fd);

--- 8 unchanged lines hidden (view full) ---

123 return TEST_SKIP;
124#else
125 int fd;
126 unsigned long tmp, tmp1 = rand();
127
128 fd = __event(HW_BREAKPOINT_R | HW_BREAKPOINT_W, (void *)&data1,
129 sizeof(data1));
130 if (fd < 0)
129 return -1;
131 return fd == -ENODEV ? TEST_SKIP : -1;
130
131 tmp = data1;
132 WP_TEST_ASSERT_VAL(fd, "RW watchpoint", 1);
133
134 data1 = tmp1 + tmp;
135 WP_TEST_ASSERT_VAL(fd, "RW watchpoint", 2);
136
137 close(fd);

--- 7 unchanged lines hidden (view full) ---

145 return TEST_SKIP;
146#else
147 int fd, ret;
148 unsigned long tmp = rand();
149 struct perf_event_attr new_attr;
150
151 fd = __event(HW_BREAKPOINT_W, (void *)&data1, sizeof(data1));
152 if (fd < 0)
132
133 tmp = data1;
134 WP_TEST_ASSERT_VAL(fd, "RW watchpoint", 1);
135
136 data1 = tmp1 + tmp;
137 WP_TEST_ASSERT_VAL(fd, "RW watchpoint", 2);
138
139 close(fd);

--- 7 unchanged lines hidden (view full) ---

147 return TEST_SKIP;
148#else
149 int fd, ret;
150 unsigned long tmp = rand();
151 struct perf_event_attr new_attr;
152
153 fd = __event(HW_BREAKPOINT_W, (void *)&data1, sizeof(data1));
154 if (fd < 0)
153 return -1;
155 return fd == -ENODEV ? TEST_SKIP : -1;
154
155 data1 = tmp;
156 WP_TEST_ASSERT_VAL(fd, "Modify watchpoint", 1);
157
158 /* Modify watchpoint with disabled = 1 */
159 get__perf_event_attr(&new_attr, HW_BREAKPOINT_W, (void *)&data2[0],
160 sizeof(u8) * 2);
161 new_attr.disabled = 1;

--- 46 unchanged lines hidden ---
156
157 data1 = tmp;
158 WP_TEST_ASSERT_VAL(fd, "Modify watchpoint", 1);
159
160 /* Modify watchpoint with disabled = 1 */
161 get__perf_event_attr(&new_attr, HW_BREAKPOINT_W, (void *)&data2[0],
162 sizeof(u8) * 2);
163 new_attr.disabled = 1;

--- 46 unchanged lines hidden ---