示例#1
0
    def testInitTermRead(self):
        self.assertRaises(win32trace.error, win32trace.read)
        win32trace.InitRead()
        result = win32trace.read()
        self.assertEquals(result, '')
        win32trace.TermRead()
        self.assertRaises(win32trace.error, win32trace.read)

        win32trace.InitRead()
        self.assertRaises(win32trace.error, win32trace.InitRead)
        win32trace.InitWrite()
        self.assertRaises(win32trace.error, win32trace.InitWrite)
        win32trace.TermWrite()
        win32trace.TermRead()
示例#2
0
def CollectorThread(stopEvent, file):
    win32trace.InitRead()
    handle = win32trace.GetHandle()
    # Run this thread at a lower priority to the main message-loop (and printing output)
    # thread can keep up
    import win32process

    win32process.SetThreadPriority(
        win32api.GetCurrentThread(), win32process.THREAD_PRIORITY_BELOW_NORMAL
    )

    try:
        while 1:
            rc = win32event.WaitForMultipleObjects(
                (handle, stopEvent), 0, win32event.INFINITE
            )
            if rc == win32event.WAIT_OBJECT_0:
                # About the only char we can't live with is \0!
                file.write(win32trace.read().replace("\0", "<null>"))
            else:
                # Stop event
                break
    finally:
        win32trace.TermRead()
        print("Thread dieing")
示例#3
0
 def tearDown(self):
     try:
         win32trace.TermRead()
     except win32trace.error:
         pass
     try:
         win32trace.TermWrite()
     except win32trace.error:
         pass
示例#4
0
def CheckNoOtherReaders():
    win32trace.write("Hi")
    time.sleep(0.05)
    if win32trace.read() != "Hi":
        # Reset everything so following tests still fail with this error!S
        win32trace.TermRead()
        win32trace.TermWrite()
        raise RuntimeError, "An existing win32trace reader appears to be " \
                            "running - please stop this process and try again"
示例#5
0
    def testInitTermRead(self):
        with pytest.raises(win32trace.error):
            win32trace.read()
        win32trace.InitRead()
        result = win32trace.read()
        assert result == ''
        win32trace.TermRead()
        with pytest.raises(win32trace.error):
            win32trace.read()

        win32trace.InitRead()
        with pytest.raises(win32trace.error):
            win32trace.InitRead()
        win32trace.InitWrite()
        with pytest.raises(win32trace.error):
            win32trace.InitWrite()
        win32trace.TermWrite()
        win32trace.TermRead()
示例#6
0
 def testInit(self):
     win32trace.TermRead()
     win32trace.TermWrite()
     traceObject = win32trace.GetTracer()
     self.assertRaises(win32trace.error, traceObject.read)
     self.assertRaises(win32trace.error, traceObject.write, '')
     win32trace.InitRead()
     win32trace.InitWrite()
     self.assertEquals('', traceObject.read())
     traceObject.write('Syver')
示例#7
0
    def testTermSematics(self):
        win32trace.InitWrite()
        win32trace.write('Ta da')

        # if we both Write and Read are terminated at the same time,
        # we lose the data as the win32 object is closed.  Note that
        # if another writer is running, we do *not* lose the data - so
        # test for either the correct data or an empty string
        win32trace.TermWrite()
        win32trace.InitRead()
        self.failUnless(win32trace.read() in ['Ta da', ''])
        win32trace.TermRead()

        # we keep the data because we init read before terminating write
        win32trace.InitWrite()
        win32trace.write('Ta da')
        win32trace.InitRead()
        win32trace.TermWrite()
        self.assertEquals('Ta da', win32trace.read())
        win32trace.TermRead()
示例#8
0
 def testInit(self):
     win32trace.TermRead()
     win32trace.TermWrite()
     traceObject = win32trace.GetTracer()
     with pytest.raises(win32trace.error):
         traceObject.read()
     with pytest.raises(win32trace.error):
         traceObject.write('')
     win32trace.InitRead()
     win32trace.InitWrite()
     assert '' == traceObject.read()
     traceObject.write('Syver')
示例#9
0
 def tearDown(self):
     win32trace.TermWrite()
     win32trace.TermRead()
示例#10
0
 def setUp(self):
     # clear old data
     win32trace.InitRead()
     win32trace.read()
     win32trace.TermRead()
示例#11
0
            assert each.verifyWritten()
        assert self.areBucketsFull()    

def _RunAsTestProcess():
    # Run as an external process by the main tests.
    WriterThread.BucketCount = int(sys.argv[2])
    threadCount = int(sys.argv[3])
    threads = [WriterThread() for each in range(threadCount)]
    win32trace.InitWrite()
    for thread in threads:
        thread.start()
    for thread in threads:
        thread.join()
    for thread in threads:
        if not thread.verifyWritten():
            sys.exit(-1)
    
if __name__ == '__main__':
    if sys.argv[1:2]==["/run_test_process"]:
        _RunAsTestProcess()
        sys.exit(0)
    # If some other win32traceutil reader is running, these tests fail
    # badly (as the other reader sometimes sees the output!)
    win32trace.InitRead()
    win32trace.InitWrite()
    CheckNoOtherReaders()
    # reset state so test env is back to normal
    win32trace.TermRead()
    win32trace.TermWrite()
    unittest.main()