repair some tests

A recent test for `_bytes` had a memory bug. An old
test for weak hash tables had a race between GC and
hash-table lookup.
This commit is contained in:
Matthew Flatt 2018-01-20 08:27:34 -07:00
parent 62b8ca3ca7
commit e2e469240f
2 changed files with 10 additions and 3 deletions

View File

@ -2270,15 +2270,18 @@
(for/list ([j 4])
(thread
(lambda ()
(define save-keys '())
(for ([i 1000])
(define v (random 100000))
(define k (a v))
(set! save-keys (cons k save-keys))
(hash-set! cht k v)
;; Make sure the addition didn't get lost, which
;; can happen when a lock is missing:
(unless (equal? (hash-ref cht k #f) v)
(error "oops")))
(semaphore-post done)))))
(semaphore-post done)
save-keys))))
(for-each sync ths)

View File

@ -533,10 +533,14 @@
(test 107 ptr-ref v _intptr))
;; Test _bytes and _bytes/nul-terminated
(let ([p (malloc 8)])
(memcpy p #"hi, all\0" 8)
(test #"hi, all" cast p _pointer _bytes)
(test #"hi, all" cast p _pointer _bytes/nul-terminated))
(let ([p (malloc 8)])
(memcpy p #"hi, all!" 8)
(test #"hi, all!" cast p _pointer _bytes)
(test #"hi, all!" cast p _pointer _bytes/nul-terminated))
(test #"hi, all!" cast p _pointer (_bytes o 8))
(test #"hi, all!" cast p _pointer (_bytes/nul-terminated o 8)))
(let* ([strdup (get-ffi-obj 'strdup #f (_fun _bytes/nul-terminated -> _pointer))]
[p (strdup #"howdy...")])
(test #"howdy..." cast p _pointer _bytes)