Beispiel #1
0
def test_dmesg_wrap_partial():
    """ Test that dmesg still works after dmesg wraps partially

    We can overwrite the DMESG_COMMAND class variable to emluate dmesg being
    filled up and overflowing. What this test does is starts with a string that
    looks like this: "a\nb\nc\n" (this is used to emluate the contents of
    dmesg), we then replace that with "b\nc\nd\n", and ensure that the update
    of dmesg contains only 'd', becasue 'd' is the only new value in the
    updated dmesg.

    """
    # We don't want weird side effects of changing DMESG_COMMAND globally, so
    # instead we set it as a class instance and manually clear the
    # _last_messages attribute
    test = dmesg.LinuxDmesg()
    test.DMESG_COMMAND = ['echo', 'a\nb\nc\n']
    test.update_dmesg()

    # Update the DMESG_COMMAND to add d\n and remove a\n, this simluates the
    # wrap
    test.DMESG_COMMAND = ['echo', 'b\nc\nd\n']
    test.update_dmesg()

    nt.assert_items_equal(test._new_messages, ['d'],
                          msg=("_new_messages should be equal to ['d'], but is"
                               " {} instead.".format(test._new_messages)))
Beispiel #2
0
def test_linuxdmesg_timestamp():
    """dmesg.LinuxDmesg: If timestamps are not detected raise"""
    with mock.patch('framework.dmesg.subprocess.check_output',
                    mock.Mock(return_value=b'foo\nbar\n')):
        with warnings.catch_warnings():
            warnings.simplefilter('error')
            dmesg.LinuxDmesg()
Beispiel #3
0
    def _do_test(error, mocker):
        # Mocking this will prevent LinuxDmesg._last_message from being
        # updated, which will force us down the warn path, which is convenient
        # for assertion puproses.
        mocker.patch('framework.dmesg.LinuxDmesg.update_dmesg')
        mocker.patch('framework.dmesg.gzip.open', side_effect=error)

        with pytest.warns(RuntimeWarning):
            dmesg.LinuxDmesg()
Beispiel #4
0
 def test(exception):
     try:
         with mock.patch('framework.dmesg.gzip.open',
                         mock.Mock(side_effect=exception)):
             with warnings.catch_warnings():
                 warnings.simplefilter('error')
                 dmesg.LinuxDmesg()
     except (exceptions.PiglitFatalError, RuntimeWarning):
         pass
Beispiel #5
0
    def test_not_timestamps(self, mocker):
        """If _last_message is populated but doesn't have a valid timestamp
        then an PiglitFatalException shoudl be raised.
        """
        mocker.patch('framework.dmesg.subprocess.check_output',
                     mocker.Mock(return_value=b'foo\nbar\n'))
        # This error will work for python 2.x and 3.x
        mocker.patch('framework.dmesg.gzip.open', side_effect=OSError)

        with pytest.raises(exceptions.PiglitFatalError):
            dmesg.LinuxDmesg()
Beispiel #6
0
def test_linuxdmesg_update_dmesg_update_no_change():
    """dmesg.LinuxDmesg.update_dmesg: calculate dmesg changes correctly with no changes"""
    result = results.TestResult('pass')
    result.dmesg = mock.sentinel.dmesg

    with mock.patch('framework.dmesg.subprocess.check_output',
                    mock.Mock(return_value=b'[1.0]this')):
        dmesg_ = dmesg.LinuxDmesg()
        dmesg_.update_result(result)

    nt.eq_(result.dmesg, mock.sentinel.dmesg)
Beispiel #7
0
    def test_update_result_no_change(self):
        """When update_result is called but no changes to dmesg have occured it
        should not set the dmesg attribute.
        """
        result = results.TestResult('pass')
        result.dmesg = mock.sentinel.dmesg

        with mock.patch('framework.dmesg.subprocess.check_output',
                        mock.Mock(return_value=b'[1.0]this')):
            test = dmesg.LinuxDmesg()
            test.update_result(result)

        assert result.dmesg is mock.sentinel.dmesg
Beispiel #8
0
def test_linuxdmesg_update_dmesg_update():
    """dmesg.LinuxDmesg.update_dmesg: calculate dmesg changes correctly with changes"""
    result = results.TestResult('pass')

    with mock.patch('framework.dmesg.subprocess.check_output',
                    mock.Mock(return_value=b'[1.0]this')):
        dmesg_ = dmesg.LinuxDmesg()

    with mock.patch('framework.dmesg.subprocess.check_output',
                    mock.Mock(return_value=b'[1.0]this\n[2.0]is\n[3.0]dmesg\n')):
        dmesg_.update_result(result)

    nt.eq_(result.dmesg, '[2.0]is\n[3.0]dmesg')
