diff mbox series

[liburing,v3,08/10] test: Add nolibc test

Message ID 20220704174858.329326-9-ammar.faizi@intel.com (mailing list archive)
State New
Headers show
Series aarch64 support | expand

Commit Message

Ammar Faizi July 4, 2022, 5:54 p.m. UTC
From: Ammar Faizi <ammarfaizi2@gnuweeb.org>

This test is used to test liburing nolibc functionality. The first use
case is test get_page_size() function, especially for aarch64 which
relies on reading /proc/self/auxv. We don't seem to have a test that
tests that function, so let's do it here.

We may add more nolibc tests in this file in the future.

Signed-off-by: Ammar Faizi <ammarfaizi2@gnuweeb.org>
---
 test/Makefile |  1 +
 test/nolibc.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 61 insertions(+)
 create mode 100644 test/nolibc.c
diff mbox series

Patch

diff --git a/test/Makefile b/test/Makefile
index 9590e1e..45674c3 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -101,6 +101,7 @@  test_srcs := \
 	mkdir.c \
 	msg-ring.c \
 	multicqes_drain.c \
+	nolibc.c \
 	nop-all-sizes.c \
 	nop.c \
 	openat2.c \
diff --git a/test/nolibc.c b/test/nolibc.c
new file mode 100644
index 0000000..e996f40
--- /dev/null
+++ b/test/nolibc.c
@@ -0,0 +1,60 @@ 
+/* SPDX-License-Identifier: MIT */
+/*
+ * Test liburing nolibc functionality.
+ *
+ * Currently, supported architectures are:
+ *   1) x86
+ *   2) x86-64
+ *   3) aarch64
+ *
+ */
+#include "helpers.h"
+
+#if !defined(__x86_64__) && !defined(__i386__) && !defined(__aarch64__)
+
+/*
+ * This arch doesn't support nolibc.
+ */
+int main(void)
+{
+	return T_EXIT_SKIP;
+}
+
+#else /* #if !defined(__x86_64__) && !defined(__i386__) && !defined(__aarch64__) */
+
+#ifndef CONFIG_NOLIBC
+#define CONFIG_NOLIBC
+#endif
+
+#include <stdio.h>
+#include <unistd.h>
+#include "../src/lib.h"
+
+static int test_get_page_size(void)
+{
+	long a, b;
+
+	a = sysconf(_SC_PAGESIZE);
+	b = get_page_size();
+	if (a != b) {
+		fprintf(stderr, "get_page_size() fails, %ld != %ld", a, b);
+		return -1;
+	}
+	return 0;
+}
+
+int main(int argc, char *argv[])
+{
+	int ret;
+
+	if (argc > 1)
+		return T_EXIT_SKIP;
+
+	ret = test_get_page_size();
+	if (ret)
+		return T_EXIT_FAIL;
+
+	return T_EXIT_PASS;
+}
+
+#endif /* #if !defined(__x86_64__) && !defined(__i386__) && !defined(__aarch64__) */