Skip to content

Commit

Permalink
Adding load_hook test
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert McLay committed Jan 1, 2025
1 parent 46c7622 commit 1f416cc
Show file tree
Hide file tree
Showing 7 changed files with 153 additions and 1 deletion.
16 changes: 16 additions & 0 deletions rt/load_hook/SitePackage.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
local hook = require("Hook")

local function xcc_depend_hook(t)
-- the arg t is a table:
-- t.modFullName: the module full name: (i.e: gcc/4.7.2)
-- t.fn: The file name: (i.e /apps/modulefiles/Core/gcc/4.7.2.lua)
-- t.mname: The Module Name object.

if (t.modFullName:find("xcc")) then
depends_on("d")
end
end

hook.register("load", xcc_depend_hook)
hook.register("unload", xcc_depend_hook)

25 changes: 25 additions & 0 deletions rt/load_hook/err.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
===========================
step 1
lua ProjectDIR/src/lmod.in.lua shell --regression_testing --version
===========================
Modules based on Lua: Version 8.7.55 2024-12-13 12:24 -07:00
by Robert McLay [email protected]
===========================
step 2
lua ProjectDIR/src/lmod.in.lua shell --regression_testing load xcc
===========================
===========================
step 3
lua ProjectDIR/src/lmod.in.lua shell --regression_testing list
===========================
Currently Loaded Modules:
1) xcc/1.0 2) d/2.0
===========================
step 4
lua ProjectDIR/src/lmod.in.lua shell --regression_testing unload xcc
===========================
===========================
step 5
lua ProjectDIR/src/lmod.in.lua shell --regression_testing list
===========================
No modules loaded
59 changes: 59 additions & 0 deletions rt/load_hook/load_hook.tdesc
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
-- -*- lua -*-
testdescript = {
owner = "rtm",
product = "modules",
description = [[
Test load hook
]],
keywords = {"load_hook" },

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

runScript = [[
. $(projectDir)/rt/common_funcs.sh
unsetMT
initStdEnvVars
LUA=`findcmd lua`
ORIGINAL_PATH=$PATH
MODULEPATH_ROOT=$(testDir)/mf; export MODULEPATH_ROOT
MODULEPATH=$MODULEPATH_ROOT/Core; export MODULEPATH
remove_generated_lmod_files
export LMOD_PACKAGE_PATH=$(testDir)
runLmod --version # 1
runLmod load xcc # 2
runLmod list # 3
runLmod unload xcc # 4
runLmod list # 5
HOME=$ORIG_HOME
PATH=$ORIGINAL_PATH
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'},
},

}
1 change: 1 addition & 0 deletions rt/load_hook/mf/Core/d/2.0.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
setenv("D","2.0")
1 change: 1 addition & 0 deletions rt/load_hook/mf/Core/xcc/1.0.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
setenv("XCC","1.0")
50 changes: 50 additions & 0 deletions rt/load_hook/out.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
===========================
step 1
lua ProjectDIR/src/lmod.in.lua shell --regression_testing --version
===========================
===========================
step 2
lua ProjectDIR/src/lmod.in.lua shell --regression_testing load xcc
===========================
D=2.0;
export D;
LOADEDMODULES=xcc/1.0:d/2.0;
export LOADEDMODULES;
__LMOD_REF_COUNT_MODULEPATH=ProjectDIR/rt/load_hook/mf/Core:1;
export __LMOD_REF_COUNT_MODULEPATH;
MODULEPATH=ProjectDIR/rt/load_hook/mf/Core;
export MODULEPATH;
XCC=1.0;
export XCC;
_LMFILES_=ProjectDIR/rt/load_hook/mf/Core/xcc/1.0.lua:ProjectDIR/rt/load_hook/mf/Core/d/2.0.lua;
export _LMFILES_;
_ModuleTable_='_ModuleTable_={MTversion=3,depthT={},family={},mT={d={fn="ProjectDIR/rt/load_hook/mf/Core/d/2.0.lua",fullName="d/2.0",loadOrder=2,propT={},ref_count=1,stackDepth=1,status="active",userName="d",wV="000000002.*zfinal",},xcc={fn="ProjectDIR/rt/load_hook/mf/Core/xcc/1.0.lua",fullName="xcc/1.0",loadOrder=1,propT={},stackDepth=0,status="active",userName="xcc",wV="000000001.*zfinal",},},mpathA={"ProjectDIR/rt/load_hook/mf/Core",},systemBaseMPATH="ProjectDIR/rt/load_hook/mf/Core",}';
export _ModuleTable_;
===========================
step 3
lua ProjectDIR/src/lmod.in.lua shell --regression_testing list
===========================
MODULEPATH=ProjectDIR/rt/load_hook/mf/Core;
export MODULEPATH;
_ModuleTable_='_ModuleTable_={MTversion=3,depthT={},family={},mT={d={fn="ProjectDIR/rt/load_hook/mf/Core/d/2.0.lua",fullName="d/2.0",loadOrder=2,propT={},ref_count=1,stackDepth=1,status="active",userName="d",wV="000000002.*zfinal",},xcc={fn="ProjectDIR/rt/load_hook/mf/Core/xcc/1.0.lua",fullName="xcc/1.0",loadOrder=1,propT={},stackDepth=0,status="active",userName="xcc",wV="000000001.*zfinal",},},mpathA={"ProjectDIR/rt/load_hook/mf/Core",},systemBaseMPATH="ProjectDIR/rt/load_hook/mf/Core",}';
export _ModuleTable_;
===========================
step 4
lua ProjectDIR/src/lmod.in.lua shell --regression_testing unload xcc
===========================
unset D;
unset LOADEDMODULES;
MODULEPATH=ProjectDIR/rt/load_hook/mf/Core;
export MODULEPATH;
unset XCC;
unset _LMFILES_;
_ModuleTable_='_ModuleTable_={MTversion=3,depthT={},family={},mT={},mpathA={"ProjectDIR/rt/load_hook/mf/Core",},systemBaseMPATH="ProjectDIR/rt/load_hook/mf/Core",}';
export _ModuleTable_;
===========================
step 5
lua ProjectDIR/src/lmod.in.lua shell --regression_testing list
===========================
MODULEPATH=ProjectDIR/rt/load_hook/mf/Core;
export MODULEPATH;
_ModuleTable_='_ModuleTable_={MTversion=3,depthT={},family={},mT={},mpathA={"ProjectDIR/rt/load_hook/mf/Core",},systemBaseMPATH="ProjectDIR/rt/load_hook/mf/Core",}';
export _ModuleTable_;
2 changes: 1 addition & 1 deletion src/Hub.lua
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ function M.unload(self,mA)
mt = frameStk:mt()
mt:remove(sn)
--l_registerUnloaded(fullName, fn)
hook.apply("unload",{fn = mname:fn(), modFullName = mname:fullName()})
hook.apply("unload",{fn = mname:fn(), modFullName = mname:fullName(), mname = mname})
end
frameStk:pop()
a[#a+1] = status
Expand Down

0 comments on commit 1f416cc

Please sign in to comment.