diff options
Diffstat (limited to 'test/functional-tests/PfwTestCase/Domains')
10 files changed, 2915 insertions, 0 deletions
diff --git a/test/functional-tests/PfwTestCase/Domains/__init__.py b/test/functional-tests/PfwTestCase/Domains/__init__.py new file mode 100644 index 0000000..e49f417 --- /dev/null +++ b/test/functional-tests/PfwTestCase/Domains/__init__.py @@ -0,0 +1,10 @@ +""" +Domains Package : All testcases about DOMAINS functions in PFW : + - domains configuration selections and restore + - domains creation and deletion + - domain rename + - rules management + - elements management + - elements sequences in domains + - domains split +"""
\ No newline at end of file diff --git a/test/functional-tests/PfwTestCase/Domains/tDomain_Configuration.py b/test/functional-tests/PfwTestCase/Domains/tDomain_Configuration.py new file mode 100644 index 0000000..e5fcfed --- /dev/null +++ b/test/functional-tests/PfwTestCase/Domains/tDomain_Configuration.py @@ -0,0 +1,505 @@ +# -*-coding:utf-8 -* + +# Copyright (c) 2011-2015, Intel Corporation +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation and/or +# other materials provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors +# may be used to endorse or promote products derived from this software without +# specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR +# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +""" +Creation, renaming and deletion configuration testcases + +List of tested functions : +-------------------------- + - [listConfigurations] function + - [createConfiguration] function + - [deleteConfiguration] function + - [renameConfiguration] function + +Test cases : +------------ + - Testing configuration creation error + - Testing configuration renaming error + - Testing configuration deletion error + - Testing nominal case +""" +import os +from Util.PfwUnitTestLib import PfwTestCase +from Util import ACTLogging +log=ACTLogging.Logger() + + +# Test of Domains - Rename +class TestCases(PfwTestCase): + def setUp(self): + self.pfw.sendCmd("setTuningMode", "on") + self.domain_name = "domain_test" + self.conf_test = "conf_white" + self.conf_test_renamed = "conf_black" + self.new_conf_number = 5 + + def tearDown(self): + self.pfw.sendCmd("setTuningMode", "off") + + def test_Conf_Creation_Error(self): + """ + Testing configuration creation error + ------------------------------------ + Test case description : + ~~~~~~~~~~~~~~~~~~~~~~~ + - Create an already existent configuration + - Create a configuration with no name specified + - Create a configuration on a wrong domain name + Tested commands : + ~~~~~~~~~~~~~~~~~ + - [createConfiguration] function + - [createDomain] function + - [listConfigurations] function + - [deleteConfiguration] function + - [deleteDomain] function + Expected result : + ~~~~~~~~~~~~~~~~~ + - no configuration created + - existent configurations not affected by error + """ + log.D(self.test_Conf_Creation_Error.__doc__) + # New domain creation for testing purpose + log.I("New domain creation for testing purpose : %s" % (self.domain_name)) + log.I("command [createDomain]") + out, err = self.pfw.sendCmd("createDomain",self.domain_name, "") + assert out == "Done", out + assert err == None, "ERROR : command [createDomain] - Error while creating domain %s" % (self.domain_name) + log.I("command [createDomain] correctly executed") + log.I("Domain %s created" % (self.domain_name)) + + # New configurations creation for testing purpose + for iteration in range (self.new_conf_number): + new_conf_name = "".join([self.conf_test, "_", str(iteration)]) + log.I("New configuration %s creation for domain %s" % (new_conf_name,self.domain_name)) + log.I("command [createConfiguration]") + out, err = self.pfw.sendCmd("createConfiguration",self.domain_name,new_conf_name) + assert out == "Done", out + assert err == None, "ERROR : command [createConfiguration] - Error while creating configuration %s" % (new_conf_name) + log.I("command [createConfiguration] correctly executed") + log.I("Configuration %s created for domain %s" % (new_conf_name,self.domain_name)) + + # Domain configurations listing backup + log.I("Configurations listing for domain %s" % (self.domain_name)) + log.I("command [listConfigurations]") + out, err = self.pfw.sendCmd("listConfigurations",self.domain_name, "") + assert err == None, "ERROR : command [listConfigurations] - Error while listing configurations for domain %s" % (self.domain_name) + log.I("command [listConfigurations] correctly executed") + # Saving configurations names + f_configurations_backup = open("f_configurations_backup", "w") + f_configurations_backup.write(out) + f_configurations_backup.close() + + # New configurations creation error + log.I("Creating an already existent configurations names") + for iteration in range (self.new_conf_number): + new_conf_name = "".join([self.conf_test, "_", str(iteration)]) + log.I("Trying to create already existent %s configuration for domain %s" % (new_conf_name,self.domain_name)) + log.I("command [createConfiguration]") + out, err = self.pfw.sendCmd("createConfiguration",self.domain_name,new_conf_name) + assert out != "Done", "ERROR : command [createConfiguration] - Error not detected while creating already existent configuration %s" % (new_conf_name) + assert err == None, "ERROR : command [createConfiguration] - Error while creating configuration %s" % (new_conf_name) + log.I("command [createConfiguration] correctly executed") + log.I("error correctly detected, no configuration created") + log.I("Creating a configuration without specifying a name") + out, err = self.pfw.sendCmd("createConfiguration",self.domain_name) + assert out != "Done", "ERROR : command [createConfiguration] - Error not detected while creating a configuration without specifying a name" + assert err == None, "ERROR : command [createConfiguration] - Error while creating configuration" + log.I("error correctly detected") + log.I("Creating a configuration on a wrong domain name") + new_conf_name = "new_conf" + out, err = self.pfw.sendCmd("createConfiguration","wrong_domain_name",new_conf_name) + assert out != "Done", "ERROR : command [createConfiguration] - Error not detected while creating a configuration on a wrong domain name" + assert err == None, "ERROR : command [createConfiguration] - Error while creating configuration" + log.I("error correctly detected") + + # New domain configurations listing + log.I("Configurations listing for domain %s" % (self.domain_name)) + log.I("command [listConfigurations]" ) + out, err = self.pfw.sendCmd("listConfigurations",self.domain_name, "") + assert err == None, "ERROR : command [listConfigurations] - Error while listing configurations for domain %s" % (self.domain_name) + log.I("command [listConfigurations] correctly executed") + # Saving configurations names + f_configurations = open("f_configurations", "w") + f_configurations.write(out) + f_configurations.close() + + # Checking configurations names integrity + log.I("Configurations listing conformity check") + f_configurations = open("f_configurations", "r") + f_configurations_backup = open("f_configurations_backup", "r") + for iteration in range(self.new_conf_number): + listed_conf_backup = f_configurations_backup.readline().strip('\n') + listed_conf = f_configurations.readline().strip('\n') + assert listed_conf==listed_conf_backup, "ERROR : Error while listing configuration %s (found %s)" % (listed_conf_backup, listed_conf) + log.I("No change detected, listed configurations names conform to expected values") + + # New domain deletion + log.I("End of test, new domain deletion") + log.I("command [deleteDomain]") + out, err = self.pfw.sendCmd("deleteDomain",self.domain_name, "") + assert out == "Done", "ERROR : %s" % (out) + assert err == None, "ERROR : command [deleteDomain] - Error while deleting domain %s" % (self.domain_name) + log.I("command [deleteDomain] correctly executed") + + # Closing and deleting temp files + f_configurations_backup.close() + os.remove("f_configurations_backup") + f_configurations.close() + os.remove("f_configurations") + + def test_Conf_Renaming_Error(self): + """ + Testing configuration renaming error + ------------------------------------ + Test case description : + ~~~~~~~~~~~~~~~~~~~~~~~ + - Rename a configuration with an already used name + - Rename a configuration with no name specified + - Rename a configuration on a wrong domain name + Tested commands : + ~~~~~~~~~~~~~~~~~ + - [renameConfiguration] function + - [createDomain] function + - [listConfigurations] function + - [createConfiguration] function + - [deleteConfiguration] function + - [deleteDomain] function + Expected result : + ~~~~~~~~~~~~~~~~~ + - error detected + - no configuration created + - existent configurations not affected by error + """ + log.D(self.test_Conf_Renaming_Error.__doc__) + # New domain creation for testing purpose + log.I("New domain creation for testing purpose : %s" % (self.domain_name)) + log.I("command [createDomain]") + out, err = self.pfw.sendCmd("createDomain",self.domain_name, "") + assert out == "Done", out + assert err == None, "ERROR : command [createDomain] - Error while creating domain %s" % (self.domain_name) + log.I("command [createDomain] correctly executed") + log.I("Domain %s created" % (self.domain_name)) + + # New configurations creation for testing purpose + for iteration in range (self.new_conf_number): + new_conf_name = "".join([self.conf_test, "_", str(iteration)]) + log.I("New configuration %s creation for domain %s" % (new_conf_name,self.domain_name)) + log.I("command [createConfiguration]") + out, err = self.pfw.sendCmd("createConfiguration",self.domain_name,new_conf_name) + assert out == "Done", out + assert err == None, "ERROR : command [createConfiguration] - Error while creating configuration %s" % (new_conf_name) + log.I("command [createConfiguration] correctly executed") + log.I("Configuration %s created for domain %s" % (new_conf_name,self.domain_name)) + + # Domain configurations listing backup + log.I("Configurations listing for domain %s" % (self.domain_name)) + log.I("command [listConfigurations]") + out, err = self.pfw.sendCmd("listConfigurations",self.domain_name, "") + assert err == None, "ERROR : command [listConfigurations] - Error while listing configurations for domain %s" % (self.domain_name) + log.I("command [listConfigurations] correctly executed") + # Saving configurations names + f_configurations_backup = open("f_configurations_backup", "w") + f_configurations_backup.write(out) + f_configurations_backup.close() + + # New configurations renaming error + log.I("renaming a configuration with an already used name") + for iteration in range (self.new_conf_number-1): + conf_name = "".join([self.conf_test, "_", str(iteration)]) + new_conf_name = "".join([self.conf_test, "_", str(iteration+1)]) + log.I("Trying to rename %s on domain %s with an already used name : %s" % (conf_name,self.domain_name,new_conf_name)) + log.I("command [renameConfiguration]" ) + out, err = self.pfw.sendCmd("renameConfiguration",self.domain_name,conf_name,new_conf_name) + assert out != "Done", "ERROR : command [renameConfiguration] - Error not detected while renaming configuration %s with an already used name" % (new_conf_name) + assert err == None, "ERROR : command [renameConfiguration] - Error while renaming configuration %s" % (new_conf_name) + log.I("command [renameConfiguration] correctly executed") + log.I("error correctly detected, no configuration renamed") + log.I("renaming a configuration without specifying a new name") + out, err = self.pfw.sendCmd("renameConfiguration",self.domain_name,new_conf_name) + assert out != "Done", "ERROR : command [renameConfiguration] - Error not detected while renaming a configuration without specifying a new name" + assert err == None, "ERROR : command [renameConfiguration] - Error while renaming configuration" + log.I("error correctly detected, no configuration renamed") + log.I("renaming a configuration on a wrong domain name") + new_conf_name = "new_conf" + out, err = self.pfw.sendCmd("renameConfiguration","wrong_domain_name",new_conf_name,"Configuration") + assert out != "Done", "ERROR : command [renameConfiguration] - Error not detected while renaming a configuration on a wrong domain name" + assert err == None, "ERROR : command [renameConfiguration] - Error while renaming configuration" + log.I("error correctly detected, no configuration renamed") + + # New domain configurations listing + log.I("Configurations listing for domain %s" % (self.domain_name)) + log.I("command [listConfigurations]") + out, err = self.pfw.sendCmd("listConfigurations",self.domain_name, "") + assert err == None, "ERROR : command [listConfigurations] - Error while listing configurations for domain %s" % (self.domain_name) + log.I("command [listConfigurations] correctly executed") + # Saving configurations names + f_configurations = open("f_configurations", "w") + f_configurations.write(out) + f_configurations.close() + + # Checking configurations names integrity + log.I("Configurations listing conformity check") + f_configurations = open("f_configurations", "r") + f_configurations_backup = open("f_configurations_backup", "r") + for iteration in range(self.new_conf_number): + listed_conf_backup = f_configurations_backup.readline().strip('\n') + listed_conf = f_configurations.readline().strip('\n') + assert listed_conf==listed_conf_backup, "ERROR : Error while listing configuration %s (found %s)" % (listed_conf_backup, listed_conf) + log.I("No change detected, listed configurations names conform to expected values") + + # Testing domain deletion + log.I("End of test, new domain deletion") + log.I("command [deleteDomain]") + out, err = self.pfw.sendCmd("deleteDomain",self.domain_name, "") + assert out == "Done", "ERROR : %s" % (out) + assert err == None, "ERROR : command [deleteDomain] - Error while deleting domain %s" % (self.domain_name) + log.I("command [deleteDomain] correctly executed") + + # Closing and deleting temp files + f_configurations_backup.close() + os.remove("f_configurations_backup") + f_configurations.close() + os.remove("f_configurations") + + def test_Conf_Deletion_Error(self): + """ + Testing configuration deletion error + ------------------------------------ + Test case description : + ~~~~~~~~~~~~~~~~~~~~~~~ + - Delete a configuration with a non existent name + - Delete a configuration with no name specified + - Delete a configuration on a wrong domain name + Tested commands : + ~~~~~~~~~~~~~~~~~ + - [deleteConfiguration] function + - [createDomain] function + - [listConfigurations] function + - [createConfiguration] function + - [deleteDomain] function + Expected result : + ~~~~~~~~~~~~~~~~~ + - error detected + - no configuration created + - existent configurations not affected by error + """ + print self.test_Conf_Renaming_Error.__doc__ + # New domain creation for testing purpose + log.I("New domain creation for testing purpose : %s" % (self.domain_name)) + log.I("command [createDomain]") + out, err = self.pfw.sendCmd("createDomain",self.domain_name, "") + assert out == "Done", out + assert err == None, "ERROR : command [createDomain] - Error while creating domain %s" % (self.domain_name) + log.I("command [createDomain] correctly executed") + log.I("Domain %s created" % (self.domain_name)) + + # New configurations creation for testing purpose + for iteration in range (self.new_conf_number): + new_conf_name = "".join([self.conf_test, "_", str(iteration)]) + log.I("New configuration %s creation for domain %s" % (new_conf_name,self.domain_name)) + log.I("command [createConfiguration]") + out, err = self.pfw.sendCmd("createConfiguration",self.domain_name,new_conf_name) + assert out == "Done", out + assert err == None, "ERROR : command [createConfiguration] - Error while creating configuration %s" % (new_conf_name) + log.I("command [createConfiguration] correctly executed") + log.I("Configuration %s created for domain %s" % (new_conf_name,self.domain_name)) + + # Domain configurations listing backup + log.I("Configurations listing for domain %s" % (self.domain_name)) + log.I("command [listConfigurations]") + out, err = self.pfw.sendCmd("listConfigurations",self.domain_name, "") + assert err == None, "ERROR : command [listConfigurations] - Error while listing configurations for domain %s" % (self.domain_name) + log.I("command [listConfigurations] correctly executed") + # Saving configurations names + f_configurations_backup = open("f_configurations_backup", "w") + f_configurations_backup.write(out) + f_configurations_backup.close() + + # Configurations deletion errors + log.I("Trying various deletions error test cases") + log.I("Trying to delete a wrong configuration name on domain %s" % (self.domain_name)) + log.I("command [deleteConfiguration]") + out, err = self.pfw.sendCmd("deleteConfiguration",self.domain_name,"wrong_configuration_name") + assert out != "Done", "ERROR : command [deleteConfiguration] - Error not detected while deleting non existent configuration name" + assert err == None, "ERROR : command [deleteConfiguration] - Error while deleting configuration" + log.I("command [deleteConfiguration] correctly executed") + log.I("error correctly detected, no configuration deleted") + log.I("deleting a configuration with no name specified") + out, err = self.pfw.sendCmd("deleteConfiguration",self.domain_name) + assert out != "Done", "ERROR : command [deleteConfiguration] - Error not detected while deleting a configuration without specifying a name" + assert err == None, "ERROR : command [deleteConfiguration] - Error while deleting configuration" + log.I("error correctly detected, no configuration deleted") + log.I("deleting a configuration on a wrong domain name") + out, err = self.pfw.sendCmd("deleteConfiguration","wrong_domain_name",new_conf_name) + assert out != "Done", "ERROR : command [deleteConfiguration] - Error not detected while deleting a configuration on a wrong domain name" + assert err == None, "ERROR : command [deleteConfiguration] - Error while deleting configuration" + log.I("error correctly detected, no configuration deleted") + + # New domain configurations listing + log.I("Configurations listing for domain %s" % (self.domain_name)) + log.I("command [listConfigurations]") + out, err = self.pfw.sendCmd("listConfigurations",self.domain_name, "") + assert err == None, "ERROR : command [listConfigurations] - Error while listing configurations for domain %s" % (self.domain_name) + log.I("command [listConfigurations] correctly executed") + # Saving configurations names + f_configurations = open("f_configurations", "w") + f_configurations.write(out) + f_configurations.close() + + # Checking configurations names integrity + log.I("Configurations listing conformity check") + f_configurations = open("f_configurations", "r") + f_configurations_backup = open("f_configurations_backup", "r") + for iteration in range(self.new_conf_number): + listed_conf_backup = f_configurations_backup.readline().strip('\n') + listed_conf = f_configurations.readline().strip('\n') + assert listed_conf==listed_conf_backup, "ERROR : Error while listing configuration %s (found %s)" % (listed_conf_backup, listed_conf) + log.I("No change detected, listed configurations names conform to expected values") + + # Testing domain deletion + log.I("End of test, new domain deletion") + log.I("command [deleteDomain]") + out, err = self.pfw.sendCmd("deleteDomain",self.domain_name, "") + assert out == "Done", "ERROR : %s" % (out) + assert err == None, "ERROR : command [deleteDomain] - Error while deleting domain %s" % (self.domain_name) + log.I("command [deleteDomain] correctly executed") + + # Closing and deleting temp files + f_configurations_backup.close() + os.remove("f_configurations_backup") + f_configurations.close() + os.remove("f_configurations") + + def test_Nominal_Case(self): + """ + Testing nominal cases + --------------------- + Test case description : + ~~~~~~~~~~~~~~~~~~~~~~~ + - Create new configurations + - List domain configurations + - Rename configurations + - Delete configurations + Tested commands : + ~~~~~~~~~~~~~~~~~ + - [listConfigurations] function + - [createConfiguration] function + - [renameConfiguration] function + - [deleteConfiguration] function + - [createDomain] function + - [deleteDomain] function + Expected result : + ~~~~~~~~~~~~~~~~~ + - all operations succeed + """ + log.D(self.test_Nominal_Case.__doc__) + # New domain creation + log.I("New domain creation for testing purpose : %s" % (self.domain_name)) + log.I("command [createDomain]") + out, err = self.pfw.sendCmd("createDomain",self.domain_name, "") + assert out == "Done", out + assert err == None, "ERROR : command [createDomain] - Error while creating domain %s" % (self.domain_name) + log.I("command [createDomain] correctly executed") + log.I("Domain %s created" % (self.domain_name)) + + # New configurations creation + for iteration in range (self.new_conf_number): + new_conf_name = "".join([self.conf_test, "_", str(iteration)]) + log.I("New configuration %s creation for domain %s" % (new_conf_name,self.domain_name)) + log.I("command [createConfiguration]" ) + out, err = self.pfw.sendCmd("createConfiguration",self.domain_name,new_conf_name) + assert out == "Done", out + assert err == None, "ERROR : command [createConfiguration] - Error while creating configuration %s" % (new_conf_name) + log.I("command [createConfiguration] correctly executed") + log.I("Configuration %s created for domain %s" % (new_conf_name,self.domain_name)) + + # Listing domain configurations + log.I("Configurations listing for domain %s" % (self.domain_name)) + log.I("command [listConfigurations]") + out, err = self.pfw.sendCmd("listConfigurations",self.domain_name, "") + assert err == None, "ERROR : command [listConfigurations] - Error while listing configurations for domain %s" % (self.domain_name) + log.I("command [listConfigurations] correctly executed") + # Saving configurations names + f_configurations = open("f_configurations", "w") + f_configurations.write(out) + f_configurations.close() + # Checking configurations names integrity + log.I("Configurations listing conformity check") + f_configurations = open("f_configurations", "r") + for iteration in range(self.new_conf_number): + new_conf_name = "".join([self.conf_test, "_", str(iteration)]) + listed_conf = f_configurations.readline().strip('\n') + assert listed_conf==new_conf_name, "ERROR : Error while listing configuration %s (found %s)" % (listed_conf, new_conf_name) + log.I("Listed configurations names conform to expected values") + + # Configuration renaming + log.I("Configurations renaming") + for iteration in range (self.new_conf_number): + conf_name = "".join([self.conf_test, "_", str(iteration)]) + new_conf_name = "".join([self.conf_test_renamed, "_", str(iteration)]) + log.I("Configuration %s renamed to %s in domain %s" % (conf_name,new_conf_name,self.domain_name)) + log.I("command [renameConfiguration]") + out, err = self.pfw.sendCmd("renameConfiguration",self.domain_name,conf_name,new_conf_name) + assert out == "Done", out + assert err == None, "ERROR : command [renameConfiguration] - Error while renaming configuration %s to %s" % (conf_name,new_conf_name) + log.I("command [renameConfiguration] correctly executed") + log.I("Configuration %s renamed to %s for domain %s" % (conf_name,new_conf_name,self.domain_name)) + # Listing domain configurations + log.I("Configurations listing to check configurations renaming") + log.I("command [listConfigurations]") + out, err = self.pfw.sendCmd("listConfigurations",self.domain_name, "") + assert err == None, "ERROR : command [listConfigurations] - Error while listing configurations for domain %s" % (self.domain_name) + log.I("command [listConfigurations] correctly executed") + # Saving configurations names + f_configurations_renamed = open("f_configurations_renamed", "w") + f_configurations_renamed.write(out) + f_configurations_renamed.close() + # Checking configurations names integrity + log.I("Configurations listing conformity check") + f_configurations_renamed = open("f_configurations_renamed", "r") + for iteration in range(self.new_conf_number): + new_conf_name = "".join([self.conf_test_renamed, "_", str(iteration)]) + listed_conf = f_configurations_renamed.readline().strip('\n') + assert listed_conf==new_conf_name, "ERROR : Error while renaming configuration %s (found %s)" % (new_conf_name,listed_conf) + log.I("Listed configurations names conform to expected values, renaming successfull") + + # New domain deletion + log.I("End of test, new domain deletion") + log.I("command [deleteDomain]") + out, err = self.pfw.sendCmd("deleteDomain",self.domain_name, "") + assert out == "Done", "ERROR : %s" % (out) + assert err == None, "ERROR : command [deleteDomain] - Error while deleting domain %s" % (self.domain_name) + log.I("command [deleteDomain] correctly executed") + + # Closing and deleting temp file + f_configurations.close() + os.remove("f_configurations") + f_configurations_renamed.close() + os.remove("f_configurations_renamed") diff --git a/test/functional-tests/PfwTestCase/Domains/tDomain_Configuration_Backup.py b/test/functional-tests/PfwTestCase/Domains/tDomain_Configuration_Backup.py new file mode 100644 index 0000000..51d3d2b --- /dev/null +++ b/test/functional-tests/PfwTestCase/Domains/tDomain_Configuration_Backup.py @@ -0,0 +1,239 @@ +# -*-coding:utf-8 -* + +# Copyright (c) 2011-2015, Intel Corporation +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation and/or +# other materials provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors +# may be used to endorse or promote products derived from this software without +# specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR +# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +""" +Save and restore configuration testcases + +List of tested functions : +-------------------------- + - [saveConfiguration] function + - [restoreConfiguration] function + +Test cases : +------------ + - Testing nominal case + - Testing saveConfiguration errors + - Testing restoreConfiguration errors +""" + +from Util.PfwUnitTestLib import PfwTestCase +from Util import ACTLogging +log=ACTLogging.Logger() + +# Test of Domains - save/restore configuration +class TestCases(PfwTestCase): + def setUp(self): + self.pfw.sendCmd("setTuningMode", "on") + self.domain_name = "Domain_0" + self.conf_1 = "Conf_0" + self.conf_2 = "Conf_1" + self.param_name = "/Test/Test/TEST_DIR/INT8" + + def tearDown(self): + self.pfw.sendCmd("setTuningMode", "off") + + def test_Nominal_Case(self): + """ + Testing nominal case + -------------------- + Test case description : + ~~~~~~~~~~~~~~~~~~~~~~~ + - save a configuration + - restore a configuration + Tested commands : + ~~~~~~~~~~~~~~~~~ + - [saveConfiguration] function + - [restoreConfiguration] function + Expected result : + ~~~~~~~~~~~~~~~~~ + - all operations succeed + """ + log.D(self.test_Nominal_Case.__doc__) + + # Saving original parameter value + log.I("restoring configuration %s from domain %s" % (self.conf_1, self.domain_name)) + out, err = self.pfw.sendCmd("restoreConfiguration", self.domain_name, self.conf_1) + assert err == None, "Error when restoring configuration %s from domain %s : %s" % (self.conf_1, self.domain_name, err) + assert out == "Done", out + out, err = self.pfw.sendCmd("getParameter", self.param_name) + assert err == None, "Error when getting parameter %s : %s" % (self.param_name, err) + Param_saved_1 = int(out) + log.I("saved parameter %s value on %s from domain %s = %s" % (self.param_name, self.conf_1, self.domain_name, Param_saved_1)) + + # Modifying parameter value + log.I("modifying parameter %s value on configuration %s from domain %s" % (self.param_name, self.conf_1, self.domain_name)) + out, err = self.pfw.sendCmd("setParameter", self.param_name, str(Param_saved_1+1)) + assert err == None, "Error when setting parameter %s : %s" % (self.param_name, err) + log.I("new parameter %s value = %s in place of %s" % (self.param_name, str(Param_saved_1+1), Param_saved_1)) + + # Saving new parameter value + log.I("saving configuration %s from domain %s" % (self.conf_1, self.domain_name)) + out, err = self.pfw.sendCmd("saveConfiguration", self.domain_name, self.conf_1) + assert err == None, "Error when saving configuration %s from domain %s : %s" % (self.conf_1, self.domain_name, err) + assert out == "Done", out + out, err = self.pfw.sendCmd("getParameter", self.param_name) + assert err == None, "Error when getting parameter %s : %s" % (self.param_name, err) + Param_saved_1 = int(out) + log.I("new saved parameter %s value on %s from domain %s = %s" % (self.param_name, self.conf_1, self.domain_name, Param_saved_1)) + + # Modifying and restoring parameter value + log.I("modifying parameter %s value on configuration %s from domain %s" % (self.param_name, self.conf_1, self.domain_name)) + out, err = self.pfw.sendCmd("setParameter", self.param_name, str(Param_saved_1+1)) + assert err == None, "Error when setting parameter %s : %s" % (self.param_name, err) + out, err = self.pfw.sendCmd("getParameter", self.param_name) + assert err == None, "Error when getting parameter %s : %s" % (self.param_name, err) + Param_saved_2 = int(out) + log.I("new parameter %s value on %s = %s in place of %s" % (self.param_name, self.conf_1, str(Param_saved_2), Param_saved_1)) + log.I("restoring configuration %s from domain %s" % (self.conf_1, self.domain_name)) + out, err = self.pfw.sendCmd("restoreConfiguration", self.domain_name, self.conf_1) + assert err == None, "Error when restoring configuration %s from domain %s : %s" % (self.conf_1, self.domain_name, err) + assert out == "Done", out + out, err = self.pfw.sendCmd("getParameter", self.param_name) + assert err == None, "Error when getting parameter %s : %s" % (self.param_name, err) + Param_saved_2 = int(out) + assert Param_saved_2 == Param_saved_1, "Error when restoring configuration %s from domain %s" % (self.conf_1, self.domain_name) + log.I("saving and restoring configuration works fine") + + def test_Save_Config_Error(self): + """ + Testing saveConfiguration error + ------------------------------- + Test case description : + ~~~~~~~~~~~~~~~~~~~~~~~ + - save a configuration with a missing argument + - save a configuration with a wrong domain name + - save a configuration with a wrong configuration name + Tested commands : + ~~~~~~~~~~~~~~~~~ + - [saveConfiguration] function + Expected result : + ~~~~~~~~~~~~~~~~~ + - errors correctly detected + """ + log.D(self.test_Save_Config_Error.__doc__) + # Saving original parameter value and setting a new value to parameter for testing purpose + log.I("restoring configuration %s from domain %s" % (self.conf_1, self.domain_name)) + out, err = self.pfw.sendCmd("restoreConfiguration", self.domain_name, self.conf_1) + assert err == None, "Error when restoring configuration %s from domain %s : %s" % (self.conf_1, self.domain_name, err) + assert out == "Done", out + out, err = self.pfw.sendCmd("getParameter", self.param_name) + assert err == None, "Error when getting parameter %s : %s" % (self.param_name, err) + Param_saved_1 = int(out) + log.I("saved parameter %s value on %s from domain %s = %s" % (self.param_name, self.conf_1, self.domain_name, Param_saved_1)) + log.I("modifying parameter %s value on configuration %s from domain %s" % (self.param_name, self.conf_1, self.domain_name)) + out, err = self.pfw.sendCmd("setParameter", self.param_name, str(Param_saved_1+1)) + assert err == None, "Error when setting parameter %s : %s" % (self.param_name, err) + log.I("new parameter %s value = %s in place of %s" % (self.param_name, str(Param_saved_1+1), Param_saved_1)) + + # Configuration saving errors + log.I("saving configuration error test cases :") + log.I("saving configuration with a missing argument") + out, err = self.pfw.sendCmd("saveConfiguration", self.domain_name) + assert err == None, "ERROR : Error when saving configuration with a missing argument" + assert out != "Done", "ERROR : Error not detected when saving configuration with a missing argument" + log.I("saving configuration with a wrong domain name") + out, err = self.pfw.sendCmd("saveConfiguration", "Wrong_Domain_Name", self.conf_1) + assert err == None, "ERROR : Error when saving configuration with a wrong domain name" + assert out != "Done", "ERROR : Error not detected when saving configuration with a wrong domain name" + log.I("saving configuration with a wrong configuration name") + out, err = self.pfw.sendCmd("saveConfiguration", self.domain_name, "Wrong_Configuration_Name") + assert err == None, "ERROR : Error when saving configuration with a wrong configuration name" + assert out != "Done", "ERROR : Error not detected when saving configuration with a wrong configuration name" + log.I("saving configuration error test cases : errors correctly detected") + + # Checking that no error has affected original configuration save + log.I("restoring configuration %s from domain %s" % (self.conf_1, self.domain_name)) + out, err = self.pfw.sendCmd("restoreConfiguration", self.domain_name, self.conf_1) + assert err == None, "error when restoring configuration %s from domain %s : %s" % (self.conf_1, self.domain_name, err) + assert out == "Done", out + out, err = self.pfw.sendCmd("getParameter", self.param_name) + assert err == None, "error when getting parameter %s : %s" % (self.param_name, err) + Param_saved_2 = int(out) + assert Param_saved_2 == Param_saved_1, "error when restoring configuration %s from domain %s, parameter %s affected by configuration saving error" % (self.conf_1, self.domain_name, Param_saved_1) + log.I("Test passed : saving errors correctly detected, no impact on previously saved configuration") + + def test_Restore_Config_Error(self): + """ + Testing restoreConfiguration error + ---------------------------------- + Test case description : + ~~~~~~~~~~~~~~~~~~~~~~~ + - restore a configuration with a missing argument + - restore a configuration with a wrong domain name + - restore a configuration with a wrong configuration name + Tested commands : + ~~~~~~~~~~~~~~~~~ + - [restoreConfiguration] function + Expected result : + ~~~~~~~~~~~~~~~~~ + - errors correctly detected + - configuration's parameters not affected by errors + """ + + log.D(self.test_Restore_Config_Error.__doc__) + # Saving original parameter value and setting a new value to parameter for testing purpose + log.I("restore configuration %s from domain %s" % (self.conf_1, self.domain_name)) + out, err = self.pfw.sendCmd("restoreConfiguration", self.domain_name, self.conf_1) + assert err == None, "Error when restoring configuration %s from domain %s : %s" % (self.conf_1, self.domain_name, err) + assert out == "Done", out + out, err = self.pfw.sendCmd("getParameter", self.param_name) + assert err == None, "Error when getting parameter %s : %s" % (self.param_name, err) + Param_saved_1 = int(out) + log.I("saved parameter %s value on %s from domain %s = %s" % (self.param_name, self.conf_1, self.domain_name, Param_saved_1)) + log.I("modifying parameter %s value on configuration %s from domain %s" % (self.param_name, self.conf_1, self.domain_name)) + out, err = self.pfw.sendCmd("setParameter", self.param_name, str(Param_saved_1+1)) + assert err == None, "Error when setting parameter %s : %s" % (self.param_name, err) + log.I("new parameter %s value = %s in place of %s" % (self.param_name, str(Param_saved_1+1), Param_saved_1)) + out, err = self.pfw.sendCmd("getParameter", self.param_name) + assert err == None, "Error when getting parameter %s : %s" % (self.param_name, err) + Param_saved_2 = int(out) + + # Configuration restore errors + log.I("restoring configuration error test cases :") + log.I("restoring configuration with a missing argument") + out, err = self.pfw.sendCmd("restoreConfiguration", self.domain_name) + assert err == None, "ERROR : Error when restoring configuration with a missing argument" + assert out != "Done", "ERROR : Error not detected when restoring configuration with a missing argument" + log.I("restoring configuration with a wrong domain name") + out, err = self.pfw.sendCmd("restoreConfiguration", "Wrong_Domain_Name", self.conf_1) + assert err == None, "ERROR : Error when restoring configuration with a wrong domain name" + assert out != "Done", "ERROR : Error not detected when restoring configuration with a wrong domain name" + log.I("restoring configuration with a wrong configuration name") + out, err = self.pfw.sendCmd("restoreConfiguration", self.domain_name, "Wrong_Configuration_Name") + assert err == None, "ERROR : Error when restoring configuration with a wrong configuration name" + assert out != "Done", "ERROR : Error not detected when restoring configuration with a wrong configuration name" + log.I("restoring configuration error test cases : errors correctly detected") + + # Checking that no error has affected configuration's parameter value + out, err = self.pfw.sendCmd("getParameter", self.param_name) + assert err == None, "error when getting parameter %s : %s" % (self.param_name, err) + Param_saved_1 = int(out) + assert Param_saved_2 == Param_saved_1, "error when restoring configuration %s from domain %s, parameter %s affected by configuration restoration error" % (self.conf_1, self.domain_name, Param_saved_1) + log.I("Test passed : restoring errors correctly detected, no impact on previously modified configuration's parameter") diff --git a/test/functional-tests/PfwTestCase/Domains/tDomain_Configuration_Selection.py b/test/functional-tests/PfwTestCase/Domains/tDomain_Configuration_Selection.py new file mode 100644 index 0000000..f67ab5f --- /dev/null +++ b/test/functional-tests/PfwTestCase/Domains/tDomain_Configuration_Selection.py @@ -0,0 +1,185 @@ +# -*-coding:utf-8 -* + +# Copyright (c) 2011-2015, Intel Corporation +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation and/or +# other materials provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors +# may be used to endorse or promote products derived from this software without +# specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR +# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +""" +Effect of criteria changes on configuration testcases + +List of tested functions : +-------------------------- + - [applyConfigurations] function + - [setCriterionState] function + +Test cases : +------------ + - test_Combinatorial_Criteria +""" +import os +from Util.PfwUnitTestLib import PfwTestCase +from Util import ACTLogging +log=ACTLogging.Logger() + +class TestCases(PfwTestCase): + + def setUp(self): + self.pfw.sendCmd("setTuningMode", "on") + self.reference_xml = "$PFW_TEST_TOOLS/xml/XML_Test/Reference_Criteria.xml" + self.temp_domain="f_Domains_Backup" + self.temp_status="f_Config_Status" + # Expected results are defined by Reference_Criteria.xml configuration settings + self.expected_result = [["Conf_1_1", "<none>", "Conf_3_0"] , + ["Conf_1_1", "Conf_2_1", "Conf_3_1"] , + ["Conf_1_1", "Conf_2_1", "Conf_3_0"] , + ["Conf_1_1", "Conf_2_0", "Conf_3_0"] , + ["Conf_1_0", "Conf_2_0", "Conf_3_0"] , + ["Conf_1_1", "Conf_2_0", "Conf_3_0"] , + ["Conf_1_1", "Conf_2_0", "Conf_3_1"]] + self.criterion_setup = [["0x2", "1"] , + ["0x2", "0"] , + ["0x1", "0"] , + ["0x1", "1"] , + ["0x3", "4"] , + ["0x0", "1"]] + # names used in this test refer to names used in Reference_Criteria.xml + self.new_domain_name = "Domain" + self.crit_change_iteration = 6 + + def tearDown(self): + self.pfw.sendCmd("setTuningMode", "off") + + def test_Combinatorial_Criteria(self): + """ + Testing combinatorial criteria + ------------------------------ + Test case description : + ~~~~~~~~~~~~~~~~~~~~~~~ + Checking that PFW behaviour is in line with expectations when setting criteria states. + - Test of all combinatorial of criteria and possible errors + - nominal case in configuration selection + - conflict in configuration selection + - no configuration selected + - error in criterion setting + - test of compound rules : All / Any + - test of matches cases : Is / IsNot / Include / Exclude + - test of criteria types : Inclusive / Exclusive + Tested commands : + ~~~~~~~~~~~~~~~~~ + - [applyConfigurations] function + - [setCriterionState] function + Expected result : + ~~~~~~~~~~~~~~~~~ + - Configurations setting conform to expected behavior + """ + log.D(self.test_Combinatorial_Criteria.__doc__) + + # Import a reference XML file + log.I("Import Domains with settings from %s"%(self.reference_xml)) + out, err = self.pfw.sendCmd("importDomainsWithSettingsXML",self.reference_xml, "") + assert err == None, log.E("Command [importDomainsWithSettingsXML %s] : %s"%(self.reference_xml,err)) + assert out == "Done", log.F("When using function importDomainsWithSettingsXML %s]"%(self.reference_xml)) + + # Check number of domain + log.I("Current domains listing") + log.I("Command [listDomains]") + out, err = self.pfw.sendCmd("listDomains","","") + assert err == None, log.E("Command [listDomains] : %s"%(err)) + log.I("Command [listDomains] : correctly executed") + + # Domains listing backup + f_Domains_Backup = open(self.temp_domain, "w") + f_Domains_Backup.write(out) + f_Domains_Backup.close() + f_Domains_Backup = open(self.temp_domain, "r") + domains_nbr = 0 + line=f_Domains_Backup.readline() + while line!="": + line=f_Domains_Backup.readline() + domains_nbr+=1 + f_Domains_Backup.close() + + # Applying default configurations + out, err = self.pfw.sendCmd("setTuningMode", "off") + assert err == None, log.E("Command [setTuningMode]") + out, err = self.hal.sendCmd("applyConfigurations") + assert err == None, log.E("Command HAL [applyConfigurations]") + + # Saving default status + out, err = self.pfw.sendCmd("status") + f_Config_Status = open(self.temp_status, "w") + f_Config_Status.write(out) + f_Config_Status.close() + + # Test cases iterations + for iteration in range (self.crit_change_iteration+1): + + # Criteria settings + # No criteria are set at the first iteration for testing default configurations + if iteration != 0: + log.I("Setting criterion %s to %s" % ("Crit_0", str(self.criterion_setup[iteration-1][0]))) + state = str(self.criterion_setup[iteration-1][0]) + out, err = self.hal.sendCmd("setCriterionState", "Crit_0", state) + assert err == None, log.E("Command HAL [setCriterionState]") + log.I("Setting criterion %s to %s" % ("Crit_1", str(self.criterion_setup[iteration-1][1]))) + state = str(self.criterion_setup[iteration-1][1]) + out, err = self.hal.sendCmd("setCriterionState", "Crit_1", state) + assert err == None, log.E("Command HAL [setCriterionState]") + log.I("Applaying new configurations") + out, err = self.hal.sendCmd("applyConfigurations") + assert err == None, log.E("Command HAL [applyConfigurations]") + out, err = self.pfw.sendCmd("status") + assert err == None, log.E("Command [status]") + os.remove(self.temp_status) + f_Config_Status = open(self.temp_status, "w") + f_Config_Status.write(out) + f_Config_Status.close() + else : + log.I("Default Configurations - no criteria are set :") + out, err = self.pfw.sendCmd("status") + os.remove(self.temp_status) + f_Config_Status = open(self.temp_status, "w") + f_Config_Status.write(out) + f_Config_Status.close() + + # Configurations checking + for domain in range (domains_nbr): + domain_name = "".join([self.new_domain_name, "_", str(domain+1)]) + config = str(self.expected_result[iteration][domain]) + log.I("Checking that domain %s is set to configuration : %s" % (domain_name,config)) + for line in open(self.temp_status, "r"): + if domain_name in line: + line = line.replace(domain_name,'') + line = line.replace(":","") + line = line.replace(' ','') + line = line.replace("\n","") + assert line == config, log.F("Domain %s - Expected configuration : %s, found : %s" % (domain_name,config,line)) + log.I("Domain %s - configuration correctly set to %s" % (domain_name,line)) + + # Temporary files deletion + os.remove(self.temp_domain) + os.remove(self.temp_status) diff --git a/test/functional-tests/PfwTestCase/Domains/tDomain_Elements.py b/test/functional-tests/PfwTestCase/Domains/tDomain_Elements.py new file mode 100644 index 0000000..8651968 --- /dev/null +++ b/test/functional-tests/PfwTestCase/Domains/tDomain_Elements.py @@ -0,0 +1,311 @@ +# -*-coding:utf-8 -* + +# Copyright (c) 2011-2015, Intel Corporation +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation and/or +# other materials provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors +# may be used to endorse or promote products derived from this software without +# specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR +# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +""" +Adding and Removing elements from domain testcases + +List of tested functions : +-------------------------- + - [listDomainElements] function + - [addElement] function + - [removeElement] function + +Test cases : +------------ + - Testing nominal case + - Testing addElement errors + - Testing removeElement errors +""" +import os +from Util.PfwUnitTestLib import PfwTestCase +from Util import ACTLogging +log=ACTLogging.Logger() + +class TestCases(PfwTestCase): + def setUp(self): + self.pfw.sendCmd("setTuningMode", "on") + self.domain_name = "Domain_0" + self.elem_0_path = "/Test/Test/TEST_DIR" + self.elem_1_path = "/Test/Test/TEST_DOMAIN_0" + self.elem_2_path = "/Test/Test/TEST_DOMAIN_1" + + def tearDown(self): + self.pfw.sendCmd("setTuningMode", "off") + + def test_Nominal_Case(self): + """ + Testing nominal case + -------------------- + Test case description : + ~~~~~~~~~~~~~~~~~~~~~~~ + - list and backup initial domain elements + - add a domain element + - remove a domain element + - list and check domains elements + Tested commands : + ~~~~~~~~~~~~~~~~~ + - [listDomainElements] function + - [addElement] function + - [removeElement] function + Expected result : + ~~~~~~~~~~~~~~~~~ + - all operations succeed + """ + log.D(self.test_Nominal_Case.__doc__) + + # List and backup initial domain elements + log.I("Listing initial domain %s elements" % (self.domain_name)) + out, err = self.pfw.sendCmd("listDomainElements",str(self.domain_name)) + assert err == None, "ERROR : command [listDomainElements] - Error while listing domain elements" + f_DomainElements_Backup = open("f_DomainElements_Backup", "w") + f_DomainElements_Backup.write(out) + f_DomainElements_Backup.close() + log.I("command [listDomainElements] correctly executed") + f_DomainElements_Backup = open("f_DomainElements_Backup", "r") + element_nbr_init = 0 + line=f_DomainElements_Backup.readline() + while line!="": + line=f_DomainElements_Backup.readline() + element_nbr_init+=1 + f_DomainElements_Backup.close() + log.I("Actual domain %s elements number is %s" % (self.domain_name,element_nbr_init)) + + # Adding a new domain element + log.I("Adding a new domain element to domain %s" % (self.domain_name)) + out, err = self.pfw.sendCmd("addElement", str(self.domain_name), str(self.elem_1_path)) + assert err == None, "ERROR : command [addElement] - Error while adding new domain element %s" % (self.elem_1_path) + assert out == "Done", "ERROR : command [addElement] - Error while adding new domain element %s" % (self.elem_1_path) + log.I("Adding a new domain element to domain %s" % (self.domain_name)) + out, err = self.pfw.sendCmd("addElement", str(self.domain_name), str(self.elem_2_path)) + assert err == None, "ERROR : command [addElement] - Error while adding new domain element %s" % (self.elem_2_path) + assert out == "Done", "ERROR : command [addElement] - Error while adding new domain element %s" % (self.elem_2_path) + log.I("New domain elements %s and %s added to domain %s" % (self.elem_1_path, self.elem_2_path, self.domain_name)) + + # Removing a domain element + log.I("Removing domain element %s from domain %s" % (self.elem_1_path,self.domain_name)) + out, err = self.pfw.sendCmd("removeElement", str(self.domain_name), str(self.elem_1_path)) + assert err == None, "ERROR : command [removeElement] - Error while removing domain element %s" % (self.elem_1_path) + assert out == "Done", "ERROR : command [removeElement] - Error while removing domain element %s" % (self.elem_1_path) + + # Checking final domain elements + log.I("Listing final domain %s elements" % (self.domain_name)) + out, err = self.pfw.sendCmd("listDomainElements",str(self.domain_name)) + assert err == None, "ERROR : command [listDomainElements] - Error while listing domain elements" + f_DomainElements = open("f_DomainElements", "w") + f_DomainElements.write(out) + f_DomainElements.close() + log.I("command [listDomainElements] correctly executed") + f_DomainElements = open("f_DomainElements", "r") + element_nbr = 0 + line=f_DomainElements.readline() + while line!="": + line=f_DomainElements.readline() + element_nbr+=1 + f_DomainElements.close() + log.I("Actual domain %s elements number is %s" % (self.domain_name,element_nbr)) + log.I("Checking domain %s elements names conformity" % (self.domain_name)) + f_DomainElements = open("f_DomainElements", "r") + f_DomainElements_Backup = open("f_DomainElements_Backup", "r") + for line in range(element_nbr): + # initial domain elements shall not have been impacted by current test + if (line < element_nbr_init): + element_name = f_DomainElements.readline().strip('\n') + element_name_backup = f_DomainElements_Backup.readline().strip('\n') + assert element_name==element_name_backup, "ERROR : Error while modifying domain elements on domain %s" % (self.domain_name) + # last listed element shall be equal to the only one element added previously + else: + element_name = f_DomainElements.readline().strip('\n') + assert element_name==str(self.elem_2_path), "ERROR : Error while modifying domain elements on domain %s" % (self.domain_name) + log.I("Actual domain %s elements names conform to expected values" % (self.domain_name)) + # Temporary files deletion + f_DomainElements.close() + f_DomainElements_Backup.close() + os.remove("f_DomainElements_Backup") + os.remove("f_DomainElements") + # Removing created domain element + out, err = self.pfw.sendCmd("removeElement", str(self.domain_name), str(self.elem_2_path)) + assert err == None, "ERROR : command [removeElement] - Error while removing domain element %s" % (self.elem_2_path) + assert out == "Done", "ERROR : command [removeElement] - Error while removing domain element %s" % (self.elem_2_path) + + def test_addElement_Error(self): + """ + Testing addElement error + ------------------------ + Test case description : + ~~~~~~~~~~~~~~~~~~~~~~~ + - add an already existing domain element + - add a non defined domain element + Tested commands : + ~~~~~~~~~~~~~~~~~ + - [addElement] function + - [listDomainElements] function + Expected result : + ~~~~~~~~~~~~~~~~~ + - Errors correctly detected + - No side effect + """ + log.D(self.test_addElement_Error.__doc__) + + # List and backup initial domain elements + log.I("Listing initial domain %s elements" % (self.domain_name)) + out, err = self.pfw.sendCmd("listDomainElements",str(self.domain_name)) + assert err == None, "ERROR : command [listDomainElements] - Error while listing domain elements" + f_DomainElements_Backup = open("f_DomainElements_Backup", "w") + f_DomainElements_Backup.write(out) + f_DomainElements_Backup.close() + log.I("command [listDomainElements] correctly executed") + f_DomainElements_Backup = open("f_DomainElements_Backup", "r") + element_nbr_init = 0 + line=f_DomainElements_Backup.readline() + while line!="": + line=f_DomainElements_Backup.readline() + element_nbr_init+=1 + f_DomainElements_Backup.close() + log.I("Actual domain %s elements number is %s" % (self.domain_name,element_nbr_init)) + + # Adding a new domain element errors + log.I("Adding an already existing domain element to domain %s" % (self.domain_name)) + out, err = self.pfw.sendCmd("addElement", str(self.domain_name), str(self.elem_0_path)) + assert err == None, "ERROR : command [addElement] - Error while adding new domain element %s" % (self.elem_0_path) + assert out != "Done", "ERROR : command [addElement] - Error not detected while adding an already existing domain element to domain %s" % (self.domain_name) + log.I("Adding a non defined domain element to domain %s" % (self.domain_name)) + out, err = self.pfw.sendCmd("addElement", str(self.domain_name), "Non_Defined_Element") + assert err == None, "ERROR : command [addElement] - Error while adding new domain element %s" % (self.elem_2_path) + assert out != "Done", "ERROR : command [addElement] - Error not detected while adding a non defined domain element to domain %s" % (self.domain_name) + log.I("Error when adding elements correctly detected") + + # Checking final domain elements + log.I("Listing final domain %s elements" % (self.domain_name)) + out, err = self.pfw.sendCmd("listDomainElements",str(self.domain_name)) + assert err == None, "ERROR : command [listDomainElements] - Error while listing domain elements" + f_DomainElements = open("f_DomainElements", "w") + f_DomainElements.write(out) + f_DomainElements.close() + log.I("command [listDomainElements] correctly executed") + f_DomainElements = open("f_DomainElements", "r") + element_nbr = 0 + line=f_DomainElements.readline() + while line!="": + line=f_DomainElements.readline() + element_nbr+=1 + f_DomainElements.close() + log.I("Actual domain %s elements number is %s" % (self.domain_name,element_nbr)) + log.I("Checking domain %s elements names conformity" % (self.domain_name)) + f_DomainElements = open("f_DomainElements", "r") + f_DomainElements_Backup = open("f_DomainElements_Backup", "r") + for line in range(element_nbr): + # initial domain elements shall not have been impacted by current test + element_name = f_DomainElements.readline().strip('\n') + element_name_backup = f_DomainElements_Backup.readline().strip('\n') + assert element_name==element_name_backup, "ERROR : domain %s elements affected by addElement errors" % (self.domain_name) + log.I("Actual domain %s elements names conform to expected values" % (self.domain_name)) + # Temporary files deletion + f_DomainElements.close() + f_DomainElements_Backup.close() + os.remove("f_DomainElements_Backup") + os.remove("f_DomainElements") + + def test_removeElement_Error(self): + """ + Testing removeElement error + --------------------------- + Test case description : + ~~~~~~~~~~~~~~~~~~~~~~~ + - remove a non defined domain element + - remove a domain element on a wrong domain name + Tested commands : + ~~~~~~~~~~~~~~~~~ + - [removeElement] function + - [listDomainElements] function + Expected result : + ~~~~~~~~~~~~~~~~~ + - Errors correctly detected + - No side effect + """ + log.D(self.test_removeElement_Error.__doc__) + + # List and backup initial domain elements + log.I("Listing initial domain %s elements" % (self.domain_name)) + out, err = self.pfw.sendCmd("listDomainElements",str(self.domain_name)) + assert err == None, "ERROR : command [listDomainElements] - Error while listing domain elements" + f_DomainElements_Backup = open("f_DomainElements_Backup", "w") + f_DomainElements_Backup.write(out) + f_DomainElements_Backup.close() + log.I("command [listDomainElements] correctly executed") + f_DomainElements_Backup = open("f_DomainElements_Backup", "r") + element_nbr_init = 0 + line=f_DomainElements_Backup.readline() + while line!="": + line=f_DomainElements_Backup.readline() + element_nbr_init+=1 + f_DomainElements_Backup.close() + log.I("Actual domain %s elements number is %s" % (self.domain_name,element_nbr_init)) + + # Error when removing domain elements + log.I("Removing a domain element from a non defined domain") + out, err = self.pfw.sendCmd("removeElement", "Wrong_Domain_Name", str(self.elem_0_path)) + assert err == None, "ERROR : command [removeElement] - Error when removing domain element %s" % (self.elem_0_path) + assert out != "Done", "ERROR : command [removeElement] - Error not detected when removing domain element %s from an undefined domain"% (self.elem_0_path) + log.I("Removing a non existent domain element from domain %s" % (self.domain_name)) + out, err = self.pfw.sendCmd("removeElement", str(self.domain_name), "Wrong_Element_Name") + assert err == None, "ERROR : command [removeElement] - Error when removing domain element %s" % (self.elem_0_path) + assert out != "Done", "ERROR : command [removeElement] - Error not detected when removing a non existent domain element from domain %s" % (self.domain_name) + log.I("Error when removing elements correctly detected") + + # Checking final domain elements + log.I("Listing final domain %s elements" % (self.domain_name)) + out, err = self.pfw.sendCmd("listDomainElements",str(self.domain_name)) + assert err == None, "ERROR : command [listDomainElements] - Error while listing domain elements" + f_DomainElements = open("f_DomainElements", "w") + f_DomainElements.write(out) + f_DomainElements.close() + log.I("command [listDomainElements] correctly executed") + f_DomainElements = open("f_DomainElements", "r") + element_nbr = 0 + line=f_DomainElements.readline() + while line!="": + line=f_DomainElements.readline() + element_nbr+=1 + f_DomainElements.close() + log.I("Actual domain %s elements number is %s" % (self.domain_name,element_nbr)) + log.I("Checking domain %s elements names conformity" % (self.domain_name)) + f_DomainElements = open("f_DomainElements", "r") + f_DomainElements_Backup = open("f_DomainElements_Backup", "r") + for line in range(element_nbr): + # initial domain elements shall not have been impacted by current test + element_name = f_DomainElements.readline().strip('\n') + element_name_backup = f_DomainElements_Backup.readline().strip('\n') + assert element_name==element_name_backup, "ERROR : domain %s elements affected by addElement errors" % (self.domain_name) + log.I("Actual domain %s elements names conform to expected values" % (self.domain_name)) + # Temporary files deletion + f_DomainElements.close() + f_DomainElements_Backup.close() + os.remove("f_DomainElements_Backup") + os.remove("f_DomainElements") diff --git a/test/functional-tests/PfwTestCase/Domains/tDomain_Elements_Sequences.py b/test/functional-tests/PfwTestCase/Domains/tDomain_Elements_Sequences.py new file mode 100644 index 0000000..1544cae --- /dev/null +++ b/test/functional-tests/PfwTestCase/Domains/tDomain_Elements_Sequences.py @@ -0,0 +1,294 @@ +# -*-coding:utf-8 -* + +# Copyright (c) 2011-2015, Intel Corporation +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation and/or +# other materials provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors +# may be used to endorse or promote products derived from this software without +# specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR +# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +""" +Element Sequence testcases + +List of tested functions : +-------------------------- + - [setElementSequence] function + - [getElementSequence] function + +Test cases : +------------ + - Testing setElementSequence errors + - Testing getElementSequence errors + - Testing nominal case +""" +import os +from Util.PfwUnitTestLib import PfwTestCase +from Util import ACTLogging +log=ACTLogging.Logger() + +class TestCases(PfwTestCase): + def setUp(self): + self.pfw.sendCmd("setTuningMode", "on") + self.domain_name = "Domain_0" + self.elem_0_path = "/Test/Test/TEST_DIR" + self.elem_1_path = "/Test/Test/TEST_DOMAIN_0" + self.elem_2_path = "/Test/Test/TEST_DOMAIN_1" + self.configuration = "Conf_0" + + def tearDown(self): + self.pfw.sendCmd("setTuningMode", "off") + + def test_Nominal_Case(self): + """ + Testing nominal case + -------------------- + Test case description : + ~~~~~~~~~~~~~~~~~~~~~~~ + - set a new sequences order for a selected configuration + Tested commands : + ~~~~~~~~~~~~~~~~~ + - [setElementSequence] function + - [getElementSequence] function + Expected result : + ~~~~~~~~~~~~~~~~~ + - all operations succeed + - new sequences order conform to expected order + """ + log.D(self.test_Nominal_Case.__doc__) + + # Adding new domain elements + log.I("Working on domain %s" % (self.domain_name)) + log.I("Adding a new domain element to domain %s" % (self.domain_name)) + out, err = self.pfw.sendCmd("addElement", str(self.domain_name), str(self.elem_1_path)) + assert err == None, "ERROR : command [addElement] - Error while adding new domain element %s" % (self.elem_1_path) + assert out == "Done", "ERROR : command [addElement] - Error while adding new domain element %s" % (self.elem_1_path) + log.I("Adding a new domain element to domain %s" % (self.domain_name)) + out, err = self.pfw.sendCmd("addElement", str(self.domain_name), str(self.elem_2_path)) + assert err == None, "ERROR : command [addElement] - Error while adding new domain element %s" % (self.elem_2_path) + assert out == "Done", "ERROR : command [addElement] - Error while adding new domain element %s" % (self.elem_2_path) + log.I("New domain elements %s and %s added to domain %s" % (self.elem_1_path, self.elem_2_path, self.domain_name)) + + # Getting elements sequence from selected configuration + log.I("Getting elements sequence from configuration %s" % (self.configuration)) + out, err = self.pfw.sendCmd("getElementSequence", self.domain_name, self.configuration) + assert err == None, "ERROR : command [getElementSequence] - Error while listing elements sequence for configuration %s" % (self.configuration) + log.I("Listing elements sequence for configuration %s correctly executed :\n%s" % (self.configuration, out)) + + # Setting new elements sequence order for selected configuration + log.I("Setting new elements sequence order for configuration %s" % (self.configuration)) + out, err = self.pfw.sendCmd("setElementSequence", self.domain_name, self.configuration, self.elem_2_path, self.elem_0_path, self.elem_1_path) + assert err == None, "ERROR : command [setElementSequence] - Error while setting new elements sequence for configuration %s" % (self.configuration) + assert out == "Done", "ERROR : command [setElementSequence] - Error while setting new elements sequence for configuration %s" % (self.configuration) + log.I("Setting new elements sequence for configuration %s correctly executed") + out, err = self.pfw.sendCmd("getElementSequence", self.domain_name, self.configuration) + assert err == None, "ERROR : command [getElementSequence] - Error while listing elements sequence for configuration %s" % (self.configuration) + log.I("New elements sequence for configuration %s :\n%s" % (self.configuration, out)) + + # Checking new elements sequence order conformity for selected configuration + log.I("Checking new elements sequence order for configuration") + f_ConfigElementsOrder = open("f_ConfigElementsOrder", "w") + f_ConfigElementsOrder.write(out) + f_ConfigElementsOrder.close() + f_ConfigElementsOrder = open("f_ConfigElementsOrder", "r") + element_name = f_ConfigElementsOrder.readline().strip('\n') + assert element_name==self.elem_2_path, "ERROR : Error while modifying configuration %s elements order on domain %s" % (self.configuration) + element_name = f_ConfigElementsOrder.readline().strip('\n') + assert element_name==self.elem_0_path, "ERROR : Error while modifying configuration %s elements order on domain %s" % (self.configuration) + element_name = f_ConfigElementsOrder.readline().strip('\n') + assert element_name==self.elem_1_path, "ERROR : Error while modifying configuration %s elements order on domain %s" % (self.configuration) + log.I("New elements sequence order conform to expected order for configuration %s" % (self.configuration)) + # Closing and removing temp file + f_ConfigElementsOrder.close() + os.remove("f_ConfigElementsOrder") + # Removing created domain element + out, err = self.pfw.sendCmd("removeElement", str(self.domain_name), str(self.elem_1_path)) + assert err == None, "ERROR : command [removeElement] - Error while removing domain element %s" % (self.elem_1_path) + assert out == "Done", "ERROR : command [removeElement] - Error while removing domain element %s" % (self.elem_1_path) + out, err = self.pfw.sendCmd("removeElement", str(self.domain_name), str(self.elem_2_path)) + assert err == None, "ERROR : command [removeElement] - Error while removing domain element %s" % (self.elem_2_path) + assert out == "Done", "ERROR : command [removeElement] - Error while removing domain element %s" % (self.elem_2_path) + + def test_setElementSequence_errors(self): + """ + Testing setElementSequence_errors + --------------------------------- + Test case description : + ~~~~~~~~~~~~~~~~~~~~~~~ + - Setting an element not belonging to configuration + - Setting undefined element in sequence order + Tested commands : + ~~~~~~~~~~~~~~~~~ + - [setElementSequence] function + Expected result : + ~~~~~~~~~~~~~~~~~ + - all errors correctly detected + - no impact on initial sequences order + """ + log.D(self.test_setElementSequence_errors.__doc__) + + # Adding a new domain element + log.I("Working on domain %s" % (self.domain_name)) + log.I("Adding a new domain element to domain %s" % (self.domain_name)) + out, err = self.pfw.sendCmd("addElement", str(self.domain_name), str(self.elem_1_path)) + assert err == None, "ERROR : command [addElement] - Error while adding new domain element %s" % (self.elem_1_path) + assert out == "Done", "ERROR : command [addElement] - Error while adding new domain element %s" % (self.elem_1_path) + log.I("New domain element %s added to domain %s" % (self.elem_1_path, self.domain_name)) + + # Getting elements sequence from selected configuration + log.I("Getting elements sequence from configuration %s" % (self.configuration)) + out, err = self.pfw.sendCmd("getElementSequence", self.domain_name, self.configuration) + assert err == None, "ERROR : command [getElementSequence] - Error while listing elements sequence for configuration %s" % (self.configuration) + log.I("Listing elements sequence for configuration %s correctly executed :\n%s" % (self.configuration, out)) + + # Elements sequence backup + f_ConfigElementsOrder_Backup = open("f_ConfigElementsOrder_Backup", "w") + f_ConfigElementsOrder_Backup.write(out) + f_ConfigElementsOrder_Backup.close() + + # Setting an element not belonging to configuration in sequence order + log.I("Setting an element not belonging to configuration %s in sequence order" % (self.configuration)) + out, err = self.pfw.sendCmd("setElementSequence", self.domain_name, self.configuration, self.elem_2_path, self.elem_0_path, self.elem_1_path) + assert err == None, "ERROR : command [setElementSequence] - Error while setting elements sequence for configuration %s" % (self.configuration) + assert out != "Done", "ERROR : command [setElementSequence] - Error not detected when setting an element not belonging to configuration" + + # Setting undefined element in sequence order for selected configuration + log.I("Setting undefined element in sequence order for configuration %s" % (self.configuration)) + out, err = self.pfw.sendCmd("setElementSequence", self.domain_name, self.configuration, "Wrong_Element_Name", self.elem_0_path, self.elem_1_path) + assert err == None, "ERROR : command [setElementSequence] - Error while setting elements sequence for configuration %s" % (self.configuration) + assert out != "Done", "ERROR : command [getElementSequence] - Error not detected when setting an undefined element to configuration" + + # Getting elements sequence from selected configuration for checking purpose + out, err = self.pfw.sendCmd("getElementSequence", self.domain_name, self.configuration) + assert err == None, "ERROR : command [getElementSequence] - Error while listing elements sequence for configuration %s" % (self.configuration) + # Elements sequence backup + f_ConfigElementsOrder = open("f_ConfigElementsOrder", "w") + f_ConfigElementsOrder.write(out) + f_ConfigElementsOrder.close() + + # Checking new elements sequence order conformity for selected configuration + log.I("Checking new elements sequence order for configuration") + f_ConfigElementsOrder = open("f_ConfigElementsOrder", "r") + f_ConfigElementsOrder_Backup = open("f_ConfigElementsOrder_Backup", "r") + new_element_name = f_ConfigElementsOrder.readline().strip('\n') + element_name = f_ConfigElementsOrder_Backup.readline().strip('\n') + assert element_name==new_element_name, "ERROR : setElementSequence errors have affected elements order on domain %s" % (self.configuration) + new_element_name = f_ConfigElementsOrder.readline().strip('\n') + element_name = f_ConfigElementsOrder_Backup.readline().strip('\n') + assert element_name==new_element_name, "ERROR : setElementSequence errors have affected elements order on domain %s" % (self.configuration) + log.I("Elements sequence order not affected by setElementSequence errors") + + # Closing and removing temp file + f_ConfigElementsOrder.close() + f_ConfigElementsOrder_Backup.close() + os.remove("f_ConfigElementsOrder") + os.remove("f_ConfigElementsOrder_Backup") + # Removing created domain element + out, err = self.pfw.sendCmd("removeElement", str(self.domain_name), str(self.elem_1_path)) + assert err == None, "ERROR : command [removeElement] - Error while removing domain element %s" % (self.elem_1_path) + assert out == "Done", "ERROR : command [removeElement] - Error while removing domain element %s" % (self.elem_1_path) + + def test_getElementSequence_errors(self): + """ + Testing getElementSequence_errors + --------------------------------- + Test case description : + ~~~~~~~~~~~~~~~~~~~~~~~ + - Getting an element sequence on a wrong domain name + - Getting an element sequence on a wrong configuration name + Tested commands : + ~~~~~~~~~~~~~~~~~ + - [getElementSequence] function + Expected result : + ~~~~~~~~~~~~~~~~~ + - all errors correctly detected + - no impact on initial sequences order + """ + log.D(self.test_getElementSequence_errors.__doc__) + + # Adding new domain elements + log.I("Adding a new domain element to domain %s" % (self.domain_name)) + out, err = self.pfw.sendCmd("addElement", str(self.domain_name), str(self.elem_1_path)) + assert err == None, "ERROR : command [addElement] - Error while adding new domain element %s" % (self.elem_1_path) + assert out == "Done", "ERROR : command [addElement] - Error while adding new domain element %s" % (self.elem_1_path) + log.I("Adding a new domain element to domain %s" % (self.domain_name)) + out, err = self.pfw.sendCmd("addElement", str(self.domain_name), str(self.elem_2_path)) + assert err == None, "ERROR : command [addElement] - Error while adding new domain element %s" % (self.elem_2_path) + assert out == "Done", "ERROR : command [addElement] - Error while adding new domain element %s" % (self.elem_2_path) + log.I("New domain elements %s and %s added to domain %s" % (self.elem_1_path, self.elem_2_path, self.domain_name)) + + # Getting elements sequence from selected configuration + log.I("Getting elements sequence from configuration %s" % (self.configuration)) + out, err = self.pfw.sendCmd("getElementSequence", self.domain_name, self.configuration) + assert err == None, "ERROR : command [getElementSequence] - Error while listing elements sequence for configuration %s" % (self.configuration) + log.I("Listing elements sequence for configuration %s correctly executed :\n%s" % (self.configuration, out)) + + # Elements sequence backup + f_ConfigElementsOrder_Backup = open("f_ConfigElementsOrder_Backup", "w") + f_ConfigElementsOrder_Backup.write(out) + f_ConfigElementsOrder_Backup.close() + + # Getting an element sequence on a wrong domain name + log.I("Getting an element sequence on a wrong domain name") + out, err = self.pfw.sendCmd("getElementSequence", "Wrong_Domain_Name", self.configuration) + assert err == None, "ERROR : command [getElementSequence] - Error when getting elements sequence for configuration %s" % (self.configuration) + assert out != "Done", "ERROR : command [getElementSequence] - Error not detected when getting elements sequence for a wrong domain name" + + # Getting an element sequence on a wrong configuration name + log.I("Getting an element sequence on a wrong configuration name") + out, err = self.pfw.sendCmd("getElementSequence", self.domain_name, "Wrong_Configuration_Name") + assert err == None, "ERROR : command [getElementSequence] - Error when getting elements sequence on a wrong configuration name" + assert out != "Done", "ERROR : command [getElementSequence] - Error not detected when getting elements sequence on a wrong configuration name" + + # Getting elements sequence from selected configuration for checking purpose + out, err = self.pfw.sendCmd("getElementSequence", self.domain_name, self.configuration) + assert err == None, "ERROR : command [getElementSequence] - Error while listing elements sequence for configuration %s" % (self.configuration) + # Elements sequence backup + f_ConfigElementsOrder = open("f_ConfigElementsOrder", "w") + f_ConfigElementsOrder.write(out) + f_ConfigElementsOrder.close() + + # Checking new elements sequence order conformity for selected configuration + log.I("Checking new elements sequence order for configuration") + f_ConfigElementsOrder = open("f_ConfigElementsOrder", "r") + f_ConfigElementsOrder_Backup = open("f_ConfigElementsOrder_Backup", "r") + new_element_name = f_ConfigElementsOrder.readline().strip('\n') + element_name = f_ConfigElementsOrder_Backup.readline().strip('\n') + assert element_name==new_element_name, "ERROR : getElementSequence errors have affected elements order on domain %s" % (self.configuration) + new_element_name = f_ConfigElementsOrder.readline().strip('\n') + element_name = f_ConfigElementsOrder_Backup.readline().strip('\n') + assert element_name==new_element_name, "ERROR : getElementSequence errors have affected elements order on domain %s" % (self.configuration) + log.I("Elements sequence order not affected by getElementSequence errors") + + # Closing and removing temp file + f_ConfigElementsOrder.close() + f_ConfigElementsOrder_Backup.close() + os.remove("f_ConfigElementsOrder") + os.remove("f_ConfigElementsOrder_Backup") + # Removing created domain element + out, err = self.pfw.sendCmd("removeElement", str(self.domain_name), str(self.elem_1_path)) + assert err == None, "ERROR : command [removeElement] - Error while removing domain element %s" % (self.elem_1_path) + assert out == "Done", "ERROR : command [removeElement] - Error while removing domain element %s" % (self.elem_1_path) + out, err = self.pfw.sendCmd("removeElement", str(self.domain_name), str(self.elem_2_path)) + assert err == None, "ERROR : command [removeElement] - Error while removing domain element %s" % (self.elem_2_path) + assert out == "Done", "ERROR : command [removeElement] - Error while removing domain element %s" % (self.elem_2_path) diff --git a/test/functional-tests/PfwTestCase/Domains/tDomain_Rules.py b/test/functional-tests/PfwTestCase/Domains/tDomain_Rules.py new file mode 100644 index 0000000..0084e22 --- /dev/null +++ b/test/functional-tests/PfwTestCase/Domains/tDomain_Rules.py @@ -0,0 +1,443 @@ +# -*-coding:utf-8 -* + +# Copyright (c) 2011-2015, Intel Corporation +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation and/or +# other materials provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors +# may be used to endorse or promote products derived from this software without +# specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR +# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +""" +Rules management testcases + +List of tested functions : +-------------------------- + - [setRule] function + - [clearRule] function + - [getRule] function + +Test cases : +------------ + - Testing clearRule errors + - Testing setRule errors + - Testing getRule errors + - Testing nominal case +""" +from Util.PfwUnitTestLib import PfwTestCase +from Util import ACTLogging +log=ACTLogging.Logger() + +# Test of Domains - Rules +class TestCases(PfwTestCase): + def setUp(self): + self.pfw.sendCmd("setTuningMode", "on") + self.domain_name = "domain_test" + self.conf_1 = "conf_1" + self.conf_2 = "conf_2" + self.rule_1 = "Any{Crit_0 Includes State_0x2, Crit_1 IsNot State_1}" + self.rule_2 = "All{Crit_0 Includes State_0x1, Crit_1 Is State_1}" + self.rule_error_1 = "All{Crit_Error Includes State_0x1, Crit_1 Is State_1}" + self.rule_error_2 = "Any{Crit_0 Includes State_0x2, Crit_0 IsNot State_1}" + self.rule_error_3 = "Ay{Crit_0 Includes State_0x2, Crit_1 IsNot State_1}" + self.rule_error_4 = "All{Crit_0 Includes State_0x4, Crit_1 IsNot State_1}" + self.rule_error_5 = "All{Crit_0 Includes State_0x2, Crit_1 IsNot 1}" + self.rule_error_nbr = 5 + + def tearDown(self): + self.pfw.sendCmd("setTuningMode", "off") + + def test_ClearRule_Errors(self): + """ + Testing configuration creation error + ------------------------------------ + Test case description : + ~~~~~~~~~~~~~~~~~~~~~~~ + - Clearing rule on a non-existent configuration + - Clearing rule on a non-existent domain + - Clearing rule with wrong parameters order + Tested commands : + ~~~~~~~~~~~~~~~~~ + - [clearRule] function + - [setRule] function + - [getRule] function + - [createDomain] function + - [createConfiguration] function + - [deleteDomain] function + Expected result : + ~~~~~~~~~~~~~~~~~ + - all errors are detected + - no rule is deleted + """ + log.D(self.test_ClearRule_Errors.__doc__) + # New domain creation for testing purpose + log.I("New domain creation for testing purpose : %s" % (self.domain_name)) + log.I("command [createDomain]") + out, err = self.pfw.sendCmd("createDomain",self.domain_name, "") + assert out == "Done", out + assert err == None, "ERROR : command [createDomain] - Error while creating domain %s" % (self.domain_name) + log.I("command [createDomain] correctly executed") + log.I("Domain %s created" % (self.domain_name)) + + # New configurations creation for testing purpose + log.I("New configuration %s creation for domain %s for testing purpose" % (self.conf_1,self.domain_name)) + log.I("command [createConfiguration]") + out, err = self.pfw.sendCmd("createConfiguration",self.domain_name,self.conf_1) + assert out == "Done", out + assert err == None, "ERROR : command [createConfiguration] - Error while creating configuration %s" % (self.conf_1) + log.I("command [createConfiguration] correctly executed") + log.I("Configuration %s created for domain %s" % (self.conf_1,self.domain_name)) + log.I("New configuration %s creation for domain %s for testing purpose" % (self.conf_2,self.domain_name)) + log.I("command [createConfiguration]") + out, err = self.pfw.sendCmd("createConfiguration",self.domain_name,self.conf_2) + assert out == "Done", out + assert err == None, "ERROR : command [createConfiguration] - Error while creating configuration %s" % (self.conf_2) + log.I("command [createConfiguration] correctly executed") + log.I("Configuration %s created for domain %s" % (self.conf_2,self.domain_name)) + + # Applying rules to configurations + log.I("Applying rules to configurations %s and %s from domain %s" % (self.conf_1,self.conf_2,self.domain_name)) + log.I("command [setRule]") + out, err = self.pfw.sendCmd("setRule",self.domain_name,self.conf_1,self.rule_1) + assert err == None, "ERROR : command [setRule] - Error while setting rule for configurations %s" % (self.conf_1) + assert out == "Done", "FAIL : command [setRule] - Error while setting rule for configuration %s" % (self.conf_1) + log.I("command [setRule] correctly executed") + log.I("rule correctly created for configuration %s" % (self.conf_1)) + out, err = self.pfw.sendCmd("setRule",self.domain_name,self.conf_2,self.rule_2) + assert err == None, "ERROR : command [setRule] - Error while setting rule for configurations %s" % (self.conf_2) + assert out == "Done", "FAIL : command [setRule] - Error while setting rule for configuration %s" % (self.conf_2) + log.I("command [setRule] correctly executed") + log.I("rule correctly created for configuration %s" % (self.conf_2)) + + # Clearing rule errors + log.I("Clearing a rule on domain %s to a non-existent configuration" % (self.domain_name)) + log.I("command [clearRule]") + out, err = self.pfw.sendCmd("clearRule",self.domain_name,"Wrong_Config_Name") + assert err == None, "ERROR : command [clearRule] - Error while clearing rule on domain %s to a non-existent configuration" % (self.domain_name) + assert out != "Done", "ERROR : command [clearRule] - Error not detected while clearing rule on domain %s to a non-existent configuration" % (self.domain_name) + log.I("error correctly detected when clearing a rule to a non-existent configuration") + log.I("Clearing a rule on a non-existent domain") + log.I("command [clearRule]") + out, err = self.pfw.sendCmd("clearRule","Wrong_Domain_Name",self.conf_2) + assert err == None, "ERROR : command [clearRule] - Error while clearing rule on a non-existent domain" + assert out != "Done", "ERROR : command [clearRule] - Error not detected while clearing rule on a non-existent domain" + log.I("error correctly detected while clearing rule on a non-existent domain") + log.I("Clearing a rule with wrong parameters order") + log.I("command [clearRule]") + out, err = self.pfw.sendCmd("clearRule",self.conf_1,self.domain_name) + assert err == None, "ERROR : command [clearRule] - Error when clearing a rule with incorrect paramaters order" + assert out != "Done", "ERROR : command [clearRule] - Error not detected when clearing a rule with incorrect paramaters order" + log.I("error correctly detected when clearing a rule with incorrect paramaters order on domain %s and configuration %s" % (self.domain_name,self.conf_1)) + + #Checking that no rule has been cleared + out, err = self.pfw.sendCmd("getRule",self.domain_name,self.conf_1) + assert out == self.rule_1, "FAIL : command [clearRule] - clearRule error has affected configuration %s" % (self.conf_1) + out, err = self.pfw.sendCmd("getRule",self.domain_name,self.conf_2) + assert out == self.rule_2, "FAIL : command [clearRule] - clearRule error has affected configuration %s" % (self.conf_2) + log.I("command [ClearRule] correctly executed, no impact due to clearing errors") + log.I("no rule removed from configurations %s and %s on domain %s" % (self.conf_1,self.conf_2,self.domain_name)) + + # New domain deletion + log.I("Domain %s deletion" % (self.domain_name)) + log.I("command [deleteDomain]") + out, err = self.pfw.sendCmd("deleteDomain",self.domain_name, "") + assert out == "Done", out + assert err == None, "ERROR : command [deleteDomain] - Error while delting domain %s" % (self.domain_name) + log.I("command [deleteDomain] correctly executed") + log.I("Domain %s deleted" % (self.domain_name)) + + def test_SetRule_Errors(self): + """ + Testing setRule errors + ---------------------- + Test case description : + ~~~~~~~~~~~~~~~~~~~~~~~ + - Setting rule on a non-existent configuration + - Setting rule on a non-existent domain + - Setting various incorrect format rules + Tested commands : + ~~~~~~~~~~~~~~~~~ + - [setRule] function + - [getRule] function + - [createDomain] function + - [createConfiguration] function + - [deleteDomain] function + Expected result : + ~~~~~~~~~~~~~~~~~ + - all errors are detected + - no new rule is created + """ + log.D(self.test_SetRule_Errors.__doc__) + # New domain creation for testing purpose + log.I("New domain creation for testing purpose : %s" % (self.domain_name)) + log.I("command [createDomain]") + out, err = self.pfw.sendCmd("createDomain",self.domain_name, "") + assert out == "Done", out + assert err == None, "ERROR : command [createDomain] - Error while creating domain %s" % (self.domain_name) + log.I("command [createDomain] correctly executed") + log.I("Domain %s created" % (self.domain_name)) + + # New configuration creation for testing purpose + log.I("New configuration %s creation for domain %s for testing purpose" % (self.conf_1,self.domain_name)) + log.I("command [createConfiguration]") + out, err = self.pfw.sendCmd("createConfiguration",self.domain_name,self.conf_1) + assert out == "Done", out + assert err == None, "ERROR : command [createConfiguration] - Error while creating configuration %s" % (self.conf_1) + log.I("command [createConfiguration] correctly executed") + log.I("Configuration %s created for domain %s" % (self.conf_1,self.domain_name)) + + # setRule :basic error cases + log.I("Applying a new rule on domain %s to a non-existent configuration" % (self.domain_name)) + log.I("command [setRule]") + out, err = self.pfw.sendCmd("setRule",self.domain_name,"Wrong_Config_Name",self.rule_1) + assert err == None, "ERROR : command [setRule] - Error while setting rule on domain %s to a non-existent configuration" % (self.domain_name) + assert out != "Done", "ERROR : command [setRule] - Error not detected while setting rule on domain %s to a non-existent configuration" % (self.domain_name) + log.I("error correctly detected when creating a rule to a non-existent configuration") + log.I("Applying a new rule on a non-existent domain") + log.I("command [setRule]") + out, err = self.pfw.sendCmd("setRule","Wrong_Domain_Name",self.conf_1,self.rule_1) + assert err == None, "ERROR : command [setRule] - Error while setting rule on a non-existent domain" + assert out != "Done", "ERROR : command [setRule] - Error not detected while setting rule on a non-existent domain" + log.I("error correctly detected while setting rule on a non-existent domain") + log.I("Applying a new rule with incorrect format") + log.I("command [setRule]") + out, err = self.pfw.sendCmd("setRule",self.domain_name,self.conf_1,"Wrong_Rule_Format") + assert err == None, "ERROR : command [setRule] - Error when setting incorrect format rule" + assert out != "Done", "ERROR : command [setRule] - Error not detected when setting incorrect format rule" + log.I("error correctly detected when setting incorrect format rule on domain %s and configuration %s" % (self.domain_name,self.conf_1)) + + # setRule : various rules errors + log.I("Various rules errors setting :") + for index in range (self.rule_error_nbr): + log.I("Rule error number %s" % (str(index))) + rule_name = "".join(["self.rule_error_", "_", str(index)]) + out, err = self.pfw.sendCmd("setRule",self.domain_name,self.conf_1, rule_name) + assert err == None, "ERROR : command [setRule] - Error when setting incorrect format rule %s" % (str(rule_name)) + assert out != "Done", "ERROR : command [setRule] - Error not detected when setting incorrect format rule %s" % (str(rule_name)) + log.I("error correctly detected when setting incorrect format rule on domain %s and configuration %s" % (self.domain_name,self.conf_1)) + + #Checking that no rule has been created + out, err = self.pfw.sendCmd("getRule",self.domain_name,self.conf_1) + assert out == "<none>", "FAIL : command [setRule] - setRule not working for configuration %s" % (self.conf_1) + log.I("command [setRule] correctly executed, no impact due to setting errors") + log.I("no rule added to configurations %s on domain %s" % (self.conf_1,self.domain_name)) + + # New domain deletion + log.I("Domain %s deletion" % (self.domain_name)) + log.I("command [deleteDomain]") + out, err = self.pfw.sendCmd("deleteDomain",self.domain_name, "") + assert out == "Done", out + assert err == None, "ERROR : command [deleteDomain] - Error while delting domain %s" % (self.domain_name) + log.I("command [deleteDomain] correctly executed") + log.I("Domain %s deleted" % (self.domain_name)) + + def test_GetRule_Errors(self): + """ + Testing getRule errors + ---------------------- + Test case description : + ~~~~~~~~~~~~~~~~~~~~~~~ + - Getting rule on a non-existent configuration + - Getting rule on a non-existent domain + - Getting rule with wrong parameters order + Tested commands : + ~~~~~~~~~~~~~~~~~ + - [getRule] function + - [setRule] function + - [clearRule] function + - [createDomain] function + - [createConfiguration] function + - [deleteDomain] function + Expected result : + ~~~~~~~~~~~~~~~~~ + - all errors are detected + """ + log.D(self.test_GetRule_Errors.__doc__) + # New domain creation for testing purpose + log.I("New domain creation for testing purpose : %s" % (self.domain_name)) + log.I("command [createDomain]") + out, err = self.pfw.sendCmd("createDomain",self.domain_name, "") + assert out == "Done", out + assert err == None, "ERROR : command [createDomain] - Error while creating domain %s" % (self.domain_name) + log.I("command [createDomain] correctly executed") + log.I("Domain %s created" % (self.domain_name)) + + # New configurations creation for testing purpose + log.I("New configuration %s creation for domain %s for testing purpose" % (self.conf_1,self.domain_name)) + log.I("command [createConfiguration]") + out, err = self.pfw.sendCmd("createConfiguration",self.domain_name,self.conf_1) + assert out == "Done", out + assert err == None, "ERROR : command [createConfiguration] - Error while creating configuration %s" % (self.conf_1) + log.I("command [createConfiguration] correctly executed") + log.I("Configuration %s created for domain %s" % (self.conf_1,self.domain_name)) + log.I("New configuration %s creation for domain %s for testing purpose" % (self.conf_2,self.domain_name)) + log.I("command [createConfiguration]") + out, err = self.pfw.sendCmd("createConfiguration",self.domain_name,self.conf_2) + assert out == "Done", out + assert err == None, "ERROR : command [createConfiguration] - Error while creating configuration %s" % (self.conf_2) + log.I("command [createConfiguration] correctly executed") + log.I("Configuration %s created for domain %s" % (self.conf_2,self.domain_name)) + + # Applying rules to configurations + log.I("Applying rules to configurations %s and %s from domain %s" % (self.conf_1,self.conf_2,self.domain_name)) + log.I("command [setRule]") + out, err = self.pfw.sendCmd("setRule",self.domain_name,self.conf_1,self.rule_1) + assert err == None, "ERROR : command [setRule] - Error while setting rule for configurations %s" % (self.conf_1) + assert out == "Done", "FAIL : command [setRule] - Error while setting rule for configuration %s" % (self.conf_1) + log.I("command [setRule] correctly executed") + log.I("rule correctly created for configuration %s" % (self.conf_1)) + out, err = self.pfw.sendCmd("setRule",self.domain_name,self.conf_2,self.rule_2) + assert err == None, "ERROR : command [setRule] - Error while setting rule for configurations %s" % (self.conf_2) + assert out == "Done", "FAIL : command [setRule] - Error while setting rule for configuration %s" % (self.conf_2) + log.I("command [setRule] correctly executed") + log.I("rule correctly created for configuration %s" % (self.conf_2)) + + # Getting rule errors + log.I("Getting a rule on domain %s from a non-existent configuration" % (self.domain_name)) + log.I("command [getRule]") + out, err = self.pfw.sendCmd("getRule",self.domain_name,"Wrong_Config_Name") + assert err == None, "ERROR : command [getRule] - Error when getting rule on domain %s from a non-existent configuration" % (self.domain_name) + assert out != "Done", "ERROR : command [getRule] - Error not detected while getting rule on domain %s from a non-existent configuration" % (self.domain_name) + log.I("error correctly detected when getting a rule from a non-existent configuration") + log.I("getting a rule from a non-existent domain") + log.I("command [getRule]") + out, err = self.pfw.sendCmd("getRule","Wrong_Domain_Name",self.conf_2) + assert err == None, "ERROR : command [getRule] - Error when getting rule from a non-existent domain" + assert out != "Done", "ERROR : command [getRule] - Error not detected while getting rule from a non-existent domain" + log.I("error correctly detected when getting rule from a non-existent domain") + log.I("getting a rule with wrong parameters order") + log.I("command [getRule]") + out, err = self.pfw.sendCmd("getRule",self.conf_1,self.domain_name) + assert err == None, "ERROR : command [getRule] - Error when getting a rule with incorrect paramaters order" + assert out != "Done", "ERROR : command [getRule] - Error not detected when getting a rule with incorrect paramaters order" + log.I("error correctly detected when getting a rule with incorrect paramaters order on domain %s and configuration %s" % (self.domain_name,self.conf_1)) + + # New domain deletion + log.I("Domain %s deletion" % (self.domain_name)) + log.I("command [deleteDomain]") + out, err = self.pfw.sendCmd("deleteDomain",self.domain_name, "") + assert out == "Done", out + assert err == None, "ERROR : command [deleteDomain] - Error while delting domain %s" % (self.domain_name) + log.I("command [deleteDomain] correctly executed") + log.I("Domain %s deleted" % (self.domain_name)) + + def test_Nominal_Case(self): + """ + Testing nominal case + -------------------- + Test case description : + ~~~~~~~~~~~~~~~~~~~~~~~ + - setting rules for configurations + - getting rules from configurations + - Clear created rules + Tested commands : + ~~~~~~~~~~~~~~~~~ + - [getRule] function + - [setRule] function + - [clearRule] function + - [createDomain] function + - [createConfiguration] function + - [deleteConfiguration] function + - [deleteDomain] function + Expected result : + ~~~~~~~~~~~~~~~~~ + - all operations succeed + """ + log.D(self.test_Nominal_Case.__doc__) + # New domain creation for testing purpose + log.I("New domain creation for testing purpose : %s" % (self.domain_name)) + log.I("command [createDomain]") + out, err = self.pfw.sendCmd("createDomain",self.domain_name, "") + assert out == "Done", out + assert err == None, "ERROR : command [createDomain] - Error while creating domain %s" % (self.domain_name) + log.I("command [createDomain] correctly executed") + log.I("Domain %s created" % (self.domain_name)) + + # New configurations creation for testing purpose + log.I("New configuration %s creation for domain %s for testing purpose" % (self.conf_1,self.domain_name)) + log.I("command [createConfiguration]") + out, err = self.pfw.sendCmd("createConfiguration",self.domain_name,self.conf_1) + assert out == "Done", out + assert err == None, "ERROR : command [createConfiguration] - Error while creating configuration %s" % (self.conf_1) + log.I("command [createConfiguration] correctly executed") + log.I("Configuration %s created for domain %s" % (self.conf_1,self.domain_name)) + log.I("New configuration %s creation for domain %s for testing purpose" % (self.conf_2,self.domain_name)) + log.I("command [createConfiguration]") + out, err = self.pfw.sendCmd("createConfiguration",self.domain_name,self.conf_2) + assert out == "Done", out + assert err == None, "ERROR : command [createConfiguration] - Error while creating configuration %s" % (self.conf_2) + log.I("command [createConfiguration] correctly executed") + log.I("Configuration %s created for domain %s" % (self.conf_2,self.domain_name)) + + # Applying rules to configurations + log.I("Applying rules to configurations %s and %s from domain %s" % (self.conf_1,self.conf_2,self.domain_name)) + log.I("command [setRule]") + out, err = self.pfw.sendCmd("setRule",self.domain_name,self.conf_1,self.rule_1) + assert err == None, "ERROR : command [setRule] - Error while setting rule for configurations %s" % (self.conf_1) + assert out == "Done", "FAIL : command [setRule] - Error while setting rule for configuration %s" % (self.conf_1) + log.I("command [setRule] correctly executed") + log.I("rule correctly created for configuration %s" % (self.conf_1)) + out, err = self.pfw.sendCmd("setRule",self.domain_name,self.conf_2,self.rule_2) + assert err == None, "ERROR : command [setRule] - Error while setting rule for configurations %s" % (self.conf_2) + assert out == "Done", "FAIL : command [setRule] - Error while setting rule for configuration %s" % (self.conf_2) + log.I("command [setRule] correctly executed") + log.I("rule correctly created for configuration %s" % (self.conf_2)) + + # Checking rules recovered + log.I("Recovering rules for configurations %s and %s from domain %s" % (self.conf_1,self.conf_2,self.domain_name)) + log.I("command [getRule]") + out, err = self.pfw.sendCmd("getRule",self.domain_name,self.conf_1) + assert err == None, "ERROR : command [getRule] - Error while setting rule to configurations %s" % (self.conf_1) + assert out == str(self.rule_1), "FAIL : command [getRule] - Error while recovering rule from configuration %s, incorrect value" % (self.conf_1) + log.I("command [getRule] correctly executed") + log.I("rule correctly recovered from configuration %s" % (self.conf_1)) + out, err = self.pfw.sendCmd("getRule",self.domain_name,self.conf_2) + assert err == None, "ERROR : command [getRule] - Error while setting rule to configurations %s" % (self.conf_2) + assert out == str(self.rule_2), "FAIL : command [getRule] - Error while recovering rule from configuration %s, incorrect value" % (self.conf_2) + log.I("command [getRule] correctly executed") + log.I("rule correctly recovered from configuration %s" % (self.conf_2)) + + # Clearing rules + log.I("Clear rules for configurations %s and %s from domain %s" % (self.conf_1,self.conf_2,self.domain_name)) + log.I("command [clearRule]") + out, err = self.pfw.sendCmd("clearRule",self.domain_name,self.conf_1) + assert err == None, "ERROR : command [clearRule] - Error on clearRule for configuration %s" % (self.conf_1) + assert out == "Done", "FAIL : command [clearRule] - Error on clearRule for configuration %s" % (self.conf_1) + out, err = self.pfw.sendCmd("getRule",self.domain_name,self.conf_1) + assert out == "<none>", "ERROR : command [clearRule] - ClearRule not working for configuration %s" % (self.conf_1) + out, err = self.pfw.sendCmd("clearRule",self.domain_name,self.conf_2) + assert err == None, "ERROR : command [clearRule] - Error on clearRule for configuration %s" % (self.conf_2) + assert out == "Done", "FAIL : command [clearRule] - Error on clearRule for configuration %s" % (self.conf_2) + out, err = self.pfw.sendCmd("getRule",self.domain_name,self.conf_2) + assert out == "<none>", "ERROR : command [clearRule] - ClearRule not working for configuration %s" % (self.conf_2) + log.I("command [clearRule] correctly executed") + log.I("ClearRule effective for configurations %s and %s" % (self.conf_1,self.conf_2)) + + # New domain deletion + log.I("Domain %s deletion" % (self.domain_name)) + log.I("command [deleteDomain]") + out, err = self.pfw.sendCmd("deleteDomain",self.domain_name, "") + assert out == "Done", out + assert err == None, "ERROR : command [deleteDomain] - Error while delting domain %s" % (self.domain_name) + log.I("command [deleteDomain] correctly executed") + log.I("Domain %s deleted" % (self.domain_name)) diff --git a/test/functional-tests/PfwTestCase/Domains/tDomain_Split.py b/test/functional-tests/PfwTestCase/Domains/tDomain_Split.py new file mode 100644 index 0000000..9d2990e --- /dev/null +++ b/test/functional-tests/PfwTestCase/Domains/tDomain_Split.py @@ -0,0 +1,247 @@ +# -*-coding:utf-8 -* + +# Copyright (c) 2011-2015, Intel Corporation +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation and/or +# other materials provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors +# may be used to endorse or promote products derived from this software without +# specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR +# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +""" +Split elements from domains testcases + +List of tested functions : +-------------------------- + - [splitDomain] function + - [listBelongingDomains] function + - [listAssociatedDomains] function + - [listAssociatedElements] function + - [listConflictingElements] function + - [listRogueElements] function +Test cases : +------------ + - Testing nominal case +""" +import os.path +from Util.PfwUnitTestLib import PfwTestCase +from Util import ACTLogging +log=ACTLogging.Logger() + +class TestCases(PfwTestCase): + + def setUp(self): + self.pfw.sendCmd("setTuningMode", "on") + self.reference_xml = "$PFW_TEST_TOOLS/xml/XML_Test/Reference_Split_Domain.xml" + + self.temp_domain="f_Domains_Backup" + self.temp_status="f_Config_Status" + + self.path_main = "/Test/Test/TEST_MAIN/" + self.path_dir_0 = "/Test/Test/TEST_MAIN/TEST_DIR_0" + self.path_dir_1 = "/Test/Test/TEST_MAIN/TEST_DIR_1" + self.path_dir_2 = "/Test/Test/TEST_MAIN/TEST_DIR_2" + self.dir_nbr = 3 + self.element_name = "TEST_DIR" + + self.domain_1 = "Domain_1" + self.domain_2 = "Domain_2" + self.domain_3 = "Domain_3" + + self.temp_file="f_temp_file" + + def tearDown(self): + self.pfw.sendCmd("setTuningMode", "off") + if os.path.exists(self.temp_file): + os.remove(self.temp_file) + def test_Combinatorial_Criteria(self): + """ + Testing combinatorial criteria + ------------------------------ + Test case description : + ~~~~~~~~~~~~~~~~~~~~~~~ + - Split a configuration element associated to a domain + - Check that the configuration element children are associated to the domain + - Pass a configuration element to rogue element + - Add a configuration element to another domain and heck that this element is + conflicting while not removed from original domain. + + Tested commands : + ~~~~~~~~~~~~~~~~~ + - [splitDomain] function + - [listBelongingDomains] function + - [listAssociatedDomains] function + - [listAssociatedElements] function + - [listConflictingElements] function + - [listRogueElements] function + Expected result : + ~~~~~~~~~~~~~~~~~ + - Conform to expected behavior + """ + log.D(self.test_Combinatorial_Criteria.__doc__) + + # Import a reference XML file + log.I("Import Domains with settings from %s"%(self.reference_xml)) + out, err = self.pfw.sendCmd("importDomainsWithSettingsXML",self.reference_xml, "") + assert err == None, log.E("Command [importDomainsWithSettingsXML %s] : %s"%(self.reference_xml,err)) + assert out == "Done", log.F("When using function importDomainsWithSettingsXML %s]"%(self.reference_xml)) + + # Checking initial state + # Checking domain integrity + log.I("Checking initial conditions :") + log.I("Checking that %s configurable element is associated to %s :" % (self.path_main,self.domain_1)) + out, err = self.pfw.sendCmd("listAssociatedDomains", self.path_main) + assert err == None, log.E("Command [listAssociatedDomains] : error when listing domain name") + f_temp_file = open(self.temp_file, "w") + f_temp_file.write(out) + f_temp_file.close() + element_name = self.domain_1 + element_found = 0 + for line in open(self.temp_file, "r"): + if element_name in line: + element_found = 1 + assert element_found==1, log.F("configurable element %s not correctly associated to domain %s" % (self.path_main, self.domain_1)) + log.I("configurable element %s correctly associated to domain %s" % (self.path_main, self.domain_1)) + # Deleting temp file + os.remove(self.temp_file) + + # Checking children integrity + log.I("Checking that %s children configurable elements are correctly set for the test" % (self.path_main)) + out, err = self.pfw.sendCmd("listElements", self.path_main) + assert err == None, log.E("Command [listElements] : listing error") + f_temp_file = open(self.temp_file, "w") + f_temp_file.write(out) + f_temp_file.close() + for index in range (self.dir_nbr): + element_name = "".join([self.element_name, "_", str(index)]) + element_found = 0 + for line in open(self.temp_file, "r"): + if element_name in line: + element_found = 1 + assert element_found==1, log.F("Element %s not found in %s" % (element_name, self.path_main)) + log.I("Element %s found in %s" % (element_name, self.path_main)) + # Checking that child element belong to domain + element_path = "".join([self.path_main, element_name]) + out, err = self.pfw.sendCmd("listBelongingDomains", element_path) + assert err == None, log.E("Command [listBelongingDomains] : listing error") + assert out == self.domain_1, log.F("Wrong behavior : %s not belonging to %s " % (element_name, self.domain_1)) + # Checking that child element is not associated to domain, and only belong to it + out, err = self.pfw.sendCmd("listAssociatedDomains", element_path) + assert err == None, log.E("Command [listAssociatedDomains] : listing error") + assert out == '', log.F("Wrong behavior : configurable element %s not associated to %s" % (element_name, self.domain_1)) + log.I("configurable element %s is belonging to %s" % (element_name, self.domain_1)) + log.I("Configurable elements : check OK") + # Deleting temp file + os.remove(self.temp_file) + + # Split domain_0 + log.I("Splitting configurable element %s from %s" % (self.path_main, self.domain_1)) + out, err = self.pfw.sendCmd("splitDomain", self.domain_1, self.path_main) + assert err == None, log.E("Command [splitDomain] : %s" % (err)) + assert out == 'Done', log.F("Wrong behavior : configurable element %s not splitted correctly" % (self.path_main)) + log.I("Splitting done") + + # check that the configurable element splitted is neither associated nor belonging to the domain + log.I("Checking that %s is neither associated nor belonging to %s" % (self.path_main, self.domain_1)) + out, err = self.pfw.sendCmd("listBelongingDomains", self.path_main) + assert err == None, log.E("Command [listBelongingDomains] : listing error") + assert out != self.domain_1, log.F("Wrong behavior : %s still belonging to %s" % (self.path_main, self.domain_1)) + out, err = self.pfw.sendCmd("listAssociatedDomains", self.path_main) + assert err == None, log.E("Command [listAssociatedDomains] : listing error") + assert out == '', log.F("Wrong behavior : configurable element %s still associated to %s" % (self.path_main, self.domain_1)) + log.I("Configurable element %s is no longer associated to %s" % (self.path_main, self.domain_1)) + + # Checking that children configurable elements are now associated to domain + log.I("Checking that %s children configurable elements are now associated to %s" % (self.path_main, self.domain_1)) + out, err = self.pfw.sendCmd("listElements", self.path_main) + assert err == None, log.E("Command [listElements] : listing error") + f_temp_file = open(self.temp_file, "w") + f_temp_file.write(out) + f_temp_file.close() + for index in range (self.dir_nbr): + element_name = "".join([self.element_name, "_", str(index)]) + element_found = 0 + for line in open(self.temp_file, "r"): + if element_name in line: + element_found = 1 + assert element_found==1, log.F("Element %s not found in %s" % (element_name, self.path_main)) + log.I("Element %s found in %s" % (element_name, self.path_main)) + # Checking that child element is associated to domain + element_path = "".join([self.path_main, element_name]) + out, err = self.pfw.sendCmd("listAssociatedDomains", element_path) + assert err == None, log.E("Command [listAssociatedDomains] : listing error") + assert out == self.domain_1, log.F("Wrong behavior : configurable element %s not associated to %s" % (element_name, self.domain_1)) + log.I("configurable element %s is associated to %s" % (element_name, self.domain_1)) + log.I("Configurable elements : check OK") + # Deleting temp file + os.remove(self.temp_file) + + # Removing one element from domain and checking that it becomes a rogue element + log.I("Removing domain element %s from domain %s" % (self.path_dir_0, self.domain_1)) + out, err = self.pfw.sendCmd("removeElement", str(self.domain_1), str(self.path_dir_0)) + assert err == None, log.E("ERROR : command [removeElement] - Error while removing domain element %s" % (self.path_dir_0)) + assert out == "Done", log.F("Domain element %s not correctly removed" % (self.path_dir_0)) + log.I("Domain element %s correctly removed from domain %s" % (self.path_dir_0, self.domain_1)) + log.I("Checking that %s is a rogue element" % (self.path_dir_0)) + out, err = self.pfw.sendCmd("listRogueElements") + assert err == None, log.E("command [listRogueElements] - Error while listing rogue elements") + f_temp_file = open(self.temp_file, "w") + f_temp_file.write(out) + f_temp_file.close() + element_found = 0 + for line in open(self.temp_file, "r"): + if self.path_dir_0 in line: + element_found = 1 + assert element_found==1, log.F("Configurable element %s not found in rogue elements" % (self.path_dir_0)) + log.I("Element %s found in rogue elements" % (self.path_dir_0)) + + # Moving one configuration element to another domain + log.I("Moving configurable element %s from domain %s to domain %s" % (self.path_dir_1, self.domain_1, self.domain_2)) + log.I("Adding %s to domain %s" % (self.path_dir_1, self.domain_2)) + out, err = self.pfw.sendCmd("addElement", self.domain_2, self.path_dir_1) + assert err == None, log.E("ERROR : command [addElement] - Error while adding element %s to domain %s" % (self.path_dir_1, self.domain_2)) + out, err = self.pfw.sendCmd("listConflictingElements") + assert err == None, log.E("command [listConflictingElements] - Error while listing conflicting elements") + f_temp_file = open(self.temp_file, "w") + f_temp_file.write(out) + f_temp_file.close() + element_found = 0 + for line in open(self.temp_file, "r"): + if self.path_dir_1 in line: + element_found = 1 + assert element_found==1, log.F("Configurable element %s not found in conflicting elements" % (self.path_dir_1)) + log.I("Element %s found in conflicting elements" % (self.path_dir_1)) + log.I("Removing %s from domain %s" % (self.path_dir_1, self.domain_1)) + out, err = self.pfw.sendCmd("removeElement", self.domain_1, self.path_dir_1) + assert err == None, log.E("ERROR : command [removeElement] - Error while removing element %s from domain %s" % (self.path_dir_1, self.domain_2)) + out, err = self.pfw.sendCmd("listConflictingElements") + assert err == None, log.E("command [listConflictingElements] - Error while listing conflicting elements") + f_temp_file = open(self.temp_file, "w") + f_temp_file.write(out) + f_temp_file.close() + element_found = 0 + for line in open(self.temp_file, "r"): + if self.path_dir_1 in line: + element_found = 1 + assert element_found!=1, log.F("Configurable element %s still found in conflicting elements" % (self.path_dir_1)) + log.I("Element %s no longer found in conflicting elements" % (self.path_dir_1)) diff --git a/test/functional-tests/PfwTestCase/Domains/tDomain_creation_deletion.py b/test/functional-tests/PfwTestCase/Domains/tDomain_creation_deletion.py new file mode 100644 index 0000000..039830d --- /dev/null +++ b/test/functional-tests/PfwTestCase/Domains/tDomain_creation_deletion.py @@ -0,0 +1,344 @@ +# -*-coding:utf-8 -* + +# Copyright (c) 2011-2015, Intel Corporation +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation and/or +# other materials provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors +# may be used to endorse or promote products derived from this software without +# specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR +# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +""" +Creation, renaming and deletion configuration testcases + +List of tested functions : +-------------------------- + - [createDomain] function + - [deleteDomain] function + +Test cases : +------------ + - Testing nominal cases + - Testing domain creation error + - Testing domain deletion error +""" +import os +from Util.PfwUnitTestLib import PfwTestCase +from Util import ACTLogging +log=ACTLogging.Logger() + +# Test of Domains - Basic operations (creations/deletions) +class TestCases(PfwTestCase): + def setUp(self): + self.pfw.sendCmd("setTuningMode", "on") + self.new_domains_number = 4 + self.new_domain_name = "Domain" + + def tearDown(self): + self.pfw.sendCmd("setTuningMode", "off") + + def test_Domain_Creation_Error(self): + """ + Testing domain creation error + ----------------------------- + Test case description : + ~~~~~~~~~~~~~~~~~~~~~~~ + - Create an already existent domain + Tested commands : + ~~~~~~~~~~~~~~~~~ + - [createDomain] function + - [listDomains] function + Expected result : + ~~~~~~~~~~~~~~~~~ + - Error detected when creating an already existent domain + - No domains list update + """ + log.D(self.test_Domain_Creation_Error.__doc__) + # New domain creation + log.I("New domain creation") + log.I("command [createDomain]") + domain_name = 'Test_Domain' + out, err = self.pfw.sendCmd("createDomain",domain_name, "") + assert out == "Done", out + assert err == None, "ERROR : command [createDomain] - Error while creating domain %s" % (domain_name) + log.I("command [createDomain] correctly executed") + + # Domains listing using "listDomains" command + log.I("Current domains listing") + log.I("command [listDomains]") + out, err = self.pfw.sendCmd("listDomains","","") + assert err == None, "ERROR : command [listDomains] - Error while listing domains" + log.I("command [listDomains] - correctly executed") + + # Domains listing backup + f_Domains_Backup = open("f_Domains_Backup", "w") + f_Domains_Backup.write(out) + f_Domains_Backup.close() + f_Domains_Backup = open("f_Domains_Backup", "r") + domains_nbr_init = 0 + line=f_Domains_Backup.readline() + while line!="": + line=f_Domains_Backup.readline() + domains_nbr_init+=1 + f_Domains_Backup.close() + log.I("Actual domains number : %s" % domains_nbr_init) + + # Trying to add an existent domain name + log.I("Adding an already existent domain name") + log.I("command [createDomain]") + domain_name = 'Test_Domain' + out, err = self.pfw.sendCmd("createDomain",domain_name, "") + assert out != "Done", "ERROR : command [createDomain] - Error not detected when creating an already existent domain" + assert err == None, err + log.I("command [createDomain] - error correctly detected") + + # Checking domains list integrity + log.I("Checking domains listing integrity after domain creation error") + ## Domains listing using "listDomains" command + out, err = self.pfw.sendCmd("listDomains","","") + assert err == None, "ERROR : command [listDomains] - Error while listing domains" + f_Domains = open("f_Domains", "w") + f_Domains.write(out) + f_Domains.close() + ## Domains listing integrity check + f_Domains = open("f_Domains", "r") + domains_nbr = 0 + line=f_Domains.readline() + while line!="": + line=f_Domains.readline() + domains_nbr+=1 + f_Domains.close() + assert domains_nbr == domains_nbr_init, "ERROR : Domains number error, expected %s, found %s" % (domains_nbr_init,domains_nbr) + log.I("Test OK - Domains number not updated") + f_Domains = open("f_Domains", "r") + f_Domains_Backup = open("f_Domains_Backup", "r") + for line in range(domains_nbr): + domain_backup_name = f_Domains_Backup.readline().strip('\n'), + domain_name = f_Domains.readline().strip('\n'), + assert domain_backup_name==domain_name, "ERROR : Error while reading domain %s" % (domain_backup_name) + log.I("Test OK - Domains listing not affected by domain creation error") + + # Closing and deleting temp files + f_Domains_Backup.close() + f_Domains.close() + os.remove("f_Domains_Backup") + os.remove("f_Domains") + + def test_Domain_Deletion_Error(self): + """ + Testing domain deletion error + ----------------------------- + Test case description : + ~~~~~~~~~~~~~~~~~~~~~~~ + - Delete a non existent domain + Tested commands : + ~~~~~~~~~~~~~~~~~ + - [deleteDomain] function + - [listDomains] function + Expected result : + ~~~~~~~~~~~~~~~~~ + - Error detected when deleting a non-existent domain + - No domains list update + """ + log.D(self.test_Domain_Deletion_Error.__doc__) + # Domains listing using "listDomains" command + log.I("Current domains listing") + log.I("command [listDomains]") + out, err = self.pfw.sendCmd("listDomains","","") + assert err == None, "ERROR : command [listDomains] - Error while listing domains" + log.I("command [listDomains] correctly executed") + + # Domains listing backup + f_Domains_Backup = open("f_Domains_Backup", "w") + f_Domains_Backup.write(out) + f_Domains_Backup.close() + f_Domains_Backup = open("f_Domains_Backup", "r") + domains_nbr_init = 0 + line=f_Domains_Backup.readline() + while line!="": + line=f_Domains_Backup.readline() + domains_nbr_init+=1 + f_Domains_Backup.close() + log.I("Actual domains number : %s" % domains_nbr_init) + + # Trying to delete a non-existent domain name + log.I("Deleting a non-existent domain name") + log.I("command [deleteDomain]") + domain_name = 'Wrong_Domain_Name' + out, err = self.pfw.sendCmd("deleteDomain",domain_name, "") + assert out != "Done", "ERROR : command [deleteDomain] - Error not detected when deleting a non-existent domain" + assert err == None, err + log.I("command [deleteDomain] - error correctly detected") + + # Checking domains list integrity + log.I("Checking domains listing integrity after domain deletion error") + ## Domains listing using "listDomains" command + out, err = self.pfw.sendCmd("listDomains","","") + assert err == None, "ERROR : command [listDomains] - Error while listing domains" + f_Domains = open("f_Domains", "w") + f_Domains.write(out) + f_Domains.close() + ## Domains listing integrity check + f_Domains = open("f_Domains", "r") + domains_nbr = 0 + line=f_Domains.readline() + while line!="": + line=f_Domains.readline() + domains_nbr+=1 + f_Domains.close() + assert domains_nbr == domains_nbr_init, "ERROR : Domains number error, expected %s, found %s" % (domains_nbr_init,domains_nbr) + log.I("Test OK - Domains number not updated") + f_Domains = open("f_Domains", "r") + f_Domains_Backup = open("f_Domains_Backup", "r") + for line in range(domains_nbr): + domain_backup_name = f_Domains_Backup.readline().strip('\n'), + domain_name = f_Domains.readline().strip('\n'), + assert domain_backup_name==domain_name, "Error while reading domain %s" % (domain_backup_name) + log.I("Test OK - Domains listing not affected by domain deletion error") + + # Closing and deleting temp files + f_Domains_Backup.close() + f_Domains.close() + os.remove("f_Domains_Backup") + os.remove("f_Domains") + + def test_Nominal_Case(self): + """ + Testing nominal cases + --------------------- + Test case description : + ~~~~~~~~~~~~~~~~~~~~~~~ + - Create X new domains + - Delete X domains + Tested commands : + ~~~~~~~~~~~~~~~~~ + - [createDomain] function + - [deleteDomain] function + - [listDomains] function + Expected result : + ~~~~~~~~~~~~~~~~~ + - X new domains created + - X domains deleted + """ + log.D(self.test_Nominal_Case.__doc__) + # Initial domains listing using "listDomains" command + log.I("Initial domains listing") + log.I("command [listDomains]") + out, err = self.pfw.sendCmd("listDomains","","") + assert err == None, "ERROR : command [listDomains] - Error while listing domains" + log.I("command [listDomains] correctly executed") + + # Initial domains number count + f_init_domains = open("f_init_domains", "w") + f_init_domains.write(out) + f_init_domains.close() + init_domains_nbr = 0 + f_init_domains = open("f_init_domains", "r") + line=f_init_domains.readline() + while line!="": + line=f_init_domains.readline() + init_domains_nbr+=1 + f_init_domains.close() + log.I("Initial domains number : %s" % (init_domains_nbr)) + + # New domains creation + log.I("New domains creation") + log.I("PFW command : [createDomain]") + for index in range (self.new_domains_number): + domain_name = "".join([self.new_domain_name, "_", str(index+init_domains_nbr)]) + out, err = self.pfw.sendCmd("createDomain",domain_name, "") + assert out == "Done", "ERROR : %s" % (out) + assert err == None, "ERROR : command [createDomain] - Error while creating domain %s" % (domain_name) + log.I("command [createDomain] correctly executed") + + # New domain creation check + log.I("New domains creation check :") + log.I("command [listDomains]") + out, err = self.pfw.sendCmd("listDomains","","") + assert err == None, "ERROR : command [listDomains] - Error while listing new domains" + log.I("command [listDomains] correctly executed") + + # Working on a temporary files to record domains listing + tempfile = open("tempfile", "w") + tempfile.write(out) + tempfile.close() + + # Checking last added entries in the listing + tempfile = open("tempfile", "r") + domains_nbr = 0 + line=tempfile.readline() + while line!="": + line=tempfile.readline() + domains_nbr+=1 + tempfile.close() + log.I("New domains conformity check") + tempfile = open("tempfile", "r") + for line in range(domains_nbr): + if (line >= (domains_nbr - self.new_domains_number)): + domain_name = "".join([self.new_domain_name,"_",str(line)]), + domain_created = tempfile.readline().strip('\n'), + assert domain_name==domain_created, "ERROR : Error while creating domain %s %s" % (domain_created, domain_name) + else: + domain_created = tempfile.readline() + log.I("New domains conform to expected values") + created_domains_number = domains_nbr - init_domains_nbr + log.I("%s new domains created" % created_domains_number) + tempfile.close() + os.remove("tempfile") + + # New domains deletion + log.I("New domains deletion") + log.I("command [deleteDomain]") + for index in range (self.new_domains_number): + domain_name = "".join([self.new_domain_name, "_", str(index+init_domains_nbr)]) + out, err = self.pfw.sendCmd("deleteDomain",domain_name, "") + assert out == "Done", "ERROR : %s" % (out) + assert err == None, "ERROR : command [deleteDomain] - Error while deleting domain %s" % (domain_name) + log.I("command [deleteDomain] correctly executed") + + # New domains deletion check + f_init_domains = open("f_init_domains", "r") + tempfile = open("tempfile", "w") + log.I("New domains deletion check :") + log.I("command [listDomains]") + out, err = self.pfw.sendCmd("listDomains","","") + assert err == None, "ERROR : command [listDomains] - Error while listing domains" + log.I("command [listDomains] correctly executed") + tempfile.write(out) + tempfile.close() + tempfile = open("tempfile", "r") + line=tempfile.readline() + line_init=f_init_domains.readline() + while line!="": + line=tempfile.readline() + line_init=f_init_domains.readline() + assert line == line_init, "ERROR : Domain deletion error" + if line=="": + assert line_init == "", "ERROR : Wrong domains deletion number" + log.I("Deletion completed - %s domains deleted" % created_domains_number) + + # Temporary files deletion + tempfile.close() + f_init_domains.close() + os.remove("tempfile") + os.remove("f_init_domains") diff --git a/test/functional-tests/PfwTestCase/Domains/tDomain_rename.py b/test/functional-tests/PfwTestCase/Domains/tDomain_rename.py new file mode 100644 index 0000000..81d4539 --- /dev/null +++ b/test/functional-tests/PfwTestCase/Domains/tDomain_rename.py @@ -0,0 +1,337 @@ +# -*-coding:utf-8 -* + +# Copyright (c) 2011-2015, Intel Corporation +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation and/or +# other materials provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors +# may be used to endorse or promote products derived from this software without +# specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR +# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +""" +Renaming domains testcases + +List of tested functions : +-------------------------- + - [renameDomain] function + +Test cases : +------------ + - Nominal cases + - Renaming errors + - Special cases +""" +import os +from Util.PfwUnitTestLib import PfwTestCase +from Util import ACTLogging +log=ACTLogging.Logger() + +# Test of Domains - Rename +class TestCases(PfwTestCase): + def setUp(self): + self.pfw.sendCmd("setTuningMode", "on") + self.domain_name = "domain_white" + self.new_domain_name = "domain_black" + self.renaming_iterations = 5 + + def tearDown(self): + self.pfw.sendCmd("setTuningMode", "off") + + def test_Nominal_Case(self): + """ + Nominal case + ------------ + Test case description : + ~~~~~~~~~~~~~~~~~~~~~~~ + - Renaming a domain + Tested commands : + ~~~~~~~~~~~~~~~~~ + - [renameDomain] function + - [createDomain] function + - [listDomains] function + Expected result : + ~~~~~~~~~~~~~~~~~ + - domains correctly renamed + """ + log.D(self.test_Nominal_Case.__doc__) + # New domain creation + log.I("New domain creation : %s" % (self.domain_name)) + log.I("command [createDomain]" ) + out, err = self.pfw.sendCmd("createDomain",self.domain_name, "") + assert out == "Done", out + assert err == None, "ERROR : command [createDomain] - ERROR while creating domain %s" % (self.domain_name) + log.I("command [createDomain] correctly executed") + log.I("Domain %s created" % (self.domain_name)) + + # Initial domains listing using "listDomains" command + log.I("Creating a domains listing backup") + log.I("command [listDomains]") + out, err = self.pfw.sendCmd("listDomains","","") + assert err == None, "INFO : command [listDomains] - ERROR while listing domains" + log.I("command [listDomains] correctly executed") + # Saving initial domains names + f_init_domains = open("f_init_domains", "w") + f_init_domains.write(out) + f_init_domains.close() + log.I("Domains listing backup created") + + # Checking domains number + f_init_domains = open("f_init_domains", "r") + domains_nbr = 0 + line=f_init_domains.readline() + while line!="": + line=f_init_domains.readline() + domains_nbr+=1 + f_init_domains.close() + os.remove("f_init_domains") + log.I("%s domains names saved" % domains_nbr) + + # Domain renaming iterations + log.I("Checking domain renaming - %s iterations" % self.renaming_iterations) + old_name = self.domain_name + new_name = self.new_domain_name + for iteration in range (self.renaming_iterations): + log.I("Iteration %s" % (iteration)) + log.I("Renaming domain %s to %s" % (old_name,new_name)) + log.I("command [renameDomain]") + out, err = self.pfw.sendCmd("renameDomain",old_name,new_name) + assert out == "Done", out + assert err == None, "ERROR : command [renameDomain] - ERROR while renaming domain %s" % (old_name) + # Domains listing using "listDomains" command + log.I("Creating a domains listing") + log.I("command [listDomains]") + out, err = self.pfw.sendCmd("listDomains","","") + assert err == None, "ERROR : command [listDomains] - ERROR while listing domains" + log.I("command [listDomains] correctly executed") + # Saving domains names + f_domains = open("f_domains", "w") + f_domains.write(out) + f_domains.close() + log.I("Domains listing created") + # Checking renaming + log.I("Checking that renaming is correct in domains listing") + f_domains = open("f_domains", "r") + for line in range(domains_nbr): + if (line >= (domains_nbr - 1)): + domain_renamed = f_domains.readline().strip('\n') + assert domain_renamed==new_name, "ERROR : Error while renaming domain %s" % (old_name) + else: + f_domains.readline() + f_domains.close() + log.I("New domain name %s conform to expected value" % (new_name)) + temp = old_name + old_name = new_name + new_name = temp + os.remove("f_domains") + + def test_Renaming_Error(self): + """ + Renaming errors + --------------- + Test case description : + ~~~~~~~~~~~~~~~~~~~~~~~ + - renaming a non existent domain + - renaming a domain with an already existent domain name + Tested commands : + ~~~~~~~~~~~~~~~~~ + - [renameDomain] function + - [createDomain] function + - [renameDomain] function + Expected result : + ~~~~~~~~~~~~~~~~~ + - error detected + - domains names remain unchanged + """ + log.D(self.test_Renaming_Error.__doc__) + # New domains creation + log.I("New domain creation : %s" % (self.domain_name)) + log.I("command [createDomain]") + out, err = self.pfw.sendCmd("createDomain",self.domain_name, "") + assert out == "Done", out + assert err == None, "ERROR : command [createDomain] - Error while creating domain %s" % (self.domain_name) + log.I("command [createDomain] - correctly executed") + log.I("command Domain %s created" % (self.domain_name)) + + # Initial domains listing using "listDomains" command + log.I("Creating a domains listing backup") + log.I("command [listDomains]") + out, err = self.pfw.sendCmd("listDomains","","") + assert err == None, "INFO : command [listDomains] - Error while listing domains" + log.I("command [listDomains] correctly executed") + # Saving initial domains names + f_init_domains = open("f_init_domains", "w") + f_init_domains.write(out) + f_init_domains.close() + log.I("Domains listing backup created") + + # Checking domains number + f_init_domains = open("f_init_domains", "r") + domains_nbr = 0 + line=f_init_domains.readline() + while line!="": + line=f_init_domains.readline() + domains_nbr+=1 + f_init_domains.close() + log.I("%s domains names saved" % domains_nbr) + + # Domain renaming error : renamed domain does not exist + log.I("Renaming a non existent domain") + log.I("Renaming domain FAKE to NEW_NAME") + log.I("command [renameDomain]") + out, err = self.pfw.sendCmd("renameDomain",'FAKE','NEW_NAME') + assert out != "Done", out + assert err == None, "ERROR : command [renameDomain] - Error while renaming domain" + log.I("command [renameDomain] - renaming error correctly detected") + # Domains listing using "listDomains" command + log.I("Creating a domains listing") + log.I("command [listDomains]") + out, err = self.pfw.sendCmd("listDomains","","") + assert err == None, "ERROR : command [listDomains] - Error while listing domains" + log.I("command [listDomains] correctly executed") + # Saving domains names + f_domains = open("f_domains", "w") + f_domains.write(out) + f_domains.close() + log.I("Domains listing created") + # Checking domains names integrity + log.I("Checking domains names integrity") + f_domains = open("f_domains", "r") + f_init_domains = open("f_init_domains", "r") + for line in range(domains_nbr): + domain_name = f_domains.readline().strip('\n') + domain_backup_name = f_init_domains.readline().strip('\n') + assert domain_name==domain_backup_name, "ERROR : Domain name %s affected by the renaming error" % (domain_backup_name) + f_domains.close() + f_init_domains.close() + log.I("Domains names not affected by the renaming error") + os.remove("f_domains") + + # Domain renaming error : renaming a domain with an already existent domain name + log.I("renaming a domain with an already existent domain name") + log.I("Renaming domain %s to %s" % (self.domain_name,self.new_domain_name) ) + log.I("command [renameDomain]") + out, err = self.pfw.sendCmd("renameDomain",self.domain_name,self.new_domain_name) + assert out != "Done", out + assert err == None, "INFO : command [renameDomain] - Error while renaming domain" + log.I("command [renameDomain] - renaming error correctly detected") + # Domains listing using "listDomains" command + log.I("Creating a domains listing") + log.I("command [listDomains]") + out, err = self.pfw.sendCmd("listDomains","","") + assert err == None, "ERROR : command [listDomains] - Error while listing domains" + log.I("command [listDomains] correctly executed") + # Saving domains names + f_domains = open("f_domains", "w") + f_domains.write(out) + f_domains.close() + log.I("Domains listing created") + # Checking domains names integrity + log.I("Checking domains names integrity") + f_domains = open("f_domains", "r") + f_init_domains = open("f_init_domains", "r") + for line in range(domains_nbr): + domain_name = f_domains.readline().strip('\n') + domain_backup_name = f_init_domains.readline().strip('\n') + assert domain_name==domain_backup_name, "ERROR : domain name %s affected by the renaming error" % (domain_backup_name) + f_domains.close() + f_init_domains.close() + log.I("Domains names not affected by the renaming error") + os.remove("f_domains") + os.remove("f_init_domains") + + def test_Special_Cases(self): + """ + Special cases + ------------- + Test case description : + ~~~~~~~~~~~~~~~~~~~~~~~ + - renaming a domain with its own name + Tested commands : + ~~~~~~~~~~~~~~~~~ + - [renameDomain] function + - [createDomain] function + - [listDomains] function + Expected result : + ~~~~~~~~~~~~~~~~~ + - no error + - domains names remain unchanged + """ + log.D(self.test_Special_Cases.__doc__) + # New domain creation + # Already created in previous test + + # Initial domains listing using "listDomains" command + log.I("Creating a domains listing backup") + log.I("command [listDomains]") + out, err = self.pfw.sendCmd("listDomains","","") + assert err == None, "ERROR : command [listDomains] - Error while listing domains" + log.I("command [listDomains] correctly executed") + # Saving initial domains names + f_init_domains = open("f_init_domains", "w") + f_init_domains.write(out) + f_init_domains.close() + log.I("Domains listing backup created") + + # Checking domains number + f_init_domains = open("f_init_domains", "r") + domains_nbr = 0 + line=f_init_domains.readline() + while line!="": + line=f_init_domains.readline() + domains_nbr+=1 + f_init_domains.close() + log.I("%s domains names saved" % domains_nbr) + + # Domain renaming error : renaming a domain with its own name + log.I("renaming a domain with its own name") + log.I("Renaming domain %s to %s" % (self.domain_name,self.domain_name)) + log.I("command [renameDomain]") + out, err = self.pfw.sendCmd("renameDomain",self.domain_name,self.domain_name) + assert out == "Done", out + assert err == None, "ERROR : command [renameDomain] - Error while renaming domain" + log.I("command [renameDomain] correctly executed") + # Domains listing using "listDomains" command + log.I("Creating a domains listing") + log.I("command [listDomains]") + out, err = self.pfw.sendCmd("listDomains","","") + assert err == None, "ERROR : command [listDomains] - Error while listing domains" + log.I("command [listDomains] correctly executed") + # Saving domains names + f_domains = open("f_domains", "w") + f_domains.write(out) + f_domains.close() + log.I("Domains listing created") + # Checking domains names integrity + log.I("Checking domains names integrity") + f_domains = open("f_domains", "r") + f_init_domains = open("f_init_domains", "r") + for line in range(domains_nbr): + domain_name = f_domains.readline().strip('\n') + domain_backup_name = f_init_domains.readline().strip('\n') + assert domain_name==domain_backup_name, "ERROR : domain name %s affected by the renaming" % (domain_backup_name) + f_domains.close() + f_init_domains.close() + log.I("Domains names not affected by the renaming") + + os.remove("f_domains") + os.remove("f_init_domains") |