1#!/usr/bin/python2 2# -*-coding:utf-8 -* 3 4# Copyright (c) 2011-2015, Intel Corporation 5# All rights reserved. 6# 7# Redistribution and use in source and binary forms, with or without modification, 8# are permitted provided that the following conditions are met: 9# 10# 1. Redistributions of source code must retain the above copyright notice, this 11# list of conditions and the following disclaimer. 12# 13# 2. Redistributions in binary form must reproduce the above copyright notice, 14# this list of conditions and the following disclaimer in the documentation and/or 15# other materials provided with the distribution. 16# 17# 3. Neither the name of the copyright holder nor the names of its contributors 18# may be used to endorse or promote products derived from this software without 19# specific prior written permission. 20# 21# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 22# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 25# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 26# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 27# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 28# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 32""" 33Create a test suite for all tests about SET/GET commands 34 35Uses PfwSetTsetSuite to create a single instance of the HAL 36for all the SET/GEt commands. 37 38These commands are tested using the methods of the classes 39"BooleanTestCase", etc... 40""" 41 42import sys 43import os 44import unittest 45import shutil 46from Util import PfwUnitTestLib 47 48class Logger(object): 49 50 def __init__(self, filename="Default.log"): 51 self.terminal = sys.stdout 52 self.log = open(filename, "a") 53 54 def write(self, message): 55 self.terminal.write(message) 56 self.log.write(message) 57 58def testsRunner(testDirectory): 59 60 tests = unittest.defaultTestLoader.discover(testDirectory, pattern='t*.py') 61 runner = unittest.TextTestRunner(verbosity=2) 62 63 return runner.run(tests).wasSuccessful() 64 65def main(): 66 67 pfw_root = os.environ["PFW_ROOT"] 68 pfw_result = os.environ["PFW_RESULT"] 69 xml_path = "xml/configuration/ParameterFrameworkConfiguration.xml" 70 71 os.environ["PFW_TEST_TOOLS"] = os.path.dirname(os.path.abspath(__file__)) 72 os.environ["PFW_TEST_CONFIGURATION"] = os.path.join(pfw_root, xml_path) 73 74 try: 75 # This directory must not exist. An exception will be raised if it does. 76 os.makedirs(pfw_result) 77 78 isAlive = os.path.join(pfw_result,"isAlive") 79 with open(isAlive, 'w') as fout: 80 fout.write('true') 81 82 needResync = os.path.join(pfw_result,"needResync") 83 with open(needResync, 'w') as fout: 84 fout.write('false') 85 86 success = testsRunner('PfwTestCase') 87 88 finally: 89 shutil.rmtree(pfw_result) 90 91 sys.exit(0 if success else 1) 92 93if __name__ == "__main__": 94 main() 95