[PATCH 1/2] lib: Add kselftests for async-domains

Chris Wilson chris at chris-wilson.co.uk
Tue May 24 10:30:30 UTC 2016


---
 lib/Kconfig                                 |   7 ++
 lib/Makefile                                |   1 +
 lib/test-async-domain.c                     | 131 ++++++++++++++++++++++++++++
 tools/testing/selftests/lib/Makefile        |   2 +-
 tools/testing/selftests/lib/async-domain.sh |  10 +++
 5 files changed, 150 insertions(+), 1 deletion(-)
 create mode 100644 lib/test-async-domain.c
 create mode 100755 tools/testing/selftests/lib/async-domain.sh

diff --git a/lib/Kconfig b/lib/Kconfig
index 3cca1222578e..2477b91a0edb 100644
--- a/lib/Kconfig
+++ b/lib/Kconfig
@@ -24,6 +24,13 @@ config HAVE_ARCH_BITREVERSE
 config RATIONAL
 	bool
 
+config ASYNC_DOMAIN_SELFTEST
+	tristate "Perform asynchronous domain self tests on init"
+	default n
+	help
+	  This option enables the asynchronous domain library functions
+	  to perform a self test on initialization.
+
 config GENERIC_STRNCPY_FROM_USER
 	bool
 
diff --git a/lib/Makefile b/lib/Makefile
index 7bd6fd436c97..a2f60c03324f 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -28,6 +28,7 @@ lib-y := ctype.o string.o vsprintf.o cmdline.o \
 	 earlycpio.o seq_buf.o nmi_backtrace.o
 
 obj-$(CONFIG_ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS) += usercopy.o
+obj-$(CONFIG_ASYNC_DOMAIN_SELFTEST) += test-async-domain.o
 lib-$(CONFIG_MMU) += ioremap.o
 lib-$(CONFIG_SMP) += cpumask.o
 lib-$(CONFIG_HAS_DMA) += dma-noop.o
diff --git a/lib/test-async-domain.c b/lib/test-async-domain.c
new file mode 100644
index 000000000000..558a71414fb6
--- /dev/null
+++ b/lib/test-async-domain.c
@@ -0,0 +1,131 @@
+/*
+ * Test cases for async-domain facility.
+ */
+
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
+#include <linux/async.h>
+#include <linux/module.h>
+#include <linux/delay.h>
+
+static void task_A(void *data, async_cookie_t cookie)
+{
+	long *result = data;
+	smp_store_mb(*result, 'A');
+}
+
+static void task_B(void *data, async_cookie_t cookie)
+{
+	long *result = data;
+	usleep_range(100, 200);
+	smp_store_mb(*result, 'B');
+}
+
+static int __init test_implicit(struct async_domain *domain)
+{
+	const long expected = 'B';
+	long result = 0;
+
+	if (!async_schedule_domain(task_B, &result, domain))
+		return -ENOMEM;
+
+	async_synchronize_full_domain(domain);
+
+	if (READ_ONCE(result) != expected) {
+		pr_warn("%s expected %c [%ld], got %ld\n",
+			__func__, (char)expected, expected, result);
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+static int __init test_registered(struct async_domain *domain)
+{
+	const long expected = 'B';
+	long result = 0;
+
+	if (!async_schedule_domain(task_B, &result, domain))
+		return -ENOMEM;
+
+	async_synchronize_full();
+
+	if (READ_ONCE(result) != expected) {
+		pr_warn("%s expected %c [%ld], got %ld\n",
+			__func__, (char)expected, expected, result);
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+static void task_nop(void *data, async_cookie_t cookie)
+{
+	async_cookie_t *result = data;
+	smp_store_mb(*result, cookie);
+}
+
+static int __init perf_nop(int batch, long timeout_us)
+{
+	ktime_t start;
+	async_cookie_t nop, last;
+	long count, delay;
+
+	count = 0;
+	nop = last = 0;
+	start = ktime_get();
+	do {
+		ktime_t delta;
+		int n;
+
+		for (n = 0; n < batch; n++)
+			last = async_schedule(task_nop, &nop);
+		async_synchronize_full();
+		delta = ktime_sub(ktime_get(), start);
+		delay = ktime_to_ns(delta) >> 10;
+		count += batch;
+	} while (delay < timeout_us);
+
+	pr_info("%ld nop tasks (batches of %d) completed in %ldus; last queued %lld, saw %lld last\n",
+		count, batch, delay,
+		(long long)last, (long long)READ_ONCE(nop));
+	return 0;
+}
+
+static int __init test_async_domain_init(void)
+{
+	ASYNC_DOMAIN(domain);
+	int ret;
+
+	pr_info("Testing async-domains\n");
+
+	ret = test_implicit(&domain);
+	if (ret)
+		return ret;
+
+	ret = test_registered(&domain);
+	if (ret)
+		return ret;
+
+	ret = perf_nop(1, 100);
+	if (ret)
+		return ret;
+
+	ret = perf_nop(128, 1000);
+	if (ret)
+		return ret;
+
+	async_unregister_domain(&domain);
+	return 0;
+}
+
+static void __exit test_async_domain_cleanup(void)
+{
+	async_synchronize_full();
+}
+
+module_init(test_async_domain_init);
+module_exit(test_async_domain_cleanup);
+
+MODULE_AUTHOR("Intel Corporation");
+MODULE_LICENSE("GPL");
diff --git a/tools/testing/selftests/lib/Makefile b/tools/testing/selftests/lib/Makefile
index 08360060ab14..46a77ac5b4c6 100644
--- a/tools/testing/selftests/lib/Makefile
+++ b/tools/testing/selftests/lib/Makefile
@@ -3,6 +3,6 @@
 # No binaries, but make sure arg-less "make" doesn't trigger "run_tests"
 all:
 
-TEST_PROGS := printf.sh bitmap.sh
+TEST_PROGS := printf.sh bitmap.sh async-domain.sh
 
 include ../lib.mk
diff --git a/tools/testing/selftests/lib/async-domain.sh b/tools/testing/selftests/lib/async-domain.sh
new file mode 100755
index 000000000000..cd10127d56fa
--- /dev/null
+++ b/tools/testing/selftests/lib/async-domain.sh
@@ -0,0 +1,10 @@
+#!/bin/sh
+# Runs infrastructure tests using test-async-timeline kernel module
+
+if /sbin/modprobe -q test-async-domain; then
+	/sbin/modprobe -q -r test-async-domain
+	echo "async-domain: ok"
+else
+	echo "async-domain: [FAIL]"
+	exit 1
+fi
-- 
2.8.1



More information about the Intel-gfx-trybot mailing list