Skip to content

Commit

Permalink
Issue #673: create jsonShell Test
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert McLay committed Nov 6, 2023
1 parent 3374ef8 commit 217c9da
Show file tree
Hide file tree
Showing 7 changed files with 234 additions and 1 deletion.
103 changes: 103 additions & 0 deletions proj_mgmt/jsonLoadConversion
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
#!/usr/bin/env lua
-- -*- lua -*-

local sys_lua_path = "@sys_lua_path@"
if (sys_lua_path:sub(1,1) == "@") then
sys_lua_path = package.path
end

local sys_lua_cpath = "@sys_lua_cpath@"
if (sys_lua_cpath:sub(1,1) == "@") then
sys_lua_cpath = package.cpath
end

package.path = sys_lua_path
package.cpath = sys_lua_cpath

local arg_0 = arg[0]
_G._DEBUG = false
local posix = require("posix")
local readlink = posix.readlink
local stat = posix.stat

local st = stat(arg_0)
while (st.type == "link") do
local lnk = readlink(arg_0)
if (arg_0:find("/") and (lnk:find("^/") == nil)) then
local dir = arg_0:gsub("/[^/]*$","")
lnk = dir .. "/" .. lnk
end
arg_0 = lnk
st = stat(arg_0)
end

local ia,ja = arg_0:find(".*/")
local LuaCommandName = false
local LuaCommandName_dir = "./"
if (ia) then
LuaCommandName_dir = arg_0:sub(1,ja)
LuaCommandName = arg_0:sub(ja+1)
end

package.path = LuaCommandName_dir .. "?.lua;" ..
LuaCommandName_dir .. "../tools/?.lua;" ..
LuaCommandName_dir .. "../tools/?/init.lua;" ..
LuaCommandName_dir .. "../shells/?.lua;" ..
LuaCommandName_dir .. "?/init.lua;" ..
sys_lua_path
package.cpath = LuaCommandName_dir .. "../lib/?.so;"..
sys_lua_cpath

require("strict")
require("string_utils")
require("serializeTbl")
local dbg = require("Dbg"):dbg()
if ( _VERSION ~= "Lua 5.1" ) then
require("declare")
declare("loadstring")
loadstring = load
end
local json = require("json")
local getenv = os.getenv
local strfmt = string.format
local concatTbl = table.concat
local base64 = require("base64")
local decode64 = base64.decode64


function main()
-- dbg:activateDebug(1)
local fn = arg[1]
local f = io.open(fn)
if (not f) then
io.stderr:write("Error: ",fn,"not found!\n")
exit(1)
end

local whole = f:read("*all")
f:close()
local tbl = json.decode(whole)
local nblks = tonumber(tbl.env._ModuleTable_Sz_)
local sA = {}
local piece = "_ModuleTable%03d_"

tbl.env._ModuleTable_Sz_ = nil
for i = 1,nblks do
local envNm = strfmt(piece,i)
sA[#sA+1] = tbl.env[envNm]
tbl.env[envNm] = nil
end

tbl.env.MT = decode64(concatTbl(sA))


local s = serializeTbl{ indent = true, name = "loadTbl",
value = tbl}
io.stdout:write(s)



end


main()
6 changes: 6 additions & 0 deletions rt/common_funcs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,11 @@ runFish ()
runBase $LUA_EXEC $projectDir/src/lmod.in.lua fish --regression_testing "$@"
}

runJson ()
{
runBase $LUA_EXEC $projectDir/src/lmod.in.lua json --regression_testing "$@"
}

