aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tools/testing/selftests/Makefile11
-rw-r--r--tools/testing/selftests/android/ion/.gitignore1
-rw-r--r--tools/testing/selftests/android/ion/Makefile5
-rw-r--r--tools/testing/selftests/android/ion/config1
-rw-r--r--tools/testing/selftests/android/ion/ionmap_test.c136
-rw-r--r--tools/testing/selftests/android/ion/ionutils.c6
-rw-r--r--tools/testing/selftests/futex/Makefile4
-rw-r--r--tools/testing/selftests/intel_pstate/Makefile5
-rw-r--r--tools/testing/selftests/kselftest.h3
-rw-r--r--tools/testing/selftests/kselftest_harness.h26
-rw-r--r--tools/testing/selftests/lib.mk1
-rw-r--r--tools/testing/selftests/seccomp/seccomp_bpf.c15
12 files changed, 200 insertions, 14 deletions
diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile
index dbda89c9d9b9..bae6a4e9f2ee 100644
--- a/tools/testing/selftests/Makefile
+++ b/tools/testing/selftests/Makefile
@@ -67,6 +67,12 @@ ifndef BUILD
67 BUILD := $(shell pwd) 67 BUILD := $(shell pwd)
68endif 68endif
69 69
70# KSFT_TAP_LEVEL is used from KSFT framework to prevent nested TAP header
71# printing from tests. Applicable to run_tests case where run_tests adds
72# TAP header prior running tests and when a test program invokes another
73# with system() call. Export it here to cover override RUN_TESTS defines.
74export KSFT_TAP_LEVEL=`echo 1`
75
70export BUILD 76export BUILD
71all: 77all:
72 @for TARGET in $(TARGETS); do \ 78 @for TARGET in $(TARGETS); do \
@@ -126,11 +132,14 @@ ifdef INSTALL_PATH
126 echo "else" >> $(ALL_SCRIPT) 132 echo "else" >> $(ALL_SCRIPT)
127 echo " OUTPUT=/dev/stdout" >> $(ALL_SCRIPT) 133 echo " OUTPUT=/dev/stdout" >> $(ALL_SCRIPT)
128 echo "fi" >> $(ALL_SCRIPT) 134 echo "fi" >> $(ALL_SCRIPT)
135 echo "export KSFT_TAP_LEVEL=`echo 1`" >> $(ALL_SCRIPT)
129 136
130 for TARGET in $(TARGETS); do \ 137 for TARGET in $(TARGETS); do \
131 BUILD_TARGET=$$BUILD/$$TARGET; \ 138 BUILD_TARGET=$$BUILD/$$TARGET; \
132 echo "echo ; echo Running tests in $$TARGET" >> $(ALL_SCRIPT); \ 139 echo "echo ; echo TAP version 13" >> $(ALL_SCRIPT); \
140 echo "echo Running tests in $$TARGET" >> $(ALL_SCRIPT); \
133 echo "echo ========================================" >> $(ALL_SCRIPT); \ 141 echo "echo ========================================" >> $(ALL_SCRIPT); \
142 echo "[ -w /dev/kmsg ] && echo \"kselftest: Running tests in $$TARGET\" >> /dev/kmsg" >> $(ALL_SCRIPT); \
134 echo "cd $$TARGET" >> $(ALL_SCRIPT); \ 143 echo "cd $$TARGET" >> $(ALL_SCRIPT); \
135 make -s --no-print-directory OUTPUT=$$BUILD_TARGET -C $$TARGET emit_tests >> $(ALL_SCRIPT); \ 144 make -s --no-print-directory OUTPUT=$$BUILD_TARGET -C $$TARGET emit_tests >> $(ALL_SCRIPT); \
136 echo "cd \$$ROOT" >> $(ALL_SCRIPT); \ 145 echo "cd \$$ROOT" >> $(ALL_SCRIPT); \
diff --git a/tools/testing/selftests/android/ion/.gitignore b/tools/testing/selftests/android/ion/.gitignore
index 67e6f391b2a9..95e8f4561474 100644
--- a/tools/testing/selftests/android/ion/.gitignore
+++ b/tools/testing/selftests/android/ion/.gitignore
@@ -1,2 +1,3 @@
1ionapp_export 1ionapp_export
2ionapp_import 2ionapp_import
3ionmap_test
diff --git a/tools/testing/selftests/android/ion/Makefile b/tools/testing/selftests/android/ion/Makefile
index 96e0c448b39d..e03695287f76 100644
--- a/tools/testing/selftests/android/ion/Makefile
+++ b/tools/testing/selftests/android/ion/Makefile
@@ -1,8 +1,8 @@
1 1
2INCLUDEDIR := -I. -I../../../../../drivers/staging/android/uapi/ 2INCLUDEDIR := -I. -I../../../../../drivers/staging/android/uapi/ -I../../../../../usr/include/
3CFLAGS := $(CFLAGS) $(INCLUDEDIR) -Wall -O2 -g 3CFLAGS := $(CFLAGS) $(INCLUDEDIR) -Wall -O2 -g
4 4
5TEST_GEN_FILES := ionapp_export ionapp_import 5TEST_GEN_FILES := ionapp_export ionapp_import ionmap_test
6 6
7all: $(TEST_GEN_FILES) 7all: $(TEST_GEN_FILES)
8 8
@@ -14,3 +14,4 @@ include ../../lib.mk
14 14
15$(OUTPUT)/ionapp_export: ionapp_export.c ipcsocket.c ionutils.c 15$(OUTPUT)/ionapp_export: ionapp_export.c ipcsocket.c ionutils.c
16$(OUTPUT)/ionapp_import: ionapp_import.c ipcsocket.c ionutils.c 16$(OUTPUT)/ionapp_import: ionapp_import.c ipcsocket.c ionutils.c
17$(OUTPUT)/ionmap_test: ionmap_test.c ionutils.c
diff --git a/tools/testing/selftests/android/ion/config b/tools/testing/selftests/android/ion/config
index 19db6ca9aa2b..b4ad748a9dd9 100644
--- a/tools/testing/selftests/android/ion/config
+++ b/tools/testing/selftests/android/ion/config
@@ -2,3 +2,4 @@ CONFIG_ANDROID=y
2CONFIG_STAGING=y 2CONFIG_STAGING=y
3CONFIG_ION=y 3CONFIG_ION=y
4CONFIG_ION_SYSTEM_HEAP=y 4CONFIG_ION_SYSTEM_HEAP=y
5CONFIG_DRM_VGEM=y
diff --git a/tools/testing/selftests/android/ion/ionmap_test.c b/tools/testing/selftests/android/ion/ionmap_test.c
new file mode 100644
index 000000000000..dab36b06b37d
--- /dev/null
+++ b/tools/testing/selftests/android/ion/ionmap_test.c
@@ -0,0 +1,136 @@
1#include <errno.h>
2#include <fcntl.h>
3#include <stdio.h>
4#include <stdint.h>
5#include <string.h>
6#include <unistd.h>
7
8#include <sys/ioctl.h>
9#include <sys/types.h>
10#include <sys/stat.h>
11
12#include <linux/dma-buf.h>
13
14#include <drm/drm.h>
15
16#include "ion.h"
17#include "ionutils.h"
18
19int check_vgem(int fd)
20{
21 drm_version_t version = { 0 };
22 char name[5];
23 int ret;
24
25 version.name_len = 4;
26 version.name = name;
27
28 ret = ioctl(fd, DRM_IOCTL_VERSION, &version);
29 if (ret)
30 return 1;
31
32 return strcmp(name, "vgem");
33}
34
35int open_vgem(void)
36{
37 int i, fd;
38 const char *drmstr = "/dev/dri/card";
39
40 fd = -1;
41 for (i = 0; i < 16; i++) {
42 char name[80];
43
44 sprintf(name, "%s%u", drmstr, i);
45
46 fd = open(name, O_RDWR);
47 if (fd < 0)
48 continue;
49
50 if (check_vgem(fd)) {
51 close(fd);
52 continue;
53 } else {
54 break;
55 }
56
57 }
58 return fd;
59}
60
61int import_vgem_fd(int vgem_fd, int dma_buf_fd, uint32_t *handle)
62{
63 struct drm_prime_handle import_handle = { 0 };
64 int ret;
65
66 import_handle.fd = dma_buf_fd;
67 import_handle.flags = 0;
68 import_handle.handle = 0;
69
70 ret = ioctl(vgem_fd, DRM_IOCTL_PRIME_FD_TO_HANDLE, &import_handle);
71 if (ret == 0)
72 *handle = import_handle.handle;
73 return ret;
74}
75
76void close_handle(int vgem_fd, uint32_t handle)
77{
78 struct drm_gem_close close = { 0 };
79
80 close.handle = handle;
81 ioctl(vgem_fd, DRM_IOCTL_GEM_CLOSE, &close);
82}
83
84int main()
85{
86 int ret, vgem_fd;
87 struct ion_buffer_info info;
88 uint32_t handle = 0;
89 struct dma_buf_sync sync = { 0 };
90
91 info.heap_type = ION_HEAP_TYPE_SYSTEM;
92 info.heap_size = 4096;
93 info.flag_type = ION_FLAG_CACHED;
94
95 ret = ion_export_buffer_fd(&info);
96 if (ret < 0) {
97 printf("ion buffer alloc failed\n");
98 return -1;
99 }
100
101 vgem_fd = open_vgem();
102 if (vgem_fd < 0) {
103 ret = vgem_fd;
104 printf("Failed to open vgem\n");
105 goto out_ion;
106 }
107
108 ret = import_vgem_fd(vgem_fd, info.buffd, &handle);
109
110 if (ret < 0) {
111 printf("Failed to import buffer\n");
112 goto out_vgem;
113 }
114
115 sync.flags = DMA_BUF_SYNC_START | DMA_BUF_SYNC_RW;
116 ret = ioctl(info.buffd, DMA_BUF_IOCTL_SYNC, &sync);
117 if (ret)
118 printf("sync start failed %d\n", errno);
119
120 memset(info.buffer, 0xff, 4096);
121
122 sync.flags = DMA_BUF_SYNC_END | DMA_BUF_SYNC_RW;
123 ret = ioctl(info.buffd, DMA_BUF_IOCTL_SYNC, &sync);
124 if (ret)
125 printf("sync end failed %d\n", errno);
126
127 close_handle(vgem_fd, handle);
128 ret = 0;
129
130out_vgem:
131 close(vgem_fd);
132out_ion:
133 ion_close_buffer_fd(&info);
134 printf("done.\n");
135 return ret;
136}
diff --git a/tools/testing/selftests/android/ion/ionutils.c b/tools/testing/selftests/android/ion/ionutils.c
index ce69c14f51fa..7d1d37c4ef6a 100644
--- a/tools/testing/selftests/android/ion/ionutils.c
+++ b/tools/testing/selftests/android/ion/ionutils.c
@@ -80,11 +80,6 @@ int ion_export_buffer_fd(struct ion_buffer_info *ion_info)
80 heap_id = MAX_HEAP_COUNT + 1; 80 heap_id = MAX_HEAP_COUNT + 1;
81 for (i = 0; i < query.cnt; i++) { 81 for (i = 0; i < query.cnt; i++) {
82 if (heap_data[i].type == ion_info->heap_type) { 82 if (heap_data[i].type == ion_info->heap_type) {
83 printf("--------------------------------------\n");
84 printf("heap type: %d\n", heap_data[i].type);
85 printf(" heap id: %d\n", heap_data[i].heap_id);
86 printf("heap name: %s\n", heap_data[i].name);
87 printf("--------------------------------------\n");
88 heap_id = heap_data[i].heap_id; 83 heap_id = heap_data[i].heap_id;
89 break; 84 break;
90 } 85 }
@@ -204,7 +199,6 @@ void ion_close_buffer_fd(struct ion_buffer_info *ion_info)
204 /* Finally, close the client fd */ 199 /* Finally, close the client fd */
205 if (ion_info->ionfd > 0) 200 if (ion_info->ionfd > 0)
206 close(ion_info->ionfd); 201 close(ion_info->ionfd);
207 printf("<%s>: buffer release successfully....\n", __func__);
208 } 202 }
209} 203}
210 204
diff --git a/tools/testing/selftests/futex/Makefile b/tools/testing/selftests/futex/Makefile
index a63e8453984d..8497a376ef9d 100644
--- a/tools/testing/selftests/futex/Makefile
+++ b/tools/testing/selftests/futex/Makefile
@@ -18,6 +18,10 @@ all:
18 done 18 done
19 19
20override define RUN_TESTS 20override define RUN_TESTS
21 @export KSFT_TAP_LEVEL=`echo 1`;
22 @echo "TAP version 13";
23 @echo "selftests: futex";
24 @echo "========================================";
21 @cd $(OUTPUT); ./run.sh 25 @cd $(OUTPUT); ./run.sh
22endef 26endef
23 27
diff --git a/tools/testing/selftests/intel_pstate/Makefile b/tools/testing/selftests/intel_pstate/Makefile
index 5a3f7d37e912..7340fd6a9a9f 100644
--- a/tools/testing/selftests/intel_pstate/Makefile
+++ b/tools/testing/selftests/intel_pstate/Makefile
@@ -2,7 +2,10 @@
2CFLAGS := $(CFLAGS) -Wall -D_GNU_SOURCE 2CFLAGS := $(CFLAGS) -Wall -D_GNU_SOURCE
3LDLIBS := $(LDLIBS) -lm 3LDLIBS := $(LDLIBS) -lm
4 4
5ifeq (,$(filter $(ARCH),x86)) 5uname_M := $(shell uname -m 2>/dev/null || echo not)
6ARCH ?= $(shell echo $(uname_M) | sed -e s/i.86/x86/ -e s/x86_64/x86/)
7
8ifeq (x86,$(ARCH))
6TEST_GEN_FILES := msr aperf 9TEST_GEN_FILES := msr aperf
7endif 10endif
8 11
diff --git a/tools/testing/selftests/kselftest.h b/tools/testing/selftests/kselftest.h
index 1a52b03962a3..1b9d8ecdebce 100644
--- a/tools/testing/selftests/kselftest.h
+++ b/tools/testing/selftests/kselftest.h
@@ -57,7 +57,8 @@ static inline int ksft_get_error_cnt(void) { return ksft_cnt.ksft_error; }
57 57
58static inline void ksft_print_header(void) 58static inline void ksft_print_header(void)
59{ 59{
60 printf("TAP version 13\n"); 60 if (!(getenv("KSFT_TAP_LEVEL")))
61 printf("TAP version 13\n");
61} 62}
62 63
63static inline void ksft_print_cnts(void) 64static inline void ksft_print_cnts(void)
diff --git a/tools/testing/selftests/kselftest_harness.h b/tools/testing/selftests/kselftest_harness.h
index e81bd28bdd89..6ae3730c4ee3 100644
--- a/tools/testing/selftests/kselftest_harness.h
+++ b/tools/testing/selftests/kselftest_harness.h
@@ -107,6 +107,27 @@
107 __FILE__, __LINE__, _metadata->name, ##__VA_ARGS__) 107 __FILE__, __LINE__, _metadata->name, ##__VA_ARGS__)
108 108
109/** 109/**
110 * XFAIL(statement, fmt, ...)
111 *
112 * @statement: statement to run after reporting XFAIL
113 * @fmt: format string
114 * @...: optional arguments
115 *
116 * This forces a "pass" after reporting a failure with an XFAIL prefix,
117 * and runs "statement", which is usually "return" or "goto skip".
118 */
119#define XFAIL(statement, fmt, ...) do { \
120 if (TH_LOG_ENABLED) { \
121 fprintf(TH_LOG_STREAM, "[ XFAIL! ] " fmt "\n", \
122 ##__VA_ARGS__); \
123 } \
124 /* TODO: find a way to pass xfail to test runner process. */ \
125 _metadata->passed = 1; \
126 _metadata->trigger = 0; \
127 statement; \
128} while (0)
129
130/**
110 * TEST(test_name) - Defines the test function and creates the registration 131 * TEST(test_name) - Defines the test function and creates the registration
111 * stub 132 * stub
112 * 133 *
@@ -198,7 +219,7 @@
198 219
199/** 220/**
200 * FIXTURE_SETUP(fixture_name) - Prepares the setup function for the fixture. 221 * FIXTURE_SETUP(fixture_name) - Prepares the setup function for the fixture.
201 * *_metadata* is included so that ASSERT_* work as a convenience 222 * *_metadata* is included so that EXPECT_* and ASSERT_* work correctly.
202 * 223 *
203 * @fixture_name: fixture name 224 * @fixture_name: fixture name
204 * 225 *
@@ -221,6 +242,7 @@
221 FIXTURE_DATA(fixture_name) __attribute__((unused)) *self) 242 FIXTURE_DATA(fixture_name) __attribute__((unused)) *self)
222/** 243/**
223 * FIXTURE_TEARDOWN(fixture_name) 244 * FIXTURE_TEARDOWN(fixture_name)
245 * *_metadata* is included so that EXPECT_* and ASSERT_* work correctly.
224 * 246 *
225 * @fixture_name: fixture name 247 * @fixture_name: fixture name
226 * 248 *
@@ -253,6 +275,8 @@
253 * Defines a test that depends on a fixture (e.g., is part of a test case). 275 * Defines a test that depends on a fixture (e.g., is part of a test case).
254 * Very similar to TEST() except that *self* is the setup instance of fixture's 276 * Very similar to TEST() except that *self* is the setup instance of fixture's
255 * datatype exposed for use by the implementation. 277 * datatype exposed for use by the implementation.
278 *
279 * Warning: use of ASSERT_* here will skip TEARDOWN.
256 */ 280 */
257/* TODO(wad) register fixtures on dedicated test lists. */ 281/* TODO(wad) register fixtures on dedicated test lists. */
258#define TEST_F(fixture_name, test_name) \ 282#define TEST_F(fixture_name, test_name) \
diff --git a/tools/testing/selftests/lib.mk b/tools/testing/selftests/lib.mk
index 7de482a0519d..195e9d4739a9 100644
--- a/tools/testing/selftests/lib.mk
+++ b/tools/testing/selftests/lib.mk
@@ -20,6 +20,7 @@ all: $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES)
20 20
21.ONESHELL: 21.ONESHELL:
22define RUN_TESTS 22define RUN_TESTS
23 @export KSFT_TAP_LEVEL=`echo 1`;
23 @test_num=`echo 0`; 24 @test_num=`echo 0`;
24 @echo "TAP version 13"; 25 @echo "TAP version 13";
25 @for TEST in $(1); do \ 26 @for TEST in $(1); do \
diff --git a/tools/testing/selftests/seccomp/seccomp_bpf.c b/tools/testing/selftests/seccomp/seccomp_bpf.c
index 5df609950a66..168c66d74fc5 100644
--- a/tools/testing/selftests/seccomp/seccomp_bpf.c
+++ b/tools/testing/selftests/seccomp/seccomp_bpf.c
@@ -2860,6 +2860,7 @@ TEST(get_metadata)
2860 int pipefd[2]; 2860 int pipefd[2];
2861 char buf; 2861 char buf;
2862 struct seccomp_metadata md; 2862 struct seccomp_metadata md;
2863 long ret;
2863 2864
2864 ASSERT_EQ(0, pipe(pipefd)); 2865 ASSERT_EQ(0, pipe(pipefd));
2865 2866
@@ -2893,16 +2894,26 @@ TEST(get_metadata)
2893 ASSERT_EQ(0, ptrace(PTRACE_ATTACH, pid)); 2894 ASSERT_EQ(0, ptrace(PTRACE_ATTACH, pid));
2894 ASSERT_EQ(pid, waitpid(pid, NULL, 0)); 2895 ASSERT_EQ(pid, waitpid(pid, NULL, 0));
2895 2896
2897 /* Past here must not use ASSERT or child process is never killed. */
2898
2896 md.filter_off = 0; 2899 md.filter_off = 0;
2897 ASSERT_EQ(sizeof(md), ptrace(PTRACE_SECCOMP_GET_METADATA, pid, sizeof(md), &md)); 2900 errno = 0;
2901 ret = ptrace(PTRACE_SECCOMP_GET_METADATA, pid, sizeof(md), &md);
2902 EXPECT_EQ(sizeof(md), ret) {
2903 if (errno == EINVAL)
2904 XFAIL(goto skip, "Kernel does not support PTRACE_SECCOMP_GET_METADATA (missing CONFIG_CHECKPOINT_RESTORE?)");
2905 }
2906
2898 EXPECT_EQ(md.flags, SECCOMP_FILTER_FLAG_LOG); 2907 EXPECT_EQ(md.flags, SECCOMP_FILTER_FLAG_LOG);
2899 EXPECT_EQ(md.filter_off, 0); 2908 EXPECT_EQ(md.filter_off, 0);
2900 2909
2901 md.filter_off = 1; 2910 md.filter_off = 1;
2902 ASSERT_EQ(sizeof(md), ptrace(PTRACE_SECCOMP_GET_METADATA, pid, sizeof(md), &md)); 2911 ret = ptrace(PTRACE_SECCOMP_GET_METADATA, pid, sizeof(md), &md);
2912 EXPECT_EQ(sizeof(md), ret);
2903 EXPECT_EQ(md.flags, 0); 2913 EXPECT_EQ(md.flags, 0);
2904 EXPECT_EQ(md.filter_off, 1); 2914 EXPECT_EQ(md.filter_off, 1);
2905 2915
2916skip:
2906 ASSERT_EQ(0, kill(pid, SIGKILL)); 2917 ASSERT_EQ(0, kill(pid, SIGKILL));
2907} 2918}
2908 2919