Update of /cvsroot/naviserver/naviserver/tests
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8676/tests
Added Files:
ns_thread.test
Log Message:
* include/ns.h:
* nsd/tclobj.c: Generalise the ns_thread routines for wrapping a C
structs with a Tcl obj handle. Slighlty enhanced: also allows
wrapping of statically allocated C structs which always have a direct
string name -> struct relationship.
* nsd/tclcmds.c:
* nsd/tclthread.c: Convert to Tcl objects, remove some duplicated
code and convert to the new ns:addr Tcl object type interface.
* tests/ns_thread.test: Exercise the ns_thread command and the
new ns:addr Tcl object type.
--- NEW FILE: ns_thread.test ---
#
# $Header: /cvsroot/naviserver/naviserver/tests/ns_thread.test,v 1.1 2005/10/21 06:22:15 sdeasey Exp $
#
package require tcltest 2.2
namespace import -force ::tcltest::*
eval ::tcltest::configure $argv
test ns_thread-1.1 {basic syntax} -body {
ns_thread ?
} -returnCodes error -result {bad option "?": must be begin, begindetached, create, wait, join, name, get, getid, id, or yield}
test ns_thread-1.2 {basic syntax} -body {
ns_mutex ?
} -returnCodes error -result {bad option "?": must be create, destroy, lock, or unlock}
test ns_thread-1.3 {basic syntax} -body {
ns_critsec ?
} -returnCodes error -result {bad option "?": must be create, destroy, enter, or leave}
test ns_thread-1.4 {basic syntax} -body {
ns_sema ?
} -returnCodes error -result {bad option "?": must be create, destroy, release, or wait}
test ns_thread-1.5 {basic syntax} -body {
ns_cond ?
} -returnCodes error -result {bad option "?": must be abswait, broadcast, create, destroy, set, signal, or wait}
test ns_thread-1.6 {basic syntax} -body {
ns_rwlock ?
} -returnCodes error -result {bad option "?": must be create, destroy, readlock, readunlock, writelock, writeunlock, or unlock}
test ns_thread-2.1 {detached thread} -body {
ns_thread begindetached {return ok}
} -result {}
test ns_thread-2.2 {wait for thread thread} -body {
set tid [ns_thread begin {return ok}]
set result [ns_thread wait $tid]
list $tid $result
} -cleanup {
unset -nocomplain -- tid result
} -match regexp -result {{t0x[a-z0-9]+ a0x[a-z0-9]+ ns:thread} ok}
test ns_thread-2.3 {get thread id of self} -body {
ns_thread id
} -match regexp -result {.[0-9]+}
test ns_thread-2.4 {thread name} -body {
ns_thread wait [ns_thread create {ns_thread name threadtest}]
} -result {threadtest}
test ns_thread-2.5 {thread yield} -body {
for {set i 0} {$i < 100} {incr i} {
ns_thread begindetached {
for {set i 0} {$i < 100} {incr i} {
set x y
ns_thread yield
}
}
}
} -cleanup {
unset -nocomplain -- i
} -result {}
test ns_thread-3.1 {create and destroy a mutex} -body {
set mutex [ns_mutex create]
ns_mutex destroy $mutex
set mutex
} -cleanup {
unset -nocomplain -- mutex
} -match regexp -result {t0x[a-z0-9]+ a0x[a-z0-9]+ ns:mutex}
test ns_thread-3.2 {mutex locking} -body {
set mutex [ns_mutex create]
ns_mutex lock $mutex
ns_mutex unlock $mutex
ns_mutex destroy $mutex
} -cleanup {
unset -nocomplain -- mutex
} -result {}
test ns_thread-4.1 {create and destroy a critical section} -body {
set cs [ns_critsec create]
ns_critsec destroy $cs
set cs
} -cleanup {
unset -nocomplain -- cs
} -match regexp -result {t0x[a-z0-9]+ a0x[a-z0-9]+ ns:critsec}
test ns_thread-4.2 {enter and then leave a critical section} -body {
set cs [ns_critsec create]
ns_critsec enter $cs
ns_critsec leave $cs
ns_critsec destroy $cs
} -cleanup {
unset -nocomplain -- cs
} -result {}
test ns_thread-5.1 {create and destroy a semaphore} -body {
set sema [ns_sema create]
ns_sema destroy $sema
set sema
} -cleanup {
unset -nocomplain -- sema
} -match regexp -result {t0x[a-z0-9]+ a0x[a-z0-9]+ ns:sema}
test ns_thread-6.1 {create and destroy a read-write lock} -body {
set rw [ns_rwlock create]
ns_rwlock destroy $rw
set rw
} -cleanup {
unset -nocomplain -- rw
} -match regexp -result {t0x[a-z0-9]+ a0x[a-z0-9]+ ns:rwlock}
test ns_thread-6.2 {read lock} -body {
set rw [ns_rwlock create]
ns_rwlock readlock $rw
ns_rwlock unlock $rw
ns_rwlock destroy $rw
} -cleanup {
unset -nocomplain -- rw
} -result {}
test ns_thread-6.2 {write lock} -body {
set rw [ns_rwlock create]
ns_rwlock writelock $rw
ns_rwlock unlock $rw
ns_rwlock destroy $rw
} -cleanup {
unset -nocomplain -- rw
} -result {}
cleanupTests
|