evsel-tp-sched.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #include <linux/err.h>
  2. #include <traceevent/event-parse.h>
  3. #include "evsel.h"
  4. #include "tests.h"
  5. #include "debug.h"
  6. static int perf_evsel__test_field(struct perf_evsel *evsel, const char *name,
  7. int size, bool should_be_signed)
  8. {
  9. struct format_field *field = perf_evsel__field(evsel, name);
  10. int is_signed;
  11. int ret = 0;
  12. if (field == NULL) {
  13. pr_debug("%s: \"%s\" field not found!\n", evsel->name, name);
  14. return -1;
  15. }
  16. is_signed = !!(field->flags & FIELD_IS_SIGNED);
  17. if (should_be_signed && !is_signed) {
  18. pr_debug("%s: \"%s\" signedness(%d) is wrong, should be %d\n",
  19. evsel->name, name, is_signed, should_be_signed);
  20. ret = -1;
  21. }
  22. if (field->size != size) {
  23. pr_debug("%s: \"%s\" size (%d) should be %d!\n",
  24. evsel->name, name, field->size, size);
  25. ret = -1;
  26. }
  27. return ret;
  28. }
  29. int test__perf_evsel__tp_sched_test(void)
  30. {
  31. struct perf_evsel *evsel = perf_evsel__newtp("sched", "sched_switch");
  32. int ret = 0;
  33. if (IS_ERR(evsel)) {
  34. pr_debug("perf_evsel__newtp failed with %ld\n", PTR_ERR(evsel));
  35. return -1;
  36. }
  37. if (perf_evsel__test_field(evsel, "prev_comm", 16, false))
  38. ret = -1;
  39. if (perf_evsel__test_field(evsel, "prev_pid", 4, true))
  40. ret = -1;
  41. if (perf_evsel__test_field(evsel, "prev_prio", 4, true))
  42. ret = -1;
  43. if (perf_evsel__test_field(evsel, "prev_state", sizeof(long), true))
  44. ret = -1;
  45. if (perf_evsel__test_field(evsel, "next_comm", 16, false))
  46. ret = -1;
  47. if (perf_evsel__test_field(evsel, "next_pid", 4, true))
  48. ret = -1;
  49. if (perf_evsel__test_field(evsel, "next_prio", 4, true))
  50. ret = -1;
  51. perf_evsel__delete(evsel);
  52. evsel = perf_evsel__newtp("sched", "sched_wakeup");
  53. if (IS_ERR(evsel)) {
  54. pr_debug("perf_evsel__newtp failed with %ld\n", PTR_ERR(evsel));
  55. return -1;
  56. }
  57. if (perf_evsel__test_field(evsel, "comm", 16, false))
  58. ret = -1;
  59. if (perf_evsel__test_field(evsel, "pid", 4, true))
  60. ret = -1;
  61. if (perf_evsel__test_field(evsel, "prio", 4, true))
  62. ret = -1;
  63. if (perf_evsel__test_field(evsel, "target_cpu", 4, true))
  64. ret = -1;
  65. perf_evsel__delete(evsel);
  66. return ret;
  67. }