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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 446
diff changeset
4 -- inf loops; closing chars are allowe to appear alone, as they are ignored
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 446
diff changeset
5 -- without any opening char (does not make a lot of sense, though)
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 446
diff changeset
6 pairs_op = { '{', '<' } --, '[' }
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 446
diff changeset
7 pairs_cl = { '}', '>' } --, ']' }
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 446
diff changeset
8
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 446
diff changeset
9 for i = 1, #pairs_op do
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 446
diff changeset
10 if string.find(types, '%'..pairs_op[i]) and not string.find(types, '%'..pairs_cl[i]) then
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 446
diff changeset
11 types = types..pairs_cl[i]
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 446
diff changeset
12 end
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 446
diff changeset
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
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 446
diff changeset
17 function mkaggr(n_nest, maxdepth, o, c)
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 446
diff changeset
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
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 446
diff changeset
23 s = s..mktype(t, n_nest, maxdepth, o)
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 446
diff changeset
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
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 446
diff changeset
29 function mktype(t, n_nest, maxdepth, aggr_open)
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 446
diff changeset
30 -- aggregate opener?
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 446
diff changeset
31 local aggr_i = 0
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 446
diff changeset
32 for i = 1, #pairs_op do
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 446
diff changeset
33 if pairs_op[i] == t then
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 446
diff changeset
34 aggr_i = i
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 446
diff changeset
35 break
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 446
diff changeset
36 end
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 446
diff changeset
37 end
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 446
diff changeset
38
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 446
diff changeset
39 -- ignore new aggregates if above depth limit
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 446
diff changeset
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
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 446
diff changeset
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
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 446
diff changeset
48 -- aggregate closer?
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 446
diff changeset
49 for i = 1, #pairs_cl do
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 446
diff changeset
50 if pairs_cl[i] == t then
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 446
diff changeset
51 aggr_i = i
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 446
diff changeset
52 break
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 446
diff changeset
53 end
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 446
diff changeset
54 end
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 446
diff changeset
55
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 446
diff changeset
56 -- if closing char, without any open, ignore
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 446
diff changeset
57 if aggr_i ~= 0 and (aggr_open == nil or pairs_op[aggr_i] ~= aggr_open) then
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 446
diff changeset
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
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 446
diff changeset
64 function contains_empty_aggr(s)
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 446
diff changeset
65 for i = 1, #pairs_op do
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 446
diff changeset
66 if string.match(s, '%'..pairs_op[i]..'%'..pairs_cl[i]) ~= nil then
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 446
diff changeset
67 return true
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 446
diff changeset
68 end
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 446
diff changeset
69 end
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 446
diff changeset
70 return false
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 446
diff changeset
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
b4ddad459690 suite_aggr;
Tassilo Philipp
parents: 434
diff changeset
75 local uniq_sigs = { }
461
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 446
diff changeset
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
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 446
diff changeset
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
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 446
diff changeset
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
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 446
diff changeset
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
b4ddad459690 suite_aggr;
Tassilo Philipp
parents: 434
diff changeset
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
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 446
diff changeset
89 until string.match(l, aggr_op_pattern) ~= nil and uniq_sigs[l] == nil and (emptyaggrs or not contains_empty_aggr(l))
438
b4ddad459690 suite_aggr;
Tassilo Philipp
parents: 434
diff changeset
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