gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gnunet-scheme] 03/04: tests/distributed-hash-table: Test 'copy-search-r


From: gnunet
Subject: [gnunet-scheme] 03/04: tests/distributed-hash-table: Test 'copy-search-result'.
Date: Tue, 18 Jan 2022 11:26:39 +0100

This is an automated email from the git hooks/post-receive script.

maxime-devos pushed a commit to branch master
in repository gnunet-scheme.

commit dd80a1de33ae4d89b91bc3400d919e3892655719
Author: Maxime Devos <maximedevos@telenet.be>
AuthorDate: Tue Jan 18 09:19:52 2022 +0000

    tests/distributed-hash-table: Test 'copy-search-result'.
    
    * tests/distributed-hash-table.scm
      (search-result->sexp,search-result=?,search-result-independent?):
      New procedures.
      ("copy-search-result: equal and independent"): New test.
---
 tests/distributed-hash-table.scm | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/tests/distributed-hash-table.scm b/tests/distributed-hash-table.scm
index b85e2f7..6bf808c 100644
--- a/tests/distributed-hash-table.scm
+++ b/tests/distributed-hash-table.scm
@@ -210,9 +210,17 @@
         (slice->bytevector (datum-value z))
         (datum-expiration z)))
 
+(define (search-result->sexp z)
+  (list (slice->bytevector (search-result-get-path z))
+       (slice->bytevector (search-result-put-path z))
+       (datum->sexp (search-result->datum z))))
+
 (define (datum=? x y)
   (equal? (datum->sexp x) (datum->sexp y)))
 
+(define (search-result=? x y)
+  (equal? (search-result->sexp x) (search-result->sexp y)))
+
 (define (slice-independent? x y)
   (not (eq? (slice-bv x) (slice-bv y))))
 
@@ -220,6 +228,13 @@
   (and (slice-independent? (datum-key x) (datum-key y))
        (slice-independent? (datum-value x) (datum-value y))))
 
+(define (search-result-independent? x y)
+  (and (datum-independent? (search-result->datum x) (search-result->datum y))
+       (slice-independent? (search-result-get-path x)
+                          (search-result-get-path y))
+       (slice-independent? (search-result-put-path x)
+                          (search-result-put-path y))))
+
 (test-assert "copy-datum: equal and independent"
   ;; A least in Guile 3.0.5, all bytevectors of length 0 are eq?,
   ;; so let the value be non-empty such that datum-independent?
@@ -233,4 +248,21 @@
       (and (datum=? old new)
           (datum-independent? old new)))))
 
+;; Detected a bug: the datum was not copied
+(test-assert "copy-search-result: equal and independent"
+  (let* ((old-key (make-slice/read-write (sizeof /hashcode:512 '())))
+        (old-value (make-slice/read-write 70))
+        (old-get-path (make-slice/read-write 9)) ; TODO: correct length
+        (old-put-path (make-slice/read-write 10)))
+    (slice-u32-set! old-key 9 #xcabba9e (endianness big))
+    (slice-u32-set! old-value 5 #xcabba9e (endianness big))
+    (slice-u32-set! old-get-path 0 #xcabba9e (endianness big))
+    (slice-u32-set! old-put-path 1 #xcabba9e (endianness big))
+    (let* ((old-datum (make-a-datum #:value old-value #:expiration 555))
+          (old (datum->search-result old-datum #:get-path old-get-path
+                                     #:put-path old-put-path))
+          (new (copy-search-result old)))
+      (and (search-result=? old new)
+          (search-result-independent? old new)))))
+
 (test-end)

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]