Beispiel #1
0
class signal_h(c.Test):
    header = c.header_test('signal.h')

    sig_atomic_t = c.type_test()
    SIG_DFL = c.macro_test()
    SIG_ERR = c.macro_test()
    SIG_IGN = c.macro_test()
    SIGABRT = c.macro_test()
    SIGFPE = c.macro_test()
    SIGILL = c.macro_test()
    SIGINT = c.macro_test()
    SIGSEGV = c.macro_test()
    SIGTERM = c.macro_test()
    signal = c.function_test(c.Function('void', 'int'),
                             'int',
                             c.Function('void', 'int'),
                             test='''
        #include <signal.h>
        void foo(int x) {}
        int main() {
            void (*f)(int) = signal(SIGTERM, foo);
            return 0;
        }
        ''')
    raise_ = c.function_test('int',
                             'int',
                             name='raise',
                             test='''
        #include <signal.h>
        int main() {
            signal(SIGTERM, SIG_IGN);
            return raise(SIGTERM) == 0 ? 0 : 1;
        }
        ''')
Beispiel #2
0
class stdlib_h(stdlib_h):
    mkdtemp = c.function_test('char*',
                              'char*',
                              test='''
        #include <stdlib.h>
        #include <unistd.h>
        int main() {
            char s[] = "XXXXXX";
            if (mkdtemp(s) == NULL) return 1;
            if (rmdir(s) == -1) return 1;
            return 0;
        }
        ''')
    strtoq = c.function_test('quad_t',
                             'const char*',
                             'char**',
                             test='''
        #include <stdlib.h>
        #include <sys/types.h>
        int main() {
            char* s1 = "15";
            char* s2 = "abc";
            char* endp;
            quad_t d = strtoq(s1, &endp, 8);
            if (s1 != endp && *endp == '\\0' && d == 13l) {
                d = strtoq(s2, &endp, 8);
                return s1 == endp || *endp != '\\0' ? 0 : 1;
            }
            return 1;
        }
        ''')
Beispiel #3
0
class strings_h(c.Test):
    header = c.header_test('strings.h')

    bcmp = c.function_test('int', 'const void*', 'const void*', 'size_t')
    bcopy = c.function_test('void',
                            'const void*',
                            'void*',
                            'size_t',
                            default_args=(0, 0, 0))
    bzero = c.function_test('void', 'void*', 'size_t')
Beispiel #4
0
class stdlib_h(c.Test):
    header = c.header_test('stdlib.h')

    ecvt = c.function_test('char*',
                           'double',
                           'int',
                           'int*',
                           'int*',
                           test='''
        #include <stdlib.h>
        int main() {
            int decpt;
            int sign;
            char* s = ecvt(0.0, 1, &decpt, &sign);
            return s[0] == '0' && s[1] == '\\0' ? 0 : 1;
        }
        ''')
    fcvt = c.function_test('char*',
                           'double',
                           'int',
                           'int*',
                           'int*',
                           test='''
        #include <stdlib.h>
        int main() {
            int decpt;
            int sign;
            char* s = fcvt(0.0, 1, &decpt, &sign);
            return s[0] == '0' && s[1] == '\\0' ? 0 : 1;
        }
        ''')
    gcvt = c.function_test('char*',
                           'double',
                           'int',
                           'char*',
                           test='''
        #include <stdlib.h>
        int main() {
            char s[50] = {0};
            int decpt;
            int sign;
            gcvt(0.0, 1, s);
            return s[0] == '0' && s[1] == '\\0' ? 0 : 1;
        }
        ''')
    mktemp = c.function_test('char*',
                             'char*',
                             test='''
        #include <stdlib.h>
        int main() {
            char s[] = "XXXXXX";
            return mktemp(s) == NULL ? 1 : 0;
        }
        ''')
Beispiel #5
0
class math_h(math_h):
    finite = c.function_test('int', 'double')
    finitef = c.function_test('int', 'float')
    finitel = c.function_test('int', 'long double')
    isinf = c.function_test('int', 'double')
    isinff = c.function_test('int', 'float')
    isinfl = c.function_test('int', 'long double')
    isnan = c.function_test('int', 'double')
    isnanf = c.function_test('int', 'float')
    isnanl = c.function_test('int', 'long double')
Beispiel #6
0
class string_h(c99.string_h):
    strdup = c.function_test('char*', 'const char*')
    strerror_r = c.function_test('int',
                                 'int',
                                 'char*',
                                 'size_t',
                                 test='''
        #include <string.h>
        int main() {
            char b[50];
            int r = strerror_r(0, b, 50);
            return r == 0 ? 0 : 1;
        }
        ''')
Beispiel #7
0
class aio_h(c.Test):
    header = c.header_test('aio.h')

    aiocb = c.struct_test(('int', 'aio_fildes'), ('off_t', 'aio_offset'),
                          ('volatile void*', 'aio_buf'),
                          ('size_t', 'aio_nbytes'), ('int', 'aio_reqprio'),
                          ('struct sigevent', 'aio_sigevent'),
                          ('int', 'aio_lio_opcode'))

    AIO_ALLDONE = c.variable_test()
    AIO_CANCELED = c.variable_test()
    AIO_NOTCANCELED = c.variable_test()
    LIO_NOP = c.variable_test()
    LIO_NOWAIT = c.variable_test()
    LIO_READ = c.variable_test()
    LIO_WAIT = c.variable_test()
    LIO_WRITE = c.variable_test()
    aio_cancel = c.function_test('int', 'int', 'struct aiocb*')
    aio_error = c.function_test('int', 'const struct aiocb*')
    aio_fsync = c.function_test('int', 'int, struct aiocb*')
    aio_read = c.function_test('int', 'struct aiocb*')
    aio_return = c.function_test('ssize_t', 'struct aiocb*')
    aio_suspend = c.function_test('int', 'const struct aiocb**', 'int',
                                  'const struct timespec*')
    aio_write = c.function_test('int', 'struct aiocb*')
    lio_listio = c.function_test('int', 'int', 'struct aiocb* const', 'int',
                                 'struct sigevent*')
