Polly 20.0.0git
Classes | Macros | Functions | Variables
imtest.c File Reference
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "imath.h"
#include "imdrover.h"

Go to the source code of this file.

Classes

struct  test_t
 

Macros

#define LINE_MAX   4096
 

Functions

bool process_file (char *file_name, FILE *ifp, FILE *ofp)
 Reads and runs test cases from ifp and writes test results to ofp.
 
int read_line (FILE *ifp, char *line, int limit)
 
void trim_line (char *line)
 Removes leading and trailing whitespace from a zero-terminated line.
 
int is_blank (char *line)
 Reports whether a zero-terminated line contains only whitespace after a line-trailing comment (# ...) is removed.
 
int parse_line (char *line, testspec_t *t)
 
int count_fields (char *line, int delim)
 Returns the number of delim separated fields occur in line.
 
void parse_fields (char *line, int delim, char **start)
 
int run_test (int test_num, testspec_t *t, FILE *ofp)
 Runs the test cases specified by t, and writes its results to ofp.
 
void free_test (testspec_t *t)
 Releases the memory occupied by a test case invocation.
 
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 a copy.
 
char * error_string (mp_result res)
 Returns a static label string describing res.
 
int main (int argc, char *argv[])
 

Variables

test_t g_tests []
 
char g_line [LINE_MAX]
 
mp_result imath_errno
 
char * imath_errmsg
 
const char * g_imath_strerr []
 

Macro Definition Documentation

◆ LINE_MAX

#define LINE_MAX   4096

Definition at line 85 of file imtest.c.

Function Documentation

◆ count_fields()

int count_fields ( char *  line,
int  delim 
)

Returns the number of delim separated fields occur in line.

Definition at line 314 of file imtest.c.

References count().

Referenced by parse_line().

◆ error_string()

char * error_string ( mp_result  res)

Returns a static label string describing res.

Note that this is not the same as the error string returned by mp_error_string, but corresponds to the spelling of the constant for its value.

Definition at line 419 of file imtest.c.

References abs(), g_imath_strerr, and res.

Referenced by run_test().

◆ find_test()

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 a copy.

It returns -1 if code is unknown.

Definition at line 389 of file imtest.c.

References g_tests.

Referenced by run_test().

◆ free_test()

void free_test ( testspec_t t)

Releases the memory occupied by a test case invocation.

Definition at line 403 of file imtest.c.

References assert, and t.

Referenced by process_file().

◆ is_blank()

int is_blank ( char *  line)

Reports whether a zero-terminated line contains only whitespace after a line-trailing comment (# ...) is removed.

Definition at line 277 of file imtest.c.

Referenced by read_line().

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 179 of file imtest.c.

References init_testing(), and process_file().

◆ parse_fields()

void parse_fields ( char *  line,
int  delim,
char **  start 
)

Definition at line 326 of file imtest.c.

References pos().

Referenced by parse_line().

◆ parse_line()

int parse_line ( char *  line,
testspec_t t 
)

Definition at line 283 of file imtest.c.

References count_fields(), parse_fields(), and t.

Referenced by process_file().

◆ process_file()

bool process_file ( char *  file_name,
FILE *  ifp,
FILE *  ofp 
)

Reads and runs test cases from ifp and writes test results to ofp.

The given file_name is used for cosmetic attribution. The return value is true if all tests passed, false if any tests failed or had errors.

Definition at line 209 of file imtest.c.

References free_test(), g_line, LINE_MAX, parse_line(), read_line(), res, run_test(), and t.

Referenced by main().

◆ read_line()

int read_line ( FILE *  ifp,
char *  line,
int  limit 
)

Definition at line 240 of file imtest.c.

References is_blank(), and trim_line().

Referenced by process_file().

◆ run_test()

int run_test ( int  test_num,
testspec_t t,
FILE *  ofp 
)

Runs the test cases specified by t, and writes its results to ofp.

The test_num is used in log output and should reflect the global ordering of tests, but is not otherwise interpreted by this function.

This function returns 0 if the test succeeds, 1 if the test fails, and -1 if the test is broken (e.g., its code is unknown).

Definition at line 342 of file imtest.c.

References test_t::call, error_string(), find_test(), imath_errmsg, imath_errno, MP_BADARG, test_t::num_inputs, test_t::num_outputs, and t.

Referenced by process_file().

◆ trim_line()

void trim_line ( char *  line)

Removes leading and trailing whitespace from a zero-terminated line.

Definition at line 260 of file imtest.c.

Referenced by parse_binary(), parse_int_values(), parse_rat_values(), read_line(), test_qrdec(), test_qtodec(), test_qtostr(), test_read_binary(), test_read_uns(), test_to_uns(), test_tobin(), and test_tostr().

Variable Documentation

◆ g_imath_strerr

const char* g_imath_strerr[]
Initial value:
= {"MP_OK", "MP_TRUE", "MP_MEMORY", "MP_RANGE",
"MP_UNDEF", "MP_TRUNC", "MP_BADARG"}

Definition at line 164 of file imtest.c.

Referenced by error_string().

◆ g_line

char g_line[LINE_MAX]

Definition at line 159 of file imtest.c.

Referenced by process_file().

◆ g_tests

test_t g_tests[]

Definition at line 94 of file imtest.c.

Referenced by find_test().

◆ imath_errmsg

char* imath_errmsg
extern

Definition at line 39 of file imdrover.c.

Referenced by init_testing(), and run_test().

◆ imath_errno

mp_result imath_errno
extern

Definition at line 38 of file imdrover.c.

Referenced by run_test().