runR ()
{
runBase $LUA_EXEC $projectDir/src/lmod.in.lua R --regression_testing "$@"
Expand Down Expand Up @@ -265,6 +270,7 @@ initStdEnvVars()
unset MODULEPATH
unset MODULEPATH_ROOT
unset MODULERCFILE
unset MY_PATH
unset TEXINPUTS
unset NLSPATH
unset OMP_NUM_THREADS
Expand Down
10 changes: 10 additions & 0 deletions rt/jsonShell/err.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
===========================
step 1
lua ProjectDIR/src/lmod.in.lua shell --regression_testing --version
===========================
Modules based on Lua: Version 8.7.32 2023-08-28 12:42 -05:00
by Robert McLay [email protected]
===========================
step 2
lua ProjectDIR/proj_mgmt/jsonLoadConversion load.json
===========================
55 changes: 55 additions & 0 deletions rt/jsonShell/jsonShell.tdesc
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
-- -*- lua -*-
local testName = "jsonShell"

testdescript = {
owner = "rtm",
product = "modules",
description = [[
Test initial module load
]],
keywords = {testName },

active = 1,
testName = testName,
job_submit_method = "INTERACTIVE",

runScript = [[
. $(projectDir)/rt/common_funcs.sh
unsetMT
initStdEnvVars
MODULEPATH=$(testDir)/mf/Core; export MODULEPATH
rm -f _stderr.* _stdout.* err.* out.*
rm -fr .lmod.d .lmodrc.lua load.json .cache .config
runLmod --version # 1
LD_PRELOAD= $LUA_EXEC $projectDir/src/lmod.in.lua json load A > load.json
runBase $LUA_EXEC $projectDir/proj_mgmt/jsonLoadConversion load.json
HOME=$ORIG_HOME
cat _stdout.[0-9][0-9][0-9] > _stdout.orig
joinBase64Results -bash _stdout.orig _stdout.new
cleanUp _stdout.new out.txt
cat _stderr.[0-9][0-9][0-9] > _stderr.orig
cleanUp _stderr.orig err.txt
rm -f results.csv
wrapperDiff --csv results.csv $(testDir)/out.txt out.txt
wrapperDiff --csv results.csv $(testDir)/err.txt err.txt
testFinish -r $(resultFn) -t $(runtimeFn) results.csv
]],


blessScript = [[
# perform what is needed
]],

tests = {
{ id='t1'},
},

}
5 changes: 5 additions & 0 deletions rt/jsonShell/mf/Core/A/1.0.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
setenv("A","A")
prepend_path("MY_PATH","/path/to/nowhere")
local bashStr = 'eval $($LMOD_DIR/ml_cmd "$@")'
local cshStr = "eval `$LMOD_DIR/ml_cmd $*`"
set_shell_function("ml",bashStr,cshStr)
49 changes: 49 additions & 0 deletions rt/jsonShell/out.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
===========================
step 1
lua ProjectDIR/src/lmod.in.lua shell --regression_testing --version
===========================
===========================
step 2
lua ProjectDIR/proj_mgmt/jsonLoadConversion load.json
===========================
loadTbl = {
_mlstatus = true,
alias = {},
env = {
A = "A",
LOADEDMODULES = "A/1.0",
MODULEPATH = "ProjectDIR/rt/jsonShell/mf/Core",
MT = [[_ModuleTable_ = {
MTversion = 3,
c_rebuildTime = false,
c_shortTime = false,
depthT = {},
family = {},
mT = {
A = {
fn = "ProjectDIR/rt/jsonShell/mf/Core/A/1.0.lua",
fullName = "A/1.0",
loadOrder = 1,
propT = {},
stackDepth = 0,
status = "active",
userName = "A",
wV = "000000001.*zfinal",
},
},
mpathA = {
"ProjectDIR/rt/jsonShell/mf/Core",
},
systemBaseMPATH = "ProjectDIR/rt/jsonShell/mf/Core",
}
]],
MY_PATH = "/path/to/nowhere",
_LMFILES_ = "ProjectDIR/rt/jsonShell/mf/Core/A/1.0.lua",
},
shellFunc = {
ml = {
"eval $($LMOD_DIR/ml_cmd \"$@\")", "eval `$LMOD_DIR/ml_cmd $*`",
},
},
unset = {},
}
7 changes: 6 additions & 1 deletion shells/JsonShell.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@

require("strict")

if ( _VERSION ~= "Lua 5.1" ) then
require("declare")
declare("loadstring")
loadstring = load
end
local js = require("json")

local BaseShell = require("BaseShell")
Expand All @@ -52,7 +57,7 @@ Json.js = ""

function Json.initialize(self)
-- Empty the json script so that it can be used in individual --
self.js = json.encode({alias={}, shellFunc={}, env={}, unset={}})
self.js = js.encode({alias={}, shellFunc={}, env={}, unset={}})
end

function Json.alias(self, k, v)
Expand Down

0 comments on commit 217c9da

Please sign in to comment.