Beispiel #8
0
class sys_epoll_h(c.Test):
    header = c.header_test('sys/epoll.h')

    EPOLLIN = c.macro_test()
    EPOLLPRI = c.macro_test()
    EPOLLOUT = c.macro_test()
    EPOLLRDNORM = c.macro_test()
    EPOLLRDBAND = c.macro_test()
    EPOLLWRNORM = c.macro_test()
    EPOLLWRBAND = c.macro_test()
    EPOLLMSG = c.macro_test()
    EPOLLERR = c.macro_test()
    EPOLLHUP = c.macro_test()
    EPOLLONESHOT = c.macro_test()
    EPOLLET = c.macro_test()
    EPOLL_CTL_ADD = c.macro_test()
    EPOLL_CTL_DEL = c.macro_test()
    EPOLL_CTL_MOD = c.macro_test()
    epoll_data_t = c.type_test()
    epoll_event = c.struct_test(('uint32_t', 'events'),
                                ('epoll_data_t', 'data'))
    epoll_create = c.function_test('int',
                                   'int',
                                   test='''
        #include <sys/epoll.h>
        int main(int argc, char** argv) {
            int efd = epoll_create(20);
            return (-1 == efd) ? 1 : 0;
        }
        ''')
    epoll_ctl = c.function_test('int',
                                'int',
                                'int',
                                'int',
                                'struct epoll_event*',
                                test='''
        #include <stdio.h>
        #include <sys/epoll.h>
        int main(int argc, char** argv) {
            int efd = epoll_create(20);
            struct epoll_event event;
            return epoll_ctl(efd, EPOLL_CTL_ADD, fileno(stdin), &event) == 0 ? 0 : 1;
        }
        ''')
    epoll_wait = c.function_test('int', 'int', 'struct epoll_event*', 'int',
                                 'int')
Beispiel #9
0
class execinfo_h(c.Test):
    header = c.header_test('execinfo.h')

    backtrace = c.function_test('int',
                                'void**',
                                'int',
                                test='''
        #include <execinfo.h>
        int main() {
            void* callstack[128];
            int frames = backtrace(callstack, 128);
            char** strs = backtrace_symbols(callstack, frames);
            return 0;
        }
        ''')
    backtrace_symbols = c.function_test('char**',
                                        'void* const*',
                                        'int',
                                        test=backtrace.test)
    backtrace_symbols_fd = c.function_test('void', 'void* const*', 'int',
                                           'int')
Beispiel #10
0
class unistd_h(c.Test):
    header = c.header_test('unistd.h')

    getcwd = c.function_test('char*', 'char*', 'size_t')
    getopt = c.function_test('int',
                             'int',
                             'char**',
                             'char*',
                             test='''
        #include <unistd.h>
        int main(int argc, char** argv) {
            int ch, ret = 0;
            while ((ch = getopt(argc, argv, "f")) != -1) {
                switch (ch) {
                case 'f':
                    break;
                default:
                    ret = 1;
                }
            }

            return ret;
        }
        ''')
    getpagesize = c.function_test('int', 'void')
    isatty = c.function_test('int', 'int')
    sysconf = c.function_test('long', 'int', default_args=('0', ))
    ttyname = c.function_test('char*', 'int')
Beispiel #11
0
class sys_mman_h(sys_mman_h):
    MADV_DOFORK = c.macro_test()
    MADV_DONTFORK = c.macro_test()
    MADV_DONTNEED = c.macro_test()
    MADV_FREE = c.macro_test()
    MADV_NORMAL = c.macro_test()
    MADV_RANDOM = c.macro_test()
    MADV_REMOVE = c.macro_test()
    MADV_SEQUENTIAL = c.macro_test()
    MADV_WILLNEED = c.macro_test()
    MAP_32BIT = c.macro_test()
    MAP_ANON = c.macro_test()
    MAP_ANONYMOUS = c.macro_test()
    MAP_COPY = c.macro_test()
    MAP_DENYWRITE = c.macro_test()
    MAP_EXECUTABLE = c.macro_test()
    MAP_FILE = c.macro_test()
    MAP_GROWSDOWN = c.macro_test()
    MAP_HASSEMAPHORE = c.macro_test()
    MAP_LOCKED = c.macro_test()
    MAP_NOCACHE = c.macro_test()
    MAP_NOEXTEND = c.macro_test()
    MAP_NONBLOCK = c.macro_test()
    MAP_NORESERVE = c.macro_test()
    MAP_POPULATE = c.macro_test()
    MAP_RENAME = c.macro_test()
    MAP_SHARED = c.macro_test()
    MAP_TYPE = c.macro_test()
    MINCORE_INCORE = c.macro_test()
    MINCORE_MODIFIED = c.macro_test()
    MINCORE_MODIFIED_OTHER = c.macro_test()
    MINCORE_REFERENCED = c.macro_test()
    MINCORE_REFERENCED_OTHER = c.macro_test()
    MREMAP_FIXED = c.macro_test()
    MREMAP_MAYMOVE = c.macro_test()
    PROT_GROWSDOWN = c.macro_test()
    PROT_GROWSUP = c.macro_test()
    madvise = c.function_test('void*', 'size_t', 'int')
    mincore = c.function_test('int', 'const void*', 'size_t', 'char*')
    minherit = c.function_test('void*', 'size_t', 'int')
