selftests/nolibc: add mmap_munmap_good test case
authorZhangjin Wu <falcon@tinylab.org>
Fri, 7 Jul 2023 15:08:20 +0000 (23:08 +0800)
committerWilly Tarreau <w@1wt.eu>
Wed, 23 Aug 2023 02:38:02 +0000 (04:38 +0200)
commitfcdbf5dda418aad3fdc5fcedbdb41900a24178a8
treedb17d7f13bd76812c49385927ce27cd80e4a4ade
parentba3d0892be0e2d5a7d144c5519920130639524fc
selftests/nolibc: add mmap_munmap_good test case

mmap() a file with a good offset and then munmap() it. a non-zero offset
is passed to test the 6th argument of my_syscall6().

Note, it is not easy to find a unique file for mmap() in different
scenes, so, a file list is used to search the right one:

- /dev/zero: is commonly used to allocate anonymous memory and is likely
  present and readable

- /proc/1/exe: for 'run' and 'run-user' target, 'run-user' can not find
  '/proc/self/exe'

- /proc/self/exe: for 'libc-test' target, normal program 'libc-test' has
  no permission to access '/proc/1/exe'

- argv0: the path of the program itself, let it pass even with worst
  case scene: no procfs and no /dev/zero

Suggested-by: Willy Tarreau <w@1wt.eu>
Link: https://lore.kernel.org/lkml/20230702193306.GK16233@1wt.eu/
Suggested-by: Thomas Weißschuh <linux@weissschuh.net>
Link: https://lore.kernel.org/lkml/bff82ea6-610b-4471-a28b-6c76c28604a6@t-8ch.de/
Signed-off-by: Zhangjin Wu <falcon@tinylab.org>
Signed-off-by: Willy Tarreau <w@1wt.eu>
tools/testing/selftests/nolibc/nolibc-test.c