ebb_on_child_test.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * Copyright 2014, Michael Ellerman, IBM Corp.
  3. * Licensed under GPLv2.
  4. */
  5. #include <signal.h>
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <stdbool.h>
  9. #include <sys/types.h>
  10. #include <sys/wait.h>
  11. #include <unistd.h>
  12. #include "ebb.h"
  13. /*
  14. * Tests we can setup an EBB on our child. Nothing interesting happens, because
  15. * even though the event is enabled and running the child hasn't enabled the
  16. * actual delivery of the EBBs.
  17. */
  18. static int victim_child(union pipe read_pipe, union pipe write_pipe)
  19. {
  20. int i;
  21. FAIL_IF(wait_for_parent(read_pipe));
  22. FAIL_IF(notify_parent(write_pipe));
  23. /* Parent creates EBB event */
  24. FAIL_IF(wait_for_parent(read_pipe));
  25. FAIL_IF(notify_parent(write_pipe));
  26. /* Check the EBB is enabled by writing PMC1 */
  27. write_pmc1();
  28. /* EBB event is enabled here */
  29. for (i = 0; i < 1000000; i++) ;
  30. return 0;
  31. }
  32. int ebb_on_child(void)
  33. {
  34. union pipe read_pipe, write_pipe;
  35. struct event event;
  36. pid_t pid;
  37. FAIL_IF(pipe(read_pipe.fds) == -1);
  38. FAIL_IF(pipe(write_pipe.fds) == -1);
  39. pid = fork();
  40. if (pid == 0) {
  41. /* NB order of pipes looks reversed */
  42. exit(victim_child(write_pipe, read_pipe));
  43. }
  44. FAIL_IF(sync_with_child(read_pipe, write_pipe));
  45. /* Child is running now */
  46. event_init_named(&event, 0x1001e, "cycles");
  47. event_leader_ebb_init(&event);
  48. event.attr.exclude_kernel = 1;
  49. event.attr.exclude_hv = 1;
  50. event.attr.exclude_idle = 1;
  51. FAIL_IF(event_open_with_pid(&event, pid));
  52. FAIL_IF(ebb_event_enable(&event));
  53. FAIL_IF(sync_with_child(read_pipe, write_pipe));
  54. /* Child should just exit happily */
  55. FAIL_IF(wait_for_child(pid));
  56. event_close(&event);
  57. return 0;
  58. }
  59. int main(void)
  60. {
  61. return test_harness(ebb_on_child, "ebb_on_child");
  62. }