def test_dmesg_performance(): """ Test that update_dmesg returns in less than .015 seconds on large loads One of the largest problems with dmesg is that there are 16000+ tests already, and more will be added. Since dmesg runs serially minimizing the amount of time spend on setup and teardown of tests is paramount, even at 1 second the results will add 4 minutes to the test run with 16000 tests. For the purpose of this test we won't actually read dmesg, it's not nice to keep trashing dmesg, and this test needs to see that a large list, say 7000 items, won't take forever. This was tested on an ivybridge i3-3217U where ~.013 was a common value, most modern systems with a desktop Intel or AMD processor should be able to hit this number. Systems with very low power CPUs may not be able to hit this number. """ dmesg = LinuxDmesg() # 7000 is an arbitrary big number length = 7000 - len(dmesg._new_messages) # make new messages really big dmesg._new_messages = ["piglit test {}".format(x) for x in xrange(length)] + dmesg._new_messages result = TestResult() result['result'] = 'pass' result = dmesg.update_result(result)
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 dmesg = LinuxDmesg() dmesg.DMESG_COMMAND = ['echo', 'a\nb\nc\n'] dmesg.update_dmesg() # Update the DMESG_COMMAND to add d\n and remove a\n, this simluates the # wrap dmesg.DMESG_COMMAND = ['echo', 'b\nc\nd\n'] dmesg.update_dmesg() nt.assert_items_equal(dmesg._new_messages, ['d'], msg="_new_messages should be equal to ['d'], but is " "{} instead.".format(dmesg._new_messages))
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 dmesg = LinuxDmesg() dmesg.DMESG_COMMAND = ['echo', 'a\nb\nc\n'] dmesg.update_dmesg() # Udamte the DMESG_COMMAND to add d\n and remove a\n, this simluates the # wrap dmesg.DMESG_COMMAND = ['echo', '1\n2\n3\n'] dmesg.update_dmesg() nt.assert_items_equal(dmesg._new_messages, ['1', '2', '3'], msg="_new_messages should be equal to " "['1', '2', '3'], but is {} instead".format( dmesg._new_messages))
def __init__(self, monitoring_source, regex): """Create a MonitoringLinuxDmesg instance""" self.DMESG_COMMAND = ['dmesg']+monitoring_source.split() BaseMonitoring.__init__(self, monitoring_source, regex) LinuxDmesg.__init__(self)
def test_linux_initialization(): """ Test that LinuxDmesg initializes """ dmesg = LinuxDmesg() assert dmesg