aboutsummaryrefslogtreecommitdiffstats
path: root/test/data
diff options
context:
space:
mode:
authorStefan Kangas2020-10-23 16:29:46 +0200
committerStefan Kangas2020-10-23 16:29:46 +0200
commit49bc8586b7abc8e1e36027ca5eec0d0488a27474 (patch)
treedd3d9c8a4eb7e85205ee7565d01c91ca21ef79ec /test/data
parentd21cdb6c056453d4e4ef8a3a1f27d8bc203c09ea (diff)
downloademacs-49bc8586b7abc8e1e36027ca5eec0d0488a27474.tar.gz
emacs-49bc8586b7abc8e1e36027ca5eec0d0488a27474.zip
Move some test data to follow our conventions
* test/data/emacs-module/mod-test.c: Move from here... * test/src/emacs-module-resources/mod-test.c: ...to here. * test/src/emacs-module-tests.el (ert-x): Require. (mod-test-file, module/describe-function-1): * test/Makefile.in (test_module_dir): Adjust for move. * test/data/files-bug18141.el.gz: Move from here... * test/lisp/files-resources/files-bug18141.el.gz: ... to here. * test/lisp/files-tests.el (ert-x): Require. (files-test-bug-18141-file): Use ert-resource-file. * test/data/mailcap/mime.types: Move from here... * test/lisp/net/mailcap-resources/mime.types: ...to here. * test/lisp/net/mailcap-tests.el (ert-x): Require. (mailcap-tests-path): Use ert-resource-file. * test/data/somelib.el: * test/data/somelib2.el: Move from here... * test/src/lread-resources/somelib.el: * test/src/lread-resources/somelib2.el: ...to here. * test/src/lread-tests.el (ert, ert-x): Require. (lread-test-bug26837): Use ert-resource-directory. * test/data/syntax-comments.txt: Move from here.... * test/src/syntax-resources/syntax-comments.txt: ...to here. * test/src/syntax-tests.el (ert-x): Require. (syntax-comments, syntax-br-comments, syntax-pps-comments): Use ert-resource-file. * test/data/xref/file1.txt: * test/data/xref/file2.txt: Move from here... * test/lisp/progmodes/xref-resources/file1.txt: * test/lisp/progmodes/xref-resources/file2.txt: ...to here. * test/lisp/progmodes/xref-tests.el (ert, ert-x): Require. (xref-tests-data-dir): Use ert-resource-directory.
Diffstat (limited to 'test/data')
-rw-r--r--test/data/emacs-module/mod-test.c801
-rw-r--r--test/data/files-bug18141.el.gzbin77 -> 0 bytes
-rw-r--r--test/data/mailcap/mime.types5
-rw-r--r--test/data/somelib.el7
-rw-r--r--test/data/somelib2.el7
-rw-r--r--test/data/syntax-comments.txt68
-rw-r--r--test/data/xref/file1.txt2
-rw-r--r--test/data/xref/file2.txt2
8 files changed, 0 insertions, 892 deletions
diff --git a/test/data/emacs-module/mod-test.c b/test/data/emacs-module/mod-test.c
deleted file mode 100644
index 258a679b207..00000000000
--- a/test/data/emacs-module/mod-test.c
+++ /dev/null
@@ -1,801 +0,0 @@
1/* Test GNU Emacs modules.
2
3Copyright 2015-2020 Free Software Foundation, Inc.
4
5This file is part of GNU Emacs.
6
7GNU Emacs is free software: you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation, either version 3 of the License, or (at
10your option) any later version.
11
12GNU Emacs is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
19
20#include "config.h"
21
22#undef NDEBUG
23#include <assert.h>
24
25#include <errno.h>
26#include <limits.h>
27#include <stdint.h>
28#include <stdio.h>
29#include <stdlib.h>
30#include <string.h>
31#include <time.h>
32
33#ifdef WINDOWSNT
34/* Cannot include <process.h> because of the local header by the same
35 name, sigh. */
36uintptr_t _beginthread (void (__cdecl *)(void *), unsigned, void *);
37# if !defined __x86_64__
38# define ALIGN_STACK __attribute__((force_align_arg_pointer))
39# endif
40# include <windows.h> /* for Sleep */
41#else /* !WINDOWSNT */
42# include <pthread.h>
43# include <unistd.h>
44#endif
45
46#include <gmp.h>
47#include <emacs-module.h>
48
49#include "timespec.h"
50
51int plugin_is_GPL_compatible;
52
53#if INTPTR_MAX <= 0
54# error "INTPTR_MAX misconfigured"
55#elif INTPTR_MAX <= INT_MAX || INTPTR_MAX <= LONG_MAX
56# define pT "ld"
57# define pZ "lu"
58# define T_TYPE long
59# define Z_TYPE unsigned long
60#elif INTPTR_MAX <= INT64_MAX
61# ifdef __MINGW32__
62# define pT "lld"
63# define pZ "llu"
64# define T_TYPE long long
65# define Z_TYPE unsigned long long
66# else
67# define pT "ld"
68# define pZ "lu"
69# define T_TYPE long
70# define Z_TYPE unsigned long
71# endif
72#else
73# error "INTPTR_MAX too large"
74#endif
75
76/* Smoke test to verify that EMACS_LIMB_MAX is defined. */
77_Static_assert (0 < EMACS_LIMB_MAX, "EMACS_LIMB_MAX missing or incorrect");
78
79/* Always return symbol 't'. */
80static emacs_value
81Fmod_test_return_t (emacs_env *env, ptrdiff_t nargs, emacs_value args[],
82 void *data)
83{
84 return env->intern (env, "t");
85}
86
87/* Expose simple sum function. */
88static intmax_t
89sum (intmax_t a, intmax_t b)
90{
91 return a + b;
92}
93
94static emacs_value
95Fmod_test_sum (emacs_env *env, ptrdiff_t nargs, emacs_value args[], void *data)
96{
97 assert (nargs == 2);
98 assert ((uintptr_t) data == 0x1234);
99
100 intmax_t a = env->extract_integer (env, args[0]);
101 intmax_t b = env->extract_integer (env, args[1]);
102
103 intmax_t r = sum (a, b);
104
105 return env->make_integer (env, r);
106}
107
108
109/* Signal '(error 56). */
110static emacs_value
111Fmod_test_signal (emacs_env *env, ptrdiff_t nargs, emacs_value args[],
112 void *data)
113{
114 assert (env->non_local_exit_check (env) == emacs_funcall_exit_return);
115 env->non_local_exit_signal (env, env->intern (env, "error"),
116 env->make_integer (env, 56));
117 return NULL;
118}
119
120
121/* Throw '(tag 65). */
122static emacs_value
123Fmod_test_throw (emacs_env *env, ptrdiff_t nargs, emacs_value args[],
124 void *data)
125{
126 assert (env->non_local_exit_check (env) == emacs_funcall_exit_return);
127 env->non_local_exit_throw (env, env->intern (env, "tag"),
128 env->make_integer (env, 65));
129 return NULL;
130}
131
132
133/* Call argument function, catch all non-local exists and return
134 either normal result or a list describing the non-local exit. */
135static emacs_value
136Fmod_test_non_local_exit_funcall (emacs_env *env, ptrdiff_t nargs,
137 emacs_value args[], void *data)
138{
139 assert (nargs == 1);
140 emacs_value result = env->funcall (env, args[0], 0, NULL);
141 emacs_value non_local_exit_symbol, non_local_exit_data;
142 enum emacs_funcall_exit code
143 = env->non_local_exit_get (env, &non_local_exit_symbol,
144 &non_local_exit_data);
145 switch (code)
146 {
147 case emacs_funcall_exit_return:
148 return result;
149 case emacs_funcall_exit_signal:
150 {
151 env->non_local_exit_clear (env);
152 emacs_value Flist = env->intern (env, "list");
153 emacs_value list_args[] = {env->intern (env, "signal"),
154 non_local_exit_symbol, non_local_exit_data};
155 return env->funcall (env, Flist, 3, list_args);
156 }
157 case emacs_funcall_exit_throw:
158 {
159 env->non_local_exit_clear (env);
160 emacs_value Flist = env->intern (env, "list");
161 emacs_value list_args[] = {env->intern (env, "throw"),
162 non_local_exit_symbol, non_local_exit_data};
163 return env->funcall (env, Flist, 3, list_args);
164 }
165 }
166
167 /* Never reached. */
168 return env->intern (env, "nil");;
169}
170
171
172/* Return a global reference. */
173static emacs_value
174Fmod_test_globref_make (emacs_env *env, ptrdiff_t nargs, emacs_value args[],
175 void *data)
176{
177 /* Make a big string and make it global. */
178 char str[26 * 100];
179 for (int i = 0; i < sizeof str; i++)
180 str[i] = 'a' + (i % 26);
181
182 /* We don't need to null-terminate str. */
183 emacs_value lisp_str = env->make_string (env, str, sizeof str);
184 return env->make_global_ref (env, lisp_str);
185}
186
187/* Create a few global references from arguments and free them. */
188static emacs_value
189Fmod_test_globref_free (emacs_env *env, ptrdiff_t nargs, emacs_value args[],
190 void *data)
191{
192 emacs_value refs[10];
193 for (int i = 0; i < 10; i++)
194 {
195 refs[i] = env->make_global_ref (env, args[i % nargs]);
196 }
197 for (int i = 0; i < 10; i++)
198 {
199 env->free_global_ref (env, refs[i]);
200 }
201 return env->intern (env, "ok");
202}
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. */
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}
217
218/* Allocate and free global references in a different order. */
219
220static emacs_value
221Fmod_test_globref_reordered (emacs_env *env, ptrdiff_t nargs,
222 emacs_value *args, void *data)
223{
224 emacs_value booleans[2] = {
225 env->intern (env, "nil"),
226 env->intern (env, "t"),
227 };
228 emacs_value local = env->intern (env, "foo");
229 emacs_value globals[4] = {
230 env->make_global_ref (env, local),
231 env->make_global_ref (env, local),
232 env->make_global_ref (env, env->intern (env, "foo")),
233 env->make_global_ref (env, env->intern (env, "bar")),
234 };
235 emacs_value elements[4];
236 for (int i = 0; i < 4; ++i)
237 elements[i] = booleans[env->eq (env, globals[i], local)];
238 emacs_value ret = env->funcall (env, env->intern (env, "list"), 4, elements);
239 env->free_global_ref (env, globals[2]);
240 env->free_global_ref (env, globals[1]);
241 env->free_global_ref (env, globals[3]);
242 env->free_global_ref (env, globals[0]);
243 return ret;
244}
245
246
247/* Return a copy of the argument string where every 'a' is replaced
248 with 'b'. */
249static emacs_value
250Fmod_test_string_a_to_b (emacs_env *env, ptrdiff_t nargs, emacs_value args[],
251 void *data)
252{
253 emacs_value lisp_str = args[0];
254 ptrdiff_t size = 0;
255 char * buf = NULL;
256
257 env->copy_string_contents (env, lisp_str, buf, &size);
258 buf = malloc (size);
259 env->copy_string_contents (env, lisp_str, buf, &size);
260
261 for (ptrdiff_t i = 0; i + 1 < size; i++)
262 if (buf[i] == 'a')
263 buf[i] = 'b';
264
265 emacs_value ret = env->make_string (env, buf, size - 1);
266 free (buf);
267 return ret;
268}
269
270
271/* Return a unibyte string. */
272static emacs_value
273Fmod_test_return_unibyte (emacs_env *env, ptrdiff_t nargs, emacs_value args[],
274 void *data)
275{
276 const char *string = "foo\x00zot";
277 return env->make_unibyte_string (env, string, 7);
278}
279
280
281/* Embedded pointers in lisp objects. */
282
283/* C struct (pointer to) that will be embedded. */
284struct super_struct
285{
286 int amazing_int;
287 char large_unused_buffer[512];
288};
289
290/* Return a new user-pointer to a super_struct, with amazing_int set
291 to the passed parameter. */
292static emacs_value
293Fmod_test_userptr_make (emacs_env *env, ptrdiff_t nargs, emacs_value args[],
294 void *data)
295{
296 struct super_struct *p = calloc (1, sizeof *p);
297 p->amazing_int = env->extract_integer (env, args[0]);
298 return env->make_user_ptr (env, free, p);
299}
300
301/* Return the amazing_int of a passed 'user-pointer to a super_struct'. */
302static emacs_value
303Fmod_test_userptr_get (emacs_env *env, ptrdiff_t nargs, emacs_value args[],
304 void *data)
305{
306 struct super_struct *p = env->get_user_ptr (env, args[0]);
307 return env->make_integer (env, p->amazing_int);
308}
309
310
311/* Fill vector in args[0] with value in args[1]. */
312static emacs_value
313Fmod_test_vector_fill (emacs_env *env, ptrdiff_t nargs, emacs_value args[],
314 void *data)
315{
316 emacs_value vec = args[0];
317 emacs_value val = args[1];
318 ptrdiff_t size = env->vec_size (env, vec);
319 for (ptrdiff_t i = 0; i < size; i++)
320 env->vec_set (env, vec, i, val);
321 return env->intern (env, "t");
322}
323
324
325/* Return whether all elements of vector in args[0] are 'eq' to value
326 in args[1]. */
327static emacs_value
328Fmod_test_vector_eq (emacs_env *env, ptrdiff_t nargs, emacs_value args[],
329 void *data)
330{
331 emacs_value vec = args[0];
332 emacs_value val = args[1];
333 ptrdiff_t size = env->vec_size (env, vec);
334 for (ptrdiff_t i = 0; i < size; i++)
335 if (!env->eq (env, env->vec_get (env, vec, i), val))
336 return env->intern (env, "nil");
337 return env->intern (env, "t");
338}
339
340static emacs_value invalid_stored_value;
341
342/* The next two functions perform a possibly-invalid operation: they
343 store a value in a static variable and load it. This causes
344 undefined behavior if the environment that the value was created
345 from is no longer live. The module assertions check for this
346 error. */
347
348static emacs_value
349Fmod_test_invalid_store (emacs_env *env, ptrdiff_t nargs, emacs_value *args,
350 void *data)
351{
352 return invalid_stored_value = env->make_integer (env, 123);
353}
354
355static emacs_value
356Fmod_test_invalid_load (emacs_env *env, ptrdiff_t nargs, emacs_value *args,
357 void *data)
358{
359 return invalid_stored_value;
360}
361
362/* The next function works in conjunction with the two previous ones.
363 It stows away a copy of the object created by
364 `Fmod_test_invalid_store' in a global reference. Module assertions
365 should still detect the invalid load of the local reference. */
366
367static emacs_value global_copy_of_invalid_stored_value;
368
369static emacs_value
370Fmod_test_invalid_store_copy (emacs_env *env, ptrdiff_t nargs,
371 emacs_value *args, void *data)
372{
373 emacs_value local = Fmod_test_invalid_store (env, 0, NULL, NULL);
374 return global_copy_of_invalid_stored_value
375 = env->make_global_ref (env, local);
376}
377
378/* An invalid finalizer: Finalizers are run during garbage collection,
379 where Lisp code can't be executed. -module-assertions tests for
380 this case. */
381
382static emacs_env *current_env;
383
384static void
385invalid_finalizer (void *ptr)
386{
387 current_env->intern (current_env, "nil");
388}
389
390static emacs_value
391Fmod_test_invalid_finalizer (emacs_env *env, ptrdiff_t nargs, emacs_value *args,
392 void *data)
393{
394 current_env = env;
395 env->make_user_ptr (env, invalid_finalizer, NULL);
396 return env->intern (env, "nil");
397}
398
399static void
400signal_system_error (emacs_env *env, int error, const char *function)
401{
402 const char *message = strerror (error);
403 emacs_value message_value = env->make_string (env, message, strlen (message));
404 emacs_value symbol = env->intern (env, "file-error");
405 emacs_value elements[2]
406 = {env->make_string (env, function, strlen (function)), message_value};
407 emacs_value data = env->funcall (env, env->intern (env, "list"), 2, elements);
408 env->non_local_exit_signal (env, symbol, data);
409}
410
411static void
412signal_errno (emacs_env *env, const char *function)
413{
414 signal_system_error (env, errno, function);
415}
416
417/* A long-running operation that occasionally calls `should_quit' or
418 `process_input'. */
419
420static emacs_value
421Fmod_test_sleep_until (emacs_env *env, ptrdiff_t nargs, emacs_value *args,
422 void *data)
423{
424 assert (nargs == 2);
425 const struct timespec until = env->extract_time (env, args[0]);
426 if (env->non_local_exit_check (env))
427 return NULL;
428 const bool process_input = env->is_not_nil (env, args[1]);
429 const struct timespec amount = make_timespec(0, 10000000);
430 while (true)
431 {
432 const struct timespec now = current_timespec ();
433 if (timespec_cmp (now, until) >= 0)
434 break;
435 if (nanosleep (&amount, NULL) && errno != EINTR)
436 {
437 signal_errno (env, "nanosleep");
438 return NULL;
439 }
440 if ((process_input
441 && env->process_input (env) == emacs_process_input_quit)
442 || env->should_quit (env))
443 return NULL;
444 }
445 return env->intern (env, "finished");
446}
447
448static emacs_value
449Fmod_test_add_nanosecond (emacs_env *env, ptrdiff_t nargs, emacs_value *args,
450 void *data)
451{
452 assert (nargs == 1);
453 struct timespec time = env->extract_time (env, args[0]);
454 assert (time.tv_nsec >= 0);
455 assert (time.tv_nsec < 2000000000); /* possible leap second */
456 time.tv_nsec++;
457 return env->make_time (env, time);
458}
459
460static void
461signal_error (emacs_env *env, const char *message)
462{
463 emacs_value data = env->make_string (env, message, strlen (message));
464 env->non_local_exit_signal (env, env->intern (env, "error"),
465 env->funcall (env, env->intern (env, "list"), 1,
466 &data));
467}
468
469static void
470memory_full (emacs_env *env)
471{
472 signal_error (env, "Memory exhausted");
473}
474
475enum
476{
477 max_count = ((SIZE_MAX < PTRDIFF_MAX ? SIZE_MAX : PTRDIFF_MAX)
478 / sizeof (emacs_limb_t))
479};
480
481static bool
482extract_big_integer (emacs_env *env, emacs_value arg, mpz_t result)
483{
484 int sign;
485 ptrdiff_t count;
486 bool success = env->extract_big_integer (env, arg, &sign, &count, NULL);
487 if (!success)
488 return false;
489 if (sign == 0)
490 {
491 mpz_set_ui (result, 0);
492 return true;
493 }
494 enum { order = -1, size = sizeof (emacs_limb_t), endian = 0, nails = 0 };
495 assert (0 < count && count <= max_count);
496 emacs_limb_t *magnitude = malloc (count * size);
497 if (magnitude == NULL)
498 {
499 memory_full (env);
500 return false;
501 }
502 success = env->extract_big_integer (env, arg, NULL, &count, magnitude);
503 assert (success);
504 mpz_import (result, count, order, size, endian, nails, magnitude);
505 free (magnitude);
506 if (sign < 0)
507 mpz_neg (result, result);
508 return true;
509}
510
511static emacs_value
512make_big_integer (emacs_env *env, const mpz_t value)
513{
514 if (mpz_sgn (value) == 0)
515 return env->make_integer (env, 0);
516 /* See
517 https://gmplib.org/manual/Integer-Import-and-Export.html#index-Export. */
518 enum
519 {
520 order = -1,
521 size = sizeof (emacs_limb_t),
522 endian = 0,
523 nails = 0,
524 numb = 8 * size - nails
525 };
526 size_t count = (mpz_sizeinbase (value, 2) + numb - 1) / numb;
527 if (max_count < count)
528 {
529 memory_full (env);
530 return NULL;
531 }
532 emacs_limb_t *magnitude = malloc (count * size);
533 if (magnitude == NULL)
534 {
535 memory_full (env);
536 return NULL;
537 }
538 size_t written;
539 mpz_export (magnitude, &written, order, size, endian, nails, value);
540 assert (written == count);
541 assert (count <= PTRDIFF_MAX);
542 emacs_value result = env->make_big_integer (env, mpz_sgn (value),
543 (ptrdiff_t) count, magnitude);
544 free (magnitude);
545 return result;
546}
547
548static emacs_value
549Fmod_test_nanoseconds (emacs_env *env, ptrdiff_t nargs, emacs_value *args, void *data) {
550 assert (nargs == 1);
551 struct timespec time = env->extract_time (env, args[0]);
552 mpz_t nanoseconds;
553 assert (LONG_MIN <= time.tv_sec && time.tv_sec <= LONG_MAX);
554 mpz_init_set_si (nanoseconds, time.tv_sec);
555#ifdef __MINGW32__
556 _Static_assert (1000000000 <= ULONG_MAX, "unsupported architecture");
557#else
558 static_assert (1000000000 <= ULONG_MAX, "unsupported architecture");
559#endif
560 mpz_mul_ui (nanoseconds, nanoseconds, 1000000000);
561 assert (0 <= time.tv_nsec && time.tv_nsec <= ULONG_MAX);
562 mpz_add_ui (nanoseconds, nanoseconds, time.tv_nsec);
563 emacs_value result = make_big_integer (env, nanoseconds);
564 mpz_clear (nanoseconds);
565 return result;
566}
567
568static emacs_value
569Fmod_test_double (emacs_env *env, ptrdiff_t nargs, emacs_value *args,
570 void *data)
571{
572 assert (nargs == 1);
573 emacs_value arg = args[0];
574 mpz_t value;
575 mpz_init (value);
576 extract_big_integer (env, arg, value);
577 mpz_mul_ui (value, value, 2);
578 emacs_value result = make_big_integer (env, value);
579 mpz_clear (value);
580 return result;
581}
582
583static int function_data;
584static int finalizer_calls_with_correct_data;
585static int finalizer_calls_with_incorrect_data;
586
587static void
588finalizer (void *data)
589{
590 if (data == &function_data)
591 ++finalizer_calls_with_correct_data;
592 else
593 ++finalizer_calls_with_incorrect_data;
594}
595
596static emacs_value
597Fmod_test_make_function_with_finalizer (emacs_env *env, ptrdiff_t nargs,
598 emacs_value *args, void *data)
599{
600 emacs_value fun
601 = env->make_function (env, 2, 2, Fmod_test_sum, NULL, &function_data);
602 env->set_function_finalizer (env, fun, finalizer);
603 if (env->get_function_finalizer (env, fun) != finalizer)
604 signal_error (env, "Invalid finalizer");
605 return fun;
606}
607
608static emacs_value
609Fmod_test_function_finalizer_calls (emacs_env *env, ptrdiff_t nargs,
610 emacs_value *args, void *data)
611{
612 emacs_value Flist = env->intern (env, "list");
613 emacs_value list_args[]
614 = {env->make_integer (env, finalizer_calls_with_correct_data),
615 env->make_integer (env, finalizer_calls_with_incorrect_data)};
616 return env->funcall (env, Flist, 2, list_args);
617}
618
619static void
620sleep_for_half_second (void)
621{
622 /* mingw.org's MinGW has nanosleep, but MinGW64 doesn't. */
623#ifdef WINDOWSNT
624 Sleep (500);
625#else
626 const struct timespec sleep = {0, 500000000};
627 if (nanosleep (&sleep, NULL) != 0)
628 perror ("nanosleep");
629#endif
630}
631
632#ifdef WINDOWSNT
633static void ALIGN_STACK
634#else
635static void *
636#endif
637write_to_pipe (void *arg)
638{
639 /* We sleep a bit to test that writing to a pipe is indeed possible
640 if no environment is active. */
641 sleep_for_half_second ();
642 FILE *stream = arg;
643 /* The string below should be identical to the one we compare with
644 in emacs-module-tests.el:module/async-pipe. */
645 if (fputs ("data from thread", stream) < 0)
646 perror ("fputs");
647 if (fclose (stream) != 0)
648 perror ("close");
649#ifndef WINDOWSNT
650 return NULL;
651#endif
652}
653
654static emacs_value
655Fmod_test_async_pipe (emacs_env *env, ptrdiff_t nargs, emacs_value *args,
656 void *data)
657{
658 assert (nargs == 1);
659 int fd = env->open_channel (env, args[0]);
660 if (env->non_local_exit_check (env) != emacs_funcall_exit_return)
661 return NULL;
662 FILE *stream = fdopen (fd, "w");
663 if (stream == NULL)
664 {
665 signal_errno (env, "fdopen");
666 return NULL;
667 }
668#ifdef WINDOWSNT
669 uintptr_t thd = _beginthread (write_to_pipe, 0, stream);
670 int error = (thd == (uintptr_t)-1L) ? errno : 0;
671#else /* !WINDOWSNT */
672 pthread_t thread;
673 int error
674 = pthread_create (&thread, NULL, write_to_pipe, stream);
675#endif
676 if (error != 0)
677 {
678 signal_system_error (env, error, "thread create");
679 if (fclose (stream) != 0)
680 perror ("fclose");
681 return NULL;
682 }
683 return env->intern (env, "nil");
684}
685
686static emacs_value
687Fmod_test_identity (emacs_env *env, ptrdiff_t nargs, emacs_value *args,
688 void *data)
689{
690 assert (nargs == 1);
691 return args[0];
692}
693
694/* Lisp utilities for easier readability (simple wrappers). */
695
696/* Provide FEATURE to Emacs. */
697static void
698provide (emacs_env *env, const char *feature)
699{
700 emacs_value Qfeat = env->intern (env, feature);
701 emacs_value Qprovide = env->intern (env, "provide");
702 emacs_value args[] = { Qfeat };
703
704 env->funcall (env, Qprovide, 1, args);
705}
706
707/* Bind NAME to FUN. */
708static void
709bind_function (emacs_env *env, const char *name, emacs_value Sfun)
710{
711 emacs_value Qdefalias = env->intern (env, "defalias");
712 emacs_value Qsym = env->intern (env, name);
713 emacs_value args[] = { Qsym, Sfun };
714
715 env->funcall (env, Qdefalias, 2, args);
716}
717
718/* Module init function. */
719int
720emacs_module_init (struct emacs_runtime *ert)
721{
722 /* Check that EMACS_MAJOR_VERSION is defined and an integral
723 constant. */
724 char dummy[EMACS_MAJOR_VERSION];
725 assert (27 <= sizeof dummy);
726
727 if (ert->size < sizeof *ert)
728 {
729 fprintf (stderr, "Runtime size of runtime structure (%"pT" bytes) "
730 "smaller than compile-time size (%"pZ" bytes)",
731 (T_TYPE) ert->size, (Z_TYPE) sizeof (*ert));
732 return 1;
733 }
734
735 emacs_env *env = ert->get_environment (ert);
736
737 if (env->size < sizeof *env)
738 {
739 fprintf (stderr, "Runtime size of environment structure (%"pT" bytes) "
740 "smaller than compile-time size (%"pZ" bytes)",
741 (T_TYPE) env->size, (Z_TYPE) sizeof (*env));
742 return 2;
743 }
744
745#define DEFUN(lsym, csym, amin, amax, doc, data) \
746 bind_function (env, lsym, \
747 env->make_function (env, amin, amax, csym, doc, data))
748
749 DEFUN ("mod-test-return-t", Fmod_test_return_t, 1, 1, NULL, NULL);
750 DEFUN ("mod-test-sum", Fmod_test_sum, 2, 2, "Return A + B\n\n(fn a b)",
751 (void *) (uintptr_t) 0x1234);
752 DEFUN ("mod-test-signal", Fmod_test_signal, 0, 0, NULL, NULL);
753 DEFUN ("mod-test-throw", Fmod_test_throw, 0, 0, NULL, NULL);
754 DEFUN ("mod-test-non-local-exit-funcall", Fmod_test_non_local_exit_funcall,
755 1, 1, NULL, NULL);
756 DEFUN ("mod-test-globref-make", Fmod_test_globref_make, 0, 0, NULL, NULL);
757 DEFUN ("mod-test-globref-free", Fmod_test_globref_free, 4, 4, NULL, NULL);
758 DEFUN ("mod-test-globref-invalid-free", Fmod_test_globref_invalid_free, 0, 0,
759 NULL, NULL);
760 DEFUN ("mod-test-globref-reordered", Fmod_test_globref_reordered, 0, 0, NULL,
761 NULL);
762 DEFUN ("mod-test-string-a-to-b", Fmod_test_string_a_to_b, 1, 1, NULL, NULL);
763 DEFUN ("mod-test-return-unibyte", Fmod_test_return_unibyte, 0, 0, NULL, NULL);
764 DEFUN ("mod-test-userptr-make", Fmod_test_userptr_make, 1, 1, NULL, NULL);
765 DEFUN ("mod-test-userptr-get", Fmod_test_userptr_get, 1, 1, NULL, NULL);
766 DEFUN ("mod-test-vector-fill", Fmod_test_vector_fill, 2, 2, NULL, NULL);
767 DEFUN ("mod-test-vector-eq", Fmod_test_vector_eq, 2, 2, NULL, NULL);
768 DEFUN ("mod-test-invalid-store", Fmod_test_invalid_store, 0, 0, NULL, NULL);
769 DEFUN ("mod-test-invalid-store-copy", Fmod_test_invalid_store_copy, 0, 0,
770 NULL, NULL);
771 DEFUN ("mod-test-invalid-load", Fmod_test_invalid_load, 0, 0, NULL, NULL);
772 DEFUN ("mod-test-invalid-finalizer", Fmod_test_invalid_finalizer, 0, 0,
773 NULL, NULL);
774 DEFUN ("mod-test-sleep-until", Fmod_test_sleep_until, 2, 2, NULL, NULL);
775 DEFUN ("mod-test-add-nanosecond", Fmod_test_add_nanosecond, 1, 1, NULL, NULL);
776 DEFUN ("mod-test-nanoseconds", Fmod_test_nanoseconds, 1, 1, NULL, NULL);
777 DEFUN ("mod-test-double", Fmod_test_double, 1, 1, NULL, NULL);
778 DEFUN ("mod-test-make-function-with-finalizer",
779 Fmod_test_make_function_with_finalizer, 0, 0, NULL, NULL);
780 DEFUN ("mod-test-function-finalizer-calls",
781 Fmod_test_function_finalizer_calls, 0, 0, NULL, NULL);
782 DEFUN ("mod-test-async-pipe", Fmod_test_async_pipe, 1, 1, NULL, NULL);
783
784#undef DEFUN
785
786 emacs_value constant_fn
787 = env->make_function (env, 0, 0, Fmod_test_return_t, NULL, NULL);
788 env->make_interactive (env, constant_fn, env->intern (env, "nil"));
789 bind_function (env, "mod-test-return-t-int", constant_fn);
790
791 emacs_value identity_fn
792 = env->make_function (env, 1, 1, Fmod_test_identity, NULL, NULL);
793 const char *interactive_spec = "i";
794 env->make_interactive (env, identity_fn,
795 env->make_string (env, interactive_spec,
796 strlen (interactive_spec)));
797 bind_function (env, "mod-test-identity", identity_fn);
798
799 provide (env, "mod-test");
800 return 0;
801}
diff --git a/test/data/files-bug18141.el.gz b/test/data/files-bug18141.el.gz
deleted file mode 100644
index 53d463e85b5..00000000000
--- a/test/data/files-bug18141.el.gz
+++ /dev/null
Binary files differ
diff --git a/test/data/mailcap/mime.types b/test/data/mailcap/mime.types
deleted file mode 100644
index 4bedfaf9702..00000000000
--- a/test/data/mailcap/mime.types
+++ /dev/null
@@ -1,5 +0,0 @@
1# this is a comment
2
3audio/ogg opus
4audio/flac flac
5audio/x-wav wav
diff --git a/test/data/somelib.el b/test/data/somelib.el
deleted file mode 100644
index 7b8d4037396..00000000000
--- a/test/data/somelib.el
+++ /dev/null
@@ -1,7 +0,0 @@
1;;; -*- lexical-binding: t; -*-
2
3;; blah
4
5(defun somefunc () t)
6
7(provide 'somelib)
diff --git a/test/data/somelib2.el b/test/data/somelib2.el
deleted file mode 100644
index 05156145a22..00000000000
--- a/test/data/somelib2.el
+++ /dev/null
@@ -1,7 +0,0 @@
1;;; -*- lexical-binding: t; -*-
2
3;; blah
4
5(defun somefunc2 () t)
6
7(provide 'somelib2)
diff --git a/test/data/syntax-comments.txt b/test/data/syntax-comments.txt
deleted file mode 100644
index 6f595e4d8dc..00000000000
--- a/test/data/syntax-comments.txt
+++ /dev/null
@@ -1,68 +0,0 @@
1/* This file is a test file for tests of the comment handling in src/syntax.c.
2 This includes the testing of comments which figure in parse-partial-sexp
3 and scan-lists. */
4
5/* Straight C comments */
61/* comment */1
72/**/2
83// comment
93
104//
114
125/*/5
136*/6
147/* \*/7
158*/8
169/* \\*/9
1710*/10
1811// \
1912
2011
2113// \\
2214
2313
2415/* /*/15
25
26/* C Comments within lists */
2759}59
2850{ /*70 comment */71 }50
2951{ /**/ }51
3052{ //72 comment
3173}52
3253{ //
33}53
3454{ //74 \
35}54
3655{/* */}55
3756{ /*76 \*/ }56
3857*/77
3958}58
4060{ /*78 \\*/79}60
41
42
43/* Straight Pascal comments (not nested) */
4420}20
4521{ Comment }21
4622{}22
4723{
48}23
4924{
5025{25
51}24
5226{ \}26
53
54
55/* Straight Lisp comments (not nested) */
5630
5730
5831; Comment
5931
6032;;;;;;;;;
6132
6233; \
6333
64
65Local Variables:
66mode: fundamental
67eval: (set-syntax-table (make-syntax-table))
68End:
diff --git a/test/data/xref/file1.txt b/test/data/xref/file1.txt
deleted file mode 100644
index 5d7cc544443..00000000000
--- a/test/data/xref/file1.txt
+++ /dev/null
@@ -1,2 +0,0 @@
1foo foo
2bar
diff --git a/test/data/xref/file2.txt b/test/data/xref/file2.txt
deleted file mode 100644
index 9f075f26004..00000000000
--- a/test/data/xref/file2.txt
+++ /dev/null
@@ -1,2 +0,0 @@
1
2bar