4 For any test that you want to perform, you write a script located in
5 test/recipes/, named {nn}-test_{name}.t, where {nn} is a two digit number and
6 {name} is a unique name of your choice.
8 Please note that if a test involves a new testing executable, you will need to
9 do some additions in test/build.info. Please refer to the section "Changes to
10 test/build.info" below.
16 A test executable is named test/{name}test.c
18 A test recipe is named test/recipes/{nn}-test_{name}.t, where {nn} is a two
19 digit number and {name} is a unique name of your choice.
21 The number {nn} is (somewhat loosely) grouped as follows:
23 00-04 sanity, internal and essential API tests
24 05-09 individual symmetric cipher algorithms
26 15-19 individual asymmetric cipher algorithms
27 20-24 openssl commands (some otherwise not tested)
28 25-29 certificate forms, generation and verification
32 80-89 "larger" protocols (CA, CMS, OCSP, SSL, TSA)
34 99 most time consuming tests [such as test_fuzz]
37 A recipe that just runs a test executable
38 =========================================
40 A script that just runs a program looks like this:
44 use OpenSSL::Test::Simple;
46 simple_test("test_{name}", "{name}test", "{name}");
48 {name} is the unique name you have chosen for your test.
50 The second argument to `simple_test' is the test executable, and `simple_test'
51 expects it to be located in test/
53 For documentation on OpenSSL::Test::Simple, do
54 `perldoc util/perl/OpenSSL/Test/Simple.pm'.
57 A recipe that runs a more complex test
58 ======================================
60 For more complex tests, you will need to read up on Test::More and
61 OpenSSL::Test. Test::More is normally preinstalled, do `man Test::More' for
62 documentation. For OpenSSL::Test, do `perldoc util/perl/OpenSSL/Test.pm'.
64 A script to start from could be this:
74 plan tests => 2; # The number of tests being performed
90 Changes to test/build.info
91 ==========================
93 Whenever a new test involves a new test executable you need to do the
94 following (at all times, replace {NAME} and {name} with the name of your
97 * add {name} to the list of programs under PROGRAMS_NO_INST
99 * create a three line description of how to build the test, you will have
100 to modify the include paths and source files if you don't want to use the
101 basic test framework:
103 SOURCE[{name}]={name}.c
104 INCLUDE[{name}]=.. ../include ../apps/include
105 DEPEND[{name}]=../libcrypto libtestutil.a
107 Generic form of C test executables
108 ==================================
110 #include "testutil.h"
112 static int my_test(void)
114 int testresult = 0; /* Assume the test will fail */
117 observed = function(); /* Call the code under test */
118 if (!TEST_int_eq(observed, 2)) /* Check the result is correct */
119 goto end; /* Exit on failure - optional */
121 testresult = 1; /* Mark the test case a success */
123 cleanup(); /* Any cleanup you require */
127 int setup_tests(void)
129 ADD_TEST(my_test); /* Add each test separately */
130 return 1; /* Indicate success */
133 You should use the TEST_xxx macros provided by testutil.h to test all failure
134 conditions. These macros produce an error message in a standard format if the
135 condition is not met (and nothing if the condition is met). Additional
136 information can be presented with the TEST_info macro that takes a printf
137 format string and arguments. TEST_error is useful for complicated conditions,
138 it also takes a printf format string and argument. In all cases the TEST_xxx
139 macros are guaranteed to evaluate their arguments exactly once. This means
140 that expressions with side effects are allowed as parameters. Thus,
142 if (!TEST_ptr(ptr = OPENSSL_malloc(..)))
144 works fine and can be used in place of:
146 ptr = OPENSSL_malloc(..);
149 The former produces a more meaningful message on failure than the latter.