diff --git a/tensorflow/python/kernel_tests/benchmark_test.py b/tensorflow/python/kernel_tests/benchmark_test.py index f4548baddaa..3e64f9d5c15 100644 --- a/tensorflow/python/kernel_tests/benchmark_test.py +++ b/tensorflow/python/kernel_tests/benchmark_test.py @@ -96,7 +96,8 @@ class BenchmarkTest(test.TestCase): self.assertFalse(_ran_somebenchmark_but_shouldnt[0]) # Run other benchmarks, but this wont run the one we care about - benchmark._run_benchmarks("unrelated") + with self.assertRaises(ValueError): + benchmark._run_benchmarks("unrelated") # Validate that SomeBenchmark has not run yet self.assertFalse(_ran_somebenchmark_1[0]) diff --git a/tensorflow/python/platform/benchmark.py b/tensorflow/python/platform/benchmark.py index dcfa4d1ef1a..0f328b2df5f 100644 --- a/tensorflow/python/platform/benchmark.py +++ b/tensorflow/python/platform/benchmark.py @@ -430,9 +430,13 @@ def _run_benchmarks(regex): Args: regex: The string regular expression to match Benchmark classes against. + + Raises: + ValueError: If no benchmarks were selected by the input regex. """ registry = list(GLOBAL_BENCHMARK_REGISTRY) + selected_benchmarks = [] # Match benchmarks in registry against regex for benchmark in registry: benchmark_name = "%s.%s" % (benchmark.__module__, benchmark.__name__) @@ -448,6 +452,7 @@ def _run_benchmarks(regex): continue full_benchmark_name = "%s.%s" % (benchmark_name, attr) if regex == "all" or re.search(regex, full_benchmark_name): + selected_benchmarks.append(full_benchmark_name) # Instantiate the class if it hasn't been instantiated benchmark_instance = benchmark_instance or benchmark() # Get the method tied to the class @@ -455,6 +460,9 @@ def _run_benchmarks(regex): # Call the instance method instance_benchmark_fn() + if not selected_benchmarks: + raise ValueError("No benchmarks matched the pattern: '{}'".format(regex)) + def benchmarks_main(true_main, argv=None): """Run benchmarks as declared in argv.