HAVE_NATIVE_COMP = @HAVE_NATIVE_COMP@
-REPLACE_FREE = @REPLACE_FREE@
-
-include ${top_builddir}/src/verbose.mk
# We never change directory before running Emacs, so a relative file
GMP_H = @GMP_H@
LIBGMP = @LIBGMP@
+LIB_CLOCK_GETTIME = @LIB_CLOCK_GETTIME@
+LIB_NANOSLEEP = @LIB_NANOSLEEP@
-MODULE_CFLAGS = -I../src -I$(srcdir)/../src -I../lib -I$(srcdir)/../lib \
+MODULE_CFLAGS = $(and $(GMP_H),-I.) -I../src -I$(srcdir)/../src \
$(FPIC_CFLAGS) $(PROFILING_CFLAGS) \
$(WARN_CFLAGS) $(WERROR_CFLAGS) $(CFLAGS)
+gmp.h:
+ echo '#include "$(srcdir)/../lib/mini-gmp.h"' >$@
+
test_module = $(test_module_dir)/mod-test${SO}
src/emacs-module-tests.log src/emacs-module-tests.elc: $(test_module)
-FREE_SOURCE_0 =
-FREE_SOURCE_1 = $(srcdir)/../lib/free.c
-
# In the compilation command, we can't use any object or archive file
# as source because those are not compiled with -fPIC. Therefore we
# use only source files.
-$(test_module): $(test_module:${SO}=.c) ../src/emacs-module.h
+$(test_module): $(test_module:${SO}=.c) ../src/emacs-module.h \
+ ../src/config.h $(and $(GMP_H),gmp.h)
$(AM_V_CCLD)${MKDIR_P} $(dir $@)
$(AM_V_at)$(CC) -shared $(CPPFLAGS) $(MODULE_CFLAGS) $(LDFLAGS) \
-o $@ $< $(LIBGMP) \
- $(and $(GMP_H),$(srcdir)/../lib/mini-gmp-gnulib.c) \
- $(FREE_SOURCE_$(REPLACE_FREE)) \
- ../lib/libgnu.a
+ $(and $(GMP_H),$(srcdir)/../lib/mini-gmp.c) \
+ $(LIB_CLOCK_GETTIME) $(LIB_NANOSLEEP)
endif
src/emacs-tests.log: ../lib-src/seccomp-filter.c
find . '(' -name '*.xml' -a ! -path '*resources*' ')' $(FIND_DELETE)
rm -f ${srcdir}/lisp/gnus/mml-sec-resources/random_seed
rm -f $(test_module_dir)/*.o $(test_module_dir)/*.so \
- $(test_module_dir)/*.dll
+ $(test_module_dir)/*.dll gmp.h
bootstrap-clean: clean
find $(srcdir) -name '*.elc' $(FIND_DELETE)
#include <gmp.h>
#include <emacs-module.h>
-#include "timespec.h"
-
int plugin_is_GPL_compatible;
#if INTPTR_MAX <= 0
# error "INTPTR_MAX too large"
#endif
-/* Smoke test to verify that EMACS_LIMB_MAX is defined. */
-_Static_assert (0 < EMACS_LIMB_MAX, "EMACS_LIMB_MAX missing or incorrect");
-
/* Always return symbol 't'. */
static emacs_value
Fmod_test_return_t (emacs_env *env, ptrdiff_t nargs, emacs_value args[],
signal_system_error (env, errno, function);
}
+#ifdef CLOCK_REALTIME
+
+/* Whether A <= B. */
+static bool
+timespec_le (struct timespec a, struct timespec b)
+{
+ return (a.tv_sec < b.tv_sec
+ || (a.tv_sec == b.tv_sec && a.tv_nsec <= b.tv_nsec));
+}
+
/* A long-running operation that occasionally calls `should_quit' or
`process_input'. */
if (env->non_local_exit_check (env))
return NULL;
const bool process_input = env->is_not_nil (env, args[1]);
- const struct timespec amount = make_timespec(0, 10000000);
+ const struct timespec amount = { .tv_nsec = 10000000 };
while (true)
{
- const struct timespec now = current_timespec ();
- if (timespec_cmp (now, until) >= 0)
+ struct timespec now;
+ if (clock_gettime (CLOCK_REALTIME, &now) != 0)
+ return NULL;
+ if (timespec_le (until, now))
break;
if (nanosleep (&amount, NULL) && errno != EINTR)
{
}
return env->intern (env, "finished");
}
+#endif
static emacs_value
Fmod_test_add_nanosecond (emacs_env *env, ptrdiff_t nargs, emacs_value *args,
return result;
}
+#ifdef CLOCK_REALTIME
static emacs_value
Fmod_test_nanoseconds (emacs_env *env, ptrdiff_t nargs, emacs_value *args, void *data) {
assert (nargs == 1);
mpz_t nanoseconds;
assert (LONG_MIN <= time.tv_sec && time.tv_sec <= LONG_MAX);
mpz_init_set_si (nanoseconds, time.tv_sec);
-#ifdef __MINGW32__
- _Static_assert (1000000000 <= ULONG_MAX, "unsupported architecture");
-#else
- static_assert (1000000000 <= ULONG_MAX, "unsupported architecture");
-#endif
mpz_mul_ui (nanoseconds, nanoseconds, 1000000000);
assert (0 <= time.tv_nsec && time.tv_nsec <= ULONG_MAX);
mpz_add_ui (nanoseconds, nanoseconds, time.tv_nsec);
mpz_clear (nanoseconds);
return result;
}
+#endif
static emacs_value
Fmod_test_double (emacs_env *env, ptrdiff_t nargs, emacs_value *args,
#ifdef WINDOWSNT
Sleep (500);
#else
- const struct timespec sleep = {0, 500000000};
+ const struct timespec sleep = { .tv_nsec = 500000000 };
if (nanosleep (&sleep, NULL) != 0)
perror ("nanosleep");
#endif
int
emacs_module_init (struct emacs_runtime *ert)
{
+ /* These smoke tests don't use _Static_assert because too many
+ compilers lack support for _Static_assert. */
+ assert (0 < EMACS_LIMB_MAX);
+ assert (1000000000 <= ULONG_MAX);
+
/* Check that EMACS_MAJOR_VERSION is defined and an integral
constant. */
char dummy[EMACS_MAJOR_VERSION];
DEFUN ("mod-test-invalid-load", Fmod_test_invalid_load, 0, 0, NULL, NULL);
DEFUN ("mod-test-invalid-finalizer", Fmod_test_invalid_finalizer, 0, 0,
NULL, NULL);
+#ifdef CLOCK_REALTIME
DEFUN ("mod-test-sleep-until", Fmod_test_sleep_until, 2, 2, NULL, NULL);
+#endif
DEFUN ("mod-test-add-nanosecond", Fmod_test_add_nanosecond, 1, 1, NULL, NULL);
+#ifdef CLOCK_REALTIME
DEFUN ("mod-test-nanoseconds", Fmod_test_nanoseconds, 1, 1, NULL, NULL);
+#endif
DEFUN ("mod-test-double", Fmod_test_double, 1, 1, NULL, NULL);
DEFUN ("mod-test-make-function-with-finalizer",
Fmod_test_make_function_with_finalizer, 0, 0, NULL, NULL);
(ert-deftest mod-test-sleep-until ()
"Check that `mod-test-sleep-until' either returns normally or quits.
Interactively, you can try hitting \\[keyboard-quit] to quit."
+ (skip-unless (fboundp 'mod-test-sleep-until))
(dolist (arg '(nil t))
;; Guard against some caller setting `inhibit-quit'.
(with-local-quit
(ert-deftest mod-test-nanoseconds ()
"Test truncation when converting to `struct timespec'."
+ (skip-unless (fboundp 'mod-test-nanoseconds))
(dolist (test-case '((0 . 0)
(-1 . -1000000000)
((1 . 1000000000) . 1)
(should (= (mod-test-nanoseconds input) expected))))))
(ert-deftest mod-test-double ()
+ (skip-unless (fboundp 'mod-test-double))
(dolist (input (list 0 1 2 -1 42 12345678901234567890
most-positive-fixnum (1+ most-positive-fixnum)
most-negative-fixnum (1- most-negative-fixnum)))