Skip to content

Commit

Permalink
pushenv/popenv complete, added path functions. added mode_select test
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcawood committed Jan 3, 2025
1 parent 3c72b25 commit 18d238e
Show file tree
Hide file tree
Showing 13 changed files with 590 additions and 47 deletions.
57 changes: 57 additions & 0 deletions rt/mode_select/err.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
===========================
step 1
lua ProjectDIR/src/lmod.in.lua shell --regression_testing load env_test
===========================
===========================
step 2
lua ProjectDIR/src/lmod.in.lua shell --regression_testing list
===========================
Currently Loaded Modules:
1) env_test/1.0
===========================
step 3
lua ProjectDIR/src/lmod.in.lua shell --regression_testing unload env_test
===========================
===========================
step 4
lua ProjectDIR/src/lmod.in.lua shell --regression_testing list
===========================
No modules loaded
===========================
step 5
lua ProjectDIR/src/lmod.in.lua shell --regression_testing load path_test
===========================
===========================
step 6
lua ProjectDIR/src/lmod.in.lua shell --regression_testing list
===========================
Currently Loaded Modules:
1) path_test/1.0
===========================
step 7
lua ProjectDIR/src/lmod.in.lua shell --regression_testing unload path_test
===========================
===========================
step 8
lua ProjectDIR/src/lmod.in.lua shell --regression_testing list
===========================
No modules loaded
===========================
step 9
lua ProjectDIR/src/lmod.in.lua shell --regression_testing load mixed_test
===========================
===========================
step 10
lua ProjectDIR/src/lmod.in.lua shell --regression_testing list
===========================
Currently Loaded Modules:
1) mixed_test/1.0
===========================
step 11
lua ProjectDIR/src/lmod.in.lua shell --regression_testing unload mixed_test
===========================
===========================
step 12
lua ProjectDIR/src/lmod.in.lua shell --regression_testing list
===========================
No modules loaded
2 changes: 2 additions & 0 deletions rt/mode_select/mf/Core/dep_both/1.0.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- Dependency module for both modes
setenv("DEP_BOTH_LOADED", "yes")
2 changes: 2 additions & 0 deletions rt/mode_select/mf/Core/dep_load/1.0.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- Dependency module for load mode
setenv("DEP_LOAD_LOADED", "yes")
2 changes: 2 additions & 0 deletions rt/mode_select/mf/Core/dep_unload/1.0.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- Dependency module for unload mode
setenv("DEP_UNLOAD_LOADED", "yes")
19 changes: 19 additions & 0 deletions rt/mode_select/mf/Core/env_test/1.0.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
-- Test module for mode-specific environment operations

-- Test setenv with mode
setenv{"TEST_VAR_LOAD", "load_only", mode={"load"}}
setenv{"TEST_VAR_UNLOAD", "unload_only", mode={"unload"}}
setenv{"TEST_VAR_BOTH", "both_modes", mode={"load", "unload"}}
setenv("TEST_VAR_NORMAL", "no_mode") -- Normal setenv for comparison

-- Test pushenv with mode
pushenv{"STACK_VAR_LOAD", "load_value", mode={"load"}}
pushenv{"STACK_VAR_UNLOAD", "unload_value", mode={"unload"}}
pushenv{"STACK_VAR_BOTH", "both_value", mode={"load", "unload"}}
pushenv("STACK_VAR_NORMAL", "normal_value") -- Normal pushenv for comparison

-- Test unsetenv with mode
unsetenv{"UNSET_VAR_LOAD", mode={"load"}}
unsetenv{"UNSET_VAR_UNLOAD", mode={"unload"}}
unsetenv{"UNSET_VAR_BOTH", mode={"load", "unload"}}
unsetenv("UNSET_VAR_NORMAL") -- Normal unsetenv for comparison
9 changes: 9 additions & 0 deletions rt/mode_select/mf/Core/load_test/1.0.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-- Test module for mode-specific load operations

-- Test load with mode
load{"dep_load", mode={"load"}} -- Should only load during load
load{"dep_unload", mode={"unload"}} -- Should only load during unload
load{"dep_both", mode={"load", "unload"}} -- Should load during both operations

-- Set environment variables to track what happened
setenv("LOAD_TEST_LOADED", "yes")
25 changes: 25 additions & 0 deletions rt/mode_select/mf/Core/mixed_test/1.0.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
-- Test module for mixed mode and non-mode operations

-- Test environment and path operations mixed together
setenv{"MIXED_ENV_LOAD", "env_load", mode={"load"}}
prepend_path{"MIXED_PATH", "/mixed/bin/load", mode={"load"}}

setenv{"MIXED_ENV_UNLOAD", "env_unload", mode={"unload"}}
append_path{"MIXED_PATH", "/mixed/bin/unload", mode={"unload"}}

