Brendan Jackman | e81fdcb | 2017-01-04 17:10:29 +0000 | [diff] [blame] | 1 | # Copyright 2015-2017 ARM Limited |
Javi Merino | 034e7cc | 2015-04-22 18:39:21 +0100 | [diff] [blame] | 2 | # |
Javi Merino | aace7c0 | 2015-08-10 14:10:47 +0100 | [diff] [blame] | 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 | |
Javi Merino | c26e1c7 | 2014-04-08 16:39:01 +0100 | [diff] [blame] | 16 | |
| 17 | import unittest |
Javi Merino | 67958b1 | 2014-04-10 16:22:13 +0100 | [diff] [blame] | 18 | import os |
Javi Merino | 3cb3d4f | 2015-02-24 19:01:44 +0000 | [diff] [blame] | 19 | import shutil |
| 20 | import subprocess |
| 21 | import tempfile |
Joel Fernandes | a19ff25 | 2017-05-15 03:02:31 -0700 | [diff] [blame] | 22 | import trappy |
| 23 | from trappy.ftrace import GenericFTrace |
Javi Merino | c26e1c7 | 2014-04-08 16:39:01 +0100 | [diff] [blame] | 24 | |
| 25 | TESTS_DIRECTORY = os.path.dirname(os.path.realpath(__file__)) |
Javi Merino | c26e1c7 | 2014-04-08 16:39:01 +0100 | [diff] [blame] | 26 | |
Javi Merino | 3cb3d4f | 2015-02-24 19:01:44 +0000 | [diff] [blame] | 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 | |
Javi Merino | c26e1c7 | 2014-04-08 16:39:01 +0100 | [diff] [blame] | 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) |
Joel Fernandes | a19ff25 | 2017-05-15 03:02:31 -0700 | [diff] [blame] | 41 | GenericFTrace.disable_cache = True |
Javi Merino | c26e1c7 | 2014-04-08 16:39:01 +0100 | [diff] [blame] | 42 | |
| 43 | def setUp(self): |
Javi Merino | 9e9ed7f | 2014-04-08 16:46:42 +0100 | [diff] [blame] | 44 | self.previous_dir = os.getcwd() |
| 45 | |
Javi Merino | c26e1c7 | 2014-04-08 16:39:01 +0100 | [diff] [blame] | 46 | self.out_dir = tempfile.mkdtemp() |
| 47 | os.chdir(self.out_dir) |
| 48 | |
Javi Merino | 10f90ef | 2014-12-16 14:51:50 +0000 | [diff] [blame] | 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)) |
Javi Merino | c26e1c7 | 2014-04-08 16:39:01 +0100 | [diff] [blame] | 52 | |
| 53 | def tearDown(self): |
Javi Merino | 9e9ed7f | 2014-04-08 16:46:42 +0100 | [diff] [blame] | 54 | os.chdir(self.previous_dir) |
Javi Merino | c26e1c7 | 2014-04-08 16:39:01 +0100 | [diff] [blame] | 55 | shutil.rmtree(self.out_dir) |