def _setupDevices(self, nodeName): self._devBooter, self._devMgr = self.launchDeviceManager( "/nodes/test_%s_node/DeviceManager.dcd.xml" % (nodeName, )) self.assertNotEqual(self._devMgr, None) self._parentDevice = None self._childDevice = None # These tests must be kept in sync with the DCD. scatest.verifyDeviceLaunch(self, self._devMgr, 2) for device in self._devMgr._get_registeredDevices(): if device._get_identifier( ) == "DCE:8f3478e3-626e-45c3-bd01-0a8117dbe59b": self._parentDevice = device elif device._get_identifier( ) == "DCE:2427279b-ed30-4f27-8a58-022110e1f898": self._childDevice = device self.assertNotEqual(self._parentDevice, None) self.assertNotEqual(self._childDevice, None) self._aggregateDevice = self._parentDevice._narrow(CF.AggregateDevice) self._executableDevice = self._parentDevice._narrow( CF.ExecutableDevice) self.assertNotEqual(self._aggregateDevice, None) self.assertNotEqual(self._executableDevice, None)
def test_NodeCleanupOnNodeBooterKill(self): # Test that if we destroy a device, all applications using that device # are released self.assertEqual(len(self._domMgr._get_applicationFactories()), 0) self.assertEqual(len(self._domMgr._get_applications()), 0) self._domMgr.installApplication("/waveforms/CommandWrapper/CommandWrapper.sad.xml") self.assertEqual(len(self._domMgr._get_applicationFactories()), 1) self.assertEqual(len(self._domMgr._get_applications()), 0) # Start the executable devices first. This will ensure that matching properties # work because CommandWrapper specifies matching properties that only work # with BasicTestDevice nb1, devMgr = self.launchDeviceManager("/nodes/test_BasicTestDevice_node/DeviceManager.dcd.xml") self.assertNotEqual(devMgr, None) scatest.verifyDeviceLaunch(self, devMgr, 1) device = devMgr._get_registeredDevices()[0] appFact = self._domMgr._get_applicationFactories()[0] app = appFact.create(appFact._get_name(), [], []) self.assertEqual(len(self._domMgr._get_applicationFactories()), 1) self.assertEqual(len(self._domMgr._get_applications()), 1) self.terminateChild(nb1) self.assertEqual(len(self._domMgr._get_applicationFactories()), 1) self.assertEqual(len(self._domMgr._get_applications()), 0) self._domMgr.uninstallApplication(appFact._get_identifier()) self.assertEqual(len(self._domMgr._get_applicationFactories()), 0) self.assertEqual(len(self._domMgr._get_applications()), 0)
def test_py_RefreshSubdir(self): self.assertNotEqual(self._domMgr, None) # Ensure the expected device is available devBooter, devMgr = self.launchDeviceManager( "/nodes/test_BasicTestDevice_node/DeviceManager.dcd.xml") self.assertNotEqual(devMgr, None) scatest.verifyDeviceLaunch(self, devMgr, 1) device = devMgr._get_registeredDevices()[0] device.load(devMgr._get_fileSys(), "/data/subdir_test", CF.LoadableDevice.EXECUTABLE) self.assertEqual( os.listdir( 'sdr/cache/.BasicTestDevice_node/BasicTestDevice1/data/subdir_test/subdir_two' ), ['second_file.txt']) os.remove( 'sdr/cache/.BasicTestDevice_node/BasicTestDevice1/data/subdir_test/subdir_two/second_file.txt' ) self.assertEqual( os.listdir( 'sdr/cache/.BasicTestDevice_node/BasicTestDevice1/data/subdir_test/subdir_two' ), []) device.load(devMgr._get_fileSys(), "/data/subdir_test", CF.LoadableDevice.EXECUTABLE) self.assertEqual( os.listdir( 'sdr/cache/.BasicTestDevice_node/BasicTestDevice1/data/subdir_test/subdir_two' ), ['second_file.txt']) device.unload("/data/subdir_test")
def test_DomainManagerBadSadFile(self): devmgr_nb, devMgr = self.launchDeviceManager( "/nodes/SimpleDevMgr/DeviceManager.dcd.xml") self.assertNotEqual(devMgr, None) # NOTE These assert check must be kept in-line with the DeviceManager.dcd.xml scatest.verifyDeviceLaunch(self, devMgr, 1) # Test that the DCD file componentproperties get pushed to configure() # as per DeviceManager requirement SR:482 scatest.verifyDeviceLaunch(self, devMgr, 1) device = devMgr._get_registeredDevices()[0] self.assertNotEqual(device, None) # Now trying the component if self._domMgr: try: # the sad file contains an invalid assembly controller # reference ID that should causes an error sadpath = "/waveforms/SimpleWaveform/BadSimpleWaveform.sad.xml" self._domMgr.installApplication(sadpath) self.assertEqual(len(self._domMgr._get_applicationFactories()), 1) appFact = self._domMgr._get_applicationFactories()[0] self._app = appFact.create(appFact._get_name(), [], []) except: # exception is expected as the SAD file does not contain a # valid assembly controller pass # making sure the domain manager still alive self.assertEqual(len(self._domMgr._get_deviceManagers()), 1)
def test_cpp_DirectoryLoad(self): self.assertNotEqual(self._domMgr, None) # Verify in the devices cache is empty componentDir = os.path.join(scatest.getSdrPath(), "dom", "components", "CommandWrapperWithDirectoryLoad") deviceCacheDir = os.path.join(scatest.getSdrCache(), ".ExecutableDevice_node", "ExecutableDevice1", "components", "CommandWrapperWithDirectoryLoad") if os.path.exists(deviceCacheDir): os.system("rm -rf %s" % deviceCacheDir) self.assertEqual(len(self._domMgr._get_applicationFactories()), 0) self.assertEqual(len(self._domMgr._get_applications()), 0) self._domMgr.installApplication( "/waveforms/CommandWrapperWithDirectoryLoad/CommandWrapper.sad.xml" ) self.assertEqual(len(self._domMgr._get_applicationFactories()), 1) self.assertEqual(len(self._domMgr._get_applications()), 0) # Ensure the expected device is available devBooter, devMgr = self.launchDeviceManager( "/nodes/test_ExecutableDevice_node/DeviceManager.dcd.xml") self.assertNotEqual(devMgr, None) scatest.verifyDeviceLaunch(self, devMgr, 1) device = devMgr._get_registeredDevices()[0] appFact = self._domMgr._get_applicationFactories()[0] app = appFact.create(appFact._get_name(), [], []) # LOOK MA, NO DAS! self.assertEqual(len(self._domMgr._get_applicationFactories()), 1) self.assertEqual(len(self._domMgr._get_applications()), 1) # Verify that properties have been changed from their defaults self.assertEqual(len(app._get_componentNamingContexts()), 1) compName = app._get_componentNamingContexts()[0] comp = self._root.resolve(URI.stringToName( compName.elementId))._narrow(CF.Resource) self.assertNotEqual(comp, None) cmd = comp.query([ CF.DataType(id="DCE:a4e7b230-1d17-4a86-aeff-ddc6ea3df26e", value=any.to_any(None)) ])[0] args = comp.query([ CF.DataType(id="DCE:5d8bfe8d-bc25-4f26-8144-248bc343aa53", value=any.to_any(None)) ])[0] self.assertEqual(cmd.value._v, "/bin/echo") self.assertEqual(args.value._v, ["Hello World"]) app.stop() app.releaseObject() self.assertEqual(len(self._domMgr._get_applicationFactories()), 1) self.assertEqual(len(self._domMgr._get_applications()), 0) self._domMgr.uninstallApplication(appFact._get_identifier())
def test_cpp_BigFiles(self): self.assertNotEqual(self._domMgr, None) self.assertEqual(len(self._domMgr._get_applicationFactories()), 0) self.assertEqual(len(self._domMgr._get_applications()), 0) self._domMgr.installApplication( "/waveforms/CommandWrapperOsProcessor/CommandWrapper.sad.xml") self.assertEqual(len(self._domMgr._get_applicationFactories()), 1) self.assertEqual(len(self._domMgr._get_applications()), 0) # Ensure the expected device is available devBooter, devMgr = self.launchDeviceManager( "/nodes/test_ExecutableDevice_node/DeviceManager.dcd.xml") self.assertNotEqual(devMgr, None) scatest.verifyDeviceLaunch(self, devMgr, 1) device = devMgr._get_registeredDevices()[0] device.load(devMgr._get_fileSys(), '/data/big_file.txt', CF.LoadableDevice.SHARED_LIBRARY) source_file = open('sdr/dev/data/big_file.txt', 'r') destination_file = open( 'sdr/cache/.ExecutableDevice_node/ExecutableDevice1/data/big_file.txt', 'r') source_data = source_file.read() destination_data = destination_file.read() source_file.close() destination_file.close() self.assertEqual(source_data, destination_data) device.unload('/data/big_file.txt')
def _test_ShutdownParent(self, node): self._setupDevices(node) # test aggregate device releaseObject functionality pids = getChildren(self._devBooter.pid) self._parentDevice.releaseObject() for pid in pids: number_attempts = 0 while True: try: os.kill(pid, 0) # check to see if the process is still alive time.sleep(0.5) number_attempts += 1 except: break if number_attempts == 5: break pids = getChildren(self._devBooter.pid) scatest.verifyDeviceLaunch(self, self._devMgr, 0) # make sure the child device was also released self.assertEqual(len(pids), 0) self._devMgr.shutdown() self.assert_(self.waitTermination(self._devBooter)) self.assertEqual(len(self._domMgr._get_deviceManagers()), 0)
def test_py_UnloadOnRelease(self): # Test that releasing the device unloads all files deviceCacheDir = os.path.join(scatest.getSdrCache(), ".BasicTestDevice_node", "BasicTestDevice1") if os.path.exists(deviceCacheDir): os.system("rm -rf %s" % deviceCacheDir) self.assertNotEqual(self._domMgr, None) # Ensure the expected device is available devBooter, devMgr = self.launchDeviceManager( "/nodes/test_BasicTestDevice_node/DeviceManager.dcd.xml") self.assertNotEqual(devMgr, None) scatest.verifyDeviceLaunch(self, devMgr, 1) device = devMgr._get_registeredDevices()[0] self.assert_(not os.path.exists(deviceCacheDir + "/components/CommandWrapper")) self.assert_(not os.path.exists(deviceCacheDir + "/components/CapacityUser")) # Load a some files and directories device.load(self._domMgr._get_fileMgr(), "/components/CommandWrapper", CF.LoadableDevice.EXECUTABLE) device.load(self._domMgr._get_fileMgr(), "/components/CapacityUser/CapacityUser.py", CF.LoadableDevice.EXECUTABLE) device.load(self._domMgr._get_fileMgr(), "/components/CapacityUser/CapacityUser.prf.xml", CF.LoadableDevice.EXECUTABLE) device.load(self._domMgr._get_fileMgr(), "/components/CapacityUser/CapacityUser.scd.xml", CF.LoadableDevice.EXECUTABLE) device.load(self._domMgr._get_fileMgr(), "/components/CapacityUser/CapacityUser.spd.xml", CF.LoadableDevice.EXECUTABLE) # Simply check that the cache dir isn't empty and has the correct number of files self.assertEqual( len(os.listdir(deviceCacheDir + "/components/CommandWrapper")), 4) self.assertEqual( len(os.listdir(deviceCacheDir + "/components/CapacityUser")), 4) device.releaseObject() # Wait for the device to unregister. self.assert_(self._waitRegisteredDevices(devMgr, 0)) self.assertEqual( len(os.listdir(deviceCacheDir + "/components/CommandWrapper")), 0) self.assertEqual( len(os.listdir(deviceCacheDir + "/components/CapacityUser")), 0) self.assertEqual(len(self._domMgr._get_deviceManagers()), 1)
def _test_ShutdownChild(self, node): self._setupDevices(node) # test child device releaseObject functionality pids = getChildren(self._devBooter.pid) pids1 = getChildren(pids[0]) pids2 = getChildren(pids[1]) if len(pids2) == 1: child_pid = pids[0] parent_pid = pids[1] else: child_pid = pids[1] parent_pid = pids[0] self._childDevice.releaseObject() number_attempts = 0 while True: try: os.kill(child_pid, 0) # check to see if the process is still alive time.sleep(0.5) number_attempts += 1 except: break if number_attempts == 5: break self.assertEqual(len(self._aggregateDevice._get_devices()), 0) scatest.verifyDeviceLaunch(self, self._devMgr, 1) # make sure child device no longer exists pids = getChildren(self._devBooter.pid) self.assertEqual(len(pids), 1) # now make sure parent device releases okay pids = getChildren(self._devBooter.pid) self._parentDevice.releaseObject() scatest.verifyDeviceLaunch(self, self._devMgr, 0) number_attempts = 0 while True: try: os.kill(parent_pid, 0) # check to see if the process is still alive time.sleep(0.5) number_attempts += 1 except: break if number_attempts == 5: break pids = getChildren(self._devBooter.pid) self.assertEqual(len(pids), 0) self._devMgr.shutdown() self.assert_(self.waitTermination(self._devBooter)) self.assertEqual(len(self._domMgr._get_deviceManagers()), 0)
def test_py_BasicOperation(self): self.assertNotEqual(self._domMgr, None) self.assertEqual(len(self._domMgr._get_applicationFactories()), 0) self.assertEqual(len(self._domMgr._get_applications()), 0) self._domMgr.installApplication( "/waveforms/CommandWrapperOsProcessor/CommandWrapper.sad.xml") self.assertEqual(len(self._domMgr._get_applicationFactories()), 1) self.assertEqual(len(self._domMgr._get_applications()), 0) # Ensure the expected device is available devBooter, devMgr = self.launchDeviceManager( "/nodes/test_BasicTestDevice_node/DeviceManager.dcd.xml") self.assertNotEqual(devMgr, None) scatest.verifyDeviceLaunch(self, devMgr, 1) device = devMgr._get_registeredDevices()[0] appFact = self._domMgr._get_applicationFactories()[0] app = appFact.create(appFact._get_name(), [], []) # LOOK MA, NO DAS! self.assertEqual(len(self._domMgr._get_applicationFactories()), 1) self.assertEqual(len(self._domMgr._get_applications()), 1) # Verify that properties have been changed from their defaults self.assertEqual(len(app._get_componentNamingContexts()), 1) compName = app._get_componentNamingContexts()[0] comp = self._root.resolve(URI.stringToName( compName.elementId))._narrow(CF.Resource) self.assertNotEqual(comp, None) cmd = comp.query([ CF.DataType(id="DCE:a4e7b230-1d17-4a86-aeff-ddc6ea3df26e", value=any.to_any(None)) ])[0] args = comp.query([ CF.DataType(id="DCE:5d8bfe8d-bc25-4f26-8144-248bc343aa53", value=any.to_any(None)) ])[0] self.assertEqual(cmd.value._v, "/bin/echo") self.assertEqual(args.value._v, ["Hello World"]) app.stop() app.releaseObject() self.assertEqual(len(self._domMgr._get_applicationFactories()), 1) self.assertEqual(len(self._domMgr._get_applications()), 0) self._domMgr.uninstallApplication(appFact._get_identifier())
def test_DASAllocationFail(self): self._domMgr.installApplication("/waveforms/CapacityUsage/CapacityUsage.sad.xml") # Start the first DeviceManager nb1, node1 = self.launchDeviceManager("/nodes/test_BasicTestDevice_node/DeviceManager.dcd.xml") # Ensure the expected device is available self.assertNotEqual(node1, None) scatest.verifyDeviceLaunch(self, node1, 1) device1 = node1._get_registeredDevices()[0] self.assertEqual(self._getBogoMips(device1), 100000000) appFact = self._domMgr._get_applicationFactories()[0] # load the device assignment sequence das = minidom.parse(os.path.join(scatest.getSdrPath(), "dom/waveforms/CapacityUsage/CapacityUsage_DAS.xml")) ds = [] deviceAssignmentTypeNodeList = das.getElementsByTagName("deviceassignmenttype") for node in deviceAssignmentTypeNodeList: componentid = node.getElementsByTagName("componentid")[0].firstChild.data assigndeviceid = node.getElementsByTagName("assigndeviceid")[0].firstChild.data ds.append( CF.DeviceAssignmentType(str(componentid),str(assigndeviceid)) ) # Create two applications to take up the capacity of the first device # first on uses DAS app1 = appFact.create(appFact._get_name(), [], ds) self.assertEqual(self._getBogoMips(device1), 50000000) # second one is sans DAS app2 = appFact.create(appFact._get_name(), [], []) self.assertEqual(self._getBogoMips(device1), 0) # Try to create another app, which should fail due to lack of capacity. # doing this with DAS since it exercises a different piece of code try: failApp = appFact.create(appFact._get_name(), [], ds) failApp.releaseObject() self.fail("Created application with no capacity") except: pass app2.releaseObject() self.assertEqual(self._getBogoMips(device1), 50000000) app1.releaseObject() self.assertEqual(self._getBogoMips(device1), 100000000) self._domMgr.uninstallApplication(appFact._get_identifier())
def _test_FileChanged(self, nodeName, deviceName): # Test that updating a file in the SCA filesystem causes a device to reload that file # in its cache. deviceCacheDir = os.path.join(scatest.getSdrCache(), "." + nodeName, deviceName) if os.path.exists(deviceCacheDir): os.system("rm -rf %s" % deviceCacheDir) self.assertNotEqual(self._domMgr, None) fileMgr = self._domMgr._get_fileMgr() # Ensure the expected device is available devBooter, devMgr = self.launchDeviceManager( dcdFile="/nodes/test_%s/DeviceManager.dcd.xml" % nodeName) self.assertNotEqual(devMgr, None) scatest.verifyDeviceLaunch(self, devMgr, 1) device = devMgr._get_registeredDevices()[0] # Create the initial file we'll be loading. testFile = 'test.out' scaPath = '/' + testFile srcFile = os.path.join(os.environ['SDRROOT'], 'dom', testFile) f = open(srcFile, 'w') f.write('Pre') f.close() self._testFiles.append(srcFile) # Load the initial file onto the device and verify that it contains the expected text. device.load(fileMgr, scaPath, CF.LoadableDevice.EXECUTABLE) cacheFile = os.path.join(deviceCacheDir, testFile) f = open(cacheFile, 'r') self.assertEqual(f.readline(), 'Pre') f.close() # Update the file, making sure that the modification time is more recent than the cached file. f = open(srcFile, 'w') f.write('Post') f.close() os.utime( srcFile, (os.path.getatime(cacheFile), os.path.getmtime(cacheFile) + 1)) # Load the file again and verify that the cache has been updated. device.load(fileMgr, scaPath, CF.LoadableDevice.EXECUTABLE) f = open(cacheFile, 'r') self.assertEqual(f.readline(), 'Post') f.close()
def test_cpp_SharedLibraryLoad(self): # Ensure the expected device is available devBooter, devMgr = self.launchDeviceManager( dcdFile="/nodes/test_ExecutableDevice_node/DeviceManager.dcd.xml") self.assertNotEqual(devMgr, None) scatest.verifyDeviceLaunch(self, devMgr, 1) device = devMgr._get_registeredDevices()[0] # Load a "shared library" with a very short basename to check that the # C++ LoadableDevice base class does not regress; previously, it tried # some string operations that assumed the filename was at least 4 # characters long. try: device.load(self._domMgr._get_fileMgr(), "/mgr", CF.LoadableDevice.SHARED_LIBRARY) except CORBA.COMM_FAILURE: self.fail('Device died loading shared library with short path')
def test_DeviceManagerURIOverride(self): # Test that the device manager DCD can override the log4cxx URI domNB, domMgr = self.launchDomainManager(loggingURI="") self.assertNotEqual(domMgr, None) # Launch a device manager devNB, devMgr = self.launchDeviceManager( "/nodes/test_LoggingBasicTestDevice_node/DeviceManager.dcd.xml", loggingURI="dev/mgr/logging.properties") self.assertNotEqual(devMgr, None) # Double check the DeviceManager LOGGING_CONFIG_URI prop = CF.DataType(id="LOGGING_CONFIG_URI", value=any.to_any(None)) result = devMgr.query([prop]) self.assertEqual(len(result), 1) self.assertEqual(result[0].id, "LOGGING_CONFIG_URI") devLoggingConfigURI = result[0].value._v expectedDevLoggingConfigUri = "file://" + os.path.join( scatest.getSdrPath(), "dev/mgr/logging.properties") self.assertEqual(devLoggingConfigURI, expectedDevLoggingConfigUri) # Check the devices exec params scatest.verifyDeviceLaunch(self, devMgr, 1) device = devMgr._get_registeredDevices()[0] execparams = device.query([ CF.DataType(id="DCE:85d133fd-1658-4e4d-b3ff-1443cd44c0e2", value=any.to_any(None)) ])[0] args = execparams.value._v.split() execparams = {} while len(args) > 0: name = args.pop(0) value = args.pop(0) execparams[name] = value self.assert_(execparams.has_key("LOGGING_CONFIG_URI")) devMgrFileSysIOR = self._orb.object_to_string(devMgr._get_fileSys()) self.assertEqual(execparams["LOGGING_CONFIG_URI"].split("?fs=")[0], "sca:///mgr/logging.properties") execparamObj = self._orb.string_to_object( execparams["LOGGING_CONFIG_URI"].split("?fs=")[1]) # Need to compare actual objects since the IOR strings could potentially differ for the same object self.assert_(devMgr._get_fileSys()._is_equivalent(execparamObj))
def test_NodeCleanupOnDevMgrShutdown(self): # Test that if we destroy a device, all applications using that device # are released self.assertEqual(len(self._domMgr._get_applicationFactories()), 0) self.assertEqual(len(self._domMgr._get_applications()), 0) self._domMgr.installApplication("/waveforms/CommandWrapperLight/CommandWrapper.sad.xml") self.assertEqual(len(self._domMgr._get_applicationFactories()), 1) self.assertEqual(len(self._domMgr._get_applications()), 0) # Start the executable devices first. This will ensure that matching properties # work because CommandWrapper specifies matching properties that only work # with BasicTestDevice nb1, devMgr = self.launchDeviceManager("/nodes/test_BasicTestDevice_node/DeviceManager.dcd.xml") self.assertNotEqual(devMgr, None) scatest.verifyDeviceLaunch(self, devMgr, 1) device = devMgr._get_registeredDevices()[0] appFact = self._domMgr._get_applicationFactories()[0] apps = [] totalApps = 10 for entry in range(totalApps): apps.append(appFact.create(appFact._get_name(), [], [])) self.assertEqual(len(self._domMgr._get_applicationFactories()), 1) self.assertEqual(len(self._domMgr._get_applications()), totalApps) devMgr.shutdown() if not self.waitTermination(nb1): self.fail("DeviceManager did not die after shutdown") self.assertEqual(len(self._domMgr._get_applicationFactories()), 1) self.assertEqual(len(self._domMgr._get_applications()), 0) self._domMgr.uninstallApplication(appFact._get_identifier()) self.assertEqual(len(self._domMgr._get_applicationFactories()), 0) self.assertEqual(len(self._domMgr._get_applications()), 0)
def test_DeviceFailure(self): self.assertNotEqual(self._domMgr, None) self.assertEqual(len(self._domMgr._get_applicationFactories()), 0) self.assertEqual(len(self._domMgr._get_applications()), 0) devmgr_nb, devMgr = self.launchDeviceManager( "/nodes/test_PythonNodeNoUpdateUsageState_node/DeviceManager.dcd.xml" ) self.assertNotEqual(devMgr, None) # NOTE These assert check must be kept in-line with the DeviceManager.dcd.xml scatest.verifyDeviceLaunch(self, devMgr, 0) # Test that the DCD file componentproperties get pushed to configure() # as per DeviceManager requirement SR:482 devMgr.shutdown() self.assert_(self.waitTermination(devmgr_nb), "Nodebooter did not die after shutdown") self.assertEqual(len(self._domMgr._get_deviceManagers()), 0) self.assertNotEqual(self._domMgr, None) self.assertEqual(len(self._domMgr._get_applicationFactories()), 0) self.assertEqual(len(self._domMgr._get_applications()), 0)
def test_EmptyDir(self): self.assertNotEqual(self._domMgr, None) self.assertEqual(len(self._domMgr._get_applicationFactories()), 0) self.assertEqual(len(self._domMgr._get_applications()), 0) self._domMgr.installApplication( "/waveforms/CommandWrapperEmptyDir/CommandWrapperEmptyDir.sad.xml") self.assertEqual(len(self._domMgr._get_applicationFactories()), 1) self.assertEqual(len(self._domMgr._get_applications()), 0) # Ensure the expected device is available devBooter, devMgr = self.launchDeviceManager( "/nodes/test_BasicTestDevice_node/DeviceManager.dcd.xml") self.assertNotEqual(devMgr, None) scatest.verifyDeviceLaunch(self, devMgr, 1) device = devMgr._get_registeredDevices()[0] appFact = self._domMgr._get_applicationFactories()[0] app = appFact.create(appFact._get_name(), [], []) # LOOK MA, NO DAS! self.assertEqual(len(self._domMgr._get_applicationFactories()), 1) self.assertEqual(len(self._domMgr._get_applications()), 1) app.start() app.stop() tmpdir = os.path.join( scatest.getSdrCache(), '.BasicTestDevice_node/BasicTestDevice1/components/CommandWrapperEmptyDir/cmd_dir/tmp' ) self.assert_(os.path.isdir(tmpdir)) app.releaseObject() self.assertEqual(len(self._domMgr._get_applicationFactories()), 1) self.assertEqual(len(self._domMgr._get_applications()), 0) self._domMgr.uninstallApplication(appFact._get_identifier())
def _test_py_SharedLibraryLoad(self, node): self.assertNotEqual(self._domMgr, None) self.assertEqual(len(self._domMgr._get_applicationFactories()), 0) self.assertEqual(len(self._domMgr._get_applications()), 0) # Verify in the devices cache is empty componentDir = os.path.join(scatest.getSdrPath(), "dom", "components", "pythonSoftpkgDep") deviceCacheDir = os.path.join(scatest.getSdrCache(), ".test_GPP_node", "GPP_1", "components", "pythonSoftpkgDep") if os.path.exists(deviceCacheDir): os.system("rm -rf %s" % deviceCacheDir) self._domMgr.installApplication( "/waveforms/python_softpkg_deps/python_softpkg_deps.sad.xml") self.assertEqual(len(self._domMgr._get_applicationFactories()), 1) self.assertEqual(len(self._domMgr._get_applications()), 0) # Ensure the expected device is available devBooter, devMgr = self.launchDeviceManager(node) self.assertNotEqual(devMgr, None) scatest.verifyDeviceLaunch(self, devMgr, 1) device = devMgr._get_registeredDevices()[0] appFact = self._domMgr._get_applicationFactories()[0] app = appFact.create(appFact._get_name(), [], []) # LOOK MA, NO DAS! self.assertEqual(len(self._domMgr._get_applicationFactories()), 1) self.assertEqual(len(self._domMgr._get_applications()), 1) # Verify that properties have been changed from their defaults self.assertEqual(len(app._get_componentNamingContexts()), 1) compName = app._get_componentNamingContexts()[0] comp = self._root.resolve(URI.stringToName( compName.elementId))._narrow(CF.Resource) self.assertNotEqual(comp, None) cmd = comp.query([CF.DataType(id="prop1", value=any.to_any(None))])[0] self.assertEqual(cmd.value._v, "hello") cmd = comp.query([CF.DataType(id="prop2", value=any.to_any(None))])[0] self.assertEqual(cmd.value._v, "world") cmd = comp.query([CF.DataType(id="prop3", value=any.to_any(None))])[0] self.assertEqual(cmd.value._v, "helloworld") comp.start() cmd = comp.query([CF.DataType(id="prop1", value=any.to_any(None))])[0] self.assertEqual(cmd.value._v, "jones") cmd = comp.query([CF.DataType(id="prop2", value=any.to_any(None))])[0] self.assertEqual(cmd.value._v, "goober") cmd = comp.query([CF.DataType(id="prop3", value=any.to_any(None))])[0] self.assertEqual(cmd.value._v, "testing") app.stop() app.releaseObject() self.assertEqual(len(self._domMgr._get_applicationFactories()), 1) self.assertEqual(len(self._domMgr._get_applications()), 0) self._domMgr.uninstallApplication(appFact._get_identifier())
def test_BasicOperation(self): nodebooter, domMgr = self.launchDomainManager() self.assertNotEqual(domMgr, None) self.assertEqual(len(domMgr._get_applicationFactories()), 0) self.assertEqual(len(domMgr._get_applications()), 0) domMgr.installApplication( "/waveforms/CommandWrapper/CommandWrapper.sad.xml") self.assertEqual(len(domMgr._get_applicationFactories()), 1) self.assertEqual(len(domMgr._get_applications()), 0) # Load on the device ID das = minidom.parse( os.path.join( scatest.getSdrPath(), "dom/waveforms/CommandWrapper/CommandWrapper_DAS.xml")) ds = [] deviceAssignmentTypeNodeList = das.getElementsByTagName( "deviceassignmenttype") for node in deviceAssignmentTypeNodeList: componentid = node.getElementsByTagName( "componentid")[0].firstChild.data assigndeviceid = node.getElementsByTagName( "assigndeviceid")[0].firstChild.data ds.append( CF.DeviceAssignmentType(str(componentid), str(assigndeviceid))) # Ensure the expected device is available nodebooter, devMgr = self.launchDeviceManager( dcdFile="/nodes/test_BasicTestDevice_node/DeviceManager.dcd.xml") self.assertNotEqual(devMgr, None) self.assertEqual(len(ds), 1) scatest.verifyDeviceLaunch(self, devMgr, 1) device = devMgr._get_registeredDevices()[0] self.assertEqual(device._get_identifier(), ds[0].assignedDeviceId) # Query the known allocation properties memCapacity = device.query([ CF.DataType(id="DCE:8dcef419-b440-4bcf-b893-cab79b6024fb", value=any.to_any(None)) ])[0] bogoMips = device.query([ CF.DataType(id="DCE:5636c210-0346-4df7-a5a3-8fd34c5540a8", value=any.to_any(None)) ])[0] self.assertEqual(memCapacity.value._v, 100000000) self.assertEqual(bogoMips.value._v, 100000000) # query all properties, make sure that only 'external' properties show up allProps = device.query([]) # convert props to a dict allProps = dict([(x.id, x.value) for x in allProps]) # This isn't all of them...but a fair amount self.assertEqual( allProps.has_key("DCE:4a23ad60-0b25-4121-a630-68803a498f75"), False) # os_name self.assertEqual( allProps.has_key("DCE:fefb9c66-d14a-438d-ad59-2cfd1adb272b"), False) # processor_name self.assertEqual( allProps.has_key("DCE:7f36cdfb-f828-4e4f-b84f-446e17f1a85b"), False) # DeviceKind self.assertEqual( allProps.has_key("DCE:64303822-4c67-4c04-9a5c-bf670f27cf39"), False) # RunsAs self.assertEqual( allProps.has_key("DCE:021f10cf-7a05-46ec-a507-04b513b84bd4"), False) # HasXMIDAS appFact = domMgr._get_applicationFactories()[0] app = appFact.create(appFact._get_name(), [], ds) self.assertEqual(len(domMgr._get_applicationFactories()), 1) self.assertEqual(len(domMgr._get_applications()), 1) self.assertEqual(app._get_started(), False) app.start() self.assertEqual(app._get_started(), True) # Verify that capacity was allocated memCapacity = device.query([ CF.DataType(id="DCE:8dcef419-b440-4bcf-b893-cab79b6024fb", value=any.to_any(None)) ])[0] bogoMips = device.query([ CF.DataType(id="DCE:5636c210-0346-4df7-a5a3-8fd34c5540a8", value=any.to_any(None)) ])[0] self.assertEqual(memCapacity.value._v, 100000000 - 5000) self.assertEqual(bogoMips.value._v, 100000000 - 1000) app.stop() self.assertEqual(app._get_started(), False) app.releaseObject() self.assertEqual(len(domMgr._get_applicationFactories()), 1) self.assertEqual(len(domMgr._get_applications()), 0) # Verify that capacity was deallocated memCapacity = device.query([ CF.DataType(id="DCE:8dcef419-b440-4bcf-b893-cab79b6024fb", value=any.to_any(None)) ])[0] bogoMips = device.query([ CF.DataType(id="DCE:5636c210-0346-4df7-a5a3-8fd34c5540a8", value=any.to_any(None)) ])[0] self.assertEqual(memCapacity.value._v, 100000000) self.assertEqual(bogoMips.value._v, 100000000) domMgr.uninstallApplication(appFact._get_identifier())
def test_py_DirectoryLoad(self): self.assertNotEqual(self._domMgr, None) self.assertEqual(len(self._domMgr._get_applicationFactories()), 0) self.assertEqual(len(self._domMgr._get_applications()), 0) # Verify in the devices cache is empty componentDir = os.path.join(scatest.getSdrPath(), "dom", "components", "CommandWrapperWithDirectoryLoad") deviceCacheDir = os.path.join(scatest.getSdrCache(), ".BasicTestDevice_node", "BasicTestDevice1", "components", "CommandWrapperWithDirectoryLoad") if os.path.exists(deviceCacheDir): os.system("rm -rf %s" % deviceCacheDir) self._domMgr.installApplication( "/waveforms/CommandWrapperWithDirectoryLoad/CommandWrapper.sad.xml" ) self.assertEqual(len(self._domMgr._get_applicationFactories()), 1) self.assertEqual(len(self._domMgr._get_applications()), 0) # Ensure the expected device is available devBooter, devMgr = self.launchDeviceManager( "/nodes/test_BasicTestDevice_node/DeviceManager.dcd.xml") self.assertNotEqual(devMgr, None) scatest.verifyDeviceLaunch(self, devMgr, 1) device = devMgr._get_registeredDevices()[0] appFact = self._domMgr._get_applicationFactories()[0] app = appFact.create(appFact._get_name(), [], []) # LOOK MA, NO DAS! self.assertEqual(len(self._domMgr._get_applicationFactories()), 1) self.assertEqual(len(self._domMgr._get_applications()), 1) # Verify that properties have been changed from their defaults self.assertEqual(len(app._get_componentNamingContexts()), 1) compName = app._get_componentNamingContexts()[0] comp = self._root.resolve(URI.stringToName( compName.elementId))._narrow(CF.Resource) self.assertNotEqual(comp, None) cmd = comp.query([ CF.DataType(id="DCE:a4e7b230-1d17-4a86-aeff-ddc6ea3df26e", value=any.to_any(None)) ])[0] args = comp.query([ CF.DataType(id="DCE:5d8bfe8d-bc25-4f26-8144-248bc343aa53", value=any.to_any(None)) ])[0] self.assertEqual(cmd.value._v, "/bin/echo") self.assertEqual(args.value._v, ["Hello World"]) # Verify in the devices cache that the directory structure was mirrored exactly for root, dirs, files in os.walk(componentDir): # turn the abs path in to a relative path rel_root = root[len(componentDir) + 1:] for dir in dirs: # Hidden files aren't loaded if dir[0] != ".": expectedDir = os.path.join(deviceCacheDir, rel_root, dir) self.assertEqual( os.path.isdir(expectedDir), True, "Dir %s not found at %s" % (dir, expectedDir)) else: # Don't descend into hidden sub-dirs dirs.remove(dir) for f in files: # Hidden files aren't loaded if f[0] != ".": expectedFile = os.path.join(deviceCacheDir, rel_root, f) self.assertEqual( os.path.isfile(expectedFile), True, "File %s not found at %s" % (f, expectedFile)) app.stop() app.releaseObject() self.assertEqual(len(self._domMgr._get_applicationFactories()), 1) self.assertEqual(len(self._domMgr._get_applications()), 0) self._domMgr.uninstallApplication(appFact._get_identifier())
def test_MultipleAllocations(self): self._domMgr.installApplication("/waveforms/CapacityUsage/CapacityUsage.sad.xml") # Start the first DeviceManager nb1, node1 = self.launchDeviceManager("/nodes/test_BasicTestDevice_node/DeviceManager.dcd.xml") # Ensure the expected device is available self.assertNotEqual(node1, None) scatest.verifyDeviceLaunch(self, node1, 1) device1 = node1._get_registeredDevices()[0] self.assertEqual(self._getBogoMips(device1), 100000000) appFact = self._domMgr._get_applicationFactories()[0] # Create two applications to take up the capacity of the first device app1 = appFact.create(appFact._get_name(), [], []) self.assertEqual(self._getBogoMips(device1), 50000000) app2 = appFact.create(appFact._get_name(), [], []) self.assertEqual(self._getBogoMips(device1), 0) # Try to create another app, which should fail due to lack of capacity. try: failApp = appFact.create(appFact._get_name(), [], []) failApp.releaseObject() self.fail("Created application with no capacity") except: pass # TODO: Check that no naming context was left behind from the failed creation (ticket #352). # Start the second DeviceManager nb2, node2 = self.launchDeviceManager("/nodes/test_BasicTestDevice3_node/DeviceManager.dcd.xml") # Ensure the expected device is available self.assertNotEqual(node2, None) scatest.verifyDeviceLaunch(self, node2, 1) device2 = node2._get_registeredDevices()[0] self.assertEqual(self._getBogoMips(device2), 100000000) # Create two more applications to take up the capacity of the second device app3 = appFact.create(appFact._get_name(), [], []) self.assertEqual(self._getBogoMips(device1), 0) self.assertEqual(self._getBogoMips(device2), 50000000) app4 = appFact.create(appFact._get_name(), [], []) self.assertEqual(self._getBogoMips(device1), 0) self.assertEqual(self._getBogoMips(device2), 0) # Release the applications and make sure that the capacities are correctly restored app4.releaseObject() self.assertEqual(self._getBogoMips(device1), 0) self.assertEqual(self._getBogoMips(device2), 50000000) app3.releaseObject() self.assertEqual(self._getBogoMips(device1), 0) self.assertEqual(self._getBogoMips(device2), 100000000) app2.releaseObject() self.assertEqual(self._getBogoMips(device1), 50000000) self.assertEqual(self._getBogoMips(device2), 100000000) app1.releaseObject() self.assertEqual(self._getBogoMips(device1), 100000000) self.assertEqual(self._getBogoMips(device2), 100000000) # Create four more copies of the application app1 = appFact.create(appFact._get_name(), [], []) app2 = appFact.create(appFact._get_name(), [], []) app3 = appFact.create(appFact._get_name(), [], []) app4 = appFact.create(appFact._get_name(), [], []) self.assertEqual(self._getBogoMips(device1), 0) self.assertEqual(self._getBogoMips(device2), 0) # Release the applications (again) and make sure that the capacities are correctly restored app4.releaseObject() app3.releaseObject() app2.releaseObject() app1.releaseObject() self.assertEqual(self._getBogoMips(device1), 100000000) self.assertEqual(self._getBogoMips(device2), 100000000) self._domMgr.uninstallApplication(appFact._get_identifier())
def test_ComplexAllocation(self): # Install the waveform before registering devices to ensure the bug #281 # doesn't come back self.assertEqual(len(self._domMgr._get_applicationFactories()), 0) self.assertEqual(len(self._domMgr._get_applications()), 0) self._domMgr.installApplication("/waveforms/CommandWrapper/CommandWrapper.sad.xml") self.assertEqual(len(self._domMgr._get_applicationFactories()), 1) self.assertEqual(len(self._domMgr._get_applications()), 0) # Start the executable devices first. This will ensure that matching properties # work because CommandWrapper specifies matching properties that only work # with BasicTestDevice nb1, execDevNode1 = self.launchDeviceManager("/nodes/test_MultipleExecutableDevice_node/DeviceManager.dcd.xml") self.assertNotEqual(execDevNode1, None) nb2, basicDevNode1 = self.launchDeviceManager("/nodes/test_BasicTestDevice_node/DeviceManager.dcd.xml") self.assertNotEqual(basicDevNode1, None) nb3, basicDevNode2 = self.launchDeviceManager("/nodes/test_BasicTestDevice3_node/DeviceManager.dcd.xml") self.assertNotEqual(basicDevNode2, None) # Ensure the expected devices are available scatest.verifyDeviceLaunch(self, basicDevNode1, 1) for device in basicDevNode1._get_registeredDevices(): # Query the known allocation properties memCapacity = device.query([CF.DataType(id="DCE:8dcef419-b440-4bcf-b893-cab79b6024fb", value=any.to_any(None))])[0] bogoMips = device.query([CF.DataType(id="DCE:5636c210-0346-4df7-a5a3-8fd34c5540a8", value=any.to_any(None))])[0] self.assertEqual(memCapacity.value._v, 100000000) self.assertEqual(bogoMips.value._v, 100000000) scatest.verifyDeviceLaunch(self, basicDevNode2, 1) for device in basicDevNode2._get_registeredDevices(): # Query the known allocation properties memCapacity = device.query([CF.DataType(id="DCE:8dcef419-b440-4bcf-b893-cab79b6024fb", value=any.to_any(None))])[0] bogoMips = device.query([CF.DataType(id="DCE:5636c210-0346-4df7-a5a3-8fd34c5540a8", value=any.to_any(None))])[0] self.assertEqual(memCapacity.value._v, 100000000) self.assertEqual(bogoMips.value._v, 100000000) scatest.verifyDeviceLaunch(self, execDevNode1, 4) appFact = self._domMgr._get_applicationFactories()[0] app = appFact.create(appFact._get_name(), [], []) # LOOK MA, NO DAS! self.assertEqual(len(self._domMgr._get_applicationFactories()), 1) self.assertEqual(len(self._domMgr._get_applications()), 1) # We don't know which device actually got allocated so check that one of them has freeDevice = None allocatedDevice = None for device in (basicDevNode1._get_registeredDevices()[0], basicDevNode2._get_registeredDevices()[0]): self.assertNotEqual(device._get_usageState(), CF.Device.BUSY) if device._get_usageState() == CF.Device.IDLE: memCapacity = device.query([CF.DataType(id="DCE:8dcef419-b440-4bcf-b893-cab79b6024fb", value=any.to_any(None))])[0] bogoMips = device.query([CF.DataType(id="DCE:5636c210-0346-4df7-a5a3-8fd34c5540a8", value=any.to_any(None))])[0] self.assertEqual(memCapacity.value._v, 100000000) self.assertEqual(bogoMips.value._v, 100000000) freeDevice = device elif device._get_usageState() == CF.Device.ACTIVE: # Verify that capacity was allocated memCapacity = device.query([CF.DataType(id="DCE:8dcef419-b440-4bcf-b893-cab79b6024fb", value=any.to_any(None))])[0] bogoMips = device.query([CF.DataType(id="DCE:5636c210-0346-4df7-a5a3-8fd34c5540a8", value=any.to_any(None))])[0] self.assertEqual(memCapacity.value._v, 100000000-5000) self.assertEqual(bogoMips.value._v, 100000000-1000) allocatedDevice = device self.assertNotEqual(freeDevice, None) self.assertNotEqual(allocatedDevice, None) app.stop() app.releaseObject() self.assertEqual(len(self._domMgr._get_applicationFactories()), 1) self.assertEqual(len(self._domMgr._get_applications()), 0) # # # Verify that capacity was deallocated # memCapacity = freeDevice.query([CF.DataType(id="DCE:8dcef419-b440-4bcf-b893-cab79b6024fb", value=any.to_any(None))])[0] bogoMips = freeDevice.query([CF.DataType(id="DCE:5636c210-0346-4df7-a5a3-8fd34c5540a8", value=any.to_any(None))])[0] self.assertEqual(memCapacity.value._v, 100000000) self.assertEqual(bogoMips.value._v, 100000000) self._domMgr.uninstallApplication(appFact._get_identifier())
def test_BasicDevice(self): nodebooter, domMgr = self.launchDomainManager() devBooter, devMgr = self.launchDeviceManager("/nodes/test_BasicTestDevice_java_node/DeviceManager.dcd.xml") # Ensure the expected device is available self.assertNotEqual(devMgr, None) scatest.verifyDeviceLaunch(self, devMgr, 1) device = devMgr._get_registeredDevices()[0] # Checks init state self.assertEqual(device._get_usageState(), CF.Device.IDLE) self.assertEqual(device._get_adminState(), CF.Device.UNLOCKED) self.assertEqual(device._get_operationalState(), CF.Device.ENABLED) # Make sure we can do limited things self.assertEqual(device._get_started(), False) device.start() self.assertEqual(device._get_started(), True) device.stop() self.assertEqual(device._get_started(), False) # Makes sure the prop query is correct int_id = "DCE:0f99b2e4-9903-4631-9846-ff349d18eaaa" short_id = "DCE:d3aa6040-b731-4110-b814-376967264728" res = device.query([]) self.assertEqual(len(res), 9) ids = [] for r in res : ids.append(r.id) self.assertEqual("DCE:cdc5ee18-7ceb-4ae6-bf4c-31f983179b4d" in ids, True) self.assertEqual("DCE:0f99b2e4-9903-4631-9846-ff349d18ecfb" in ids, True) self.assertEqual(int_id in ids, True) self.assertEqual(short_id in ids, True) # Makes initial prop values are correct for r in res : if r.id == int_id: self.assertEqual(any.from_any(r.value), 10) elif r.id == short_id: self.assertEqual(any.from_any(r.value), 22) # Make sure allocs can be done props_int = [CF.DataType(id=int_id, value=any.to_any(2))] props_short = [CF.DataType(id=short_id, value=any.to_any(20))] self.assertEqual(device.allocateCapacity(props_int), True) self.assertEqual(device.allocateCapacity(props_short), True) # Makes sure values are correct after alloc res = device.query([]) for r in res : if r.id == int_id: self.assertEqual(any.from_any(r.value), 8) elif r.id == short_id: self.assertEqual(any.from_any(r.value), 2) # Makes sure device becomes BUSY when all allocation has been done props = [CF.DataType(id=int_id, value=any.to_any(4)), CF.DataType(id=short_id, value=any.to_any(1))] self.assertEqual(device.allocateCapacity(props), True) self.assertEqual(device._get_usageState(), CF.Device.ACTIVE) self.assertEqual(device.allocateCapacity(props), True) self.assertEqual(device._get_usageState(), CF.Device.BUSY) # Makes sure that no more allocation can be done self.assertEqual(device.allocateCapacity(props_int), False) self.assertEqual(device.allocateCapacity(props_short), False) self.assertEqual(device.allocateCapacity(props), False) # Makes sure that the dealloc works properly device.deallocateCapacity(props) res = device.query([]) for r in res : if r.id == int_id: self.assertEqual(any.from_any(r.value), 4) elif r.id == short_id: self.assertEqual(any.from_any(r.value), 1) # Makes sure that alloc fail of 1 prop prevents both from writing self.assertEqual(device.allocateCapacity(props_int), True) self.assertEqual(device.allocateCapacity(props_int), True) self.assertEqual(device.allocateCapacity(props), False) res = device.query([]) for r in res: if r.id == int_id: self.assertEqual(any.from_any(r.value), 0) elif r.id == short_id: self.assertEqual(any.from_any(r.value), 1) # Makes sure that props can't be dealloced beyond their orig capacity props = [CF.DataType(id=int_id, value=any.to_any(9)), CF.DataType(id=short_id, value=any.to_any(20))] device.deallocateCapacity(props) self.assertRaises(CF.Device.InvalidCapacity, device.deallocateCapacity, props_int) self.assertRaises(CF.Device.InvalidCapacity, device.deallocateCapacity, props_short) # Save current values to restore later state = device.query([CF.DataType(int_id, any.to_any(None)), CF.DataType(short_id, any.to_any(None))]) # Makes sure if if 1 dealloc fails, neither are written # NB: 1.9 does not guarantee this behavior. props = [CF.DataType(id=int_id, value=any.to_any(1)), CF.DataType(id=short_id, value=any.to_any(20))] self.assertRaises(CF.Device.InvalidCapacity, device.deallocateCapacity, props) #res = device.query([]) #for r in res: # if r.id == int_id: # self.assertEqual(any.from_any(r.value), 9) # elif r.id == short_id: # self.assertEqual(any.from_any(r.value), 21) # Restore device to known state device.configure(state) # Makes sure if props are at full capacity, usage State returns to IDLE props = [CF.DataType(id=int_id, value=any.to_any(1)), CF.DataType(id=short_id, value=any.to_any(1))] device.deallocateCapacity(props) self.assertEqual(device._get_usageState(), CF.Device.IDLE) res = device.query([]) for r in res: if r.id == int_id: self.assertEqual(any.from_any(r.value), 10) elif r.id == short_id: self.assertEqual(any.from_any(r.value), 22) # Makes sure that props with aren't allocatable, don't get allocated prop = [CF.DataType(id="no_allocation", value=any.to_any(1))] self.assertRaises(CF.Device.InvalidCapacity, device.allocateCapacity, prop) prop = [CF.DataType(id="not_external", value=any.to_any(1.1))] self.assertRaises(CF.Device.InvalidCapacity, device.allocateCapacity, prop) prop = [CF.DataType(id="non_simple1", value=any.to_any("Hello"))] self.assertRaises(CF.Device.InvalidCapacity, device.allocateCapacity, prop) prop = [CF.DataType(id="non_simple2", value=any.to_any([]))] self.assertRaises(CF.Device.InvalidCapacity, device.allocateCapacity, prop) res = device.query([]) for r in res: if r.id == int_id: self.assertEqual(any.from_any(r.value), 10) elif r.id == short_id: self.assertEqual(any.from_any(r.value), 22) # Check that execparams are set in initialize (issue #561). for prop in device.runTest(561, []): self.assertNotEqual(any.from_any(prop.value), None, 'execparams not set in intialize()') device.releaseObject() scatest.verifyDeviceLaunch(self, devMgr, 0) self.assertEqual(len(domMgr._get_deviceManagers()), 1) devMgr.shutdown() self.assertEqual(len(domMgr._get_deviceManagers()), 0)
def test_cpp_LoadUnload(self): # Test that releasing the device unloads all files deviceCacheDir = os.path.join(scatest.getSdrCache(), ".ExecutableDevice_node", "ExecutableDevice1") if os.path.exists(deviceCacheDir): os.system("rm -rf %s" % deviceCacheDir) self.assertNotEqual(self._domMgr, None) # Ensure the expected device is available devBooter, devMgr = self.launchDeviceManager( "/nodes/test_ExecutableDevice_node/DeviceManager.dcd.xml") self.assertNotEqual(devMgr, None) scatest.verifyDeviceLaunch(self, devMgr, 1) device = devMgr._get_registeredDevices()[0] self.assert_(not os.path.exists(deviceCacheDir + "/components/CommandWrapper")) self.assert_(not os.path.exists(deviceCacheDir + "/components/CapacityUser")) # Load a some files and directories device.load(self._domMgr._get_fileMgr(), "/components/CommandWrapper", CF.LoadableDevice.EXECUTABLE) device.load(self._domMgr._get_fileMgr(), "/components/CapacityUser/CapacityUser.py", CF.LoadableDevice.EXECUTABLE) device.load(self._domMgr._get_fileMgr(), "/components/CapacityUser/CapacityUser.prf.xml", CF.LoadableDevice.EXECUTABLE) device.load(self._domMgr._get_fileMgr(), "/components/CapacityUser/CapacityUser.scd.xml", CF.LoadableDevice.EXECUTABLE) device.load(self._domMgr._get_fileMgr(), "/components/CapacityUser/CapacityUser.spd.xml", CF.LoadableDevice.EXECUTABLE) # Simply check that the cache dir isn't empty and has the correct number of files self.assertEqual( len(os.listdir(deviceCacheDir + "/components/CommandWrapper")), 4) self.assertEqual( len(os.listdir(deviceCacheDir + "/components/CapacityUser")), 4) # Check that a second load doesn't do anything weird device.load(self._domMgr._get_fileMgr(), "/components/CommandWrapper", CF.LoadableDevice.EXECUTABLE) device.load(self._domMgr._get_fileMgr(), "/components/CapacityUser/CapacityUser.py", CF.LoadableDevice.EXECUTABLE) device.load(self._domMgr._get_fileMgr(), "/components/CapacityUser/CapacityUser.prf.xml", CF.LoadableDevice.EXECUTABLE) device.load(self._domMgr._get_fileMgr(), "/components/CapacityUser/CapacityUser.scd.xml", CF.LoadableDevice.EXECUTABLE) device.load(self._domMgr._get_fileMgr(), "/components/CapacityUser/CapacityUser.spd.xml", CF.LoadableDevice.EXECUTABLE) self.assertEqual( len(os.listdir(deviceCacheDir + "/components/CommandWrapper")), 4) self.assertEqual( len(os.listdir(deviceCacheDir + "/components/CapacityUser")), 4) # Clear out the deviceCache os.system("rm -rf %s" % (deviceCacheDir + "/components/CommandWrapper")) os.system( "rm -rf %s" % (deviceCacheDir + "/components/CapacityUser/CapacityUser.py")) self.assertEqual( os.path.exists(deviceCacheDir + "/components/CommandWrapper"), False) self.assertEqual( len(os.listdir(deviceCacheDir + "/components/CapacityUser")), 3) # Load files and directories, this should copy the files over because they don't exist, even if though the refCnt > 0 device.load(self._domMgr._get_fileMgr(), "/components/CommandWrapper", CF.LoadableDevice.EXECUTABLE) device.load(self._domMgr._get_fileMgr(), "/components/CapacityUser/CapacityUser.py", CF.LoadableDevice.EXECUTABLE) device.load(self._domMgr._get_fileMgr(), "/components/CapacityUser/CapacityUser.prf.xml", CF.LoadableDevice.EXECUTABLE) device.load(self._domMgr._get_fileMgr(), "/components/CapacityUser/CapacityUser.scd.xml", CF.LoadableDevice.EXECUTABLE) device.load(self._domMgr._get_fileMgr(), "/components/CapacityUser/CapacityUser.spd.xml", CF.LoadableDevice.EXECUTABLE) self.assertEqual( len(os.listdir(deviceCacheDir + "/components/CommandWrapper")), 4) self.assertEqual( len(os.listdir(deviceCacheDir + "/components/CapacityUser")), 4) # Now we need to unload 3 times print os.listdir(deviceCacheDir + "/components") for i in xrange(3): self.assertEqual( len(os.listdir(deviceCacheDir + "/components/CommandWrapper")), 4) self.assertEqual( len(os.listdir(deviceCacheDir + "/components/CapacityUser")), 4) device.unload("/components/CommandWrapper") device.unload("/components/CapacityUser/CapacityUser.py") device.unload("/components/CapacityUser/CapacityUser.prf.xml") device.unload("/components/CapacityUser/CapacityUser.scd.xml") device.unload("/components/CapacityUser/CapacityUser.spd.xml") #self.assertEqual(len(os.listdir(deviceCacheDir + "/components/CommandWrapper")), 0) # Empty directories get deleted self.assert_(not os.path.exists(deviceCacheDir + "/components/CommandWrapper")) self.assertEqual( len(os.listdir(deviceCacheDir + "/components/CapacityUser")), 0) device.releaseObject() # Wait for the device to unregister. self.assert_(self._waitRegisteredDevices(devMgr, 0)) self.assertEqual(len(self._domMgr._get_deviceManagers()), 1)
def test_java_SharedLibraryLoad(self): fp = open( 'sdr/dev/nodes/test_GPP_node/DeviceManager.dcd.xml.cache_working_dir', 'r') dcd_contents = fp.read() fp.close() dcd_contents = dcd_contents.replace('@@DIR1@@', os.getcwd() + "/tmp_cache") dcd_contents = dcd_contents.replace('@@DIR2@@', os.getcwd() + "/tmp_working") fp = open('sdr/dev/nodes/test_GPP_node/tmp.dcd.xml', 'w') fp.write(dcd_contents) fp.close() self.assertNotEqual(self._domMgr, None) self.assertEqual(len(self._domMgr._get_applicationFactories()), 0) self.assertEqual(len(self._domMgr._get_applications()), 0) # Verify in the devices cache is empty componentDir = os.path.join(scatest.getSdrPath(), "dom", "components", "javaSoftpkgJarDep") deviceCacheDir = os.path.join(os.getcwd(), "/tmp_cache") if os.path.exists(deviceCacheDir): os.system("rm -rf %s" % deviceCacheDir) # self._domMgr.installApplication("/waveforms/CommandWrapperWithDirectoryLoad/CommandWrapper.sad.xml") self._domMgr.installApplication( "/waveforms/java_softpkg_deps/java_softpkg_deps.sad.xml") self.assertEqual(len(self._domMgr._get_applicationFactories()), 1) self.assertEqual(len(self._domMgr._get_applications()), 0) # Ensure the expected device is available devBooter, devMgr = self.launchDeviceManager( "/nodes/test_GPP_node/tmp.dcd.xml") self.assertNotEqual(devMgr, None) scatest.verifyDeviceLaunch(self, devMgr, 1) device = devMgr._get_registeredDevices()[0] appFact = self._domMgr._get_applicationFactories()[0] app = appFact.create(appFact._get_name(), [], []) # LOOK MA, NO DAS! self.assertEqual(len(self._domMgr._get_applicationFactories()), 1) self.assertEqual(len(self._domMgr._get_applications()), 1) # Verify that properties have been changed from their defaults self.assertEqual(len(app._get_componentNamingContexts()), 1) compName = app._get_componentNamingContexts()[0] comp = self._root.resolve(URI.stringToName( compName.elementId))._narrow(CF.Resource) self.assertNotEqual(comp, None) cmd = comp.query([CF.DataType(id="hello", value=any.to_any(None))])[0] self.assertEqual(cmd.value._v, "world") comp.start() begin_time = time.time() cmd = comp.query([CF.DataType(id="hello", value=any.to_any(None))])[0] while cmd.value._v != "Java is so cool" and time.time( ) - begin_time < 15: time.sleep(0.5) cmd = comp.query([CF.DataType(id="hello", value=any.to_any(None))])[0] self.assertEqual(cmd.value._v, "Java is so cool") app.stop() app.releaseObject() self.assertEqual(len(self._domMgr._get_applicationFactories()), 1) self.assertEqual(len(self._domMgr._get_applications()), 0) self._domMgr.uninstallApplication(appFact._get_identifier()) (status, output) = commands.getstatusoutput('rm -rf tmp_cache') (status, output) = commands.getstatusoutput('rm -rf tmp_working') self._testFiles.append('sdr/dev/nodes/test_GPP_node/tmp.dcd.xml')
def checkRegisteredDevices(self,numDevices): scatest.verifyDeviceLaunch(self, self._devMgr, numDevices)
def setUp(self): domBooter, self._domMgr = self.launchDomainManager() devBooter, self._devMgr = self.launchDeviceManager( "/nodes/issue_111_node_cpp/DeviceManager.dcd.xml") scatest.verifyDeviceLaunch(self, self._devMgr, 1) self._device = self._devMgr._get_registeredDevices()[0]