blob: e13b8689b3195c137b6fff703c6d0386726b4677 [file] [log] [blame]
Brendan Jackmane81fdcb2017-01-04 17:10:29 +00001# Copyright 2015-2017 ARM Limited
Javi Merino034e7cc2015-04-22 18:39:21 +01002#
Javi Merinoaace7c02015-08-10 14:10:47 +01003# 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
Javi Merinoc26e1c72014-04-08 16:39:01 +010016
17import unittest
Javi Merino67958b12014-04-10 16:22:13 +010018import os
Javi Merino3cb3d4f2015-02-24 19:01:44 +000019import shutil
20import subprocess
21import tempfile
Joel Fernandesa19ff252017-05-15 03:02:31 -070022import trappy
23from trappy.ftrace import GenericFTrace
Javi Merinoc26e1c72014-04-08 16:39:01 +010024
25TESTS_DIRECTORY = os.path.dirname(os.path.realpath(__file__))
Javi Merinoc26e1c72014-04-08 16:39:01 +010026
Javi Merino3cb3d4f2015-02-24 19:01:44 +000027def trace_cmd_installed():
28 """Return true if trace-cmd is installed, false otherwise"""
29 with open(os.devnull) as devnull:
30 try:
31 subprocess.check_call(["trace-cmd", "options"], stdout=devnull)
32 except OSError:
33 return False
34
35 return True
36
Javi Merinoc26e1c72014-04-08 16:39:01 +010037class SetupDirectory(unittest.TestCase):
38 def __init__(self, files_to_copy, *args, **kwargs):
39 self.files_to_copy = files_to_copy
40 super(SetupDirectory, self).__init__(*args, **kwargs)
Joel Fernandesa19ff252017-05-15 03:02:31 -070041 GenericFTrace.disable_cache = True
Javi Merinoc26e1c72014-04-08 16:39:01 +010042
43 def setUp(self):
Javi Merino9e9ed7f2014-04-08 16:46:42 +010044 self.previous_dir = os.getcwd()
45
Javi Merinoc26e1c72014-04-08 16:39:01 +010046 self.out_dir = tempfile.mkdtemp()
47 os.chdir(self.out_dir)
48
Javi Merino10f90ef2014-12-16 14:51:50 +000049 for src_fname, dst_fname in self.files_to_copy:
50 src_fname = os.path.join(TESTS_DIRECTORY, src_fname)
51 shutil.copy(src_fname, os.path.join(self.out_dir, dst_fname))
Javi Merinoc26e1c72014-04-08 16:39:01 +010052
53 def tearDown(self):
Javi Merino9e9ed7f2014-04-08 16:46:42 +010054 os.chdir(self.previous_dir)
Javi Merinoc26e1c72014-04-08 16:39:01 +010055 shutil.rmtree(self.out_dir)