Mercurial > pub > dyncall > dyncall
comparison test/callback_suite/make-signatures.lua @ 495:45ac093ca822
- test/callback_suite: make it use shared random sig generator from call_suite and call_suite_aggrs
author | Tassilo Philipp |
---|---|
date | Mon, 21 Mar 2022 16:50:44 +0100 |
parents | 3e629dc19168 |
children | 1a813b706de4 |
comparison
equal
deleted
inserted
replaced
494:d45c582b5457 | 495:45ac093ca822 |
---|---|
1 require "config" | 1 require "config" |
2 require "math" | 2 require "math" |
3 require "string" | 3 require "string" |
4 | 4 |
5 local nargtypes = string.len(argtypes) | |
6 local nrettypes = string.len(rettypes) | |
7 local argrange = maxargs - minargs | |
8 math.randomseed(seed) | |
9 | 5 |
10 function randomSignatures(nsigs) | 6 function randomSignatures() |
11 local i | 7 package.path = '../common/?.lua;' .. package.path |
12 for i = 1, nsigs do | 8 require"rand-sig" |
13 local nargs = minargs + math.random(argrange+1) - 1 | |
14 local signature = "" | |
15 for j = 1, nargs do | |
16 local typeindex = math.random(nargtypes) | |
17 signature = signature .. string.sub(argtypes, typeindex, typeindex) | |
18 end | |
19 local rtypeindex = math.random(nrettypes) | |
20 signature = signature .. ")" .. string.sub(rettypes, rtypeindex, rtypeindex) | |
21 io.write(signature .. "\n") | |
22 end | |
23 end | 9 end |
10 | |
24 | 11 |
25 function orderedSignature(x) | 12 function orderedSignature(x) |
26 local signature = "" | 13 local signature = "" |
27 local typeindex | 14 local typeindex |
15 local nargtypes = string.len(types) | |
28 while true do | 16 while true do |
29 if x < nargtypes then break end | 17 if x < nargtypes then break end |
30 typeindex = 1 + math.mod(x, nargtypes) | 18 typeindex = 1 + math.mod(x, nargtypes) |
31 signature = signature .. string.sub(argtypes, typeindex, typeindex) | 19 signature = signature .. string.sub(types, typeindex, typeindex) |
32 x = math.floor( x / nargtypes ) | 20 x = math.floor( x / nargtypes ) |
33 end | 21 end |
34 typeindex = 1 + x | 22 typeindex = 1 + x |
35 signature = signature .. ")" .. string.sub(argtypes, typeindex, typeindex) | 23 signature = signature .. ")" .. string.sub(types, typeindex, typeindex) |
36 return signature | 24 return signature |
37 end | 25 end |
38 | 26 |
39 function orderedSignatures(nsigs) | 27 |
28 function orderedSignatures() | |
40 local i | 29 local i |
41 for i = 1, nsigs do | 30 for i = 1, ncases do |
42 io.write( orderedSignature(offset+i*step) .. "\n" ) | 31 io.write( orderedSignature(offset+i*step) .. "\n" ) |
43 end | 32 end |
44 end | 33 end |
34 | |
45 | 35 |
46 function designedSignatures() | 36 function designedSignatures() |
47 for line in io.lines(designfile) do | 37 for line in io.lines(designfile) do |
48 io.write( line ) | 38 io.write( line ) |
49 io.write( "\n" ) | 39 io.write( "\n" ) |
50 end | 40 end |
51 end | 41 end |
52 | 42 |
43 | |
53 if mode == "random" then | 44 if mode == "random" then |
54 randomSignatures(nsigs) | 45 randomSignatures() |
55 elseif mode == "ordered" then | 46 elseif mode == "ordered" then |
56 orderedSignatures(nsigs) | 47 orderedSignatures() |
57 elseif mode == "designed" then | 48 elseif mode == "designed" then |
58 designedSignatures() | 49 designedSignatures() |
59 else | 50 else |
60 error("'mode' must be 'random' or 'ordered'") | 51 error("'mode' must be 'random', 'ordered' or 'designed'") |
61 end | 52 end |
62 | 53 |
63 io.flush() | 54 io.flush() |
64 | 55 |