Beispiel #12
0
    def open(self):
        with tempfile.NamedTemporaryFile() as f:
            test = '''
                #include <fcntl.h>
                int main() {
                    int fd;
                    if ((fd = open("%s", O_RDONLY)) == -1) return 1;
                    return 0;
                }
                ''' % f.name

            if self.builder.check_run(test, "checking open in 'fcntl.h'"):
                return c.function_test('int', 'const char*', 'int')
Beispiel #13
0
    def open(self):
        with tempfile.NamedTemporaryFile() as f:
            test = '''
                #include <fcntl.h>
                int main() {
                    int fd;
                    if ((fd = open("%s", O_RDONLY)) == -1) return 1;
                    return 0;
                }
                ''' % f.name

            if self.builder.check_run(test, "checking open in 'fcntl.h'"):
                return c.function_test('int', 'const char*', 'int')
Beispiel #14
0
class locale_h(c.Test):
    header = c.header_test('locale.h')

    LC_ALL = c.macro_test()
    LC_COLLATE = c.macro_test()
    LC_CTYPE = c.macro_test()
    LC_MONETARY = c.macro_test()
    LC_NUMERIC = c.macro_test()
    LC_TIME = c.macro_test()
    NULL = c.macro_test()
    lconv = c.struct_test(
        ('char*', 'decimal_point'), ('char*', 'thousands_sep'),
        ('char*', 'grouping'), ('char*', 'int_curr_symbol'),
        ('char*', 'currency_symbol'), ('char*', 'mon_decimal_point'),
        ('char*', 'mon_thousands_sep'), ('char*', 'mon_grouping'),
        ('char*', 'positive_sign'), ('char*', 'negative_sign'),
        ('char', 'int_frac_digits'), ('char', 'frac_digits'),
        ('char', 'p_cs_precedes'), ('char', 'p_sep_by_space'),
        ('char', 'n_cs_precedes'), ('char', 'n_sep_by_space'),
        ('char', 'p_sign_posn'), ('char', 'n_sign_posn'))
    setlocale = c.function_test('char*', 'int', 'const char*')
    localeconv = c.function_test('struct lconv*', 'void')
Beispiel #15
0
class port_h(c.Test):
    header = c.header_test('port.h')

    port_create = c.function_test('int',
                                  'void',
                                  test='''
        #include <port.h>
        int main(int argc, char** argv) {
            int port = port_create();
            if (port < 0) { return 1; }
            if (close(port) < 0) { return 1; }
            return 0;
        }
        ''')
Beispiel #16
0
class malloc_malloc_h(c.Test):
    header = c.header_test('malloc/malloc.h')

    malloc_zone_statistics = c.function_test('void',
                                             'malloc_zone_t*',
                                             'malloc_statistics_t*',
                                             test='''
        #include <malloc/malloc.h>
        int main() {
            malloc_statistics_t stats;
            malloc_zone_statistics(malloc_default_zone(), &stats);
            return 0;
        }
        ''')
Beispiel #17
0
class sys_time_h(c.Test):
    header = c.header_test('sys/time.h')

    gettimeofday = c.function_test('int',
                                   'struct timeval*',
                                   'void*',
                                   test='''
        #include <sys/time.h>
        int main() {
            struct timeval tp;
            return gettimeofday(&tp, 0) == 0 ? 0 : 1;
        }
        ''')
    settimeofday = c.function_test('int',
                                   'struct timeval*',
                                   'void*',
                                   test='''
        #include <sys/time.h>
        /* Don't actually call settimeofday because it modifies the global
         * time. */
        void foo() { settimeofday(0, 0); }
        int main() { return 0; }
        ''')
Beispiel #18
0
class unistd_h(c.Test):
    header = c.header_test('unistd.h')

    brk = c.function_test('void*', 'void*')
    getopt = c.function_test('int',
                             'int',
                             'char**',
                             'char*',
                             test='''
        #include <unistd.h>
        int main(int argc, char** argv) {
            int ch, ret = 0;
            while ((ch = getopt(argc, argv, "f")) != -1) {
                switch (ch) {
                case 'f':
                    break;
                default:
                    ret = 1;
                }
            }

            return ret;
        }
        ''')
    getwd = c.function_test('char*',
                            'char*',
                            test='''
        #include <unistd.h>
        #include <sys/param.h>
        int main() {
            char arg[MAXPATHLEN];
            char* res = getwd(arg);
            return 0;
        }
        ''')
    sbrk = c.function_test('void*', 'intptr_t')
    ttyslot = c.function_test('int', 'void')
Beispiel #19
0
class sys_event_h(c.Test):
    header = c.header_test('sys/event.h')

    kqueue = c.function_test('int',
                             'void',
                             test='''
        #include <sys/types.h>      // from the kqueue manpage
        #include <sys/event.h>      // kernel events
        #include <sys/time.h>       // timespec (kevent timeout)

        int main(int argc, char** argv) {
            int kq = kqueue();
            return (-1 == kq) ? 1 : 0;
        }
        ''')
