diff options
| author | Philipp Stephani | 2020-07-25 23:04:05 +0200 |
|---|---|---|
| committer | Philipp Stephani | 2020-07-26 14:31:49 +0200 |
| commit | bde5f5f8978f704f24cce2fc7beec8c740d0e331 (patch) | |
| tree | a0d974e7ac975edc32270ce203db24ea6290982d /test | |
| parent | 4b3085a7fe8980432aa63ddf614fee2a6fb04e94 (diff) | |
| download | emacs-bde5f5f8978f704f24cce2fc7beec8c740d0e331.tar.gz emacs-bde5f5f8978f704f24cce2fc7beec8c740d0e331.zip | |
Backport: Add module test for edge case.
This backports commit 6355a3ec62 from master. Since the bug isn’t
present in emacs-27, just backport the test case.
* test/data/emacs-module/mod-test.c
(Fmod_test_invalid_store_copy): New test module function.
(emacs_module_init): Export it.
* test/src/emacs-module-tests.el
(module--test-assertions--load-non-live-object-with-global-copy):
New unit test.
Diffstat (limited to 'test')
| -rw-r--r-- | test/data/emacs-module/mod-test.c | 18 | ||||
| -rw-r--r-- | test/src/emacs-module-tests.el | 18 |
2 files changed, 36 insertions, 0 deletions
diff --git a/test/data/emacs-module/mod-test.c b/test/data/emacs-module/mod-test.c index 8dc9ff144af..f6c1c7cf3d2 100644 --- a/test/data/emacs-module/mod-test.c +++ b/test/data/emacs-module/mod-test.c | |||
| @@ -296,6 +296,22 @@ Fmod_test_invalid_load (emacs_env *env, ptrdiff_t nargs, emacs_value *args, | |||
| 296 | return invalid_stored_value; | 296 | return invalid_stored_value; |
| 297 | } | 297 | } |
| 298 | 298 | ||
| 299 | /* The next function works in conjunction with the two previous ones. | ||
| 300 | It stows away a copy of the object created by | ||
| 301 | `Fmod_test_invalid_store' in a global reference. Module assertions | ||
| 302 | should still detect the invalid load of the local reference. */ | ||
| 303 | |||
| 304 | static emacs_value global_copy_of_invalid_stored_value; | ||
| 305 | |||
| 306 | static emacs_value | ||
| 307 | Fmod_test_invalid_store_copy (emacs_env *env, ptrdiff_t nargs, | ||
| 308 | emacs_value *args, void *data) | ||
| 309 | { | ||
| 310 | emacs_value local = Fmod_test_invalid_store (env, 0, NULL, NULL); | ||
| 311 | return global_copy_of_invalid_stored_value | ||
| 312 | = env->make_global_ref (env, local); | ||
| 313 | } | ||
| 314 | |||
| 299 | /* An invalid finalizer: Finalizers are run during garbage collection, | 315 | /* An invalid finalizer: Finalizers are run during garbage collection, |
| 300 | where Lisp code can’t be executed. -module-assertions tests for | 316 | where Lisp code can’t be executed. -module-assertions tests for |
| 301 | this case. */ | 317 | this case. */ |
| @@ -559,6 +575,8 @@ emacs_module_init (struct emacs_runtime *ert) | |||
| 559 | DEFUN ("mod-test-vector-fill", Fmod_test_vector_fill, 2, 2, NULL, NULL); | 575 | DEFUN ("mod-test-vector-fill", Fmod_test_vector_fill, 2, 2, NULL, NULL); |
| 560 | DEFUN ("mod-test-vector-eq", Fmod_test_vector_eq, 2, 2, NULL, NULL); | 576 | DEFUN ("mod-test-vector-eq", Fmod_test_vector_eq, 2, 2, NULL, NULL); |
| 561 | DEFUN ("mod-test-invalid-store", Fmod_test_invalid_store, 0, 0, NULL, NULL); | 577 | DEFUN ("mod-test-invalid-store", Fmod_test_invalid_store, 0, 0, NULL, NULL); |
| 578 | DEFUN ("mod-test-invalid-store-copy", Fmod_test_invalid_store_copy, 0, 0, | ||
| 579 | NULL, NULL); | ||
| 562 | DEFUN ("mod-test-invalid-load", Fmod_test_invalid_load, 0, 0, NULL, NULL); | 580 | DEFUN ("mod-test-invalid-load", Fmod_test_invalid_load, 0, 0, NULL, NULL); |
| 563 | DEFUN ("mod-test-invalid-finalizer", Fmod_test_invalid_finalizer, 0, 0, | 581 | DEFUN ("mod-test-invalid-finalizer", Fmod_test_invalid_finalizer, 0, 0, |
| 564 | NULL, NULL); | 582 | NULL, NULL); |
diff --git a/test/src/emacs-module-tests.el b/test/src/emacs-module-tests.el index 6f14d4f7fa3..de707a4243a 100644 --- a/test/src/emacs-module-tests.el +++ b/test/src/emacs-module-tests.el | |||
| @@ -270,6 +270,24 @@ must evaluate to a regular expression string." | |||
| 270 | (mod-test-invalid-store) | 270 | (mod-test-invalid-store) |
| 271 | (mod-test-invalid-load))) | 271 | (mod-test-invalid-load))) |
| 272 | 272 | ||
| 273 | (ert-deftest module--test-assertions--load-non-live-object-with-global-copy () | ||
| 274 | "Check that -module-assertions verify that non-live objects aren't accessed. | ||
| 275 | This differs from `module--test-assertions-load-non-live-object' | ||
| 276 | in that it stows away a global reference. The module assertions | ||
| 277 | should nevertheless detect the invalid load." | ||
| 278 | (skip-unless (or (file-executable-p mod-test-emacs) | ||
| 279 | (and (eq system-type 'windows-nt) | ||
| 280 | (file-executable-p (concat mod-test-emacs ".exe"))))) | ||
| 281 | ;; This doesn't yet cause undefined behavior. | ||
| 282 | (should (eq (mod-test-invalid-store-copy) 123)) | ||
| 283 | (module--test-assertion (rx "Emacs value not found in " | ||
| 284 | (+ digit) " values of " | ||
| 285 | (+ digit) " environments\n") | ||
| 286 | ;; Storing and reloading a local value causes undefined behavior, | ||
| 287 | ;; which should be detected by the module assertions. | ||
| 288 | (mod-test-invalid-store-copy) | ||
| 289 | (mod-test-invalid-load))) | ||
| 290 | |||
| 273 | (ert-deftest module--test-assertions--call-emacs-from-gc () | 291 | (ert-deftest module--test-assertions--call-emacs-from-gc () |
| 274 | "Check that -module-assertions prevents calling Emacs functions | 292 | "Check that -module-assertions prevents calling Emacs functions |
| 275 | during garbage collection." | 293 | during garbage collection." |