~ubuntu-branches/ubuntu/maverick/evolution-data-server/maverick-proposed

« back to all changes in this revision

Viewing changes to libdb/test/mutex002.tcl

  • Committer: Bazaar Package Importer
  • Author(s): Didier Roche
  • Date: 2010-05-17 17:02:06 UTC
  • mfrom: (1.1.79 upstream) (1.6.12 experimental)
  • Revision ID: james.westby@ubuntu.com-20100517170206-4ufr52vwrhh26yh0
Tags: 2.30.1-1ubuntu1
* Merge from debian experimental. Remaining change:
  (LP: #42199, #229669, #173703, #360344, #508494)
  + debian/control:
    - add Vcs-Bzr tag
    - don't use libgnome
    - Use Breaks instead of Conflicts against evolution 2.25 and earlier.
  + debian/evolution-data-server.install,
    debian/patches/45_libcamel_providers_version.patch:
    - use the upstream versioning, not a Debian-specific one 
  + debian/libedata-book1.2-dev.install, debian/libebackend-1.2-dev.install,
    debian/libcamel1.2-dev.install, debian/libedataserverui1.2-dev.install:
    - install html documentation
  + debian/rules:
    - don't build documentation it's shipped with the tarball

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# See the file LICENSE for redistribution information.
2
 
#
3
 
# Copyright (c) 1996-2002
4
 
#       Sleepycat Software.  All rights reserved.
5
 
#
6
 
# $Id$
7
 
#
8
 
 
9
 
# TEST  mutex002
10
 
# TEST  Test basic mutex synchronization
11
 
proc mutex002 { } {
12
 
        source ./include.tcl
13
 
 
14
 
        puts "Mutex002: Basic synchronization"
15
 
        env_cleanup $testdir
16
 
        set nlocks 20
17
 
 
18
 
        # Fork off child before we open any files.
19
 
        set f1 [open |$tclsh_path r+]
20
 
        puts $f1 "source $test_path/test.tcl"
21
 
        flush $f1
22
 
 
23
 
        # Open the environment and the mutex locally
24
 
        puts "\tMutex002.a: Open local and remote env"
25
 
        set local_env [berkdb_env -create -mode 0644 -lock -home $testdir]
26
 
        error_check_good env_open [is_valid_env $local_env] TRUE
27
 
 
28
 
        set local_mutex [$local_env mutex 0644 $nlocks]
29
 
        error_check_good \
30
 
            mutex_init [is_valid_mutex $local_mutex $local_env] TRUE
31
 
 
32
 
        # Open the environment and the mutex remotely
33
 
        set remote_env [send_cmd $f1 "berkdb_env -lock -home $testdir"]
34
 
        error_check_good remote:env_open [is_valid_env $remote_env] TRUE
35
 
 
36
 
        set remote_mutex [send_cmd $f1 "$remote_env mutex 0644 $nlocks"]
37
 
        error_check_good \
38
 
            mutex_init [is_valid_mutex $remote_mutex $remote_env] TRUE
39
 
 
40
 
        # Do a get here, then set the value to be pid.
41
 
        # On the remote side fire off a get and getval.
42
 
        puts "\tMutex002.b: Local and remote get/set"
43
 
        set r [$local_mutex get 1]
44
 
        error_check_good lock_get $r 0
45
 
 
46
 
        set r [$local_mutex setval 1 [pid]]
47
 
        error_check_good lock_get $r 0
48
 
 
49
 
        # Now have the remote side request the lock and check its
50
 
        # value. Then wait 5 seconds, release the mutex and see
51
 
        # what the remote side returned.
52
 
        send_timed_cmd $f1 1 "$remote_mutex get 1"
53
 
        send_timed_cmd $f1 1 "set ret \[$remote_mutex getval 1\]"
54
 
 
55
 
        # Now sleep before resetting and releasing lock
56
 
        tclsleep 5
57
 
        set newv [expr [pid] - 1]
58
 
        set r [$local_mutex setval 1 $newv]
59
 
        error_check_good mutex_setval $r 0
60
 
 
61
 
        set r [$local_mutex release 1]
62
 
        error_check_good mutex_release $r 0
63
 
 
64
 
        # Now get the result from the other script
65
 
        # Timestamp
66
 
        set result [rcv_result $f1]
67
 
        error_check_good lock_get:remote_time [expr $result > 4] 1
68
 
 
69
 
        # Timestamp
70
 
        set result [rcv_result $f1]
71
 
 
72
 
        # Mutex value
73
 
        set result [send_cmd $f1 "puts \$ret"]
74
 
        error_check_good lock_get:remote_getval $result $newv
75
 
 
76
 
        # Close down the remote
77
 
        puts "\tMutex002.c: Close remote"
78
 
        set ret [send_cmd $f1 "$remote_mutex close" 5]
79
 
        # Not sure why we need this, but we do... an extra blank line
80
 
        # someone gets output somewhere
81
 
        gets $f1 ret
82
 
        error_check_good remote:mutex_close $ret 0
83
 
 
84
 
        set ret [send_cmd $f1 "$remote_env close"]
85
 
        error_check_good remote:env_close $ret 0
86
 
 
87
 
        catch { close $f1 } result
88
 
 
89
 
        set ret [$local_mutex close]
90
 
        error_check_good local:mutex_close $ret 0
91
 
 
92
 
        set ret [$local_env close]
93
 
        error_check_good local:env_close $ret 0
94
 
}