Beispiel #20
0
class arpa_inet_h(c.Test):
    header = c.header_test('arpa/inet.h')

    in_port_t = c.type_test()
    in_addr_t = c.type_test()
    in_addr = c.struct_test(('sa_family_t', 'sin_family'),
                            ('in_port_t', 'sin_port'),
                            ('struct in_addr', 'sin_addr'))
    INET_ADDRSTRLEN = c.macro_test()
    INET6_ADDRSTRLEN = c.macro_test()
    htonl = c.function_test('uint32_t', 'uint32_t')
    htons = c.function_test('uint16_t', 'uint16_t')
    ntohl = c.function_test('uint32_t', 'uint32_t')
    ntohs = c.function_test('uint16_t', 'uint16_t')
    inet_addr = c.function_test('in_addr_t', 'constchar*')
    inet_ntoa = c.function_test('char*', 'struct in_addr')
    inet_ntop = c.function_test('const char*', 'int', 'const void*', 'char*',
                                'socklen_t')
    inet_pton = c.function_test('int', 'int', 'const char*', 'void*')
Beispiel #21
0
class setjmp_h(c99.setjmp_h):
    sigjmp_buf = c.type_test()

    siglongjmp = c.function_test('void',
                                 'sigjmp_buf',
                                 'int',
                                 test='''
        #include <setjmp.h>
        int main() {
            jmp_buf env;
            int i = sigsetjmp(env, 0);
            if (i == 2) return 0;
            siglongjmp(env, 2);
            return 2;
        }
        ''')

    @property
    def sigsetjmp(self):
        if self.siglongjmp:
            return c.Function('int', 'sigjmp_buf', 'int')
Beispiel #22
0
class setjmp_h(c.Test):
    header = c.header_test('setjmp.h')

    jmp_buf = c.type_test()

    longjmp = c.function_test('void',
                              'jmp_buf',
                              'int',
                              test='''
        #include <setjmp.h>
        int main() {
            jmp_buf env;
            int i = setjmp(env);
            if (i == 2) return 0;
            longjmp(env, 2);
            return 2;
        }
        ''')

    @property
    def setjmp(self):
        if self.longjmp:
            return c.Function('int', 'jmp_buf')
Beispiel #23
0
class stdlib_h(c99.stdlib_h):
    drand48 = c.function_test('double', 'void')
    lrand48 = c.function_test('long', 'void')
    mkstemp = c.function_test('int',
                              'char*',
                              test='''
        #include <stdlib.h>
        #include <unistd.h>
        int main() {
            char s[] = "XXXXXX";
            int fd;
            if ((fd = mkstemp(s)) == -1) return 1;
            if (close(fd) == -1) return 1;
            return 0;
        }
        ''')
    realpath = c.function_test('char*', 'const char*', 'char*')
    srand = c.function_test('void', 'unsigned int')
    srand48 = c.function_test('void', 'long')
Beispiel #24
0
class math_h(c.Test):
    header = c.header_test('math.h')

    HUGE_VAL = c.macro_test()
    acos = c.function_test('double', 'double')
    asin = c.function_test('double', 'double')
    atan = c.function_test('double', 'double')
    atan2 = c.function_test('double', 'double', 'double')
    cos = c.function_test('double', 'double')
    sin = c.function_test('double', 'double')
    tan = c.function_test('double', 'double')
    cosh = c.function_test('double', 'double')
    sinh = c.function_test('double', 'double')
    tanh = c.function_test('double', 'double')
    exp = c.function_test('double', 'double')
    frexp = c.function_test('double',
                            'double',
                            'int*',
                            test='''
        #include <math.h>
        int main() {
            int d0;
            double d1 = frexp(0., &d0);
            return 0;
        }
        ''')
    ldexp = c.function_test('double', 'double', 'int')
    log = c.function_test('double', 'double')
    log10 = c.function_test('double', 'double')
    modf = c.function_test('double',
                           'double',
                           'double*',
                           test='''
        #include <math.h>
        int main() {
            double d0;
            double d1 = modf(0., &d0);
            return 0;
        }
        ''')
    pow = c.function_test('double', 'double', 'double')
    sqrt = c.function_test('double', 'double')
    ceil = c.function_test('double', 'double')
    fabs = c.function_test('double', 'double')
    floor = c.function_test('double', 'double')
    fmod = c.function_test('double', 'double', 'double')
Beispiel #25
0
class unistd_h(unistd_h):
    mkstemps = c.function_test('int', 'char*', 'int')
    mkdtemp = c.function_test('char*', 'char*')
Beispiel #26
0
 def feof(self):
     if self.fopen:
         return c.function_test('int', 'FILE*')
Beispiel #27
0
class omp_h(c.Test):
    header = c.header_test('omp.h')

    omp_get_thread_num = c.function_test('int', 'void')
