README 4.5 KB

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