]> git.ipfire.org Git - thirdparty/glibc.git/blame - posix/runtests.c
Increase some test timeouts.
[thirdparty/glibc.git] / posix / runtests.c
CommitLineData
4cca6b86
UD
1/***********************************************************
2
3Copyright 1995 by Tom Lord
4
5 All Rights Reserved
6
02fb3d17
UD
7Permission to use, copy, modify, and distribute this software and its
8documentation for any purpose and without fee is hereby granted,
4cca6b86 9provided that the above copyright notice appear in all copies and that
02fb3d17 10both that copyright notice and this permission notice appear in
4cca6b86
UD
11supporting documentation, and that the name of the copyright holder not be
12used in advertising or publicity pertaining to distribution of the
02fb3d17 13software without specific, written prior permission.
4cca6b86
UD
14
15Tom Lord DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
16INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
17EVENT SHALL TOM LORD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
18CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
19USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
20OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
21PERFORMANCE OF THIS SOFTWARE.
22
23******************************************************************/
24
25
26\f
27#include <sys/types.h>
28#include <regex.h>
29#include <stdio.h>
30#include <stdlib.h>
3e1f480e 31#include <string.h>
4cca6b86
UD
32
33\f
34
35struct a_test
36{
37 int expected;
38 const char * pattern;
701666b7 39 const char * data;
4cca6b86
UD
40};
41
02fb3d17 42static const struct a_test the_tests[] =
4cca6b86
UD
43{
44#include "testcases.h"
45 {-1, 0, 0}
46};
47
48
49\f
50
de149cdb 51static int
4cca6b86
UD
52run_a_test (int id, const struct a_test * t)
53{
54 static const char * last_pattern = 0;
55 static regex_t r;
56 int err;
57 char errmsg[100];
58 int x;
59 regmatch_t regs[10];
60
61 if (!last_pattern || strcmp (last_pattern, t->pattern))
62 {
63 if (last_pattern)
64 regfree (&r);
65 last_pattern = t->pattern;
66 err = regcomp (&r, t->pattern, REG_EXTENDED);
67 if (err)
68 {
648c1337 69 if (t->expected == 2)
4cca6b86
UD
70 {
71 puts (" OK.");
72 return 0;
73 }
b3d3d974
UD
74 if (last_pattern)
75 regfree (&r);
76 last_pattern = NULL;
4cca6b86 77 regerror (err, &r, errmsg, 100);
78d8b07a 78 printf (" FAIL: %s.\n", errmsg);
4cca6b86
UD
79 return 1;
80 }
648c1337
UD
81 else if (t->expected == 2)
82 {
83 printf ("test %d\n", id);
84 printf ("pattern \"%s\" successfull compilation not expected\n",
85 t->pattern);
86 return 1;
87 }
4cca6b86 88 }
02fb3d17 89
4cca6b86
UD
90 err = regexec (&r, t->data, 10, regs, 0);
91
92 if (err != t->expected)
93 {
94 printf ("test %d\n", id);
95 printf ("pattern \"%s\" data \"%s\" wanted %d got %d\n",
96 t->pattern, t->data, t->expected, err);
97 for (x = 0; x < 10; ++x)
98 printf ("reg %d == (%d, %d) %.*s\n",
99 x,
100 regs[x].rm_so,
101 regs[x].rm_eo,
102 regs[x].rm_eo - regs[x].rm_so,
103 t->data + regs[x].rm_so);
104 return 1;
105 }
106 puts (" OK.");
107 return 0;
108}
109
110\f
111
112int
113main (int argc, char * argv[])
114{
115 int x;
116 int lo;
117 int hi;
118 int res = 0;
119
120 lo = 0;
121 hi = (sizeof (the_tests) / sizeof (the_tests[0])) - 1;
122
123 if (argc > 1)
124 {
125 lo = atoi (argv[1]);
126 hi = lo + 1;
127
128 if (argc > 2)
129 hi = atoi (argv[2]);
130 }
131
132 for (x = lo; x < hi; ++x)
133 {
134 printf ("#%d:", x);
135 res |= run_a_test (x, &the_tests[x]);
136 }
02fb3d17 137 return res != 0;
4cca6b86 138}