diff options
author | Igor Murashkin <iam@google.com> | 2019-06-18 16:03:20 -0700 |
---|---|---|
committer | Igor Murashkin <iam@google.com> | 2019-06-26 21:19:27 +0000 |
commit | 06d017ee1913b20d5ebbb9c31e4c6061d993067e (patch) | |
tree | 86bcd6facf165e7b70e5900e05f41c70a0dd2df1 /startop/scripts/iorap/lib/inode2filename_test.py | |
parent | 42439214ebdf1b6de12683790ea325164fda37fc (diff) |
startop: Add iorap compiler written in python
Compiler will be used for experimentation purpose since it's both easier
to develop in python and it accepts ftrace, making it very easy to write
complicated-experimental changes that we aren't sure are worth it yet
for the on-device C++/perfetto compiler.
This 'new' compiler accepts ftrace/systrace files as input,
then generates an in-memory sqlite3 database (using the trace_analyzer
source code), and finally code-generates a TraceFile.pb protobuf.
(Also refactor trace_analyzer into a library, and update it to
parse systrace.html files)
Limitations: currently does not accept perfetto_trace.pb files due to
'ofs' fields missing (see bug#135555191)
Test: py.test-3 frameworks/base/startop/scripts
Test: ./compiler.py -i tmp_sargo/textcache -t tmp_sargo/trace.html -o tmp/output.pb
Test: ./compiler.py -i tmp_sargo/textcache -t tmp_sargo/trace.html -o tmp/output.pb -f '^/data'
Test: ./trace_analyzer music_run.trace tmp_dbs/12345.db
Bug: 135557978
Bug: 134789969
Change-Id: Ic8295900ee9e634b4cfd8cf99b671ae08d2ea4f7
Diffstat (limited to 'startop/scripts/iorap/lib/inode2filename_test.py')
-rwxr-xr-x | startop/scripts/iorap/lib/inode2filename_test.py | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/startop/scripts/iorap/lib/inode2filename_test.py b/startop/scripts/iorap/lib/inode2filename_test.py new file mode 100755 index 000000000000..1224c61da641 --- /dev/null +++ b/startop/scripts/iorap/lib/inode2filename_test.py @@ -0,0 +1,83 @@ +#!/usr/bin/env python3 +# +# Copyright 2019, The Android Open Source Project +# +# 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. +# + +""" +Unit tests for inode2filename module. + +Install: + $> sudo apt-get install python3-pytest ## OR + $> pip install -U pytest +See also https://docs.pytest.org/en/latest/getting-started.html + +Usage: + $> ./inode2filename_test.py + $> pytest inode2filename_test.py + $> python -m pytest inode2filename_test.py + +See also https://docs.pytest.org/en/latest/usage.html +""" + +# global imports +from contextlib import contextmanager +import io +import shlex +import sys +import typing + +# pip imports +import pytest + +# local imports +from inode2filename import * + +def create_inode2filename(*contents): + buf = io.StringIO() + + for c in contents: + buf.write(c) + buf.write("\n") + + buf.seek(0) + + i2f = Inode2Filename(buf) + + buf.close() + + return i2f + +def test_inode2filename(): + a = create_inode2filename("") + assert len(a) == 0 + assert a.resolve(1, 2) == None + + a = create_inode2filename("1 2 3 foo.bar") + assert len(a) == 1 + assert a.resolve(1, 2) == "foo.bar" + assert a.resolve(4, 5) == None + + a = create_inode2filename("1 2 3 foo.bar", "4 5 6 bar.baz") + assert len(a) == 2 + assert a.resolve(1, 2) == "foo.bar" + assert a.resolve(4, 5) == "bar.baz" + + a = create_inode2filename("1567d 8910 -1 /a/b/c/", "4 5 6 bar.baz") + assert len(a) == 2 + assert a.resolve(1567, 8910) == "/a/b/c/" + assert a.resolve(4, 5) == "bar.baz" + +if __name__ == '__main__': + pytest.main() |