From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.177]) (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 8DF394779B9 for ; Thu, 30 Apr 2026 16:41:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.177 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777567303; cv=none; b=QlOzKEm/l1AtDMqDZoEUModprnI1G/mv4jNA1odpAVX8i/PgoiuxJ3dL0Nhb6z07ma8bl21FJEkHr7QSbqAtyX0HK4tHMzvxO3JFAABiDWDHPCXkr2mKbvUjNuPWKWwn8d2rG3kq7d+wgnCIT3Qz37HuRCQkniGUpyodf6LzeHM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777567303; c=relaxed/simple; bh=Q+mj5tOpWprawCyKSxQvWS9f0xkXgaZq6bjn0F/KSww=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SQXtAuypGjzEIXezcqiAxaW+J4EK3cgXkoEU0lgaB7WfXLyjZzO/Fwi/ybQkjQtGkAGxbKvQ1uO5AK51B2YuOWvQ9iuL/SyI2nuA6BTCmMeVo/oB7xqdrQ+un7LfuSFBlhFuq9zUxcbK27CpQo94W++Dqu/CZO9lu9oHWeZ6yZI= 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=N6DmJap9; arc=none smtp.client-ip=209.85.210.177 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="N6DmJap9" Received: by mail-pf1-f177.google.com with SMTP id d2e1a72fcca58-83177129e28so552721b3a.1 for ; Thu, 30 Apr 2026 09:41:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=thingy.jp; s=google; t=1777567300; x=1778172100; 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=BmsKRGljhhKJgxL+hpJaEbt7k4QMLUdUPZtSPvqBX8E=; b=N6DmJap9lX1/0mxhBeeq8ahbp9W31qHpXbTLXHypuyX2X4tQHh/unhYwE9xV6whLaV gUjqYKPeX7sMD4cpir2utXuD4hLtR7HVnMLxguwsNGET+/49NCBvuFFcPQEkXfK5fXLK 68JyWN/CkAVipQrKVz7cG+MDy5lFsn/ktOCLA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777567300; x=1778172100; 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=BmsKRGljhhKJgxL+hpJaEbt7k4QMLUdUPZtSPvqBX8E=; b=DtDm88eiY2kApxFzHN5VNx2mUIj3VtY/PgulBMzbErms6Rghw6hYWiRWz2MQF7AYWs WMESS8ex7Jq06HS63n5kzGF7rjQFLPmevdUGuvWn3yfmXWFmeFBbtwLyuf9kvgaZPebY +IopK8ONo2RmpMx9LFbzx9bbxLeXy7AZbXUFV0o0HknrdabAghsa8WsILrGF6P/bNrCL hPMIOz9PUmJ1vTeclRkivL/PjLdLkNeg4oMQb+IFbbmvkTpbs47G7FFve+3nEIJE4j0x l5tOnR/ffcJSOhXVDOm8DfDLCSuMFefQh+XOKTpDBILHL5FsdsPLsW+C9L9NR50Q/G/s /8xg== X-Gm-Message-State: AOJu0YwVjmgACNhOFZ450pJFu0vDD00Vg0oIv7pjiwOhJbtORigN///d MMaLaUJLLTBrimMP18IPAPRHJS7dhopIfP9V7BKPC2FEPzkW709mVKqasJq7dTNmSvh+0i2FN8k mksPo X-Gm-Gg: AeBDieskNfo5qcNDZWJeKGo0Keqec9Rvy4CPADe12GYQVLGhfPhS3wfPR/sYN7+oYPm s8cXo5XEGOQAhgXvWqCIeLd+84m0whc8IaamgniU1r0P/HshQJPjyHs3ipo0wsJ6s0TDpRwyDnM 8kZSLb2nITED5Al3rMdJLPCArl2jDZJSiOgQjhr/EM+/xSMVK7xSgihY9EEpUldNwE63689Q2nX U1GcJbShAVFF+93orUM+GDoyQJS1LMYdut34u8p731oeMYgFlDUnM3UJkg2Nf7/lAy8aqECBF5s WHOOzWCOgM8ad9jUEFngwuwOauszk7hSn90by8L1pcrXUBzyPC4g1qkgzudur9kKtWHw8nkVR1i CkQA+MWunbr9o421DcfzvRUcPu2t2v2RFydKEMBO2Eb7Vmow6wSeuc4KfAlTer0F7nkjMWwfJpM V9ZdWEIh+Vo2i+GZSICL0vNm9QYWmElyWhSoI9t41DuajsY/W9GUncEpf3ZOMSNF0AXtUDQHR4t jgetWDlb5QWIN7g7CUhBL76oh4= X-Received: by 2002:a05:6a00:4503:b0:82d:5da9:adbf with SMTP id d2e1a72fcca58-834fdccc01fmr4688962b3a.41.1777567300396; Thu, 30 Apr 2026 09:41:40 -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 d2e1a72fcca58-83515b543b0sm130519b3a.53.2026.04.30.09.41.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Apr 2026 09:41:39 -0700 (PDT) From: Daniel Palmer To: w@1wt.eu, linux@weissschuh.net Cc: linux-kernel@vger.kernel.org, Daniel Palmer Subject: [PATCH v3 2/2] selftests/nolibc: Add a very basic test for fallocate() Date: Fri, 1 May 2026 01:41:25 +0900 Message-ID: <20260430164125.1106350-3-daniel@thingy.jp> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260430164125.1106350-1-daniel@thingy.jp> References: <20260430164125.1106350-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. sparc32 seems to return EOPNOTSUPP for fallocate() so skip the test there. Signed-off-by: Daniel Palmer --- tools/testing/selftests/nolibc/nolibc-test.c | 69 ++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c index 08610cacf030..a586e9d9ede2 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -89,6 +89,14 @@ static const int is_glibc = #endif ; +static const int is_sparc32 = +#if defined(__sparc__) && !defined(__arch64__) + 1 +#else + 0 +#endif +; + #if !defined(NOLIBC) /* Some disabled tests may not compile. */ @@ -898,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; @@ -1507,6 +1575,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(!is_sparc32, 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