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
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
462
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
9 aggr_op_pattern = '[%'..table.concat(pairs_op,'%')..']'
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
10
461
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 446
diff changeset
11 for i = 1, #pairs_op do
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 446
diff changeset
12 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
13 types = types..pairs_cl[i]
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 446
diff changeset
14 end
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 446
diff changeset
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
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 446
diff changeset
19 function mkaggr(n_nest, maxdepth, o, c)
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 446
diff changeset
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
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
37
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
38 -- member (which cannot be first char) as array? Disallow multidimensional arrays
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
39 if #s > 1 and t ~= c and s:sub(-1) ~= ']' and math.random(arraydice) == 1 then
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
40 s = s..'['..math.random(maxarraylen)..']'
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
41 end
461
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 446
diff changeset
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
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 446
diff changeset
47 function mktype(t, n_nest, maxdepth, aggr_open)
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 446
diff changeset
48 -- aggregate opener?
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 446
diff changeset
49 local aggr_i = 0
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 446
diff changeset
50 for i = 1, #pairs_op do
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 446
diff changeset
51 if pairs_op[i] == t then
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 446
diff changeset
52 aggr_i = i
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 446
diff changeset
53 break
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 446
diff changeset
54 end
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 446
diff changeset
55 end
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 446
diff changeset
56
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 446
diff changeset
57 -- ignore new aggregates if above depth limit
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 446
diff changeset
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
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 446
diff changeset
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
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 446
diff changeset
66 -- aggregate closer?
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 446
diff changeset
67 for i = 1, #pairs_cl do
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 446
diff changeset
68 if pairs_cl[i] == t then
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 446
diff changeset
69 aggr_i = i
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 446
diff changeset
70 break
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 446
diff changeset
71 end
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 446
diff changeset
72 end
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 446
diff changeset
73
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 446
diff changeset
74 -- if closing char, without any open, ignore
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 446
diff changeset
75 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
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
b4ddad459690 suite_aggr;
Tassilo Philipp
parents: 434
diff changeset
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
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 446
diff changeset
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
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 446
diff changeset
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
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 446
diff changeset
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
b4ddad459690 suite_aggr;
Tassilo Philipp
parents: 434
diff changeset
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
b4ddad459690 suite_aggr;
Tassilo Philipp
parents: 434
diff changeset
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