1 1.1 christos How to add recipes 2 1.1 christos ================== 3 1.1 christos 4 1.1 christos For any test that you want to perform, you write a script located in 5 1.1 christos test/recipes/, named {nn}-test_{name}.t, where {nn} is a two digit number and 6 1.1 christos {name} is a unique name of your choice. 7 1.1 christos 8 1.1 christos Please note that if a test involves a new testing executable, you will need to 9 1.1 christos do some additions in test/Makefile. More on this later. 10 1.1 christos 11 1.1 christos 12 1.1 christos Naming conventions 13 1.1 christos ================= 14 1.1 christos 15 1.1 christos A test executable is named test/{name}test.c 16 1.1 christos 17 1.1 christos A test recipe is named test/recipes/{nn}-test_{name}.t, where {nn} is a two 18 1.1 christos digit number and {name} is a unique name of your choice. 19 1.1 christos 20 1.1 christos The number {nn} is (somewhat loosely) grouped as follows: 21 1.1 christos 22 1.1 christos 00-04 sanity, internal and essential API tests 23 1.1 christos 05-09 individual symmetric cipher algorithms 24 1.1 christos 10-14 math (bignum) 25 1.1 christos 15-19 individual asymmetric cipher algorithms 26 1.1 christos 20-24 openssl commands (some otherwise not tested) 27 1.1 christos 25-29 certificate forms, generation and verification 28 1.1 christos 30-35 engine and evp 29 1.1 christos 60-79 APIs 30 1.1 christos 70 PACKET layer 31 1.1 christos 80-89 "larger" protocols (CA, CMS, OCSP, SSL, TSA) 32 1.1 christos 90-98 misc 33 1.1 christos 99 most time consuming tests [such as test_fuzz] 34 1.1 christos 35 1.1 christos 36 1.1 christos A recipe that just runs a test executable 37 1.1 christos ========================================= 38 1.1 christos 39 1.1 christos A script that just runs a program looks like this: 40 1.1 christos 41 1.1 christos #! /usr/bin/perl 42 1.1 christos 43 1.1 christos use OpenSSL::Test::Simple; 44 1.1 christos 45 1.1 christos simple_test("test_{name}", "{name}test", "{name}"); 46 1.1 christos 47 1.1 christos {name} is the unique name you have chosen for your test. 48 1.1 christos 49 1.1 christos The second argument to `simple_test' is the test executable, and `simple_test' 50 1.1 christos expects it to be located in test/ 51 1.1 christos 52 1.1 christos For documentation on OpenSSL::Test::Simple, do 53 1.1 christos `perldoc util/perl/OpenSSL/Test/Simple.pm'. 54 1.1 christos 55 1.1 christos 56 1.1 christos A recipe that runs a more complex test 57 1.1 christos ====================================== 58 1.1 christos 59 1.1 christos For more complex tests, you will need to read up on Test::More and 60 1.1 christos OpenSSL::Test. Test::More is normally preinstalled, do `man Test::More' for 61 1.1 christos documentation. For OpenSSL::Test, do `perldoc util/perl/OpenSSL/Test.pm'. 62 1.1 christos 63 1.1 christos A script to start from could be this: 64 1.1 christos 65 1.1 christos #! /usr/bin/perl 66 1.1 christos 67 1.1 christos use strict; 68 1.1 christos use warnings; 69 1.1 christos use OpenSSL::Test; 70 1.1 christos 71 1.1 christos setup("test_{name}"); 72 1.1 christos 73 1.1 christos plan tests => 2; # The number of tests being performed 74 1.1 christos 75 1.1 christos ok(test1, "test1"); 76 1.1 christos ok(test2, "test1"); 77 1.1 christos 78 1.1 christos sub test1 79 1.1 christos { 80 1.1 christos # test feature 1 81 1.1 christos } 82 1.1 christos 83 1.1 christos sub test2 84 1.1 christos { 85 1.1 christos # test feature 2 86 1.1 christos } 87 1.1 christos 88 1.1 christos 89 1.1 christos Changes to test/build.info 90 1.1 christos ========================== 91 1.1 christos 92 1.1 christos Whenever a new test involves a new test executable you need to do the 93 1.1 christos following (at all times, replace {NAME} and {name} with the name of your 94 1.1 christos test): 95 1.1 christos 96 1.1 christos * add {name} to the list of programs under PROGRAMS_NO_INST 97 1.1 christos 98 1.1 christos * create a three line description of how to build the test, you will have 99 1.1 christos to modify the include paths and source files if you don't want to use the 100 1.1 christos basic test framework: 101 1.1 christos 102 1.1 christos SOURCE[{name}]={name}.c 103 1.1 christos INCLUDE[{name}]=.. ../include 104 1.1 christos DEPEND[{name}]=../libcrypto libtestutil.a 105 1.1 christos 106 1.1 christos Generic form of C test executables 107 1.1 christos ================================== 108 1.1 christos 109 1.1 christos #include "testutil.h" 110 1.1 christos 111 1.1 christos static int my_test(void) 112 1.1 christos { 113 1.1 christos int testresult = 0; /* Assume the test will fail */ 114 1.1 christos int observed; 115 1.1 christos 116 1.1 christos observed = function(); /* Call the code under test */ 117 1.1 christos if (!TEST_int_eq(observed, 2)) /* Check the result is correct */ 118 1.1 christos goto end; /* Exit on failure - optional */ 119 1.1 christos 120 1.1 christos testresult = 1; /* Mark the test case a success */ 121 1.1 christos end: 122 1.1 christos cleanup(); /* Any cleanup you require */ 123 1.1 christos return testresult; 124 1.1 christos } 125 1.1 christos 126 1.1 christos int setup_tests(void) 127 1.1 christos { 128 1.1 christos ADD_TEST(my_test); /* Add each test separately */ 129 1.1 christos return 1; /* Indicate success */ 130 1.1 christos } 131 1.1 christos 132 1.1 christos You should use the TEST_xxx macros provided by testutil.h to test all failure 133 1.1 christos conditions. These macros produce an error message in a standard format if the 134 1.1 christos condition is not met (and nothing if the condition is met). Additional 135 1.1 christos information can be presented with the TEST_info macro that takes a printf 136 1.1 christos format string and arguments. TEST_error is useful for complicated conditions, 137 1.1 christos it also takes a printf format string and argument. In all cases the TEST_xxx 138 1.1 christos macros are guaranteed to evaluate their arguments exactly once. This means 139 1.1 christos that expressions with side effects are allowed as parameters. Thus, 140 1.1 christos 141 1.1 christos if (!TEST_ptr(ptr = OPENSSL_malloc(..))) 142 1.1 christos 143 1.1 christos works fine and can be used in place of: 144 1.1 christos 145 1.1 christos ptr = OPENSSL_malloc(..); 146 1.1 christos if (!TEST_ptr(ptr)) 147 1.1 christos 148 1.1 christos The former produces a more meaningful message on failure than the latter. 149 1.1 christos 150