Mercurial > pub > dyncall > dyncall
annotate test/suite_aggrs/rand-sig.lua @ 461:236015fdf7a8
suite_aggrs:
- added support to gen unions in addition to structs
- regenerated struct/union-mixed and nested cases
- made rand-sig.lua ignore closing struct/union chars if not opened, effectively reducing number of empty aggregates as it now generated way too much
author | Tassilo Philipp |
---|---|
date | Mon, 31 Jan 2022 14:41:11 +0100 |
parents | 54c1dc2e6ea5 |
children | 653b65580cb4 |
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 | |
9 for i = 1, #pairs_op do | |
10 if string.find(types, '%'..pairs_op[i]) and not string.find(types, '%'..pairs_cl[i]) then | |
11 types = types..pairs_cl[i] | |
12 end | |
13 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
|
14 |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
15 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
|
16 |
461 | 17 function mkaggr(n_nest, maxdepth, o, c) |
18 local s = o | |
432
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
19 |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
20 repeat |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
21 local id = math.random(#types) |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
22 local t = types:sub(id,id) |
461 | 23 s = s..mktype(t, n_nest, maxdepth, o) |
24 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
|
25 |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
26 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
|
27 end |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
28 |
461 | 29 function mktype(t, n_nest, maxdepth, aggr_open) |
30 -- aggregate opener? | |
31 local aggr_i = 0 | |
32 for i = 1, #pairs_op do | |
33 if pairs_op[i] == t then | |
34 aggr_i = i | |
35 break | |
36 end | |
37 end | |
38 | |
39 -- ignore new aggregates if above depth limit | |
40 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
|
41 if n_nest < maxdepth then |
461 | 42 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
|
43 else |
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 '' |
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 end |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
47 |
461 | 48 -- aggregate closer? |
49 for i = 1, #pairs_cl do | |
50 if pairs_cl[i] == t then | |
51 aggr_i = i | |
52 break | |
53 end | |
54 end | |
55 | |
56 -- if closing char, without any open, ignore | |
57 if aggr_i ~= 0 and (aggr_open == nil or pairs_op[aggr_i] ~= aggr_open) then | |
58 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
|
59 end |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
60 |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
61 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
|
62 end |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
63 |
461 | 64 function contains_empty_aggr(s) |
65 for i = 1, #pairs_op do | |
66 if string.match(s, '%'..pairs_op[i]..'%'..pairs_cl[i]) ~= nil then | |
67 return true | |
68 end | |
69 end | |
70 return false | |
71 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
|
72 |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
73 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
|
74 local id |
438 | 75 local uniq_sigs = { } |
461 | 76 local aggr_op_pattern = '[%'..table.concat(pairs_op,'%')..']' |
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 for i = 1, ncases do |
434
3d2c5d156d78
- test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents:
432
diff
changeset
|
78 local l = '' |
3d2c5d156d78
- test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents:
432
diff
changeset
|
79 repeat |
461 | 80 local nargs = math.random(minargs,maxargs) |
434
3d2c5d156d78
- test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents:
432
diff
changeset
|
81 id = math.random(#rtypes) |
461 | 82 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
|
83 for j = 1, nargs do |
3d2c5d156d78
- test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents:
432
diff
changeset
|
84 id = math.random(#types) |
461 | 85 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
|
86 end |
438 | 87 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
|
88 -- reject dupes, sigs without any aggregate (as this is about aggrs after all), and empty ones (if not wanted) |
461 | 89 until string.match(l, aggr_op_pattern) ~= nil and uniq_sigs[l] == nil and (emptyaggrs or not contains_empty_aggr(l)) |
438 | 90 uniq_sigs[l] = 1 |
434
3d2c5d156d78
- test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents:
432
diff
changeset
|
91 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
|
92 end |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
93 |