aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorBenoit Germain <bnt.germain@gmail.com>2011-11-05 17:31:02 +0100
committerBenoit Germain <bnt.germain@gmail.com>2011-11-05 17:31:02 +0100
commit053f7cff3c95acb915e6babfd306971f11bb7986 (patch)
treeee38c60b1119d34eb96aea1105ef033e851d266e /tests
parent717eadee9c3644fabb32c7ee59949f2846143690 (diff)
downloadlanes-053f7cff3c95acb915e6babfd306971f11bb7986.tar.gz
lanes-053f7cff3c95acb915e6babfd306971f11bb7986.tar.bz2
lanes-053f7cff3c95acb915e6babfd306971f11bb7986.zip
* process exit change: close everything at GC when main state closes, not when atexit() handlers are processed
* Lua 5.2-style module: * module() is no longer used to implement lanes.lua * a global "lanes" variable is no longer created when the module is required * the Lanes module table is returned instead * Lanes must be initialized before used: * the first occurence of 'require "lanes"' produces a minimal interface that only contains a configure() function * the remainder of the interface is made available once this function is called * subsequent calls to configure() do nothing * configure() controls the number of keeper states and the startup of timers * LuaJIT 2 compatibility * non-Lua functions are no longer copied by creating a C closure from a C pointer, but through 2-way lookup tables * this means that if a lane function body pulls non-Lua functions, the lane generator description must contain the list of libraries and modules that exports them * introduces a change in configuration .globals management: contents are copied *after* std libs are loaded * new .required configuration entry to list modules that must be require()'ed before lane body is transferred * lane:cancel() wakes up waiting lindas like what is done at lane shutdown
Diffstat (limited to 'tests')
-rw-r--r--tests/appendud.lua3
-rw-r--r--tests/atexit.lua3
-rw-r--r--tests/atomic.lua3
-rw-r--r--tests/basic.lua3
-rw-r--r--tests/cyclic.lua3
-rw-r--r--tests/ehynes.lua3
-rw-r--r--tests/errhangtest.lua3
-rw-r--r--tests/error.lua3
-rw-r--r--tests/fibonacci.lua24
-rw-r--r--tests/fifo.lua11
-rw-r--r--tests/finalizer.lua3
-rw-r--r--tests/func_is_string.lua3
-rw-r--r--tests/hangtest.lua3
-rw-r--r--tests/irayo_closure.lua5
-rw-r--r--tests/irayo_recursive.lua3
-rw-r--r--tests/keeper.lua3
-rw-r--r--tests/launchtest.lua3
-rw-r--r--tests/linda_perf.lua3
-rw-r--r--tests/objects.lua3
-rw-r--r--tests/perftest.lua3
-rw-r--r--tests/protectproxy.lua3
-rw-r--r--tests/recursive.lua4
-rw-r--r--tests/require.lua3
-rw-r--r--tests/timer.lua3
24 files changed, 75 insertions, 29 deletions
diff --git a/tests/appendud.lua b/tests/appendud.lua
index eb1f768..e275a98 100644
--- a/tests/appendud.lua
+++ b/tests/appendud.lua
@@ -6,7 +6,8 @@
6-- 6--
7-- Needs Lanes >= 2.0.3 7-- Needs Lanes >= 2.0.3
8-- 8--
9require "lanes" 9local lanes = require "lanes"
10lanes.configure( 1)
10 11
11local _tab = { 12local _tab = {
12 beginupdate = function (this) print('tab.beginupdate') end; 13 beginupdate = function (this) print('tab.beginupdate') end;
diff --git a/tests/atexit.lua b/tests/atexit.lua
index fb4f34a..09fbafd 100644
--- a/tests/atexit.lua
+++ b/tests/atexit.lua
@@ -1,4 +1,5 @@
1require "lanes" 1local lanes = require "lanes"
2lanes.configure( 1)
2 3
3-- create a free-running lane 4-- create a free-running lane
4 5
diff --git a/tests/atomic.lua b/tests/atomic.lua
index a027453..f1c9428 100644
--- a/tests/atomic.lua
+++ b/tests/atomic.lua
@@ -4,7 +4,8 @@
4-- Test program for Lua Lanes 4-- Test program for Lua Lanes
5-- 5--
6 6
7require "lanes" 7local lanes = require "lanes"
8lanes.configure( 1)
8 9
9local linda= lanes.linda() 10local linda= lanes.linda()
10local key= "$" 11local key= "$"
diff --git a/tests/basic.lua b/tests/basic.lua
index 853a8de..8b07697 100644
--- a/tests/basic.lua
+++ b/tests/basic.lua
@@ -7,7 +7,8 @@
7-- - ... 7-- - ...
8-- 8--
9 9
10require "lanes" 10local lanes = require "lanes"
11lanes.configure( 1)
11require "assert" -- assert.fails() 12require "assert" -- assert.fails()
12 13
13local lanes_gen= assert( lanes.gen ) 14local lanes_gen= assert( lanes.gen )
diff --git a/tests/cyclic.lua b/tests/cyclic.lua
index 06452bd..15abc9c 100644
--- a/tests/cyclic.lua
+++ b/tests/cyclic.lua
@@ -4,7 +4,8 @@
4-- Test program for Lua Lanes 4-- Test program for Lua Lanes
5-- 5--
6 6
7require "lanes" 7local lanes = require "lanes"
8lanes.configure( 1)
8 9
9local table_concat= assert(table.concat) 10local table_concat= assert(table.concat)
10 11
diff --git a/tests/ehynes.lua b/tests/ehynes.lua
index 4cc370e..b529f98 100644
--- a/tests/ehynes.lua
+++ b/tests/ehynes.lua
@@ -1,7 +1,8 @@
1-- 1--
2-- Test from <ehynes at dharmagaia.com> 2-- Test from <ehynes at dharmagaia.com>
3-- 3--
4require 'lanes' 4local lanes = require "lanes"
5lanes.configure( 1)
5 6
6local function PRINT_FMT( fmt, ... ) 7local function PRINT_FMT( fmt, ... )
7 io.stderr:write( string.format(fmt,...).."\n" ) 8 io.stderr:write( string.format(fmt,...).."\n" )
diff --git a/tests/errhangtest.lua b/tests/errhangtest.lua
index ddc1bfb..7127326 100644
--- a/tests/errhangtest.lua
+++ b/tests/errhangtest.lua
@@ -1,4 +1,5 @@
1lanes = require('lanes') 1local lanes = require "lanes"
2lanes.configure( 1)
2 3
3local linda = lanes.linda() 4local linda = lanes.linda()
4 5
diff --git a/tests/error.lua b/tests/error.lua
index 4922846..aee4221 100644
--- a/tests/error.lua
+++ b/tests/error.lua
@@ -4,7 +4,8 @@
4-- Note: this code is supposed to end in errors; not included in 'make test' 4-- Note: this code is supposed to end in errors; not included in 'make test'
5-- 5--
6 6
7require "lanes" 7local lanes = require "lanes"
8lanes.configure( 1)
8 9
9local function lane() 10local function lane()
10 11
diff --git a/tests/fibonacci.lua b/tests/fibonacci.lua
index 667a3e9..2e0cd62 100644
--- a/tests/fibonacci.lua
+++ b/tests/fibonacci.lua
@@ -12,7 +12,8 @@
12 12
13-- Need to say it's 'local' so it can be an upvalue 13-- Need to say it's 'local' so it can be an upvalue
14-- 14--
15local lanes= require "lanes" 15local lanes = require "lanes"
16lanes.configure( 1, "NO_TIMERS")
16 17
17local function WR(str) 18local function WR(str)
18 io.stderr:write( str.."\n" ) 19 io.stderr:write( str.."\n" )
@@ -38,7 +39,9 @@ local function fib( n )
38 else 39 else
39 -- Splits into two; this task remains waiting for the results 40 -- Splits into two; this task remains waiting for the results
40 -- 41 --
41 local gen_f= lanes.gen( "io,math,debug", fib ) 42 -- note that lanes is pulled in as upvalue, so we need package library to require internals properly
43 -- (because lua51-lanes is always required internally if possible, which is necessary in that case)
44 local gen_f= lanes.gen( "package,string,io,math,debug", fib )
42 45
43 local n1=floor(n/2) +1 46 local n1=floor(n/2) +1
44 local n2=floor(n/2) -1 + n%2 47 local n2=floor(n/2) -1 + n%2
@@ -64,7 +67,22 @@ end
64-- 67--
65-- Right answers from: <http://sonic.net/~douglasi/fibo.htm> 68-- Right answers from: <http://sonic.net/~douglasi/fibo.htm>
66-- 69--
67local right= { 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025, 121393, 196418, 317811, 514229, 832040, 1346269, 2178309, 3524578, 5702887, 9227465, 14930352, 24157817, 39088169, 63245986, 102334155, 165580141, 267914296, 433494437, 701408733, 1134903170, 1836311903, 2971215073, 4807526976, 7778742049, 12586269025, 20365011074, 32951280099, 53316291173, 86267571272, 139583862445, 225851433717, 365435296162, 591286729879, 956722026041, 1548008755920, 2504730781961, 4052739537881, 6557470319842, 10610209857723, 17167680177565, 27777890035288, 44945570212853, 72723460248141, 117669030460994, 190392490709135, 308061521170129, 498454011879264, 806515533049393, 1304969544928657, 2111485077978050, 3416454622906707, 5527939700884757, 8944394323791464, 14472334024676220, 23416728348467684, 37889062373143900, 61305790721611580, 99194853094755490, 160500643816367070, 259695496911122560, 420196140727489660, 679891637638612200, 1100087778366101900, 1779979416004714000, 2880067194370816000, 4660046610375530000, 7540113804746346000, 12200160415121877000, 19740274219868226000, 31940434634990105000, 51680708854858334000, 83621143489848440000, 135301852344706780000, 218922995834555200000 70local right=
71{
72 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711,
73 28657, 46368, 75025, 121393, 196418, 317811, 514229, 832040, 1346269, 2178309, 3524578, 5702887,
74 9227465, 14930352, 24157817, 39088169, 63245986, 102334155, 165580141, 267914296, 433494437,
75 701408733, 1134903170, 1836311903, 2971215073, 4807526976, 7778742049, 12586269025, 20365011074,
76 32951280099, 53316291173, 86267571272, 139583862445, 225851433717, 365435296162, 591286729879,
77 956722026041, 1548008755920, 2504730781961, 4052739537881, 6557470319842, 10610209857723,
78 17167680177565, 27777890035288, 44945570212853, 72723460248141, 117669030460994, 190392490709135,
79 308061521170129, 498454011879264, 806515533049393, 1304969544928657, 2111485077978050,
80 3416454622906707, 5527939700884757, 8944394323791464, 14472334024676220, 23416728348467684,
81 37889062373143900, 61305790721611580, 99194853094755490, 160500643816367070, 259695496911122560,
82 420196140727489660, 679891637638612200, 1100087778366101900, 1779979416004714000,
83 2880067194370816000, 4660046610375530000, 7540113804746346000, 12200160415121877000,
84 19740274219868226000, 31940434634990105000, 51680708854858334000, 83621143489848440000,
85 135301852344706780000, 218922995834555200000
68} 86}
69assert( #right==99 ) 87assert( #right==99 )
70 88
diff --git a/tests/fifo.lua b/tests/fifo.lua
index 898b04d..d8289c1 100644
--- a/tests/fifo.lua
+++ b/tests/fifo.lua
@@ -4,7 +4,8 @@
4-- Sample program for Lua Lanes 4-- Sample program for Lua Lanes
5-- 5--
6 6
7require "lanes" 7local lanes = require "lanes"
8lanes.configure( 1)
8 9
9local linda= lanes.linda() 10local linda= lanes.linda()
10local atomic_inc= lanes.genatomic( linda, "FIFO_n" ) 11local atomic_inc= lanes.genatomic( linda, "FIFO_n" )
@@ -18,8 +19,12 @@ local function FIFO()
18 return { 19 return {
19 -- Giving explicit 'nil' timeout allows numbers to be used as 'my_channel' 20 -- Giving explicit 'nil' timeout allows numbers to be used as 'my_channel'
20 -- 21 --
21 send= function(...) linda:send( nil, my_channel, ... ) end, 22 send= function(self, ...)
22 receive= function(timeout) linda:receive( timeout, my_channel ) end 23 linda:send( nil, my_channel, ... )
24 end,
25 receive = function(self, timeout)
26 linda:receive( timeout, my_channel )
27 end
23 } 28 }
24end 29end
25 30
diff --git a/tests/finalizer.lua b/tests/finalizer.lua
index c94b36d..88f51c1 100644
--- a/tests/finalizer.lua
+++ b/tests/finalizer.lua
@@ -8,7 +8,8 @@
8-- thing to do. -- AKa 22-Jan-2009 8-- thing to do. -- AKa 22-Jan-2009
9-- 9--
10 10
11require "lanes" 11local lanes = require "lanes"
12lanes.configure( 1)
12 13
13local FN= "finalizer-test.tmp" 14local FN= "finalizer-test.tmp"
14 15
diff --git a/tests/func_is_string.lua b/tests/func_is_string.lua
index 98ea62b..5d94f85 100644
--- a/tests/func_is_string.lua
+++ b/tests/func_is_string.lua
@@ -1,4 +1,5 @@
1require "lanes" 1local lanes = require "lanes"
2lanes.configure( 1)
2 3
3local options = {globals = { b = 666 }} 4local options = {globals = { b = 666 }}
4 5
diff --git a/tests/hangtest.lua b/tests/hangtest.lua
index d0bbea4..923496a 100644
--- a/tests/hangtest.lua
+++ b/tests/hangtest.lua
@@ -2,7 +2,8 @@
2-- Test case for hang on [1]s and :join()s. 2-- Test case for hang on [1]s and :join()s.
3-- 3--
4 4
5require "lanes" 5local lanes = require "lanes"
6lanes.configure( 1)
6 7
7local function ret(b) 8local function ret(b)
8 return b 9 return b
diff --git a/tests/irayo_closure.lua b/tests/irayo_closure.lua
index 3a82302..77ddbde 100644
--- a/tests/irayo_closure.lua
+++ b/tests/irayo_closure.lua
@@ -10,7 +10,8 @@ haven't investigated further.
10e.g. { globals = { data = 1, func = function() useclosurehere() end } }" 10e.g. { globals = { data = 1, func = function() useclosurehere() end } }"
11]] 11]]
12 12
13require "lanes" 13local lanes = require "lanes"
14lanes.configure( 1)
14 15
15local function testrun() 16local function testrun()
16 assert( print ) 17 assert( print )
@@ -20,7 +21,7 @@ local function testrun()
20 return true 21 return true
21end 22end
22 23
23-- When some function dereferences a global key, the asssociated global in the source state 24-- When some function dereferences a global key, the associated global in the source state
24-- isn't sent over the target lane 25-- isn't sent over the target lane
25-- therefore, the necessary functions must either be pulled as upvalues (hence locals) 26-- therefore, the necessary functions must either be pulled as upvalues (hence locals)
26-- or the globals must exist in the target lanes because the modules have been required there 27-- or the globals must exist in the target lanes because the modules have been required there
diff --git a/tests/irayo_recursive.lua b/tests/irayo_recursive.lua
index 82e5a54..3eb14b8 100644
--- a/tests/irayo_recursive.lua
+++ b/tests/irayo_recursive.lua
@@ -8,7 +8,8 @@ local function recurse()
8 print("level "..i); 8 print("level "..i);
9 if i > 10 then return "finished" end 9 if i > 10 then return "finished" end
10 10
11 require "lanes" 11 local lanes = require "lanes"
12 lanes.configure( 1, "NO_TIMERS")
12 13
13 local lane = lanes.gen( "*", { globals = { ["i"]= i + 1 } }, recurse ) () 14 local lane = lanes.gen( "*", { globals = { ["i"]= i + 1 } }, recurse ) ()
14 return lane[1] 15 return lane[1]
diff --git a/tests/keeper.lua b/tests/keeper.lua
index 5c8c23a..7b11242 100644
--- a/tests/keeper.lua
+++ b/tests/keeper.lua
@@ -4,7 +4,8 @@
4-- Test program for Lua Lanes 4-- Test program for Lua Lanes
5-- 5--
6 6
7require "lanes" 7local lanes = require "lanes"
8lanes.configure( 1)
8 9
9local function keeper(linda) 10local function keeper(linda)
10 local mt= { 11 local mt= {
diff --git a/tests/launchtest.lua b/tests/launchtest.lua
index 5e3037f..8456091 100644
--- a/tests/launchtest.lua
+++ b/tests/launchtest.lua
@@ -45,7 +45,8 @@ for k,v in pairs( argtable(...) ) do
45 end 45 end
46end 46end
47 47
48require "lanes" 48local lanes = require "lanes"
49lanes.configure( 1)
49 50
50local g= lanes.gen( LIBS, function(i) 51local g= lanes.gen( LIBS, function(i)
51 --io.stderr:write( i.."\t" ) 52 --io.stderr:write( i.."\t" )
diff --git a/tests/linda_perf.lua b/tests/linda_perf.lua
index bad0024..12159da 100644
--- a/tests/linda_perf.lua
+++ b/tests/linda_perf.lua
@@ -1,4 +1,5 @@
1require "lanes" 1local lanes = require "lanes"
2lanes.configure( 1)
2 3
3-- this lane eats items in the linda one by one 4-- this lane eats items in the linda one by one
4local eater = function( l, loop) 5local eater = function( l, loop)
diff --git a/tests/objects.lua b/tests/objects.lua
index 8f56a5f..29e16d8 100644
--- a/tests/objects.lua
+++ b/tests/objects.lua
@@ -4,7 +4,8 @@
4-- Tests that objects (metatables) can be passed between lanes. 4-- Tests that objects (metatables) can be passed between lanes.
5-- 5--
6 6
7require "lanes" 7local lanes = require "lanes"
8lanes.configure( 1)
8 9
9local linda= lanes.linda() 10local linda= lanes.linda()
10 11
diff --git a/tests/perftest.lua b/tests/perftest.lua
index 8ce1b3c..3d9fde0 100644
--- a/tests/perftest.lua
+++ b/tests/perftest.lua
@@ -27,7 +27,8 @@
27local MSYS= os.getenv("OSTYPE")=="msys" 27local MSYS= os.getenv("OSTYPE")=="msys"
28 28
29 29
30require "lanes" 30local lanes = require "lanes"
31lanes.configure( 1)
31 32
32local m= require "argtable" 33local m= require "argtable"
33local argtable= assert( m.argtable ) 34local argtable= assert( m.argtable )
diff --git a/tests/protectproxy.lua b/tests/protectproxy.lua
index 57ca831..363dbf5 100644
--- a/tests/protectproxy.lua
+++ b/tests/protectproxy.lua
@@ -1,4 +1,5 @@
1require "lanes" 1local lanes = require "lanes"
2lanes.configure( 1)
2 3
3local body = function( param) 4local body = function( param)
4 print ( "lane body: " .. param) 5 print ( "lane body: " .. param)
diff --git a/tests/recursive.lua b/tests/recursive.lua
index 49c03d3..ad32df8 100644
--- a/tests/recursive.lua
+++ b/tests/recursive.lua
@@ -11,7 +11,9 @@ local function func( depth )
11 return "done!" 11 return "done!"
12 end 12 end
13 13
14 require "lanes" 14 local lanes = require "lanes"
15 -- lanes.configure() is gone after we call it...
16 lanes.configure( 1)
15 local lane= lanes.gen("*", func)( depth+1 ) 17 local lane= lanes.gen("*", func)( depth+1 )
16 return lane[1] 18 return lane[1]
17end 19end
diff --git a/tests/require.lua b/tests/require.lua
index 2cfe780..96717dc 100644
--- a/tests/require.lua
+++ b/tests/require.lua
@@ -3,7 +3,8 @@
3-- 3--
4-- Test that 'require' works from sublanes 4-- Test that 'require' works from sublanes
5-- 5--
6require 'lanes' 6local lanes = require "lanes"
7lanes.configure( 1)
7 8
8local function a_lane() 9local function a_lane()
9 -- To require 'math' we still actually need to have it initialized for 10 -- To require 'math' we still actually need to have it initialized for
diff --git a/tests/timer.lua b/tests/timer.lua
index e95f326..f0027d7 100644
--- a/tests/timer.lua
+++ b/tests/timer.lua
@@ -8,7 +8,8 @@
8io.stderr:setvbuf "no" 8io.stderr:setvbuf "no"
9 9
10 10
11require "lanes" 11local lanes = require "lanes"
12lanes.configure( 1)
12 13
13local linda= lanes.linda() 14local linda= lanes.linda()
14 15