def test_simple_proceedings(self): """Tests a simple download and build of Bake. """ mercurial = ModuleSource.create("mercurial") testResult = mercurial.check_version(self._env) self.assertTrue(testResult) mercurial.attribute("url").value = "http://code.nsnam.org/daniel/bake" self._env._module_name = "bake" self._env._module_dir = "bake" testStatus = subprocess.getoutput('rm -rf /tmp/source') self._logger.set_current_module(self._env._module_name) testResult = mercurial.download(self._env) self.assertFalse(testResult) testStatus = subprocess.getoutput( 'cd /tmp/source/bake;./bake.py configure -p ns3-min') self.assertEquals(testStatus, "", "Should have worked the download of the code") testStatus = subprocess.getoutput( 'cd /tmp/source/bake;./bake.py download') self.assertFalse("Problem" in testStatus, "Should have worked the download of the code") testStatus = subprocess.getoutput( 'cd /tmp/source/bake;./bake.py build') self.assertFalse("Problem" in testStatus, "Should have worked the build of the code")
def test_fullclean(self): """Tests distclean command call. """ waf = ModuleBuild.create("waf") self.assertNotEqual(waf, None) self.assertEqual(waf.name(), "waf") # Environment settings mercurial = ModuleSource.create("mercurial") testResult = mercurial.check_version(self._env) self.assertTrue(testResult) mercurial.attribute("url").value = "http://code.nsnam.org/bhurd/openflow" self._env._module_name="openflow-ns3" self._env._module_dir="openflow-ns3" self._env._objdir = "/tmp/object_openflow" self._env._installdir = "/tmp/install_openflow" testStatus = commands.getoutput('rm -rf /tmp/source') self._logger.set_current_module(self._env._module_name) testResult = mercurial.download(self._env) self.assertEqual(testResult, None) self._env.start_build("openflow-ns3", "/tmp/source/openflow-ns3", True) waf.attribute('configure_arguments').value = 'configure --prefix='+ self._env.installdir + ' --destdir=' + self._env.installdir + ' --blddir=' + self._env.objdir try: testResult = waf.build(self._env, "1") except TaskError as t: print(t.reason) self.assertEqual(testResult, None) testStatus = os.path.isdir('/tmp/source/openflow-ns3') self.assertTrue(testStatus) testStatus = os.path.isdir('/tmp/object_openflow') self.assertTrue(testStatus) module = Module(self._env._module_name, mercurial, waf) module._module_supports_objdir = True self._env.end_build() try: testResult = module.fullclean(self._env) except TaskError as t: print(t.reason) self.assertTrue(testResult) testStatus = os.path.isdir('/tmp/source/openflow-ns3') self.assertFalse(testStatus) testStatus = os.path.isdir('/tmp/source/object_openflow') self.assertFalse(testStatus) testStatus = os.path.isdir('/tmp/source/install_openflow') self.assertFalse(testStatus)
def test_systemPrecondition(self): """Tests the SelfInstallerModule class. """ # it first needs to be able to create the class otherwise will not be # able to do anything else installer = ModuleSource.create("system_dependency") self.assertNotEqual(installer, None) testResult = installer._check_dependency_expression(self._env, "") self.assertTrue(testResult) testResult = installer._check_dependency_expression(self._env, "ls") self.assertTrue(testResult) testResult = installer._check_dependency_expression( self._env, "(ls and bash)") self.assertTrue(testResult) testResult = installer._check_dependency_expression( self._env, "(ls or us9245l25k)") self.assertTrue(testResult) testResult = installer._check_dependency_expression( self._env, "(ls and not us9245l25k)") self.assertTrue(testResult) testResult = installer._check_dependency_expression( self._env, "(ls and us9245l25k)") self.assertFalse(testResult) testResult = installer._check_dependency_expression( self._env, "(ls and bash) and rm") self.assertTrue(testResult) testResult = installer._check_dependency_expression( self._env, "(ls and bash) and us9245l25k") self.assertFalse(testResult) testResult = installer._check_dependency_expression( self._env, "(ls and bash) or us9245l25k") self.assertTrue(testResult) testResult = installer._check_dependency_expression( self._env, "((ls and bash) or us9245l25k)") self.assertTrue(testResult)
def test_systemPrecondition(self): """Tests the SelfInstallerModule class. """ # it first needs to be able to create the class otherwise will not be # able to do anything else installer = ModuleSource.create("system_dependency") self.assertNotEqual(installer, None) testResult = installer._check_dependency_expression(self._env,"") self.assertTrue(testResult) testResult = installer._check_dependency_expression(self._env,"ls") self.assertTrue(testResult) testResult = installer._check_dependency_expression(self._env, "(ls and bash)") self.assertTrue(testResult) testResult = installer._check_dependency_expression(self._env, "(ls or us9245l25k)") self.assertTrue(testResult) testResult = installer._check_dependency_expression(self._env, "(ls and not us9245l25k)") self.assertTrue(testResult) testResult = installer._check_dependency_expression(self._env, "(ls and us9245l25k)") self.assertFalse(testResult) testResult = installer._check_dependency_expression(self._env, "(ls and bash) and rm") self.assertTrue(testResult) testResult = installer._check_dependency_expression(self._env, "(ls and bash) and us9245l25k") self.assertFalse(testResult) testResult = installer._check_dependency_expression(self._env, "(ls and bash) or us9245l25k") self.assertTrue(testResult) testResult = installer._check_dependency_expression(self._env, "((ls and bash) or us9245l25k)") self.assertTrue(testResult)
def test_simple_proceedings(self): """Tests a simple download and build of Bake. """ mercurial = ModuleSource.create("mercurial") testResult = mercurial.check_version(self._env) self.assertTrue(testResult) mercurial.attribute("url").value = "http://code.nsnam.org/daniel/bake" self._env._module_name="bake" self._env._module_dir="bake" testStatus = commands.getoutput('rm -rf /tmp/source') self._logger.set_current_module(self._env._module_name) testResult = mercurial.download(self._env) self.assertFalse(testResult) testStatus = commands.getoutput('cd /tmp/source/bake;./bake.py configure -p ns3-min') self.assertEquals(testStatus, "", "Should have worked the download of the code") testStatus = commands.getoutput('cd /tmp/source/bake;./bake.py download') self.assertFalse("Problem" in testStatus, "Should have worked the download of the code") testStatus = commands.getoutput('cd /tmp/source/bake;./bake.py build') self.assertFalse("Problem" in testStatus, "Should have worked the build of the code")
def test_PythonModuleBuild(self): """Tests the WafModuleBuild Class from ModuleBuild. """ # creating python build module test python = ModuleBuild.create("python") self.assertNotEqual(python, None) self.assertEqual(python.name(), "python") self._env.start_build("python", "/tmp", python.supports_objdir) #checks that the machine has python installed self._logger.set_current_module(self._env._module_name) testResult = python.check_version(self._env) self.assertTrue(testResult) # set up the environment: create directories and download the target code archive = ModuleSource.create("archive") archive.attribute("url").value = "http://switch.dl.sourceforge.net/project/pygccxml/pygccxml/pygccxml-1.0/pygccxml-1.0.0.zip" self._env._module_name="pygccxml" self._env._module_dir="pygccxml" testStatus = commands.getoutput('rm -rf /tmp/source/pygccxml') testStatus = commands.getoutput('mkdir /tmp/source') self._logger.set_current_module(self._env._module_name) testResult = archive.download(self._env) self.assertEqual(testResult, None) testStatus = commands.getoutput('ls /tmp/source/pygccxml|wc') created = re.compile(' +\d+').search(testStatus).group().strip() self.assertNotEqual(created, "0") # Expected case test self._env.objdir = self._env.srcdir+"/object_bake" self._env._installdir = self._env.srcdir+"/install_bake" # test patch self.assertEqual(python.attribute('patch').value, '') python.attribute('patch').value = self._env.srcdir + '/test.patch' self.assertEqual(python.attribute('patch').value, self._env.srcdir + '/test.patch') testResult = None try: testResult = python.add_attribute('patch', 'ERRROR', 'SHOULD NOT HAVE BEEN ADDED') self.fail("The attribute patch exists already, " + "should not be able to add it. ") except AssertionError as e: self.assertNotEqual(e, None) self.assertEqual(testResult, None) try: testResult = python.build(self._env, "1") self.fail("The patch does not exist, should not have being able" + " to find the path file and give an error. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) # creates the file, empty, but created testStatus = commands.getoutput('touch ' + self._env.srcdir + '/test.patch') testResult = python.build(self._env, "1") self.assertEqual(testResult, None) # TODO: find a python module that accepts the distclean # testResult = python.distclean(self._env) # self.assertEqual(testResult, None) python.attribute('patch').value = '' testStatus = commands.getoutput('rm -rf ' + self._env.objdir) testStatus = commands.getoutput('rm -rf ' + self._env._installdir) testResult = python.build(self._env, "1") self.assertEqual(testResult, None) testStatus = commands.getoutput('ls /tmp/source/pygccxml/object_bake|wc') created = re.compile(' +\d+').search(testStatus).group().strip() self.assertNotEqual(created, "0") testStatus = commands.getoutput('ls /tmp/source/pygccxml/install_bake|wc') created = re.compile(' +\d+').search(testStatus).group().strip() self.assertNotEqual(created, "0") # No permission in the target directories self._env.objdir = "/tmp/source/test1/testobj" self._env._installdir = "/tmp/source/test1/testinst" testStatus = commands.getoutput('rm -rf ' + "/tmp/source/test1") testStatus = commands.getoutput('mkdir ' + "/tmp/source/test1") testStatus = commands.getoutput('chmod 000 ' +"/tmp/source/test1") testResult = None try: testResult = python.build(self._env, "1") self.fail("Has no permission in the target directory, and " + "passed any way. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) testStatus = commands.getoutput('chmod 755 ' + "/tmp/source/test1") testStatus = commands.getoutput('rm -rf ' + "/tmp/source/test1")
def test_check_build_version(self): """Tests the _check_source_code method of Class Bake. """ # Environment settings # Environment settings mercurial = ModuleSource.create("mercurial") testResult = mercurial.check_version(self._env) self.assertTrue(testResult) self._env._debug = True pathname = os.path.dirname(compensate_third_runner()) if not pathname: pathname = "." testStatus = subprocess.getoutput('python ' + pathname + '/../bake.py configure' ' --enable=openflow-ns3' ' --sourcedir=/tmp/source' ' --installdir=/tmp/source') mercurial.attribute( "url").value = "http://code.nsnam.org/bhurd/openflow" self._env._module_name = "openflow-ns3" self._env._module_dir = "openflow-ns3" testStatus = subprocess.getoutput('rm -rf /tmp/source') self._logger.set_current_module(self._env._module_name) testResult = mercurial.download(self._env) # try: # testResult = mercurial.download(self._env) # self.fail("The directory does not exist, this shouldn't work") # except TaskError as e: # self.assertNotEqual(e._reason, None) # self.assertEqual(testResult, None) bake = Bake() config = "bakefile.xml" #bakefile.xml" args = [] parser = bake._option_parser('build') parser.add_option('-j', '--jobs', help='Allow N jobs at once. Default is 1.', type='int', action='store', dest='jobs', default=1) parser.add_option( "--debug", action="store_true", dest="debug", default=False, help="Should we enable extra Bake debugging output ?") (options, args_left) = parser.parse_args(args) # bake.setMainOptions(options) Bake.main_options = options # Tests typical case, the module is there and the object directory is not self._env._installdir = self._env.srcdir + "/install_bake" testResult = bake._check_build_version(config, options) self.assertEqual(testResult, None) # if the user has no permission to see the file testStatus = subprocess.getoutput('chmod 000 /tmp/source') testResult = None try: testResult = bake._check_source_code(config, options) except SystemExit as e: self.assertTrue(e.code == 1, "Wrong error code received") self.assertFalse(testResult, None) testStatus = subprocess.getoutput('chmod 755 /tmp/source') # if the folder is not where it should be testStatus = subprocess.getoutput('rm -rf /tmp/source') testResult = None testResult = None try: testResult = bake._check_source_code(config, options) except SystemExit as e: self.assertTrue(e.code == 1, "Wrong error code received") self.assertFalse(testResult, None)
def test_cvs(self): """Tests the CvsModuleSourceclass. """ # checks if can create the class cvs = ModuleSource.create("cvs") self.assertNotEqual(cvs, None) self.assertEqual(cvs.name(), "cvs") # Verifies if cvs is installed testResult = cvs.check_version(self._env) self.assertTrue(testResult) cvs.attribute( "root").value = ":pserver:anoncvs:@www.gccxml.org:/cvsroot/GCC_XML" cvs.attribute("module").value = "gccxml" cvs.attribute("date").value = "2009-09-21" self._env._module_name = "gccxml" self._logger.set_current_module(self._env._module_name) ##### Normal Flow test #clean up the environment, just to be safe self.execute_command(["/bin/rm", "-rf", "gccxml"], "/tmp") testResult = cvs.download(self._env) # None means everything was OK, since there were no exceptions self.assertEqual(testResult, None) # will use the README file to see if the update works testStatus = commands.getoutput( 'cd /tmp/gccxml; cvs status CMakeLists.txt') lastVersion = re.compile('\d+.\d+').search(testStatus).group().replace( ".", "") #after the test, clean the environment self.execute_command(["rm", "-rf", "gccxml"], "/tmp") # download a specific version cvs.attribute("date").value = "2007-09-21" testResult = cvs.download(self._env) self.assertEqual(testResult, None) # verify that the version is the correct one testStatus = commands.getoutput( 'cd /tmp/gccxml; cvs status CMakeLists.txt') version = re.compile('\d+.\d+').search(testStatus).group().replace( ".", "") self.assertEqual(version, "18") # makes an update of the version to a latter version cvs.attribute("date").value = "2008-09-21" testResult = cvs.update(self._env) self.assertEqual(testResult, None) # verify that the version is bigger than the previous one testStatus = commands.getoutput( 'cd /tmp/gccxml; cvs status CMakeLists.txt') version2 = re.compile('\d+.\d+').search(testStatus).group().replace( ".", "") self.assertTrue((float(version) < float(version2))) # Verify if it updates to today's version cvs.attribute("date").value = None testResult = cvs.update(self._env) self.assertEqual(testResult, None) testStatus = commands.getoutput( 'cd /tmp/gccxml; cvs status CMakeLists.txt') version3 = re.compile('\d+.\d+').search(testStatus).group().replace( ".", "") self.assertTrue(float(version2) < float(version3)) self.execute_command(["rm", "-rf", "gccxml"], "/tmp") # Wrong repository cvs.attribute( "root" ).value = ":pserver:anoncvs:@non.Existent.server.com:/cvsroot/GCC_XML" cvs.attribute("date").value = "2008-09-21" self._logger.set_current_module(self._env._module_name) testResult = None try: testResult = cvs.download(self._env) self.fail("There was no problem with a non existent repository. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) self.execute_command(["rm", "-rf", "gccxml"], "/tmp") # try to download to a non existent directory testStatus = commands.getoutput('rm -rf /tmp/testDir') self._env._sourcedir = "/tmp/testDir" testResult = None try: testResult = cvs.download(self._env) self.fail("There was no problem, target directory does not exist" " and it managed to finish the operation. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) # try to download to a directory where the user has no permission testStatus = commands.getoutput( 'mkdir /tmp/testDir;chmod 000 /tmp/testDir') testResult = None try: testResult = cvs.download(self._env) self.fail( "There was no problem, user has no permission on the" " target directory and it managed to finish the operation. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) testStatus = commands.getoutput( 'chmod 755 /tmp/testDir; rm -rf /tmp/testDir') # returns to the original state cvs.attribute( "root").value = ":pserver:anoncvs:@www.gccxml.org:/cvsroot/GCC_XML" self._env._sourcedir = "/tmp" # Invalid argument, it is int and should be string cvs.attribute("checkout_directory").value = -60 testResult = None try: testResult = cvs.download(self._env) self.fail("The version is inexistent, but there is no error. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) # can't go for an inexistent version cvs.attribute("checkout_directory").value = "/tmp" cvs.attribute("date").value = "5000-09-21" testResult = None try: testResult = cvs.download(self._env) self.fail("The version is inexistent, but there is no error. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) # last clean up self.execute_command(["rm", "-rf", "gccxml"], "/tmp")
def test_mercurial(self): """Tests the MercurialModuleSource class. """ # it first needs to be able to create the class otherwise will not be # able to do anything else mercurial = ModuleSource.create("mercurial") self.assertNotEqual(mercurial, None) self.assertEqual(mercurial.name(), "mercurial") # Verifies if the system has the mercurial installed, if not does not # even worth continuing testResult = mercurial.check_version(self._env) self.assertTrue(testResult) mercurial.attribute("url").value = "http://code.nsnam.org/daniel/bake" self._env._module_name = "bake" self._logger.set_current_module(self._env._module_name) #clean up the environment, just to be safe self.execute_command(["/bin/rm", "-rf", "bake"], "/tmp") testResult = mercurial.download(self._env) # if something goes wrong it should rise an exception so, None means # everything is OK self.assertEqual(testResult, None) #after the test, clean the environment self.execute_command(["rm", "-rf", "bake"], "/tmp") # download a specific version mercurial.attribute("revision").value = "63" testResult = mercurial.download(self._env) self.assertEqual(testResult, None) # verify that the version is the correct one testStatus = commands.getoutput('cd /tmp/bake;hg summary') version = re.compile('\d+').search(testStatus).group() self.assertEqual(version, "63") # makes an update of the version to the last version mercurial.attribute("revision").value = "64" testResult = mercurial.update(self._env) self.assertEqual(testResult, None) # verify that the version is the correct one testStatus = commands.getoutput('cd /tmp/bake;hg summary') version = re.compile('\d+').search(testStatus).group() self.assertEqual(version, "64") # Verifies the update to the tip mercurial.attribute("revision").value = "tip" testResult = mercurial.update(self._env) self.assertEqual(testResult, None) # verify that the version is the correct one testStatus = commands.getoutput('cd /tmp/bake;hg log') versionRepository = re.compile('\d+').search(testStatus).group() testStatus = commands.getoutput('cd /tmp/bake;hg summary') versionDownloaded = re.compile('\d+').search(testStatus).group() self.assertEqual(versionRepository, versionDownloaded) self.execute_command(["rm", "-rf", "bake"], "/tmp") # Not http should give you a TaskError exception mercurial.attribute("url").value = "code.nsnam.org/daniel/bake" self._env._module_name = "bake" self._logger.set_current_module(self._env._module_name) testResult = None try: testResult = mercurial.download(self._env) self.fail("There was no problem not passing the protocol. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) self.execute_command(["rm", "-rf", "bake"], "/tmp") testStatus = commands.getoutput('mkdir /tmp/bake;chmod 000 /tmp/bake') mercurial.attribute("url").value = "http://code.nsnam.org/daniel/bake" testResult = None try: testResult = mercurial.download(self._env) self.fail("There was no problem and the user has no permission" " over the directory. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) testStatus = commands.getoutput('chmod 755 /tmp/bake') self.execute_command(["rm", "-rf", "bake"], "/tmp") # try to download to a non existent directory # mercurial cretes the directory testStatus = commands.getoutput('rm -rf /tmp/testDir') self._env._sourcedir = "/tmp/testDir" testResult = mercurial.download(self._env) self.assertEqual(testResult, None) testStatus = commands.getoutput('rm -rf /tmp/testDir') testStatus = commands.getoutput( 'mkdir /tmp/testDir;chmod 000 /tmp/testDir') testResult = None try: testResult = mercurial.download(self._env) self.fail( "There was no problem, user has no permission on the" " target directory and it managed to finish the operation. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) testStatus = commands.getoutput( 'chmod 755 /tmp/testDir; rm -rf /tmp/testDir') # Try to get a wrong version, there is a but in the mercurial # that permits negative revisions, such as -34, for example, # however bigger than the tip version gives an error mercurial.attribute("revision").value = "9999999" testResult = None try: testResult = mercurial.download(self._env) self.fail("The version is inexistent, but there is no error. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) # last clean up self.execute_command(["rm", "-rf", "bake"], "/tmp")
def test_SystemDependencySource(self): """Tests the SelfInstallerModule class. """ # it first needs to be able to create the class otherwise will not be # able to do anything else installer = ModuleSource.create("system_dependency") self.assertNotEqual(installer, None) self.assertEqual(installer.name(), "system_dependency") # Verifies if the system has the right tools installed, if not does not # even worth continuing # Verify if the installer, for this architecture exists testResult = installer.check_version(self._env) self.assertTrue(testResult) self._env._module_name = "testModule" self._logger.set_current_module(self._env._module_name) # Unknown file type installer.attribute("dependency_test").value = "NonExistentSoftForTest" installer.attribute( 'more_information').value = "Message test for inexistent module" installer.attribute("try_to_install").value = 'True' installer.attribute("sudoer_install").value = 'True' testResult = None try: testResult = installer.download(self._env) except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) # print(e._reason) installer.attribute("dependency_test").value = "gcc" installer.attribute('more_information').value = "You miss gcc download" " it from your linux distribution website" testResult = None try: testResult = installer.download(self._env) except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) # print(e._reason) self.assertTrue(testResult) #try to install a non existent module installer.attribute("dependency_test").value = "erlang" installer.attribute('more_information').value = "You miss erlang, " "download it from your linux distribution website" installer.attribute('sudoer_install').value = 'True' testResult = None try: testResult = installer.download(self._env) except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) # print(e._reason) self.assertTrue(testResult == None) # remove the NOT installed module testResult = None reason = None try: testResult = installer.remove(self._env) except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) reason = e._reason # print(e._reason) self.assertTrue(testResult == None) self.assertFalse(not reason) installer.attribute('name_yum').value = "erlang" installer.attribute('name_apt-get').value = "erlang" testResult = None reason = None try: testResult = installer.download(self._env) except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) reason = e._reason # print(e._reason) self.assertTrue(testResult == None) self.assertFalse(not reason) # Adds the sudo tag... now the modules should be able to be installed self._env._sudoEnabled = True # Just to be sure the erlang module is not installed on the machine testResult = None try: testResult = installer.remove(self._env) except TaskError as e: print(e._reason) # this installation should work for sure now! # remove the just installed module testResult = None reason = None try: testResult = installer.download(self._env) except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) reason = e._reason print(e._reason) self.assertTrue(testResult) self.assertTrue(not reason) # Just to be sure the erlang module is not installed on the machine testResult = None try: testResult = installer.remove(self._env) except TaskError as e: print(e._reason)
def test_bazaar(self): """Tests the BazaarModuleSource class. """ # checks if can create the class bazaar = ModuleSource.create("bazaar") self.assertNotEqual(bazaar, None) self.assertEqual(bazaar.name(), "bazaar") # Verifies if Bazaar is installed testResult = bazaar.check_version(self._env) self.assertTrue(testResult) bazaar.attribute("url").value = "https://launchpad.net/pybindgen" self._env._module_name="pybindgen" self._logger.set_current_module(self._env._module_name) ##### Normal Flow test #clean up the environment, just to be safe self.execute_command(["/bin/rm", "-rf", "pybindgen"], "/tmp") testResult = bazaar.download(self._env) # None means everything was OK, since there were no exceptions self.assertEqual(testResult, None) testStatus = commands.getoutput('cd /tmp/pybindgen; bzr log') lastVersion = re.compile('\d+').search(testStatus).group() #after the test, clean the environment self.execute_command(["rm", "-rf", "pybindgen"], "/tmp") # download a specific version bazaar.attribute("revision").value = "794" testResult = bazaar.download(self._env) self.assertEqual(testResult, None) # verify that the version is the correct one testStatus = commands.getoutput('cd /tmp/pybindgen; bzr log') version = re.compile('\d+').search(testStatus).group() self.assertEqual(version, "794") # makes an update of the version to a latter version bazaar.attribute("revision").value = "795" testResult = bazaar.update(self._env) self.assertEqual(testResult, None) # verify that the version is the correct one testStatus = commands.getoutput('cd /tmp/pybindgen; bzr log') version = re.compile('\d+').search(testStatus).group() self.assertEqual(version, "795") self.execute_command(["rm", "-rf", "pybindgen"], "/tmp") # Wrong repository bazaar.attribute("url").value = "http://code.nsnam.org/daniel/bake" self._logger.set_current_module(self._env._module_name) testResult = None try: testResult = bazaar.download(self._env) self.fail("There was no problem not passing the protocol. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) # No protocol http/https bazaar.attribute("url").value = "launchpad.net/pybindgen" bazaar.attribute("revision").value = None self._logger.set_current_module(self._env._module_name) testResult = None try: testResult = bazaar.download(self._env) self.fail("There was no problem not passing the protocol. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) self.execute_command(["rm", "-rf", "pybindgen"], "/tmp") testStatus = commands.getoutput('mkdir /tmp/pybindgen;chmod 000 /tmp/pybindgen') bazaar.attribute("url").value = "https://launchpad.net/pybindgen" testResult = None try: testResult = bazaar.download(self._env) self.fail("There was no problem and the user has no permission" " over the directory. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) testStatus = commands.getoutput('chmod 755 /tmp/pybindgen') self.execute_command(["rm", "-rf", "pybindgen"], "/tmp") # try to download to a non existent directory testStatus = commands.getoutput('rm -rf /tmp/testDir') self._env._sourcedir = "/tmp/testDir" testResult = None try: testResult = bazaar.download(self._env) self.fail("There was no problem, target directory does not exist" " and it managed to finish the operation. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) # try to download to a directory where the user has no permission testStatus = commands.getoutput('mkdir /tmp/testDir;chmod 000 /tmp/testDir') testResult = None try: testResult = bazaar.download(self._env) self.fail("There was no problem, user has no permission on the" " target directory and it managed to finish the operation. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) testStatus = commands.getoutput('chmod 755 /tmp/testDir; rm -rf /tmp/testDir') # returns to the original state bazaar.attribute("url").value = "https://launchpad.net/pybindgen" self._env._sourcedir = "/tmp" # Try to get an unavailable version bazaar.attribute("revision").value = str(int(lastVersion) + 1) testResult = None try: testResult = bazaar.download(self._env) self.fail("The version is inexistent, but there is no error. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) # verifies the update to a inexistent version bazaar.attribute("revision").value = None testResult = bazaar.download(self._env) self.assertEqual(testResult, None) # Invalid argument, it is int and should be string bazaar.attribute("revision").value = -60 testResult = None try: testResult = bazaar.download(self._env) self.fail("The version is inexistent, but there is no error. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) # can not go for a negative version bazaar.attribute("revision").value = str(-60) testResult = None try: testResult = bazaar.download(self._env) self.fail("The version is inexistent, but there is no error. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) # last clean up self.execute_command(["rm", "-rf", "pybindgen"], "/tmp")
def test_mercurial(self): """Tests the MercurialModuleSource class. """ # it first needs to be able to create the class otherwise will not be # able to do anything else mercurial = ModuleSource.create("mercurial") self.assertNotEqual(mercurial, None) self.assertEqual(mercurial.name(), "mercurial") # Verifies if the system has the mercurial installed, if not does not # even worth continuing testResult = mercurial.check_version(self._env) self.assertTrue(testResult) mercurial.attribute("url").value = "http://code.nsnam.org/daniel/bake" self._env._module_name="bake" self._logger.set_current_module(self._env._module_name) #clean up the environment, just to be safe self.execute_command(["/bin/rm", "-rf", "bake"], "/tmp") testResult = mercurial.download(self._env) # if something goes wrong it should rise an exception so, None means # everything is OK self.assertEqual(testResult, None) #after the test, clean the environment self.execute_command(["rm", "-rf", "bake"], "/tmp") # download a specific version mercurial.attribute("revision").value = "63" testResult = mercurial.download(self._env) self.assertEqual(testResult, None) # verify that the version is the correct one testStatus = commands.getoutput('cd /tmp/bake;hg summary') version = re.compile('\d+').search(testStatus).group() self.assertEqual(version, "63") # makes an update of the version to the last version mercurial.attribute("revision").value = "64" testResult = mercurial.update(self._env) self.assertEqual(testResult, None) # verify that the version is the correct one testStatus = commands.getoutput('cd /tmp/bake;hg summary') version = re.compile('\d+').search(testStatus).group() self.assertEqual(version, "64") # Verifies the update to the tip mercurial.attribute("revision").value = "tip" testResult = mercurial.update(self._env) self.assertEqual(testResult, None) # verify that the version is the correct one testStatus = commands.getoutput('cd /tmp/bake;hg log') versionRepository = re.compile('\d+').search(testStatus).group() testStatus = commands.getoutput('cd /tmp/bake;hg summary') versionDownloaded = re.compile('\d+').search(testStatus).group() self.assertEqual(versionRepository, versionDownloaded) self.execute_command(["rm", "-rf", "bake"], "/tmp") # Not http should give you a TaskError exception mercurial.attribute("url").value = "code.nsnam.org/daniel/bake" self._env._module_name="bake" self._logger.set_current_module(self._env._module_name) testResult = None try: testResult = mercurial.download(self._env) self.fail("There was no problem not passing the protocol. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) self.execute_command(["rm", "-rf", "bake"], "/tmp") testStatus = commands.getoutput('mkdir /tmp/bake;chmod 000 /tmp/bake') mercurial.attribute("url").value = "http://code.nsnam.org/daniel/bake" testResult = None try: testResult = mercurial.download(self._env) self.fail("There was no problem and the user has no permission" " over the directory. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) testStatus = commands.getoutput('chmod 755 /tmp/bake') self.execute_command(["rm", "-rf", "bake"], "/tmp") # try to download to a non existent directory # mercurial cretes the directory testStatus = commands.getoutput('rm -rf /tmp/testDir') self._env._sourcedir = "/tmp/testDir" testResult = mercurial.download(self._env) self.assertEqual(testResult, None) testStatus = commands.getoutput('rm -rf /tmp/testDir') testStatus = commands.getoutput('mkdir /tmp/testDir;chmod 000 /tmp/testDir') testResult = None try: testResult = mercurial.download(self._env) self.fail("There was no problem, user has no permission on the" " target directory and it managed to finish the operation. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) testStatus = commands.getoutput('chmod 755 /tmp/testDir; rm -rf /tmp/testDir') # Try to get a wrong version, there is a but in the mercurial # that permits negative revisions, such as -34, for example, # however bigger than the tip version gives an error mercurial.attribute("revision").value = "9999999" testResult = None try: testResult = mercurial.download(self._env) self.fail("The version is inexistent, but there is no error. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) # last clean up self.execute_command(["rm", "-rf", "bake"], "/tmp")
def test_archive_module_source(self): """Tests the ArchiveModuleSource class. """ # it first needs to be able to create the class otherwise will not be # able to do anything else archive = ModuleSource.create("archive") self.assertNotEqual(archive, None) self.assertEqual(archive.name(), "archive") # Verifies if the system has the right tools installed, if not does not # even worth continuing # no file was declared yet, so the issue should be False testResult = archive.check_version(self._env) self.assertFalse(testResult) # Unknown file type archive.attribute("url").value = "http://JustATest.com/File.unknownFileType" testResult = archive.check_version(self._env) self.assertFalse(testResult, "There is no tool to handle the target extension, the result should be false") # zip archive.attribute("url").value = "http://JustATest.com/File.zip" testResult = archive.check_version(self._env) self.assertTrue(testResult, "unzip is not present on the system") # rar archive.attribute("url").value = "http://JustATest.com/File.rar" testResult = archive.check_version(self._env) self.assertTrue(testResult, "unrar is not present on the system") # tar archive.attribute("url").value = "http://JustATest.com/File.tar" testResult = archive.check_version(self._env) self.assertTrue(testResult, "tar is not present on the system") # tar.Z archive.attribute("url").value = "http://JustATest.com/File.tar.Z" testResult = archive.check_version(self._env) self.assertTrue(testResult, "tar is not present on the system") # tar.bz2 archive.attribute("url").value = "http://JustATest.com/File.tar.bz2" testResult = archive.check_version(self._env) self.assertTrue(testResult, "tar is not present on the system") # tar.gz archive.attribute("url").value = "http://read.cs.ucla.edu/click/click-1.8.0.tar.gz" # archive.attribute("url").value = "http://read.cs.ucla.edu/click/click-1.8.0.tar.gz" testResult = archive.check_version(self._env) self.assertTrue(testResult, "tar is not present on the system") self._env._module_name="click-1.8.0" self._logger.set_current_module(self._env._module_name) #clean up the environment, just to be safe self.execute_command(["/bin/rm", "-rf", "click-1.8.0.tar.gz"], "/tmp") self.execute_command(["/bin/rm", "-rf", "click-1.8.0"], "/tmp") testResult = archive.download(self._env) # if something goes wrong it should rise an exception so, None means # everything is OK self.assertEqual(testResult, None) # verifies that files are really there after the download testStatus = commands.getoutput('ls /tmp/click-1.8.0.tar.gz') self.assertEqual("/tmp/click-1.8.0.tar.gz", testStatus) testStatus = commands.getoutput('ls -d /tmp/click-1.8.0') self.assertEqual("/tmp/click-1.8.0", testStatus) #after the test, clean the environment self.execute_command(["/bin/rm", "-rf", "click-1.8.0.tar.gz"], "/tmp") self.execute_command(["/bin/rm", "-rf", "click-1.8.0"], "/tmp") # Searches for a valid file into an inexistent repository archive.attribute("url").value = "http://non.existent.host.com/click-1.8.0.tar.gz" testResult = None try: testResult = archive.download(self._env) self.fail("There was no problem, and the server does not exist. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) # Try to download to a directory that the user has no permission archive.attribute("url").value = "http://read.cs.ucla.edu/click/click-1.8.0.tar.gz" testStatus = commands.getoutput('touch /tmp/click-1.8.0;chmod 000 /tmp/click-1.8.0') testResult = None try: testResult = archive.download(self._env) self.fail("There was no problem, the user has no permission over the target directory. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) testStatus = commands.getoutput("chmod 755 /tmp/click-1.8.0; rm -f " "/tmp/click-1.8.0") # try to download to a non existent directory testStatus = commands.getoutput('rm -rf /tmp/testDir') self._env._sourcedir = "/tmp/testDir" testResult = None try: testResult = archive.download(self._env) self.fail("There was no problem, target directory does not exist " "and it managed to finish the operation. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) testStatus = commands.getoutput('mkdir /tmp/testDir;chmod 000 /tmp/testDir') testResult = None try: testResult = archive.download(self._env) self.fail("There was no problem, user has no permission on the " "target directory and it managed to finish the operation.") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) testStatus = commands.getoutput('chmod 755 /tmp/testDir; rm -rf /tmp/testDir') # no protocol download url gives you an error archive.attribute("url").value = "read.cs.ucla.edu/click/click-1.8.0.tar.gz" testResult = None try: testResult = archive.download(self._env) self.fail("There was no problem, the user didn't add the protocol" " for the url. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) # just to be sure that the update does nothing testResult = archive.update(self._env) self.assertEqual(testResult, None)
def test_general_failures(self): """Tests Some general failures that could happen in the Module Source. """ #Verifies the return of the creation of a non existent module module = ModuleSource.create("NonExistentModule") self.assertEqual(module, None)
def test_SystemDependencySource(self): """Tests the SelfInstallerModule class. """ # it first needs to be able to create the class otherwise will not be # able to do anything else installer = ModuleSource.create("system_dependency") self.assertNotEqual(installer, None) self.assertEqual(installer.name(), "system_dependency") # Verifies if the system has the right tools installed, if not does not # even worth continuing # Verify if the installer, for this architecture exists testResult = installer.check_version(self._env) self.assertTrue(testResult) self._env._module_name="testModule" self._logger.set_current_module(self._env._module_name) # Unknown file type installer.attribute("dependency_test").value = "NonExistentSoftForTest" installer.attribute('more_information').value = "Message test for inexistent module" installer.attribute("try_to_install").value='True' installer.attribute("sudoer_install").value='True' testResult = None try : testResult = installer.download(self._env) except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) # print(e._reason) installer.attribute("dependency_test").value = "gcc" installer.attribute('more_information').value = "You miss gcc download" " it from your linux distribution website" testResult = None try : testResult = installer.download(self._env) except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) # print(e._reason) self.assertTrue(testResult) #try to install a non existent module installer.attribute("dependency_test").value = "erlang" installer.attribute('more_information').value = "You miss erlang, " "download it from your linux distribution website" installer.attribute('sudoer_install').value = 'True' testResult = None try : testResult = installer.download(self._env) except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) # print(e._reason) self.assertTrue(testResult==None) # remove the NOT installed module testResult = None reason=None try : testResult = installer.remove(self._env) except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) reason=e._reason # print(e._reason) self.assertTrue(testResult==None) self.assertFalse(not reason) installer.attribute('name_yum').value = "erlang" installer.attribute('name_apt-get').value = "erlang" testResult = None reason=None try : testResult = installer.download(self._env) except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) reason=e._reason # print(e._reason) self.assertTrue(testResult==None) self.assertFalse(not reason) # Adds the sudo tag... now the modules should be able to be installed self._env._sudoEnabled=True # Just to be sure the erlang module is not installed on the machine testResult = None try : testResult = installer.remove(self._env) except TaskError as e: print(e._reason) # this installation should work for sure now! # remove the just installed module testResult = None reason=None try : testResult = installer.download(self._env) except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) reason=e._reason print(e._reason) self.assertTrue(testResult) self.assertTrue(not reason) # Just to be sure the erlang module is not installed on the machine testResult = None try : testResult = installer.remove(self._env) except TaskError as e: print(e._reason)
def test_check_dependency_expression(self): """ Tests the _check_dependency_expression method. """ # it first needs to be able to create the class otherwise will not be # able to do anything else installer = ModuleSource.create("system_dependency") self.assertNotEqual(installer, None) self.assertEqual(installer.name(), "system_dependency") self._env._module_name="testModule" self._logger.set_current_module(self._env._module_name) # Unknown file type installer.attribute('more_information').value = "Just a test" installer.attribute('sudoer_install').value = 'False' installer.attribute("try_to_install").value='True' installer.attribute("dependency_test").value = "NonExistentSoftForTest" testResult = None testResult = installer._check_dependency_expression(self._env, "NonExistentSoft") self.assertFalse(testResult, "Non existent software, should be false") testResult = None testResult = installer._check_dependency_expression(self._env, "bash") self.assertTrue(testResult, "Existent software, should be true") testResult = None testResult = installer._check_dependency_expression(self._env, "nthing or bash") self.assertTrue(testResult, "Existent software, should be true") testResult = None testResult = installer._check_dependency_expression(self._env, "nthinag and bash") self.assertFalse(testResult, "Inexistent software AND existent one, " "should be false") testResult = None testResult = installer._check_dependency_expression(self._env, "not bash") self.assertFalse(testResult, "The software should exist so it, " "should be false") testResult = None testResult = installer._check_dependency_expression(self._env, "not nthing") self.assertTrue(testResult, "The software does not exist so it, " "should be true") testResult = None testResult = installer._check_dependency_expression(self._env, "/bin/ls") self.assertTrue(testResult, "The software exist so it, " "should be true") testResult = None testResult = installer._check_dependency_expression(self._env, "/lib") self.assertTrue(testResult, "The repository exist so it, " "should be true") testResult = None testResult = installer._check_dependency_expression(self._env, "/tt/NoDirDir") self.assertFalse(testResult, "The repository does not exist so it, " "should be False") testResult = None testResult = installer._check_dependency_expression(self._env, "libc.so") self.assertTrue(testResult, "The library should exist so it, " "should be True") testResult = None testResult = installer._check_dependency_expression(self._env, "notValidLibNot.so") self.assertFalse(testResult, "The library should not exist so it, " "should be False")
def test_check_dependency_expression(self): """ Tests the _check_dependency_expression method. """ # it first needs to be able to create the class otherwise will not be # able to do anything else installer = ModuleSource.create("system_dependency") self.assertNotEqual(installer, None) self.assertEqual(installer.name(), "system_dependency") self._env._module_name = "testModule" self._logger.set_current_module(self._env._module_name) # Unknown file type installer.attribute('more_information').value = "Just a test" installer.attribute('sudoer_install').value = 'False' installer.attribute("try_to_install").value = 'True' installer.attribute("dependency_test").value = "NonExistentSoftForTest" testResult = None testResult = installer._check_dependency_expression( self._env, "NonExistentSoft") self.assertFalse(testResult, "Non existent software, should be false") testResult = None testResult = installer._check_dependency_expression(self._env, "bash") self.assertTrue(testResult, "Existent software, should be true") testResult = None testResult = installer._check_dependency_expression( self._env, "nthing or bash") self.assertTrue(testResult, "Existent software, should be true") testResult = None testResult = installer._check_dependency_expression( self._env, "nthinag and bash") self.assertFalse( testResult, "Inexistent software AND existent one, " "should be false") testResult = None testResult = installer._check_dependency_expression( self._env, "not bash") self.assertFalse(testResult, "The software should exist so it, " "should be false") testResult = None testResult = installer._check_dependency_expression( self._env, "not nthing") self.assertTrue(testResult, "The software does not exist so it, " "should be true") testResult = None testResult = installer._check_dependency_expression( self._env, "/bin/ls") self.assertTrue(testResult, "The software exist so it, " "should be true") testResult = None testResult = installer._check_dependency_expression(self._env, "/lib") self.assertTrue(testResult, "The repository exist so it, " "should be true") testResult = None testResult = installer._check_dependency_expression( self._env, "/tt/NoDirDir") self.assertFalse( testResult, "The repository does not exist so it, " "should be False") testResult = None testResult = installer._check_dependency_expression( self._env, "libc.so") self.assertTrue(testResult, "The library should exist so it, " "should be True") testResult = None testResult = installer._check_dependency_expression( self._env, "notValidLibNot.so") self.assertFalse( testResult, "The library should not exist so it, " "should be False")
def test_cvs(self): """Tests the CvsModuleSourceclass. """ # checks if can create the class cvs = ModuleSource.create("cvs") self.assertNotEqual(cvs, None) self.assertEqual(cvs.name(), "cvs") # Verifies if cvs is installed testResult = cvs.check_version(self._env) self.assertTrue(testResult) cvs.attribute("root").value = ":pserver:anoncvs:@www.gccxml.org:/cvsroot/GCC_XML" cvs.attribute("module").value="gccxml" cvs.attribute("date").value="2009-09-21" self._env._module_name="gccxml" self._logger.set_current_module(self._env._module_name) ##### Normal Flow test #clean up the environment, just to be safe self.execute_command(["/bin/rm", "-rf", "gccxml"], "/tmp") testResult = cvs.download(self._env) # None means everything was OK, since there were no exceptions self.assertEqual(testResult, None) # will use the README file to see if the update works testStatus = commands.getoutput('cd /tmp/gccxml; cvs status CMakeLists.txt') lastVersion = re.compile('\d+.\d+').search(testStatus).group().replace(".","") #after the test, clean the environment self.execute_command(["rm", "-rf", "gccxml"], "/tmp") # download a specific version cvs.attribute("date").value="2007-09-21" testResult = cvs.download(self._env) self.assertEqual(testResult, None) # verify that the version is the correct one testStatus = commands.getoutput('cd /tmp/gccxml; cvs status CMakeLists.txt') version = re.compile('\d+.\d+').search(testStatus).group().replace(".","") self.assertEqual(version, "18") # makes an update of the version to a latter version cvs.attribute("date").value="2008-09-21" testResult = cvs.update(self._env) self.assertEqual(testResult, None) # verify that the version is bigger than the previous one testStatus = commands.getoutput('cd /tmp/gccxml; cvs status CMakeLists.txt') version2 = re.compile('\d+.\d+').search(testStatus).group().replace(".","") self.assertTrue((float(version) < float(version2))) # Verify if it updates to today's version cvs.attribute("date").value=None testResult = cvs.update(self._env) self.assertEqual(testResult, None) testStatus = commands.getoutput('cd /tmp/gccxml; cvs status CMakeLists.txt') version3 = re.compile('\d+.\d+').search(testStatus).group().replace(".","") self.assertTrue(float(version2) < float(version3)) self.execute_command(["rm", "-rf", "gccxml"], "/tmp") # Wrong repository cvs.attribute("root").value = ":pserver:anoncvs:@non.Existent.server.com:/cvsroot/GCC_XML" cvs.attribute("date").value="2008-09-21" self._logger.set_current_module(self._env._module_name) testResult = None try: testResult = cvs.download(self._env) self.fail("There was no problem with a non existent repository. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) self.execute_command(["rm", "-rf", "gccxml"], "/tmp") # try to download to a non existent directory testStatus = commands.getoutput('rm -rf /tmp/testDir') self._env._sourcedir = "/tmp/testDir" testResult = None try: testResult = cvs.download(self._env) self.fail("There was no problem, target directory does not exist" " and it managed to finish the operation. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) # try to download to a directory where the user has no permission testStatus = commands.getoutput('mkdir /tmp/testDir;chmod 000 /tmp/testDir') testResult = None try: testResult = cvs.download(self._env) self.fail("There was no problem, user has no permission on the" " target directory and it managed to finish the operation. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) testStatus = commands.getoutput('chmod 755 /tmp/testDir; rm -rf /tmp/testDir') # returns to the original state cvs.attribute("root").value = ":pserver:anoncvs:@www.gccxml.org:/cvsroot/GCC_XML" self._env._sourcedir = "/tmp" # Invalid argument, it is int and should be string cvs.attribute("checkout_directory").value = -60 testResult = None try: testResult = cvs.download(self._env) self.fail("The version is inexistent, but there is no error. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) # can't go for an inexistent version cvs.attribute("checkout_directory").value = "/tmp" cvs.attribute("date").value="5000-09-21" testResult = None try: testResult = cvs.download(self._env) self.fail("The version is inexistent, but there is no error. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) # last clean up self.execute_command(["rm", "-rf", "gccxml"], "/tmp")
def test_git(self): """Tests the GitModuleSource. """ # checks if can create the class git = ModuleSource.create("git") self.assertNotEqual(git, None) self.assertEqual(git.name(), "git") # Verifies if git is installed testResult = git.check_version(self._env) self.assertTrue(testResult) git.attribute("url").value = "git://github.com/git/hello-world.git" git.attribute("revision").value = "78cfc43c2827b9e48e6586a3523ff845a6378889" self._env._module_name="hello-world" self._logger.set_current_module(self._env._module_name) ##### Normal Flow test #clean up the environment, just to be safe self.execute_command(["/bin/rm", "-rf", "hello-world"], "/tmp") testResult = git.download(self._env) # None means everything was OK, since there were no exceptions self.assertEqual(testResult, None) # will use the README file to see if the update works testStatus = commands.getoutput('cd /tmp/hello-world; git log') lastVersion = re.compile(' +\w+').search(testStatus).group().replace(" ","") self.assertEqual(lastVersion, "78cfc43c2827b9e48e6586a3523ff845a6378889") testResult = git.update(self._env) self.assertEqual(testResult, None) git.attribute("revision").value="45021a874e090b765acc5e2696154c495686614b" testResult = git.update(self._env) self.assertEqual(testResult, None) commands.getoutput("cat /tmp/hello-world/c.c >> /tmp/hello-world/dos.bat") testResult = git.update(self._env) self.assertEqual(testResult, None) #after the test, clean the environment self.execute_command(["rm", "-rf", "hello-world"], "/tmp") # download a specific version git.attribute("revision").value="3fa7c46d11b11d61f1cbadc6888be5d0eae21969" testResult = git.download(self._env) self.assertEqual(testResult, None) # verify that the version is the correct one testStatus = commands.getoutput('cd /tmp/hello-world; git log') version = re.compile(' +\w+').search(testStatus).group().replace(" ","") self.assertEqual(version, "3fa7c46d11b11d61f1cbadc6888be5d0eae21969") self.execute_command(["rm", "-rf", "gccxml"], "/tmp") #Wrong repository git.attribute("url").value = "git://inexistant.server.com/git/hello-world.git" git.attribute("revision").value = "78cfc43c2827b9e48e6586a3523ff845a6378889" self._logger.set_current_module(self._env._module_name) testResult = None try: testResult = git.download(self._env) self.fail("There was no problem with a non existent repository. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) self.execute_command(["rm", "-rf", "gccxml"], "/tmp") # no protocol git.attribute("url").value = "github.com/git/hello-world.git" self._logger.set_current_module(self._env._module_name) testResult = None try: testResult = git.download(self._env) self.fail("There was no problem without protocol. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) git.attribute("url").value = "git://github.com/git/hello-world.git" self.execute_command(["rm", "-rf", "gccxml"], "/tmp") # try to download to a non existent directory testStatus = commands.getoutput('rm -rf /tmp/testDir') self._env._sourcedir = "/tmp/testDir" testResult = None try: testResult = git.download(self._env) self.fail("There was no problem, target directory does not" " exist and it managed to finish the operation. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) # try to download to a directory where the user has no permission testStatus = commands.getoutput('mkdir /tmp/testDir;chmod 000 /tmp/testDir') testResult = None try: testResult = git.download(self._env) self.fail("There was no problem, user has no permission on the" " target directory and it managed to finish the operation. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) testStatus = commands.getoutput('chmod 755 /tmp/testDir; rm -rf /tmp/testDir') # Invalid argument, it is int and should be string self._env._sourcedir = -60 testResult = None try: testResult = git.download(self._env) self.fail("The version is inexistent, but there is no error. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) # returns to the original state self._env._sourcedir = "/tmp" # can't go for an inexistent version git.attribute("revision").value = "1000000000000000000000000000000000000000" testResult = None try: testResult = git.download(self._env) self.fail("The version is inexistent, but there is no error. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None)
def test_archive_module_source(self): """Tests the ArchiveModuleSource class. """ # it first needs to be able to create the class otherwise will not be # able to do anything else archive = ModuleSource.create("archive") self.assertNotEqual(archive, None) self.assertEqual(archive.name(), "archive") # Verifies if the system has the right tools installed, if not does not # even worth continuing # no file was declared yet, so the issue should be False testResult = archive.check_version(self._env) self.assertFalse(testResult) # Unknown file type archive.attribute( "url").value = "http://JustATest.com/File.unknownFileType" testResult = archive.check_version(self._env) self.assertFalse( testResult, "There is no tool to handle the target extension, the result should be false" ) # zip archive.attribute("url").value = "http://JustATest.com/File.zip" testResult = archive.check_version(self._env) self.assertTrue(testResult, "unzip is not present on the system") # rar archive.attribute("url").value = "http://JustATest.com/File.rar" testResult = archive.check_version(self._env) self.assertTrue(testResult, "unrar is not present on the system") # tar archive.attribute("url").value = "http://JustATest.com/File.tar" testResult = archive.check_version(self._env) self.assertTrue(testResult, "tar is not present on the system") # tar.Z archive.attribute("url").value = "http://JustATest.com/File.tar.Z" testResult = archive.check_version(self._env) self.assertTrue(testResult, "tar is not present on the system") # tar.bz2 archive.attribute("url").value = "http://JustATest.com/File.tar.bz2" testResult = archive.check_version(self._env) self.assertTrue(testResult, "tar is not present on the system") # tar.gz archive.attribute( "url").value = "http://read.cs.ucla.edu/click/click-1.8.0.tar.gz" # archive.attribute("url").value = "http://read.cs.ucla.edu/click/click-1.8.0.tar.gz" testResult = archive.check_version(self._env) self.assertTrue(testResult, "tar is not present on the system") self._env._module_name = "click-1.8.0" self._logger.set_current_module(self._env._module_name) #clean up the environment, just to be safe self.execute_command(["/bin/rm", "-rf", "click-1.8.0.tar.gz"], "/tmp") self.execute_command(["/bin/rm", "-rf", "click-1.8.0"], "/tmp") testResult = archive.download(self._env) # if something goes wrong it should rise an exception so, None means # everything is OK self.assertEqual(testResult, None) # verifies that files are really there after the download testStatus = commands.getoutput('ls /tmp/click-1.8.0.tar.gz') self.assertEqual("/tmp/click-1.8.0.tar.gz", testStatus) testStatus = commands.getoutput('ls -d /tmp/click-1.8.0') self.assertEqual("/tmp/click-1.8.0", testStatus) #after the test, clean the environment self.execute_command(["/bin/rm", "-rf", "click-1.8.0.tar.gz"], "/tmp") self.execute_command(["/bin/rm", "-rf", "click-1.8.0"], "/tmp") # Searches for a valid file into an inexistent repository archive.attribute( "url").value = "http://non.existent.host.com/click-1.8.0.tar.gz" testResult = None try: testResult = archive.download(self._env) self.fail("There was no problem, and the server does not exist. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) # Try to download to a directory that the user has no permission archive.attribute( "url").value = "http://read.cs.ucla.edu/click/click-1.8.0.tar.gz" testStatus = commands.getoutput( 'touch /tmp/click-1.8.0;chmod 000 /tmp/click-1.8.0') testResult = None try: testResult = archive.download(self._env) self.fail( "There was no problem, the user has no permission over the target directory. " ) except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) testStatus = commands.getoutput("chmod 755 /tmp/click-1.8.0; rm -f " "/tmp/click-1.8.0") # try to download to a non existent directory testStatus = commands.getoutput('rm -rf /tmp/testDir') self._env._sourcedir = "/tmp/testDir" testResult = None try: testResult = archive.download(self._env) self.fail("There was no problem, target directory does not exist " "and it managed to finish the operation. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) testStatus = commands.getoutput( 'mkdir /tmp/testDir;chmod 000 /tmp/testDir') testResult = None try: testResult = archive.download(self._env) self.fail( "There was no problem, user has no permission on the " "target directory and it managed to finish the operation.") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) testStatus = commands.getoutput( 'chmod 755 /tmp/testDir; rm -rf /tmp/testDir') # no protocol download url gives you an error archive.attribute( "url").value = "read.cs.ucla.edu/click/click-1.8.0.tar.gz" testResult = None try: testResult = archive.download(self._env) self.fail("There was no problem, the user didn't add the protocol" " for the url. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) # just to be sure that the update does nothing testResult = archive.update(self._env) self.assertEqual(testResult, None)
def test_WafModuleBuild(self): """Tests the WafModuleBuild Class from ModuleBuild. """ waf = ModuleBuild.create("waf") self.assertNotEqual(waf, None) self.assertEqual(waf.name(), "waf") testStatus = commands.getoutput('cp test.patch /tmp/source/' 'openflow-ns3/test.patch' ) self._env.start_build("waf", "/tmp", waf.supports_objdir) testResult = None testResult = waf.check_version(self._env) self.assertFalse(testResult) # try: # self.fail("There was a miss configuration problem and there was no error.") # except TaskError as e: # self.assertNotEqual(e._reason, None) # self.assertEqual(testResult, None) # Environment settings mercurial = ModuleSource.create("mercurial") testResult = mercurial.check_version(self._env) self.assertTrue(testResult) mercurial.attribute("url").value = "http://code.nsnam.org/bhurd/openflow" self._env._module_name="openflow-ns3" self._env._module_dir="openflow-ns3" testStatus = commands.getoutput('rm -rf /tmp/source') self._logger.set_current_module(self._env._module_name) testResult = mercurial.download(self._env) self.assertEqual(testResult, None) #check that has the waf version required installed in the machine testResult = waf.check_version(self._env) self.assertTrue(testResult) # Verirfies the path to the waf file testResult = waf._binary(self._env.srcdir) self.assertEqual(testResult, "/tmp/source/openflow-ns3/waf") # wrong path testResult = waf._binary("/tmp/source") self.assertEqual(testResult, "waf") # non existing path testResult = waf._binary("/NonExistant/Path") self.assertEqual(testResult, "waf") # Expected case test self._env.objdir = self._env.srcdir+"/object" # test patch self.assertEqual(waf.attribute('patch').value, '') waf.attribute('patch').value = self._env.srcdir + '/test.patch' self.assertEqual(waf.attribute('patch').value, self._env.srcdir + '/test.patch') testResult = None try: testResult = waf.add_attribute('patch', 'ERRROR', 'SHOULD NOT HAVE BEEN ADDED') self.fail("The attribute patch exists already, should not be" + " able to add it. ") except AssertionError as e: self.assertNotEqual(e, None) self.assertEqual(testResult, None) try: testResult = waf.build(self._env, "1") self.fail("The patch does not exist, should not have being able" + " to find the path file and give an error. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) testStatus = commands.getoutput('cp test.patch /tmp/source/' 'openflow-ns3/test.patch' ) # creates the file, empty, but created waf.attribute('patch').value = '/tmp/source/openflow-ns3/test.patch' self.assertEqual(waf.attribute('patch').value, '/tmp/source/' 'openflow-ns3/test.patch') waf.attribute('configure_arguments').value = 'configure' try: testResult = waf.build(self._env, "1") except TaskError as t: print(t.reason) self.assertEqual(testResult, None) testStatus = commands.getoutput('ls /tmp/source/openflow-ns3/build|wc') created = re.compile(' +\d+').search(testStatus).group().strip() self.assertNotEqual(created, "0") waf.attribute('patch').value = '' # call the distclean to remove the build testResult = waf.distclean(self._env) self.assertEqual(testResult, None) testStatus = commands.getoutput('ls /tmp/source/openflow-ns3/build|wc') created = re.compile(' +\d+').search(testStatus).group().strip() self.assertEqual(created, "0") # Call with extra options # TODO: find a solution either use another packet, like pybindgen, that # uses waf, or see to fix the openflow, because open flow does not accept # the configure arguments even though it is in the example of the # man page --enable-examples --enable-tests does not compile gives an error # flolowed the steps of http://www.nsnam.org/docs/models/html/openflow-switch.html waf.attribute("CFLAGS").value = "-g" # waf.attribute("configure_arguments").value = " " # waf.attribute("builarguments").value = "-O2" try: testResult = waf.build(self._env, "1") except TaskError as t: print(t.reason) self.assertEqual(testResult, None) testStatus = commands.getoutput('ls /tmp/source/openflow-ns3/build/default/lib|wc') created = re.compile(' +\d+').search(testStatus).group().strip() self.assertNotEqual(created, "0") # call the clean to remove the build testResult = waf.clean(self._env) self.assertEqual(testResult, None) testStatus = commands.getoutput('ls /tmp/source/openflow-ns3/build/default/lib|wc') created = re.compile(' +\d+').search(testStatus).group().strip() self.assertEqual(created, "0")
def test_bazaar(self): """Tests the BazaarModuleSource class. """ # checks if can create the class bazaar = ModuleSource.create("bazaar") self.assertNotEqual(bazaar, None) self.assertEqual(bazaar.name(), "bazaar") # Verifies if Bazaar is installed testResult = bazaar.check_version(self._env) self.assertTrue(testResult) bazaar.attribute("url").value = "https://launchpad.net/pybindgen" self._env._module_name = "pybindgen" self._logger.set_current_module(self._env._module_name) ##### Normal Flow test #clean up the environment, just to be safe self.execute_command(["/bin/rm", "-rf", "pybindgen"], "/tmp") testResult = bazaar.download(self._env) # None means everything was OK, since there were no exceptions self.assertEqual(testResult, None) testStatus = commands.getoutput('cd /tmp/pybindgen; bzr log') lastVersion = re.compile('\d+').search(testStatus).group() #after the test, clean the environment self.execute_command(["rm", "-rf", "pybindgen"], "/tmp") # download a specific version bazaar.attribute("revision").value = "794" testResult = bazaar.download(self._env) self.assertEqual(testResult, None) # verify that the version is the correct one testStatus = commands.getoutput('cd /tmp/pybindgen; bzr log') version = re.compile('\d+').search(testStatus).group() self.assertEqual(version, "794") # makes an update of the version to a latter version bazaar.attribute("revision").value = "795" testResult = bazaar.update(self._env) self.assertEqual(testResult, None) # verify that the version is the correct one testStatus = commands.getoutput('cd /tmp/pybindgen; bzr log') version = re.compile('\d+').search(testStatus).group() self.assertEqual(version, "795") self.execute_command(["rm", "-rf", "pybindgen"], "/tmp") # Wrong repository bazaar.attribute("url").value = "http://code.nsnam.org/daniel/bake" self._logger.set_current_module(self._env._module_name) testResult = None try: testResult = bazaar.download(self._env) self.fail("There was no problem not passing the protocol. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) # No protocol http/https bazaar.attribute("url").value = "launchpad.net/pybindgen" bazaar.attribute("revision").value = None self._logger.set_current_module(self._env._module_name) testResult = None try: testResult = bazaar.download(self._env) self.fail("There was no problem not passing the protocol. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) self.execute_command(["rm", "-rf", "pybindgen"], "/tmp") testStatus = commands.getoutput( 'mkdir /tmp/pybindgen;chmod 000 /tmp/pybindgen') bazaar.attribute("url").value = "https://launchpad.net/pybindgen" testResult = None try: testResult = bazaar.download(self._env) self.fail("There was no problem and the user has no permission" " over the directory. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) testStatus = commands.getoutput('chmod 755 /tmp/pybindgen') self.execute_command(["rm", "-rf", "pybindgen"], "/tmp") # try to download to a non existent directory testStatus = commands.getoutput('rm -rf /tmp/testDir') self._env._sourcedir = "/tmp/testDir" testResult = None try: testResult = bazaar.download(self._env) self.fail("There was no problem, target directory does not exist" " and it managed to finish the operation. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) # try to download to a directory where the user has no permission testStatus = commands.getoutput( 'mkdir /tmp/testDir;chmod 000 /tmp/testDir') testResult = None try: testResult = bazaar.download(self._env) self.fail( "There was no problem, user has no permission on the" " target directory and it managed to finish the operation. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) testStatus = commands.getoutput( 'chmod 755 /tmp/testDir; rm -rf /tmp/testDir') # returns to the original state bazaar.attribute("url").value = "https://launchpad.net/pybindgen" self._env._sourcedir = "/tmp" # Try to get an unavailable version bazaar.attribute("revision").value = str(int(lastVersion) + 1) testResult = None try: testResult = bazaar.download(self._env) self.fail("The version is inexistent, but there is no error. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) # verifies the update to a inexistent version bazaar.attribute("revision").value = None testResult = bazaar.download(self._env) self.assertEqual(testResult, None) # Invalid argument, it is int and should be string bazaar.attribute("revision").value = -60 testResult = None try: testResult = bazaar.download(self._env) self.fail("The version is inexistent, but there is no error. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) # can not go for a negative version bazaar.attribute("revision").value = str(-60) testResult = None try: testResult = bazaar.download(self._env) self.fail("The version is inexistent, but there is no error. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) # last clean up self.execute_command(["rm", "-rf", "pybindgen"], "/tmp")
def test_WafModuleBuildPybind(self): """Tests the WafModuleBuild Class from ModuleBuild. """ waf = ModuleBuild.create("waf") self.assertNotEqual(waf, None) self.assertEqual(waf.name(), "waf") waf.attribute("configure_arguments").value = "configure" self._env.start_build("waf", "/tmp", waf.supports_objdir) testResult = None testResult = waf.check_version(self._env) self.assertFalse(testResult) # Environment settings bazaar = ModuleSource.create("bazaar") testResult = bazaar.check_version(self._env) self.assertTrue(testResult) bazaar.attribute("url").value = "https://launchpad.net/pybindgen" self._env._module_name="pybindgen" self._env._module_dir="pybindgen" self._logger.set_current_module(self._env._module_name) # bazaar.attribute("revision").value = "revno:795" self._env._module_name="pybindgen" self._env._module_dir="pybindgen" testStatus = commands.getoutput('mkdir /tmp/source') self._logger.set_current_module(self._env._module_name) testResult = bazaar.download(self._env) self.assertEqual(testResult, None) #check that has the waf version required installed in the machine testResult = waf.check_version(self._env) self.assertTrue(testResult) # Verirfies the path to the waf file testResult = waf._binary(self._env.srcdir) self.assertEqual(testResult, "/tmp/source/pybindgen/waf") # wrong path testResult = waf._binary("/tmp/source") self.assertEqual(testResult, "waf") # non existing path testResult = waf._binary("/NonExistant/Path") self.assertEqual(testResult, "waf") # Expected case test self._env.objdir = self._env.srcdir+"/object" # test patch self.assertEqual(waf.attribute('patch').value, '') waf.attribute('patch').value = self._env.srcdir + '/test.patch' self.assertEqual(waf.attribute('patch').value, self._env.srcdir + '/test.patch') testResult = None try: testResult = waf.add_attribute('patch', 'ERRROR', 'SHOULD NOT HAVE BEEN ADDED') self.fail("The attribute patch exists already, should not be" + " able to add it. ") except AssertionError as e: self.assertNotEqual(e, None) self.assertEqual(testResult, None) try: testResult = waf.build(self._env, "1") self.fail("The patch does not exist, should not have being able" + " to find the path file and give an error. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) # creates the file, empty, but created testStatus = commands.getoutput('touch ' + self._env.srcdir + '/test.patch') testStatus = commands.getoutput('rm -rf /tmp/source/pybindgen/object') try: testResult = waf.build(self._env, "1") except TaskError as e: self.assertTrue(e._reason.startswith('Could not install') or e._reason.startswith('Subprocess failed')) self.assertEqual(testResult, None) testStatus = os.path.exists('/tmp/source/pybindgen/object') self.assertFalse(testStatus) # call the clean to remove the build # TODO: Find a solution for the remaining directories # - It is strange because the waf does not remove the directories, # just the object files.... Should this be like that??!?! testResult = waf.clean(self._env) self.assertEqual(testResult, None) testStatus = os.path.exists('/tmp/source/pybindgen/object/default/tests') self.assertFalse(testStatus) # TODO: neighter the --generate-version appears but I couldn't also # find a configuration argument for pybindgen :( # Call with extra options waf.attribute("CFLAGS").value = "-g" waf.attribute("configure_arguments").value = "configure" waf.attribute("build_arguments").value = "--generate-version" try: testResult = waf.build(self._env, "1") except TaskError as e: self.assertTrue(e._reason.startswith('Could not install') or e._reason.startswith('Subprocess failed')) self.assertEqual(testResult, None) testStatus = os.path.exists('/tmp/source/openflow-ns3/object') self.assertFalse(testStatus)
def test_git(self): """Tests the GitModuleSource. """ # checks if can create the class git = ModuleSource.create("git") self.assertNotEqual(git, None) self.assertEqual(git.name(), "git") # Verifies if git is installed testResult = git.check_version(self._env) self.assertTrue(testResult) git.attribute("url").value = "git://github.com/git/hello-world.git" git.attribute( "revision").value = "78cfc43c2827b9e48e6586a3523ff845a6378889" self._env._module_name = "hello-world" self._logger.set_current_module(self._env._module_name) ##### Normal Flow test #clean up the environment, just to be safe self.execute_command(["/bin/rm", "-rf", "hello-world"], "/tmp") testResult = git.download(self._env) # None means everything was OK, since there were no exceptions self.assertEqual(testResult, None) # will use the README file to see if the update works testStatus = commands.getoutput('cd /tmp/hello-world; git log') lastVersion = re.compile(' +\w+').search(testStatus).group().replace( " ", "") self.assertEqual(lastVersion, "78cfc43c2827b9e48e6586a3523ff845a6378889") testResult = git.update(self._env) self.assertEqual(testResult, None) git.attribute( "revision").value = "45021a874e090b765acc5e2696154c495686614b" testResult = git.update(self._env) self.assertEqual(testResult, None) commands.getoutput( "cat /tmp/hello-world/c.c >> /tmp/hello-world/dos.bat") testResult = git.update(self._env) self.assertEqual(testResult, None) #after the test, clean the environment self.execute_command(["rm", "-rf", "hello-world"], "/tmp") # download a specific version git.attribute( "revision").value = "3fa7c46d11b11d61f1cbadc6888be5d0eae21969" testResult = git.download(self._env) self.assertEqual(testResult, None) # verify that the version is the correct one testStatus = commands.getoutput('cd /tmp/hello-world; git log') version = re.compile(' +\w+').search(testStatus).group().replace( " ", "") self.assertEqual(version, "3fa7c46d11b11d61f1cbadc6888be5d0eae21969") self.execute_command(["rm", "-rf", "gccxml"], "/tmp") #Wrong repository git.attribute( "url").value = "git://inexistant.server.com/git/hello-world.git" git.attribute( "revision").value = "78cfc43c2827b9e48e6586a3523ff845a6378889" self._logger.set_current_module(self._env._module_name) testResult = None try: testResult = git.download(self._env) self.fail("There was no problem with a non existent repository. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) self.execute_command(["rm", "-rf", "gccxml"], "/tmp") # no protocol git.attribute("url").value = "github.com/git/hello-world.git" self._logger.set_current_module(self._env._module_name) testResult = None try: testResult = git.download(self._env) self.fail("There was no problem without protocol. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) git.attribute("url").value = "git://github.com/git/hello-world.git" self.execute_command(["rm", "-rf", "gccxml"], "/tmp") # try to download to a non existent directory testStatus = commands.getoutput('rm -rf /tmp/testDir') self._env._sourcedir = "/tmp/testDir" testResult = None try: testResult = git.download(self._env) self.fail("There was no problem, target directory does not" " exist and it managed to finish the operation. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) # try to download to a directory where the user has no permission testStatus = commands.getoutput( 'mkdir /tmp/testDir;chmod 000 /tmp/testDir') testResult = None try: testResult = git.download(self._env) self.fail( "There was no problem, user has no permission on the" " target directory and it managed to finish the operation. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) testStatus = commands.getoutput( 'chmod 755 /tmp/testDir; rm -rf /tmp/testDir') # Invalid argument, it is int and should be string self._env._sourcedir = -60 testResult = None try: testResult = git.download(self._env) self.fail("The version is inexistent, but there is no error. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) # returns to the original state self._env._sourcedir = "/tmp" # can't go for an inexistent version git.attribute( "revision").value = "1000000000000000000000000000000000000000" testResult = None try: testResult = git.download(self._env) self.fail("The version is inexistent, but there is no error. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None)
def test_CmakeModule(self): """Tests the WafModuleBuild Class from ModuleBuild. """ cmake = ModuleBuild.create("cmake") self.assertNotEqual(cmake, None) self.assertEqual(cmake.name(), "cmake") self._env.start_build("cmake", "/tmp", cmake.supports_objdir) # Environment settings cvs = ModuleSource.create("cvs") testResult = cvs.check_version(self._env) self.assertTrue(testResult) cvs.attribute("root").value = ":pserver:anoncvs:@www.gccxml.org:/cvsroot/GCC_XML" cvs.attribute("module").value="gccxml" cvs.attribute("date").value="2009-09-21" self._env._module_name="gccxml" self._env._module_dir="gccxml" self._logger.set_current_module(self._env._module_name) # bazaar.attribute("revision").value = "revno:795" testStatus = commands.getoutput('mkdir /tmp/source') testResult = cvs.download(self._env) self.assertEqual(testResult, None) #check that has the cmake version required is installed in the machine testResult = cmake.check_version(self._env) self.assertTrue(testResult) # Expected case test self._env.objdir = self._env.srcdir+"/object" # test patch self.assertEqual(cmake.attribute('patch').value, '') cmake.attribute('patch').value = self._env.srcdir + '/test.patch' self.assertEqual(cmake.attribute('patch').value, self._env.srcdir + '/test.patch') testResult = None try: testResult = cmake.add_attribute('patch', 'ERRROR', 'SHOULD NOT HAVE BEEN ADDED') self.fail("The attribute patch exists already, should not be" + " able to add it. ") except AssertionError as e: self.assertNotEqual(e, None) self.assertEqual(testResult, None) try: testResult = cmake.build(self._env, "1") self.fail("The patch does not exist, should not have being able" + " to find the path file and give an error. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) # creates the file, empty, but created testStatus = commands.getoutput('touch ' + self._env.srcdir + '/test.patch') testStatus = commands.getoutput('rm -rf /tmp/source/gccxml/object') try: testResult = cmake.build(self._env, "1") except TaskError as t: print("Error compiling the module, maybe gccxml is not compatible with this architecture") self.assertEqual(testResult, None) testStatus = commands.getoutput('ls /tmp/source/gccxml/object|wc') created = re.compile(' +\d+').search(testStatus).group().strip() self.assertNotEqual(created, "0") # call the distclean to remove the build #TODO: This module does not accepts distclean find another one to test # testResult = cmake.distclean(self._env) # self.assertEqual(testResult, None) # testStatus = commands.getoutput('ls /tmp/source/gccxml/object|wc') # created = re.compile(' +\d+').search(testStatus).group().strip() # self.assertEqual(created, "0") # call the clean to remove the build # TODO: Find a solution for the remaining directories # - It is strange because the waf does not remove the directories, # just the object files.... Should this be like that??!?! testResult = cmake.clean(self._env) self.assertEqual(testResult, None) testStatus = commands.getoutput('ls /tmp/source/gccxml/object/GCC/' 'gcc/CMakeFiles/backend.dir/*.o|wc') created = re.compile(' +\d+').search(testStatus).group().strip() self.assertEqual(created, "0") # TODO: neighter the --generate-version appears but I couldn't also # find a configuration argument for pybindgen :( # Call with extra options cmake.attribute("CFLAGS").value = "-g" # waf.attribute("configure_arguments").value = "--enable-examples --enable-tests" # cmake.attribute("builarguments").value = "--generate-version" try: testResult = cmake.build(self._env, "1") except TaskError as t: print("Error compiling the module, maybe gccxml is not compatible with this architecture") self.assertEqual(testResult, None) testStatus = commands.getoutput('ls -l /tmp/source/gccxml/object|wc') created = re.compile(' +\d+').search(testStatus).group().strip() self.assertNotEqual(created, "0")
def test_makeModule(self): """Tests the WafModuleBuild Class from ModuleBuild. """ make = ModuleBuild.create("make") self.assertNotEqual(make, None) self.assertEqual(make.name(), "make") make.attribute('install_arguments').value = 'PREFIX=/tmp/source/readversiondef' self._env.start_build("make", "/tmp", make.supports_objdir) # Environment settings mercurial = ModuleSource.create("mercurial") testResult = mercurial.check_version(self._env) self.assertTrue(testResult) mercurial.attribute("url").value = "http://code.nsnam.org/mathieu/readversiondef" self._env._module_name="readversiondef" self._env._module_dir="readversiondef" testStatus = commands.getoutput('rm -rf /tmp/source') self._logger.set_current_module(self._env._module_name) testResult = mercurial.download(self._env) self.assertEqual(testResult, None) #check that has the make version required is installed in the machine testResult = make.check_version(self._env) self.assertTrue(testResult) # Expected case test self._env.objdir = self._env.srcdir+"/object" # test patch self.assertEqual(make.attribute('patch').value, '') make.attribute('patch').value = self._env.srcdir + '/test.patch' self.assertEqual(make.attribute('patch').value, self._env.srcdir + '/test.patch') testResult = None try: testResult = make.add_attribute('patch', 'ERRROR', 'SHOULD NOT HAVE BEEN ADDED') self.fail("The attribute patch exists already, should not be" + " able to add it. ") except AssertionError as e: self.assertNotEqual(e, None) self.assertEqual(testResult, None) try: testResult = make.build(self._env, "1") self.fail("The patch does not exist, should not have being able" + " to find the path file and give an error. ") except TaskError as e: self.assertNotEqual(e._reason, None) self.assertEqual(testResult, None) # creates the file, empty, but created testStatus = commands.getoutput('touch ' + self._env.srcdir + '/test.patch') testStatus = commands.getoutput('rm -rf /tmp/source/readversiondef/object') try: testResult = make.build(self._env, "1") except TaskError as t: print(t.reason) self.assertEqual(testResult, None) make.attribute('patch').value = '' testStatus = commands.getoutput('ls /tmp/source/readversiondef/bin|wc') created = re.compile(' +\d+').search(testStatus).group().strip() self.assertNotEqual(created, "0") #TODO: This module does not accepts distclean find another one to test # testResult = make.distclean(self._env) # self.assertEqual(testResult, None) # testStatus = commands.getoutput('ls /tmp/source/readversiondef/bin|wc') # created = re.compile(' +\d+').search(testStatus).group().strip() # self.assertEqual(created, "0") # call the clean to remove the build # TODO: This module does not support make clean find another one # testResult = make.clean(self._env) # self.assertEqual(testResult, None) # testStatus = commands.getoutput('ls /tmp/source/readversiondef/*.o|wc') # created = re.compile(' +\d+').search(testStatus).group().strip() # self.assertEqual(created, "0") # TODO: neither the --generate-version appears but I couldn't also # find a configuration argument for pybindgen :( # Call with extra options make.attribute("configure_arguments").value = "all" try: testResult = make.build(self._env, "1") except TaskError as t: print(t.reason) self.assertEqual(testResult, None) make.attribute('configure_arguments').value = '' make.attribute("post_installation").value = "rm -rf /tmp/source/readversiondef/readversiondef.o" try: testResult = make.build(self._env, "1") except TaskError as t: print(t.reason) self.assertEqual(testResult, None) make.perform_post_installation(self._env) testStatus = commands.getoutput('ls /tmp/source/readversiondef/*.o|wc') created = re.compile(' +\d+').search(testStatus).group().strip() self.assertEqual(created, "0")
def test_check_build_version(self): """Tests the _check_source_code method of Class Bake. """ # Environment settings # Environment settings mercurial = ModuleSource.create("mercurial") testResult = mercurial.check_version(self._env) self.assertTrue(testResult) self._env._debug = True pathname = os.path.dirname(compensate_third_runner()) if not pathname: pathname="." testStatus = commands.getoutput('python ' + pathname + '/../bake.py configure' ' --enable=openflow-ns3' ' --sourcedir=/tmp/source' ' --installdir=/tmp/source') mercurial.attribute("url").value = "http://code.nsnam.org/bhurd/openflow" self._env._module_name="openflow-ns3" self._env._module_dir="openflow-ns3" testStatus = commands.getoutput('rm -rf /tmp/source') self._logger.set_current_module(self._env._module_name) testResult = mercurial.download(self._env) # try: # testResult = mercurial.download(self._env) # self.fail("The directory does not exist, this shouldn't work") # except TaskError as e: # self.assertNotEqual(e._reason, None) # self.assertEqual(testResult, None) bake = Bake() config = "bakefile.xml" #bakefile.xml" args = [] parser = bake._option_parser('build') parser.add_option('-j', '--jobs', help='Allow N jobs at once. Default is 1.', type='int', action='store', dest='jobs', default=1) parser.add_option("--debug", action="store_true", dest="debug", default=False, help="Should we enable extra Bake debugging output ?") (options, args_left) = parser.parse_args(args) # bake.setMainOptions(options) Bake.main_options = options # Tests typical case, the module is there and the object directory is not self._env._installdir = self._env.srcdir+"/install_bake" testResult = bake._check_build_version(config, options); self.assertEqual(testResult, None) # if the user has no permission to see the file testStatus = commands.getoutput('chmod 000 /tmp/source') testResult=None try: testResult = bake._check_source_code(config, options); except SystemExit as e: self.assertTrue(e.code==1,"Wrong error code received") self.assertFalse(testResult, None) testStatus = commands.getoutput('chmod 755 /tmp/source') # if the folder is not where it should be testStatus = commands.getoutput('rm -rf /tmp/source') testResult=None testResult=None try: testResult = bake._check_source_code(config, options); except SystemExit as e: self.assertTrue(e.code==1,"Wrong error code received") self.assertFalse(testResult, None)