Mercurial > pub > dyncall > dyncall
annotate test/call_suite_aggrs/rand-sig.lua @ 485:0c68b3f91367
- renamed suite_aggrs to call_suite_aggrs for consistency (callback version will be called callback_suite_aggrs)
author | Tassilo Philipp |
---|---|
date | Thu, 17 Mar 2022 15:41:26 +0100 |
parents | test/suite_aggrs/rand-sig.lua@bd8f5da2c74b |
children | d45c582b5457 |
rev | line source |
---|---|
432
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
1 require"config" |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
2 |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
3 -- assure aggr chars are present in pairs (can be weighted, though), to avoid |
461 | 4 -- inf loops; closing chars are allowe to appear alone, as they are ignored |
5 -- without any opening char (does not make a lot of sense, though) | |
6 pairs_op = { '{', '<' } --, '[' } | |
7 pairs_cl = { '}', '>' } --, ']' } | |
8 | |
462 | 9 aggr_op_pattern = '[%'..table.concat(pairs_op,'%')..']' |
10 | |
461 | 11 for i = 1, #pairs_op do |
12 if string.find(types, '%'..pairs_op[i]) and not string.find(types, '%'..pairs_cl[i]) then | |
13 types = types..pairs_cl[i] | |
14 end | |
15 end | |
432
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
16 |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
17 rtypes = "v"..types |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
18 |
461 | 19 function mkaggr(n_nest, maxdepth, o, c) |
20 local s = o | |
463
bd8f5da2c74b
suite_aggr: added configurable limits to number of struct fields (also simplified allowing (or not) empty ones)
Tassilo Philipp
parents:
462
diff
changeset
|
21 local nfields = 0 |
432
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
22 |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
23 repeat |
463
bd8f5da2c74b
suite_aggr: added configurable limits to number of struct fields (also simplified allowing (or not) empty ones)
Tassilo Philipp
parents:
462
diff
changeset
|
24 local t = c |
bd8f5da2c74b
suite_aggr: added configurable limits to number of struct fields (also simplified allowing (or not) empty ones)
Tassilo Philipp
parents:
462
diff
changeset
|
25 if nfields < maxaggrfields then |
bd8f5da2c74b
suite_aggr: added configurable limits to number of struct fields (also simplified allowing (or not) empty ones)
Tassilo Philipp
parents:
462
diff
changeset
|
26 repeat |
bd8f5da2c74b
suite_aggr: added configurable limits to number of struct fields (also simplified allowing (or not) empty ones)
Tassilo Philipp
parents:
462
diff
changeset
|
27 local id = math.random(#types) |
bd8f5da2c74b
suite_aggr: added configurable limits to number of struct fields (also simplified allowing (or not) empty ones)
Tassilo Philipp
parents:
462
diff
changeset
|
28 t = types:sub(id,id) |
bd8f5da2c74b
suite_aggr: added configurable limits to number of struct fields (also simplified allowing (or not) empty ones)
Tassilo Philipp
parents:
462
diff
changeset
|
29 until t ~= c or nfields >= minaggrfields |
bd8f5da2c74b
suite_aggr: added configurable limits to number of struct fields (also simplified allowing (or not) empty ones)
Tassilo Philipp
parents:
462
diff
changeset
|
30 end |
bd8f5da2c74b
suite_aggr: added configurable limits to number of struct fields (also simplified allowing (or not) empty ones)
Tassilo Philipp
parents:
462
diff
changeset
|
31 |
bd8f5da2c74b
suite_aggr: added configurable limits to number of struct fields (also simplified allowing (or not) empty ones)
Tassilo Philipp
parents:
462
diff
changeset
|
32 s_ = mktype(t, n_nest, maxdepth, o) |
bd8f5da2c74b
suite_aggr: added configurable limits to number of struct fields (also simplified allowing (or not) empty ones)
Tassilo Philipp
parents:
462
diff
changeset
|
33 if(#s_ > 0) then |
bd8f5da2c74b
suite_aggr: added configurable limits to number of struct fields (also simplified allowing (or not) empty ones)
Tassilo Philipp
parents:
462
diff
changeset
|
34 nfields = nfields + 1 |
bd8f5da2c74b
suite_aggr: added configurable limits to number of struct fields (also simplified allowing (or not) empty ones)
Tassilo Philipp
parents:
462
diff
changeset
|
35 end |
bd8f5da2c74b
suite_aggr: added configurable limits to number of struct fields (also simplified allowing (or not) empty ones)
Tassilo Philipp
parents:
462
diff
changeset
|
36 s = s..s_ |
462 | 37 |
38 -- member (which cannot be first char) as array? Disallow multidimensional arrays | |
39 if #s > 1 and t ~= c and s:sub(-1) ~= ']' and math.random(arraydice) == 1 then | |
40 s = s..'['..math.random(maxarraylen)..']' | |
41 end | |
461 | 42 until t == c |
432
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
43 |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
44 return s |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
45 end |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
46 |
461 | 47 function mktype(t, n_nest, maxdepth, aggr_open) |
48 -- aggregate opener? | |
49 local aggr_i = 0 | |
50 for i = 1, #pairs_op do | |
51 if pairs_op[i] == t then | |
52 aggr_i = i | |
53 break | |
54 end | |
55 end | |
56 | |
57 -- ignore new aggregates if above depth limit | |
58 if aggr_i ~= 0 and t == pairs_op[aggr_i] then | |
434
3d2c5d156d78
- test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents:
432
diff
changeset
|
59 if n_nest < maxdepth then |
461 | 60 return mkaggr(n_nest + 1, maxdepth, pairs_op[aggr_i], pairs_cl[aggr_i]) |
432
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
61 else |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
62 return '' |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
63 end |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
64 end |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
65 |
461 | 66 -- aggregate closer? |
67 for i = 1, #pairs_cl do | |
68 if pairs_cl[i] == t then | |
69 aggr_i = i | |
70 break | |
71 end | |
72 end | |
73 | |
74 -- if closing char, without any open, ignore | |
75 if aggr_i ~= 0 and (aggr_open == nil or pairs_op[aggr_i] ~= aggr_open) then | |
76 return '' | |
432
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
77 end |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
78 |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
79 return t |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
80 end |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
81 |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
82 math.randomseed(seed) |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
83 local id |
438 | 84 local uniq_sigs = { } |
432
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
85 for i = 1, ncases do |
434
3d2c5d156d78
- test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents:
432
diff
changeset
|
86 local l = '' |
3d2c5d156d78
- test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents:
432
diff
changeset
|
87 repeat |
461 | 88 local nargs = math.random(minargs,maxargs) |
434
3d2c5d156d78
- test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents:
432
diff
changeset
|
89 id = math.random(#rtypes) |
461 | 90 local sig = { mktype(rtypes:sub(id,id), 0, math.random(maxaggrdepth), nil) } -- random depth avoids excessive nesting |
434
3d2c5d156d78
- test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents:
432
diff
changeset
|
91 for j = 1, nargs do |
3d2c5d156d78
- test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents:
432
diff
changeset
|
92 id = math.random(#types) |
461 | 93 sig[#sig+1] = mktype(types:sub(id,id), 0, math.random(maxaggrdepth), nil) -- random depth avoids excessive nesting |
434
3d2c5d156d78
- test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents:
432
diff
changeset
|
94 end |
438 | 95 l = table.concat(sig) |
446
54c1dc2e6ea5
suite_aggrs: added knob to enable/disable generation of empty structs (some compilers like Plan9's pcc don't allow them)
Tassilo Philipp
parents:
438
diff
changeset
|
96 -- reject dupes, sigs without any aggregate (as this is about aggrs after all), and empty ones (if not wanted) |
463
bd8f5da2c74b
suite_aggr: added configurable limits to number of struct fields (also simplified allowing (or not) empty ones)
Tassilo Philipp
parents:
462
diff
changeset
|
97 until string.match(l, aggr_op_pattern) ~= nil and uniq_sigs[l] == nil |
438 | 98 uniq_sigs[l] = 1 |
434
3d2c5d156d78
- test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents:
432
diff
changeset
|
99 io.write(l.."\n") |
432
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
100 end |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
101 |