aboutsummaryrefslogtreecommitdiffstats
path: root/test/src
diff options
context:
space:
mode:
authorAndrea Corallo2020-11-29 15:11:38 +0100
committerAndrea Corallo2020-11-29 15:11:38 +0100
commit6523b8401519a29ca0aefaf44c3dfa36f681f64e (patch)
treea691422921ad1287fdeade2128efed4c59c14e8d /test/src
parent2e0256e0a02edad129e0af1ea97b9e263c5d83fb (diff)
parent38ed05f49fcfe7c6d6908041010881a04a7ff6b1 (diff)
downloademacs-6523b8401519a29ca0aefaf44c3dfa36f681f64e.tar.gz
emacs-6523b8401519a29ca0aefaf44c3dfa36f681f64e.zip
Merge remote-tracking branch 'savannah/master' into HEAD
Diffstat (limited to 'test/src')
-rw-r--r--test/src/emacs-module-resources/mod-test.c10
-rw-r--r--test/src/emacs-module-tests.el50
2 files changed, 60 insertions, 0 deletions
diff --git a/test/src/emacs-module-resources/mod-test.c b/test/src/emacs-module-resources/mod-test.c
index 258a679b207..419621256ae 100644
--- a/test/src/emacs-module-resources/mod-test.c
+++ b/test/src/emacs-module-resources/mod-test.c
@@ -691,6 +691,14 @@ Fmod_test_identity (emacs_env *env, ptrdiff_t nargs, emacs_value *args,
691 return args[0]; 691 return args[0];
692} 692}
693 693
694static emacs_value
695Fmod_test_funcall (emacs_env *env, ptrdiff_t nargs, emacs_value *args,
696 void *data)
697{
698 assert (0 < nargs);
699 return env->funcall (env, args[0], nargs - 1, args + 1);
700}
701
694/* Lisp utilities for easier readability (simple wrappers). */ 702/* Lisp utilities for easier readability (simple wrappers). */
695 703
696/* Provide FEATURE to Emacs. */ 704/* Provide FEATURE to Emacs. */
@@ -780,6 +788,8 @@ emacs_module_init (struct emacs_runtime *ert)
780 DEFUN ("mod-test-function-finalizer-calls", 788 DEFUN ("mod-test-function-finalizer-calls",
781 Fmod_test_function_finalizer_calls, 0, 0, NULL, NULL); 789 Fmod_test_function_finalizer_calls, 0, 0, NULL, NULL);
782 DEFUN ("mod-test-async-pipe", Fmod_test_async_pipe, 1, 1, NULL, NULL); 790 DEFUN ("mod-test-async-pipe", Fmod_test_async_pipe, 1, 1, NULL, NULL);
791 DEFUN ("mod-test-funcall", Fmod_test_funcall, 1, emacs_variadic_function,
792 NULL, NULL);
783 793
784#undef DEFUN 794#undef DEFUN
785 795
diff --git a/test/src/emacs-module-tests.el b/test/src/emacs-module-tests.el
index fb4ed4a6842..99d4cafb4af 100644
--- a/test/src/emacs-module-tests.el
+++ b/test/src/emacs-module-tests.el
@@ -506,4 +506,54 @@ See Bug#36226."
506 (should (not (multibyte-string-p (mod-test-return-unibyte)))) 506 (should (not (multibyte-string-p (mod-test-return-unibyte))))
507 (should (equal result "foo\x00zot")))) 507 (should (equal result "foo\x00zot"))))
508 508
509(cl-defstruct (emacs-module-tests--variable
510 (:constructor nil)
511 (:constructor emacs-module-tests--make-variable
512 (name
513 &aux
514 (mutex (make-mutex name))
515 (condvar (make-condition-variable mutex name))))
516 (:copier nil))
517 "A variable that's protected by a mutex."
518 value
519 (mutex nil :read-only t :type mutex)
520 (condvar nil :read-only t :type condition-variable))
521
522(defun emacs-module-tests--wait-for-variable (variable desired)
523 (with-mutex (emacs-module-tests--variable-mutex variable)
524 (while (not (eq (emacs-module-tests--variable-value variable) desired))
525 (condition-wait (emacs-module-tests--variable-condvar variable)))))
526
527(defun emacs-module-tests--change-variable (variable new)
528 (with-mutex (emacs-module-tests--variable-mutex variable)
529 (setf (emacs-module-tests--variable-value variable) new)
530 (condition-notify (emacs-module-tests--variable-condvar variable) :all)))
531
532(ert-deftest emacs-module-tests/interleaved-threads ()
533 (let* ((state-1 (emacs-module-tests--make-variable "1"))
534 (state-2 (emacs-module-tests--make-variable "2"))
535 (thread-1
536 (make-thread
537 (lambda ()
538 (emacs-module-tests--change-variable state-1 'before-module)
539 (mod-test-funcall
540 (lambda ()
541 (emacs-module-tests--change-variable state-1 'in-module)
542 (emacs-module-tests--wait-for-variable state-2 'in-module)))
543 (emacs-module-tests--change-variable state-1 'after-module))
544 "thread 1"))
545 (thread-2
546 (make-thread
547 (lambda ()
548 (emacs-module-tests--change-variable state-2 'before-module)
549 (emacs-module-tests--wait-for-variable state-1 'in-module)
550 (mod-test-funcall
551 (lambda ()
552 (emacs-module-tests--change-variable state-2 'in-module)
553 (emacs-module-tests--wait-for-variable state-1 'after-module)))
554 (emacs-module-tests--change-variable state-2 'after-module))
555 "thread 2")))
556 (thread-join thread-1)
557 (thread-join thread-2)))
558
509;;; emacs-module-tests.el ends here 559;;; emacs-module-tests.el ends here