From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f45.google.com (mail-pj1-f45.google.com [209.85.216.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1C28D38F248 for ; Thu, 7 May 2026 09:04:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.45 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778144660; cv=none; b=Jw9uy7Fn7HU+GuLAXX1aAq1I3rtS1YRh4chTui8PFRnYXjmHCNE+/G1eim8MMLLmXYL6j7OTMQ+yLM/oVQOoHCwL3wxdjevRgIjcENpSs/w8RmZUJQOFXIZ794ThXATwHXcEW385PbA3F4EGloNgSMDETwMKzPsyapdNCqU4i/Q= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778144660; c=relaxed/simple; bh=aNoEqGApD+eAjWkTOz/lXdtBlXoEuUexshsIqjlwc/Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=L83UXVAx35TM3JInkvLoChVDtjEmwd8/w+tCqgTLINLNcP/wvfcseRSy1HMX5Uh3c5Frj0MsKmOdJO0OOL9siUd6wWWPQ/u+elmzo/TkBBNpJkdcmrHcnvQjMh/WtzAH1mOXmx8KJc4zdZTkEDT5LMbZ0DvDKIITADMW7tO7MUI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=thingy.jp; spf=pass smtp.mailfrom=0x0f.com; dkim=pass (1024-bit key) header.d=thingy.jp header.i=@thingy.jp header.b=pA7eiE7D; arc=none smtp.client-ip=209.85.216.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=thingy.jp Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=0x0f.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=thingy.jp header.i=@thingy.jp header.b="pA7eiE7D" Received: by mail-pj1-f45.google.com with SMTP id 98e67ed59e1d1-365312a27abso626237a91.3 for ; Thu, 07 May 2026 02:04:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=thingy.jp; s=google; t=1778144651; x=1778749451; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=RE2b5bv8drxMPZvWvisFxWNHfnllHA18/fcjXacN4ZQ=; b=pA7eiE7DU3GLuJ9RiaWolhsiK6cdHa9otI7IGWoqcJUpKNKaKIz+LXoIm3iigxww+m uZ3SRMUDyUBFT1D79JJnMSbbqt8yS4Yv3jo+g8E0X9YABxDTDKxi+pypPA2p5xfOBvKY uGNYNWn0lBxUw/IuZ89Vt7qmhJK8wajRZ2IoE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778144651; x=1778749451; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=RE2b5bv8drxMPZvWvisFxWNHfnllHA18/fcjXacN4ZQ=; b=T8iOygpX4hMRSdT4cJZADOZm6bjlBG1UyhozIVL/HKiNGdeMmRQU2swsu3T7AcoPNW RW1JcRPDJvhPeVVENwEYzYS+9Io16D/djj/r4yHOcP2//WtWUtAkr1+sWLkMbQqF6zPC cyGi66C0LYJmxVicVZU+b8Ym9v4c3v0/zPiCObb+vZtAlzW3BoJ7bDdsqt+G6FeqQE4W IWHkzvdb9bG/n9e0CAR4+zmwV92DQttDqU2nUC8oXGIegiigG4bH4FJKhpol0IuNtNmU FWnxdtGZgdx4ivUSmg/CfOj2Z2XOygQB9a07Y3U4ASQnmXG6ID0dDZrnfwMg2eXLfxEJ S/bQ== X-Forwarded-Encrypted: i=1; AFNElJ+MJKXGOO0CYvrHFM4Bd/r46Wn6guXz0krpHDGuf5ncRYjEqwEjhDtWUUTK8lMq46XQVPcp1XLPWWFzsT4=@vger.kernel.org X-Gm-Message-State: AOJu0YwZxiAXX9qVrzsyXqtSF8wY3G/SgXEYk+NkpJxQBXwJSe3lx+H+ 1x4sk8z3c5oH/3mbbXeVEgcpqYJevdgmi4B/iFoyW9tzxpr8m3iOuC1d3AqFlaLvTw0= X-Gm-Gg: AeBDiet8j8Eug775/kjUvzNt5vQfe9QN3OwFJPgA2qwa/Hw1wrhohklUG2dUxHeInE7 vxRHPP1bwFQ+QZrCVg5TQfQCw9ZSv/sqC+JOqJ2hZ/zdStImKcxzg2/ilUH2x2JrxE/+MhAI6LC /yA3KEi7wUrgJRDNKWULsDMJpxCgXasT4/uG336gcqGDEcwTHmLJ6t8zDdev0SU15GlUoGmU2sf AuU9f9ThwwzBE7kUMTSbEazd4avzH8Upbvs6S6ozt9ZNeM4eGakThkJ9SHY4/iqtxSr3RPReyqC E6wU3INarjGh/jZVClcCjE8IhC0tgTRt14O+kY3TRNnkw/yWWrN6/3NtCKGzfmhdWE4xee2Ih8S BF8+vzsmWeek4eTwgKHNrB6TwIurmiDzrBBBEdoaMJgO+XNs8s6jAw7UIlzCXSKgqSGH/zArk5J I5fmyqLv1jOpvZXgbFZ6Mmyw7PLpZ2suOJebM55AaXOx33SBqnvwQDBxlSA+DmcJnCF/7UMOCwc PkdM3hLJWN0ncSgofdo5mDulOk= X-Received: by 2002:a17:902:fc8b:b0:2b2:4eec:9806 with SMTP id d9443c01a7336-2ba78b48751mr45472395ad.8.1778144651429; Thu, 07 May 2026 02:04:11 -0700 (PDT) Received: from kinako.work.home.arpa (p1387170-ipxg00a01sizuokaden.shizuoka.ocn.ne.jp. [153.221.239.170]) by smtp.googlemail.com with ESMTPSA id d9443c01a7336-2babaac34a4sm20061215ad.16.2026.05.07.02.04.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 May 2026 02:04:11 -0700 (PDT) From: Daniel Palmer To: w@1wt.eu, linux@weissschuh.net Cc: david.laight.linux@gmail.com, linux-kernel@vger.kernel.org, Daniel Palmer Subject: [PATCH v4 3/3] selftests/nolibc: Add a very basic test for fallocate() Date: Thu, 7 May 2026 18:03:53 +0900 Message-ID: <20260507090353.356764-4-daniel@thingy.jp> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260507090353.356764-1-daniel@thingy.jp> References: <20260507090353.356764-1-daniel@thingy.jp> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 1: Create a tmp file, fallocate() to make it a bit bigger, check the size is what was expected. 2: Try to fallocate() (1 << 20), this should work. 3: Try to fallocate() (1 << 52), this should cause ENOSPC or EFBIG. 2 and 3 are basically to make sure if the offset or size are split into a pair of registers for the syscall that we are passing them the correct way around. This test requires /tmp to be a tmpfs and not ramfs or something else so before running the tests check what /tmp is and if its not tmpfs skip the test. Signed-off-by: Daniel Palmer --- tools/testing/selftests/nolibc/nolibc-test.c | 70 ++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c index 1db6e8d55c16..2a3b855214bc 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -48,6 +48,9 @@ #include #include +/* For TMPFS_MAGIC */ +#include + #pragma GCC diagnostic ignored "-Wmissing-prototypes" #include "nolibc-test-linkage.h" @@ -903,6 +906,66 @@ int test_getpagesize(void) return !c; } +int test_fallocate(void) +{ + struct stat st; + int fd, r; + + /* Create a new tmp file */ + fd = open("/tmp", O_TMPFILE | O_RDWR, 0644); + if (fd == -1) + return -1; + + /* Expand it to 42 bytes */ + r = fallocate(fd, 0, 0, 42); + if (r) + goto close_tmpfile; + + /* Get the new stat */ + r = fstat(fd, &st); + if (r) + goto close_tmpfile; + + /* It should be 42 bytes long */ + if (st.st_size != 42) { + r = -1; + goto close_tmpfile; + } + + /* Now try to allocate 1MiB. This puts a single bit + * into one of the registers if the size is split into + * two registers. This shouldn't fail if the bit is in + * the correct register. + */ + r = fallocate(fd, 0, 0, (1ll << 20)); + if (r) + goto close_tmpfile; + + /* Check a massive size that puts a single bit into + * the other register if splitting. + * This should return an error and errno = ENOSPC or + * EFBIG indicating the value was passed correctly but it + * was rejected. + */ + r = fallocate(fd, 0, 0, (1ll << (20 + 32))); + if (r != -1) { + r = -1; + goto close_tmpfile; + } + if (errno != ENOSPC && errno != EFBIG) { + r = -1; + goto close_tmpfile; + } + + /* Test passed */ + r = 0; + +close_tmpfile: + close(fd); + + return r; +} + int test_file_stream(void) { FILE *f; @@ -1455,6 +1518,8 @@ int run_syscall(int min, int max) void *p1, *p2; int has_gettid = 1; int has_brk; + int tmp_is_tmpfs = 0; + struct statfs tmp_statfs_buf; /* indicates whether or not /proc is mounted */ proc = stat("/proc", &stat_buf) == 0; @@ -1470,6 +1535,10 @@ int run_syscall(int min, int max) /* on musl setting brk()/sbrk() always fails */ has_brk = brk(0) == 0; + /* Check if /tmp is tmpfs */ + if (statfs("/tmp", &tmp_statfs_buf) == 0 && tmp_statfs_buf.f_type == TMPFS_MAGIC) + tmp_is_tmpfs = 1; + for (test = min; test >= 0 && test <= max; test++) { int llen = 0; /* line length */ @@ -1512,6 +1581,7 @@ int run_syscall(int min, int max) CASE_TEST(dup3_0); tmp = dup3(0, 100, 0); EXPECT_SYSNE(1, tmp, -1); close(tmp); break; CASE_TEST(dup3_m1); tmp = dup3(-1, 100, 0); EXPECT_SYSER(1, tmp, -1, EBADF); if (tmp != -1) close(tmp); break; CASE_TEST(execve_root); EXPECT_SYSER(1, execve("/", (char*[]){ [0] = "/", [1] = NULL }, NULL), -1, EACCES); break; + CASE_TEST(fallocate); EXPECT_SYSZR(tmp_is_tmpfs, test_fallocate()); break; CASE_TEST(fchdir_stdin); EXPECT_SYSER(1, fchdir(STDIN_FILENO), -1, ENOTDIR); break; CASE_TEST(fchdir_badfd); EXPECT_SYSER(1, fchdir(-1), -1, EBADF); break; CASE_TEST(file_stream); EXPECT_SYSZR(1, test_file_stream()); break; -- 2.53.0