-- Test normal operations mixed with mode operations
setenv("MIXED_NORMAL_ENV", "normal_env")
prepend_path{"MIXED_PATH", "/mixed/bin/both", mode={"load", "unload"}}

-- Test pushenv with path operations
pushenv{"MIXED_STACK", "stack_load", mode={"load"}}
append_path("MIXED_LIB", "/mixed/lib/normal")

-- Test complex combinations
setenv{"MIXED_COMPLEX", "complex_load", mode={"load"}}
prepend_path{"MIXED_COMPLEX_PATH", "/complex/bin", delim=";", priority=100, mode={"load"}}
pushenv{"MIXED_COMPLEX_STACK", "complex_both", mode={"load", "unload"}}

-- Test error cases
setenv{"MIXED_ERROR", "error_value", mode={}} -- Empty mode table
prepend_path{"MIXED_ERROR_PATH", "/error/bin", mode={"invalid_mode"}} -- Invalid mode
23 changes: 23 additions & 0 deletions rt/mode_select/mf/Core/path_test/1.0.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
-- Test module for mode-specific path operations

-- Test prepend_path with mode
prepend_path{"PATH", "/test/bin/load", mode={"load"}}
prepend_path{"PATH", "/test/bin/unload", mode={"unload"}}
prepend_path{"PATH", "/test/bin/both", mode={"load", "unload"}}
prepend_path("PATH", "/test/bin/normal") -- Normal prepend for comparison

-- Test append_path with mode
append_path{"LD_LIBRARY_PATH", "/test/lib/load", mode={"load"}}
append_path{"LD_LIBRARY_PATH", "/test/lib/unload", mode={"unload"}}
append_path{"LD_LIBRARY_PATH", "/test/lib/both", mode={"load", "unload"}}
append_path("LD_LIBRARY_PATH", "/test/lib/normal") -- Normal append for comparison

-- Test remove_path with mode
remove_path{"REMOVE_PATH", "/old/bin/load", mode={"load"}}
remove_path{"REMOVE_PATH", "/old/bin/unload", mode={"unload"}}
remove_path{"REMOVE_PATH", "/old/bin/both", mode={"load", "unload"}}
remove_path("REMOVE_PATH", "/old/bin/normal") -- Normal remove for comparison

-- Test with delimiters and priorities
prepend_path{"CUSTOM_PATH", "/custom/path", delim=";", priority=100, mode={"load"}}
append_path{"CUSTOM_LIB", "/custom/lib", delim=":", priority=50, mode={"unload"}}
84 changes: 84 additions & 0 deletions rt/mode_select/mode_select.tdesc
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
-- -*- lua -*-
local testName = "mode_select"

testdescript = {
owner = "mcawood",
product = "modules",
description = [[
Test mode-specific functionality for various Lmod functions:
- Environment operations (setenv, pushenv, unsetenv)
- Path operations (prepend_path, append_path, remove_path)
Tests include:
1. Basic mode-specific operations
2. Mixed mode and non-mode operations
3. Error cases and edge conditions
]],
keywords = {testName},

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

runScript = [[
. $(projectDir)/rt/common_funcs.sh
unsetMT
initStdEnvVars
MODULEPATH_ROOT=$(testDir)/mf; export MODULEPATH_ROOT
MODULEPATH=$(testDir)/mf/Core; export MODULEPATH
remove_generated_lmod_files
cp $(projectDir)/init/lmodrc.lua .lmodrc.lua
mkdir -p $HOME/.cache/lmod
buildSpiderT $MODULEPATH > $HOME/.cache/lmod/spiderT.lua
# Test Environment Variable Operations
runLmod load env_test # 1 (Test mode-specific setenv)
runLmod list # 2 (Verify environment variables)
runLmod unload env_test # 3 (Test unload behavior)
runLmod list # 4 (Verify cleanup)
# Test Path Operations
runLmod load path_test # 5 (Test mode-specific path operations)
runLmod list # 6 (Verify path modifications)
runLmod unload path_test # 7 (Test path cleanup)
runLmod list # 8 (Verify path restoration)
# Test Mixed Operations
runLmod load mixed_test # 9 (Test mixed mode and non-mode operations)
runLmod list # 10 (Verify mixed state)
runLmod unload mixed_test # 11 (Test mixed cleanup)
runLmod list # 12 (Verify final state)
# Test Load/Unload Operations
runLmod load load_test # 13 (Test mode-specific module loading)
runLmod list # 14 (Verify loaded modules)
runLmod unload load_test # 15 (Test mode-specific module unloading)
runLmod list # 16 (Verify final state)
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'},
},
}
Loading

0 comments on commit 18d238e

Please sign in to comment.