diff --git a/tests/tests/test-ng-maps/cleanup.mad b/tests/tests/test-ng-maps/cleanup.mad new file mode 100644 index 000000000..c033d2a1e --- /dev/null +++ b/tests/tests/test-ng-maps/cleanup.mad @@ -0,0 +1,32 @@ +local filesys in MAD +local clean_plots = false +local clean_results = true +local clean_configs = true +MAD.warn( + "Cleaning up" .. + (clean_plots and " plots," or "") .. + (clean_results and " results," or "") .. + (clean_configs and " configs," or "") .. + " and all txt files in output/" +) + +for filename in filesys.dir ("output/") do + if clean_results and filename:find("_res.tfs") then + os.remove("output/"..filename) + elseif clean_configs and filename:find("_cfg.tfs") then + os.remove("output/"..filename) + elseif filename:find(".txt") then + os.remove("output/"..filename) + end +end + +if clean_plots then + for filename in filesys.dir ("output/plots/") do + os.remove("output/plots/"..filename) + end +end +os.remove("TMP_MAD_PLOT") +os.remove("setup1.out") +os.remove("output/setup1.mad") +os.remove("setup2.out") +os.remove("output/setup2.mad") \ No newline at end of file diff --git a/tests/tests/test-ng-maps/test-all-maps.mad b/tests/tests/test-ng-maps/test-all-maps.mad index dc8b9a51c..737dcbd83 100644 --- a/tests/tests/test-ng-maps/test-all-maps.mad +++ b/tests/tests/test-ng-maps/test-all-maps.mad @@ -46,8 +46,7 @@ Usage of directions: -- list of test suites (see src/madl_main.mad) local modules = { - "curved", "electric", "fringe", "misalignment", "misc", "multipole", "patch", - "subelm" + "curv", "elec", "fringe", "mis", "misc", "patch", "straight", "subelm" } -- allow global access @@ -97,6 +96,9 @@ MAD.strict() local parse_cmd_args, run_tests in require("testvsng") if parse_cmd_args() then return run_tests() end +ref_cfg.do_utest = true -- Unittest setup +ref_cfg.doplot = true -- Unittest setup + -- run test suites local status = MAD.utest.LuaUnit.run() diff --git a/tests/tests/test-ng-maps/test-curved-maps.mad b/tests/tests/test-ng-maps/test-curv-maps.mad similarity index 93% rename from tests/tests/test-ng-maps/test-curved-maps.mad rename to tests/tests/test-ng-maps/test-curv-maps.mad index 742962b62..22bc2b8d1 100644 --- a/tests/tests/test-ng-maps/test-curved-maps.mad +++ b/tests/tests/test-ng-maps/test-curv-maps.mad @@ -5,18 +5,6 @@ local run_test in require("trackvsng") -- The tests ------------------------------------------------------------------o TestCurved = {} -function TestCurved:setUp() - -- Turn off all unnecessary components for unit testing - ref_cfg.dodbg = false - ref_cfg.doprnt = 0 - ref_cfg.dosave = false - - -- Turn on the components for unit testing - ref_cfg.dorun = true - ref_cfg.do_utest = true - ref_cfg.doplot = true -end - function TestCurved:testSBEND() -- Test the body (~2 min) local cfg = ref_cfg "sbend" { elm = [[sbend 'sbend' { diff --git a/tests/tests/test-ng-maps/test-electric-maps.mad b/tests/tests/test-ng-maps/test-elec-maps.mad similarity index 88% rename from tests/tests/test-ng-maps/test-electric-maps.mad rename to tests/tests/test-ng-maps/test-elec-maps.mad index ad65f4379..4a73ff5a8 100644 --- a/tests/tests/test-ng-maps/test-electric-maps.mad +++ b/tests/tests/test-ng-maps/test-elec-maps.mad @@ -5,19 +5,6 @@ local run_test in require("trackvsng") -- The tests ------------------------------------------------------------------o TestElectric = {} -function TestElectric:setUp() - -- Turn off all unnecessary components for unit testing - - ref_cfg.dodbg = false - ref_cfg.doprnt = 0 - ref_cfg.dosave = false - - -- Turn on the components for unit testing - ref_cfg.dorun = true - ref_cfg.do_utest = true - ref_cfg.doplot = true -end - function TestElectric:testRFMULTIPOLE() local cfg = ref_cfg "rfmultipole" { elm = [[${element} 'rfm' { diff --git a/tests/tests/test-ng-maps/test-fringe-maps.mad b/tests/tests/test-ng-maps/test-fringe-maps.mad index a45b935ff..df9ccec10 100644 --- a/tests/tests/test-ng-maps/test-fringe-maps.mad +++ b/tests/tests/test-ng-maps/test-fringe-maps.mad @@ -6,18 +6,6 @@ local run_test in require("trackvsng") -- The tests ------------------------------------------------------------------o TestFringes = {} -function TestFringes:setUp() - -- Turn off all unnecessary components for unit testing - ref_cfg.dodbg = false - ref_cfg.doprnt = 0 - ref_cfg.dosave = false - - -- Turn on the components for unit testing - ref_cfg.dorun = true - ref_cfg.do_utest = true - ref_cfg.doplot = true -end - function TestFringes:testQUADfQSAD () local qsad in fringe fringe.qsad = 4 diff --git a/tests/tests/test-ng-maps/test-misalignment-maps.mad b/tests/tests/test-ng-maps/test-mis-maps.mad similarity index 94% rename from tests/tests/test-ng-maps/test-misalignment-maps.mad rename to tests/tests/test-ng-maps/test-mis-maps.mad index a0421a343..a9dff0f0e 100644 --- a/tests/tests/test-ng-maps/test-misalignment-maps.mad +++ b/tests/tests/test-ng-maps/test-mis-maps.mad @@ -5,18 +5,6 @@ local run_test in require("trackvsng") -- The tests ------------------------------------------------------------------o TestMis = {} --backtrack has high error (1e-12) for straight elements -function TestMis:setUp() - -- Turn off all unnecessary components for unit testing - ref_cfg.dodbg = false - ref_cfg.doprnt = 0 - ref_cfg.dosave = false - - -- Turn on the components for unit testing - ref_cfg.dorun = true - ref_cfg.do_utest = true - ref_cfg.doplot = true -end - function TestMis:testSBENDtrans() -- Test the body (~2 min) local cfg = ref_cfg "sbend_trans" { elm = [[sbend 'sbend' { diff --git a/tests/tests/test-ng-maps/test-misc-maps.mad b/tests/tests/test-ng-maps/test-misc-maps.mad index 33c647884..e4857a81b 100644 --- a/tests/tests/test-ng-maps/test-misc-maps.mad +++ b/tests/tests/test-ng-maps/test-misc-maps.mad @@ -5,18 +5,6 @@ local run_test in require("trackvsng") -- The tests ------------------------------------------------------------------o TestMisc = {} -function TestMisc:setUp() - -- Turn off all unnecessary components for unit testing - ref_cfg.dodbg = false - ref_cfg.doprnt = 0 - ref_cfg.dosave = false - - -- Turn on the components for unit testing - ref_cfg.dorun = true - ref_cfg.do_utest = true - ref_cfg.doplot = true -end - function TestMisc:testKICKER() local cfg = ref_cfg "kicker" { elm = "kicker 'kicker' {at=0.75, l=1.5, hkick=${bdir}*${hkick}, vkick=${bdir}*${vkick}}", diff --git a/tests/tests/test-ng-maps/test-patch-maps.mad b/tests/tests/test-ng-maps/test-patch-maps.mad index 50257e9b2..e226a1d17 100644 --- a/tests/tests/test-ng-maps/test-patch-maps.mad +++ b/tests/tests/test-ng-maps/test-patch-maps.mad @@ -5,18 +5,6 @@ local run_test in require("trackvsng") -- The tests ------------------------------------------------------------------o TestPatch = {} -function TestPatch:setUp() - -- Turn off all unnecessary components for unit testing - ref_cfg.dodbg = false - ref_cfg.doprnt = 0 - ref_cfg.dosave = false - - -- Turn on the components for unit testing - ref_cfg.dorun = true - ref_cfg.do_utest = true - ref_cfg.doplot = true -end - function TestPatch:testROTATION() local cfg = ref_cfg "rot" { elm = "${dir}rotation 'rot' {at=${at}, angle=${tdir}*math.pi/${_angle}}", diff --git a/tests/tests/test-ng-maps/test-multipole-maps.mad b/tests/tests/test-ng-maps/test-straight-maps.mad similarity index 89% rename from tests/tests/test-ng-maps/test-multipole-maps.mad rename to tests/tests/test-ng-maps/test-straight-maps.mad index 42bba39cc..ec48cff88 100644 --- a/tests/tests/test-ng-maps/test-multipole-maps.mad +++ b/tests/tests/test-ng-maps/test-straight-maps.mad @@ -3,21 +3,9 @@ local tblcat in MAD.utility local run_test in require("trackvsng") -- The tests ------------------------------------------------------------------o -TestMult = {} - -function TestMult:setUp() - -- Turn off all unnecessary components for unit testing - ref_cfg.dodbg = false - ref_cfg.doprnt = 0 - ref_cfg.dosave = false - - -- Turn on the components for unit testing - ref_cfg.dorun = true - ref_cfg.do_utest = true - ref_cfg.doplot = true -end +TestStraight = {} -function TestMult:testQUAD() -- Test the body (~2 min) +function TestStraight:testQUAD() -- Test the body (~2 min) local cfg = ref_cfg "quad" { elm = "quadrupole 'quad' {at=0.75, l=1.5, k1=${bdir}*${k1}, k1s=${bdir}*${k1s},tilt=${tdir}*${tilt}, fringe=0}", model = {1, 2}, @@ -53,7 +41,7 @@ function TestMult:testQUAD() -- Test the body (~2 min) run_test(cfg, equiv) end -function TestMult:testSEXT() +function TestStraight:testSEXT() local cfg = ref_cfg "sext" { elm = "sextupole 'sext' {at=0.75, l=1.5, k2=${bdir}*${k2}, k2s=${bdir}*${k2s},tilt=${tilt}}", model = {1, 2}, @@ -90,7 +78,7 @@ function TestMult:testSEXT() run_test(cfg, equiv) end -function TestMult:testOCT() +function TestStraight:testOCT() local cfg = ref_cfg "oct" { elm = "octupole 'oct' {at=0.75, l=1.5, k3=${bdir}*${k3}, k3s=${bdir}*${k3s},tilt=${tilt}, fringe=0}", model = {1, 2}, @@ -125,7 +113,7 @@ function TestMult:testOCT() run_test(cfg, equiv) end -function TestMult:testMULTIPOLE() +function TestStraight:testMULTIPOLE() local cfg = ref_cfg "mult" { elm = [[ multipole 'mult' { diff --git a/tests/tests/test-ng-maps/test-subelm-maps.mad b/tests/tests/test-ng-maps/test-subelm-maps.mad index 1f343bff7..7b6704561 100644 --- a/tests/tests/test-ng-maps/test-subelm-maps.mad +++ b/tests/tests/test-ng-maps/test-subelm-maps.mad @@ -2,6 +2,7 @@ local object, vector in MAD local tblcat in MAD.utility local run_test in require("trackvsng") +MAD.warn("TestSubElm: This test is not complete, missing fringe/tilt/misalignment tests") --[[ MISSING TEST -> SUB ELEMENTS + FRINGE/TILT/MISALIGNMENT ]] diff --git a/tests/tests/test-ng-maps/testvsng.mad b/tests/tests/test-ng-maps/testvsng.mad index 7da2b4011..532f21d26 100644 --- a/tests/tests/test-ng-maps/testvsng.mad +++ b/tests/tests/test-ng-maps/testvsng.mad @@ -39,7 +39,7 @@ Additional/Augmented options for unit tests, provided for tests against PTC: -c, --cmapall: Only run the cmap comparison, charge, edir and backtracking tests -l --luaall: Only run the lua charge, edir and backtracking tests -t, --test: Do not run unittests, instead run as a test where PTC is - run for every configuration. + run for every configuration. See -t -h for more details. If any of the following options are selected, by default all other tests are deselected --chg: Select to run the charge tests diff --git a/tests/tests/test-ng-maps/trackvsng.mad b/tests/tests/test-ng-maps/trackvsng.mad index f4270d4ac..38825ed97 100644 --- a/tests/tests/test-ng-maps/trackvsng.mad +++ b/tests/tests/test-ng-maps/trackvsng.mad @@ -6,8 +6,9 @@ local is_number, is_damap in MAD.typeid local assertTrue in MAD.utest package.path = package.path .. ";../tools/?.mad" -local get_diff, store_results, prnt_results, gen_cfg, in_dir, X0s, chk_tol, get_cfgs_to_run, - out_dir, add_trk_gen_cols, show_res, get_prev_res, tbl2da, save_res in require "track-tool" +local get_diff, store_results, prnt_results, gen_cfg, in_dir, X0s, chk_tol, + get_cfgs_to_run, out_dir, add_trk_gen_cols, show_res, get_prev_res, + tbl2da, save_res in require "track-tool" local plt_dir, plot_trk_res, do_norun in require "plot-tool" 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 end local function backtrack(cfg, results) + if not cfg.chk_cfg then -- If cfg is not in the list of cfgs to run, increment cfgid and return + cfg.cur_cfg.cfgid = cfg.cur_cfg.cfgid + cfg.npar + return + end if not cfg.dobck then return end -- Setup backward tracking local bck_cfg = tblcpy(cfg.cur_cfg) @@ -153,11 +158,19 @@ local function reverse_attr(cfg, results, attr) end local function reverse_chg(cfg, results) + if not cfg.chk_cfg then -- If cfg is not in the list of cfgs to run, increment cfgid and return + cfg.cur_cfg.cfgid = cfg.cur_cfg.cfgid + cfg.npar + return + end if not cfg.dochg then return end reverse_attr(cfg, results, "chg") end local function reverse_edir(cfg, results) + if not cfg.chk_cfg then -- If cfg is not in the list of cfgs to run, increment cfgid and return + cfg.cur_cfg.cfgid = cfg.cur_cfg.cfgid + cfg.npar + return + end if not cfg.doedir then return end reverse_attr(cfg, results, "edir") end @@ -166,7 +179,9 @@ local function cmaps(cfg, results) cfg.cmap = not cfg.cmap local cmap_script = create_run(cfg, cfg.cur_cfg) local _, cmap_res = loadstring(cmap_script)() - if cfg.docmap then + if not cfg.chk_cfg then -- If cfg is not in the list of cfgs to run, increment cfgid and continue + cfg.cur_cfg.cfgid = cfg.cur_cfg.cfgid + cfg.npar + elseif cfg.docmap then cfg.cur_cfg.test_type = "cmap" -- Set test type dif_save_prnt_dbg(cfg, cfg.ref_map, cmap_res, results, cmap_script) end @@ -182,10 +197,6 @@ end local function run_cfg(cfg, equiv, results) -- Get the mflow for the main config - if not cfg.chk_cfg then -- If cfg is not in the list of cfgs to run, increment cfgid and return - cfg.cur_cfg.cfgid = cfg.cur_cfg.cfgid + cfg.npar - return - end cfg.ref_script = create_run(cfg, cfg.cur_cfg) local _, ref = assert(loadstring(cfg.ref_script))() cfg.ref_map = ref @@ -201,7 +212,10 @@ local function run_cfg(cfg, equiv, results) end -- Copy main config to make comparable config and then compare - + if not cfg.chk_cfg then -- If cfg is not in the list of cfgs to run, increment cfgid and return + cfg.cur_cfg.cfgid = cfg.cur_cfg.cfgid + cfg.npar + return + end -- Generate similar configs if not cfg.docstm then return end for i, change_type in ipairs(equiv.alist or {}) do -- Go through list of equivalences @@ -254,15 +268,15 @@ end -- Run test -------------------------------------------------------------------o local function run_test(cfg, equiv) -- list of core values that are changed manually throughout the tests + args_to_cfg(cfg) -- Do this first to avoid side effects (cmap) + cfg.edir = 1 -- 1/-1 (element direction) cfg.sdir = 1 -- 1/-1 (tracking direction) cfg.chg = 1 -- 1/-1 (charge) cfg.tdir = \s-> s.edir * s.sdir -- tracking time direction cfg.bdir = \s-> s.edir * s.sdir * s.chg -- tracking beam direction - cfg.cmap = true -- Change the default for the release 0.9.8 - - args_to_cfg(cfg) - cfg.chk_cfg = get_cfgs_to_run(cfg.cid) + cfg.cmap = false -- default is lua since the test was built for lua first + cfg.chk_cfg = get_cfgs_to_run(cfg.cid) -- if cid not nil, get the cfgs to run otherwise true -- If the user does not want to run the test, just show results from previous run if not cfg.dorun then return do_norun (cfg) end @@ -278,7 +292,15 @@ local function run_test(cfg, equiv) novector = true, } - io.write("Running ", cfg.name, " (tol = ", tostring(cfg.tol), ")\n") + io.write("Running ", cfg.name, " (tol = ", tostring(cfg.tol), " eps)\n") + io.write( + "setup =", cfg.dosave and " sv" or "", cfg.doplot and " plt" or "", + cfg.doprnt > 0 and " prnt" or "", cfg.dodbg and " dbg" or "", + cfg.dobck and " bck" or "", cfg.doedir and " edir" or "", + cfg.dochg and " chg" or "", cfg.docmap and " cmap" or "", + cfg.docstm and " cstm" or "", not cfg.doluaall and " nolua" or "", + not cfg.docppall and " nocpp" or "", " o", cfg.order, " npar", cfg.npar, "\n" + ) if cfg.doprnt > 1 then -- Print the header io.write("cfgid\t") diff --git a/tests/tests/test-ptc-maps/cleanup.mad b/tests/tests/test-ptc-maps/cleanup.mad new file mode 100644 index 000000000..48889007e --- /dev/null +++ b/tests/tests/test-ptc-maps/cleanup.mad @@ -0,0 +1,41 @@ +local filesys in MAD +local clean_plots = false +local clean_results = true +local clean_configs = true +MAD.warn( + "Cleaning up" .. + (clean_plots and " plots," or "") .. + (clean_results and " results," or "") .. + (clean_configs and " configs," or "") .. + " and all txt files in output/" +) + +local input_files = { -- List of files that should not be removed + ["ref.mad" ] = true, + ["ref.madx"] = true, + ["." ] = true, + [".." ] = true, +} + +for filename in filesys.dir ("input/") do + if not input_files[filename] then + os.remove("input/"..filename) + end +end + +for filename in filesys.dir ("output/") do + if clean_results and filename:find("_res.tfs") then + os.remove("output/"..filename) + elseif clean_configs and filename:find("_cfg.tfs") then + os.remove("output/"..filename) + elseif filename:find(".txt") then + os.remove("output/"..filename) + end +end + +if clean_plots then + for filename in filesys.dir ("output/plots/") do + os.remove("output/plots/"..filename) + end +end +os.remove("TMP_MAD_PLOT") diff --git a/tests/tests/test-ptc-maps/test-all-maps.mad b/tests/tests/test-ptc-maps/test-all-maps.mad index 7b4b42fd5..0724bbe4f 100644 --- a/tests/tests/test-ptc-maps/test-all-maps.mad +++ b/tests/tests/test-ptc-maps/test-all-maps.mad @@ -37,6 +37,31 @@ local modules = { -- allow global access MAD.strict(false) +ref_cfg = MAD.object "ref" { + -- How to run the tests + dorun = true, -- Default: true + dosave = false, -- Default: false + doprnt = 0 , -- Default: 0 + dodbg = false, -- Default: false + doplot = false, -- Default: false + + gen_utest = false, -- Default: false + + -- list of variables in the tests + alist = {"model", "energy", "method", "nslice", "x0i"}, --attributes list + tol = 10, + + -- list of values that are used to run test but are not changed throughout + order = 4, -- 2/4 + icase = 56, -- 56/6 + debug = 0, -- 0/6 + snm = -1, + seql = 2, + cmap = true, + + x0i = 1..5, -- 0, 4D, 5D, 5D strong, 6D (see get_mad_str) +} + -- load test suites for _,v in ipairs(modules) do modules[v] = require("test-" .. v .. "-maps") @@ -51,6 +76,9 @@ MAD.strict() local parse_cmd_args, run_tests in require("testvsptc") if parse_cmd_args() then return run_tests() end +ref_cfg.do_utest = true -- Unitttest defaults +ref_cfg.doplot = true -- Unitttest defaults + -- run test suites local status = MAD.utest.LuaUnit.run() @@ -59,6 +87,7 @@ local testname = MAD.utest.LuaUnit.collectTests() -- build dict MAD.utility.setkeys(testname) +testname["ref_cfg"] = true -- Not an unexpected global -- check for unexpected globals MAD.checkglobal(testname) diff --git a/tests/tests/test-ptc-maps/test-elec-maps.mad b/tests/tests/test-ptc-maps/test-elec-maps.mad index 42fa9c427..0e7e3d41b 100644 --- a/tests/tests/test-ptc-maps/test-elec-maps.mad +++ b/tests/tests/test-ptc-maps/test-elec-maps.mad @@ -9,47 +9,12 @@ local rfcav_fringe = MAD.element.flags.fringe.rfcav -- The setup for the tests ----------------------------------------------------o -local ref_cfg = object "ref" { - -- How to run the tests - dorun = true, -- Default: true - dosave = false, -- Default: false - doprnt = 0 , -- Default: 0 - dodbg = false, -- Default: false - doplot = false, -- Default: false - - gen_utest = false, -- Default: false - - -- list of variables in the tests - alist = {"model", "energy", "method", "nslice", "x0i"}, --attributes list - tol = 10, - - -- list of values that are used to run test but are not changed throughout - order = 4, -- 2/4 - icase = 6, -- 56/6 - debug = 0, -- 0/6 - snm = -1, - seql = 2, - cmap = true, - - x0i = 1..5, -- 0, 4D, 5D, 5D strong, 6D (see get_mad_str) +local ref_cfg = ref_cfg { + icase = 6, -- We need icase = 6 for the electric maps } TestElectric = {} -function TestElectric:setUp() - -- Turn off all unnecessary components for unit testing - ref_cfg.gen_utest = false - ref_cfg.dodbg = false - ref_cfg.doprnt = 0 - ref_cfg.dosave = false - - -- Turn on the components for unit testing - ref_cfg.dorun = true - ref_cfg.do_utest = true - ref_cfg.doplot = true -end - - function TestElectric:testCAV() -- ~15 mins local cfg = ref_cfg "cav" { elm = [[ diff --git a/tests/tests/test-ptc-maps/test-misalign-maps.mad b/tests/tests/test-ptc-maps/test-misalign-maps.mad index 019342b4f..860119293 100644 --- a/tests/tests/test-ptc-maps/test-misalign-maps.mad +++ b/tests/tests/test-ptc-maps/test-misalign-maps.mad @@ -1,48 +1,11 @@ +-- ../mad test-all-maps.mad TestMis local object in MAD local tblcat in MAD.utility local run_test in require("trackvsptc") -local ref_cfg = object "ref" { - -- How to run the tests - dorun = true, -- Default: true - dosave = false, -- Default: false - doprnt = 0 , -- Default: 0 - dodbg = false, -- Default: false - doplot = false, -- Default: false - - gen_utest = false, -- Default: false - - -- list of variables in the tests - alist = {"model", "energy", "method", "nslice", "x0i"}, --attributes list - tol = 10, - - -- list of values that are used to run test but are not changed throughout - order = 4, -- 2/4 - icase = 56, -- 56/6 - debug = 0, -- 0/6 - snm = -1, - seql = 2, - cmap = true, - - x0i = 1..5, -- 0, 4D, 5D, 5D strong, 6D (see get_mad_str) -} - - --- The tests ------------------------------------------------------------------o TestMis = {} -function TestMis:setUp() - -- Turn off all unnecessary components for unit testing - ref_cfg.dodbg = false - ref_cfg.doprnt = 0 - ref_cfg.dosave = false - - -- Turn on the components for unit testing - ref_cfg.dorun = true - ref_cfg.do_utest = true - ref_cfg.doplot = true -end - +-- The tests ------------------------------------------------------------------o function TestMis:testSBENDtrn() -- Test the body (~2 min) local cfg = ref_cfg "sbend_trn" { elm = [[ diff --git a/tests/tests/test-ptc-maps/test-misc-maps.mad b/tests/tests/test-ptc-maps/test-misc-maps.mad index 3c409184a..0fd75deef 100644 --- a/tests/tests/test-ptc-maps/test-misc-maps.mad +++ b/tests/tests/test-ptc-maps/test-misc-maps.mad @@ -6,47 +6,8 @@ local tblcat in MAD.utility local run_test in require("trackvsptc") -- The setup for the tests ----------------------------------------------------o - -local ref_cfg = object "ref" { - -- How to run the tests - dorun = true, -- Default: true - dosave = false, -- Default: false - doprnt = 0 , -- Default: 0 - dodbg = false, -- Default: false - doplot = false, -- Default: false - - gen_utest = false, -- Default: false - - -- list of variables in the tests - alist = {"model", "energy", "method", "nslice", "x0i"}, --attributes list - tol = 10, - - -- list of values that are used to run test but are not changed throughout - order = 4, -- 2/4 - icase = 56, -- 56/6 - debug = 0, -- 0/6 - snm = -1, - seql = 2, - cmap = true, - - x0i = 1..5, -- 0, 4D, 5D, 5D strong, 6D (see get_mad_str) -} - TestMisc = {} -function TestMisc:setUp() - -- Turn off all unnecessary components for unit testing - ref_cfg.gen_utest = false - ref_cfg.dodbg = false - ref_cfg.doprnt = 0 - ref_cfg.dosave = false - - -- Turn on the components for unit testing - ref_cfg.dorun = true - ref_cfg.do_utest = true - ref_cfg.doplot = true -end - function TestMisc:testDRIFT() local cfg = ref_cfg "drift" { elm = "DRIFT, at=${at}, l=${l}, tilt=${tilt}*pi/8;", diff --git a/tests/tests/test-ptc-maps/test-mult-maps.mad b/tests/tests/test-ptc-maps/test-mult-maps.mad index 1fbe126af..b36a04a9a 100644 --- a/tests/tests/test-ptc-maps/test-mult-maps.mad +++ b/tests/tests/test-ptc-maps/test-mult-maps.mad @@ -1,4 +1,4 @@ --- ../mad test-mult-maps.mad +-- ../mad test-all-maps.mad TestMult -- assume ../madx64 to be present... local object, tostring in MAD @@ -7,47 +7,13 @@ local run_test in require("trackvsptc") -- The setup for the tests ----------------------------------------------------o -local ref_cfg = object "ref" { - -- How to run the tests - dorun = true, -- Default: true - dosave = false, -- Default: false - doprnt = 0 , -- Default: 0 - dodbg = false, -- Default: false - doplot = false, -- Default: false - - gen_utest = false, -- Default: false - - -- list of variables in the tests - alist = {"model", "energy", "method", "nslice", "x0i"}, --attributes list - tol = 10, - - -- list of values that are used to run test but are not changed throughout - order = 6, -- 2/4 - icase = 56, -- 56/6 - debug = 0, -- 0/6 - snm = -1, - seql = 2, - cmap = true, - - x0i = 1..5, -- 0, 4D, 5D, 6D (see get_mad_str) +local ref_cfg = ref_cfg { + order = 6, -- higher order multipoles tested here } TestMult = {} -function TestMult:setUp() - -- Turn off all unnecessary components for unit testing - ref_cfg.gen_utest = false - ref_cfg.dodbg = false - ref_cfg.doprnt = 0 - ref_cfg.dosave = false - - -- Turn on the components for unit testing - ref_cfg.dorun = true - ref_cfg.do_utest = true - ref_cfg.doplot = true -end - - +-- The tests ------------------------------------------------------------------o function TestMult:testMULT() -- Test multipole (1 min) local cfg = ref_cfg "mult" { elm = [[ diff --git a/tests/tests/test-ptc-maps/test-octu-maps.mad b/tests/tests/test-ptc-maps/test-octu-maps.mad index 65c9f164e..e5c4ac54f 100644 --- a/tests/tests/test-ptc-maps/test-octu-maps.mad +++ b/tests/tests/test-ptc-maps/test-octu-maps.mad @@ -1,52 +1,12 @@ --- ../mad test-octupole-maps.mad +-- ../mad test-all-maps.mad TestOctupole -- assume ../madx64 to be present... local object, tostring in MAD local tblcat in MAD.utility local run_test in require("trackvsptc") --- The setup for the tests ----------------------------------------------------o - -local ref_cfg = object "ref" { - -- How to run the tests - dorun = true, -- Default: true - dosave = false, -- Default: false - doprnt = 0 , -- Default: 0 - dodbg = false, -- Default: false - doplot = false, -- Default: false - - gen_utest = false, -- Default: false - - -- list of variables in the tests - alist = {"model", "energy", "method", "nslice", "x0i"}, --attributes list - tol = 10, - - -- list of values that are used to run test but are not changed throughout - order = 4, -- 2/4 - icase = 56, -- 56/6 - debug = 0, -- 0/6 - snm = -1, - seql = 2, - cmap = true, - - x0i = 1..5, -- 0, 4D, 5D, 5D strong, 6D (see get_mad_str) -} - TestOctupole = {} -function TestOctupole:setUp() - -- Turn off all unnecessary components for unit testing - ref_cfg.gen_utest = false - ref_cfg.dodbg = false - ref_cfg.doprnt = 0 - ref_cfg.dosave = false - - -- Turn on the components for unit testing - ref_cfg.dorun = true - ref_cfg.do_utest = true - ref_cfg.doplot = true -end - -- The tests ------------------------------------------------------------------o function TestOctupole:testOCT() -- Test the body (~2 min) local cfg = ref_cfg "oct" { diff --git a/tests/tests/test-ptc-maps/test-patch-maps.mad b/tests/tests/test-ptc-maps/test-patch-maps.mad index 6817fbd26..d2f9dbe78 100644 --- a/tests/tests/test-ptc-maps/test-patch-maps.mad +++ b/tests/tests/test-ptc-maps/test-patch-maps.mad @@ -1,52 +1,13 @@ --- ../mad test-patch-maps.mad +-- ../mad test-all-maps.mad TestPatch -- assume ../madx64 to be present... local object in MAD local tblcat in MAD.utility local run_test in require("trackvsptc") --- The setup for the tests ----------------------------------------------------o - -local ref_cfg = object "ref" { - -- How to run the tests - dorun = true, -- Default: true - dosave = false, -- Default: false - doprnt = 0 , -- Default: 0 - dodbg = false, -- Default: false - doplot = false, -- Default: false - - gen_utest = false, -- Default: false - - -- list of variables in the tests - alist = {"model", "energy", "method", "nslice", "x0i"}, --attributes list - tol = 10, - - -- list of values that are used to run test but are not changed throughout - order = 4, -- 2/4 - icase = 56, -- 56/6 - debug = 0, -- 0/6 - snm = -1, - seql = 2, - cmap = true, - - x0i = 1..5, -- 0, 4D, 5D, 5D strong, 6D (see get_mad_str) -} - TestPatch = {} -function TestPatch:setUp() - -- Turn off all unnecessary components for unit testing - ref_cfg.gen_utest = false - ref_cfg.dodbg = false - ref_cfg.doprnt = 0 - ref_cfg.dosave = false - - -- Turn on the components for unit testing - ref_cfg.dorun = true - ref_cfg.do_utest = true - ref_cfg.doplot = true -end - +-- The tests ------------------------------------------------------------------o function TestPatch:testRotation() local cfg = ref_cfg "rot" { elm = "${dir}ROTATION, at=${at}, angle=pi/${_angle};", diff --git a/tests/tests/test-ptc-maps/test-quad-maps.mad b/tests/tests/test-ptc-maps/test-quad-maps.mad index 4fa286ba8..476f7f55d 100644 --- a/tests/tests/test-ptc-maps/test-quad-maps.mad +++ b/tests/tests/test-ptc-maps/test-quad-maps.mad @@ -1,52 +1,12 @@ --- ../mad test-quad-maps.mad +-- ../mad test-all-maps.mad TestQuad -- assume ../madx64 to be present... local object, tostring in MAD local tblcat in MAD.utility local run_test in require("trackvsptc") --- The setup for the tests ----------------------------------------------------o - -local ref_cfg = object "ref" { - -- How to run the tests - dorun = true, -- Default: true - dosave = false, -- Default: false - doprnt = 0 , -- Default: 0 - dodbg = false, -- Default: false - doplot = false, -- Default: false - - gen_utest = false, -- Default: false - - -- list of variables in the tests - alist = {"model", "energy", "method", "nslice", "x0i"}, --attributes list - tol = 10, - - -- list of values that are used to run test but are not changed throughout - order = 4, -- 2/4 - icase = 56, -- 56/6 - debug = 0, -- 0/6 - snm = -1, - seql = 2, - cmap = true, - - x0i = 1..5, -- 0, 4D, 5D, 6D (see get_mad_str) -} - TestQuad = {} -function TestQuad:setUp() - -- Turn off all unnecessary components for unit testing - ref_cfg.gen_utest = false - ref_cfg.dodbg = false - ref_cfg.doprnt = 0 - ref_cfg.dosave = false - - -- Turn on the components for unit testing - ref_cfg.dorun = true - ref_cfg.do_utest = true - ref_cfg.doplot = true -end - -- The tests ------------------------------------------------------------------o function TestQuad:testQUAD() -- Test the body (~2 min) local cfg = ref_cfg "quad" { diff --git a/tests/tests/test-ptc-maps/test-rbend-maps.mad b/tests/tests/test-ptc-maps/test-rbend-maps.mad index 1ab30500f..8d6708b0b 100644 --- a/tests/tests/test-ptc-maps/test-rbend-maps.mad +++ b/tests/tests/test-ptc-maps/test-rbend-maps.mad @@ -1,52 +1,13 @@ --- ../mad test-rbend-maps.mad +-- ../mad test-all-maps.mad TestRBend -- assume ../madx64 to be present... local object, tostring in MAD local tblcat in MAD.utility local run_test in require("trackvsptc") --- The setup for the tests ----------------------------------------------------o - -local ref_cfg = object "ref" { - -- How to run the tests - dorun = true, -- Default: true - dosave = false, -- Default: false - doprnt = 0 , -- Default: 0 - dodbg = false, -- Default: false - doplot = false, -- Default: false - - gen_utest = false, -- Default: false - - -- list of variables in the tests - alist = {"model", "energy", "method", "nslice", "x0i"}, --attributes list - tol = 10, - - -- list of values that are used to run test but are not changed throughout - order = 4, -- 2/4 - icase = 56, -- 56/6 - debug = 0, -- 0/6 - snm = -1, - seql = 2, - cmap = true, - - x0i = 1..5, -- 0, 4D, 5D, 5D strong, 6D (see get_mad_str) -} - TestRBend = {} -function TestRBend:setUp() - -- Turn off all unnecessary components for unit testing - ref_cfg.gen_utest = false - ref_cfg.dodbg = false - ref_cfg.doprnt = 0 - ref_cfg.dosave = false - - -- Turn on the components for unit testing - ref_cfg.dorun = true - ref_cfg.do_utest = true - ref_cfg.doplot = true -end - +-- The tests ------------------------------------------------------------------o function TestRBend:testRBEND() local cfg = ref_cfg "rbend"{ elm = [[ diff --git a/tests/tests/test-ptc-maps/test-sbend-maps.mad b/tests/tests/test-ptc-maps/test-sbend-maps.mad index 3b8f29074..30c3e4ddf 100644 --- a/tests/tests/test-ptc-maps/test-sbend-maps.mad +++ b/tests/tests/test-ptc-maps/test-sbend-maps.mad @@ -1,53 +1,13 @@ --- ../mad test-sbend-maps.mad +-- ../mad test-all-maps.mad TestSBend -- assume ../madx64 to be present... local object, tostring in MAD local tblcat in MAD.utility local run_test in require("trackvsptc") --- The setup for the tests ----------------------------------------------------o - -local ref_cfg = object "ref_cfg" { - -- How to run the tests - dorun = true , -- Default: true - dosave = false, -- Default: false - doprnt = 0 , -- Default: 0 - dodbg = false, -- Default: false - doplot = false, -- Default: false - - gen_utest = false, -- Default: false - - -- list of variables in the tests - alist = {"model", "energy", "method", "nslice", "x0i"}, --attributes list - tol = 10, - - -- list of values that are used to run test but are not changed throughout - order = 4, -- 2/4 - icase = 56, -- 56/6 - debug = 0, -- 0/6 - snm = -1, - seql = 2, - cmap = true, - - x0i = 1..5, -- 0, 4D, 5D, 6D (see get_mad_str) -} - TestSBend = {} -function TestSBend:setUp() - -- Turn off all unnecessary components for unit testing - ref_cfg.gen_utest = false - ref_cfg.dodbg = false - ref_cfg.doprnt = 0 - ref_cfg.dosave = false - - -- Turn on the components for unit testing - ref_cfg.dorun = true - ref_cfg.do_utest = true - ref_cfg.doplot = true -end - - +-- The tests ------------------------------------------------------------------o function TestSBend:testSBEND() -- Why k0 = 0 bad? local cfg = ref_cfg "sbend" { elm = [[ diff --git a/tests/tests/test-ptc-maps/test-sext-maps.mad b/tests/tests/test-ptc-maps/test-sext-maps.mad index 343a39796..e07b17af9 100644 --- a/tests/tests/test-ptc-maps/test-sext-maps.mad +++ b/tests/tests/test-ptc-maps/test-sext-maps.mad @@ -1,52 +1,12 @@ --- ../mad test-sext-maps.mad +-- ../mad test-all-maps.mad TestSextupole -- assume ../madx64 to be present... local object, tostring in MAD local tblcat in MAD.utility local run_test in require("trackvsptc") --- The setup for the tests ----------------------------------------------------o - -local ref_cfg = object "ref" { - -- How to run the tests - dorun = true, -- Default: true - dosave = false, -- Default: false - doprnt = 0 , -- Default: 0 - dodbg = false, -- Default: false - doplot = false, -- Default: false - - gen_utest = false, -- Default: false - - -- list of variables in the tests - alist = {"model", "energy", "method", "nslice", "x0i"}, --attributes list - tol = 10, - - -- list of values that are used to run test but are not changed throughout - order = 4, -- 2/4 - icase = 56, -- 56/6 - debug = 0, -- 0/6 - snm = -1, - seql = 2, - cmap = true, - - x0i = 1..5, -- 0, 4D, 5D, 5D strong, 6D (see get_mad_str) -} - TestSextupole = {} -function TestSextupole:setUp() - -- Turn off all unnecessary components for unit testing - ref_cfg.gen_utest = false - ref_cfg.dodbg = false - ref_cfg.doprnt = 0 - ref_cfg.dosave = false - - -- Turn on the components for unit testing - ref_cfg.dorun = true - ref_cfg.do_utest = true - ref_cfg.doplot = true -end - -- The tests ------------------------------------------------------------------o function TestSextupole:testSEXT() -- Test the body (~2 min) local cfg = ref_cfg "sext" { diff --git a/tests/tests/test-ptc-maps/test-solen-maps.mad b/tests/tests/test-ptc-maps/test-solen-maps.mad index 7be59af6e..e435356a0 100644 --- a/tests/tests/test-ptc-maps/test-solen-maps.mad +++ b/tests/tests/test-ptc-maps/test-solen-maps.mad @@ -1,4 +1,4 @@ --- ../mad test-sol-maps.mad +-- ../mad test-all-maps.mad TestSol -- assume ../madx64 to be present... local object in MAD @@ -6,47 +6,8 @@ local tblcat in MAD.utility local run_test in require("trackvsptc") -- The setup for the tests ----------------------------------------------------o - -local ref_cfg = object "ref" { - -- How to run the tests - dorun = true, -- Default: true - dosave = false, -- Default: false - doprnt = 0 , -- Default: 0 - dodbg = false, -- Default: false - doplot = false, -- Default: false - - gen_utest = false, -- Default: false - - -- list of variables in the tests - alist = {"model", "energy", "method", "nslice", "x0i"}, --attributes list - tol = 10, - - -- list of values that are used to run test but are not changed throughout - order = 4, -- 2/4 - icase = 56, -- 56/6 - debug = 0, -- 0/6 - snm = -1, - seql = 2, - cmap = true, - - x0i = 1..5, -- 0, 4D, 5D, 5D strong, 6D (see get_mad_str) -} - TestSol = {} -function TestSol:setUp() - -- Turn off all unnecessary components for unit testing - ref_cfg.gen_utest = false - ref_cfg.dodbg = false - ref_cfg.doprnt = 0 - ref_cfg.dosave = false - - -- Turn on the components for unit testing - ref_cfg.dorun = true - ref_cfg.do_utest = true - ref_cfg.doplot = true -end - -- MADX PTC makes assumptions on whether you solenoid is thin or thick -- see https://github.com/MethodicalAcceleratorDesign/MAD-X/issues/1147 function TestSol:testSOL() diff --git a/tests/tests/test-ptc-maps/testvsptc.mad b/tests/tests/test-ptc-maps/testvsptc.mad index a520ba300..2e471765e 100644 --- a/tests/tests/test-ptc-maps/testvsptc.mad +++ b/tests/tests/test-ptc-maps/testvsptc.mad @@ -11,7 +11,7 @@ Tests options: -n, --norun: Do not run tests, just read cfg and res files and continue with other options -f, --figure: Generate a figure for each test in output/plots -g, --gutest: Generate unit tests for the current configuration - -c, --cmap: Use the C++ maps instead of the Lua maps for the test + -c, --cmap: Turn the C++ maps off, therefore use the Lua maps for the test -t, --test: Do not run unittests, instead run as a test where PTC is run for every configuration. -p, --pattern PATTERN: Execute all test names matching the Lua PATTERN @@ -30,9 +30,9 @@ UnitTests options: -d, --debug: Run dbgmap on PTC and MAD output (saved in output/) before assertion failure -g, --gutest: Generate as the unit tests is ran -s, --save: Save the config and results to a file - -c, --cmap: Use the C++ maps instead of the Lua maps for the utest + -c, --cmap: Turn the C++ maps off, therefore use the Lua maps for the utest -t, --test: Do not run unittests, instead run as a test where PTC is - run for every configuration. + run for every configuration. See -t -h for more details. Note: Plots are automatically generated for all utests in output/plots ]] diff --git a/tests/tests/test-ptc-maps/trackvsptc.mad b/tests/tests/test-ptc-maps/trackvsptc.mad index 67d6e7733..c05bbbb36 100644 --- a/tests/tests/test-ptc-maps/trackvsptc.mad +++ b/tests/tests/test-ptc-maps/trackvsptc.mad @@ -165,7 +165,18 @@ local function run_test(cfg) novector = true, } - io.write("Running ", cfg.name, " (tol = ", tostring(cfg.tol), ")\n") + local num_cfg = 1 + for _, attr in ipairs(cfg.alist) do num_cfg = num_cfg * #cfg[attr] end + io.write( + "Running ", cfg.name, + " (tol = ", tostring(cfg.tol), " eps, ", num_cfg, " configurations)\n" + ) + io.write( + "setup =", cfg.dosave and " sv" or "", cfg.doplot and " plt" or "", + cfg.doprnt > 0 and " prnt" or "", cfg.dodbg and " dbg" or "", + cfg.cmap and " cmap" or "", " coords", tostring(cfg.x0i), + " o", cfg.order, " icase", cfg.icase, " snm", cfg.snm, "\n" + ) if cfg.doprnt > 1 then io.write("cfgid\t") for i = 0, cfg.order do io.write("order ", i, "\t") end diff --git a/tests/tests/tools/test-tool.mad b/tests/tests/tools/test-tool.mad index be27a00f8..9443c1157 100644 --- a/tests/tests/tools/test-tool.mad +++ b/tests/tests/tools/test-tool.mad @@ -26,7 +26,7 @@ Additional/Augmented options for unit tests: -d, --debug: Run dbgmap on PTC and MAD output (saved in output/) before assertion failure -s, --save: Save the config and results to a file -t, --test: Do not run unittests, instead run as a test where PTC is - run for every configuration. + run for every configuration. See -t -h for more details. Note: Plots are automatically generated for all utests in output/plots ]] diff --git a/tests/tests/tools/track-tool.mad b/tests/tests/tools/track-tool.mad index d58a9470a..2a1d51c6a 100644 --- a/tests/tests/tools/track-tool.mad +++ b/tests/tests/tools/track-tool.mad @@ -58,6 +58,10 @@ local mtable = mtable {novector=true} -- All mtables should be novector -- Preprocessing what configs to run ------------------------------------------o local function get_cfgs_to_run (cid) + if is_nil(cid) then -- cid has not been defined + return true + end + MAD.warn("cid is defined, not all the configurations will be run") if is_table(cid) then local cfgs_to_run = setkeys(cid) return \s->cfgs_to_run[s.cur_cfg.cfgid + 1] -- +1 because we know cfgid is incremented after this function @@ -65,8 +69,6 @@ local function get_cfgs_to_run (cid) return \s->s.cur_cfg.cfgid+1 >= cid.start and s.cur_cfg.cfgid+1 <= cid.stop elseif is_number(cid) then return \s->s.cur_cfg.cfgid+1 == cid - elseif is_nil(cid) then - return \s->true else error("Invalid config id type") end