Skip to content

Commit afb0fd4

Browse files
committed
add error checking for invalid values
Signed-off-by: Jade Abraham <[email protected]>
1 parent 2c8f653 commit afb0fd4

22 files changed

+86
-56
lines changed

util/chplenv/chpl_atomics.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import chpl_comm, chpl_compiler, chpl_platform, overrides
66
from compiler_utils import CompVersion, get_compiler_version, has_std_atomics
7-
from utils import error, memoize, warning
7+
from utils import error, memoize, warning, check_valid_var
88

99

1010
@memoize
@@ -21,7 +21,7 @@ def get(flag='target'):
2121
elif atomics_val == 'gasnet':
2222
error("CHPL_NETWORK_ATOMICS=gasnet is not supported")
2323
elif atomics_val not in valid:
24-
error("CHPL_NETWORK_ATOMICS must be one of " + ','.join(valid))
24+
check_valid_var("CHPL_NETWORK_ATOMICS", atomics_val, valid)
2525
elif atomics_val != 'none' and atomics_val != comm_val:
2626
error("CHPL_NETWORK_ATOMICS=%s is incompatible with CHPL_COMM=%s"
2727
% (atomics_val, comm_val))
@@ -82,6 +82,8 @@ def get(flag='target'):
8282
# we can't use intrinsics, fall back to locks
8383
if not atomics_val:
8484
atomics_val = 'locks'
85+
else:
86+
check_valid_var("CHPL_ATOMICS", atomics_val, ['cstdlib', 'intrinsics', 'locks'])
8587
else:
8688
error("Invalid flag: '{0}'".format(flag), ValueError)
8789

util/chplenv/chpl_aux_filesys.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44
from glob import glob
55

66
import overrides
7-
from utils import memoize
7+
from utils import memoize, check_valid_var
88

99

1010
@memoize
1111
def get():
1212
aux_fs = overrides.get('CHPL_AUX_FILESYS', 'none')
13+
check_valid_var('CHPL_AUX_FILESYS', aux_fs, ['none', 'lustre'])
1314
return aux_fs
1415

1516

util/chplenv/chpl_comm.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import sys
33

44
import chpl_platform, overrides
5-
from utils import memoize
5+
from utils import memoize, check_valid_var
66

77

88
@memoize
@@ -21,6 +21,8 @@ def get():
2121
comm_val = 'gasnet'
2222
else:
2323
comm_val = 'none'
24+
25+
check_valid_var("CHPL_COMM", comm_val, ("none", "gasnet", "ofi", "ugni"))
2426
return comm_val
2527

2628

util/chplenv/chpl_comm_ofi_oob.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import overrides
77
import third_party_utils
88

9-
from utils import error, memoize
9+
from utils import error, memoize, check_valid_var
1010

1111
@memoize
1212
def get():
@@ -16,8 +16,7 @@ def get():
1616

1717
oob_val = overrides.get('CHPL_COMM_OFI_OOB')
1818
if oob_val:
19-
if oob_val not in ('mpi', 'pmi2', 'sockets'):
20-
error("CHPL_COMM_OFI_OOB must be 'mpi', 'pmi2', or 'sockets'")
19+
check_valid_var("CHPL_COMM_OFI_OOB", oob_val, ("mpi", "pmi2", "sockets"))
2120
return oob_val
2221

2322
#

util/chplenv/chpl_comm_segment.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import sys
33

44
import chpl_comm, chpl_comm_substrate, chpl_platform, overrides
5-
from utils import memoize
5+
from utils import memoize, check_valid_var
66

77

88
@memoize
@@ -21,6 +21,8 @@ def get():
2121
segment_val = 'large'
2222
else:
2323
segment_val = 'everything'
24+
else:
25+
check_valid_var("CHPL_GASNET_SEGMENT", segment_val, ("none", "fast", "large", "everything"))
2426
else:
2527
segment_val = 'none'
2628
return segment_val

util/chplenv/chpl_comm_substrate.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import sys
33

44
import chpl_comm, chpl_platform, overrides
5-
from utils import memoize
5+
from utils import memoize, check_valid_var
66

77

88
@memoize
@@ -25,6 +25,8 @@ def get():
2525
substrate_val = 'udp'
2626
else:
2727
substrate_val = 'none'
28+
29+
check_valid_var("CHPL_COMM_SUBSTRATE", substrate_val, ("none", "aries", "ofi", "ibv", "udp", "mpi"))
2830
return substrate_val
2931

3032

util/chplenv/chpl_gmp.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import chpl_compiler, chpl_platform, overrides, third_party_utils
77
from chpl_home_utils import get_chpl_third_party
8-
from utils import memoize, warning, error
8+
from utils import memoize, warning, error, check_valid_var
99

1010
# returns True if CHPL_GMP was set by the user
1111
# (i.e. not inferred to be the default)
@@ -36,6 +36,7 @@ def get():
3636
else:
3737
gmp_val = 'none'
3838

39+
check_valid_var('CHPL_GMP', gmp_val, ['none', 'bundled', 'system'])
3940
return gmp_val
4041

