Ldstest

Version 1 (Laurent Defert, 11/28/2009 09:02 pm)

1 1
h1. Overview
2 1
3 1
This project provides a few Bash scripts to perform automated tests.
4 1
Main features are: 
5 1
* Transparently run tests under Valgrind
6 1
* Kills buggy tests after a certain timeout
7 1
* Generic
8 1
* Easy to use
9 1
* Easy to modify
10 1
11 1
h1. Installation
12 1
13 1
You can either checkout the git repository:
14 1
15 1
<pre>
16 1
git clone git://piggledy.org/ldstest.git
17 1
</pre>
18 1
19 1
Or install it using the available "Gentoo overlay":/projects/show/gentoo-overlay, by emerging the ebuild dev-util/ldstest.
20 1
21 1
h1. Documentation
22 1
23 1
h2. Checking simple commands:
24 1
25 1
When writing test scripts, you mainly want to have an overview of what test was successful and which test was a failure.
26 1
In order to do that you would use the script ldstest_check like this:
27 1
28 1
<pre>
29 1
ldstest_check "Testing: ls /" 5 ls /
30 1
ldstest_check "Testing: touch /" 5 touch /
31 1
ldstest_check "Testing: sleep 10" 5 sleep 10
32 1
</pre>
33 1
34 1
Where arguments to the ldstest_check are:
35 1
* The description of the test
36 1
* The timeout of the test
37 1
* The command to run
38 1
39 1
In case of failure the output of the command is displayed. The previous example would show:
40 1
41 1
<pre>
42 1
Testing: ls /		OK
43 1
Testing: touch /		FAILED
44 1
45 1
touch /
46 1
touch: setting times of `/': Permission denied
47 1
Testing: sleep 10		TIMEOUT
48 1
49 1
sleep 10
50 1
/home/lds/dev/ldstest/ldstest_check: line 52: 15596 Killed                  ldstest_log_to_file "$@"
51 1
</pre>
52 1
53 1
h2. Checking C code:
54 1
55 1
To test C code ldstest provides a ldstest_check_c command to transparently run the test under valgrind. The ldstest_check_c command exports a $STARTER environment variable that provides a helper script that will run the test under Valgrind. To use it:
56 1
57 1
<pre>
58 1
ldstest_check_c "1 2 3" "Testing echo output" ./test_echo_output.sh
59 1
</pre>
60 1
61 1
Where arguments to the ldstest_check are:
62 1
* The timeouts when running the test normally, the under valgrind, then under helgrind
63 1
* The description of the test
64 1
* The command to run
65 1
66 1
The test_echo_output.sh would contain :
67 1
68 1
<pre>
69 1
#!/bin/bash
70 1
71 1
# Check the output of "echo blah" is really blah
72 1
if [ $("$STARTER" echo blah) != "blah" ]
73 1
then
74 1
	echo "Doo!"
75 1
	exit 1
76 1
fi
77 1
</pre>
78 1
79 1
At runtime the $STARTER variable is replaced by the correct, issuing such tests:
80 1
81 1
<pre>
82 1
Testing echo output		OK
83 1
Valgrind check: Testing echo output		OK
84 1
Helgrind check: Testing echo output		OK
85 1
</pre>