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/Makefile. More on this later.
15 A test executable is named test/{name}test.c
17 A test recipe is named test/recipes/{nn}-test_{name}.t, where {nn} is a two
18 digit number and {name} is a unique name of your choice.
20 The number {nn} is (somewhat loosely) grouped as follows:
22 00-04 sanity, internal and essential API tests
23 05-09 individual symmetric cipher algorithms
25 15-19 individual asymmetric cipher algorithms
26 20-24 openssl commands (some otherwise not tested)
27 25-29 certificate forms, generation and verification
31 80-89 "larger" protocols (CA, CMS, OCSP, SSL, TSA)
33 99 most time consuming tests [such as test_fuzz]
36 A recipe that just runs a test executable
37 =========================================
39 A script that just runs a program looks like this:
43 use OpenSSL::Test::Simple;
45 simple_test("test_{name}", "{name}test", "{name}");
47 {name} is the unique name you have chosen for your test.
49 The second argument to `simple_test' is the test executable, and `simple_test'
50 expects it to be located in test/
52 For documentation on OpenSSL::Test::Simple, do
53 `perldoc util/perl/OpenSSL/Test/Simple.pm'.
56 A recipe that runs a more complex test
57 ======================================
59 For more complex tests, you will need to read up on Test::More and
60 OpenSSL::Test. Test::More is normally preinstalled, do `man Test::More' for
61 documentation. For OpenSSL::Test, do `perldoc util/perl/OpenSSL/Test.pm'.
63 A script to start from could be this:
73 plan tests => 2; # The number of tests being performed
89 Changes to test/build.info
90 ==========================
92 Whenever a new test involves a new test executable you need to do the
93 following (at all times, replace {NAME} and {name} with the name of your
96 * add {name} to the list of programs under PROGRAMS_NO_INST
98 * create a three line description of how to build the test, you will have
99 to modify the include paths and source files if you don't want to use the
100 basic test framework:
102 SOURCE[{name}]={name}.c
103 INCLUDE[{name}]=.. ../include
104 DEPEND[{name}]=../libcrypto libtestutil.a
106 Generic form of C test executables
107 ==================================
109 #include "testutil.h"
111 static int my_test(void)
113 int testresult = 0; /* Assume the test will fail */
116 observed = function(); /* Call the code under test */
117 if (!TEST_int_equal(observed, 2)) /* Check the result is correct */
118 goto end; /* Exit on failure - optional */
120 testresult = 1; /* Mark the test case a success */
122 cleanup(); /* Any cleanup you require */
126 int setup_tests(void)
128 ADD_TEST(my_test); /* Add each test separately */
129 return 1; /* Indicate success */
132 You should use the TEST_xxx macros provided by testutil.h to test all failure
133 conditions. These macros produce an error message in a standard format if the
134 condition is not met (and nothing if the condition is met). Additional
135 information can be presented with the TEST_info macro that takes a printf
136 format string and arguments. TEST_error is useful for complicated conditions,
137 it also takes a printf format string and argument. In all cases the TEST_xxx
138 macros are guaranteed to evaluate their arguments exactly once. This means
139 that expressions with side effects are allowed as parameters. Thus,
141 if (!TEST_ptr(ptr = OPENSSL_malloc(..)))
143 works fine and can be used in place of:
145 ptr = OPENSSL_malloc(..);
148 The former produces a more meaningful message on failure than the latter.