blob: 99441e9ea5ed813d2358849fe7bd23dfb221f6bc [file] [log] [blame]
Javi Merinoaace7c02015-08-10 14:10:47 +01001# Copyright 2015-2015 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
Javi Merinoc26e1c72014-04-08 16:39:01 +010022
23TESTS_DIRECTORY = os.path.dirname(os.path.realpath(__file__))
Javi Merinoc26e1c72014-04-08 16:39:01 +010024
Javi Merino3cb3d4f2015-02-24 19:01:44 +000025def trace_cmd_installed():
26 """Return true if trace-cmd is installed, false otherwise"""
27 with open(os.devnull) as devnull:
28 try:
29 subprocess.check_call(["trace-cmd", "options"], stdout=devnull)
30 except OSError:
31 return False
32
33 return True
34
Javi Merinoc26e1c72014-04-08 16:39:01 +010035class SetupDirectory(unittest.TestCase):
36 def __init__(self, files_to_copy, *args, **kwargs):
37 self.files_to_copy = files_to_copy
38 super(SetupDirectory, self).__init__(*args, **kwargs)
39
40 def setUp(self):
Javi Merino9e9ed7f2014-04-08 16:46:42 +010041 self.previous_dir = os.getcwd()
42
Javi Merinoc26e1c72014-04-08 16:39:01 +010043 self.out_dir = tempfile.mkdtemp()
44 os.chdir(self.out_dir)
45
Javi Merino10f90ef2014-12-16 14:51:50 +000046 for src_fname, dst_fname in self.files_to_copy:
47 src_fname = os.path.join(TESTS_DIRECTORY, src_fname)
48 shutil.copy(src_fname, os.path.join(self.out_dir, dst_fname))
Javi Merinoc26e1c72014-04-08 16:39:01 +010049
50 def tearDown(self):
Javi Merino9e9ed7f2014-04-08 16:46:42 +010051 os.chdir(self.previous_dir)
Javi Merinoc26e1c72014-04-08 16:39:01 +010052 shutil.rmtree(self.out_dir)