@@ -0,0 +1,1975 @@
+%0Aimport sys%0A%0Aimport nose.tools%0A%0Afrom simuvex import SimState%0A%0Adef test_file_create():%0A    # Create a state first%0A    state = SimState(arch=%22AMD64%22, mode='symbolic')%0A%0A    # Create a file%0A    fd = state.posix.open(%22test%22, %22wb%22)%0A%0A    nose.tools.assert_equal(fd, 3)%0A%0Adef test_file_read():%0A    state = SimState(arch=%22AMD64%22, mode='symbolic')%0A%0A    content = state.se.BVV(0xbadf00d, 32)%0A    content_size = content.size() / 8%0A%0A    fd = state.posix.open(%22test%22, %22wb%22)%0A    state.posix.write(fd, content, content_size)%0A    state.posix.seek(fd, 0, 0)%0A    state.posix.read(fd, 0xc0000000, content_size)%0A%0A    data = state.memory.load(0xc0000000, content_size)%0A%0A    nose.tools.assert_true(state.se.is_true(data == content))%0A%0Adef test_file_seek():%0A%0A    # TODO: Make this test more complete%0A%0A    SEEK_SET = 0%0A    SEEK_END = 1%0A    SEEK_CUR = 2%0A%0A    state = SimState(arch=%22AMD64%22, mode='symbolic')%0A%0A    # Normal seeking%0A    fd = state.posix.open(%22test%22, %22wb%22)%0A    r = state.posix.seek(fd, 0, SEEK_SET)%0A    nose.tools.assert_equal(r, 0)%0A    state.posix.close(fd)%0A%0A    # TODO: test case: seek cannot go beyond the file size or current file pos%0A    # TODO: test case: seek should not work for stdin/stdout/stderr%0A%0A    # Seek from the end%0A    fd = state.posix.open(%22test%22, %22wb%22)%0A    state.posix.files%5Bfd%5D.size = 20%0A    state.posix.seek(fd, 0, SEEK_END)%0A    nose.tools.assert_true(state.se.is_true(state.posix.files%5Bfd%5D.pos == 19))%0A    state.posix.close(fd)%0A%0A    # cannot seek from a file whose size is unknown%0A    fd = state.posix.open(%22unknown_size%22, %22wb%22)%0A    r = state.posix.seek(fd, 0, SEEK_END)%0A    nose.tools.assert_equal(r, -1)%0A    state.posix.close(fd)%0A%0Adef main():%0A    g = globals()%0A    if len(sys.argv) %3E 1:%0A        f = %22test_%22 + sys.argv%5B1%5D%0A        if f in g and hasattr(g%5Bf%5D, %22__call__%22):%0A            g%5Bf%5D()%0A    else:%0A        for f, func in g.iteritems():%0A            if f.startswith(%22test_%22) and hasattr(func, %22__call__%22):%0A                func()%0A%0Aif __name__ == %22__main__%22:%0A    main()%0A

Add a very simple test case for posix file support.