Beispiel #28
0
class stdlib_h(c.Test):
    header = c.header_test('stdlib.h')

    EXIT_FAILURE = c.macro_test()
    EXIT_SUCCESS = c.macro_test()
    MB_CUR_MAX = c.macro_test()
    NULL = c.macro_test()
    RAND_MAX = c.macro_test()
    div_t = c.type_test()
    ldiv_t = c.type_test()
    size_t = c.int_type_test()
    wchar_t = c.int_type_test()
    atof = c.function_test('double',
                           'const char*',
                           test='''
        #include <stdlib.h>
        int main() {
            return atof("0.5") == 0.5 ? 0 : 1;
        }
        ''')
    atoi = c.function_test('int',
                           'const char*',
                           test='''
        #include <stdlib.h>
        int main() {
            return atoi("1234") == 1234 ? 0 : 1;
        }
        ''')
    atol = c.function_test('long int',
                           'const char*',
                           test='''
        #include <stdlib.h>
        int main() {
            return atol("1234") == 1234L ? 0 : 1;
        }
        ''')
    strtod = c.function_test('double',
                             'const char*',
                             'char**',
                             test='''
        #include <stdlib.h>
        int main() {
            char* s1 = "0.5";
            char* s2 = "abc";
            char* endp;
            double d = strtod(s1, &endp);
            if (s1 != endp && *endp == '\\0' && d == 0.5) {
                d = strtod(s2, &endp);
                return s1 == endp || *endp != '\\0' ? 0 : 1;
            }
            return 1;
        }
        ''')
    strtol = c.function_test('long int',
                             'const char*',
                             'char**',
                             'int',
                             test='''
        #include <stdlib.h>
        int main() {
            char* s1 = "15";
            char* s2 = "abc";
            char* endp;
            long int d = strtol(s1, &endp, 8);
            if (s1 != endp && *endp == '\\0' && d == 13l) {
                d = strtol(s2, &endp, 8);
                return s1 == endp || *endp != '\\0' ? 0 : 1;
            }
            return 1;
        }
        ''')
    strtoul = c.function_test('unsigned long int',
                              'const char*',
                              'char**',
                              'int',
                              test='''
        #include <stdlib.h>
        int main() {
            char* s1 = "15";
            char* s2 = "abc";
            char* endp;
            unsigned long int d = strtoul(s1, &endp, 8);
            if (s1 != endp && *endp == '\\0' && d == 13ul) {
                d = strtoul(s2, &endp, 8);
                return s1 == endp || *endp != '\\0' ? 0 : 1;
            }
            return 1;
        }
        ''')
    rand = c.function_test('int', 'void')
    srand = c.function_test('void', 'unsigned int')
    calloc = c.function_test('void*', 'size_t', 'size_t')
    free = c.function_test('void',
                           'void* ptr',
                           test='''
        #include <stdlib.h>
        int main() {
            void* p = malloc(5);
            if (!p) return 1;
            free(p);
            return 0;
        }
        ''')
    malloc = c.function_test('void*', 'size_t', test=free.test)
    realloc = c.function_test('void*',
                              'void*',
                              'size_t',
                              test='''
        #include <stdlib.h>
        int main() {
            void* p = malloc(5);
            if (!p) return 1;
            p = realloc(p, 6);
            if (!p) return 1;
            free(p);
            return 0;
        }
        ''')

    @c.cacheproperty
    def abort(self):
        self.ctx.logger.check("checking abort in 'stdlib.h'")

        with self.builder.tempfile('''
                #include <stdlib.h>
                #ifdef _WIN32
                #include <windows.h>
                #endif

                int main() {
                #ifdef _WIN32
                    /* Turn off the windows error box */
                    DWORD dwMode = SetErrorMode(SEM_NOGPFAULTERRORBOX);
                    SetErrorMode(dwMode | SEM_NOGPFAULTERRORBOX);
                #endif
                    abort();
                    return 0;
                }
                ''') as src:
            dst = src.parent / 'temp'
            try:
                obj = self.builder.uncached_compile(src, quieter=1)
                exe = self.builder.uncached_link_exe(dst, [obj], quieter=1)
            except fbuild.ExecutionError:
                pass
            else:
                try:
                    self.builder.ctx.execute([exe], quieter=1)
                except fbuild.ExecutionError as e:
                    self.ctx.logger.passed()
                    return c.Function('void', 'void')

        self.ctx.logger.failed()

    atexit = c.function_test('int',
                             'void (*f)(void)',
                             test='''
        #include <stdio.h>
        #include <stdlib.h>
        void f() { printf("passed"); }
        int main() {
            atexit(&f);
            return 0;
        }
        ''',
                             stdout=b'passed')

    exit = c.function_test('void',
                           'int',
                           test='''
        #include <stdlib.h>
        int main() {
            exit(0);
            return 1;
        }
        ''')
    getenv = c.function_test('char*', 'const char*', default_args=('""', ))
    system = c.function_test('int', 'const char*', default_args=('NULL', ))
    bsearch = c.function_test('void*',
                              'const void*',
                              'const void*',
                              'size_t',
                              'size_t',
                              'int (*f)(const void*, const void*)',
                              test='''
        #include <stdlib.h>
        int f(const void* a, const void* b) { return *(int*)a - *(int*)b; }
        int main() {
            int a[] = {0, 1, 2, 3, 4};
            int b = 3;
            int* c = (int*)bsearch(&b, a, 5, sizeof(a[0]), &f);
            return c && c == &a[3] && *c == 3 ? 0 : 1;
        }
        ''')
    qsort = c.function_test('void',
                            'void*',
                            'size_t',
                            'size_t',
                            'int (*f)(const void*, const void*)',
                            test='''
        #include <stdlib.h>
        int f(const void* a, const void* b) { return *(int*)a - *(int*)b; }
        int main() {
            int a[] = {4, 3, 2, 1, 0};
            qsort(a, 5, sizeof(a[0]), f);
            return
                a[0] == 0 &&
                a[1] == 1 &&
                a[2] == 2 &&
                a[3] == 3 &&
                a[4] == 4 ? 0 : 1;
        }
        ''')
    abs = c.function_test('int', 'int')
    div = c.function_test('div_t', 'int', 'int', default_args=(4, 2))
    labs = c.function_test('long int', 'long int')
    ldiv = c.function_test('ldiv_t',
                           'long int',
                           'long int',
                           default_args=(4, 2))
    mblen = c.function_test('int',
                            'const char*',
                            'size_t',
                            default_args=('""', 0))
    mbtowc = c.function_test('int',
                             'wchar_t*',
                             'const char*',
                             'size_t',
                             test='''
        #include <stdlib.h>
        int main() {
            wchar_t s[50];
            return mbtowc(s, "5", 50) == 1 && s[0] == L'5' ? 0 : 1;
        }
        ''')
    wctomb = c.function_test('int', 'char*', 'wchar_t')
    mbstowcs = c.function_test('size_t',
                               'wchar_t*',
                               'const char*',
                               'size_t',
                               test='''
        #include <stdlib.h>
        int main() {
            wchar_t s[50];
            return mbstowcs(s, "5 6", 50) == 3 &&
                s[0] == L'5' &&
                s[1] == L' ' &&
                s[2] == L'6' &&
                s[3] == L'\\0' ? 0 : 1;
        }
        ''')
    wcstombs = c.function_test('size_t',
                               'char*',
                               'const wchar_t*',
                               'size_t',
                               test='''
        #include <stdlib.h>
        int main() {
            char s[50];
            return wcstombs(s, L"5 6", 50) == 3 &&
                s[0] == '5' &&
                s[1] == ' ' &&
                s[2] == '6' &&
                s[3] == '\\0' ? 0 : 1;
        }
        ''')
