11 #if defined _POSIX_CPUTIME && _POSIX_CPUTIME >= 0
19 #if defined _POSIX_CPUTIME && _POSIX_CPUTIME >= 0
20 # if _POSIX_CPUTIME == 0
21 if (sysconf (_SC_CPUTIME
) < 0)
25 /* See whether we can use the CPU clock. */
26 use_clock
= clock_getcpuclockid (0, &cl
) == 0;
29 static const char *pat
[] = {
30 ".?.?.?.?.?.?.?Log\\.13",
31 "(.?)(.?)(.?)(.?)(.?)(.?)(.?)Log\\.13",
32 "((((((((((.?))))))))))((((((((((.?))))))))))((((((((((.?))))))))))"
33 "((((((((((.?))))))))))((((((((((.?))))))))))((((((((((.?))))))))))"
34 "((((((((((.?))))))))))Log\\.13" };
36 int fd
= open ("../ChangeLog.14", O_RDONLY
);
39 printf ("Couldn't open ChangeLog.14: %m\n");
44 if (fstat64 (fd
, &st
) < 0)
46 printf ("Couldn't fstat ChangeLog.14: %m\n");
50 char *buf
= malloc (st
.st_size
+ 1);
53 printf ("Couldn't allocate buffer: %m\n");
57 if (read (fd
, buf
, st
.st_size
) != (ssize_t
) st
.st_size
)
59 puts ("Couldn't read ChangeLog.14");
64 buf
[st
.st_size
] = '\0';
66 setlocale (LC_ALL
, "de_DE.UTF-8");
69 size_t len
= st
.st_size
;
71 #ifndef WHOLE_FILE_TIMING
72 /* Don't search the whole file normally, it takes too long. */
73 if (len
> 500000 + 64)
80 for (int testno
= 0; testno
< 4; ++testno
)
81 for (int i
= 0; i
< sizeof (pat
) / sizeof (pat
[0]); ++i
)
83 printf ("test %d pattern %d", testno
, i
);
86 struct re_pattern_buffer rpbuf
;
90 err
= regcomp (&rbuf
, pat
[i
],
91 REG_EXTENDED
| (testno
? REG_NOSUB
: 0));
96 regerror (err
, &rbuf
, errstr
, sizeof (errstr
));
103 re_set_syntax (RE_SYNTAX_POSIX_EGREP
104 | (testno
== 3 ? RE_NO_SUB
: 0));
106 memset (&rpbuf
, 0, sizeof (rpbuf
));
107 const char *s
= re_compile_pattern (pat
[i
], strlen (pat
[i
]),
111 printf ("\n%s\n", s
);
115 /* Just so that this can be tested with earlier glibc as well. */
120 #if defined _POSIX_CPUTIME && _POSIX_CPUTIME >= 0
121 struct timespec start
, stop
;
123 use_clock
= clock_gettime (cl
, &start
) == 0;
128 regmatch_t pmatch
[71];
129 err
= regexec (&rbuf
, string
, 71, pmatch
, 0);
130 if (err
== REG_NOMATCH
)
132 puts ("\nregexec failed");
138 if (pmatch
[0].rm_eo
!= pmatch
[0].rm_so
+ 13
139 || pmatch
[0].rm_eo
> len
140 || pmatch
[0].rm_so
< len
- 100
141 || strncmp (string
+ pmatch
[0].rm_so
,
142 " ChangeLog.13 for earlier changes",
143 sizeof " ChangeLog.13 for earlier changes" - 1)
146 puts ("\nregexec without REG_NOSUB did not find the correct match");
151 for (int j
= 0, l
= 1; j
< 7; ++j
)
152 for (int k
= 0; k
< (i
== 1 ? 1 : 10); ++k
, ++l
)
153 if (pmatch
[l
].rm_so
!= pmatch
[0].rm_so
+ j
154 || pmatch
[l
].rm_eo
!= pmatch
[l
].rm_so
+ 1)
156 printf ("\npmatch[%d] incorrect\n", l
);
163 struct re_registers regs
;
165 memset (®s
, 0, sizeof (regs
));
166 int match
= re_search (&rpbuf
, string
, len
, 0, len
,
170 puts ("\nre_search failed");
176 || strncmp (string
+ match
,
177 " ChangeLog.13 for earlier changes",
178 sizeof " ChangeLog.13 for earlier changes" - 1)
181 puts ("\nre_search did not find the correct match");
187 if (regs
.num_regs
!= 2 + (i
== 0 ? 0 : i
== 1 ? 7 : 70))
189 printf ("\nincorrect num_regs %d\n", regs
.num_regs
);
193 if (regs
.start
[0] != match
|| regs
.end
[0] != match
+ 13)
195 printf ("\nincorrect regs.{start,end}[0] = { %d, %d}\n",
196 regs
.start
[0], regs
.end
[0]);
200 if (regs
.start
[regs
.num_regs
- 1] != -1
201 || regs
.end
[regs
.num_regs
- 1] != -1)
203 puts ("\nincorrect regs.{start,end}[num_regs - 1]");
208 for (int j
= 0, l
= 1; j
< 7; ++j
)
209 for (int k
= 0; k
< (i
== 1 ? 1 : 10); ++k
, ++l
)
210 if (regs
.start
[l
] != match
+ j
211 || regs
.end
[l
] != regs
.start
[l
] + 1)
213 printf ("\nregs.{start,end}[%d] incorrect\n", l
);
219 #if defined _POSIX_CPUTIME && _POSIX_CPUTIME >= 0
221 use_clock
= clock_gettime (cl
, &stop
) == 0;
224 stop
.tv_sec
-= start
.tv_sec
;
225 if (stop
.tv_nsec
< start
.tv_nsec
)
228 stop
.tv_nsec
+= 1000000000 - start
.tv_nsec
;
231 stop
.tv_nsec
-= start
.tv_nsec
;
232 printf (": %ld.%09lds\n", (long) stop
.tv_sec
, (long) stop
.tv_nsec
);
248 #define TEST_FUNCTION do_test ()
249 #include "../test-skeleton.c"