Beispiel #9
0
    def test_warn(self, mocker):
        """Test that if /proc/config is not available, and there are no values
        to check in _last_message a RuntimeWarning should be issued.
        """
        # Mocking this will prevent LinuxDmesg._last_message from being
        # updated, which will force us down the warn path
        mocker.patch('framework.dmesg.LinuxDmesg.update_dmesg')

        # OSError was picked because it will work for both python2 and python3
        # (FileNotFoundError is a descendent of OSError)
        mocker.patch('framework.dmesg.gzip.open', side_effect=OSError)

        with pytest.warns(RuntimeWarning):
            dmesg.LinuxDmesg()
Beispiel #10
0
    def test_update_result_sets_result_attr(self):
        """When update_dmesg is called on a value it should set the dmesg
        attribute of the results.
        """
        result = results.TestResult(status.PASS)

        with mock.patch('framework.dmesg.subprocess.check_output',
                        mock.Mock(return_value=b'[1.0]this')):
            test = dmesg.LinuxDmesg()
        with mock.patch(
                'framework.dmesg.subprocess.check_output',
                mock.Mock(return_value=b'[1.0]this\n[2.0]is\n[2.5]dmesg!\n')):
            test.update_result(result)

        assert result.dmesg == '[2.0]is\n[2.5]dmesg!'
Beispiel #11
0
    def test_complete_wrap(self):
        """dmesg.LinuxDmesg.update_dmesg: correctly handles complete wrap.

        Since dmesg is a ringbuffer (at least on Linux) it can roll over, and we
        need to ensure that we're handling that correctly.
        """
        result = results.TestResult()

        mock_out = mock.Mock(return_value=b'[1.0]This\n[2.0]is\n[3.0]dmesg')
        with mock.patch('framework.dmesg.subprocess.check_output', mock_out):
            test = dmesg.LinuxDmesg()

        mock_out.return_value = b'[4.0]whoo!\n[5.0]doggy'
        with mock.patch('framework.dmesg.subprocess.check_output', mock_out):
            test.update_result(result)

        assert result.dmesg == '[4.0]whoo!\n[5.0]doggy'
Beispiel #12
0
def test_partial_wrap():
    """dmesg.LinuxDmesg.update_dmesg: correctly handles partial wrap

    Since dmesg is a ringbuffer (at least on Linux) it can roll over, and we
    need to ensure that we're handling that correctly.

    """
    result = results.TestResult()

    mock_out = mock.Mock(return_value=b'[1.0]This\n[2.0]is\n[3.0]dmesg')
    with mock.patch('framework.dmesg.subprocess.check_output', mock_out):
        test = dmesg.LinuxDmesg()

    mock_out.return_value = b'[3.0]dmesg\n[4.0]whoo!'
    with mock.patch('framework.dmesg.subprocess.check_output', mock_out):
        test.update_result(result)

    nt.eq_(result.dmesg, '[4.0]whoo!')
Beispiel #13
0
def test_dmesg_wrap_complete():
    """ Test that dmesg still works after dmesg wraps completely

    just like the partial version, but with nothingin common.

    """
    # We don't want weird side effects of changing DMESG_COMMAND globally, so
    # instead we set it as a class instance and manually clear the
    # _last_messages attribute
    test = dmesg.LinuxDmesg()
    test.DMESG_COMMAND = ['echo', 'a\nb\nc\n']
    test.update_dmesg()

    # Udamte the DMESG_COMMAND to add d\n and remove a\n, this simluates the
    # wrap
    test.DMESG_COMMAND = ['echo', '1\n2\n3\n']
    test.update_dmesg()

    nt.assert_items_equal(test._new_messages, ['1', '2', '3'],
                          msg=("_new_messages should be equal to "
                               "['1', '2', '3'], but is {} instead".format(
                                   test._new_messages)))
Beispiel #14
0
def test_linux_initialization():
    """ Test that LinuxDmesg initializes """
    dmesg.LinuxDmesg()
Beispiel #15
0
 def test_repr(self):
     with mock.patch('framework.dmesg.subprocess.check_output',
                     mock.Mock(return_value=b'[1.0]this')):
         assert repr(dmesg.LinuxDmesg()) == 'LinuxDmesg()'
Beispiel #16
0
def test_linuxdmesg_warn():
    """dmesg.LinuxDmesg: Warn if timestamp support is uncheckable"""
    with mock.patch('framework.dmesg.LinuxDmesg.update_dmesg', mock.Mock()):
        with warnings.catch_warnings():
            warnings.simplefilter('error')
            dmesg.LinuxDmesg()