diff options
| author | Benoit Germain <benoit.germain@ubisoft.com> | 2025-03-11 12:06:16 +0100 |
|---|---|---|
| committer | Benoit Germain <benoit.germain@ubisoft.com> | 2025-03-11 12:06:16 +0100 |
| commit | 9ba9cd6185a00bd0623f3cbc96a20ce34dafbbc5 (patch) | |
| tree | 3fd12bf590e43a84cc9c8117b5effbe29900d7e5 | |
| parent | af3161e5265b56a3d33a1ed45597f85c34806928 (diff) | |
| download | lanes-9ba9cd6185a00bd0623f3cbc96a20ce34dafbbc5.tar.gz lanes-9ba9cd6185a00bd0623f3cbc96a20ce34dafbbc5.tar.bz2 lanes-9ba9cd6185a00bd0623f3cbc96a20ce34dafbbc5.zip | |
Kill obsolete deeptest.lua file
| -rw-r--r-- | deep_test/deeptest.lua | 159 |
1 files changed, 0 insertions, 159 deletions
diff --git a/deep_test/deeptest.lua b/deep_test/deeptest.lua deleted file mode 100644 index de282a1..0000000 --- a/deep_test/deeptest.lua +++ /dev/null | |||
| @@ -1,159 +0,0 @@ | |||
| 1 | local lanes = require("lanes").configure{ with_timers = false} | ||
| 2 | local l = lanes.linda "my linda" | ||
| 3 | |||
| 4 | local table_unpack = table.unpack or unpack -- Lua 5.1 support | ||
| 5 | |||
| 6 | -- we will transfer userdata created by this module, so we need to make Lanes aware of it | ||
| 7 | local dt = lanes.require "deep_test" | ||
| 8 | |||
| 9 | -- set DEEP to any non-false value to run the Deep Userdata tests. "gc" selects a special test for debug purposes | ||
| 10 | DEEP = DEEP or true | ||
| 11 | -- set CLONABLE to any non-false value to run the Clonable Userdata tests | ||
| 12 | CLONABLE = CLONABLE or true | ||
| 13 | |||
| 14 | -- lua 5.1->5.2 support a single table uservalue | ||
| 15 | -- lua 5.3->5.4 supports an arbitrary type uservalue | ||
| 16 | local test_uvtype = (_VERSION == "Lua 5.4") and "function" or (_VERSION == "Lua 5.3") and "string" or "table" | ||
| 17 | -- lua 5.4 supports multiple uservalues | ||
| 18 | local nupvals = _VERSION == "Lua 5.4" and 3 or 1 | ||
| 19 | |||
| 20 | local makeUserValue = function( obj_) | ||
| 21 | if test_uvtype == "table" then | ||
| 22 | return {"some uservalue"} | ||
| 23 | elseif test_uvtype == "string" then | ||
| 24 | return "some uservalue" | ||
| 25 | elseif test_uvtype == "function" then | ||
| 26 | -- a function that pull the userdata as upvalue | ||
| 27 | local f = function() | ||
| 28 | return "-> '" .. tostring( obj_) .. "'" | ||
| 29 | end | ||
| 30 | return f | ||
| 31 | end | ||
| 32 | end | ||
| 33 | |||
| 34 | local printDeep = function( prefix_, obj_, t_) | ||
| 35 | print( prefix_, obj_) | ||
| 36 | for uvi = 1, nupvals do | ||
| 37 | local uservalue = obj_:getuv(uvi) | ||
| 38 | print ("uv #" .. uvi, type( uservalue), uservalue, type(uservalue) == "function" and uservalue() or "") | ||
| 39 | end | ||
| 40 | if t_ then | ||
| 41 | local count = 0 | ||
| 42 | for k, v in ipairs( t_) do | ||
| 43 | print( "t["..tostring(k).."]", v) | ||
| 44 | count = count + 1 | ||
| 45 | end | ||
| 46 | -- we should have only 2 indexed entries with the same value | ||
| 47 | assert(count == 2 and t_[1] == t_[2]) | ||
| 48 | end | ||
| 49 | print() | ||
| 50 | end | ||
| 51 | |||
| 52 | local performTest = function( obj_) | ||
| 53 | -- setup the userdata with some value and a uservalue | ||
| 54 | obj_:set( 666) | ||
| 55 | obj_:setuv( 1, makeUserValue( obj_)) | ||
| 56 | if nupvals > 1 then | ||
| 57 | -- keep uv #2 as nil | ||
| 58 | obj_:setuv( 3, "ENDUV") | ||
| 59 | end | ||
| 60 | |||
| 61 | local t = | ||
| 62 | { | ||
| 63 | -- two indices with an identical value: we should also have identical values on the other side (even if not the same as the original ones when they are clonables) | ||
| 64 | obj_, | ||
| 65 | obj_, | ||
| 66 | -- this one won't transfer because we don't support full uservalue as keys | ||
| 67 | [obj_] = "val" | ||
| 68 | } | ||
| 69 | |||
| 70 | -- read back the contents of the object | ||
| 71 | printDeep( "immediate:", obj_, t) | ||
| 72 | |||
| 73 | -- send the object in a linda, get it back out, read the contents | ||
| 74 | l:set( "key", obj_, t) | ||
| 75 | -- when obj_ is a deep userdata, out is the same userdata as obj_ (not another one pointing on the same deep memory block) because of an internal cache table [deep*] -> proxy) | ||
| 76 | -- when obj_ is a clonable userdata, we get a different clone everytime we cross a linda or lane barrier | ||
| 77 | local _n, _val1, _val2 = l:get( "key", 2) | ||
| 78 | assert(_n == (_val2 and 2 or 1)) | ||
| 79 | printDeep( "out of linda:", _val1, _val2) | ||
| 80 | |||
| 81 | -- send the object in a lane through argument passing, the lane body returns it as return value, read the contents | ||
| 82 | local g = lanes.gen( | ||
| 83 | "package" | ||
| 84 | , { | ||
| 85 | required = { "deep_test"} -- we will transfer userdata created by this module, so we need to make this lane aware of it | ||
| 86 | } | ||
| 87 | , function( arg_, t_) | ||
| 88 | -- read contents inside lane: arg_ and t_ by argument | ||
| 89 | printDeep( "in lane, as arguments:", arg_, t_) | ||
| 90 | -- read contents inside lane: obj_ and t by upvalue | ||
| 91 | printDeep( "in lane, as upvalues:", obj_, t) | ||
| 92 | -- read contents inside lane: in linda | ||
| 93 | local _n, _val1, _val2 = l:get( "key", 2) | ||
| 94 | assert(_n == (_val2 and 2 or 1)) | ||
| 95 | printDeep( "in lane, from linda:", _val1, _val2) | ||
| 96 | return arg_, t_ | ||
| 97 | end | ||
| 98 | ) | ||
| 99 | h = g( obj_, t) | ||
| 100 | -- when obj_ is a deep userdata, from_lane is the same userdata as obj_ (not another one pointing on the same deep memory block) because of an internal cache table [deep*] -> proxy) | ||
| 101 | -- when obj_ is a clonable userdata, we get a different clone everytime we cross a linda or lane barrier | ||
| 102 | printDeep( "from lane:", h[1], h[2]) | ||
| 103 | end | ||
| 104 | |||
| 105 | if DEEP then | ||
| 106 | print "================================================================" | ||
| 107 | print "DEEP" | ||
| 108 | local d = dt.new_deep(nupvals) | ||
| 109 | if type(DEEP) == "string" then | ||
| 110 | local gc_tests = { | ||
| 111 | thrasher = function(repeat_, size_) | ||
| 112 | print "in thrasher" | ||
| 113 | -- result is a table of repeat_ tables, each containing size_ entries | ||
| 114 | local result = {} | ||
| 115 | for i = 1, repeat_ do | ||
| 116 | local batch_values = {} | ||
| 117 | for j = 1, size_ do | ||
| 118 | table.insert(batch_values, j) | ||
| 119 | end | ||
| 120 | table.insert(result, batch_values) | ||
| 121 | end | ||
| 122 | print "thrasher done" | ||
| 123 | return result | ||
| 124 | end, | ||
| 125 | stack_abuser = function(repeat_, size_) | ||
| 126 | print "in stack_abuser" | ||
| 127 | for i = 1, repeat_ do | ||
| 128 | local batch_values = {} | ||
| 129 | for j = 1, size_ do | ||
| 130 | table.insert(batch_values, j) | ||
| 131 | end | ||
| 132 | -- return size_ values | ||
| 133 | local _ = table_unpack(batch_values) | ||
| 134 | end | ||
| 135 | print "stack_abuser done" | ||
| 136 | return result | ||
| 137 | end | ||
| 138 | } | ||
| 139 | -- have the object call the function from inside one of its functions, to detect if it gets collected from there (while in use!) | ||
| 140 | local testf = gc_tests[DEEP] | ||
| 141 | if testf then | ||
| 142 | local r = d:invoke(gc_tests[DEEP], REPEAT or 10, SIZE or 10) | ||
| 143 | print("invoke -> ", tostring(r)) | ||
| 144 | else | ||
| 145 | print("unknown test '" .. DEEP .. "'") | ||
| 146 | end | ||
| 147 | else | ||
| 148 | performTest(d) | ||
| 149 | end | ||
| 150 | end | ||
| 151 | |||
| 152 | if CLONABLE then | ||
| 153 | print "================================================================" | ||
| 154 | print "CLONABLE" | ||
| 155 | performTest( dt.new_clonable(nupvals)) | ||
| 156 | end | ||
| 157 | |||
| 158 | print "================================================================" | ||
| 159 | print "TEST OK" \ No newline at end of file | ||
