| 1 |
This document describes the working of the GNU Wget Test Suite. |
| 2 |
|
| 3 |
Install Instructions: |
| 4 |
================================================================================ |
| 5 |
|
| 6 |
This Test Suite exploits the Parallel Test Harness available in GNU Autotools. |
| 7 |
Since it uses features from a relatively recent version of Autotools, the minimum |
| 8 |
required version as been bumped up to 1.11. |
| 9 |
Run the './configure' command to generate the Makefile and then run 'make check' |
| 10 |
to execute the Test Suite. Use the '-j n' option with 'make check' to execute |
| 11 |
n tests simultaneously. |
| 12 |
|
| 13 |
Structure: |
| 14 |
================================================================================ |
| 15 |
|
| 16 |
* server: This package contains custom programmatically configurable servers |
| 17 |
(both HTTP and FTP) for testing Wget. The HTTP server runs an instance of |
| 18 |
Python's http.server module. The FTP server is to be implemented. |
| 19 |
|
| 20 |
* test: This package contains the test case classes for HTTP and FTP. The |
| 21 |
test case classes includes methods for initializing and cleaning up of the |
| 22 |
test environment. |
| 23 |
|
| 24 |
* Test-Proto.py: This is a prototype Test Case file. The file defines all |
| 25 |
the acceptable elements and their uses. Typically, one must copy this file |
| 26 |
and edit it for writing Test Cases. |
| 27 |
|
| 28 |
* exc: This package contains custom exception classes used in this test |
| 29 |
suite. |
| 30 |
|
| 31 |
* conf: This package contains the configuration classes for servers to be |
| 32 |
configured with. |
| 33 |
|
| 34 |
* misc: This package contains several helper modules used in this test |
| 35 |
suite. |
| 36 |
- colour_terminal.py: A custom module for printing coloured output to |
| 37 |
the terminal. Currently it only supports 4 colours in a *nix |
| 38 |
environment. |
| 39 |
- wget_file.py: Module which contains WgetFile, which is a file data |
| 40 |
container object. |
| 41 |
|
| 42 |
Working: |
| 43 |
================================================================================ |
| 44 |
|
| 45 |
The Test Files are valid Python scripts and the default mask for them is 755. |
| 46 |
A singular Test must be invoked in the following manner, with the current |
| 47 |
directory being the testenv directory: |
| 48 |
$ ./python3 <Name of Test File> OR |
| 49 |
$ ./<Name of Test File> |
| 50 |
The script will then initialize the various elements and pass them to an object |
| 51 |
of the respective Test Class. A directory with the name <Test name>-test will be |
| 52 |
created and the PWD will be changed to this directory. The server is then |
| 53 |
spawned with the required configuration elements. A blocking call to Wget is |
| 54 |
made with the command line arguments specified in the Test Case along with the |
| 55 |
list of URLs that it must download. The server is killed once Wget returns and |
| 56 |
the following checks are used to determine the pass/fail status of the test: |
| 57 |
* Return Code: The Exit code of Wget is matched against the expected Exit |
| 58 |
Code as mentioned in the Test Case File. |
| 59 |
* Downloaded Files: Check whether the expected downloaded files exist on |
| 60 |
disk. |
| 61 |
* File Content: Test whether the file contents were correctly downloaded by |
| 62 |
Wget and not corrupted mid-way. |
| 63 |
* Excess Files: Check to see whether any unexpected files were downloaded |
| 64 |
by Wget. |
| 65 |
|
| 66 |
Exit Codes: |
| 67 |
=============================================================================== |
| 68 |
|
| 69 |
Following is a list of Exit Status Codes for the tests: |
| 70 |
* 0 Test Successful |
| 71 |
* 66 Errors/Warnings Reported by Thread Sanitizer (If built with -fsanitize) |
| 72 |
* 77 Test Skipped |
| 73 |
* 99 Hard Error |
| 74 |
* 100 Test Failed |
| 75 |
|
| 76 |
Tests are skipped when they are either not supported by the platform, or Wget |
| 77 |
is not compiled with support for that feature. This feature has not yet been |
| 78 |
implemented. |
| 79 |
|
| 80 |
Hard Errors occur when there are problems with the Environment code. Hard |
| 81 |
Error reporting is currently not enabled and all errors are reported as |
| 82 |
failures. |
| 83 |
|
| 84 |
All exceptions should ideally be handled gracefully. If you see any unhandled |
| 85 |
exceptions, please file a bug report at <[email protected]> |
| 86 |
|
| 87 |
Environment Variables: |
| 88 |
================================================================================ |
| 89 |
|
| 90 |
* SERVER_WAIT: Set this environment variable with a value for the number of |
| 91 |
seconds the test should sleep between invoking the server and calling the Wget |
| 92 |
executable. This is used when one would like to test a different version of |
| 93 |
the executable or for running the test through external utilities like gdb and |
| 94 |
valgrind. |
| 95 |
* NO_CLEANUP: Do not remove the temporary files created by the test. |
| 96 |
This will prevent the ${testname}-test directory from being deleted |
| 97 |
* VALGRIND_TESTS: If this variable is set and contains the valgrind command line, |
| 98 |
the test suite will execute all the tests via this command. |
| 99 |
If it is set to "1", valgrind memcheck is enabled with hard coded options. |
| 100 |
This variable is set by ./configure --enable-valgrind-tests. |
| 101 |
* SSL_TESTS: This must be set to run any https tests. |
| 102 |
* WGET_PATH: Set this environment variable to a path to wget binary on which you |
| 103 |
want to run tests. This is useful for OS distributions, which want to reuse |
| 104 |
upstream tests for testing wget build that they distribute. If the variable is |
| 105 |
not set, the "../src/wget" binary is used by tests. |
| 106 |
|
| 107 |
|
| 108 |
File Structure: |
| 109 |
================================================================================ |
| 110 |
|
| 111 |
The test case files are Python scripts. It is believed that Python is a simple |
| 112 |
yet elegant language and should be easy for everyone to comprehend. This test |
| 113 |
suite is written with the objective of making it easy to write new tests. The |
| 114 |
structure has been kept as intuitive as possible and should not require much |
| 115 |
effort to get accustomed to. |
| 116 |
|
| 117 |
All Test Files MUST begin with the following Three Lines: |
| 118 |
#!/usr/bin/python3 |
| 119 |
from sys import exit |
| 120 |
from WgetTest import {HTTPTest|FTPTest} |
| 121 |
from misc.wget_file import WgetFile |
| 122 |
|
| 123 |
It is recommended that a small description of the Test Case is provided next. |
| 124 |
This would be very helpful to future contributors. |
| 125 |
|
| 126 |
Each File in the Test must be represented as a WgetFile object. The WgetFile |
| 127 |
Class has the following prototype: |
| 128 |
WgetFile (str name, str contents, str timestamp, dict rules) |
| 129 |
None except name is a mandatory parameter, one may pass only those parameters |
| 130 |
that are required by the File object. |
| 131 |
|
| 132 |
The timestamp string should be in a format: "YYYY-MM-DD HH:MM:SS" in UTC zone. |
| 133 |
The rules object is a dictionary element, with the key as the Rule Name and |
| 134 |
value as the Rule Data. In most cases, the Rule Data is another dictionary. |
| 135 |
|
| 136 |
Various variables used consistently across all tests are: |
| 137 |
* WGET_OPTIONS: The command line string passed to Wget upon invocation. This |
| 138 |
string may contain URLs, like in the case where in-URL authentication is |
| 139 |
used. Variable names passed like {{var_name}} will be replaced by the |
| 140 |
contents of the variable self.var_name before being passed to Wget |
| 141 |
* WGET_URLS: This is a list of filenames which will be appended as the URLs |
| 142 |
to Wget during invocation. This is a list of lists, where WGET_URLS[0] |
| 143 |
represents the list of Filenames called from Server[0], WGET_URLS[1] is a |
| 144 |
list of files downloaded from Server[2], etc. They must be relative URLs, |
| 145 |
i.e., not start with "/". |
| 146 |
* Files: This variable defines the files that exist in the Server's |
| 147 |
file system. The Files variable is a list of lists of WgetFile objects. |
| 148 |
This means that File[0] is a list of WgetFile objects that lie on Server[0], |
| 149 |
File[1] a list of files on Server[1] and so on. |
| 150 |
* Existing_Files: This is a list of files that already exist in the |
| 151 |
directory from which Wget is invoked. |
| 152 |
* ExpectedReturnCode: The Exit Code expected to be returned by Wget after |
| 153 |
the test. |
| 154 |
* ExpectedDownloadedFiles: A list of files that are expected in the local |
| 155 |
directory after Wget has finished executing. This does not include the files |
| 156 |
already existing before Wget was launched and must be mentioned again. |
| 157 |
* Request_List: An unordered list of Requests that each server must receive. |
| 158 |
This too is a list of lists and follows the same convention as others above. |
| 159 |
|
| 160 |
Both, the HTTPTest and FTPTest modules have the same prototype: |
| 161 |
{ |
| 162 |
pre_hook, |
| 163 |
test_options, |
| 164 |
post_hook, |
| 165 |
protocols |
| 166 |
} |
| 167 |
the three hooks should be Python dict objects and protocols should be a list of |
| 168 |
protocols, like [HTTP, HTTPS]. |
| 169 |
|
| 170 |
Valid File Rules: |
| 171 |
================================================================================ |
| 172 |
|
| 173 |
This section lists the currently supported File Rules and their structure. |
| 174 |
|
| 175 |
* Authentication: Used when a File must require Authorization for access. |
| 176 |
The value for this key is the following dictionary: |
| 177 |
|-->Type : Basic|Digest|Both|Both_inline |
| 178 |
|-->User : <Username> |
| 179 |
--->Pass : <Password> |
| 180 |
|
| 181 |
* ExpectHeader : The following Headers MUST exist in every Request for the |
| 182 |
File. The value for this key is a dictionary object where each header is |
| 183 |
represented as: |
| 184 |
|-->Header Name : <Header Data> |
| 185 |
|
| 186 |
* RejectHeader : This list of Headers must NEVER occur in a request. It |
| 187 |
uses the same value format as ExpectHeader. |
| 188 |
|
| 189 |
* SendHeader : This list of Headers will be sent in EVERY response to a |
| 190 |
request for the respective file. It follows the same value format as |
| 191 |
ExpectHeader. Additionally you can specify a list of strings as <Header Data> |
| 192 |
if you want the header repeated with multiple values. |
| 193 |
|
| 194 |
* Response : The HTTP Response Code to send to a request for this File. |
| 195 |
The value is an Integer that represents a valid HTTP Response Code. |
| 196 |
|
| 197 |
Pre Test Hooks: |
| 198 |
================================================================================ |
| 199 |
|
| 200 |
The Pre-Test Hooks are executed just after starting the server and just before |
| 201 |
spawning an instance of the server. These are usually used for setting up the |
| 202 |
Test Environment and Server Rules. The currently supported Pre-Test Hooks are: |
| 203 |
|
| 204 |
* ServerFiles : A list of WgetFile objects that must exist on the Server |
| 205 |
* LocalFiles : A list of WgetFile objects that exist locally on disk |
| 206 |
before Wget is executed. |
| 207 |
|
| 208 |
Since pre_test is a dictionary, one may not assume that the hooks will be |
| 209 |
executed in the same order as they are defined. |
| 210 |
|
| 211 |
Test Options: |
| 212 |
================================================================================ |
| 213 |
|
| 214 |
The test_options dictionary defines the commands to be used when the Test is |
| 215 |
executed. The currently supported options are: |
| 216 |
|
| 217 |
* Urls : A list of the filenames that Wget must attempt to |
| 218 |
download. The complete URL will be created and passed to Wget |
| 219 |
automatically. (alias URLs) |
| 220 |
* WgetCommands : A string consisting of the various commandline switches |
| 221 |
sent to Wget upon invocation. Any data placed between {{ }} in this string |
| 222 |
will be replaced with the contents of self.<data> before being passed to |
| 223 |
Wget. This is particularly useful for getting the hostname and port for a |
| 224 |
file. While all Download URL's are passed to Urls, a notable exception is |
| 225 |
when in-url authentication is used. In such a case, the URL is specified in |
| 226 |
the WgetCommands string. |
| 227 |
* EnvironmentVariables: A dictionary with key-value items, which will be |
| 228 |
defined as environment variables during the execution of wget command in |
| 229 |
test. |
| 230 |
|
| 231 |
Post-Test Hooks: |
| 232 |
================================================================================ |
| 233 |
|
| 234 |
These hooks are executed as soon as the call to Wget returns. The post-test |
| 235 |
hooks are usually used to run checks on the data, files downloaded, return code, |
| 236 |
etc. The following hooks are currently supported: |
| 237 |
|
| 238 |
* ExpectedRetcode : This is an integer value of the ReturnCode with which |
| 239 |
Wget is expected to exit. (alias ExpectedRetCode) |
| 240 |
* ExpectedFiles : This is a list of WgetFile objects of the files that |
| 241 |
must exist locally on disk in the Test directory. |
| 242 |
* FilesCrawled : This requires a list of the Requests that the server is |
| 243 |
expected to receive. The order is un-important since it will vary on the |
| 244 |
parallel-wget branch. This hook is used in tests for Recursive mode to |
| 245 |
ensure that the website is traversed correctly. |
| 246 |
|
| 247 |
Writing New Tests: |
| 248 |
================================================================================ |
| 249 |
|
| 250 |
See Test-Proto.py for an example of how to write Test Case files. The |
| 251 |
recommended method for writing new Test Case files is to copy Test-Proto.py and |
| 252 |
modify it to ones needs. |
| 253 |
|
| 254 |
In case you require any functionality that is not currently defined in List of |
| 255 |
Rules defined above, you should implement a new class in the conf package. The |
| 256 |
file name doesn't matter (though it's better to give it an appropriate name). |
| 257 |
The new rule or hook class should be like this: |
| 258 |
============================================ |
| 259 |
from conf import rule |
| 260 |
|
| 261 |
|
| 262 |
@rule() |
| 263 |
class MyNewRule: |
| 264 |
def __init__(self, rule_arg): |
| 265 |
self.rule_arg = rule_arg |
| 266 |
# your rule initialization code goes here |
| 267 |
============================================ |
| 268 |
from conf import hook |
| 269 |
|
| 270 |
|
| 271 |
@hook() |
| 272 |
class MyNewHook: |
| 273 |
def __init__(self, hook_arg): |
| 274 |
self.hook_arg = hook_arg |
| 275 |
# your hook initialization code goes here |
| 276 |
|
| 277 |
def __call__(self, test_obj): |
| 278 |
# your hook code goes here |
| 279 |
============================================ |
| 280 |
|
| 281 |
Once a new Test File is created, it must be added to the TESTS variable in |
| 282 |
Makefile.am. This way the Test will be executed on running a 'make check'. |
| 283 |
If a Test is expected to fail on the current master branch, then the Test should |
| 284 |
also be added to the XFAIL_TESTS variable. This will allow expected failures to |
| 285 |
pass through. If a test mentioned in the XFAIL_TESTS variable passes, it gets |
| 286 |
red-flagged as a XPASS. Currently, tests expected to fail under valgrind are not |
| 287 |
explicitly marked as XFAIL. Tests failing under valgrind must always be |
| 288 |
considered a blocking error. |
| 289 |
|
| 290 |
Work Remaining: |
| 291 |
================================================================================ |
| 292 |
|
| 293 |
Some amount of work still remains to be done. |
| 294 |
* Errors in server-side checks need to be handled more explicitly |
| 295 |
* Support parallel-wget branch |
| 296 |
* Support to spawn multiple servers is already in place. Need to handle |
| 297 |
multiple requests to a server simultaneously. Use THreading MixIn. |
| 298 |
* SSL Tests. Use xyne's HTTPS server implementation |
| 299 |
* Complete support for FTP Tests |
| 300 |
* IRI Support. This shouldn't require much effort |
| 301 |
|
| 302 |
Requirements: |
| 303 |
================================================================================ |
| 304 |
|
| 305 |
1. Python >= 3.0 |
| 306 |
2. Automake >= 1.11 |