diff options
author | Benoit Germain <bnt.germain@gmail.com> | 2011-02-17 07:52:53 +0100 |
---|---|---|
committer | Benoit Germain <bnt.germain@gmail.com> | 2011-02-17 07:52:53 +0100 |
commit | ab233d0c9a1edc34836e2249c1eb6d714f1066b5 (patch) | |
tree | a91078b0ca240f870f5f15c2930bc0719a86c9d1 /tests | |
parent | afb2da4789cdaddc5a0c3c9c2d57ccd36bcc74c7 (diff) | |
download | lanes-ab233d0c9a1edc34836e2249c1eb6d714f1066b5.tar.gz lanes-ab233d0c9a1edc34836e2249c1eb6d714f1066b5.tar.bz2 lanes-ab233d0c9a1edc34836e2249c1eb6d714f1066b5.zip |
Lane userdata implementation refactoring:
- Refactor lane proxy implementation: it is now a full userdata instead
of a table, and its methods are implemented in C instead of Lua.
* its metatable is no longer accessible.
* writing to the proxy raises an error.
* it is no longer possible to overwrite its join() and cancel() methods
- when a deep userdata idfunc requests a module to be required, manually
check that it is not loaded before requiring it instead of relying on
the require function's loop detection feature.
- when a module must be required, raise an error if the 'require' function
is not found in the target state.
- we know Lanes is loaded in the master state, so we don't force it
to be required in every lane too when a linda deep userdata is copied.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/appendud.lua | 20 | ||||
-rw-r--r-- | tests/basic.lua | 2 | ||||
-rw-r--r-- | tests/error.lua | 6 | ||||
-rw-r--r-- | tests/fibonacci.lua | 2 | ||||
-rw-r--r-- | tests/protectproxy.lua | 27 |
5 files changed, 43 insertions, 14 deletions
diff --git a/tests/appendud.lua b/tests/appendud.lua index 65d0798..eb1f768 100644 --- a/tests/appendud.lua +++ b/tests/appendud.lua | |||
@@ -31,28 +31,30 @@ local _ud = { | |||
31 | 31 | ||
32 | 32 | ||
33 | function appendud(tab, ud) | 33 | function appendud(tab, ud) |
34 | io.stderr:write "Starting" | 34 | io.stderr:write "Starting " |
35 | tab:beginupdate() set_finalizer( function() tab:endupdate() end ) | 35 | tab:beginupdate() set_finalizer( function() tab:endupdate() end ) |
36 | ud:lock() set_finalizer( function() ud:unlock() end ) | 36 | ud:lock() set_finalizer( function() ud:unlock() end ) |
37 | for i = 1,#ud do | 37 | for i = 1,#ud do |
38 | tab[#tab+1] = ud[i] | 38 | tab[#tab+1] = ud[i] |
39 | end | 39 | end |
40 | io.stderr:write "Ending" | 40 | io.stderr:write "Ending " |
41 | return tab -- need to return 'tab' since we're running in a separate thread | 41 | return tab -- need to return 'tab' since we're running in a separate thread |
42 | -- ('tab' is passed over lanes by value, not by reference) | 42 | -- ('tab' is passed over lanes by value, not by reference) |
43 | end | 43 | end |
44 | 44 | ||
45 | local t,err= lanes.gen( "io", appendud )( _tab, _ud ) -- create & launch a thread | 45 | local t,err= lanes.gen( "base,io", appendud )( _tab, _ud ) -- create & launch a thread |
46 | assert(t) | 46 | assert(t) |
47 | assert(not err) | 47 | assert(not err) |
48 | 48 | ||
49 | -- test | 49 | -- test |
50 | 50 | -- print("t:join()") | |
51 | t:join() -- Need to explicitly wait for the thread, since 'ipairs()' does not | 51 | a,b,c = t[1],t[2],t[3] -- Need to explicitly wait for the thread, since 'ipairs()' does not |
52 | --a,b,c = t:join() -- Need to explicitly wait for the thread, since 'ipairs()' does not | ||
52 | -- value the '__index' metamethod (wouldn't it be cool if it did..?) | 53 | -- value the '__index' metamethod (wouldn't it be cool if it did..?) |
53 | 54 | ||
54 | io.stderr:write(t[1]) | 55 | print(a,b,c) |
56 | -- print("io.stderr:write(t[1])") | ||
57 | -- io.stderr:write(t[1]) | ||
58 | _ = t[0] | ||
59 | print(_) | ||
55 | 60 | ||
56 | for k,v in ipairs(t) do | ||
57 | print(k,v) | ||
58 | end | ||
diff --git a/tests/basic.lua b/tests/basic.lua index 352e029..853a8de 100644 --- a/tests/basic.lua +++ b/tests/basic.lua | |||
@@ -171,7 +171,7 @@ local function PEEK() return linda:get("<-") end | |||
171 | local function SEND(...) linda:send( "->", ... ) end | 171 | local function SEND(...) linda:send( "->", ... ) end |
172 | local function RECEIVE() return linda:receive( "<-" ) end | 172 | local function RECEIVE() return linda:receive( "<-" ) end |
173 | 173 | ||
174 | local t= lanes_gen("io,package",chunk)(linda) -- prepare & launch | 174 | local t= lanes_gen("io",chunk)(linda) -- prepare & launch |
175 | 175 | ||
176 | SEND(1); WR( "1 sent\n" ) | 176 | SEND(1); WR( "1 sent\n" ) |
177 | SEND(2); WR( "2 sent\n" ) | 177 | SEND(2); WR( "2 sent\n" ) |
diff --git a/tests/error.lua b/tests/error.lua index 673bcb5..4922846 100644 --- a/tests/error.lua +++ b/tests/error.lua | |||
@@ -9,9 +9,9 @@ require "lanes" | |||
9 | local function lane() | 9 | local function lane() |
10 | 10 | ||
11 | local subf= function() -- this so that we can see the call stack | 11 | local subf= function() -- this so that we can see the call stack |
12 | --error "aa" | 12 | error "aa" |
13 | error({}) | 13 | --error({}) |
14 | error(error) | 14 | --error(error) |
15 | end | 15 | end |
16 | local subf2= function() | 16 | local subf2= function() |
17 | subf() | 17 | subf() |
diff --git a/tests/fibonacci.lua b/tests/fibonacci.lua index 8867e14..667a3e9 100644 --- a/tests/fibonacci.lua +++ b/tests/fibonacci.lua | |||
@@ -70,6 +70,6 @@ assert( #right==99 ) | |||
70 | 70 | ||
71 | local N= 80 | 71 | local N= 80 |
72 | local res= fib(N) | 72 | local res= fib(N) |
73 | print( right[N] ) | 73 | print( right[N], res ) |
74 | assert( res==right[N] ) | 74 | assert( res==right[N] ) |
75 | 75 | ||
diff --git a/tests/protectproxy.lua b/tests/protectproxy.lua new file mode 100644 index 0000000..57ca831 --- /dev/null +++ b/tests/protectproxy.lua | |||
@@ -0,0 +1,27 @@ | |||
1 | require "lanes" | ||
2 | |||
3 | local body = function( param) | ||
4 | print ( "lane body: " .. param) | ||
5 | return 1 | ||
6 | end | ||
7 | |||
8 | local gen = lanes.gen( "*", body) | ||
9 | |||
10 | local mylane = gen( "hello") | ||
11 | |||
12 | local result = mylane[1] | ||
13 | |||
14 | -- make sure we have properly protected the lane | ||
15 | |||
16 | -- can't access the metatable | ||
17 | print( "metatable:" .. tostring( getmetatable( mylane))) | ||
18 | |||
19 | -- can't write to the userdata | ||
20 | print( "lane result: " .. mylane[1]) | ||
21 | |||
22 | -- read nonexistent values -> nil | ||
23 | print "reading nonexistent return value" | ||
24 | a = mylane[2] | ||
25 | |||
26 | print "writing to the lane -> error" | ||
27 | mylane[4] = true | ||