Пример #1
0
    def Test_C_poll(self):
        log_level = self.log.getEffectiveLevel()

        poll_fd, poll_send = self.self_pipe()

        poll = taskforce.poll.poll()
        poll.register(poll_fd, taskforce.poll.POLLIN)

        #  Check active poll
        os.write(poll_send, '\0'.encode('utf-8'))
        evlist = poll.poll(timeout=30)
        self.dump_evlist(poll, 'active poll', evlist)
        assert evlist
        assert len(os.read(poll_fd, 10)) == 1

        #  Check timeout
        evlist = poll.poll(timeout=30)
        self.dump_evlist(poll, 'timeout poll', evlist)
        assert evlist == []

        #  Check timeout accuracy
        start = time.time()
        delay = 500
        evlist = poll.poll(timeout=500)
        self.dump_evlist(poll, 'timeout accuracy', evlist)
        assert evlist == []
        delta = abs(time.time() - start - delay/1000.0)
        self.log.info("%s poll timeout delta from wall clock %s", my(self), deltafmt(delta, decimals=6))
        assert delta < 0.1

        if poll.get_mode() == taskforce.poll.PL_SELECT:
            self.log.warning("%s Default mode is PL_SELECT so retest skipped", my(self))
        else:
            poll = taskforce.poll.poll()
            poll.set_mode(taskforce.poll.PL_SELECT)
            poll.register(poll_fd, taskforce.poll.POLLIN)

            #  Check active poll
            os.write(poll_send, '\0'.encode('utf-8'))
            evlist = poll.poll(timeout=30)
            self.dump_evlist(poll, 'select active poll', evlist)
            assert evlist
            assert len(os.read(poll_fd, 10)) == 1

            #  Check timeout
            evlist = poll.poll(timeout=30)
            self.dump_evlist(poll, 'select timeout poll', evlist)
            assert evlist == []

            #  Check timeout accuracy
            start = time.time()
            delay = 500
            evlist = poll.poll(timeout=500)
            self.dump_evlist(poll, 'select timeout accuracy', evlist)
            assert evlist == []
            delta = abs(time.time() - start - delay/1000.0)
            self.log.info("%s select poll timeout delta from wall clock %s", my(self), deltafmt(delta, decimals=6))
            assert delta < 0.1

        self.close_pipe()
Пример #2
0
	def Test_C_poll(self):
		log_level = self.log.getEffectiveLevel()

		poll_fd, poll_send = self.self_pipe()

		poll = taskforce.poll.poll()
		poll.register(poll_fd, taskforce.poll.POLLIN)

		#  Check active poll
		os.write(poll_send, '\0'.encode('utf-8'))
		evlist = poll.poll(timeout=30)
		self.dump_evlist(poll, 'active poll', evlist)
		assert evlist
		assert len(os.read(poll_fd, 10)) == 1

		#  Check timeout
		evlist = poll.poll(timeout=30)
		self.dump_evlist(poll, 'timeout poll', evlist)
		assert evlist == []

		#  Check timeout accuracy
		start = time.time()
		delay = 500
		evlist = poll.poll(timeout=500)
		self.dump_evlist(poll, 'timeout accuracy', evlist)
		assert evlist == []
		delta = abs(time.time() - start - delay/1000.0)
		self.log.info("%s poll timeout delta from wall clock %s", my(self), deltafmt(delta, decimals=6))
		assert delta < 0.1

		if poll.get_mode() == taskforce.poll.PL_SELECT:
			self.log.warning("%s Default mode is PL_SELECT so retest skipped", my(self))
		else:
			poll = taskforce.poll.poll()
			poll.set_mode(taskforce.poll.PL_SELECT)
			poll.register(poll_fd, taskforce.poll.POLLIN)

			#  Check active poll
			os.write(poll_send, '\0'.encode('utf-8'))
			evlist = poll.poll(timeout=30)
			self.dump_evlist(poll, 'select active poll', evlist)
			assert evlist
			assert len(os.read(poll_fd, 10)) == 1

			#  Check timeout
			evlist = poll.poll(timeout=30)
			self.dump_evlist(poll, 'select timeout poll', evlist)
			assert evlist == []

			#  Check timeout accuracy
			start = time.time()
			delay = 500
			evlist = poll.poll(timeout=500)
			self.dump_evlist(poll, 'select timeout accuracy', evlist)
			assert evlist == []
			delta = abs(time.time() - start - delay/1000.0)
			self.log.info("%s select poll timeout delta from wall clock %s", my(self), deltafmt(delta, decimals=6))
			assert delta < 0.1

		self.close_pipe()
Пример #3
0
    def Test_A_mode(self):
        log_level = self.log.getEffectiveLevel()

        poll = taskforce.poll.poll()
        mode = poll.get_mode()
        allowed_modes = poll.get_available_modes()
        self.log.info("%s Default polling mode is '%s' of %s",
                        my(self), poll.get_mode_name(mode=mode), str(poll.get_available_mode_names()))

        #  get_mode_name() should always return a string
        #
        name = poll.get_mode_name(mode='junk')
        self.log.info("%s get_mode_name() response to invalid mode %s", my(self), name)
        assert type(name) is str

        #  Format multiple events
        #
        evtext = poll.get_event(taskforce.poll.POLLIN|taskforce.poll.POLLOUT)
        self.log.info("%s get_event() response to multiple events %s", my(self), evtext)
        assert type(name) is str

        #  Format bad events
        #
        evtext = poll.get_event(taskforce.poll.POLLIN|taskforce.poll.POLLOUT|0x800)
        self.log.info("%s get_event() response to multiple events %s", my(self), evtext)
        assert type(name) is str

        #  Invalid event input
        #
        try:
            #  Mask the log message as we expect a failure
            self.log.setLevel(logging.CRITICAL)
            poll.get_event(None)
            self.log.setLevel(log_level)
            expected_error_occurred = False
        except Exception as e:
            self.log.setLevel(log_level)
            self.log.info("%s Received expected invalid event error -- %s", my(self), str(e))
            expected_error_occurred = True
        assert expected_error_occurred

        #  Should always be able to force PL_SELECT
        poll.set_mode(taskforce.poll.PL_SELECT)
        assert poll.get_mode() == taskforce.poll.PL_SELECT

        #  Find a mode that is not available
        bad_mode = None
        for mode in known_polling_modes:
            if mode not in allowed_modes:
                bad_mode = mode
                break
        self.log.info("%s Determined unavailable mode as %s", my(self), poll.get_mode_name(mode=bad_mode))

        #  Check that we can't set mode to None
        #
        try:
            #  Mask the log message as we expect a failure
            self.log.setLevel(logging.CRITICAL)
            poll.set_mode(None)
            self.log.setLevel(log_level)
            expected_error_occurred = False
        except Exception as e:
            self.log.setLevel(log_level)
            self.log.info("%s Received expected error -- %s", my(self), str(e))
            expected_error_occurred = True
        assert expected_error_occurred

        #  Check that we can't set mode to an impossible value
        #
        try:
            #  Mask the log message as we expect a failure
            self.log.setLevel(logging.CRITICAL)
            poll.set_mode(-1)
            self.log.setLevel(log_level)
            expected_error_occurred = False
        except Exception as e:
            self.log.setLevel(log_level)
            self.log.info("%s Received expected error -- %s", my(self), str(e))
            expected_error_occurred = True
        assert expected_error_occurred

        #  Check that we can't set an unavailable mode
        #
        try:
            #  Mask the log message as we expect a failure
            self.log.setLevel(logging.CRITICAL)
            poll.set_mode(bad_mode)
            self.log.setLevel(log_level)
            expected_error_occurred = False
        except Exception as e:
            self.log.setLevel(log_level)
            self.log.info("%s Received expected error -- %s", my(self), str(e))
            expected_error_occurred = True
        assert expected_error_occurred
