mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-30 06:50:31 +02:00
add ffi tests
* test-suite/standalone/Makefile.am: * test-suite/standalone/test-ffi: * test-suite/standalone/test-ffi-lib.c: Add some tests for the ffi.
This commit is contained in:
parent
4d9130a5b7
commit
37371ea1ba
3 changed files with 354 additions and 1 deletions
|
@ -1,6 +1,6 @@
|
|||
## Process this file with automake to produce Makefile.in.
|
||||
##
|
||||
## Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Software Foundation, Inc.
|
||||
## Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 Software Foundation, Inc.
|
||||
##
|
||||
## This file is part of GUILE.
|
||||
##
|
||||
|
@ -87,6 +87,16 @@ BUILT_SOURCES += test-asmobs-lib.x
|
|||
check_SCRIPTS += test-asmobs
|
||||
TESTS += test-asmobs
|
||||
|
||||
# test-ffi
|
||||
noinst_LTLIBRARIES += libtest-ffi.la
|
||||
libtest_ffi_la_SOURCES = test-ffi-lib.c test-ffi-lib.x
|
||||
libtest_ffi_la_CFLAGS = ${test_cflags}
|
||||
libtest_ffi_la_LDFLAGS = -no-undefined -rpath `pwd` # so libtool will really build an .so
|
||||
libtest_ffi_la_LIBADD = ${top_builddir}/libguile/libguile.la
|
||||
BUILT_SOURCES += test-ffi-lib.x
|
||||
check_SCRIPTS += test-ffi
|
||||
TESTS += test-ffi
|
||||
|
||||
# test-list
|
||||
test_list_SOURCES = test-list.c
|
||||
test_list_CFLAGS = ${test_cflags}
|
||||
|
|
149
test-suite/standalone/test-ffi
Executable file
149
test-suite/standalone/test-ffi
Executable file
|
@ -0,0 +1,149 @@
|
|||
#!/bin/sh
|
||||
exec guile -q -s "$0" "$@"
|
||||
!#
|
||||
|
||||
(use-modules (system foreign))
|
||||
|
||||
(define lib
|
||||
(dynamic-link (string-append (getenv "builddir") "/libtest-ffi")))
|
||||
|
||||
(define-syntax test
|
||||
(syntax-rules ()
|
||||
((_ exp res)
|
||||
(let ((expected res)
|
||||
(actual exp))
|
||||
(if (not (equal? actual expected))
|
||||
(error "Bad return from expression" 'exp actual expected))))))
|
||||
|
||||
;;;
|
||||
;;; No args
|
||||
;;;
|
||||
(define f-v-
|
||||
(make-foreign-function void (dynamic-func "test_ffi_v_" lib) '()))
|
||||
(test (f-v-) *unspecified*)
|
||||
|
||||
(define f-s8-
|
||||
(make-foreign-function int8 (dynamic-func "test_ffi_s8_" lib) '()))
|
||||
(test (f-s8-) -100)
|
||||
|
||||
(define f-u8-
|
||||
(make-foreign-function uint8 (dynamic-func "test_ffi_u8_" lib) '()))
|
||||
(test (f-u8-) 200)
|
||||
|
||||
(define f-s16-
|
||||
(make-foreign-function int16 (dynamic-func "test_ffi_s16_" lib) '()))
|
||||
(test (f-s16-) -20000)
|
||||
|
||||
(define f-u16-
|
||||
(make-foreign-function uint16 (dynamic-func "test_ffi_u16_" lib) '()))
|
||||
(test (f-u16-) 40000)
|
||||
|
||||
(define f-s32-
|
||||
(make-foreign-function int32 (dynamic-func "test_ffi_s32_" lib) '()))
|
||||
(test (f-s32-) -2000000000)
|
||||
|
||||
(define f-u32-
|
||||
(make-foreign-function uint32 (dynamic-func "test_ffi_u32_" lib) '()))
|
||||
(test (f-u32-) 4000000000)
|
||||
|
||||
(define f-s64-
|
||||
(make-foreign-function int64 (dynamic-func "test_ffi_s64_" lib) '()))
|
||||
(test (f-s64-) -2000000000)
|
||||
|
||||
(define f-u64-
|
||||
(make-foreign-function uint64 (dynamic-func "test_ffi_u64_" lib) '()))
|
||||
(test (f-u64-) 4000000000)
|
||||
|
||||
;;;
|
||||
;;; One u8 arg
|
||||
;;;
|
||||
(define f-v-u8
|
||||
(make-foreign-function void (dynamic-func "test_ffi_v_u8" lib) (list uint8)))
|
||||
(test (f-v-u8 10) *unspecified*)
|
||||
|
||||
(define f-s8-u8
|
||||
(make-foreign-function int8 (dynamic-func "test_ffi_s8_u8" lib) (list uint8)))
|
||||
(test (f-s8-u8 10) -90)
|
||||
|
||||
(define f-u8-u8
|
||||
(make-foreign-function uint8 (dynamic-func "test_ffi_u8_u8" lib) (list uint8)))
|
||||
(test (f-u8-u8 10) 210)
|
||||
|
||||
(define f-s16-u8
|
||||
(make-foreign-function int16 (dynamic-func "test_ffi_s16_u8" lib) (list uint8)))
|
||||
(test (f-s16-u8 10) -19990)
|
||||
|
||||
(define f-u16-u8
|
||||
(make-foreign-function uint16 (dynamic-func "test_ffi_u16_u8" lib) (list uint8)))
|
||||
(test (f-u16-u8 10) 40010)
|
||||
|
||||
(define f-s32-u8
|
||||
(make-foreign-function int32 (dynamic-func "test_ffi_s32_u8" lib) (list uint8)))
|
||||
(test (f-s32-u8 10) -1999999990)
|
||||
|
||||
(define f-u32-u8
|
||||
(make-foreign-function uint32 (dynamic-func "test_ffi_u32_u8" lib) (list uint8)))
|
||||
(test (f-u32-u8 10) 4000000010)
|
||||
|
||||
(define f-s64-u8
|
||||
(make-foreign-function int64 (dynamic-func "test_ffi_s64_u8" lib) (list uint8)))
|
||||
(test (f-s64-u8 10) -1999999990)
|
||||
|
||||
(define f-u64-u8
|
||||
(make-foreign-function uint64 (dynamic-func "test_ffi_u64_u8" lib) (list uint8)))
|
||||
(test (f-u64-u8 10) 4000000010)
|
||||
|
||||
|
||||
;;;
|
||||
;;; One s64 arg
|
||||
;;;
|
||||
(define f-v-s64
|
||||
(make-foreign-function void (dynamic-func "test_ffi_v_s64" lib) (list int64)))
|
||||
(test (f-v-s64 10) *unspecified*)
|
||||
|
||||
(define f-s8-s64
|
||||
(make-foreign-function int8 (dynamic-func "test_ffi_s8_s64" lib) (list int64)))
|
||||
(test (f-s8-s64 10) -90)
|
||||
|
||||
(define f-u8-s64
|
||||
(make-foreign-function uint8 (dynamic-func "test_ffi_u8_s64" lib) (list int64)))
|
||||
(test (f-u8-s64 10) 210)
|
||||
|
||||
(define f-s16-s64
|
||||
(make-foreign-function int16 (dynamic-func "test_ffi_s16_s64" lib) (list int64)))
|
||||
(test (f-s16-s64 10) -19990)
|
||||
|
||||
(define f-u16-s64
|
||||
(make-foreign-function uint16 (dynamic-func "test_ffi_u16_s64" lib) (list int64)))
|
||||
(test (f-u16-s64 10) 40010)
|
||||
|
||||
(define f-s32-s64
|
||||
(make-foreign-function int32 (dynamic-func "test_ffi_s32_s64" lib) (list int64)))
|
||||
(test (f-s32-s64 10) -1999999990)
|
||||
|
||||
(define f-u32-s64
|
||||
(make-foreign-function uint32 (dynamic-func "test_ffi_u32_s64" lib) (list int64)))
|
||||
(test (f-u32-s64 10) 4000000010)
|
||||
|
||||
(define f-s64-s64
|
||||
(make-foreign-function int64 (dynamic-func "test_ffi_s64_s64" lib) (list int64)))
|
||||
(test (f-s64-s64 10) -1999999990)
|
||||
|
||||
(define f-u64-s64
|
||||
(make-foreign-function uint64 (dynamic-func "test_ffi_u64_s64" lib) (list int64)))
|
||||
(test (f-u64-s64 10) 4000000010)
|
||||
|
||||
|
||||
;;
|
||||
;; Multiple int args of differing types
|
||||
;;
|
||||
(define f-sum
|
||||
(make-foreign-function int64 (dynamic-func "test_ffi_sum" lib)
|
||||
(list int8 int16 int32 int64)))
|
||||
(test (f-sum -1 2000 -30000 40000000000)
|
||||
(+ -1 2000 -30000 40000000000))
|
||||
|
||||
|
||||
;; Local Variables:
|
||||
;; mode: scheme
|
||||
;; End:
|
194
test-suite/standalone/test-ffi-lib.c
Normal file
194
test-suite/standalone/test-ffi-lib.c
Normal file
|
@ -0,0 +1,194 @@
|
|||
/* Copyright (C) 2010 Free Software Foundation, Inc.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation; either version 3 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include <libguile.h>
|
||||
|
||||
void test_ffi_v_ (void);
|
||||
void test_ffi_v_ (void)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
void test_ffi_v_u8 (scm_t_uint8 a);
|
||||
void test_ffi_v_u8 (scm_t_uint8 a)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
void test_ffi_v_s64 (scm_t_int64 a);
|
||||
void test_ffi_v_s64 (scm_t_int64 a)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
scm_t_int8 test_ffi_s8_ (void);
|
||||
scm_t_int8 test_ffi_s8_ (void)
|
||||
{
|
||||
return -100;
|
||||
}
|
||||
scm_t_int8 test_ffi_s8_u8 (scm_t_uint8 a);
|
||||
scm_t_int8 test_ffi_s8_u8 (scm_t_uint8 a)
|
||||
{
|
||||
return -100 + a;
|
||||
}
|
||||
|
||||
scm_t_int8 test_ffi_s8_s64 (scm_t_int64 a);
|
||||
scm_t_int8 test_ffi_s8_s64 (scm_t_int64 a)
|
||||
{
|
||||
return -100 + a;
|
||||
}
|
||||
|
||||
scm_t_uint8 test_ffi_u8_ (void);
|
||||
scm_t_uint8 test_ffi_u8_ (void)
|
||||
{
|
||||
return 200;
|
||||
}
|
||||
|
||||
scm_t_uint8 test_ffi_u8_u8 (scm_t_uint8 a);
|
||||
scm_t_uint8 test_ffi_u8_u8 (scm_t_uint8 a)
|
||||
{
|
||||
return 200 + a;
|
||||
}
|
||||
|
||||
scm_t_uint8 test_ffi_u8_s64 (scm_t_int64 a);
|
||||
scm_t_uint8 test_ffi_u8_s64 (scm_t_int64 a)
|
||||
{
|
||||
return 200 + a;
|
||||
}
|
||||
|
||||
scm_t_int16 test_ffi_s16_ (void);
|
||||
scm_t_int16 test_ffi_s16_ (void)
|
||||
{
|
||||
return -20000;
|
||||
}
|
||||
|
||||
scm_t_int16 test_ffi_s16_u8 (scm_t_uint8 a);
|
||||
scm_t_int16 test_ffi_s16_u8 (scm_t_uint8 a)
|
||||
{
|
||||
return -20000 + a;
|
||||
}
|
||||
|
||||
scm_t_int16 test_ffi_s16_s64 (scm_t_int64 a);
|
||||
scm_t_int16 test_ffi_s16_s64 (scm_t_int64 a)
|
||||
{
|
||||
return -20000 + a;
|
||||
}
|
||||
|
||||
scm_t_uint16 test_ffi_u16_ (void);
|
||||
scm_t_uint16 test_ffi_u16_ (void)
|
||||
{
|
||||
return 40000;
|
||||
}
|
||||
|
||||
scm_t_uint16 test_ffi_u16_u8 (scm_t_uint8 a);
|
||||
scm_t_uint16 test_ffi_u16_u8 (scm_t_uint8 a)
|
||||
{
|
||||
return 40000 + a;
|
||||
}
|
||||
|
||||
scm_t_uint16 test_ffi_u16_s64 (scm_t_int64 a);
|
||||
scm_t_uint16 test_ffi_u16_s64 (scm_t_int64 a)
|
||||
{
|
||||
return 40000 + a;
|
||||
}
|
||||
|
||||
scm_t_int32 test_ffi_s32_ (void);
|
||||
scm_t_int32 test_ffi_s32_ (void)
|
||||
{
|
||||
return -2000000000;
|
||||
}
|
||||
|
||||
scm_t_int32 test_ffi_s32_u8 (scm_t_uint8 a);
|
||||
scm_t_int32 test_ffi_s32_u8 (scm_t_uint8 a)
|
||||
{
|
||||
return -2000000000 + a;
|
||||
}
|
||||
|
||||
scm_t_int32 test_ffi_s32_s64 (scm_t_int64 a);
|
||||
scm_t_int32 test_ffi_s32_s64 (scm_t_int64 a)
|
||||
{
|
||||
return -2000000000 + a;
|
||||
}
|
||||
|
||||
scm_t_uint32 test_ffi_u32_ (void);
|
||||
scm_t_uint32 test_ffi_u32_ (void)
|
||||
{
|
||||
return 4000000000;
|
||||
}
|
||||
|
||||
scm_t_uint32 test_ffi_u32_u8 (scm_t_uint8 a);
|
||||
scm_t_uint32 test_ffi_u32_u8 (scm_t_uint8 a)
|
||||
{
|
||||
return 4000000000 + a;
|
||||
}
|
||||
|
||||
scm_t_uint32 test_ffi_u32_s64 (scm_t_int64 a);
|
||||
scm_t_uint32 test_ffi_u32_s64 (scm_t_int64 a)
|
||||
{
|
||||
return 4000000000 + a;
|
||||
}
|
||||
|
||||
/* FIXME: use 64-bit literals */
|
||||
scm_t_int64 test_ffi_s64_ (void);
|
||||
scm_t_int64 test_ffi_s64_ (void)
|
||||
{
|
||||
return -2000000000;
|
||||
}
|
||||
|
||||
scm_t_int64 test_ffi_s64_u8 (scm_t_uint8 a);
|
||||
scm_t_int64 test_ffi_s64_u8 (scm_t_uint8 a)
|
||||
{
|
||||
return -2000000000 + a;
|
||||
}
|
||||
|
||||
scm_t_int64 test_ffi_s64_s64 (scm_t_int64 a);
|
||||
scm_t_int64 test_ffi_s64_s64 (scm_t_int64 a)
|
||||
{
|
||||
return -2000000000 + a;
|
||||
}
|
||||
|
||||
scm_t_uint64 test_ffi_u64_ (void);
|
||||
scm_t_uint64 test_ffi_u64_ (void)
|
||||
{
|
||||
return 4000000000;
|
||||
}
|
||||
|
||||
scm_t_uint64 test_ffi_u64_u8 (scm_t_uint8 a);
|
||||
scm_t_uint64 test_ffi_u64_u8 (scm_t_uint8 a)
|
||||
{
|
||||
return 4000000000 + a;
|
||||
}
|
||||
|
||||
scm_t_uint64 test_ffi_u64_s64 (scm_t_int64 a);
|
||||
scm_t_uint64 test_ffi_u64_s64 (scm_t_int64 a)
|
||||
{
|
||||
return 4000000000 + a;
|
||||
}
|
||||
|
||||
|
||||
scm_t_int64 test_ffi_sum (scm_t_int8 a, scm_t_int16 b,
|
||||
scm_t_int32 c, scm_t_int64 d);
|
||||
scm_t_int64 test_ffi_sum (scm_t_int8 a, scm_t_int16 b,
|
||||
scm_t_int32 c, scm_t_int64 d)
|
||||
{
|
||||
return d + c + b + a;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue