• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#    Copyright 2015-2016 ARM Limited
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#     http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14#
15
16
17import unittest
18import os
19import shutil
20import subprocess
21import tempfile
22
23TESTS_DIRECTORY = os.path.dirname(os.path.realpath(__file__))
24
25
26def trace_cmd_installed():
27    """Return true if trace-cmd is installed, false otherwise"""
28    with open(os.devnull) as devnull:
29        try:
30            subprocess.check_call(["trace-cmd", "options"], stdout=devnull)
31        except OSError:
32            return False
33
34    return True
35
36class SetupDirectory(unittest.TestCase):
37
38    def __init__(self, files_to_copy, *args, **kwargs):
39        self.files_to_copy = files_to_copy
40        super(SetupDirectory, self).__init__(*args, **kwargs)
41
42    def setUp(self):
43        self.previous_dir = os.getcwd()
44
45        self.out_dir = tempfile.mkdtemp()
46        os.chdir(self.out_dir)
47
48        for src_fname, dst_fname in self.files_to_copy:
49            src_fname = os.path.join(TESTS_DIRECTORY, src_fname)
50            shutil.copy(src_fname, os.path.join(self.out_dir, dst_fname))
51
52    def tearDown(self):
53        os.chdir(self.previous_dir)
54        shutil.rmtree(self.out_dir)
55
56
57class TestBART(SetupDirectory):
58
59    def __init__(self, *args, **kwargs):
60        super(TestBART, self).__init__(
61            [
62                ("./trace.txt", "trace.txt"),
63                ("./trace.raw.txt", "trace.raw.txt")
64            ],
65            *args,
66            **kwargs)
67