Home | History | Annotate | Download | only in tests
      1 #    Copyright 2015-2017 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 
     17 import unittest
     18 import os
     19 import shutil
     20 import subprocess
     21 import tempfile
     22 import trappy
     23 from trappy.ftrace import GenericFTrace
     24 
     25 TESTS_DIRECTORY = os.path.dirname(os.path.realpath(__file__))
     26 
     27 def 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 
     37 class 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)
     41         GenericFTrace.disable_cache = True
     42 
     43     def setUp(self):
     44         self.previous_dir = os.getcwd()
     45 
     46         self.out_dir = tempfile.mkdtemp()
     47         os.chdir(self.out_dir)
     48 
     49         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))
     52 
     53     def tearDown(self):
     54         os.chdir(self.previous_dir)
     55         shutil.rmtree(self.out_dir)
     56