aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorAndrea Corallo2020-07-26 09:40:02 +0200
committerAndrea Corallo2020-07-26 09:40:02 +0200
commit7a161dc688f0eeee64e307a55efbc7d11bab3627 (patch)
tree127cd6d6257e8e484a7021b12790610d308f7594 /test
parent79ed90380547128b9919d407901a886fed0306b7 (diff)
parent9f01ce6327af886f26399924a9aadf16cdd4fd9f (diff)
downloademacs-7a161dc688f0eeee64e307a55efbc7d11bab3627.tar.gz
emacs-7a161dc688f0eeee64e307a55efbc7d11bab3627.zip
Merge remote-tracking branch 'savahnna/master' into HEAD
Diffstat (limited to 'test')
-rw-r--r--test/data/emacs-module/mod-test.c32
-rw-r--r--test/src/emacs-module-tests.el29
2 files changed, 61 insertions, 0 deletions
diff --git a/test/data/emacs-module/mod-test.c b/test/data/emacs-module/mod-test.c
index 1e64bcd65f1..ed289d7a863 100644
--- a/test/data/emacs-module/mod-test.c
+++ b/test/data/emacs-module/mod-test.c
@@ -201,7 +201,19 @@ Fmod_test_globref_free (emacs_env *env, ptrdiff_t nargs, emacs_value args[],
201 return env->intern (env, "ok"); 201 return env->intern (env, "ok");
202} 202}
203 203
204/* Treat a local reference as global and free it. Module assertions
205 should detect this case even if a global reference representing the
206 same object also exists. */
204 207
208static emacs_value
209Fmod_test_globref_invalid_free (emacs_env *env, ptrdiff_t nargs,
210 emacs_value *args, void *data)
211{
212 emacs_value local = env->make_integer (env, 9876);
213 env->make_global_ref (env, local);
214 env->free_global_ref (env, local); /* Not allowed. */
215 return env->intern (env, "nil");
216}
205 217
206/* Return a copy of the argument string where every 'a' is replaced 218/* Return a copy of the argument string where every 'a' is replaced
207 with 'b'. */ 219 with 'b'. */
@@ -306,6 +318,22 @@ Fmod_test_invalid_load (emacs_env *env, ptrdiff_t nargs, emacs_value *args,
306 return invalid_stored_value; 318 return invalid_stored_value;
307} 319}
308 320
321/* The next function works in conjunction with the two previous ones.
322 It stows away a copy of the object created by
323 `Fmod_test_invalid_store' in a global reference. Module assertions
324 should still detect the invalid load of the local reference. */
325
326static emacs_value global_copy_of_invalid_stored_value;
327
328static emacs_value
329Fmod_test_invalid_store_copy (emacs_env *env, ptrdiff_t nargs,
330 emacs_value *args, void *data)
331{
332 emacs_value local = Fmod_test_invalid_store (env, 0, NULL, NULL);
333 return global_copy_of_invalid_stored_value
334 = env->make_global_ref (env, local);
335}
336
309/* An invalid finalizer: Finalizers are run during garbage collection, 337/* An invalid finalizer: Finalizers are run during garbage collection,
310 where Lisp code can't be executed. -module-assertions tests for 338 where Lisp code can't be executed. -module-assertions tests for
311 this case. */ 339 this case. */
@@ -678,12 +706,16 @@ emacs_module_init (struct emacs_runtime *ert)
678 1, 1, NULL, NULL); 706 1, 1, NULL, NULL);
679 DEFUN ("mod-test-globref-make", Fmod_test_globref_make, 0, 0, NULL, NULL); 707 DEFUN ("mod-test-globref-make", Fmod_test_globref_make, 0, 0, NULL, NULL);
680 DEFUN ("mod-test-globref-free", Fmod_test_globref_free, 4, 4, NULL, NULL); 708 DEFUN ("mod-test-globref-free", Fmod_test_globref_free, 4, 4, NULL, NULL);
709 DEFUN ("mod-test-globref-invalid-free", Fmod_test_globref_invalid_free, 0, 0,
710 NULL, NULL);
681 DEFUN ("mod-test-string-a-to-b", Fmod_test_string_a_to_b, 1, 1, NULL, NULL); 711 DEFUN ("mod-test-string-a-to-b", Fmod_test_string_a_to_b, 1, 1, NULL, NULL);
682 DEFUN ("mod-test-userptr-make", Fmod_test_userptr_make, 1, 1, NULL, NULL); 712 DEFUN ("mod-test-userptr-make", Fmod_test_userptr_make, 1, 1, NULL, NULL);
683 DEFUN ("mod-test-userptr-get", Fmod_test_userptr_get, 1, 1, NULL, NULL); 713 DEFUN ("mod-test-userptr-get", Fmod_test_userptr_get, 1, 1, NULL, NULL);
684 DEFUN ("mod-test-vector-fill", Fmod_test_vector_fill, 2, 2, NULL, NULL); 714 DEFUN ("mod-test-vector-fill", Fmod_test_vector_fill, 2, 2, NULL, NULL);
685 DEFUN ("mod-test-vector-eq", Fmod_test_vector_eq, 2, 2, NULL, NULL); 715 DEFUN ("mod-test-vector-eq", Fmod_test_vector_eq, 2, 2, NULL, NULL);
686 DEFUN ("mod-test-invalid-store", Fmod_test_invalid_store, 0, 0, NULL, NULL); 716 DEFUN ("mod-test-invalid-store", Fmod_test_invalid_store, 0, 0, NULL, NULL);
717 DEFUN ("mod-test-invalid-store-copy", Fmod_test_invalid_store_copy, 0, 0,
718 NULL, NULL);
687 DEFUN ("mod-test-invalid-load", Fmod_test_invalid_load, 0, 0, NULL, NULL); 719 DEFUN ("mod-test-invalid-load", Fmod_test_invalid_load, 0, 0, NULL, NULL);
688 DEFUN ("mod-test-invalid-finalizer", Fmod_test_invalid_finalizer, 0, 0, 720 DEFUN ("mod-test-invalid-finalizer", Fmod_test_invalid_finalizer, 0, 0,
689 NULL, NULL); 721 NULL, NULL);
diff --git a/test/src/emacs-module-tests.el b/test/src/emacs-module-tests.el
index 411b4505da0..8465fd02e1e 100644
--- a/test/src/emacs-module-tests.el
+++ b/test/src/emacs-module-tests.el
@@ -272,6 +272,24 @@ must evaluate to a regular expression string."
272 (mod-test-invalid-store) 272 (mod-test-invalid-store)
273 (mod-test-invalid-load))) 273 (mod-test-invalid-load)))
274 274
275(ert-deftest module--test-assertions--load-non-live-object-with-global-copy ()
276 "Check that -module-assertions verify that non-live objects aren't accessed.
277This differs from `module--test-assertions-load-non-live-object'
278in that it stows away a global reference. The module assertions
279should nevertheless detect the invalid load."
280 (skip-unless (or (file-executable-p mod-test-emacs)
281 (and (eq system-type 'windows-nt)
282 (file-executable-p (concat mod-test-emacs ".exe")))))
283 ;; This doesn't yet cause undefined behavior.
284 (should (eq (mod-test-invalid-store-copy) 123))
285 (module--test-assertion (rx "Emacs value not found in "
286 (+ digit) " values of "
287 (+ digit) " environments\n")
288 ;; Storing and reloading a local value causes undefined behavior,
289 ;; which should be detected by the module assertions.
290 (mod-test-invalid-store-copy)
291 (mod-test-invalid-load)))
292
275(ert-deftest module--test-assertions--call-emacs-from-gc () 293(ert-deftest module--test-assertions--call-emacs-from-gc ()
276 "Check that -module-assertions prevents calling Emacs functions 294 "Check that -module-assertions prevents calling Emacs functions
277during garbage collection." 295during garbage collection."
@@ -283,6 +301,17 @@ during garbage collection."
283 (mod-test-invalid-finalizer) 301 (mod-test-invalid-finalizer)
284 (garbage-collect))) 302 (garbage-collect)))
285 303
304(ert-deftest module--test-assertions--globref-invalid-free ()
305 "Check that -module-assertions detects invalid freeing of a
306local reference."
307 (skip-unless (or (file-executable-p mod-test-emacs)
308 (and (eq system-type 'windows-nt)
309 (file-executable-p (concat mod-test-emacs ".exe")))))
310 (module--test-assertion
311 (rx "Global value was not found in list of " (+ digit) " globals")
312 (mod-test-globref-invalid-free)
313 (garbage-collect)))
314
286(ert-deftest module/describe-function-1 () 315(ert-deftest module/describe-function-1 ()
287 "Check that Bug#30163 is fixed." 316 "Check that Bug#30163 is fixed."
288 (with-temp-buffer 317 (with-temp-buffer