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

TOMOYO Linux Cross Reference
Linux/tools/perf/tests/sdt.c

Version: ~ [ linux-6.11-rc3 ] ~ [ linux-6.10.4 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.45 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.104 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.164 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.223 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.281 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.319 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ 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 // SPDX-License-Identifier: GPL-2.0
  2 #include <errno.h>
  3 #include <limits.h>
  4 #include <stdio.h>
  5 #include <stdlib.h>
  6 #include <unistd.h>
  7 #include <sys/epoll.h>
  8 #include <util/symbol.h>
  9 #include <linux/filter.h>
 10 #include "tests.h"
 11 #include "debug.h"
 12 #include "probe-file.h"
 13 #include "build-id.h"
 14 #include "util.h"
 15 
 16 /* To test SDT event, we need libelf support to scan elf binary */
 17 #if defined(HAVE_SDT_EVENT) && defined(HAVE_LIBELF_SUPPORT)
 18 
 19 #include <sys/sdt.h>
 20 
 21 static int target_function(void)
 22 {
 23         DTRACE_PROBE(perf, test_target);
 24         return TEST_OK;
 25 }
 26 
 27 /* Copied from builtin-buildid-cache.c */
 28 static int build_id_cache__add_file(const char *filename)
 29 {
 30         char sbuild_id[SBUILD_ID_SIZE];
 31         struct build_id bid;
 32         int err;
 33 
 34         err = filename__read_build_id(filename, &bid);
 35         if (err < 0) {
 36                 pr_debug("Failed to read build id of %s\n", filename);
 37                 return err;
 38         }
 39 
 40         build_id__sprintf(&bid, sbuild_id);
 41         err = build_id_cache__add_s(sbuild_id, filename, NULL, false, false);
 42         if (err < 0)
 43                 pr_debug("Failed to add build id cache of %s\n", filename);
 44         return err;
 45 }
 46 
 47 static char *get_self_path(void)
 48 {
 49         char *buf = calloc(PATH_MAX, sizeof(char));
 50 
 51         if (buf && readlink("/proc/self/exe", buf, PATH_MAX - 1) < 0) {
 52                 pr_debug("Failed to get correct path of perf\n");
 53                 free(buf);
 54                 return NULL;
 55         }
 56         return buf;
 57 }
 58 
 59 static int search_cached_probe(const char *target,
 60                                const char *group, const char *event)
 61 {
 62         struct probe_cache *cache = probe_cache__new(target, NULL);
 63         int ret = 0;
 64 
 65         if (!cache) {
 66                 pr_debug("Failed to open probe cache of %s\n", target);
 67                 return -EINVAL;
 68         }
 69 
 70         if (!probe_cache__find_by_name(cache, group, event)) {
 71                 pr_debug("Failed to find %s:%s in the cache\n", group, event);
 72                 ret = -ENOENT;
 73         }
 74         probe_cache__delete(cache);
 75 
 76         return ret;
 77 }
 78 
 79 static int test__sdt_event(struct test_suite *test __maybe_unused, int subtests __maybe_unused)
 80 {
 81         int ret = TEST_FAIL;
 82         char __tempdir[] = "./test-buildid-XXXXXX";
 83         char *tempdir = NULL, *myself = get_self_path();
 84 
 85         if (myself == NULL || mkdtemp(__tempdir) == NULL) {
 86                 pr_debug("Failed to make a tempdir for build-id cache\n");
 87                 goto error;
 88         }
 89         /* Note that buildid_dir must be an absolute path */
 90         tempdir = realpath(__tempdir, NULL);
 91         if (tempdir == NULL)
 92                 goto error_rmdir;
 93 
 94         /* At first, scan itself */
 95         set_buildid_dir(tempdir);
 96         if (build_id_cache__add_file(myself) < 0)
 97                 goto error_rmdir;
 98 
 99         /* Open a cache and make sure the SDT is stored */
100         if (search_cached_probe(myself, "sdt_perf", "test_target") < 0)
101                 goto error_rmdir;
102 
103         /* TBD: probing on the SDT event and collect logs */
104 
105         /* Call the target and get an event */
106         ret = target_function();
107 
108 error_rmdir:
109         /* Cleanup temporary buildid dir */
110         rm_rf(__tempdir);
111 error:
112         free(tempdir);
113         free(myself);
114         return ret;
115 }
116 #else
117 static int test__sdt_event(struct test_suite *test __maybe_unused, int subtests __maybe_unused)
118 {
119         pr_debug("Skip SDT event test because SDT support is not compiled\n");
120         return TEST_SKIP;
121 }
122 #endif
123 
124 DEFINE_SUITE("Probe SDT events", sdt_event);
125 

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

kernel.org | git.kernel.org | LWN.net | Project Home | 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.

sflogo.php