Commit 0d309f04 authored by Beau Belgrave's avatar Beau Belgrave Committed by Steven Rostedt (Google)

tracing/user_events: Update self-tests to write ABI

ABI has been changed to remote writes, update existing test cases to use
this new ABI to ensure existing functionality continues to work.

Link: https://lkml.kernel.org/r/20230328235219.203-7-beaub@linux.microsoft.comSigned-off-by: default avatarBeau Belgrave <beaub@linux.microsoft.com>
Signed-off-by: default avatarSteven Rostedt (Google) <rostedt@goodmis.org>
parent dcb8177c
...@@ -19,7 +19,6 @@ ...@@ -19,7 +19,6 @@
#include "../kselftest_harness.h" #include "../kselftest_harness.h"
const char *data_file = "/sys/kernel/tracing/user_events_data"; const char *data_file = "/sys/kernel/tracing/user_events_data";
const char *status_file = "/sys/kernel/tracing/user_events_status";
const char *id_file = "/sys/kernel/tracing/events/user_events/__test_event/id"; const char *id_file = "/sys/kernel/tracing/events/user_events/__test_event/id";
const char *fmt_file = "/sys/kernel/tracing/events/user_events/__test_event/format"; const char *fmt_file = "/sys/kernel/tracing/events/user_events/__test_event/format";
...@@ -35,11 +34,6 @@ static long perf_event_open(struct perf_event_attr *pe, pid_t pid, ...@@ -35,11 +34,6 @@ static long perf_event_open(struct perf_event_attr *pe, pid_t pid,
return syscall(__NR_perf_event_open, pe, pid, cpu, group_fd, flags); return syscall(__NR_perf_event_open, pe, pid, cpu, group_fd, flags);
} }
static inline int status_check(char *status_page, int status_bit)
{
return status_page[status_bit >> 3] & (1 << (status_bit & 7));
}
static int get_id(void) static int get_id(void)
{ {
FILE *fp = fopen(id_file, "r"); FILE *fp = fopen(id_file, "r");
...@@ -88,45 +82,38 @@ static int get_offset(void) ...@@ -88,45 +82,38 @@ static int get_offset(void)
} }
FIXTURE(user) { FIXTURE(user) {
int status_fd;
int data_fd; int data_fd;
int check;
}; };
FIXTURE_SETUP(user) { FIXTURE_SETUP(user) {
self->status_fd = open(status_file, O_RDONLY);
ASSERT_NE(-1, self->status_fd);
self->data_fd = open(data_file, O_RDWR); self->data_fd = open(data_file, O_RDWR);
ASSERT_NE(-1, self->data_fd); ASSERT_NE(-1, self->data_fd);
} }
FIXTURE_TEARDOWN(user) { FIXTURE_TEARDOWN(user) {
close(self->status_fd);
close(self->data_fd); close(self->data_fd);
} }
TEST_F(user, perf_write) { TEST_F(user, perf_write) {
struct perf_event_attr pe = {0}; struct perf_event_attr pe = {0};
struct user_reg reg = {0}; struct user_reg reg = {0};
int page_size = sysconf(_SC_PAGESIZE);
char *status_page;
struct event event; struct event event;
struct perf_event_mmap_page *perf_page; struct perf_event_mmap_page *perf_page;
int page_size = sysconf(_SC_PAGESIZE);
int id, fd, offset; int id, fd, offset;
__u32 *val; __u32 *val;
reg.size = sizeof(reg); reg.size = sizeof(reg);
reg.name_args = (__u64)"__test_event u32 field1; u32 field2"; reg.name_args = (__u64)"__test_event u32 field1; u32 field2";
reg.enable_bit = 31;
status_page = mmap(NULL, page_size, PROT_READ, MAP_SHARED, reg.enable_addr = (__u64)&self->check;
self->status_fd, 0); reg.enable_size = sizeof(self->check);
ASSERT_NE(MAP_FAILED, status_page);
/* Register should work */ /* Register should work */
ASSERT_EQ(0, ioctl(self->data_fd, DIAG_IOCSREG, &reg)); ASSERT_EQ(0, ioctl(self->data_fd, DIAG_IOCSREG, &reg));
ASSERT_EQ(0, reg.write_index); ASSERT_EQ(0, reg.write_index);
ASSERT_NE(0, reg.status_bit); ASSERT_EQ(0, self->check);
ASSERT_EQ(0, status_check(status_page, reg.status_bit));
/* Id should be there */ /* Id should be there */
id = get_id(); id = get_id();
...@@ -149,7 +136,7 @@ TEST_F(user, perf_write) { ...@@ -149,7 +136,7 @@ TEST_F(user, perf_write) {
ASSERT_NE(MAP_FAILED, perf_page); ASSERT_NE(MAP_FAILED, perf_page);
/* Status should be updated */ /* Status should be updated */
ASSERT_NE(0, status_check(status_page, reg.status_bit)); ASSERT_EQ(1 << reg.enable_bit, self->check);
event.index = reg.write_index; event.index = reg.write_index;
event.field1 = 0xc001; event.field1 = 0xc001;
...@@ -165,6 +152,12 @@ TEST_F(user, perf_write) { ...@@ -165,6 +152,12 @@ TEST_F(user, perf_write) {
/* Ensure correct */ /* Ensure correct */
ASSERT_EQ(event.field1, *val++); ASSERT_EQ(event.field1, *val++);
ASSERT_EQ(event.field2, *val++); ASSERT_EQ(event.field2, *val++);
munmap(perf_page, page_size * 2);
close(fd);
/* Status should be updated */
ASSERT_EQ(0, self->check);
} }
int main(int argc, char **argv) int main(int argc, char **argv)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment