diff options
author | Javi Merino <javi.merino@arm.com> | 2016-07-13 17:05:21 +0100 |
---|---|---|
committer | Javi Merino <javi.merino@arm.com> | 2016-07-13 17:11:25 +0100 |
commit | e467a1eb564c59de66673a9a3b5795c4b16f4ce8 (patch) | |
tree | 802cd17ddfcb03eac7a54da68e4af8ae32d6a052 | |
parent | f9054d7f36c9c892f85aad1f0ff79aa3e2f6ce55 (diff) | |
download | bart-e467a1eb564c59de66673a9a3b5795c4b16f4ce8.tar.gz |
sched: raise a ValueError in get_pids_for_process() if the trace doesn't contain sched_switch events
-rw-r--r-- | bart/sched/functions.py | 3 | ||||
-rw-r--r-- | tests/test_sched_functions.py | 39 |
2 files changed, 42 insertions, 0 deletions
diff --git a/bart/sched/functions.py b/bart/sched/functions.py index 546e8fb..8a3d7a0 100644 --- a/bart/sched/functions.py +++ b/bart/sched/functions.py @@ -436,6 +436,9 @@ def get_pids_for_process(ftrace, execname, cls=None): df = ftrace.sched_switch.data_frame except AttributeError: raise ValueError("SchedSwitch event not found in ftrace") + + if len(df) == 0: + raise ValueError("SchedSwitch event not found in ftrace") else: event = getattr(ftrace, cls.name) df = event.data_frame diff --git a/tests/test_sched_functions.py b/tests/test_sched_functions.py new file mode 100644 index 0000000..164df3c --- /dev/null +++ b/tests/test_sched_functions.py @@ -0,0 +1,39 @@ +# Copyright 2016-2016 ARM Limited +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +import trappy + +import utils_tests + +class TestSchedFunctions(utils_tests.SetupDirectory): + def __init__(self, *args, **kwargs): + super(TestSchedFunctions, self).__init__([], *args, **kwargs) + + def test_get_pids_for_processes_no_sched_switch(self): + """get_pids_for_processes() raises an exception if the trace doesn't have a sched_switch event""" + from bart.sched.functions import get_pids_for_process + + trace_file = "trace.txt" + raw_trace_file = "trace.raw.txt" + + with open(trace_file, "w") as fout: + fout.write("") + + with open(raw_trace_file, "w") as fout: + fout.write("") + + trace = trappy.FTrace(trace_file) + with self.assertRaises(ValueError): + get_pids_for_process(trace, "foo") |