<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.openssl.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Mbland</id>
	<title>OpenSSLWiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.openssl.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Mbland"/>
	<link rel="alternate" type="text/html" href="https://wiki.openssl.org/index.php/Special:Contributions/Mbland"/>
	<updated>2026-05-12T22:15:02Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.35.13</generator>
	<entry>
		<id>https://wiki.openssl.org/index.php?title=How_To_Write_Unit_Tests_For_OpenSSL&amp;diff=2610</id>
		<title>How To Write Unit Tests For OpenSSL</title>
		<link rel="alternate" type="text/html" href="https://wiki.openssl.org/index.php?title=How_To_Write_Unit_Tests_For_OpenSSL&amp;diff=2610"/>
		<updated>2017-08-10T11:03:07Z</updated>

		<summary type="html">&lt;p&gt;Mbland: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This is an outline of the basic process and principles to follow when writing unit tests. This document will evolve quite a bit as the community gains experience.&lt;br /&gt;
&lt;br /&gt;
==Mechanics ==&lt;br /&gt;
&lt;br /&gt;
=== Check out the Tools and Tips page ===&lt;br /&gt;
[[Testing and Development Tools and Tips]] has information on tools that may make navigating and building the code a bit easier.&lt;br /&gt;
&lt;br /&gt;
Create a new test file in the same directory as the code under test using this template:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
 * TODO: Add Description&lt;br /&gt;
 *&lt;br /&gt;
 * Author:  $(git config --get user.name) ($(git config --get user.email))&lt;br /&gt;
 * Date:    $(date +%Y-%m-%d)&lt;br /&gt;
 *&lt;br /&gt;
 * ====================================================================&lt;br /&gt;
 * Copyright (c) $(date +%Y) The OpenSSL Project.  All rights reserved.&lt;br /&gt;
 * &lt;br /&gt;
 * Redistribution and use in source and binary forms, with or without&lt;br /&gt;
 * modification, are permitted provided that the following conditions&lt;br /&gt;
 * are met:&lt;br /&gt;
 * &lt;br /&gt;
 * 1. Redistributions of source code must retain the above copyright&lt;br /&gt;
 *    notice, this list of conditions and the following disclaimer.&lt;br /&gt;
 * &lt;br /&gt;
 * 2. Redistributions in binary form must reproduce the above copyright&lt;br /&gt;
 *    notice, this list of conditions and the following disclaimer in&lt;br /&gt;
 *    the documentation and/or other materials provided with the&lt;br /&gt;
 *    distribution.&lt;br /&gt;
 * &lt;br /&gt;
 * 3. All advertising materials mentioning features or use of this&lt;br /&gt;
 *    software must display the following acknowledgment:&lt;br /&gt;
 *    &amp;quot;This product includes software developed by the OpenSSL Project&lt;br /&gt;
 *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)&amp;quot;&lt;br /&gt;
 * &lt;br /&gt;
 * 4. The names &amp;quot;OpenSSL Toolkit&amp;quot; and &amp;quot;OpenSSL Project&amp;quot; must not be used to&lt;br /&gt;
 *    endorse or promote products derived from this software without&lt;br /&gt;
 *    prior written permission. For written permission, please contact&lt;br /&gt;
 *    licensing@OpenSSL.org.&lt;br /&gt;
 * &lt;br /&gt;
 * 5. Products derived from this software may not be called &amp;quot;OpenSSL&amp;quot;&lt;br /&gt;
 *    nor may &amp;quot;OpenSSL&amp;quot; appear in their names without prior written&lt;br /&gt;
 *    permission of the OpenSSL Project.&lt;br /&gt;
 * &lt;br /&gt;
 * 6. Redistributions of any form whatsoever must retain the following&lt;br /&gt;
 *    acknowledgment:&lt;br /&gt;
 *    &amp;quot;This product includes software developed by the OpenSSL Project&lt;br /&gt;
 *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)&amp;quot;&lt;br /&gt;
 * &lt;br /&gt;
 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY&lt;br /&gt;
 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE&lt;br /&gt;
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR&lt;br /&gt;
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR&lt;br /&gt;
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,&lt;br /&gt;
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT&lt;br /&gt;
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;&lt;br /&gt;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)&lt;br /&gt;
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,&lt;br /&gt;
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)&lt;br /&gt;
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED&lt;br /&gt;
 * OF THE POSSIBILITY OF SUCH DAMAGE.&lt;br /&gt;
 * ====================================================================&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
#define OPENSSL_UNIT_TEST&lt;br /&gt;
&lt;br /&gt;
/* #include header for interface under test */&lt;br /&gt;
&lt;br /&gt;
#include &amp;quot;testutil.h&amp;quot;&lt;br /&gt;
#include &amp;lt;ctype.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
#include &amp;lt;string.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#if !defined(OPENSSL_NO_UNIT_TEST)&lt;br /&gt;
&lt;br /&gt;
/* Add test code as per&lt;br /&gt;
 * http://wiki.openssl.org/index.php/How_To_Write_Unit_Tests_For_OpenSSL#Style&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
typedef struct test_fixture&lt;br /&gt;
	{&lt;br /&gt;
	const char* test_case_name;&lt;br /&gt;
	} TEST_FIXTURE;&lt;br /&gt;
&lt;br /&gt;
static TEST_FIXTURE set_up(const char* const test_case_name)&lt;br /&gt;
	{&lt;br /&gt;
	TEST_FIXTURE fixture;&lt;br /&gt;
	int setup_ok = 1;&lt;br /&gt;
	memset(&amp;amp;fixture, 0, sizeof(fixture));&lt;br /&gt;
	fixture.test_case_name = test_case_name;&lt;br /&gt;
&lt;br /&gt;
	/* Allocate memory owned by the fixture, exit on error */&lt;br /&gt;
&lt;br /&gt;
	if (!setup_ok)&lt;br /&gt;
		{&lt;br /&gt;
		ERR_print_errors_fp(stderr);&lt;br /&gt;
		exit(EXIT_FAILURE);&lt;br /&gt;
		}&lt;br /&gt;
	return fixture;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
static void tear_down(TEST_FIXTURE fixture)&lt;br /&gt;
	{&lt;br /&gt;
	ERR_print_errors_fp(stderr);&lt;br /&gt;
	/* Free any memory owned by the fixture, etc. */&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
static int execute(TEST_FIXTURE fixture)&lt;br /&gt;
	{&lt;br /&gt;
	int result = 0;&lt;br /&gt;
	/* Execute the code under test, make assertions, format and print errors,&lt;br /&gt;
 	 * return zero on success and one on error */&lt;br /&gt;
	if (result != 0)&lt;br /&gt;
		{&lt;br /&gt;
		printf(&amp;quot;** %s failed **\n--------\n&amp;quot;, fixture.test_case_name);&lt;br /&gt;
		}&lt;br /&gt;
	return result;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
static int test_REPLACE_ME_WITH_A_MEANINGFUL_NAME()&lt;br /&gt;
	{&lt;br /&gt;
	SETUP_TEST_FIXTURE(TEST_FIXTURE, set_up);&lt;br /&gt;
	/* Do test case-specific set up; set expected return values and&lt;br /&gt;
 	 * side effects */&lt;br /&gt;
	EXECUTE_TEST(execute, tear_down);&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
int main(int argc, char *argv[])&lt;br /&gt;
	{&lt;br /&gt;
	int result = 0;&lt;br /&gt;
&lt;br /&gt;
	SSL_library_init();&lt;br /&gt;
	SSL_load_error_strings();&lt;br /&gt;
&lt;br /&gt;
	ADD_TEST(test_REPLACE_ME_WITH_A_MEANINGFUL_NAME);&lt;br /&gt;
&lt;br /&gt;
	result = run_tests(argv[0]);&lt;br /&gt;
	ERR_print_errors_fp(stderr);&lt;br /&gt;
	return result;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
#else /* OPENSSL_NO_UNIT_TEST*/&lt;br /&gt;
&lt;br /&gt;
int main(int argc, char *argv[])&lt;br /&gt;
	{&lt;br /&gt;
	return EXIT_SUCCESS;&lt;br /&gt;
	}&lt;br /&gt;
#endif /* OPENSSL_NO_UNIT_TEST */&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Add Makefile Targets ===&lt;br /&gt;
The following instructions use the &amp;lt;code&amp;gt;Makefile&amp;lt;/code&amp;gt; targets for &amp;lt;code&amp;gt;ssl/heartbeat_test.c&amp;lt;/code&amp;gt; as an example.&lt;br /&gt;
&lt;br /&gt;
In the &amp;lt;code&amp;gt;Makefile&amp;lt;/code&amp;gt; for the library containing the test, add the test source file to the &amp;lt;code&amp;gt;TEST&amp;lt;/code&amp;gt; variable:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# ssl/Makefile&lt;br /&gt;
TEST=ssltest.c heartbeat_test.c&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In &amp;lt;code&amp;gt;test/Makefile&amp;lt;/code&amp;gt;:&lt;br /&gt;
* add a variable for the test target near the top of the file, right after the existing test variables&lt;br /&gt;
* use the variable to add an executable target to the &amp;lt;code&amp;gt;EXE&amp;lt;/code&amp;gt; variable&lt;br /&gt;
* use the variable to add an object file target to the &amp;lt;code&amp;gt;OBJ&amp;lt;/code&amp;gt; variable&lt;br /&gt;
* use the variable to add a source file target to the &amp;lt;code&amp;gt;SRC&amp;lt;/code&amp;gt; variable&lt;br /&gt;
* add the test target to the &amp;lt;code&amp;gt;alltests&amp;lt;/code&amp;gt; target&lt;br /&gt;
* add the target to execute the test&lt;br /&gt;
* add the target to build the test executable&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# test/Makefile&lt;br /&gt;
HEARTBEATTEST=  heartbeat_test&lt;br /&gt;
EXE=  ... $(HEARTBEATTEST)$(EXE_EXT)&lt;br /&gt;
OBJ= ... $(HEARTBEATTEST).o&lt;br /&gt;
SRC= ... $(HEARTBEATTEST).c&lt;br /&gt;
alltests: \&lt;br /&gt;
        ... test_heartbeat&lt;br /&gt;
&lt;br /&gt;
test_heartbeat: $(HEARTBEATTEST)$(EXE_EXT)&lt;br /&gt;
  ../util/shlib_wrap.sh ./$(HEARTBEATTEST)&lt;br /&gt;
&lt;br /&gt;
$(HEARTBEATTEST)$(EXE_EXT): $(HEARTBEATTEST).o $(DLIBCRYPTO) testutil.o&lt;br /&gt;
  @target=$(HEARTBEATTEST) testutil=testutil.o; $(BUILD_CMD)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Run &amp;lt;code&amp;gt;make links &amp;amp;&amp;amp; make depend&amp;lt;/code&amp;gt; ===&lt;br /&gt;
Finally, run &amp;lt;code&amp;gt;make links &amp;amp;&amp;amp; make depend&amp;lt;/code&amp;gt; to link the new test into the &amp;lt;code&amp;gt;test/&amp;lt;/code&amp;gt; directory and automatically generate the header file dependencies.&lt;br /&gt;
&lt;br /&gt;
=== Building and Running the Test ===&lt;br /&gt;
If you're initially developing on Mac OS X or (for now) FreeBSD 10, just use the stock method of building and testing:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ ./config enable-unit-test &amp;amp;&amp;amp; make &amp;amp;&amp;amp; make test&lt;br /&gt;
&lt;br /&gt;
# To execute just one specific test, where &amp;lt;test&amp;gt; is the basename of the test file:&lt;br /&gt;
$ make TESTS=&amp;lt;test&amp;gt; test &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Ultimately the test will have to compile and pass with developer flags enabled:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ ./GitConfigure debug-ben-debug-64-clang enable-unit-test&lt;br /&gt;
$ ./GitMake -j 2&lt;br /&gt;
$ ./GitMake test_heartbeat&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above currently doesn't work on Mac OS X or FreeBSD &amp;gt; 9.1. The [https://github.com/openssl/openssl/commit/a3984ff8a2e84132f221557bc26415314daf3259 {,darwin64-}debug-test-64-clang Configure targets] commit, which should go in soon as part of [https://github.com/openssl/openssl/pull/145 pull request #145], should solve the issues. Other commits from #145 contain other OS X-specific fixes.&lt;br /&gt;
&lt;br /&gt;
=== Keep your repo up-to-date ===&lt;br /&gt;
Periodically run the following to keep your branch up-to-date:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ git fetch upstream master&lt;br /&gt;
$ git rebase upstream/master&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This will pull all the updates from the master OpenSSL repository into your repository, then update your branch to apply your changes on top of the latest updates.&lt;br /&gt;
&lt;br /&gt;
=== Send a pull request ===&lt;br /&gt;
When your test is ready, send a [https://help.github.com/articles/using-pull-requests GitHub pull request]. We'll review the code, and when it's ready, it'll get merged into the repository.&lt;br /&gt;
&lt;br /&gt;
== Style ==&lt;br /&gt;
[http://mike-bland.com/2014/06/05/pseudo-xunit-pattern.html The Pseudo-xUnit Pattern] pattern organizes code in a fashion reminiscent of the [http://en.wikipedia.org/wiki/XUnit xUnit] family of unit testing frameworks, without actually using a testing framework. This should lower the barrier to entry for people wanting to write unit tests, but enable a relatively easy migration to an xUnit-based framework if we decide to do so one day.&lt;br /&gt;
&lt;br /&gt;
Some of the basic principles to follow are:&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;code&amp;gt;#include&amp;lt;/code&amp;gt; the header for the code under test first ===&lt;br /&gt;
Having the header file for the code under test appear as the first &amp;lt;code&amp;gt;#include&amp;lt;/code&amp;gt; directive ensures that that file is self-contained, i.e. it includes every header file it depends on, rather than relying on client code to include its dependencies.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;code&amp;gt;#include &amp;quot;testutil.h&amp;quot;&amp;lt;/code&amp;gt; should come second ===&lt;br /&gt;
&amp;lt;code&amp;gt;test/testutil.h&amp;lt;/code&amp;gt; contains the helper macros used in writing OpenSSL tests. Since the tests will be linked into &amp;lt;code&amp;gt;test/&amp;lt;/code&amp;gt; by the [[#Run_make_links_.26.26_make_depend|make links]] step, and built in the &amp;lt;code&amp;gt;test/&amp;lt;/code&amp;gt; directory, the &amp;quot;testutil.h&amp;quot; file will appear to be in the same directory as the test file.&lt;br /&gt;
&lt;br /&gt;
=== Define a fixture structure ===&lt;br /&gt;
The fixture structure should contain all of the inputs to the code under test and all of the expected result values. It should also contain a &amp;lt;code&amp;gt;const char*&amp;lt;/code&amp;gt; for the name of the test case function that created it, to aid in error message formatting. Even though the fixture may contain dynamically-allocated members, the fixture itself should be copied by value to reduce the necessary degree of memory management in a small unit test program.&lt;br /&gt;
&lt;br /&gt;
=== Define set_up() and tear_down() functions for the fixture ===&lt;br /&gt;
&amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; should return a newly-initialized test fixture structure. It should take the name of the test case as an argument (i.e. &amp;lt;code&amp;gt;__func__&amp;lt;/code&amp;gt;) and assign it to the fixture. All of the fixture members should be initialized, which each test case function can then override as needed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;tear_down()&amp;lt;/code&amp;gt; should take the fixture as an argument and release any resources allocated by &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt;. It can also call any library-wide error printing routines (e.g. &amp;lt;code&amp;gt;ERR_print_errors_fp(stderr)&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
=== Use &amp;lt;code&amp;gt;SETUP_TEST_FIXTURE()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;EXECUTE_TEST()&amp;lt;/code&amp;gt; from &amp;lt;code&amp;gt;test/testutil.h&amp;lt;/code&amp;gt; ===&lt;br /&gt;
Each test case function should call &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; as its first statement, and should call &amp;lt;code&amp;gt;tear_down()&amp;lt;/code&amp;gt; just before returning. This is handled in a uniform fashion when using the &amp;lt;code&amp;gt;SETUP_TEST_FIXTURE()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;EXECUTE_TEST()&amp;lt;/code&amp;gt; helper macros from [http://git.openssl.org/gitweb/?p=openssl.git;a=blob;f=test/testutil.h test/testutil.h]. See the comments in &amp;lt;code&amp;gt;test/testutil.h&amp;lt;/code&amp;gt; for usage.&lt;br /&gt;
&lt;br /&gt;
=== Use test case functions, not a table of fixtures ===&lt;br /&gt;
Individual test case functions that call a common execution function are much more readable and maintainable than a loop over a table of fixture structures. Explicit fixture variable assignments aid comprehension when reading a specific test case, which saves time and energy when trying to understand a test or diagnose a failure. When a new member is added to an existing fixture, &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; can set a default for all test cases, and only the test cases that rely on that new member need to be updated.&lt;br /&gt;
&lt;br /&gt;
=== Use very descriptive test case names ===&lt;br /&gt;
Give tests long, descriptive names that provide ample context for the details of the test case. Good test names are also help produce good error messages.&lt;br /&gt;
&lt;br /&gt;
=== Group test cases into &amp;quot;suites&amp;quot; by naming convention ===&lt;br /&gt;
Give logically-related test functions the same prefix. If need be, you can define suite-specific &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; functions that call the common &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; and elaborate on it. (This generally shouldn't be necessary for &amp;lt;code&amp;gt;tear_down()&amp;lt;/code&amp;gt;.)&lt;br /&gt;
&lt;br /&gt;
=== Keep individual test case functions focused on one thing ===&lt;br /&gt;
If the test name contains the word &amp;quot;and&amp;quot;, consider breaking it into two or more separate test case functions.&lt;br /&gt;
&lt;br /&gt;
=== Write very descriptive error messages ===&lt;br /&gt;
Include the test case function name in each error message, and explain in detail the context for the assertion that failed. Include the expected result (contained in the fixture structure) and the actual result returned from the code under test. Write helper methods for complex values as needed.&lt;br /&gt;
&lt;br /&gt;
=== Return zero on success and one on failure ===&lt;br /&gt;
The return value will be used to tally the number of test cases that failed. Even if multiple assertions fail for a single test case, the result should be exactly one.&lt;br /&gt;
&lt;br /&gt;
=== Register each test case using ADD_TEST() and execute using run_tests() ===&lt;br /&gt;
Whatever function is used as the test runner, be that &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt; or a separate function called by &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt;, add your test case functions to that function using &amp;lt;code&amp;gt;ADD_TEST()&amp;lt;/code&amp;gt; and execute them using &amp;lt;code&amp;gt;run_tests()&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;run_tests()&amp;lt;/code&amp;gt; will add up the total number of failed test cases and report that number as the last error message of the test. The return value of &amp;lt;code&amp;gt;run_tests()&amp;lt;/code&amp;gt; should be the value returned from &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt;, which will be &amp;lt;code&amp;gt;EXIT_FAILURE&amp;lt;/code&amp;gt; if any test cases failed, &amp;lt;code&amp;gt;EXIT_SUCCESS&amp;lt;/code&amp;gt; otherwise.&lt;br /&gt;
&lt;br /&gt;
=== Disable for Windows (for now) ===&lt;br /&gt;
Until we solve the private-symbol problem on Windows, we will need to wrap our unit test code in the following &amp;lt;code&amp;gt;#ifdef&amp;lt;/code&amp;gt; block:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#if !defined(OPENSSL_SYS_WINDOWS)&lt;br /&gt;
&lt;br /&gt;
/* All the test code, including main() */&lt;br /&gt;
&lt;br /&gt;
int main(int argc, char *argv[])                                                &lt;br /&gt;
    {&lt;br /&gt;
        return EXIT_SUCCESS;                                                    &lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
#endif /* OPENSSL_NO_WINDOWS  */&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mbland</name></author>
	</entry>
	<entry>
		<id>https://wiki.openssl.org/index.php?title=How_To_Write_Unit_Tests_For_OpenSSL&amp;diff=1877</id>
		<title>How To Write Unit Tests For OpenSSL</title>
		<link rel="alternate" type="text/html" href="https://wiki.openssl.org/index.php?title=How_To_Write_Unit_Tests_For_OpenSSL&amp;diff=1877"/>
		<updated>2014-08-21T14:15:22Z</updated>

		<summary type="html">&lt;p&gt;Mbland: /* Use the Test Template Generator */ Revamped as &amp;quot;Create a new test file using the test template&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This is an outline of the basic process and principles to follow when writing unit tests. This document will evolve quite a bit as the community gains experience.&lt;br /&gt;
&lt;br /&gt;
==Mechanics ==&lt;br /&gt;
=== Forking the Repo ===&lt;br /&gt;
&lt;br /&gt;
For now, people contributing new unit tests for uncovered code (as opposed to submitting tests with new code changes) should fork [https://github.com/mbland/openssl Mike Bland's GitHub repository] and issue changes via [https://help.github.com/articles/using-pull-requests GitHub pull requests] to this repo. &lt;br /&gt;
&lt;br /&gt;
Remember to do all development on a topic branch (not &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt;). Tests committed to this repo will occasionally get merged into the master OpenSSL repo.&lt;br /&gt;
&lt;br /&gt;
Be sure to set up the [https://github.com/openssl/openssl OpenSSL master repository] as your upstream remote as per [https://help.github.com/articles/fork-a-repo#step-3-configure-remotes GitHub's instructions on configuring remotes], and pull in upstream changes frequently. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ cd my-openssl-repo&lt;br /&gt;
$ git remote add upstream https://github.com/openssl/openssl.git&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You should see the following output from &amp;lt;code&amp;gt;git remove -v&amp;lt;/code&amp;gt; (where &amp;lt;code&amp;gt;$USER&amp;lt;/code&amp;gt; is your GitHub username):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ git remote -v&lt;br /&gt;
origin  https://github.com/$USER/openssl.git (fetch)&lt;br /&gt;
origin  https://github.com/$USER/openssl.git (push)&lt;br /&gt;
upstream        https://github.com/openssl/openssl.git (fetch)&lt;br /&gt;
upstream        https://github.com/openssl/openssl.git (push)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Rationale per Matt Caswell: We should think about process here. If you are going off to recruit an army of people writing tests then I wonder if it is worth setting up a separate github repository whilst you are building up the tests. We can then merge in from that on a periodic basis. I wouldn't want availability of openssl team committers to be a bottle neck.&lt;br /&gt;
&lt;br /&gt;
=== Check out the Tools and Tips page ===&lt;br /&gt;
[[Testing and Development Tools and Tips]] has information on tools that may make navigating and building the code a bit easier.&lt;br /&gt;
&lt;br /&gt;
=== Create a new test file using the test template ===&lt;br /&gt;
TODO(mbland): Get &amp;lt;code&amp;gt;test/new-test.sh&amp;lt;/code&amp;gt; test template generator checked-in ([https://github.com/mbland/openssl/compare/test-util pending in the test-util branch]). Maybe have a template generator for each library, e.g. &amp;lt;code&amp;gt;ssl/new-test.sh&amp;lt;/code&amp;gt; that has additional setup boilerplate specific to the &amp;lt;code&amp;gt;ssl&amp;lt;/code&amp;gt; library.&lt;br /&gt;
&lt;br /&gt;
Create a new test file in the same directory as the code under test using this template; see [http://git.openssl.org/gitweb/?p=openssl.git;a=blob;f=ssl/heartbeat_test.c ssl/heartbeat_test.c] for a full example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
 * TODO: Add Description&lt;br /&gt;
 *&lt;br /&gt;
 * Author:  $(git config --get user.name) ($(git config --get user.email))&lt;br /&gt;
 * Date:    $(date +%Y-%m-%d)&lt;br /&gt;
 *&lt;br /&gt;
 * ====================================================================&lt;br /&gt;
 * Copyright (c) $(date +%Y) The OpenSSL Project.  All rights reserved.&lt;br /&gt;
 * &lt;br /&gt;
 * Redistribution and use in source and binary forms, with or without&lt;br /&gt;
 * modification, are permitted provided that the following conditions&lt;br /&gt;
 * are met:&lt;br /&gt;
 * &lt;br /&gt;
 * 1. Redistributions of source code must retain the above copyright&lt;br /&gt;
 *    notice, this list of conditions and the following disclaimer.&lt;br /&gt;
 * &lt;br /&gt;
 * 2. Redistributions in binary form must reproduce the above copyright&lt;br /&gt;
 *    notice, this list of conditions and the following disclaimer in&lt;br /&gt;
 *    the documentation and/or other materials provided with the&lt;br /&gt;
 *    distribution.&lt;br /&gt;
 * &lt;br /&gt;
 * 3. All advertising materials mentioning features or use of this&lt;br /&gt;
 *    software must display the following acknowledgment:&lt;br /&gt;
 *    &amp;quot;This product includes software developed by the OpenSSL Project&lt;br /&gt;
 *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)&amp;quot;&lt;br /&gt;
 * &lt;br /&gt;
 * 4. The names &amp;quot;OpenSSL Toolkit&amp;quot; and &amp;quot;OpenSSL Project&amp;quot; must not be used to&lt;br /&gt;
 *    endorse or promote products derived from this software without&lt;br /&gt;
 *    prior written permission. For written permission, please contact&lt;br /&gt;
 *    licensing@OpenSSL.org.&lt;br /&gt;
 * &lt;br /&gt;
 * 5. Products derived from this software may not be called &amp;quot;OpenSSL&amp;quot;&lt;br /&gt;
 *    nor may &amp;quot;OpenSSL&amp;quot; appear in their names without prior written&lt;br /&gt;
 *    permission of the OpenSSL Project.&lt;br /&gt;
 * &lt;br /&gt;
 * 6. Redistributions of any form whatsoever must retain the following&lt;br /&gt;
 *    acknowledgment:&lt;br /&gt;
 *    &amp;quot;This product includes software developed by the OpenSSL Project&lt;br /&gt;
 *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)&amp;quot;&lt;br /&gt;
 * &lt;br /&gt;
 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY&lt;br /&gt;
 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE&lt;br /&gt;
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR&lt;br /&gt;
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR&lt;br /&gt;
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,&lt;br /&gt;
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT&lt;br /&gt;
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;&lt;br /&gt;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)&lt;br /&gt;
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,&lt;br /&gt;
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)&lt;br /&gt;
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED&lt;br /&gt;
 * OF THE POSSIBILITY OF SUCH DAMAGE.&lt;br /&gt;
 * ====================================================================&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
#define OPENSSL_UNIT_TEST&lt;br /&gt;
&lt;br /&gt;
/* #include header for interface under test */&lt;br /&gt;
&lt;br /&gt;
#include &amp;quot;testutil.h&amp;quot;&lt;br /&gt;
#include &amp;lt;ctype.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
#include &amp;lt;string.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#if !defined(OPENSSL_NO_UNIT_TEST)&lt;br /&gt;
&lt;br /&gt;
/* Add test code as per&lt;br /&gt;
 * http://wiki.openssl.org/index.php/How_To_Write_Unit_Tests_For_OpenSSL#Style&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
typedef struct test_fixture&lt;br /&gt;
	{&lt;br /&gt;
	const char* test_case_name;&lt;br /&gt;
	} TEST_FIXTURE;&lt;br /&gt;
&lt;br /&gt;
static TEST_FIXTURE set_up(const char* const test_case_name)&lt;br /&gt;
	{&lt;br /&gt;
	TEST_FIXTURE fixture;&lt;br /&gt;
	int setup_ok = 1;&lt;br /&gt;
	memset(&amp;amp;fixture, 0, sizeof(fixture));&lt;br /&gt;
	fixture.test_case_name = test_case_name;&lt;br /&gt;
&lt;br /&gt;
	/* Allocate memory owned by the fixture, exit on error */&lt;br /&gt;
&lt;br /&gt;
	if (!setup_ok)&lt;br /&gt;
		{&lt;br /&gt;
		ERR_print_errors_fp(stderr);&lt;br /&gt;
		exit(EXIT_FAILURE);&lt;br /&gt;
		}&lt;br /&gt;
	return fixture;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
static void tear_down(TEST_FIXTURE fixture)&lt;br /&gt;
	{&lt;br /&gt;
	ERR_print_errors_fp(stderr);&lt;br /&gt;
	/* Free any memory owned by the fixture, etc. */&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
static int execute(TEST_FIXTURE fixture)&lt;br /&gt;
	{&lt;br /&gt;
	int result = 0;&lt;br /&gt;
	/* Execute the code under test, make assertions, format and print errors,&lt;br /&gt;
 	 * return zero on success and one on error */&lt;br /&gt;
	if (result != 0)&lt;br /&gt;
		{&lt;br /&gt;
		printf(&amp;quot;** %s failed **\n--------\n&amp;quot;, fixture.test_case_name);&lt;br /&gt;
		}&lt;br /&gt;
	return result;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
static int test_REPLACE_ME_WITH_A_MEANINGFUL_NAME()&lt;br /&gt;
	{&lt;br /&gt;
	SETUP_TEST_FIXTURE(TEST_FIXTURE, set_up);&lt;br /&gt;
	/* Do test case-specific set up; set expected return values and&lt;br /&gt;
 	 * side effects */&lt;br /&gt;
	EXECUTE_TEST(execute, tear_down);&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
int main(int argc, char *argv[])&lt;br /&gt;
	{&lt;br /&gt;
	int result = 0;&lt;br /&gt;
&lt;br /&gt;
	SSL_library_init();&lt;br /&gt;
	SSL_load_error_strings();&lt;br /&gt;
&lt;br /&gt;
	ADD_TEST(test_REPLACE_ME_WITH_A_MEANINGFUL_NAME);&lt;br /&gt;
&lt;br /&gt;
	result = run_tests(argv[0]);&lt;br /&gt;
	ERR_print_errors_fp(stderr);&lt;br /&gt;
	return result;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
#else /* OPENSSL_NO_UNIT_TEST*/&lt;br /&gt;
&lt;br /&gt;
int main(int argc, char *argv[])&lt;br /&gt;
	{&lt;br /&gt;
	return EXIT_SUCCESS;&lt;br /&gt;
	}&lt;br /&gt;
#endif /* OPENSSL_NO_UNIT_TEST */&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Add Makefile Targets ===&lt;br /&gt;
The following instructions use the &amp;lt;code&amp;gt;Makefile&amp;lt;/code&amp;gt; targets for &amp;lt;code&amp;gt;ssl/heartbeat_test.c&amp;lt;/code&amp;gt; as an example.&lt;br /&gt;
&lt;br /&gt;
In the &amp;lt;code&amp;gt;Makefile&amp;lt;/code&amp;gt; for the library containing the test, add the test source file to the &amp;lt;code&amp;gt;TEST&amp;lt;/code&amp;gt; variable:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# ssl/Makefile&lt;br /&gt;
TEST=ssltest.c heartbeat_test.c&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In &amp;lt;code&amp;gt;test/Makefile&amp;lt;/code&amp;gt;:&lt;br /&gt;
* add a variable for the test target near the top of the file, right after the existing test variables&lt;br /&gt;
* use the variable to add an executable target to the &amp;lt;code&amp;gt;EXE&amp;lt;/code&amp;gt; variable&lt;br /&gt;
* use the variable to add an object file target to the &amp;lt;code&amp;gt;OBJ&amp;lt;/code&amp;gt; variable&lt;br /&gt;
* use the variable to add a source file target to the &amp;lt;code&amp;gt;SRC&amp;lt;/code&amp;gt; variable&lt;br /&gt;
* add the test target to the &amp;lt;code&amp;gt;alltests&amp;lt;/code&amp;gt; target&lt;br /&gt;
* add the target to execute the test&lt;br /&gt;
* add the target to build the test executable&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# test/Makefile&lt;br /&gt;
HEARTBEATTEST=  heartbeat_test&lt;br /&gt;
EXE=  ... $(HEARTBEATTEST)$(EXE_EXT)&lt;br /&gt;
OBJ= ... $(HEARTBEATTEST).o&lt;br /&gt;
SRC= ... $(HEARTBEATTEST).c&lt;br /&gt;
alltests: \&lt;br /&gt;
        ... test_heartbeat&lt;br /&gt;
&lt;br /&gt;
test_heartbeat: $(HEARTBEATTEST)$(EXE_EXT)&lt;br /&gt;
  ../util/shlib_wrap.sh ./$(HEARTBEATTEST)&lt;br /&gt;
&lt;br /&gt;
$(HEARTBEATTEST)$(EXE_EXT): $(HEARTBEATTEST).o $(DLIBCRYPTO) testutil.o&lt;br /&gt;
  @target=$(HEARTBEATTEST) testutil=testutil.o; $(BUILD_CMD)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Run &amp;lt;code&amp;gt;make links &amp;amp;&amp;amp; make depend&amp;lt;/code&amp;gt; ===&lt;br /&gt;
Finally, run &amp;lt;code&amp;gt;make links &amp;amp;&amp;amp; make depend&amp;lt;/code&amp;gt; to link the new test into the &amp;lt;code&amp;gt;test/&amp;lt;/code&amp;gt; directory and automatically generate the header file dependencies.&lt;br /&gt;
&lt;br /&gt;
=== Building and Running the Test ===&lt;br /&gt;
If you're initially developing on Mac OS X or (for now) FreeBSD 10, just use the stock method of building and testing:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ ./config enable-unit-test &amp;amp;&amp;amp; make &amp;amp;&amp;amp; make test&lt;br /&gt;
&lt;br /&gt;
# To execute just one specific test&lt;br /&gt;
$ make TESTS=test_heartbeat test &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Ultimately the test will have to compile and pass with developer flags enabled:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ ./GitConfigure debug-ben-debug-64-clang enable-unit-test&lt;br /&gt;
$ ./GitMake -j 2&lt;br /&gt;
$ ./GitMake test_heartbeat&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above currently doesn't work on Mac OS X or FreeBSD &amp;gt; 9.1. The [https://github.com/mbland/openssl/commit/a3984ff8a2e84132f221557bc26415314daf3259 {,darwin64-}debug-test-64-clang Configure targets] commit, which should go in soon as part of [https://github.com/openssl/openssl/pull/145 pull request #145], should solve the issues. Other commits from #145 contain other OS X-specific fixes.&lt;br /&gt;
&lt;br /&gt;
=== Keep your repo up-to-date ===&lt;br /&gt;
Periodically run the following to keep your branch up-to-date:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ git fetch upstream master&lt;br /&gt;
$ git rebase upstream/master&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This will pull all the updates from the master OpenSSL repository into your repository, then update your branch to apply your changes on top of the latest updates.&lt;br /&gt;
&lt;br /&gt;
=== Send a pull request ===&lt;br /&gt;
When your test is ready, send a [https://help.github.com/articles/using-pull-requests GitHub pull request]. Note that the pull request should be based on the &amp;lt;code&amp;gt;tests&amp;lt;/code&amp;gt; branch of Mike's repository, not &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt;. (This should be the default; let Mike know if it doesn't appear to be!) We'll review the code, and when it's ready, it'll get merged into Mike's repository. From there, it will eventually get pulled into the master OpenSSL repository.&lt;br /&gt;
&lt;br /&gt;
== Style ==&lt;br /&gt;
[http://mike-bland.com/2014/06/05/pseudo-xunit-pattern.html The Pseudo-xUnit Pattern] is that established by [http://git.openssl.org/gitweb/?p=openssl.git;a=blob;f=ssl/heartbeat_test.c ssl/heartbeat_test.c]. This pattern organizes code in a fashion reminiscent of the [http://en.wikipedia.org/wiki/XUnit xUnit] family of unit testing frameworks, without actually using a testing framework. This should lower the barrier to entry for people wanting to write unit tests, but enable a relatively easy migration to an xUnit-based framework if we decide to do so one day.&lt;br /&gt;
&lt;br /&gt;
Some of the basic principles to follow are:&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;code&amp;gt;#include&amp;lt;/code&amp;gt; the header for the code under test first ===&lt;br /&gt;
Having the header file for the code under test appear as the first &amp;lt;code&amp;gt;#include&amp;lt;/code&amp;gt; directive ensures that that file is self-contained, i.e. it includes every header file it depends on, rather than relying on client code to include its dependencies.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;code&amp;gt;#include &amp;quot;testutil.h&amp;quot;&amp;lt;/code&amp;gt; should come second ===&lt;br /&gt;
&amp;lt;code&amp;gt;test/testutil.h&amp;lt;/code&amp;gt; contains the helper macros used in writing OpenSSL tests. Since the tests will be linked into &amp;lt;code&amp;gt;test/&amp;lt;/code&amp;gt; by the [[#Run_make_links_.26.26_make_depend|make links]] step, and built in the &amp;lt;code&amp;gt;test/&amp;lt;/code&amp;gt; directory, the &amp;quot;testutil.h&amp;quot; file will appear to be in the same directory as the test file.&lt;br /&gt;
&lt;br /&gt;
=== Define a fixture structure ===&lt;br /&gt;
The fixture structure should contain all of the inputs to the code under test and all of the expected result values. It should also contain a &amp;lt;code&amp;gt;const char*&amp;lt;/code&amp;gt; for the name of the test case function that created it, to aid in error message formatting. Even though the fixture may contain dynamically-allocated members, the fixture itself should be copied by value to reduce the necessary degree of memory management in a small unit test program.&lt;br /&gt;
&lt;br /&gt;
=== Define set_up() and tear_down() functions for the fixture ===&lt;br /&gt;
&amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; should return a newly-initialized test fixture structure. It should take the name of the test case as an argument (i.e. &amp;lt;code&amp;gt;__func__&amp;lt;/code&amp;gt;) and assign it to the fixture. All of the fixture members should be initialized, which each test case function can then override as needed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;tear_down()&amp;lt;/code&amp;gt; should take the fixture as an argument and release any resources allocated by &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt;. It can also call any library-wide error printing routines (e.g. &amp;lt;code&amp;gt;ERR_print_errors_fp(stderr)&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
=== Use &amp;lt;code&amp;gt;SETUP_TEST_FIXTURE()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;EXECUTE_TEST()&amp;lt;/code&amp;gt; from &amp;lt;code&amp;gt;test/testutil.h&amp;lt;/code&amp;gt; ===&lt;br /&gt;
Each test case function should call &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; as its first statement, and should call &amp;lt;code&amp;gt;tear_down()&amp;lt;/code&amp;gt; just before returning. This is handled in a uniform fashion when using the &amp;lt;code&amp;gt;SETUP_TEST_FIXTURE()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;EXECUTE_TEST()&amp;lt;/code&amp;gt; helper macros from [http://git.openssl.org/gitweb/?p=openssl.git;a=blob;f=test/testutil.h test/testutil.h]. See the comments in &amp;lt;code&amp;gt;test/testutil.h&amp;lt;/code&amp;gt; for usage, and &amp;lt;code&amp;gt;ssl/heartbeat_test.c&amp;lt;/code&amp;gt; for an example of how to wrap the macros for a specific unit test.&lt;br /&gt;
&lt;br /&gt;
=== Use test case functions, not a table of fixtures ===&lt;br /&gt;
Individual test case functions that call a common execution function are much more readable and maintainable than a loop over a table of fixture structures. Explicit fixture variable assignments aid comprehension when reading a specific test case, which saves time and energy when trying to understand a test or diagnose a failure. When a new member is added to an existing fixture, &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; can set a default for all test cases, and only the test cases that rely on that new member need to be updated.&lt;br /&gt;
&lt;br /&gt;
=== Use very descriptive test case names ===&lt;br /&gt;
Give tests long, descriptive names that provide ample context for the details of the test case. Good test names are also help produce good error messages.&lt;br /&gt;
&lt;br /&gt;
=== Group test cases into &amp;quot;suites&amp;quot; by naming convention ===&lt;br /&gt;
Give logically-related tests the same prefix, e.g. &amp;lt;code&amp;gt;test_dtls1_&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;test_tls1&amp;lt;/code&amp;gt; from &amp;lt;code&amp;gt;ssl/heartbeat_test.c&amp;lt;/code&amp;gt;. If need be, you can define suite-specific &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; functions that call the common &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; and elaborate on it. (This generally shouldn't be necessary for &amp;lt;code&amp;gt;tear_down()&amp;lt;/code&amp;gt;.)&lt;br /&gt;
&lt;br /&gt;
=== Keep individual test case functions focused on one thing ===&lt;br /&gt;
If the test name contains the word &amp;quot;and&amp;quot;, consider breaking it into two or more separate test case functions.&lt;br /&gt;
&lt;br /&gt;
=== Write very descriptive error messages ===&lt;br /&gt;
Include the test case function name in each error message, and explain in detail the context for the assertion that failed. Include the expected result (contained in the fixture structure) and the actual result returned from the code under test. Write helper methods for complex values as needed (e.g. &amp;lt;code&amp;gt;print_payload()&amp;lt;/code&amp;gt; in &amp;lt;code&amp;gt;ssl/heartbeat_test.c&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
=== Return zero on success and one on failure ===&lt;br /&gt;
The return value will be used to tally the number of test cases that failed. Even if multiple assertions fail for a single test case, the result should be exactly one.&lt;br /&gt;
&lt;br /&gt;
=== Register each test case using ADD_TEST() and execute using run_tests() ===&lt;br /&gt;
Whatever function is used as the test runner, be that &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt; or a separate function called by &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt;, add your test case functions to that function using &amp;lt;code&amp;gt;ADD_TEST()&amp;lt;/code&amp;gt; and execute them using &amp;lt;code&amp;gt;run_tests()&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;run_tests()&amp;lt;/code&amp;gt; will add up the total number of failed test cases and report that number as the last error message of the test. The return value of &amp;lt;code&amp;gt;run_tests()&amp;lt;/code&amp;gt; should be the value returned from &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt;, which will be &amp;lt;code&amp;gt;EXIT_FAILURE&amp;lt;/code&amp;gt; if any test cases failed, &amp;lt;code&amp;gt;EXIT_SUCCESS&amp;lt;/code&amp;gt; otherwise.&lt;br /&gt;
&lt;br /&gt;
TODO(mbland): create some kind of automated script or editor macros?&lt;br /&gt;
&lt;br /&gt;
=== Disable for Windows (for now) ===&lt;br /&gt;
Until we solve the private-symbol problem on Windows, we will need to wrap our unit test code in the following &amp;lt;code&amp;gt;#ifdef&amp;lt;/code&amp;gt; block:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#if !defined(OPENSSL_SYS_WINDOWS)&lt;br /&gt;
&lt;br /&gt;
/* All the test code, including main() */&lt;br /&gt;
&lt;br /&gt;
int main(int argc, char *argv[])                                                &lt;br /&gt;
    {&lt;br /&gt;
        return EXIT_SUCCESS;                                                    &lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
#endif /* OPENSSL_NO_WINDOWS  */&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Samples ==&lt;br /&gt;
Existing tests that can be used as models for new tests.&lt;br /&gt;
* [http://git.openssl.org/gitweb/?p=openssl.git;a=blob;f=ssl/heartbeat_test.c ssl/heartbeat_test.c]: Follows [http://mike-bland.com/2014/06/05/pseudo-xunit-pattern.html the Pseudo-xUnit pattern]&lt;/div&gt;</summary>
		<author><name>Mbland</name></author>
	</entry>
	<entry>
		<id>https://wiki.openssl.org/index.php?title=How_To_Write_Unit_Tests_For_OpenSSL&amp;diff=1858</id>
		<title>How To Write Unit Tests For OpenSSL</title>
		<link rel="alternate" type="text/html" href="https://wiki.openssl.org/index.php?title=How_To_Write_Unit_Tests_For_OpenSSL&amp;diff=1858"/>
		<updated>2014-08-02T18:28:24Z</updated>

		<summary type="html">&lt;p&gt;Mbland: /* Building and Running the Test */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This is an outline of the basic process and principles to follow when writing unit tests. This document will evolve quite a bit as the community gains experience.&lt;br /&gt;
&lt;br /&gt;
==Mechanics ==&lt;br /&gt;
=== Forking the Repo ===&lt;br /&gt;
For now, people contributing new unit tests for uncovered code (as opposed to submitting tests with new code changes) should fork [https://github.com/mbland/openssl Mike Bland's GitHub repository] and issue [https://help.github.com/articles/using-pull-requests GitHub pull requests]. Remember to do all development on a topic branch (not &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt;). Tests committed to this repo will occasionally get merged into the master OpenSSL repo.&lt;br /&gt;
&lt;br /&gt;
Rationale per Matt Caswell: We should think about process here. If you are going off to recruit an army of people writing tests then I wonder if it is worth setting up a separate github repository whilst you are building up the tests. We can then merge in from that on a periodic basis. I wouldn't want availability of openssl team committers to be a bottle neck.&lt;br /&gt;
&lt;br /&gt;
Set up the [https://github.com/openssl/openssl OpenSSL master repository] as your upstream remote as per [https://help.github.com/articles/fork-a-repo#step-3-configure-remotes GitHub's instructions on configuring remotes]:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ cd my-openssl-repo&lt;br /&gt;
$ git remote add upstream https://github.com/openssl/openssl.git&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You should see the following output from &amp;lt;code&amp;gt;git remove -v&amp;lt;/code&amp;gt; (where &amp;lt;code&amp;gt;$USER&amp;lt;/code&amp;gt; is your GitHub username):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ git remote -v&lt;br /&gt;
origin  https://github.com/$USER/openssl.git (fetch)&lt;br /&gt;
origin  https://github.com/$USER/openssl.git (push)&lt;br /&gt;
upstream        https://github.com/openssl/openssl.git (fetch)&lt;br /&gt;
upstream        https://github.com/openssl/openssl.git (push)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Check out the Tools and Tips page ===&lt;br /&gt;
[[Testing and Development Tools and Tips]] has information on tools that may make navigating and building the code a bit easier.&lt;br /&gt;
&lt;br /&gt;
=== Use the Test Template Generator ===&lt;br /&gt;
TODO(mbland): Get template generator checked-in. Maybe have a template generator for each library, e.g. &amp;lt;code&amp;gt;ssl/new-test.sh&amp;lt;/code&amp;gt; that has additional setup boilerplate specific to the &amp;lt;code&amp;gt;ssl&amp;lt;/code&amp;gt; library.&lt;br /&gt;
&lt;br /&gt;
Use the &amp;lt;code&amp;gt;test/new-test.sh&amp;lt;/code&amp;gt; script to generate a skeleton test file. ([https://github.com/mbland/openssl/compare/test-util pending in the test-util branch])&lt;br /&gt;
&lt;br /&gt;
=== Add Makefile Targets ===&lt;br /&gt;
The following instructions use the &amp;lt;code&amp;gt;Makefile&amp;lt;/code&amp;gt; targets for &amp;lt;code&amp;gt;ssl/heartbeat_test.c&amp;lt;/code&amp;gt; as an example.&lt;br /&gt;
&lt;br /&gt;
In the &amp;lt;code&amp;gt;Makefile&amp;lt;/code&amp;gt; for the library containing the test, add the test source file to the &amp;lt;code&amp;gt;TEST&amp;lt;/code&amp;gt; variable:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# ssl/Makefile&lt;br /&gt;
TEST=ssltest.c heartbeat_test.c&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In &amp;lt;code&amp;gt;test/Makefile&amp;lt;/code&amp;gt;:&lt;br /&gt;
* add a variable for the test target near the top of the file, right after the existing test variables&lt;br /&gt;
* use the variable to add an executable target to the &amp;lt;code&amp;gt;EXE&amp;lt;/code&amp;gt; variable&lt;br /&gt;
* use the variable to add an object file target to the &amp;lt;code&amp;gt;OBJ&amp;lt;/code&amp;gt; variable&lt;br /&gt;
* use the variable to add a source file target to the &amp;lt;code&amp;gt;SRC&amp;lt;/code&amp;gt; variable&lt;br /&gt;
* add the test target to the &amp;lt;code&amp;gt;alltests&amp;lt;/code&amp;gt; target&lt;br /&gt;
* add the target to execute the test&lt;br /&gt;
* add the target to build the test executable&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# test/Makefile&lt;br /&gt;
HEARTBEATTEST=  heartbeat_test&lt;br /&gt;
EXE=  ... $(HEARTBEATTEST)$(EXE_EXT)&lt;br /&gt;
OBJ= ... $(HEARTBEATTEST).o&lt;br /&gt;
SRC= ... $(HEARTBEATTEST).c&lt;br /&gt;
alltests: \&lt;br /&gt;
        ... test_heartbeat&lt;br /&gt;
&lt;br /&gt;
test_heartbeat: $(HEARTBEATTEST)$(EXE_EXT)&lt;br /&gt;
  ../util/shlib_wrap.sh ./$(HEARTBEATTEST)&lt;br /&gt;
&lt;br /&gt;
$(HEARTBEATTEST)$(EXE_EXT): $(HEARTBEATTEST).o $(DLIBCRYPTO) testutil.o&lt;br /&gt;
  @target=$(HEARTBEATTEST) testutil=testutil.o; $(BUILD_CMD)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Run &amp;lt;code&amp;gt;make links &amp;amp;&amp;amp; make depend&amp;lt;/code&amp;gt; ===&lt;br /&gt;
Finally, run &amp;lt;code&amp;gt;make links &amp;amp;&amp;amp; make depend&amp;lt;/code&amp;gt; to link the new test into the &amp;lt;code&amp;gt;test/&amp;lt;/code&amp;gt; directory and automatically generate the header file dependencies.&lt;br /&gt;
&lt;br /&gt;
=== Building and Running the Test ===&lt;br /&gt;
If you're initially developing on Mac OS X or (for now) FreeBSD 10, just use the stock method of building and testing:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ ./config enable-unit-test &amp;amp;&amp;amp; make &amp;amp;&amp;amp; make test&lt;br /&gt;
&lt;br /&gt;
# To execute just one specific test&lt;br /&gt;
$ make TESTS=test_heartbeat test &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Ultimately the test will have to compile and pass with developer flags enabled:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ ./GitConfigure debug-ben-debug-64-clang enable-unit-test&lt;br /&gt;
$ ./GitMake -j 2&lt;br /&gt;
$ ./GitMake test_heartbeat&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above currently doesn't work on Mac OS X or FreeBSD &amp;gt; 9.1. The [https://github.com/mbland/openssl/commit/a3984ff8a2e84132f221557bc26415314daf3259 {,darwin64-}debug-test-64-clang Configure targets] commit, which should go in soon as part of [https://github.com/openssl/openssl/pull/145 pull request #145], should solve the issues. Other commits from #145 contain other OS X-specific fixes.&lt;br /&gt;
&lt;br /&gt;
=== Keep your repo up-to-date ===&lt;br /&gt;
Periodically run the following to keep your branch up-to-date:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ git fetch upstream master&lt;br /&gt;
$ git rebase upstream/master&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This will pull all the updates from the master OpenSSL repository into your repository, then update your branch to apply your changes on top of the latest updates.&lt;br /&gt;
&lt;br /&gt;
=== Send a pull request ===&lt;br /&gt;
When your test is ready, send a [https://help.github.com/articles/using-pull-requests GitHub pull request]. Note that the pull request should be based on the &amp;lt;code&amp;gt;tests&amp;lt;/code&amp;gt; branch of Mike's repository, not &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt;. (This should be the default; let Mike know if it doesn't appear to be!) We'll review the code, and when it's ready, it'll get merged into Mike's repository. From there, it will eventually get pulled into the master OpenSSL repository.&lt;br /&gt;
&lt;br /&gt;
== Style ==&lt;br /&gt;
[http://mike-bland.com/2014/06/05/pseudo-xunit-pattern.html The Pseudo-xUnit Pattern] is that established by [http://git.openssl.org/gitweb/?p=openssl.git;a=blob;f=ssl/heartbeat_test.c ssl/heartbeat_test.c]. This pattern organizes code in a fashion reminiscent of the [http://en.wikipedia.org/wiki/XUnit xUnit] family of unit testing frameworks, without actually using a testing framework. This should lower the barrier to entry for people wanting to write unit tests, but enable a relatively easy migration to an xUnit-based framework if we decide to do so one day.&lt;br /&gt;
&lt;br /&gt;
Some of the basic principles to follow are:&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;code&amp;gt;#include&amp;lt;/code&amp;gt; the header for the code under test first ===&lt;br /&gt;
Having the header file for the code under test appear as the first &amp;lt;code&amp;gt;#include&amp;lt;/code&amp;gt; directive ensures that that file is self-contained, i.e. it includes every header file it depends on, rather than relying on client code to include its dependencies.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;code&amp;gt;#include &amp;quot;testutil.h&amp;quot;&amp;lt;/code&amp;gt; should come second ===&lt;br /&gt;
&amp;lt;code&amp;gt;test/testutil.h&amp;lt;/code&amp;gt; contains the helper macros used in writing OpenSSL tests. Since the tests will be linked into &amp;lt;code&amp;gt;test/&amp;lt;/code&amp;gt; by the [[#Run_make_links_.26.26_make_depend|make links]] step, and built in the &amp;lt;code&amp;gt;test/&amp;lt;/code&amp;gt; directory, the &amp;quot;testutil.h&amp;quot; file will appear to be in the same directory as the test file.&lt;br /&gt;
&lt;br /&gt;
=== Define a fixture structure ===&lt;br /&gt;
The fixture structure should contain all of the inputs to the code under test and all of the expected result values. It should also contain a &amp;lt;code&amp;gt;const char*&amp;lt;/code&amp;gt; for the name of the test case function that created it, to aid in error message formatting. Even though the fixture may contain dynamically-allocated members, the fixture itself should be copied by value to reduce the necessary degree of memory management in a small unit test program.&lt;br /&gt;
&lt;br /&gt;
=== Define set_up() and tear_down() functions for the fixture ===&lt;br /&gt;
&amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; should return a newly-initialized test fixture structure. It should take the name of the test case as an argument (i.e. &amp;lt;code&amp;gt;__func__&amp;lt;/code&amp;gt;) and assign it to the fixture. All of the fixture members should be initialized, which each test case function can then override as needed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;tear_down()&amp;lt;/code&amp;gt; should take the fixture as an argument and release any resources allocated by &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt;. It can also call any library-wide error printing routines (e.g. &amp;lt;code&amp;gt;ERR_print_errors_fp(stderr)&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
=== Use &amp;lt;code&amp;gt;SETUP_TEST_FIXTURE()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;EXECUTE_TEST()&amp;lt;/code&amp;gt; from &amp;lt;code&amp;gt;test/testutil.h&amp;lt;/code&amp;gt; ===&lt;br /&gt;
Each test case function should call &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; as its first statement, and should call &amp;lt;code&amp;gt;tear_down()&amp;lt;/code&amp;gt; just before returning. This is handled in a uniform fashion when using the &amp;lt;code&amp;gt;SETUP_TEST_FIXTURE()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;EXECUTE_TEST()&amp;lt;/code&amp;gt; helper macros from [http://git.openssl.org/gitweb/?p=openssl.git;a=blob;f=test/testutil.h test/testutil.h]. See the comments in &amp;lt;code&amp;gt;test/testutil.h&amp;lt;/code&amp;gt; for usage, and &amp;lt;code&amp;gt;ssl/heartbeat_test.c&amp;lt;/code&amp;gt; for an example of how to wrap the macros for a specific unit test.&lt;br /&gt;
&lt;br /&gt;
=== Use test case functions, not a table of fixtures ===&lt;br /&gt;
Individual test case functions that call a common execution function are much more readable and maintainable than a loop over a table of fixture structures. Explicit fixture variable assignments aid comprehension when reading a specific test case, which saves time and energy when trying to understand a test or diagnose a failure. When a new member is added to an existing fixture, &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; can set a default for all test cases, and only the test cases that rely on that new member need to be updated.&lt;br /&gt;
&lt;br /&gt;
=== Use very descriptive test case names ===&lt;br /&gt;
Give tests long, descriptive names that provide ample context for the details of the test case. Good test names are also help produce good error messages.&lt;br /&gt;
&lt;br /&gt;
=== Group test cases into &amp;quot;suites&amp;quot; by naming convention ===&lt;br /&gt;
Give logically-related tests the same prefix, e.g. &amp;lt;code&amp;gt;test_dtls1_&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;test_tls1&amp;lt;/code&amp;gt; from &amp;lt;code&amp;gt;ssl/heartbeat_test.c&amp;lt;/code&amp;gt;. If need be, you can define suite-specific &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; functions that call the common &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; and elaborate on it. (This generally shouldn't be necessary for &amp;lt;code&amp;gt;tear_down()&amp;lt;/code&amp;gt;.)&lt;br /&gt;
&lt;br /&gt;
=== Keep individual test case functions focused on one thing ===&lt;br /&gt;
If the test name contains the word &amp;quot;and&amp;quot;, consider breaking it into two or more separate test case functions.&lt;br /&gt;
&lt;br /&gt;
=== Write very descriptive error messages ===&lt;br /&gt;
Include the test case function name in each error message, and explain in detail the context for the assertion that failed. Include the expected result (contained in the fixture structure) and the actual result returned from the code under test. Write helper methods for complex values as needed (e.g. &amp;lt;code&amp;gt;print_payload()&amp;lt;/code&amp;gt; in &amp;lt;code&amp;gt;ssl/heartbeat_test.c&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
=== Return zero on success and one on failure ===&lt;br /&gt;
The return value will be used to tally the number of test cases that failed. Even if multiple assertions fail for a single test case, the result should be exactly one.&lt;br /&gt;
&lt;br /&gt;
=== Register each test case using ADD_TEST() and execute using run_tests() ===&lt;br /&gt;
Whatever function is used as the test runner, be that &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt; or a separate function called by &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt;, add your test case functions to that function using &amp;lt;code&amp;gt;ADD_TEST()&amp;lt;/code&amp;gt; and execute them using &amp;lt;code&amp;gt;run_tests()&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;run_tests()&amp;lt;/code&amp;gt; will add up the total number of failed test cases and report that number as the last error message of the test. The return value of &amp;lt;code&amp;gt;run_tests()&amp;lt;/code&amp;gt; should be the value returned from &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt;, which will be &amp;lt;code&amp;gt;EXIT_FAILURE&amp;lt;/code&amp;gt; if any test cases failed, &amp;lt;code&amp;gt;EXIT_SUCCESS&amp;lt;/code&amp;gt; otherwise.&lt;br /&gt;
&lt;br /&gt;
TODO(mbland): create some kind of automated script or editor macros?&lt;br /&gt;
&lt;br /&gt;
=== Disable for Windows (for now) ===&lt;br /&gt;
Until we solve the private-symbol problem on Windows, we will need to wrap our unit test code in the following &amp;lt;code&amp;gt;#ifdef&amp;lt;/code&amp;gt; block:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#if !defined(OPENSSL_SYS_WINDOWS)&lt;br /&gt;
&lt;br /&gt;
/* All the test code, including main() */&lt;br /&gt;
&lt;br /&gt;
int main(int argc, char *argv[])                                                &lt;br /&gt;
    {&lt;br /&gt;
        return EXIT_SUCCESS;                                                    &lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
#endif /* OPENSSL_NO_WINDOWS  */&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Samples ==&lt;br /&gt;
Existing tests that can be used as models for new tests.&lt;br /&gt;
* [http://git.openssl.org/gitweb/?p=openssl.git;a=blob;f=ssl/heartbeat_test.c ssl/heartbeat_test.c]: Follows [http://mike-bland.com/2014/06/05/pseudo-xunit-pattern.html the Pseudo-xUnit pattern]&lt;/div&gt;</summary>
		<author><name>Mbland</name></author>
	</entry>
	<entry>
		<id>https://wiki.openssl.org/index.php?title=How_To_Write_Unit_Tests_For_OpenSSL&amp;diff=1850</id>
		<title>How To Write Unit Tests For OpenSSL</title>
		<link rel="alternate" type="text/html" href="https://wiki.openssl.org/index.php?title=How_To_Write_Unit_Tests_For_OpenSSL&amp;diff=1850"/>
		<updated>2014-07-20T00:00:12Z</updated>

		<summary type="html">&lt;p&gt;Mbland: /* Style */ Combine last two sections in light of ADD_TEST() and run_tests()&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This is an outline of the basic process and principles to follow when writing unit tests. This document will evolve quite a bit as the community gains experience.&lt;br /&gt;
&lt;br /&gt;
==Mechanics ==&lt;br /&gt;
=== Forking the Repo ===&lt;br /&gt;
For now, people contributing new unit tests for uncovered code (as opposed to submitting tests with new code changes) should fork [https://github.com/mbland/openssl Mike Bland's GitHub repository] and issue [https://help.github.com/articles/using-pull-requests GitHub pull requests]. Remember to do all development on a topic branch (not &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt;). Tests committed to this repo will occasionally get merged into the master OpenSSL repo.&lt;br /&gt;
&lt;br /&gt;
Rationale per Matt Caswell: We should think about process here. If you are going off to recruit an army of people writing tests then I wonder if it is worth setting up a separate github repository whilst you are building up the tests. We can then merge in from that on a periodic basis. I wouldn't want availability of openssl team committers to be a bottle neck.&lt;br /&gt;
&lt;br /&gt;
Set up the [https://github.com/openssl/openssl OpenSSL master repository] as your upstream remote as per [https://help.github.com/articles/fork-a-repo#step-3-configure-remotes GitHub's instructions on configuring remotes]:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ cd my-openssl-repo&lt;br /&gt;
$ git remote add upstream https://github.com/openssl/openssl.git&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You should see the following output from &amp;lt;code&amp;gt;git remove -v&amp;lt;/code&amp;gt; (where &amp;lt;code&amp;gt;$USER&amp;lt;/code&amp;gt; is your GitHub username):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ git remote -v&lt;br /&gt;
origin  https://github.com/$USER/openssl.git (fetch)&lt;br /&gt;
origin  https://github.com/$USER/openssl.git (push)&lt;br /&gt;
upstream        https://github.com/openssl/openssl.git (fetch)&lt;br /&gt;
upstream        https://github.com/openssl/openssl.git (push)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Check out the Tools and Tips page ===&lt;br /&gt;
[[Testing and Development Tools and Tips]] has information on tools that may make navigating and building the code a bit easier.&lt;br /&gt;
&lt;br /&gt;
=== Use the Test Template Generator ===&lt;br /&gt;
TODO(mbland): Get template generator checked-in. Maybe have a template generator for each library, e.g. &amp;lt;code&amp;gt;ssl/new-test.sh&amp;lt;/code&amp;gt; that has additional setup boilerplate specific to the &amp;lt;code&amp;gt;ssl&amp;lt;/code&amp;gt; library.&lt;br /&gt;
&lt;br /&gt;
Use the &amp;lt;code&amp;gt;test/new-test.sh&amp;lt;/code&amp;gt; script to generate a skeleton test file. ([https://github.com/mbland/openssl/compare/test-util pending in the test-util branch])&lt;br /&gt;
&lt;br /&gt;
=== Add Makefile Targets ===&lt;br /&gt;
The following instructions use the &amp;lt;code&amp;gt;Makefile&amp;lt;/code&amp;gt; targets for &amp;lt;code&amp;gt;ssl/heartbeat_test.c&amp;lt;/code&amp;gt; as an example.&lt;br /&gt;
&lt;br /&gt;
In the &amp;lt;code&amp;gt;Makefile&amp;lt;/code&amp;gt; for the library containing the test, add the test source file to the &amp;lt;code&amp;gt;TEST&amp;lt;/code&amp;gt; variable:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# ssl/Makefile&lt;br /&gt;
TEST=ssltest.c heartbeat_test.c&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In &amp;lt;code&amp;gt;test/Makefile&amp;lt;/code&amp;gt;:&lt;br /&gt;
* add a variable for the test target near the top of the file, right after the existing test variables&lt;br /&gt;
* use the variable to add an executable target to the &amp;lt;code&amp;gt;EXE&amp;lt;/code&amp;gt; variable&lt;br /&gt;
* use the variable to add an object file target to the &amp;lt;code&amp;gt;OBJ&amp;lt;/code&amp;gt; variable&lt;br /&gt;
* use the variable to add a source file target to the &amp;lt;code&amp;gt;SRC&amp;lt;/code&amp;gt; variable&lt;br /&gt;
* add the test target to the &amp;lt;code&amp;gt;alltests&amp;lt;/code&amp;gt; target&lt;br /&gt;
* add the target to execute the test&lt;br /&gt;
* add the target to build the test executable&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# test/Makefile&lt;br /&gt;
HEARTBEATTEST=  heartbeat_test&lt;br /&gt;
EXE=  ... $(HEARTBEATTEST)$(EXE_EXT)&lt;br /&gt;
OBJ= ... $(HEARTBEATTEST).o&lt;br /&gt;
SRC= ... $(HEARTBEATTEST).c&lt;br /&gt;
alltests: \&lt;br /&gt;
        ... test_heartbeat&lt;br /&gt;
&lt;br /&gt;
test_heartbeat: $(HEARTBEATTEST)$(EXE_EXT)&lt;br /&gt;
  ../util/shlib_wrap.sh ./$(HEARTBEATTEST)&lt;br /&gt;
&lt;br /&gt;
$(HEARTBEATTEST)$(EXE_EXT): $(HEARTBEATTEST).o $(DLIBCRYPTO) testutil.o&lt;br /&gt;
  @target=$(HEARTBEATTEST) testutil=testutil.o; $(BUILD_CMD)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Run &amp;lt;code&amp;gt;make links &amp;amp;&amp;amp; make depend&amp;lt;/code&amp;gt; ===&lt;br /&gt;
Finally, run &amp;lt;code&amp;gt;make links &amp;amp;&amp;amp; make depend&amp;lt;/code&amp;gt; to link the new test into the &amp;lt;code&amp;gt;test/&amp;lt;/code&amp;gt; directory and automatically generate the header file dependencies.&lt;br /&gt;
&lt;br /&gt;
=== Building and Running the Test ===&lt;br /&gt;
If you're initially developing on Mac OS X or (for now) FreeBSD 10, just use the stock method of building and testing:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ ./config &amp;amp;&amp;amp; make &amp;amp;&amp;amp; make test&lt;br /&gt;
&lt;br /&gt;
# To execute just one specific test&lt;br /&gt;
$ make TESTS=test_heartbeat test &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Ultimately the test will have to compile and pass with developer flags enabled:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ ./GitConfigure debug-ben-debug-64-clang&lt;br /&gt;
$ ./GitMake -j 2&lt;br /&gt;
$ ./GitMake test_heartbeat&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above currently doesn't work on Mac OS X or FreeBSD 10; for now, you can install the 9.1 release of [http://www.freebsd.org/ FreeBSD], which uses Clang 3.1, via a virtualization platform such as [https://www.virtualbox.org/ VirtualBox]. (Mac OS X breaks, in part, due to the fact that it doesn't use the GNU assembler; &amp;lt;code&amp;gt;-fsanitize&amp;lt;/code&amp;gt; appears to be ignored on FreeBSD 9.1/Clang 3.1, but later versions break because the Clang compiler will emit &amp;lt;code&amp;gt;-fsanitize&amp;lt;/code&amp;gt; symbols but the &amp;lt;code&amp;gt;libasan&amp;lt;/code&amp;gt; library [http://lists.freebsd.org/pipermail/freebsd-hackers/2013-December/043995.html has yet to be ported to FreeBSD].)&lt;br /&gt;
&lt;br /&gt;
=== Keep your repo up-to-date ===&lt;br /&gt;
Periodically run the following to keep your branch up-to-date:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ git fetch upstream master&lt;br /&gt;
$ git rebase upstream/master&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This will pull all the updates from the master OpenSSL repository into your repository, then update your branch to apply your changes on top of the latest updates.&lt;br /&gt;
&lt;br /&gt;
=== Send a pull request ===&lt;br /&gt;
When your test is ready, send a [https://help.github.com/articles/using-pull-requests GitHub pull request]. Note that the pull request should be based on the &amp;lt;code&amp;gt;tests&amp;lt;/code&amp;gt; branch of Mike's repository, not &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt;. (This should be the default; let Mike know if it doesn't appear to be!) We'll review the code, and when it's ready, it'll get merged into Mike's repository. From there, it will eventually get pulled into the master OpenSSL repository.&lt;br /&gt;
&lt;br /&gt;
== Style ==&lt;br /&gt;
[http://mike-bland.com/2014/06/05/pseudo-xunit-pattern.html The Pseudo-xUnit Pattern] is that established by [http://git.openssl.org/gitweb/?p=openssl.git;a=blob;f=ssl/heartbeat_test.c ssl/heartbeat_test.c]. This pattern organizes code in a fashion reminiscent of the [http://en.wikipedia.org/wiki/XUnit xUnit] family of unit testing frameworks, without actually using a testing framework. This should lower the barrier to entry for people wanting to write unit tests, but enable a relatively easy migration to an xUnit-based framework if we decide to do so one day.&lt;br /&gt;
&lt;br /&gt;
Some of the basic principles to follow are:&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;code&amp;gt;#include&amp;lt;/code&amp;gt; the header for the code under test first ===&lt;br /&gt;
Having the header file for the code under test appear as the first &amp;lt;code&amp;gt;#include&amp;lt;/code&amp;gt; directive ensures that that file is self-contained, i.e. it includes every header file it depends on, rather than relying on client code to include its dependencies.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;code&amp;gt;#include &amp;quot;testutil.h&amp;quot;&amp;lt;/code&amp;gt; should come second ===&lt;br /&gt;
&amp;lt;code&amp;gt;test/testutil.h&amp;lt;/code&amp;gt; contains the helper macros used in writing OpenSSL tests. Since the tests will be linked into &amp;lt;code&amp;gt;test/&amp;lt;/code&amp;gt; by the [[#Run_make_links_.26.26_make_depend|make links]] step, and built in the &amp;lt;code&amp;gt;test/&amp;lt;/code&amp;gt; directory, the &amp;quot;testutil.h&amp;quot; file will appear to be in the same directory as the test file.&lt;br /&gt;
&lt;br /&gt;
=== Define a fixture structure ===&lt;br /&gt;
The fixture structure should contain all of the inputs to the code under test and all of the expected result values. It should also contain a &amp;lt;code&amp;gt;const char*&amp;lt;/code&amp;gt; for the name of the test case function that created it, to aid in error message formatting. Even though the fixture may contain dynamically-allocated members, the fixture itself should be copied by value to reduce the necessary degree of memory management in a small unit test program.&lt;br /&gt;
&lt;br /&gt;
=== Define set_up() and tear_down() functions for the fixture ===&lt;br /&gt;
&amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; should return a newly-initialized test fixture structure. It should take the name of the test case as an argument (i.e. &amp;lt;code&amp;gt;__func__&amp;lt;/code&amp;gt;) and assign it to the fixture. All of the fixture members should be initialized, which each test case function can then override as needed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;tear_down()&amp;lt;/code&amp;gt; should take the fixture as an argument and release any resources allocated by &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt;. It can also call any library-wide error printing routines (e.g. &amp;lt;code&amp;gt;ERR_print_errors_fp(stderr)&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
=== Use &amp;lt;code&amp;gt;SETUP_TEST_FIXTURE()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;EXECUTE_TEST()&amp;lt;/code&amp;gt; from &amp;lt;code&amp;gt;test/testutil.h&amp;lt;/code&amp;gt; ===&lt;br /&gt;
Each test case function should call &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; as its first statement, and should call &amp;lt;code&amp;gt;tear_down()&amp;lt;/code&amp;gt; just before returning. This is handled in a uniform fashion when using the &amp;lt;code&amp;gt;SETUP_TEST_FIXTURE()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;EXECUTE_TEST()&amp;lt;/code&amp;gt; helper macros from [http://git.openssl.org/gitweb/?p=openssl.git;a=blob;f=test/testutil.h test/testutil.h]. See the comments in &amp;lt;code&amp;gt;test/testutil.h&amp;lt;/code&amp;gt; for usage, and &amp;lt;code&amp;gt;ssl/heartbeat_test.c&amp;lt;/code&amp;gt; for an example of how to wrap the macros for a specific unit test.&lt;br /&gt;
&lt;br /&gt;
=== Use test case functions, not a table of fixtures ===&lt;br /&gt;
Individual test case functions that call a common execution function are much more readable and maintainable than a loop over a table of fixture structures. Explicit fixture variable assignments aid comprehension when reading a specific test case, which saves time and energy when trying to understand a test or diagnose a failure. When a new member is added to an existing fixture, &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; can set a default for all test cases, and only the test cases that rely on that new member need to be updated.&lt;br /&gt;
&lt;br /&gt;
=== Use very descriptive test case names ===&lt;br /&gt;
Give tests long, descriptive names that provide ample context for the details of the test case. Good test names are also help produce good error messages.&lt;br /&gt;
&lt;br /&gt;
=== Group test cases into &amp;quot;suites&amp;quot; by naming convention ===&lt;br /&gt;
Give logically-related tests the same prefix, e.g. &amp;lt;code&amp;gt;test_dtls1_&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;test_tls1&amp;lt;/code&amp;gt; from &amp;lt;code&amp;gt;ssl/heartbeat_test.c&amp;lt;/code&amp;gt;. If need be, you can define suite-specific &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; functions that call the common &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; and elaborate on it. (This generally shouldn't be necessary for &amp;lt;code&amp;gt;tear_down()&amp;lt;/code&amp;gt;.)&lt;br /&gt;
&lt;br /&gt;
=== Keep individual test case functions focused on one thing ===&lt;br /&gt;
If the test name contains the word &amp;quot;and&amp;quot;, consider breaking it into two or more separate test case functions.&lt;br /&gt;
&lt;br /&gt;
=== Write very descriptive error messages ===&lt;br /&gt;
Include the test case function name in each error message, and explain in detail the context for the assertion that failed. Include the expected result (contained in the fixture structure) and the actual result returned from the code under test. Write helper methods for complex values as needed (e.g. &amp;lt;code&amp;gt;print_payload()&amp;lt;/code&amp;gt; in &amp;lt;code&amp;gt;ssl/heartbeat_test.c&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
=== Return zero on success and one on failure ===&lt;br /&gt;
The return value will be used to tally the number of test cases that failed. Even if multiple assertions fail for a single test case, the result should be exactly one.&lt;br /&gt;
&lt;br /&gt;
=== Register each test case using ADD_TEST() and execute using run_tests() ===&lt;br /&gt;
Whatever function is used as the test runner, be that &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt; or a separate function called by &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt;, add your test case functions to that function using &amp;lt;code&amp;gt;ADD_TEST()&amp;lt;/code&amp;gt; and execute them using &amp;lt;code&amp;gt;run_tests()&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;run_tests()&amp;lt;/code&amp;gt; will add up the total number of failed test cases and report that number as the last error message of the test. The return value of &amp;lt;code&amp;gt;run_tests()&amp;lt;/code&amp;gt; should be the value returned from &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt;, which will be &amp;lt;code&amp;gt;EXIT_FAILURE&amp;lt;/code&amp;gt; if any test cases failed, &amp;lt;code&amp;gt;EXIT_SUCCESS&amp;lt;/code&amp;gt; otherwise.&lt;br /&gt;
&lt;br /&gt;
TODO(mbland): create some kind of automated script or editor macros?&lt;br /&gt;
&lt;br /&gt;
=== Disable for Windows (for now) ===&lt;br /&gt;
Until we solve the private-symbol problem on Windows, we will need to wrap our unit test code in the following &amp;lt;code&amp;gt;#ifdef&amp;lt;/code&amp;gt; block:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#if !defined(OPENSSL_SYS_WINDOWS)&lt;br /&gt;
&lt;br /&gt;
/* All the test code, including main() */&lt;br /&gt;
&lt;br /&gt;
int main(int argc, char *argv[])                                                &lt;br /&gt;
    {&lt;br /&gt;
        return EXIT_SUCCESS;                                                    &lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
#endif /* OPENSSL_NO_WINDOWS  */&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Samples ==&lt;br /&gt;
Existing tests that can be used as models for new tests.&lt;br /&gt;
* [http://git.openssl.org/gitweb/?p=openssl.git;a=blob;f=ssl/heartbeat_test.c ssl/heartbeat_test.c]: Follows [http://mike-bland.com/2014/06/05/pseudo-xunit-pattern.html the Pseudo-xUnit pattern]&lt;/div&gt;</summary>
		<author><name>Mbland</name></author>
	</entry>
	<entry>
		<id>https://wiki.openssl.org/index.php?title=How_To_Write_Unit_Tests_For_OpenSSL&amp;diff=1849</id>
		<title>How To Write Unit Tests For OpenSSL</title>
		<link rel="alternate" type="text/html" href="https://wiki.openssl.org/index.php?title=How_To_Write_Unit_Tests_For_OpenSSL&amp;diff=1849"/>
		<updated>2014-07-19T23:56:37Z</updated>

		<summary type="html">&lt;p&gt;Mbland: /* Add each test case function to the test runner function */ Update with advice to use ADD_TEST() and run_tests()&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This is an outline of the basic process and principles to follow when writing unit tests. This document will evolve quite a bit as the community gains experience.&lt;br /&gt;
&lt;br /&gt;
==Mechanics ==&lt;br /&gt;
=== Forking the Repo ===&lt;br /&gt;
For now, people contributing new unit tests for uncovered code (as opposed to submitting tests with new code changes) should fork [https://github.com/mbland/openssl Mike Bland's GitHub repository] and issue [https://help.github.com/articles/using-pull-requests GitHub pull requests]. Remember to do all development on a topic branch (not &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt;). Tests committed to this repo will occasionally get merged into the master OpenSSL repo.&lt;br /&gt;
&lt;br /&gt;
Rationale per Matt Caswell: We should think about process here. If you are going off to recruit an army of people writing tests then I wonder if it is worth setting up a separate github repository whilst you are building up the tests. We can then merge in from that on a periodic basis. I wouldn't want availability of openssl team committers to be a bottle neck.&lt;br /&gt;
&lt;br /&gt;
Set up the [https://github.com/openssl/openssl OpenSSL master repository] as your upstream remote as per [https://help.github.com/articles/fork-a-repo#step-3-configure-remotes GitHub's instructions on configuring remotes]:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ cd my-openssl-repo&lt;br /&gt;
$ git remote add upstream https://github.com/openssl/openssl.git&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You should see the following output from &amp;lt;code&amp;gt;git remove -v&amp;lt;/code&amp;gt; (where &amp;lt;code&amp;gt;$USER&amp;lt;/code&amp;gt; is your GitHub username):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ git remote -v&lt;br /&gt;
origin  https://github.com/$USER/openssl.git (fetch)&lt;br /&gt;
origin  https://github.com/$USER/openssl.git (push)&lt;br /&gt;
upstream        https://github.com/openssl/openssl.git (fetch)&lt;br /&gt;
upstream        https://github.com/openssl/openssl.git (push)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Check out the Tools and Tips page ===&lt;br /&gt;
[[Testing and Development Tools and Tips]] has information on tools that may make navigating and building the code a bit easier.&lt;br /&gt;
&lt;br /&gt;
=== Use the Test Template Generator ===&lt;br /&gt;
TODO(mbland): Get template generator checked-in. Maybe have a template generator for each library, e.g. &amp;lt;code&amp;gt;ssl/new-test.sh&amp;lt;/code&amp;gt; that has additional setup boilerplate specific to the &amp;lt;code&amp;gt;ssl&amp;lt;/code&amp;gt; library.&lt;br /&gt;
&lt;br /&gt;
Use the &amp;lt;code&amp;gt;test/new-test.sh&amp;lt;/code&amp;gt; script to generate a skeleton test file. ([https://github.com/mbland/openssl/compare/test-util pending in the test-util branch])&lt;br /&gt;
&lt;br /&gt;
=== Add Makefile Targets ===&lt;br /&gt;
The following instructions use the &amp;lt;code&amp;gt;Makefile&amp;lt;/code&amp;gt; targets for &amp;lt;code&amp;gt;ssl/heartbeat_test.c&amp;lt;/code&amp;gt; as an example.&lt;br /&gt;
&lt;br /&gt;
In the &amp;lt;code&amp;gt;Makefile&amp;lt;/code&amp;gt; for the library containing the test, add the test source file to the &amp;lt;code&amp;gt;TEST&amp;lt;/code&amp;gt; variable:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# ssl/Makefile&lt;br /&gt;
TEST=ssltest.c heartbeat_test.c&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In &amp;lt;code&amp;gt;test/Makefile&amp;lt;/code&amp;gt;:&lt;br /&gt;
* add a variable for the test target near the top of the file, right after the existing test variables&lt;br /&gt;
* use the variable to add an executable target to the &amp;lt;code&amp;gt;EXE&amp;lt;/code&amp;gt; variable&lt;br /&gt;
* use the variable to add an object file target to the &amp;lt;code&amp;gt;OBJ&amp;lt;/code&amp;gt; variable&lt;br /&gt;
* use the variable to add a source file target to the &amp;lt;code&amp;gt;SRC&amp;lt;/code&amp;gt; variable&lt;br /&gt;
* add the test target to the &amp;lt;code&amp;gt;alltests&amp;lt;/code&amp;gt; target&lt;br /&gt;
* add the target to execute the test&lt;br /&gt;
* add the target to build the test executable&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# test/Makefile&lt;br /&gt;
HEARTBEATTEST=  heartbeat_test&lt;br /&gt;
EXE=  ... $(HEARTBEATTEST)$(EXE_EXT)&lt;br /&gt;
OBJ= ... $(HEARTBEATTEST).o&lt;br /&gt;
SRC= ... $(HEARTBEATTEST).c&lt;br /&gt;
alltests: \&lt;br /&gt;
        ... test_heartbeat&lt;br /&gt;
&lt;br /&gt;
test_heartbeat: $(HEARTBEATTEST)$(EXE_EXT)&lt;br /&gt;
  ../util/shlib_wrap.sh ./$(HEARTBEATTEST)&lt;br /&gt;
&lt;br /&gt;
$(HEARTBEATTEST)$(EXE_EXT): $(HEARTBEATTEST).o $(DLIBCRYPTO) testutil.o&lt;br /&gt;
  @target=$(HEARTBEATTEST) testutil=testutil.o; $(BUILD_CMD)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Run &amp;lt;code&amp;gt;make links &amp;amp;&amp;amp; make depend&amp;lt;/code&amp;gt; ===&lt;br /&gt;
Finally, run &amp;lt;code&amp;gt;make links &amp;amp;&amp;amp; make depend&amp;lt;/code&amp;gt; to link the new test into the &amp;lt;code&amp;gt;test/&amp;lt;/code&amp;gt; directory and automatically generate the header file dependencies.&lt;br /&gt;
&lt;br /&gt;
=== Building and Running the Test ===&lt;br /&gt;
If you're initially developing on Mac OS X or (for now) FreeBSD 10, just use the stock method of building and testing:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ ./config &amp;amp;&amp;amp; make &amp;amp;&amp;amp; make test&lt;br /&gt;
&lt;br /&gt;
# To execute just one specific test&lt;br /&gt;
$ make TESTS=test_heartbeat test &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Ultimately the test will have to compile and pass with developer flags enabled:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ ./GitConfigure debug-ben-debug-64-clang&lt;br /&gt;
$ ./GitMake -j 2&lt;br /&gt;
$ ./GitMake test_heartbeat&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above currently doesn't work on Mac OS X or FreeBSD 10; for now, you can install the 9.1 release of [http://www.freebsd.org/ FreeBSD], which uses Clang 3.1, via a virtualization platform such as [https://www.virtualbox.org/ VirtualBox]. (Mac OS X breaks, in part, due to the fact that it doesn't use the GNU assembler; &amp;lt;code&amp;gt;-fsanitize&amp;lt;/code&amp;gt; appears to be ignored on FreeBSD 9.1/Clang 3.1, but later versions break because the Clang compiler will emit &amp;lt;code&amp;gt;-fsanitize&amp;lt;/code&amp;gt; symbols but the &amp;lt;code&amp;gt;libasan&amp;lt;/code&amp;gt; library [http://lists.freebsd.org/pipermail/freebsd-hackers/2013-December/043995.html has yet to be ported to FreeBSD].)&lt;br /&gt;
&lt;br /&gt;
=== Keep your repo up-to-date ===&lt;br /&gt;
Periodically run the following to keep your branch up-to-date:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ git fetch upstream master&lt;br /&gt;
$ git rebase upstream/master&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This will pull all the updates from the master OpenSSL repository into your repository, then update your branch to apply your changes on top of the latest updates.&lt;br /&gt;
&lt;br /&gt;
=== Send a pull request ===&lt;br /&gt;
When your test is ready, send a [https://help.github.com/articles/using-pull-requests GitHub pull request]. Note that the pull request should be based on the &amp;lt;code&amp;gt;tests&amp;lt;/code&amp;gt; branch of Mike's repository, not &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt;. (This should be the default; let Mike know if it doesn't appear to be!) We'll review the code, and when it's ready, it'll get merged into Mike's repository. From there, it will eventually get pulled into the master OpenSSL repository.&lt;br /&gt;
&lt;br /&gt;
== Style ==&lt;br /&gt;
[http://mike-bland.com/2014/06/05/pseudo-xunit-pattern.html The Pseudo-xUnit Pattern] is that established by [http://git.openssl.org/gitweb/?p=openssl.git;a=blob;f=ssl/heartbeat_test.c ssl/heartbeat_test.c]. This pattern organizes code in a fashion reminiscent of the [http://en.wikipedia.org/wiki/XUnit xUnit] family of unit testing frameworks, without actually using a testing framework. This should lower the barrier to entry for people wanting to write unit tests, but enable a relatively easy migration to an xUnit-based framework if we decide to do so one day.&lt;br /&gt;
&lt;br /&gt;
Some of the basic principles to follow are:&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;code&amp;gt;#include&amp;lt;/code&amp;gt; the header for the code under test first ===&lt;br /&gt;
Having the header file for the code under test appear as the first &amp;lt;code&amp;gt;#include&amp;lt;/code&amp;gt; directive ensures that that file is self-contained, i.e. it includes every header file it depends on, rather than relying on client code to include its dependencies.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;code&amp;gt;#include &amp;quot;testutil.h&amp;quot;&amp;lt;/code&amp;gt; should come second ===&lt;br /&gt;
&amp;lt;code&amp;gt;test/testutil.h&amp;lt;/code&amp;gt; contains the helper macros used in writing OpenSSL tests. Since the tests will be linked into &amp;lt;code&amp;gt;test/&amp;lt;/code&amp;gt; by the [[#Run_make_links_.26.26_make_depend|make links]] step, and built in the &amp;lt;code&amp;gt;test/&amp;lt;/code&amp;gt; directory, the &amp;quot;testutil.h&amp;quot; file will appear to be in the same directory as the test file.&lt;br /&gt;
&lt;br /&gt;
=== Define a fixture structure ===&lt;br /&gt;
The fixture structure should contain all of the inputs to the code under test and all of the expected result values. It should also contain a &amp;lt;code&amp;gt;const char*&amp;lt;/code&amp;gt; for the name of the test case function that created it, to aid in error message formatting. Even though the fixture may contain dynamically-allocated members, the fixture itself should be copied by value to reduce the necessary degree of memory management in a small unit test program.&lt;br /&gt;
&lt;br /&gt;
=== Define set_up() and tear_down() functions for the fixture ===&lt;br /&gt;
&amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; should return a newly-initialized test fixture structure. It should take the name of the test case as an argument (i.e. &amp;lt;code&amp;gt;__func__&amp;lt;/code&amp;gt;) and assign it to the fixture. All of the fixture members should be initialized, which each test case function can then override as needed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;tear_down()&amp;lt;/code&amp;gt; should take the fixture as an argument and release any resources allocated by &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt;. It can also call any library-wide error printing routines (e.g. &amp;lt;code&amp;gt;ERR_print_errors_fp(stderr)&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
=== Use &amp;lt;code&amp;gt;SETUP_TEST_FIXTURE()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;EXECUTE_TEST()&amp;lt;/code&amp;gt; from &amp;lt;code&amp;gt;test/testutil.h&amp;lt;/code&amp;gt; ===&lt;br /&gt;
Each test case function should call &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; as its first statement, and should call &amp;lt;code&amp;gt;tear_down()&amp;lt;/code&amp;gt; just before returning. This is handled in a uniform fashion when using the &amp;lt;code&amp;gt;SETUP_TEST_FIXTURE()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;EXECUTE_TEST()&amp;lt;/code&amp;gt; helper macros from [http://git.openssl.org/gitweb/?p=openssl.git;a=blob;f=test/testutil.h test/testutil.h]. See the comments in &amp;lt;code&amp;gt;test/testutil.h&amp;lt;/code&amp;gt; for usage, and &amp;lt;code&amp;gt;ssl/heartbeat_test.c&amp;lt;/code&amp;gt; for an example of how to wrap the macros for a specific unit test.&lt;br /&gt;
&lt;br /&gt;
=== Use test case functions, not a table of fixtures ===&lt;br /&gt;
Individual test case functions that call a common execution function are much more readable and maintainable than a loop over a table of fixture structures. Explicit fixture variable assignments aid comprehension when reading a specific test case, which saves time and energy when trying to understand a test or diagnose a failure. When a new member is added to an existing fixture, &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; can set a default for all test cases, and only the test cases that rely on that new member need to be updated.&lt;br /&gt;
&lt;br /&gt;
=== Use very descriptive test case names ===&lt;br /&gt;
Give tests long, descriptive names that provide ample context for the details of the test case. Good test names are also help produce good error messages.&lt;br /&gt;
&lt;br /&gt;
=== Group test cases into &amp;quot;suites&amp;quot; by naming convention ===&lt;br /&gt;
Give logically-related tests the same prefix, e.g. &amp;lt;code&amp;gt;test_dtls1_&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;test_tls1&amp;lt;/code&amp;gt; from &amp;lt;code&amp;gt;ssl/heartbeat_test.c&amp;lt;/code&amp;gt;. If need be, you can define suite-specific &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; functions that call the common &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; and elaborate on it. (This generally shouldn't be necessary for &amp;lt;code&amp;gt;tear_down()&amp;lt;/code&amp;gt;.)&lt;br /&gt;
&lt;br /&gt;
=== Keep individual test case functions focused on one thing ===&lt;br /&gt;
If the test name contains the word &amp;quot;and&amp;quot;, consider breaking it into two or more separate test case functions.&lt;br /&gt;
&lt;br /&gt;
=== Write very descriptive error messages ===&lt;br /&gt;
Include the test case function name in each error message, and explain in detail the context for the assertion that failed. Include the expected result (contained in the fixture structure) and the actual result returned from the code under test. Write helper methods for complex values as needed (e.g. &amp;lt;code&amp;gt;print_payload()&amp;lt;/code&amp;gt; in &amp;lt;code&amp;gt;ssl/heartbeat_test.c&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
=== Return zero on success and one on failure ===&lt;br /&gt;
The return value will be used to tally the number of test cases that failed. Even if multiple assertions fail for a single test case, the result should be exactly one.&lt;br /&gt;
&lt;br /&gt;
=== Add each test case function to the test runner function ===&lt;br /&gt;
Whatever function is used as the test runner, be that &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt; or a separate function called by &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt;, add your test case functions to that function using &amp;lt;code&amp;gt;ADD_TEST()&amp;lt;/code&amp;gt; and execute them using &amp;lt;code&amp;gt;run_tests()&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
TODO(mbland): create some kind of automated script or editor macros?&lt;br /&gt;
&lt;br /&gt;
=== Report the number of test cases that failed ===&lt;br /&gt;
Add up the total number of failed test cases in &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt; and report that number as the last error message of the test. &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt; should return &amp;lt;code&amp;gt;EXIT_FAILURE&amp;lt;/code&amp;gt; if any test cases failed, &amp;lt;code&amp;gt;EXIT_SUCCESS&amp;lt;/code&amp;gt; otherwise.&lt;br /&gt;
&lt;br /&gt;
=== Disable for Windows (for now) ===&lt;br /&gt;
Until we solve the private-symbol problem on Windows, we will need to wrap our unit test code in the following &amp;lt;code&amp;gt;#ifdef&amp;lt;/code&amp;gt; block:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#if !defined(OPENSSL_SYS_WINDOWS)&lt;br /&gt;
&lt;br /&gt;
/* All the test code, including main() */&lt;br /&gt;
&lt;br /&gt;
int main(int argc, char *argv[])                                                &lt;br /&gt;
    {&lt;br /&gt;
        return EXIT_SUCCESS;                                                    &lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
#endif /* OPENSSL_NO_WINDOWS  */&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Samples ==&lt;br /&gt;
Existing tests that can be used as models for new tests.&lt;br /&gt;
* [http://git.openssl.org/gitweb/?p=openssl.git;a=blob;f=ssl/heartbeat_test.c ssl/heartbeat_test.c]: Follows [http://mike-bland.com/2014/06/05/pseudo-xunit-pattern.html the Pseudo-xUnit pattern]&lt;/div&gt;</summary>
		<author><name>Mbland</name></author>
	</entry>
	<entry>
		<id>https://wiki.openssl.org/index.php?title=How_To_Write_Unit_Tests_For_OpenSSL&amp;diff=1848</id>
		<title>How To Write Unit Tests For OpenSSL</title>
		<link rel="alternate" type="text/html" href="https://wiki.openssl.org/index.php?title=How_To_Write_Unit_Tests_For_OpenSSL&amp;diff=1848"/>
		<updated>2014-07-19T23:53:01Z</updated>

		<summary type="html">&lt;p&gt;Mbland: /* Add Makefile Targets */ Add testutil.o to test executable build rule&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This is an outline of the basic process and principles to follow when writing unit tests. This document will evolve quite a bit as the community gains experience.&lt;br /&gt;
&lt;br /&gt;
==Mechanics ==&lt;br /&gt;
=== Forking the Repo ===&lt;br /&gt;
For now, people contributing new unit tests for uncovered code (as opposed to submitting tests with new code changes) should fork [https://github.com/mbland/openssl Mike Bland's GitHub repository] and issue [https://help.github.com/articles/using-pull-requests GitHub pull requests]. Remember to do all development on a topic branch (not &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt;). Tests committed to this repo will occasionally get merged into the master OpenSSL repo.&lt;br /&gt;
&lt;br /&gt;
Rationale per Matt Caswell: We should think about process here. If you are going off to recruit an army of people writing tests then I wonder if it is worth setting up a separate github repository whilst you are building up the tests. We can then merge in from that on a periodic basis. I wouldn't want availability of openssl team committers to be a bottle neck.&lt;br /&gt;
&lt;br /&gt;
Set up the [https://github.com/openssl/openssl OpenSSL master repository] as your upstream remote as per [https://help.github.com/articles/fork-a-repo#step-3-configure-remotes GitHub's instructions on configuring remotes]:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ cd my-openssl-repo&lt;br /&gt;
$ git remote add upstream https://github.com/openssl/openssl.git&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You should see the following output from &amp;lt;code&amp;gt;git remove -v&amp;lt;/code&amp;gt; (where &amp;lt;code&amp;gt;$USER&amp;lt;/code&amp;gt; is your GitHub username):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ git remote -v&lt;br /&gt;
origin  https://github.com/$USER/openssl.git (fetch)&lt;br /&gt;
origin  https://github.com/$USER/openssl.git (push)&lt;br /&gt;
upstream        https://github.com/openssl/openssl.git (fetch)&lt;br /&gt;
upstream        https://github.com/openssl/openssl.git (push)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Check out the Tools and Tips page ===&lt;br /&gt;
[[Testing and Development Tools and Tips]] has information on tools that may make navigating and building the code a bit easier.&lt;br /&gt;
&lt;br /&gt;
=== Use the Test Template Generator ===&lt;br /&gt;
TODO(mbland): Get template generator checked-in. Maybe have a template generator for each library, e.g. &amp;lt;code&amp;gt;ssl/new-test.sh&amp;lt;/code&amp;gt; that has additional setup boilerplate specific to the &amp;lt;code&amp;gt;ssl&amp;lt;/code&amp;gt; library.&lt;br /&gt;
&lt;br /&gt;
Use the &amp;lt;code&amp;gt;test/new-test.sh&amp;lt;/code&amp;gt; script to generate a skeleton test file. ([https://github.com/mbland/openssl/compare/test-util pending in the test-util branch])&lt;br /&gt;
&lt;br /&gt;
=== Add Makefile Targets ===&lt;br /&gt;
The following instructions use the &amp;lt;code&amp;gt;Makefile&amp;lt;/code&amp;gt; targets for &amp;lt;code&amp;gt;ssl/heartbeat_test.c&amp;lt;/code&amp;gt; as an example.&lt;br /&gt;
&lt;br /&gt;
In the &amp;lt;code&amp;gt;Makefile&amp;lt;/code&amp;gt; for the library containing the test, add the test source file to the &amp;lt;code&amp;gt;TEST&amp;lt;/code&amp;gt; variable:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# ssl/Makefile&lt;br /&gt;
TEST=ssltest.c heartbeat_test.c&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In &amp;lt;code&amp;gt;test/Makefile&amp;lt;/code&amp;gt;:&lt;br /&gt;
* add a variable for the test target near the top of the file, right after the existing test variables&lt;br /&gt;
* use the variable to add an executable target to the &amp;lt;code&amp;gt;EXE&amp;lt;/code&amp;gt; variable&lt;br /&gt;
* use the variable to add an object file target to the &amp;lt;code&amp;gt;OBJ&amp;lt;/code&amp;gt; variable&lt;br /&gt;
* use the variable to add a source file target to the &amp;lt;code&amp;gt;SRC&amp;lt;/code&amp;gt; variable&lt;br /&gt;
* add the test target to the &amp;lt;code&amp;gt;alltests&amp;lt;/code&amp;gt; target&lt;br /&gt;
* add the target to execute the test&lt;br /&gt;
* add the target to build the test executable&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# test/Makefile&lt;br /&gt;
HEARTBEATTEST=  heartbeat_test&lt;br /&gt;
EXE=  ... $(HEARTBEATTEST)$(EXE_EXT)&lt;br /&gt;
OBJ= ... $(HEARTBEATTEST).o&lt;br /&gt;
SRC= ... $(HEARTBEATTEST).c&lt;br /&gt;
alltests: \&lt;br /&gt;
        ... test_heartbeat&lt;br /&gt;
&lt;br /&gt;
test_heartbeat: $(HEARTBEATTEST)$(EXE_EXT)&lt;br /&gt;
  ../util/shlib_wrap.sh ./$(HEARTBEATTEST)&lt;br /&gt;
&lt;br /&gt;
$(HEARTBEATTEST)$(EXE_EXT): $(HEARTBEATTEST).o $(DLIBCRYPTO) testutil.o&lt;br /&gt;
  @target=$(HEARTBEATTEST) testutil=testutil.o; $(BUILD_CMD)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Run &amp;lt;code&amp;gt;make links &amp;amp;&amp;amp; make depend&amp;lt;/code&amp;gt; ===&lt;br /&gt;
Finally, run &amp;lt;code&amp;gt;make links &amp;amp;&amp;amp; make depend&amp;lt;/code&amp;gt; to link the new test into the &amp;lt;code&amp;gt;test/&amp;lt;/code&amp;gt; directory and automatically generate the header file dependencies.&lt;br /&gt;
&lt;br /&gt;
=== Building and Running the Test ===&lt;br /&gt;
If you're initially developing on Mac OS X or (for now) FreeBSD 10, just use the stock method of building and testing:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ ./config &amp;amp;&amp;amp; make &amp;amp;&amp;amp; make test&lt;br /&gt;
&lt;br /&gt;
# To execute just one specific test&lt;br /&gt;
$ make TESTS=test_heartbeat test &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Ultimately the test will have to compile and pass with developer flags enabled:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ ./GitConfigure debug-ben-debug-64-clang&lt;br /&gt;
$ ./GitMake -j 2&lt;br /&gt;
$ ./GitMake test_heartbeat&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above currently doesn't work on Mac OS X or FreeBSD 10; for now, you can install the 9.1 release of [http://www.freebsd.org/ FreeBSD], which uses Clang 3.1, via a virtualization platform such as [https://www.virtualbox.org/ VirtualBox]. (Mac OS X breaks, in part, due to the fact that it doesn't use the GNU assembler; &amp;lt;code&amp;gt;-fsanitize&amp;lt;/code&amp;gt; appears to be ignored on FreeBSD 9.1/Clang 3.1, but later versions break because the Clang compiler will emit &amp;lt;code&amp;gt;-fsanitize&amp;lt;/code&amp;gt; symbols but the &amp;lt;code&amp;gt;libasan&amp;lt;/code&amp;gt; library [http://lists.freebsd.org/pipermail/freebsd-hackers/2013-December/043995.html has yet to be ported to FreeBSD].)&lt;br /&gt;
&lt;br /&gt;
=== Keep your repo up-to-date ===&lt;br /&gt;
Periodically run the following to keep your branch up-to-date:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ git fetch upstream master&lt;br /&gt;
$ git rebase upstream/master&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This will pull all the updates from the master OpenSSL repository into your repository, then update your branch to apply your changes on top of the latest updates.&lt;br /&gt;
&lt;br /&gt;
=== Send a pull request ===&lt;br /&gt;
When your test is ready, send a [https://help.github.com/articles/using-pull-requests GitHub pull request]. Note that the pull request should be based on the &amp;lt;code&amp;gt;tests&amp;lt;/code&amp;gt; branch of Mike's repository, not &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt;. (This should be the default; let Mike know if it doesn't appear to be!) We'll review the code, and when it's ready, it'll get merged into Mike's repository. From there, it will eventually get pulled into the master OpenSSL repository.&lt;br /&gt;
&lt;br /&gt;
== Style ==&lt;br /&gt;
[http://mike-bland.com/2014/06/05/pseudo-xunit-pattern.html The Pseudo-xUnit Pattern] is that established by [http://git.openssl.org/gitweb/?p=openssl.git;a=blob;f=ssl/heartbeat_test.c ssl/heartbeat_test.c]. This pattern organizes code in a fashion reminiscent of the [http://en.wikipedia.org/wiki/XUnit xUnit] family of unit testing frameworks, without actually using a testing framework. This should lower the barrier to entry for people wanting to write unit tests, but enable a relatively easy migration to an xUnit-based framework if we decide to do so one day.&lt;br /&gt;
&lt;br /&gt;
Some of the basic principles to follow are:&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;code&amp;gt;#include&amp;lt;/code&amp;gt; the header for the code under test first ===&lt;br /&gt;
Having the header file for the code under test appear as the first &amp;lt;code&amp;gt;#include&amp;lt;/code&amp;gt; directive ensures that that file is self-contained, i.e. it includes every header file it depends on, rather than relying on client code to include its dependencies.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;code&amp;gt;#include &amp;quot;testutil.h&amp;quot;&amp;lt;/code&amp;gt; should come second ===&lt;br /&gt;
&amp;lt;code&amp;gt;test/testutil.h&amp;lt;/code&amp;gt; contains the helper macros used in writing OpenSSL tests. Since the tests will be linked into &amp;lt;code&amp;gt;test/&amp;lt;/code&amp;gt; by the [[#Run_make_links_.26.26_make_depend|make links]] step, and built in the &amp;lt;code&amp;gt;test/&amp;lt;/code&amp;gt; directory, the &amp;quot;testutil.h&amp;quot; file will appear to be in the same directory as the test file.&lt;br /&gt;
&lt;br /&gt;
=== Define a fixture structure ===&lt;br /&gt;
The fixture structure should contain all of the inputs to the code under test and all of the expected result values. It should also contain a &amp;lt;code&amp;gt;const char*&amp;lt;/code&amp;gt; for the name of the test case function that created it, to aid in error message formatting. Even though the fixture may contain dynamically-allocated members, the fixture itself should be copied by value to reduce the necessary degree of memory management in a small unit test program.&lt;br /&gt;
&lt;br /&gt;
=== Define set_up() and tear_down() functions for the fixture ===&lt;br /&gt;
&amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; should return a newly-initialized test fixture structure. It should take the name of the test case as an argument (i.e. &amp;lt;code&amp;gt;__func__&amp;lt;/code&amp;gt;) and assign it to the fixture. All of the fixture members should be initialized, which each test case function can then override as needed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;tear_down()&amp;lt;/code&amp;gt; should take the fixture as an argument and release any resources allocated by &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt;. It can also call any library-wide error printing routines (e.g. &amp;lt;code&amp;gt;ERR_print_errors_fp(stderr)&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
=== Use &amp;lt;code&amp;gt;SETUP_TEST_FIXTURE()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;EXECUTE_TEST()&amp;lt;/code&amp;gt; from &amp;lt;code&amp;gt;test/testutil.h&amp;lt;/code&amp;gt; ===&lt;br /&gt;
Each test case function should call &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; as its first statement, and should call &amp;lt;code&amp;gt;tear_down()&amp;lt;/code&amp;gt; just before returning. This is handled in a uniform fashion when using the &amp;lt;code&amp;gt;SETUP_TEST_FIXTURE()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;EXECUTE_TEST()&amp;lt;/code&amp;gt; helper macros from [http://git.openssl.org/gitweb/?p=openssl.git;a=blob;f=test/testutil.h test/testutil.h]. See the comments in &amp;lt;code&amp;gt;test/testutil.h&amp;lt;/code&amp;gt; for usage, and &amp;lt;code&amp;gt;ssl/heartbeat_test.c&amp;lt;/code&amp;gt; for an example of how to wrap the macros for a specific unit test.&lt;br /&gt;
&lt;br /&gt;
=== Use test case functions, not a table of fixtures ===&lt;br /&gt;
Individual test case functions that call a common execution function are much more readable and maintainable than a loop over a table of fixture structures. Explicit fixture variable assignments aid comprehension when reading a specific test case, which saves time and energy when trying to understand a test or diagnose a failure. When a new member is added to an existing fixture, &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; can set a default for all test cases, and only the test cases that rely on that new member need to be updated.&lt;br /&gt;
&lt;br /&gt;
=== Use very descriptive test case names ===&lt;br /&gt;
Give tests long, descriptive names that provide ample context for the details of the test case. Good test names are also help produce good error messages.&lt;br /&gt;
&lt;br /&gt;
=== Group test cases into &amp;quot;suites&amp;quot; by naming convention ===&lt;br /&gt;
Give logically-related tests the same prefix, e.g. &amp;lt;code&amp;gt;test_dtls1_&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;test_tls1&amp;lt;/code&amp;gt; from &amp;lt;code&amp;gt;ssl/heartbeat_test.c&amp;lt;/code&amp;gt;. If need be, you can define suite-specific &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; functions that call the common &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; and elaborate on it. (This generally shouldn't be necessary for &amp;lt;code&amp;gt;tear_down()&amp;lt;/code&amp;gt;.)&lt;br /&gt;
&lt;br /&gt;
=== Keep individual test case functions focused on one thing ===&lt;br /&gt;
If the test name contains the word &amp;quot;and&amp;quot;, consider breaking it into two or more separate test case functions.&lt;br /&gt;
&lt;br /&gt;
=== Write very descriptive error messages ===&lt;br /&gt;
Include the test case function name in each error message, and explain in detail the context for the assertion that failed. Include the expected result (contained in the fixture structure) and the actual result returned from the code under test. Write helper methods for complex values as needed (e.g. &amp;lt;code&amp;gt;print_payload()&amp;lt;/code&amp;gt; in &amp;lt;code&amp;gt;ssl/heartbeat_test.c&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
=== Return zero on success and one on failure ===&lt;br /&gt;
The return value will be used to tally the number of test cases that failed. Even if multiple assertions fail for a single test case, the result should be exactly one.&lt;br /&gt;
&lt;br /&gt;
=== Add each test case function to the test runner function ===&lt;br /&gt;
Whatever function is used to execute the batch of test case functions, be that &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt; or a separate function called by &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt;, don't forget to add your test case functions to that function.&lt;br /&gt;
&lt;br /&gt;
TODO(mbland): create some kind of automated script or editor macros?&lt;br /&gt;
&lt;br /&gt;
=== Report the number of test cases that failed ===&lt;br /&gt;
Add up the total number of failed test cases in &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt; and report that number as the last error message of the test. &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt; should return &amp;lt;code&amp;gt;EXIT_FAILURE&amp;lt;/code&amp;gt; if any test cases failed, &amp;lt;code&amp;gt;EXIT_SUCCESS&amp;lt;/code&amp;gt; otherwise.&lt;br /&gt;
&lt;br /&gt;
=== Disable for Windows (for now) ===&lt;br /&gt;
Until we solve the private-symbol problem on Windows, we will need to wrap our unit test code in the following &amp;lt;code&amp;gt;#ifdef&amp;lt;/code&amp;gt; block:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#if !defined(OPENSSL_SYS_WINDOWS)&lt;br /&gt;
&lt;br /&gt;
/* All the test code, including main() */&lt;br /&gt;
&lt;br /&gt;
int main(int argc, char *argv[])                                                &lt;br /&gt;
    {&lt;br /&gt;
        return EXIT_SUCCESS;                                                    &lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
#endif /* OPENSSL_NO_WINDOWS  */&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Samples ==&lt;br /&gt;
Existing tests that can be used as models for new tests.&lt;br /&gt;
* [http://git.openssl.org/gitweb/?p=openssl.git;a=blob;f=ssl/heartbeat_test.c ssl/heartbeat_test.c]: Follows [http://mike-bland.com/2014/06/05/pseudo-xunit-pattern.html the Pseudo-xUnit pattern]&lt;/div&gt;</summary>
		<author><name>Mbland</name></author>
	</entry>
	<entry>
		<id>https://wiki.openssl.org/index.php?title=Testing_and_Development_Tools_and_Tips&amp;diff=1847</id>
		<title>Testing and Development Tools and Tips</title>
		<link rel="alternate" type="text/html" href="https://wiki.openssl.org/index.php?title=Testing_and_Development_Tools_and_Tips&amp;diff=1847"/>
		<updated>2014-07-19T23:49:50Z</updated>

		<summary type="html">&lt;p&gt;Mbland: /* test/testutil.h */ Add ADD_TEST() and run_tests()&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This is a collection of helpful tools and tips for navigating the OpenSSL code base and managing a local git repository.&lt;br /&gt;
&lt;br /&gt;
== Testing Environment and Tools ==&lt;br /&gt;
In [https://github.com/mbland/openssl/compare/test-util the test-util branch of Mike Bland's fork] are a few helper files that you may wish to copy or pull into your branch. As they are incorporated into the main OpenSSL repository, links to the mainline versions will be incorporated into the descriptions below. However, there may be newer versions in Mike's fork.&lt;br /&gt;
&lt;br /&gt;
=== test/testutil.h ===&lt;br /&gt;
[http://git.openssl.org/gitweb/?p=openssl.git;a=blob;f=test/testutil.h test/testutil.h] defines:&lt;br /&gt;
* the generic &amp;lt;code&amp;gt;SETUP_TEST_FIXTURE&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;EXECUTE_TEST&amp;lt;/code&amp;gt; macros; the header comments describe how to define test-specific macros based on these&lt;br /&gt;
* &amp;lt;code&amp;gt;ADD_TEST()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;run_tests()&amp;lt;/code&amp;gt; to standardize the registration and execution of test case functions within &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== test/new-test.sh ===&lt;br /&gt;
[https://github.com/mbland/openssl/blob/test-util/test/new-test.sh test/new-test.sh (mbland's fork)] generates a new automated test stub, following [http://mike-bland.com/2014/06/05/pseudo-xunit-pattern.html the Pseudo-xUnit Pattern] and using the macros from &amp;lt;code&amp;gt;test/testutil.h&amp;lt;/code&amp;gt;. The generated stub will compile standalone.&lt;br /&gt;
&lt;br /&gt;
=== test/test_env.bash ===&lt;br /&gt;
[https://github.com/mbland/openssl/blob/test-util/test/test_env.bash test/test_env.bash (mbland's fork)]: contains environment variables, functions, and aliases to help with OpenSSL unit testing. The header comments contain documentation on each of the functions and aliases in the file.&lt;br /&gt;
&lt;br /&gt;
== Cscope ==&lt;br /&gt;
[http://cscope.sourceforge.net/ Cscope] is a powerful C source code browser. Once you have it installed, you can use the &amp;lt;code&amp;gt;make-cscope&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;open-cscope&amp;lt;/code&amp;gt; functions from &amp;lt;code&amp;gt;test/test_env.bash&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Vim Integration ===&lt;br /&gt;
Once &amp;lt;code&amp;gt;$CSCOPE_DB&amp;lt;/code&amp;gt; (defined in &amp;lt;code&amp;gt;test/test_env.bash&amp;lt;/code&amp;gt;) is built using &amp;lt;code&amp;gt;make-cscope&amp;lt;/code&amp;gt;, you can take advantage of the Cscope integration in Vim by adding something like the following to your &amp;lt;code&amp;gt;.vimrc&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;quot; Detect whether cscope features are present and whether we should add a&lt;br /&gt;
&amp;quot; connection to an existing cscope.out database file&lt;br /&gt;
if has(&amp;quot;cscope&amp;quot;)&lt;br /&gt;
  set nocsverb&lt;br /&gt;
  if filereadable(&amp;quot;./cscope.out&amp;quot;)&lt;br /&gt;
    cs add cscope.out&lt;br /&gt;
  elseif $CSCOPE_DB != &amp;quot;&amp;quot;&lt;br /&gt;
    if filereadable($CSCOPE_DB)&lt;br /&gt;
      cs add $CSCOPE_DB&lt;br /&gt;
    else&lt;br /&gt;
      echo &amp;quot;Can't read $CSCOPE_DB; cscope add not run&amp;quot;&lt;br /&gt;
    endif&lt;br /&gt;
  endif&lt;br /&gt;
  set csre&lt;br /&gt;
  set csverb&lt;br /&gt;
endif&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Ctags ==&lt;br /&gt;
Ctags generates an index of symbols that many editors can use to quickly navigate the source code. Though many Unices ship with a version installed at &amp;lt;code&amp;gt;/usr/bin/ctags&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;test_env.bash&amp;lt;/code&amp;gt; presumes that [http://ctags.sourceforge.net/ Exuberant Ctags] is installed.&lt;br /&gt;
&lt;br /&gt;
=== Vim Integration ===&lt;br /&gt;
Add this to your &amp;lt;code&amp;gt;.vimrc&amp;lt;/code&amp;gt; to take advantage of Ctags integration in vim (where &amp;lt;code&amp;gt;$TAGS_FILE&amp;lt;/code&amp;gt; is defined in &amp;lt;code&amp;gt;test/test_env.bash&amp;lt;/code&amp;gt;):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;quot; The tags path, as set below, will search the local file first, then the       &lt;br /&gt;
&amp;quot; project-wide file.&lt;br /&gt;
if $TAGS_FILE != &amp;quot;&amp;quot;                                                             &lt;br /&gt;
  if filereadable($TAGS_FILE)&lt;br /&gt;
    set tags+=$TAGS_FILE&lt;br /&gt;
  else                                                                          &lt;br /&gt;
    echo &amp;quot;Can't read $TAGS_FILE; tags not set&amp;quot;&lt;br /&gt;
  endif&lt;br /&gt;
endif&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== git-new-workdir ==&lt;br /&gt;
Usually installed as &amp;lt;code&amp;gt;/usr/local/share/git-core/contrib/workdir/git-new-workdir&amp;lt;/code&amp;gt;, this will create a new working directory for a specified branch that's linked to the original repository. This is nice when working on multiple branches in parallel, as it doesn't require committing or stashing changes before issuing a &amp;lt;code&amp;gt;git checkout&amp;lt;/code&amp;gt; to switch between branches. The following &amp;lt;code&amp;gt;bash&amp;lt;/code&amp;gt; function wraps &amp;lt;code&amp;gt;git-new-workdir&amp;lt;/code&amp;gt; to create a working dir called &amp;lt;code&amp;gt;reponame-branchname&amp;lt;/code&amp;gt; in the same directory as the original repository:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Creates a branch-specific git working directory in the same directory as the&lt;br /&gt;
# original repository.&lt;br /&gt;
git-new-workdir() {                                                             &lt;br /&gt;
  if test $# -ne 2; then&lt;br /&gt;
    echo &amp;quot;Usage: $FUNCNAME &amp;lt;git repo&amp;gt; &amp;lt;branch name&amp;gt;&amp;quot;                            &lt;br /&gt;
    return 1&lt;br /&gt;
  elif test ! -d $1; then&lt;br /&gt;
    echo &amp;quot;$1 does not exist&amp;quot;&lt;br /&gt;
    return 1&lt;br /&gt;
  fi&lt;br /&gt;
  new_workdir=$1-$2&lt;br /&gt;
  if /usr/local/share/git-core/contrib/workdir/git-new-workdir\&lt;br /&gt;
    $1 $new_workdir $2; then&lt;br /&gt;
    echo &amp;quot;Created $new_workdir&amp;quot;&lt;br /&gt;
  else&lt;br /&gt;
    return 1&lt;br /&gt;
  fi&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Note:''' On Ubuntu 14.04, &amp;lt;code&amp;gt;git-new-workdir&amp;lt;/code&amp;gt; is installed as part of the &amp;lt;code&amp;gt;git&amp;lt;/code&amp;gt; package as &amp;lt;code&amp;gt;/usr/share/doc/git/contrib/workdir/git-new-workdir&amp;lt;/code&amp;gt; and does not have execute permission by default.&lt;br /&gt;
&lt;br /&gt;
== tmux Terminal Multiplexer ==&lt;br /&gt;
[http://tmux.sourceforge.net/ The tmux terminal multiplexer] is helpful for using a single terminal window to efficiently manage different editing and build sessions, amongst many other useful functions. [http://pragprog.com/book/bhtmux/tmux tmux: Productive Mouse-Free Development] from The Pragmatic Bookshelf is a great primer.&lt;br /&gt;
&lt;br /&gt;
These are some helpful config options to add to &amp;lt;code&amp;gt;~/.tmux.conf&amp;lt;/code&amp;gt;, including getting GNU screen-like CTRL-a behavior:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set-option -g prefix C-a&lt;br /&gt;
unbind-key C-b&lt;br /&gt;
bind-key C-a send-prefix&lt;br /&gt;
&lt;br /&gt;
bind R source-file ~/.tmux.conf \; display &amp;quot;Reloaded ~/.tmux.conf&amp;quot;&lt;br /&gt;
set -g default-terminal &amp;quot;screen-256color&amp;quot;&lt;br /&gt;
set -g status-style fg=black,bg=colour7&lt;br /&gt;
setw -g window-status-style fg=default,bg=default,none&lt;br /&gt;
setw -g window-status-current-style fg=black,bg=colour15,bold&lt;br /&gt;
set -g pane-active-border-style fg=default,bg=colour7&lt;br /&gt;
set -g message-style fg=black,bg=colour11,bright&lt;br /&gt;
set -g status-utf8 on&lt;br /&gt;
setw -g monitor-activity on&lt;br /&gt;
set -g visual-activity on&lt;br /&gt;
&lt;br /&gt;
bind -r H resize-pane -L 5&lt;br /&gt;
bind -r J resize-pane -D 5&lt;br /&gt;
bind -r K resize-pane -U 5                                                      &lt;br /&gt;
bind -r L resize-pane -R 5&lt;br /&gt;
&lt;br /&gt;
# Enables nohup to work. From:&lt;br /&gt;
# https://github.com/ChrisJohnsen/tmux-MacOSX-pasteboard                        &lt;br /&gt;
set-option -g default-command &amp;quot;reattach-to-user-namespace -l $SHELL&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mbland</name></author>
	</entry>
	<entry>
		<id>https://wiki.openssl.org/index.php?title=Testing_and_Development_Tools_and_Tips&amp;diff=1784</id>
		<title>Testing and Development Tools and Tips</title>
		<link rel="alternate" type="text/html" href="https://wiki.openssl.org/index.php?title=Testing_and_Development_Tools_and_Tips&amp;diff=1784"/>
		<updated>2014-07-02T18:46:07Z</updated>

		<summary type="html">&lt;p&gt;Mbland: /* git-new-workdir */ Notice about git-new-workdir location on Ubuntu&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This is a collection of helpful tools and tips for navigating the OpenSSL code base and managing a local git repository.&lt;br /&gt;
&lt;br /&gt;
== Testing Environment and Tools ==&lt;br /&gt;
In [https://github.com/mbland/openssl/compare/test-util the test-util branch of Mike Bland's fork] are a few helper files that you may wish to copy or pull into your branch. As they are incorporated into the main OpenSSL repository, links to the mainline versions will be incorporated into the descriptions below. However, there may be newer versions in Mike's fork.&lt;br /&gt;
&lt;br /&gt;
=== test/testutil.h ===&lt;br /&gt;
[http://git.openssl.org/gitweb/?p=openssl.git;a=blob;f=test/testutil.h test/testutil.h] defines the generic &amp;lt;code&amp;gt;SETUP_TEST_FIXTURE&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;EXECUTE_TEST&amp;lt;/code&amp;gt; macros. The header comments describe how to define test-specific macros based on these.&lt;br /&gt;
&lt;br /&gt;
=== test/new-test.sh ===&lt;br /&gt;
[https://github.com/mbland/openssl/blob/test-util/test/new-test.sh test/new-test.sh (mbland's fork)] generates a new automated test stub, following [http://mike-bland.com/2014/06/05/pseudo-xunit-pattern.html the Pseudo-xUnit Pattern] and using the macros from &amp;lt;code&amp;gt;test/testutil.h&amp;lt;/code&amp;gt;. The generated stub will compile standalone.&lt;br /&gt;
&lt;br /&gt;
=== test/test_env.bash ===&lt;br /&gt;
[https://github.com/mbland/openssl/blob/test-util/test/test_env.bash test/test_env.bash (mbland's fork)]: contains environment variables, functions, and aliases to help with OpenSSL unit testing. The header comments contain documentation on each of the functions and aliases in the file.&lt;br /&gt;
&lt;br /&gt;
== Cscope ==&lt;br /&gt;
[http://cscope.sourceforge.net/ Cscope] is a powerful C source code browser. Once you have it installed, you can use the &amp;lt;code&amp;gt;make-cscope&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;open-cscope&amp;lt;/code&amp;gt; functions from &amp;lt;code&amp;gt;test/test_env.bash&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Vim Integration ===&lt;br /&gt;
Once &amp;lt;code&amp;gt;$CSCOPE_DB&amp;lt;/code&amp;gt; (defined in &amp;lt;code&amp;gt;test/test_env.bash&amp;lt;/code&amp;gt;) is built using &amp;lt;code&amp;gt;make-cscope&amp;lt;/code&amp;gt;, you can take advantage of the Cscope integration in Vim by adding something like the following to your &amp;lt;code&amp;gt;.vimrc&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;quot; Detect whether cscope features are present and whether we should add a&lt;br /&gt;
&amp;quot; connection to an existing cscope.out database file&lt;br /&gt;
if has(&amp;quot;cscope&amp;quot;)&lt;br /&gt;
  set nocsverb&lt;br /&gt;
  if filereadable(&amp;quot;./cscope.out&amp;quot;)&lt;br /&gt;
    cs add cscope.out&lt;br /&gt;
  elseif $CSCOPE_DB != &amp;quot;&amp;quot;&lt;br /&gt;
    if filereadable($CSCOPE_DB)&lt;br /&gt;
      cs add $CSCOPE_DB&lt;br /&gt;
    else&lt;br /&gt;
      echo &amp;quot;Can't read $CSCOPE_DB; cscope add not run&amp;quot;&lt;br /&gt;
    endif&lt;br /&gt;
  endif&lt;br /&gt;
  set csre&lt;br /&gt;
  set csverb&lt;br /&gt;
endif&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Ctags ==&lt;br /&gt;
Ctags generates an index of symbols that many editors can use to quickly navigate the source code. Though many Unices ship with a version installed at &amp;lt;code&amp;gt;/usr/bin/ctags&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;test_env.bash&amp;lt;/code&amp;gt; presumes that [http://ctags.sourceforge.net/ Exuberant Ctags] is installed.&lt;br /&gt;
&lt;br /&gt;
=== Vim Integration ===&lt;br /&gt;
Add this to your &amp;lt;code&amp;gt;.vimrc&amp;lt;/code&amp;gt; to take advantage of Ctags integration in vim (where &amp;lt;code&amp;gt;$TAGS_FILE&amp;lt;/code&amp;gt; is defined in &amp;lt;code&amp;gt;test/test_env.bash&amp;lt;/code&amp;gt;):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;quot; The tags path, as set below, will search the local file first, then the       &lt;br /&gt;
&amp;quot; project-wide file.&lt;br /&gt;
if $TAGS_FILE != &amp;quot;&amp;quot;                                                             &lt;br /&gt;
  if filereadable($TAGS_FILE)&lt;br /&gt;
    set tags+=$TAGS_FILE&lt;br /&gt;
  else                                                                          &lt;br /&gt;
    echo &amp;quot;Can't read $TAGS_FILE; tags not set&amp;quot;&lt;br /&gt;
  endif&lt;br /&gt;
endif&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== git-new-workdir ==&lt;br /&gt;
Usually installed as &amp;lt;code&amp;gt;/usr/local/share/git-core/contrib/workdir/git-new-workdir&amp;lt;/code&amp;gt;, this will create a new working directory for a specified branch that's linked to the original repository. This is nice when working on multiple branches in parallel, as it doesn't require committing or stashing changes before issuing a &amp;lt;code&amp;gt;git checkout&amp;lt;/code&amp;gt; to switch between branches. The following &amp;lt;code&amp;gt;bash&amp;lt;/code&amp;gt; function wraps &amp;lt;code&amp;gt;git-new-workdir&amp;lt;/code&amp;gt; to create a working dir called &amp;lt;code&amp;gt;reponame-branchname&amp;lt;/code&amp;gt; in the same directory as the original repository:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Creates a branch-specific git working directory in the same directory as the&lt;br /&gt;
# original repository.&lt;br /&gt;
git-new-workdir() {                                                             &lt;br /&gt;
  if test $# -ne 2; then&lt;br /&gt;
    echo &amp;quot;Usage: $FUNCNAME &amp;lt;git repo&amp;gt; &amp;lt;branch name&amp;gt;&amp;quot;                            &lt;br /&gt;
    return 1&lt;br /&gt;
  elif test ! -d $1; then&lt;br /&gt;
    echo &amp;quot;$1 does not exist&amp;quot;&lt;br /&gt;
    return 1&lt;br /&gt;
  fi&lt;br /&gt;
  new_workdir=$1-$2&lt;br /&gt;
  if /usr/local/share/git-core/contrib/workdir/git-new-workdir\&lt;br /&gt;
    $1 $new_workdir $2; then&lt;br /&gt;
    echo &amp;quot;Created $new_workdir&amp;quot;&lt;br /&gt;
  else&lt;br /&gt;
    return 1&lt;br /&gt;
  fi&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Note:''' On Ubuntu 14.04, &amp;lt;code&amp;gt;git-new-workdir&amp;lt;/code&amp;gt; is installed as part of the &amp;lt;code&amp;gt;git&amp;lt;/code&amp;gt; package as &amp;lt;code&amp;gt;/usr/share/doc/git/contrib/workdir/git-new-workdir&amp;lt;/code&amp;gt; and does not have execute permission by default.&lt;br /&gt;
&lt;br /&gt;
== tmux Terminal Multiplexer ==&lt;br /&gt;
[http://tmux.sourceforge.net/ The tmux terminal multiplexer] is helpful for using a single terminal window to efficiently manage different editing and build sessions, amongst many other useful functions. [http://pragprog.com/book/bhtmux/tmux tmux: Productive Mouse-Free Development] from The Pragmatic Bookshelf is a great primer.&lt;br /&gt;
&lt;br /&gt;
These are some helpful config options to add to &amp;lt;code&amp;gt;~/.tmux.conf&amp;lt;/code&amp;gt;, including getting GNU screen-like CTRL-a behavior:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set-option -g prefix C-a&lt;br /&gt;
unbind-key C-b&lt;br /&gt;
bind-key C-a send-prefix&lt;br /&gt;
&lt;br /&gt;
bind R source-file ~/.tmux.conf \; display &amp;quot;Reloaded ~/.tmux.conf&amp;quot;&lt;br /&gt;
set -g default-terminal &amp;quot;screen-256color&amp;quot;&lt;br /&gt;
set -g status-style fg=black,bg=colour7&lt;br /&gt;
setw -g window-status-style fg=default,bg=default,none&lt;br /&gt;
setw -g window-status-current-style fg=black,bg=colour15,bold&lt;br /&gt;
set -g pane-active-border-style fg=default,bg=colour7&lt;br /&gt;
set -g message-style fg=black,bg=colour11,bright&lt;br /&gt;
set -g status-utf8 on&lt;br /&gt;
setw -g monitor-activity on&lt;br /&gt;
set -g visual-activity on&lt;br /&gt;
&lt;br /&gt;
bind -r H resize-pane -L 5&lt;br /&gt;
bind -r J resize-pane -D 5&lt;br /&gt;
bind -r K resize-pane -U 5                                                      &lt;br /&gt;
bind -r L resize-pane -R 5&lt;br /&gt;
&lt;br /&gt;
# Enables nohup to work. From:&lt;br /&gt;
# https://github.com/ChrisJohnsen/tmux-MacOSX-pasteboard                        &lt;br /&gt;
set-option -g default-command &amp;quot;reattach-to-user-namespace -l $SHELL&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mbland</name></author>
	</entry>
	<entry>
		<id>https://wiki.openssl.org/index.php?title=Unit_Testing&amp;diff=1771</id>
		<title>Unit Testing</title>
		<link rel="alternate" type="text/html" href="https://wiki.openssl.org/index.php?title=Unit_Testing&amp;diff=1771"/>
		<updated>2014-06-26T18:32:10Z</updated>

		<summary type="html">&lt;p&gt;Mbland: /* Tech Writer */ Add Lisa Carey to the Tech Writer team! :-)&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page will track the effort to improve unit test and other automated test coverage for OpenSSL. Everyone is encouraged to help with this effort, but this page will track which community members have accepted specific responsibilities, and what tasks are currently underway.&lt;br /&gt;
&lt;br /&gt;
== Goals ==&lt;br /&gt;
&lt;br /&gt;
The goals of this project are:&lt;br /&gt;
&lt;br /&gt;
* Establish a written contribution/code review policy that requires:&lt;br /&gt;
** tests for every new code change, except for very trivial changes that do not directly impact program logic (e.g. documentation fixes, string constant updates, build script tweaks); this can be limited to an agreed-upon subset of the code to start, but would hopefully be expanded to cover most, if not all, of the code base&lt;br /&gt;
** tests for every bugfix &lt;br /&gt;
** smaller, well-tested changes building up to a complete feature (as opposed to large and/or untested changes that implement a large, complex feature all at once) &lt;br /&gt;
* Establish a schedule of Build Cops and Tutors to begin enforcing rollbacks/fixes and to help shepherd new contributors through the testing process.&lt;br /&gt;
* Set up a series of publicly-accessible continuous integration servers using whatever system the community prefers (e.g. Jenkins, Buildbot, etc.). These can be dedicated hardware or possibly Amazon Web Services-based. Establish a written policy that these remain green at all times, and that breakages be rolled-back or fixed within no more than 30 minutes.&lt;br /&gt;
&lt;br /&gt;
We can add more concrete goals to this list after we make progress on these. Getting people to own roles, setting up build infrastructure, and setting and enforcing policy are important first steps. Upon that foundation, we can begin to make serious progress towards improved test coverage, code quality, and defect prevention.&lt;br /&gt;
&lt;br /&gt;
== Discussion List ==&lt;br /&gt;
[https://groups.google.com/d/forum/openssl-testing openssl-testing] is the mailing list dedicated to the unit/automated testing effort, to avoid clogging openssl-dev. Membership is open to whoever wishes to join, even if only to lurk. Ideally all testing discussions will eventually move to openssl-dev once we have processes, tools, conventions, etc. in place.&lt;br /&gt;
&lt;br /&gt;
== Team ==&lt;br /&gt;
&lt;br /&gt;
We can define new roles as needed. The success of this effort will be inversely proportional to the number of roles with any one individual's name next to them. Each role can have more than one person filling it, but needs specific people to fill them. &lt;br /&gt;
&lt;br /&gt;
The point is not to tell people what to do and not do: it’s to establish clear responsibilities so everyone can run with them right away and begin applying their creative energy to solutions, rather than waste it figuring out what the hell is going on, what they should do to contribute, and who they need to coordinate with to get things done.&lt;br /&gt;
&lt;br /&gt;
=== Organizer===&lt;br /&gt;
&lt;br /&gt;
Contact: [mailto:mbland@acm.org Mike Bland]&lt;br /&gt;
&lt;br /&gt;
Ensures the overall effort is making progress by facilitating communication, removing obstacles, and making hands-on contributions when necessary.&lt;br /&gt;
&lt;br /&gt;
=== Tech Writer ===&lt;br /&gt;
&lt;br /&gt;
Contacts: [mailto:mbland@acm.org Mike Bland], Sandeep Mankar, Chelsea Komlo, Graham Brooks, Lisa Carey&lt;br /&gt;
&lt;br /&gt;
Maintains documentation of tools, techniques, outstanding issues, etc. May maintain a code review/testing style guide based on the community consensus. Also documents who currently fills each role, as well as who might've filled it in the past.&lt;br /&gt;
&lt;br /&gt;
=== Buildmaster ===&lt;br /&gt;
&lt;br /&gt;
Contacts:  [mailto:mbland@acm.org Mike Bland], Isaac Truett, Dileep Bapat, Graham Brooks&lt;br /&gt;
&lt;br /&gt;
Sets up and maintains automated builds and any infrastructure used to monitor them and report breakage.&lt;br /&gt;
&lt;br /&gt;
=== Toolsmith ===&lt;br /&gt;
&lt;br /&gt;
Contact: Tony Aiuto&lt;br /&gt;
&lt;br /&gt;
Maintains any tools and frameworks that are a part of the core build process; proposes, integrates, and/or retires existing tools.&lt;br /&gt;
&lt;br /&gt;
=== Tutor ===&lt;br /&gt;
&lt;br /&gt;
Contacts: [mailto:mbland@acm.org Mike Bland], Darshan Mody, Tom Francis, Brian N. Makin, Edward Knapp, Dileep Bapat, Graham Brooks&lt;br /&gt;
&lt;br /&gt;
Helps contributors, particularly new contributors, with the details of writing unit or other automated tests. May be assigned by the reviewer of a patch to help a contributor get a new change under test. Submission of the patch should require the approval of the tutor in most cases. (Should ideally be more than one person.)&lt;br /&gt;
&lt;br /&gt;
== Tasks ==&lt;br /&gt;
The current list is posted in the [http://goo.gl/5u9nbw OpenSSL Testing Tasks Google Spreadsheet].&lt;br /&gt;
&lt;br /&gt;
(Would be nice to enable the [http://www.mediawiki.org/wiki/Extension:Widget MediaWiki Widget extension] and the [http://www.mediawikiwidgets.org/Google_Spreadsheet Google Spreadsheet widget].)&lt;br /&gt;
&lt;br /&gt;
== Howtos and Style Guides ==&lt;br /&gt;
Documents that provide background on specific testing issues and idioms should be linked from here.&lt;br /&gt;
&lt;br /&gt;
* [[How To Write Unit Tests For OpenSSL]]&lt;br /&gt;
* [http://mike-bland.com/2014/06/05/pseudo-xunit-pattern.html The Pseudo-xUnit Pattern]&lt;br /&gt;
* [[Testing and Development Tools and Tips]]&lt;br /&gt;
&lt;br /&gt;
== Discussion Topics ==&lt;br /&gt;
These are discussions related to some of the current testing tasks.&lt;br /&gt;
&lt;br /&gt;
=== First Area of Focus ===&lt;br /&gt;
Matt Caswell: One criterion might be ease of testing. If you were going down that route you might choose some of the low level packages within libcrypto which are relatively self-contained. I'm not talking about the crypto algorithms themselves (there are at least *some* tests for those), I'm thinking more about bio, pem, x509, x509v3, etc.&lt;br /&gt;
&lt;br /&gt;
Another criterion might be where you get the most value. I suspect we will get the most value from a really good set of unit tests for libssl. I suspect this might be a big ask to start off with (you would probably have to mock out a lot of stuff).&lt;br /&gt;
&lt;br /&gt;
=== Build Systems/Machines ===&lt;br /&gt;
Where can we get the machines? Is someone willing to donate them? What system should we use?&lt;br /&gt;
&lt;br /&gt;
=== Get Unit Tests to Build on Windows ===&lt;br /&gt;
Steve Henson on building ssl/heartbeat_test.c on Windows: The first problem is that __func__ isn't understood. Changing that to __FUNCTION__ resolves that easily enough.&lt;br /&gt;
&lt;br /&gt;
The second problem is more serious. Windows (and a couple of other platforms IIRC) is strict about only exporting approved symbols from global headers in shared libraries and wont export internal only functions.&lt;br /&gt;
&lt;br /&gt;
That means you get linker errors:&lt;br /&gt;
&lt;br /&gt;
heartbeat_test.obj : error LNK2019: unresolved external symbol _ssl3_setup_buffe&lt;br /&gt;
rs referenced in function _set_up&lt;br /&gt;
heartbeat_test.obj : error LNK2019: unresolved external symbol _ssl_init_wbio_bu&lt;br /&gt;
ffer referenced in function _set_up&lt;br /&gt;
heartbeat_test.obj : error LNK2019: unresolved external symbol _tls1_process_hea&lt;br /&gt;
rtbeat referenced in function _set_up_tls&lt;br /&gt;
heartbeat_test.obj : error LNK2019: unresolved external symbol _dtls1_process_he&lt;br /&gt;
artbeat referenced in function _set_up_dtls&lt;br /&gt;
out32dll\heartbeat_test.exe : fatal error LNK1120: 4 unresolved externals&lt;br /&gt;
NMAKE : fatal error U1077: '&amp;quot;C:\Program Files (x86)\Microsoft Visual Studio 11.0&lt;br /&gt;
\VC\BIN\link.EXE&amp;quot;' : return code '0x460'&lt;br /&gt;
&lt;br /&gt;
Potential solutions:&lt;br /&gt;
* http://stackoverflow.com/questions/7759777/is-it-possible-to-test-internal-class-from-a-c-dll-using-mstest&lt;br /&gt;
* http://stackoverflow.com/questions/19934714/googletest-c-unit-testing-linking-error&lt;br /&gt;
* http://stackoverflow.com/questions/14010627/unresolved-externals-when-compiling-unit-tests-for-visual-c-2012&lt;br /&gt;
&lt;br /&gt;
ifdef'd out (for now): https://github.com/openssl/openssl/commit/7ce79a5bfdbcd53ae75f85e94eed665a05b5dea3&lt;br /&gt;
&lt;br /&gt;
=== How to Manage Private Symbols ===&lt;br /&gt;
Steve Henson: As this also affects other platforms a general solution might be in order.&lt;br /&gt;
&lt;br /&gt;
One option is to link to static libraries as has been mentioned. If you have a&lt;br /&gt;
lot of unit tests you could end up with a lot of large binaries. Would need some&lt;br /&gt;
changes to the dreaded Windows build system too.&lt;br /&gt;
&lt;br /&gt;
A different option would be to export the unit test functions through a&lt;br /&gt;
structure pointer which a function returns. So you'd have something like..&lt;br /&gt;
&lt;br /&gt;
unit_test = SSL_get_unit_test_funcs();&lt;br /&gt;
&lt;br /&gt;
unit_test.some_internal_funcction(...);&lt;br /&gt;
&lt;br /&gt;
Where the actual structure is opaque to applications (so they aren't tempted to&lt;br /&gt;
poke around in internals) but visible to the unit test code. Then the unit test&lt;br /&gt;
code doesn't call any internal functions not defined in there and doesn't need&lt;br /&gt;
to load private headers (unless it needs them for some definitions).&lt;br /&gt;
&lt;br /&gt;
Mike Bland: This is an interesting idea, though I'd expect the unit tests will&lt;br /&gt;
still need access to internal headers.&lt;br /&gt;
&lt;br /&gt;
But I have a question: Why do any of the symbols need to be private?&lt;br /&gt;
Is that degree of encapsulation necessary, and does it really&lt;br /&gt;
discourage irresponsible clients? The source code is open, so people&lt;br /&gt;
can always build their own copy and depend on internals if they really&lt;br /&gt;
want to, and the default UNIX/Linux/OS X build (i.e. ./configure &amp;amp;&amp;amp;&lt;br /&gt;
make &amp;amp;&amp;amp; make test) doesn't lock down internal symbols. Have&lt;br /&gt;
dependencies on internal APIs ever been a problem in practice?&lt;br /&gt;
&lt;br /&gt;
I'm not saying I feel strongly either way, but it seems that clients&lt;br /&gt;
should be clear that the public API is what's available in&lt;br /&gt;
openssl/include, and shouldn't depend on anything else. I just don't&lt;br /&gt;
understand what making symbols private buys anyone in the context of&lt;br /&gt;
OpenSSL, in light of how it appears to complicate the ability to unit&lt;br /&gt;
test.&lt;br /&gt;
&lt;br /&gt;
Not trying to be argumentative, I just want to understand the&lt;br /&gt;
rationale. I'll work with whatever environment I have to.&lt;br /&gt;
&lt;br /&gt;
Tom Francis: Making the symbols private allows the link editors on Windows and pretty much every UNIX system that doesn't use GNU ld to:&lt;br /&gt;
1) Run much, much faster at link time (not a minor consideration for most of the software I've worked on); and&lt;br /&gt;
2) optimize the final binary to load much faster.&lt;br /&gt;
Last time I checked, there was a minor improvement for GNU ld for #1, but it's trivial compared to Windows and HP's link editor, e.g. (I can't overstate the difference there).  The runtime improvement is also dramatic on Windows, HP-UX, and AIX (we're talking tens for milliseconds for libraries that are much smaller than OpenSSL -- never tried it with OpenSSL, too lazy to mark everything, after having just done so for the library I was really interested in).&lt;br /&gt;
&lt;br /&gt;
If you want to avoid a bunch of small binaries, you could combine all the unit tests into a single test application, and use multiple runs of it for each test, similar to how the openssl binary is created; if you link the object files directly (or a static library), you avoid the private symbols issue.  Of course, this may be an issue for some of the embedded systems, where the loading a large binary for running the tests might not be acceptable (but might be preferable to a bunch of binaries?).  Mike Bland was concerned about parallelization, and for any kind of automated tests on commits, that's a big point, if you can guarantee that each system only compiles/executes a limited number of tests (it could be useful for OS vendors, too).  For the average OpenSSL user, that's not really a consideration; an average user is more likely concerned with how long (wall clock) it takes to compile and run the tests, and depending on the size of a single binary v the size of each smaller binary, it'll vary from system to system (generally, it'll be many times faster to create a single large binary than a few hundred smaller binaries, but the larger the binary, the longer it takes to load -- at some point, the load time might well outweigh the hundreds of smaller binaries (assuming you execute the large binary several times, rather than have a method for it to execute all tests in a single go).  That point is probably &amp;gt; 100MB for larger systems, but for an embedded system, it could be much smaller.&lt;br /&gt;
&lt;br /&gt;
For Steve's second suggestion, I think my biggest concerns would be how to logically separate out a unit test method without including the test framework (maybe throw it all in there?).  I kinda like the idea of keeping the test inside the libraries, but I'm not sure why -- maybe 'cause I recently spent a few months back in a java world, where it's normal to throw all your unit tests into the same jar for production.  I'm not sure I like that, though.  The overhead of a single function per &amp;quot;module&amp;quot; added to the exports is also unlikely to drastically decrease link-time or run-time performance, too (compared with exporting everything).&lt;br /&gt;
&lt;br /&gt;
=== Improved Patch/Cherry-pick Process ===&lt;br /&gt;
Geoff Thorpe: (a) patches that are not applied/cherry-picked to all the branches they apply to, or (b) applied to more branches than they should be. A complication of (a) is that some patches may need to be reworked in order to apply (or in order to not break binary compatibility of a stable branch). The difficulty of (b) is determining when the nature of the change either breaks binary compatibility or causes some other behavioral deviation that is not in keeping with the &amp;quot;promises&amp;quot; of stable branches.&lt;br /&gt;
&lt;br /&gt;
http://ispras.linuxbase.org/index.php/ABI_compliance_checker&lt;br /&gt;
https://github.com/lvc/abi-compliance-checker/&lt;br /&gt;
&lt;br /&gt;
Geoff on 2014-05-30: ...we might move to a scheme whereby we only maintain one most-recent stable branch for production releases, with snapshots or whatever of the development head. Ie. two branches, one for maximum-compatibility/bug-fixes-only, and the other for more active development. The number of &amp;quot;stable&amp;quot; branches would thus be 1 rather than 'n'. The idea is that we may defer to downstream &amp;quot;slow-moving&amp;quot; users (eg. long-term releases of linux distros) the opportunity to step up and do the work of maintaining (cherry-picking, back-porting, ...) older branches. Ie. what they typically already do in-house, but the opportunity to do it under our roof and thus combine their efforts with any other similarly-interested parties. If there's noone prepared to do that, the logical conclusion is that there is probably no need for it (or so the argument goes).&lt;br /&gt;
&lt;br /&gt;
=== Improve/Standardize Algorithm Testing ===&lt;br /&gt;
Steve Henson: While the algorithms are partly tested I don't think they're anything like comprehensive enough. The way they are handled is also haphazard and spread across multiple tests covering all sorts of odd APIs, some of which are deprecated.&lt;br /&gt;
&lt;br /&gt;
In fact I'd say they're (with the odd exception) an example of how *not* to do things.&lt;br /&gt;
&lt;br /&gt;
Examples rc2test tests RC2 it has various test vectors hard coded inconsistent indentation and use of low level APIs. The rc4test is a similar story and uses a different format to rc2test. The same tale is repeated all over the place with ideatest, rmdtest etc etc.&lt;br /&gt;
&lt;br /&gt;
Then we come to the code which I think is closest to how things should be which is evp_test. It uses the standard high level EVP API the format is consistent (if undocumented) and adding new tests can be done simply by editing a text file.&lt;br /&gt;
&lt;br /&gt;
It currently however only works for some algorithms and the text file format could be better. It currently doesn't handle public key algorithms or test variants of the same algorithm (e.g. AES-NI versus non AES-NI) either.&lt;br /&gt;
&lt;br /&gt;
=== Develop SSL/TLS Stack and Other Tools ===&lt;br /&gt;
Steve Henson: The heartbeat bug is an example where you can perform some testing without a complete SSL/TLS stack. However looking through the code in heartbeat_test.c it uses a lot of functionality which would normally be strictly off-limits for an application.&lt;br /&gt;
&lt;br /&gt;
Some bugs are far more subtle and harder to test. For example some involve doing *almost* everything right and then slipping in some illegal parameter or badly formatted message. If you want to do that in a standalone bit of code you need a near complete SSL/TLS stack.&lt;br /&gt;
&lt;br /&gt;
I can think of a couple of ways to handle that. One is to have some kind of hooks in libssl so testing code can misbehave and send out illegal messages in controlled ways (I had a prototype &amp;quot;bad heartbeat&amp;quot; API which only added a couple of lines to libssl). An alternative would be to write some kind of tiny SSL/TLS code used only by the test programs and carefully tailored to permit such things.&lt;/div&gt;</summary>
		<author><name>Mbland</name></author>
	</entry>
	<entry>
		<id>https://wiki.openssl.org/index.php?title=Testing_and_Development_Tools_and_Tips&amp;diff=1770</id>
		<title>Testing and Development Tools and Tips</title>
		<link rel="alternate" type="text/html" href="https://wiki.openssl.org/index.php?title=Testing_and_Development_Tools_and_Tips&amp;diff=1770"/>
		<updated>2014-06-25T13:56:47Z</updated>

		<summary type="html">&lt;p&gt;Mbland: /* test/new-test.sh */ Fix new-test.sh link&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This is a collection of helpful tools and tips for navigating the OpenSSL code base and managing a local git repository.&lt;br /&gt;
&lt;br /&gt;
== Testing Environment and Tools ==&lt;br /&gt;
In [https://github.com/mbland/openssl/compare/test-util the test-util branch of Mike Bland's fork] are a few helper files that you may wish to copy or pull into your branch. As they are incorporated into the main OpenSSL repository, links to the mainline versions will be incorporated into the descriptions below. However, there may be newer versions in Mike's fork.&lt;br /&gt;
&lt;br /&gt;
=== test/testutil.h ===&lt;br /&gt;
[http://git.openssl.org/gitweb/?p=openssl.git;a=blob;f=test/testutil.h test/testutil.h] defines the generic &amp;lt;code&amp;gt;SETUP_TEST_FIXTURE&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;EXECUTE_TEST&amp;lt;/code&amp;gt; macros. The header comments describe how to define test-specific macros based on these.&lt;br /&gt;
&lt;br /&gt;
=== test/new-test.sh ===&lt;br /&gt;
[https://github.com/mbland/openssl/blob/test-util/test/new-test.sh test/new-test.sh (mbland's fork)] generates a new automated test stub, following [http://mike-bland.com/2014/06/05/pseudo-xunit-pattern.html the Pseudo-xUnit Pattern] and using the macros from &amp;lt;code&amp;gt;test/testutil.h&amp;lt;/code&amp;gt;. The generated stub will compile standalone.&lt;br /&gt;
&lt;br /&gt;
=== test/test_env.bash ===&lt;br /&gt;
[https://github.com/mbland/openssl/blob/test-util/test/test_env.bash test/test_env.bash (mbland's fork)]: contains environment variables, functions, and aliases to help with OpenSSL unit testing. The header comments contain documentation on each of the functions and aliases in the file.&lt;br /&gt;
&lt;br /&gt;
== Cscope ==&lt;br /&gt;
[http://cscope.sourceforge.net/ Cscope] is a powerful C source code browser. Once you have it installed, you can use the &amp;lt;code&amp;gt;make-cscope&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;open-cscope&amp;lt;/code&amp;gt; functions from &amp;lt;code&amp;gt;test/test_env.bash&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Vim Integration ===&lt;br /&gt;
Once &amp;lt;code&amp;gt;$CSCOPE_DB&amp;lt;/code&amp;gt; (defined in &amp;lt;code&amp;gt;test/test_env.bash&amp;lt;/code&amp;gt;) is built using &amp;lt;code&amp;gt;make-cscope&amp;lt;/code&amp;gt;, you can take advantage of the Cscope integration in Vim by adding something like the following to your &amp;lt;code&amp;gt;.vimrc&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;quot; Detect whether cscope features are present and whether we should add a&lt;br /&gt;
&amp;quot; connection to an existing cscope.out database file&lt;br /&gt;
if has(&amp;quot;cscope&amp;quot;)&lt;br /&gt;
  set nocsverb&lt;br /&gt;
  if filereadable(&amp;quot;./cscope.out&amp;quot;)&lt;br /&gt;
    cs add cscope.out&lt;br /&gt;
  elseif $CSCOPE_DB != &amp;quot;&amp;quot;&lt;br /&gt;
    if filereadable($CSCOPE_DB)&lt;br /&gt;
      cs add $CSCOPE_DB&lt;br /&gt;
    else&lt;br /&gt;
      echo &amp;quot;Can't read $CSCOPE_DB; cscope add not run&amp;quot;&lt;br /&gt;
    endif&lt;br /&gt;
  endif&lt;br /&gt;
  set csre&lt;br /&gt;
  set csverb&lt;br /&gt;
endif&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Ctags ==&lt;br /&gt;
Ctags generates an index of symbols that many editors can use to quickly navigate the source code. Though many Unices ship with a version installed at &amp;lt;code&amp;gt;/usr/bin/ctags&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;test_env.bash&amp;lt;/code&amp;gt; presumes that [http://ctags.sourceforge.net/ Exuberant Ctags] is installed.&lt;br /&gt;
&lt;br /&gt;
=== Vim Integration ===&lt;br /&gt;
Add this to your &amp;lt;code&amp;gt;.vimrc&amp;lt;/code&amp;gt; to take advantage of Ctags integration in vim (where &amp;lt;code&amp;gt;$TAGS_FILE&amp;lt;/code&amp;gt; is defined in &amp;lt;code&amp;gt;test/test_env.bash&amp;lt;/code&amp;gt;):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;quot; The tags path, as set below, will search the local file first, then the       &lt;br /&gt;
&amp;quot; project-wide file.&lt;br /&gt;
if $TAGS_FILE != &amp;quot;&amp;quot;                                                             &lt;br /&gt;
  if filereadable($TAGS_FILE)&lt;br /&gt;
    set tags+=$TAGS_FILE&lt;br /&gt;
  else                                                                          &lt;br /&gt;
    echo &amp;quot;Can't read $TAGS_FILE; tags not set&amp;quot;&lt;br /&gt;
  endif&lt;br /&gt;
endif&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== git-new-workdir ==&lt;br /&gt;
Usually installed as &amp;lt;code&amp;gt;/usr/local/share/git-core/contrib/workdir/git-new-workdir&amp;lt;/code&amp;gt;, this will create a new working directory for a specified branch that's linked to the original repository. This is nice when working on multiple branches in parallel, as it doesn't require committing or stashing changes before issuing a &amp;lt;code&amp;gt;git checkout&amp;lt;/code&amp;gt; to switch between branches. The following &amp;lt;code&amp;gt;bash&amp;lt;/code&amp;gt; function wraps &amp;lt;code&amp;gt;git-new-workdir&amp;lt;/code&amp;gt; to create a working dir called &amp;lt;code&amp;gt;reponame-branchname&amp;lt;/code&amp;gt; in the same directory as the original repository:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Creates a branch-specific git working directory in the same directory as the&lt;br /&gt;
# original repository.&lt;br /&gt;
git-new-workdir() {                                                             &lt;br /&gt;
  if test $# -ne 2; then&lt;br /&gt;
    echo &amp;quot;Usage: $FUNCNAME &amp;lt;git repo&amp;gt; &amp;lt;branch name&amp;gt;&amp;quot;                            &lt;br /&gt;
    return 1&lt;br /&gt;
  elif test ! -d $1; then&lt;br /&gt;
    echo &amp;quot;$1 does not exist&amp;quot;&lt;br /&gt;
    return 1&lt;br /&gt;
  fi&lt;br /&gt;
  new_workdir=$1-$2&lt;br /&gt;
  if /usr/local/share/git-core/contrib/workdir/git-new-workdir\&lt;br /&gt;
    $1 $new_workdir $2; then&lt;br /&gt;
    echo &amp;quot;Created $new_workdir&amp;quot;&lt;br /&gt;
  else&lt;br /&gt;
    return 1&lt;br /&gt;
  fi&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== tmux Terminal Multiplexer ==&lt;br /&gt;
[http://tmux.sourceforge.net/ The tmux terminal multiplexer] is helpful for using a single terminal window to efficiently manage different editing and build sessions, amongst many other useful functions. [http://pragprog.com/book/bhtmux/tmux tmux: Productive Mouse-Free Development] from The Pragmatic Bookshelf is a great primer.&lt;br /&gt;
&lt;br /&gt;
These are some helpful config options to add to &amp;lt;code&amp;gt;~/.tmux.conf&amp;lt;/code&amp;gt;, including getting GNU screen-like CTRL-a behavior:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set-option -g prefix C-a&lt;br /&gt;
unbind-key C-b&lt;br /&gt;
bind-key C-a send-prefix&lt;br /&gt;
&lt;br /&gt;
bind R source-file ~/.tmux.conf \; display &amp;quot;Reloaded ~/.tmux.conf&amp;quot;&lt;br /&gt;
set -g default-terminal &amp;quot;screen-256color&amp;quot;&lt;br /&gt;
set -g status-style fg=black,bg=colour7&lt;br /&gt;
setw -g window-status-style fg=default,bg=default,none&lt;br /&gt;
setw -g window-status-current-style fg=black,bg=colour15,bold&lt;br /&gt;
set -g pane-active-border-style fg=default,bg=colour7&lt;br /&gt;
set -g message-style fg=black,bg=colour11,bright&lt;br /&gt;
set -g status-utf8 on&lt;br /&gt;
setw -g monitor-activity on&lt;br /&gt;
set -g visual-activity on&lt;br /&gt;
&lt;br /&gt;
bind -r H resize-pane -L 5&lt;br /&gt;
bind -r J resize-pane -D 5&lt;br /&gt;
bind -r K resize-pane -U 5                                                      &lt;br /&gt;
bind -r L resize-pane -R 5&lt;br /&gt;
&lt;br /&gt;
# Enables nohup to work. From:&lt;br /&gt;
# https://github.com/ChrisJohnsen/tmux-MacOSX-pasteboard                        &lt;br /&gt;
set-option -g default-command &amp;quot;reattach-to-user-namespace -l $SHELL&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mbland</name></author>
	</entry>
	<entry>
		<id>https://wiki.openssl.org/index.php?title=Testing_and_Development_Tools_and_Tips&amp;diff=1769</id>
		<title>Testing and Development Tools and Tips</title>
		<link rel="alternate" type="text/html" href="https://wiki.openssl.org/index.php?title=Testing_and_Development_Tools_and_Tips&amp;diff=1769"/>
		<updated>2014-06-25T13:56:14Z</updated>

		<summary type="html">&lt;p&gt;Mbland: /* Testing Environment and Tools */ Add links to test scripts in mbland's test-util fork on GitHub&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This is a collection of helpful tools and tips for navigating the OpenSSL code base and managing a local git repository.&lt;br /&gt;
&lt;br /&gt;
== Testing Environment and Tools ==&lt;br /&gt;
In [https://github.com/mbland/openssl/compare/test-util the test-util branch of Mike Bland's fork] are a few helper files that you may wish to copy or pull into your branch. As they are incorporated into the main OpenSSL repository, links to the mainline versions will be incorporated into the descriptions below. However, there may be newer versions in Mike's fork.&lt;br /&gt;
&lt;br /&gt;
=== test/testutil.h ===&lt;br /&gt;
[http://git.openssl.org/gitweb/?p=openssl.git;a=blob;f=test/testutil.h test/testutil.h] defines the generic &amp;lt;code&amp;gt;SETUP_TEST_FIXTURE&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;EXECUTE_TEST&amp;lt;/code&amp;gt; macros. The header comments describe how to define test-specific macros based on these.&lt;br /&gt;
&lt;br /&gt;
=== test/new-test.sh ===&lt;br /&gt;
[https://github.com/mbland/openssl/blob/test-util/test/test_env.bash test/new-test.sh (mbland's fork)] generates a new automated test stub, following [http://mike-bland.com/2014/06/05/pseudo-xunit-pattern.html the Pseudo-xUnit Pattern] and using the macros from &amp;lt;code&amp;gt;test/testutil.h&amp;lt;/code&amp;gt;. The generated stub will compile standalone.&lt;br /&gt;
&lt;br /&gt;
=== test/test_env.bash ===&lt;br /&gt;
[https://github.com/mbland/openssl/blob/test-util/test/test_env.bash test/test_env.bash (mbland's fork)]: contains environment variables, functions, and aliases to help with OpenSSL unit testing. The header comments contain documentation on each of the functions and aliases in the file.&lt;br /&gt;
&lt;br /&gt;
== Cscope ==&lt;br /&gt;
[http://cscope.sourceforge.net/ Cscope] is a powerful C source code browser. Once you have it installed, you can use the &amp;lt;code&amp;gt;make-cscope&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;open-cscope&amp;lt;/code&amp;gt; functions from &amp;lt;code&amp;gt;test/test_env.bash&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Vim Integration ===&lt;br /&gt;
Once &amp;lt;code&amp;gt;$CSCOPE_DB&amp;lt;/code&amp;gt; (defined in &amp;lt;code&amp;gt;test/test_env.bash&amp;lt;/code&amp;gt;) is built using &amp;lt;code&amp;gt;make-cscope&amp;lt;/code&amp;gt;, you can take advantage of the Cscope integration in Vim by adding something like the following to your &amp;lt;code&amp;gt;.vimrc&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;quot; Detect whether cscope features are present and whether we should add a&lt;br /&gt;
&amp;quot; connection to an existing cscope.out database file&lt;br /&gt;
if has(&amp;quot;cscope&amp;quot;)&lt;br /&gt;
  set nocsverb&lt;br /&gt;
  if filereadable(&amp;quot;./cscope.out&amp;quot;)&lt;br /&gt;
    cs add cscope.out&lt;br /&gt;
  elseif $CSCOPE_DB != &amp;quot;&amp;quot;&lt;br /&gt;
    if filereadable($CSCOPE_DB)&lt;br /&gt;
      cs add $CSCOPE_DB&lt;br /&gt;
    else&lt;br /&gt;
      echo &amp;quot;Can't read $CSCOPE_DB; cscope add not run&amp;quot;&lt;br /&gt;
    endif&lt;br /&gt;
  endif&lt;br /&gt;
  set csre&lt;br /&gt;
  set csverb&lt;br /&gt;
endif&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Ctags ==&lt;br /&gt;
Ctags generates an index of symbols that many editors can use to quickly navigate the source code. Though many Unices ship with a version installed at &amp;lt;code&amp;gt;/usr/bin/ctags&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;test_env.bash&amp;lt;/code&amp;gt; presumes that [http://ctags.sourceforge.net/ Exuberant Ctags] is installed.&lt;br /&gt;
&lt;br /&gt;
=== Vim Integration ===&lt;br /&gt;
Add this to your &amp;lt;code&amp;gt;.vimrc&amp;lt;/code&amp;gt; to take advantage of Ctags integration in vim (where &amp;lt;code&amp;gt;$TAGS_FILE&amp;lt;/code&amp;gt; is defined in &amp;lt;code&amp;gt;test/test_env.bash&amp;lt;/code&amp;gt;):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;quot; The tags path, as set below, will search the local file first, then the       &lt;br /&gt;
&amp;quot; project-wide file.&lt;br /&gt;
if $TAGS_FILE != &amp;quot;&amp;quot;                                                             &lt;br /&gt;
  if filereadable($TAGS_FILE)&lt;br /&gt;
    set tags+=$TAGS_FILE&lt;br /&gt;
  else                                                                          &lt;br /&gt;
    echo &amp;quot;Can't read $TAGS_FILE; tags not set&amp;quot;&lt;br /&gt;
  endif&lt;br /&gt;
endif&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== git-new-workdir ==&lt;br /&gt;
Usually installed as &amp;lt;code&amp;gt;/usr/local/share/git-core/contrib/workdir/git-new-workdir&amp;lt;/code&amp;gt;, this will create a new working directory for a specified branch that's linked to the original repository. This is nice when working on multiple branches in parallel, as it doesn't require committing or stashing changes before issuing a &amp;lt;code&amp;gt;git checkout&amp;lt;/code&amp;gt; to switch between branches. The following &amp;lt;code&amp;gt;bash&amp;lt;/code&amp;gt; function wraps &amp;lt;code&amp;gt;git-new-workdir&amp;lt;/code&amp;gt; to create a working dir called &amp;lt;code&amp;gt;reponame-branchname&amp;lt;/code&amp;gt; in the same directory as the original repository:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Creates a branch-specific git working directory in the same directory as the&lt;br /&gt;
# original repository.&lt;br /&gt;
git-new-workdir() {                                                             &lt;br /&gt;
  if test $# -ne 2; then&lt;br /&gt;
    echo &amp;quot;Usage: $FUNCNAME &amp;lt;git repo&amp;gt; &amp;lt;branch name&amp;gt;&amp;quot;                            &lt;br /&gt;
    return 1&lt;br /&gt;
  elif test ! -d $1; then&lt;br /&gt;
    echo &amp;quot;$1 does not exist&amp;quot;&lt;br /&gt;
    return 1&lt;br /&gt;
  fi&lt;br /&gt;
  new_workdir=$1-$2&lt;br /&gt;
  if /usr/local/share/git-core/contrib/workdir/git-new-workdir\&lt;br /&gt;
    $1 $new_workdir $2; then&lt;br /&gt;
    echo &amp;quot;Created $new_workdir&amp;quot;&lt;br /&gt;
  else&lt;br /&gt;
    return 1&lt;br /&gt;
  fi&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== tmux Terminal Multiplexer ==&lt;br /&gt;
[http://tmux.sourceforge.net/ The tmux terminal multiplexer] is helpful for using a single terminal window to efficiently manage different editing and build sessions, amongst many other useful functions. [http://pragprog.com/book/bhtmux/tmux tmux: Productive Mouse-Free Development] from The Pragmatic Bookshelf is a great primer.&lt;br /&gt;
&lt;br /&gt;
These are some helpful config options to add to &amp;lt;code&amp;gt;~/.tmux.conf&amp;lt;/code&amp;gt;, including getting GNU screen-like CTRL-a behavior:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set-option -g prefix C-a&lt;br /&gt;
unbind-key C-b&lt;br /&gt;
bind-key C-a send-prefix&lt;br /&gt;
&lt;br /&gt;
bind R source-file ~/.tmux.conf \; display &amp;quot;Reloaded ~/.tmux.conf&amp;quot;&lt;br /&gt;
set -g default-terminal &amp;quot;screen-256color&amp;quot;&lt;br /&gt;
set -g status-style fg=black,bg=colour7&lt;br /&gt;
setw -g window-status-style fg=default,bg=default,none&lt;br /&gt;
setw -g window-status-current-style fg=black,bg=colour15,bold&lt;br /&gt;
set -g pane-active-border-style fg=default,bg=colour7&lt;br /&gt;
set -g message-style fg=black,bg=colour11,bright&lt;br /&gt;
set -g status-utf8 on&lt;br /&gt;
setw -g monitor-activity on&lt;br /&gt;
set -g visual-activity on&lt;br /&gt;
&lt;br /&gt;
bind -r H resize-pane -L 5&lt;br /&gt;
bind -r J resize-pane -D 5&lt;br /&gt;
bind -r K resize-pane -U 5                                                      &lt;br /&gt;
bind -r L resize-pane -R 5&lt;br /&gt;
&lt;br /&gt;
# Enables nohup to work. From:&lt;br /&gt;
# https://github.com/ChrisJohnsen/tmux-MacOSX-pasteboard                        &lt;br /&gt;
set-option -g default-command &amp;quot;reattach-to-user-namespace -l $SHELL&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mbland</name></author>
	</entry>
	<entry>
		<id>https://wiki.openssl.org/index.php?title=How_To_Write_Unit_Tests_For_OpenSSL&amp;diff=1759</id>
		<title>How To Write Unit Tests For OpenSSL</title>
		<link rel="alternate" type="text/html" href="https://wiki.openssl.org/index.php?title=How_To_Write_Unit_Tests_For_OpenSSL&amp;diff=1759"/>
		<updated>2014-06-18T20:40:19Z</updated>

		<summary type="html">&lt;p&gt;Mbland: /* Style */ Add testutil.h section&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This is an outline of the basic process and principles to follow when writing unit tests. This document will evolve quite a bit as the community gains experience.&lt;br /&gt;
&lt;br /&gt;
==Mechanics ==&lt;br /&gt;
=== Forking the Repo ===&lt;br /&gt;
For now, people contributing new unit tests for uncovered code (as opposed to submitting tests with new code changes) should fork [https://github.com/mbland/openssl Mike Bland's GitHub repository] and issue [https://help.github.com/articles/using-pull-requests GitHub pull requests]. Remember to do all development on a topic branch (not &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt;). Tests committed to this repo will occasionally get merged into the master OpenSSL repo.&lt;br /&gt;
&lt;br /&gt;
Rationale per Matt Caswell: We should think about process here. If you are going off to recruit an army of people writing tests then I wonder if it is worth setting up a separate github repository whilst you are building up the tests. We can then merge in from that on a periodic basis. I wouldn't want availability of openssl team committers to be a bottle neck.&lt;br /&gt;
&lt;br /&gt;
Set up the [https://github.com/openssl/openssl OpenSSL master repository] as your upstream remote as per [https://help.github.com/articles/fork-a-repo#step-3-configure-remotes GitHub's instructions on configuring remotes]:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ cd my-openssl-repo&lt;br /&gt;
$ git remote add upstream https://github.com/openssl/openssl.git&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You should see the following output from &amp;lt;code&amp;gt;git remove -v&amp;lt;/code&amp;gt; (where &amp;lt;code&amp;gt;$USER&amp;lt;/code&amp;gt; is your GitHub username):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ git remote -v&lt;br /&gt;
origin  https://github.com/$USER/openssl.git (fetch)&lt;br /&gt;
origin  https://github.com/$USER/openssl.git (push)&lt;br /&gt;
upstream        https://github.com/openssl/openssl.git (fetch)&lt;br /&gt;
upstream        https://github.com/openssl/openssl.git (push)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Check out the Tools and Tips page ===&lt;br /&gt;
[[Testing and Development Tools and Tips]] has information on tools that may make navigating and building the code a bit easier.&lt;br /&gt;
&lt;br /&gt;
=== Use the Test Template Generator ===&lt;br /&gt;
TODO(mbland): Get template generator checked-in. Maybe have a template generator for each library, e.g. &amp;lt;code&amp;gt;ssl/new-test.sh&amp;lt;/code&amp;gt; that has additional setup boilerplate specific to the &amp;lt;code&amp;gt;ssl&amp;lt;/code&amp;gt; library.&lt;br /&gt;
&lt;br /&gt;
Use the &amp;lt;code&amp;gt;test/new-test.sh&amp;lt;/code&amp;gt; script to generate a skeleton test file. ([https://github.com/mbland/openssl/compare/test-util pending in the test-util branch])&lt;br /&gt;
&lt;br /&gt;
=== Add Makefile Targets ===&lt;br /&gt;
The following instructions use the &amp;lt;code&amp;gt;Makefile&amp;lt;/code&amp;gt; targets for &amp;lt;code&amp;gt;ssl/heartbeat_test.c&amp;lt;/code&amp;gt; as an example.&lt;br /&gt;
&lt;br /&gt;
In the &amp;lt;code&amp;gt;Makefile&amp;lt;/code&amp;gt; for the library containing the test, add the test source file to the &amp;lt;code&amp;gt;TEST&amp;lt;/code&amp;gt; variable:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# ssl/Makefile&lt;br /&gt;
TEST=ssltest.c heartbeat_test.c&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In &amp;lt;code&amp;gt;test/Makefile&amp;lt;/code&amp;gt;:&lt;br /&gt;
* add a variable for the test target near the top of the file, right after the existing test variables&lt;br /&gt;
* use the variable to add an executable target to the &amp;lt;code&amp;gt;EXE&amp;lt;/code&amp;gt; variable&lt;br /&gt;
* use the variable to add an object file target to the &amp;lt;code&amp;gt;OBJ&amp;lt;/code&amp;gt; variable&lt;br /&gt;
* use the variable to add a source file target to the &amp;lt;code&amp;gt;SRC&amp;lt;/code&amp;gt; variable&lt;br /&gt;
* add the test target to the &amp;lt;code&amp;gt;alltests&amp;lt;/code&amp;gt; target&lt;br /&gt;
* add the target to execute the test&lt;br /&gt;
* add the target to build the test executable&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# test/Makefile&lt;br /&gt;
HEARTBEATTEST=  heartbeat_test&lt;br /&gt;
EXE=  ... $(HEARTBEATTEST)$(EXE_EXT)&lt;br /&gt;
OBJ= ... $(HEARTBEATTEST).o&lt;br /&gt;
SRC= ... $(HEARTBEATTEST).c&lt;br /&gt;
alltests: \&lt;br /&gt;
        ... test_heartbeat&lt;br /&gt;
&lt;br /&gt;
test_heartbeat: $(HEARTBEATTEST)$(EXE_EXT)&lt;br /&gt;
  ../util/shlib_wrap.sh ./$(HEARTBEATTEST)&lt;br /&gt;
&lt;br /&gt;
$(HEARTBEATTEST)$(EXE_EXT): $(HEARTBEATTEST).o $(DLIBCRYPTO)&lt;br /&gt;
  @target=$(HEARTBEATTEST); $(BUILD_CMD)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Run &amp;lt;code&amp;gt;make links &amp;amp;&amp;amp; make depend&amp;lt;/code&amp;gt; ===&lt;br /&gt;
Finally, run &amp;lt;code&amp;gt;make links &amp;amp;&amp;amp; make depend&amp;lt;/code&amp;gt; to link the new test into the &amp;lt;code&amp;gt;test/&amp;lt;/code&amp;gt; directory and automatically generate the header file dependencies.&lt;br /&gt;
&lt;br /&gt;
=== Building and Running the Test ===&lt;br /&gt;
If you're initially developing on Mac OS X or (for now) FreeBSD 10, just use the stock method of building and testing:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ ./config &amp;amp;&amp;amp; make &amp;amp;&amp;amp; make test&lt;br /&gt;
&lt;br /&gt;
# To execute just one specific test&lt;br /&gt;
$ make TESTS=test_heartbeat test &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Ultimately the test will have to compile and pass with developer flags enabled:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ ./GitConfigure debug-ben-debug-64-clang&lt;br /&gt;
$ ./GitMake -j 2&lt;br /&gt;
$ ./GitMake test_heartbeat&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above currently doesn't work on Mac OS X or FreeBSD 10; for now, you can install the 9.1 release of [http://www.freebsd.org/ FreeBSD], which uses Clang 3.1, via a virtualization platform such as [https://www.virtualbox.org/ VirtualBox]. (Mac OS X breaks, in part, due to the fact that it doesn't use the GNU assembler; &amp;lt;code&amp;gt;-fsanitize&amp;lt;/code&amp;gt; appears to be ignored on FreeBSD 9.1/Clang 3.1, but later versions break because the Clang compiler will emit &amp;lt;code&amp;gt;-fsanitize&amp;lt;/code&amp;gt; symbols but the &amp;lt;code&amp;gt;libasan&amp;lt;/code&amp;gt; library [http://lists.freebsd.org/pipermail/freebsd-hackers/2013-December/043995.html has yet to be ported to FreeBSD].)&lt;br /&gt;
&lt;br /&gt;
=== Keep your repo up-to-date ===&lt;br /&gt;
Periodically run the following to keep your branch up-to-date:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ git fetch upstream master&lt;br /&gt;
$ git rebase upstream/master&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This will pull all the updates from the master OpenSSL repository into your repository, then update your branch to apply your changes on top of the latest updates.&lt;br /&gt;
&lt;br /&gt;
=== Send a pull request ===&lt;br /&gt;
When your test is ready, send a [https://help.github.com/articles/using-pull-requests GitHub pull request]. Note that the pull request should be based on the &amp;lt;code&amp;gt;tests&amp;lt;/code&amp;gt; branch of Mike's repository, not &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt;. (This should be the default; let Mike know if it doesn't appear to be!) We'll review the code, and when it's ready, it'll get merged into Mike's repository. From there, it will eventually get pulled into the master OpenSSL repository.&lt;br /&gt;
&lt;br /&gt;
== Style ==&lt;br /&gt;
[http://mike-bland.com/2014/06/05/pseudo-xunit-pattern.html The Pseudo-xUnit Pattern] is that established by [http://git.openssl.org/gitweb/?p=openssl.git;a=blob;f=ssl/heartbeat_test.c ssl/heartbeat_test.c]. This pattern organizes code in a fashion reminiscent of the [http://en.wikipedia.org/wiki/XUnit xUnit] family of unit testing frameworks, without actually using a testing framework. This should lower the barrier to entry for people wanting to write unit tests, but enable a relatively easy migration to an xUnit-based framework if we decide to do so one day.&lt;br /&gt;
&lt;br /&gt;
Some of the basic principles to follow are:&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;code&amp;gt;#include&amp;lt;/code&amp;gt; the header for the code under test first ===&lt;br /&gt;
Having the header file for the code under test appear as the first &amp;lt;code&amp;gt;#include&amp;lt;/code&amp;gt; directive ensures that that file is self-contained, i.e. it includes every header file it depends on, rather than relying on client code to include its dependencies.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;code&amp;gt;#include &amp;quot;testutil.h&amp;quot;&amp;lt;/code&amp;gt; should come second ===&lt;br /&gt;
&amp;lt;code&amp;gt;test/testutil.h&amp;lt;/code&amp;gt; contains the helper macros used in writing OpenSSL tests. Since the tests will be linked into &amp;lt;code&amp;gt;test/&amp;lt;/code&amp;gt; by the [[#Run_make_links_.26.26_make_depend|make links]] step, and built in the &amp;lt;code&amp;gt;test/&amp;lt;/code&amp;gt; directory, the &amp;quot;testutil.h&amp;quot; file will appear to be in the same directory as the test file.&lt;br /&gt;
&lt;br /&gt;
=== Define a fixture structure ===&lt;br /&gt;
The fixture structure should contain all of the inputs to the code under test and all of the expected result values. It should also contain a &amp;lt;code&amp;gt;const char*&amp;lt;/code&amp;gt; for the name of the test case function that created it, to aid in error message formatting. Even though the fixture may contain dynamically-allocated members, the fixture itself should be copied by value to reduce the necessary degree of memory management in a small unit test program.&lt;br /&gt;
&lt;br /&gt;
=== Define set_up() and tear_down() functions for the fixture ===&lt;br /&gt;
&amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; should return a newly-initialized test fixture structure. It should take the name of the test case as an argument (i.e. &amp;lt;code&amp;gt;__func__&amp;lt;/code&amp;gt;) and assign it to the fixture. All of the fixture members should be initialized, which each test case function can then override as needed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;tear_down()&amp;lt;/code&amp;gt; should take the fixture as an argument and release any resources allocated by &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt;. It can also call any library-wide error printing routines (e.g. &amp;lt;code&amp;gt;ERR_print_errors_fp(stderr)&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
=== Use &amp;lt;code&amp;gt;SETUP_TEST_FIXTURE()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;EXECUTE_TEST()&amp;lt;/code&amp;gt; from &amp;lt;code&amp;gt;test/testutil.h&amp;lt;/code&amp;gt; ===&lt;br /&gt;
Each test case function should call &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; as its first statement, and should call &amp;lt;code&amp;gt;tear_down()&amp;lt;/code&amp;gt; just before returning. This is handled in a uniform fashion when using the &amp;lt;code&amp;gt;SETUP_TEST_FIXTURE()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;EXECUTE_TEST()&amp;lt;/code&amp;gt; helper macros from [http://git.openssl.org/gitweb/?p=openssl.git;a=blob;f=test/testutil.h test/testutil.h]. See the comments in &amp;lt;code&amp;gt;test/testutil.h&amp;lt;/code&amp;gt; for usage, and &amp;lt;code&amp;gt;ssl/heartbeat_test.c&amp;lt;/code&amp;gt; for an example of how to wrap the macros for a specific unit test.&lt;br /&gt;
&lt;br /&gt;
=== Use test case functions, not a table of fixtures ===&lt;br /&gt;
Individual test case functions that call a common execution function are much more readable and maintainable than a loop over a table of fixture structures. Explicit fixture variable assignments aid comprehension when reading a specific test case, which saves time and energy when trying to understand a test or diagnose a failure. When a new member is added to an existing fixture, &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; can set a default for all test cases, and only the test cases that rely on that new member need to be updated.&lt;br /&gt;
&lt;br /&gt;
=== Use very descriptive test case names ===&lt;br /&gt;
Give tests long, descriptive names that provide ample context for the details of the test case. Good test names are also help produce good error messages.&lt;br /&gt;
&lt;br /&gt;
=== Group test cases into &amp;quot;suites&amp;quot; by naming convention ===&lt;br /&gt;
Give logically-related tests the same prefix, e.g. &amp;lt;code&amp;gt;test_dtls1_&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;test_tls1&amp;lt;/code&amp;gt; from &amp;lt;code&amp;gt;ssl/heartbeat_test.c&amp;lt;/code&amp;gt;. If need be, you can define suite-specific &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; functions that call the common &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; and elaborate on it. (This generally shouldn't be necessary for &amp;lt;code&amp;gt;tear_down()&amp;lt;/code&amp;gt;.)&lt;br /&gt;
&lt;br /&gt;
=== Keep individual test case functions focused on one thing ===&lt;br /&gt;
If the test name contains the word &amp;quot;and&amp;quot;, consider breaking it into two or more separate test case functions.&lt;br /&gt;
&lt;br /&gt;
=== Write very descriptive error messages ===&lt;br /&gt;
Include the test case function name in each error message, and explain in detail the context for the assertion that failed. Include the expected result (contained in the fixture structure) and the actual result returned from the code under test. Write helper methods for complex values as needed (e.g. &amp;lt;code&amp;gt;print_payload()&amp;lt;/code&amp;gt; in &amp;lt;code&amp;gt;ssl/heartbeat_test.c&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
=== Return zero on success and one on failure ===&lt;br /&gt;
The return value will be used to tally the number of test cases that failed. Even if multiple assertions fail for a single test case, the result should be exactly one.&lt;br /&gt;
&lt;br /&gt;
=== Add each test case function to the test runner function ===&lt;br /&gt;
Whatever function is used to execute the batch of test case functions, be that &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt; or a separate function called by &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt;, don't forget to add your test case functions to that function.&lt;br /&gt;
&lt;br /&gt;
TODO(mbland): create some kind of automated script or editor macros?&lt;br /&gt;
&lt;br /&gt;
=== Report the number of test cases that failed ===&lt;br /&gt;
Add up the total number of failed test cases in &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt; and report that number as the last error message of the test. &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt; should return &amp;lt;code&amp;gt;EXIT_FAILURE&amp;lt;/code&amp;gt; if any test cases failed, &amp;lt;code&amp;gt;EXIT_SUCCESS&amp;lt;/code&amp;gt; otherwise.&lt;br /&gt;
&lt;br /&gt;
=== Disable for Windows (for now) ===&lt;br /&gt;
Until we solve the private-symbol problem on Windows, we will need to wrap our unit test code in the following &amp;lt;code&amp;gt;#ifdef&amp;lt;/code&amp;gt; block:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#if !defined(OPENSSL_SYS_WINDOWS)&lt;br /&gt;
&lt;br /&gt;
/* All the test code, including main() */&lt;br /&gt;
&lt;br /&gt;
int main(int argc, char *argv[])                                                &lt;br /&gt;
    {&lt;br /&gt;
        return EXIT_SUCCESS;                                                    &lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
#endif /* OPENSSL_NO_WINDOWS  */&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Samples ==&lt;br /&gt;
Existing tests that can be used as models for new tests.&lt;br /&gt;
* [http://git.openssl.org/gitweb/?p=openssl.git;a=blob;f=ssl/heartbeat_test.c ssl/heartbeat_test.c]: Follows [http://mike-bland.com/2014/06/05/pseudo-xunit-pattern.html the Pseudo-xUnit pattern]&lt;/div&gt;</summary>
		<author><name>Mbland</name></author>
	</entry>
	<entry>
		<id>https://wiki.openssl.org/index.php?title=How_To_Write_Unit_Tests_For_OpenSSL&amp;diff=1758</id>
		<title>How To Write Unit Tests For OpenSSL</title>
		<link rel="alternate" type="text/html" href="https://wiki.openssl.org/index.php?title=How_To_Write_Unit_Tests_For_OpenSSL&amp;diff=1758"/>
		<updated>2014-06-18T20:28:23Z</updated>

		<summary type="html">&lt;p&gt;Mbland: /* Style */ Added section on #including the header for the code under test first&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This is an outline of the basic process and principles to follow when writing unit tests. This document will evolve quite a bit as the community gains experience.&lt;br /&gt;
&lt;br /&gt;
==Mechanics ==&lt;br /&gt;
=== Forking the Repo ===&lt;br /&gt;
For now, people contributing new unit tests for uncovered code (as opposed to submitting tests with new code changes) should fork [https://github.com/mbland/openssl Mike Bland's GitHub repository] and issue [https://help.github.com/articles/using-pull-requests GitHub pull requests]. Remember to do all development on a topic branch (not &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt;). Tests committed to this repo will occasionally get merged into the master OpenSSL repo.&lt;br /&gt;
&lt;br /&gt;
Rationale per Matt Caswell: We should think about process here. If you are going off to recruit an army of people writing tests then I wonder if it is worth setting up a separate github repository whilst you are building up the tests. We can then merge in from that on a periodic basis. I wouldn't want availability of openssl team committers to be a bottle neck.&lt;br /&gt;
&lt;br /&gt;
Set up the [https://github.com/openssl/openssl OpenSSL master repository] as your upstream remote as per [https://help.github.com/articles/fork-a-repo#step-3-configure-remotes GitHub's instructions on configuring remotes]:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ cd my-openssl-repo&lt;br /&gt;
$ git remote add upstream https://github.com/openssl/openssl.git&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You should see the following output from &amp;lt;code&amp;gt;git remove -v&amp;lt;/code&amp;gt; (where &amp;lt;code&amp;gt;$USER&amp;lt;/code&amp;gt; is your GitHub username):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ git remote -v&lt;br /&gt;
origin  https://github.com/$USER/openssl.git (fetch)&lt;br /&gt;
origin  https://github.com/$USER/openssl.git (push)&lt;br /&gt;
upstream        https://github.com/openssl/openssl.git (fetch)&lt;br /&gt;
upstream        https://github.com/openssl/openssl.git (push)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Check out the Tools and Tips page ===&lt;br /&gt;
[[Testing and Development Tools and Tips]] has information on tools that may make navigating and building the code a bit easier.&lt;br /&gt;
&lt;br /&gt;
=== Use the Test Template Generator ===&lt;br /&gt;
TODO(mbland): Get template generator checked-in. Maybe have a template generator for each library, e.g. &amp;lt;code&amp;gt;ssl/new-test.sh&amp;lt;/code&amp;gt; that has additional setup boilerplate specific to the &amp;lt;code&amp;gt;ssl&amp;lt;/code&amp;gt; library.&lt;br /&gt;
&lt;br /&gt;
Use the &amp;lt;code&amp;gt;test/new-test.sh&amp;lt;/code&amp;gt; script to generate a skeleton test file. ([https://github.com/mbland/openssl/compare/test-util pending in the test-util branch])&lt;br /&gt;
&lt;br /&gt;
=== Add Makefile Targets ===&lt;br /&gt;
The following instructions use the &amp;lt;code&amp;gt;Makefile&amp;lt;/code&amp;gt; targets for &amp;lt;code&amp;gt;ssl/heartbeat_test.c&amp;lt;/code&amp;gt; as an example.&lt;br /&gt;
&lt;br /&gt;
In the &amp;lt;code&amp;gt;Makefile&amp;lt;/code&amp;gt; for the library containing the test, add the test source file to the &amp;lt;code&amp;gt;TEST&amp;lt;/code&amp;gt; variable:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# ssl/Makefile&lt;br /&gt;
TEST=ssltest.c heartbeat_test.c&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In &amp;lt;code&amp;gt;test/Makefile&amp;lt;/code&amp;gt;:&lt;br /&gt;
* add a variable for the test target near the top of the file, right after the existing test variables&lt;br /&gt;
* use the variable to add an executable target to the &amp;lt;code&amp;gt;EXE&amp;lt;/code&amp;gt; variable&lt;br /&gt;
* use the variable to add an object file target to the &amp;lt;code&amp;gt;OBJ&amp;lt;/code&amp;gt; variable&lt;br /&gt;
* use the variable to add a source file target to the &amp;lt;code&amp;gt;SRC&amp;lt;/code&amp;gt; variable&lt;br /&gt;
* add the test target to the &amp;lt;code&amp;gt;alltests&amp;lt;/code&amp;gt; target&lt;br /&gt;
* add the target to execute the test&lt;br /&gt;
* add the target to build the test executable&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# test/Makefile&lt;br /&gt;
HEARTBEATTEST=  heartbeat_test&lt;br /&gt;
EXE=  ... $(HEARTBEATTEST)$(EXE_EXT)&lt;br /&gt;
OBJ= ... $(HEARTBEATTEST).o&lt;br /&gt;
SRC= ... $(HEARTBEATTEST).c&lt;br /&gt;
alltests: \&lt;br /&gt;
        ... test_heartbeat&lt;br /&gt;
&lt;br /&gt;
test_heartbeat: $(HEARTBEATTEST)$(EXE_EXT)&lt;br /&gt;
  ../util/shlib_wrap.sh ./$(HEARTBEATTEST)&lt;br /&gt;
&lt;br /&gt;
$(HEARTBEATTEST)$(EXE_EXT): $(HEARTBEATTEST).o $(DLIBCRYPTO)&lt;br /&gt;
  @target=$(HEARTBEATTEST); $(BUILD_CMD)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Run &amp;lt;code&amp;gt;make links &amp;amp;&amp;amp; make depend&amp;lt;/code&amp;gt; ===&lt;br /&gt;
Finally, run &amp;lt;code&amp;gt;make links &amp;amp;&amp;amp; make depend&amp;lt;/code&amp;gt; to link the new test into the &amp;lt;code&amp;gt;test/&amp;lt;/code&amp;gt; directory and automatically generate the header file dependencies.&lt;br /&gt;
&lt;br /&gt;
=== Building and Running the Test ===&lt;br /&gt;
If you're initially developing on Mac OS X or (for now) FreeBSD 10, just use the stock method of building and testing:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ ./config &amp;amp;&amp;amp; make &amp;amp;&amp;amp; make test&lt;br /&gt;
&lt;br /&gt;
# To execute just one specific test&lt;br /&gt;
$ make TESTS=test_heartbeat test &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Ultimately the test will have to compile and pass with developer flags enabled:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ ./GitConfigure debug-ben-debug-64-clang&lt;br /&gt;
$ ./GitMake -j 2&lt;br /&gt;
$ ./GitMake test_heartbeat&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above currently doesn't work on Mac OS X or FreeBSD 10; for now, you can install the 9.1 release of [http://www.freebsd.org/ FreeBSD], which uses Clang 3.1, via a virtualization platform such as [https://www.virtualbox.org/ VirtualBox]. (Mac OS X breaks, in part, due to the fact that it doesn't use the GNU assembler; &amp;lt;code&amp;gt;-fsanitize&amp;lt;/code&amp;gt; appears to be ignored on FreeBSD 9.1/Clang 3.1, but later versions break because the Clang compiler will emit &amp;lt;code&amp;gt;-fsanitize&amp;lt;/code&amp;gt; symbols but the &amp;lt;code&amp;gt;libasan&amp;lt;/code&amp;gt; library [http://lists.freebsd.org/pipermail/freebsd-hackers/2013-December/043995.html has yet to be ported to FreeBSD].)&lt;br /&gt;
&lt;br /&gt;
=== Keep your repo up-to-date ===&lt;br /&gt;
Periodically run the following to keep your branch up-to-date:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ git fetch upstream master&lt;br /&gt;
$ git rebase upstream/master&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This will pull all the updates from the master OpenSSL repository into your repository, then update your branch to apply your changes on top of the latest updates.&lt;br /&gt;
&lt;br /&gt;
=== Send a pull request ===&lt;br /&gt;
When your test is ready, send a [https://help.github.com/articles/using-pull-requests GitHub pull request]. Note that the pull request should be based on the &amp;lt;code&amp;gt;tests&amp;lt;/code&amp;gt; branch of Mike's repository, not &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt;. (This should be the default; let Mike know if it doesn't appear to be!) We'll review the code, and when it's ready, it'll get merged into Mike's repository. From there, it will eventually get pulled into the master OpenSSL repository.&lt;br /&gt;
&lt;br /&gt;
== Style ==&lt;br /&gt;
[http://mike-bland.com/2014/06/05/pseudo-xunit-pattern.html The Pseudo-xUnit Pattern] is that established by [http://git.openssl.org/gitweb/?p=openssl.git;a=blob;f=ssl/heartbeat_test.c ssl/heartbeat_test.c]. This pattern organizes code in a fashion reminiscent of the [http://en.wikipedia.org/wiki/XUnit xUnit] family of unit testing frameworks, without actually using a testing framework. This should lower the barrier to entry for people wanting to write unit tests, but enable a relatively easy migration to an xUnit-based framework if we decide to do so one day.&lt;br /&gt;
&lt;br /&gt;
Some of the basic principles to follow are:&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;code&amp;gt;#include&amp;lt;/code&amp;gt; the header for the code under test first ===&lt;br /&gt;
Having the header file for the code under test appear as the first &amp;lt;code&amp;gt;#include&amp;lt;/code&amp;gt; directive ensures that that file is self-contained, i.e. it includes every header file it depends on, rather than relying on client code to include its dependencies.&lt;br /&gt;
&lt;br /&gt;
=== Define a fixture structure ===&lt;br /&gt;
The fixture structure should contain all of the inputs to the code under test and all of the expected result values. It should also contain a &amp;lt;code&amp;gt;const char*&amp;lt;/code&amp;gt; for the name of the test case function that created it, to aid in error message formatting. Even though the fixture may contain dynamically-allocated members, the fixture itself should be copied by value to reduce the necessary degree of memory management in a small unit test program.&lt;br /&gt;
&lt;br /&gt;
=== Define set_up() and tear_down() functions for the fixture ===&lt;br /&gt;
&amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; should return a newly-initialized test fixture structure. It should take the name of the test case as an argument (i.e. &amp;lt;code&amp;gt;__func__&amp;lt;/code&amp;gt;) and assign it to the fixture. All of the fixture members should be initialized, which each test case function can then override as needed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;tear_down()&amp;lt;/code&amp;gt; should take the fixture as an argument and release any resources allocated by &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt;. It can also call any library-wide error printing routines (e.g. &amp;lt;code&amp;gt;ERR_print_errors_fp(stderr)&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
=== Use &amp;lt;code&amp;gt;SETUP_TEST_FIXTURE()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;EXECUTE_TEST()&amp;lt;/code&amp;gt; from &amp;lt;code&amp;gt;test/testutil.h&amp;lt;/code&amp;gt; ===&lt;br /&gt;
Each test case function should call &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; as its first statement, and should call &amp;lt;code&amp;gt;tear_down()&amp;lt;/code&amp;gt; just before returning. This is handled in a uniform fashion when using the &amp;lt;code&amp;gt;SETUP_TEST_FIXTURE()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;EXECUTE_TEST()&amp;lt;/code&amp;gt; helper macros from [http://git.openssl.org/gitweb/?p=openssl.git;a=blob;f=test/testutil.h test/testutil.h]. See the comments in &amp;lt;code&amp;gt;test/testutil.h&amp;lt;/code&amp;gt; for usage, and &amp;lt;code&amp;gt;ssl/heartbeat_test.c&amp;lt;/code&amp;gt; for an example of how to wrap the macros for a specific unit test.&lt;br /&gt;
&lt;br /&gt;
=== Use test case functions, not a table of fixtures ===&lt;br /&gt;
Individual test case functions that call a common execution function are much more readable and maintainable than a loop over a table of fixture structures. Explicit fixture variable assignments aid comprehension when reading a specific test case, which saves time and energy when trying to understand a test or diagnose a failure. When a new member is added to an existing fixture, &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; can set a default for all test cases, and only the test cases that rely on that new member need to be updated.&lt;br /&gt;
&lt;br /&gt;
=== Use very descriptive test case names ===&lt;br /&gt;
Give tests long, descriptive names that provide ample context for the details of the test case. Good test names are also help produce good error messages.&lt;br /&gt;
&lt;br /&gt;
=== Group test cases into &amp;quot;suites&amp;quot; by naming convention ===&lt;br /&gt;
Give logically-related tests the same prefix, e.g. &amp;lt;code&amp;gt;test_dtls1_&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;test_tls1&amp;lt;/code&amp;gt; from &amp;lt;code&amp;gt;ssl/heartbeat_test.c&amp;lt;/code&amp;gt;. If need be, you can define suite-specific &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; functions that call the common &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; and elaborate on it. (This generally shouldn't be necessary for &amp;lt;code&amp;gt;tear_down()&amp;lt;/code&amp;gt;.)&lt;br /&gt;
&lt;br /&gt;
=== Keep individual test case functions focused on one thing ===&lt;br /&gt;
If the test name contains the word &amp;quot;and&amp;quot;, consider breaking it into two or more separate test case functions.&lt;br /&gt;
&lt;br /&gt;
=== Write very descriptive error messages ===&lt;br /&gt;
Include the test case function name in each error message, and explain in detail the context for the assertion that failed. Include the expected result (contained in the fixture structure) and the actual result returned from the code under test. Write helper methods for complex values as needed (e.g. &amp;lt;code&amp;gt;print_payload()&amp;lt;/code&amp;gt; in &amp;lt;code&amp;gt;ssl/heartbeat_test.c&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
=== Return zero on success and one on failure ===&lt;br /&gt;
The return value will be used to tally the number of test cases that failed. Even if multiple assertions fail for a single test case, the result should be exactly one.&lt;br /&gt;
&lt;br /&gt;
=== Add each test case function to the test runner function ===&lt;br /&gt;
Whatever function is used to execute the batch of test case functions, be that &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt; or a separate function called by &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt;, don't forget to add your test case functions to that function.&lt;br /&gt;
&lt;br /&gt;
TODO(mbland): create some kind of automated script or editor macros?&lt;br /&gt;
&lt;br /&gt;
=== Report the number of test cases that failed ===&lt;br /&gt;
Add up the total number of failed test cases in &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt; and report that number as the last error message of the test. &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt; should return &amp;lt;code&amp;gt;EXIT_FAILURE&amp;lt;/code&amp;gt; if any test cases failed, &amp;lt;code&amp;gt;EXIT_SUCCESS&amp;lt;/code&amp;gt; otherwise.&lt;br /&gt;
&lt;br /&gt;
=== Disable for Windows (for now) ===&lt;br /&gt;
Until we solve the private-symbol problem on Windows, we will need to wrap our unit test code in the following &amp;lt;code&amp;gt;#ifdef&amp;lt;/code&amp;gt; block:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#if !defined(OPENSSL_SYS_WINDOWS)&lt;br /&gt;
&lt;br /&gt;
/* All the test code, including main() */&lt;br /&gt;
&lt;br /&gt;
int main(int argc, char *argv[])                                                &lt;br /&gt;
    {&lt;br /&gt;
        return EXIT_SUCCESS;                                                    &lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
#endif /* OPENSSL_NO_WINDOWS  */&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Samples ==&lt;br /&gt;
Existing tests that can be used as models for new tests.&lt;br /&gt;
* [http://git.openssl.org/gitweb/?p=openssl.git;a=blob;f=ssl/heartbeat_test.c ssl/heartbeat_test.c]: Follows [http://mike-bland.com/2014/06/05/pseudo-xunit-pattern.html the Pseudo-xUnit pattern]&lt;/div&gt;</summary>
		<author><name>Mbland</name></author>
	</entry>
	<entry>
		<id>https://wiki.openssl.org/index.php?title=How_To_Write_Unit_Tests_For_OpenSSL&amp;diff=1757</id>
		<title>How To Write Unit Tests For OpenSSL</title>
		<link rel="alternate" type="text/html" href="https://wiki.openssl.org/index.php?title=How_To_Write_Unit_Tests_For_OpenSSL&amp;diff=1757"/>
		<updated>2014-06-18T20:13:49Z</updated>

		<summary type="html">&lt;p&gt;Mbland: /* Run make depend */ Updated to clarify that 'make links' must be run first.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This is an outline of the basic process and principles to follow when writing unit tests. This document will evolve quite a bit as the community gains experience.&lt;br /&gt;
&lt;br /&gt;
==Mechanics ==&lt;br /&gt;
=== Forking the Repo ===&lt;br /&gt;
For now, people contributing new unit tests for uncovered code (as opposed to submitting tests with new code changes) should fork [https://github.com/mbland/openssl Mike Bland's GitHub repository] and issue [https://help.github.com/articles/using-pull-requests GitHub pull requests]. Remember to do all development on a topic branch (not &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt;). Tests committed to this repo will occasionally get merged into the master OpenSSL repo.&lt;br /&gt;
&lt;br /&gt;
Rationale per Matt Caswell: We should think about process here. If you are going off to recruit an army of people writing tests then I wonder if it is worth setting up a separate github repository whilst you are building up the tests. We can then merge in from that on a periodic basis. I wouldn't want availability of openssl team committers to be a bottle neck.&lt;br /&gt;
&lt;br /&gt;
Set up the [https://github.com/openssl/openssl OpenSSL master repository] as your upstream remote as per [https://help.github.com/articles/fork-a-repo#step-3-configure-remotes GitHub's instructions on configuring remotes]:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ cd my-openssl-repo&lt;br /&gt;
$ git remote add upstream https://github.com/openssl/openssl.git&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You should see the following output from &amp;lt;code&amp;gt;git remove -v&amp;lt;/code&amp;gt; (where &amp;lt;code&amp;gt;$USER&amp;lt;/code&amp;gt; is your GitHub username):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ git remote -v&lt;br /&gt;
origin  https://github.com/$USER/openssl.git (fetch)&lt;br /&gt;
origin  https://github.com/$USER/openssl.git (push)&lt;br /&gt;
upstream        https://github.com/openssl/openssl.git (fetch)&lt;br /&gt;
upstream        https://github.com/openssl/openssl.git (push)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Check out the Tools and Tips page ===&lt;br /&gt;
[[Testing and Development Tools and Tips]] has information on tools that may make navigating and building the code a bit easier.&lt;br /&gt;
&lt;br /&gt;
=== Use the Test Template Generator ===&lt;br /&gt;
TODO(mbland): Get template generator checked-in. Maybe have a template generator for each library, e.g. &amp;lt;code&amp;gt;ssl/new-test.sh&amp;lt;/code&amp;gt; that has additional setup boilerplate specific to the &amp;lt;code&amp;gt;ssl&amp;lt;/code&amp;gt; library.&lt;br /&gt;
&lt;br /&gt;
Use the &amp;lt;code&amp;gt;test/new-test.sh&amp;lt;/code&amp;gt; script to generate a skeleton test file. ([https://github.com/mbland/openssl/compare/test-util pending in the test-util branch])&lt;br /&gt;
&lt;br /&gt;
=== Add Makefile Targets ===&lt;br /&gt;
The following instructions use the &amp;lt;code&amp;gt;Makefile&amp;lt;/code&amp;gt; targets for &amp;lt;code&amp;gt;ssl/heartbeat_test.c&amp;lt;/code&amp;gt; as an example.&lt;br /&gt;
&lt;br /&gt;
In the &amp;lt;code&amp;gt;Makefile&amp;lt;/code&amp;gt; for the library containing the test, add the test source file to the &amp;lt;code&amp;gt;TEST&amp;lt;/code&amp;gt; variable:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# ssl/Makefile&lt;br /&gt;
TEST=ssltest.c heartbeat_test.c&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In &amp;lt;code&amp;gt;test/Makefile&amp;lt;/code&amp;gt;:&lt;br /&gt;
* add a variable for the test target near the top of the file, right after the existing test variables&lt;br /&gt;
* use the variable to add an executable target to the &amp;lt;code&amp;gt;EXE&amp;lt;/code&amp;gt; variable&lt;br /&gt;
* use the variable to add an object file target to the &amp;lt;code&amp;gt;OBJ&amp;lt;/code&amp;gt; variable&lt;br /&gt;
* use the variable to add a source file target to the &amp;lt;code&amp;gt;SRC&amp;lt;/code&amp;gt; variable&lt;br /&gt;
* add the test target to the &amp;lt;code&amp;gt;alltests&amp;lt;/code&amp;gt; target&lt;br /&gt;
* add the target to execute the test&lt;br /&gt;
* add the target to build the test executable&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# test/Makefile&lt;br /&gt;
HEARTBEATTEST=  heartbeat_test&lt;br /&gt;
EXE=  ... $(HEARTBEATTEST)$(EXE_EXT)&lt;br /&gt;
OBJ= ... $(HEARTBEATTEST).o&lt;br /&gt;
SRC= ... $(HEARTBEATTEST).c&lt;br /&gt;
alltests: \&lt;br /&gt;
        ... test_heartbeat&lt;br /&gt;
&lt;br /&gt;
test_heartbeat: $(HEARTBEATTEST)$(EXE_EXT)&lt;br /&gt;
  ../util/shlib_wrap.sh ./$(HEARTBEATTEST)&lt;br /&gt;
&lt;br /&gt;
$(HEARTBEATTEST)$(EXE_EXT): $(HEARTBEATTEST).o $(DLIBCRYPTO)&lt;br /&gt;
  @target=$(HEARTBEATTEST); $(BUILD_CMD)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Run &amp;lt;code&amp;gt;make links &amp;amp;&amp;amp; make depend&amp;lt;/code&amp;gt; ===&lt;br /&gt;
Finally, run &amp;lt;code&amp;gt;make links &amp;amp;&amp;amp; make depend&amp;lt;/code&amp;gt; to link the new test into the &amp;lt;code&amp;gt;test/&amp;lt;/code&amp;gt; directory and automatically generate the header file dependencies.&lt;br /&gt;
&lt;br /&gt;
=== Building and Running the Test ===&lt;br /&gt;
If you're initially developing on Mac OS X or (for now) FreeBSD 10, just use the stock method of building and testing:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ ./config &amp;amp;&amp;amp; make &amp;amp;&amp;amp; make test&lt;br /&gt;
&lt;br /&gt;
# To execute just one specific test&lt;br /&gt;
$ make TESTS=test_heartbeat test &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Ultimately the test will have to compile and pass with developer flags enabled:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ ./GitConfigure debug-ben-debug-64-clang&lt;br /&gt;
$ ./GitMake -j 2&lt;br /&gt;
$ ./GitMake test_heartbeat&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above currently doesn't work on Mac OS X or FreeBSD 10; for now, you can install the 9.1 release of [http://www.freebsd.org/ FreeBSD], which uses Clang 3.1, via a virtualization platform such as [https://www.virtualbox.org/ VirtualBox]. (Mac OS X breaks, in part, due to the fact that it doesn't use the GNU assembler; &amp;lt;code&amp;gt;-fsanitize&amp;lt;/code&amp;gt; appears to be ignored on FreeBSD 9.1/Clang 3.1, but later versions break because the Clang compiler will emit &amp;lt;code&amp;gt;-fsanitize&amp;lt;/code&amp;gt; symbols but the &amp;lt;code&amp;gt;libasan&amp;lt;/code&amp;gt; library [http://lists.freebsd.org/pipermail/freebsd-hackers/2013-December/043995.html has yet to be ported to FreeBSD].)&lt;br /&gt;
&lt;br /&gt;
=== Keep your repo up-to-date ===&lt;br /&gt;
Periodically run the following to keep your branch up-to-date:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ git fetch upstream master&lt;br /&gt;
$ git rebase upstream/master&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This will pull all the updates from the master OpenSSL repository into your repository, then update your branch to apply your changes on top of the latest updates.&lt;br /&gt;
&lt;br /&gt;
=== Send a pull request ===&lt;br /&gt;
When your test is ready, send a [https://help.github.com/articles/using-pull-requests GitHub pull request]. Note that the pull request should be based on the &amp;lt;code&amp;gt;tests&amp;lt;/code&amp;gt; branch of Mike's repository, not &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt;. (This should be the default; let Mike know if it doesn't appear to be!) We'll review the code, and when it's ready, it'll get merged into Mike's repository. From there, it will eventually get pulled into the master OpenSSL repository.&lt;br /&gt;
&lt;br /&gt;
== Style ==&lt;br /&gt;
[http://mike-bland.com/2014/06/05/pseudo-xunit-pattern.html The Pseudo-xUnit Pattern] is that established by [http://git.openssl.org/gitweb/?p=openssl.git;a=blob;f=ssl/heartbeat_test.c ssl/heartbeat_test.c]. This pattern organizes code in a fashion reminiscent of the [http://en.wikipedia.org/wiki/XUnit xUnit] family of unit testing frameworks, without actually using a testing framework. This should lower the barrier to entry for people wanting to write unit tests, but enable a relatively easy migration to an xUnit-based framework if we decide to do so one day.&lt;br /&gt;
&lt;br /&gt;
Some of the basic principles to follow are:&lt;br /&gt;
&lt;br /&gt;
=== Define a fixture structure ===&lt;br /&gt;
The fixture structure should contain all of the inputs to the code under test and all of the expected result values. It should also contain a &amp;lt;code&amp;gt;const char*&amp;lt;/code&amp;gt; for the name of the test case function that created it, to aid in error message formatting. Even though the fixture may contain dynamically-allocated members, the fixture itself should be copied by value to reduce the necessary degree of memory management in a small unit test program.&lt;br /&gt;
&lt;br /&gt;
=== Define set_up() and tear_down() functions for the fixture ===&lt;br /&gt;
&amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; should return a newly-initialized test fixture structure. It should take the name of the test case as an argument (i.e. &amp;lt;code&amp;gt;__func__&amp;lt;/code&amp;gt;) and assign it to the fixture. All of the fixture members should be initialized, which each test case function can then override as needed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;tear_down()&amp;lt;/code&amp;gt; should take the fixture as an argument and release any resources allocated by &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt;. It can also call any library-wide error printing routines (e.g. &amp;lt;code&amp;gt;ERR_print_errors_fp(stderr)&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
=== Use &amp;lt;code&amp;gt;SETUP_TEST_FIXTURE()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;EXECUTE_TEST()&amp;lt;/code&amp;gt; from &amp;lt;code&amp;gt;test/testutil.h&amp;lt;/code&amp;gt; ===&lt;br /&gt;
Each test case function should call &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; as its first statement, and should call &amp;lt;code&amp;gt;tear_down()&amp;lt;/code&amp;gt; just before returning. This is handled in a uniform fashion when using the &amp;lt;code&amp;gt;SETUP_TEST_FIXTURE()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;EXECUTE_TEST()&amp;lt;/code&amp;gt; helper macros from [http://git.openssl.org/gitweb/?p=openssl.git;a=blob;f=test/testutil.h test/testutil.h]. See the comments in &amp;lt;code&amp;gt;test/testutil.h&amp;lt;/code&amp;gt; for usage, and &amp;lt;code&amp;gt;ssl/heartbeat_test.c&amp;lt;/code&amp;gt; for an example of how to wrap the macros for a specific unit test.&lt;br /&gt;
&lt;br /&gt;
=== Use test case functions, not a table of fixtures ===&lt;br /&gt;
Individual test case functions that call a common execution function are much more readable and maintainable than a loop over a table of fixture structures. Explicit fixture variable assignments aid comprehension when reading a specific test case, which saves time and energy when trying to understand a test or diagnose a failure. When a new member is added to an existing fixture, &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; can set a default for all test cases, and only the test cases that rely on that new member need to be updated.&lt;br /&gt;
&lt;br /&gt;
=== Use very descriptive test case names ===&lt;br /&gt;
Give tests long, descriptive names that provide ample context for the details of the test case. Good test names are also help produce good error messages.&lt;br /&gt;
&lt;br /&gt;
=== Group test cases into &amp;quot;suites&amp;quot; by naming convention ===&lt;br /&gt;
Give logically-related tests the same prefix, e.g. &amp;lt;code&amp;gt;test_dtls1_&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;test_tls1&amp;lt;/code&amp;gt; from &amp;lt;code&amp;gt;ssl/heartbeat_test.c&amp;lt;/code&amp;gt;. If need be, you can define suite-specific &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; functions that call the common &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; and elaborate on it. (This generally shouldn't be necessary for &amp;lt;code&amp;gt;tear_down()&amp;lt;/code&amp;gt;.)&lt;br /&gt;
&lt;br /&gt;
=== Keep individual test case functions focused on one thing ===&lt;br /&gt;
If the test name contains the word &amp;quot;and&amp;quot;, consider breaking it into two or more separate test case functions.&lt;br /&gt;
&lt;br /&gt;
=== Write very descriptive error messages ===&lt;br /&gt;
Include the test case function name in each error message, and explain in detail the context for the assertion that failed. Include the expected result (contained in the fixture structure) and the actual result returned from the code under test. Write helper methods for complex values as needed (e.g. &amp;lt;code&amp;gt;print_payload()&amp;lt;/code&amp;gt; in &amp;lt;code&amp;gt;ssl/heartbeat_test.c&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
=== Return zero on success and one on failure ===&lt;br /&gt;
The return value will be used to tally the number of test cases that failed. Even if multiple assertions fail for a single test case, the result should be exactly one.&lt;br /&gt;
&lt;br /&gt;
=== Add each test case function to the test runner function ===&lt;br /&gt;
Whatever function is used to execute the batch of test case functions, be that &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt; or a separate function called by &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt;, don't forget to add your test case functions to that function.&lt;br /&gt;
&lt;br /&gt;
TODO(mbland): create some kind of automated script or editor macros?&lt;br /&gt;
&lt;br /&gt;
=== Report the number of test cases that failed ===&lt;br /&gt;
Add up the total number of failed test cases in &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt; and report that number as the last error message of the test. &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt; should return &amp;lt;code&amp;gt;EXIT_FAILURE&amp;lt;/code&amp;gt; if any test cases failed, &amp;lt;code&amp;gt;EXIT_SUCCESS&amp;lt;/code&amp;gt; otherwise.&lt;br /&gt;
&lt;br /&gt;
=== Disable for Windows (for now) ===&lt;br /&gt;
Until we solve the private-symbol problem on Windows, we will need to wrap our unit test code in the following &amp;lt;code&amp;gt;#ifdef&amp;lt;/code&amp;gt; block:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#if !defined(OPENSSL_SYS_WINDOWS)&lt;br /&gt;
&lt;br /&gt;
/* All the test code, including main() */&lt;br /&gt;
&lt;br /&gt;
int main(int argc, char *argv[])                                                &lt;br /&gt;
    {&lt;br /&gt;
        return EXIT_SUCCESS;                                                    &lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
#endif /* OPENSSL_NO_WINDOWS  */&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Samples ==&lt;br /&gt;
Existing tests that can be used as models for new tests.&lt;br /&gt;
* [http://git.openssl.org/gitweb/?p=openssl.git;a=blob;f=ssl/heartbeat_test.c ssl/heartbeat_test.c]: Follows [http://mike-bland.com/2014/06/05/pseudo-xunit-pattern.html the Pseudo-xUnit pattern]&lt;/div&gt;</summary>
		<author><name>Mbland</name></author>
	</entry>
	<entry>
		<id>https://wiki.openssl.org/index.php?title=How_To_Write_Unit_Tests_For_OpenSSL&amp;diff=1755</id>
		<title>How To Write Unit Tests For OpenSSL</title>
		<link rel="alternate" type="text/html" href="https://wiki.openssl.org/index.php?title=How_To_Write_Unit_Tests_For_OpenSSL&amp;diff=1755"/>
		<updated>2014-06-16T16:15:33Z</updated>

		<summary type="html">&lt;p&gt;Mbland: /* Send a pull request */ Mention that pull requests should be against the tests branch, which should be set by default.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This is an outline of the basic process and principles to follow when writing unit tests. This document will evolve quite a bit as the community gains experience.&lt;br /&gt;
&lt;br /&gt;
==Mechanics ==&lt;br /&gt;
=== Forking the Repo ===&lt;br /&gt;
For now, people contributing new unit tests for uncovered code (as opposed to submitting tests with new code changes) should fork [https://github.com/mbland/openssl Mike Bland's GitHub repository] and issue [https://help.github.com/articles/using-pull-requests GitHub pull requests]. Remember to do all development on a topic branch (not &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt;). Tests committed to this repo will occasionally get merged into the master OpenSSL repo.&lt;br /&gt;
&lt;br /&gt;
Rationale per Matt Caswell: We should think about process here. If you are going off to recruit an army of people writing tests then I wonder if it is worth setting up a separate github repository whilst you are building up the tests. We can then merge in from that on a periodic basis. I wouldn't want availability of openssl team committers to be a bottle neck.&lt;br /&gt;
&lt;br /&gt;
Set up the [https://github.com/openssl/openssl OpenSSL master repository] as your upstream remote as per [https://help.github.com/articles/fork-a-repo#step-3-configure-remotes GitHub's instructions on configuring remotes]:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ cd my-openssl-repo&lt;br /&gt;
$ git remote add upstream https://github.com/openssl/openssl.git&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You should see the following output from &amp;lt;code&amp;gt;git remove -v&amp;lt;/code&amp;gt; (where &amp;lt;code&amp;gt;$USER&amp;lt;/code&amp;gt; is your GitHub username):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ git remote -v&lt;br /&gt;
origin  https://github.com/$USER/openssl.git (fetch)&lt;br /&gt;
origin  https://github.com/$USER/openssl.git (push)&lt;br /&gt;
upstream        https://github.com/openssl/openssl.git (fetch)&lt;br /&gt;
upstream        https://github.com/openssl/openssl.git (push)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Check out the Tools and Tips page ===&lt;br /&gt;
[[Testing and Development Tools and Tips]] has information on tools that may make navigating and building the code a bit easier.&lt;br /&gt;
&lt;br /&gt;
=== Use the Test Template Generator ===&lt;br /&gt;
TODO(mbland): Get template generator checked-in. Maybe have a template generator for each library, e.g. &amp;lt;code&amp;gt;ssl/new-test.sh&amp;lt;/code&amp;gt; that has additional setup boilerplate specific to the &amp;lt;code&amp;gt;ssl&amp;lt;/code&amp;gt; library.&lt;br /&gt;
&lt;br /&gt;
Use the &amp;lt;code&amp;gt;test/new-test.sh&amp;lt;/code&amp;gt; script to generate a skeleton test file. ([https://github.com/mbland/openssl/compare/test-util pending in the test-util branch])&lt;br /&gt;
&lt;br /&gt;
=== Add Makefile Targets ===&lt;br /&gt;
The following instructions use the &amp;lt;code&amp;gt;Makefile&amp;lt;/code&amp;gt; targets for &amp;lt;code&amp;gt;ssl/heartbeat_test.c&amp;lt;/code&amp;gt; as an example.&lt;br /&gt;
&lt;br /&gt;
In the &amp;lt;code&amp;gt;Makefile&amp;lt;/code&amp;gt; for the library containing the test, add the test source file to the &amp;lt;code&amp;gt;TEST&amp;lt;/code&amp;gt; variable:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# ssl/Makefile&lt;br /&gt;
TEST=ssltest.c heartbeat_test.c&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In &amp;lt;code&amp;gt;test/Makefile&amp;lt;/code&amp;gt;:&lt;br /&gt;
* add a variable for the test target near the top of the file, right after the existing test variables&lt;br /&gt;
* use the variable to add an executable target to the &amp;lt;code&amp;gt;EXE&amp;lt;/code&amp;gt; variable&lt;br /&gt;
* use the variable to add an object file target to the &amp;lt;code&amp;gt;OBJ&amp;lt;/code&amp;gt; variable&lt;br /&gt;
* use the variable to add a source file target to the &amp;lt;code&amp;gt;SRC&amp;lt;/code&amp;gt; variable&lt;br /&gt;
* add the test target to the &amp;lt;code&amp;gt;alltests&amp;lt;/code&amp;gt; target&lt;br /&gt;
* add the target to execute the test&lt;br /&gt;
* add the target to build the test executable&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# test/Makefile&lt;br /&gt;
HEARTBEATTEST=  heartbeat_test&lt;br /&gt;
EXE=  ... $(HEARTBEATTEST)$(EXE_EXT)&lt;br /&gt;
OBJ= ... $(HEARTBEATTEST).o&lt;br /&gt;
SRC= ... $(HEARTBEATTEST).c&lt;br /&gt;
alltests: \&lt;br /&gt;
        ... test_heartbeat&lt;br /&gt;
&lt;br /&gt;
test_heartbeat: $(HEARTBEATTEST)$(EXE_EXT)&lt;br /&gt;
  ../util/shlib_wrap.sh ./$(HEARTBEATTEST)&lt;br /&gt;
&lt;br /&gt;
$(HEARTBEATTEST)$(EXE_EXT): $(HEARTBEATTEST).o $(DLIBCRYPTO)&lt;br /&gt;
  @target=$(HEARTBEATTEST); $(BUILD_CMD)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Run &amp;lt;code&amp;gt;make depend&amp;lt;/code&amp;gt; ===&lt;br /&gt;
Finally, run &amp;lt;code&amp;gt;make depend&amp;lt;/code&amp;gt; to automatically generate the header file dependencies.&lt;br /&gt;
&lt;br /&gt;
=== Building and Running the Test ===&lt;br /&gt;
If you're initially developing on Mac OS X or (for now) FreeBSD 10, just use the stock method of building and testing:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ ./config &amp;amp;&amp;amp; make &amp;amp;&amp;amp; make test&lt;br /&gt;
&lt;br /&gt;
# To execute just one specific test&lt;br /&gt;
$ make TESTS=test_heartbeat test &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Ultimately the test will have to compile and pass with developer flags enabled:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ ./GitConfigure debug-ben-debug-64-clang&lt;br /&gt;
$ ./GitMake -j 2&lt;br /&gt;
$ ./GitMake test_heartbeat&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above currently doesn't work on Mac OS X or FreeBSD 10; for now, you can install the 9.1 release of [http://www.freebsd.org/ FreeBSD], which uses Clang 3.1, via a virtualization platform such as [https://www.virtualbox.org/ VirtualBox]. (Mac OS X breaks, in part, due to the fact that it doesn't use the GNU assembler; &amp;lt;code&amp;gt;-fsanitize&amp;lt;/code&amp;gt; appears to be ignored on FreeBSD 9.1/Clang 3.1, but later versions break because the Clang compiler will emit &amp;lt;code&amp;gt;-fsanitize&amp;lt;/code&amp;gt; symbols but the &amp;lt;code&amp;gt;libasan&amp;lt;/code&amp;gt; library [http://lists.freebsd.org/pipermail/freebsd-hackers/2013-December/043995.html has yet to be ported to FreeBSD].)&lt;br /&gt;
&lt;br /&gt;
=== Keep your repo up-to-date ===&lt;br /&gt;
Periodically run the following to keep your branch up-to-date:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ git fetch upstream master&lt;br /&gt;
$ git rebase upstream/master&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This will pull all the updates from the master OpenSSL repository into your repository, then update your branch to apply your changes on top of the latest updates.&lt;br /&gt;
&lt;br /&gt;
=== Send a pull request ===&lt;br /&gt;
When your test is ready, send a [https://help.github.com/articles/using-pull-requests GitHub pull request]. Note that the pull request should be based on the &amp;lt;code&amp;gt;tests&amp;lt;/code&amp;gt; branch of Mike's repository, not &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt;. (This should be the default; let Mike know if it doesn't appear to be!) We'll review the code, and when it's ready, it'll get merged into Mike's repository. From there, it will eventually get pulled into the master OpenSSL repository.&lt;br /&gt;
&lt;br /&gt;
== Style ==&lt;br /&gt;
[http://mike-bland.com/2014/06/05/pseudo-xunit-pattern.html The Pseudo-xUnit Pattern] is that established by [http://git.openssl.org/gitweb/?p=openssl.git;a=blob;f=ssl/heartbeat_test.c ssl/heartbeat_test.c]. This pattern organizes code in a fashion reminiscent of the [http://en.wikipedia.org/wiki/XUnit xUnit] family of unit testing frameworks, without actually using a testing framework. This should lower the barrier to entry for people wanting to write unit tests, but enable a relatively easy migration to an xUnit-based framework if we decide to do so one day.&lt;br /&gt;
&lt;br /&gt;
Some of the basic principles to follow are:&lt;br /&gt;
&lt;br /&gt;
=== Define a fixture structure ===&lt;br /&gt;
The fixture structure should contain all of the inputs to the code under test and all of the expected result values. It should also contain a &amp;lt;code&amp;gt;const char*&amp;lt;/code&amp;gt; for the name of the test case function that created it, to aid in error message formatting. Even though the fixture may contain dynamically-allocated members, the fixture itself should be copied by value to reduce the necessary degree of memory management in a small unit test program.&lt;br /&gt;
&lt;br /&gt;
=== Define set_up() and tear_down() functions for the fixture ===&lt;br /&gt;
&amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; should return a newly-initialized test fixture structure. It should take the name of the test case as an argument (i.e. &amp;lt;code&amp;gt;__func__&amp;lt;/code&amp;gt;) and assign it to the fixture. All of the fixture members should be initialized, which each test case function can then override as needed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;tear_down()&amp;lt;/code&amp;gt; should take the fixture as an argument and release any resources allocated by &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt;. It can also call any library-wide error printing routines (e.g. &amp;lt;code&amp;gt;ERR_print_errors_fp(stderr)&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
=== Use &amp;lt;code&amp;gt;SETUP_TEST_FIXTURE()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;EXECUTE_TEST()&amp;lt;/code&amp;gt; from &amp;lt;code&amp;gt;test/testutil.h&amp;lt;/code&amp;gt; ===&lt;br /&gt;
Each test case function should call &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; as its first statement, and should call &amp;lt;code&amp;gt;tear_down()&amp;lt;/code&amp;gt; just before returning. This is handled in a uniform fashion when using the &amp;lt;code&amp;gt;SETUP_TEST_FIXTURE()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;EXECUTE_TEST()&amp;lt;/code&amp;gt; helper macros from [http://git.openssl.org/gitweb/?p=openssl.git;a=blob;f=test/testutil.h test/testutil.h]. See the comments in &amp;lt;code&amp;gt;test/testutil.h&amp;lt;/code&amp;gt; for usage, and &amp;lt;code&amp;gt;ssl/heartbeat_test.c&amp;lt;/code&amp;gt; for an example of how to wrap the macros for a specific unit test.&lt;br /&gt;
&lt;br /&gt;
=== Use test case functions, not a table of fixtures ===&lt;br /&gt;
Individual test case functions that call a common execution function are much more readable and maintainable than a loop over a table of fixture structures. Explicit fixture variable assignments aid comprehension when reading a specific test case, which saves time and energy when trying to understand a test or diagnose a failure. When a new member is added to an existing fixture, &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; can set a default for all test cases, and only the test cases that rely on that new member need to be updated.&lt;br /&gt;
&lt;br /&gt;
=== Use very descriptive test case names ===&lt;br /&gt;
Give tests long, descriptive names that provide ample context for the details of the test case. Good test names are also help produce good error messages.&lt;br /&gt;
&lt;br /&gt;
=== Group test cases into &amp;quot;suites&amp;quot; by naming convention ===&lt;br /&gt;
Give logically-related tests the same prefix, e.g. &amp;lt;code&amp;gt;test_dtls1_&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;test_tls1&amp;lt;/code&amp;gt; from &amp;lt;code&amp;gt;ssl/heartbeat_test.c&amp;lt;/code&amp;gt;. If need be, you can define suite-specific &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; functions that call the common &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; and elaborate on it. (This generally shouldn't be necessary for &amp;lt;code&amp;gt;tear_down()&amp;lt;/code&amp;gt;.)&lt;br /&gt;
&lt;br /&gt;
=== Keep individual test case functions focused on one thing ===&lt;br /&gt;
If the test name contains the word &amp;quot;and&amp;quot;, consider breaking it into two or more separate test case functions.&lt;br /&gt;
&lt;br /&gt;
=== Write very descriptive error messages ===&lt;br /&gt;
Include the test case function name in each error message, and explain in detail the context for the assertion that failed. Include the expected result (contained in the fixture structure) and the actual result returned from the code under test. Write helper methods for complex values as needed (e.g. &amp;lt;code&amp;gt;print_payload()&amp;lt;/code&amp;gt; in &amp;lt;code&amp;gt;ssl/heartbeat_test.c&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
=== Return zero on success and one on failure ===&lt;br /&gt;
The return value will be used to tally the number of test cases that failed. Even if multiple assertions fail for a single test case, the result should be exactly one.&lt;br /&gt;
&lt;br /&gt;
=== Add each test case function to the test runner function ===&lt;br /&gt;
Whatever function is used to execute the batch of test case functions, be that &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt; or a separate function called by &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt;, don't forget to add your test case functions to that function.&lt;br /&gt;
&lt;br /&gt;
TODO(mbland): create some kind of automated script or editor macros?&lt;br /&gt;
&lt;br /&gt;
=== Report the number of test cases that failed ===&lt;br /&gt;
Add up the total number of failed test cases in &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt; and report that number as the last error message of the test. &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt; should return &amp;lt;code&amp;gt;EXIT_FAILURE&amp;lt;/code&amp;gt; if any test cases failed, &amp;lt;code&amp;gt;EXIT_SUCCESS&amp;lt;/code&amp;gt; otherwise.&lt;br /&gt;
&lt;br /&gt;
=== Disable for Windows (for now) ===&lt;br /&gt;
Until we solve the private-symbol problem on Windows, we will need to wrap our unit test code in the following &amp;lt;code&amp;gt;#ifdef&amp;lt;/code&amp;gt; block:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#if !defined(OPENSSL_SYS_WINDOWS)&lt;br /&gt;
&lt;br /&gt;
/* All the test code, including main() */&lt;br /&gt;
&lt;br /&gt;
int main(int argc, char *argv[])                                                &lt;br /&gt;
    {&lt;br /&gt;
        return EXIT_SUCCESS;                                                    &lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
#endif /* OPENSSL_NO_WINDOWS  */&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Samples ==&lt;br /&gt;
Existing tests that can be used as models for new tests.&lt;br /&gt;
* [http://git.openssl.org/gitweb/?p=openssl.git;a=blob;f=ssl/heartbeat_test.c ssl/heartbeat_test.c]: Follows [http://mike-bland.com/2014/06/05/pseudo-xunit-pattern.html the Pseudo-xUnit pattern]&lt;/div&gt;</summary>
		<author><name>Mbland</name></author>
	</entry>
	<entry>
		<id>https://wiki.openssl.org/index.php?title=How_To_Write_Unit_Tests_For_OpenSSL&amp;diff=1754</id>
		<title>How To Write Unit Tests For OpenSSL</title>
		<link rel="alternate" type="text/html" href="https://wiki.openssl.org/index.php?title=How_To_Write_Unit_Tests_For_OpenSSL&amp;diff=1754"/>
		<updated>2014-06-16T16:12:56Z</updated>

		<summary type="html">&lt;p&gt;Mbland: /* Keep your repo up-to-date */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This is an outline of the basic process and principles to follow when writing unit tests. This document will evolve quite a bit as the community gains experience.&lt;br /&gt;
&lt;br /&gt;
==Mechanics ==&lt;br /&gt;
=== Forking the Repo ===&lt;br /&gt;
For now, people contributing new unit tests for uncovered code (as opposed to submitting tests with new code changes) should fork [https://github.com/mbland/openssl Mike Bland's GitHub repository] and issue [https://help.github.com/articles/using-pull-requests GitHub pull requests]. Remember to do all development on a topic branch (not &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt;). Tests committed to this repo will occasionally get merged into the master OpenSSL repo.&lt;br /&gt;
&lt;br /&gt;
Rationale per Matt Caswell: We should think about process here. If you are going off to recruit an army of people writing tests then I wonder if it is worth setting up a separate github repository whilst you are building up the tests. We can then merge in from that on a periodic basis. I wouldn't want availability of openssl team committers to be a bottle neck.&lt;br /&gt;
&lt;br /&gt;
Set up the [https://github.com/openssl/openssl OpenSSL master repository] as your upstream remote as per [https://help.github.com/articles/fork-a-repo#step-3-configure-remotes GitHub's instructions on configuring remotes]:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ cd my-openssl-repo&lt;br /&gt;
$ git remote add upstream https://github.com/openssl/openssl.git&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You should see the following output from &amp;lt;code&amp;gt;git remove -v&amp;lt;/code&amp;gt; (where &amp;lt;code&amp;gt;$USER&amp;lt;/code&amp;gt; is your GitHub username):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ git remote -v&lt;br /&gt;
origin  https://github.com/$USER/openssl.git (fetch)&lt;br /&gt;
origin  https://github.com/$USER/openssl.git (push)&lt;br /&gt;
upstream        https://github.com/openssl/openssl.git (fetch)&lt;br /&gt;
upstream        https://github.com/openssl/openssl.git (push)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Check out the Tools and Tips page ===&lt;br /&gt;
[[Testing and Development Tools and Tips]] has information on tools that may make navigating and building the code a bit easier.&lt;br /&gt;
&lt;br /&gt;
=== Use the Test Template Generator ===&lt;br /&gt;
TODO(mbland): Get template generator checked-in. Maybe have a template generator for each library, e.g. &amp;lt;code&amp;gt;ssl/new-test.sh&amp;lt;/code&amp;gt; that has additional setup boilerplate specific to the &amp;lt;code&amp;gt;ssl&amp;lt;/code&amp;gt; library.&lt;br /&gt;
&lt;br /&gt;
Use the &amp;lt;code&amp;gt;test/new-test.sh&amp;lt;/code&amp;gt; script to generate a skeleton test file. ([https://github.com/mbland/openssl/compare/test-util pending in the test-util branch])&lt;br /&gt;
&lt;br /&gt;
=== Add Makefile Targets ===&lt;br /&gt;
The following instructions use the &amp;lt;code&amp;gt;Makefile&amp;lt;/code&amp;gt; targets for &amp;lt;code&amp;gt;ssl/heartbeat_test.c&amp;lt;/code&amp;gt; as an example.&lt;br /&gt;
&lt;br /&gt;
In the &amp;lt;code&amp;gt;Makefile&amp;lt;/code&amp;gt; for the library containing the test, add the test source file to the &amp;lt;code&amp;gt;TEST&amp;lt;/code&amp;gt; variable:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# ssl/Makefile&lt;br /&gt;
TEST=ssltest.c heartbeat_test.c&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In &amp;lt;code&amp;gt;test/Makefile&amp;lt;/code&amp;gt;:&lt;br /&gt;
* add a variable for the test target near the top of the file, right after the existing test variables&lt;br /&gt;
* use the variable to add an executable target to the &amp;lt;code&amp;gt;EXE&amp;lt;/code&amp;gt; variable&lt;br /&gt;
* use the variable to add an object file target to the &amp;lt;code&amp;gt;OBJ&amp;lt;/code&amp;gt; variable&lt;br /&gt;
* use the variable to add a source file target to the &amp;lt;code&amp;gt;SRC&amp;lt;/code&amp;gt; variable&lt;br /&gt;
* add the test target to the &amp;lt;code&amp;gt;alltests&amp;lt;/code&amp;gt; target&lt;br /&gt;
* add the target to execute the test&lt;br /&gt;
* add the target to build the test executable&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# test/Makefile&lt;br /&gt;
HEARTBEATTEST=  heartbeat_test&lt;br /&gt;
EXE=  ... $(HEARTBEATTEST)$(EXE_EXT)&lt;br /&gt;
OBJ= ... $(HEARTBEATTEST).o&lt;br /&gt;
SRC= ... $(HEARTBEATTEST).c&lt;br /&gt;
alltests: \&lt;br /&gt;
        ... test_heartbeat&lt;br /&gt;
&lt;br /&gt;
test_heartbeat: $(HEARTBEATTEST)$(EXE_EXT)&lt;br /&gt;
  ../util/shlib_wrap.sh ./$(HEARTBEATTEST)&lt;br /&gt;
&lt;br /&gt;
$(HEARTBEATTEST)$(EXE_EXT): $(HEARTBEATTEST).o $(DLIBCRYPTO)&lt;br /&gt;
  @target=$(HEARTBEATTEST); $(BUILD_CMD)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Run &amp;lt;code&amp;gt;make depend&amp;lt;/code&amp;gt; ===&lt;br /&gt;
Finally, run &amp;lt;code&amp;gt;make depend&amp;lt;/code&amp;gt; to automatically generate the header file dependencies.&lt;br /&gt;
&lt;br /&gt;
=== Building and Running the Test ===&lt;br /&gt;
If you're initially developing on Mac OS X or (for now) FreeBSD 10, just use the stock method of building and testing:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ ./config &amp;amp;&amp;amp; make &amp;amp;&amp;amp; make test&lt;br /&gt;
&lt;br /&gt;
# To execute just one specific test&lt;br /&gt;
$ make TESTS=test_heartbeat test &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Ultimately the test will have to compile and pass with developer flags enabled:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ ./GitConfigure debug-ben-debug-64-clang&lt;br /&gt;
$ ./GitMake -j 2&lt;br /&gt;
$ ./GitMake test_heartbeat&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above currently doesn't work on Mac OS X or FreeBSD 10; for now, you can install the 9.1 release of [http://www.freebsd.org/ FreeBSD], which uses Clang 3.1, via a virtualization platform such as [https://www.virtualbox.org/ VirtualBox]. (Mac OS X breaks, in part, due to the fact that it doesn't use the GNU assembler; &amp;lt;code&amp;gt;-fsanitize&amp;lt;/code&amp;gt; appears to be ignored on FreeBSD 9.1/Clang 3.1, but later versions break because the Clang compiler will emit &amp;lt;code&amp;gt;-fsanitize&amp;lt;/code&amp;gt; symbols but the &amp;lt;code&amp;gt;libasan&amp;lt;/code&amp;gt; library [http://lists.freebsd.org/pipermail/freebsd-hackers/2013-December/043995.html has yet to be ported to FreeBSD].)&lt;br /&gt;
&lt;br /&gt;
=== Keep your repo up-to-date ===&lt;br /&gt;
Periodically run the following to keep your branch up-to-date:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ git fetch upstream master&lt;br /&gt;
$ git rebase upstream/master&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This will pull all the updates from the master OpenSSL repository into your repository, then update your branch to apply your changes on top of the latest updates.&lt;br /&gt;
&lt;br /&gt;
=== Send a pull request ===&lt;br /&gt;
When your test is ready, send a [https://help.github.com/articles/using-pull-requests GitHub pull request]. We'll review the code, and when it's ready, it'll get merged into Mike's repository. From there, it will eventually get pulled into the master OpenSSL repository.&lt;br /&gt;
&lt;br /&gt;
== Style ==&lt;br /&gt;
[http://mike-bland.com/2014/06/05/pseudo-xunit-pattern.html The Pseudo-xUnit Pattern] is that established by [http://git.openssl.org/gitweb/?p=openssl.git;a=blob;f=ssl/heartbeat_test.c ssl/heartbeat_test.c]. This pattern organizes code in a fashion reminiscent of the [http://en.wikipedia.org/wiki/XUnit xUnit] family of unit testing frameworks, without actually using a testing framework. This should lower the barrier to entry for people wanting to write unit tests, but enable a relatively easy migration to an xUnit-based framework if we decide to do so one day.&lt;br /&gt;
&lt;br /&gt;
Some of the basic principles to follow are:&lt;br /&gt;
&lt;br /&gt;
=== Define a fixture structure ===&lt;br /&gt;
The fixture structure should contain all of the inputs to the code under test and all of the expected result values. It should also contain a &amp;lt;code&amp;gt;const char*&amp;lt;/code&amp;gt; for the name of the test case function that created it, to aid in error message formatting. Even though the fixture may contain dynamically-allocated members, the fixture itself should be copied by value to reduce the necessary degree of memory management in a small unit test program.&lt;br /&gt;
&lt;br /&gt;
=== Define set_up() and tear_down() functions for the fixture ===&lt;br /&gt;
&amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; should return a newly-initialized test fixture structure. It should take the name of the test case as an argument (i.e. &amp;lt;code&amp;gt;__func__&amp;lt;/code&amp;gt;) and assign it to the fixture. All of the fixture members should be initialized, which each test case function can then override as needed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;tear_down()&amp;lt;/code&amp;gt; should take the fixture as an argument and release any resources allocated by &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt;. It can also call any library-wide error printing routines (e.g. &amp;lt;code&amp;gt;ERR_print_errors_fp(stderr)&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
=== Use &amp;lt;code&amp;gt;SETUP_TEST_FIXTURE()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;EXECUTE_TEST()&amp;lt;/code&amp;gt; from &amp;lt;code&amp;gt;test/testutil.h&amp;lt;/code&amp;gt; ===&lt;br /&gt;
Each test case function should call &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; as its first statement, and should call &amp;lt;code&amp;gt;tear_down()&amp;lt;/code&amp;gt; just before returning. This is handled in a uniform fashion when using the &amp;lt;code&amp;gt;SETUP_TEST_FIXTURE()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;EXECUTE_TEST()&amp;lt;/code&amp;gt; helper macros from [http://git.openssl.org/gitweb/?p=openssl.git;a=blob;f=test/testutil.h test/testutil.h]. See the comments in &amp;lt;code&amp;gt;test/testutil.h&amp;lt;/code&amp;gt; for usage, and &amp;lt;code&amp;gt;ssl/heartbeat_test.c&amp;lt;/code&amp;gt; for an example of how to wrap the macros for a specific unit test.&lt;br /&gt;
&lt;br /&gt;
=== Use test case functions, not a table of fixtures ===&lt;br /&gt;
Individual test case functions that call a common execution function are much more readable and maintainable than a loop over a table of fixture structures. Explicit fixture variable assignments aid comprehension when reading a specific test case, which saves time and energy when trying to understand a test or diagnose a failure. When a new member is added to an existing fixture, &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; can set a default for all test cases, and only the test cases that rely on that new member need to be updated.&lt;br /&gt;
&lt;br /&gt;
=== Use very descriptive test case names ===&lt;br /&gt;
Give tests long, descriptive names that provide ample context for the details of the test case. Good test names are also help produce good error messages.&lt;br /&gt;
&lt;br /&gt;
=== Group test cases into &amp;quot;suites&amp;quot; by naming convention ===&lt;br /&gt;
Give logically-related tests the same prefix, e.g. &amp;lt;code&amp;gt;test_dtls1_&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;test_tls1&amp;lt;/code&amp;gt; from &amp;lt;code&amp;gt;ssl/heartbeat_test.c&amp;lt;/code&amp;gt;. If need be, you can define suite-specific &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; functions that call the common &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; and elaborate on it. (This generally shouldn't be necessary for &amp;lt;code&amp;gt;tear_down()&amp;lt;/code&amp;gt;.)&lt;br /&gt;
&lt;br /&gt;
=== Keep individual test case functions focused on one thing ===&lt;br /&gt;
If the test name contains the word &amp;quot;and&amp;quot;, consider breaking it into two or more separate test case functions.&lt;br /&gt;
&lt;br /&gt;
=== Write very descriptive error messages ===&lt;br /&gt;
Include the test case function name in each error message, and explain in detail the context for the assertion that failed. Include the expected result (contained in the fixture structure) and the actual result returned from the code under test. Write helper methods for complex values as needed (e.g. &amp;lt;code&amp;gt;print_payload()&amp;lt;/code&amp;gt; in &amp;lt;code&amp;gt;ssl/heartbeat_test.c&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
=== Return zero on success and one on failure ===&lt;br /&gt;
The return value will be used to tally the number of test cases that failed. Even if multiple assertions fail for a single test case, the result should be exactly one.&lt;br /&gt;
&lt;br /&gt;
=== Add each test case function to the test runner function ===&lt;br /&gt;
Whatever function is used to execute the batch of test case functions, be that &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt; or a separate function called by &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt;, don't forget to add your test case functions to that function.&lt;br /&gt;
&lt;br /&gt;
TODO(mbland): create some kind of automated script or editor macros?&lt;br /&gt;
&lt;br /&gt;
=== Report the number of test cases that failed ===&lt;br /&gt;
Add up the total number of failed test cases in &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt; and report that number as the last error message of the test. &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt; should return &amp;lt;code&amp;gt;EXIT_FAILURE&amp;lt;/code&amp;gt; if any test cases failed, &amp;lt;code&amp;gt;EXIT_SUCCESS&amp;lt;/code&amp;gt; otherwise.&lt;br /&gt;
&lt;br /&gt;
=== Disable for Windows (for now) ===&lt;br /&gt;
Until we solve the private-symbol problem on Windows, we will need to wrap our unit test code in the following &amp;lt;code&amp;gt;#ifdef&amp;lt;/code&amp;gt; block:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#if !defined(OPENSSL_SYS_WINDOWS)&lt;br /&gt;
&lt;br /&gt;
/* All the test code, including main() */&lt;br /&gt;
&lt;br /&gt;
int main(int argc, char *argv[])                                                &lt;br /&gt;
    {&lt;br /&gt;
        return EXIT_SUCCESS;                                                    &lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
#endif /* OPENSSL_NO_WINDOWS  */&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Samples ==&lt;br /&gt;
Existing tests that can be used as models for new tests.&lt;br /&gt;
* [http://git.openssl.org/gitweb/?p=openssl.git;a=blob;f=ssl/heartbeat_test.c ssl/heartbeat_test.c]: Follows [http://mike-bland.com/2014/06/05/pseudo-xunit-pattern.html the Pseudo-xUnit pattern]&lt;/div&gt;</summary>
		<author><name>Mbland</name></author>
	</entry>
	<entry>
		<id>https://wiki.openssl.org/index.php?title=How_To_Write_Unit_Tests_For_OpenSSL&amp;diff=1753</id>
		<title>How To Write Unit Tests For OpenSSL</title>
		<link rel="alternate" type="text/html" href="https://wiki.openssl.org/index.php?title=How_To_Write_Unit_Tests_For_OpenSSL&amp;diff=1753"/>
		<updated>2014-06-16T16:06:16Z</updated>

		<summary type="html">&lt;p&gt;Mbland: /* Mechanics */ Better git remote and rebase instructions.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This is an outline of the basic process and principles to follow when writing unit tests. This document will evolve quite a bit as the community gains experience.&lt;br /&gt;
&lt;br /&gt;
==Mechanics ==&lt;br /&gt;
=== Forking the Repo ===&lt;br /&gt;
For now, people contributing new unit tests for uncovered code (as opposed to submitting tests with new code changes) should fork [https://github.com/mbland/openssl Mike Bland's GitHub repository] and issue [https://help.github.com/articles/using-pull-requests GitHub pull requests]. Remember to do all development on a topic branch (not &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt;). Tests committed to this repo will occasionally get merged into the master OpenSSL repo.&lt;br /&gt;
&lt;br /&gt;
Rationale per Matt Caswell: We should think about process here. If you are going off to recruit an army of people writing tests then I wonder if it is worth setting up a separate github repository whilst you are building up the tests. We can then merge in from that on a periodic basis. I wouldn't want availability of openssl team committers to be a bottle neck.&lt;br /&gt;
&lt;br /&gt;
Set up the [https://github.com/openssl/openssl OpenSSL master repository] as your upstream remote as per [https://help.github.com/articles/fork-a-repo#step-3-configure-remotes GitHub's instructions on configuring remotes]:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ cd my-openssl-repo&lt;br /&gt;
$ git remote add upstream https://github.com/openssl/openssl.git&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You should see the following output from &amp;lt;code&amp;gt;git remove -v&amp;lt;/code&amp;gt; (where &amp;lt;code&amp;gt;$USER&amp;lt;/code&amp;gt; is your GitHub username):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ git remote -v&lt;br /&gt;
origin  https://github.com/$USER/openssl.git (fetch)&lt;br /&gt;
origin  https://github.com/$USER/openssl.git (push)&lt;br /&gt;
upstream        https://github.com/openssl/openssl.git (fetch)&lt;br /&gt;
upstream        https://github.com/openssl/openssl.git (push)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Check out the Tools and Tips page ===&lt;br /&gt;
[[Testing and Development Tools and Tips]] has information on tools that may make navigating and building the code a bit easier.&lt;br /&gt;
&lt;br /&gt;
=== Use the Test Template Generator ===&lt;br /&gt;
TODO(mbland): Get template generator checked-in. Maybe have a template generator for each library, e.g. &amp;lt;code&amp;gt;ssl/new-test.sh&amp;lt;/code&amp;gt; that has additional setup boilerplate specific to the &amp;lt;code&amp;gt;ssl&amp;lt;/code&amp;gt; library.&lt;br /&gt;
&lt;br /&gt;
Use the &amp;lt;code&amp;gt;test/new-test.sh&amp;lt;/code&amp;gt; script to generate a skeleton test file. ([https://github.com/mbland/openssl/compare/test-util pending in the test-util branch])&lt;br /&gt;
&lt;br /&gt;
=== Add Makefile Targets ===&lt;br /&gt;
The following instructions use the &amp;lt;code&amp;gt;Makefile&amp;lt;/code&amp;gt; targets for &amp;lt;code&amp;gt;ssl/heartbeat_test.c&amp;lt;/code&amp;gt; as an example.&lt;br /&gt;
&lt;br /&gt;
In the &amp;lt;code&amp;gt;Makefile&amp;lt;/code&amp;gt; for the library containing the test, add the test source file to the &amp;lt;code&amp;gt;TEST&amp;lt;/code&amp;gt; variable:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# ssl/Makefile&lt;br /&gt;
TEST=ssltest.c heartbeat_test.c&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In &amp;lt;code&amp;gt;test/Makefile&amp;lt;/code&amp;gt;:&lt;br /&gt;
* add a variable for the test target near the top of the file, right after the existing test variables&lt;br /&gt;
* use the variable to add an executable target to the &amp;lt;code&amp;gt;EXE&amp;lt;/code&amp;gt; variable&lt;br /&gt;
* use the variable to add an object file target to the &amp;lt;code&amp;gt;OBJ&amp;lt;/code&amp;gt; variable&lt;br /&gt;
* use the variable to add a source file target to the &amp;lt;code&amp;gt;SRC&amp;lt;/code&amp;gt; variable&lt;br /&gt;
* add the test target to the &amp;lt;code&amp;gt;alltests&amp;lt;/code&amp;gt; target&lt;br /&gt;
* add the target to execute the test&lt;br /&gt;
* add the target to build the test executable&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# test/Makefile&lt;br /&gt;
HEARTBEATTEST=  heartbeat_test&lt;br /&gt;
EXE=  ... $(HEARTBEATTEST)$(EXE_EXT)&lt;br /&gt;
OBJ= ... $(HEARTBEATTEST).o&lt;br /&gt;
SRC= ... $(HEARTBEATTEST).c&lt;br /&gt;
alltests: \&lt;br /&gt;
        ... test_heartbeat&lt;br /&gt;
&lt;br /&gt;
test_heartbeat: $(HEARTBEATTEST)$(EXE_EXT)&lt;br /&gt;
  ../util/shlib_wrap.sh ./$(HEARTBEATTEST)&lt;br /&gt;
&lt;br /&gt;
$(HEARTBEATTEST)$(EXE_EXT): $(HEARTBEATTEST).o $(DLIBCRYPTO)&lt;br /&gt;
  @target=$(HEARTBEATTEST); $(BUILD_CMD)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Run &amp;lt;code&amp;gt;make depend&amp;lt;/code&amp;gt; ===&lt;br /&gt;
Finally, run &amp;lt;code&amp;gt;make depend&amp;lt;/code&amp;gt; to automatically generate the header file dependencies.&lt;br /&gt;
&lt;br /&gt;
=== Building and Running the Test ===&lt;br /&gt;
If you're initially developing on Mac OS X or (for now) FreeBSD 10, just use the stock method of building and testing:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ ./config &amp;amp;&amp;amp; make &amp;amp;&amp;amp; make test&lt;br /&gt;
&lt;br /&gt;
# To execute just one specific test&lt;br /&gt;
$ make TESTS=test_heartbeat test &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Ultimately the test will have to compile and pass with developer flags enabled:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ ./GitConfigure debug-ben-debug-64-clang&lt;br /&gt;
$ ./GitMake -j 2&lt;br /&gt;
$ ./GitMake test_heartbeat&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above currently doesn't work on Mac OS X or FreeBSD 10; for now, you can install the 9.1 release of [http://www.freebsd.org/ FreeBSD], which uses Clang 3.1, via a virtualization platform such as [https://www.virtualbox.org/ VirtualBox]. (Mac OS X breaks, in part, due to the fact that it doesn't use the GNU assembler; &amp;lt;code&amp;gt;-fsanitize&amp;lt;/code&amp;gt; appears to be ignored on FreeBSD 9.1/Clang 3.1, but later versions break because the Clang compiler will emit &amp;lt;code&amp;gt;-fsanitize&amp;lt;/code&amp;gt; symbols but the &amp;lt;code&amp;gt;libasan&amp;lt;/code&amp;gt; library [http://lists.freebsd.org/pipermail/freebsd-hackers/2013-December/043995.html has yet to be ported to FreeBSD].)&lt;br /&gt;
&lt;br /&gt;
=== Keep your repo up-to-date ===&lt;br /&gt;
Periodically run the following to keep your branch up-to-date:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ git fetch upstream master&lt;br /&gt;
$ git rebase upstream/master&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This will pull all the updates from the master OpenSSL repository into your repository, then update your branch to apply your changes on top of the latest updates from the master OpenSSL repository.&lt;br /&gt;
&lt;br /&gt;
=== Send a pull request ===&lt;br /&gt;
When your test is ready, send a [https://help.github.com/articles/using-pull-requests GitHub pull request]. We'll review the code, and when it's ready, it'll get merged into Mike's repository. From there, it will eventually get pulled into the master OpenSSL repository.&lt;br /&gt;
&lt;br /&gt;
== Style ==&lt;br /&gt;
[http://mike-bland.com/2014/06/05/pseudo-xunit-pattern.html The Pseudo-xUnit Pattern] is that established by [http://git.openssl.org/gitweb/?p=openssl.git;a=blob;f=ssl/heartbeat_test.c ssl/heartbeat_test.c]. This pattern organizes code in a fashion reminiscent of the [http://en.wikipedia.org/wiki/XUnit xUnit] family of unit testing frameworks, without actually using a testing framework. This should lower the barrier to entry for people wanting to write unit tests, but enable a relatively easy migration to an xUnit-based framework if we decide to do so one day.&lt;br /&gt;
&lt;br /&gt;
Some of the basic principles to follow are:&lt;br /&gt;
&lt;br /&gt;
=== Define a fixture structure ===&lt;br /&gt;
The fixture structure should contain all of the inputs to the code under test and all of the expected result values. It should also contain a &amp;lt;code&amp;gt;const char*&amp;lt;/code&amp;gt; for the name of the test case function that created it, to aid in error message formatting. Even though the fixture may contain dynamically-allocated members, the fixture itself should be copied by value to reduce the necessary degree of memory management in a small unit test program.&lt;br /&gt;
&lt;br /&gt;
=== Define set_up() and tear_down() functions for the fixture ===&lt;br /&gt;
&amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; should return a newly-initialized test fixture structure. It should take the name of the test case as an argument (i.e. &amp;lt;code&amp;gt;__func__&amp;lt;/code&amp;gt;) and assign it to the fixture. All of the fixture members should be initialized, which each test case function can then override as needed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;tear_down()&amp;lt;/code&amp;gt; should take the fixture as an argument and release any resources allocated by &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt;. It can also call any library-wide error printing routines (e.g. &amp;lt;code&amp;gt;ERR_print_errors_fp(stderr)&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
=== Use &amp;lt;code&amp;gt;SETUP_TEST_FIXTURE()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;EXECUTE_TEST()&amp;lt;/code&amp;gt; from &amp;lt;code&amp;gt;test/testutil.h&amp;lt;/code&amp;gt; ===&lt;br /&gt;
Each test case function should call &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; as its first statement, and should call &amp;lt;code&amp;gt;tear_down()&amp;lt;/code&amp;gt; just before returning. This is handled in a uniform fashion when using the &amp;lt;code&amp;gt;SETUP_TEST_FIXTURE()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;EXECUTE_TEST()&amp;lt;/code&amp;gt; helper macros from [http://git.openssl.org/gitweb/?p=openssl.git;a=blob;f=test/testutil.h test/testutil.h]. See the comments in &amp;lt;code&amp;gt;test/testutil.h&amp;lt;/code&amp;gt; for usage, and &amp;lt;code&amp;gt;ssl/heartbeat_test.c&amp;lt;/code&amp;gt; for an example of how to wrap the macros for a specific unit test.&lt;br /&gt;
&lt;br /&gt;
=== Use test case functions, not a table of fixtures ===&lt;br /&gt;
Individual test case functions that call a common execution function are much more readable and maintainable than a loop over a table of fixture structures. Explicit fixture variable assignments aid comprehension when reading a specific test case, which saves time and energy when trying to understand a test or diagnose a failure. When a new member is added to an existing fixture, &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; can set a default for all test cases, and only the test cases that rely on that new member need to be updated.&lt;br /&gt;
&lt;br /&gt;
=== Use very descriptive test case names ===&lt;br /&gt;
Give tests long, descriptive names that provide ample context for the details of the test case. Good test names are also help produce good error messages.&lt;br /&gt;
&lt;br /&gt;
=== Group test cases into &amp;quot;suites&amp;quot; by naming convention ===&lt;br /&gt;
Give logically-related tests the same prefix, e.g. &amp;lt;code&amp;gt;test_dtls1_&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;test_tls1&amp;lt;/code&amp;gt; from &amp;lt;code&amp;gt;ssl/heartbeat_test.c&amp;lt;/code&amp;gt;. If need be, you can define suite-specific &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; functions that call the common &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; and elaborate on it. (This generally shouldn't be necessary for &amp;lt;code&amp;gt;tear_down()&amp;lt;/code&amp;gt;.)&lt;br /&gt;
&lt;br /&gt;
=== Keep individual test case functions focused on one thing ===&lt;br /&gt;
If the test name contains the word &amp;quot;and&amp;quot;, consider breaking it into two or more separate test case functions.&lt;br /&gt;
&lt;br /&gt;
=== Write very descriptive error messages ===&lt;br /&gt;
Include the test case function name in each error message, and explain in detail the context for the assertion that failed. Include the expected result (contained in the fixture structure) and the actual result returned from the code under test. Write helper methods for complex values as needed (e.g. &amp;lt;code&amp;gt;print_payload()&amp;lt;/code&amp;gt; in &amp;lt;code&amp;gt;ssl/heartbeat_test.c&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
=== Return zero on success and one on failure ===&lt;br /&gt;
The return value will be used to tally the number of test cases that failed. Even if multiple assertions fail for a single test case, the result should be exactly one.&lt;br /&gt;
&lt;br /&gt;
=== Add each test case function to the test runner function ===&lt;br /&gt;
Whatever function is used to execute the batch of test case functions, be that &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt; or a separate function called by &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt;, don't forget to add your test case functions to that function.&lt;br /&gt;
&lt;br /&gt;
TODO(mbland): create some kind of automated script or editor macros?&lt;br /&gt;
&lt;br /&gt;
=== Report the number of test cases that failed ===&lt;br /&gt;
Add up the total number of failed test cases in &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt; and report that number as the last error message of the test. &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt; should return &amp;lt;code&amp;gt;EXIT_FAILURE&amp;lt;/code&amp;gt; if any test cases failed, &amp;lt;code&amp;gt;EXIT_SUCCESS&amp;lt;/code&amp;gt; otherwise.&lt;br /&gt;
&lt;br /&gt;
=== Disable for Windows (for now) ===&lt;br /&gt;
Until we solve the private-symbol problem on Windows, we will need to wrap our unit test code in the following &amp;lt;code&amp;gt;#ifdef&amp;lt;/code&amp;gt; block:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#if !defined(OPENSSL_SYS_WINDOWS)&lt;br /&gt;
&lt;br /&gt;
/* All the test code, including main() */&lt;br /&gt;
&lt;br /&gt;
int main(int argc, char *argv[])                                                &lt;br /&gt;
    {&lt;br /&gt;
        return EXIT_SUCCESS;                                                    &lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
#endif /* OPENSSL_NO_WINDOWS  */&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Samples ==&lt;br /&gt;
Existing tests that can be used as models for new tests.&lt;br /&gt;
* [http://git.openssl.org/gitweb/?p=openssl.git;a=blob;f=ssl/heartbeat_test.c ssl/heartbeat_test.c]: Follows [http://mike-bland.com/2014/06/05/pseudo-xunit-pattern.html the Pseudo-xUnit pattern]&lt;/div&gt;</summary>
		<author><name>Mbland</name></author>
	</entry>
	<entry>
		<id>https://wiki.openssl.org/index.php?title=How_To_Write_Unit_Tests_For_OpenSSL&amp;diff=1752</id>
		<title>How To Write Unit Tests For OpenSSL</title>
		<link rel="alternate" type="text/html" href="https://wiki.openssl.org/index.php?title=How_To_Write_Unit_Tests_For_OpenSSL&amp;diff=1752"/>
		<updated>2014-06-16T15:59:04Z</updated>

		<summary type="html">&lt;p&gt;Mbland: /* Keep your repo up-to-date */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This is an outline of the basic process and principles to follow when writing unit tests. This document will evolve quite a bit as the community gains experience.&lt;br /&gt;
&lt;br /&gt;
==Mechanics ==&lt;br /&gt;
=== Forking the Repo ===&lt;br /&gt;
For now, people contributing new unit tests for uncovered code (as opposed to submitting tests with new code changes) should fork [https://github.com/mbland/openssl Mike Bland's GitHub repository] and issue [https://help.github.com/articles/using-pull-requests GitHub pull requests]. Remember to do all development on a topic branch (not &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt;). Tests committed to this repo will occasionally get merged into the master OpenSSL repo.&lt;br /&gt;
&lt;br /&gt;
Rationale per Matt Caswell: We should think about process here. If you are going off to recruit an army of people writing tests then I wonder if it is worth setting up a separate github repository whilst you are building up the tests. We can then merge in from that on a periodic basis. I wouldn't want availability of openssl team committers to be a bottle neck.&lt;br /&gt;
&lt;br /&gt;
=== Check out the Tools and Tips page ===&lt;br /&gt;
[[Testing and Development Tools and Tips]] has information on tools that may make navigating and building the code a bit easier.&lt;br /&gt;
&lt;br /&gt;
=== Use the Test Template Generator ===&lt;br /&gt;
TODO(mbland): Get template generator checked-in. Maybe have a template generator for each library, e.g. &amp;lt;code&amp;gt;ssl/new-test.sh&amp;lt;/code&amp;gt; that has additional setup boilerplate specific to the &amp;lt;code&amp;gt;ssl&amp;lt;/code&amp;gt; library.&lt;br /&gt;
&lt;br /&gt;
Use the &amp;lt;code&amp;gt;test/new-test.sh&amp;lt;/code&amp;gt; script to generate a skeleton test file. ([https://github.com/mbland/openssl/compare/test-util pending in the test-util branch])&lt;br /&gt;
&lt;br /&gt;
=== Add Makefile Targets ===&lt;br /&gt;
The following instructions use the &amp;lt;code&amp;gt;Makefile&amp;lt;/code&amp;gt; targets for &amp;lt;code&amp;gt;ssl/heartbeat_test.c&amp;lt;/code&amp;gt; as an example.&lt;br /&gt;
&lt;br /&gt;
In the &amp;lt;code&amp;gt;Makefile&amp;lt;/code&amp;gt; for the library containing the test, add the test source file to the &amp;lt;code&amp;gt;TEST&amp;lt;/code&amp;gt; variable:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# ssl/Makefile&lt;br /&gt;
TEST=ssltest.c heartbeat_test.c&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In &amp;lt;code&amp;gt;test/Makefile&amp;lt;/code&amp;gt;:&lt;br /&gt;
* add a variable for the test target near the top of the file, right after the existing test variables&lt;br /&gt;
* use the variable to add an executable target to the &amp;lt;code&amp;gt;EXE&amp;lt;/code&amp;gt; variable&lt;br /&gt;
* use the variable to add an object file target to the &amp;lt;code&amp;gt;OBJ&amp;lt;/code&amp;gt; variable&lt;br /&gt;
* use the variable to add a source file target to the &amp;lt;code&amp;gt;SRC&amp;lt;/code&amp;gt; variable&lt;br /&gt;
* add the test target to the &amp;lt;code&amp;gt;alltests&amp;lt;/code&amp;gt; target&lt;br /&gt;
* add the target to execute the test&lt;br /&gt;
* add the target to build the test executable&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# test/Makefile&lt;br /&gt;
HEARTBEATTEST=  heartbeat_test&lt;br /&gt;
EXE=  ... $(HEARTBEATTEST)$(EXE_EXT)&lt;br /&gt;
OBJ= ... $(HEARTBEATTEST).o&lt;br /&gt;
SRC= ... $(HEARTBEATTEST).c&lt;br /&gt;
alltests: \&lt;br /&gt;
        ... test_heartbeat&lt;br /&gt;
&lt;br /&gt;
test_heartbeat: $(HEARTBEATTEST)$(EXE_EXT)&lt;br /&gt;
  ../util/shlib_wrap.sh ./$(HEARTBEATTEST)&lt;br /&gt;
&lt;br /&gt;
$(HEARTBEATTEST)$(EXE_EXT): $(HEARTBEATTEST).o $(DLIBCRYPTO)&lt;br /&gt;
  @target=$(HEARTBEATTEST); $(BUILD_CMD)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Run &amp;lt;code&amp;gt;make depend&amp;lt;/code&amp;gt; ===&lt;br /&gt;
Finally, run &amp;lt;code&amp;gt;make depend&amp;lt;/code&amp;gt; to automatically generate the header file dependencies.&lt;br /&gt;
&lt;br /&gt;
=== Building and Running the Test ===&lt;br /&gt;
If you're initially developing on Mac OS X or (for now) FreeBSD 10, just use the stock method of building and testing:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ ./config &amp;amp;&amp;amp; make &amp;amp;&amp;amp; make test&lt;br /&gt;
&lt;br /&gt;
# To execute just one specific test&lt;br /&gt;
$ make TESTS=test_heartbeat test &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Ultimately the test will have to compile and pass with developer flags enabled:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ ./GitConfigure debug-ben-debug-64-clang&lt;br /&gt;
$ ./GitMake -j 2&lt;br /&gt;
$ ./GitMake test_heartbeat&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above currently doesn't work on Mac OS X or FreeBSD 10; for now, you can install the 9.1 release of [http://www.freebsd.org/ FreeBSD], which uses Clang 3.1, via a virtualization platform such as [https://www.virtualbox.org/ VirtualBox]. (Mac OS X breaks, in part, due to the fact that it doesn't use the GNU assembler; &amp;lt;code&amp;gt;-fsanitize&amp;lt;/code&amp;gt; appears to be ignored on FreeBSD 9.1/Clang 3.1, but later versions break because the Clang compiler will emit &amp;lt;code&amp;gt;-fsanitize&amp;lt;/code&amp;gt; symbols but the &amp;lt;code&amp;gt;libasan&amp;lt;/code&amp;gt; library [http://lists.freebsd.org/pipermail/freebsd-hackers/2013-December/043995.html has yet to be ported to FreeBSD].)&lt;br /&gt;
&lt;br /&gt;
=== Keep your repo up-to-date ===&lt;br /&gt;
Set up the [https://github.com/openssl/openssl OpenSSL master repository] as your upstream remote as per [https://help.github.com/articles/fork-a-repo#step-3-configure-remotes GitHub's instructions on configuring remotes]:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ cd my-openssl-repo&lt;br /&gt;
$ git remote add upstream https://github.com/openssl/openssl.git&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Then periodically run the following to keep your branch up-to-date:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ git fetch upstream master&lt;br /&gt;
$ git rebase upstream/master&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Send a pull request ===&lt;br /&gt;
When your test is ready, send a [https://help.github.com/articles/using-pull-requests GitHub pull request]. We'll review the code, and when it's ready, it'll get merged into Mike's repository. From there, it will eventually get pulled into the master OpenSSL repository.&lt;br /&gt;
&lt;br /&gt;
== Style ==&lt;br /&gt;
[http://mike-bland.com/2014/06/05/pseudo-xunit-pattern.html The Pseudo-xUnit Pattern] is that established by [http://git.openssl.org/gitweb/?p=openssl.git;a=blob;f=ssl/heartbeat_test.c ssl/heartbeat_test.c]. This pattern organizes code in a fashion reminiscent of the [http://en.wikipedia.org/wiki/XUnit xUnit] family of unit testing frameworks, without actually using a testing framework. This should lower the barrier to entry for people wanting to write unit tests, but enable a relatively easy migration to an xUnit-based framework if we decide to do so one day.&lt;br /&gt;
&lt;br /&gt;
Some of the basic principles to follow are:&lt;br /&gt;
&lt;br /&gt;
=== Define a fixture structure ===&lt;br /&gt;
The fixture structure should contain all of the inputs to the code under test and all of the expected result values. It should also contain a &amp;lt;code&amp;gt;const char*&amp;lt;/code&amp;gt; for the name of the test case function that created it, to aid in error message formatting. Even though the fixture may contain dynamically-allocated members, the fixture itself should be copied by value to reduce the necessary degree of memory management in a small unit test program.&lt;br /&gt;
&lt;br /&gt;
=== Define set_up() and tear_down() functions for the fixture ===&lt;br /&gt;
&amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; should return a newly-initialized test fixture structure. It should take the name of the test case as an argument (i.e. &amp;lt;code&amp;gt;__func__&amp;lt;/code&amp;gt;) and assign it to the fixture. All of the fixture members should be initialized, which each test case function can then override as needed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;tear_down()&amp;lt;/code&amp;gt; should take the fixture as an argument and release any resources allocated by &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt;. It can also call any library-wide error printing routines (e.g. &amp;lt;code&amp;gt;ERR_print_errors_fp(stderr)&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
=== Use &amp;lt;code&amp;gt;SETUP_TEST_FIXTURE()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;EXECUTE_TEST()&amp;lt;/code&amp;gt; from &amp;lt;code&amp;gt;test/testutil.h&amp;lt;/code&amp;gt; ===&lt;br /&gt;
Each test case function should call &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; as its first statement, and should call &amp;lt;code&amp;gt;tear_down()&amp;lt;/code&amp;gt; just before returning. This is handled in a uniform fashion when using the &amp;lt;code&amp;gt;SETUP_TEST_FIXTURE()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;EXECUTE_TEST()&amp;lt;/code&amp;gt; helper macros from [http://git.openssl.org/gitweb/?p=openssl.git;a=blob;f=test/testutil.h test/testutil.h]. See the comments in &amp;lt;code&amp;gt;test/testutil.h&amp;lt;/code&amp;gt; for usage, and &amp;lt;code&amp;gt;ssl/heartbeat_test.c&amp;lt;/code&amp;gt; for an example of how to wrap the macros for a specific unit test.&lt;br /&gt;
&lt;br /&gt;
=== Use test case functions, not a table of fixtures ===&lt;br /&gt;
Individual test case functions that call a common execution function are much more readable and maintainable than a loop over a table of fixture structures. Explicit fixture variable assignments aid comprehension when reading a specific test case, which saves time and energy when trying to understand a test or diagnose a failure. When a new member is added to an existing fixture, &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; can set a default for all test cases, and only the test cases that rely on that new member need to be updated.&lt;br /&gt;
&lt;br /&gt;
=== Use very descriptive test case names ===&lt;br /&gt;
Give tests long, descriptive names that provide ample context for the details of the test case. Good test names are also help produce good error messages.&lt;br /&gt;
&lt;br /&gt;
=== Group test cases into &amp;quot;suites&amp;quot; by naming convention ===&lt;br /&gt;
Give logically-related tests the same prefix, e.g. &amp;lt;code&amp;gt;test_dtls1_&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;test_tls1&amp;lt;/code&amp;gt; from &amp;lt;code&amp;gt;ssl/heartbeat_test.c&amp;lt;/code&amp;gt;. If need be, you can define suite-specific &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; functions that call the common &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; and elaborate on it. (This generally shouldn't be necessary for &amp;lt;code&amp;gt;tear_down()&amp;lt;/code&amp;gt;.)&lt;br /&gt;
&lt;br /&gt;
=== Keep individual test case functions focused on one thing ===&lt;br /&gt;
If the test name contains the word &amp;quot;and&amp;quot;, consider breaking it into two or more separate test case functions.&lt;br /&gt;
&lt;br /&gt;
=== Write very descriptive error messages ===&lt;br /&gt;
Include the test case function name in each error message, and explain in detail the context for the assertion that failed. Include the expected result (contained in the fixture structure) and the actual result returned from the code under test. Write helper methods for complex values as needed (e.g. &amp;lt;code&amp;gt;print_payload()&amp;lt;/code&amp;gt; in &amp;lt;code&amp;gt;ssl/heartbeat_test.c&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
=== Return zero on success and one on failure ===&lt;br /&gt;
The return value will be used to tally the number of test cases that failed. Even if multiple assertions fail for a single test case, the result should be exactly one.&lt;br /&gt;
&lt;br /&gt;
=== Add each test case function to the test runner function ===&lt;br /&gt;
Whatever function is used to execute the batch of test case functions, be that &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt; or a separate function called by &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt;, don't forget to add your test case functions to that function.&lt;br /&gt;
&lt;br /&gt;
TODO(mbland): create some kind of automated script or editor macros?&lt;br /&gt;
&lt;br /&gt;
=== Report the number of test cases that failed ===&lt;br /&gt;
Add up the total number of failed test cases in &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt; and report that number as the last error message of the test. &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt; should return &amp;lt;code&amp;gt;EXIT_FAILURE&amp;lt;/code&amp;gt; if any test cases failed, &amp;lt;code&amp;gt;EXIT_SUCCESS&amp;lt;/code&amp;gt; otherwise.&lt;br /&gt;
&lt;br /&gt;
=== Disable for Windows (for now) ===&lt;br /&gt;
Until we solve the private-symbol problem on Windows, we will need to wrap our unit test code in the following &amp;lt;code&amp;gt;#ifdef&amp;lt;/code&amp;gt; block:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#if !defined(OPENSSL_SYS_WINDOWS)&lt;br /&gt;
&lt;br /&gt;
/* All the test code, including main() */&lt;br /&gt;
&lt;br /&gt;
int main(int argc, char *argv[])                                                &lt;br /&gt;
    {&lt;br /&gt;
        return EXIT_SUCCESS;                                                    &lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
#endif /* OPENSSL_NO_WINDOWS  */&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Samples ==&lt;br /&gt;
Existing tests that can be used as models for new tests.&lt;br /&gt;
* [http://git.openssl.org/gitweb/?p=openssl.git;a=blob;f=ssl/heartbeat_test.c ssl/heartbeat_test.c]: Follows [http://mike-bland.com/2014/06/05/pseudo-xunit-pattern.html the Pseudo-xUnit pattern]&lt;/div&gt;</summary>
		<author><name>Mbland</name></author>
	</entry>
	<entry>
		<id>https://wiki.openssl.org/index.php?title=How_To_Write_Unit_Tests_For_OpenSSL&amp;diff=1751</id>
		<title>How To Write Unit Tests For OpenSSL</title>
		<link rel="alternate" type="text/html" href="https://wiki.openssl.org/index.php?title=How_To_Write_Unit_Tests_For_OpenSSL&amp;diff=1751"/>
		<updated>2014-06-16T15:56:33Z</updated>

		<summary type="html">&lt;p&gt;Mbland: /* Keep your repo up-to-date */ Better explain how to keep up with changes in the master repository.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This is an outline of the basic process and principles to follow when writing unit tests. This document will evolve quite a bit as the community gains experience.&lt;br /&gt;
&lt;br /&gt;
==Mechanics ==&lt;br /&gt;
=== Forking the Repo ===&lt;br /&gt;
For now, people contributing new unit tests for uncovered code (as opposed to submitting tests with new code changes) should fork [https://github.com/mbland/openssl Mike Bland's GitHub repository] and issue [https://help.github.com/articles/using-pull-requests GitHub pull requests]. Remember to do all development on a topic branch (not &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt;). Tests committed to this repo will occasionally get merged into the master OpenSSL repo.&lt;br /&gt;
&lt;br /&gt;
Rationale per Matt Caswell: We should think about process here. If you are going off to recruit an army of people writing tests then I wonder if it is worth setting up a separate github repository whilst you are building up the tests. We can then merge in from that on a periodic basis. I wouldn't want availability of openssl team committers to be a bottle neck.&lt;br /&gt;
&lt;br /&gt;
=== Check out the Tools and Tips page ===&lt;br /&gt;
[[Testing and Development Tools and Tips]] has information on tools that may make navigating and building the code a bit easier.&lt;br /&gt;
&lt;br /&gt;
=== Use the Test Template Generator ===&lt;br /&gt;
TODO(mbland): Get template generator checked-in. Maybe have a template generator for each library, e.g. &amp;lt;code&amp;gt;ssl/new-test.sh&amp;lt;/code&amp;gt; that has additional setup boilerplate specific to the &amp;lt;code&amp;gt;ssl&amp;lt;/code&amp;gt; library.&lt;br /&gt;
&lt;br /&gt;
Use the &amp;lt;code&amp;gt;test/new-test.sh&amp;lt;/code&amp;gt; script to generate a skeleton test file. ([https://github.com/mbland/openssl/compare/test-util pending in the test-util branch])&lt;br /&gt;
&lt;br /&gt;
=== Add Makefile Targets ===&lt;br /&gt;
The following instructions use the &amp;lt;code&amp;gt;Makefile&amp;lt;/code&amp;gt; targets for &amp;lt;code&amp;gt;ssl/heartbeat_test.c&amp;lt;/code&amp;gt; as an example.&lt;br /&gt;
&lt;br /&gt;
In the &amp;lt;code&amp;gt;Makefile&amp;lt;/code&amp;gt; for the library containing the test, add the test source file to the &amp;lt;code&amp;gt;TEST&amp;lt;/code&amp;gt; variable:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# ssl/Makefile&lt;br /&gt;
TEST=ssltest.c heartbeat_test.c&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In &amp;lt;code&amp;gt;test/Makefile&amp;lt;/code&amp;gt;:&lt;br /&gt;
* add a variable for the test target near the top of the file, right after the existing test variables&lt;br /&gt;
* use the variable to add an executable target to the &amp;lt;code&amp;gt;EXE&amp;lt;/code&amp;gt; variable&lt;br /&gt;
* use the variable to add an object file target to the &amp;lt;code&amp;gt;OBJ&amp;lt;/code&amp;gt; variable&lt;br /&gt;
* use the variable to add a source file target to the &amp;lt;code&amp;gt;SRC&amp;lt;/code&amp;gt; variable&lt;br /&gt;
* add the test target to the &amp;lt;code&amp;gt;alltests&amp;lt;/code&amp;gt; target&lt;br /&gt;
* add the target to execute the test&lt;br /&gt;
* add the target to build the test executable&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# test/Makefile&lt;br /&gt;
HEARTBEATTEST=  heartbeat_test&lt;br /&gt;
EXE=  ... $(HEARTBEATTEST)$(EXE_EXT)&lt;br /&gt;
OBJ= ... $(HEARTBEATTEST).o&lt;br /&gt;
SRC= ... $(HEARTBEATTEST).c&lt;br /&gt;
alltests: \&lt;br /&gt;
        ... test_heartbeat&lt;br /&gt;
&lt;br /&gt;
test_heartbeat: $(HEARTBEATTEST)$(EXE_EXT)&lt;br /&gt;
  ../util/shlib_wrap.sh ./$(HEARTBEATTEST)&lt;br /&gt;
&lt;br /&gt;
$(HEARTBEATTEST)$(EXE_EXT): $(HEARTBEATTEST).o $(DLIBCRYPTO)&lt;br /&gt;
  @target=$(HEARTBEATTEST); $(BUILD_CMD)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Run &amp;lt;code&amp;gt;make depend&amp;lt;/code&amp;gt; ===&lt;br /&gt;
Finally, run &amp;lt;code&amp;gt;make depend&amp;lt;/code&amp;gt; to automatically generate the header file dependencies.&lt;br /&gt;
&lt;br /&gt;
=== Building and Running the Test ===&lt;br /&gt;
If you're initially developing on Mac OS X or (for now) FreeBSD 10, just use the stock method of building and testing:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ ./config &amp;amp;&amp;amp; make &amp;amp;&amp;amp; make test&lt;br /&gt;
&lt;br /&gt;
# To execute just one specific test&lt;br /&gt;
$ make TESTS=test_heartbeat test &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Ultimately the test will have to compile and pass with developer flags enabled:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ ./GitConfigure debug-ben-debug-64-clang&lt;br /&gt;
$ ./GitMake -j 2&lt;br /&gt;
$ ./GitMake test_heartbeat&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above currently doesn't work on Mac OS X or FreeBSD 10; for now, you can install the 9.1 release of [http://www.freebsd.org/ FreeBSD], which uses Clang 3.1, via a virtualization platform such as [https://www.virtualbox.org/ VirtualBox]. (Mac OS X breaks, in part, due to the fact that it doesn't use the GNU assembler; &amp;lt;code&amp;gt;-fsanitize&amp;lt;/code&amp;gt; appears to be ignored on FreeBSD 9.1/Clang 3.1, but later versions break because the Clang compiler will emit &amp;lt;code&amp;gt;-fsanitize&amp;lt;/code&amp;gt; symbols but the &amp;lt;code&amp;gt;libasan&amp;lt;/code&amp;gt; library [http://lists.freebsd.org/pipermail/freebsd-hackers/2013-December/043995.html has yet to be ported to FreeBSD].)&lt;br /&gt;
&lt;br /&gt;
=== Keep your repo up-to-date ===&lt;br /&gt;
Set up the [https://github.com/openssl/openssl OpenSSL master repository] as your upstream remote as per [https://help.github.com/articles/fork-a-repo#step-3-configure-remotes GitHub's instructions on configuring remotes:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ cd my-openssl-repo&lt;br /&gt;
$ git remote add upstream https://github.com/openssl/openssl.git&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Then periodically run the following to keep your branch up-to-date:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ git fetch upstream master&lt;br /&gt;
$ git rebase upstream/master&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Send a pull request ===&lt;br /&gt;
When your test is ready, send a [https://help.github.com/articles/using-pull-requests GitHub pull request]. We'll review the code, and when it's ready, it'll get merged into Mike's repository. From there, it will eventually get pulled into the master OpenSSL repository.&lt;br /&gt;
&lt;br /&gt;
== Style ==&lt;br /&gt;
[http://mike-bland.com/2014/06/05/pseudo-xunit-pattern.html The Pseudo-xUnit Pattern] is that established by [http://git.openssl.org/gitweb/?p=openssl.git;a=blob;f=ssl/heartbeat_test.c ssl/heartbeat_test.c]. This pattern organizes code in a fashion reminiscent of the [http://en.wikipedia.org/wiki/XUnit xUnit] family of unit testing frameworks, without actually using a testing framework. This should lower the barrier to entry for people wanting to write unit tests, but enable a relatively easy migration to an xUnit-based framework if we decide to do so one day.&lt;br /&gt;
&lt;br /&gt;
Some of the basic principles to follow are:&lt;br /&gt;
&lt;br /&gt;
=== Define a fixture structure ===&lt;br /&gt;
The fixture structure should contain all of the inputs to the code under test and all of the expected result values. It should also contain a &amp;lt;code&amp;gt;const char*&amp;lt;/code&amp;gt; for the name of the test case function that created it, to aid in error message formatting. Even though the fixture may contain dynamically-allocated members, the fixture itself should be copied by value to reduce the necessary degree of memory management in a small unit test program.&lt;br /&gt;
&lt;br /&gt;
=== Define set_up() and tear_down() functions for the fixture ===&lt;br /&gt;
&amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; should return a newly-initialized test fixture structure. It should take the name of the test case as an argument (i.e. &amp;lt;code&amp;gt;__func__&amp;lt;/code&amp;gt;) and assign it to the fixture. All of the fixture members should be initialized, which each test case function can then override as needed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;tear_down()&amp;lt;/code&amp;gt; should take the fixture as an argument and release any resources allocated by &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt;. It can also call any library-wide error printing routines (e.g. &amp;lt;code&amp;gt;ERR_print_errors_fp(stderr)&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
=== Use &amp;lt;code&amp;gt;SETUP_TEST_FIXTURE()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;EXECUTE_TEST()&amp;lt;/code&amp;gt; from &amp;lt;code&amp;gt;test/testutil.h&amp;lt;/code&amp;gt; ===&lt;br /&gt;
Each test case function should call &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; as its first statement, and should call &amp;lt;code&amp;gt;tear_down()&amp;lt;/code&amp;gt; just before returning. This is handled in a uniform fashion when using the &amp;lt;code&amp;gt;SETUP_TEST_FIXTURE()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;EXECUTE_TEST()&amp;lt;/code&amp;gt; helper macros from [http://git.openssl.org/gitweb/?p=openssl.git;a=blob;f=test/testutil.h test/testutil.h]. See the comments in &amp;lt;code&amp;gt;test/testutil.h&amp;lt;/code&amp;gt; for usage, and &amp;lt;code&amp;gt;ssl/heartbeat_test.c&amp;lt;/code&amp;gt; for an example of how to wrap the macros for a specific unit test.&lt;br /&gt;
&lt;br /&gt;
=== Use test case functions, not a table of fixtures ===&lt;br /&gt;
Individual test case functions that call a common execution function are much more readable and maintainable than a loop over a table of fixture structures. Explicit fixture variable assignments aid comprehension when reading a specific test case, which saves time and energy when trying to understand a test or diagnose a failure. When a new member is added to an existing fixture, &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; can set a default for all test cases, and only the test cases that rely on that new member need to be updated.&lt;br /&gt;
&lt;br /&gt;
=== Use very descriptive test case names ===&lt;br /&gt;
Give tests long, descriptive names that provide ample context for the details of the test case. Good test names are also help produce good error messages.&lt;br /&gt;
&lt;br /&gt;
=== Group test cases into &amp;quot;suites&amp;quot; by naming convention ===&lt;br /&gt;
Give logically-related tests the same prefix, e.g. &amp;lt;code&amp;gt;test_dtls1_&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;test_tls1&amp;lt;/code&amp;gt; from &amp;lt;code&amp;gt;ssl/heartbeat_test.c&amp;lt;/code&amp;gt;. If need be, you can define suite-specific &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; functions that call the common &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; and elaborate on it. (This generally shouldn't be necessary for &amp;lt;code&amp;gt;tear_down()&amp;lt;/code&amp;gt;.)&lt;br /&gt;
&lt;br /&gt;
=== Keep individual test case functions focused on one thing ===&lt;br /&gt;
If the test name contains the word &amp;quot;and&amp;quot;, consider breaking it into two or more separate test case functions.&lt;br /&gt;
&lt;br /&gt;
=== Write very descriptive error messages ===&lt;br /&gt;
Include the test case function name in each error message, and explain in detail the context for the assertion that failed. Include the expected result (contained in the fixture structure) and the actual result returned from the code under test. Write helper methods for complex values as needed (e.g. &amp;lt;code&amp;gt;print_payload()&amp;lt;/code&amp;gt; in &amp;lt;code&amp;gt;ssl/heartbeat_test.c&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
=== Return zero on success and one on failure ===&lt;br /&gt;
The return value will be used to tally the number of test cases that failed. Even if multiple assertions fail for a single test case, the result should be exactly one.&lt;br /&gt;
&lt;br /&gt;
=== Add each test case function to the test runner function ===&lt;br /&gt;
Whatever function is used to execute the batch of test case functions, be that &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt; or a separate function called by &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt;, don't forget to add your test case functions to that function.&lt;br /&gt;
&lt;br /&gt;
TODO(mbland): create some kind of automated script or editor macros?&lt;br /&gt;
&lt;br /&gt;
=== Report the number of test cases that failed ===&lt;br /&gt;
Add up the total number of failed test cases in &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt; and report that number as the last error message of the test. &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt; should return &amp;lt;code&amp;gt;EXIT_FAILURE&amp;lt;/code&amp;gt; if any test cases failed, &amp;lt;code&amp;gt;EXIT_SUCCESS&amp;lt;/code&amp;gt; otherwise.&lt;br /&gt;
&lt;br /&gt;
=== Disable for Windows (for now) ===&lt;br /&gt;
Until we solve the private-symbol problem on Windows, we will need to wrap our unit test code in the following &amp;lt;code&amp;gt;#ifdef&amp;lt;/code&amp;gt; block:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#if !defined(OPENSSL_SYS_WINDOWS)&lt;br /&gt;
&lt;br /&gt;
/* All the test code, including main() */&lt;br /&gt;
&lt;br /&gt;
int main(int argc, char *argv[])                                                &lt;br /&gt;
    {&lt;br /&gt;
        return EXIT_SUCCESS;                                                    &lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
#endif /* OPENSSL_NO_WINDOWS  */&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Samples ==&lt;br /&gt;
Existing tests that can be used as models for new tests.&lt;br /&gt;
* [http://git.openssl.org/gitweb/?p=openssl.git;a=blob;f=ssl/heartbeat_test.c ssl/heartbeat_test.c]: Follows [http://mike-bland.com/2014/06/05/pseudo-xunit-pattern.html the Pseudo-xUnit pattern]&lt;/div&gt;</summary>
		<author><name>Mbland</name></author>
	</entry>
	<entry>
		<id>https://wiki.openssl.org/index.php?title=How_To_Write_Unit_Tests_For_OpenSSL&amp;diff=1750</id>
		<title>How To Write Unit Tests For OpenSSL</title>
		<link rel="alternate" type="text/html" href="https://wiki.openssl.org/index.php?title=How_To_Write_Unit_Tests_For_OpenSSL&amp;diff=1750"/>
		<updated>2014-06-16T15:42:31Z</updated>

		<summary type="html">&lt;p&gt;Mbland: /* Building and Running the Test */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This is an outline of the basic process and principles to follow when writing unit tests. This document will evolve quite a bit as the community gains experience.&lt;br /&gt;
&lt;br /&gt;
==Mechanics ==&lt;br /&gt;
=== Forking the Repo ===&lt;br /&gt;
For now, people contributing new unit tests for uncovered code (as opposed to submitting tests with new code changes) should fork [https://github.com/mbland/openssl Mike Bland's GitHub repository] and issue [https://help.github.com/articles/using-pull-requests GitHub pull requests]. Remember to do all development on a topic branch (not &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt;). Tests committed to this repo will occasionally get merged into the master OpenSSL repo.&lt;br /&gt;
&lt;br /&gt;
Rationale per Matt Caswell: We should think about process here. If you are going off to recruit an army of people writing tests then I wonder if it is worth setting up a separate github repository whilst you are building up the tests. We can then merge in from that on a periodic basis. I wouldn't want availability of openssl team committers to be a bottle neck.&lt;br /&gt;
&lt;br /&gt;
=== Check out the Tools and Tips page ===&lt;br /&gt;
[[Testing and Development Tools and Tips]] has information on tools that may make navigating and building the code a bit easier.&lt;br /&gt;
&lt;br /&gt;
=== Use the Test Template Generator ===&lt;br /&gt;
TODO(mbland): Get template generator checked-in. Maybe have a template generator for each library, e.g. &amp;lt;code&amp;gt;ssl/new-test.sh&amp;lt;/code&amp;gt; that has additional setup boilerplate specific to the &amp;lt;code&amp;gt;ssl&amp;lt;/code&amp;gt; library.&lt;br /&gt;
&lt;br /&gt;
Use the &amp;lt;code&amp;gt;test/new-test.sh&amp;lt;/code&amp;gt; script to generate a skeleton test file. ([https://github.com/mbland/openssl/compare/test-util pending in the test-util branch])&lt;br /&gt;
&lt;br /&gt;
=== Add Makefile Targets ===&lt;br /&gt;
The following instructions use the &amp;lt;code&amp;gt;Makefile&amp;lt;/code&amp;gt; targets for &amp;lt;code&amp;gt;ssl/heartbeat_test.c&amp;lt;/code&amp;gt; as an example.&lt;br /&gt;
&lt;br /&gt;
In the &amp;lt;code&amp;gt;Makefile&amp;lt;/code&amp;gt; for the library containing the test, add the test source file to the &amp;lt;code&amp;gt;TEST&amp;lt;/code&amp;gt; variable:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# ssl/Makefile&lt;br /&gt;
TEST=ssltest.c heartbeat_test.c&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In &amp;lt;code&amp;gt;test/Makefile&amp;lt;/code&amp;gt;:&lt;br /&gt;
* add a variable for the test target near the top of the file, right after the existing test variables&lt;br /&gt;
* use the variable to add an executable target to the &amp;lt;code&amp;gt;EXE&amp;lt;/code&amp;gt; variable&lt;br /&gt;
* use the variable to add an object file target to the &amp;lt;code&amp;gt;OBJ&amp;lt;/code&amp;gt; variable&lt;br /&gt;
* use the variable to add a source file target to the &amp;lt;code&amp;gt;SRC&amp;lt;/code&amp;gt; variable&lt;br /&gt;
* add the test target to the &amp;lt;code&amp;gt;alltests&amp;lt;/code&amp;gt; target&lt;br /&gt;
* add the target to execute the test&lt;br /&gt;
* add the target to build the test executable&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# test/Makefile&lt;br /&gt;
HEARTBEATTEST=  heartbeat_test&lt;br /&gt;
EXE=  ... $(HEARTBEATTEST)$(EXE_EXT)&lt;br /&gt;
OBJ= ... $(HEARTBEATTEST).o&lt;br /&gt;
SRC= ... $(HEARTBEATTEST).c&lt;br /&gt;
alltests: \&lt;br /&gt;
        ... test_heartbeat&lt;br /&gt;
&lt;br /&gt;
test_heartbeat: $(HEARTBEATTEST)$(EXE_EXT)&lt;br /&gt;
  ../util/shlib_wrap.sh ./$(HEARTBEATTEST)&lt;br /&gt;
&lt;br /&gt;
$(HEARTBEATTEST)$(EXE_EXT): $(HEARTBEATTEST).o $(DLIBCRYPTO)&lt;br /&gt;
  @target=$(HEARTBEATTEST); $(BUILD_CMD)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Run &amp;lt;code&amp;gt;make depend&amp;lt;/code&amp;gt; ===&lt;br /&gt;
Finally, run &amp;lt;code&amp;gt;make depend&amp;lt;/code&amp;gt; to automatically generate the header file dependencies.&lt;br /&gt;
&lt;br /&gt;
=== Building and Running the Test ===&lt;br /&gt;
If you're initially developing on Mac OS X or (for now) FreeBSD 10, just use the stock method of building and testing:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ ./config &amp;amp;&amp;amp; make &amp;amp;&amp;amp; make test&lt;br /&gt;
&lt;br /&gt;
# To execute just one specific test&lt;br /&gt;
$ make TESTS=test_heartbeat test &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Ultimately the test will have to compile and pass with developer flags enabled:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ ./GitConfigure debug-ben-debug-64-clang&lt;br /&gt;
$ ./GitMake -j 2&lt;br /&gt;
$ ./GitMake test_heartbeat&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above currently doesn't work on Mac OS X or FreeBSD 10; for now, you can install the 9.1 release of [http://www.freebsd.org/ FreeBSD], which uses Clang 3.1, via a virtualization platform such as [https://www.virtualbox.org/ VirtualBox]. (Mac OS X breaks, in part, due to the fact that it doesn't use the GNU assembler; &amp;lt;code&amp;gt;-fsanitize&amp;lt;/code&amp;gt; appears to be ignored on FreeBSD 9.1/Clang 3.1, but later versions break because the Clang compiler will emit &amp;lt;code&amp;gt;-fsanitize&amp;lt;/code&amp;gt; symbols but the &amp;lt;code&amp;gt;libasan&amp;lt;/code&amp;gt; library [http://lists.freebsd.org/pipermail/freebsd-hackers/2013-December/043995.html has yet to be ported to FreeBSD].)&lt;br /&gt;
&lt;br /&gt;
=== Keep your repo up-to-date ===&lt;br /&gt;
With [https://github.com/mbland/openssl Mike Bland's GitHub fork] set up as the upstream remote, periodically run &amp;lt;code&amp;gt;git pull --all&amp;lt;/code&amp;gt; to keep your repository up-to-date. Then, in the branch in which you're working, execute:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ git merge upstream/master&lt;br /&gt;
$ git rebase upstream/master&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Send a pull request ===&lt;br /&gt;
When your test is ready, send a [https://help.github.com/articles/using-pull-requests GitHub pull request]. We'll review the code, and when it's ready, it'll get merged into Mike's repository. From there, it will eventually get pulled into the master OpenSSL repository.&lt;br /&gt;
&lt;br /&gt;
== Style ==&lt;br /&gt;
[http://mike-bland.com/2014/06/05/pseudo-xunit-pattern.html The Pseudo-xUnit Pattern] is that established by [http://git.openssl.org/gitweb/?p=openssl.git;a=blob;f=ssl/heartbeat_test.c ssl/heartbeat_test.c]. This pattern organizes code in a fashion reminiscent of the [http://en.wikipedia.org/wiki/XUnit xUnit] family of unit testing frameworks, without actually using a testing framework. This should lower the barrier to entry for people wanting to write unit tests, but enable a relatively easy migration to an xUnit-based framework if we decide to do so one day.&lt;br /&gt;
&lt;br /&gt;
Some of the basic principles to follow are:&lt;br /&gt;
&lt;br /&gt;
=== Define a fixture structure ===&lt;br /&gt;
The fixture structure should contain all of the inputs to the code under test and all of the expected result values. It should also contain a &amp;lt;code&amp;gt;const char*&amp;lt;/code&amp;gt; for the name of the test case function that created it, to aid in error message formatting. Even though the fixture may contain dynamically-allocated members, the fixture itself should be copied by value to reduce the necessary degree of memory management in a small unit test program.&lt;br /&gt;
&lt;br /&gt;
=== Define set_up() and tear_down() functions for the fixture ===&lt;br /&gt;
&amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; should return a newly-initialized test fixture structure. It should take the name of the test case as an argument (i.e. &amp;lt;code&amp;gt;__func__&amp;lt;/code&amp;gt;) and assign it to the fixture. All of the fixture members should be initialized, which each test case function can then override as needed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;tear_down()&amp;lt;/code&amp;gt; should take the fixture as an argument and release any resources allocated by &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt;. It can also call any library-wide error printing routines (e.g. &amp;lt;code&amp;gt;ERR_print_errors_fp(stderr)&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
=== Use &amp;lt;code&amp;gt;SETUP_TEST_FIXTURE()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;EXECUTE_TEST()&amp;lt;/code&amp;gt; from &amp;lt;code&amp;gt;test/testutil.h&amp;lt;/code&amp;gt; ===&lt;br /&gt;
Each test case function should call &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; as its first statement, and should call &amp;lt;code&amp;gt;tear_down()&amp;lt;/code&amp;gt; just before returning. This is handled in a uniform fashion when using the &amp;lt;code&amp;gt;SETUP_TEST_FIXTURE()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;EXECUTE_TEST()&amp;lt;/code&amp;gt; helper macros from [http://git.openssl.org/gitweb/?p=openssl.git;a=blob;f=test/testutil.h test/testutil.h]. See the comments in &amp;lt;code&amp;gt;test/testutil.h&amp;lt;/code&amp;gt; for usage, and &amp;lt;code&amp;gt;ssl/heartbeat_test.c&amp;lt;/code&amp;gt; for an example of how to wrap the macros for a specific unit test.&lt;br /&gt;
&lt;br /&gt;
=== Use test case functions, not a table of fixtures ===&lt;br /&gt;
Individual test case functions that call a common execution function are much more readable and maintainable than a loop over a table of fixture structures. Explicit fixture variable assignments aid comprehension when reading a specific test case, which saves time and energy when trying to understand a test or diagnose a failure. When a new member is added to an existing fixture, &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; can set a default for all test cases, and only the test cases that rely on that new member need to be updated.&lt;br /&gt;
&lt;br /&gt;
=== Use very descriptive test case names ===&lt;br /&gt;
Give tests long, descriptive names that provide ample context for the details of the test case. Good test names are also help produce good error messages.&lt;br /&gt;
&lt;br /&gt;
=== Group test cases into &amp;quot;suites&amp;quot; by naming convention ===&lt;br /&gt;
Give logically-related tests the same prefix, e.g. &amp;lt;code&amp;gt;test_dtls1_&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;test_tls1&amp;lt;/code&amp;gt; from &amp;lt;code&amp;gt;ssl/heartbeat_test.c&amp;lt;/code&amp;gt;. If need be, you can define suite-specific &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; functions that call the common &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; and elaborate on it. (This generally shouldn't be necessary for &amp;lt;code&amp;gt;tear_down()&amp;lt;/code&amp;gt;.)&lt;br /&gt;
&lt;br /&gt;
=== Keep individual test case functions focused on one thing ===&lt;br /&gt;
If the test name contains the word &amp;quot;and&amp;quot;, consider breaking it into two or more separate test case functions.&lt;br /&gt;
&lt;br /&gt;
=== Write very descriptive error messages ===&lt;br /&gt;
Include the test case function name in each error message, and explain in detail the context for the assertion that failed. Include the expected result (contained in the fixture structure) and the actual result returned from the code under test. Write helper methods for complex values as needed (e.g. &amp;lt;code&amp;gt;print_payload()&amp;lt;/code&amp;gt; in &amp;lt;code&amp;gt;ssl/heartbeat_test.c&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
=== Return zero on success and one on failure ===&lt;br /&gt;
The return value will be used to tally the number of test cases that failed. Even if multiple assertions fail for a single test case, the result should be exactly one.&lt;br /&gt;
&lt;br /&gt;
=== Add each test case function to the test runner function ===&lt;br /&gt;
Whatever function is used to execute the batch of test case functions, be that &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt; or a separate function called by &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt;, don't forget to add your test case functions to that function.&lt;br /&gt;
&lt;br /&gt;
TODO(mbland): create some kind of automated script or editor macros?&lt;br /&gt;
&lt;br /&gt;
=== Report the number of test cases that failed ===&lt;br /&gt;
Add up the total number of failed test cases in &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt; and report that number as the last error message of the test. &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt; should return &amp;lt;code&amp;gt;EXIT_FAILURE&amp;lt;/code&amp;gt; if any test cases failed, &amp;lt;code&amp;gt;EXIT_SUCCESS&amp;lt;/code&amp;gt; otherwise.&lt;br /&gt;
&lt;br /&gt;
=== Disable for Windows (for now) ===&lt;br /&gt;
Until we solve the private-symbol problem on Windows, we will need to wrap our unit test code in the following &amp;lt;code&amp;gt;#ifdef&amp;lt;/code&amp;gt; block:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#if !defined(OPENSSL_SYS_WINDOWS)&lt;br /&gt;
&lt;br /&gt;
/* All the test code, including main() */&lt;br /&gt;
&lt;br /&gt;
int main(int argc, char *argv[])                                                &lt;br /&gt;
    {&lt;br /&gt;
        return EXIT_SUCCESS;                                                    &lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
#endif /* OPENSSL_NO_WINDOWS  */&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Samples ==&lt;br /&gt;
Existing tests that can be used as models for new tests.&lt;br /&gt;
* [http://git.openssl.org/gitweb/?p=openssl.git;a=blob;f=ssl/heartbeat_test.c ssl/heartbeat_test.c]: Follows [http://mike-bland.com/2014/06/05/pseudo-xunit-pattern.html the Pseudo-xUnit pattern]&lt;/div&gt;</summary>
		<author><name>Mbland</name></author>
	</entry>
	<entry>
		<id>https://wiki.openssl.org/index.php?title=Testing_and_Development_Tools_and_Tips&amp;diff=1746</id>
		<title>Testing and Development Tools and Tips</title>
		<link rel="alternate" type="text/html" href="https://wiki.openssl.org/index.php?title=Testing_and_Development_Tools_and_Tips&amp;diff=1746"/>
		<updated>2014-06-10T19:19:35Z</updated>

		<summary type="html">&lt;p&gt;Mbland: Typo fix in &amp;quot;Cscope &amp;gt; Vim Integration&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This is a collection of helpful tools and tips for navigating the OpenSSL code base and managing a local git repository.&lt;br /&gt;
&lt;br /&gt;
== Testing Environment and Tools ==&lt;br /&gt;
In [https://github.com/mbland/openssl/compare/test-util the test-util branch of Mike Bland's fork] are a few helper files that you may wish to copy or pull into your branch. As they are incorporated into the main OpenSSL repository, links to the mainline versions will be incorporated into the descriptions below. However, there may be newer versions in Mike's fork.&lt;br /&gt;
&lt;br /&gt;
=== test/testutil.h ===&lt;br /&gt;
[http://git.openssl.org/gitweb/?p=openssl.git;a=blob;f=test/testutil.h test/testutil.h] defines the generic &amp;lt;code&amp;gt;SETUP_TEST_FIXTURE&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;EXECUTE_TEST&amp;lt;/code&amp;gt; macros. The header comments describe how to define test-specific macros based on these.&lt;br /&gt;
&lt;br /&gt;
=== test/new-test.sh ===&lt;br /&gt;
Generates a new automated test stub, following [http://mike-bland.com/2014/06/05/pseudo-xunit-pattern.html the Pseudo-xUnit Pattern] and using the macros from &amp;lt;code&amp;gt;test/testutil.h&amp;lt;/code&amp;gt;. The generated stub will compile standalone.&lt;br /&gt;
&lt;br /&gt;
=== test/test_env.bash ===&lt;br /&gt;
Environment variables, functions, and aliases to help with OpenSSL unit testing. The header comments contain documentation on each of the functions and aliases in the file.&lt;br /&gt;
&lt;br /&gt;
== Cscope ==&lt;br /&gt;
[http://cscope.sourceforge.net/ Cscope] is a powerful C source code browser. Once you have it installed, you can use the &amp;lt;code&amp;gt;make-cscope&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;open-cscope&amp;lt;/code&amp;gt; functions from &amp;lt;code&amp;gt;test/test_env.bash&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Vim Integration ===&lt;br /&gt;
Once &amp;lt;code&amp;gt;$CSCOPE_DB&amp;lt;/code&amp;gt; (defined in &amp;lt;code&amp;gt;test/test_env.bash&amp;lt;/code&amp;gt;) is built using &amp;lt;code&amp;gt;make-cscope&amp;lt;/code&amp;gt;, you can take advantage of the Cscope integration in Vim by adding something like the following to your &amp;lt;code&amp;gt;.vimrc&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;quot; Detect whether cscope features are present and whether we should add a&lt;br /&gt;
&amp;quot; connection to an existing cscope.out database file&lt;br /&gt;
if has(&amp;quot;cscope&amp;quot;)&lt;br /&gt;
  set nocsverb&lt;br /&gt;
  if filereadable(&amp;quot;./cscope.out&amp;quot;)&lt;br /&gt;
    cs add cscope.out&lt;br /&gt;
  elseif $CSCOPE_DB != &amp;quot;&amp;quot;&lt;br /&gt;
    if filereadable($CSCOPE_DB)&lt;br /&gt;
      cs add $CSCOPE_DB&lt;br /&gt;
    else&lt;br /&gt;
      echo &amp;quot;Can't read $CSCOPE_DB; cscope add not run&amp;quot;&lt;br /&gt;
    endif&lt;br /&gt;
  endif&lt;br /&gt;
  set csre&lt;br /&gt;
  set csverb&lt;br /&gt;
endif&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Ctags ==&lt;br /&gt;
Ctags generates an index of symbols that many editors can use to quickly navigate the source code. Though many Unices ship with a version installed at &amp;lt;code&amp;gt;/usr/bin/ctags&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;test_env.bash&amp;lt;/code&amp;gt; presumes that [http://ctags.sourceforge.net/ Exuberant Ctags] is installed.&lt;br /&gt;
&lt;br /&gt;
=== Vim Integration ===&lt;br /&gt;
Add this to your &amp;lt;code&amp;gt;.vimrc&amp;lt;/code&amp;gt; to take advantage of Ctags integration in vim (where &amp;lt;code&amp;gt;$TAGS_FILE&amp;lt;/code&amp;gt; is defined in &amp;lt;code&amp;gt;test/test_env.bash&amp;lt;/code&amp;gt;):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;quot; The tags path, as set below, will search the local file first, then the       &lt;br /&gt;
&amp;quot; project-wide file.&lt;br /&gt;
if $TAGS_FILE != &amp;quot;&amp;quot;                                                             &lt;br /&gt;
  if filereadable($TAGS_FILE)&lt;br /&gt;
    set tags+=$TAGS_FILE&lt;br /&gt;
  else                                                                          &lt;br /&gt;
    echo &amp;quot;Can't read $TAGS_FILE; tags not set&amp;quot;&lt;br /&gt;
  endif&lt;br /&gt;
endif&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== git-new-workdir ==&lt;br /&gt;
Usually installed as &amp;lt;code&amp;gt;/usr/local/share/git-core/contrib/workdir/git-new-workdir&amp;lt;/code&amp;gt;, this will create a new working directory for a specified branch that's linked to the original repository. This is nice when working on multiple branches in parallel, as it doesn't require committing or stashing changes before issuing a &amp;lt;code&amp;gt;git checkout&amp;lt;/code&amp;gt; to switch between branches. The following &amp;lt;code&amp;gt;bash&amp;lt;/code&amp;gt; function wraps &amp;lt;code&amp;gt;git-new-workdir&amp;lt;/code&amp;gt; to create a working dir called &amp;lt;code&amp;gt;reponame-branchname&amp;lt;/code&amp;gt; in the same directory as the original repository:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Creates a branch-specific git working directory in the same directory as the&lt;br /&gt;
# original repository.&lt;br /&gt;
git-new-workdir() {                                                             &lt;br /&gt;
  if test $# -ne 2; then&lt;br /&gt;
    echo &amp;quot;Usage: $FUNCNAME &amp;lt;git repo&amp;gt; &amp;lt;branch name&amp;gt;&amp;quot;                            &lt;br /&gt;
    return 1&lt;br /&gt;
  elif test ! -d $1; then&lt;br /&gt;
    echo &amp;quot;$1 does not exist&amp;quot;&lt;br /&gt;
    return 1&lt;br /&gt;
  fi&lt;br /&gt;
  new_workdir=$1-$2&lt;br /&gt;
  if /usr/local/share/git-core/contrib/workdir/git-new-workdir\&lt;br /&gt;
    $1 $new_workdir $2; then&lt;br /&gt;
    echo &amp;quot;Created $new_workdir&amp;quot;&lt;br /&gt;
  else&lt;br /&gt;
    return 1&lt;br /&gt;
  fi&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== tmux Terminal Multiplexer ==&lt;br /&gt;
[http://tmux.sourceforge.net/ The tmux terminal multiplexer] is helpful for using a single terminal window to efficiently manage different editing and build sessions, amongst many other useful functions. [http://pragprog.com/book/bhtmux/tmux tmux: Productive Mouse-Free Development] from The Pragmatic Bookshelf is a great primer.&lt;br /&gt;
&lt;br /&gt;
These are some helpful config options to add to &amp;lt;code&amp;gt;~/.tmux.conf&amp;lt;/code&amp;gt;, including getting GNU screen-like CTRL-a behavior:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set-option -g prefix C-a&lt;br /&gt;
unbind-key C-b&lt;br /&gt;
bind-key C-a send-prefix&lt;br /&gt;
&lt;br /&gt;
bind R source-file ~/.tmux.conf \; display &amp;quot;Reloaded ~/.tmux.conf&amp;quot;&lt;br /&gt;
set -g default-terminal &amp;quot;screen-256color&amp;quot;&lt;br /&gt;
set -g status-style fg=black,bg=colour7&lt;br /&gt;
setw -g window-status-style fg=default,bg=default,none&lt;br /&gt;
setw -g window-status-current-style fg=black,bg=colour15,bold&lt;br /&gt;
set -g pane-active-border-style fg=default,bg=colour7&lt;br /&gt;
set -g message-style fg=black,bg=colour11,bright&lt;br /&gt;
set -g status-utf8 on&lt;br /&gt;
setw -g monitor-activity on&lt;br /&gt;
set -g visual-activity on&lt;br /&gt;
&lt;br /&gt;
bind -r H resize-pane -L 5&lt;br /&gt;
bind -r J resize-pane -D 5&lt;br /&gt;
bind -r K resize-pane -U 5                                                      &lt;br /&gt;
bind -r L resize-pane -R 5&lt;br /&gt;
&lt;br /&gt;
# Enables nohup to work. From:&lt;br /&gt;
# https://github.com/ChrisJohnsen/tmux-MacOSX-pasteboard                        &lt;br /&gt;
set-option -g default-command &amp;quot;reattach-to-user-namespace -l $SHELL&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mbland</name></author>
	</entry>
	<entry>
		<id>https://wiki.openssl.org/index.php?title=Testing_and_Development_Tools_and_Tips&amp;diff=1745</id>
		<title>Testing and Development Tools and Tips</title>
		<link rel="alternate" type="text/html" href="https://wiki.openssl.org/index.php?title=Testing_and_Development_Tools_and_Tips&amp;diff=1745"/>
		<updated>2014-06-10T19:18:44Z</updated>

		<summary type="html">&lt;p&gt;Mbland: Explain that $TAGS_FILE is defined in test/test_env.bash&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This is a collection of helpful tools and tips for navigating the OpenSSL code base and managing a local git repository.&lt;br /&gt;
&lt;br /&gt;
== Testing Environment and Tools ==&lt;br /&gt;
In [https://github.com/mbland/openssl/compare/test-util the test-util branch of Mike Bland's fork] are a few helper files that you may wish to copy or pull into your branch. As they are incorporated into the main OpenSSL repository, links to the mainline versions will be incorporated into the descriptions below. However, there may be newer versions in Mike's fork.&lt;br /&gt;
&lt;br /&gt;
=== test/testutil.h ===&lt;br /&gt;
[http://git.openssl.org/gitweb/?p=openssl.git;a=blob;f=test/testutil.h test/testutil.h] defines the generic &amp;lt;code&amp;gt;SETUP_TEST_FIXTURE&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;EXECUTE_TEST&amp;lt;/code&amp;gt; macros. The header comments describe how to define test-specific macros based on these.&lt;br /&gt;
&lt;br /&gt;
=== test/new-test.sh ===&lt;br /&gt;
Generates a new automated test stub, following [http://mike-bland.com/2014/06/05/pseudo-xunit-pattern.html the Pseudo-xUnit Pattern] and using the macros from &amp;lt;code&amp;gt;test/testutil.h&amp;lt;/code&amp;gt;. The generated stub will compile standalone.&lt;br /&gt;
&lt;br /&gt;
=== test/test_env.bash ===&lt;br /&gt;
Environment variables, functions, and aliases to help with OpenSSL unit testing. The header comments contain documentation on each of the functions and aliases in the file.&lt;br /&gt;
&lt;br /&gt;
== Cscope ==&lt;br /&gt;
[http://cscope.sourceforge.net/ Cscope] is a powerful C source code browser. Once you have it installed, you can use the &amp;lt;code&amp;gt;make-cscope&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;open-cscope&amp;lt;/code&amp;gt; functions from &amp;lt;code&amp;gt;test/test_env.bash&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Vim Integration ===&lt;br /&gt;
Once &amp;lt;code&amp;gt;$CSCOPE_DB&amp;lt;/code&amp;gt; (defined in &amp;lt;code&amp;gt;test/test_env.bash&amp;lt;/code&amp;gt; is built using &amp;lt;code&amp;gt;make-cscope&amp;lt;/code&amp;gt;, you can take advantage of the Cscope integration in Vim by adding something like the following to your &amp;lt;code&amp;gt;.vimrc&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;quot; Detect whether cscope features are present and whether we should add a&lt;br /&gt;
&amp;quot; connection to an existing cscope.out database file&lt;br /&gt;
if has(&amp;quot;cscope&amp;quot;)&lt;br /&gt;
  set nocsverb&lt;br /&gt;
  if filereadable(&amp;quot;./cscope.out&amp;quot;)&lt;br /&gt;
    cs add cscope.out&lt;br /&gt;
  elseif $CSCOPE_DB != &amp;quot;&amp;quot;&lt;br /&gt;
    if filereadable($CSCOPE_DB)&lt;br /&gt;
      cs add $CSCOPE_DB&lt;br /&gt;
    else&lt;br /&gt;
      echo &amp;quot;Can't read $CSCOPE_DB; cscope add not run&amp;quot;&lt;br /&gt;
    endif&lt;br /&gt;
  endif&lt;br /&gt;
  set csre&lt;br /&gt;
  set csverb&lt;br /&gt;
endif&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Ctags ==&lt;br /&gt;
Ctags generates an index of symbols that many editors can use to quickly navigate the source code. Though many Unices ship with a version installed at &amp;lt;code&amp;gt;/usr/bin/ctags&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;test_env.bash&amp;lt;/code&amp;gt; presumes that [http://ctags.sourceforge.net/ Exuberant Ctags] is installed.&lt;br /&gt;
&lt;br /&gt;
=== Vim Integration ===&lt;br /&gt;
Add this to your &amp;lt;code&amp;gt;.vimrc&amp;lt;/code&amp;gt; to take advantage of Ctags integration in vim (where &amp;lt;code&amp;gt;$TAGS_FILE&amp;lt;/code&amp;gt; is defined in &amp;lt;code&amp;gt;test/test_env.bash&amp;lt;/code&amp;gt;):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;quot; The tags path, as set below, will search the local file first, then the       &lt;br /&gt;
&amp;quot; project-wide file.&lt;br /&gt;
if $TAGS_FILE != &amp;quot;&amp;quot;                                                             &lt;br /&gt;
  if filereadable($TAGS_FILE)&lt;br /&gt;
    set tags+=$TAGS_FILE&lt;br /&gt;
  else                                                                          &lt;br /&gt;
    echo &amp;quot;Can't read $TAGS_FILE; tags not set&amp;quot;&lt;br /&gt;
  endif&lt;br /&gt;
endif&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== git-new-workdir ==&lt;br /&gt;
Usually installed as &amp;lt;code&amp;gt;/usr/local/share/git-core/contrib/workdir/git-new-workdir&amp;lt;/code&amp;gt;, this will create a new working directory for a specified branch that's linked to the original repository. This is nice when working on multiple branches in parallel, as it doesn't require committing or stashing changes before issuing a &amp;lt;code&amp;gt;git checkout&amp;lt;/code&amp;gt; to switch between branches. The following &amp;lt;code&amp;gt;bash&amp;lt;/code&amp;gt; function wraps &amp;lt;code&amp;gt;git-new-workdir&amp;lt;/code&amp;gt; to create a working dir called &amp;lt;code&amp;gt;reponame-branchname&amp;lt;/code&amp;gt; in the same directory as the original repository:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Creates a branch-specific git working directory in the same directory as the&lt;br /&gt;
# original repository.&lt;br /&gt;
git-new-workdir() {                                                             &lt;br /&gt;
  if test $# -ne 2; then&lt;br /&gt;
    echo &amp;quot;Usage: $FUNCNAME &amp;lt;git repo&amp;gt; &amp;lt;branch name&amp;gt;&amp;quot;                            &lt;br /&gt;
    return 1&lt;br /&gt;
  elif test ! -d $1; then&lt;br /&gt;
    echo &amp;quot;$1 does not exist&amp;quot;&lt;br /&gt;
    return 1&lt;br /&gt;
  fi&lt;br /&gt;
  new_workdir=$1-$2&lt;br /&gt;
  if /usr/local/share/git-core/contrib/workdir/git-new-workdir\&lt;br /&gt;
    $1 $new_workdir $2; then&lt;br /&gt;
    echo &amp;quot;Created $new_workdir&amp;quot;&lt;br /&gt;
  else&lt;br /&gt;
    return 1&lt;br /&gt;
  fi&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== tmux Terminal Multiplexer ==&lt;br /&gt;
[http://tmux.sourceforge.net/ The tmux terminal multiplexer] is helpful for using a single terminal window to efficiently manage different editing and build sessions, amongst many other useful functions. [http://pragprog.com/book/bhtmux/tmux tmux: Productive Mouse-Free Development] from The Pragmatic Bookshelf is a great primer.&lt;br /&gt;
&lt;br /&gt;
These are some helpful config options to add to &amp;lt;code&amp;gt;~/.tmux.conf&amp;lt;/code&amp;gt;, including getting GNU screen-like CTRL-a behavior:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set-option -g prefix C-a&lt;br /&gt;
unbind-key C-b&lt;br /&gt;
bind-key C-a send-prefix&lt;br /&gt;
&lt;br /&gt;
bind R source-file ~/.tmux.conf \; display &amp;quot;Reloaded ~/.tmux.conf&amp;quot;&lt;br /&gt;
set -g default-terminal &amp;quot;screen-256color&amp;quot;&lt;br /&gt;
set -g status-style fg=black,bg=colour7&lt;br /&gt;
setw -g window-status-style fg=default,bg=default,none&lt;br /&gt;
setw -g window-status-current-style fg=black,bg=colour15,bold&lt;br /&gt;
set -g pane-active-border-style fg=default,bg=colour7&lt;br /&gt;
set -g message-style fg=black,bg=colour11,bright&lt;br /&gt;
set -g status-utf8 on&lt;br /&gt;
setw -g monitor-activity on&lt;br /&gt;
set -g visual-activity on&lt;br /&gt;
&lt;br /&gt;
bind -r H resize-pane -L 5&lt;br /&gt;
bind -r J resize-pane -D 5&lt;br /&gt;
bind -r K resize-pane -U 5                                                      &lt;br /&gt;
bind -r L resize-pane -R 5&lt;br /&gt;
&lt;br /&gt;
# Enables nohup to work. From:&lt;br /&gt;
# https://github.com/ChrisJohnsen/tmux-MacOSX-pasteboard                        &lt;br /&gt;
set-option -g default-command &amp;quot;reattach-to-user-namespace -l $SHELL&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mbland</name></author>
	</entry>
	<entry>
		<id>https://wiki.openssl.org/index.php?title=Testing_and_Development_Tools_and_Tips&amp;diff=1744</id>
		<title>Testing and Development Tools and Tips</title>
		<link rel="alternate" type="text/html" href="https://wiki.openssl.org/index.php?title=Testing_and_Development_Tools_and_Tips&amp;diff=1744"/>
		<updated>2014-06-10T19:15:59Z</updated>

		<summary type="html">&lt;p&gt;Mbland: Add link to PragProg tmux book&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This is a collection of helpful tools and tips for navigating the OpenSSL code base and managing a local git repository.&lt;br /&gt;
&lt;br /&gt;
== Testing Environment and Tools ==&lt;br /&gt;
In [https://github.com/mbland/openssl/compare/test-util the test-util branch of Mike Bland's fork] are a few helper files that you may wish to copy or pull into your branch. As they are incorporated into the main OpenSSL repository, links to the mainline versions will be incorporated into the descriptions below. However, there may be newer versions in Mike's fork.&lt;br /&gt;
&lt;br /&gt;
=== test/testutil.h ===&lt;br /&gt;
[http://git.openssl.org/gitweb/?p=openssl.git;a=blob;f=test/testutil.h test/testutil.h] defines the generic &amp;lt;code&amp;gt;SETUP_TEST_FIXTURE&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;EXECUTE_TEST&amp;lt;/code&amp;gt; macros. The header comments describe how to define test-specific macros based on these.&lt;br /&gt;
&lt;br /&gt;
=== test/new-test.sh ===&lt;br /&gt;
Generates a new automated test stub, following [http://mike-bland.com/2014/06/05/pseudo-xunit-pattern.html the Pseudo-xUnit Pattern] and using the macros from &amp;lt;code&amp;gt;test/testutil.h&amp;lt;/code&amp;gt;. The generated stub will compile standalone.&lt;br /&gt;
&lt;br /&gt;
=== test/test_env.bash ===&lt;br /&gt;
Environment variables, functions, and aliases to help with OpenSSL unit testing. The header comments contain documentation on each of the functions and aliases in the file.&lt;br /&gt;
&lt;br /&gt;
== Cscope ==&lt;br /&gt;
[http://cscope.sourceforge.net/ Cscope] is a powerful C source code browser. Once you have it installed, you can use the &amp;lt;code&amp;gt;make-cscope&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;open-cscope&amp;lt;/code&amp;gt; functions from &amp;lt;code&amp;gt;test/test_env.bash&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Vim Integration ===&lt;br /&gt;
Once &amp;lt;code&amp;gt;$CSCOPE_DB&amp;lt;/code&amp;gt; (defined in &amp;lt;code&amp;gt;test/test_env.bash&amp;lt;/code&amp;gt; is built using &amp;lt;code&amp;gt;make-cscope&amp;lt;/code&amp;gt;, you can take advantage of the Cscope integration in Vim by adding something like the following to your &amp;lt;code&amp;gt;.vimrc&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;quot; Detect whether cscope features are present and whether we should add a&lt;br /&gt;
&amp;quot; connection to an existing cscope.out database file&lt;br /&gt;
if has(&amp;quot;cscope&amp;quot;)&lt;br /&gt;
  set nocsverb&lt;br /&gt;
  if filereadable(&amp;quot;./cscope.out&amp;quot;)&lt;br /&gt;
    cs add cscope.out&lt;br /&gt;
  elseif $CSCOPE_DB != &amp;quot;&amp;quot;&lt;br /&gt;
    if filereadable($CSCOPE_DB)&lt;br /&gt;
      cs add $CSCOPE_DB&lt;br /&gt;
    else&lt;br /&gt;
      echo &amp;quot;Can't read $CSCOPE_DB; cscope add not run&amp;quot;&lt;br /&gt;
    endif&lt;br /&gt;
  endif&lt;br /&gt;
  set csre&lt;br /&gt;
  set csverb&lt;br /&gt;
endif&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Ctags ==&lt;br /&gt;
Ctags generates an index of symbols that many editors can use to quickly navigate the source code. Though many Unices ship with a version installed at &amp;lt;code&amp;gt;/usr/bin/ctags&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;test_env.bash&amp;lt;/code&amp;gt; presumes that [http://ctags.sourceforge.net/ Exuberant Ctags] is installed.&lt;br /&gt;
&lt;br /&gt;
=== Vim Integration ===&lt;br /&gt;
Add this to your &amp;lt;code&amp;gt;.vimrc&amp;lt;/code&amp;gt; to take advantage of Ctags integration in vim:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;quot; The tags path, as set below, will search the local file first, then the       &lt;br /&gt;
&amp;quot; project-wide file.&lt;br /&gt;
if $TAGS_FILE != &amp;quot;&amp;quot;                                                             &lt;br /&gt;
  if filereadable($TAGS_FILE)&lt;br /&gt;
    set tags+=$TAGS_FILE&lt;br /&gt;
  else                                                                          &lt;br /&gt;
    echo &amp;quot;Can't read $TAGS_FILE; tags not set&amp;quot;&lt;br /&gt;
  endif&lt;br /&gt;
endif&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== git-new-workdir ==&lt;br /&gt;
Usually installed as &amp;lt;code&amp;gt;/usr/local/share/git-core/contrib/workdir/git-new-workdir&amp;lt;/code&amp;gt;, this will create a new working directory for a specified branch that's linked to the original repository. This is nice when working on multiple branches in parallel, as it doesn't require committing or stashing changes before issuing a &amp;lt;code&amp;gt;git checkout&amp;lt;/code&amp;gt; to switch between branches. The following &amp;lt;code&amp;gt;bash&amp;lt;/code&amp;gt; function wraps &amp;lt;code&amp;gt;git-new-workdir&amp;lt;/code&amp;gt; to create a working dir called &amp;lt;code&amp;gt;reponame-branchname&amp;lt;/code&amp;gt; in the same directory as the original repository:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Creates a branch-specific git working directory in the same directory as the&lt;br /&gt;
# original repository.&lt;br /&gt;
git-new-workdir() {                                                             &lt;br /&gt;
  if test $# -ne 2; then&lt;br /&gt;
    echo &amp;quot;Usage: $FUNCNAME &amp;lt;git repo&amp;gt; &amp;lt;branch name&amp;gt;&amp;quot;                            &lt;br /&gt;
    return 1&lt;br /&gt;
  elif test ! -d $1; then&lt;br /&gt;
    echo &amp;quot;$1 does not exist&amp;quot;&lt;br /&gt;
    return 1&lt;br /&gt;
  fi&lt;br /&gt;
  new_workdir=$1-$2&lt;br /&gt;
  if /usr/local/share/git-core/contrib/workdir/git-new-workdir\&lt;br /&gt;
    $1 $new_workdir $2; then&lt;br /&gt;
    echo &amp;quot;Created $new_workdir&amp;quot;&lt;br /&gt;
  else&lt;br /&gt;
    return 1&lt;br /&gt;
  fi&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== tmux Terminal Multiplexer ==&lt;br /&gt;
[http://tmux.sourceforge.net/ The tmux terminal multiplexer] is helpful for using a single terminal window to efficiently manage different editing and build sessions, amongst many other useful functions. [http://pragprog.com/book/bhtmux/tmux tmux: Productive Mouse-Free Development] from The Pragmatic Bookshelf is a great primer.&lt;br /&gt;
&lt;br /&gt;
These are some helpful config options to add to &amp;lt;code&amp;gt;~/.tmux.conf&amp;lt;/code&amp;gt;, including getting GNU screen-like CTRL-a behavior:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set-option -g prefix C-a&lt;br /&gt;
unbind-key C-b&lt;br /&gt;
bind-key C-a send-prefix&lt;br /&gt;
&lt;br /&gt;
bind R source-file ~/.tmux.conf \; display &amp;quot;Reloaded ~/.tmux.conf&amp;quot;&lt;br /&gt;
set -g default-terminal &amp;quot;screen-256color&amp;quot;&lt;br /&gt;
set -g status-style fg=black,bg=colour7&lt;br /&gt;
setw -g window-status-style fg=default,bg=default,none&lt;br /&gt;
setw -g window-status-current-style fg=black,bg=colour15,bold&lt;br /&gt;
set -g pane-active-border-style fg=default,bg=colour7&lt;br /&gt;
set -g message-style fg=black,bg=colour11,bright&lt;br /&gt;
set -g status-utf8 on&lt;br /&gt;
setw -g monitor-activity on&lt;br /&gt;
set -g visual-activity on&lt;br /&gt;
&lt;br /&gt;
bind -r H resize-pane -L 5&lt;br /&gt;
bind -r J resize-pane -D 5&lt;br /&gt;
bind -r K resize-pane -U 5                                                      &lt;br /&gt;
bind -r L resize-pane -R 5&lt;br /&gt;
&lt;br /&gt;
# Enables nohup to work. From:&lt;br /&gt;
# https://github.com/ChrisJohnsen/tmux-MacOSX-pasteboard                        &lt;br /&gt;
set-option -g default-command &amp;quot;reattach-to-user-namespace -l $SHELL&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mbland</name></author>
	</entry>
	<entry>
		<id>https://wiki.openssl.org/index.php?title=Testing_and_Development_Tools_and_Tips&amp;diff=1743</id>
		<title>Testing and Development Tools and Tips</title>
		<link rel="alternate" type="text/html" href="https://wiki.openssl.org/index.php?title=Testing_and_Development_Tools_and_Tips&amp;diff=1743"/>
		<updated>2014-06-10T18:46:34Z</updated>

		<summary type="html">&lt;p&gt;Mbland: Add note that test utils will be linked to mainline as they are integrated&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This is a collection of helpful tools and tips for navigating the OpenSSL code base and managing a local git repository.&lt;br /&gt;
&lt;br /&gt;
== Testing Environment and Tools ==&lt;br /&gt;
In [https://github.com/mbland/openssl/compare/test-util the test-util branch of Mike Bland's fork] are a few helper files that you may wish to copy or pull into your branch. As they are incorporated into the main OpenSSL repository, links to the mainline versions will be incorporated into the descriptions below. However, there may be newer versions in Mike's fork.&lt;br /&gt;
&lt;br /&gt;
=== test/testutil.h ===&lt;br /&gt;
[http://git.openssl.org/gitweb/?p=openssl.git;a=blob;f=test/testutil.h test/testutil.h] defines the generic &amp;lt;code&amp;gt;SETUP_TEST_FIXTURE&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;EXECUTE_TEST&amp;lt;/code&amp;gt; macros. The header comments describe how to define test-specific macros based on these.&lt;br /&gt;
&lt;br /&gt;
=== test/new-test.sh ===&lt;br /&gt;
Generates a new automated test stub, following [http://mike-bland.com/2014/06/05/pseudo-xunit-pattern.html the Pseudo-xUnit Pattern] and using the macros from &amp;lt;code&amp;gt;test/testutil.h&amp;lt;/code&amp;gt;. The generated stub will compile standalone.&lt;br /&gt;
&lt;br /&gt;
=== test/test_env.bash ===&lt;br /&gt;
Environment variables, functions, and aliases to help with OpenSSL unit testing. The header comments contain documentation on each of the functions and aliases in the file.&lt;br /&gt;
&lt;br /&gt;
== Cscope ==&lt;br /&gt;
[http://cscope.sourceforge.net/ Cscope] is a powerful C source code browser. Once you have it installed, you can use the &amp;lt;code&amp;gt;make-cscope&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;open-cscope&amp;lt;/code&amp;gt; functions from &amp;lt;code&amp;gt;test/test_env.bash&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Vim Integration ===&lt;br /&gt;
Once &amp;lt;code&amp;gt;$CSCOPE_DB&amp;lt;/code&amp;gt; (defined in &amp;lt;code&amp;gt;test/test_env.bash&amp;lt;/code&amp;gt; is built using &amp;lt;code&amp;gt;make-cscope&amp;lt;/code&amp;gt;, you can take advantage of the Cscope integration in Vim by adding something like the following to your &amp;lt;code&amp;gt;.vimrc&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;quot; Detect whether cscope features are present and whether we should add a&lt;br /&gt;
&amp;quot; connection to an existing cscope.out database file&lt;br /&gt;
if has(&amp;quot;cscope&amp;quot;)&lt;br /&gt;
  set nocsverb&lt;br /&gt;
  if filereadable(&amp;quot;./cscope.out&amp;quot;)&lt;br /&gt;
    cs add cscope.out&lt;br /&gt;
  elseif $CSCOPE_DB != &amp;quot;&amp;quot;&lt;br /&gt;
    if filereadable($CSCOPE_DB)&lt;br /&gt;
      cs add $CSCOPE_DB&lt;br /&gt;
    else&lt;br /&gt;
      echo &amp;quot;Can't read $CSCOPE_DB; cscope add not run&amp;quot;&lt;br /&gt;
    endif&lt;br /&gt;
  endif&lt;br /&gt;
  set csre&lt;br /&gt;
  set csverb&lt;br /&gt;
endif&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Ctags ==&lt;br /&gt;
Ctags generates an index of symbols that many editors can use to quickly navigate the source code. Though many Unices ship with a version installed at &amp;lt;code&amp;gt;/usr/bin/ctags&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;test_env.bash&amp;lt;/code&amp;gt; presumes that [http://ctags.sourceforge.net/ Exuberant Ctags] is installed.&lt;br /&gt;
&lt;br /&gt;
=== Vim Integration ===&lt;br /&gt;
Add this to your &amp;lt;code&amp;gt;.vimrc&amp;lt;/code&amp;gt; to take advantage of Ctags integration in vim:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;quot; The tags path, as set below, will search the local file first, then the       &lt;br /&gt;
&amp;quot; project-wide file.&lt;br /&gt;
if $TAGS_FILE != &amp;quot;&amp;quot;                                                             &lt;br /&gt;
  if filereadable($TAGS_FILE)&lt;br /&gt;
    set tags+=$TAGS_FILE&lt;br /&gt;
  else                                                                          &lt;br /&gt;
    echo &amp;quot;Can't read $TAGS_FILE; tags not set&amp;quot;&lt;br /&gt;
  endif&lt;br /&gt;
endif&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== git-new-workdir ==&lt;br /&gt;
Usually installed as &amp;lt;code&amp;gt;/usr/local/share/git-core/contrib/workdir/git-new-workdir&amp;lt;/code&amp;gt;, this will create a new working directory for a specified branch that's linked to the original repository. This is nice when working on multiple branches in parallel, as it doesn't require committing or stashing changes before issuing a &amp;lt;code&amp;gt;git checkout&amp;lt;/code&amp;gt; to switch between branches. The following &amp;lt;code&amp;gt;bash&amp;lt;/code&amp;gt; function wraps &amp;lt;code&amp;gt;git-new-workdir&amp;lt;/code&amp;gt; to create a working dir called &amp;lt;code&amp;gt;reponame-branchname&amp;lt;/code&amp;gt; in the same directory as the original repository:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Creates a branch-specific git working directory in the same directory as the&lt;br /&gt;
# original repository.&lt;br /&gt;
git-new-workdir() {                                                             &lt;br /&gt;
  if test $# -ne 2; then&lt;br /&gt;
    echo &amp;quot;Usage: $FUNCNAME &amp;lt;git repo&amp;gt; &amp;lt;branch name&amp;gt;&amp;quot;                            &lt;br /&gt;
    return 1&lt;br /&gt;
  elif test ! -d $1; then&lt;br /&gt;
    echo &amp;quot;$1 does not exist&amp;quot;&lt;br /&gt;
    return 1&lt;br /&gt;
  fi&lt;br /&gt;
  new_workdir=$1-$2&lt;br /&gt;
  if /usr/local/share/git-core/contrib/workdir/git-new-workdir\&lt;br /&gt;
    $1 $new_workdir $2; then&lt;br /&gt;
    echo &amp;quot;Created $new_workdir&amp;quot;&lt;br /&gt;
  else&lt;br /&gt;
    return 1&lt;br /&gt;
  fi&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== tmux Terminal Multiplexer ==&lt;br /&gt;
[http://tmux.sourceforge.net/ The tmux terminal multiplexer] is helpful for using a single terminal window to efficiently manage different editing and build sessions, amongst many other useful functions. These are some helpful config options to add to &amp;lt;code&amp;gt;~/.tmux.conf&amp;lt;/code&amp;gt;, including getting GNU screen-like CTRL-a behavior:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set-option -g prefix C-a&lt;br /&gt;
unbind-key C-b&lt;br /&gt;
bind-key C-a send-prefix&lt;br /&gt;
&lt;br /&gt;
bind R source-file ~/.tmux.conf \; display &amp;quot;Reloaded ~/.tmux.conf&amp;quot;&lt;br /&gt;
set -g default-terminal &amp;quot;screen-256color&amp;quot;&lt;br /&gt;
set -g status-style fg=black,bg=colour7&lt;br /&gt;
setw -g window-status-style fg=default,bg=default,none&lt;br /&gt;
setw -g window-status-current-style fg=black,bg=colour15,bold&lt;br /&gt;
set -g pane-active-border-style fg=default,bg=colour7&lt;br /&gt;
set -g message-style fg=black,bg=colour11,bright&lt;br /&gt;
set -g status-utf8 on&lt;br /&gt;
setw -g monitor-activity on&lt;br /&gt;
set -g visual-activity on&lt;br /&gt;
&lt;br /&gt;
bind -r H resize-pane -L 5&lt;br /&gt;
bind -r J resize-pane -D 5&lt;br /&gt;
bind -r K resize-pane -U 5                                                      &lt;br /&gt;
bind -r L resize-pane -R 5&lt;br /&gt;
&lt;br /&gt;
# Enables nohup to work. From:&lt;br /&gt;
# https://github.com/ChrisJohnsen/tmux-MacOSX-pasteboard                        &lt;br /&gt;
set-option -g default-command &amp;quot;reattach-to-user-namespace -l $SHELL&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mbland</name></author>
	</entry>
	<entry>
		<id>https://wiki.openssl.org/index.php?title=How_To_Write_Unit_Tests_For_OpenSSL&amp;diff=1742</id>
		<title>How To Write Unit Tests For OpenSSL</title>
		<link rel="alternate" type="text/html" href="https://wiki.openssl.org/index.php?title=How_To_Write_Unit_Tests_For_OpenSSL&amp;diff=1742"/>
		<updated>2014-06-10T18:40:54Z</updated>

		<summary type="html">&lt;p&gt;Mbland: Update &amp;quot;Use SETUP_TEST_FIXTURE() and EXECUTE_TEST() from test/testutil.h&amp;quot; after openssl/master commit 3ead9f3798cb6de93b9824d6f833da9f00d8f5d7&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This is an outline of the basic process and principles to follow when writing unit tests. This document will evolve quite a bit as the community gains experience.&lt;br /&gt;
&lt;br /&gt;
==Mechanics ==&lt;br /&gt;
=== Forking the Repo ===&lt;br /&gt;
For now, people contributing new unit tests for uncovered code (as opposed to submitting tests with new code changes) should fork [https://github.com/mbland/openssl Mike Bland's GitHub repository] and issue [https://help.github.com/articles/using-pull-requests GitHub pull requests]. Remember to do all development on a topic branch (not &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt;). Tests committed to this repo will occasionally get merged into the master OpenSSL repo.&lt;br /&gt;
&lt;br /&gt;
Rationale per Matt Caswell: We should think about process here. If you are going off to recruit an army of people writing tests then I wonder if it is worth setting up a separate github repository whilst you are building up the tests. We can then merge in from that on a periodic basis. I wouldn't want availability of openssl team committers to be a bottle neck.&lt;br /&gt;
&lt;br /&gt;
=== Check out the Tools and Tips page ===&lt;br /&gt;
[[Testing and Development Tools and Tips]] has information on tools that may make navigating and building the code a bit easier.&lt;br /&gt;
&lt;br /&gt;
=== Use the Test Template Generator ===&lt;br /&gt;
TODO(mbland): Get template generator checked-in. Maybe have a template generator for each library, e.g. &amp;lt;code&amp;gt;ssl/new-test.sh&amp;lt;/code&amp;gt; that has additional setup boilerplate specific to the &amp;lt;code&amp;gt;ssl&amp;lt;/code&amp;gt; library.&lt;br /&gt;
&lt;br /&gt;
Use the &amp;lt;code&amp;gt;test/new-test.sh&amp;lt;/code&amp;gt; script to generate a skeleton test file. ([https://github.com/mbland/openssl/compare/test-util pending in the test-util branch])&lt;br /&gt;
&lt;br /&gt;
=== Add Makefile Targets ===&lt;br /&gt;
The following instructions use the &amp;lt;code&amp;gt;Makefile&amp;lt;/code&amp;gt; targets for &amp;lt;code&amp;gt;ssl/heartbeat_test.c&amp;lt;/code&amp;gt; as an example.&lt;br /&gt;
&lt;br /&gt;
In the &amp;lt;code&amp;gt;Makefile&amp;lt;/code&amp;gt; for the library containing the test, add the test source file to the &amp;lt;code&amp;gt;TEST&amp;lt;/code&amp;gt; variable:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# ssl/Makefile&lt;br /&gt;
TEST=ssltest.c heartbeat_test.c&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In &amp;lt;code&amp;gt;test/Makefile&amp;lt;/code&amp;gt;:&lt;br /&gt;
* add a variable for the test target near the top of the file, right after the existing test variables&lt;br /&gt;
* use the variable to add an executable target to the &amp;lt;code&amp;gt;EXE&amp;lt;/code&amp;gt; variable&lt;br /&gt;
* use the variable to add an object file target to the &amp;lt;code&amp;gt;OBJ&amp;lt;/code&amp;gt; variable&lt;br /&gt;
* use the variable to add a source file target to the &amp;lt;code&amp;gt;SRC&amp;lt;/code&amp;gt; variable&lt;br /&gt;
* add the test target to the &amp;lt;code&amp;gt;alltests&amp;lt;/code&amp;gt; target&lt;br /&gt;
* add the target to execute the test&lt;br /&gt;
* add the target to build the test executable&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# test/Makefile&lt;br /&gt;
HEARTBEATTEST=  heartbeat_test&lt;br /&gt;
EXE=  ... $(HEARTBEATTEST)$(EXE_EXT)&lt;br /&gt;
OBJ= ... $(HEARTBEATTEST).o&lt;br /&gt;
SRC= ... $(HEARTBEATTEST).c&lt;br /&gt;
alltests: \&lt;br /&gt;
        ... test_heartbeat&lt;br /&gt;
&lt;br /&gt;
test_heartbeat: $(HEARTBEATTEST)$(EXE_EXT)&lt;br /&gt;
  ../util/shlib_wrap.sh ./$(HEARTBEATTEST)&lt;br /&gt;
&lt;br /&gt;
$(HEARTBEATTEST)$(EXE_EXT): $(HEARTBEATTEST).o $(DLIBCRYPTO)&lt;br /&gt;
  @target=$(HEARTBEATTEST); $(BUILD_CMD)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Run &amp;lt;code&amp;gt;make depend&amp;lt;/code&amp;gt; ===&lt;br /&gt;
Finally, run &amp;lt;code&amp;gt;make depend&amp;lt;/code&amp;gt; to automatically generate the header file dependencies.&lt;br /&gt;
&lt;br /&gt;
=== Building and Running the Test ===&lt;br /&gt;
If you're initially developing on Mac OS X or (for now) FreeBSD 10, just use the stock method of building and testing:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ config &amp;amp;&amp;amp; make &amp;amp;&amp;amp; make test&lt;br /&gt;
&lt;br /&gt;
# To execute just one specific test&lt;br /&gt;
$ make TESTS=test_heartbeat test &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Ultimately the test will have to compile and pass with developer flags enabled:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ ./GitConfigure debug-ben-debug-64-clang&lt;br /&gt;
$ ./GitMake -j 2&lt;br /&gt;
$ ./GitMake test_heartbeat&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above currently doesn't work on Mac OS X or FreeBSD 10; for now, you can install the 9.1 release of [http://www.freebsd.org/ FreeBSD], which uses Clang 3.1, via a virtualization platform such as [https://www.virtualbox.org/ VirtualBox]. (Mac OS X breaks, in part, due to the fact that it doesn't use the GNU assembler; &amp;lt;code&amp;gt;-fsanitize&amp;lt;/code&amp;gt; appears to be ignored on FreeBSD 9.1/Clang 3.1, but later versions break because the Clang compiler will emit &amp;lt;code&amp;gt;-fsanitize&amp;lt;/code&amp;gt; symbols but the &amp;lt;code&amp;gt;libasan&amp;lt;/code&amp;gt; library [http://lists.freebsd.org/pipermail/freebsd-hackers/2013-December/043995.html has yet to be ported to FreeBSD].)&lt;br /&gt;
&lt;br /&gt;
=== Keep your repo up-to-date ===&lt;br /&gt;
With [https://github.com/mbland/openssl Mike Bland's GitHub fork] set up as the upstream remote, periodically run &amp;lt;code&amp;gt;git pull --all&amp;lt;/code&amp;gt; to keep your repository up-to-date. Then, in the branch in which you're working, execute:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ git merge upstream/master&lt;br /&gt;
$ git rebase upstream/master&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Send a pull request ===&lt;br /&gt;
When your test is ready, send a [https://help.github.com/articles/using-pull-requests GitHub pull request]. We'll review the code, and when it's ready, it'll get merged into Mike's repository. From there, it will eventually get pulled into the master OpenSSL repository.&lt;br /&gt;
&lt;br /&gt;
== Style ==&lt;br /&gt;
[http://mike-bland.com/2014/06/05/pseudo-xunit-pattern.html The Pseudo-xUnit Pattern] is that established by [http://git.openssl.org/gitweb/?p=openssl.git;a=blob;f=ssl/heartbeat_test.c ssl/heartbeat_test.c]. This pattern organizes code in a fashion reminiscent of the [http://en.wikipedia.org/wiki/XUnit xUnit] family of unit testing frameworks, without actually using a testing framework. This should lower the barrier to entry for people wanting to write unit tests, but enable a relatively easy migration to an xUnit-based framework if we decide to do so one day.&lt;br /&gt;
&lt;br /&gt;
Some of the basic principles to follow are:&lt;br /&gt;
&lt;br /&gt;
=== Define a fixture structure ===&lt;br /&gt;
The fixture structure should contain all of the inputs to the code under test and all of the expected result values. It should also contain a &amp;lt;code&amp;gt;const char*&amp;lt;/code&amp;gt; for the name of the test case function that created it, to aid in error message formatting. Even though the fixture may contain dynamically-allocated members, the fixture itself should be copied by value to reduce the necessary degree of memory management in a small unit test program.&lt;br /&gt;
&lt;br /&gt;
=== Define set_up() and tear_down() functions for the fixture ===&lt;br /&gt;
&amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; should return a newly-initialized test fixture structure. It should take the name of the test case as an argument (i.e. &amp;lt;code&amp;gt;__func__&amp;lt;/code&amp;gt;) and assign it to the fixture. All of the fixture members should be initialized, which each test case function can then override as needed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;tear_down()&amp;lt;/code&amp;gt; should take the fixture as an argument and release any resources allocated by &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt;. It can also call any library-wide error printing routines (e.g. &amp;lt;code&amp;gt;ERR_print_errors_fp(stderr)&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
=== Use &amp;lt;code&amp;gt;SETUP_TEST_FIXTURE()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;EXECUTE_TEST()&amp;lt;/code&amp;gt; from &amp;lt;code&amp;gt;test/testutil.h&amp;lt;/code&amp;gt; ===&lt;br /&gt;
Each test case function should call &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; as its first statement, and should call &amp;lt;code&amp;gt;tear_down()&amp;lt;/code&amp;gt; just before returning. This is handled in a uniform fashion when using the &amp;lt;code&amp;gt;SETUP_TEST_FIXTURE()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;EXECUTE_TEST()&amp;lt;/code&amp;gt; helper macros from [http://git.openssl.org/gitweb/?p=openssl.git;a=blob;f=test/testutil.h test/testutil.h]. See the comments in &amp;lt;code&amp;gt;test/testutil.h&amp;lt;/code&amp;gt; for usage, and &amp;lt;code&amp;gt;ssl/heartbeat_test.c&amp;lt;/code&amp;gt; for an example of how to wrap the macros for a specific unit test.&lt;br /&gt;
&lt;br /&gt;
=== Use test case functions, not a table of fixtures ===&lt;br /&gt;
Individual test case functions that call a common execution function are much more readable and maintainable than a loop over a table of fixture structures. Explicit fixture variable assignments aid comprehension when reading a specific test case, which saves time and energy when trying to understand a test or diagnose a failure. When a new member is added to an existing fixture, &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; can set a default for all test cases, and only the test cases that rely on that new member need to be updated.&lt;br /&gt;
&lt;br /&gt;
=== Use very descriptive test case names ===&lt;br /&gt;
Give tests long, descriptive names that provide ample context for the details of the test case. Good test names are also help produce good error messages.&lt;br /&gt;
&lt;br /&gt;
=== Group test cases into &amp;quot;suites&amp;quot; by naming convention ===&lt;br /&gt;
Give logically-related tests the same prefix, e.g. &amp;lt;code&amp;gt;test_dtls1_&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;test_tls1&amp;lt;/code&amp;gt; from &amp;lt;code&amp;gt;ssl/heartbeat_test.c&amp;lt;/code&amp;gt;. If need be, you can define suite-specific &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; functions that call the common &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; and elaborate on it. (This generally shouldn't be necessary for &amp;lt;code&amp;gt;tear_down()&amp;lt;/code&amp;gt;.)&lt;br /&gt;
&lt;br /&gt;
=== Keep individual test case functions focused on one thing ===&lt;br /&gt;
If the test name contains the word &amp;quot;and&amp;quot;, consider breaking it into two or more separate test case functions.&lt;br /&gt;
&lt;br /&gt;
=== Write very descriptive error messages ===&lt;br /&gt;
Include the test case function name in each error message, and explain in detail the context for the assertion that failed. Include the expected result (contained in the fixture structure) and the actual result returned from the code under test. Write helper methods for complex values as needed (e.g. &amp;lt;code&amp;gt;print_payload()&amp;lt;/code&amp;gt; in &amp;lt;code&amp;gt;ssl/heartbeat_test.c&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
=== Return zero on success and one on failure ===&lt;br /&gt;
The return value will be used to tally the number of test cases that failed. Even if multiple assertions fail for a single test case, the result should be exactly one.&lt;br /&gt;
&lt;br /&gt;
=== Add each test case function to the test runner function ===&lt;br /&gt;
Whatever function is used to execute the batch of test case functions, be that &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt; or a separate function called by &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt;, don't forget to add your test case functions to that function.&lt;br /&gt;
&lt;br /&gt;
TODO(mbland): create some kind of automated script or editor macros?&lt;br /&gt;
&lt;br /&gt;
=== Report the number of test cases that failed ===&lt;br /&gt;
Add up the total number of failed test cases in &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt; and report that number as the last error message of the test. &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt; should return &amp;lt;code&amp;gt;EXIT_FAILURE&amp;lt;/code&amp;gt; if any test cases failed, &amp;lt;code&amp;gt;EXIT_SUCCESS&amp;lt;/code&amp;gt; otherwise.&lt;br /&gt;
&lt;br /&gt;
=== Disable for Windows (for now) ===&lt;br /&gt;
Until we solve the private-symbol problem on Windows, we will need to wrap our unit test code in the following &amp;lt;code&amp;gt;#ifdef&amp;lt;/code&amp;gt; block:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#if !defined(OPENSSL_SYS_WINDOWS)&lt;br /&gt;
&lt;br /&gt;
/* All the test code, including main() */&lt;br /&gt;
&lt;br /&gt;
int main(int argc, char *argv[])                                                &lt;br /&gt;
    {&lt;br /&gt;
        return EXIT_SUCCESS;                                                    &lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
#endif /* OPENSSL_NO_WINDOWS  */&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Samples ==&lt;br /&gt;
Existing tests that can be used as models for new tests.&lt;br /&gt;
* [http://git.openssl.org/gitweb/?p=openssl.git;a=blob;f=ssl/heartbeat_test.c ssl/heartbeat_test.c]: Follows [http://mike-bland.com/2014/06/05/pseudo-xunit-pattern.html the Pseudo-xUnit pattern]&lt;/div&gt;</summary>
		<author><name>Mbland</name></author>
	</entry>
	<entry>
		<id>https://wiki.openssl.org/index.php?title=Testing_and_Development_Tools_and_Tips&amp;diff=1741</id>
		<title>Testing and Development Tools and Tips</title>
		<link rel="alternate" type="text/html" href="https://wiki.openssl.org/index.php?title=Testing_and_Development_Tools_and_Tips&amp;diff=1741"/>
		<updated>2014-06-10T18:38:36Z</updated>

		<summary type="html">&lt;p&gt;Mbland: Update test/testutil.h now that's it's merged into openssl/master as commit 3ead9f3798cb6de93b9824d6f833da9f00d8f5d7&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This is a collection of helpful tools and tips for navigating the OpenSSL code base and managing a local git repository.&lt;br /&gt;
&lt;br /&gt;
== Testing Environment and Tools ==&lt;br /&gt;
In [https://github.com/mbland/openssl/compare/test-util the test-util branch of Mike Bland's fork] are a few helper files that you may wish to copy or pull into your branch.&lt;br /&gt;
&lt;br /&gt;
=== test/testutil.h ===&lt;br /&gt;
[http://git.openssl.org/gitweb/?p=openssl.git;a=blob;f=test/testutil.h test/testutil.h] defines the generic &amp;lt;code&amp;gt;SETUP_TEST_FIXTURE&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;EXECUTE_TEST&amp;lt;/code&amp;gt; macros. The header comments describe how to define test-specific macros based on these.&lt;br /&gt;
&lt;br /&gt;
=== test/new-test.sh ===&lt;br /&gt;
Generates a new automated test stub, following [http://mike-bland.com/2014/06/05/pseudo-xunit-pattern.html the Pseudo-xUnit Pattern] and using the macros from &amp;lt;code&amp;gt;test/testutil.h&amp;lt;/code&amp;gt;. The generated stub will compile standalone.&lt;br /&gt;
&lt;br /&gt;
=== test/test_env.bash ===&lt;br /&gt;
Environment variables, functions, and aliases to help with OpenSSL unit testing. The header comments contain documentation on each of the functions and aliases in the file.&lt;br /&gt;
&lt;br /&gt;
== Cscope ==&lt;br /&gt;
[http://cscope.sourceforge.net/ Cscope] is a powerful C source code browser. Once you have it installed, you can use the &amp;lt;code&amp;gt;make-cscope&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;open-cscope&amp;lt;/code&amp;gt; functions from &amp;lt;code&amp;gt;test/test_env.bash&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Vim Integration ===&lt;br /&gt;
Once &amp;lt;code&amp;gt;$CSCOPE_DB&amp;lt;/code&amp;gt; (defined in &amp;lt;code&amp;gt;test/test_env.bash&amp;lt;/code&amp;gt; is built using &amp;lt;code&amp;gt;make-cscope&amp;lt;/code&amp;gt;, you can take advantage of the Cscope integration in Vim by adding something like the following to your &amp;lt;code&amp;gt;.vimrc&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;quot; Detect whether cscope features are present and whether we should add a&lt;br /&gt;
&amp;quot; connection to an existing cscope.out database file&lt;br /&gt;
if has(&amp;quot;cscope&amp;quot;)&lt;br /&gt;
  set nocsverb&lt;br /&gt;
  if filereadable(&amp;quot;./cscope.out&amp;quot;)&lt;br /&gt;
    cs add cscope.out&lt;br /&gt;
  elseif $CSCOPE_DB != &amp;quot;&amp;quot;&lt;br /&gt;
    if filereadable($CSCOPE_DB)&lt;br /&gt;
      cs add $CSCOPE_DB&lt;br /&gt;
    else&lt;br /&gt;
      echo &amp;quot;Can't read $CSCOPE_DB; cscope add not run&amp;quot;&lt;br /&gt;
    endif&lt;br /&gt;
  endif&lt;br /&gt;
  set csre&lt;br /&gt;
  set csverb&lt;br /&gt;
endif&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Ctags ==&lt;br /&gt;
Ctags generates an index of symbols that many editors can use to quickly navigate the source code. Though many Unices ship with a version installed at &amp;lt;code&amp;gt;/usr/bin/ctags&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;test_env.bash&amp;lt;/code&amp;gt; presumes that [http://ctags.sourceforge.net/ Exuberant Ctags] is installed.&lt;br /&gt;
&lt;br /&gt;
=== Vim Integration ===&lt;br /&gt;
Add this to your &amp;lt;code&amp;gt;.vimrc&amp;lt;/code&amp;gt; to take advantage of Ctags integration in vim:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;quot; The tags path, as set below, will search the local file first, then the       &lt;br /&gt;
&amp;quot; project-wide file.&lt;br /&gt;
if $TAGS_FILE != &amp;quot;&amp;quot;                                                             &lt;br /&gt;
  if filereadable($TAGS_FILE)&lt;br /&gt;
    set tags+=$TAGS_FILE&lt;br /&gt;
  else                                                                          &lt;br /&gt;
    echo &amp;quot;Can't read $TAGS_FILE; tags not set&amp;quot;&lt;br /&gt;
  endif&lt;br /&gt;
endif&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== git-new-workdir ==&lt;br /&gt;
Usually installed as &amp;lt;code&amp;gt;/usr/local/share/git-core/contrib/workdir/git-new-workdir&amp;lt;/code&amp;gt;, this will create a new working directory for a specified branch that's linked to the original repository. This is nice when working on multiple branches in parallel, as it doesn't require committing or stashing changes before issuing a &amp;lt;code&amp;gt;git checkout&amp;lt;/code&amp;gt; to switch between branches. The following &amp;lt;code&amp;gt;bash&amp;lt;/code&amp;gt; function wraps &amp;lt;code&amp;gt;git-new-workdir&amp;lt;/code&amp;gt; to create a working dir called &amp;lt;code&amp;gt;reponame-branchname&amp;lt;/code&amp;gt; in the same directory as the original repository:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Creates a branch-specific git working directory in the same directory as the&lt;br /&gt;
# original repository.&lt;br /&gt;
git-new-workdir() {                                                             &lt;br /&gt;
  if test $# -ne 2; then&lt;br /&gt;
    echo &amp;quot;Usage: $FUNCNAME &amp;lt;git repo&amp;gt; &amp;lt;branch name&amp;gt;&amp;quot;                            &lt;br /&gt;
    return 1&lt;br /&gt;
  elif test ! -d $1; then&lt;br /&gt;
    echo &amp;quot;$1 does not exist&amp;quot;&lt;br /&gt;
    return 1&lt;br /&gt;
  fi&lt;br /&gt;
  new_workdir=$1-$2&lt;br /&gt;
  if /usr/local/share/git-core/contrib/workdir/git-new-workdir\&lt;br /&gt;
    $1 $new_workdir $2; then&lt;br /&gt;
    echo &amp;quot;Created $new_workdir&amp;quot;&lt;br /&gt;
  else&lt;br /&gt;
    return 1&lt;br /&gt;
  fi&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== tmux Terminal Multiplexer ==&lt;br /&gt;
[http://tmux.sourceforge.net/ The tmux terminal multiplexer] is helpful for using a single terminal window to efficiently manage different editing and build sessions, amongst many other useful functions. These are some helpful config options to add to &amp;lt;code&amp;gt;~/.tmux.conf&amp;lt;/code&amp;gt;, including getting GNU screen-like CTRL-a behavior:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set-option -g prefix C-a&lt;br /&gt;
unbind-key C-b&lt;br /&gt;
bind-key C-a send-prefix&lt;br /&gt;
&lt;br /&gt;
bind R source-file ~/.tmux.conf \; display &amp;quot;Reloaded ~/.tmux.conf&amp;quot;&lt;br /&gt;
set -g default-terminal &amp;quot;screen-256color&amp;quot;&lt;br /&gt;
set -g status-style fg=black,bg=colour7&lt;br /&gt;
setw -g window-status-style fg=default,bg=default,none&lt;br /&gt;
setw -g window-status-current-style fg=black,bg=colour15,bold&lt;br /&gt;
set -g pane-active-border-style fg=default,bg=colour7&lt;br /&gt;
set -g message-style fg=black,bg=colour11,bright&lt;br /&gt;
set -g status-utf8 on&lt;br /&gt;
setw -g monitor-activity on&lt;br /&gt;
set -g visual-activity on&lt;br /&gt;
&lt;br /&gt;
bind -r H resize-pane -L 5&lt;br /&gt;
bind -r J resize-pane -D 5&lt;br /&gt;
bind -r K resize-pane -U 5                                                      &lt;br /&gt;
bind -r L resize-pane -R 5&lt;br /&gt;
&lt;br /&gt;
# Enables nohup to work. From:&lt;br /&gt;
# https://github.com/ChrisJohnsen/tmux-MacOSX-pasteboard                        &lt;br /&gt;
set-option -g default-command &amp;quot;reattach-to-user-namespace -l $SHELL&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mbland</name></author>
	</entry>
	<entry>
		<id>https://wiki.openssl.org/index.php?title=How_To_Write_Unit_Tests_For_OpenSSL&amp;diff=1740</id>
		<title>How To Write Unit Tests For OpenSSL</title>
		<link rel="alternate" type="text/html" href="https://wiki.openssl.org/index.php?title=How_To_Write_Unit_Tests_For_OpenSSL&amp;diff=1740"/>
		<updated>2014-06-10T17:13:50Z</updated>

		<summary type="html">&lt;p&gt;Mbland: Add &amp;quot;Keep your repo up-to-date&amp;quot; and &amp;quot;Send a pull request&amp;quot; subsections&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This is an outline of the basic process and principles to follow when writing unit tests. This document will evolve quite a bit as the community gains experience.&lt;br /&gt;
&lt;br /&gt;
==Mechanics ==&lt;br /&gt;
=== Forking the Repo ===&lt;br /&gt;
For now, people contributing new unit tests for uncovered code (as opposed to submitting tests with new code changes) should fork [https://github.com/mbland/openssl Mike Bland's GitHub repository] and issue [https://help.github.com/articles/using-pull-requests GitHub pull requests]. Remember to do all development on a topic branch (not &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt;). Tests committed to this repo will occasionally get merged into the master OpenSSL repo.&lt;br /&gt;
&lt;br /&gt;
Rationale per Matt Caswell: We should think about process here. If you are going off to recruit an army of people writing tests then I wonder if it is worth setting up a separate github repository whilst you are building up the tests. We can then merge in from that on a periodic basis. I wouldn't want availability of openssl team committers to be a bottle neck.&lt;br /&gt;
&lt;br /&gt;
=== Check out the Tools and Tips page ===&lt;br /&gt;
[[Testing and Development Tools and Tips]] has information on tools that may make navigating and building the code a bit easier.&lt;br /&gt;
&lt;br /&gt;
=== Use the Test Template Generator ===&lt;br /&gt;
TODO(mbland): Get template generator checked-in. Maybe have a template generator for each library, e.g. &amp;lt;code&amp;gt;ssl/new-test.sh&amp;lt;/code&amp;gt; that has additional setup boilerplate specific to the &amp;lt;code&amp;gt;ssl&amp;lt;/code&amp;gt; library.&lt;br /&gt;
&lt;br /&gt;
Use the &amp;lt;code&amp;gt;test/new-test.sh&amp;lt;/code&amp;gt; script to generate a skeleton test file. ([https://github.com/mbland/openssl/compare/test-util pending in the test-util branch])&lt;br /&gt;
&lt;br /&gt;
=== Add Makefile Targets ===&lt;br /&gt;
The following instructions use the &amp;lt;code&amp;gt;Makefile&amp;lt;/code&amp;gt; targets for &amp;lt;code&amp;gt;ssl/heartbeat_test.c&amp;lt;/code&amp;gt; as an example.&lt;br /&gt;
&lt;br /&gt;
In the &amp;lt;code&amp;gt;Makefile&amp;lt;/code&amp;gt; for the library containing the test, add the test source file to the &amp;lt;code&amp;gt;TEST&amp;lt;/code&amp;gt; variable:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# ssl/Makefile&lt;br /&gt;
TEST=ssltest.c heartbeat_test.c&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In &amp;lt;code&amp;gt;test/Makefile&amp;lt;/code&amp;gt;:&lt;br /&gt;
* add a variable for the test target near the top of the file, right after the existing test variables&lt;br /&gt;
* use the variable to add an executable target to the &amp;lt;code&amp;gt;EXE&amp;lt;/code&amp;gt; variable&lt;br /&gt;
* use the variable to add an object file target to the &amp;lt;code&amp;gt;OBJ&amp;lt;/code&amp;gt; variable&lt;br /&gt;
* use the variable to add a source file target to the &amp;lt;code&amp;gt;SRC&amp;lt;/code&amp;gt; variable&lt;br /&gt;
* add the test target to the &amp;lt;code&amp;gt;alltests&amp;lt;/code&amp;gt; target&lt;br /&gt;
* add the target to execute the test&lt;br /&gt;
* add the target to build the test executable&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# test/Makefile&lt;br /&gt;
HEARTBEATTEST=  heartbeat_test&lt;br /&gt;
EXE=  ... $(HEARTBEATTEST)$(EXE_EXT)&lt;br /&gt;
OBJ= ... $(HEARTBEATTEST).o&lt;br /&gt;
SRC= ... $(HEARTBEATTEST).c&lt;br /&gt;
alltests: \&lt;br /&gt;
        ... test_heartbeat&lt;br /&gt;
&lt;br /&gt;
test_heartbeat: $(HEARTBEATTEST)$(EXE_EXT)&lt;br /&gt;
  ../util/shlib_wrap.sh ./$(HEARTBEATTEST)&lt;br /&gt;
&lt;br /&gt;
$(HEARTBEATTEST)$(EXE_EXT): $(HEARTBEATTEST).o $(DLIBCRYPTO)&lt;br /&gt;
  @target=$(HEARTBEATTEST); $(BUILD_CMD)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Run &amp;lt;code&amp;gt;make depend&amp;lt;/code&amp;gt; ===&lt;br /&gt;
Finally, run &amp;lt;code&amp;gt;make depend&amp;lt;/code&amp;gt; to automatically generate the header file dependencies.&lt;br /&gt;
&lt;br /&gt;
=== Building and Running the Test ===&lt;br /&gt;
If you're initially developing on Mac OS X or (for now) FreeBSD 10, just use the stock method of building and testing:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ config &amp;amp;&amp;amp; make &amp;amp;&amp;amp; make test&lt;br /&gt;
&lt;br /&gt;
# To execute just one specific test&lt;br /&gt;
$ make TESTS=test_heartbeat test &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Ultimately the test will have to compile and pass with developer flags enabled:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ ./GitConfigure debug-ben-debug-64-clang&lt;br /&gt;
$ ./GitMake -j 2&lt;br /&gt;
$ ./GitMake test_heartbeat&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above currently doesn't work on Mac OS X or FreeBSD 10; for now, you can install the 9.1 release of [http://www.freebsd.org/ FreeBSD], which uses Clang 3.1, via a virtualization platform such as [https://www.virtualbox.org/ VirtualBox]. (Mac OS X breaks, in part, due to the fact that it doesn't use the GNU assembler; &amp;lt;code&amp;gt;-fsanitize&amp;lt;/code&amp;gt; appears to be ignored on FreeBSD 9.1/Clang 3.1, but later versions break because the Clang compiler will emit &amp;lt;code&amp;gt;-fsanitize&amp;lt;/code&amp;gt; symbols but the &amp;lt;code&amp;gt;libasan&amp;lt;/code&amp;gt; library [http://lists.freebsd.org/pipermail/freebsd-hackers/2013-December/043995.html has yet to be ported to FreeBSD].)&lt;br /&gt;
&lt;br /&gt;
=== Keep your repo up-to-date ===&lt;br /&gt;
With [https://github.com/mbland/openssl Mike Bland's GitHub fork] set up as the upstream remote, periodically run &amp;lt;code&amp;gt;git pull --all&amp;lt;/code&amp;gt; to keep your repository up-to-date. Then, in the branch in which you're working, execute:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ git merge upstream/master&lt;br /&gt;
$ git rebase upstream/master&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Send a pull request ===&lt;br /&gt;
When your test is ready, send a [https://help.github.com/articles/using-pull-requests GitHub pull request]. We'll review the code, and when it's ready, it'll get merged into Mike's repository. From there, it will eventually get pulled into the master OpenSSL repository.&lt;br /&gt;
&lt;br /&gt;
== Style ==&lt;br /&gt;
[http://mike-bland.com/2014/06/05/pseudo-xunit-pattern.html The Pseudo-xUnit Pattern] is that established by [http://git.openssl.org/gitweb/?p=openssl.git;a=blob;f=ssl/heartbeat_test.c ssl/heartbeat_test.c]. This pattern organizes code in a fashion reminiscent of the [http://en.wikipedia.org/wiki/XUnit xUnit] family of unit testing frameworks, without actually using a testing framework. This should lower the barrier to entry for people wanting to write unit tests, but enable a relatively easy migration to an xUnit-based framework if we decide to do so one day.&lt;br /&gt;
&lt;br /&gt;
Some of the basic principles to follow are:&lt;br /&gt;
&lt;br /&gt;
=== Define a fixture structure ===&lt;br /&gt;
The fixture structure should contain all of the inputs to the code under test and all of the expected result values. It should also contain a &amp;lt;code&amp;gt;const char*&amp;lt;/code&amp;gt; for the name of the test case function that created it, to aid in error message formatting. Even though the fixture may contain dynamically-allocated members, the fixture itself should be copied by value to reduce the necessary degree of memory management in a small unit test program.&lt;br /&gt;
&lt;br /&gt;
=== Define set_up() and tear_down() functions for the fixture ===&lt;br /&gt;
&amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; should return a newly-initialized test fixture structure. It should take the name of the test case as an argument (i.e. &amp;lt;code&amp;gt;__func__&amp;lt;/code&amp;gt;) and assign it to the fixture. All of the fixture members should be initialized, which each test case function can then override as needed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;tear_down()&amp;lt;/code&amp;gt; should take the fixture as an argument and release any resources allocated by &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt;. It can also call any library-wide error printing routines (e.g. &amp;lt;code&amp;gt;ERR_print_errors_fp(stderr)&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
=== Use &amp;lt;code&amp;gt;SETUP_TEST_FIXTURE()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;EXECUTE_TEST()&amp;lt;/code&amp;gt; from &amp;lt;code&amp;gt;test/testutil.h&amp;lt;/code&amp;gt; ===&lt;br /&gt;
Each test case function should call &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; as its first statement, and should call &amp;lt;code&amp;gt;tear_down()&amp;lt;/code&amp;gt; just before returning. This is handled in a uniform fashion when using the &amp;lt;code&amp;gt;SETUP_TEST_FIXTURE()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;EXECUTE_TEST()&amp;lt;/code&amp;gt; helper macros from &amp;lt;code&amp;gt;test/testutil.h&amp;lt;/code&amp;gt; ([https://github.com/openssl/openssl/pull/126 pending pull request]). See the comments in &amp;lt;code&amp;gt;test/testutil.h&amp;lt;/code&amp;gt; for usage, and &amp;lt;code&amp;gt;ssl/heartbeat_test.c&amp;lt;/code&amp;gt; for an example of how to wrap the macros for a specific unit test.&lt;br /&gt;
&lt;br /&gt;
=== Use test case functions, not a table of fixtures ===&lt;br /&gt;
Individual test case functions that call a common execution function are much more readable and maintainable than a loop over a table of fixture structures. Explicit fixture variable assignments aid comprehension when reading a specific test case, which saves time and energy when trying to understand a test or diagnose a failure. When a new member is added to an existing fixture, &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; can set a default for all test cases, and only the test cases that rely on that new member need to be updated.&lt;br /&gt;
&lt;br /&gt;
=== Use very descriptive test case names ===&lt;br /&gt;
Give tests long, descriptive names that provide ample context for the details of the test case. Good test names are also help produce good error messages.&lt;br /&gt;
&lt;br /&gt;
=== Group test cases into &amp;quot;suites&amp;quot; by naming convention ===&lt;br /&gt;
Give logically-related tests the same prefix, e.g. &amp;lt;code&amp;gt;test_dtls1_&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;test_tls1&amp;lt;/code&amp;gt; from &amp;lt;code&amp;gt;ssl/heartbeat_test.c&amp;lt;/code&amp;gt;. If need be, you can define suite-specific &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; functions that call the common &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; and elaborate on it. (This generally shouldn't be necessary for &amp;lt;code&amp;gt;tear_down()&amp;lt;/code&amp;gt;.)&lt;br /&gt;
&lt;br /&gt;
=== Keep individual test case functions focused on one thing ===&lt;br /&gt;
If the test name contains the word &amp;quot;and&amp;quot;, consider breaking it into two or more separate test case functions.&lt;br /&gt;
&lt;br /&gt;
=== Write very descriptive error messages ===&lt;br /&gt;
Include the test case function name in each error message, and explain in detail the context for the assertion that failed. Include the expected result (contained in the fixture structure) and the actual result returned from the code under test. Write helper methods for complex values as needed (e.g. &amp;lt;code&amp;gt;print_payload()&amp;lt;/code&amp;gt; in &amp;lt;code&amp;gt;ssl/heartbeat_test.c&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
=== Return zero on success and one on failure ===&lt;br /&gt;
The return value will be used to tally the number of test cases that failed. Even if multiple assertions fail for a single test case, the result should be exactly one.&lt;br /&gt;
&lt;br /&gt;
=== Add each test case function to the test runner function ===&lt;br /&gt;
Whatever function is used to execute the batch of test case functions, be that &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt; or a separate function called by &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt;, don't forget to add your test case functions to that function.&lt;br /&gt;
&lt;br /&gt;
TODO(mbland): create some kind of automated script or editor macros?&lt;br /&gt;
&lt;br /&gt;
=== Report the number of test cases that failed ===&lt;br /&gt;
Add up the total number of failed test cases in &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt; and report that number as the last error message of the test. &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt; should return &amp;lt;code&amp;gt;EXIT_FAILURE&amp;lt;/code&amp;gt; if any test cases failed, &amp;lt;code&amp;gt;EXIT_SUCCESS&amp;lt;/code&amp;gt; otherwise.&lt;br /&gt;
&lt;br /&gt;
=== Disable for Windows (for now) ===&lt;br /&gt;
Until we solve the private-symbol problem on Windows, we will need to wrap our unit test code in the following &amp;lt;code&amp;gt;#ifdef&amp;lt;/code&amp;gt; block:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#if !defined(OPENSSL_SYS_WINDOWS)&lt;br /&gt;
&lt;br /&gt;
/* All the test code, including main() */&lt;br /&gt;
&lt;br /&gt;
int main(int argc, char *argv[])                                                &lt;br /&gt;
    {&lt;br /&gt;
        return EXIT_SUCCESS;                                                    &lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
#endif /* OPENSSL_NO_WINDOWS  */&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Samples ==&lt;br /&gt;
Existing tests that can be used as models for new tests.&lt;br /&gt;
* [http://git.openssl.org/gitweb/?p=openssl.git;a=blob;f=ssl/heartbeat_test.c ssl/heartbeat_test.c]: Follows [http://mike-bland.com/2014/06/05/pseudo-xunit-pattern.html the Pseudo-xUnit pattern]&lt;/div&gt;</summary>
		<author><name>Mbland</name></author>
	</entry>
	<entry>
		<id>https://wiki.openssl.org/index.php?title=How_To_Write_Unit_Tests_For_OpenSSL&amp;diff=1739</id>
		<title>How To Write Unit Tests For OpenSSL</title>
		<link rel="alternate" type="text/html" href="https://wiki.openssl.org/index.php?title=How_To_Write_Unit_Tests_For_OpenSSL&amp;diff=1739"/>
		<updated>2014-06-10T17:04:03Z</updated>

		<summary type="html">&lt;p&gt;Mbland: Add Check out the Tools and Tips page subsection&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This is an outline of the basic process and principles to follow when writing unit tests. This document will evolve quite a bit as the community gains experience.&lt;br /&gt;
&lt;br /&gt;
==Mechanics ==&lt;br /&gt;
=== Forking the Repo ===&lt;br /&gt;
For now, people contributing new unit tests for uncovered code (as opposed to submitting tests with new code changes) should fork [https://github.com/mbland/openssl Mike Bland's GitHub repository] and issue [https://help.github.com/articles/using-pull-requests GitHub pull requests]. Remember to do all development on a topic branch (not &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt;). Tests committed to this repo will occasionally get merged into the master OpenSSL repo.&lt;br /&gt;
&lt;br /&gt;
Rationale per Matt Caswell: We should think about process here. If you are going off to recruit an army of people writing tests then I wonder if it is worth setting up a separate github repository whilst you are building up the tests. We can then merge in from that on a periodic basis. I wouldn't want availability of openssl team committers to be a bottle neck.&lt;br /&gt;
&lt;br /&gt;
=== Check out the Tools and Tips page ===&lt;br /&gt;
[[Testing and Development Tools and Tips]] has information on tools that may make navigating and building the code a bit easier.&lt;br /&gt;
&lt;br /&gt;
=== Use the Test Template Generator ===&lt;br /&gt;
TODO(mbland): Get template generator checked-in. Maybe have a template generator for each library, e.g. &amp;lt;code&amp;gt;ssl/new-test.sh&amp;lt;/code&amp;gt; that has additional setup boilerplate specific to the &amp;lt;code&amp;gt;ssl&amp;lt;/code&amp;gt; library.&lt;br /&gt;
&lt;br /&gt;
Use the &amp;lt;code&amp;gt;test/new-test.sh&amp;lt;/code&amp;gt; script to generate a skeleton test file. ([https://github.com/mbland/openssl/compare/test-util pending in the test-util branch])&lt;br /&gt;
&lt;br /&gt;
=== Add Makefile Targets ===&lt;br /&gt;
The following instructions use the &amp;lt;code&amp;gt;Makefile&amp;lt;/code&amp;gt; targets for &amp;lt;code&amp;gt;ssl/heartbeat_test.c&amp;lt;/code&amp;gt; as an example.&lt;br /&gt;
&lt;br /&gt;
In the &amp;lt;code&amp;gt;Makefile&amp;lt;/code&amp;gt; for the library containing the test, add the test source file to the &amp;lt;code&amp;gt;TEST&amp;lt;/code&amp;gt; variable:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# ssl/Makefile&lt;br /&gt;
TEST=ssltest.c heartbeat_test.c&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In &amp;lt;code&amp;gt;test/Makefile&amp;lt;/code&amp;gt;:&lt;br /&gt;
* add a variable for the test target near the top of the file, right after the existing test variables&lt;br /&gt;
* use the variable to add an executable target to the &amp;lt;code&amp;gt;EXE&amp;lt;/code&amp;gt; variable&lt;br /&gt;
* use the variable to add an object file target to the &amp;lt;code&amp;gt;OBJ&amp;lt;/code&amp;gt; variable&lt;br /&gt;
* use the variable to add a source file target to the &amp;lt;code&amp;gt;SRC&amp;lt;/code&amp;gt; variable&lt;br /&gt;
* add the test target to the &amp;lt;code&amp;gt;alltests&amp;lt;/code&amp;gt; target&lt;br /&gt;
* add the target to execute the test&lt;br /&gt;
* add the target to build the test executable&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# test/Makefile&lt;br /&gt;
HEARTBEATTEST=  heartbeat_test&lt;br /&gt;
EXE=  ... $(HEARTBEATTEST)$(EXE_EXT)&lt;br /&gt;
OBJ= ... $(HEARTBEATTEST).o&lt;br /&gt;
SRC= ... $(HEARTBEATTEST).c&lt;br /&gt;
alltests: \&lt;br /&gt;
        ... test_heartbeat&lt;br /&gt;
&lt;br /&gt;
test_heartbeat: $(HEARTBEATTEST)$(EXE_EXT)&lt;br /&gt;
  ../util/shlib_wrap.sh ./$(HEARTBEATTEST)&lt;br /&gt;
&lt;br /&gt;
$(HEARTBEATTEST)$(EXE_EXT): $(HEARTBEATTEST).o $(DLIBCRYPTO)&lt;br /&gt;
  @target=$(HEARTBEATTEST); $(BUILD_CMD)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Run &amp;lt;code&amp;gt;make depend&amp;lt;/code&amp;gt; ===&lt;br /&gt;
Finally, run &amp;lt;code&amp;gt;make depend&amp;lt;/code&amp;gt; to automatically generate the header file dependencies.&lt;br /&gt;
&lt;br /&gt;
=== Building and Running the Test ===&lt;br /&gt;
If you're initially developing on Mac OS X or (for now) FreeBSD 10, just use the stock method of building and testing:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ config &amp;amp;&amp;amp; make &amp;amp;&amp;amp; make test&lt;br /&gt;
&lt;br /&gt;
# To execute just one specific test&lt;br /&gt;
$ make TESTS=test_heartbeat test &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Ultimately the test will have to compile and pass with developer flags enabled:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ ./GitConfigure debug-ben-debug-64-clang&lt;br /&gt;
$ ./GitMake -j 2&lt;br /&gt;
$ ./GitMake test_heartbeat&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above currently doesn't work on Mac OS X or FreeBSD 10; for now, you can install the 9.1 release of [http://www.freebsd.org/ FreeBSD], which uses Clang 3.1, via a virtualization platform such as [https://www.virtualbox.org/ VirtualBox]. (Mac OS X breaks, in part, due to the fact that it doesn't use the GNU assembler; &amp;lt;code&amp;gt;-fsanitize&amp;lt;/code&amp;gt; appears to be ignored on FreeBSD 9.1/Clang 3.1, but later versions break because the Clang compiler will emit &amp;lt;code&amp;gt;-fsanitize&amp;lt;/code&amp;gt; symbols but the &amp;lt;code&amp;gt;libasan&amp;lt;/code&amp;gt; library [http://lists.freebsd.org/pipermail/freebsd-hackers/2013-December/043995.html has yet to be ported to FreeBSD].)&lt;br /&gt;
&lt;br /&gt;
== Style ==&lt;br /&gt;
[http://mike-bland.com/2014/06/05/pseudo-xunit-pattern.html The Pseudo-xUnit Pattern] is that established by [http://git.openssl.org/gitweb/?p=openssl.git;a=blob;f=ssl/heartbeat_test.c ssl/heartbeat_test.c]. This pattern organizes code in a fashion reminiscent of the [http://en.wikipedia.org/wiki/XUnit xUnit] family of unit testing frameworks, without actually using a testing framework. This should lower the barrier to entry for people wanting to write unit tests, but enable a relatively easy migration to an xUnit-based framework if we decide to do so one day.&lt;br /&gt;
&lt;br /&gt;
Some of the basic principles to follow are:&lt;br /&gt;
&lt;br /&gt;
=== Define a fixture structure ===&lt;br /&gt;
The fixture structure should contain all of the inputs to the code under test and all of the expected result values. It should also contain a &amp;lt;code&amp;gt;const char*&amp;lt;/code&amp;gt; for the name of the test case function that created it, to aid in error message formatting. Even though the fixture may contain dynamically-allocated members, the fixture itself should be copied by value to reduce the necessary degree of memory management in a small unit test program.&lt;br /&gt;
&lt;br /&gt;
=== Define set_up() and tear_down() functions for the fixture ===&lt;br /&gt;
&amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; should return a newly-initialized test fixture structure. It should take the name of the test case as an argument (i.e. &amp;lt;code&amp;gt;__func__&amp;lt;/code&amp;gt;) and assign it to the fixture. All of the fixture members should be initialized, which each test case function can then override as needed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;tear_down()&amp;lt;/code&amp;gt; should take the fixture as an argument and release any resources allocated by &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt;. It can also call any library-wide error printing routines (e.g. &amp;lt;code&amp;gt;ERR_print_errors_fp(stderr)&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
=== Use &amp;lt;code&amp;gt;SETUP_TEST_FIXTURE()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;EXECUTE_TEST()&amp;lt;/code&amp;gt; from &amp;lt;code&amp;gt;test/testutil.h&amp;lt;/code&amp;gt; ===&lt;br /&gt;
Each test case function should call &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; as its first statement, and should call &amp;lt;code&amp;gt;tear_down()&amp;lt;/code&amp;gt; just before returning. This is handled in a uniform fashion when using the &amp;lt;code&amp;gt;SETUP_TEST_FIXTURE()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;EXECUTE_TEST()&amp;lt;/code&amp;gt; helper macros from &amp;lt;code&amp;gt;test/testutil.h&amp;lt;/code&amp;gt; ([https://github.com/openssl/openssl/pull/126 pending pull request]). See the comments in &amp;lt;code&amp;gt;test/testutil.h&amp;lt;/code&amp;gt; for usage, and &amp;lt;code&amp;gt;ssl/heartbeat_test.c&amp;lt;/code&amp;gt; for an example of how to wrap the macros for a specific unit test.&lt;br /&gt;
&lt;br /&gt;
=== Use test case functions, not a table of fixtures ===&lt;br /&gt;
Individual test case functions that call a common execution function are much more readable and maintainable than a loop over a table of fixture structures. Explicit fixture variable assignments aid comprehension when reading a specific test case, which saves time and energy when trying to understand a test or diagnose a failure. When a new member is added to an existing fixture, &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; can set a default for all test cases, and only the test cases that rely on that new member need to be updated.&lt;br /&gt;
&lt;br /&gt;
=== Use very descriptive test case names ===&lt;br /&gt;
Give tests long, descriptive names that provide ample context for the details of the test case. Good test names are also help produce good error messages.&lt;br /&gt;
&lt;br /&gt;
=== Group test cases into &amp;quot;suites&amp;quot; by naming convention ===&lt;br /&gt;
Give logically-related tests the same prefix, e.g. &amp;lt;code&amp;gt;test_dtls1_&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;test_tls1&amp;lt;/code&amp;gt; from &amp;lt;code&amp;gt;ssl/heartbeat_test.c&amp;lt;/code&amp;gt;. If need be, you can define suite-specific &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; functions that call the common &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; and elaborate on it. (This generally shouldn't be necessary for &amp;lt;code&amp;gt;tear_down()&amp;lt;/code&amp;gt;.)&lt;br /&gt;
&lt;br /&gt;
=== Keep individual test case functions focused on one thing ===&lt;br /&gt;
If the test name contains the word &amp;quot;and&amp;quot;, consider breaking it into two or more separate test case functions.&lt;br /&gt;
&lt;br /&gt;
=== Write very descriptive error messages ===&lt;br /&gt;
Include the test case function name in each error message, and explain in detail the context for the assertion that failed. Include the expected result (contained in the fixture structure) and the actual result returned from the code under test. Write helper methods for complex values as needed (e.g. &amp;lt;code&amp;gt;print_payload()&amp;lt;/code&amp;gt; in &amp;lt;code&amp;gt;ssl/heartbeat_test.c&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
=== Return zero on success and one on failure ===&lt;br /&gt;
The return value will be used to tally the number of test cases that failed. Even if multiple assertions fail for a single test case, the result should be exactly one.&lt;br /&gt;
&lt;br /&gt;
=== Add each test case function to the test runner function ===&lt;br /&gt;
Whatever function is used to execute the batch of test case functions, be that &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt; or a separate function called by &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt;, don't forget to add your test case functions to that function.&lt;br /&gt;
&lt;br /&gt;
TODO(mbland): create some kind of automated script or editor macros?&lt;br /&gt;
&lt;br /&gt;
=== Report the number of test cases that failed ===&lt;br /&gt;
Add up the total number of failed test cases in &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt; and report that number as the last error message of the test. &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt; should return &amp;lt;code&amp;gt;EXIT_FAILURE&amp;lt;/code&amp;gt; if any test cases failed, &amp;lt;code&amp;gt;EXIT_SUCCESS&amp;lt;/code&amp;gt; otherwise.&lt;br /&gt;
&lt;br /&gt;
=== Disable for Windows (for now) ===&lt;br /&gt;
Until we solve the private-symbol problem on Windows, we will need to wrap our unit test code in the following &amp;lt;code&amp;gt;#ifdef&amp;lt;/code&amp;gt; block:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#if !defined(OPENSSL_SYS_WINDOWS)&lt;br /&gt;
&lt;br /&gt;
/* All the test code, including main() */&lt;br /&gt;
&lt;br /&gt;
int main(int argc, char *argv[])                                                &lt;br /&gt;
    {&lt;br /&gt;
        return EXIT_SUCCESS;                                                    &lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
#endif /* OPENSSL_NO_WINDOWS  */&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Samples ==&lt;br /&gt;
Existing tests that can be used as models for new tests.&lt;br /&gt;
* [http://git.openssl.org/gitweb/?p=openssl.git;a=blob;f=ssl/heartbeat_test.c ssl/heartbeat_test.c]: Follows [http://mike-bland.com/2014/06/05/pseudo-xunit-pattern.html the Pseudo-xUnit pattern]&lt;/div&gt;</summary>
		<author><name>Mbland</name></author>
	</entry>
	<entry>
		<id>https://wiki.openssl.org/index.php?title=Testing_and_Development_Tools_and_Tips&amp;diff=1738</id>
		<title>Testing and Development Tools and Tips</title>
		<link rel="alternate" type="text/html" href="https://wiki.openssl.org/index.php?title=Testing_and_Development_Tools_and_Tips&amp;diff=1738"/>
		<updated>2014-06-10T17:00:42Z</updated>

		<summary type="html">&lt;p&gt;Mbland: Add tmux section&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This is a collection of helpful tools and tips for navigating the OpenSSL code base and managing a local git repository.&lt;br /&gt;
&lt;br /&gt;
== Testing Environment and Tools ==&lt;br /&gt;
In [https://github.com/mbland/openssl/compare/test-util the test-util branch of Mike Bland's fork] are a few helper files that you may wish to copy or pull into your branch.&lt;br /&gt;
&lt;br /&gt;
=== test/testutil.h ===&lt;br /&gt;
Defines the generic &amp;lt;code&amp;gt;SETUP_TEST_FIXTURE&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;EXECUTE_TEST&amp;lt;/code&amp;gt; macros. Should be pulled into the mainline pending acceptance of [https://github.com/openssl/openssl/pull/126 pull request #126].&lt;br /&gt;
&lt;br /&gt;
=== test/new-test.sh ===&lt;br /&gt;
Generates a new automated test stub, following [http://mike-bland.com/2014/06/05/pseudo-xunit-pattern.html the Pseudo-xUnit Pattern] and using the macros from &amp;lt;code&amp;gt;test/testutil.h&amp;lt;/code&amp;gt;. The generated stub will compile standalone.&lt;br /&gt;
&lt;br /&gt;
=== test/test_env.bash ===&lt;br /&gt;
Environment variables, functions, and aliases to help with OpenSSL unit testing. The header comments contain documentation on each of the functions and aliases in the file.&lt;br /&gt;
&lt;br /&gt;
== Cscope ==&lt;br /&gt;
[http://cscope.sourceforge.net/ Cscope] is a powerful C source code browser. Once you have it installed, you can use the &amp;lt;code&amp;gt;make-cscope&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;open-cscope&amp;lt;/code&amp;gt; functions from &amp;lt;code&amp;gt;test/test_env.bash&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Vim Integration ===&lt;br /&gt;
Once &amp;lt;code&amp;gt;$CSCOPE_DB&amp;lt;/code&amp;gt; (defined in &amp;lt;code&amp;gt;test/test_env.bash&amp;lt;/code&amp;gt; is built using &amp;lt;code&amp;gt;make-cscope&amp;lt;/code&amp;gt;, you can take advantage of the Cscope integration in Vim by adding something like the following to your &amp;lt;code&amp;gt;.vimrc&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;quot; Detect whether cscope features are present and whether we should add a&lt;br /&gt;
&amp;quot; connection to an existing cscope.out database file&lt;br /&gt;
if has(&amp;quot;cscope&amp;quot;)&lt;br /&gt;
  set nocsverb&lt;br /&gt;
  if filereadable(&amp;quot;./cscope.out&amp;quot;)&lt;br /&gt;
    cs add cscope.out&lt;br /&gt;
  elseif $CSCOPE_DB != &amp;quot;&amp;quot;&lt;br /&gt;
    if filereadable($CSCOPE_DB)&lt;br /&gt;
      cs add $CSCOPE_DB&lt;br /&gt;
    else&lt;br /&gt;
      echo &amp;quot;Can't read $CSCOPE_DB; cscope add not run&amp;quot;&lt;br /&gt;
    endif&lt;br /&gt;
  endif&lt;br /&gt;
  set csre&lt;br /&gt;
  set csverb&lt;br /&gt;
endif&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Ctags ==&lt;br /&gt;
Ctags generates an index of symbols that many editors can use to quickly navigate the source code. Though many Unices ship with a version installed at &amp;lt;code&amp;gt;/usr/bin/ctags&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;test_env.bash&amp;lt;/code&amp;gt; presumes that [http://ctags.sourceforge.net/ Exuberant Ctags] is installed.&lt;br /&gt;
&lt;br /&gt;
=== Vim Integration ===&lt;br /&gt;
Add this to your &amp;lt;code&amp;gt;.vimrc&amp;lt;/code&amp;gt; to take advantage of Ctags integration in vim:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;quot; The tags path, as set below, will search the local file first, then the       &lt;br /&gt;
&amp;quot; project-wide file.&lt;br /&gt;
if $TAGS_FILE != &amp;quot;&amp;quot;                                                             &lt;br /&gt;
  if filereadable($TAGS_FILE)&lt;br /&gt;
    set tags+=$TAGS_FILE&lt;br /&gt;
  else                                                                          &lt;br /&gt;
    echo &amp;quot;Can't read $TAGS_FILE; tags not set&amp;quot;&lt;br /&gt;
  endif&lt;br /&gt;
endif&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== git-new-workdir ==&lt;br /&gt;
Usually installed as &amp;lt;code&amp;gt;/usr/local/share/git-core/contrib/workdir/git-new-workdir&amp;lt;/code&amp;gt;, this will create a new working directory for a specified branch that's linked to the original repository. This is nice when working on multiple branches in parallel, as it doesn't require committing or stashing changes before issuing a &amp;lt;code&amp;gt;git checkout&amp;lt;/code&amp;gt; to switch between branches. The following &amp;lt;code&amp;gt;bash&amp;lt;/code&amp;gt; function wraps &amp;lt;code&amp;gt;git-new-workdir&amp;lt;/code&amp;gt; to create a working dir called &amp;lt;code&amp;gt;reponame-branchname&amp;lt;/code&amp;gt; in the same directory as the original repository:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Creates a branch-specific git working directory in the same directory as the&lt;br /&gt;
# original repository.&lt;br /&gt;
git-new-workdir() {                                                             &lt;br /&gt;
  if test $# -ne 2; then&lt;br /&gt;
    echo &amp;quot;Usage: $FUNCNAME &amp;lt;git repo&amp;gt; &amp;lt;branch name&amp;gt;&amp;quot;                            &lt;br /&gt;
    return 1&lt;br /&gt;
  elif test ! -d $1; then&lt;br /&gt;
    echo &amp;quot;$1 does not exist&amp;quot;&lt;br /&gt;
    return 1&lt;br /&gt;
  fi&lt;br /&gt;
  new_workdir=$1-$2&lt;br /&gt;
  if /usr/local/share/git-core/contrib/workdir/git-new-workdir\&lt;br /&gt;
    $1 $new_workdir $2; then&lt;br /&gt;
    echo &amp;quot;Created $new_workdir&amp;quot;&lt;br /&gt;
  else&lt;br /&gt;
    return 1&lt;br /&gt;
  fi&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== tmux Terminal Multiplexer ==&lt;br /&gt;
[http://tmux.sourceforge.net/ The tmux terminal multiplexer] is helpful for using a single terminal window to efficiently manage different editing and build sessions, amongst many other useful functions. These are some helpful config options to add to &amp;lt;code&amp;gt;~/.tmux.conf&amp;lt;/code&amp;gt;, including getting GNU screen-like CTRL-a behavior:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set-option -g prefix C-a&lt;br /&gt;
unbind-key C-b&lt;br /&gt;
bind-key C-a send-prefix&lt;br /&gt;
&lt;br /&gt;
bind R source-file ~/.tmux.conf \; display &amp;quot;Reloaded ~/.tmux.conf&amp;quot;&lt;br /&gt;
set -g default-terminal &amp;quot;screen-256color&amp;quot;&lt;br /&gt;
set -g status-style fg=black,bg=colour7&lt;br /&gt;
setw -g window-status-style fg=default,bg=default,none&lt;br /&gt;
setw -g window-status-current-style fg=black,bg=colour15,bold&lt;br /&gt;
set -g pane-active-border-style fg=default,bg=colour7&lt;br /&gt;
set -g message-style fg=black,bg=colour11,bright&lt;br /&gt;
set -g status-utf8 on&lt;br /&gt;
setw -g monitor-activity on&lt;br /&gt;
set -g visual-activity on&lt;br /&gt;
&lt;br /&gt;
bind -r H resize-pane -L 5&lt;br /&gt;
bind -r J resize-pane -D 5&lt;br /&gt;
bind -r K resize-pane -U 5                                                      &lt;br /&gt;
bind -r L resize-pane -R 5&lt;br /&gt;
&lt;br /&gt;
# Enables nohup to work. From:&lt;br /&gt;
# https://github.com/ChrisJohnsen/tmux-MacOSX-pasteboard                        &lt;br /&gt;
set-option -g default-command &amp;quot;reattach-to-user-namespace -l $SHELL&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mbland</name></author>
	</entry>
	<entry>
		<id>https://wiki.openssl.org/index.php?title=Testing_and_Development_Tools_and_Tips&amp;diff=1737</id>
		<title>Testing and Development Tools and Tips</title>
		<link rel="alternate" type="text/html" href="https://wiki.openssl.org/index.php?title=Testing_and_Development_Tools_and_Tips&amp;diff=1737"/>
		<updated>2014-06-10T16:56:02Z</updated>

		<summary type="html">&lt;p&gt;Mbland: Flesh out git-new-workdir section&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This is a collection of helpful tools and tips for navigating the OpenSSL code base and managing a local git repository.&lt;br /&gt;
&lt;br /&gt;
== Testing Environment and Tools ==&lt;br /&gt;
In [https://github.com/mbland/openssl/compare/test-util the test-util branch of Mike Bland's fork] are a few helper files that you may wish to copy or pull into your branch.&lt;br /&gt;
&lt;br /&gt;
=== test/testutil.h ===&lt;br /&gt;
Defines the generic &amp;lt;code&amp;gt;SETUP_TEST_FIXTURE&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;EXECUTE_TEST&amp;lt;/code&amp;gt; macros. Should be pulled into the mainline pending acceptance of [https://github.com/openssl/openssl/pull/126 pull request #126].&lt;br /&gt;
&lt;br /&gt;
=== test/new-test.sh ===&lt;br /&gt;
Generates a new automated test stub, following [http://mike-bland.com/2014/06/05/pseudo-xunit-pattern.html the Pseudo-xUnit Pattern] and using the macros from &amp;lt;code&amp;gt;test/testutil.h&amp;lt;/code&amp;gt;. The generated stub will compile standalone.&lt;br /&gt;
&lt;br /&gt;
=== test/test_env.bash ===&lt;br /&gt;
Environment variables, functions, and aliases to help with OpenSSL unit testing. The header comments contain documentation on each of the functions and aliases in the file.&lt;br /&gt;
&lt;br /&gt;
== Cscope ==&lt;br /&gt;
[http://cscope.sourceforge.net/ Cscope] is a powerful C source code browser. Once you have it installed, you can use the &amp;lt;code&amp;gt;make-cscope&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;open-cscope&amp;lt;/code&amp;gt; functions from &amp;lt;code&amp;gt;test/test_env.bash&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Vim Integration ===&lt;br /&gt;
Once &amp;lt;code&amp;gt;$CSCOPE_DB&amp;lt;/code&amp;gt; (defined in &amp;lt;code&amp;gt;test/test_env.bash&amp;lt;/code&amp;gt; is built using &amp;lt;code&amp;gt;make-cscope&amp;lt;/code&amp;gt;, you can take advantage of the Cscope integration in Vim by adding something like the following to your &amp;lt;code&amp;gt;.vimrc&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;quot; Detect whether cscope features are present and whether we should add a&lt;br /&gt;
&amp;quot; connection to an existing cscope.out database file&lt;br /&gt;
if has(&amp;quot;cscope&amp;quot;)&lt;br /&gt;
  set nocsverb&lt;br /&gt;
  if filereadable(&amp;quot;./cscope.out&amp;quot;)&lt;br /&gt;
    cs add cscope.out&lt;br /&gt;
  elseif $CSCOPE_DB != &amp;quot;&amp;quot;&lt;br /&gt;
    if filereadable($CSCOPE_DB)&lt;br /&gt;
      cs add $CSCOPE_DB&lt;br /&gt;
    else&lt;br /&gt;
      echo &amp;quot;Can't read $CSCOPE_DB; cscope add not run&amp;quot;&lt;br /&gt;
    endif&lt;br /&gt;
  endif&lt;br /&gt;
  set csre&lt;br /&gt;
  set csverb&lt;br /&gt;
endif&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Ctags ==&lt;br /&gt;
Ctags generates an index of symbols that many editors can use to quickly navigate the source code. Though many Unices ship with a version installed at &amp;lt;code&amp;gt;/usr/bin/ctags&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;test_env.bash&amp;lt;/code&amp;gt; presumes that [http://ctags.sourceforge.net/ Exuberant Ctags] is installed.&lt;br /&gt;
&lt;br /&gt;
=== Vim Integration ===&lt;br /&gt;
Add this to your &amp;lt;code&amp;gt;.vimrc&amp;lt;/code&amp;gt; to take advantage of Ctags integration in vim:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;quot; The tags path, as set below, will search the local file first, then the       &lt;br /&gt;
&amp;quot; project-wide file.&lt;br /&gt;
if $TAGS_FILE != &amp;quot;&amp;quot;                                                             &lt;br /&gt;
  if filereadable($TAGS_FILE)&lt;br /&gt;
    set tags+=$TAGS_FILE&lt;br /&gt;
  else                                                                          &lt;br /&gt;
    echo &amp;quot;Can't read $TAGS_FILE; tags not set&amp;quot;&lt;br /&gt;
  endif&lt;br /&gt;
endif&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== git-new-workdir ==&lt;br /&gt;
Usually installed as &amp;lt;code&amp;gt;/usr/local/share/git-core/contrib/workdir/git-new-workdir&amp;lt;/code&amp;gt;, this will create a new working directory for a specified branch that's linked to the original repository. This is nice when working on multiple branches in parallel, as it doesn't require committing or stashing changes before issuing a &amp;lt;code&amp;gt;git checkout&amp;lt;/code&amp;gt; to switch between branches. The following &amp;lt;code&amp;gt;bash&amp;lt;/code&amp;gt; function wraps &amp;lt;code&amp;gt;git-new-workdir&amp;lt;/code&amp;gt; to create a working dir called &amp;lt;code&amp;gt;reponame-branchname&amp;lt;/code&amp;gt; in the same directory as the original repository:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Creates a branch-specific git working directory in the same directory as the&lt;br /&gt;
# original repository.&lt;br /&gt;
git-new-workdir() {                                                             &lt;br /&gt;
  if test $# -ne 2; then&lt;br /&gt;
    echo &amp;quot;Usage: $FUNCNAME &amp;lt;git repo&amp;gt; &amp;lt;branch name&amp;gt;&amp;quot;                            &lt;br /&gt;
    return 1&lt;br /&gt;
  elif test ! -d $1; then&lt;br /&gt;
    echo &amp;quot;$1 does not exist&amp;quot;&lt;br /&gt;
    return 1&lt;br /&gt;
  fi&lt;br /&gt;
  new_workdir=$1-$2&lt;br /&gt;
  if /usr/local/share/git-core/contrib/workdir/git-new-workdir\&lt;br /&gt;
    $1 $new_workdir $2; then&lt;br /&gt;
    echo &amp;quot;Created $new_workdir&amp;quot;&lt;br /&gt;
  else&lt;br /&gt;
    return 1&lt;br /&gt;
  fi&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mbland</name></author>
	</entry>
	<entry>
		<id>https://wiki.openssl.org/index.php?title=Testing_and_Development_Tools_and_Tips&amp;diff=1736</id>
		<title>Testing and Development Tools and Tips</title>
		<link rel="alternate" type="text/html" href="https://wiki.openssl.org/index.php?title=Testing_and_Development_Tools_and_Tips&amp;diff=1736"/>
		<updated>2014-06-10T16:51:27Z</updated>

		<summary type="html">&lt;p&gt;Mbland: Flesh out Ctags section&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This is a collection of helpful tools and tips for navigating the OpenSSL code base and managing a local git repository.&lt;br /&gt;
&lt;br /&gt;
== Testing Environment and Tools ==&lt;br /&gt;
In [https://github.com/mbland/openssl/compare/test-util the test-util branch of Mike Bland's fork] are a few helper files that you may wish to copy or pull into your branch.&lt;br /&gt;
&lt;br /&gt;
=== test/testutil.h ===&lt;br /&gt;
Defines the generic &amp;lt;code&amp;gt;SETUP_TEST_FIXTURE&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;EXECUTE_TEST&amp;lt;/code&amp;gt; macros. Should be pulled into the mainline pending acceptance of [https://github.com/openssl/openssl/pull/126 pull request #126].&lt;br /&gt;
&lt;br /&gt;
=== test/new-test.sh ===&lt;br /&gt;
Generates a new automated test stub, following [http://mike-bland.com/2014/06/05/pseudo-xunit-pattern.html the Pseudo-xUnit Pattern] and using the macros from &amp;lt;code&amp;gt;test/testutil.h&amp;lt;/code&amp;gt;. The generated stub will compile standalone.&lt;br /&gt;
&lt;br /&gt;
=== test/test_env.bash ===&lt;br /&gt;
Environment variables, functions, and aliases to help with OpenSSL unit testing. The header comments contain documentation on each of the functions and aliases in the file.&lt;br /&gt;
&lt;br /&gt;
== Cscope ==&lt;br /&gt;
[http://cscope.sourceforge.net/ Cscope] is a powerful C source code browser. Once you have it installed, you can use the &amp;lt;code&amp;gt;make-cscope&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;open-cscope&amp;lt;/code&amp;gt; functions from &amp;lt;code&amp;gt;test/test_env.bash&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Vim Integration ===&lt;br /&gt;
Once &amp;lt;code&amp;gt;$CSCOPE_DB&amp;lt;/code&amp;gt; (defined in &amp;lt;code&amp;gt;test/test_env.bash&amp;lt;/code&amp;gt; is built using &amp;lt;code&amp;gt;make-cscope&amp;lt;/code&amp;gt;, you can take advantage of the Cscope integration in Vim by adding something like the following to your &amp;lt;code&amp;gt;.vimrc&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;quot; Detect whether cscope features are present and whether we should add a&lt;br /&gt;
&amp;quot; connection to an existing cscope.out database file&lt;br /&gt;
if has(&amp;quot;cscope&amp;quot;)&lt;br /&gt;
  set nocsverb&lt;br /&gt;
  if filereadable(&amp;quot;./cscope.out&amp;quot;)&lt;br /&gt;
    cs add cscope.out&lt;br /&gt;
  elseif $CSCOPE_DB != &amp;quot;&amp;quot;&lt;br /&gt;
    if filereadable($CSCOPE_DB)&lt;br /&gt;
      cs add $CSCOPE_DB&lt;br /&gt;
    else&lt;br /&gt;
      echo &amp;quot;Can't read $CSCOPE_DB; cscope add not run&amp;quot;&lt;br /&gt;
    endif&lt;br /&gt;
  endif&lt;br /&gt;
  set csre&lt;br /&gt;
  set csverb&lt;br /&gt;
endif&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Ctags ==&lt;br /&gt;
Ctags generates an index of symbols that many editors can use to quickly navigate the source code. Though many Unices ship with a version installed at &amp;lt;code&amp;gt;/usr/bin/ctags&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;test_env.bash&amp;lt;/code&amp;gt; presumes that [http://ctags.sourceforge.net/ Exuberant Ctags] is installed.&lt;br /&gt;
&lt;br /&gt;
=== Vim Integration ===&lt;br /&gt;
Add this to your &amp;lt;code&amp;gt;.vimrc&amp;lt;/code&amp;gt; to take advantage of Ctags integration in vim:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;quot; The tags path, as set below, will search the local file first, then the       &lt;br /&gt;
&amp;quot; project-wide file.&lt;br /&gt;
if $TAGS_FILE != &amp;quot;&amp;quot;                                                             &lt;br /&gt;
  if filereadable($TAGS_FILE)&lt;br /&gt;
    set tags+=$TAGS_FILE&lt;br /&gt;
  else                                                                          &lt;br /&gt;
    echo &amp;quot;Can't read $TAGS_FILE; tags not set&amp;quot;&lt;br /&gt;
  endif&lt;br /&gt;
endif&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== git-new-workdir ==&lt;/div&gt;</summary>
		<author><name>Mbland</name></author>
	</entry>
	<entry>
		<id>https://wiki.openssl.org/index.php?title=Testing_and_Development_Tools_and_Tips&amp;diff=1735</id>
		<title>Testing and Development Tools and Tips</title>
		<link rel="alternate" type="text/html" href="https://wiki.openssl.org/index.php?title=Testing_and_Development_Tools_and_Tips&amp;diff=1735"/>
		<updated>2014-06-10T16:48:03Z</updated>

		<summary type="html">&lt;p&gt;Mbland: Flesh out Cscope section&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This is a collection of helpful tools and tips for navigating the OpenSSL code base and managing a local git repository.&lt;br /&gt;
&lt;br /&gt;
== Testing Environment and Tools ==&lt;br /&gt;
In [https://github.com/mbland/openssl/compare/test-util the test-util branch of Mike Bland's fork] are a few helper files that you may wish to copy or pull into your branch.&lt;br /&gt;
&lt;br /&gt;
=== test/testutil.h ===&lt;br /&gt;
Defines the generic &amp;lt;code&amp;gt;SETUP_TEST_FIXTURE&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;EXECUTE_TEST&amp;lt;/code&amp;gt; macros. Should be pulled into the mainline pending acceptance of [https://github.com/openssl/openssl/pull/126 pull request #126].&lt;br /&gt;
&lt;br /&gt;
=== test/new-test.sh ===&lt;br /&gt;
Generates a new automated test stub, following [http://mike-bland.com/2014/06/05/pseudo-xunit-pattern.html the Pseudo-xUnit Pattern] and using the macros from &amp;lt;code&amp;gt;test/testutil.h&amp;lt;/code&amp;gt;. The generated stub will compile standalone.&lt;br /&gt;
&lt;br /&gt;
=== test/test_env.bash ===&lt;br /&gt;
Environment variables, functions, and aliases to help with OpenSSL unit testing. The header comments contain documentation on each of the functions and aliases in the file.&lt;br /&gt;
&lt;br /&gt;
== Cscope ==&lt;br /&gt;
[http://cscope.sourceforge.net/ Cscope] is a powerful C source code browser. Once you have it installed, you can use the &amp;lt;code&amp;gt;make-cscope&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;open-cscope&amp;lt;/code&amp;gt; functions from &amp;lt;code&amp;gt;test/test_env.bash&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Vim Integration ===&lt;br /&gt;
Once &amp;lt;code&amp;gt;$CSCOPE_DB&amp;lt;/code&amp;gt; (defined in &amp;lt;code&amp;gt;test/test_env.bash&amp;lt;/code&amp;gt; is built using &amp;lt;code&amp;gt;make-cscope&amp;lt;/code&amp;gt;, you can take advantage of the Cscope integration in Vim by adding something like the following to your &amp;lt;code&amp;gt;.vimrc&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;quot; Detect whether cscope features are present and whether we should add a&lt;br /&gt;
&amp;quot; connection to an existing cscope.out database file&lt;br /&gt;
if has(&amp;quot;cscope&amp;quot;)&lt;br /&gt;
  set nocsverb&lt;br /&gt;
  if filereadable(&amp;quot;./cscope.out&amp;quot;)&lt;br /&gt;
    cs add cscope.out&lt;br /&gt;
  elseif $CSCOPE_DB != &amp;quot;&amp;quot;&lt;br /&gt;
    if filereadable($CSCOPE_DB)&lt;br /&gt;
      cs add $CSCOPE_DB&lt;br /&gt;
    else&lt;br /&gt;
      echo &amp;quot;Can't read $CSCOPE_DB; cscope add not run&amp;quot;&lt;br /&gt;
    endif&lt;br /&gt;
  endif&lt;br /&gt;
  set csre&lt;br /&gt;
  set csverb&lt;br /&gt;
endif&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Ctags ==&lt;br /&gt;
=== Vim Integration ===&lt;br /&gt;
&lt;br /&gt;
== git-new-workdir ==&lt;/div&gt;</summary>
		<author><name>Mbland</name></author>
	</entry>
	<entry>
		<id>https://wiki.openssl.org/index.php?title=Testing_and_Development_Tools_and_Tips&amp;diff=1734</id>
		<title>Testing and Development Tools and Tips</title>
		<link rel="alternate" type="text/html" href="https://wiki.openssl.org/index.php?title=Testing_and_Development_Tools_and_Tips&amp;diff=1734"/>
		<updated>2014-06-10T16:43:56Z</updated>

		<summary type="html">&lt;p&gt;Mbland: Flesh out Testing Environment and Tools&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This is a collection of helpful tools and tips for navigating the OpenSSL code base and managing a local git repository.&lt;br /&gt;
&lt;br /&gt;
== Testing Environment and Tools ==&lt;br /&gt;
In [https://github.com/mbland/openssl/compare/test-util the test-util branch of Mike Bland's fork] are a few helper files that you may wish to copy or pull into your branch.&lt;br /&gt;
&lt;br /&gt;
=== test/testutil.h ===&lt;br /&gt;
Defines the generic &amp;lt;code&amp;gt;SETUP_TEST_FIXTURE&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;EXECUTE_TEST&amp;lt;/code&amp;gt; macros. Should be pulled into the mainline pending acceptance of [https://github.com/openssl/openssl/pull/126 pull request #126].&lt;br /&gt;
&lt;br /&gt;
=== test/new-test.sh ===&lt;br /&gt;
Generates a new automated test stub, following [http://mike-bland.com/2014/06/05/pseudo-xunit-pattern.html the Pseudo-xUnit Pattern] and using the macros from &amp;lt;code&amp;gt;test/testutil.h&amp;lt;/code&amp;gt;. The generated stub will compile standalone.&lt;br /&gt;
&lt;br /&gt;
=== test/test_env.bash ===&lt;br /&gt;
Environment variables, functions, and aliases to help with OpenSSL unit testing. The header comments contain documentation on each of the functions and aliases in the file.&lt;br /&gt;
&lt;br /&gt;
== Cscope ==&lt;br /&gt;
=== Vim Integration ===&lt;br /&gt;
&lt;br /&gt;
== Ctags ==&lt;br /&gt;
=== Vim Integration ===&lt;br /&gt;
&lt;br /&gt;
== git-new-workdir ==&lt;/div&gt;</summary>
		<author><name>Mbland</name></author>
	</entry>
	<entry>
		<id>https://wiki.openssl.org/index.php?title=Testing_and_Development_Tools_and_Tips&amp;diff=1733</id>
		<title>Testing and Development Tools and Tips</title>
		<link rel="alternate" type="text/html" href="https://wiki.openssl.org/index.php?title=Testing_and_Development_Tools_and_Tips&amp;diff=1733"/>
		<updated>2014-06-10T16:27:27Z</updated>

		<summary type="html">&lt;p&gt;Mbland: Created page, initial sections&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This is a collection of helpful tools and tips for navigating the OpenSSL code base and managing a local git repository.&lt;br /&gt;
&lt;br /&gt;
== Testing Environment and Tools ==&lt;br /&gt;
&lt;br /&gt;
== Cscope ==&lt;br /&gt;
=== Vim Integration ===&lt;br /&gt;
&lt;br /&gt;
== Ctags ==&lt;br /&gt;
=== Vim Integration ===&lt;br /&gt;
&lt;br /&gt;
== git-new-workdir ==&lt;/div&gt;</summary>
		<author><name>Mbland</name></author>
	</entry>
	<entry>
		<id>https://wiki.openssl.org/index.php?title=Unit_Testing&amp;diff=1732</id>
		<title>Unit Testing</title>
		<link rel="alternate" type="text/html" href="https://wiki.openssl.org/index.php?title=Unit_Testing&amp;diff=1732"/>
		<updated>2014-06-10T16:24:39Z</updated>

		<summary type="html">&lt;p&gt;Mbland: /* Howtos and Style Guides */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page will track the effort to improve unit test and other automated test coverage for OpenSSL. Everyone is encouraged to help with this effort, but this page will track which community members have accepted specific responsibilities, and what tasks are currently underway.&lt;br /&gt;
&lt;br /&gt;
== Goals ==&lt;br /&gt;
&lt;br /&gt;
The goals of this project are:&lt;br /&gt;
&lt;br /&gt;
* Establish a written contribution/code review policy that requires:&lt;br /&gt;
** tests for every new code change, except for very trivial changes that do not directly impact program logic (e.g. documentation fixes, string constant updates, build script tweaks); this can be limited to an agreed-upon subset of the code to start, but would hopefully be expanded to cover most, if not all, of the code base&lt;br /&gt;
** tests for every bugfix &lt;br /&gt;
** smaller, well-tested changes building up to a complete feature (as opposed to large and/or untested changes that implement a large, complex feature all at once) &lt;br /&gt;
* Establish a schedule of Build Cops and Tutors to begin enforcing rollbacks/fixes and to help shepherd new contributors through the testing process.&lt;br /&gt;
* Set up a series of publicly-accessible continuous integration servers using whatever system the community prefers (e.g. Jenkins, Buildbot, etc.). These can be dedicated hardware or possibly Amazon Web Services-based. Establish a written policy that these remain green at all times, and that breakages be rolled-back or fixed within no more than 30 minutes.&lt;br /&gt;
&lt;br /&gt;
We can add more concrete goals to this list after we make progress on these. Getting people to own roles, setting up build infrastructure, and setting and enforcing policy are important first steps. Upon that foundation, we can begin to make serious progress towards improved test coverage, code quality, and defect prevention.&lt;br /&gt;
&lt;br /&gt;
== Discussion List ==&lt;br /&gt;
[https://groups.google.com/d/forum/openssl-testing openssl-testing] is the mailing list dedicated to the unit/automated testing effort, to avoid clogging openssl-dev. Membership is open to whoever wishes to join, even if only to lurk. Ideally all testing discussions will eventually move to openssl-dev once we have processes, tools, conventions, etc. in place.&lt;br /&gt;
&lt;br /&gt;
== Team ==&lt;br /&gt;
&lt;br /&gt;
We can define new roles as needed. The success of this effort will be inversely proportional to the number of roles with any one individual's name next to them. Each role can have more than one person filling it, but needs specific people to fill them. &lt;br /&gt;
&lt;br /&gt;
The point is not to tell people what to do and not do: it’s to establish clear responsibilities so everyone can run with them right away and begin applying their creative energy to solutions, rather than waste it figuring out what the hell is going on, what they should do to contribute, and who they need to coordinate with to get things done.&lt;br /&gt;
&lt;br /&gt;
=== Organizer===&lt;br /&gt;
&lt;br /&gt;
Contact: [mailto:mbland@acm.org Mike Bland]&lt;br /&gt;
&lt;br /&gt;
Ensures the overall effort is making progress by facilitating communication, removing obstacles, and making hands-on contributions when necessary.&lt;br /&gt;
&lt;br /&gt;
=== Tech Writer ===&lt;br /&gt;
&lt;br /&gt;
Contacts: [mailto:mbland@acm.org Mike Bland], Sandeep Mankar, Chelsea Komlo, Graham Brooks&lt;br /&gt;
&lt;br /&gt;
Maintains documentation of tools, techniques, outstanding issues, etc. May maintain a code review/testing style guide based on the community consensus. Also documents who currently fills each role, as well as who might've filled it in the past.&lt;br /&gt;
&lt;br /&gt;
=== Buildmaster ===&lt;br /&gt;
&lt;br /&gt;
Contacts:  [mailto:mbland@acm.org Mike Bland], Isaac Truett, Dileep Bapat, Graham Brooks&lt;br /&gt;
&lt;br /&gt;
Sets up and maintains automated builds and any infrastructure used to monitor them and report breakage.&lt;br /&gt;
&lt;br /&gt;
=== Toolsmith ===&lt;br /&gt;
&lt;br /&gt;
Contact: Tony Aiuto&lt;br /&gt;
&lt;br /&gt;
Maintains any tools and frameworks that are a part of the core build process; proposes, integrates, and/or retires existing tools.&lt;br /&gt;
&lt;br /&gt;
=== Tutor ===&lt;br /&gt;
&lt;br /&gt;
Contacts: [mailto:mbland@acm.org Mike Bland], Darshan Mody, Tom Francis, Brian N. Makin, Chelsea Komlo, Edward Knapp, Dileep Bapat, Graham Brooks&lt;br /&gt;
&lt;br /&gt;
Helps contributors, particularly new contributors, with the details of writing unit or other automated tests. May be assigned by the reviewer of a patch to help a contributor get a new change under test. Submission of the patch should require the approval of the tutor in most cases. (Should ideally be more than one person.)&lt;br /&gt;
&lt;br /&gt;
== Tasks ==&lt;br /&gt;
The current list is posted in the [http://goo.gl/5u9nbw OpenSSL Testing Tasks Google Spreadsheet].&lt;br /&gt;
&lt;br /&gt;
(Would be nice to enable the [http://www.mediawiki.org/wiki/Extension:Widget MediaWiki Widget extension] and the [http://www.mediawikiwidgets.org/Google_Spreadsheet Google Spreadsheet widget].)&lt;br /&gt;
&lt;br /&gt;
== Howtos and Style Guides ==&lt;br /&gt;
Documents that provide background on specific testing issues and idioms should be linked from here.&lt;br /&gt;
&lt;br /&gt;
* [[How To Write Unit Tests For OpenSSL]]&lt;br /&gt;
* [http://mike-bland.com/2014/06/05/pseudo-xunit-pattern.html The Pseudo-xUnit Pattern]&lt;br /&gt;
* [[Testing and Development Tools and Tips]]&lt;br /&gt;
&lt;br /&gt;
== Discussion Topics ==&lt;br /&gt;
These are discussions related to some of the current testing tasks.&lt;br /&gt;
&lt;br /&gt;
=== First Area of Focus ===&lt;br /&gt;
Matt Caswell: One criterion might be ease of testing. If you were going down that route you might choose some of the low level packages within libcrypto which are relatively self-contained. I'm not talking about the crypto algorithms themselves (there are at least *some* tests for those), I'm thinking more about bio, pem, x509, x509v3, etc.&lt;br /&gt;
&lt;br /&gt;
Another criterion might be where you get the most value. I suspect we will get the most value from a really good set of unit tests for libssl. I suspect this might be a big ask to start off with (you would probably have to mock out a lot of stuff).&lt;br /&gt;
&lt;br /&gt;
=== Build Systems/Machines ===&lt;br /&gt;
Where can we get the machines? Is someone willing to donate them? What system should we use?&lt;br /&gt;
&lt;br /&gt;
=== Get Unit Tests to Build on Windows ===&lt;br /&gt;
Steve Henson on building ssl/heartbeat_test.c on Windows: The first problem is that __func__ isn't understood. Changing that to __FUNCTION__ resolves that easily enough.&lt;br /&gt;
&lt;br /&gt;
The second problem is more serious. Windows (and a couple of other platforms IIRC) is strict about only exporting approved symbols from global headers in shared libraries and wont export internal only functions.&lt;br /&gt;
&lt;br /&gt;
That means you get linker errors:&lt;br /&gt;
&lt;br /&gt;
heartbeat_test.obj : error LNK2019: unresolved external symbol _ssl3_setup_buffe&lt;br /&gt;
rs referenced in function _set_up&lt;br /&gt;
heartbeat_test.obj : error LNK2019: unresolved external symbol _ssl_init_wbio_bu&lt;br /&gt;
ffer referenced in function _set_up&lt;br /&gt;
heartbeat_test.obj : error LNK2019: unresolved external symbol _tls1_process_hea&lt;br /&gt;
rtbeat referenced in function _set_up_tls&lt;br /&gt;
heartbeat_test.obj : error LNK2019: unresolved external symbol _dtls1_process_he&lt;br /&gt;
artbeat referenced in function _set_up_dtls&lt;br /&gt;
out32dll\heartbeat_test.exe : fatal error LNK1120: 4 unresolved externals&lt;br /&gt;
NMAKE : fatal error U1077: '&amp;quot;C:\Program Files (x86)\Microsoft Visual Studio 11.0&lt;br /&gt;
\VC\BIN\link.EXE&amp;quot;' : return code '0x460'&lt;br /&gt;
&lt;br /&gt;
Potential solutions:&lt;br /&gt;
* http://stackoverflow.com/questions/7759777/is-it-possible-to-test-internal-class-from-a-c-dll-using-mstest&lt;br /&gt;
* http://stackoverflow.com/questions/19934714/googletest-c-unit-testing-linking-error&lt;br /&gt;
* http://stackoverflow.com/questions/14010627/unresolved-externals-when-compiling-unit-tests-for-visual-c-2012&lt;br /&gt;
&lt;br /&gt;
ifdef'd out (for now): https://github.com/openssl/openssl/commit/7ce79a5bfdbcd53ae75f85e94eed665a05b5dea3&lt;br /&gt;
&lt;br /&gt;
=== How to Manage Private Symbols ===&lt;br /&gt;
Steve Henson: As this also affects other platforms a general solution might be in order.&lt;br /&gt;
&lt;br /&gt;
One option is to link to static libraries as has been mentioned. If you have a&lt;br /&gt;
lot of unit tests you could end up with a lot of large binaries. Would need some&lt;br /&gt;
changes to the dreaded Windows build system too.&lt;br /&gt;
&lt;br /&gt;
A different option would be to export the unit test functions through a&lt;br /&gt;
structure pointer which a function returns. So you'd have something like..&lt;br /&gt;
&lt;br /&gt;
unit_test = SSL_get_unit_test_funcs();&lt;br /&gt;
&lt;br /&gt;
unit_test.some_internal_funcction(...);&lt;br /&gt;
&lt;br /&gt;
Where the actual structure is opaque to applications (so they aren't tempted to&lt;br /&gt;
poke around in internals) but visible to the unit test code. Then the unit test&lt;br /&gt;
code doesn't call any internal functions not defined in there and doesn't need&lt;br /&gt;
to load private headers (unless it needs them for some definitions).&lt;br /&gt;
&lt;br /&gt;
Mike Bland: This is an interesting idea, though I'd expect the unit tests will&lt;br /&gt;
still need access to internal headers.&lt;br /&gt;
&lt;br /&gt;
But I have a question: Why do any of the symbols need to be private?&lt;br /&gt;
Is that degree of encapsulation necessary, and does it really&lt;br /&gt;
discourage irresponsible clients? The source code is open, so people&lt;br /&gt;
can always build their own copy and depend on internals if they really&lt;br /&gt;
want to, and the default UNIX/Linux/OS X build (i.e. ./configure &amp;amp;&amp;amp;&lt;br /&gt;
make &amp;amp;&amp;amp; make test) doesn't lock down internal symbols. Have&lt;br /&gt;
dependencies on internal APIs ever been a problem in practice?&lt;br /&gt;
&lt;br /&gt;
I'm not saying I feel strongly either way, but it seems that clients&lt;br /&gt;
should be clear that the public API is what's available in&lt;br /&gt;
openssl/include, and shouldn't depend on anything else. I just don't&lt;br /&gt;
understand what making symbols private buys anyone in the context of&lt;br /&gt;
OpenSSL, in light of how it appears to complicate the ability to unit&lt;br /&gt;
test.&lt;br /&gt;
&lt;br /&gt;
Not trying to be argumentative, I just want to understand the&lt;br /&gt;
rationale. I'll work with whatever environment I have to.&lt;br /&gt;
&lt;br /&gt;
Tom Francis: Making the symbols private allows the link editors on Windows and pretty much every UNIX system that doesn't use GNU ld to:&lt;br /&gt;
1) Run much, much faster at link time (not a minor consideration for most of the software I've worked on); and&lt;br /&gt;
2) optimize the final binary to load much faster.&lt;br /&gt;
Last time I checked, there was a minor improvement for GNU ld for #1, but it's trivial compared to Windows and HP's link editor, e.g. (I can't overstate the difference there).  The runtime improvement is also dramatic on Windows, HP-UX, and AIX (we're talking tens for milliseconds for libraries that are much smaller than OpenSSL -- never tried it with OpenSSL, too lazy to mark everything, after having just done so for the library I was really interested in).&lt;br /&gt;
&lt;br /&gt;
If you want to avoid a bunch of small binaries, you could combine all the unit tests into a single test application, and use multiple runs of it for each test, similar to how the openssl binary is created; if you link the object files directly (or a static library), you avoid the private symbols issue.  Of course, this may be an issue for some of the embedded systems, where the loading a large binary for running the tests might not be acceptable (but might be preferable to a bunch of binaries?).  Mike Bland was concerned about parallelization, and for any kind of automated tests on commits, that's a big point, if you can guarantee that each system only compiles/executes a limited number of tests (it could be useful for OS vendors, too).  For the average OpenSSL user, that's not really a consideration; an average user is more likely concerned with how long (wall clock) it takes to compile and run the tests, and depending on the size of a single binary v the size of each smaller binary, it'll vary from system to system (generally, it'll be many times faster to create a single large binary than a few hundred smaller binaries, but the larger the binary, the longer it takes to load -- at some point, the load time might well outweigh the hundreds of smaller binaries (assuming you execute the large binary several times, rather than have a method for it to execute all tests in a single go).  That point is probably &amp;gt; 100MB for larger systems, but for an embedded system, it could be much smaller.&lt;br /&gt;
&lt;br /&gt;
For Steve's second suggestion, I think my biggest concerns would be how to logically separate out a unit test method without including the test framework (maybe throw it all in there?).  I kinda like the idea of keeping the test inside the libraries, but I'm not sure why -- maybe 'cause I recently spent a few months back in a java world, where it's normal to throw all your unit tests into the same jar for production.  I'm not sure I like that, though.  The overhead of a single function per &amp;quot;module&amp;quot; added to the exports is also unlikely to drastically decrease link-time or run-time performance, too (compared with exporting everything).&lt;br /&gt;
&lt;br /&gt;
=== Improved Patch/Cherry-pick Process ===&lt;br /&gt;
Geoff Thorpe: (a) patches that are not applied/cherry-picked to all the branches they apply to, or (b) applied to more branches than they should be. A complication of (a) is that some patches may need to be reworked in order to apply (or in order to not break binary compatibility of a stable branch). The difficulty of (b) is determining when the nature of the change either breaks binary compatibility or causes some other behavioral deviation that is not in keeping with the &amp;quot;promises&amp;quot; of stable branches.&lt;br /&gt;
&lt;br /&gt;
http://ispras.linuxbase.org/index.php/ABI_compliance_checker&lt;br /&gt;
https://github.com/lvc/abi-compliance-checker/&lt;br /&gt;
&lt;br /&gt;
Geoff on 2014-05-30: ...we might move to a scheme whereby we only maintain one most-recent stable branch for production releases, with snapshots or whatever of the development head. Ie. two branches, one for maximum-compatibility/bug-fixes-only, and the other for more active development. The number of &amp;quot;stable&amp;quot; branches would thus be 1 rather than 'n'. The idea is that we may defer to downstream &amp;quot;slow-moving&amp;quot; users (eg. long-term releases of linux distros) the opportunity to step up and do the work of maintaining (cherry-picking, back-porting, ...) older branches. Ie. what they typically already do in-house, but the opportunity to do it under our roof and thus combine their efforts with any other similarly-interested parties. If there's noone prepared to do that, the logical conclusion is that there is probably no need for it (or so the argument goes).&lt;br /&gt;
&lt;br /&gt;
=== Improve/Standardize Algorithm Testing ===&lt;br /&gt;
Steve Henson: While the algorithms are partly tested I don't think they're anything like comprehensive enough. The way they are handled is also haphazard and spread across multiple tests covering all sorts of odd APIs, some of which are deprecated.&lt;br /&gt;
&lt;br /&gt;
In fact I'd say they're (with the odd exception) an example of how *not* to do things.&lt;br /&gt;
&lt;br /&gt;
Examples rc2test tests RC2 it has various test vectors hard coded inconsistent indentation and use of low level APIs. The rc4test is a similar story and uses a different format to rc2test. The same tale is repeated all over the place with ideatest, rmdtest etc etc.&lt;br /&gt;
&lt;br /&gt;
Then we come to the code which I think is closest to how things should be which is evp_test. It uses the standard high level EVP API the format is consistent (if undocumented) and adding new tests can be done simply by editing a text file.&lt;br /&gt;
&lt;br /&gt;
It currently however only works for some algorithms and the text file format could be better. It currently doesn't handle public key algorithms or test variants of the same algorithm (e.g. AES-NI versus non AES-NI) either.&lt;br /&gt;
&lt;br /&gt;
=== Develop SSL/TLS Stack and Other Tools ===&lt;br /&gt;
Steve Henson: The heartbeat bug is an example where you can perform some testing without a complete SSL/TLS stack. However looking through the code in heartbeat_test.c it uses a lot of functionality which would normally be strictly off-limits for an application.&lt;br /&gt;
&lt;br /&gt;
Some bugs are far more subtle and harder to test. For example some involve doing *almost* everything right and then slipping in some illegal parameter or badly formatted message. If you want to do that in a standalone bit of code you need a near complete SSL/TLS stack.&lt;br /&gt;
&lt;br /&gt;
I can think of a couple of ways to handle that. One is to have some kind of hooks in libssl so testing code can misbehave and send out illegal messages in controlled ways (I had a prototype &amp;quot;bad heartbeat&amp;quot; API which only added a couple of lines to libssl). An alternative would be to write some kind of tiny SSL/TLS code used only by the test programs and carefully tailored to permit such things.&lt;/div&gt;</summary>
		<author><name>Mbland</name></author>
	</entry>
	<entry>
		<id>https://wiki.openssl.org/index.php?title=Unit_Testing&amp;diff=1731</id>
		<title>Unit Testing</title>
		<link rel="alternate" type="text/html" href="https://wiki.openssl.org/index.php?title=Unit_Testing&amp;diff=1731"/>
		<updated>2014-06-10T16:23:51Z</updated>

		<summary type="html">&lt;p&gt;Mbland: Link to new Testing and Development Tools and Tips page&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page will track the effort to improve unit test and other automated test coverage for OpenSSL. Everyone is encouraged to help with this effort, but this page will track which community members have accepted specific responsibilities, and what tasks are currently underway.&lt;br /&gt;
&lt;br /&gt;
== Goals ==&lt;br /&gt;
&lt;br /&gt;
The goals of this project are:&lt;br /&gt;
&lt;br /&gt;
* Establish a written contribution/code review policy that requires:&lt;br /&gt;
** tests for every new code change, except for very trivial changes that do not directly impact program logic (e.g. documentation fixes, string constant updates, build script tweaks); this can be limited to an agreed-upon subset of the code to start, but would hopefully be expanded to cover most, if not all, of the code base&lt;br /&gt;
** tests for every bugfix &lt;br /&gt;
** smaller, well-tested changes building up to a complete feature (as opposed to large and/or untested changes that implement a large, complex feature all at once) &lt;br /&gt;
* Establish a schedule of Build Cops and Tutors to begin enforcing rollbacks/fixes and to help shepherd new contributors through the testing process.&lt;br /&gt;
* Set up a series of publicly-accessible continuous integration servers using whatever system the community prefers (e.g. Jenkins, Buildbot, etc.). These can be dedicated hardware or possibly Amazon Web Services-based. Establish a written policy that these remain green at all times, and that breakages be rolled-back or fixed within no more than 30 minutes.&lt;br /&gt;
&lt;br /&gt;
We can add more concrete goals to this list after we make progress on these. Getting people to own roles, setting up build infrastructure, and setting and enforcing policy are important first steps. Upon that foundation, we can begin to make serious progress towards improved test coverage, code quality, and defect prevention.&lt;br /&gt;
&lt;br /&gt;
== Discussion List ==&lt;br /&gt;
[https://groups.google.com/d/forum/openssl-testing openssl-testing] is the mailing list dedicated to the unit/automated testing effort, to avoid clogging openssl-dev. Membership is open to whoever wishes to join, even if only to lurk. Ideally all testing discussions will eventually move to openssl-dev once we have processes, tools, conventions, etc. in place.&lt;br /&gt;
&lt;br /&gt;
== Team ==&lt;br /&gt;
&lt;br /&gt;
We can define new roles as needed. The success of this effort will be inversely proportional to the number of roles with any one individual's name next to them. Each role can have more than one person filling it, but needs specific people to fill them. &lt;br /&gt;
&lt;br /&gt;
The point is not to tell people what to do and not do: it’s to establish clear responsibilities so everyone can run with them right away and begin applying their creative energy to solutions, rather than waste it figuring out what the hell is going on, what they should do to contribute, and who they need to coordinate with to get things done.&lt;br /&gt;
&lt;br /&gt;
=== Organizer===&lt;br /&gt;
&lt;br /&gt;
Contact: [mailto:mbland@acm.org Mike Bland]&lt;br /&gt;
&lt;br /&gt;
Ensures the overall effort is making progress by facilitating communication, removing obstacles, and making hands-on contributions when necessary.&lt;br /&gt;
&lt;br /&gt;
=== Tech Writer ===&lt;br /&gt;
&lt;br /&gt;
Contacts: [mailto:mbland@acm.org Mike Bland], Sandeep Mankar, Chelsea Komlo, Graham Brooks&lt;br /&gt;
&lt;br /&gt;
Maintains documentation of tools, techniques, outstanding issues, etc. May maintain a code review/testing style guide based on the community consensus. Also documents who currently fills each role, as well as who might've filled it in the past.&lt;br /&gt;
&lt;br /&gt;
=== Buildmaster ===&lt;br /&gt;
&lt;br /&gt;
Contacts:  [mailto:mbland@acm.org Mike Bland], Isaac Truett, Dileep Bapat, Graham Brooks&lt;br /&gt;
&lt;br /&gt;
Sets up and maintains automated builds and any infrastructure used to monitor them and report breakage.&lt;br /&gt;
&lt;br /&gt;
=== Toolsmith ===&lt;br /&gt;
&lt;br /&gt;
Contact: Tony Aiuto&lt;br /&gt;
&lt;br /&gt;
Maintains any tools and frameworks that are a part of the core build process; proposes, integrates, and/or retires existing tools.&lt;br /&gt;
&lt;br /&gt;
=== Tutor ===&lt;br /&gt;
&lt;br /&gt;
Contacts: [mailto:mbland@acm.org Mike Bland], Darshan Mody, Tom Francis, Brian N. Makin, Chelsea Komlo, Edward Knapp, Dileep Bapat, Graham Brooks&lt;br /&gt;
&lt;br /&gt;
Helps contributors, particularly new contributors, with the details of writing unit or other automated tests. May be assigned by the reviewer of a patch to help a contributor get a new change under test. Submission of the patch should require the approval of the tutor in most cases. (Should ideally be more than one person.)&lt;br /&gt;
&lt;br /&gt;
== Tasks ==&lt;br /&gt;
The current list is posted in the [http://goo.gl/5u9nbw OpenSSL Testing Tasks Google Spreadsheet].&lt;br /&gt;
&lt;br /&gt;
(Would be nice to enable the [http://www.mediawiki.org/wiki/Extension:Widget MediaWiki Widget extension] and the [http://www.mediawikiwidgets.org/Google_Spreadsheet Google Spreadsheet widget].)&lt;br /&gt;
&lt;br /&gt;
== Howtos and Style Guides ==&lt;br /&gt;
Documents that provide background on specific testing issues and idioms should be linked from here.&lt;br /&gt;
&lt;br /&gt;
* [[How To Write Unit Tests For OpenSSL]]&lt;br /&gt;
* [http://mike-bland.com/2014/06/05/pseudo-xunit-pattern.html The Pseudo-xUnit Pattern]&lt;br /&gt;
* [[Testing And Development Tools and Tips]]&lt;br /&gt;
&lt;br /&gt;
== Discussion Topics ==&lt;br /&gt;
These are discussions related to some of the current testing tasks.&lt;br /&gt;
&lt;br /&gt;
=== First Area of Focus ===&lt;br /&gt;
Matt Caswell: One criterion might be ease of testing. If you were going down that route you might choose some of the low level packages within libcrypto which are relatively self-contained. I'm not talking about the crypto algorithms themselves (there are at least *some* tests for those), I'm thinking more about bio, pem, x509, x509v3, etc.&lt;br /&gt;
&lt;br /&gt;
Another criterion might be where you get the most value. I suspect we will get the most value from a really good set of unit tests for libssl. I suspect this might be a big ask to start off with (you would probably have to mock out a lot of stuff).&lt;br /&gt;
&lt;br /&gt;
=== Build Systems/Machines ===&lt;br /&gt;
Where can we get the machines? Is someone willing to donate them? What system should we use?&lt;br /&gt;
&lt;br /&gt;
=== Get Unit Tests to Build on Windows ===&lt;br /&gt;
Steve Henson on building ssl/heartbeat_test.c on Windows: The first problem is that __func__ isn't understood. Changing that to __FUNCTION__ resolves that easily enough.&lt;br /&gt;
&lt;br /&gt;
The second problem is more serious. Windows (and a couple of other platforms IIRC) is strict about only exporting approved symbols from global headers in shared libraries and wont export internal only functions.&lt;br /&gt;
&lt;br /&gt;
That means you get linker errors:&lt;br /&gt;
&lt;br /&gt;
heartbeat_test.obj : error LNK2019: unresolved external symbol _ssl3_setup_buffe&lt;br /&gt;
rs referenced in function _set_up&lt;br /&gt;
heartbeat_test.obj : error LNK2019: unresolved external symbol _ssl_init_wbio_bu&lt;br /&gt;
ffer referenced in function _set_up&lt;br /&gt;
heartbeat_test.obj : error LNK2019: unresolved external symbol _tls1_process_hea&lt;br /&gt;
rtbeat referenced in function _set_up_tls&lt;br /&gt;
heartbeat_test.obj : error LNK2019: unresolved external symbol _dtls1_process_he&lt;br /&gt;
artbeat referenced in function _set_up_dtls&lt;br /&gt;
out32dll\heartbeat_test.exe : fatal error LNK1120: 4 unresolved externals&lt;br /&gt;
NMAKE : fatal error U1077: '&amp;quot;C:\Program Files (x86)\Microsoft Visual Studio 11.0&lt;br /&gt;
\VC\BIN\link.EXE&amp;quot;' : return code '0x460'&lt;br /&gt;
&lt;br /&gt;
Potential solutions:&lt;br /&gt;
* http://stackoverflow.com/questions/7759777/is-it-possible-to-test-internal-class-from-a-c-dll-using-mstest&lt;br /&gt;
* http://stackoverflow.com/questions/19934714/googletest-c-unit-testing-linking-error&lt;br /&gt;
* http://stackoverflow.com/questions/14010627/unresolved-externals-when-compiling-unit-tests-for-visual-c-2012&lt;br /&gt;
&lt;br /&gt;
ifdef'd out (for now): https://github.com/openssl/openssl/commit/7ce79a5bfdbcd53ae75f85e94eed665a05b5dea3&lt;br /&gt;
&lt;br /&gt;
=== How to Manage Private Symbols ===&lt;br /&gt;
Steve Henson: As this also affects other platforms a general solution might be in order.&lt;br /&gt;
&lt;br /&gt;
One option is to link to static libraries as has been mentioned. If you have a&lt;br /&gt;
lot of unit tests you could end up with a lot of large binaries. Would need some&lt;br /&gt;
changes to the dreaded Windows build system too.&lt;br /&gt;
&lt;br /&gt;
A different option would be to export the unit test functions through a&lt;br /&gt;
structure pointer which a function returns. So you'd have something like..&lt;br /&gt;
&lt;br /&gt;
unit_test = SSL_get_unit_test_funcs();&lt;br /&gt;
&lt;br /&gt;
unit_test.some_internal_funcction(...);&lt;br /&gt;
&lt;br /&gt;
Where the actual structure is opaque to applications (so they aren't tempted to&lt;br /&gt;
poke around in internals) but visible to the unit test code. Then the unit test&lt;br /&gt;
code doesn't call any internal functions not defined in there and doesn't need&lt;br /&gt;
to load private headers (unless it needs them for some definitions).&lt;br /&gt;
&lt;br /&gt;
Mike Bland: This is an interesting idea, though I'd expect the unit tests will&lt;br /&gt;
still need access to internal headers.&lt;br /&gt;
&lt;br /&gt;
But I have a question: Why do any of the symbols need to be private?&lt;br /&gt;
Is that degree of encapsulation necessary, and does it really&lt;br /&gt;
discourage irresponsible clients? The source code is open, so people&lt;br /&gt;
can always build their own copy and depend on internals if they really&lt;br /&gt;
want to, and the default UNIX/Linux/OS X build (i.e. ./configure &amp;amp;&amp;amp;&lt;br /&gt;
make &amp;amp;&amp;amp; make test) doesn't lock down internal symbols. Have&lt;br /&gt;
dependencies on internal APIs ever been a problem in practice?&lt;br /&gt;
&lt;br /&gt;
I'm not saying I feel strongly either way, but it seems that clients&lt;br /&gt;
should be clear that the public API is what's available in&lt;br /&gt;
openssl/include, and shouldn't depend on anything else. I just don't&lt;br /&gt;
understand what making symbols private buys anyone in the context of&lt;br /&gt;
OpenSSL, in light of how it appears to complicate the ability to unit&lt;br /&gt;
test.&lt;br /&gt;
&lt;br /&gt;
Not trying to be argumentative, I just want to understand the&lt;br /&gt;
rationale. I'll work with whatever environment I have to.&lt;br /&gt;
&lt;br /&gt;
Tom Francis: Making the symbols private allows the link editors on Windows and pretty much every UNIX system that doesn't use GNU ld to:&lt;br /&gt;
1) Run much, much faster at link time (not a minor consideration for most of the software I've worked on); and&lt;br /&gt;
2) optimize the final binary to load much faster.&lt;br /&gt;
Last time I checked, there was a minor improvement for GNU ld for #1, but it's trivial compared to Windows and HP's link editor, e.g. (I can't overstate the difference there).  The runtime improvement is also dramatic on Windows, HP-UX, and AIX (we're talking tens for milliseconds for libraries that are much smaller than OpenSSL -- never tried it with OpenSSL, too lazy to mark everything, after having just done so for the library I was really interested in).&lt;br /&gt;
&lt;br /&gt;
If you want to avoid a bunch of small binaries, you could combine all the unit tests into a single test application, and use multiple runs of it for each test, similar to how the openssl binary is created; if you link the object files directly (or a static library), you avoid the private symbols issue.  Of course, this may be an issue for some of the embedded systems, where the loading a large binary for running the tests might not be acceptable (but might be preferable to a bunch of binaries?).  Mike Bland was concerned about parallelization, and for any kind of automated tests on commits, that's a big point, if you can guarantee that each system only compiles/executes a limited number of tests (it could be useful for OS vendors, too).  For the average OpenSSL user, that's not really a consideration; an average user is more likely concerned with how long (wall clock) it takes to compile and run the tests, and depending on the size of a single binary v the size of each smaller binary, it'll vary from system to system (generally, it'll be many times faster to create a single large binary than a few hundred smaller binaries, but the larger the binary, the longer it takes to load -- at some point, the load time might well outweigh the hundreds of smaller binaries (assuming you execute the large binary several times, rather than have a method for it to execute all tests in a single go).  That point is probably &amp;gt; 100MB for larger systems, but for an embedded system, it could be much smaller.&lt;br /&gt;
&lt;br /&gt;
For Steve's second suggestion, I think my biggest concerns would be how to logically separate out a unit test method without including the test framework (maybe throw it all in there?).  I kinda like the idea of keeping the test inside the libraries, but I'm not sure why -- maybe 'cause I recently spent a few months back in a java world, where it's normal to throw all your unit tests into the same jar for production.  I'm not sure I like that, though.  The overhead of a single function per &amp;quot;module&amp;quot; added to the exports is also unlikely to drastically decrease link-time or run-time performance, too (compared with exporting everything).&lt;br /&gt;
&lt;br /&gt;
=== Improved Patch/Cherry-pick Process ===&lt;br /&gt;
Geoff Thorpe: (a) patches that are not applied/cherry-picked to all the branches they apply to, or (b) applied to more branches than they should be. A complication of (a) is that some patches may need to be reworked in order to apply (or in order to not break binary compatibility of a stable branch). The difficulty of (b) is determining when the nature of the change either breaks binary compatibility or causes some other behavioral deviation that is not in keeping with the &amp;quot;promises&amp;quot; of stable branches.&lt;br /&gt;
&lt;br /&gt;
http://ispras.linuxbase.org/index.php/ABI_compliance_checker&lt;br /&gt;
https://github.com/lvc/abi-compliance-checker/&lt;br /&gt;
&lt;br /&gt;
Geoff on 2014-05-30: ...we might move to a scheme whereby we only maintain one most-recent stable branch for production releases, with snapshots or whatever of the development head. Ie. two branches, one for maximum-compatibility/bug-fixes-only, and the other for more active development. The number of &amp;quot;stable&amp;quot; branches would thus be 1 rather than 'n'. The idea is that we may defer to downstream &amp;quot;slow-moving&amp;quot; users (eg. long-term releases of linux distros) the opportunity to step up and do the work of maintaining (cherry-picking, back-porting, ...) older branches. Ie. what they typically already do in-house, but the opportunity to do it under our roof and thus combine their efforts with any other similarly-interested parties. If there's noone prepared to do that, the logical conclusion is that there is probably no need for it (or so the argument goes).&lt;br /&gt;
&lt;br /&gt;
=== Improve/Standardize Algorithm Testing ===&lt;br /&gt;
Steve Henson: While the algorithms are partly tested I don't think they're anything like comprehensive enough. The way they are handled is also haphazard and spread across multiple tests covering all sorts of odd APIs, some of which are deprecated.&lt;br /&gt;
&lt;br /&gt;
In fact I'd say they're (with the odd exception) an example of how *not* to do things.&lt;br /&gt;
&lt;br /&gt;
Examples rc2test tests RC2 it has various test vectors hard coded inconsistent indentation and use of low level APIs. The rc4test is a similar story and uses a different format to rc2test. The same tale is repeated all over the place with ideatest, rmdtest etc etc.&lt;br /&gt;
&lt;br /&gt;
Then we come to the code which I think is closest to how things should be which is evp_test. It uses the standard high level EVP API the format is consistent (if undocumented) and adding new tests can be done simply by editing a text file.&lt;br /&gt;
&lt;br /&gt;
It currently however only works for some algorithms and the text file format could be better. It currently doesn't handle public key algorithms or test variants of the same algorithm (e.g. AES-NI versus non AES-NI) either.&lt;br /&gt;
&lt;br /&gt;
=== Develop SSL/TLS Stack and Other Tools ===&lt;br /&gt;
Steve Henson: The heartbeat bug is an example where you can perform some testing without a complete SSL/TLS stack. However looking through the code in heartbeat_test.c it uses a lot of functionality which would normally be strictly off-limits for an application.&lt;br /&gt;
&lt;br /&gt;
Some bugs are far more subtle and harder to test. For example some involve doing *almost* everything right and then slipping in some illegal parameter or badly formatted message. If you want to do that in a standalone bit of code you need a near complete SSL/TLS stack.&lt;br /&gt;
&lt;br /&gt;
I can think of a couple of ways to handle that. One is to have some kind of hooks in libssl so testing code can misbehave and send out illegal messages in controlled ways (I had a prototype &amp;quot;bad heartbeat&amp;quot; API which only added a couple of lines to libssl). An alternative would be to write some kind of tiny SSL/TLS code used only by the test programs and carefully tailored to permit such things.&lt;/div&gt;</summary>
		<author><name>Mbland</name></author>
	</entry>
	<entry>
		<id>https://wiki.openssl.org/index.php?title=How_To_Write_Unit_Tests_For_OpenSSL&amp;diff=1730</id>
		<title>How To Write Unit Tests For OpenSSL</title>
		<link rel="alternate" type="text/html" href="https://wiki.openssl.org/index.php?title=How_To_Write_Unit_Tests_For_OpenSSL&amp;diff=1730"/>
		<updated>2014-06-08T19:21:01Z</updated>

		<summary type="html">&lt;p&gt;Mbland: /* Building and Running the Test */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This is an outline of the basic process and principles to follow when writing unit tests. This document will evolve quite a bit as the community gains experience.&lt;br /&gt;
&lt;br /&gt;
==Mechanics ==&lt;br /&gt;
=== Forking the Repo ===&lt;br /&gt;
For now, people contributing new unit tests for uncovered code (as opposed to submitting tests with new code changes) should fork [https://github.com/mbland/openssl Mike Bland's GitHub repository] and issue [https://help.github.com/articles/using-pull-requests GitHub pull requests]. Remember to do all development on a topic branch (not &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt;). Tests committed to this repo will occasionally get merged into the master OpenSSL repo.&lt;br /&gt;
&lt;br /&gt;
Rationale per Matt Caswell: We should think about process here. If you are going off to recruit an army of people writing tests then I wonder if it is worth setting up a separate github repository whilst you are building up the tests. We can then merge in from that on a periodic basis. I wouldn't want availability of openssl team committers to be a bottle neck.&lt;br /&gt;
&lt;br /&gt;
=== Use the Test Template Generator ===&lt;br /&gt;
TODO(mbland): Get template generator checked-in. Maybe have a template generator for each library, e.g. &amp;lt;code&amp;gt;ssl/new-test.sh&amp;lt;/code&amp;gt; that has additional setup boilerplate specific to the &amp;lt;code&amp;gt;ssl&amp;lt;/code&amp;gt; library.&lt;br /&gt;
&lt;br /&gt;
Use the &amp;lt;code&amp;gt;test/new-test.sh&amp;lt;/code&amp;gt; script to generate a skeleton test file. ([https://github.com/mbland/openssl/compare/test-util pending in the test-util branch])&lt;br /&gt;
&lt;br /&gt;
=== Add Makefile Targets ===&lt;br /&gt;
The following instructions use the &amp;lt;code&amp;gt;Makefile&amp;lt;/code&amp;gt; targets for &amp;lt;code&amp;gt;ssl/heartbeat_test.c&amp;lt;/code&amp;gt; as an example.&lt;br /&gt;
&lt;br /&gt;
In the &amp;lt;code&amp;gt;Makefile&amp;lt;/code&amp;gt; for the library containing the test, add the test source file to the &amp;lt;code&amp;gt;TEST&amp;lt;/code&amp;gt; variable:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# ssl/Makefile&lt;br /&gt;
TEST=ssltest.c heartbeat_test.c&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In &amp;lt;code&amp;gt;test/Makefile&amp;lt;/code&amp;gt;:&lt;br /&gt;
* add a variable for the test target near the top of the file, right after the existing test variables&lt;br /&gt;
* use the variable to add an executable target to the &amp;lt;code&amp;gt;EXE&amp;lt;/code&amp;gt; variable&lt;br /&gt;
* use the variable to add an object file target to the &amp;lt;code&amp;gt;OBJ&amp;lt;/code&amp;gt; variable&lt;br /&gt;
* use the variable to add a source file target to the &amp;lt;code&amp;gt;SRC&amp;lt;/code&amp;gt; variable&lt;br /&gt;
* add the test target to the &amp;lt;code&amp;gt;alltests&amp;lt;/code&amp;gt; target&lt;br /&gt;
* add the target to execute the test&lt;br /&gt;
* add the target to build the test executable&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# test/Makefile&lt;br /&gt;
HEARTBEATTEST=  heartbeat_test&lt;br /&gt;
EXE=  ... $(HEARTBEATTEST)$(EXE_EXT)&lt;br /&gt;
OBJ= ... $(HEARTBEATTEST).o&lt;br /&gt;
SRC= ... $(HEARTBEATTEST).c&lt;br /&gt;
alltests: \&lt;br /&gt;
        ... test_heartbeat&lt;br /&gt;
&lt;br /&gt;
test_heartbeat: $(HEARTBEATTEST)$(EXE_EXT)&lt;br /&gt;
  ../util/shlib_wrap.sh ./$(HEARTBEATTEST)&lt;br /&gt;
&lt;br /&gt;
$(HEARTBEATTEST)$(EXE_EXT): $(HEARTBEATTEST).o $(DLIBCRYPTO)&lt;br /&gt;
  @target=$(HEARTBEATTEST); $(BUILD_CMD)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Run &amp;lt;code&amp;gt;make depend&amp;lt;/code&amp;gt; ===&lt;br /&gt;
Finally, run &amp;lt;code&amp;gt;make depend&amp;lt;/code&amp;gt; to automatically generate the header file dependencies.&lt;br /&gt;
&lt;br /&gt;
=== Building and Running the Test ===&lt;br /&gt;
If you're initially developing on Mac OS X or (for now) FreeBSD 10, just use the stock method of building and testing:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ config &amp;amp;&amp;amp; make &amp;amp;&amp;amp; make test&lt;br /&gt;
&lt;br /&gt;
# To execute just one specific test&lt;br /&gt;
$ make TESTS=test_heartbeat test &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Ultimately the test will have to compile and pass with developer flags enabled:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ ./GitConfigure debug-ben-debug-64-clang&lt;br /&gt;
$ ./GitMake -j 2&lt;br /&gt;
$ ./GitMake test_heartbeat&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above currently doesn't work on Mac OS X or FreeBSD 10; for now, you can install the 9.1 release of [http://www.freebsd.org/ FreeBSD], which uses Clang 3.1, via a virtualization platform such as [https://www.virtualbox.org/ VirtualBox]. (Mac OS X breaks, in part, due to the fact that it doesn't use the GNU assembler; &amp;lt;code&amp;gt;-fsanitize&amp;lt;/code&amp;gt; appears to be ignored on FreeBSD 9.1/Clang 3.1, but later versions break because the Clang compiler will emit &amp;lt;code&amp;gt;-fsanitize&amp;lt;/code&amp;gt; symbols but the &amp;lt;code&amp;gt;libasan&amp;lt;/code&amp;gt; library [http://lists.freebsd.org/pipermail/freebsd-hackers/2013-December/043995.html has yet to be ported to FreeBSD].)&lt;br /&gt;
&lt;br /&gt;
== Style ==&lt;br /&gt;
[http://mike-bland.com/2014/06/05/pseudo-xunit-pattern.html The Pseudo-xUnit Pattern] is that established by [http://git.openssl.org/gitweb/?p=openssl.git;a=blob;f=ssl/heartbeat_test.c ssl/heartbeat_test.c]. This pattern organizes code in a fashion reminiscent of the [http://en.wikipedia.org/wiki/XUnit xUnit] family of unit testing frameworks, without actually using a testing framework. This should lower the barrier to entry for people wanting to write unit tests, but enable a relatively easy migration to an xUnit-based framework if we decide to do so one day.&lt;br /&gt;
&lt;br /&gt;
Some of the basic principles to follow are:&lt;br /&gt;
&lt;br /&gt;
=== Define a fixture structure ===&lt;br /&gt;
The fixture structure should contain all of the inputs to the code under test and all of the expected result values. It should also contain a &amp;lt;code&amp;gt;const char*&amp;lt;/code&amp;gt; for the name of the test case function that created it, to aid in error message formatting. Even though the fixture may contain dynamically-allocated members, the fixture itself should be copied by value to reduce the necessary degree of memory management in a small unit test program.&lt;br /&gt;
&lt;br /&gt;
=== Define set_up() and tear_down() functions for the fixture ===&lt;br /&gt;
&amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; should return a newly-initialized test fixture structure. It should take the name of the test case as an argument (i.e. &amp;lt;code&amp;gt;__func__&amp;lt;/code&amp;gt;) and assign it to the fixture. All of the fixture members should be initialized, which each test case function can then override as needed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;tear_down()&amp;lt;/code&amp;gt; should take the fixture as an argument and release any resources allocated by &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt;. It can also call any library-wide error printing routines (e.g. &amp;lt;code&amp;gt;ERR_print_errors_fp(stderr)&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
=== Use &amp;lt;code&amp;gt;SETUP_TEST_FIXTURE()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;EXECUTE_TEST()&amp;lt;/code&amp;gt; from &amp;lt;code&amp;gt;test/testutil.h&amp;lt;/code&amp;gt; ===&lt;br /&gt;
Each test case function should call &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; as its first statement, and should call &amp;lt;code&amp;gt;tear_down()&amp;lt;/code&amp;gt; just before returning. This is handled in a uniform fashion when using the &amp;lt;code&amp;gt;SETUP_TEST_FIXTURE()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;EXECUTE_TEST()&amp;lt;/code&amp;gt; helper macros from &amp;lt;code&amp;gt;test/testutil.h&amp;lt;/code&amp;gt; ([https://github.com/openssl/openssl/pull/126 pending pull request]). See the comments in &amp;lt;code&amp;gt;test/testutil.h&amp;lt;/code&amp;gt; for usage, and &amp;lt;code&amp;gt;ssl/heartbeat_test.c&amp;lt;/code&amp;gt; for an example of how to wrap the macros for a specific unit test.&lt;br /&gt;
&lt;br /&gt;
=== Use test case functions, not a table of fixtures ===&lt;br /&gt;
Individual test case functions that call a common execution function are much more readable and maintainable than a loop over a table of fixture structures. Explicit fixture variable assignments aid comprehension when reading a specific test case, which saves time and energy when trying to understand a test or diagnose a failure. When a new member is added to an existing fixture, &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; can set a default for all test cases, and only the test cases that rely on that new member need to be updated.&lt;br /&gt;
&lt;br /&gt;
=== Use very descriptive test case names ===&lt;br /&gt;
Give tests long, descriptive names that provide ample context for the details of the test case. Good test names are also help produce good error messages.&lt;br /&gt;
&lt;br /&gt;
=== Group test cases into &amp;quot;suites&amp;quot; by naming convention ===&lt;br /&gt;
Give logically-related tests the same prefix, e.g. &amp;lt;code&amp;gt;test_dtls1_&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;test_tls1&amp;lt;/code&amp;gt; from &amp;lt;code&amp;gt;ssl/heartbeat_test.c&amp;lt;/code&amp;gt;. If need be, you can define suite-specific &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; functions that call the common &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; and elaborate on it. (This generally shouldn't be necessary for &amp;lt;code&amp;gt;tear_down()&amp;lt;/code&amp;gt;.)&lt;br /&gt;
&lt;br /&gt;
=== Keep individual test case functions focused on one thing ===&lt;br /&gt;
If the test name contains the word &amp;quot;and&amp;quot;, consider breaking it into two or more separate test case functions.&lt;br /&gt;
&lt;br /&gt;
=== Write very descriptive error messages ===&lt;br /&gt;
Include the test case function name in each error message, and explain in detail the context for the assertion that failed. Include the expected result (contained in the fixture structure) and the actual result returned from the code under test. Write helper methods for complex values as needed (e.g. &amp;lt;code&amp;gt;print_payload()&amp;lt;/code&amp;gt; in &amp;lt;code&amp;gt;ssl/heartbeat_test.c&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
=== Return zero on success and one on failure ===&lt;br /&gt;
The return value will be used to tally the number of test cases that failed. Even if multiple assertions fail for a single test case, the result should be exactly one.&lt;br /&gt;
&lt;br /&gt;
=== Add each test case function to the test runner function ===&lt;br /&gt;
Whatever function is used to execute the batch of test case functions, be that &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt; or a separate function called by &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt;, don't forget to add your test case functions to that function.&lt;br /&gt;
&lt;br /&gt;
TODO(mbland): create some kind of automated script or editor macros?&lt;br /&gt;
&lt;br /&gt;
=== Report the number of test cases that failed ===&lt;br /&gt;
Add up the total number of failed test cases in &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt; and report that number as the last error message of the test. &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt; should return &amp;lt;code&amp;gt;EXIT_FAILURE&amp;lt;/code&amp;gt; if any test cases failed, &amp;lt;code&amp;gt;EXIT_SUCCESS&amp;lt;/code&amp;gt; otherwise.&lt;br /&gt;
&lt;br /&gt;
=== Disable for Windows (for now) ===&lt;br /&gt;
Until we solve the private-symbol problem on Windows, we will need to wrap our unit test code in the following &amp;lt;code&amp;gt;#ifdef&amp;lt;/code&amp;gt; block:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#if !defined(OPENSSL_SYS_WINDOWS)&lt;br /&gt;
&lt;br /&gt;
/* All the test code, including main() */&lt;br /&gt;
&lt;br /&gt;
int main(int argc, char *argv[])                                                &lt;br /&gt;
    {&lt;br /&gt;
        return EXIT_SUCCESS;                                                    &lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
#endif /* OPENSSL_NO_WINDOWS  */&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Samples ==&lt;br /&gt;
Existing tests that can be used as models for new tests.&lt;br /&gt;
* [http://git.openssl.org/gitweb/?p=openssl.git;a=blob;f=ssl/heartbeat_test.c ssl/heartbeat_test.c]: Follows [http://mike-bland.com/2014/06/05/pseudo-xunit-pattern.html the Pseudo-xUnit pattern]&lt;/div&gt;</summary>
		<author><name>Mbland</name></author>
	</entry>
	<entry>
		<id>https://wiki.openssl.org/index.php?title=How_To_Write_Unit_Tests_For_OpenSSL&amp;diff=1727</id>
		<title>How To Write Unit Tests For OpenSSL</title>
		<link rel="alternate" type="text/html" href="https://wiki.openssl.org/index.php?title=How_To_Write_Unit_Tests_For_OpenSSL&amp;diff=1727"/>
		<updated>2014-06-07T18:49:57Z</updated>

		<summary type="html">&lt;p&gt;Mbland: /* Use the Test Template Generator */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This is an outline of the basic process and principles to follow when writing unit tests. This document will evolve quite a bit as the community gains experience.&lt;br /&gt;
&lt;br /&gt;
==Mechanics ==&lt;br /&gt;
=== Forking the Repo ===&lt;br /&gt;
For now, people contributing new unit tests for uncovered code (as opposed to submitting tests with new code changes) should fork [https://github.com/mbland/openssl Mike Bland's GitHub repository] and issue [https://help.github.com/articles/using-pull-requests GitHub pull requests]. Remember to do all development on a topic branch (not &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt;). Tests committed to this repo will occasionally get merged into the master OpenSSL repo.&lt;br /&gt;
&lt;br /&gt;
Rationale per Matt Caswell: We should think about process here. If you are going off to recruit an army of people writing tests then I wonder if it is worth setting up a separate github repository whilst you are building up the tests. We can then merge in from that on a periodic basis. I wouldn't want availability of openssl team committers to be a bottle neck.&lt;br /&gt;
&lt;br /&gt;
=== Use the Test Template Generator ===&lt;br /&gt;
TODO(mbland): Get template generator checked-in. Maybe have a template generator for each library, e.g. &amp;lt;code&amp;gt;ssl/new-test.sh&amp;lt;/code&amp;gt; that has additional setup boilerplate specific to the &amp;lt;code&amp;gt;ssl&amp;lt;/code&amp;gt; library.&lt;br /&gt;
&lt;br /&gt;
Use the &amp;lt;code&amp;gt;test/new-test.sh&amp;lt;/code&amp;gt; script to generate a skeleton test file. ([https://github.com/mbland/openssl/compare/test-util pending in the test-util branch])&lt;br /&gt;
&lt;br /&gt;
=== Add Makefile Targets ===&lt;br /&gt;
The following instructions use the &amp;lt;code&amp;gt;Makefile&amp;lt;/code&amp;gt; targets for &amp;lt;code&amp;gt;ssl/heartbeat_test.c&amp;lt;/code&amp;gt; as an example.&lt;br /&gt;
&lt;br /&gt;
In the &amp;lt;code&amp;gt;Makefile&amp;lt;/code&amp;gt; for the library containing the test, add the test source file to the &amp;lt;code&amp;gt;TEST&amp;lt;/code&amp;gt; variable:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# ssl/Makefile&lt;br /&gt;
TEST=ssltest.c heartbeat_test.c&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In &amp;lt;code&amp;gt;test/Makefile&amp;lt;/code&amp;gt;:&lt;br /&gt;
* add a variable for the test target near the top of the file, right after the existing test variables&lt;br /&gt;
* use the variable to add an executable target to the &amp;lt;code&amp;gt;EXE&amp;lt;/code&amp;gt; variable&lt;br /&gt;
* use the variable to add an object file target to the &amp;lt;code&amp;gt;OBJ&amp;lt;/code&amp;gt; variable&lt;br /&gt;
* use the variable to add a source file target to the &amp;lt;code&amp;gt;SRC&amp;lt;/code&amp;gt; variable&lt;br /&gt;
* add the test target to the &amp;lt;code&amp;gt;alltests&amp;lt;/code&amp;gt; target&lt;br /&gt;
* add the target to execute the test&lt;br /&gt;
* add the target to build the test executable&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# test/Makefile&lt;br /&gt;
HEARTBEATTEST=  heartbeat_test&lt;br /&gt;
EXE=  ... $(HEARTBEATTEST)$(EXE_EXT)&lt;br /&gt;
OBJ= ... $(HEARTBEATTEST).o&lt;br /&gt;
SRC= ... $(HEARTBEATTEST).c&lt;br /&gt;
alltests: \&lt;br /&gt;
        ... test_heartbeat&lt;br /&gt;
&lt;br /&gt;
test_heartbeat: $(HEARTBEATTEST)$(EXE_EXT)&lt;br /&gt;
  ../util/shlib_wrap.sh ./$(HEARTBEATTEST)&lt;br /&gt;
&lt;br /&gt;
$(HEARTBEATTEST)$(EXE_EXT): $(HEARTBEATTEST).o $(DLIBCRYPTO)&lt;br /&gt;
  @target=$(HEARTBEATTEST); $(BUILD_CMD)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Run &amp;lt;code&amp;gt;make depend&amp;lt;/code&amp;gt; ===&lt;br /&gt;
Finally, run &amp;lt;code&amp;gt;make depend&amp;lt;/code&amp;gt; to automatically generate the header file dependencies.&lt;br /&gt;
&lt;br /&gt;
=== Building and Running the Test ===&lt;br /&gt;
If you're initially developing on Mac OS X or (for now) FreeBSD 10, just use the stock method of building and testing:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ config &amp;amp;&amp;amp; make &amp;amp;&amp;amp; make test&lt;br /&gt;
&lt;br /&gt;
# To execute just one specific test&lt;br /&gt;
$ TESTS=test_heartbeat make test &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Ultimately the test will have to compile and pass with developer flags enabled:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ ./GitConfigure debug-ben-debug-64-clang&lt;br /&gt;
$ ./GitMake -j 2&lt;br /&gt;
$ ./GitMake test_heartbeat&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above currently doesn't work on Mac OS X or FreeBSD 10; for now, you can install the latest 9.x release of [http://www.freebsd.org/ FreeBSD] via a virtualization platform such as [https://www.virtualbox.org/ VirtualBox].&lt;br /&gt;
&lt;br /&gt;
== Style ==&lt;br /&gt;
[http://mike-bland.com/2014/06/05/pseudo-xunit-pattern.html The Pseudo-xUnit Pattern] is that established by [http://git.openssl.org/gitweb/?p=openssl.git;a=blob;f=ssl/heartbeat_test.c ssl/heartbeat_test.c]. This pattern organizes code in a fashion reminiscent of the [http://en.wikipedia.org/wiki/XUnit xUnit] family of unit testing frameworks, without actually using a testing framework. This should lower the barrier to entry for people wanting to write unit tests, but enable a relatively easy migration to an xUnit-based framework if we decide to do so one day.&lt;br /&gt;
&lt;br /&gt;
Some of the basic principles to follow are:&lt;br /&gt;
&lt;br /&gt;
=== Define a fixture structure ===&lt;br /&gt;
The fixture structure should contain all of the inputs to the code under test and all of the expected result values. It should also contain a &amp;lt;code&amp;gt;const char*&amp;lt;/code&amp;gt; for the name of the test case function that created it, to aid in error message formatting. Even though the fixture may contain dynamically-allocated members, the fixture itself should be copied by value to reduce the necessary degree of memory management in a small unit test program.&lt;br /&gt;
&lt;br /&gt;
=== Define set_up() and tear_down() functions for the fixture ===&lt;br /&gt;
&amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; should return a newly-initialized test fixture structure. It should take the name of the test case as an argument (i.e. &amp;lt;code&amp;gt;__func__&amp;lt;/code&amp;gt;) and assign it to the fixture. All of the fixture members should be initialized, which each test case function can then override as needed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;tear_down()&amp;lt;/code&amp;gt; should take the fixture as an argument and release any resources allocated by &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt;. It can also call any library-wide error printing routines (e.g. &amp;lt;code&amp;gt;ERR_print_errors_fp(stderr)&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
=== Use &amp;lt;code&amp;gt;SETUP_TEST_FIXTURE()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;EXECUTE_TEST()&amp;lt;/code&amp;gt; from &amp;lt;code&amp;gt;test/testutil.h&amp;lt;/code&amp;gt; ===&lt;br /&gt;
Each test case function should call &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; as its first statement, and should call &amp;lt;code&amp;gt;tear_down()&amp;lt;/code&amp;gt; just before returning. This is handled in a uniform fashion when using the &amp;lt;code&amp;gt;SETUP_TEST_FIXTURE()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;EXECUTE_TEST()&amp;lt;/code&amp;gt; helper macros from &amp;lt;code&amp;gt;test/testutil.h&amp;lt;/code&amp;gt; ([https://github.com/openssl/openssl/pull/126 pending pull request]). See the comments in &amp;lt;code&amp;gt;test/testutil.h&amp;lt;/code&amp;gt; for usage, and &amp;lt;code&amp;gt;ssl/heartbeat_test.c&amp;lt;/code&amp;gt; for an example of how to wrap the macros for a specific unit test.&lt;br /&gt;
&lt;br /&gt;
=== Use test case functions, not a table of fixtures ===&lt;br /&gt;
Individual test case functions that call a common execution function are much more readable and maintainable than a loop over a table of fixture structures. Explicit fixture variable assignments aid comprehension when reading a specific test case, which saves time and energy when trying to understand a test or diagnose a failure. When a new member is added to an existing fixture, &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; can set a default for all test cases, and only the test cases that rely on that new member need to be updated.&lt;br /&gt;
&lt;br /&gt;
=== Use very descriptive test case names ===&lt;br /&gt;
Give tests long, descriptive names that provide ample context for the details of the test case. Good test names are also help produce good error messages.&lt;br /&gt;
&lt;br /&gt;
=== Group test cases into &amp;quot;suites&amp;quot; by naming convention ===&lt;br /&gt;
Give logically-related tests the same prefix, e.g. &amp;lt;code&amp;gt;test_dtls1_&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;test_tls1&amp;lt;/code&amp;gt; from &amp;lt;code&amp;gt;ssl/heartbeat_test.c&amp;lt;/code&amp;gt;. If need be, you can define suite-specific &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; functions that call the common &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; and elaborate on it. (This generally shouldn't be necessary for &amp;lt;code&amp;gt;tear_down()&amp;lt;/code&amp;gt;.)&lt;br /&gt;
&lt;br /&gt;
=== Keep individual test case functions focused on one thing ===&lt;br /&gt;
If the test name contains the word &amp;quot;and&amp;quot;, consider breaking it into two or more separate test case functions.&lt;br /&gt;
&lt;br /&gt;
=== Write very descriptive error messages ===&lt;br /&gt;
Include the test case function name in each error message, and explain in detail the context for the assertion that failed. Include the expected result (contained in the fixture structure) and the actual result returned from the code under test. Write helper methods for complex values as needed (e.g. &amp;lt;code&amp;gt;print_payload()&amp;lt;/code&amp;gt; in &amp;lt;code&amp;gt;ssl/heartbeat_test.c&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
=== Return zero on success and one on failure ===&lt;br /&gt;
The return value will be used to tally the number of test cases that failed. Even if multiple assertions fail for a single test case, the result should be exactly one.&lt;br /&gt;
&lt;br /&gt;
=== Add each test case function to the test runner function ===&lt;br /&gt;
Whatever function is used to execute the batch of test case functions, be that &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt; or a separate function called by &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt;, don't forget to add your test case functions to that function.&lt;br /&gt;
&lt;br /&gt;
TODO(mbland): create some kind of automated script or editor macros?&lt;br /&gt;
&lt;br /&gt;
=== Report the number of test cases that failed ===&lt;br /&gt;
Add up the total number of failed test cases in &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt; and report that number as the last error message of the test. &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt; should return &amp;lt;code&amp;gt;EXIT_FAILURE&amp;lt;/code&amp;gt; if any test cases failed, &amp;lt;code&amp;gt;EXIT_SUCCESS&amp;lt;/code&amp;gt; otherwise.&lt;br /&gt;
&lt;br /&gt;
=== Disable for Windows (for now) ===&lt;br /&gt;
Until we solve the private-symbol problem on Windows, we will need to wrap our unit test code in the following &amp;lt;code&amp;gt;#ifdef&amp;lt;/code&amp;gt; block:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#if !defined(OPENSSL_SYS_WINDOWS)&lt;br /&gt;
&lt;br /&gt;
/* All the test code, including main() */&lt;br /&gt;
&lt;br /&gt;
int main(int argc, char *argv[])                                                &lt;br /&gt;
    {&lt;br /&gt;
        return EXIT_SUCCESS;                                                    &lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
#endif /* OPENSSL_NO_WINDOWS  */&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Samples ==&lt;br /&gt;
Existing tests that can be used as models for new tests.&lt;br /&gt;
* [http://git.openssl.org/gitweb/?p=openssl.git;a=blob;f=ssl/heartbeat_test.c ssl/heartbeat_test.c]: Follows [http://mike-bland.com/2014/06/05/pseudo-xunit-pattern.html the Pseudo-xUnit pattern]&lt;/div&gt;</summary>
		<author><name>Mbland</name></author>
	</entry>
	<entry>
		<id>https://wiki.openssl.org/index.php?title=How_To_Write_Unit_Tests_For_OpenSSL&amp;diff=1725</id>
		<title>How To Write Unit Tests For OpenSSL</title>
		<link rel="alternate" type="text/html" href="https://wiki.openssl.org/index.php?title=How_To_Write_Unit_Tests_For_OpenSSL&amp;diff=1725"/>
		<updated>2014-06-07T17:45:48Z</updated>

		<summary type="html">&lt;p&gt;Mbland: /* Style */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This is an outline of the basic process and principles to follow when writing unit tests. This document will evolve quite a bit as the community gains experience.&lt;br /&gt;
&lt;br /&gt;
==Mechanics ==&lt;br /&gt;
=== Forking the Repo ===&lt;br /&gt;
For now, people contributing new unit tests for uncovered code (as opposed to submitting tests with new code changes) should fork [https://github.com/mbland/openssl Mike Bland's GitHub repository] and issue [https://help.github.com/articles/using-pull-requests GitHub pull requests]. Remember to do all development on a topic branch (not &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt;). Tests committed to this repo will occasionally get merged into the master OpenSSL repo.&lt;br /&gt;
&lt;br /&gt;
Rationale per Matt Caswell: We should think about process here. If you are going off to recruit an army of people writing tests then I wonder if it is worth setting up a separate github repository whilst you are building up the tests. We can then merge in from that on a periodic basis. I wouldn't want availability of openssl team committers to be a bottle neck.&lt;br /&gt;
&lt;br /&gt;
=== Use the Test Template Generator ===&lt;br /&gt;
TODO(mbland): Get template generator checked-in. Maybe have a template generator for each library, e.g. &amp;lt;code&amp;gt;ssl/new-test.sh&amp;lt;/code&amp;gt; that has additional setup boilerplate specific to the &amp;lt;code&amp;gt;ssl&amp;lt;/code&amp;gt; library.&lt;br /&gt;
&lt;br /&gt;
Use the &amp;lt;code&amp;gt;test/new-test.sh&amp;lt;/code&amp;gt; script to generate a skeleton test file. ([https://github.com/mbland/openssl/commit/6929798053fd0b16004035bf4df838f55f6aeb92 pending commit]) &lt;br /&gt;
&lt;br /&gt;
=== Add Makefile Targets ===&lt;br /&gt;
The following instructions use the &amp;lt;code&amp;gt;Makefile&amp;lt;/code&amp;gt; targets for &amp;lt;code&amp;gt;ssl/heartbeat_test.c&amp;lt;/code&amp;gt; as an example.&lt;br /&gt;
&lt;br /&gt;
In the &amp;lt;code&amp;gt;Makefile&amp;lt;/code&amp;gt; for the library containing the test, add the test source file to the &amp;lt;code&amp;gt;TEST&amp;lt;/code&amp;gt; variable:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# ssl/Makefile&lt;br /&gt;
TEST=ssltest.c heartbeat_test.c&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In &amp;lt;code&amp;gt;test/Makefile&amp;lt;/code&amp;gt;:&lt;br /&gt;
* add a variable for the test target near the top of the file, right after the existing test variables&lt;br /&gt;
* use the variable to add an executable target to the &amp;lt;code&amp;gt;EXE&amp;lt;/code&amp;gt; variable&lt;br /&gt;
* use the variable to add an object file target to the &amp;lt;code&amp;gt;OBJ&amp;lt;/code&amp;gt; variable&lt;br /&gt;
* use the variable to add a source file target to the &amp;lt;code&amp;gt;SRC&amp;lt;/code&amp;gt; variable&lt;br /&gt;
* add the test target to the &amp;lt;code&amp;gt;alltests&amp;lt;/code&amp;gt; target&lt;br /&gt;
* add the target to execute the test&lt;br /&gt;
* add the target to build the test executable&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# test/Makefile&lt;br /&gt;
HEARTBEATTEST=  heartbeat_test&lt;br /&gt;
EXE=  ... $(HEARTBEATTEST)$(EXE_EXT)&lt;br /&gt;
OBJ= ... $(HEARTBEATTEST).o&lt;br /&gt;
SRC= ... $(HEARTBEATTEST).c&lt;br /&gt;
alltests: \&lt;br /&gt;
        ... test_heartbeat&lt;br /&gt;
&lt;br /&gt;
test_heartbeat: $(HEARTBEATTEST)$(EXE_EXT)&lt;br /&gt;
  ../util/shlib_wrap.sh ./$(HEARTBEATTEST)&lt;br /&gt;
&lt;br /&gt;
$(HEARTBEATTEST)$(EXE_EXT): $(HEARTBEATTEST).o $(DLIBCRYPTO)&lt;br /&gt;
  @target=$(HEARTBEATTEST); $(BUILD_CMD)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Run &amp;lt;code&amp;gt;make depend&amp;lt;/code&amp;gt; ===&lt;br /&gt;
Finally, run &amp;lt;code&amp;gt;make depend&amp;lt;/code&amp;gt; to automatically generate the header file dependencies.&lt;br /&gt;
&lt;br /&gt;
=== Building and Running the Test ===&lt;br /&gt;
If you're initially developing on Mac OS X or (for now) FreeBSD 10, just use the stock method of building and testing:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ config &amp;amp;&amp;amp; make &amp;amp;&amp;amp; make test&lt;br /&gt;
&lt;br /&gt;
# To execute just one specific test&lt;br /&gt;
$ TESTS=test_heartbeat make test &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Ultimately the test will have to compile and pass with developer flags enabled:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ ./GitConfigure debug-ben-debug-64-clang&lt;br /&gt;
$ ./GitMake -j 2&lt;br /&gt;
$ ./GitMake test_heartbeat&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above currently doesn't work on Mac OS X or FreeBSD 10; for now, you can install the latest 9.x release of [http://www.freebsd.org/ FreeBSD] via a virtualization platform such as [https://www.virtualbox.org/ VirtualBox].&lt;br /&gt;
&lt;br /&gt;
== Style ==&lt;br /&gt;
[http://mike-bland.com/2014/06/05/pseudo-xunit-pattern.html The Pseudo-xUnit Pattern] is that established by [http://git.openssl.org/gitweb/?p=openssl.git;a=blob;f=ssl/heartbeat_test.c ssl/heartbeat_test.c]. This pattern organizes code in a fashion reminiscent of the [http://en.wikipedia.org/wiki/XUnit xUnit] family of unit testing frameworks, without actually using a testing framework. This should lower the barrier to entry for people wanting to write unit tests, but enable a relatively easy migration to an xUnit-based framework if we decide to do so one day.&lt;br /&gt;
&lt;br /&gt;
Some of the basic principles to follow are:&lt;br /&gt;
&lt;br /&gt;
=== Define a fixture structure ===&lt;br /&gt;
The fixture structure should contain all of the inputs to the code under test and all of the expected result values. It should also contain a &amp;lt;code&amp;gt;const char*&amp;lt;/code&amp;gt; for the name of the test case function that created it, to aid in error message formatting. Even though the fixture may contain dynamically-allocated members, the fixture itself should be copied by value to reduce the necessary degree of memory management in a small unit test program.&lt;br /&gt;
&lt;br /&gt;
=== Define set_up() and tear_down() functions for the fixture ===&lt;br /&gt;
&amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; should return a newly-initialized test fixture structure. It should take the name of the test case as an argument (i.e. &amp;lt;code&amp;gt;__func__&amp;lt;/code&amp;gt;) and assign it to the fixture. All of the fixture members should be initialized, which each test case function can then override as needed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;tear_down()&amp;lt;/code&amp;gt; should take the fixture as an argument and release any resources allocated by &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt;. It can also call any library-wide error printing routines (e.g. &amp;lt;code&amp;gt;ERR_print_errors_fp(stderr)&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
=== Use &amp;lt;code&amp;gt;SETUP_TEST_FIXTURE()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;EXECUTE_TEST()&amp;lt;/code&amp;gt; from &amp;lt;code&amp;gt;test/testutil.h&amp;lt;/code&amp;gt; ===&lt;br /&gt;
Each test case function should call &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; as its first statement, and should call &amp;lt;code&amp;gt;tear_down()&amp;lt;/code&amp;gt; just before returning. This is handled in a uniform fashion when using the &amp;lt;code&amp;gt;SETUP_TEST_FIXTURE()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;EXECUTE_TEST()&amp;lt;/code&amp;gt; helper macros from &amp;lt;code&amp;gt;test/testutil.h&amp;lt;/code&amp;gt; ([https://github.com/openssl/openssl/pull/126 pending pull request]). See the comments in &amp;lt;code&amp;gt;test/testutil.h&amp;lt;/code&amp;gt; for usage, and &amp;lt;code&amp;gt;ssl/heartbeat_test.c&amp;lt;/code&amp;gt; for an example of how to wrap the macros for a specific unit test.&lt;br /&gt;
&lt;br /&gt;
=== Use test case functions, not a table of fixtures ===&lt;br /&gt;
Individual test case functions that call a common execution function are much more readable and maintainable than a loop over a table of fixture structures. Explicit fixture variable assignments aid comprehension when reading a specific test case, which saves time and energy when trying to understand a test or diagnose a failure. When a new member is added to an existing fixture, &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; can set a default for all test cases, and only the test cases that rely on that new member need to be updated.&lt;br /&gt;
&lt;br /&gt;
=== Use very descriptive test case names ===&lt;br /&gt;
Give tests long, descriptive names that provide ample context for the details of the test case. Good test names are also help produce good error messages.&lt;br /&gt;
&lt;br /&gt;
=== Group test cases into &amp;quot;suites&amp;quot; by naming convention ===&lt;br /&gt;
Give logically-related tests the same prefix, e.g. &amp;lt;code&amp;gt;test_dtls1_&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;test_tls1&amp;lt;/code&amp;gt; from &amp;lt;code&amp;gt;ssl/heartbeat_test.c&amp;lt;/code&amp;gt;. If need be, you can define suite-specific &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; functions that call the common &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; and elaborate on it. (This generally shouldn't be necessary for &amp;lt;code&amp;gt;tear_down()&amp;lt;/code&amp;gt;.)&lt;br /&gt;
&lt;br /&gt;
=== Keep individual test case functions focused on one thing ===&lt;br /&gt;
If the test name contains the word &amp;quot;and&amp;quot;, consider breaking it into two or more separate test case functions.&lt;br /&gt;
&lt;br /&gt;
=== Write very descriptive error messages ===&lt;br /&gt;
Include the test case function name in each error message, and explain in detail the context for the assertion that failed. Include the expected result (contained in the fixture structure) and the actual result returned from the code under test. Write helper methods for complex values as needed (e.g. &amp;lt;code&amp;gt;print_payload()&amp;lt;/code&amp;gt; in &amp;lt;code&amp;gt;ssl/heartbeat_test.c&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
=== Return zero on success and one on failure ===&lt;br /&gt;
The return value will be used to tally the number of test cases that failed. Even if multiple assertions fail for a single test case, the result should be exactly one.&lt;br /&gt;
&lt;br /&gt;
=== Add each test case function to the test runner function ===&lt;br /&gt;
Whatever function is used to execute the batch of test case functions, be that &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt; or a separate function called by &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt;, don't forget to add your test case functions to that function.&lt;br /&gt;
&lt;br /&gt;
TODO(mbland): create some kind of automated script or editor macros?&lt;br /&gt;
&lt;br /&gt;
=== Report the number of test cases that failed ===&lt;br /&gt;
Add up the total number of failed test cases in &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt; and report that number as the last error message of the test. &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt; should return &amp;lt;code&amp;gt;EXIT_FAILURE&amp;lt;/code&amp;gt; if any test cases failed, &amp;lt;code&amp;gt;EXIT_SUCCESS&amp;lt;/code&amp;gt; otherwise.&lt;br /&gt;
&lt;br /&gt;
=== Disable for Windows (for now) ===&lt;br /&gt;
Until we solve the private-symbol problem on Windows, we will need to wrap our unit test code in the following &amp;lt;code&amp;gt;#ifdef&amp;lt;/code&amp;gt; block:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#if !defined(OPENSSL_SYS_WINDOWS)&lt;br /&gt;
&lt;br /&gt;
/* All the test code, including main() */&lt;br /&gt;
&lt;br /&gt;
int main(int argc, char *argv[])                                                &lt;br /&gt;
    {&lt;br /&gt;
        return EXIT_SUCCESS;                                                    &lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
#endif /* OPENSSL_NO_WINDOWS  */&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Samples ==&lt;br /&gt;
Existing tests that can be used as models for new tests.&lt;br /&gt;
* [http://git.openssl.org/gitweb/?p=openssl.git;a=blob;f=ssl/heartbeat_test.c ssl/heartbeat_test.c]: Follows [http://mike-bland.com/2014/06/05/pseudo-xunit-pattern.html the Pseudo-xUnit pattern]&lt;/div&gt;</summary>
		<author><name>Mbland</name></author>
	</entry>
	<entry>
		<id>https://wiki.openssl.org/index.php?title=How_To_Write_Unit_Tests_For_OpenSSL&amp;diff=1724</id>
		<title>How To Write Unit Tests For OpenSSL</title>
		<link rel="alternate" type="text/html" href="https://wiki.openssl.org/index.php?title=How_To_Write_Unit_Tests_For_OpenSSL&amp;diff=1724"/>
		<updated>2014-06-07T17:25:41Z</updated>

		<summary type="html">&lt;p&gt;Mbland: /* Building and Running the Test */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This is an outline of the basic process and principles to follow when writing unit tests. This document will evolve quite a bit as the community gains experience.&lt;br /&gt;
&lt;br /&gt;
==Mechanics ==&lt;br /&gt;
=== Forking the Repo ===&lt;br /&gt;
For now, people contributing new unit tests for uncovered code (as opposed to submitting tests with new code changes) should fork [https://github.com/mbland/openssl Mike Bland's GitHub repository] and issue [https://help.github.com/articles/using-pull-requests GitHub pull requests]. Remember to do all development on a topic branch (not &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt;). Tests committed to this repo will occasionally get merged into the master OpenSSL repo.&lt;br /&gt;
&lt;br /&gt;
Rationale per Matt Caswell: We should think about process here. If you are going off to recruit an army of people writing tests then I wonder if it is worth setting up a separate github repository whilst you are building up the tests. We can then merge in from that on a periodic basis. I wouldn't want availability of openssl team committers to be a bottle neck.&lt;br /&gt;
&lt;br /&gt;
=== Use the Test Template Generator ===&lt;br /&gt;
TODO(mbland): Get template generator checked-in. Maybe have a template generator for each library, e.g. &amp;lt;code&amp;gt;ssl/new-test.sh&amp;lt;/code&amp;gt; that has additional setup boilerplate specific to the &amp;lt;code&amp;gt;ssl&amp;lt;/code&amp;gt; library.&lt;br /&gt;
&lt;br /&gt;
Use the &amp;lt;code&amp;gt;test/new-test.sh&amp;lt;/code&amp;gt; script to generate a skeleton test file. ([https://github.com/mbland/openssl/commit/6929798053fd0b16004035bf4df838f55f6aeb92 pending commit]) &lt;br /&gt;
&lt;br /&gt;
=== Add Makefile Targets ===&lt;br /&gt;
The following instructions use the &amp;lt;code&amp;gt;Makefile&amp;lt;/code&amp;gt; targets for &amp;lt;code&amp;gt;ssl/heartbeat_test.c&amp;lt;/code&amp;gt; as an example.&lt;br /&gt;
&lt;br /&gt;
In the &amp;lt;code&amp;gt;Makefile&amp;lt;/code&amp;gt; for the library containing the test, add the test source file to the &amp;lt;code&amp;gt;TEST&amp;lt;/code&amp;gt; variable:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# ssl/Makefile&lt;br /&gt;
TEST=ssltest.c heartbeat_test.c&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In &amp;lt;code&amp;gt;test/Makefile&amp;lt;/code&amp;gt;:&lt;br /&gt;
* add a variable for the test target near the top of the file, right after the existing test variables&lt;br /&gt;
* use the variable to add an executable target to the &amp;lt;code&amp;gt;EXE&amp;lt;/code&amp;gt; variable&lt;br /&gt;
* use the variable to add an object file target to the &amp;lt;code&amp;gt;OBJ&amp;lt;/code&amp;gt; variable&lt;br /&gt;
* use the variable to add a source file target to the &amp;lt;code&amp;gt;SRC&amp;lt;/code&amp;gt; variable&lt;br /&gt;
* add the test target to the &amp;lt;code&amp;gt;alltests&amp;lt;/code&amp;gt; target&lt;br /&gt;
* add the target to execute the test&lt;br /&gt;
* add the target to build the test executable&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# test/Makefile&lt;br /&gt;
HEARTBEATTEST=  heartbeat_test&lt;br /&gt;
EXE=  ... $(HEARTBEATTEST)$(EXE_EXT)&lt;br /&gt;
OBJ= ... $(HEARTBEATTEST).o&lt;br /&gt;
SRC= ... $(HEARTBEATTEST).c&lt;br /&gt;
alltests: \&lt;br /&gt;
        ... test_heartbeat&lt;br /&gt;
&lt;br /&gt;
test_heartbeat: $(HEARTBEATTEST)$(EXE_EXT)&lt;br /&gt;
  ../util/shlib_wrap.sh ./$(HEARTBEATTEST)&lt;br /&gt;
&lt;br /&gt;
$(HEARTBEATTEST)$(EXE_EXT): $(HEARTBEATTEST).o $(DLIBCRYPTO)&lt;br /&gt;
  @target=$(HEARTBEATTEST); $(BUILD_CMD)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Run &amp;lt;code&amp;gt;make depend&amp;lt;/code&amp;gt; ===&lt;br /&gt;
Finally, run &amp;lt;code&amp;gt;make depend&amp;lt;/code&amp;gt; to automatically generate the header file dependencies.&lt;br /&gt;
&lt;br /&gt;
=== Building and Running the Test ===&lt;br /&gt;
If you're initially developing on Mac OS X or (for now) FreeBSD 10, just use the stock method of building and testing:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ config &amp;amp;&amp;amp; make &amp;amp;&amp;amp; make test&lt;br /&gt;
&lt;br /&gt;
# To execute just one specific test&lt;br /&gt;
$ TESTS=test_heartbeat make test &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Ultimately the test will have to compile and pass with developer flags enabled:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ ./GitConfigure debug-ben-debug-64-clang&lt;br /&gt;
$ ./GitMake -j 2&lt;br /&gt;
$ ./GitMake test_heartbeat&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above currently doesn't work on Mac OS X or FreeBSD 10; for now, you can install the latest 9.x release of [http://www.freebsd.org/ FreeBSD] via a virtualization platform such as [https://www.virtualbox.org/ VirtualBox].&lt;br /&gt;
&lt;br /&gt;
== Style ==&lt;br /&gt;
[http://mike-bland.com/2014/06/05/pseudo-xunit-pattern.html The Pseudo-xUnit Pattern] is that established by [http://git.openssl.org/gitweb/?p=openssl.git;a=blob;f=ssl/heartbeat_test.c ssl/heartbeat_test.c]. This pattern organizes code in a fashion reminiscent of the [http://en.wikipedia.org/wiki/XUnit xUnit] family of unit testing frameworks, without actually using a testing framework. This should lower the barrier to entry for people wanting to write unit tests, but enable a relatively easy migration to an xUnit-based framework if we decide to do so one day.&lt;br /&gt;
&lt;br /&gt;
Some of the basic principles to follow are:&lt;br /&gt;
&lt;br /&gt;
=== Define a fixture structure ===&lt;br /&gt;
The fixture structure should contain all of the inputs to the code under test and all of the expected result values. It should also contain a &amp;lt;code&amp;gt;const char*&amp;lt;/code&amp;gt; for the name of the test case function that created it, to aid in error message formatting. Even though the fixture may contain dynamically-allocated members, the fixture itself should be copied by value to reduce the necessary degree of memory management in a small unit test program.&lt;br /&gt;
&lt;br /&gt;
=== Define set_up() and tear_down() functions for the fixture ===&lt;br /&gt;
&amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; should return a newly-initialized test fixture structure. It should take the name of the test case as an argument (i.e. &amp;lt;code&amp;gt;__func__&amp;lt;/code&amp;gt;) and assign it to the fixture. All of the fixture members should be initialized, which each test case function can then override as needed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;tear_down()&amp;lt;/code&amp;gt; should take the fixture as an argument and release any resources allocated by &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt;. It can also call any library-wide error printing routines (e.g. &amp;lt;code&amp;gt;ERR_print_errors_fp(stderr)&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Each test case function should call &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; as its first statement, and should call &amp;lt;code&amp;gt;tear_down()&amp;lt;/code&amp;gt; just before returning.&lt;br /&gt;
&lt;br /&gt;
=== Use test case functions, not a table of fixtures ===&lt;br /&gt;
Individual test case functions that call a common execution function are much more readable and maintainable than a loop over a table of fixture structures. Explicit fixture variable assignments aid comprehension when reading a specific test case, which saves time and energy when trying to understand a test or diagnose a failure. When a new member is added to an existing fixture, &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; can set a default for all test cases, and only the test cases that rely on that new member need to be updated.&lt;br /&gt;
&lt;br /&gt;
=== Use very descriptive test case names ===&lt;br /&gt;
Give tests long, descriptive names that provide ample context for the details of the test case. Good test names are also help produce good error messages.&lt;br /&gt;
&lt;br /&gt;
=== Group test cases into &amp;quot;suites&amp;quot; by naming convention ===&lt;br /&gt;
Give logically-related tests the same prefix, e.g. &amp;lt;code&amp;gt;test_dtls1_&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;test_tls1&amp;lt;/code&amp;gt; from &amp;lt;code&amp;gt;ssl/heartbeat_test.c&amp;lt;/code&amp;gt;. If need be, you can define suite-specific &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; functions that call the common &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; and elaborate on it. (This generally shouldn't be necessary for &amp;lt;code&amp;gt;tear_down()&amp;lt;/code&amp;gt;.)&lt;br /&gt;
&lt;br /&gt;
=== Keep individual test case functions focused on one thing ===&lt;br /&gt;
If the test name contains the word &amp;quot;and&amp;quot;, consider breaking it into two or more separate test case functions.&lt;br /&gt;
&lt;br /&gt;
=== Write very descriptive error messages ===&lt;br /&gt;
Include the test case function name in each error message, and explain in detail the context for the assertion that failed. Include the expected result (contained in the fixture structure) and the actual result returned from the code under test. Write helper methods for complex values as needed (e.g. &amp;lt;code&amp;gt;print_payload()&amp;lt;/code&amp;gt; in &amp;lt;code&amp;gt;ssl/heartbeat_test.c&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
=== Return zero on success and one on failure ===&lt;br /&gt;
The return value will be used to tally the number of test cases that failed. Even if multiple assertions fail for a single test case, the result should be exactly one.&lt;br /&gt;
&lt;br /&gt;
=== Add each test case function to the test runner function ===&lt;br /&gt;
Whatever function is used to execute the batch of test case functions, be that &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt; or a separate function called by &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt;, don't forget to add your test case functions to that function.&lt;br /&gt;
&lt;br /&gt;
TODO(mbland): create some kind of automated script or editor macros?&lt;br /&gt;
&lt;br /&gt;
=== Report the number of test cases that failed ===&lt;br /&gt;
Add up the total number of failed test cases in &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt; and report that number as the last error message of the test. &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt; should return &amp;lt;code&amp;gt;EXIT_FAILURE&amp;lt;/code&amp;gt; if any test cases failed, &amp;lt;code&amp;gt;EXIT_SUCCESS&amp;lt;/code&amp;gt; otherwise.&lt;br /&gt;
&lt;br /&gt;
=== Disable for Windows (for now) ===&lt;br /&gt;
Until we solve the private-symbol problem on Windows, we will need to wrap our unit test code in the following &amp;lt;code&amp;gt;#ifdef&amp;lt;/code&amp;gt; block:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#if !defined(OPENSSL_SYS_WINDOWS)&lt;br /&gt;
&lt;br /&gt;
/* All the test code, including main() */&lt;br /&gt;
&lt;br /&gt;
int main(int argc, char *argv[])                                                &lt;br /&gt;
    {&lt;br /&gt;
        return EXIT_SUCCESS;                                                    &lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
#endif /* OPENSSL_NO_WINDOWS  */&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Samples ==&lt;br /&gt;
Existing tests that can be used as models for new tests.&lt;br /&gt;
* [http://git.openssl.org/gitweb/?p=openssl.git;a=blob;f=ssl/heartbeat_test.c ssl/heartbeat_test.c]: Follows [http://mike-bland.com/2014/06/05/pseudo-xunit-pattern.html the Pseudo-xUnit pattern]&lt;/div&gt;</summary>
		<author><name>Mbland</name></author>
	</entry>
	<entry>
		<id>https://wiki.openssl.org/index.php?title=Unit_Testing&amp;diff=1719</id>
		<title>Unit Testing</title>
		<link rel="alternate" type="text/html" href="https://wiki.openssl.org/index.php?title=Unit_Testing&amp;diff=1719"/>
		<updated>2014-06-06T17:52:05Z</updated>

		<summary type="html">&lt;p&gt;Mbland: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page will track the effort to improve unit test and other automated test coverage for OpenSSL. Everyone is encouraged to help with this effort, but this page will track which community members have accepted specific responsibilities, and what tasks are currently underway.&lt;br /&gt;
&lt;br /&gt;
== Discussion List ==&lt;br /&gt;
[https://groups.google.com/d/forum/openssl-testing openssl-testing] is the mailing list dedicated to the unit/automated testing effort, to avoid clogging openssl-dev. Membership is open to whoever wishes to join, even if only to lurk. Ideally all testing discussions will eventually move to openssl-dev once we have processes, tools, conventions, etc. in place.&lt;br /&gt;
&lt;br /&gt;
== Team ==&lt;br /&gt;
We can define new roles as needed. The success of this effort will be inversely proportional to the number of roles with any one individual's name next to them. Each role can have more than one person filling it, but needs specific people to fill them. &lt;br /&gt;
&lt;br /&gt;
The point is not to tell people what to do and not do: it’s to establish clear responsibilities so everyone can run with them right away and begin applying their creative energy to solutions, rather than waste it figuring out what the hell is going on, what they should do to contribute, and who they need to coordinate with to get things done.&lt;br /&gt;
&lt;br /&gt;
'''Organizer''': [mailto:mbland@acm.org Mike Bland]&amp;lt;br /&amp;gt;&lt;br /&gt;
Ensures the overall effort is making progress by facilitating communication, removing obstacles, and making hands-on contributions when necessary.&lt;br /&gt;
&lt;br /&gt;
'''Tech Writer''': [mailto:mbland@acm.org Mike Bland], Sandeep Mankar, Chelsea Komlo, Graham Brooks&amp;lt;br /&amp;gt;&lt;br /&gt;
Maintains documentation of tools, techniques, outstanding issues, etc. May maintain a code review/testing style guide based on the community consensus. Also documents who currently fills each role, as well as who might've filled it in the past.&lt;br /&gt;
&lt;br /&gt;
'''Buildmaster''': [mailto:mbland@acm.org Mike Bland], Isaac Truett, Dileep Bapat, Graham Brooks&amp;lt;br /&amp;gt;&lt;br /&gt;
Sets up and maintains automated builds and any infrastructure used to monitor them and report breakage.&lt;br /&gt;
&lt;br /&gt;
'''Toolsmith''': Tony Aiuto&lt;br /&gt;
Maintains any tools and frameworks that are a part of the core build process; proposes, integrates, and/or retires existing tools.&lt;br /&gt;
&lt;br /&gt;
'''Tutor''': [mailto:mbland@acm.org Mike Bland], Darshan Mody, Tom Francis, Brian N. Makin, Chelsea Komlo, Edward Knapp, Dileep Bapat, Graham Brooks&amp;lt;br /&amp;gt;&lt;br /&gt;
Helps contributors, particularly new contributors, with the details of writing unit or other automated tests. May be assigned by the reviewer of a patch to help a contributor get a new change under test. Submission of the patch should require the approval of the tutor in most cases. (Should ideally be more than one person.)&lt;br /&gt;
&lt;br /&gt;
== Goals ==&lt;br /&gt;
We can add more concrete goals to this list after we make progress on these. Getting people to own roles, setting up build infrastructure, and setting and enforcing policy are important first steps. Upon that foundation, we can begin to make serious progress towards improved test coverage, code quality, and defect prevention.&lt;br /&gt;
* Establish a written contribution/code review policy that requires:&lt;br /&gt;
** tests for every new code change, except for very trivial changes that do not directly impact program logic (e.g. documentation fixes, string constant updates, build script tweaks); this can be limited to an agreed-upon subset of the code to start, but would hopefully be expanded to cover most, if not all, of the code base&lt;br /&gt;
** tests for every bugfix &lt;br /&gt;
** smaller, well-tested changes building up to a complete feature (as opposed to large and/or untested changes that implement a large, complex feature all at once) &lt;br /&gt;
* Establish a schedule of Build Cops and Tutors to begin enforcing rollbacks/fixes and to help shepherd new contributors through the testing process.&lt;br /&gt;
* Set up a series of publicly-accessible continuous integration servers using whatever system the community prefers (e.g. Jenkins, Buildbot, etc.). These can be dedicated hardware or possibly Amazon Web Services-based. Establish a written policy that these remain green at all times, and that breakages be rolled-back or fixed within no more than 30 minutes. &lt;br /&gt;
&lt;br /&gt;
== Tasks ==&lt;br /&gt;
The current list is posted in the [http://goo.gl/5u9nbw OpenSSL Testing Tasks Google Spreadsheet].&lt;br /&gt;
&lt;br /&gt;
(Would be nice to enable the [http://www.mediawiki.org/wiki/Extension:Widget MediaWiki Widget extension] and the [http://www.mediawikiwidgets.org/Google_Spreadsheet Google Spreadsheet widget].)&lt;br /&gt;
&lt;br /&gt;
== Howtos and Style Guides ==&lt;br /&gt;
Documents that provide background on specific testing issues and idioms should be linked from here.&lt;br /&gt;
&lt;br /&gt;
* [[How To Write Unit Tests For OpenSSL]]&lt;br /&gt;
* [http://mike-bland.com/2014/06/05/pseudo-xunit-pattern.html The Pseudo-xUnit Pattern]&lt;br /&gt;
&lt;br /&gt;
== Discussion Topics ==&lt;br /&gt;
These are discussions related to some of the current testing tasks.&lt;br /&gt;
&lt;br /&gt;
=== First Area of Focus ===&lt;br /&gt;
Matt Caswell: One criterion might be ease of testing. If you were going down that route you might choose some of the low level packages within libcrypto which are relatively self-contained. I'm not talking about the crypto algorithms themselves (there are at least *some* tests for those), I'm thinking more about bio, pem, x509, x509v3, etc.&lt;br /&gt;
&lt;br /&gt;
Another criterion might be where you get the most value. I suspect we will get the most value from a really good set of unit tests for libssl. I suspect this might be a big ask to start off with (you would probably have to mock out a lot of stuff).&lt;br /&gt;
&lt;br /&gt;
=== Build Systems/Machines ===&lt;br /&gt;
Where can we get the machines? Is someone willing to donate them? What system should we use?&lt;br /&gt;
&lt;br /&gt;
=== Get Unit Tests to Build on Windows ===&lt;br /&gt;
Steve Henson on building ssl/heartbeat_test.c on Windows: The first problem is that __func__ isn't understood. Changing that to __FUNCTION__ resolves that easily enough.&lt;br /&gt;
&lt;br /&gt;
The second problem is more serious. Windows (and a couple of other platforms IIRC) is strict about only exporting approved symbols from global headers in shared libraries and wont export internal only functions.&lt;br /&gt;
&lt;br /&gt;
That means you get linker errors:&lt;br /&gt;
&lt;br /&gt;
heartbeat_test.obj : error LNK2019: unresolved external symbol _ssl3_setup_buffe&lt;br /&gt;
rs referenced in function _set_up&lt;br /&gt;
heartbeat_test.obj : error LNK2019: unresolved external symbol _ssl_init_wbio_bu&lt;br /&gt;
ffer referenced in function _set_up&lt;br /&gt;
heartbeat_test.obj : error LNK2019: unresolved external symbol _tls1_process_hea&lt;br /&gt;
rtbeat referenced in function _set_up_tls&lt;br /&gt;
heartbeat_test.obj : error LNK2019: unresolved external symbol _dtls1_process_he&lt;br /&gt;
artbeat referenced in function _set_up_dtls&lt;br /&gt;
out32dll\heartbeat_test.exe : fatal error LNK1120: 4 unresolved externals&lt;br /&gt;
NMAKE : fatal error U1077: '&amp;quot;C:\Program Files (x86)\Microsoft Visual Studio 11.0&lt;br /&gt;
\VC\BIN\link.EXE&amp;quot;' : return code '0x460'&lt;br /&gt;
&lt;br /&gt;
Potential solutions:&lt;br /&gt;
* http://stackoverflow.com/questions/7759777/is-it-possible-to-test-internal-class-from-a-c-dll-using-mstest&lt;br /&gt;
* http://stackoverflow.com/questions/19934714/googletest-c-unit-testing-linking-error&lt;br /&gt;
* http://stackoverflow.com/questions/14010627/unresolved-externals-when-compiling-unit-tests-for-visual-c-2012&lt;br /&gt;
&lt;br /&gt;
ifdef'd out (for now): https://github.com/openssl/openssl/commit/7ce79a5bfdbcd53ae75f85e94eed665a05b5dea3&lt;br /&gt;
&lt;br /&gt;
=== How to Manage Private Symbols ===&lt;br /&gt;
Steve Henson: As this also affects other platforms a general solution might be in order.&lt;br /&gt;
&lt;br /&gt;
One option is to link to static libraries as has been mentioned. If you have a&lt;br /&gt;
lot of unit tests you could end up with a lot of large binaries. Would need some&lt;br /&gt;
changes to the dreaded Windows build system too.&lt;br /&gt;
&lt;br /&gt;
A different option would be to export the unit test functions through a&lt;br /&gt;
structure pointer which a function returns. So you'd have something like..&lt;br /&gt;
&lt;br /&gt;
unit_test = SSL_get_unit_test_funcs();&lt;br /&gt;
&lt;br /&gt;
unit_test.some_internal_funcction(...);&lt;br /&gt;
&lt;br /&gt;
Where the actual structure is opaque to applications (so they aren't tempted to&lt;br /&gt;
poke around in internals) but visible to the unit test code. Then the unit test&lt;br /&gt;
code doesn't call any internal functions not defined in there and doesn't need&lt;br /&gt;
to load private headers (unless it needs them for some definitions).&lt;br /&gt;
&lt;br /&gt;
Mike Bland: This is an interesting idea, though I'd expect the unit tests will&lt;br /&gt;
still need access to internal headers.&lt;br /&gt;
&lt;br /&gt;
But I have a question: Why do any of the symbols need to be private?&lt;br /&gt;
Is that degree of encapsulation necessary, and does it really&lt;br /&gt;
discourage irresponsible clients? The source code is open, so people&lt;br /&gt;
can always build their own copy and depend on internals if they really&lt;br /&gt;
want to, and the default UNIX/Linux/OS X build (i.e. ./configure &amp;amp;&amp;amp;&lt;br /&gt;
make &amp;amp;&amp;amp; make test) doesn't lock down internal symbols. Have&lt;br /&gt;
dependencies on internal APIs ever been a problem in practice?&lt;br /&gt;
&lt;br /&gt;
I'm not saying I feel strongly either way, but it seems that clients&lt;br /&gt;
should be clear that the public API is what's available in&lt;br /&gt;
openssl/include, and shouldn't depend on anything else. I just don't&lt;br /&gt;
understand what making symbols private buys anyone in the context of&lt;br /&gt;
OpenSSL, in light of how it appears to complicate the ability to unit&lt;br /&gt;
test.&lt;br /&gt;
&lt;br /&gt;
Not trying to be argumentative, I just want to understand the&lt;br /&gt;
rationale. I'll work with whatever environment I have to.&lt;br /&gt;
&lt;br /&gt;
=== Improved Patch/Cherry-pick Process ===&lt;br /&gt;
Geoff Thorpe: (a) patches that are not applied/cherry-picked to all the branches they apply to, or (b) applied to more branches than they should be. A complication of (a) is that some patches may need to be reworked in order to apply (or in order to not break binary compatibility of a stable branch). The difficulty of (b) is determining when the nature of the change either breaks binary compatibility or causes some other behavioral deviation that is not in keeping with the &amp;quot;promises&amp;quot; of stable branches.&lt;br /&gt;
&lt;br /&gt;
http://ispras.linuxbase.org/index.php/ABI_compliance_checker&lt;br /&gt;
https://github.com/lvc/abi-compliance-checker/&lt;br /&gt;
&lt;br /&gt;
Geoff on 2014-05-30: ...we might move to a scheme whereby we only maintain one most-recent stable branch for production releases, with snapshots or whatever of the development head. Ie. two branches, one for maximum-compatibility/bug-fixes-only, and the other for more active development. The number of &amp;quot;stable&amp;quot; branches would thus be 1 rather than 'n'. The idea is that we may defer to downstream &amp;quot;slow-moving&amp;quot; users (eg. long-term releases of linux distros) the opportunity to step up and do the work of maintaining (cherry-picking, back-porting, ...) older branches. Ie. what they typically already do in-house, but the opportunity to do it under our roof and thus combine their efforts with any other similarly-interested parties. If there's noone prepared to do that, the logical conclusion is that there is probably no need for it (or so the argument goes).&lt;br /&gt;
&lt;br /&gt;
=== Improve/Standardize Algorithm Testing ===&lt;br /&gt;
Steve Henson: While the algorithms are partly tested I don't think they're anything like comprehensive enough. The way they are handled is also haphazard and spread across multiple tests covering all sorts of odd APIs, some of which are deprecated.&lt;br /&gt;
&lt;br /&gt;
In fact I'd say they're (with the odd exception) an example of how *not* to do things.&lt;br /&gt;
&lt;br /&gt;
Examples rc2test tests RC2 it has various test vectors hard coded inconsistent indentation and use of low level APIs. The rc4test is a similar story and uses a different format to rc2test. The same tale is repeated all over the place with ideatest, rmdtest etc etc.&lt;br /&gt;
&lt;br /&gt;
Then we come to the code which I think is closest to how things should be which is evp_test. It uses the standard high level EVP API the format is consistent (if undocumented) and adding new tests can be done simply by editing a text file.&lt;br /&gt;
&lt;br /&gt;
It currently however only works for some algorithms and the text file format could be better. It currently doesn't handle public key algorithms or test variants of the same algorithm (e.g. AES-NI versus non AES-NI) either.&lt;br /&gt;
&lt;br /&gt;
=== Develop SSL/TLS Stack and Other Tools ===&lt;br /&gt;
Steve Henson: The heartbeat bug is an example where you can perform some testing without a complete SSL/TLS stack. However looking through the code in heartbeat_test.c it uses a lot of functionality which would normally be strictly off-limits for an application.&lt;br /&gt;
&lt;br /&gt;
Some bugs are far more subtle and harder to test. For example some involve doing *almost* everything right and then slipping in some illegal parameter or badly formatted message. If you want to do that in a standalone bit of code you need a near complete SSL/TLS stack.&lt;br /&gt;
&lt;br /&gt;
I can think of a couple of ways to handle that. One is to have some kind of hooks in libssl so testing code can misbehave and send out illegal messages in controlled ways (I had a prototype &amp;quot;bad heartbeat&amp;quot; API which only added a couple of lines to libssl). An alternative would be to write some kind of tiny SSL/TLS code used only by the test programs and carefully tailored to permit such things.&lt;/div&gt;</summary>
		<author><name>Mbland</name></author>
	</entry>
	<entry>
		<id>https://wiki.openssl.org/index.php?title=Unit_Testing&amp;diff=1718</id>
		<title>Unit Testing</title>
		<link rel="alternate" type="text/html" href="https://wiki.openssl.org/index.php?title=Unit_Testing&amp;diff=1718"/>
		<updated>2014-06-06T17:39:53Z</updated>

		<summary type="html">&lt;p&gt;Mbland: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page will track the effort to improve unit test and other automated test coverage for OpenSSL. Everyone is encouraged to help with this effort, but this page will track which community members have accepted specific responsibilities, and what tasks are currently underway.&lt;br /&gt;
&lt;br /&gt;
== Discussion List ==&lt;br /&gt;
[https://groups.google.com/forum/#!forum/openssl-testing openssl-testing] is the mailing list dedicated to the unit/automated testing effort, to avoid clogging openssl-dev. Membership is open to whoever wishes to join, even if only to lurk. Ideally all testing discussions will eventually move to openssl-dev once we have processes, tools, conventions, etc. in place.&lt;br /&gt;
&lt;br /&gt;
== Team ==&lt;br /&gt;
We can define new roles as needed. The success of this effort will be inversely proportional to the number of roles with any one individual's name next to them. Each role can have more than one person filling it, but needs specific people to fill them. &lt;br /&gt;
&lt;br /&gt;
The point is not to tell people what to do and not do: it’s to establish clear responsibilities so everyone can run with them right away and begin applying their creative energy to solutions, rather than waste it figuring out what the hell is going on, what they should do to contribute, and who they need to coordinate with to get things done.&lt;br /&gt;
&lt;br /&gt;
'''Organizer''': [mailto:mbland@acm.org Mike Bland]&amp;lt;br /&amp;gt;&lt;br /&gt;
Ensures the overall effort is making progress by facilitating communication, removing obstacles, and making hands-on contributions when necessary.&lt;br /&gt;
&lt;br /&gt;
'''Tech Writer''': [mailto:mbland@acm.org Mike Bland], Sandeep Mankar, Chelsea Komlo, Graham Brooks&amp;lt;br /&amp;gt;&lt;br /&gt;
Maintains documentation of tools, techniques, outstanding issues, etc. May maintain a code review/testing style guide based on the community consensus. Also documents who currently fills each role, as well as who might've filled it in the past.&lt;br /&gt;
&lt;br /&gt;
'''Buildmaster''': [mailto:mbland@acm.org Mike Bland], Isaac Truett, Dileep Bapat, Graham Brooks&amp;lt;br /&amp;gt;&lt;br /&gt;
Sets up and maintains automated builds and any infrastructure used to monitor them and report breakage.&lt;br /&gt;
&lt;br /&gt;
'''Toolsmith''': Tony Aiuto&lt;br /&gt;
Maintains any tools and frameworks that are a part of the core build process; proposes, integrates, and/or retires existing tools.&lt;br /&gt;
&lt;br /&gt;
'''Tutor''': [mailto:mbland@acm.org Mike Bland], Darshan Mody, Tom Francis, Brian N. Makin, Chelsea Komlo, Edward Knapp, Dileep Bapat, Graham Brooks&amp;lt;br /&amp;gt;&lt;br /&gt;
Helps contributors, particularly new contributors, with the details of writing unit or other automated tests. May be assigned by the reviewer of a patch to help a contributor get a new change under test. Submission of the patch should require the approval of the tutor in most cases. (Should ideally be more than one person.)&lt;br /&gt;
&lt;br /&gt;
== Goals ==&lt;br /&gt;
We can add more concrete goals to this list after we make progress on these. Getting people to own roles, setting up build infrastructure, and setting and enforcing policy are important first steps. Upon that foundation, we can begin to make serious progress towards improved test coverage, code quality, and defect prevention.&lt;br /&gt;
* Establish a written contribution/code review policy that requires:&lt;br /&gt;
** tests for every new code change, except for very trivial changes that do not directly impact program logic (e.g. documentation fixes, string constant updates, build script tweaks); this can be limited to an agreed-upon subset of the code to start, but would hopefully be expanded to cover most, if not all, of the code base&lt;br /&gt;
** tests for every bugfix &lt;br /&gt;
** smaller, well-tested changes building up to a complete feature (as opposed to large and/or untested changes that implement a large, complex feature all at once) &lt;br /&gt;
* Establish a schedule of Build Cops and Tutors to begin enforcing rollbacks/fixes and to help shepherd new contributors through the testing process.&lt;br /&gt;
* Set up a series of publicly-accessible continuous integration servers using whatever system the community prefers (e.g. Jenkins, Buildbot, etc.). These can be dedicated hardware or possibly Amazon Web Services-based. Establish a written policy that these remain green at all times, and that breakages be rolled-back or fixed within no more than 30 minutes. &lt;br /&gt;
&lt;br /&gt;
== Tasks ==&lt;br /&gt;
The current list is posted in the [http://goo.gl/5u9nbw OpenSSL Testing Tasks Google Spreadsheet].&lt;br /&gt;
&lt;br /&gt;
(Would be nice to enable the [http://www.mediawiki.org/wiki/Extension:Widget MediaWiki Widget extension] and the [http://www.mediawikiwidgets.org/Google_Spreadsheet Google Spreadsheet widget].)&lt;br /&gt;
&lt;br /&gt;
== Howtos and Style Guides ==&lt;br /&gt;
Documents that provide background on specific testing issues and idioms should be linked from here.&lt;br /&gt;
&lt;br /&gt;
* [[How To Write Unit Tests For OpenSSL]]&lt;br /&gt;
* [http://mike-bland.com/2014/06/05/pseudo-xunit-pattern.html The Pseudo-xUnit Pattern]&lt;br /&gt;
&lt;br /&gt;
== Discussion Topics ==&lt;br /&gt;
These are discussions related to some of the current testing tasks.&lt;br /&gt;
&lt;br /&gt;
=== First Area of Focus ===&lt;br /&gt;
Matt Caswell: One criterion might be ease of testing. If you were going down that route you might choose some of the low level packages within libcrypto which are relatively self-contained. I'm not talking about the crypto algorithms themselves (there are at least *some* tests for those), I'm thinking more about bio, pem, x509, x509v3, etc.&lt;br /&gt;
&lt;br /&gt;
Another criterion might be where you get the most value. I suspect we will get the most value from a really good set of unit tests for libssl. I suspect this might be a big ask to start off with (you would probably have to mock out a lot of stuff).&lt;br /&gt;
&lt;br /&gt;
=== Build Systems/Machines ===&lt;br /&gt;
Where can we get the machines? Is someone willing to donate them? What system should we use?&lt;br /&gt;
&lt;br /&gt;
=== Get Unit Tests to Build on Windows ===&lt;br /&gt;
Steve Henson on building ssl/heartbeat_test.c on Windows: The first problem is that __func__ isn't understood. Changing that to __FUNCTION__ resolves that easily enough.&lt;br /&gt;
&lt;br /&gt;
The second problem is more serious. Windows (and a couple of other platforms IIRC) is strict about only exporting approved symbols from global headers in shared libraries and wont export internal only functions.&lt;br /&gt;
&lt;br /&gt;
That means you get linker errors:&lt;br /&gt;
&lt;br /&gt;
heartbeat_test.obj : error LNK2019: unresolved external symbol _ssl3_setup_buffe&lt;br /&gt;
rs referenced in function _set_up&lt;br /&gt;
heartbeat_test.obj : error LNK2019: unresolved external symbol _ssl_init_wbio_bu&lt;br /&gt;
ffer referenced in function _set_up&lt;br /&gt;
heartbeat_test.obj : error LNK2019: unresolved external symbol _tls1_process_hea&lt;br /&gt;
rtbeat referenced in function _set_up_tls&lt;br /&gt;
heartbeat_test.obj : error LNK2019: unresolved external symbol _dtls1_process_he&lt;br /&gt;
artbeat referenced in function _set_up_dtls&lt;br /&gt;
out32dll\heartbeat_test.exe : fatal error LNK1120: 4 unresolved externals&lt;br /&gt;
NMAKE : fatal error U1077: '&amp;quot;C:\Program Files (x86)\Microsoft Visual Studio 11.0&lt;br /&gt;
\VC\BIN\link.EXE&amp;quot;' : return code '0x460'&lt;br /&gt;
&lt;br /&gt;
Potential solutions:&lt;br /&gt;
* http://stackoverflow.com/questions/7759777/is-it-possible-to-test-internal-class-from-a-c-dll-using-mstest&lt;br /&gt;
* http://stackoverflow.com/questions/19934714/googletest-c-unit-testing-linking-error&lt;br /&gt;
* http://stackoverflow.com/questions/14010627/unresolved-externals-when-compiling-unit-tests-for-visual-c-2012&lt;br /&gt;
&lt;br /&gt;
ifdef'd out (for now): https://github.com/openssl/openssl/commit/7ce79a5bfdbcd53ae75f85e94eed665a05b5dea3&lt;br /&gt;
&lt;br /&gt;
=== How to Manage Private Symbols ===&lt;br /&gt;
Steve Henson: As this also affects other platforms a general solution might be in order.&lt;br /&gt;
&lt;br /&gt;
One option is to link to static libraries as has been mentioned. If you have a&lt;br /&gt;
lot of unit tests you could end up with a lot of large binaries. Would need some&lt;br /&gt;
changes to the dreaded Windows build system too.&lt;br /&gt;
&lt;br /&gt;
A different option would be to export the unit test functions through a&lt;br /&gt;
structure pointer which a function returns. So you'd have something like..&lt;br /&gt;
&lt;br /&gt;
unit_test = SSL_get_unit_test_funcs();&lt;br /&gt;
&lt;br /&gt;
unit_test.some_internal_funcction(...);&lt;br /&gt;
&lt;br /&gt;
Where the actual structure is opaque to applications (so they aren't tempted to&lt;br /&gt;
poke around in internals) but visible to the unit test code. Then the unit test&lt;br /&gt;
code doesn't call any internal functions not defined in there and doesn't need&lt;br /&gt;
to load private headers (unless it needs them for some definitions).&lt;br /&gt;
&lt;br /&gt;
Mike Bland: This is an interesting idea, though I'd expect the unit tests will&lt;br /&gt;
still need access to internal headers.&lt;br /&gt;
&lt;br /&gt;
But I have a question: Why do any of the symbols need to be private?&lt;br /&gt;
Is that degree of encapsulation necessary, and does it really&lt;br /&gt;
discourage irresponsible clients? The source code is open, so people&lt;br /&gt;
can always build their own copy and depend on internals if they really&lt;br /&gt;
want to, and the default UNIX/Linux/OS X build (i.e. ./configure &amp;amp;&amp;amp;&lt;br /&gt;
make &amp;amp;&amp;amp; make test) doesn't lock down internal symbols. Have&lt;br /&gt;
dependencies on internal APIs ever been a problem in practice?&lt;br /&gt;
&lt;br /&gt;
I'm not saying I feel strongly either way, but it seems that clients&lt;br /&gt;
should be clear that the public API is what's available in&lt;br /&gt;
openssl/include, and shouldn't depend on anything else. I just don't&lt;br /&gt;
understand what making symbols private buys anyone in the context of&lt;br /&gt;
OpenSSL, in light of how it appears to complicate the ability to unit&lt;br /&gt;
test.&lt;br /&gt;
&lt;br /&gt;
Not trying to be argumentative, I just want to understand the&lt;br /&gt;
rationale. I'll work with whatever environment I have to.&lt;br /&gt;
&lt;br /&gt;
=== Improved Patch/Cherry-pick Process ===&lt;br /&gt;
Geoff Thorpe: (a) patches that are not applied/cherry-picked to all the branches they apply to, or (b) applied to more branches than they should be. A complication of (a) is that some patches may need to be reworked in order to apply (or in order to not break binary compatibility of a stable branch). The difficulty of (b) is determining when the nature of the change either breaks binary compatibility or causes some other behavioral deviation that is not in keeping with the &amp;quot;promises&amp;quot; of stable branches.&lt;br /&gt;
&lt;br /&gt;
http://ispras.linuxbase.org/index.php/ABI_compliance_checker&lt;br /&gt;
https://github.com/lvc/abi-compliance-checker/&lt;br /&gt;
&lt;br /&gt;
Geoff on 2014-05-30: ...we might move to a scheme whereby we only maintain one most-recent stable branch for production releases, with snapshots or whatever of the development head. Ie. two branches, one for maximum-compatibility/bug-fixes-only, and the other for more active development. The number of &amp;quot;stable&amp;quot; branches would thus be 1 rather than 'n'. The idea is that we may defer to downstream &amp;quot;slow-moving&amp;quot; users (eg. long-term releases of linux distros) the opportunity to step up and do the work of maintaining (cherry-picking, back-porting, ...) older branches. Ie. what they typically already do in-house, but the opportunity to do it under our roof and thus combine their efforts with any other similarly-interested parties. If there's noone prepared to do that, the logical conclusion is that there is probably no need for it (or so the argument goes).&lt;br /&gt;
&lt;br /&gt;
=== Improve/Standardize Algorithm Testing ===&lt;br /&gt;
Steve Henson: While the algorithms are partly tested I don't think they're anything like comprehensive enough. The way they are handled is also haphazard and spread across multiple tests covering all sorts of odd APIs, some of which are deprecated.&lt;br /&gt;
&lt;br /&gt;
In fact I'd say they're (with the odd exception) an example of how *not* to do things.&lt;br /&gt;
&lt;br /&gt;
Examples rc2test tests RC2 it has various test vectors hard coded inconsistent indentation and use of low level APIs. The rc4test is a similar story and uses a different format to rc2test. The same tale is repeated all over the place with ideatest, rmdtest etc etc.&lt;br /&gt;
&lt;br /&gt;
Then we come to the code which I think is closest to how things should be which is evp_test. It uses the standard high level EVP API the format is consistent (if undocumented) and adding new tests can be done simply by editing a text file.&lt;br /&gt;
&lt;br /&gt;
It currently however only works for some algorithms and the text file format could be better. It currently doesn't handle public key algorithms or test variants of the same algorithm (e.g. AES-NI versus non AES-NI) either.&lt;br /&gt;
&lt;br /&gt;
=== Develop SSL/TLS Stack and Other Tools ===&lt;br /&gt;
Steve Henson: The heartbeat bug is an example where you can perform some testing without a complete SSL/TLS stack. However looking through the code in heartbeat_test.c it uses a lot of functionality which would normally be strictly off-limits for an application.&lt;br /&gt;
&lt;br /&gt;
Some bugs are far more subtle and harder to test. For example some involve doing *almost* everything right and then slipping in some illegal parameter or badly formatted message. If you want to do that in a standalone bit of code you need a near complete SSL/TLS stack.&lt;br /&gt;
&lt;br /&gt;
I can think of a couple of ways to handle that. One is to have some kind of hooks in libssl so testing code can misbehave and send out illegal messages in controlled ways (I had a prototype &amp;quot;bad heartbeat&amp;quot; API which only added a couple of lines to libssl). An alternative would be to write some kind of tiny SSL/TLS code used only by the test programs and carefully tailored to permit such things.&lt;/div&gt;</summary>
		<author><name>Mbland</name></author>
	</entry>
	<entry>
		<id>https://wiki.openssl.org/index.php?title=How_To_Write_Unit_Tests_For_OpenSSL&amp;diff=1717</id>
		<title>How To Write Unit Tests For OpenSSL</title>
		<link rel="alternate" type="text/html" href="https://wiki.openssl.org/index.php?title=How_To_Write_Unit_Tests_For_OpenSSL&amp;diff=1717"/>
		<updated>2014-06-06T16:13:19Z</updated>

		<summary type="html">&lt;p&gt;Mbland: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This is an outline of the basic process and principles to follow when writing unit tests. This document will evolve quite a bit as the community gains experience.&lt;br /&gt;
&lt;br /&gt;
==Mechanics ==&lt;br /&gt;
=== Forking the Repo ===&lt;br /&gt;
For now, people contributing new unit tests for uncovered code (as opposed to submitting tests with new code changes) should fork [https://github.com/mbland/openssl Mike Bland's GitHub repository] and issue [https://help.github.com/articles/using-pull-requests GitHub pull requests]. Remember to do all development on a topic branch (not &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt;). Tests committed to this repo will occasionally get merged into the master OpenSSL repo.&lt;br /&gt;
&lt;br /&gt;
Rationale per Matt Caswell: We should think about process here. If you are going off to recruit an army of people writing tests then I wonder if it is worth setting up a separate github repository whilst you are building up the tests. We can then merge in from that on a periodic basis. I wouldn't want availability of openssl team committers to be a bottle neck.&lt;br /&gt;
&lt;br /&gt;
=== Use the Test Template Generator ===&lt;br /&gt;
TODO(mbland): Get template generator checked-in. Maybe have a template generator for each library, e.g. &amp;lt;code&amp;gt;ssl/new-test.sh&amp;lt;/code&amp;gt; that has additional setup boilerplate specific to the &amp;lt;code&amp;gt;ssl&amp;lt;/code&amp;gt; library.&lt;br /&gt;
&lt;br /&gt;
Use the &amp;lt;code&amp;gt;test/new-test.sh&amp;lt;/code&amp;gt; script to generate a skeleton test file. ([https://github.com/mbland/openssl/commit/6929798053fd0b16004035bf4df838f55f6aeb92 pending commit]) &lt;br /&gt;
&lt;br /&gt;
=== Add Makefile Targets ===&lt;br /&gt;
The following instructions use the &amp;lt;code&amp;gt;Makefile&amp;lt;/code&amp;gt; targets for &amp;lt;code&amp;gt;ssl/heartbeat_test.c&amp;lt;/code&amp;gt; as an example.&lt;br /&gt;
&lt;br /&gt;
In the &amp;lt;code&amp;gt;Makefile&amp;lt;/code&amp;gt; for the library containing the test, add the test source file to the &amp;lt;code&amp;gt;TEST&amp;lt;/code&amp;gt; variable:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# ssl/Makefile&lt;br /&gt;
TEST=ssltest.c heartbeat_test.c&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In &amp;lt;code&amp;gt;test/Makefile&amp;lt;/code&amp;gt;:&lt;br /&gt;
* add a variable for the test target near the top of the file, right after the existing test variables&lt;br /&gt;
* use the variable to add an executable target to the &amp;lt;code&amp;gt;EXE&amp;lt;/code&amp;gt; variable&lt;br /&gt;
* use the variable to add an object file target to the &amp;lt;code&amp;gt;OBJ&amp;lt;/code&amp;gt; variable&lt;br /&gt;
* use the variable to add a source file target to the &amp;lt;code&amp;gt;SRC&amp;lt;/code&amp;gt; variable&lt;br /&gt;
* add the test target to the &amp;lt;code&amp;gt;alltests&amp;lt;/code&amp;gt; target&lt;br /&gt;
* add the target to execute the test&lt;br /&gt;
* add the target to build the test executable&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# test/Makefile&lt;br /&gt;
HEARTBEATTEST=  heartbeat_test&lt;br /&gt;
EXE=  ... $(HEARTBEATTEST)$(EXE_EXT)&lt;br /&gt;
OBJ= ... $(HEARTBEATTEST).o&lt;br /&gt;
SRC= ... $(HEARTBEATTEST).c&lt;br /&gt;
alltests: \&lt;br /&gt;
        ... test_heartbeat&lt;br /&gt;
&lt;br /&gt;
test_heartbeat: $(HEARTBEATTEST)$(EXE_EXT)&lt;br /&gt;
  ../util/shlib_wrap.sh ./$(HEARTBEATTEST)&lt;br /&gt;
&lt;br /&gt;
$(HEARTBEATTEST)$(EXE_EXT): $(HEARTBEATTEST).o $(DLIBCRYPTO)&lt;br /&gt;
  @target=$(HEARTBEATTEST); $(BUILD_CMD)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Run &amp;lt;code&amp;gt;make depend&amp;lt;/code&amp;gt; ===&lt;br /&gt;
Finally, run &amp;lt;code&amp;gt;make depend&amp;lt;/code&amp;gt; to automatically generate the header file dependencies.&lt;br /&gt;
&lt;br /&gt;
=== Building and Running the Test ===&lt;br /&gt;
If you're initially developing on Mac OS X or (for now) FreeBSD 10, just use the stock method of building and testing:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ config &amp;amp;&amp;amp; make &amp;amp;&amp;amp; make test&lt;br /&gt;
&lt;br /&gt;
# To execute just one specific test&lt;br /&gt;
$ TESTS=test_heartbeat make test &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Ultimately the test will have to compile and pass with developer flags enabled:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ ./GitConfigure debug-ben-debug-64-clang&lt;br /&gt;
$ ./GitMake -j 2&lt;br /&gt;
$ ./GitMake test&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above currently doesn't work on Mac OS X or FreeBSD 10; for now, you can install the latest 9.x release of [http://www.freebsd.org/ FreeBSD] via a virtualization platform such as [https://www.virtualbox.org/ VirtualBox].&lt;br /&gt;
&lt;br /&gt;
== Style ==&lt;br /&gt;
[http://mike-bland.com/2014/06/05/pseudo-xunit-pattern.html The Pseudo-xUnit Pattern] is that established by [http://git.openssl.org/gitweb/?p=openssl.git;a=blob;f=ssl/heartbeat_test.c ssl/heartbeat_test.c]. This pattern organizes code in a fashion reminiscent of the [http://en.wikipedia.org/wiki/XUnit xUnit] family of unit testing frameworks, without actually using a testing framework. This should lower the barrier to entry for people wanting to write unit tests, but enable a relatively easy migration to an xUnit-based framework if we decide to do so one day.&lt;br /&gt;
&lt;br /&gt;
Some of the basic principles to follow are:&lt;br /&gt;
&lt;br /&gt;
=== Define a fixture structure ===&lt;br /&gt;
The fixture structure should contain all of the inputs to the code under test and all of the expected result values. It should also contain a &amp;lt;code&amp;gt;const char*&amp;lt;/code&amp;gt; for the name of the test case function that created it, to aid in error message formatting. Even though the fixture may contain dynamically-allocated members, the fixture itself should be copied by value to reduce the necessary degree of memory management in a small unit test program.&lt;br /&gt;
&lt;br /&gt;
=== Define set_up() and tear_down() functions for the fixture ===&lt;br /&gt;
&amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; should return a newly-initialized test fixture structure. It should take the name of the test case as an argument (i.e. &amp;lt;code&amp;gt;__func__&amp;lt;/code&amp;gt;) and assign it to the fixture. All of the fixture members should be initialized, which each test case function can then override as needed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;tear_down()&amp;lt;/code&amp;gt; should take the fixture as an argument and release any resources allocated by &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt;. It can also call any library-wide error printing routines (e.g. &amp;lt;code&amp;gt;ERR_print_errors_fp(stderr)&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Each test case function should call &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; as its first statement, and should call &amp;lt;code&amp;gt;tear_down()&amp;lt;/code&amp;gt; just before returning.&lt;br /&gt;
&lt;br /&gt;
=== Use test case functions, not a table of fixtures ===&lt;br /&gt;
Individual test case functions that call a common execution function are much more readable and maintainable than a loop over a table of fixture structures. Explicit fixture variable assignments aid comprehension when reading a specific test case, which saves time and energy when trying to understand a test or diagnose a failure. When a new member is added to an existing fixture, &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; can set a default for all test cases, and only the test cases that rely on that new member need to be updated.&lt;br /&gt;
&lt;br /&gt;
=== Use very descriptive test case names ===&lt;br /&gt;
Give tests long, descriptive names that provide ample context for the details of the test case. Good test names are also help produce good error messages.&lt;br /&gt;
&lt;br /&gt;
=== Group test cases into &amp;quot;suites&amp;quot; by naming convention ===&lt;br /&gt;
Give logically-related tests the same prefix, e.g. &amp;lt;code&amp;gt;test_dtls1_&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;test_tls1&amp;lt;/code&amp;gt; from &amp;lt;code&amp;gt;ssl/heartbeat_test.c&amp;lt;/code&amp;gt;. If need be, you can define suite-specific &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; functions that call the common &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; and elaborate on it. (This generally shouldn't be necessary for &amp;lt;code&amp;gt;tear_down()&amp;lt;/code&amp;gt;.)&lt;br /&gt;
&lt;br /&gt;
=== Keep individual test case functions focused on one thing ===&lt;br /&gt;
If the test name contains the word &amp;quot;and&amp;quot;, consider breaking it into two or more separate test case functions.&lt;br /&gt;
&lt;br /&gt;
=== Write very descriptive error messages ===&lt;br /&gt;
Include the test case function name in each error message, and explain in detail the context for the assertion that failed. Include the expected result (contained in the fixture structure) and the actual result returned from the code under test. Write helper methods for complex values as needed (e.g. &amp;lt;code&amp;gt;print_payload()&amp;lt;/code&amp;gt; in &amp;lt;code&amp;gt;ssl/heartbeat_test.c&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
=== Return zero on success and one on failure ===&lt;br /&gt;
The return value will be used to tally the number of test cases that failed. Even if multiple assertions fail for a single test case, the result should be exactly one.&lt;br /&gt;
&lt;br /&gt;
=== Add each test case function to the test runner function ===&lt;br /&gt;
Whatever function is used to execute the batch of test case functions, be that &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt; or a separate function called by &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt;, don't forget to add your test case functions to that function.&lt;br /&gt;
&lt;br /&gt;
TODO(mbland): create some kind of automated script or editor macros?&lt;br /&gt;
&lt;br /&gt;
=== Report the number of test cases that failed ===&lt;br /&gt;
Add up the total number of failed test cases in &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt; and report that number as the last error message of the test. &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt; should return &amp;lt;code&amp;gt;EXIT_FAILURE&amp;lt;/code&amp;gt; if any test cases failed, &amp;lt;code&amp;gt;EXIT_SUCCESS&amp;lt;/code&amp;gt; otherwise.&lt;br /&gt;
&lt;br /&gt;
=== Disable for Windows (for now) ===&lt;br /&gt;
Until we solve the private-symbol problem on Windows, we will need to wrap our unit test code in the following &amp;lt;code&amp;gt;#ifdef&amp;lt;/code&amp;gt; block:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#if !defined(OPENSSL_SYS_WINDOWS)&lt;br /&gt;
&lt;br /&gt;
/* All the test code, including main() */&lt;br /&gt;
&lt;br /&gt;
int main(int argc, char *argv[])                                                &lt;br /&gt;
    {&lt;br /&gt;
        return EXIT_SUCCESS;                                                    &lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
#endif /* OPENSSL_NO_WINDOWS  */&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Samples ==&lt;br /&gt;
Existing tests that can be used as models for new tests.&lt;br /&gt;
* [http://git.openssl.org/gitweb/?p=openssl.git;a=blob;f=ssl/heartbeat_test.c ssl/heartbeat_test.c]: Follows [http://mike-bland.com/2014/06/05/pseudo-xunit-pattern.html the Pseudo-xUnit pattern]&lt;/div&gt;</summary>
		<author><name>Mbland</name></author>
	</entry>
	<entry>
		<id>https://wiki.openssl.org/index.php?title=How_To_Write_Unit_Tests_For_OpenSSL&amp;diff=1716</id>
		<title>How To Write Unit Tests For OpenSSL</title>
		<link rel="alternate" type="text/html" href="https://wiki.openssl.org/index.php?title=How_To_Write_Unit_Tests_For_OpenSSL&amp;diff=1716"/>
		<updated>2014-06-06T16:02:05Z</updated>

		<summary type="html">&lt;p&gt;Mbland: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This is an outline of the basic process and principles to follow when writing unit tests. This document will evolve quite a bit as the community gains experience.&lt;br /&gt;
&lt;br /&gt;
==Mechanics ==&lt;br /&gt;
=== Forking the Repo ===&lt;br /&gt;
For now, people contributing new unit tests for uncovered code (as opposed to submitting tests with new code changes) should fork [https://github.com/mbland/openssl Mike Bland's GitHub repository] and issue [https://help.github.com/articles/using-pull-requests GitHub pull requests]. Remember to do all development on a topic branch (not &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt;). Tests committed to this repo will occasionally get merged into the master OpenSSL repo.&lt;br /&gt;
&lt;br /&gt;
Rationale per Matt Caswell: We should think about process here. If you are going off to recruit an army of people writing tests then I wonder if it is worth setting up a separate github repository whilst you are building up the tests. We can then merge in from that on a periodic basis. I wouldn't want availability of openssl team committers to be a bottle neck.&lt;br /&gt;
&lt;br /&gt;
=== Use the Test Template Generator ===&lt;br /&gt;
TODO(mbland): Get template generator checked-in. Maybe have a template generator for each library, e.g. &amp;lt;code&amp;gt;ssl/new-test.sh&amp;lt;/code&amp;gt; that has additional setup boilerplate specific to the &amp;lt;code&amp;gt;ssl&amp;lt;/code&amp;gt; library.&lt;br /&gt;
&lt;br /&gt;
Use the &amp;lt;code&amp;gt;test/new-test.sh&amp;lt;/code&amp;gt; script to generate a skeleton test file.&lt;br /&gt;
&lt;br /&gt;
=== Add Makefile Targets ===&lt;br /&gt;
The following instructions use the &amp;lt;code&amp;gt;Makefile&amp;lt;/code&amp;gt; targets for &amp;lt;code&amp;gt;ssl/heartbeat_test.c&amp;lt;/code&amp;gt; as an example.&lt;br /&gt;
&lt;br /&gt;
In the &amp;lt;code&amp;gt;Makefile&amp;lt;/code&amp;gt; for the library containing the test, add the test source file to the &amp;lt;code&amp;gt;TEST&amp;lt;/code&amp;gt; variable:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# ssl/Makefile&lt;br /&gt;
TEST=ssltest.c heartbeat_test.c&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In &amp;lt;code&amp;gt;test/Makefile&amp;lt;/code&amp;gt;:&lt;br /&gt;
* add a variable for the test target near the top of the file, right after the existing test variables&lt;br /&gt;
* use the variable to add an executable target to the &amp;lt;code&amp;gt;EXE&amp;lt;/code&amp;gt; variable&lt;br /&gt;
* use the variable to add an object file target to the &amp;lt;code&amp;gt;OBJ&amp;lt;/code&amp;gt; variable&lt;br /&gt;
* use the variable to add a source file target to the &amp;lt;code&amp;gt;SRC&amp;lt;/code&amp;gt; variable&lt;br /&gt;
* add the test target to the &amp;lt;code&amp;gt;alltests&amp;lt;/code&amp;gt; target&lt;br /&gt;
* add the target to execute the test&lt;br /&gt;
* add the target to build the test executable&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# test/Makefile&lt;br /&gt;
HEARTBEATTEST=  heartbeat_test&lt;br /&gt;
EXE=  ... $(HEARTBEATTEST)$(EXE_EXT)&lt;br /&gt;
OBJ= ... $(HEARTBEATTEST).o&lt;br /&gt;
SRC= ... $(HEARTBEATTEST).c&lt;br /&gt;
alltests: \&lt;br /&gt;
        ... test_heartbeat&lt;br /&gt;
&lt;br /&gt;
test_heartbeat: $(HEARTBEATTEST)$(EXE_EXT)&lt;br /&gt;
  ../util/shlib_wrap.sh ./$(HEARTBEATTEST)&lt;br /&gt;
&lt;br /&gt;
$(HEARTBEATTEST)$(EXE_EXT): $(HEARTBEATTEST).o $(DLIBCRYPTO)&lt;br /&gt;
  @target=$(HEARTBEATTEST); $(BUILD_CMD)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Run &amp;lt;code&amp;gt;make depend&amp;lt;/code&amp;gt; ===&lt;br /&gt;
Finally, run &amp;lt;code&amp;gt;make depend&amp;lt;/code&amp;gt; to automatically generate the header file dependencies.&lt;br /&gt;
&lt;br /&gt;
=== Building and Running the Test ===&lt;br /&gt;
If you're initially developing on Mac OS X or (for now) FreeBSD 10, just use the stock method of building and testing:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ config &amp;amp;&amp;amp; make &amp;amp;&amp;amp; make test&lt;br /&gt;
&lt;br /&gt;
# To execute just one specific test&lt;br /&gt;
$ TESTS=test_heartbeat make test &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Ultimately the test will have to compile and pass with developer flags enabled:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ ./GitConfigure debug-ben-debug-64-clang&lt;br /&gt;
$ ./GitMake -j 2&lt;br /&gt;
$ ./GitMake test&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above currently doesn't work on Mac OS X or FreeBSD 10; for now, you can install the latest 9.x release of [http://www.freebsd.org/ FreeBSD] via a virtualization platform such as [https://www.virtualbox.org/ VirtualBox].&lt;br /&gt;
&lt;br /&gt;
== Style ==&lt;br /&gt;
[http://mike-bland.com/2014/06/05/pseudo-xunit-pattern.html The Pseudo-xUnit Pattern] is that established by [http://git.openssl.org/gitweb/?p=openssl.git;a=blob;f=ssl/heartbeat_test.c ssl/heartbeat_test.c]. This pattern organizes code in a fashion reminiscent of the [http://en.wikipedia.org/wiki/XUnit xUnit] family of unit testing frameworks, without actually using a testing framework. This should lower the barrier to entry for people wanting to write unit tests, but enable a relatively easy migration to an xUnit-based framework if we decide to do so one day.&lt;br /&gt;
&lt;br /&gt;
Some of the basic principles to follow are:&lt;br /&gt;
&lt;br /&gt;
=== Define a fixture structure ===&lt;br /&gt;
The fixture structure should contain all of the inputs to the code under test and all of the expected result values. It should also contain a &amp;lt;code&amp;gt;const char*&amp;lt;/code&amp;gt; for the name of the test case function that created it, to aid in error message formatting. Even though the fixture may contain dynamically-allocated members, the fixture itself should be copied by value to reduce the necessary degree of memory management in a small unit test program.&lt;br /&gt;
&lt;br /&gt;
=== Define set_up() and tear_down() functions for the fixture ===&lt;br /&gt;
&amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; should return a newly-initialized test fixture structure. It should take the name of the test case as an argument (i.e. &amp;lt;code&amp;gt;__func__&amp;lt;/code&amp;gt;) and assign it to the fixture. All of the fixture members should be initialized, which each test case function can then override as needed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;tear_down()&amp;lt;/code&amp;gt; should take the fixture as an argument and release any resources allocated by &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt;. It can also call any library-wide error printing routines (e.g. &amp;lt;code&amp;gt;ERR_print_errors_fp(stderr)&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Each test case function should call &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; as its first statement, and should call &amp;lt;code&amp;gt;tear_down()&amp;lt;/code&amp;gt; just before returning.&lt;br /&gt;
&lt;br /&gt;
=== Use test case functions, not a table of fixtures ===&lt;br /&gt;
Individual test case functions that call a common execution function are much more readable and maintainable than a loop over a table of fixture structures. Explicit fixture variable assignments aid comprehension when reading a specific test case, which saves time and energy when trying to understand a test or diagnose a failure. When a new member is added to an existing fixture, &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; can set a default for all test cases, and only the test cases that rely on that new member need to be updated.&lt;br /&gt;
&lt;br /&gt;
=== Use very descriptive test case names ===&lt;br /&gt;
Give tests long, descriptive names that provide ample context for the details of the test case. Good test names are also help produce good error messages.&lt;br /&gt;
&lt;br /&gt;
=== Group test cases into &amp;quot;suites&amp;quot; by naming convention ===&lt;br /&gt;
Give logically-related tests the same prefix, e.g. &amp;lt;code&amp;gt;test_dtls1_&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;test_tls1&amp;lt;/code&amp;gt; from &amp;lt;code&amp;gt;ssl/heartbeat_test.c&amp;lt;/code&amp;gt;. If need be, you can define suite-specific &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; functions that call the common &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; and elaborate on it. (This generally shouldn't be necessary for &amp;lt;code&amp;gt;tear_down()&amp;lt;/code&amp;gt;.)&lt;br /&gt;
&lt;br /&gt;
=== Keep individual test case functions focused on one thing ===&lt;br /&gt;
If the test name contains the word &amp;quot;and&amp;quot;, consider breaking it into two or more separate test case functions.&lt;br /&gt;
&lt;br /&gt;
=== Write very descriptive error messages ===&lt;br /&gt;
Include the test case function name in each error message, and explain in detail the context for the assertion that failed. Include the expected result (contained in the fixture structure) and the actual result returned from the code under test. Write helper methods for complex values as needed (e.g. &amp;lt;code&amp;gt;print_payload()&amp;lt;/code&amp;gt; in &amp;lt;code&amp;gt;ssl/heartbeat_test.c&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
=== Return zero on success and one on failure ===&lt;br /&gt;
The return value will be used to tally the number of test cases that failed. Even if multiple assertions fail for a single test case, the result should be exactly one.&lt;br /&gt;
&lt;br /&gt;
=== Add each test case function to the test runner function ===&lt;br /&gt;
Whatever function is used to execute the batch of test case functions, be that &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt; or a separate function called by &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt;, don't forget to add your test case functions to that function.&lt;br /&gt;
&lt;br /&gt;
TODO(mbland): create some kind of automated script or editor macros?&lt;br /&gt;
&lt;br /&gt;
=== Report the number of test cases that failed ===&lt;br /&gt;
Add up the total number of failed test cases in &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt; and report that number as the last error message of the test. &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt; should return &amp;lt;code&amp;gt;EXIT_FAILURE&amp;lt;/code&amp;gt; if any test cases failed, &amp;lt;code&amp;gt;EXIT_SUCCESS&amp;lt;/code&amp;gt; otherwise.&lt;br /&gt;
&lt;br /&gt;
=== Disable for Windows (for now) ===&lt;br /&gt;
Until we solve the private-symbol problem on Windows, we will need to wrap our unit test code in the following &amp;lt;code&amp;gt;#ifdef&amp;lt;/code&amp;gt; block:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#if !defined(OPENSSL_SYS_WINDOWS)&lt;br /&gt;
&lt;br /&gt;
/* All the test code, including main() */&lt;br /&gt;
&lt;br /&gt;
int main(int argc, char *argv[])                                                &lt;br /&gt;
    {&lt;br /&gt;
        return EXIT_SUCCESS;                                                    &lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
#endif /* OPENSSL_NO_WINDOWS  */&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Samples ==&lt;br /&gt;
Existing tests that can be used as models for new tests.&lt;br /&gt;
* [http://git.openssl.org/gitweb/?p=openssl.git;a=blob;f=ssl/heartbeat_test.c ssl/heartbeat_test.c]: Follows [http://mike-bland.com/2014/06/05/pseudo-xunit-pattern.html the Pseudo-xUnit pattern]&lt;/div&gt;</summary>
		<author><name>Mbland</name></author>
	</entry>
	<entry>
		<id>https://wiki.openssl.org/index.php?title=Unit_Testing&amp;diff=1715</id>
		<title>Unit Testing</title>
		<link rel="alternate" type="text/html" href="https://wiki.openssl.org/index.php?title=Unit_Testing&amp;diff=1715"/>
		<updated>2014-06-06T15:57:30Z</updated>

		<summary type="html">&lt;p&gt;Mbland: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page will track the effort to improve unit test and other automated test coverage for OpenSSL. Everyone is encouraged to help with this effort, but this page will track which community members have accepted specific responsibilities, and what tasks are currently underway.&lt;br /&gt;
&lt;br /&gt;
== Team ==&lt;br /&gt;
We can define new roles as needed. The success of this effort will be inversely proportional to the number of roles with any one individual's name next to them. Each role can have more than one person filling it, but needs specific people to fill them. &lt;br /&gt;
&lt;br /&gt;
The point is not to tell people what to do and not do: it’s to establish clear responsibilities so everyone can run with them right away and begin applying their creative energy to solutions, rather than waste it figuring out what the hell is going on, what they should do to contribute, and who they need to coordinate with to get things done.&lt;br /&gt;
&lt;br /&gt;
'''Organizer''': [mailto:mbland@acm.org Mike Bland]&amp;lt;br /&amp;gt;&lt;br /&gt;
Ensures the overall effort is making progress by facilitating communication, removing obstacles, and making hands-on contributions when necessary.&lt;br /&gt;
&lt;br /&gt;
'''Tech Writer''': [mailto:mbland@acm.org Mike Bland], Sandeep Mankar, Chelsea Komlo, Graham Brooks&amp;lt;br /&amp;gt;&lt;br /&gt;
Maintains documentation of tools, techniques, outstanding issues, etc. May maintain a code review/testing style guide based on the community consensus. Also documents who currently fills each role, as well as who might've filled it in the past.&lt;br /&gt;
&lt;br /&gt;
'''Buildmaster''': [mailto:mbland@acm.org Mike Bland], Isaac Truett, Dileep Bapat, Graham Brooks&amp;lt;br /&amp;gt;&lt;br /&gt;
Sets up and maintains automated builds and any infrastructure used to monitor them and report breakage.&lt;br /&gt;
&lt;br /&gt;
'''Toolsmith''': Tony Aiuto&lt;br /&gt;
Maintains any tools and frameworks that are a part of the core build process; proposes, integrates, and/or retires existing tools.&lt;br /&gt;
&lt;br /&gt;
'''Tutor''': [mailto:mbland@acm.org Mike Bland], Darshan Mody, Tom Francis, Brian N. Makin, Chelsea Komlo, Edward Knapp, Dileep Bapat, Graham Brooks&amp;lt;br /&amp;gt;&lt;br /&gt;
Helps contributors, particularly new contributors, with the details of writing unit or other automated tests. May be assigned by the reviewer of a patch to help a contributor get a new change under test. Submission of the patch should require the approval of the tutor in most cases. (Should ideally be more than one person.)&lt;br /&gt;
&lt;br /&gt;
== Goals ==&lt;br /&gt;
We can add more concrete goals to this list after we make progress on these. Getting people to own roles, setting up build infrastructure, and setting and enforcing policy are important first steps. Upon that foundation, we can begin to make serious progress towards improved test coverage, code quality, and defect prevention.&lt;br /&gt;
* Establish a written contribution/code review policy that requires:&lt;br /&gt;
** tests for every new code change, except for very trivial changes that do not directly impact program logic (e.g. documentation fixes, string constant updates, build script tweaks); this can be limited to an agreed-upon subset of the code to start, but would hopefully be expanded to cover most, if not all, of the code base&lt;br /&gt;
** tests for every bugfix &lt;br /&gt;
** smaller, well-tested changes building up to a complete feature (as opposed to large and/or untested changes that implement a large, complex feature all at once) &lt;br /&gt;
* Establish a schedule of Build Cops and Tutors to begin enforcing rollbacks/fixes and to help shepherd new contributors through the testing process.&lt;br /&gt;
* Set up a series of publicly-accessible continuous integration servers using whatever system the community prefers (e.g. Jenkins, Buildbot, etc.). These can be dedicated hardware or possibly Amazon Web Services-based. Establish a written policy that these remain green at all times, and that breakages be rolled-back or fixed within no more than 30 minutes. &lt;br /&gt;
&lt;br /&gt;
== Tasks ==&lt;br /&gt;
The current list is posted in the [http://goo.gl/5u9nbw OpenSSL Testing Tasks Google Spreadsheet].&lt;br /&gt;
&lt;br /&gt;
(Would be nice to enable the [http://www.mediawiki.org/wiki/Extension:Widget MediaWiki Widget extension] and the [http://www.mediawikiwidgets.org/Google_Spreadsheet Google Spreadsheet widget].)&lt;br /&gt;
&lt;br /&gt;
== Howtos and Style Guides ==&lt;br /&gt;
Documents that provide background on specific testing issues and idioms should be linked from here.&lt;br /&gt;
&lt;br /&gt;
* [[How To Write Unit Tests For OpenSSL]]&lt;br /&gt;
* [http://mike-bland.com/2014/06/05/pseudo-xunit-pattern.html The Pseudo-xUnit Pattern]&lt;br /&gt;
&lt;br /&gt;
== Discussion Topics ==&lt;br /&gt;
These are discussions related to some of the current testing tasks.&lt;br /&gt;
&lt;br /&gt;
=== First Area of Focus ===&lt;br /&gt;
Matt Caswell: One criterion might be ease of testing. If you were going down that route you might choose some of the low level packages within libcrypto which are relatively self-contained. I'm not talking about the crypto algorithms themselves (there are at least *some* tests for those), I'm thinking more about bio, pem, x509, x509v3, etc.&lt;br /&gt;
&lt;br /&gt;
Another criterion might be where you get the most value. I suspect we will get the most value from a really good set of unit tests for libssl. I suspect this might be a big ask to start off with (you would probably have to mock out a lot of stuff).&lt;br /&gt;
&lt;br /&gt;
=== Build Systems/Machines ===&lt;br /&gt;
Where can we get the machines? Is someone willing to donate them? What system should we use?&lt;br /&gt;
&lt;br /&gt;
=== Get Unit Tests to Build on Windows ===&lt;br /&gt;
Steve Henson on building ssl/heartbeat_test.c on Windows: The first problem is that __func__ isn't understood. Changing that to __FUNCTION__ resolves that easily enough.&lt;br /&gt;
&lt;br /&gt;
The second problem is more serious. Windows (and a couple of other platforms IIRC) is strict about only exporting approved symbols from global headers in shared libraries and wont export internal only functions.&lt;br /&gt;
&lt;br /&gt;
That means you get linker errors:&lt;br /&gt;
&lt;br /&gt;
heartbeat_test.obj : error LNK2019: unresolved external symbol _ssl3_setup_buffe&lt;br /&gt;
rs referenced in function _set_up&lt;br /&gt;
heartbeat_test.obj : error LNK2019: unresolved external symbol _ssl_init_wbio_bu&lt;br /&gt;
ffer referenced in function _set_up&lt;br /&gt;
heartbeat_test.obj : error LNK2019: unresolved external symbol _tls1_process_hea&lt;br /&gt;
rtbeat referenced in function _set_up_tls&lt;br /&gt;
heartbeat_test.obj : error LNK2019: unresolved external symbol _dtls1_process_he&lt;br /&gt;
artbeat referenced in function _set_up_dtls&lt;br /&gt;
out32dll\heartbeat_test.exe : fatal error LNK1120: 4 unresolved externals&lt;br /&gt;
NMAKE : fatal error U1077: '&amp;quot;C:\Program Files (x86)\Microsoft Visual Studio 11.0&lt;br /&gt;
\VC\BIN\link.EXE&amp;quot;' : return code '0x460'&lt;br /&gt;
&lt;br /&gt;
Potential solutions:&lt;br /&gt;
* http://stackoverflow.com/questions/7759777/is-it-possible-to-test-internal-class-from-a-c-dll-using-mstest&lt;br /&gt;
* http://stackoverflow.com/questions/19934714/googletest-c-unit-testing-linking-error&lt;br /&gt;
* http://stackoverflow.com/questions/14010627/unresolved-externals-when-compiling-unit-tests-for-visual-c-2012&lt;br /&gt;
&lt;br /&gt;
ifdef'd out (for now): https://github.com/openssl/openssl/commit/7ce79a5bfdbcd53ae75f85e94eed665a05b5dea3&lt;br /&gt;
&lt;br /&gt;
=== How to Manage Private Symbols ===&lt;br /&gt;
Steve Henson: As this also affects other platforms a general solution might be in order.&lt;br /&gt;
&lt;br /&gt;
One option is to link to static libraries as has been mentioned. If you have a&lt;br /&gt;
lot of unit tests you could end up with a lot of large binaries. Would need some&lt;br /&gt;
changes to the dreaded Windows build system too.&lt;br /&gt;
&lt;br /&gt;
A different option would be to export the unit test functions through a&lt;br /&gt;
structure pointer which a function returns. So you'd have something like..&lt;br /&gt;
&lt;br /&gt;
unit_test = SSL_get_unit_test_funcs();&lt;br /&gt;
&lt;br /&gt;
unit_test.some_internal_funcction(...);&lt;br /&gt;
&lt;br /&gt;
Where the actual structure is opaque to applications (so they aren't tempted to&lt;br /&gt;
poke around in internals) but visible to the unit test code. Then the unit test&lt;br /&gt;
code doesn't call any internal functions not defined in there and doesn't need&lt;br /&gt;
to load private headers (unless it needs them for some definitions).&lt;br /&gt;
&lt;br /&gt;
Mike Bland: This is an interesting idea, though I'd expect the unit tests will&lt;br /&gt;
still need access to internal headers.&lt;br /&gt;
&lt;br /&gt;
But I have a question: Why do any of the symbols need to be private?&lt;br /&gt;
Is that degree of encapsulation necessary, and does it really&lt;br /&gt;
discourage irresponsible clients? The source code is open, so people&lt;br /&gt;
can always build their own copy and depend on internals if they really&lt;br /&gt;
want to, and the default UNIX/Linux/OS X build (i.e. ./configure &amp;amp;&amp;amp;&lt;br /&gt;
make &amp;amp;&amp;amp; make test) doesn't lock down internal symbols. Have&lt;br /&gt;
dependencies on internal APIs ever been a problem in practice?&lt;br /&gt;
&lt;br /&gt;
I'm not saying I feel strongly either way, but it seems that clients&lt;br /&gt;
should be clear that the public API is what's available in&lt;br /&gt;
openssl/include, and shouldn't depend on anything else. I just don't&lt;br /&gt;
understand what making symbols private buys anyone in the context of&lt;br /&gt;
OpenSSL, in light of how it appears to complicate the ability to unit&lt;br /&gt;
test.&lt;br /&gt;
&lt;br /&gt;
Not trying to be argumentative, I just want to understand the&lt;br /&gt;
rationale. I'll work with whatever environment I have to.&lt;br /&gt;
&lt;br /&gt;
=== Improved Patch/Cherry-pick Process ===&lt;br /&gt;
Geoff Thorpe: (a) patches that are not applied/cherry-picked to all the branches they apply to, or (b) applied to more branches than they should be. A complication of (a) is that some patches may need to be reworked in order to apply (or in order to not break binary compatibility of a stable branch). The difficulty of (b) is determining when the nature of the change either breaks binary compatibility or causes some other behavioral deviation that is not in keeping with the &amp;quot;promises&amp;quot; of stable branches.&lt;br /&gt;
&lt;br /&gt;
http://ispras.linuxbase.org/index.php/ABI_compliance_checker&lt;br /&gt;
https://github.com/lvc/abi-compliance-checker/&lt;br /&gt;
&lt;br /&gt;
Geoff on 2014-05-30: ...we might move to a scheme whereby we only maintain one most-recent stable branch for production releases, with snapshots or whatever of the development head. Ie. two branches, one for maximum-compatibility/bug-fixes-only, and the other for more active development. The number of &amp;quot;stable&amp;quot; branches would thus be 1 rather than 'n'. The idea is that we may defer to downstream &amp;quot;slow-moving&amp;quot; users (eg. long-term releases of linux distros) the opportunity to step up and do the work of maintaining (cherry-picking, back-porting, ...) older branches. Ie. what they typically already do in-house, but the opportunity to do it under our roof and thus combine their efforts with any other similarly-interested parties. If there's noone prepared to do that, the logical conclusion is that there is probably no need for it (or so the argument goes).&lt;br /&gt;
&lt;br /&gt;
=== Improve/Standardize Algorithm Testing ===&lt;br /&gt;
Steve Henson: While the algorithms are partly tested I don't think they're anything like comprehensive enough. The way they are handled is also haphazard and spread across multiple tests covering all sorts of odd APIs, some of which are deprecated.&lt;br /&gt;
&lt;br /&gt;
In fact I'd say they're (with the odd exception) an example of how *not* to do things.&lt;br /&gt;
&lt;br /&gt;
Examples rc2test tests RC2 it has various test vectors hard coded inconsistent indentation and use of low level APIs. The rc4test is a similar story and uses a different format to rc2test. The same tale is repeated all over the place with ideatest, rmdtest etc etc.&lt;br /&gt;
&lt;br /&gt;
Then we come to the code which I think is closest to how things should be which is evp_test. It uses the standard high level EVP API the format is consistent (if undocumented) and adding new tests can be done simply by editing a text file.&lt;br /&gt;
&lt;br /&gt;
It currently however only works for some algorithms and the text file format could be better. It currently doesn't handle public key algorithms or test variants of the same algorithm (e.g. AES-NI versus non AES-NI) either.&lt;br /&gt;
&lt;br /&gt;
=== Develop SSL/TLS Stack and Other Tools ===&lt;br /&gt;
Steve Henson: The heartbeat bug is an example where you can perform some testing without a complete SSL/TLS stack. However looking through the code in heartbeat_test.c it uses a lot of functionality which would normally be strictly off-limits for an application.&lt;br /&gt;
&lt;br /&gt;
Some bugs are far more subtle and harder to test. For example some involve doing *almost* everything right and then slipping in some illegal parameter or badly formatted message. If you want to do that in a standalone bit of code you need a near complete SSL/TLS stack.&lt;br /&gt;
&lt;br /&gt;
I can think of a couple of ways to handle that. One is to have some kind of hooks in libssl so testing code can misbehave and send out illegal messages in controlled ways (I had a prototype &amp;quot;bad heartbeat&amp;quot; API which only added a couple of lines to libssl). An alternative would be to write some kind of tiny SSL/TLS code used only by the test programs and carefully tailored to permit such things.&lt;/div&gt;</summary>
		<author><name>Mbland</name></author>
	</entry>
	<entry>
		<id>https://wiki.openssl.org/index.php?title=Unit_Testing&amp;diff=1714</id>
		<title>Unit Testing</title>
		<link rel="alternate" type="text/html" href="https://wiki.openssl.org/index.php?title=Unit_Testing&amp;diff=1714"/>
		<updated>2014-06-06T15:50:46Z</updated>

		<summary type="html">&lt;p&gt;Mbland: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page will track the effort to improve unit test and other automated test coverage for OpenSSL. Everyone is encouraged to help with this effort, but this page will track which community members have accepted specific responsibilities, and what tasks are currently underway.&lt;br /&gt;
&lt;br /&gt;
== Team ==&lt;br /&gt;
We can define new roles as needed. The success of this effort will be inversely proportional to the number of roles with any one individual's name next to them. Each role can have more than one person filling it, but needs specific people to fill them. &lt;br /&gt;
&lt;br /&gt;
The point is not to tell people what to do and not do: it’s to establish clear responsibilities so everyone can run with them right away and begin applying their creative energy to solutions, rather than waste it figuring out what the hell is going on, what they should do to contribute, and who they need to coordinate with to get things done.&lt;br /&gt;
&lt;br /&gt;
'''Organizer''': [mailto:mbland@acm.org Mike Bland]&amp;lt;br /&amp;gt;&lt;br /&gt;
Ensures the overall effort is making progress by facilitating communication, removing obstacles, and making hands-on contributions when necessary.&lt;br /&gt;
&lt;br /&gt;
'''Tech Writer''': [mailto:mbland@acm.org Mike Bland], Sandeep Mankar, Chelsea Komlo&amp;lt;br /&amp;gt;&lt;br /&gt;
Maintains documentation of tools, techniques, outstanding issues, etc. May maintain a code review/testing style guide based on the community consensus. Also documents who currently fills each role, as well as who might've filled it in the past.&lt;br /&gt;
&lt;br /&gt;
'''Buildmaster''': [mailto:mbland@acm.org Mike Bland], Isaac Truett, Dileep Bapat&amp;lt;br /&amp;gt;&lt;br /&gt;
Sets up and maintains automated builds and any infrastructure used to monitor them and report breakage.&lt;br /&gt;
&lt;br /&gt;
'''Toolsmith''': Tony Aiuto&lt;br /&gt;
Maintains any tools and frameworks that are a part of the core build process; proposes, integrates, and/or retires existing tools.&lt;br /&gt;
&lt;br /&gt;
'''Tutor''': [mailto:mbland@acm.org Mike Bland], Darshan Mody, Tom Francis, Brian N. Makin, Chelsea Komlo, Edward Knapp, Dileep Bapat&amp;lt;br /&amp;gt;&lt;br /&gt;
Helps contributors, particularly new contributors, with the details of writing unit or other automated tests. May be assigned by the reviewer of a patch to help a contributor get a new change under test. Submission of the patch should require the approval of the tutor in most cases. (Should ideally be more than one person.)&lt;br /&gt;
&lt;br /&gt;
== Goals ==&lt;br /&gt;
We can add more concrete goals to this list after we make progress on these. Getting people to own roles, setting up build infrastructure, and setting and enforcing policy are important first steps. Upon that foundation, we can begin to make serious progress towards improved test coverage, code quality, and defect prevention.&lt;br /&gt;
* Establish a written contribution/code review policy that requires:&lt;br /&gt;
** tests for every new code change, except for very trivial changes that do not directly impact program logic (e.g. documentation fixes, string constant updates, build script tweaks); this can be limited to an agreed-upon subset of the code to start, but would hopefully be expanded to cover most, if not all, of the code base&lt;br /&gt;
** tests for every bugfix &lt;br /&gt;
** smaller, well-tested changes building up to a complete feature (as opposed to large and/or untested changes that implement a large, complex feature all at once) &lt;br /&gt;
* Establish a schedule of Build Cops and Tutors to begin enforcing rollbacks/fixes and to help shepherd new contributors through the testing process.&lt;br /&gt;
* Set up a series of publicly-accessible continuous integration servers using whatever system the community prefers (e.g. Jenkins, Buildbot, etc.). These can be dedicated hardware or possibly Amazon Web Services-based. Establish a written policy that these remain green at all times, and that breakages be rolled-back or fixed within no more than 30 minutes. &lt;br /&gt;
&lt;br /&gt;
== Tasks ==&lt;br /&gt;
The current list is posted in the [http://goo.gl/5u9nbw OpenSSL Testing Tasks Google Spreadsheet].&lt;br /&gt;
&lt;br /&gt;
(Would be nice to enable the [http://www.mediawiki.org/wiki/Extension:Widget MediaWiki Widget extension] and the [http://www.mediawikiwidgets.org/Google_Spreadsheet Google Spreadsheet widget].)&lt;br /&gt;
&lt;br /&gt;
== Howtos and Style Guides ==&lt;br /&gt;
Documents that provide background on specific testing issues and idioms should be linked from here.&lt;br /&gt;
&lt;br /&gt;
* [[How To Write Unit Tests For OpenSSL]]&lt;br /&gt;
* [http://mike-bland.com/2014/06/05/pseudo-xunit-pattern.html The Pseudo-xUnit Pattern]&lt;br /&gt;
&lt;br /&gt;
== Discussion Topics ==&lt;br /&gt;
These are discussions related to some of the current testing tasks.&lt;br /&gt;
&lt;br /&gt;
=== First Area of Focus ===&lt;br /&gt;
Matt Caswell: One criterion might be ease of testing. If you were going down that route you might choose some of the low level packages within libcrypto which are relatively self-contained. I'm not talking about the crypto algorithms themselves (there are at least *some* tests for those), I'm thinking more about bio, pem, x509, x509v3, etc.&lt;br /&gt;
&lt;br /&gt;
Another criterion might be where you get the most value. I suspect we will get the most value from a really good set of unit tests for libssl. I suspect this might be a big ask to start off with (you would probably have to mock out a lot of stuff).&lt;br /&gt;
&lt;br /&gt;
=== Build Systems/Machines ===&lt;br /&gt;
Where can we get the machines? Is someone willing to donate them? What system should we use?&lt;br /&gt;
&lt;br /&gt;
=== Get Unit Tests to Build on Windows ===&lt;br /&gt;
Steve Henson on building ssl/heartbeat_test.c on Windows: The first problem is that __func__ isn't understood. Changing that to __FUNCTION__ resolves that easily enough.&lt;br /&gt;
&lt;br /&gt;
The second problem is more serious. Windows (and a couple of other platforms IIRC) is strict about only exporting approved symbols from global headers in shared libraries and wont export internal only functions.&lt;br /&gt;
&lt;br /&gt;
That means you get linker errors:&lt;br /&gt;
&lt;br /&gt;
heartbeat_test.obj : error LNK2019: unresolved external symbol _ssl3_setup_buffe&lt;br /&gt;
rs referenced in function _set_up&lt;br /&gt;
heartbeat_test.obj : error LNK2019: unresolved external symbol _ssl_init_wbio_bu&lt;br /&gt;
ffer referenced in function _set_up&lt;br /&gt;
heartbeat_test.obj : error LNK2019: unresolved external symbol _tls1_process_hea&lt;br /&gt;
rtbeat referenced in function _set_up_tls&lt;br /&gt;
heartbeat_test.obj : error LNK2019: unresolved external symbol _dtls1_process_he&lt;br /&gt;
artbeat referenced in function _set_up_dtls&lt;br /&gt;
out32dll\heartbeat_test.exe : fatal error LNK1120: 4 unresolved externals&lt;br /&gt;
NMAKE : fatal error U1077: '&amp;quot;C:\Program Files (x86)\Microsoft Visual Studio 11.0&lt;br /&gt;
\VC\BIN\link.EXE&amp;quot;' : return code '0x460'&lt;br /&gt;
&lt;br /&gt;
Potential solutions:&lt;br /&gt;
* http://stackoverflow.com/questions/7759777/is-it-possible-to-test-internal-class-from-a-c-dll-using-mstest&lt;br /&gt;
* http://stackoverflow.com/questions/19934714/googletest-c-unit-testing-linking-error&lt;br /&gt;
* http://stackoverflow.com/questions/14010627/unresolved-externals-when-compiling-unit-tests-for-visual-c-2012&lt;br /&gt;
&lt;br /&gt;
ifdef'd out (for now): https://github.com/openssl/openssl/commit/7ce79a5bfdbcd53ae75f85e94eed665a05b5dea3&lt;br /&gt;
&lt;br /&gt;
=== Improved Patch/Cherry-pick Process ===&lt;br /&gt;
Geoff Thorpe: (a) patches that are not applied/cherry-picked to all the branches they apply to, or (b) applied to more branches than they should be. A complication of (a) is that some patches may need to be reworked in order to apply (or in order to not break binary compatibility of a stable branch). The difficulty of (b) is determining when the nature of the change either breaks binary compatibility or causes some other behavioral deviation that is not in keeping with the &amp;quot;promises&amp;quot; of stable branches.&lt;br /&gt;
&lt;br /&gt;
http://ispras.linuxbase.org/index.php/ABI_compliance_checker&lt;br /&gt;
https://github.com/lvc/abi-compliance-checker/&lt;br /&gt;
&lt;br /&gt;
Geoff on 2014-05-30: ...we might move to a scheme whereby we only maintain one most-recent stable branch for production releases, with snapshots or whatever of the development head. Ie. two branches, one for maximum-compatibility/bug-fixes-only, and the other for more active development. The number of &amp;quot;stable&amp;quot; branches would thus be 1 rather than 'n'. The idea is that we may defer to downstream &amp;quot;slow-moving&amp;quot; users (eg. long-term releases of linux distros) the opportunity to step up and do the work of maintaining (cherry-picking, back-porting, ...) older branches. Ie. what they typically already do in-house, but the opportunity to do it under our roof and thus combine their efforts with any other similarly-interested parties. If there's noone prepared to do that, the logical conclusion is that there is probably no need for it (or so the argument goes).&lt;br /&gt;
&lt;br /&gt;
=== Improve/Standardize Algorithm Testing ===&lt;br /&gt;
Steve Henson: While the algorithms are partly tested I don't think they're anything like comprehensive enough. The way they are handled is also haphazard and spread across multiple tests covering all sorts of odd APIs, some of which are deprecated.&lt;br /&gt;
&lt;br /&gt;
In fact I'd say they're (with the odd exception) an example of how *not* to do things.&lt;br /&gt;
&lt;br /&gt;
Examples rc2test tests RC2 it has various test vectors hard coded inconsistent indentation and use of low level APIs. The rc4test is a similar story and uses a different format to rc2test. The same tale is repeated all over the place with ideatest, rmdtest etc etc.&lt;br /&gt;
&lt;br /&gt;
Then we come to the code which I think is closest to how things should be which is evp_test. It uses the standard high level EVP API the format is consistent (if undocumented) and adding new tests can be done simply by editing a text file.&lt;br /&gt;
&lt;br /&gt;
It currently however only works for some algorithms and the text file format could be better. It currently doesn't handle public key algorithms or test variants of the same algorithm (e.g. AES-NI versus non AES-NI) either.&lt;br /&gt;
&lt;br /&gt;
=== Develop SSL/TLS Stack and Other Tools ===&lt;br /&gt;
Steve Henson: The heartbeat bug is an example where you can perform some testing without a complete SSL/TLS stack. However looking through the code in heartbeat_test.c it uses a lot of functionality which would normally be strictly off-limits for an application.&lt;br /&gt;
&lt;br /&gt;
Some bugs are far more subtle and harder to test. For example some involve doing *almost* everything right and then slipping in some illegal parameter or badly formatted message. If you want to do that in a standalone bit of code you need a near complete SSL/TLS stack.&lt;br /&gt;
&lt;br /&gt;
I can think of a couple of ways to handle that. One is to have some kind of hooks in libssl so testing code can misbehave and send out illegal messages in controlled ways (I had a prototype &amp;quot;bad heartbeat&amp;quot; API which only added a couple of lines to libssl). An alternative would be to write some kind of tiny SSL/TLS code used only by the test programs and carefully tailored to permit such things.&lt;/div&gt;</summary>
		<author><name>Mbland</name></author>
	</entry>
	<entry>
		<id>https://wiki.openssl.org/index.php?title=How_To_Write_Unit_Tests_For_OpenSSL&amp;diff=1713</id>
		<title>How To Write Unit Tests For OpenSSL</title>
		<link rel="alternate" type="text/html" href="https://wiki.openssl.org/index.php?title=How_To_Write_Unit_Tests_For_OpenSSL&amp;diff=1713"/>
		<updated>2014-06-06T15:50:35Z</updated>

		<summary type="html">&lt;p&gt;Mbland: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This is an outline of the basic process and principles to follow when writing unit tests. This document will evolve quite a bit as the community gains experience.&lt;br /&gt;
&lt;br /&gt;
==Mechanics ==&lt;br /&gt;
=== Forking the Repo ===&lt;br /&gt;
For now, people contributing new unit tests for uncovered code (as opposed to submitting tests with new code changes) should fork [https://github.com/mbland/openssl Mike Bland's GitHub repository] and issue [https://help.github.com/articles/using-pull-requests GitHub pull requests]. Remember to do all development on a topic branch (not &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt;). Tests committed to this repo will occasionally get merged into the master OpenSSL repo.&lt;br /&gt;
&lt;br /&gt;
Rationale per Matt Caswell: We should think about process here. If you are going off to recruit an army of people writing tests then I wonder if it is worth setting up a separate github repository whilst you are building up the tests. We can then merge in from that on a periodic basis. I wouldn't want availability of openssl team committers to be a bottle neck.&lt;br /&gt;
&lt;br /&gt;
=== Use the Test Template Generator ===&lt;br /&gt;
TODO(mbland): Get template generator checked-in. Maybe have a template generator for each library, e.g. &amp;lt;code&amp;gt;ssl/new-test.sh&amp;lt;/code&amp;gt; that has additional setup boilerplate specific to the &amp;lt;code&amp;gt;ssl&amp;lt;/code&amp;gt; library.&lt;br /&gt;
&lt;br /&gt;
Use the &amp;lt;code&amp;gt;test/new-test.sh&amp;lt;/code&amp;gt; script to generate a skeleton test file.&lt;br /&gt;
&lt;br /&gt;
=== Add Makefile Targets ===&lt;br /&gt;
The following instructions use the &amp;lt;code&amp;gt;Makefile&amp;lt;/code&amp;gt; targets for &amp;lt;code&amp;gt;ssl/heartbeat_test.c&amp;lt;/code&amp;gt; as an example.&lt;br /&gt;
&lt;br /&gt;
In the &amp;lt;code&amp;gt;Makefile&amp;lt;/code&amp;gt; for the library containing the test, add the test source file to the &amp;lt;code&amp;gt;TEST&amp;lt;/code&amp;gt; variable:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# ssl/Makefile&lt;br /&gt;
TEST=ssltest.c heartbeat_test.c&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In &amp;lt;code&amp;gt;test/Makefile&amp;lt;/code&amp;gt;:&lt;br /&gt;
* add a variable for the test target near the top of the file, right after the existing test variables&lt;br /&gt;
* use the variable to add an executable target to the &amp;lt;code&amp;gt;EXE&amp;lt;/code&amp;gt; variable&lt;br /&gt;
* use the variable to add an object file target to the &amp;lt;code&amp;gt;OBJ&amp;lt;/code&amp;gt; variable&lt;br /&gt;
* use the variable to add a source file target to the &amp;lt;code&amp;gt;SRC&amp;lt;/code&amp;gt; variable&lt;br /&gt;
* add the test target to the &amp;lt;code&amp;gt;alltests&amp;lt;/code&amp;gt; target&lt;br /&gt;
* add the target to execute the test&lt;br /&gt;
* add the target to build the test executable&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# test/Makefile&lt;br /&gt;
HEARTBEATTEST=  heartbeat_test&lt;br /&gt;
EXE=  ... $(HEARTBEATTEST)$(EXE_EXT)&lt;br /&gt;
OBJ= ... $(HEARTBEATTEST).o&lt;br /&gt;
SRC= ... $(HEARTBEATTEST).c&lt;br /&gt;
alltests: \&lt;br /&gt;
        ... test_heartbeat&lt;br /&gt;
&lt;br /&gt;
test_heartbeat: $(HEARTBEATTEST)$(EXE_EXT)&lt;br /&gt;
  ../util/shlib_wrap.sh ./$(HEARTBEATTEST)&lt;br /&gt;
&lt;br /&gt;
$(HEARTBEATTEST)$(EXE_EXT): $(HEARTBEATTEST).o $(DLIBCRYPTO)&lt;br /&gt;
  @target=$(HEARTBEATTEST); $(BUILD_CMD)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally, run &amp;lt;code&amp;gt;make depend&amp;lt;/code&amp;gt; to automatically generate the header file dependencies.&lt;br /&gt;
&lt;br /&gt;
=== Building and Running the Test ===&lt;br /&gt;
If you're initially developing on Mac OS X or (for now) FreeBSD 10, just use the stock method of building and testing:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ config &amp;amp;&amp;amp; make &amp;amp;&amp;amp; make test&lt;br /&gt;
&lt;br /&gt;
# To execute just one specific test&lt;br /&gt;
$ TESTS=test_heartbeat make test &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Ultimately the test will have to compile and pass with developer flags enabled:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ ./GitConfigure debug-ben-debug-64-clang&lt;br /&gt;
$ ./GitMake -j 2&lt;br /&gt;
$ ./GitMake test&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above currently doesn't work on Mac OS X or FreeBSD 10; for now, you can install the latest 9.x release of [http://www.freebsd.org/ FreeBSD] via a virtualization platform such as [https://www.virtualbox.org/ VirtualBox].&lt;br /&gt;
&lt;br /&gt;
== Style ==&lt;br /&gt;
=== Follow Pseudo-xUnit Style ===&lt;br /&gt;
[http://mike-bland.com/2014/06/05/pseudo-xunit-pattern.html The Pseudo-xUnit Pattern] is that established by [http://git.openssl.org/gitweb/?p=openssl.git;a=blob;f=ssl/heartbeat_test.c ssl/heartbeat_test.c]. This pattern organizes code in a fashion reminiscent of the [http://en.wikipedia.org/wiki/XUnit xUnit] family of unit testing frameworks, without actually using a testing framework. This should lower the barrier to entry for people wanting to write unit tests, but enable a relatively easy migration to an xUnit-based framework if we decide to do so one day.&lt;br /&gt;
&lt;br /&gt;
Some of the basic principles to follow are:&lt;br /&gt;
&lt;br /&gt;
==== Define a fixture structure ====&lt;br /&gt;
The fixture structure should contain all of the inputs to the code under test and all of the expected result values. It should also contain a &amp;lt;code&amp;gt;const char*&amp;lt;/code&amp;gt; for the name of the test case function that created it, to aid in error message formatting. Even though the fixture may contain dynamically-allocated members, the fixture itself should be copied by value to reduce the necessary degree of memory management in a small unit test program.&lt;br /&gt;
&lt;br /&gt;
==== Define set_up() and tear_down() functions for the fixture ====&lt;br /&gt;
&amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; should return a newly-initialized test fixture structure. It should take the name of the test case as an argument (i.e. &amp;lt;code&amp;gt;__func__&amp;lt;/code&amp;gt;) and assign it to the fixture. All of the fixture members should be initialized, which each test case function can then override as needed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;tear_down()&amp;lt;/code&amp;gt; should take the fixture as an argument and release any resources allocated by &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt;. It can also call any library-wide error printing routines (e.g. &amp;lt;code&amp;gt;ERR_print_errors_fp(stderr)&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Each test case function should call &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; as its first statement, and should call &amp;lt;code&amp;gt;tear_down()&amp;lt;/code&amp;gt; just before returning.&lt;br /&gt;
&lt;br /&gt;
==== Use test case functions, not a table of fixtures ====&lt;br /&gt;
Individual test case functions that call a common execution function are much more readable and maintainable than a loop over a table of fixture structures. Explicit fixture variable assignments aid comprehension when reading a specific test case, which saves time and energy when trying to understand a test or diagnose a failure. When a new member is added to an existing fixture, &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; can set a default for all test cases, and only the test cases that rely on that new member need to be updated.&lt;br /&gt;
&lt;br /&gt;
==== Use very descriptive test case names ====&lt;br /&gt;
Give tests long, descriptive names that provide ample context for the details of the test case. Good test names are also help produce good error messages.&lt;br /&gt;
&lt;br /&gt;
==== Group test cases into &amp;quot;suites&amp;quot; by naming convention ====&lt;br /&gt;
Give logically-related tests the same prefix, e.g. &amp;lt;code&amp;gt;test_dtls1_&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;test_tls1&amp;lt;/code&amp;gt; from &amp;lt;code&amp;gt;ssl/heartbeat_test.c&amp;lt;/code&amp;gt;. If need be, you can define suite-specific &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; functions that call the common &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; and elaborate on it. (This generally shouldn't be necessary for &amp;lt;code&amp;gt;tear_down()&amp;lt;/code&amp;gt;.)&lt;br /&gt;
&lt;br /&gt;
==== Keep individual test case functions focused on one thing ====&lt;br /&gt;
If the test name contains the word &amp;quot;and&amp;quot;, consider breaking it into two or more separate test case functions.&lt;br /&gt;
&lt;br /&gt;
==== Write very descriptive error messages ====&lt;br /&gt;
Include the test case function name in each error message, and explain in detail the context for the assertion that failed. Include the expected result (contained in the fixture structure) and the actual result returned from the code under test. Write helper methods for complex values as needed (e.g. &amp;lt;code&amp;gt;print_payload()&amp;lt;/code&amp;gt; in &amp;lt;code&amp;gt;ssl/heartbeat_test.c&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
==== Return zero on success and one on failure ====&lt;br /&gt;
The return value will be used to tally the number of test cases that failed. Even if multiple assertions fail for a single test case, the result should be exactly one.&lt;br /&gt;
&lt;br /&gt;
==== Add each test case function to the test runner function ====&lt;br /&gt;
Whatever function is used to execute the batch of test case functions, be that &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt; or a separate function called by &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt;, don't forget to add your test case functions to that function.&lt;br /&gt;
&lt;br /&gt;
TODO(mbland): create some kind of automated script or editor macros?&lt;br /&gt;
&lt;br /&gt;
==== Report the number of test cases that failed ====&lt;br /&gt;
Add up the total number of failed test cases in &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt; and report that number as the last error message of the test. &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt; should return &amp;lt;code&amp;gt;EXIT_FAILURE&amp;lt;/code&amp;gt; if any test cases failed, &amp;lt;code&amp;gt;EXIT_SUCCESS&amp;lt;/code&amp;gt; otherwise.&lt;br /&gt;
&lt;br /&gt;
=== Disable for Windows (for now) ===&lt;br /&gt;
Until we solve the private-symbol problem on Windows, we will need to wrap our unit test code in the following &amp;lt;code&amp;gt;#ifdef&amp;lt;/code&amp;gt; block:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#if !defined(OPENSSL_SYS_WINDOWS)&lt;br /&gt;
&lt;br /&gt;
/* All the test code, including main() */&lt;br /&gt;
&lt;br /&gt;
int main(int argc, char *argv[])                                                &lt;br /&gt;
    {&lt;br /&gt;
        return EXIT_SUCCESS;                                                    &lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
#endif /* OPENSSL_NO_WINDOWS  */&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Samples ==&lt;br /&gt;
Existing tests that can be used as models for new tests.&lt;br /&gt;
* [http://git.openssl.org/gitweb/?p=openssl.git;a=blob;f=ssl/heartbeat_test.c ssl/heartbeat_test.c]: Follows [http://mike-bland.com/2014/06/05/pseudo-xunit-pattern.html the Pseudo-xUnit pattern]&lt;/div&gt;</summary>
		<author><name>Mbland</name></author>
	</entry>
	<entry>
		<id>https://wiki.openssl.org/index.php?title=How_To_Write_Unit_Tests_For_OpenSSL&amp;diff=1712</id>
		<title>How To Write Unit Tests For OpenSSL</title>
		<link rel="alternate" type="text/html" href="https://wiki.openssl.org/index.php?title=How_To_Write_Unit_Tests_For_OpenSSL&amp;diff=1712"/>
		<updated>2014-06-06T15:49:22Z</updated>

		<summary type="html">&lt;p&gt;Mbland: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This is an outline of the basic process and principles to follow when writing unit tests. This document will evolve quite a bit as the community gains experience.&lt;br /&gt;
&lt;br /&gt;
==Mechanics ==&lt;br /&gt;
=== Forking the Repo ===&lt;br /&gt;
For now, people contributing new unit tests for uncovered code (as opposed to submitting tests with new code changes) should fork [https://github.com/mbland/openssl Mike Bland's GitHub repository] and issue [https://help.github.com/articles/using-pull-requests GitHub pull requests]. Remember to do all development on a topic branch (not &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt;). Tests committed to this repo will occasionally get merged into the master OpenSSL repo.&lt;br /&gt;
&lt;br /&gt;
Rationale per Matt Caswell: We should think about process here. If you are going off to recruit an army of people writing tests then I wonder if it is worth setting up a separate github repository whilst you are building up the tests. We can then merge in from that on a periodic basis. I wouldn't want availability of openssl team committers to be a bottle neck.&lt;br /&gt;
&lt;br /&gt;
=== Use the Test Template Generator ===&lt;br /&gt;
TODO(mbland): Get template generator checked-in. Maybe have a template generator for each library, e.g. &amp;lt;code&amp;gt;ssl/new-test.sh&amp;lt;/code&amp;gt; that has additional setup boilerplate specific to the &amp;lt;code&amp;gt;ssl&amp;lt;/code&amp;gt; library.&lt;br /&gt;
&lt;br /&gt;
Use the &amp;lt;code&amp;gt;test/new-test.sh&amp;lt;/code&amp;gt; script to generate a skeleton test file.&lt;br /&gt;
&lt;br /&gt;
=== Add Makefile Targets ===&lt;br /&gt;
The following instructions use the &amp;lt;code&amp;gt;Makefile&amp;lt;/code&amp;gt; targets for &amp;lt;code&amp;gt;ssl/heartbeat_test.c&amp;lt;/code&amp;gt; as an example.&lt;br /&gt;
&lt;br /&gt;
In the &amp;lt;code&amp;gt;Makefile&amp;lt;/code&amp;gt; for the library containing the test, add the test source file to the &amp;lt;code&amp;gt;TEST&amp;lt;/code&amp;gt; variable:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# ssl/Makefile&lt;br /&gt;
TEST=ssltest.c heartbeat_test.c&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In &amp;lt;code&amp;gt;test/Makefile&amp;lt;/code&amp;gt;:&lt;br /&gt;
* add a variable for the test target near the top of the file, right after the existing test variables&lt;br /&gt;
* use the variable to add an executable target to the &amp;lt;code&amp;gt;EXE&amp;lt;/code&amp;gt; variable&lt;br /&gt;
* use the variable to add an object file target to the &amp;lt;code&amp;gt;OBJ&amp;lt;/code&amp;gt; variable&lt;br /&gt;
* use the variable to add a source file target to the &amp;lt;code&amp;gt;SRC&amp;lt;/code&amp;gt; variable&lt;br /&gt;
* add the test target to the &amp;lt;code&amp;gt;alltests&amp;lt;/code&amp;gt; target&lt;br /&gt;
* add the target to execute the test&lt;br /&gt;
* add the target to build the test executable&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# test/Makefile&lt;br /&gt;
HEARTBEATTEST=  heartbeat_test&lt;br /&gt;
EXE=  ... $(HEARTBEATTEST)$(EXE_EXT)&lt;br /&gt;
OBJ= ... $(HEARTBEATTEST).o&lt;br /&gt;
SRC= ... $(HEARTBEATTEST).c&lt;br /&gt;
alltests: \&lt;br /&gt;
        ... test_heartbeat&lt;br /&gt;
&lt;br /&gt;
test_heartbeat: $(HEARTBEATTEST)$(EXE_EXT)&lt;br /&gt;
  ../util/shlib_wrap.sh ./$(HEARTBEATTEST)&lt;br /&gt;
&lt;br /&gt;
$(HEARTBEATTEST)$(EXE_EXT): $(HEARTBEATTEST).o $(DLIBCRYPTO)&lt;br /&gt;
  @target=$(HEARTBEATTEST); $(BUILD_CMD)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally, run &amp;lt;code&amp;gt;make depend&amp;lt;/code&amp;gt; to automatically generate the header file dependencies.&lt;br /&gt;
&lt;br /&gt;
=== Building and Running the Test ===&lt;br /&gt;
If you're initially developing on Mac OS X or (for now) FreeBSD 10, just use the stock method of building and testing:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ config &amp;amp;&amp;amp; make &amp;amp;&amp;amp; make test&lt;br /&gt;
&lt;br /&gt;
# To execute just one specific test&lt;br /&gt;
$ TESTS=test_heartbeat make test &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Ultimately the test will have to compile and pass with developer flags enabled:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ ./GitConfigure debug-ben-debug-64-clang&lt;br /&gt;
$ ./GitMake -j 2&lt;br /&gt;
$ ./GitMake test&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above currently doesn't work on Mac OS X or FreeBSD 10; for now, you can install the latest 9.x release of [http://www.freebsd.org/ FreeBSD] via a virtualization platform such as [https://www.virtualbox.org/ VirtualBox].&lt;br /&gt;
&lt;br /&gt;
== Style ==&lt;br /&gt;
=== Follow Pseudo-xUnit Style ===&lt;br /&gt;
[http://mike-bland.com/2014/06/05/pseudo-xunit-pattern.html The Pseudo-xUnit Pattern] is that established by [http://git.openssl.org/gitweb/?p=openssl.git;a=blob;f=ssl/heartbeat_test.c ssl/heartbeat_test.c]. This pattern organizes code in a fashion reminiscent of the [http://en.wikipedia.org/wiki/XUnit xUnit] family of unit testing frameworks, without actually using a testing framework. This should lower the barrier to entry for people wanting to write unit tests, but enable a relatively easy migration to an xUnit-based framework if we decide to do so one day.&lt;br /&gt;
&lt;br /&gt;
Some of the basic principles to follow are:&lt;br /&gt;
&lt;br /&gt;
==== Define a fixture structure ====&lt;br /&gt;
The fixture structure should contain all of the inputs to the code under test and all of the expected result values. It should also contain a &amp;lt;code&amp;gt;const char*&amp;lt;/code&amp;gt; for the name of the test case function that created it, to aid in error message formatting. Even though the fixture may contain dynamically-allocated members, the fixture itself should be copied by value to reduce the necessary degree of memory management in a small unit test program.&lt;br /&gt;
&lt;br /&gt;
==== Define set_up() and tear_down() functions for the fixture ====&lt;br /&gt;
&amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; should return a newly-initialized test fixture structure. It should take the name of the test case as an argument (i.e. &amp;lt;code&amp;gt;__func__&amp;lt;/code&amp;gt;) and assign it to the fixture. All of the fixture members should be initialized, which each test case function can then override as needed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;tear_down()&amp;lt;/code&amp;gt; should take the fixture as an argument and release any resources allocated by &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt;. It can also call any library-wide error printing routines (e.g. &amp;lt;code&amp;gt;ERR_print_errors_fp(stderr)&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Each test case function should call &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; as its first statement, and should call &amp;lt;code&amp;gt;tear_down()&amp;lt;/code&amp;gt; just before returning.&lt;br /&gt;
&lt;br /&gt;
==== Use test case functions, not a table of fixtures ====&lt;br /&gt;
Individual test case functions that call a common execution function are much more readable and maintainable than a loop over a table of fixture structures. Explicit fixture variable assignments aid comprehension when reading a specific test case, which saves time and energy when trying to understand a test or diagnose a failure. When a new member is added to an existing fixture, &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; can set a default for all test cases, and only the test cases that rely on that new member need to be updated.&lt;br /&gt;
&lt;br /&gt;
==== Use very descriptive test case names ====&lt;br /&gt;
Give tests long, descriptive names that provide ample context for the details of the test case. Good test names are also help produce good error messages.&lt;br /&gt;
&lt;br /&gt;
==== Group test cases into &amp;quot;suites&amp;quot; by naming convention ====&lt;br /&gt;
Give logically-related tests the same prefix, e.g. &amp;lt;code&amp;gt;test_dtls1_&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;test_tls1&amp;lt;/code&amp;gt; from &amp;lt;code&amp;gt;ssl/heartbeat_test.c&amp;lt;/code&amp;gt;. If need be, you can define suite-specific &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; functions that call the common &amp;lt;code&amp;gt;set_up()&amp;lt;/code&amp;gt; and elaborate on it. (This generally shouldn't be necessary for &amp;lt;code&amp;gt;tear_down()&amp;lt;/code&amp;gt;.)&lt;br /&gt;
&lt;br /&gt;
==== Keep individual test case functions focused on one thing ====&lt;br /&gt;
If the test name contains the word &amp;quot;and&amp;quot;, consider breaking it into two or more separate test case functions.&lt;br /&gt;
&lt;br /&gt;
==== Write very descriptive error messages ====&lt;br /&gt;
Include the test case function name in each error message, and explain in detail the context for the assertion that failed. Include the expected result (contained in the fixture structure) and the actual result returned from the code under test. Write helper methods for complex values as needed (e.g. &amp;lt;code&amp;gt;print_payload()&amp;lt;/code&amp;gt; in &amp;lt;code&amp;gt;ssl/heartbeat_test.c&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
==== Return zero on success and one on failure ====&lt;br /&gt;
The return value will be used to tally the number of test cases that failed. Even if multiple assertions fail for a single test case, the result should be exactly one.&lt;br /&gt;
&lt;br /&gt;
==== Add each test case function to the test runner function ====&lt;br /&gt;
Whatever function is used to execute the batch of test case functions, be that &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt; or a separate function called by &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt;, don't forget to add your test case functions to that function.&lt;br /&gt;
&lt;br /&gt;
TODO(mbland): create some kind of automated script or editor macros?&lt;br /&gt;
&lt;br /&gt;
==== Report the number of test cases that failed ====&lt;br /&gt;
Add up the total number of failed test cases in &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt; and report that number as the last error message of the test. &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt; should return &amp;lt;code&amp;gt;EXIT_FAILURE&amp;lt;/code&amp;gt; if any test cases failed, &amp;lt;code&amp;gt;EXIT_SUCCESS&amp;lt;/code&amp;gt; otherwise.&lt;br /&gt;
&lt;br /&gt;
=== Disable for Windows (for now) ===&lt;br /&gt;
Until we solve the private-symbol problem on Windows, we will need to wrap our unit test code in the following &amp;lt;code&amp;gt;#ifdef&amp;lt;/code&amp;gt; block:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#if !defined(OPENSSL_SYS_WINDOWS)&lt;br /&gt;
&lt;br /&gt;
/* All the test code, including main() */&lt;br /&gt;
&lt;br /&gt;
int main(int argc, char *argv[])                                                &lt;br /&gt;
    {&lt;br /&gt;
        return EXIT_SUCCESS;                                                    &lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
#endif /* OPENSSL_NO_WINDOWS  */&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mbland</name></author>
	</entry>
	<entry>
		<id>https://wiki.openssl.org/index.php?title=How_To_Write_Unit_Tests_For_OpenSSL&amp;diff=1711</id>
		<title>How To Write Unit Tests For OpenSSL</title>
		<link rel="alternate" type="text/html" href="https://wiki.openssl.org/index.php?title=How_To_Write_Unit_Tests_For_OpenSSL&amp;diff=1711"/>
		<updated>2014-06-06T15:21:46Z</updated>

		<summary type="html">&lt;p&gt;Mbland: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This is an outline of the basic process and principles to follow when writing unit tests. This document will evolve quite a bit as the community gains experience.&lt;br /&gt;
&lt;br /&gt;
==Mechanics ==&lt;br /&gt;
=== Forking the Repo ===&lt;br /&gt;
For now, people contributing new unit tests for uncovered code (as opposed to submitting tests with new code changes) should fork [https://github.com/mbland/openssl Mike Bland's GitHub repository] and issue [https://help.github.com/articles/using-pull-requests GitHub pull requests]. Remember to do all development on a topic branch (not &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt;). Tests committed to this repo will occasionally get merged into the master OpenSSL repo.&lt;br /&gt;
&lt;br /&gt;
Rationale per Matt Caswell: We should think about process here. If you are going off to recruit an army of people writing tests then I wonder if it is worth setting up a separate github repository whilst you are building up the tests. We can then merge in from that on a periodic basis. I wouldn't want availability of openssl team committers to be a bottle neck.&lt;br /&gt;
&lt;br /&gt;
=== Use the Test Template Generator ===&lt;br /&gt;
TODO(mbland): Get template generator checked-in. Maybe have a template generator for each library, e.g. &amp;lt;code&amp;gt;ssl/new-test.sh&amp;lt;/code&amp;gt; that has additional setup boilerplate specific to the &amp;lt;code&amp;gt;ssl&amp;lt;/code&amp;gt; library.&lt;br /&gt;
&lt;br /&gt;
Use the &amp;lt;code&amp;gt;test/new-test.sh&amp;lt;/code&amp;gt; script to generate a skeleton test file.&lt;br /&gt;
&lt;br /&gt;
=== Add Makefile Targets ===&lt;br /&gt;
The following instructions use the &amp;lt;code&amp;gt;Makefile&amp;lt;/code&amp;gt; targets for &amp;lt;code&amp;gt;ssl/heartbeat_test.c&amp;lt;/code&amp;gt; as an example.&lt;br /&gt;
&lt;br /&gt;
In the &amp;lt;code&amp;gt;Makefile&amp;lt;/code&amp;gt; for the library containing the test, add the test source file to the &amp;lt;code&amp;gt;TEST&amp;lt;/code&amp;gt; variable:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# ssl/Makefile&lt;br /&gt;
TEST=ssltest.c heartbeat_test.c&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In &amp;lt;code&amp;gt;test/Makefile&amp;lt;/code&amp;gt;:&lt;br /&gt;
* add a variable for the test target near the top of the file, right after the existing test variables&lt;br /&gt;
* use the variable to add an executable target to the &amp;lt;code&amp;gt;EXE&amp;lt;/code&amp;gt; variable&lt;br /&gt;
* use the variable to add an object file target to the &amp;lt;code&amp;gt;OBJ&amp;lt;/code&amp;gt; variable&lt;br /&gt;
* use the variable to add a source file target to the &amp;lt;code&amp;gt;SRC&amp;lt;/code&amp;gt; variable&lt;br /&gt;
* add the test target to the &amp;lt;code&amp;gt;alltests&amp;lt;/code&amp;gt; target&lt;br /&gt;
* add the target to execute the test&lt;br /&gt;
* add the target to build the test executable&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# test/Makefile&lt;br /&gt;
HEARTBEATTEST=  heartbeat_test&lt;br /&gt;
EXE=  ... $(HEARTBEATTEST)$(EXE_EXT)&lt;br /&gt;
OBJ= ... $(HEARTBEATTEST).o&lt;br /&gt;
SRC= ... $(HEARTBEATTEST).c&lt;br /&gt;
alltests: \&lt;br /&gt;
        ... test_heartbeat&lt;br /&gt;
&lt;br /&gt;
test_heartbeat: $(HEARTBEATTEST)$(EXE_EXT)&lt;br /&gt;
  ../util/shlib_wrap.sh ./$(HEARTBEATTEST)&lt;br /&gt;
&lt;br /&gt;
$(HEARTBEATTEST)$(EXE_EXT): $(HEARTBEATTEST).o $(DLIBCRYPTO)&lt;br /&gt;
  @target=$(HEARTBEATTEST); $(BUILD_CMD)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally, run &amp;lt;code&amp;gt;make depend&amp;lt;/code&amp;gt; to automatically generate the header file dependencies.&lt;br /&gt;
&lt;br /&gt;
=== Building the Test ===&lt;br /&gt;
If you're initially developing on Mac OS X or (for now) FreeBSD 10, just use the stock method of building and testing:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ config &amp;amp;&amp;amp; make &amp;amp;&amp;amp; make test&lt;br /&gt;
&lt;br /&gt;
# To execute just one specific test&lt;br /&gt;
$ TESTS=test_heartbeat make test &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Ultimately the test will have to compile and pass with developer flags enabled:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ ./GitConfigure debug-ben-debug-64-clang&lt;br /&gt;
$ ./GitMake -j 2&lt;br /&gt;
$ ./GitMake test&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above currently doesn't work on Mac OS X or FreeBSD 10; for now, you can install the latest 9.x release of [http://www.freebsd.org/ FreeBSD] via a virtualization platform such as [https://www.virtualbox.org/ VirtualBox].&lt;br /&gt;
&lt;br /&gt;
== Style ==&lt;br /&gt;
=== Follow Pseudo-xUnit Style ===&lt;br /&gt;
[http://mike-bland.com/2014/06/05/pseudo-xunit-pattern.html The Pseudo-xUnit Pattern] is that established by [http://git.openssl.org/gitweb/?p=openssl.git;a=blob;f=ssl/heartbeat_test.c ssl/heartbeat_test.c]. This pattern organizes code in a fashion reminiscent of the [http://en.wikipedia.org/wiki/XUnit xUnit] family of unit testing frameworks, without actually using a testing framework. This should lower the barrier to entry for people wanting to write unit tests, but enable a relatively easy migration to an xUnit-based framework if we decide to do so one day.&lt;br /&gt;
&lt;br /&gt;
=== Disable for Windows (for now) ===&lt;br /&gt;
Until we solve the private-symbol problem on Windows, we will need to wrap our unit test code in the following &amp;lt;code&amp;gt;#ifdef&amp;lt;/code&amp;gt; block:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#if !defined(OPENSSL_SYS_WINDOWS)&lt;br /&gt;
&lt;br /&gt;
/* All the test code, including main() */&lt;br /&gt;
&lt;br /&gt;
int main(int argc, char *argv[])                                                &lt;br /&gt;
    {&lt;br /&gt;
        return EXIT_SUCCESS;                                                    &lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
#endif /* OPENSSL_NO_WINDOWS  */&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mbland</name></author>
	</entry>
	<entry>
		<id>https://wiki.openssl.org/index.php?title=How_To_Write_Unit_Tests_For_OpenSSL&amp;diff=1710</id>
		<title>How To Write Unit Tests For OpenSSL</title>
		<link rel="alternate" type="text/html" href="https://wiki.openssl.org/index.php?title=How_To_Write_Unit_Tests_For_OpenSSL&amp;diff=1710"/>
		<updated>2014-06-06T15:10:51Z</updated>

		<summary type="html">&lt;p&gt;Mbland: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This is an outline of the basic process and principles to follow when writing unit tests. This document will evolve quite a bit as the community gains experience.&lt;br /&gt;
&lt;br /&gt;
==Mechanics ==&lt;br /&gt;
=== Forking the Repo ===&lt;br /&gt;
For now, people contributing new unit tests for uncovered code (as opposed to submitting tests with new code changes) should fork [https://github.com/mbland/openssl Mike Bland's GitHub repository] and issue [https://help.github.com/articles/using-pull-requests GitHub pull requests]. Remember to do all development on a topic branch (not &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt;). Tests committed to this repo will occasionally get merged into the master OpenSSL repo.&lt;br /&gt;
&lt;br /&gt;
Rationale per Matt Caswell: We should think about process here. If you are going off to recruit an army of people writing tests then I wonder if it is worth setting up a separate github repository whilst you are building up the tests. We can then merge in from that on a periodic basis. I wouldn't want availability of openssl team committers to be a bottle neck.&lt;br /&gt;
&lt;br /&gt;
=== Use the Test Template Generator ===&lt;br /&gt;
TODO(mbland): Get template generator checked-in. Maybe have a template generator for each library, e.g. &amp;lt;code&amp;gt;ssl/new-test.sh&amp;lt;/code&amp;gt; that has additional setup boilerplate specific to the &amp;lt;code&amp;gt;ssl&amp;lt;/code&amp;gt; library.&lt;br /&gt;
&lt;br /&gt;
Use the &amp;lt;code&amp;gt;test/new-test.sh&amp;lt;/code&amp;gt; script to generate a skeleton test file.&lt;br /&gt;
&lt;br /&gt;
Until we solve the private-symbol problem on Windows, we will need to wrap our unit test code in the following &amp;lt;code&amp;gt;#ifdef&amp;lt;/code&amp;gt; block:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#if !defined(OPENSSL_SYS_WINDOWS)&lt;br /&gt;
&lt;br /&gt;
/* All the test code, including main() */&lt;br /&gt;
&lt;br /&gt;
int main(int argc, char *argv[])                                                &lt;br /&gt;
    {&lt;br /&gt;
        return EXIT_SUCCESS;                                                    &lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
#endif /* OPENSSL_NO_WINDOWS  */&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Add Makefile Targets ===&lt;br /&gt;
The following instructions use the &amp;lt;code&amp;gt;Makefile&amp;lt;/code&amp;gt; targets for &amp;lt;code&amp;gt;ssl/heartbeat_test.c&amp;lt;/code&amp;gt; as an example.&lt;br /&gt;
&lt;br /&gt;
In the &amp;lt;code&amp;gt;Makefile&amp;lt;/code&amp;gt; for the library containing the test, add the test source file to the &amp;lt;code&amp;gt;TEST&amp;lt;/code&amp;gt; variable:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# ssl/Makefile&lt;br /&gt;
TEST=ssltest.c heartbeat_test.c&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In &amp;lt;code&amp;gt;test/Makefile&amp;lt;/code&amp;gt;:&lt;br /&gt;
* add a variable for the test target near the top of the file, right after the existing test variables&lt;br /&gt;
* use the variable to add an executable target to the &amp;lt;code&amp;gt;EXE&amp;lt;/code&amp;gt; variable&lt;br /&gt;
* use the variable to add an object file target to the &amp;lt;code&amp;gt;OBJ&amp;lt;/code&amp;gt; variable&lt;br /&gt;
* use the variable to add a source file target to the &amp;lt;code&amp;gt;SRC&amp;lt;/code&amp;gt; variable&lt;br /&gt;
* add the test target to the &amp;lt;code&amp;gt;alltests&amp;lt;/code&amp;gt; target&lt;br /&gt;
* add the target to execute the test&lt;br /&gt;
* add the target to build the test executable&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# test/Makefile&lt;br /&gt;
HEARTBEATTEST=  heartbeat_test&lt;br /&gt;
EXE=  ... $(HEARTBEATTEST)$(EXE_EXT)&lt;br /&gt;
OBJ= ... $(HEARTBEATTEST).o&lt;br /&gt;
SRC= ... $(HEARTBEATTEST).c&lt;br /&gt;
alltests: \&lt;br /&gt;
        ... test_heartbeat&lt;br /&gt;
&lt;br /&gt;
test_heartbeat: $(HEARTBEATTEST)$(EXE_EXT)&lt;br /&gt;
  ../util/shlib_wrap.sh ./$(HEARTBEATTEST)&lt;br /&gt;
&lt;br /&gt;
$(HEARTBEATTEST)$(EXE_EXT): $(HEARTBEATTEST).o $(DLIBCRYPTO)&lt;br /&gt;
  @target=$(HEARTBEATTEST); $(BUILD_CMD)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally, run &amp;lt;code&amp;gt;make depend&amp;lt;/code&amp;gt; to automatically generate the header file dependencies.&lt;br /&gt;
&lt;br /&gt;
== Style ==&lt;br /&gt;
=== Follow Pseudo-xUnit Style ===&lt;br /&gt;
[http://mike-bland.com/2014/06/05/pseudo-xunit-pattern.html The Pseudo-xUnit Pattern] is that established by [http://git.openssl.org/gitweb/?p=openssl.git;a=blob;f=ssl/heartbeat_test.c ssl/heartbeat_test.c]. This pattern organizes code in a fashion reminiscent of the [http://en.wikipedia.org/wiki/XUnit xUnit] family of unit testing frameworks, without actually using a testing framework. This should lower the barrier to entry for people wanting to write unit tests, but enable a relatively easy migration to an xUnit-based framework if we decide to do so one day.&lt;/div&gt;</summary>
		<author><name>Mbland</name></author>
	</entry>
</feed>