20 /* See whether we can use the CPU clock. */
21 use_clock
= clock_getcpuclockid (0, &cl
) == 0;
24 static const char *pat
[] = {
25 ".?.?.?.?.?.?.?Log\\.13",
26 "(.?)(.?)(.?)(.?)(.?)(.?)(.?)Log\\.13",
27 "((((((((((.?))))))))))((((((((((.?))))))))))((((((((((.?))))))))))"
28 "((((((((((.?))))))))))((((((((((.?))))))))))((((((((((.?))))))))))"
29 "((((((((((.?))))))))))Log\\.13" };
31 int fd
= open ("../ChangeLog.14", O_RDONLY
);
34 printf ("Couldn't open ChangeLog.14: %m\n");
39 if (fstat64 (fd
, &st
) < 0)
41 printf ("Couldn't fstat ChangeLog.14: %m\n");
45 char *buf
= malloc (st
.st_size
+ 1);
48 printf ("Couldn't allocate buffer: %m\n");
52 if (read (fd
, buf
, st
.st_size
) != (ssize_t
) st
.st_size
)
54 puts ("Couldn't read ChangeLog.14");
59 buf
[st
.st_size
] = '\0';
61 setlocale (LC_ALL
, "de_DE.UTF-8");
64 size_t len
= st
.st_size
;
66 #ifndef WHOLE_FILE_TIMING
67 /* Don't search the whole file normally, it takes too long. */
68 if (len
> 500000 + 64)
75 for (int testno
= 0; testno
< 4; ++testno
)
76 for (int i
= 0; i
< sizeof (pat
) / sizeof (pat
[0]); ++i
)
78 printf ("test %d pattern %d", testno
, i
);
81 struct re_pattern_buffer rpbuf
;
85 err
= regcomp (&rbuf
, pat
[i
],
86 REG_EXTENDED
| (testno
? REG_NOSUB
: 0));
91 regerror (err
, &rbuf
, errstr
, sizeof (errstr
));
98 re_set_syntax (RE_SYNTAX_POSIX_EGREP
99 | (testno
== 3 ? RE_NO_SUB
: 0));
101 memset (&rpbuf
, 0, sizeof (rpbuf
));
102 const char *s
= re_compile_pattern (pat
[i
], strlen (pat
[i
]),
106 printf ("\n%s\n", s
);
110 /* Just so that this can be tested with earlier glibc as well. */
115 #ifdef _POSIX_CPUTIME
116 struct timespec start
, stop
;
118 use_clock
= clock_gettime (cl
, &start
) == 0;
123 regmatch_t pmatch
[71];
124 err
= regexec (&rbuf
, string
, 71, pmatch
, 0);
125 if (err
== REG_NOMATCH
)
127 puts ("\nregexec failed");
133 if (pmatch
[0].rm_eo
!= pmatch
[0].rm_so
+ 13
134 || pmatch
[0].rm_eo
> len
135 || pmatch
[0].rm_so
< len
- 100
136 || strncmp (string
+ pmatch
[0].rm_so
,
137 " ChangeLog.13 for earlier changes",
138 sizeof " ChangeLog.13 for earlier changes" - 1)
141 puts ("\nregexec without REG_NOSUB did not find the correct match");
146 for (int j
= 0, l
= 1; j
< 7; ++j
)
147 for (int k
= 0; k
< (i
== 1 ? 1 : 10); ++k
, ++l
)
148 if (pmatch
[l
].rm_so
!= pmatch
[0].rm_so
+ j
149 || pmatch
[l
].rm_eo
!= pmatch
[l
].rm_so
+ 1)
151 printf ("\npmatch[%d] incorrect\n", l
);
158 struct re_registers regs
;
160 memset (®s
, 0, sizeof (regs
));
161 int match
= re_search (&rpbuf
, string
, len
, 0, len
,
165 puts ("\nre_search failed");
171 || strncmp (string
+ match
,
172 " ChangeLog.13 for earlier changes",
173 sizeof " ChangeLog.13 for earlier changes" - 1)
176 puts ("\nre_search did not find the correct match");
182 if (regs
.num_regs
!= 2 + (i
== 0 ? 0 : i
== 1 ? 7 : 70))
184 printf ("\nincorrect num_regs %d\n", regs
.num_regs
);
188 if (regs
.start
[0] != match
|| regs
.end
[0] != match
+ 13)
190 printf ("\nincorrect regs.{start,end}[0] = { %d, %d}\n",
191 regs
.start
[0], regs
.end
[0]);
195 if (regs
.start
[regs
.num_regs
- 1] != -1
196 || regs
.end
[regs
.num_regs
- 1] != -1)
198 puts ("\nincorrect regs.{start,end}[num_regs - 1]");
203 for (int j
= 0, l
= 1; j
< 7; ++j
)
204 for (int k
= 0; k
< (i
== 1 ? 1 : 10); ++k
, ++l
)
205 if (regs
.start
[l
] != match
+ j
206 || regs
.end
[l
] != regs
.start
[l
] + 1)
208 printf ("\nregs.{start,end}[%d] incorrect\n", l
);
214 #ifdef _POSIX_CPUTIME
216 use_clock
= clock_gettime (cl
, &stop
) == 0;
219 stop
.tv_sec
-= start
.tv_sec
;
220 if (stop
.tv_nsec
< start
.tv_nsec
)
223 stop
.tv_nsec
+= 1000000000 - start
.tv_nsec
;
226 stop
.tv_nsec
-= start
.tv_nsec
;
227 printf (": %ld.%09lds\n", (long) stop
.tv_sec
, (long) stop
.tv_nsec
);
243 #define TEST_FUNCTION do_test ()
244 #include "../test-skeleton.c"