Ldstest
Version 3 (Laurent Defert, 09/4/2010 08:57 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 | 2 | Laurent Defert | You can see it in action in the tests performed here: |
| 12 | 2 | Laurent Defert | * http://piggledy.org/libprocess-buildbot/waterfall |
| 13 | 2 | Laurent Defert | * http://piggledy.org/libldsw-buildbot/waterfall |
| 14 | 2 | Laurent Defert | |
| 15 | 1 | h1. Installation |
|
| 16 | 1 | ||
| 17 | 1 | You can either checkout the git repository: |
|
| 18 | 1 | ||
| 19 | 1 | <pre> |
|
| 20 | 1 | git clone git://piggledy.org/ldstest.git |
|
| 21 | 1 | </pre> |
|
| 22 | 1 | ||
| 23 | 1 | Or install it using the available "Gentoo overlay":/projects/show/gentoo-overlay, by emerging the ebuild dev-util/ldstest. |
|
| 24 | 1 | ||
| 25 | 1 | h1. Documentation |
|
| 26 | 1 | ||
| 27 | 1 | h2. Checking simple commands: |
|
| 28 | 1 | ||
| 29 | 1 | When writing test scripts, you mainly want to have an overview of what test was successful and which test was a failure. |
|
| 30 | 1 | In order to do that you would use the script ldstest_check like this: |
|
| 31 | 1 | ||
| 32 | 1 | <pre> |
|
| 33 | 1 | ldstest_check "Testing: ls /" 5 ls / |
|
| 34 | 1 | ldstest_check "Testing: touch /" 5 touch / |
|
| 35 | 1 | ldstest_check "Testing: sleep 10" 5 sleep 10 |
|
| 36 | 1 | </pre> |
|
| 37 | 1 | ||
| 38 | 1 | Where arguments to the ldstest_check are: |
|
| 39 | 1 | * The description of the test |
|
| 40 | 1 | * The timeout of the test |
|
| 41 | 1 | * The command to run |
|
| 42 | 1 | ||
| 43 | 1 | In case of failure the output of the command is displayed. The previous example would show: |
|
| 44 | 1 | ||
| 45 | 1 | <pre> |
|
| 46 | 1 | Testing: ls / OK |
|
| 47 | 1 | Testing: touch / FAILED |
|
| 48 | 1 | ||
| 49 | 1 | touch / |
|
| 50 | 1 | touch: setting times of `/': Permission denied |
|
| 51 | 1 | Testing: sleep 10 TIMEOUT |
|
| 52 | 1 | ||
| 53 | 1 | sleep 10 |
|
| 54 | 1 | /home/lds/dev/ldstest/ldstest_check: line 52: 15596 Killed ldstest_log_to_file "$@" |
|
| 55 | 1 | </pre> |
|
| 56 | 1 | ||
| 57 | 1 | h2. Checking C code: |
|
| 58 | 1 | ||
| 59 | 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: |
|
| 60 | 1 | ||
| 61 | 1 | <pre> |
|
| 62 | 1 | ldstest_check_c "1 2 3" "Testing echo output" ./test_echo_output.sh |
|
| 63 | 1 | </pre> |
|
| 64 | 1 | ||
| 65 | 1 | Where arguments to the ldstest_check are: |
|
| 66 | 1 | * The timeouts when running the test normally, the under valgrind, then under helgrind |
|
| 67 | 1 | * The description of the test |
|
| 68 | 1 | * The command to run |
|
| 69 | 1 | ||
| 70 | 1 | The test_echo_output.sh would contain : |
|
| 71 | 1 | ||
| 72 | 1 | <pre> |
|
| 73 | 1 | #!/bin/bash |
|
| 74 | 1 | ||
| 75 | 1 | # Check the output of "echo blah" is really blah |
|
| 76 | 1 | if [ $("$STARTER" echo blah) != "blah" ] |
|
| 77 | 1 | then |
|
| 78 | 1 | echo "Doo!" |
|
| 79 | 1 | exit 1 |
|
| 80 | 1 | fi |
|
| 81 | 1 | </pre> |
|
| 82 | 1 | ||
| 83 | 1 | At runtime the $STARTER variable is replaced by the correct, issuing such tests: |
|
| 84 | 1 | ||
| 85 | 1 | <pre> |
|
| 86 | 1 | Testing echo output OK |
|
| 87 | 1 | Valgrind check: Testing echo output OK |
|
| 88 | 1 | Helgrind check: Testing echo output OK |
|
| 89 | 1 | </pre> |
|
| 90 | 3 | Laurent Defert | |
| 91 | 3 | Laurent Defert | h2. Other options |
| 92 | 3 | Laurent Defert | |
| 93 | 3 | Laurent Defert | Some options can be exported as global variables to modify the behavior of tests: |
| 94 | 3 | Laurent Defert | |
| 95 | 3 | Laurent Defert | |Variable|Description| |
| 96 | 3 | Laurent Defert | |HELGRIND_OPT|Arguments passed to helgrind| |
| 97 | 3 | Laurent Defert | |VALGRIND_OPT|Arguments passed to valgrind| |