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_dup2.py

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