[v1,11/17] selftests/nolibc: prepare tmpfs and hugetlbfs

Message ID 604d011aab4b7ec3734685ce9f1a163771a2c9d4.1687344643.git.falcon@tinylab.org
State New
Headers
Series selftests/nolibc: allow run with minimal kernel config |

Commit Message

Zhangjin Wu June 21, 2023, 1:07 p.m. UTC
  Let's make the /tmp and /hugetlb directories and mount tmpfs and
hugetlbfs respectively, they will be used to check the existing of tmpfs
and hugetlbfs.

We will also use tmpfs to let some test cases run without procfs.

Signed-off-by: Zhangjin Wu <falcon@tinylab.org>
---
 tools/testing/selftests/nolibc/nolibc-test.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
  

Patch

diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c
index 69f59a395746..8b587961e46a 100644
--- a/tools/testing/selftests/nolibc/nolibc-test.c
+++ b/tools/testing/selftests/nolibc/nolibc-test.c
@@ -935,6 +935,18 @@  int prepare(void)
 		}
 	}
 
+	/* try to mount /tmp if not mounted. Silently fail otherwise */
+	if (stat("/tmp/.", &stat_buf) == 0 || mkdir("/tmp", 0755) == 0) {
+		if (mount("none", "/tmp", "tmpfs", 0, 0) != 0)
+			rmdir("/tmp");
+	}
+
+	/* try to mount /hugetlb if not mounted. Silently fail otherwise */
+	if (stat("/hugetlb/.", &stat_buf) == 0 || mkdir("/hugetlb", 0755) == 0) {
+		if (mount("none", "/hugetlb", "hugetlbfs", 0, 0) != 0)
+			rmdir("/hugetlb");
+	}
+
 	return 0;
 }