4142
@memoize

util/chplenv/chpl_gpu.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import chpl_tasks
99
import chpl_home_utils
1010
import overrides
11-
from utils import error, warning, memoize, try_run_command, which, is_ver_in_range
11+
from utils import error, warning, memoize, try_run_command, which, is_ver_in_range, check_valid_var
1212

1313
def _validate_cuda_version():
1414
return _validate_cuda_version_impl()
@@ -234,7 +234,7 @@ def get():
234234
chpl_gpu_env = overrides.get("CHPL_GPU")
235235
if chpl_gpu_env:
236236
if chpl_gpu_env not in GPU_TYPES:
237-
error("Only {} supported for 'CHPL_GPU'".format(list(GPU_TYPES.keys())))
237+
check_valid_var("CHPL_GPU", chpl_gpu_env, list(GPU_TYPES.keys()))
238238
else:
239239
return chpl_gpu_env
240240
else:

util/chplenv/chpl_hwloc.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import optparse
66
import chpl_locale_model, chpl_tasks, chpl_platform, overrides, third_party_utils
77
import chpl_hwloc_pci
8-
from utils import error, memoize, warning, try_run_command, run_command
8+
from utils import error, memoize, warning, try_run_command, run_command, check_valid_var
99

1010

1111
@memoize
@@ -18,6 +18,7 @@ def get():
1818
else:
1919
hwloc_val = 'none'
2020

21+
check_valid_var('CHPL_HWLOC', hwloc_val, ['none', 'bundled', 'system'])
2122
return hwloc_val
2223

2324

util/chplenv/chpl_hwloc_pci.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import chpl_hwloc, chpl_comm, chpl_locale_model, chpl_gpu
1414
import overrides
1515

16-
from utils import error, memoize
16+
from utils import error, memoize, check_valid_var
1717

1818
@memoize
1919
def get():
@@ -33,6 +33,7 @@ def get():
3333
gpu_val = chpl_gpu.get()
3434
if gpu_val != 'cpu':
3535
pci_val = 'enable'
36+
check_valid_var('CHPL_HWLOC_PCI', pci_val, ['enable', 'disable'])
3637
return pci_val
3738

3839

util/chplenv/chpl_jemalloc.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import chpl_bin_subdir, chpl_compiler, chpl_mem, chpl_platform, overrides, third_party_utils
77
import homebrew_utils
8-
from utils import error, memoize, run_command, warning
8+
from utils import error, memoize, run_command, warning, check_valid_var
99

1010

1111
@memoize
@@ -56,6 +56,9 @@ def get(flag='target'):
5656
elif mem_val != 'jemalloc' and jemalloc_val != 'none':
5757
error("CHPL_JEMALLOC must be 'none' when CHPL_MEM is not jemalloc")
5858

59+
var_name = 'CHPL_{0}_JEMALLOC'.format(flag.upper())
60+
var_name = 'CHPL_JEMALLOC' if chpl_target_jemalloc is None else var_name
61+
check_valid_var(var_name, jemalloc_val, ["none", "bundled", "system"])
5962
return jemalloc_val
6063

6164

util/chplenv/chpl_launcher.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import sys
44

55
import chpl_comm, chpl_comm_substrate, chpl_platform, overrides
6-
from utils import which, error, memoize, warning
6+
from utils import which, error, memoize, warning, check_valid_var
77

88

99
def slurm_prefix(base_launcher, platform_val):
@@ -69,6 +69,13 @@ def get():
6969
if launcher_val is None:
7070
launcher_val = 'none'
7171

72+
gasnet_launchers = ["mpi", "ibv", "ucx", "ofi"]
73+
valid_values = ["none", "amudprun", "smp", "aprun", "slurm-srun"]
74+
valid_values.extend(["lsf-gasnetrun_ibv", "mpirun", "mpirun4ofi", "pals", "pbs-aprun", "pbs-gasnetrun_ibv"])
75+
valid_values.extend(["gasnetrun_{}".format(l) for l in gasnet_launchers])
76+
valid_values.extend(["slurm-gasnetrun_{}".format(l) for l in gasnet_launchers])
77+
check_valid_var("CHPL_LAUNCHER", launcher_val, valid_values)
78+
7279
return launcher_val
7380

7481

util/chplenv/chpl_lib_pic.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@
33

44
import overrides
55
import chpl_platform
6-
from utils import memoize
6+
from utils import memoize, check_valid_var
77

88
@memoize
99
def get():
10-
lib_pic_val = overrides.get('CHPL_LIB_PIC')
11-
if not lib_pic_val:
12-
lib_pic_val = 'none'
13-
10+
lib_pic_val = overrides.get('CHPL_LIB_PIC', 'none')
11+
check_valid_var("CHPL_LIB_PIC", lib_pic_val, ["none", "pic"])
1412
return lib_pic_val
1513

1614

util/chplenv/chpl_libfabric.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import chpl_comm, chpl_comm_debug, chpl_launcher, chpl_platform, chpl_comm_ofi_oob
77
import overrides, third_party_utils
88

