README
1 #
2 # CDDL HEADER START
3 #
4 # The contents of this file are subject to the terms of the
5 # Common Development and Distribution License (the "License").
6 # You may not use this file except in compliance with the License.
7 #
8 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 # or http://www.opensolaris.org/os/licensing.
10 # See the License for the specific language governing permissions
11 # and limitations under the License.
12 #
13 # When distributing Covered Code, include this CDDL HEADER in each
14 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 # If applicable, add the following below this CDDL HEADER, with the
16 # fields enclosed by brackets "[]" replaced with your own identifying
17 # information: Portions Copyright [yyyy] [name of copyright owner]
18 #
19 # CDDL HEADER END
20 #
21
22 #
23 # Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24 # Use is subject to license terms.
25 #
26 # ident "@(#)README 1.3 09/03/15 SMI"
27 #
28
29 #
30 # README file for nc(1) CTI-TET test suite.
31 #
32
33 1. Introduction
34 2. Test coverage
35 3. System requirements
36 4. System changes
37 5. Installation
38 6. Running the tests
39 7. Building, configuring and running the tests from source code
40 8. Notes
41 9. Future work
42 10. Information for developers
43 11. Contact us
44
45
46 1. Introduction
47 ---------------
48
49 The Netcat test suite residing here is set of basic functionality tests
50 for Netcat implementation shipped with Solaris. It is based on unit
51 tests developed for pre-RTI testing of nc(1) integration into ON.
52
53 The test suite uses CTI-TET, Common Test Infrastructure (CTI) for Test
54 Environment Toolkit (TET). Please see the following link for more
55 information about CTI-TET both in OpenSolaris context and in general:
56
57 http://opensolaris.org/os/community/testing/testsuites/ctifortet/
58
59 The test suite is intended to be run by anyone from OpenSolaris community
60 who wants to contribute a bug fix or RFE to Netcat shipped with Solaris.
61
62 If you want to make a change in this test suite be sure you read "Information
63 for developers" section before progressing any further.
64
65 2. Test coverage
66 ----------------
67
68 With every RFE, new test purpose or test case should be added. The same
69 for serious bugs. Most of the functionality is covered by the tests with the
70 exception of features which require setup of servers (e.g. SOCKS support).
71
72 All tests should PASS. If not, please report a bug.
73
74 3. System requirements
75 ----------------------
76
77 3.1 Access to your local machine
78 --------------------------------
79
80 All tests run on local machine only. Root access is not required
81 unless the tests are set to use privileged port (see section 8) or test
82 suite package is installed/removed.
83
84 The test suite can be run both on SPARC and i386. Those two are the only
85 relevant modes because we use only shell scripts in this test suite.
86
87 3.2 Network interfaces
88 ----------------------
89
90 All tests need two loopback interface (lo0) instances, configured with
91 IPv4 (127.0.0.1) and IPv6 address (::1/128).
92
93 4. System changes
94 -----------------
95
96 This test suite does not currently modify system configuration in any way.
97
98 5. Installation
99 ---------------
100
101 This section is for those who want to install the test suite package. If you
102 want to run the tests from source code, see section 7.
103
104 The package will be installed into /opt. It is recommended that you install
105 the package from scratch, rather than on top of an existing installation.
106 Thus, if an old version of the tests is installed, remove it and install it
107 again:
108
109 root# pkgrm SUNWstc-net-nc
110 root# pkgadd -d <package-location> SUNWstc-net-nc
111
112 Note: SUNWstc-tetlite which contains CTI-TET framework tools is prerequisite
113 for SUNWstc-net-nc.
114
115 6. Running the tests
116 --------------------
117
118 Run the tests from the package like this:
119
120 $ cd /opt/SUNWstc-net-nc && \
121 export CTI_ROOT=/opt/SUNWstc-tetlite/contrib/ctitools; \
122 export PATH=$PATH:$CTI_ROOT/bin; \
123 run_test nc
124
125 The results files will be stored in /var/tmp/results.<PID> directory.
126 The default journal file name will be /var/tmp/results.<PID>/testlog
127 where PID is pid of run_test process.
128
129 6.1 Running single test case
130 ----------------------------
131
132 To run single test case (which can contain several test purposes)
133 use additional argument for run_test, e.g. for Tflag test case:
134
135 $ run_test nc Tflag
136
137 6.2 Running predefined scenarios
138 ---------------------------------
139
140 nc test suite is based on CTI-TET framework. It supports scenarios
141 and the test suite has predefined the following scenarios:
142
143 - short
144 - longer
145
146 Scenario definitions reside in the 'tet_scen' file.
147
148 To run e.g. the short scenario use the following command:
149
150 $ run_test nc short
151
152 6.3 Testing custom nc program
153 ------------------------------
154
155 To test nc program stored at different location than the default
156 /usr/bin/nc, set STC2_NC_PATH environment variable to
157 an alternative location.
158
159 7. Building, configuring and running the tests from source code
160 ---------------------------------------------------------------
161
162 - checkout the test suite source, if desired. For example,
163
164 $ hg clone ssh://anon@hg.opensolaris.org/hg/test-dev/stcnv-gate
165
166 If the previous Mercurial command was performed in directory
167 /local/userfoo/testing (say) then the source code of the nc
168 test suite will be placed at 'usr/src/suites/net/nc'. For
169 the rest of this discussion, we will use the string <WS_ROOT>
170 to refer to /local/userfoo/testing.
171
172 - to build the tests, set CTI-TET variables and run 'make':
173
174 $ export CTI_ROOT=/opt/SUNWstc-tetlite/contrib/ctitools; \
175 export PATH=$PATH:$CTI_ROOT/bin; \
176 cd <WS_ROOT>/usr/src/suites/net/nc \
177 && make
178
179 - run the test suite
180
181 $ cd <WS_ROOT>/usr/src/suites/net/nc && run_test nc
182
183 - examine results
184
185 $ less /var/tmp/results.<number>/testlog
186
187 Full path to the journal file is printed by run_test before start
188 of the tests and at the end of the run.
189
190 - at some later time the journal can be displayed in comprehensive form
191 via the following command:
192
193 $ report_writer /var/tmp/results.<number>/testlog /tmp/report.$$
194
195 - you can also build the SUNWstc-net-nc package:
196
197 $ cd <WS_ROOT>/usr/src/suites/net/nc && make package
198
199 The package will be constructed in
200 <WS_ROOT>/packages/`uname -p`/SUNWstc-net-nc/ directory.
201
202 After that it can be converted to the cpio package format via:
203
204 $ pkgtrans -s <WS_ROOT>/packages/`uname -p` \
205 /tmp/SUNWstc-net-nc.pkg SUNWstc-net-nc
206
207 The result package /tmp/SUNWstc-net-nc.pkg can be simply copied to
208 remote sytem and installed:
209
210 $ pkgadd -d SUNWstc-net-nc.pkg all
211
212 8. Notes
213 --------
214
215 8.1 Solution for bad latency to the tools
216 -----------------------------------------
217
218 If you run this test suite far from where the gate is exported from it
219 might be very slow. In that case it is enough just to recursively copy
220 tetlite directory from proto area to your local proto/tools directory
221 and then to set PATH accordingly.
222
223 8.2 Internal variables
224 ----------------------
225
226 If you need to test nc binary which is not in default location (for
227 example you want to test it without copying it from a build server)
228 or need to change port used for testing there is a list of variables
229 that you can set and export before running the test suite, together
230 with their default values:
231
232 variable default value
233 ------------------------------+----------------
234 STC2_NC_PATH /usr/bin/nc
235 STC2_NC_TEST_PORT 4444
236 STC2_NC_TEST_SOURCE_PORT_FIRST 55555
237 STC2_NC_TEST_SOURCE_PORT_LAST 55566
238 STC2_NC_WATCHMALLOC 1
239 STC2_NC_DEBUG 0
240 STC2_NC_STARTUP_TIMEOUT 10
241
242 8.3 Memory checking
243 -------------------
244
245 By default every nc command is run with watchmalloc(3MALLOC) checking.
246 Setting STC2_NC_WATCHMALLOC environment variable to 0 will cause nc to be run
247 without the checks.
248
249 8.4 Binding to ports and privileges
250 -----------------------------------
251
252 All of the tests utilizing TCP/UDP connections are using default port
253 number STC2_NC_TEST_PORT which is set to unprivileged port.
254
255 This could lead to setup phase (for test purposes which start nc in server
256 mode first and then perform the test by connecting with nc client process)
257 failures where bind(3SOCKET) call fails because the port is already
258 bound by different process. To overcome this limitation,
259 the default value can be overriden by setting STC2_NC_TEST_PORT
260 environment variable to privileged port (smaller than 1024) and
261 running the test suite with net_privaddr privilege (e.g. under root).
262
263 STC2_NC_TEST_SOURCE_PORT_{FIRST,LAST} port range is used (by calling
264 try_connect_srcport()) in test purposes using -p flag for setting source
265 TCP port such as those in vflag or pflag test cases. Same rules apply w.r.t.
266 privileged port number as above.
267
268 9. Future work
269 --------------
270
271 Aside from better test suite coverage, changes should be done which
272 would make the test suite more robust:
273
274 - addition of timeouts for test purposes
275 - detection of bind(3socket) failures and restart or using
276 net_privaddr privilege for running all tests with privileged port
277
278 As with nc(1), patches and contributions are welcome.
279
280 10. Information for developers
281 ------------------------------
282
283 If you want or need to debug the test suite, set STC2_NC_DEBUG variable to
284 positive value before running the tests. It will put some more
285 information into the journal.
286
287 nc should be executed either using predefined functions such as
288 listen_wrapper() or start_nc(). In some cases it is needed to execute
289 it directly. In such cases it should be started like this:
290
291 $ eval $NC arguments
292
293 This is because of watchmalloc(3MALLOC) checking (see NC_PRELOADS
294 definition in include/vars for details).
295
296 10.1 Start and end of a test purpose
297 ------------------------------------
298
299 Each test purpose should begin with a call to init_test() and should
300 end with a call to finish_test().
301
302 init_test() prints test purpose ID and description to journal file
303 and sets test_port/test_source_port internals variable to
304 STC2_NC_TEST_PORT/STC2_NC_TEST_SOURCE_PORT values, respectively.
305
306 finish_test() performs cleanup by killing any potentional left-over nc
307 processes via stop_nc() which uses internal variable NC_PIDFILE.
308
309 Also note that tet_startup,tet_cleanup variables are set to common_startup
310 and common_cleanup (defined in src/lib/ksh/common_funcs.ksh), respectively.
311
312 10.2 Internal variables
313 -----------------------
314
315 start_nc() sets two internal variables which accessible from test purposes:
316
317 Name Meaning
318 ------------+----------------------------------------------
319 NC_PIDFILE file containing pid of nc process
320 NC_ERRFILE file containing stderr produced by nc process
321
322 Both files have to be removed when the program started by start_nc() exits.
323 Normally, finish_test() takes care of that but in case start_nc()
324 is executed with custom pid file and error file the caller has to remove
325 them.
326
327 To remove custom pid files and kill the processes associated with them
328 finish_test() can be passed the variables.
329
330 10.3 Adding new tests
331 ---------------------
332
333 10.3.1 Adding new test purpose
334 ------------------------------
335
336 The following steps are needed:
337
338 1. create the file for the test purpose in given test case directory
339 e.g. tests/uflag/tp_uflag_004_neg.ksh
340
341 2. add new test purpose to TARGET_KSH variable in Makefile
342 for given test case
343
344 3. include the test purpose in test case script
345 (e.g. tests/uflag/tc_uflag.ksh)
346
347 10.3.2 Adding new test case
348 ---------------------------
349
350 To add new test case the following steps are needed:
351
352 1. add new subdirectory in tests/ directory with all necessary files
353 (Makefile, .ksh script for the test case, files for the test purposes)
354
355 2. modify the following files:
356
357 - tests/Makefile
358 append new test case directory to SUBDIRS variable definition
359
360 - tet_scen
361 add a new test case name to appropriate scenario and define
362 the test case with a path to the script
363
364 - Targetdirs
365 add new directory for the test case to ROOT.TEST variable
366
367 10.4 Code style
368 ---------------
369
370 When writing new ksh code make sure that the shell style rules are
371 followed:
372
373 http://www.opensolaris.org/os/project/shell/shellstyle/
374
375 All tests should run with both ksh88 and ksh93.
376
377 10.5 Using internal functions
378 -----------------------------
379
380 Temporary files or directories should be created using the nc_mktemp()
381 or nc_mktemp_dir() routines, respectively. These functions use common
382 prefix from the NC_TMPFILE_PREFIX variable defined in include/vars file.
383
384 Whenever nc_mktemp() is used directly, its output should be checked and
385 if it fails (empty string is returned) the caller should bail out.
386 For example (assuming we are in a function which returns 1 on failure):
387
388 typeset -r tmp_out=$( nc_mktemp test_purpose.out )
389 [[ -z $tmp_out ]] && return 1
390
391 In a test purpose, finish_test() should be called before returning.
392
393 Upon failure, nc_mktemp() will set the result of the currently running test
394 purpose to UNRESOLVED.
395
396 Assuming all test cases/purposes use these functions it should be easy to
397 check for leftover temporary files at the end of test suite run (signaling
398 there is a problem in test suite code). This command will perform the
399 check (with current definition of the common prefix used for
400 temporary files/directories) using the NC_TMPFILE_PREFIX definition from
401 include/vars:
402
403 $ /usr/bin/find /tmp/ -name 'nc_tet-*' 2>/dev/null
404
405 The output of the command should be empty.
406
407 11. Contact us
408 --------------
409
410 Please e-mail the STC_CONTACT listed in the STC.INFO file if you want to
411 contact us - your feedback is appreciated. If you want to file a bug, use
412 stc/net/nc category.
413
414