diff options
| author | Andy Wingo <wingo@pobox.com> | 2016-09-08 16:57:55 +0200 |
|---|---|---|
| committer | Andy Wingo <wingo@pobox.com> | 2016-09-08 16:57:55 +0200 |
| commit | 29c217e04394fe8e9a7317b90cabbefd5385989d (patch) | |
| tree | d3f494ddfd3b73c2801c4ba7e103251594633008 | |
| parent | Quit the scheduler when there is nothing left to do (diff) | |
| download | guile-fibers-29c217e04394fe8e9a7317b90cabbefd5385989d.tar.gz | |
Add tests
* Makefile.am (TESTS, TESTS_ENVIRONMENT):
* configure.ac: Enable tests.
* tests/basic.scm: Add some tests.
| -rw-r--r-- | Makefile.am | 4 | ||||
| -rw-r--r-- | configure.ac | 2 | ||||
| -rw-r--r-- | tests/basic.scm | 121 |
3 files changed, 124 insertions, 3 deletions
diff --git a/Makefile.am b/Makefile.am index 6e478b6..98c4f55 100644 --- a/Makefile.am +++ b/Makefile.am @@ -39,8 +39,8 @@ epoll_la_CFLAGS = $(AM_CFLAGS) $(GUILE_CFLAGS) epoll_la_LIBADD = $(GUILE_LIBS) epoll_la_LDFLAGS = -export-dynamic -module -# TESTS=tests/org-mode.scm -# TESTS_ENVIRONMENT=top_srcdir="$(abs_top_srcdir)" ./env guile -s +TESTS=tests/basic.scm +TESTS_ENVIRONMENT=top_srcdir="$(abs_top_srcdir)" ./env guile -s EXTRA_DIST += \ env.in \ diff --git a/configure.ac b/configure.ac index 314ab23..6845080 100644 --- a/configure.ac +++ b/configure.ac @@ -23,7 +23,7 @@ AC_INIT([fibers], [0.1.0]) AC_CONFIG_SRCDIR([env.in]) AC_CONFIG_AUX_DIR([build-aux]) AC_CONFIG_MACRO_DIRS([m4]) -AM_INIT_AUTOMAKE +AM_INIT_AUTOMAKE([serial-tests]) AC_COPYRIGHT(FIBERS_CONFIGURE_COPYRIGHT) AM_CONFIG_HEADER(config.h) diff --git a/tests/basic.scm b/tests/basic.scm new file mode 100644 index 0000000..bfcbc03 --- /dev/null +++ b/tests/basic.scm @@ -0,0 +1,121 @@ +;; Fibers: cooperative, event-driven user-space threads. + +;;;; Copyright (C) 2016 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 +;;;; + +(define-module (tests basic) + #:use-module (fibers)) + +(define failed? #f) + +(define-syntax-rule (assert-equal expected actual) + (let ((x expected)) + (format #t "assert ~s equal to ~s: " 'actual x) + (force-output) + (let ((y actual)) + (cond + ((equal? x y) (format #t "ok\n")) + (else + (format #t "no (got ~s)\n" y) + (set! failed? #t)))))) + +(define-syntax-rule (assert-terminates exp) + (begin + (format #t "assert ~s terminates: " 'exp) + (force-output) + exp + (format #t "ok\n"))) + +(define-syntax-rule (assert-run-fibers-terminates exp) + (begin + (format #t "assert run-fibers on ~s terminates: " 'exp) + (force-output) + (let ((start (get-internal-real-time))) + (run-fibers (lambda () exp)) + (format #t "ok (~a s)\n" (/ (- (get-internal-real-time) start) + 1.0 internal-time-units-per-second))))) + +(define-syntax-rule (do-times n exp) + (let lp ((count n)) + (let ((count (1- count))) + exp + (unless (zero? count) (lp count))))) + +(assert-equal #f #f) +(assert-terminates #t) +(assert-terminates (run-fibers)) +(assert-run-fibers-terminates (sleep 1)) +(assert-run-fibers-terminates (do-times 1 (spawn-fiber (lambda () #t)))) +(assert-run-fibers-terminates (do-times 10 (spawn-fiber (lambda () #t)))) +(assert-run-fibers-terminates (do-times 100 (spawn-fiber (lambda () #t)))) +(assert-run-fibers-terminates (do-times 1000 (spawn-fiber (lambda () #t)))) +(assert-run-fibers-terminates (do-times 10000 (spawn-fiber (lambda () #t)))) +(assert-run-fibers-terminates (do-times 100000 (spawn-fiber (lambda () #t)))) +(assert-run-fibers-terminates (do-times 1 (spawn-fiber (lambda () (sleep 1))))) +(assert-run-fibers-terminates (do-times 10 (spawn-fiber (lambda () (sleep 1))))) +(assert-run-fibers-terminates (do-times 100 (spawn-fiber (lambda () (sleep 1))))) +(assert-run-fibers-terminates (do-times 1000 (spawn-fiber (lambda () (sleep 1))))) +(assert-run-fibers-terminates (do-times 10000 (spawn-fiber (lambda () (sleep 1))))) +(assert-run-fibers-terminates (do-times 20000 (spawn-fiber (lambda () (sleep 1))))) +(assert-run-fibers-terminates (do-times 40000 (spawn-fiber (lambda () (sleep 1))))) + +(define (spawn-fiber-tree n leaf) + (do-times n (spawn-fiber + (lambda () + (if (= n 1) + (leaf) + (spawn-fiber-tree (1- n) leaf)))))) +(assert-run-fibers-terminates (spawn-fiber-tree 5 (lambda () (sleep 1)))) + +(define (spawn-fiber-chain n) + (spawn-fiber + (lambda () + (unless (zero? (1- n)) + (spawn-fiber-chain (1- n)))))) +(assert-run-fibers-terminates (spawn-fiber-chain 5)) +(assert-run-fibers-terminates (spawn-fiber-chain 50)) +(assert-run-fibers-terminates (spawn-fiber-chain 500)) +(assert-run-fibers-terminates (spawn-fiber-chain 5000)) +(assert-run-fibers-terminates (spawn-fiber-chain 50000)) +(assert-run-fibers-terminates (spawn-fiber-chain 500000)) +(assert-run-fibers-terminates (spawn-fiber-chain 5000000)) + +;; spawn deterministic number of fibers that halt -> stop + +;; spawn many fibers -> stop + +;; chain or tree of fibers -> stop + +;; sleep wakeup order + +;; fib using channels + +;; sleep durations + +;; timed channel wait + +;; multi-channel wait + +;; exceptions + +;; cross-thread calls + +;; closing port causes pollerr + +;; live threads list + +(exit (if failed? 1 0)) |
