Skip to content

Commit a290296

Browse files
ammarfaizi2paulmckrcu
authored andcommitted
selftests/nolibc: Add getpagesize(2) selftest
Test the getpagesize() function. Make sure it returns the correct value. Signed-off-by: Ammar Faizi <[email protected]> Signed-off-by: Willy Tarreau <[email protected]> Signed-off-by: Paul E. McKenney <[email protected]>
1 parent 7efd762 commit a290296

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

tools/testing/selftests/nolibc/nolibc-test.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,35 @@ int test_getdents64(const char *dir)
442442
return ret;
443443
}
444444

445+
static int test_getpagesize(void)
446+
{
447+
long x = getpagesize();
448+
int c;
449+
450+
if (x < 0)
451+
return x;
452+
453+
#if defined(__x86_64__) || defined(__i386__) || defined(__i486__) || defined(__i586__) || defined(__i686__)
454+
/*
455+
* x86 family is always 4K page.
456+
*/
457+
c = (x == 4096);
458+
#elif defined(__aarch64__)
459+
/*
460+
* Linux aarch64 supports three values of page size: 4K, 16K, and 64K
461+
* which are selected at kernel compilation time.
462+
*/
463+
c = (x == 4096 || x == (16 * 1024) || x == (64 * 1024));
464+
#else
465+
/*
466+
* Assuming other architectures must have at least 4K page.
467+
*/
468+
c = (x >= 4096);
469+
#endif
470+
471+
return !c;
472+
}
473+
445474
/* Run syscall tests between IDs <min> and <max>.
446475
* Return 0 on success, non-zero on failure.
447476
*/
@@ -502,6 +531,7 @@ int run_syscall(int min, int max)
502531
CASE_TEST(gettimeofday_bad2); EXPECT_SYSER(1, gettimeofday(NULL, (void *)1), -1, EFAULT); break;
503532
CASE_TEST(gettimeofday_bad2); EXPECT_SYSER(1, gettimeofday(NULL, (void *)1), -1, EFAULT); break;
504533
#endif
534+
CASE_TEST(getpagesize); EXPECT_SYSZR(1, test_getpagesize()); break;
505535
CASE_TEST(ioctl_tiocinq); EXPECT_SYSZR(1, ioctl(0, TIOCINQ, &tmp)); break;
506536
CASE_TEST(ioctl_tiocinq); EXPECT_SYSZR(1, ioctl(0, TIOCINQ, &tmp)); break;
507537
CASE_TEST(link_root1); EXPECT_SYSER(1, link("/", "/"), -1, EEXIST); break;

0 commit comments

Comments
 (0)