Skip to content

Commit 216a137

Browse files
beaubelgraverostedt
authored andcommitted
selftests/user_events: Ensure auto cleanup works as expected
User events now auto cleanup upon the last reference put. Update ftrace_test to ensure this works as expected. Ensure EBUSY delays while event is being deleted do not cause transient failures by waiting and re-attempting. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Beau Belgrave <[email protected]> Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent a65442e commit 216a137

File tree

1 file changed

+38
-11
lines changed

1 file changed

+38
-11
lines changed

tools/testing/selftests/user_events/ftrace_test.c

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -102,30 +102,56 @@ static int get_print_fmt(char *buffer, int len)
102102
return -1;
103103
}
104104

105+
static bool wait_for_delete(void)
106+
{
107+
int i;
108+
109+
for (i = 0; i < 1000; ++i) {
110+
int fd = open(enable_file, O_RDONLY);
111+
112+
if (fd == -1)
113+
return true;
114+
115+
close(fd);
116+
usleep(1000);
117+
}
118+
119+
return false;
120+
}
121+
105122
static int clear(int *check)
106123
{
107124
struct user_unreg unreg = {0};
125+
int fd;
108126

109127
unreg.size = sizeof(unreg);
110128
unreg.disable_bit = 31;
111129
unreg.disable_addr = (__u64)check;
112130

113-
int fd = open(data_file, O_RDWR);
131+
fd = open(data_file, O_RDWR);
114132

115133
if (fd == -1)
116134
return -1;
117135

118136
if (ioctl(fd, DIAG_IOCSUNREG, &unreg) == -1)
119137
if (errno != ENOENT)
120-
return -1;
121-
122-
if (ioctl(fd, DIAG_IOCSDEL, "__test_event") == -1)
123-
if (errno != ENOENT)
124-
return -1;
138+
goto fail;
139+
140+
if (ioctl(fd, DIAG_IOCSDEL, "__test_event") == -1) {
141+
if (errno == EBUSY) {
142+
if (!wait_for_delete())
143+
goto fail;
144+
} else if (errno != ENOENT)
145+
goto fail;
146+
}
125147

126148
close(fd);
127149

128150
return 0;
151+
fail:
152+
close(fd);
153+
154+
return -1;
129155
}
130156

131157
static int check_print_fmt(const char *event, const char *expected, int *check)
@@ -155,16 +181,17 @@ static int check_print_fmt(const char *event, const char *expected, int *check)
155181
/* Register should work */
156182
ret = ioctl(fd, DIAG_IOCSREG, &reg);
157183

158-
close(fd);
159-
160184
if (ret != 0) {
185+
close(fd);
161186
printf("Reg failed in fmt\n");
162187
return ret;
163188
}
164189

165190
/* Ensure correct print_fmt */
166191
ret = get_print_fmt(print_fmt, sizeof(print_fmt));
167192

193+
close(fd);
194+
168195
if (ret != 0)
169196
return ret;
170197

@@ -256,10 +283,10 @@ TEST_F(user, register_events) {
256283
unreg.disable_bit = 30;
257284
ASSERT_EQ(0, ioctl(self->data_fd, DIAG_IOCSUNREG, &unreg));
258285

259-
/* Delete should work only after close and unregister */
286+
/* Delete should have been auto-done after close and unregister */
260287
close(self->data_fd);
261-
self->data_fd = open(data_file, O_RDWR);
262-
ASSERT_EQ(0, ioctl(self->data_fd, DIAG_IOCSDEL, "__test_event"));
288+
289+
ASSERT_EQ(true, wait_for_delete());
263290
}
264291

265292
TEST_F(user, write_events) {

0 commit comments

Comments
 (0)