linux/tools/testing/selftests/powerpc/pmu/ebb/task_event_vs_ebb_test.c
<<
>>
Prefs
   1/*
   2 * Copyright 2014, Michael Ellerman, IBM Corp.
   3 * Licensed under GPLv2.
   4 */
   5
   6#include <signal.h>
   7#include <stdio.h>
   8#include <stdlib.h>
   9#include <stdbool.h>
  10#include <sys/types.h>
  11#include <sys/wait.h>
  12#include <unistd.h>
  13
  14#include "ebb.h"
  15
  16
  17/*
  18 * Tests a per-task event vs an EBB - in that order. The EBB should push the
  19 * per-task event off the PMU.
  20 */
  21
  22static int setup_child_event(struct event *event, pid_t child_pid)
  23{
  24        event_init_named(event, 0x400FA, "PM_RUN_INST_CMPL");
  25
  26        event->attr.exclude_kernel = 1;
  27        event->attr.exclude_hv = 1;
  28        event->attr.exclude_idle = 1;
  29
  30        FAIL_IF(event_open_with_pid(event, child_pid));
  31        FAIL_IF(event_enable(event));
  32
  33        return 0;
  34}
  35
  36int task_event_vs_ebb(void)
  37{
  38        union pipe read_pipe, write_pipe;
  39        struct event event;
  40        pid_t pid;
  41        int rc;
  42
  43        FAIL_IF(pipe(read_pipe.fds) == -1);
  44        FAIL_IF(pipe(write_pipe.fds) == -1);
  45
  46        pid = fork();
  47        if (pid == 0) {
  48                /* NB order of pipes looks reversed */
  49                exit(ebb_child(write_pipe, read_pipe));
  50        }
  51
  52        /* We setup the task event first */
  53        rc = setup_child_event(&event, pid);
  54        if (rc) {
  55                kill_child_and_wait(pid);
  56                return rc;
  57        }
  58
  59        /* Signal the child to install its EBB event and wait */
  60        if (sync_with_child(read_pipe, write_pipe))
  61                /* If it fails, wait for it to exit */
  62                goto wait;
  63
  64        /* Signal the child to run */
  65        FAIL_IF(sync_with_child(read_pipe, write_pipe));
  66
  67wait:
  68        /* The EBB event should push the task event off so the child should succeed */
  69        FAIL_IF(wait_for_child(pid));
  70        FAIL_IF(event_disable(&event));
  71        FAIL_IF(event_read(&event));
  72
  73        event_report(&event);
  74
  75        /* The task event may have run, or not so we can't assert anything about it */
  76
  77        return 0;
  78}
  79
  80int main(void)
  81{
  82        return test_harness(task_event_vs_ebb, "task_event_vs_ebb");
  83}
  84