Пример #4
0
    def Test_B_register(self):
        log_level = self.log.getEffectiveLevel()
        poll = taskforce.poll.poll()
        currmode = poll.get_mode()
        self.log.info("%s Default polling mode is '%s' of %s",
                        my(self), poll.get_mode_name(mode=currmode), str(poll.get_available_mode_names()))

        #  Find a valid mode that is not the current mode
        #
        nextmode = None
        for mode in poll.get_available_modes():
            if mode != currmode:
                nextmode = mode
        self.log.info("%s Determined valid non-active mode as %s", my(self), poll.get_mode_name(mode=nextmode))

        poll_fd, poll_send = self.self_pipe()
        poll.register(poll_fd)

        #  Test that an attempt to change mode is rejected
        #
        try:
            #  Mask the log message as we expect a failure
            self.log.setLevel(logging.CRITICAL)
            poll.set_mode(nextmode)
            self.log.setLevel(log_level)
            expected_error_occurred = False
        except Exception as e:
            self.log.setLevel(log_level)
            self.log.info("%s Received expected error -- %s", my(self), str(e))
            expected_error_occurred = True
        assert expected_error_occurred

        #  Test that an attempt to register an invalid fd fails
        #
        inv_fd = 999

        #  Make sure it is invalid
        try: os.close(inv_fd)
        except: pass
        try:
            #  Mask the log message as we expect a failure
            self.log.setLevel(logging.CRITICAL)
            poll.register(inv_fd)
            self.log.setLevel(log_level)
            expected_error_occurred = False
        except Exception as e:
            self.log.setLevel(log_level)
            self.log.info("%s Received expected invalid fd error -- %s", my(self), str(e))
            expected_error_occurred = True
        assert expected_error_occurred

        #  Confirm new mode is same as previous
        poll = taskforce.poll.poll()
        mode = poll.get_mode()
        self.log.info("%s Default polling mode is '%s' and should be same as previous '%s'",
                        my(self), poll.get_mode_name(mode=mode), poll.get_mode_name(mode=currmode))

        #  Change to PL_SELECT and register
        poll.set_mode(taskforce.poll.PL_SELECT)
        assert poll.get_mode() == taskforce.poll.PL_SELECT
        poll.register(poll_fd)

        #  Check invalid unregister
        #
        try:
            #  Mask the log message as we expect a failure
            self.log.setLevel(logging.CRITICAL)
            poll.unregister(self)
            self.log.setLevel(log_level)
            expected_error_occurred = False
        except Exception as e:
            self.log.setLevel(log_level)
            self.log.info("%s Received expected error -- %s", my(self), str(e))
            expected_error_occurred = True
        assert expected_error_occurred

        #  Check valid unregister
        #
        poll.unregister(poll_fd)

        self.close_pipe()
Пример #5
0
	def Test_A_mode(self):
		log_level = self.log.getEffectiveLevel()

		poll = taskforce.poll.poll()
		mode = poll.get_mode()
		allowed_modes = poll.get_available_modes()
		self.log.info("%s Default polling mode is '%s' of %s",
						my(self), poll.get_mode_name(mode=mode), str(poll.get_available_mode_names()))

		#  get_mode_name() should always return a string
		#
		name = poll.get_mode_name(mode='junk')
		self.log.info("%s get_mode_name() response to invalid mode %s", my(self), name)
		assert type(name) is str

		#  Format multiple events
		#
		evtext = poll.get_event(taskforce.poll.POLLIN|taskforce.poll.POLLOUT)
		self.log.info("%s get_event() response to multiple events %s", my(self), evtext)
		assert type(name) is str

		#  Format bad events
		#
		evtext = poll.get_event(taskforce.poll.POLLIN|taskforce.poll.POLLOUT|0x800)
		self.log.info("%s get_event() response to multiple events %s", my(self), evtext)
		assert type(name) is str

		#  Invalid event input
		#
		try:
			#  Mask the log message as we expect a failure
			self.log.setLevel(logging.CRITICAL)
			poll.get_event(None)
			self.log.setLevel(log_level)
			expected_error_occurred = False
		except Exception as e:
			self.log.setLevel(log_level)
			self.log.info("%s Received expected invalid event error -- %s", my(self), str(e))
			expected_error_occurred = True
		assert expected_error_occurred

		#  Should always be able to force PL_SELECT
		poll.set_mode(taskforce.poll.PL_SELECT)
		assert poll.get_mode() == taskforce.poll.PL_SELECT

		#  Find a mode that is not available
		bad_mode = None
		for mode in known_polling_modes:
			if mode not in allowed_modes:
				bad_mode = mode
				break
		self.log.info("%s Determined unavailable mode as %s", my(self), poll.get_mode_name(mode=bad_mode))

		#  Check that we can't set mode to None
		#
		try:
			#  Mask the log message as we expect a failure
			self.log.setLevel(logging.CRITICAL)
			poll.set_mode(None)
			self.log.setLevel(log_level)
			expected_error_occurred = False
		except Exception as e:
			self.log.setLevel(log_level)
			self.log.info("%s Received expected error -- %s", my(self), str(e))
			expected_error_occurred = True
		assert expected_error_occurred

		#  Check that we can't set mode to an impossible value
		#
		try:
			#  Mask the log message as we expect a failure
			self.log.setLevel(logging.CRITICAL)
			poll.set_mode(-1)
			self.log.setLevel(log_level)
			expected_error_occurred = False
		except Exception as e:
			self.log.setLevel(log_level)
			self.log.info("%s Received expected error -- %s", my(self), str(e))
			expected_error_occurred = True
		assert expected_error_occurred

		#  Check that we can't set an unavailable mode
		#
		try:
			#  Mask the log message as we expect a failure
			self.log.setLevel(logging.CRITICAL)
			poll.set_mode(bad_mode)
			self.log.setLevel(log_level)
			expected_error_occurred = False
		except Exception as e:
			self.log.setLevel(log_level)
			self.log.info("%s Received expected error -- %s", my(self), str(e))
			expected_error_occurred = True
		assert expected_error_occurred
