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

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

Version: ~ [ linux-5.15-rc5 ] ~ [ linux-5.14.11 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.72 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.152 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.210 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.250 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.286 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.288 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.18.140 ] ~ [ linux-3.16.85 ] ~ [ linux-3.14.79 ] ~ [ linux-3.12.74 ] ~ [ 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.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

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

~ [ 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