]>
Commit | Line | Data |
---|---|---|
232087fd JN |
1 | #!/bin/sh |
2 | ||
3 | test_description="Test the svn importer's input handling routines. | |
d280f683 JN |
4 | |
5 | These tests exercise the line_buffer library, but their real purpose | |
6 | is to check the assumptions that library makes of the platform's input | |
7 | routines. Processes engaged in bi-directional communication would | |
8 | hang if fread or fgets is too greedy. | |
9 | ||
10 | While at it, check that input of newlines and null bytes are handled | |
11 | correctly. | |
232087fd JN |
12 | " |
13 | . ./test-lib.sh | |
14 | ||
d280f683 JN |
15 | test -n "$GIT_REMOTE_SVN_TEST_BIG_FILES" && test_set_prereq EXPENSIVE |
16 | ||
17 | generate_tens_of_lines () { | |
18 | tens=$1 && | |
19 | line=$2 && | |
20 | ||
21 | i=0 && | |
22 | while test $i -lt "$tens" | |
23 | do | |
24 | for j in a b c d e f g h i j | |
25 | do | |
26 | echo "$line" | |
27 | done && | |
28 | : $((i = $i + 1)) || | |
29 | return | |
30 | done | |
31 | } | |
32 | ||
33 | long_read_test () { | |
34 | : each line is 10 bytes, including newline && | |
35 | line=abcdefghi && | |
36 | echo "$line" >expect && | |
37 | ||
38 | if ! test_declared_prereq PIPE | |
39 | then | |
40 | echo >&4 "long_read_test: need to declare PIPE prerequisite" | |
41 | return 127 | |
42 | fi && | |
43 | tens_of_lines=$(($1 / 100 + 1)) && | |
44 | lines=$(($tens_of_lines * 10)) && | |
45 | readsize=$((($lines - 1) * 10 + 3)) && | |
46 | copysize=7 && | |
47 | rm -f input && | |
48 | mkfifo input && | |
49 | { | |
50 | { | |
51 | generate_tens_of_lines $tens_of_lines "$line" && | |
52 | sleep 100 | |
53 | } >input & | |
54 | } && | |
55 | test-line-buffer input <<-EOF >output && | |
56 | read $readsize | |
57 | copy $copysize | |
58 | EOF | |
59 | kill $! && | |
60 | test_line_count = $lines output && | |
61 | tail -n 1 <output >actual && | |
62 | test_cmp expect actual | |
63 | } | |
64 | ||
65 | test_expect_success 'setup: have pipes?' ' | |
66 | rm -f frob && | |
67 | if mkfifo frob | |
68 | then | |
69 | test_set_prereq PIPE | |
70 | fi | |
71 | ' | |
72 | ||
73 | test_expect_success 'hello world' ' | |
232087fd JN |
74 | echo HELLO >expect && |
75 | test-line-buffer <<-\EOF >actual && | |
7b990c90 | 76 | read 6 |
232087fd JN |
77 | HELLO |
78 | EOF | |
79 | test_cmp expect actual | |
80 | ' | |
81 | ||
d280f683 JN |
82 | test_expect_success PIPE '0-length read, no input available' ' |
83 | >expect && | |
84 | rm -f input && | |
85 | mkfifo input && | |
86 | { | |
87 | sleep 100 >input & | |
88 | } && | |
89 | test-line-buffer input <<-\EOF >actual && | |
90 | read 0 | |
91 | copy 0 | |
92 | EOF | |
93 | kill $! && | |
94 | test_cmp expect actual | |
95 | ' | |
96 | ||
232087fd | 97 | test_expect_success '0-length read, send along greeting' ' |
7b990c90 | 98 | echo HELLO >expect && |
232087fd JN |
99 | test-line-buffer <<-\EOF >actual && |
100 | read 0 | |
7b990c90 | 101 | copy 6 |
232087fd JN |
102 | HELLO |
103 | EOF | |
104 | test_cmp expect actual | |
105 | ' | |
106 | ||
d280f683 JN |
107 | test_expect_success PIPE '1-byte read, no input available' ' |
108 | printf "%s" ab >expect && | |
109 | rm -f input && | |
110 | mkfifo input && | |
111 | { | |
112 | { | |
113 | printf "%s" a && | |
114 | printf "%s" b && | |
115 | sleep 100 | |
116 | } >input & | |
117 | } && | |
118 | test-line-buffer input <<-\EOF >actual && | |
119 | read 1 | |
120 | copy 1 | |
121 | EOF | |
122 | kill $! && | |
123 | test_cmp expect actual | |
124 | ' | |
125 | ||
126 | test_expect_success PIPE 'long read (around 8192 bytes)' ' | |
127 | long_read_test 8192 | |
128 | ' | |
129 | ||
130 | test_expect_success PIPE,EXPENSIVE 'longer read (around 65536 bytes)' ' | |
131 | long_read_test 65536 | |
132 | ' | |
133 | ||
7b990c90 JN |
134 | test_expect_success 'buffer_read_string copes with null byte' ' |
135 | >expect && | |
232087fd | 136 | q_to_nul <<-\EOF | test-line-buffer >actual && |
7b990c90 | 137 | read 2 |
232087fd JN |
138 | Q |
139 | EOF | |
140 | test_cmp expect actual | |
141 | ' | |
142 | ||
7b990c90 JN |
143 | test_expect_success 'skip, copy null byte' ' |
144 | echo Q | q_to_nul >expect && | |
232087fd | 145 | q_to_nul <<-\EOF | test-line-buffer >actual && |
7b990c90 JN |
146 | skip 2 |
147 | Q | |
148 | copy 2 | |
232087fd JN |
149 | Q |
150 | EOF | |
151 | test_cmp expect actual | |
152 | ' | |
153 | ||
e832f43c JN |
154 | test_expect_success 'read null byte' ' |
155 | echo ">QhelloQ" | q_to_nul >expect && | |
156 | q_to_nul <<-\EOF | test-line-buffer >actual && | |
157 | binary 8 | |
158 | QhelloQ | |
159 | EOF | |
160 | test_cmp expect actual | |
161 | ' | |
162 | ||
232087fd | 163 | test_expect_success 'long reads are truncated' ' |
7b990c90 | 164 | echo foo >expect && |
232087fd JN |
165 | test-line-buffer <<-\EOF >actual && |
166 | read 5 | |
167 | foo | |
168 | EOF | |
169 | test_cmp expect actual | |
170 | ' | |
171 | ||
172 | test_expect_success 'long copies are truncated' ' | |
173 | printf "%s\n" "" foo >expect && | |
174 | test-line-buffer <<-\EOF >actual && | |
7b990c90 | 175 | read 1 |
232087fd JN |
176 | |
177 | copy 5 | |
178 | foo | |
179 | EOF | |
180 | test_cmp expect actual | |
181 | ' | |
182 | ||
e832f43c JN |
183 | test_expect_success 'long binary reads are truncated' ' |
184 | echo ">foo" >expect && | |
185 | test-line-buffer <<-\EOF >actual && | |
186 | binary 5 | |
187 | foo | |
188 | EOF | |
189 | test_cmp expect actual | |
190 | ' | |
191 | ||
232087fd | 192 | test_done |