Blame test/README

Packit c4476c
How to add recipes
Packit c4476c
==================
Packit c4476c
Packit c4476c
For any test that you want to perform, you write a script located in
Packit c4476c
test/recipes/, named {nn}-test_{name}.t, where {nn} is a two digit number and
Packit c4476c
{name} is a unique name of your choice.
Packit c4476c
Packit c4476c
Please note that if a test involves a new testing executable, you will need to
Packit c4476c
do some additions in test/Makefile.  More on this later.
Packit c4476c
Packit c4476c
Packit c4476c
Naming conventions
Packit c4476c
=================
Packit c4476c
Packit c4476c
A test executable is named test/{name}test.c
Packit c4476c
Packit c4476c
A test recipe is named test/recipes/{nn}-test_{name}.t, where {nn} is a two
Packit c4476c
digit number and {name} is a unique name of your choice.
Packit c4476c
Packit c4476c
The number {nn} is (somewhat loosely) grouped as follows:
Packit c4476c
Packit c4476c
00-04  sanity, internal and essential API tests
Packit c4476c
05-09  individual symmetric cipher algorithms
Packit c4476c
10-14  math (bignum)
Packit c4476c
15-19  individual asymmetric cipher algorithms
Packit c4476c
20-24  openssl commands (some otherwise not tested)
Packit c4476c
25-29  certificate forms, generation and verification
Packit c4476c
30-35  engine and evp
Packit c4476c
60-79  APIs
Packit c4476c
   70  PACKET layer
Packit c4476c
80-89  "larger" protocols (CA, CMS, OCSP, SSL, TSA)
Packit c4476c
90-98  misc
Packit c4476c
99     most time consuming tests [such as test_fuzz]
Packit c4476c
Packit c4476c
Packit c4476c
A recipe that just runs a test executable
Packit c4476c
=========================================
Packit c4476c
Packit c4476c
A script that just runs a program looks like this:
Packit c4476c
Packit c4476c
    #! /usr/bin/perl
Packit c4476c
Packit c4476c
    use OpenSSL::Test::Simple;
Packit c4476c
Packit c4476c
    simple_test("test_{name}", "{name}test", "{name}");
Packit c4476c
Packit c4476c
{name} is the unique name you have chosen for your test.
Packit c4476c
Packit c4476c
The second argument to `simple_test' is the test executable, and `simple_test'
Packit c4476c
expects it to be located in test/
Packit c4476c
Packit c4476c
For documentation on OpenSSL::Test::Simple, do
Packit c4476c
`perldoc util/perl/OpenSSL/Test/Simple.pm'.
Packit c4476c
Packit c4476c
Packit c4476c
A recipe that runs a more complex test
Packit c4476c
======================================
Packit c4476c
Packit c4476c
For more complex tests, you will need to read up on Test::More and
Packit c4476c
OpenSSL::Test.  Test::More is normally preinstalled, do `man Test::More' for
Packit c4476c
documentation.  For OpenSSL::Test, do `perldoc util/perl/OpenSSL/Test.pm'.
Packit c4476c
Packit c4476c
A script to start from could be this:
Packit c4476c
Packit c4476c
    #! /usr/bin/perl
Packit c4476c
Packit c4476c
    use strict;
Packit c4476c
    use warnings;
Packit c4476c
    use OpenSSL::Test;
Packit c4476c
Packit c4476c
    setup("test_{name}");
Packit c4476c
Packit c4476c
    plan tests => 2;                # The number of tests being performed
Packit c4476c
Packit c4476c
    ok(test1, "test1");
Packit c4476c
    ok(test2, "test1");
Packit c4476c
Packit c4476c
    sub test1
Packit c4476c
    {
Packit c4476c
        # test feature 1
Packit c4476c
    }
Packit c4476c
Packit c4476c
    sub test2
Packit c4476c
    {
Packit c4476c
        # test feature 2
Packit c4476c
    }
Packit c4476c
Packit c4476c
Packit c4476c
Changes to test/build.info
Packit c4476c
==========================
Packit c4476c
Packit c4476c
Whenever a new test involves a new test executable you need to do the
Packit c4476c
following (at all times, replace {NAME} and {name} with the name of your
Packit c4476c
test):
Packit c4476c
Packit c4476c
* add {name} to the list of programs under PROGRAMS_NO_INST
Packit c4476c
Packit c4476c
* create a three line description of how to build the test, you will have
Packit c4476c
to modify the include paths and source files if you don't want to use the
Packit c4476c
basic test framework:
Packit c4476c
Packit c4476c
    SOURCE[{name}]={name}.c
Packit c4476c
    INCLUDE[{name}]=.. ../include
Packit c4476c
    DEPEND[{name}]=../libcrypto libtestutil.a
Packit c4476c
Packit c4476c
Generic form of C test executables
Packit c4476c
==================================
Packit c4476c
Packit c4476c
    #include "testutil.h"
Packit c4476c
Packit c4476c
    static int my_test(void)
Packit c4476c
    {
Packit c4476c
        int testresult = 0;                 /* Assume the test will fail    */
Packit c4476c
        int observed;
Packit c4476c
Packit c4476c
        observed = function();              /* Call the code under test     */
Packit c4476c
        if (!TEST_int_eq(observed, 2))      /* Check the result is correct  */
Packit c4476c
            goto end;                       /* Exit on failure - optional   */
Packit c4476c
Packit c4476c
        testresult = 1;                     /* Mark the test case a success */
Packit c4476c
    end:
Packit c4476c
        cleanup();                          /* Any cleanup you require      */
Packit c4476c
        return testresult;
Packit c4476c
    }
Packit c4476c
Packit c4476c
    int setup_tests(void)
Packit c4476c
    {
Packit c4476c
        ADD_TEST(my_test);                  /* Add each test separately     */
Packit c4476c
        return 1;                           /* Indicate success             */
Packit c4476c
    }
Packit c4476c
Packit c4476c
You should use the TEST_xxx macros provided by testutil.h to test all failure
Packit c4476c
conditions.  These macros produce an error message in a standard format if the
Packit c4476c
condition is not met (and nothing if the condition is met).  Additional
Packit c4476c
information can be presented with the TEST_info macro that takes a printf
Packit c4476c
format string and arguments.  TEST_error is useful for complicated conditions,
Packit c4476c
it also takes a printf format string and argument.  In all cases the TEST_xxx
Packit c4476c
macros are guaranteed to evaluate their arguments exactly once.  This means
Packit c4476c
that expressions with side effects are allowed as parameters.  Thus,
Packit c4476c
Packit c4476c
    if (!TEST_ptr(ptr = OPENSSL_malloc(..)))
Packit c4476c
Packit c4476c
works fine and can be used in place of:
Packit c4476c
Packit c4476c
    ptr = OPENSSL_malloc(..);
Packit c4476c
    if (!TEST_ptr(ptr))
Packit c4476c
Packit c4476c
The former produces a more meaningful message on failure than the latter.
Packit c4476c