Please note that the CVS and issue trackers have moved to GitHub. These Trac pages are no longer kept up-to-date.

root/seattle/branches/nacl_repy/seattlelib/tests/ut_lind_fs_dup.py

Revision 5140, 1.6 KB (checked in by justinc, 6 years ago)

removed circular imports and created a new Python testing mechanism called
lind_test_server. This removes the need for wrappers, etc.

Line 
1import lind_test_server
2
3from lind_fs_constants import *
4
5# Try to do dup2
6lind_test_server._blank_fs_init()
7
8flags = O_TRUNC | O_CREAT | O_RDWR
9mode = 438   # 0666
10name = 'double_open_file'
11
12myfd = lind_test_server.open_syscall(name, flags, mode)
13assert(lind_test_server.write_syscall(myfd,'hi')==2)
14
15# duplicate the file descriptor...
16myfd2 = lind_test_server.dup_syscall(myfd)
17
18assert(myfd != myfd2)
19
20# this should actually be essentially a no-op.   It closes myfd+1 and sets it
21# to be the same as the current fd (which was done by the prior call)
22myfd3 = lind_test_server.dup_syscall(myfd)
23
24# they should be different fds...
25assert(myfd != myfd3 and myfd2 != myfd3)
26
27# we don't need all three
28lind_test_server.close_syscall(myfd3)
29
30# should be at the same place...
31assert(lind_test_server.lseek_syscall(myfd,0,SEEK_CUR) == 
32       lind_test_server.lseek_syscall(myfd2,0,SEEK_CUR))
33
34# write some data to move the first position
35assert(lind_test_server.write_syscall(myfd,'yo')==2)
36
37# _still_ should be at the same place...
38assert(lind_test_server.lseek_syscall(myfd,0,SEEK_CUR) == 
39       lind_test_server.lseek_syscall(myfd2,0,SEEK_CUR))
40
41# reset the position within the file
42lind_test_server.lseek_syscall(myfd2,0,SEEK_SET)
43
44# read from the other fd
45assert(lind_test_server.read_syscall(myfd,10)=='hiyo')
46
47# close one fd
48lind_test_server.close_syscall(myfd)
49
50# the other should still work...
51assert(lind_test_server.write_syscall(myfd2,'raar')==4)
52lind_test_server.lseek_syscall(myfd2,0,SEEK_SET)
53assert(lind_test_server.read_syscall(myfd2,10)=='hiyoraar')
54
55lind_test_server.close_syscall(myfd2)
Note: See TracBrowser for help on using the browser.