1 /* PSPP - a program for statistical analysis.
2 Copyright (C) 2006, 2010 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17 /* This is a test program for the llx_* routines defined in
18 ll.c. This test program aims to be as comprehensive as
19 possible. "gcov -b" should report 100% coverage of lines and
20 branches in llx.c and llx.h. "valgrind --leak-check=yes
21 --show-reachable=yes" should give a clean report.
23 This test program depends only on ll.c, llx.c, and the
26 See ll-test.c for a similar program for the ll_* routines. */
32 #include <libpspp/llx.h>
37 /* Support preliminaries. */
38 #if __GNUC__ >= 2 && !defined UNUSED
39 #define UNUSED __attribute__ ((unused))
44 /* Exit with a failure code.
45 (Place a breakpoint on this function while debugging.) */
52 /* If OK is not true, prints a message about failure on the
53 current source file and the given LINE and terminates. */
55 check_func (bool ok, int line)
59 fprintf (stderr, "%s:%d: check failed\n", __FILE__, line);
64 /* Verifies that EXPR evaluates to true.
65 If not, prints a message citing the calling line number and
67 #define check(EXPR) check_func ((EXPR), __LINE__)
69 /* Prints a message about memory exhaustion and exits with a
74 printf ("virtual memory exhausted\n");
78 /* Allocates and returns N bytes of memory. */
94 /* Allocates and returns N * M bytes of memory. */
96 xnmalloc (size_t n, size_t m)
98 if ((size_t) -1 / m <= n)
100 return xmalloc (n * m);
103 /* Always returns a null pointer, failing allocation. */
105 null_allocate_node (void *aux UNUSED)
112 null_release_node (struct llx *llx UNUSED, void *aux UNUSED)
116 /* Memory manager that fails all allocations and does nothing on
118 static const struct llx_manager llx_null_mgr =
125 /* List type and support routines. */
127 /* Test data element. */
130 int x; /* Primary value. */
131 int y; /* Secondary value. */
136 /* Prints the elements in LIST. */
138 print_list (struct llx_list *list)
143 for (x = llx_head (list); x != llx_null (list); x = llx_next (x))
145 const struct element *e = llx_data (x);
146 printf (" %d", e->x);
151 /* Prints the value returned by PREDICATE given auxiliary data
152 AUX for each element in LIST. */
154 print_pred (struct llx_list *list,
155 llx_predicate_func *predicate, void *aux UNUSED)
160 for (x = llx_head (list); x != llx_null (list); x = llx_next (x))
161 printf (" %d", predicate (x, aux));
165 /* Prints the CNT numbers in VALUES. */
167 print_array (int values[], size_t cnt)
172 for (i = 0; i < cnt; i++)
173 printf (" %d", values[i]);
177 /* Compares the `x' values in A and B and returns a strcmp-type
178 return value. Verifies that AUX points to aux_data. */
180 compare_elements (const void *a_, const void *b_, void *aux)
182 const struct element *a = a_;
183 const struct element *b = b_;
185 check (aux == &aux_data);
186 return a->x < b->x ? -1 : a->x > b->x;
189 /* Compares the `x' and `y' values in A and B and returns a
190 strcmp-type return value. Verifies that AUX points to
193 compare_elements_x_y (const void *a_, const void *b_, void *aux)
195 const struct element *a = a_;
196 const struct element *b = b_;
198 check (aux == &aux_data);
200 return a->x < b->x ? -1 : 1;
201 else if (a->y != b->y)
202 return a->y < b->y ? -1 : 1;
207 /* Compares the `y' values in A and B and returns a strcmp-type
208 return value. Verifies that AUX points to aux_data. */
210 compare_elements_y (const void *a_, const void *b_, void *aux)
212 const struct element *a = a_;
213 const struct element *b = b_;
215 check (aux == &aux_data);
216 return a->y < b->y ? -1 : a->y > b->y;
219 /* Returns true if the bit in *PATTERN indicated by `x in
220 *ELEMENT is set, false otherwise. */
222 pattern_pred (const void *element_, void *pattern_)
224 const struct element *element = element_;
225 unsigned int *pattern = pattern_;
227 return (*pattern & (1u << element->x)) != 0;
230 /* Allocates N elements in *ELEMS.
231 Adds the elements to LIST, if it is nonnull.
232 Puts pointers to the elements' list elements in *ELEMP,
233 followed by a pointer to the list null element, if ELEMP is
235 Allocates space for N values in *VALUES, if VALUES is
238 allocate_elements (size_t n,
239 struct llx_list *list,
240 struct element ***elems,
249 *elems = xnmalloc (n, sizeof **elems);
252 *elemp = xnmalloc (n + 1, sizeof *elemp);
253 (*elemp)[n] = llx_null (list);
256 for (i = 0; i < n; i++)
258 (*elems)[i] = xmalloc (sizeof ***elems);
261 struct llx *llx = llx_push_tail (list, (*elems)[i], &llx_malloc_mgr);
268 *values = xnmalloc (n, sizeof *values);
271 /* Copies the CNT values of `x' from LIST into VALUES[]. */
273 extract_values (struct llx_list *list, int values[], size_t cnt)
277 check (llx_count (list) == cnt);
278 for (x = llx_head (list); x != llx_null (list); x = llx_next (x))
280 struct element *e = llx_data (x);
285 /* As allocate_elements, but sets ascending values, starting
286 from 0, in `x' values in *ELEMS and in *VALUES (if
289 allocate_ascending (size_t n,
290 struct llx_list *list,
291 struct element ***elems,
297 allocate_elements (n, list, elems, elemp, values);
299 for (i = 0; i < n; i++)
302 extract_values (list, *values, n);
305 /* As allocate_elements, but sets binary values extracted from
306 successive bits in PATTERN in `x' values in *ELEMS and in
307 *VALUES (if nonnull). */
309 allocate_pattern (size_t n,
311 struct llx_list *list,
312 struct element ***elems,
318 allocate_elements (n, list, elems, elemp, values);
320 for (i = 0; i < n; i++)
321 (*elems)[i]->x = (pattern & (1 << i)) != 0;
323 extract_values (list, *values, n);
326 /* Randomly shuffles the CNT elements in ARRAY, each of which is
327 SIZE bytes in size. */
329 random_shuffle (void *array_, size_t cnt, size_t size)
331 char *array = array_;
332 char *tmp = xmalloc (size);
335 for (i = 0; i < cnt; i++)
337 size_t j = rand () % (cnt - i) + i;
340 memcpy (tmp, array + j * size, size);
341 memcpy (array + j * size, array + i * size, size);
342 memcpy (array + i * size, tmp, size);
349 /* As allocate_ascending, but orders the values randomly. */
351 allocate_random (size_t n,
352 struct llx_list *list,
353 struct element ***elems,
359 allocate_elements (n, list, elems, elemp, values);
361 for (i = 0; i < n; i++)
363 random_shuffle (*elems, n, sizeof **elems);
365 extract_values (list, *values, n);
368 /* Frees LIST, the N elements of ELEMS, ELEMP, and VALUES. */
370 free_elements (size_t n,
371 struct llx_list *list,
372 struct element **elems,
379 llx_destroy (list, NULL, NULL, &llx_malloc_mgr);
380 for (i = 0; i < n; i++)
387 /* Compares A and B and returns a strcmp-type return value. */
389 compare_ints (const void *a_, const void *b_, void *aux UNUSED)
394 return *a < *b ? -1 : *a > *b;
397 /* Compares A and B and returns a strcmp-type return value. */
399 compare_ints_noaux (const void *a_, const void *b_)
404 return *a < *b ? -1 : *a > *b;
407 /* Checks that LIST contains the CNT values in ELEMENTS. */
409 check_list_contents (struct llx_list *list, int elements[], size_t cnt)
414 check ((cnt == 0) == llx_is_empty (list));
416 /* Iterate in forward order. */
417 for (llx = llx_head (list), i = 0; i < cnt; llx = llx_next (llx), i++)
419 struct element *e = llx_data (llx);
420 check (elements[i] == e->x);
421 check (llx != llx_null (list));
423 check (llx == llx_null (list));
425 /* Iterate in reverse order. */
426 for (llx = llx_tail (list), i = 0; i < cnt; llx = llx_prev (llx), i++)
428 struct element *e = llx_data (llx);
429 check (elements[cnt - i - 1] == e->x);
430 check (llx != llx_null (list));
432 check (llx == llx_null (list));
434 check (llx_count (list) == cnt);
437 /* Lexicographicallxy compares ARRAY1, which contains COUNT1
438 elements of SIZE bytes each, to ARRAY2, which contains COUNT2
439 elements of SIZE bytes, according to COMPARE. Returns a
440 strcmp-type result. AUX is passed to COMPARE as auxiliary
443 lexicographical_compare_3way (const void *array1, size_t count1,
444 const void *array2, size_t count2,
446 int (*compare) (const void *, const void *,
450 const char *first1 = array1;
451 const char *first2 = array2;
452 size_t min_count = count1 < count2 ? count1 : count2;
454 while (min_count > 0)
456 int cmp = compare (first1, first2, aux);
465 return count1 < count2 ? -1 : count1 > count2;
470 /* Tests list push and pop operations. */
474 const int max_elems = 1024;
476 struct llx_list list;
477 struct element **elems;
482 allocate_elements (max_elems, NULL, &elems, NULL, &values);
486 check_list_contents (&list, NULL, 0);
487 for (i = 0; i < max_elems; i++)
489 values[i] = elems[i]->x = i;
490 llx_push_tail (&list, elems[i], &llx_malloc_mgr);
491 check_list_contents (&list, values, i + 1);
494 /* Remove from tail. */
495 for (i = 0; i < max_elems; i++)
497 struct element *e = llx_pop_tail (&list, &llx_malloc_mgr);
498 check (e->x == max_elems - i - 1);
499 check_list_contents (&list, values, max_elems - i - 1);
503 check_list_contents (&list, NULL, 0);
504 for (i = 0; i < max_elems; i++)
506 values[max_elems - i - 1] = elems[i]->x = max_elems - i - 1;
507 llx_push_head (&list, elems[i], &llx_malloc_mgr);
508 check_list_contents (&list, &values[max_elems - i - 1], i + 1);
511 /* Remove from start. */
512 for (i = 0; i < max_elems; i++)
514 struct element *e = llx_pop_head (&list, &llx_malloc_mgr);
515 check (e->x == (int) i);
516 check_list_contents (&list, &values[i + 1], max_elems - i - 1);
519 free_elements (max_elems, &list, elems, NULL, values);
522 /* Tests insertion and removal at arbitrary positions. */
524 test_insert_remove (void)
526 const int max_elems = 16;
529 for (cnt = 0; cnt < max_elems; cnt++)
531 struct element **elems;
533 int *values = xnmalloc (cnt + 1, sizeof *values);
535 struct llx_list list;
536 struct element extra;
537 struct llx *extra_llx;
540 allocate_ascending (cnt, &list, &elems, &elemp, NULL);
542 for (pos = 0; pos <= cnt; pos++)
546 extra_llx = llx_insert (elemp[pos], &extra, &llx_malloc_mgr);
547 check (extra_llx != NULL);
550 for (i = 0; i < pos; i++)
555 check_list_contents (&list, values, cnt + 1);
557 llx_remove (extra_llx, &llx_malloc_mgr);
559 check_list_contents (&list, values, cnt);
561 free_elements (cnt, &list, elems, elemp, values);
565 /* Tests swapping individual elements. */
569 const int max_elems = 8;
572 for (cnt = 0; cnt <= max_elems; cnt++)
574 struct llx_list list;
575 struct element **elems;
581 allocate_ascending (cnt, &list, &elems, &elemp, &values);
582 check_list_contents (&list, values, cnt);
584 for (i = 0; i < cnt; i++)
585 for (j = 0; j < cnt; j++)
586 for (k = 0; k < 2; k++)
590 llx_swap (elemp[i], elemp[j]);
592 values[i] = values[j];
594 check_list_contents (&list, values, cnt);
597 free_elements (cnt, &list, elems, elemp, values);
601 /* Tests swapping ranges of list elements. */
603 test_swap_range (void)
605 const int max_elems = 8;
606 int cnt, a0, a1, b0, b1, r;
608 for (cnt = 0; cnt <= max_elems; cnt++)
609 for (a0 = 0; a0 <= cnt; a0++)
610 for (a1 = a0; a1 <= cnt; a1++)
611 for (b0 = a1; b0 <= cnt; b0++)
612 for (b1 = b0; b1 <= cnt; b1++)
613 for (r = 0; r < 2; r++)
615 struct llx_list list;
616 struct element **elems;
622 allocate_ascending (cnt, &list, &elems, &elemp, &values);
623 check_list_contents (&list, values, cnt);
626 for (i = 0; i < a0; i++)
628 for (i = b0; i < b1; i++)
630 for (i = a1; i < b0; i++)
632 for (i = a0; i < a1; i++)
634 for (i = b1; i < cnt; i++)
639 llx_swap_range (elemp[a0], elemp[a1], elemp[b0], elemp[b1]);
641 llx_swap_range (elemp[b0], elemp[b1], elemp[a0], elemp[a1]);
642 check_list_contents (&list, values, cnt);
644 free_elements (cnt, &list, elems, elemp, values);
648 /* Tests removing ranges of list elements. */
650 test_remove_range (void)
652 const int max_elems = 8;
656 for (cnt = 0; cnt <= max_elems; cnt++)
657 for (r0 = 0; r0 <= cnt; r0++)
658 for (r1 = r0; r1 <= cnt; r1++)
660 struct llx_list list;
661 struct element **elems;
667 allocate_ascending (cnt, &list, &elems, &elemp, &values);
668 check_list_contents (&list, values, cnt);
671 for (i = 0; i < r0; i++)
673 for (i = r1; i < cnt; i++)
676 llx_remove_range (elemp[r0], elemp[r1], &llx_malloc_mgr);
677 check_list_contents (&list, values, j);
679 free_elements (cnt, &list, elems, elemp, values);
683 /* Tests llx_remove_equal. */
685 test_remove_equal (void)
687 const int max_elems = 8;
689 int cnt, r0, r1, eq_pat;
691 for (cnt = 0; cnt <= max_elems; cnt++)
692 for (r0 = 0; r0 <= cnt; r0++)
693 for (r1 = r0; r1 <= cnt; r1++)
694 for (eq_pat = 0; eq_pat <= 1 << cnt; eq_pat++)
696 struct llx_list list;
697 struct element **elems;
701 struct element to_remove;
705 allocate_elements (cnt, &list, &elems, &elemp, &values);
708 for (i = 0; i < cnt; i++)
710 int x = eq_pat & (1 << i) ? -1 : i;
711 bool delete = x == -1 && r0 <= i && i < r1;
714 values[remaining++] = x;
718 check ((int) llx_remove_equal (elemp[r0], elemp[r1], &to_remove,
719 compare_elements, &aux_data,
722 check_list_contents (&list, values, remaining);
724 free_elements (cnt, &list, elems, elemp, values);
728 /* Tests llx_remove_if. */
730 test_remove_if (void)
732 const int max_elems = 8;
734 int cnt, r0, r1, pattern;
736 for (cnt = 0; cnt <= max_elems; cnt++)
737 for (r0 = 0; r0 <= cnt; r0++)
738 for (r1 = r0; r1 <= cnt; r1++)
739 for (pattern = 0; pattern <= 1 << cnt; pattern++)
741 struct llx_list list;
742 struct element **elems;
749 allocate_ascending (cnt, &list, &elems, &elemp, &values);
752 for (i = 0; i < cnt; i++)
754 bool delete = (pattern & (1 << i)) && r0 <= i && i < r1;
756 values[remaining++] = i;
759 check ((int) llx_remove_if (elemp[r0], elemp[r1],
760 pattern_pred, &pattern,
763 check_list_contents (&list, values, remaining);
765 free_elements (cnt, &list, elems, elemp, values);
769 /* Tests, via HELPER, a function that looks at list elements
770 equal to some specified element. */
772 test_examine_equal_range (void (*helper) (int r0, int r1, int eq_pat,
776 const int max_elems = 8;
778 int cnt, r0, r1, eq_pat;
780 for (cnt = 0; cnt <= max_elems; cnt++)
781 for (eq_pat = 0; eq_pat <= 1 << cnt; eq_pat++)
783 struct llx_list list;
784 struct element **elems;
788 struct element to_find;
792 allocate_ascending (cnt, &list, &elems, &elemp, &values);
794 for (i = 0; i < cnt; i++)
795 if (eq_pat & (1 << i))
796 values[i] = elems[i]->x = -1;
799 for (r0 = 0; r0 <= cnt; r0++)
800 for (r1 = r0; r1 <= cnt; r1++)
801 helper (r0, r1, eq_pat, &to_find, elemp);
803 check_list_contents (&list, values, cnt);
805 free_elements (cnt, &list, elems, elemp, values);
809 /* Tests, via HELPER, a function that looks at list elements for
810 which a given predicate returns true. */
812 test_examine_if_range (void (*helper) (int r0, int r1, int eq_pat,
815 const int max_elems = 8;
817 int cnt, r0, r1, eq_pat;
819 for (cnt = 0; cnt <= max_elems; cnt++)
820 for (eq_pat = 0; eq_pat <= 1 << cnt; eq_pat++)
822 struct llx_list list;
823 struct element **elems;
827 allocate_ascending (cnt, &list, &elems, &elemp, &values);
829 for (r0 = 0; r0 <= cnt; r0++)
830 for (r1 = r0; r1 <= cnt; r1++)
831 helper (r0, r1, eq_pat, elemp);
833 check_list_contents (&list, values, cnt);
835 free_elements (cnt, &list, elems, elemp, values);
839 /* Helper function for testing llx_find_equal. */
841 test_find_equal_helper (int r0, int r1, int eq_pat,
842 const void *to_find, struct llx **elemp)
847 match = llx_find_equal (elemp[r0], elemp[r1], to_find,
848 compare_elements, &aux_data);
849 for (i = r0; i < r1; i++)
850 if (eq_pat & (1 << i))
853 check (match == elemp[i]);
856 /* Tests llx_find_equal. */
858 test_find_equal (void)
860 test_examine_equal_range (test_find_equal_helper);
863 /* Tests llx_find(). */
867 const int max_elems = 8;
871 for (cnt = 0; cnt <= max_elems; cnt++)
873 struct llx_list list;
874 struct element **elems;
880 allocate_ascending (cnt, &list, &elems, &elemp, &values);
882 for (i = 0; i < cnt; i++)
883 check (llx_find (llx_head (&list), llx_null (&list), elems[i])
885 check (llx_find (llx_head (&list), llx_null (&list), NULL) == NULL);
887 free_elements (cnt, &list, elems, elemp, values);
891 /* Helper function for testing llx_find_if. */
893 test_find_if_helper (int r0, int r1, int eq_pat, struct llx **elemp)
895 struct llx *match = llx_find_if (elemp[r0], elemp[r1],
896 pattern_pred, &eq_pat);
899 for (i = r0; i < r1; i++)
900 if (eq_pat & (1 << i))
903 check (match == elemp[i]);
906 /* Tests llx_find_if. */
910 test_examine_if_range (test_find_if_helper);
913 /* Tests llx_find_adjacent_equal. */
915 test_find_adjacent_equal (void)
917 const int max_elems = 8;
921 for (cnt = 0; cnt <= max_elems; cnt++)
922 for (eq_pat = 0; eq_pat <= 1 << cnt; eq_pat++)
924 struct llx_list list;
925 struct element **elems;
932 allocate_ascending (cnt, &list, &elems, &elemp, &values);
935 for (i = 0; i < cnt - 1; i++)
938 if (eq_pat & (1 << i))
940 values[i] = elems[i]->x = match;
941 values[i + 1] = elems[i + 1]->x = match;
947 for (i = 0; i <= cnt; i++)
949 struct llx *llx1 = llx_find_adjacent_equal (elemp[i], llx_null (&list),
955 llx2 = llx_null (&list);
956 for (j = i; j < cnt - 1; j++)
957 if (eq_pat & (1 << j))
962 check (llx1 == llx2);
964 check_list_contents (&list, values, cnt);
966 free_elements (cnt, &list, elems, elemp, values);
970 /* Helper function for testing llx_count_range. */
972 test_count_range_helper (int r0, int r1, int eq_pat UNUSED, struct llx **elemp)
974 check ((int) llx_count_range (elemp[r0], elemp[r1]) == r1 - r0);
977 /* Tests llx_count_range. */
979 test_count_range (void)
981 test_examine_if_range (test_count_range_helper);
984 /* Helper function for testing llx_count_equal. */
986 test_count_equal_helper (int r0, int r1, int eq_pat,
987 const void *to_find, struct llx **elemp)
992 count1 = llx_count_equal (elemp[r0], elemp[r1], to_find,
993 compare_elements, &aux_data);
995 for (i = r0; i < r1; i++)
996 if (eq_pat & (1 << i))
999 check (count1 == count2);
1002 /* Tests llx_count_equal. */
1004 test_count_equal (void)
1006 test_examine_equal_range (test_count_equal_helper);
1009 /* Helper function for testing llx_count_if. */
1011 test_count_if_helper (int r0, int r1, int eq_pat, struct llx **elemp)
1017 count1 = llx_count_if (elemp[r0], elemp[r1], pattern_pred, &eq_pat);
1020 for (i = r0; i < r1; i++)
1021 if (eq_pat & (1 << i))
1024 check (count1 == count2);
1027 /* Tests llx_count_if. */
1029 test_count_if (void)
1031 test_examine_if_range (test_count_if_helper);
1036 factorial (unsigned int n)
1038 unsigned int value = 1;
1044 /* Returns the number of permutations of the CNT values in
1045 VALUES. If VALUES contains duplicates, they must be
1048 expected_perms (int *values, size_t cnt)
1051 unsigned int perm_cnt;
1053 perm_cnt = factorial (cnt);
1054 for (i = 0; i < cnt; i = j)
1056 for (j = i + 1; j < cnt; j++)
1057 if (values[i] != values[j])
1059 perm_cnt /= factorial (j - i);
1064 /* Tests llx_min and llx_max. */
1068 const int max_elems = 6;
1071 for (cnt = 0; cnt <= max_elems; cnt++)
1073 struct llx_list list;
1074 struct element **elems;
1077 int *new_values = xnmalloc (cnt, sizeof *values);
1081 allocate_ascending (cnt, &list, &elems, &elemp, &values);
1084 while (llx_next_permutation (llx_head (&list), llx_null (&list),
1085 compare_elements, &aux_data))
1091 for (i = 0, x = llx_head (&list); x != llx_null (&list);
1092 x = llx_next (x), i++)
1094 struct element *e = llx_data (x);
1096 new_values[i] = e->x;
1098 for (r0 = 0; r0 <= cnt; r0++)
1099 for (r1 = r0; r1 <= cnt; r1++)
1101 struct llx *min = llx_min (elemp[r0], elemp[r1],
1102 compare_elements, &aux_data);
1103 struct llx *max = llx_max (elemp[r0], elemp[r1],
1104 compare_elements, &aux_data);
1107 check (min == elemp[r1]);
1108 check (max == elemp[r1]);
1112 struct element *min_elem = llx_data (min);
1113 struct element *max_elem = llx_data (max);
1114 int min_int, max_int;
1117 min_int = max_int = new_values[r0];
1118 for (i = r0; i < r1; i++)
1120 int value = new_values[i];
1121 if (value < min_int)
1123 if (value > max_int)
1126 check (min != elemp[r1] && min_elem->x == min_int);
1127 check (max != elemp[r1] && max_elem->x == max_int);
1132 check (perm_cnt == factorial (cnt));
1133 check_list_contents (&list, values, cnt);
1135 free_elements (cnt, &list, elems, elemp, values);
1140 /* Tests llx_lexicographical_compare_3way. */
1142 test_lexicographical_compare_3way (void)
1144 const int max_elems = 4;
1146 int cnt_a, pat_a, cnt_b, pat_b;
1148 for (cnt_a = 0; cnt_a <= max_elems; cnt_a++)
1149 for (pat_a = 0; pat_a <= 1 << cnt_a; pat_a++)
1150 for (cnt_b = 0; cnt_b <= max_elems; cnt_b++)
1151 for (pat_b = 0; pat_b <= 1 << cnt_b; pat_b++)
1153 struct llx_list list_a, list_b;
1154 struct element **elems_a, **elems_b;
1155 struct llx **elemp_a, **elemp_b;
1156 int *values_a, *values_b;
1160 allocate_pattern (cnt_a, pat_a,
1161 &list_a, &elems_a, &elemp_a, &values_a);
1162 allocate_pattern (cnt_b, pat_b,
1163 &list_b, &elems_b, &elemp_b, &values_b);
1165 for (a0 = 0; a0 <= cnt_a; a0++)
1166 for (a1 = a0; a1 <= cnt_a; a1++)
1167 for (b0 = 0; b0 <= cnt_b; b0++)
1168 for (b1 = b0; b1 <= cnt_b; b1++)
1170 int a_ordering = lexicographical_compare_3way (
1171 values_a + a0, a1 - a0,
1172 values_b + b0, b1 - b0,
1174 compare_ints, NULL);
1176 int b_ordering = llx_lexicographical_compare_3way (
1177 elemp_a[a0], elemp_a[a1],
1178 elemp_b[b0], elemp_b[b1],
1179 compare_elements, &aux_data);
1181 check (a_ordering == b_ordering);
1184 free_elements (cnt_a, &list_a, elems_a, elemp_a, values_a);
1185 free_elements (cnt_b, &list_b, elems_b, elemp_b, values_b);
1189 /* Appends the `x' value in element E to the array pointed to by
1190 NEXT_OUTPUT, and advances NEXT_OUTPUT to the next position. */
1192 apply_func (void *e_, void *next_output_)
1194 struct element *e = e_;
1195 int **next_output = next_output_;
1197 *(*next_output)++ = e->x;
1200 /* Tests llx_apply. */
1204 const int max_elems = 8;
1208 for (cnt = 0; cnt <= max_elems; cnt++)
1209 for (r0 = 0; r0 <= cnt; r0++)
1210 for (r1 = r0; r1 <= cnt; r1++)
1212 struct llx_list list;
1213 struct element **elems;
1221 allocate_ascending (cnt, &list, &elems, &elemp, &values);
1222 check_list_contents (&list, values, cnt);
1224 output = next_output = xnmalloc (cnt, sizeof *output);
1225 llx_apply (elemp[r0], elemp[r1], apply_func, &next_output);
1226 check_list_contents (&list, values, cnt);
1227 llx_destroy (&list, NULL, NULL, &llx_malloc_mgr);
1229 check (r1 - r0 == next_output - output);
1230 for (j = 0; j < r1 - r0; j++)
1231 check (output[j] == r0 + j);
1233 free_elements (cnt, NULL, elems, elemp, values);
1238 /* Tests llx_destroy. */
1242 const int max_elems = 8;
1246 for (cnt = 0; cnt <= max_elems; cnt++)
1248 struct llx_list list;
1249 struct element **elems;
1257 allocate_ascending (cnt, &list, &elems, &elemp, &values);
1258 check_list_contents (&list, values, cnt);
1260 output = next_output = xnmalloc (cnt, sizeof *output);
1261 llx_destroy (&list, apply_func, &next_output, &llx_malloc_mgr);
1263 check (cnt == next_output - output);
1264 for (j = 0; j < cnt; j++)
1265 check (output[j] == j);
1267 free_elements (cnt, NULL, elems, elemp, values);
1272 /* Tests llx_reverse. */
1276 const int max_elems = 8;
1280 for (cnt = 0; cnt <= max_elems; cnt++)
1281 for (r0 = 0; r0 <= cnt; r0++)
1282 for (r1 = r0; r1 <= cnt; r1++)
1284 struct llx_list list;
1285 struct element **elems;
1291 allocate_ascending (cnt, &list, &elems, &elemp, &values);
1292 check_list_contents (&list, values, cnt);
1295 for (i = 0; i < r0; i++)
1297 for (i = r1 - 1; i >= r0; i--)
1299 for (i = r1; i < cnt; i++)
1302 llx_reverse (elemp[r0], elemp[r1]);
1303 check_list_contents (&list, values, cnt);
1305 free_elements (cnt, &list, elems, elemp, values);
1309 /* Tests llx_next_permutation and llx_prev_permutation when the
1310 permuted values have no duplicates. */
1312 test_permutations_no_dups (void)
1314 const int max_elems = 8;
1317 for (cnt = 0; cnt <= max_elems; cnt++)
1319 struct llx_list list;
1320 struct element **elems;
1322 int *old_values = xnmalloc (cnt, sizeof *values);
1323 int *new_values = xnmalloc (cnt, sizeof *values);
1327 allocate_ascending (cnt, &list, &elems, NULL, &values);
1330 extract_values (&list, old_values, cnt);
1331 while (llx_next_permutation (llx_head (&list), llx_null (&list),
1332 compare_elements, &aux_data))
1334 extract_values (&list, new_values, cnt);
1335 check (lexicographical_compare_3way (new_values, cnt,
1338 compare_ints, NULL) > 0);
1339 memcpy (old_values, new_values, (cnt) * sizeof *old_values);
1342 check (perm_cnt == factorial (cnt));
1343 check_list_contents (&list, values, cnt);
1346 llx_reverse (llx_head (&list), llx_null (&list));
1347 extract_values (&list, old_values, cnt);
1348 while (llx_prev_permutation (llx_head (&list), llx_null (&list),
1349 compare_elements, &aux_data))
1351 extract_values (&list, new_values, cnt);
1352 check (lexicographical_compare_3way (new_values, cnt,
1355 compare_ints, NULL) < 0);
1356 memcpy (old_values, new_values, (cnt) * sizeof *old_values);
1359 check (perm_cnt == factorial (cnt));
1360 llx_reverse (llx_head (&list), llx_null (&list));
1361 check_list_contents (&list, values, cnt);
1363 free_elements (cnt, &list, elems, NULL, values);
1369 /* Tests llx_next_permutation and llx_prev_permutation when the
1370 permuted values contain duplicates. */
1372 test_permutations_with_dups (void)
1374 const int max_elems = 8;
1375 const int max_dup = 3;
1376 const int repetitions = 1024;
1380 for (repeat = 0; repeat < repetitions; repeat++)
1381 for (cnt = 0; cnt < max_elems; cnt++)
1383 struct llx_list list;
1384 struct element **elems;
1387 int *old_values = xnmalloc (max_elems, sizeof *values);
1388 int *new_values = xnmalloc (max_elems, sizeof *values);
1390 unsigned int permutation_cnt;
1394 allocate_elements (cnt, &list, &elems, &elemp, &values);
1399 int max = left < max_dup ? left : max_dup;
1400 int n = rand () % max + 1;
1403 int idx = cnt - left--;
1404 values[idx] = elems[idx]->x = value;
1409 permutation_cnt = 1;
1410 extract_values (&list, old_values, cnt);
1411 while (llx_next_permutation (llx_head (&list), llx_null (&list),
1412 compare_elements, &aux_data))
1414 extract_values (&list, new_values, cnt);
1415 check (lexicographical_compare_3way (new_values, cnt,
1418 compare_ints, NULL) > 0);
1419 memcpy (old_values, new_values, cnt * sizeof *old_values);
1422 check (permutation_cnt == expected_perms (values, cnt));
1423 check_list_contents (&list, values, cnt);
1425 permutation_cnt = 1;
1426 llx_reverse (llx_head (&list), llx_null (&list));
1427 extract_values (&list, old_values, cnt);
1428 while (llx_prev_permutation (llx_head (&list), llx_null (&list),
1429 compare_elements, &aux_data))
1431 extract_values (&list, new_values, cnt);
1432 check (lexicographical_compare_3way (new_values, cnt,
1435 compare_ints, NULL) < 0);
1438 llx_reverse (llx_head (&list), llx_null (&list));
1439 check (permutation_cnt == expected_perms (values, cnt));
1440 check_list_contents (&list, values, cnt);
1442 free_elements (cnt, &list, elems, elemp, values);
1448 /* Tests llx_merge when no equal values are to be merged. */
1450 test_merge_no_dups (void)
1452 const int max_elems = 8;
1453 const int max_fillxer = 3;
1455 int merge_cnt, pattern, pfx, gap, sfx, order;
1457 for (merge_cnt = 0; merge_cnt < max_elems; merge_cnt++)
1458 for (pattern = 0; pattern <= (1 << merge_cnt); pattern++)
1459 for (pfx = 0; pfx < max_fillxer; pfx++)
1460 for (gap = 0; gap < max_fillxer; gap++)
1461 for (sfx = 0; sfx < max_fillxer; sfx++)
1462 for (order = 0; order < 2; order++)
1464 struct llx_list list;
1465 struct element **elems;
1469 int list_cnt = pfx + merge_cnt + gap + sfx;
1473 allocate_elements (list_cnt, &list,
1474 &elems, &elemp, &values);
1477 for (i = 0; i < pfx; i++)
1478 elems[j++]->x = 100 + i;
1480 for (i = 0; i < merge_cnt; i++)
1481 if (pattern & (1u << i))
1484 for (i = 0; i < gap; i++)
1485 elems[j++]->x = 200 + i;
1487 for (i = 0; i < merge_cnt; i++)
1488 if (!(pattern & (1u << i)))
1491 for (i = 0; i < sfx; i++)
1492 elems[j++]->x = 300 + i;
1493 check (list_cnt == j);
1496 for (i = 0; i < pfx; i++)
1497 values[j++] = 100 + i;
1499 for (i = 0; i < merge_cnt; i++)
1501 for (i = 0; i < gap; i++)
1502 values[j++] = 200 + i;
1504 for (i = 0; i < merge_cnt; i++)
1506 for (i = 0; i < sfx; i++)
1507 values[j++] = 300 + i;
1508 check (list_cnt == j);
1511 llx_merge (elemp[a0], elemp[a1], elemp[b0], elemp[b1],
1512 compare_elements, &aux_data);
1514 llx_merge (elemp[b0], elemp[b1], elemp[a0], elemp[a1],
1515 compare_elements, &aux_data);
1517 check_list_contents (&list, values, list_cnt);
1519 free_elements (list_cnt, &list, elems, elemp, values);
1523 /* Tests llx_merge when equal values are to be merged. */
1525 test_merge_with_dups (void)
1527 const int max_elems = 8;
1529 int cnt, merge_pat, inc_pat, order;
1531 for (cnt = 0; cnt <= max_elems; cnt++)
1532 for (merge_pat = 0; merge_pat <= (1 << cnt); merge_pat++)
1533 for (inc_pat = 0; inc_pat <= (1 << cnt); inc_pat++)
1534 for (order = 0; order < 2; order++)
1536 struct llx_list list;
1537 struct element **elems;
1544 allocate_elements (cnt, &list, &elems, &elemp, &values);
1547 for (i = k = 0; i < cnt; i++)
1549 if (merge_pat & (1u << i))
1551 if (inc_pat & (1u << i))
1555 for (i = k = 0; i < cnt; i++)
1557 if (!(merge_pat & (1u << i)))
1559 if (inc_pat & (1u << i))
1566 for (i = 0; i < cnt; i++)
1571 for (i = 0; i < mid; i++)
1572 elems[i]->y = 100 + i;
1573 for (i = mid; i < cnt; i++)
1578 for (i = k = 0; i < cnt; i++)
1581 if (inc_pat & (1u << i))
1587 llx_merge (elemp[0], elemp[mid], elemp[mid], elemp[cnt],
1588 compare_elements, &aux_data);
1590 llx_merge (elemp[mid], elemp[cnt], elemp[0], elemp[mid],
1591 compare_elements, &aux_data);
1593 check_list_contents (&list, values, cnt);
1594 check (llx_is_sorted (llx_head (&list), llx_null (&list),
1595 compare_elements_x_y, &aux_data));
1597 free_elements (cnt, &list, elems, elemp, values);
1601 /* Tests llx_sort on all permutations up to a maximum number of
1604 test_sort_exhaustive (void)
1606 const int max_elems = 8;
1609 for (cnt = 0; cnt <= max_elems; cnt++)
1611 struct llx_list list;
1612 struct element **elems;
1615 struct element **perm_elems;
1620 allocate_ascending (cnt, &list, &elems, NULL, &values);
1621 allocate_elements (cnt, NULL, &perm_elems, NULL, &perm_values);
1624 while (llx_next_permutation (llx_head (&list), llx_null (&list),
1625 compare_elements, &aux_data))
1627 struct llx_list perm_list;
1630 extract_values (&list, perm_values, cnt);
1631 llx_init (&perm_list);
1632 for (j = 0; j < cnt; j++)
1634 perm_elems[j]->x = perm_values[j];
1635 llx_push_tail (&perm_list, perm_elems[j], &llx_malloc_mgr);
1637 llx_sort (llx_head (&perm_list), llx_null (&perm_list),
1638 compare_elements, &aux_data);
1639 check_list_contents (&perm_list, values, cnt);
1640 check (llx_is_sorted (llx_head (&perm_list), llx_null (&perm_list),
1641 compare_elements, &aux_data));
1642 llx_destroy (&perm_list, NULL, NULL, &llx_malloc_mgr);
1645 check (perm_cnt == factorial (cnt));
1647 free_elements (cnt, &list, elems, NULL, values);
1648 free_elements (cnt, NULL, perm_elems, NULL, perm_values);
1652 /* Tests that llx_sort is stable in the presence of equal
1655 test_sort_stable (void)
1657 const int max_elems = 6;
1660 for (cnt = 0; cnt <= max_elems; cnt++)
1661 for (inc_pat = 0; inc_pat <= 1 << cnt; inc_pat++)
1663 struct llx_list list;
1664 struct element **elems;
1667 struct element **perm_elems;
1673 allocate_elements (cnt, &list, &elems, NULL, &values);
1674 allocate_elements (cnt, NULL, &perm_elems, NULL, &perm_values);
1677 for (i = 0; i < cnt; i++)
1679 elems[i]->x = values[i] = j;
1680 if (inc_pat & (1 << i))
1686 while (llx_next_permutation (llx_head (&list), llx_null (&list),
1687 compare_elements_y, &aux_data))
1689 struct llx_list perm_list;
1691 extract_values (&list, perm_values, cnt);
1692 llx_init (&perm_list);
1693 for (i = 0; i < cnt; i++)
1695 perm_elems[i]->x = perm_values[i];
1696 perm_elems[i]->y = i;
1697 llx_push_tail (&perm_list, perm_elems[i], &llx_malloc_mgr);
1699 llx_sort (llx_head (&perm_list), llx_null (&perm_list),
1700 compare_elements, &aux_data);
1701 check_list_contents (&perm_list, values, cnt);
1702 check (llx_is_sorted (llx_head (&perm_list), llx_null (&perm_list),
1703 compare_elements_x_y, &aux_data));
1704 llx_destroy (&perm_list, NULL, NULL, &llx_malloc_mgr);
1707 check (perm_cnt == factorial (cnt));
1709 free_elements (cnt, &list, elems, NULL, values);
1710 free_elements (cnt, NULL, perm_elems, NULL, perm_values);
1714 /* Tests that llx_sort does not disturb elements outside the
1717 test_sort_subset (void)
1719 const int max_elems = 8;
1721 int cnt, r0, r1, repeat;
1723 for (cnt = 0; cnt <= max_elems; cnt++)
1724 for (repeat = 0; repeat < 100; repeat++)
1725 for (r0 = 0; r0 <= cnt; r0++)
1726 for (r1 = r0; r1 <= cnt; r1++)
1728 struct llx_list list;
1729 struct element **elems;
1733 allocate_random (cnt, &list, &elems, &elemp, &values);
1735 qsort (&values[r0], r1 - r0, sizeof *values, compare_ints_noaux);
1736 llx_sort (elemp[r0], elemp[r1], compare_elements, &aux_data);
1737 check_list_contents (&list, values, cnt);
1739 free_elements (cnt, &list, elems, elemp, values);
1743 /* Tests that llx_sort works with large lists. */
1745 test_sort_big (void)
1747 const int max_elems = 1024;
1751 for (cnt = 0; cnt < max_elems; cnt++)
1753 struct llx_list list;
1754 struct element **elems;
1757 allocate_random (cnt, &list, &elems, NULL, &values);
1759 qsort (values, cnt, sizeof *values, compare_ints_noaux);
1760 llx_sort (llx_head (&list), llx_null (&list), compare_elements, &aux_data);
1761 check_list_contents (&list, values, cnt);
1763 free_elements (cnt, &list, elems, NULL, values);
1767 /* Tests llx_unique. */
1771 const int max_elems = 10;
1773 int *ascending = xnmalloc (max_elems, sizeof *ascending);
1775 int cnt, inc_pat, i, j, unique_values;
1777 for (i = 0; i < max_elems; i++)
1780 for (cnt = 0; cnt < max_elems; cnt++)
1781 for (inc_pat = 0; inc_pat < (1 << cnt); inc_pat++)
1783 struct llx_list list, dups;
1784 struct element **elems;
1787 allocate_elements (cnt, &list, &elems, NULL, &values);
1789 j = unique_values = 0;
1790 for (i = 0; i < cnt; i++)
1792 unique_values = j + 1;
1793 elems[i]->x = values[i] = j;
1794 if (inc_pat & (1 << i))
1797 check_list_contents (&list, values, cnt);
1800 check (llx_unique (llx_head (&list), llx_null (&list),
1802 compare_elements, &aux_data,
1804 == (size_t) unique_values);
1805 check_list_contents (&list, ascending, unique_values);
1807 llx_splice (llx_null (&list), llx_head (&dups), llx_null (&dups));
1808 llx_sort (llx_head (&list), llx_null (&list), compare_elements, &aux_data);
1809 check_list_contents (&list, values, cnt);
1811 llx_destroy (&dups, NULL, NULL, &llx_malloc_mgr);
1812 free_elements (cnt, &list, elems, NULL, values);
1818 /* Tests llx_sort_unique. */
1820 test_sort_unique (void)
1822 const int max_elems = 7;
1825 for (cnt = 0; cnt <= max_elems; cnt++)
1826 for (inc_pat = 0; inc_pat <= 1 << cnt; inc_pat++)
1828 struct llx_list list;
1829 struct element **elems;
1832 struct element **perm_elems;
1841 allocate_elements (cnt, &list, &elems, NULL, &values);
1842 allocate_elements (cnt, NULL, &perm_elems, NULL, &perm_values);
1845 for (i = 0; i < cnt; i++)
1847 elems[i]->x = values[i] = j;
1849 if (inc_pat & (1 << i))
1853 unique_values = xnmalloc (unique_cnt, sizeof *unique_values);
1854 for (i = 0; i < unique_cnt; i++)
1855 unique_values[i] = i;
1858 while (llx_next_permutation (llx_head (&list), llx_null (&list),
1859 compare_elements, &aux_data))
1861 struct llx_list perm_list;
1863 extract_values (&list, perm_values, cnt);
1864 llx_init (&perm_list);
1865 for (i = 0; i < cnt; i++)
1867 perm_elems[i]->x = perm_values[i];
1868 perm_elems[i]->y = i;
1869 llx_push_tail (&perm_list, perm_elems[i], &llx_malloc_mgr);
1871 llx_sort_unique (llx_head (&perm_list), llx_null (&perm_list), NULL,
1872 compare_elements, &aux_data,
1874 check_list_contents (&perm_list, unique_values, unique_cnt);
1875 check (llx_is_sorted (llx_head (&perm_list), llx_null (&perm_list),
1876 compare_elements_x_y, &aux_data));
1877 llx_destroy (&perm_list, NULL, NULL, &llx_malloc_mgr);
1880 check (perm_cnt == expected_perms (values, cnt));
1882 free_elements (cnt, &list, elems, NULL, values);
1883 free_elements (cnt, NULL, perm_elems, NULL, perm_values);
1884 free (unique_values);
1888 /* Tests llx_insert_ordered. */
1890 test_insert_ordered (void)
1892 const int max_elems = 6;
1895 for (cnt = 0; cnt <= max_elems; cnt++)
1896 for (inc_pat = 0; inc_pat <= 1 << cnt; inc_pat++)
1898 struct llx_list list;
1899 struct element **elems;
1902 struct element **perm_elems;
1908 allocate_elements (cnt, &list, &elems, NULL, &values);
1909 allocate_elements (cnt, NULL, &perm_elems, NULL, &perm_values);
1912 for (i = 0; i < cnt; i++)
1914 elems[i]->x = values[i] = j;
1915 if (inc_pat & (1 << i))
1921 while (llx_next_permutation (llx_head (&list), llx_null (&list),
1922 compare_elements_y, &aux_data))
1924 struct llx_list perm_list;
1926 extract_values (&list, perm_values, cnt);
1927 llx_init (&perm_list);
1928 for (i = 0; i < cnt; i++)
1930 perm_elems[i]->x = perm_values[i];
1931 perm_elems[i]->y = i;
1932 llx_insert_ordered (llx_head (&perm_list),
1933 llx_null (&perm_list),
1935 compare_elements, &aux_data,
1938 check (llx_is_sorted (llx_head (&perm_list), llx_null (&perm_list),
1939 compare_elements_x_y, &aux_data));
1940 llx_destroy (&perm_list, NULL, NULL, &llx_malloc_mgr);
1943 check (perm_cnt == factorial (cnt));
1945 free_elements (cnt, &list, elems, NULL, values);
1946 free_elements (cnt, NULL, perm_elems, NULL, perm_values);
1950 /* Tests llx_partition. */
1952 test_partition (void)
1954 const int max_elems = 10;
1960 for (cnt = 0; cnt < max_elems; cnt++)
1961 for (r0 = 0; r0 <= cnt; r0++)
1962 for (r1 = r0; r1 <= cnt; r1++)
1963 for (pbase = 0; pbase <= (1u << (r1 - r0)); pbase++)
1965 struct llx_list list;
1966 struct element **elems;
1970 unsigned int pattern = pbase << r0;
1973 struct llx *part_llx;
1975 allocate_ascending (cnt, &list, &elems, &elemp, &values);
1977 /* Check that llx_find_partition works okay in every
1978 case. We use it after partitioning, too, but that
1979 only tests cases where it returns non-null. */
1980 for (i = r0; i < r1; i++)
1981 if (!(pattern & (1u << i)))
1985 if (pattern & (1u << i))
1987 part_llx = llx_find_partition (elemp[r0], elemp[r1],
1991 check (part_llx == elemp[j]);
1993 check (part_llx == NULL);
1995 /* Figure out expected results. */
1998 for (i = 0; i < r0; i++)
2000 for (i = r0; i < r1; i++)
2001 if (pattern & (1u << i))
2003 for (i = r0; i < r1; i++)
2004 if (!(pattern & (1u << i)))
2006 if (first_false == -1)
2010 if (first_false == -1)
2012 for (i = r1; i < cnt; i++)
2016 /* Partition and check for expected results. */
2017 check (llx_partition (elemp[r0], elemp[r1],
2018 pattern_pred, &pattern)
2019 == elemp[first_false]);
2020 check (llx_find_partition (elemp[r0], elemp[r1],
2021 pattern_pred, &pattern)
2022 == elemp[first_false]);
2023 check_list_contents (&list, values, cnt);
2024 check ((int) llx_count (&list) == cnt);
2026 free_elements (cnt, &list, elems, elemp, values);
2030 /* Tests that allocation failure is gracefully handled. */
2032 test_allocation_failure (void)
2034 struct llx_list list;
2037 check (llx_push_head (&list, NULL, &llx_null_mgr) == NULL);
2038 check (llx_push_tail (&list, NULL, &llx_null_mgr) == NULL);
2039 check (llx_insert (llx_null (&list), NULL, &llx_null_mgr) == NULL);
2040 check_list_contents (&list, NULL, 0);
2048 const char *description;
2049 void (*function) (void);
2052 static const struct test tests[] =
2105 "find-adjacent-equal",
2106 "find_adjacent_equal",
2107 test_find_adjacent_equal
2130 "lexicographical-compare-3way",
2131 "lexicographical_compare_3way",
2132 test_lexicographical_compare_3way
2150 "permutations-no-dups",
2151 "permutations (no dups)",
2152 test_permutations_no_dups
2155 "permutations-with-dups",
2156 "permutations (with dups)",
2157 test_permutations_with_dups
2166 "merge (with dups)",
2167 test_merge_with_dups
2171 "sort (exhaustive)",
2172 test_sort_exhaustive
2210 "allocation-failure",
2211 "allocation failure",
2212 test_allocation_failure
2216 enum { N_TESTS = sizeof tests / sizeof *tests };
2219 main (int argc, char *argv[])
2225 fprintf (stderr, "exactly one argument required; use --help for help\n");
2226 return EXIT_FAILURE;
2228 else if (!strcmp (argv[1], "--help"))
2230 printf ("%s: test doubly linked list of pointers (llx) library\n"
2231 "usage: %s TEST-NAME\n"
2232 "where TEST-NAME is one of the following:\n",
2234 for (i = 0; i < N_TESTS; i++)
2235 printf (" %s\n %s\n", tests[i].name, tests[i].description);
2240 for (i = 0; i < N_TESTS; i++)
2241 if (!strcmp (argv[1], tests[i].name))
2243 tests[i].function ();
2247 fprintf (stderr, "unknown test %s; use --help for help\n", argv[1]);
2248 return EXIT_FAILURE;