0001
0002
0003
0004
0005
0006 #include <signal.h>
0007 #include <stdio.h>
0008 #include <stdlib.h>
0009 #include <stdbool.h>
0010 #include <sys/types.h>
0011 #include <sys/wait.h>
0012 #include <unistd.h>
0013
0014 #include "ebb.h"
0015
0016
0017
0018
0019
0020
0021
0022 static int setup_cpu_event(struct event *event, int cpu)
0023 {
0024 event_init_named(event, 0x400FA, "PM_RUN_INST_CMPL");
0025
0026 event->attr.exclude_kernel = 1;
0027 event->attr.exclude_hv = 1;
0028 event->attr.exclude_idle = 1;
0029
0030 SKIP_IF(require_paranoia_below(1));
0031 FAIL_IF(event_open_with_cpu(event, cpu));
0032 FAIL_IF(event_enable(event));
0033
0034 return 0;
0035 }
0036
0037 int ebb_vs_cpu_event(void)
0038 {
0039 union pipe read_pipe, write_pipe;
0040 struct event event;
0041 int cpu, rc;
0042 pid_t pid;
0043
0044 SKIP_IF(!ebb_is_supported());
0045
0046 cpu = pick_online_cpu();
0047 FAIL_IF(cpu < 0);
0048 FAIL_IF(bind_to_cpu(cpu));
0049
0050 FAIL_IF(pipe(read_pipe.fds) == -1);
0051 FAIL_IF(pipe(write_pipe.fds) == -1);
0052
0053 pid = fork();
0054 if (pid == 0) {
0055
0056 exit(ebb_child(write_pipe, read_pipe));
0057 }
0058
0059
0060 FAIL_IF(sync_with_child(read_pipe, write_pipe));
0061
0062
0063 rc = setup_cpu_event(&event, cpu);
0064 if (rc) {
0065 kill_child_and_wait(pid);
0066 return rc;
0067 }
0068
0069
0070 FAIL_IF(sync_with_child(read_pipe, write_pipe));
0071
0072
0073 FAIL_IF(wait_for_child(pid));
0074 FAIL_IF(event_disable(&event));
0075 FAIL_IF(event_read(&event));
0076
0077 event_report(&event);
0078
0079
0080 FAIL_IF(event.result.enabled >= event.result.running);
0081
0082 return 0;
0083 }
0084
0085 int main(void)
0086 {
0087 return test_harness(ebb_vs_cpu_event, "ebb_vs_cpu_event");
0088 }