Ensure test cases work as non-root always

We have a few where we try to use SQTHREAD, which will fail if the
effective user isn't root. Just skip these tests if we're not root.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
diff --git a/test/accept.c b/test/accept.c
index 501af58..65f275c 100644
--- a/test/accept.c
+++ b/test/accept.c
@@ -209,7 +209,13 @@
 	struct io_uring m_io_uring;
 	int ret;
 
-	assert(io_uring_queue_init(32, &m_io_uring, IORING_SETUP_SQPOLL) >= 0);
+	ret = io_uring_queue_init(32, &m_io_uring, IORING_SETUP_SQPOLL);
+	if (ret && geteuid()) {
+		printf("%s: skipped, not root\n", __FUNCTION__);
+		return 0;
+	} else if (ret)
+		return ret;
+
 	ret = test(&m_io_uring, 1);
 	io_uring_queue_exit(&m_io_uring);
 	return ret;
diff --git a/test/defer.c b/test/defer.c
index 1f1b3aa..9298112 100644
--- a/test/defer.c
+++ b/test/defer.c
@@ -209,7 +209,7 @@
 {
 	struct io_uring ring, poll_ring, sqthread_ring;
 	struct io_uring_params p;
-	int ret;
+	int ret, no_sqthread = 0;
 
 	memset(&p, 0, sizeof(p));
 	ret = io_uring_queue_init_params(1000, &ring, &p);
@@ -227,8 +227,12 @@
 	ret = io_uring_queue_init(1000, &sqthread_ring,
 				IORING_SETUP_SQPOLL | IORING_SETUP_IOPOLL);
 	if (ret) {
-		printf("poll_ring setup failed\n");
-		return 1;
+		if (geteuid()) {
+			no_sqthread = 1;
+		} else {
+			printf("poll_ring setup failed\n");
+			return 1;
+		}
 	}
 
 	ret = test_cancelled_userdata(&poll_ring);
@@ -237,10 +241,14 @@
 		return ret;
 	}
 
-	ret = test_thread_link_cancel(&sqthread_ring);
-	if (ret) {
-		printf("test_thread_link_cancel failed\n");
-		return ret;
+	if (no_sqthread) {
+		printf("test_thread_link_cancel: skipped, not root\n");
+	} else {
+		ret = test_thread_link_cancel(&sqthread_ring);
+		if (ret) {
+			printf("test_thread_link_cancel failed\n");
+			return ret;
+		}
 	}
 
 	if (!(p.features & IORING_FEAT_NODROP)) {