diff options
author | Piotr Szarmanski | 2022-09-25 19:54:42 +0200 |
---|---|---|
committer | Piotr Szarmanski | 2022-09-25 19:54:42 +0200 |
commit | 8db501749d47964b436bc63cafb80a17bfd42396 (patch) | |
tree | d6982ac6eff1aeed514f7c11ee5df46a1930805d /tests | |
parent | 67d00dc4ce131d5cc46f4041dbf40391697e281d (diff) |
Add parallel decoder.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/decode-tests.lisp | 12 | ||||
-rw-r--r-- | tests/encode-tests.lisp | 4 | ||||
-rw-r--r-- | tests/package.lisp | 2 | ||||
-rw-r--r-- | tests/parallel-tests.lisp | 38 |
4 files changed, 47 insertions, 9 deletions
diff --git a/tests/decode-tests.lisp b/tests/decode-tests.lisp index af3edb0..ab9b56a 100644 --- a/tests/decode-tests.lisp +++ b/tests/decode-tests.lisp @@ -33,9 +33,9 @@ (read-capability (eris-encode array ,block-size #'hashtable-encode)) (decoded-array (make-array (length array) :element-type '(unsigned-byte 8))) (stream (eris-decode read-capability #'hashtable-decode))) - (stream-read-sequence stream decoded-array) + (stream-read-sequence stream decoded-array 0 (length decoded-array)) (is (equalp decoded-array array)) - (file-position stream 0) + (setf (stream-file-position stream) 0) (is (equalp array (alexandria:read-stream-content-into-byte-vector stream))))) @@ -124,8 +124,8 @@ (read-capability (eris-encode array ,block-size #'hashtable-encode)) (buf (make-array 24 :element-type '(unsigned-byte 8))) (stream (eris-decode read-capability #'hashtable-decode))) - (stream-file-position stream ,pos) - (stream-read-sequence stream buf) + (setf (stream-file-position stream) ,pos) + (stream-read-sequence stream buf 0 (length buf)) ;; (print (pos (buffer stream))) ;; (print (+ 24 ,buffer-pos)) ;; (print (pos stream)) @@ -146,7 +146,7 @@ (read-capability (eris-encode array ,block-size #'hashtable-encode)) (stream (eris-decode read-capability #'hashtable-decode))) (signals ,condition - (stream-file-position stream ,pos)))) + (setf (stream-file-position stream) ,pos)))) (test random-access-eof-1kib (assert-random-access-condition (make-octets 512 :element 1) 1024 512 eof) @@ -189,7 +189,7 @@ (read-capability (eris-encode array ,block-size #'hashtable-encode)) (decoded-array (make-array (length array) :element-type '(unsigned-byte 8))) (stream (eris-decode read-capability #'hashtable-decode))) - (stream-read-sequence stream decoded-array) + (stream-read-sequence stream decoded-array 0 (length decoded-array)) (is (equalp (length array) (eof stream))))) diff --git a/tests/encode-tests.lisp b/tests/encode-tests.lisp index c6b50d4..6c04444 100644 --- a/tests/encode-tests.lisp +++ b/tests/encode-tests.lisp @@ -37,11 +37,11 @@ "urn:eris:BIAD77QDJMFAKZYH2DXBUZYAP3MXZ3DJZVFYQ5DFWC6T65WSFCU5S2IT4YZGJ7AC4SYQMP2DM2ANS2ZTCP3DJJIRV733CRAAHOSWIYZM3M")) ;; simple gray stream class for this particular construction. -(defclass null-stream (fundamental-binary-stream) +(defclass null-stream (fundamental-binary-input-stream) ((counter :initform 0 :accessor counter) (max-counter :initarg :max-counter))) -(defmethod stream-read-sequence ((stream null-stream) seq &optional start end) +(defmethod stream-read-sequence ((stream null-stream) seq start end &key) (with-slots (counter max-counter) stream (if (eql counter max-counter) 0 diff --git a/tests/package.lisp b/tests/package.lisp index 71d6c82..98fdd81 100644 --- a/tests/package.lisp +++ b/tests/package.lisp @@ -1,5 +1,5 @@ (defpackage eris/test - (:use common-lisp eris fiveam sb-gray ironclad)) + (:use common-lisp eris fiveam trivial-gray-streams ironclad)) (in-package :eris/test) diff --git a/tests/parallel-tests.lisp b/tests/parallel-tests.lisp new file mode 100644 index 0000000..c139b31 --- /dev/null +++ b/tests/parallel-tests.lisp @@ -0,0 +1,38 @@ +;; This file is part of eris-cl. +;; Copyright (C) 2022 Piotr SzarmaĆski + +;; eris-cl 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 versqion. + +;; eris-cl 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 General Public License for more details. + +;; You should have received a copy of the GNU General Public License along with +;; eris-cl. If not, see <https://www.gnu.org/licenses/>. + +(in-package :eris/test) + +(def-suite* parallel-tests :in eris-tests) + +(defmacro assert-parallel-decode (array block-size) + `(uiop:with-temporary-file (:stream output-file :pathname pathname :direction :io) + (let* ((*table* (make-hash-table :test #'equalp)) + (array ,array) + (read-capability (eris-encode array ,block-size #'hashtable-encode))) + (eris-decode-parallel read-capability #'hashtable-decode pathname + :initial-bindings (acons '*table* *table* bordeaux-threads:*default-special-bindings*) + :threads 4) + (is (equalp array + (alexandria:read-stream-content-into-byte-vector output-file)))))) + +(test simple-parallel-decode + (assert-parallel-decode (make-octets 4096 :element 101) 1024) + (assert-parallel-decode (make-octets 4095 :element 102) 1024) + (assert-parallel-decode (make-octets 18000 :element 103) 1024) + (assert-parallel-decode (make-octets 128000 :element 104) 32768) + (assert-parallel-decode (make-octets 131071 :element 104) 32768) + (assert-parallel-decode (make-octets 131072 :element 104) 32768) + (assert-parallel-decode (make-octets 131073 :element 104) 32768)) |