def remoteSetUp(self): debug("%s", self.uuid) gst.log("%s" % self.uuid) # local variables # create the pipeline try: self.pipeline = self.createPipeline() except: exception("Error while creating pipeline") self.pipeline = None finally: self.validateStep("valid-pipeline", not self.pipeline == None) if self.pipeline == None: self.remoteStop() return factory = self.pipeline.get_factory() if factory is None: facname = "(no factory)" else: facname = factory.get_name() self._elements = [(self.pipeline.get_name(),facname, "")] #name,factoryname,parentname self._watchContainer(self.pipeline) # connect to bus self.bus = self.pipeline.get_bus() self.bus.add_signal_watch() self.bus.connect("message", self._busMessageHandlerCb) PythonDBusTest.remoteSetUp(self)
def _generate(self): debug("Running generator command line in %r: %r" % (self.cwd, self.command)) try: process = subprocess.Popen([self.command], stdin=None, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=self.cwd, shell=True, universal_newlines=True) except Exception, e: exception("Error running external generator: %r: %s", self.command, e) return []
def run(self): TesterClient.run(self) # Now run the main loop, which blocks until finished or quitting: try: self._ml.run() except KeyboardInterrupt: exception("Interrupted, calling clean-up") self.quit()
def setUp(self): Monitor.setUp(self) self._saveCoreDumps = self.arguments.get("save-core-dumps", False) self._generateBackTraces = self.arguments.get("generate-back-traces", True) self._GDBScript = self.arguments.get("gdb-script", "gdb.instructions") # add some env variables self.test._environ["G_DEBUG"] = "fatal_warnings" try: import resource resource.setrlimit(resource.RLIMIT_CORE, (-1, -1)) except: exception("Couldn't change core limit") return False return True
def setUp(self): info("uuid:%s", self.uuid) if Test.setUp(self) == False: return False # get the remote launcher pargs = self._preargs pargs.extend(self.get_remote_launcher_args()) shell = isinstance (pargs, basestring) cwd = self._testrun.getWorkingDirectory() self._environ["PRIVATE_DBUS_ADDRESS"] = self._bus_address info("Setting PRIVATE_DBUS_ADDRESS : %r" % self._bus_address) info("bus:%r" % self._bus) self._prepareArguments() if False: # useful to allow some time to run dbus-monitor on the private bus print("Setting PRIVATE_DBUS_ADDRESS : %r" % self._bus_address) time.sleep(5) # spawn the other process info("opening %r" % pargs) info("cwd %s" % cwd) try: self._subprocessspawntime = time.time() self._process = subprocess.Popen(pargs, stdin = self._stdin, stdout = subprocess.PIPE, stderr = subprocess.PIPE, env=self._environ, shell = shell, cwd=cwd) self._ensureOutRedirection() self._pid = self._process.pid except: exception("Error starting the subprocess command ! %r", pargs) self.validateChecklistItem("dbus-process-spawned", False) return False debug("Subprocess created successfully [pid:%d]", self._pid) self.validateChecklistItem("dbus-process-spawned") # add a poller for the proces self._processpollid = gobject.timeout_add(500, self._pollSubProcess) # Don't forget to set a timeout for waiting for the connection return True
def _startNextSubTest(self): try: testclass, args, monitors = self._tests.pop(0) if not 'bus' in args.keys(): args["bus"] = self.arguments.get("bus") if not 'bus_address' in args.keys(): args["bus_address"] = self.arguments.get("bus_address") debug("About to create subtest %r with arguments %r", testclass, args) instance = testclass(testrun=self._testrun, **args) if monitors: for monitor in monitors: instance.addMonitor(*monitor) except Exception, e: exception("Failed to create instance of class %r : %r", testclass, e) self.stop() return
def createPipeline(self): """ Construct and return the pipeline for the given test Return a gst.Pipeline if creation was successful. Return None if an error occured. """ # default implementation : ask for parse-launch syntax pipestring = self.getPipelineString() debug("%s Got pipeline string %s", self.uuid, pipestring) try: pip = gst.parse_launch(pipestring) except: exception("error while creating pipeline") pip = None self.pipelineCreatedCb(pip) return pip
def tearDown(self): Monitor.tearDown(self) # if the return value of the subprocess is non-null, we most # likely have a crasher and core dump if not self.test._returncode == 0: debug("non-null returncode [%d] for pid %d", self.test._returncode, self.test._pid) # try to find the core file core = self._findCoreFile() if core: debug("Got core file %s", core) if self._generateBackTraces: # output file for backtrace backtracefd, backtracepath = self.testrun.get_temp_file(nameid="gdb-back-trace") backtracefile = open(backtracepath, "a+") # run the backtrace script # This blocks, which is acceptable since we're tearing down subprocess.Popen(["libtool", "--mode=execute", "gdb", "--batch", "-x", self._GDBScript, self.test._metadata.__test_filename__, core], stdout = backtracefile, stderr = backtracefile).wait() # cleanup os.close(backtracefd) backtracefile.close() # notify of backtrace file self.setOutputFile("backtrace-file", backtracepath) if self._saveCoreDumps: # copy over the core dump corefd, corepath = self.testrun.get_temp_file(nameid="core-dump") # copy core dump to that file # FIXME : THIS MIGHT NOT WORK ON WINDOWS (see os.rename docs) try: os.rename(core, corepath) self.setOutputFile("core-dump", corepath) except: exception("Couldn't rename core dump file !!!") os.remove(core) finally: os.close(corefd) else: os.remove(core)
def _newRemoteTest(self, testrun, uuid): if not uuid == self.uuid: return info("%s our remote counterpart has started", self.uuid) self.validateStep("dbus-process-connected") self._subprocessconnecttime = time.time() delay = self._subprocessconnecttime - self._subprocessspawntime self.extraInfo("subprocess-spawn-time", delay) # we need to give the remote process the following information: # * filename where the Test class is located (self.get_file()) # * class name (self.__class__.__name__) # * the arguments (self.arguments) + proxy=True rname = "net.gstreamer.Insanity.Test.Test%s" % self.uuid rpath = "/net/gstreamer/Insanity/Test/RemotePythonRunner%s" % self.uuid # get the proxy object to our counterpart remoteobj = self._bus.get_object(rname, rpath) debug("Got remote runner object %r" % remoteobj) # call createTestInstance() remoterunner = dbus.Interface(remoteobj, "net.gstreamer.Insanity.RemotePythonRunner") debug("Got remote iface %r" % remoterunner) args = self.arguments.copy() args["bus_address"] = self._bus_address args["timeout"] = self._timeout if self._outputfiles: args["outputfiles"] = self.getOutputFiles() debug( "Creating remote instance with arguments %s %s %s %r", self.get_file(), self.__module__, self.__class__.__name__, args, ) try: remoterunner.createTestInstance( self.get_file(), self.__module__, self.__class__.__name__, args, reply_handler=self._createTestInstanceCallBack, error_handler=self._voidRemoteErrBackHandler, ) except: exception("Exception raised when creating remote instance !") self.validateStep("remote-instanced-created", False) self.stop()
def unicode_dict(adict): """ Returns a copy on the given dictionnary where all string values are validated as proper unicode """ res = {} for key, val in adict.iteritems(): if isinstance(val, str): try: res[key] = unicode(val) except: try: res[key] = unicode(val, 'iso8859_1') except: exception("Argument [%s] is not valid UTF8 (%r)", key, val) else: res[key] = val return res
def setUp(self): info("uuid:%s proxy:%r", self.uuid, self._isproxy) if Test.setUp(self) == False: return False if self._isproxy: # get the remote launcher pargs = self._preargs pargs.extend(self.get_remote_launcher_args()) cwd = self._testrun.getWorkingDirectory() self._environ["PRIVATE_DBUS_ADDRESS"] = self._bus_address info("Setting PRIVATE_DBUS_ADDRESS : %r" % self._bus_address) info("bus:%r" % self._bus) # spawn the other process info("opening %r" % pargs) info("cwd %s" % cwd) try: self._subprocessspawntime = time.time() self._process = subprocess.Popen( pargs, stdin=self._stdin, stdout=self._stdout, stderr=self._stderr, env=self._environ, cwd=cwd ) self._pid = self._process.pid except: exception("Error starting the subprocess command ! %r", pargs) self.validateStep("dbus-process-spawned", False) return False debug("Subprocess created successfully [pid:%d]", self._pid) self.validateStep("dbus-process-spawned") # add a poller for the proces self._processpollid = gobject.timeout_add(500, self._pollSubProcess) # Don't forget to set a timeout for waiting for the connection else: # remote instance setup # self.remoteSetUp() pass return True
def _newRemoteTest(self, testrun, uuid): if not uuid == self.uuid: return info("%s our remote counterpart has started", self.uuid) self.validateChecklistItem("dbus-process-connected") self._subprocessconnecttime = time.time() delay = self._subprocessconnecttime - self._subprocessspawntime self.extraInfo("subprocess-spawn-time", int(delay * 1000)) # we need to give the remote process the following information: # * filename where the Test class is located (self.get_file()) # * class name (self.__class__.__name__) # * the arguments (self.arguments) rname = "net.gstreamer.Insanity.Test.Test%s" % self.uuid rpath = "/net/gstreamer/Insanity/Test/Test%s" % self.uuid # get the proxy object to our counterpart remoteobj = self._bus.get_object(rname, rpath) debug("Got remote runner object %r" % remoteobj) # call createTestInstance() remoterunner = dbus.Interface(remoteobj, "net.gstreamer.Insanity.Test") debug("Got remote iface %r" % remoterunner) try: delay = time.time() - self._subprocessconnecttime self._remoteinstance = dbus.Interface(remoteobj, "net.gstreamer.Insanity.Test") info ('Listening to signals from %s' % self._remoteinstance) self._remoteinstance.connect_to_signal("remoteDoneSignal", self._remoteDoneCb) self._remoteinstance.connect_to_signal("remoteValidateChecklistItemSignal", self._remoteValidateChecklistItemCb) self._remoteinstance.connect_to_signal("remoteExtraInfoSignal", self._remoteExtraInfoCb) self._remoteinstance.connect_to_signal("remotePingSignal", self._remotePingCb) self.callRemoteSetUp() except: exception("Exception raised when creating remote instance !") self.stop()