From 335cc8f54e4510d4a9025a401cc67a7d32ce1f56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Nieper-Wi=C3=9Fkirchen?= Date: Sat, 25 Nov 2023 18:14:55 +0100 Subject: [PATCH] jit/cache-tests: New module. * m4/valgrind-helper.m4: Unconditionally set support_valgrind to fix configure error. * modules/jit/cache-tests: New file. Mark the test as unportable for now. * tests/jit/test-cache.c: New file. --- ChangeLog | 9 +++++ m4/valgrind-helper.m4 | 3 +- modules/jit/cache-tests | 20 +++++++++++ tests/jit/test-cache.c | 77 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 108 insertions(+), 1 deletion(-) create mode 100644 modules/jit/cache-tests create mode 100644 tests/jit/test-cache.c diff --git a/ChangeLog b/ChangeLog index 1834acd9da..89419032b3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2023-11-25 Marc Nieper-Wißkirchen + + jit/cache-tests: New module. + * m4/valgrind-helper.m4: Unconditionally set support_valgrind to + fix configure error. + * modules/jit/cache-tests: New file. Mark the test as unportable + for now. + * tests/jit/test-cache.c: New file. + 2023-11-24 Bruno Haible floorf, ceilf tests: Strengthen against compiler optimizations. diff --git a/m4/valgrind-helper.m4 b/m4/valgrind-helper.m4 index 99c31030b9..90637e6745 100644 --- a/m4/valgrind-helper.m4 +++ b/m4/valgrind-helper.m4 @@ -17,7 +17,8 @@ AC_DEFUN_ONCE([gl_VALGRIND_HELPER], else support_valgrind=0 fi - ]) + ], + [support_valgrind=0]) if test $support_valgrind = 1; then AC_CHECK_HEADERS([valgrind/valgrind.h]) if test $ac_cv_header_valgrind_valgrind_h != yes; then diff --git a/modules/jit/cache-tests b/modules/jit/cache-tests new file mode 100644 index 0000000000..eff828890d --- /dev/null +++ b/modules/jit/cache-tests @@ -0,0 +1,20 @@ +Files: +tests/jit/test-cache.c +tests/macros.h + +Status: +unportable-test + +Depends-on: +getpagesize +pagealign_alloc +stdint + +configure.ac: +AC_CHECK_HEADERS_ONCE([sys/mman.h]) +AC_CHECK_FUNCS_ONCE([mprotect]) + +Makefile.am: +TESTS += test-cache +check_PROGRAMS += test-cache +test_cache_SOURCES = jit/test-cache.c diff --git a/tests/jit/test-cache.c b/tests/jit/test-cache.c new file mode 100644 index 0000000000..47c81a8b1e --- /dev/null +++ b/tests/jit/test-cache.c @@ -0,0 +1,77 @@ +/* Test clear_cache. + + Copyright 2023 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#include + +#include + +#include +#include +#include + +#if HAVE_SYS_MMAN_H && HAVE_MPROTECT +# include +#endif + +#include "macros.h" + +/* This test assumes that the code generated by the compiler for the + procedures `return1' and `return2' is position independent. It + also assumes that function pointers are compatible with data + pointers and that these are bit-compatible to integers. */ + +static int +return1 (void) +{ + return 1; +} + +static int +return2 (void) +{ + return 2; +} + +int +main () +{ +#if !(HAVE_SYS_MMAN_H && HAVE_SYS_MMAN_H) + return 77; +#endif + + int const pagesize = getpagesize (); + unsigned char *start = pagealign_xalloc (pagesize); + unsigned char *end = start + pagesize; + + /* We have to call `mprotect' before the tests because on some + platforms `mprotect' invalidates the caches. */ + mprotect (start, end - start, PROT_READ | PROT_WRITE | PROT_EXEC); + + int (*f) (void) = (void *) start; + + /* We assume that the code is not longer than 64 bytes and that we + can access the full 64 bytes for reading. */ + memcpy (start, return1, 64); + clear_cache (start, end); + ASSERT (f () == 1); + + memcpy (start, return2, 64); + clear_cache (start, end); + ASSERT (f () == 2); + + return 0; +} -- 2.40.1