Beispiel #29
0
 def feof(self):
     if self.fopen:
         return c.function_test('int', 'FILE*')
Beispiel #30
0
class stdio_h(c.Test):
    header = c.header_test('stdio.h')

    _IOFBF = c.macro_test()
    _IOLBF = c.macro_test()
    _IONBF = c.macro_test()
    BUFSIZ = c.macro_test()
    EOF = c.macro_test()
    FILE = c.type_test()
    FILENAME_MAX = c.macro_test()
    FOPEN_MAX = c.macro_test()
    fpos_t = c.type_test()
    L_tmpnam = c.macro_test()
    NULL = c.macro_test()
    SEEK_CUR = c.macro_test()
    SEEK_END = c.macro_test()
    SEEK_SET = c.macro_test()
    size_t = c.int_type_test()
    stderr = c.variable_test()
    stdin = c.variable_test()
    stdout = c.variable_test()
    TMP_MAX = c.macro_test()
    remove = c.function_test('int', 'const char*', default_args=('""', ))
    rename = c.function_test('int', 'const char*', 'const char*')
    tmpfile = c.function_test('FILE*', 'void')
    tmpnam = c.function_test('char*', 'char*', default_args=('NULL', ))

    @c.cacheproperty
    def fclose(self):
        if self.fopen:
            return c.Function('int', 'FILE*')

    fflush = c.function_test('int',
                             'FILE*',
                             test='''
        #include <stdio.h>
        int main() {
            return fflush(stdout) == 0 ? 0 : 1;
        }
        ''')

    @c.cacheproperty
    def fopen(self):
        with tempfile.NamedTemporaryFile() as f:
            test = '''
                #include <errno.h>
                #include <stdio.h>
                int main() {
                    FILE* f;
                    fpos_t p;
                    if (!(f = fopen("%s", "r"))) return 1;
                    if (ftell(f) != 0) return 1;
                    if (fgetpos(f, &p) != 0) return 1;
                    if (fseek(f, 1L, SEEK_CUR) != 0) return 1;
                    if (ftell(f) != 1) return 1;
                    if (fsetpos(f, &p) != 0) return 1;
                    if (ftell(f) != 0) return 1;
                    if (fflush(NULL) != 0) return 1;
                    if (!(f = freopen(NULL, "r", f))) return 1;
                    errno = 0;
                    rewind(f);
                    if (errno) return 1;
                    if (ferror(f) != 0) return 1;
                    if (feof(f) != 0) return 1;
                    if (fclose(f) != 0) return 1;
                    return 0;
                }
                ''' % f.name

            if self.builder.check_run(test, "checking fopen in 'stdio.h'"):
                return c.Function('FILE*', 'const char*', 'const char*')

    @c.cacheproperty
    def freopen(self):
        if self.fopen:
            return c.Function('FILE*', 'const char*', 'const char*', 'FILE*')

    setbuf = c.function_test('void',
                             'FILE*',
                             'char*',
                             test='''
        #include <stdio.h>
        int main() {
            setbuf(stdout, "");
            return 0;
        }
        ''')
    setvbuf = c.function_test('int',
                              'FILE*',
                              'char*',
                              'int',
                              'size_t',
                              test='''
        #include <stdio.h>
        int main() {
            setvbuf(stdout, "", _IONBF, 0);
            return 0;
        }
        ''')
    fprintf = c.function_test('int',
                              'FILE*',
                              'const char*',
                              test='''
        #include <stdio.h>
        int main() {
            return fprintf(stdout, "%d %d", 5, 6) ? 0 : 1;
        }
        ''',
                              stdout=b'5 6')
    fscanf = c.function_test('int',
                             'FILE*',
                             'const char*',
                             test='''
        #include <stdio.h>
        int main() {
            int x = 0, y = 0;
            return fscanf(stdin, "%d %d", &x, &y) &&
                x == 5 &&
                y == 6 ? 0 : 1;
        }
        ''',
                             stdin=b'5 6')
    printf = c.function_test('int',
                             'const char*',
                             test='''
        #include <stdio.h>
        int main() {
            return printf("%d %d", 5, 6) ? 0 : 1;
        }
        ''',
                             stdout=b'5 6')
    scanf = c.function_test('int',
                            'const char*',
                            test='''
        #include <stdio.h>
        int main() {
            int x = 0, y = 0;
            return scanf("%d %d", &x, &y) &&
                x == 5 &&
                y == 6 ? 0 : 1;
        }
        ''',
                            stdin=b'5 6')
    sprintf = c.function_test('int',
                              'char*',
                              'const char*',
                              test='''
        #include <stdio.h>
        int main() {
            char s[50];
            return sprintf(s, "%d%d", 5, 6) &&
                s[0] == '5' &&
                s[1] == '6' ? 0 : 1;
        }
        ''')
    sscanf = c.function_test('int',
                             'const char*',
                             'const char*',
                             test='''
        #include <stdio.h>
        int main() {
            int x = 0, y = 0;
            return sscanf("5 6", "%d %d", &x, &y) &&
                x == 5 && y == 6 ? 0 : 1;
        }
        ''')
    vfprintf = c.function_test('int',
                               'FILE*',
                               'const char*',
                               'va_list',
                               test='''
        #include <stdarg.h>
        #include <stdio.h>
        int f(char* s, ...) {
            int rc;
            va_list ap;
            va_start(ap, s);
            rc = vfprintf(stdout, s, ap);
            va_end(ap);
            return rc;
        }
        int main() {
            return f("%d %d", 5, 6) ? 0 : 1;
        }
        ''',
                               stdout=b'5 6')
    vprintf = c.function_test('int',
                              'const char*',
                              'va_list',
                              test='''
        #include <stdarg.h>
        #include <stdio.h>
        int f(char* s, ...) {
            int rc;
            va_list ap;
            va_start(ap, s);
            rc = vprintf(s, ap);
            va_end(ap);
            return rc;
        }
        int main() {
            return f("%d %d", 5, 6) ? 0 : 1;
        }
        ''',
                              stdout=b'5 6')
    vsprintf = c.function_test('int',
                               'char*',
                               'const char*',
                               'va_list',
                               test='''
        #include <stdarg.h>
        #include <stdio.h>
        int f(char* s, ...) {
            int rc;
            va_list ap;
            va_start(ap, s);
            rc = vsprintf(s, "%d %d", ap);
            va_end(ap);
            return rc;
        }
        int main() {
            char s[50] = {0};
            return f(s, 5, 6) &&
                s[0] == '5' &&
                s[1] == ' ' &&
                s[2] == '6' &&
                s[3] == '\\0' ? 0 : 1;
        }
        ''')
    fgetc = c.function_test('int',
                            'FILE*',
                            test='''
        #include <stdio.h>
        int main() {
            return fgetc(stdin) == '5' ? 0 : 1;
        }
        ''',
                            stdin=b'5')
    fgets = c.function_test('char*',
                            'char*',
                            'int',
                            'FILE*',
                            test='''
        #include <stdio.h>
        int main() {
            char s[50] = {0};
            return fgets(s, 4, stdin) &&
                s[0] == '5' &&
                s[1] == ' ' &&
                s[2] == '6' &&
                s[3] == '\\0' ? 0 : 1;
        }
        ''',
                            stdin=b'5 6')
    fputc = c.function_test('int',
                            'int',
                            'FILE*',
                            test='''
        #include <stdio.h>
        int main() {
            return fputc('5', stdout) == '5' ? 0 : 1;
        }
        ''',
                            stdout=b'5')
    fputs = c.function_test('int',
                            'const char*',
                            'FILE*',
                            test='''
        #include <stdio.h>
        int main() {
            return fputs("5 6", stdout) ? 0 : 1;
        }
        ''',
                            stdout=b'5 6')
    getc = c.function_test('int',
                           'FILE*',
                           test='''
        #include <stdio.h>
        int main() {
            return getc(stdin) == '5' ? 0 : 1;
        }
        ''',
                           stdin=b'5')
    getchar = c.function_test('int',
                              'void',
                              test='''
        #include <stdio.h>
        int main() {
            return getchar() == '5' ? 0 : 1;
        }
        ''',
                              stdin=b'5')
    gets = c.function_test('char*',
                           'char*',
                           test='''
        #include <stdio.h>
        int main() {
            char s[50] = {0};
            return s == gets(s) &&
                s[0] == '5' &&
                s[1] == ' ' &&
                s[2] == '6' &&
                s[3] == '\\0' ? 0 : 1;
        }
        ''',
                           stdin=b'5 6')
    putc = c.function_test('int',
                           'int',
                           'FILE*',
                           test='''
        #include <stdio.h>
        int main() {
            return putc('5', stdout) == '5' ? 0 : 1;
        }
        ''',
                           stdout=b'5')
    putchar = c.function_test('int',
                              'int',
                              test='''
        #include <stdio.h>
        int main() {
            return putchar('5') == '5' ? 0 : 1;
        }
        ''',
                              stdout=b'5')
    puts = c.function_test('int',
                           'const char*',
                           test='''
        #include <stdio.h>
        int main() {
            return puts("5 6") ? 0 : 1;
        }
        ''',
                           stdout=b'5 6\n')
    ungetc = c.function_test('int',
                             'int',
                             'FILE*',
                             test='''
        #include <stdio.h>
        int main() {
            if (ungetc('5', stdin) != '5') return 1;
            return getc(stdin) == '5' ? 0 : 1;
        }
        ''')
    fread = c.function_test('size_t',
                            'void*',
                            'size_t',
                            'size_t',
                            'FILE*',
                            test='''
        #include <stdio.h>
        int main() {
            char s[50] = {0};
            return fread(s, sizeof(char), 3, stdin) == 3 &&
                s[0] == '5' &&
                s[1] == ' ' &&
                s[2] == '6' ? 0 : 1;
        }
        ''',
                            stdin=b'5 6')
    fwrite = c.function_test('size_t',
                             'const void*',
                             'size_t',
                             'size_t',
                             'FILE*',
                             test='''
        #include <stdio.h>
        int main() {
            return fwrite("5 6", sizeof(char), 3, stdout) == 3 ? 0 : 1;
        }
        ''',
                             stdout=b'5 6')

    @c.cacheproperty
    def fgetpos(self):
        if self.fopen:
            return c.Function('int', 'FILE*', 'fpos_t*', 'fgetpos')

    @c.cacheproperty
    def fseek(self):
        if self.fopen:
            return c.Function('int', 'FILE*', 'long int', 'int', 'fseek')

    @c.cacheproperty
    def fsetpos(self):
        if self.fopen:
            return c.Function('int', 'FILE*', 'const fpos_t*', 'fsetpos')

    @c.cacheproperty
    def ftell(self):
        if self.fopen:
            return c.Function('long int', 'FILE*', 'ftell')

    @c.cacheproperty
    def rewind(self):
        if self.fopen:
            return c.Function('void', 'FILE*', 'rewind')

    clearerr = c.function_test('void',
                               'FILE*',
                               test='''
        #include <stdio.h>
        int main() {
            clearerr(stdout);
            return 0;
        }
        ''')

    @property
    def feof(self):
        if self.fopen:
            return c.function_test('int', 'FILE*')

    @property
    def ferror(self):
        if self.fopen:
            return c.Function('int', 'FILE*')

    perror = c.function_test('void', 'const char*', default_args=('""', ))