9-
from utils import error, memoize, try_run_command, warning
9+
from utils import error, memoize, try_run_command, warning, check_valid_var
1010

1111
@memoize
1212
def get():
@@ -23,6 +23,8 @@ def get():
2323
error("CHPL_LIBFABRIC must not be 'none' when CHPL_COMM is ofi")
2424
elif platform_val == 'hpe-cray-ex' and libfabric_val != 'system':
2525
warning('CHPL_LIBFABRIC!=system is discouraged on HPE Cray EX')
26+
27+
check_valid_var('CHPL_LIBFABRIC', libfabric_val, ['bundled', 'system'])
2628
else:
2729
libfabric_val = 'none'
2830

util/chplenv/chpl_llvm.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from chpl_home_utils import get_chpl_third_party, get_chpl_home
1010
import chpl_gpu
1111
import homebrew_utils
12-
from utils import which, memoize, error, run_command, try_run_command, warning
12+
from utils import which, memoize, error, run_command, try_run_command, warning, check_valid_var
1313
from collections import defaultdict
1414

1515
# returns a tuple of supported major LLVM versions as strings
@@ -641,6 +641,9 @@ def has_compatible_installed_llvm():
641641
@memoize
642642
def get():
643643
llvm_val = overrides.get('CHPL_LLVM')
644+
if llvm_val:
645+
check_valid_var("CHPL_LLVM", llvm_val, ['none', 'bundled', 'system'])
646+
644647
if not llvm_val:
645648
llvm_val = 'unset'
646649

util/chplenv/chpl_locale_model.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,13 @@
22
import sys
33

44
import overrides
5-
from utils import memoize, error
5+
from utils import memoize, error, check_valid_var
66

77

88
@memoize
99
def get():
1010
locale_model_val = overrides.get('CHPL_LOCALE_MODEL', 'flat')
11-
12-
if locale_model_val not in ['flat', 'gpu']:
13-
error('{} is not a valid value for CHPL_LOCALE_MODEL. '
14-
'It can only be "flat" or "gpu".'.format(locale_model_val))
15-
11+
check_valid_var("CHPL_LOCALE_MODEL", locale_model_val, ["flat", "shared"])
1612
return locale_model_val
1713

1814

util/chplenv/chpl_mem.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import sys
44

55
import chpl_platform, overrides
6-
from utils import error, memoize, warning
6+
from utils import error, memoize, warning, check_valid_var
77

88
@memoize
99
def get(flag='host'):
@@ -35,6 +35,10 @@ def get(flag='host'):
3535
mem_val = 'jemalloc'
3636
else:
3737
error("Invalid flag: '{0}'".format(flag), ValueError)
38+
39+
var_name = 'CHPL_{0}_MEM'.format(flag.upper())
40+
var_name = 'CHPL_MEM' if chpl_target_mem is None else var_name
41+
check_valid_var(var_name, mem_val, ["cstdlib", "jemalloc"])
3842
return mem_val
3943

4044

util/chplenv/chpl_re2.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import chpl_compiler, chpl_platform, overrides, third_party_utils
66
from chpl_home_utils import get_chpl_third_party
7-
from utils import memoize, warning, error
7+
from utils import memoize, warning, error, check_valid_var
88

99

1010
# returns True if CHPL_RE2 was set by the user
@@ -21,14 +21,14 @@ def is_overridden():
2121
@memoize
2222
def get():
2323
re2 = overrides.get('CHPL_RE2')
24-
if re2 == "system":
25-
error("CHPL_RE2=system is not supported. Please use CHPL_RE2=bundled or CHL_RE2=none instead.")
2624

2725
if not re2:
2826
re2_header = os.path.join(get_chpl_third_party(), 're2',
2927
'install', get_uniq_cfg_path(),
3028
'include', 're2', 're2.h')
3129
re2 = 'bundled' if os.path.exists(re2_header) else 'none'
30+
31+
check_valid_var("CHPL_RE2", re2, ["none", "bundled"])
3232
return re2
3333

3434

util/chplenv/chpl_tasks.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import chpl_arch, chpl_compiler, chpl_platform, overrides
55
from chpl_home_utils import using_chapel_module
66
from compiler_utils import CompVersion
7-
from utils import memoize
7+
from utils import memoize, check_valid_var
88

99

1010
@memoize
@@ -23,6 +23,8 @@ def get():
2323
tasks_val = 'fifo'
2424
else:
2525
tasks_val = 'qthreads'
26+
27+
check_valid_var("CHPL_TASKS", tasks_val, ("fifo", "qthreads"))
2628
return tasks_val
2729

2830

util/chplenv/chpl_timers.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
import sys
33

44
import overrides
5-
from utils import memoize
5+
from utils import memoize, check_valid_var
66

77

88
@memoize
99
def get():
1010
timers_val = overrides.get('CHPL_TIMERS', 'generic')
11+
check_valid_var("CHPL_TIMERS", timers_val, ["generic"])
1112
return timers_val
1213

1314

0 commit comments

Comments
 (0)