Commit 4db40c94 authored by Richard Levitte's avatar Richard Levitte
Browse files

Refactor the test framework testutil



It's now built as a static library, and greatly simplified for test
programs, which no longer need to include test_main_custom.h or
test_main.h and link with the corresponding object files.

Reviewed-by: default avatarRich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/3243)
parent 20626cfd
Loading
Loading
Loading
Loading
+2 −3
Original line number Diff line number Diff line
@@ -99,14 +99,13 @@ test):
to modify the include paths and source files if you don't want to use the
basic test framework:

    SOURCE[{name}]={name}.c testutil.c test_main.c
    SOURCE[{name}]={name}.c
    INCLUDE[{name}]=.. ../include
    DEPEND[{name}]=../libcrypto
    DEPEND[{name}]=../libcrypto libtestutil.a

Generic form of C test executables
==================================

    #include "test_main.h"
    #include "testutil.h"

    static int my_test(void)
+7 −2
Original line number Diff line number Diff line
@@ -5,11 +5,16 @@
         my ($base, $files) = @_;
         return join(" ", map { "$base/$_" } split(/\s+/, $files));
     }
     our $apps_extra =
         $config{target} =~ /^vms-/ ? "../apps/vms_term_sock.c" : "";
     ""
-}
IF[{- !$disabled{tests} -}]
  LIBS_NO_INST=libtestutil.a
  SOURCE[libtestutil.a]=testutil/basic_output.c testutil/driver.c \
          testutil/tests.c testutil/test_main.c testutil/main.c \
          {- rebase_files("../apps", $target{apps_aux_src}) -}
  INCLUDE[libtestutil.a]=../include
  DEPEND[libtestutil.a]=../libcrypto

  PROGRAMS_NO_INST=\
          aborttest test_test \
          sanitytest exdatatest bntest \

test/test_main.h

deleted100644 → 0
+0 −18
Original line number Diff line number Diff line
/*
 * Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
 *
 * Licensed under the OpenSSL license (the "License").  You may not use
 * this file except in compliance with the License.  You can obtain a copy
 * in the file LICENSE in the source distribution or at
 * https://www.openssl.org/source/license.html
 */

#ifndef HEADER_TEST_MAIN_H
# define HEADER_TEST_MAIN_H

/*
 * Simple unit tests should implement register_tests() and link to test_main.c.
 */
extern void register_tests(void);

#endif  /* HEADER_TEST_MAIN_H */

test/test_main_custom.h

deleted100644 → 0
+0 −20
Original line number Diff line number Diff line
/*
 * Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
 *
 * Licensed under the OpenSSL license (the "License").  You may not use
 * this file except in compliance with the License.  You can obtain a copy
 * in the file LICENSE in the source distribution or at
 * https://www.openssl.org/source/license.html
 */

#ifndef HEADER_TEST_MAIN_CUSTOM_H
# define HEADER_TEST_MAIN_CUSTOM_H

/*
 * Unit tests that need a custom main() should implement test_main and link to
 * test_main_custom.c
 * test_main() should return the result of run_tests().
 */
extern int test_main(int argc, char *argv[]);

#endif  /* HEADER_TEST_MAIN_CUSTOM_H */
+37 −9
Original line number Diff line number Diff line
@@ -16,12 +16,9 @@
#include <openssl/e_os2.h>

/*-
 * Simple unit tests should implement register_tests() from test_main.h
 * and link against test_main.c.
 * Simple unit tests should implement register_tests().
 * To register tests, call ADD_TEST or ADD_ALL_TESTS:
 *
 * #include "test_main.h"
 *
 * void register_tests(void)
 * {
 *     ADD_TEST(test_foo);
@@ -29,8 +26,7 @@
 * }
 *
 * Tests that need to perform custom setup or read command-line arguments should
 * implement test_main() from test_main_custom.h and link against
 * test_main_custom.c:
 * implement test_main():
 *
 * int test_main(int argc, char *argv[])
 * {
@@ -138,14 +134,27 @@ void add_test(const char *test_case_name, int (*test_fn) ());
void add_all_tests(const char *test_case_name, int (*test_fn)(int idx), int num);
__owur int run_tests(const char *test_prog_name);

/*
 * Declarations for user defined functions
 */
void register_tests(void);
int test_main(int argc, char *argv[]);


/*
 *  Test assumption verification helpers.
 */

# if defined(__GNUC__)
#define PRINTF_FORMAT(a, b)   __attribute__ ((format(printf, a, b)))
# else
#define PRINTF_FORMAT(a, b)
#if defined(__GNUC__) && defined(__STDC_VERSION__)
  /*
   * Because we support the 'z' modifier, which made its appearance in C99,
   * we can't use __attribute__ with pre C99 dialects.
   */
# if __STDC_VERSION__ >= 199901L
#  undef PRINTF_FORMAT
#  define PRINTF_FORMAT(a, b)   __attribute__ ((format(printf, a, b)))
# endif
#endif

#  define DECLARE_COMPARISON(type, name, opname)                        \
@@ -335,3 +344,22 @@ void test_info_c90(const char *desc, ...) PRINTF_FORMAT(1, 2);
        }                                       \
    } while (0)
#endif                          /* HEADER_TESTUTIL_H */


/*
 * The basic I/O functions used by the test framework.  These can be
 * overriden when needed. Note that if one is, then all must be.
 */
void test_open_streams(void);
void test_close_streams(void);
/* The following ALL return the number of characters written */
int test_puts_stdout(const char *str);
int test_puts_stderr(const char *str);
int test_vprintf_stdout(const char *fmt, va_list ap);
int test_vprintf_stderr(const char *fmt, va_list ap);
/* These return failure or success */
int test_flush_stdout(void);
int test_flush_stderr(void);

extern BIO *bio_out;
extern BIO *bio_err;
Loading