tools build: Add test for setns()
authorArnaldo Carvalho de Melo <acme@redhat.com>
Tue, 18 Jul 2017 20:15:29 +0000 (17:15 -0300)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 19 Jul 2017 02:14:08 +0000 (23:14 -0300)
And provide an alternative implementation to keep perf building on older
distros as we're about to add initial support for namespaces.

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Krister Johansen <kjlx@templeofstupid.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/n/tip-bqdwijunhjlvps1ardykhw1i@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/build/Makefile.feature
tools/build/feature/Makefile
tools/build/feature/test-all.c
tools/build/feature/test-setns.c [new file with mode: 0644]
tools/perf/Makefile.config
tools/perf/util/Build
tools/perf/util/setns.c [new file with mode: 0644]
tools/perf/util/util.h

index 523911f316ce5e65511962f0c13fe0032a06427a..c71a05b9c984f8b38dda2f201caf90ae15fcef52 100644 (file)
@@ -64,7 +64,8 @@ FEATURE_TESTS_BASIC :=                  \
         get_cpuid                       \
         bpf                             \
         sched_getcpu                   \
-        sdt
+        sdt                            \
+        setns
 
 # FEATURE_TESTS_BASIC + FEATURE_TESTS_EXTRA is the complete list
 # of all feature tests
index e35e4e5ad192e6126404b4f5ee52e397e2bb22db..ee2546ddf02831c587ef1d217c69a3d17b140705 100644 (file)
@@ -49,7 +49,8 @@ FILES=                                          \
          test-sdt.bin                           \
          test-cxx.bin                           \
          test-jvmti.bin                                \
-         test-sched_getcpu.bin
+         test-sched_getcpu.bin                 \
+         test-setns.bin
 
 FILES := $(addprefix $(OUTPUT),$(FILES))
 
@@ -95,6 +96,9 @@ $(OUTPUT)test-glibc.bin:
 $(OUTPUT)test-sched_getcpu.bin:
        $(BUILD)
 
+$(OUTPUT)test-setns.bin:
+       $(BUILD)
+
 DWARFLIBS := -ldw
 ifeq ($(findstring -static,${LDFLAGS}),-static)
 DWARFLIBS += -lelf -lebl -lz -llzma -lbz2
index cc6c7c01f4cadd5f8fe28ced947b9c80a2a0515d..b5cfc64457716f0c6eeda10db2d5c1a916f73395 100644 (file)
 # include "test-sdt.c"
 #undef main
 
+#define main main_test_setns
+# include "test-setns.c"
+#undef main
+
 int main(int argc, char *argv[])
 {
        main_test_libpython();
@@ -188,6 +192,7 @@ int main(int argc, char *argv[])
        main_test_libcrypto();
        main_test_sched_getcpu();
        main_test_sdt();
+       main_test_setns();
 
        return 0;
 }
diff --git a/tools/build/feature/test-setns.c b/tools/build/feature/test-setns.c
new file mode 100644 (file)
index 0000000..1f714d2
--- /dev/null
@@ -0,0 +1,7 @@
+#define _GNU_SOURCE
+#include <sched.h>
+
+int main(void)
+{
+       return setns(0, 0);
+}
index bdf0e87f9b2938c33dc94b0541c8a63d1965cb35..37d203c4cd1f7252a7e663db7d6defbd4aeb9fa5 100644 (file)
@@ -330,6 +330,11 @@ ifeq ($(feature-sched_getcpu), 1)
   CFLAGS += -DHAVE_SCHED_GETCPU_SUPPORT
 endif
 
+ifeq ($(feature-setns), 1)
+  CFLAGS += -DHAVE_SETNS_SUPPORT
+  $(call detected,CONFIG_SETNS)
+endif
+
 ifndef NO_LIBELF
   CFLAGS += -DHAVE_LIBELF_SUPPORT
   EXTLIBS += -lelf
index 79dea95a7f688ca9fa9b16346b3fae25af797f5c..7580fe4d5d3006be3e85b8dfb71063c0782f613d 100644 (file)
@@ -104,6 +104,10 @@ ifndef CONFIG_LIBELF
 libperf-y += symbol-minimal.o
 endif
 
+ifndef CONFIG_SETNS
+libperf-y += setns.o
+endif
+
 libperf-$(CONFIG_DWARF) += probe-finder.o
 libperf-$(CONFIG_DWARF) += dwarf-aux.o
 libperf-$(CONFIG_DWARF) += dwarf-regs.o
diff --git a/tools/perf/util/setns.c b/tools/perf/util/setns.c
new file mode 100644 (file)
index 0000000..ce8fc29
--- /dev/null
@@ -0,0 +1,8 @@
+#include "util.h"
+#include <unistd.h>
+#include <sys/syscall.h>
+
+int setns(int fd, int nstype)
+{
+       return syscall(__NR_setns, fd, nstype);
+}
index 2c9e58a45310446eeb5b1af2859b8ef70e2d8089..1e5fe1d9ec32eda4eac6cb007d7e055135f63194 100644 (file)
@@ -58,4 +58,8 @@ const char *perf_tip(const char *dirpath);
 int sched_getcpu(void);
 #endif
 
+#ifndef HAVE_SETNS_SUPPORT
+int setns(int fd, int nstype);
+#endif
+
 #endif /* GIT_COMPAT_UTIL_H */