Пример #6
0
	def Test_B_register(self):
		log_level = self.log.getEffectiveLevel()
		poll = taskforce.poll.poll()
		currmode = poll.get_mode()
		self.log.info("%s Default polling mode is '%s' of %s",
						my(self), poll.get_mode_name(mode=currmode), str(poll.get_available_mode_names()))

		#  Find a valid mode that is not the current mode
		#
		nextmode = None
		for mode in poll.get_available_modes():
			if mode != currmode:
				nextmode = mode
		self.log.info("%s Determined valid non-active mode as %s", my(self), poll.get_mode_name(mode=nextmode))

		poll_fd, poll_send = self.self_pipe()
		poll.register(poll_fd)

		#  Test that an attempt to change mode is rejected
		#
		try:
			#  Mask the log message as we expect a failure
			self.log.setLevel(logging.CRITICAL)
			poll.set_mode(nextmode)
			self.log.setLevel(log_level)
			expected_error_occurred = False
		except Exception as e:
			self.log.setLevel(log_level)
			self.log.info("%s Received expected error -- %s", my(self), str(e))
			expected_error_occurred = True
		assert expected_error_occurred

		#  Test that an attempt to register an invalid fd fails
		#
		inv_fd = 999

		#  Make sure it is invalid
		try: os.close(inv_fd)
		except: pass
		try:
			#  Mask the log message as we expect a failure
			self.log.setLevel(logging.CRITICAL)
			poll.register(inv_fd)
			self.log.setLevel(log_level)
			expected_error_occurred = False
		except Exception as e:
			self.log.setLevel(log_level)
			self.log.info("%s Received expected invalid fd error -- %s", my(self), str(e))
			expected_error_occurred = True
		assert expected_error_occurred

		#  Confirm new mode is same as previous
		poll = taskforce.poll.poll()
		mode = poll.get_mode()
		self.log.info("%s Default polling mode is '%s' and should be same as previous '%s'",
						my(self), poll.get_mode_name(mode=mode), poll.get_mode_name(mode=currmode))

		#  Change to PL_SELECT and register
		poll.set_mode(taskforce.poll.PL_SELECT)
		assert poll.get_mode() == taskforce.poll.PL_SELECT
		poll.register(poll_fd)

		#  Check invalid unregister
		#
		try:
			#  Mask the log message as we expect a failure
			self.log.setLevel(logging.CRITICAL)
			poll.unregister(self)
			self.log.setLevel(log_level)
			expected_error_occurred = False
		except Exception as e:
			self.log.setLevel(log_level)
			self.log.info("%s Received expected error -- %s", my(self), str(e))
			expected_error_occurred = True
		assert expected_error_occurred

		#  Check valid unregister
		#
		poll.unregister(poll_fd)

		self.close_pipe()