~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/perf/tests/parse-no-sample-id-all.c

Version: ~ [ linux-6.1-rc7 ] ~ [ linux-6.0.10 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.80 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.156 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.225 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.267 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.300 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.334 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.302 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 #include <linux/kernel.h>
  2 #include <linux/types.h>
  3 #include <stddef.h>
  4 
  5 #include "tests.h"
  6 
  7 #include "event.h"
  8 #include "evlist.h"
  9 #include "header.h"
 10 #include "debug.h"
 11 
 12 static int process_event(struct evlist **pevlist, union perf_event *event)
 13 {
 14         struct perf_sample sample;
 15 
 16         if (event->header.type == PERF_RECORD_HEADER_ATTR) {
 17                 if (perf_event__process_attr(NULL, event, pevlist)) {
 18                         pr_debug("perf_event__process_attr failed\n");
 19                         return -1;
 20                 }
 21                 return 0;
 22         }
 23 
 24         if (event->header.type >= PERF_RECORD_USER_TYPE_START)
 25                 return -1;
 26 
 27         if (!*pevlist)
 28                 return -1;
 29 
 30         if (evlist__parse_sample(*pevlist, event, &sample)) {
 31                 pr_debug("evlist__parse_sample failed\n");
 32                 return -1;
 33         }
 34 
 35         return 0;
 36 }
 37 
 38 static int process_events(union perf_event **events, size_t count)
 39 {
 40         struct evlist *evlist = NULL;
 41         int err = 0;
 42         size_t i;
 43 
 44         for (i = 0; i < count && !err; i++)
 45                 err = process_event(&evlist, events[i]);
 46 
 47         evlist__delete(evlist);
 48 
 49         return err;
 50 }
 51 
 52 struct test_attr_event {
 53         struct perf_event_header header;
 54         struct perf_event_attr   attr;
 55         u64 id;
 56 };
 57 
 58 /**
 59  * test__parse_no_sample_id_all - test parsing with no sample_id_all bit set.
 60  *
 61  * This function tests parsing data produced on kernel's that do not support the
 62  * sample_id_all bit.  Without the sample_id_all bit, non-sample events (such as
 63  * mmap events) do not have an id sample appended, and consequently logic
 64  * designed to determine the id will not work.  That case happens when there is
 65  * more than one selected event, so this test processes three events: 2
 66  * attributes representing the selected events and one mmap event.
 67  *
 68  * Return: %0 on success, %-1 if the test fails.
 69  */
 70 static int test__parse_no_sample_id_all(struct test_suite *test __maybe_unused,
 71                                         int subtest __maybe_unused)
 72 {
 73         int err;
 74 
 75         struct test_attr_event event1 = {
 76                 .header = {
 77                         .type = PERF_RECORD_HEADER_ATTR,
 78                         .size = sizeof(struct test_attr_event),
 79                 },
 80                 .id = 1,
 81         };
 82         struct test_attr_event event2 = {
 83                 .header = {
 84                         .type = PERF_RECORD_HEADER_ATTR,
 85                         .size = sizeof(struct test_attr_event),
 86                 },
 87                 .id = 2,
 88         };
 89         struct perf_record_mmap event3 = {
 90                 .header = {
 91                         .type = PERF_RECORD_MMAP,
 92                         .size = sizeof(struct perf_record_mmap),
 93                 },
 94         };
 95         union perf_event *events[] = {
 96                 (union perf_event *)&event1,
 97                 (union perf_event *)&event2,
 98                 (union perf_event *)&event3,
 99         };
100 
101         err = process_events(events, ARRAY_SIZE(events));
102         if (err)
103                 return -1;
104 
105         return 0;
106 }
107 
108 DEFINE_SUITE("Parse with no sample_id_all bit set", parse_no_sample_id_all);
109 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp