Skip to content

Commit 6f30b43

Browse files
authored
Merge pull request #407 from jgray-19/ng_vs_ng
Improve Test System
2 parents 27addf7 + c425665 commit 6f30b43

29 files changed

+186
-553
lines changed

tests/tests/test-ng-maps/cleanup.mad

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
local filesys in MAD
2+
local clean_plots = false
3+
local clean_results = true
4+
local clean_configs = true
5+
MAD.warn(
6+
"Cleaning up" ..
7+
(clean_plots and " plots," or "") ..
8+
(clean_results and " results," or "") ..
9+
(clean_configs and " configs," or "") ..
10+
" and all txt files in output/"
11+
)
12+
13+
for filename in filesys.dir ("output/") do
14+
if clean_results and filename:find("_res.tfs") then
15+
os.remove("output/"..filename)
16+
elseif clean_configs and filename:find("_cfg.tfs") then
17+
os.remove("output/"..filename)
18+
elseif filename:find(".txt") then
19+
os.remove("output/"..filename)
20+
end
21+
end
22+
23+
if clean_plots then
24+
for filename in filesys.dir ("output/plots/") do
25+
os.remove("output/plots/"..filename)
26+
end
27+
end
28+
os.remove("TMP_MAD_PLOT")
29+
os.remove("setup1.out")
30+
os.remove("output/setup1.mad")
31+
os.remove("setup2.out")
32+
os.remove("output/setup2.mad")

tests/tests/test-ng-maps/test-all-maps.mad

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ Usage of directions:
4646

4747
-- list of test suites (see src/madl_main.mad)
4848
local modules = {
49-
"curved", "electric", "fringe", "misalignment", "misc", "multipole", "patch",
50-
"subelm"
49+
"curv", "elec", "fringe", "mis", "misc", "patch", "straight", "subelm"
5150
}
5251

5352
-- allow global access
@@ -97,6 +96,9 @@ MAD.strict()
9796
local parse_cmd_args, run_tests in require("testvsng")
9897
if parse_cmd_args() then return run_tests() end
9998

99+
ref_cfg.do_utest = true -- Unittest setup
100+
ref_cfg.doplot = true -- Unittest setup
101+
100102
-- run test suites
101103
local status = MAD.utest.LuaUnit.run()
102104

tests/tests/test-ng-maps/test-curved-maps.mad renamed to tests/tests/test-ng-maps/test-curv-maps.mad

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,6 @@ local run_test in require("trackvsng")
55
-- The tests ------------------------------------------------------------------o
66
TestCurved = {}
77

8-
function TestCurved:setUp()
9-
-- Turn off all unnecessary components for unit testing
10-
ref_cfg.dodbg = false
11-
ref_cfg.doprnt = 0
12-
ref_cfg.dosave = false
13-
14-
-- Turn on the components for unit testing
15-
ref_cfg.dorun = true
16-
ref_cfg.do_utest = true
17-
ref_cfg.doplot = true
18-
end
19-
208
function TestCurved:testSBEND() -- Test the body (~2 min)
219
local cfg = ref_cfg "sbend" {
2210
elm = [[sbend 'sbend' {

tests/tests/test-ng-maps/test-electric-maps.mad renamed to tests/tests/test-ng-maps/test-elec-maps.mad

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,6 @@ local run_test in require("trackvsng")
55
-- The tests ------------------------------------------------------------------o
66
TestElectric = {}
77

8-
function TestElectric:setUp()
9-
-- Turn off all unnecessary components for unit testing
10-
11-
ref_cfg.dodbg = false
12-
ref_cfg.doprnt = 0
13-
ref_cfg.dosave = false
14-
15-
-- Turn on the components for unit testing
16-
ref_cfg.dorun = true
17-
ref_cfg.do_utest = true
18-
ref_cfg.doplot = true
19-
end
20-
218
function TestElectric:testRFMULTIPOLE()
229
local cfg = ref_cfg "rfmultipole" {
2310
elm = [[${element} 'rfm' {

tests/tests/test-ng-maps/test-fringe-maps.mad

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,6 @@ local run_test in require("trackvsng")
66
-- The tests ------------------------------------------------------------------o
77
TestFringes = {}
88

9-
function TestFringes:setUp()
10-
-- Turn off all unnecessary components for unit testing
11-
ref_cfg.dodbg = false
12-
ref_cfg.doprnt = 0
13-
ref_cfg.dosave = false
14-
15-
-- Turn on the components for unit testing
16-
ref_cfg.dorun = true
17-
ref_cfg.do_utest = true
18-
ref_cfg.doplot = true
19-
end
20-
219
function TestFringes:testQUADfQSAD ()
2210
local qsad in fringe
2311
fringe.qsad = 4

tests/tests/test-ng-maps/test-misalignment-maps.mad renamed to tests/tests/test-ng-maps/test-mis-maps.mad

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,6 @@ local run_test in require("trackvsng")
55
-- The tests ------------------------------------------------------------------o
66
TestMis = {} --backtrack has high error (1e-12) for straight elements
77

8-
function TestMis:setUp()
9-
-- Turn off all unnecessary components for unit testing
10-
ref_cfg.dodbg = false
11-
ref_cfg.doprnt = 0
12-
ref_cfg.dosave = false
13-
14-
-- Turn on the components for unit testing
15-
ref_cfg.dorun = true
16-
ref_cfg.do_utest = true
17-
ref_cfg.doplot = true
18-
end
19-
208
function TestMis:testSBENDtrans() -- Test the body (~2 min)
219
local cfg = ref_cfg "sbend_trans" {
2210
elm = [[sbend 'sbend' {

tests/tests/test-ng-maps/test-misc-maps.mad

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,6 @@ local run_test in require("trackvsng")
55
-- The tests ------------------------------------------------------------------o
66
TestMisc = {}
77

8-
function TestMisc:setUp()
9-
-- Turn off all unnecessary components for unit testing
10-
ref_cfg.dodbg = false
11-
ref_cfg.doprnt = 0
12-
ref_cfg.dosave = false
13-
14-
-- Turn on the components for unit testing
15-
ref_cfg.dorun = true
16-
ref_cfg.do_utest = true
17-
ref_cfg.doplot = true
18-
end
19-
208
function TestMisc:testKICKER()
219
local cfg = ref_cfg "kicker" {
2210
elm = "kicker 'kicker' {at=0.75, l=1.5, hkick=${bdir}*${hkick}, vkick=${bdir}*${vkick}}",

tests/tests/test-ng-maps/test-patch-maps.mad

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,6 @@ local run_test in require("trackvsng")
55
-- The tests ------------------------------------------------------------------o
66
TestPatch = {}
77

8-
function TestPatch:setUp()
9-
-- Turn off all unnecessary components for unit testing
10-
ref_cfg.dodbg = false
11-
ref_cfg.doprnt = 0
12-
ref_cfg.dosave = false
13-
14-
-- Turn on the components for unit testing
15-
ref_cfg.dorun = true
16-
ref_cfg.do_utest = true
17-
ref_cfg.doplot = true
18-
end
19-
208
function TestPatch:testROTATION()
219
local cfg = ref_cfg "rot" {
2210
elm = "${dir}rotation 'rot' {at=${at}, angle=${tdir}*math.pi/${_angle}}",

tests/tests/test-ng-maps/test-multipole-maps.mad renamed to tests/tests/test-ng-maps/test-straight-maps.mad

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,9 @@ local tblcat in MAD.utility
33
local run_test in require("trackvsng")
44

55
-- The tests ------------------------------------------------------------------o
6-
TestMult = {}
7-
8-
function TestMult:setUp()
9-
-- Turn off all unnecessary components for unit testing
10-
ref_cfg.dodbg = false
11-
ref_cfg.doprnt = 0
12-
ref_cfg.dosave = false
13-
14-
-- Turn on the components for unit testing
15-
ref_cfg.dorun = true
16-
ref_cfg.do_utest = true
17-
ref_cfg.doplot = true
18-
end
6+
TestStraight = {}
197

20-
function TestMult:testQUAD() -- Test the body (~2 min)
8+
function TestStraight:testQUAD() -- Test the body (~2 min)
219
local cfg = ref_cfg "quad" {
2210
elm = "quadrupole 'quad' {at=0.75, l=1.5, k1=${bdir}*${k1}, k1s=${bdir}*${k1s},tilt=${tdir}*${tilt}, fringe=0}",
2311
model = {1, 2},
@@ -53,7 +41,7 @@ function TestMult:testQUAD() -- Test the body (~2 min)
5341
run_test(cfg, equiv)
5442
end
5543

56-
function TestMult:testSEXT()
44+
function TestStraight:testSEXT()
5745
local cfg = ref_cfg "sext" {
5846
elm = "sextupole 'sext' {at=0.75, l=1.5, k2=${bdir}*${k2}, k2s=${bdir}*${k2s},tilt=${tilt}}",
5947
model = {1, 2},
@@ -90,7 +78,7 @@ function TestMult:testSEXT()
9078
run_test(cfg, equiv)
9179
end
9280

93-
function TestMult:testOCT()
81+
function TestStraight:testOCT()
9482
local cfg = ref_cfg "oct" {
9583
elm = "octupole 'oct' {at=0.75, l=1.5, k3=${bdir}*${k3}, k3s=${bdir}*${k3s},tilt=${tilt}, fringe=0}",
9684
model = {1, 2},
@@ -125,7 +113,7 @@ function TestMult:testOCT()
125113
run_test(cfg, equiv)
126114
end
127115

128-
function TestMult:testMULTIPOLE()
116+
function TestStraight:testMULTIPOLE()
129117
local cfg = ref_cfg "mult" {
130118
elm = [[
131119
multipole 'mult' {

tests/tests/test-ng-maps/test-subelm-maps.mad

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ local object, vector in MAD
22
local tblcat in MAD.utility
33
local run_test in require("trackvsng")
44

5+
MAD.warn("TestSubElm: This test is not complete, missing fringe/tilt/misalignment tests")
56
--[[
67
MISSING TEST -> SUB ELEMENTS + FRINGE/TILT/MISALIGNMENT
78
]]

tests/tests/test-ng-maps/testvsng.mad

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Additional/Augmented options for unit tests, provided for tests against PTC:
3939
-c, --cmapall: Only run the cmap comparison, charge, edir and backtracking tests
4040
-l --luaall: Only run the lua charge, edir and backtracking tests
4141
-t, --test: Do not run unittests, instead run as a test where PTC is
42-
run for every configuration.
42+
run for every configuration. See -t -h for more details.
4343

4444
If any of the following options are selected, by default all other tests are deselected
4545
--chg: Select to run the charge tests

tests/tests/test-ng-maps/trackvsng.mad

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ local is_number, is_damap in MAD.typeid
66
local assertTrue in MAD.utest
77

88
package.path = package.path .. ";../tools/?.mad"
9-
local get_diff, store_results, prnt_results, gen_cfg, in_dir, X0s, chk_tol, get_cfgs_to_run,
10-
out_dir, add_trk_gen_cols, show_res, get_prev_res, tbl2da, save_res in require "track-tool"
9+
local get_diff, store_results, prnt_results, gen_cfg, in_dir, X0s, chk_tol,
10+
get_cfgs_to_run, out_dir, add_trk_gen_cols, show_res, get_prev_res,
11+
tbl2da, save_res in require "track-tool"
1112

1213
local plt_dir, plot_trk_res, do_norun in require "plot-tool"
1314
local args_to_cfg in require "test-tool"
@@ -126,6 +127,10 @@ local function dif_save_prnt_dbg(cfg, exp, res, result_mtbl, script) -- exp and
126127
end
127128

128129
local function backtrack(cfg, results)
130+
if not cfg.chk_cfg then -- If cfg is not in the list of cfgs to run, increment cfgid and return
131+
cfg.cur_cfg.cfgid = cfg.cur_cfg.cfgid + cfg.npar
132+
return
133+
end
129134
if not cfg.dobck then return end
130135
-- Setup backward tracking
131136
local bck_cfg = tblcpy(cfg.cur_cfg)
@@ -153,11 +158,19 @@ local function reverse_attr(cfg, results, attr)
153158
end
154159

155160
local function reverse_chg(cfg, results)
161+
if not cfg.chk_cfg then -- If cfg is not in the list of cfgs to run, increment cfgid and return
162+
cfg.cur_cfg.cfgid = cfg.cur_cfg.cfgid + cfg.npar
163+
return
164+
end
156165
if not cfg.dochg then return end
157166
reverse_attr(cfg, results, "chg")
158167
end
159168

160169
local function reverse_edir(cfg, results)
170+
if not cfg.chk_cfg then -- If cfg is not in the list of cfgs to run, increment cfgid and return
171+
cfg.cur_cfg.cfgid = cfg.cur_cfg.cfgid + cfg.npar
172+
return
173+
end
161174
if not cfg.doedir then return end
162175
reverse_attr(cfg, results, "edir")
163176
end
@@ -166,7 +179,9 @@ local function cmaps(cfg, results)
166179
cfg.cmap = not cfg.cmap
167180
local cmap_script = create_run(cfg, cfg.cur_cfg)
168181
local _, cmap_res = loadstring(cmap_script)()
169-
if cfg.docmap then
182+
if not cfg.chk_cfg then -- If cfg is not in the list of cfgs to run, increment cfgid and continue
183+
cfg.cur_cfg.cfgid = cfg.cur_cfg.cfgid + cfg.npar
184+
elseif cfg.docmap then
170185
cfg.cur_cfg.test_type = "cmap" -- Set test type
171186
dif_save_prnt_dbg(cfg, cfg.ref_map, cmap_res, results, cmap_script)
172187
end
@@ -182,10 +197,6 @@ end
182197

183198
local function run_cfg(cfg, equiv, results)
184199
-- Get the mflow for the main config
185-
if not cfg.chk_cfg then -- If cfg is not in the list of cfgs to run, increment cfgid and return
186-
cfg.cur_cfg.cfgid = cfg.cur_cfg.cfgid + cfg.npar
187-
return
188-
end
189200
cfg.ref_script = create_run(cfg, cfg.cur_cfg)
190201
local _, ref = assert(loadstring(cfg.ref_script))()
191202
cfg.ref_map = ref
@@ -201,7 +212,10 @@ local function run_cfg(cfg, equiv, results)
201212
end
202213

203214
-- Copy main config to make comparable config and then compare
204-
215+
if not cfg.chk_cfg then -- If cfg is not in the list of cfgs to run, increment cfgid and return
216+
cfg.cur_cfg.cfgid = cfg.cur_cfg.cfgid + cfg.npar
217+
return
218+
end
205219
-- Generate similar configs
206220
if not cfg.docstm then return end
207221
for i, change_type in ipairs(equiv.alist or {}) do -- Go through list of equivalences
@@ -254,15 +268,15 @@ end
254268
-- Run test -------------------------------------------------------------------o
255269
local function run_test(cfg, equiv)
256270
-- list of core values that are changed manually throughout the tests
271+
args_to_cfg(cfg) -- Do this first to avoid side effects (cmap)
272+
257273
cfg.edir = 1 -- 1/-1 (element direction)
258274
cfg.sdir = 1 -- 1/-1 (tracking direction)
259275
cfg.chg = 1 -- 1/-1 (charge)
260276
cfg.tdir = \s-> s.edir * s.sdir -- tracking time direction
261277
cfg.bdir = \s-> s.edir * s.sdir * s.chg -- tracking beam direction
262-
cfg.cmap = true -- Change the default for the release 0.9.8
263-
264-
args_to_cfg(cfg)
265-
cfg.chk_cfg = get_cfgs_to_run(cfg.cid)
278+
cfg.cmap = false -- default is lua since the test was built for lua first
279+
cfg.chk_cfg = get_cfgs_to_run(cfg.cid) -- if cid not nil, get the cfgs to run otherwise true
266280

267281
-- If the user does not want to run the test, just show results from previous run
268282
if not cfg.dorun then return do_norun (cfg) end
@@ -278,7 +292,15 @@ local function run_test(cfg, equiv)
278292
novector = true,
279293
}
280294

281-
io.write("Running ", cfg.name, " (tol = ", tostring(cfg.tol), ")\n")
295+
io.write("Running ", cfg.name, " (tol = ", tostring(cfg.tol), " eps)\n")
296+
io.write(
297+
"setup =", cfg.dosave and " sv" or "", cfg.doplot and " plt" or "",
298+
cfg.doprnt > 0 and " prnt" or "", cfg.dodbg and " dbg" or "",
299+
cfg.dobck and " bck" or "", cfg.doedir and " edir" or "",
300+
cfg.dochg and " chg" or "", cfg.docmap and " cmap" or "",
301+
cfg.docstm and " cstm" or "", not cfg.doluaall and " nolua" or "",
302+
not cfg.docppall and " nocpp" or "", " o", cfg.order, " npar", cfg.npar, "\n"
303+
)
282304
if cfg.doprnt > 1 then
283305
-- Print the header
284306
io.write("cfgid\t")

tests/tests/test-ptc-maps/cleanup.mad

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
local filesys in MAD
2+
local clean_plots = false
3+
local clean_results = true
4+
local clean_configs = true
5+
MAD.warn(
6+
"Cleaning up" ..
7+
(clean_plots and " plots," or "") ..
8+
(clean_results and " results," or "") ..
9+
(clean_configs and " configs," or "") ..
10+
" and all txt files in output/"
11+
)
12+
13+
local input_files = { -- List of files that should not be removed
14+
["ref.mad" ] = true,
15+
["ref.madx"] = true,
16+
["." ] = true,
17+
[".." ] = true,
18+
}
19+
20+
for filename in filesys.dir ("input/") do
21+
if not input_files[filename] then
22+
os.remove("input/"..filename)
23+
end
24+
end
25+
26+
for filename in filesys.dir ("output/") do
27+
if clean_results and filename:find("_res.tfs") then
28+
os.remove("output/"..filename)
29+
elseif clean_configs and filename:find("_cfg.tfs") then
30+
os.remove("output/"..filename)
31+
elseif filename:find(".txt") then
32+
os.remove("output/"..filename)
33+
end
34+
end
35+
36+
if clean_plots then
37+
for filename in filesys.dir ("output/plots/") do
38+
os.remove("output/plots/"..filename)
39+
end
40+
end
41+
os.remove("TMP_MAD_PLOT")

0 commit comments

Comments
 (0)