Beispiel #31
0
class ctype_h(c.Test):
    header = c.header_test('ctype.h')

    isalnum = c.function_test('int', 'int')
    isalpha = c.function_test('int', 'int')
    iscntrl = c.function_test('int', 'int')
    isdigit = c.function_test('int', 'int')
    isgraph = c.function_test('int', 'int')
    islower = c.function_test('int', 'int')
    isprint = c.function_test('int', 'int')
    ispunct = c.function_test('int', 'int')
    isspace = c.function_test('int', 'int')
    isupper = c.function_test('int', 'int')
    isxdigit = c.function_test('int', 'int')
    tolower = c.function_test('int', 'int')
    toupper = c.function_test('int', 'int')
Beispiel #32
0
class time_h(c.Test):
    header = c.header_test('time.h')

    CLK_TCK = c.macro_test()
    NULL = c.macro_test()
    clock_t = c.int_type_test()
    time_t = c.int_type_test()
    size_t = c.int_type_test()
    tm = c.struct_test(
        ('int', 'tm_sec'), ('int', 'tm_min'), ('int', 'tm_hour'),
        ('int', 'tm_mday'), ('int', 'tm_mon'), ('int', 'tm_year'),
        ('int', 'tm_wday'), ('int', 'tm_yday'), ('int', 'tm_isdst'))
    clock = c.function_test('clock_t', 'void')
    difftime = c.function_test('double', 'time_t', 'time_t')
    mktime = c.function_test('time_t',
                             'struct tm*',
                             test='''
        #include <time.h>
        int main() {
            struct tm a;
            time_t b = mktime(&a);
            return 0;
        }
        ''')
    time = c.function_test('time_t', 'time_t*', default_args=('NULL', ))
    asctime = c.function_test('char*',
                              'const struct tm*',
                              test='''
        #include <time.h>
        int main() {
            struct tm t = { 0, 0, 0, 1, 0, 70, 4, 0, 0 };
            char* s = asctime(&t);
            return 0;
        }
        ''')
    ctime = c.function_test('char*',
                            'const time_t*',
                            test='''
        #include <time.h>
        int main() {
            time_t t = 0;
            char* s = ctime(&t);
            return 0;
        }
        ''')
    gmtime = c.function_test('struct tm*',
                             'const time_t*',
                             test='''
        #include <time.h>
        int main() {
            time_t t = 0;
            struct tm* tm = gmtime(&t);
            return 0;
        }
        ''')
    localtime = c.function_test('struct tm*',
                                'const time_t*',
                                test='''
        #include <time.h>
        int main() {
            time_t t = 0;
            struct tm* tm = localtime(&t);
            return 0;
        }
        ''')
    strftime = c.function_test('size_t',
                               'char*',
                               'size_t',
                               'const char*',
                               'const struct tm*',
                               test='''
        #include <time.h>
        int main() {
            struct tm t = { 0, 0, 0, 1, 0, 70, 4, 0, 0 };
            char s[50] = {0};
            return strftime(s, 50, " ", &t) == 1 ? 0 : 1;
        }
        ''')