diff --git a/FWCore/Framework/test/BuildFile.xml b/FWCore/Framework/test/BuildFile.xml index 9b9d27f444767..daef0d52b86dd 100644 --- a/FWCore/Framework/test/BuildFile.xml +++ b/FWCore/Framework/test/BuildFile.xml @@ -419,3 +419,8 @@ + + + + + diff --git a/FWCore/Framework/test/run_wrongOptionsType.sh b/FWCore/Framework/test/run_wrongOptionsType.sh new file mode 100755 index 0000000000000..dffe4a34c84b5 --- /dev/null +++ b/FWCore/Framework/test/run_wrongOptionsType.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +NAME=$1 +VALUE=$2 + +function die { echo $1: status $2 ; echo === Log file === ; cat ${3:-/dev/null} ; echo === End log file === ; exit $2; } + +cmsRun ${SCRAM_TEST_PATH}/test_wrongOptionsType_cfg.py -- --name=${NAME} --value="$VALUE" > ${NAME}.log 2>&1 && die "cmsRun for ${NAME} succeeded, should have failed" 1 ${NAME}.log +grep -E "(The type in the configuration is incorrect)|(ValueError type of .* is expected to be .* but declared as)" ${NAME}.log > /dev/null || die "cmsRun for ${NAME} failed for other reason than incorrect configuration type" $? ${NAME}.log + diff --git a/FWCore/Framework/test/test_wrongOptionsType_cfg.py b/FWCore/Framework/test/test_wrongOptionsType_cfg.py new file mode 100644 index 0000000000000..e2bcaad4c6134 --- /dev/null +++ b/FWCore/Framework/test/test_wrongOptionsType_cfg.py @@ -0,0 +1,21 @@ +import FWCore.ParameterSet.Config as cms + +import argparse +import sys + +parser = argparse.ArgumentParser(prog=sys.argv[0], description='Test wrong process.options parameter types') + +parser.add_argument("--name", help="Name of parameter", type=str) +parser.add_argument("--value", help="Value of the parameter", type=str) + +argv = sys.argv[:] +if '--' in argv: + argv.remove("--") +args, unknown = parser.parse_known_args(argv) + +process = cms.Process("TEST") +process.source = cms.Source("EmptySource") + +process.maxEvents.input = 2 + +setattr(process.options, args.name, eval(str(args.value))) diff --git a/FWCore/ParameterSet/src/ThreadsInfo.cc b/FWCore/ParameterSet/src/ThreadsInfo.cc index a8a44adc55689..23b80b45f8590 100644 --- a/FWCore/ParameterSet/src/ThreadsInfo.cc +++ b/FWCore/ParameterSet/src/ThreadsInfo.cc @@ -12,12 +12,15 @@ namespace edm { // default values ThreadsInfo threadsInfo; - if (pset.existsAs("options", false)) { + // Note: it is important to not check the type or trackedness in + // exists() call to ensure that the getUntrackedParameter() calls + // will fail if the parameters have an incorrect type + if (pset.exists("options")) { auto const& ops = pset.getUntrackedParameterSet("options"); - if (ops.existsAs("numberOfThreads", false)) { + if (ops.exists("numberOfThreads")) { threadsInfo.nThreads_ = ops.getUntrackedParameter("numberOfThreads"); } - if (ops.existsAs("sizeOfStackForThreadsInKB", false)) { + if (ops.exists("sizeOfStackForThreadsInKB")) { threadsInfo.stackSize_ = ops.getUntrackedParameter("sizeOfStackForThreadsInKB"); } } @@ -26,7 +29,7 @@ namespace edm { void setThreadOptions(ThreadsInfo const& threadsInfo, edm::ParameterSet& pset) { edm::ParameterSet newOp; - if (pset.existsAs("options", false)) { + if (pset.exists("options")) { newOp = pset.getUntrackedParameterSet("options"); } newOp.addUntrackedParameter("numberOfThreads", threadsInfo.nThreads_);