165 "MP_UNDEF",
"MP_TRUNC",
"MP_BADARG"};
167bool process_file(
char *file_name, FILE *ifp, FILE *ofp);
168int read_line(FILE *ifp,
char *line,
int limit);
179int main(
int argc,
char *argv[]) {
185 fprintf(stderr,
"[reading from stdin]\n");
191 for (i = 1; i < argc; ++i) {
192 if (strcmp(argv[i],
"-") == 0) {
194 }
else if ((ifp = fopen(argv[i],
"r")) == NULL) {
195 fprintf(stderr,
"Cannot open '%s': %s\n", argv[i], strerror(errno));
198 if (!
process_file(argv[i], ifp, stdout)) exit_status = 1;
210 int res, line_num, test_num = 0, num_failed = 0, num_bogus = 0;
211 clock_t start, finish;
221 }
else if (
res == 0) {
226 fprintf(stderr,
"Line %d: Incorrect input syntax.\n", line_num);
233 "# %s %d tests: %d passed, %d failed, %d errors. (%.2f seconds)\n",
234 file_name, test_num, (test_num - num_failed - num_bogus), num_failed,
235 num_bogus, ((
double)(finish - start) / CLOCKS_PER_SEC));
237 return num_failed == 0 && num_bogus == 0;
241 static FILE *current_fp = NULL;
242 static int current_line = 0;
244 if (ifp != current_fp) {
250 if (fgets(line, limit, ifp) == NULL)
return 0;
265 while (isspace((
unsigned char)*fnw)) ++fnw;
268 memmove(line, fnw, len);
271 fnw = line + len - 1;
272 while (fnw >= line && isspace((
unsigned char)*fnw)) *fnw-- =
'\0';
278 while (*line && *line !=
'#' && isspace((
unsigned char)*line)) ++line;
280 return *line ==
'\0' || *line ==
'#';
284 char *code_brk, *in_brk;
287 if ((code_brk = strchr(line,
':')) == NULL)
return 0;
288 if ((in_brk = strchr(code_brk + 1,
':')) == NULL)
return 0;
295 t->num_inputs = num_fields;
299 t->num_outputs = num_fields;
302 if (
t->num_inputs > 0) {
303 t->input = calloc(
t->num_inputs,
sizeof(
char *));
306 if (
t->num_outputs > 0) {
307 t->output = calloc(
t->num_outputs,
sizeof(
char *));
317 if (*line ==
'\0')
return 0;
320 if (*line == (
char)delim && *(line + 1) !=
'\0') ++
count;
330 while ((line = strchr(line, delim)) != NULL) {
347 fprintf(stderr,
"Line %d: Test code '%s' is unknown.\n",
t->line,
t->code);
354 "Line %d: Wrong number of inputs to %s (want %d, have %d)\n",
360 "Line %d: Wrong number of outputs to %s (want %d, have %d)\n",
365 fprintf(stderr,
"Line %d: %d error(s), skipping this test.\n",
t->line,
374 if ((info.
call)(
t, ofp)) {
375 fprintf(ofp,
"%s\t%d\t%d\tOK\n",
t->file,
t->line, test_num);
378 fprintf(ofp,
"%s\t%d\t%d\t%s\n",
t->file,
t->line, test_num,
381 fprintf(ofp,
"%s\t%d\t%d\tFAILED\t%s\n",
t->file,
t->line, test_num,
392 while (
g_tests[i].code != NULL) {
393 if (strcmp(
g_tests[i].code, code) == 0) {
406 if (
t->input != NULL) {
410 if (
t->output != NULL) {
void GMPZAPI() abs(mp_int rop, mp_int op)
bool test_qtodec(testspec_t *t, FILE *ofp)
bool test_qsubz(testspec_t *t, FILE *ofp)
bool test_divv(testspec_t *t, FILE *ofp)
bool test_mod(testspec_t *t, FILE *ofp)
bool test_sqrt(testspec_t *t, FILE *ofp)
bool test_abs(testspec_t *t, FILE *ofp)
bool test_comp(testspec_t *t, FILE *ofp)
bool test_div(testspec_t *t, FILE *ofp)
bool test_read_uns(testspec_t *t, FILE *ofp)
bool test_mul(testspec_t *t, FILE *ofp)
bool test_qaddz(testspec_t *t, FILE *ofp)
bool test_exptf(testspec_t *t, FILE *ofp)
bool test_exptmod_ev(testspec_t *t, FILE *ofp)
bool test_qdivz(testspec_t *t, FILE *ofp)
bool test_qdiv(testspec_t *t, FILE *ofp)
bool test_set(testspec_t *t, FILE *ofp)
bool test_vcomp(testspec_t *t, FILE *ofp)
bool test_invmod(testspec_t *t, FILE *ofp)
bool test_zcomp(testspec_t *t, FILE *ofp)
bool test_qmul(testspec_t *t, FILE *ofp)
bool test_sqr(testspec_t *t, FILE *ofp)
bool test_init(testspec_t *t, FILE *ofp)
bool test_add(testspec_t *t, FILE *ofp)
bool test_qadd(testspec_t *t, FILE *ofp)
bool test_expt(testspec_t *t, FILE *ofp)
bool test_gcd(testspec_t *t, FILE *ofp)
bool test_neg(testspec_t *t, FILE *ofp)
bool test_qtostr(testspec_t *t, FILE *ofp)
bool test_exptmod_bv(testspec_t *t, FILE *ofp)
bool test_to_uint(testspec_t *t, FILE *ofp)
bool test_read_binary(testspec_t *t, FILE *ofp)
bool test_ucomp(testspec_t *t, FILE *ofp)
bool test_lcm(testspec_t *t, FILE *ofp)
bool test_egcd(testspec_t *t, FILE *ofp)
bool test_qrecip(testspec_t *t, FILE *ofp)
bool test_tostr(testspec_t *t, FILE *ofp)
bool test_mulv(testspec_t *t, FILE *ofp)
bool test_qexpt(testspec_t *t, FILE *ofp)
bool test_qmulz(testspec_t *t, FILE *ofp)
bool test_meta(testspec_t *t, FILE *ofp)
bool test_uvcomp(testspec_t *t, FILE *ofp)
bool test_divp2(testspec_t *t, FILE *ofp)
bool test_to_int(testspec_t *t, FILE *ofp)
bool test_qrdec(testspec_t *t, FILE *ofp)
bool test_qneg(testspec_t *t, FILE *ofp)
bool test_mulp2(testspec_t *t, FILE *ofp)
bool test_qabs(testspec_t *t, FILE *ofp)
bool test_root(testspec_t *t, FILE *ofp)
bool test_sub(testspec_t *t, FILE *ofp)
bool test_qsub(testspec_t *t, FILE *ofp)
bool test_is_prime(testspec_t *t, FILE *OFP)
bool test_tobin(testspec_t *t, FILE *ofp)
bool test_exptmod(testspec_t *t, FILE *ofp)
bool test_exptv(testspec_t *t, FILE *ofp)
bool test_to_uns(testspec_t *t, FILE *ofp)
bool(* test_f)(testspec_t *, FILE *)
void parse_fields(char *line, int delim, char **start)
char * error_string(mp_result res)
Returns a static label string describing res.
int find_test(char *code, test_t *info)
Locates the run instructions for the specified test code, and if they are found populates *info with ...
int read_line(FILE *ifp, char *line, int limit)
const char * g_imath_strerr[]
int count_fields(char *line, int delim)
Returns the number of delim separated fields occur in line.
int is_blank(char *line)
Reports whether a zero-terminated line contains only whitespace after a line-trailing comment (# ....
bool process_file(char *file_name, FILE *ifp, FILE *ofp)
Reads and runs test cases from ifp and writes test results to ofp.
void free_test(testspec_t *t)
Releases the memory occupied by a test case invocation.
void trim_line(char *line)
Removes leading and trailing whitespace from a zero-terminated line.
int parse_line(char *line, testspec_t *t)
int run_test(int test_num, testspec_t *t, FILE *ofp)
Runs the test cases specified by t, and writes its results to ofp.
static int count(int *con, unsigned len, int status)
static unsigned pos(__isl_keep isl_space *space, enum isl_dim_type type)