Commit 3e1b2ec6 authored by Jacob Champion's avatar Jacob Champion
Browse files

httpdunit: merge to trunk from feature branch

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1799378 13f79535-47bb-0310-9956-ffa450edef68
parents f822bb3d 502e2af7
Loading
Loading
Loading
Loading
+67 −0
Original line number Diff line number Diff line
@@ -64,6 +64,12 @@ ELSE()
  SET(default_brotli_libraries)
ENDIF()

IF(EXISTS "${CMAKE_INSTALL_PREFIX}/lib/check.lib")
  SET(default_check_libraries "${CMAKE_INSTALL_PREFIX}/lib/check.lib" "${CMAKE_INSTALL_PREFIX}/lib/compat.lib")
ELSE()
  SET(default_check_libraries)
ENDIF()

SET(APR_INCLUDE_DIR       "${CMAKE_INSTALL_PREFIX}/include" CACHE STRING "Directory with APR[-Util] include files")
SET(APR_LIBRARIES         ${default_apr_libraries}       CACHE STRING "APR libraries to link with")
SET(NGHTTP2_INCLUDE_DIR   "${CMAKE_INSTALL_PREFIX}/include" CACHE STRING "Directory with NGHTTP2 include files within nghttp2 subdirectory")
@@ -74,6 +80,8 @@ SET(LIBXML2_ICONV_INCLUDE_DIR "" CACHE STRING "Directory
SET(LIBXML2_ICONV_LIBRARIES       ""                     CACHE STRING "iconv libraries to link with for libxml2")
SET(BROTLI_INCLUDE_DIR    "${CMAKE_INSTALL_PREFIX}/include" CACHE STRING "Directory with include files for Brotli")
SET(BROTLI_LIBRARIES      ${default_brotli_libraries}    CACHE STRING "Brotli libraries to link with")
SET(CHECK_INCLUDE_DIR     "${CMAKE_INSTALL_PREFIX}/include" CACHE STRING "Directory with include files for Check")
SET(CHECK_LIBRARIES       "${default_check_libraries}"   CACHE STRING "Check libraries to link with")
# end support library configuration

# Misc. options
@@ -211,6 +219,18 @@ ELSE()
  SET(BROTLI_FOUND FALSE)
ENDIF()

# See if we have Check
SET(CHECK_FOUND TRUE)
IF (EXISTS "${CHECK_INCLUDE_DIR}/check.h")
  FOREACH(onelib ${CHECK_LIBRARIES})
    IF(NOT EXISTS "${onelib}")
      SET(CHECK_FOUND FALSE)
    ENDIF()
  ENDFOREACH()
ELSE()
  SET(CHECK_FOUND FALSE)
ENDIF()

MESSAGE(STATUS "")
MESSAGE(STATUS "Summary of feature detection:")
MESSAGE(STATUS "")
@@ -220,6 +240,7 @@ MESSAGE(STATUS "NGHTTP2_FOUND ............ : ${NGHTTP2_FOUND}")
MESSAGE(STATUS "OPENSSL_FOUND ............ : ${OPENSSL_FOUND}")
MESSAGE(STATUS "ZLIB_FOUND ............... : ${ZLIB_FOUND}")
MESSAGE(STATUS "BROTLI_FOUND ............. : ${BROTLI_FOUND}")
MESSAGE(STATUS "CHECK_FOUND .............. : ${CHECK_FOUND}")
MESSAGE(STATUS "APR_HAS_LDAP ............. : ${APR_HAS_LDAP}")
MESSAGE(STATUS "APR_HAS_XLATE ............ : ${APR_HAS_XLATE}")
MESSAGE(STATUS "APU_HAVE_CRYPTO .......... : ${APU_HAVE_CRYPTO}")
@@ -884,6 +905,50 @@ IF(OPENSSL_FOUND)
ENDIF()
GET_PROPERTY(tmp_includes TARGET ab PROPERTY INCLUDE_DIRECTORIES)

# Unit Test Suite
IF(CHECK_FOUND)
  # Get all of the test cases.
  # XXX Per CMake documentation, if a test case is added or removed we must
  # re-run CMake due to our use of GLOB. TBD if this tradeoff to have
  # "plug-and-play" test cases is really worth it.
  FILE(GLOB httpdunit_cases "${CMAKE_SOURCE_DIR}/test/unit/*.c")

  ADD_EXECUTABLE(httpdunit
                   test/httpdunit.c
                   ${httpdunit_cases})
  SET_TARGET_PROPERTIES(httpdunit PROPERTIES
                        INCLUDE_DIRECTORIES "${HTTPD_INCLUDE_DIRECTORIES} ${CHECK_INCLUDE_DIR}"
                        # FIXME why does Check need HAVE_STDINT_H on Windows?
                        COMPILE_FLAGS "-DHAVE_STDINT_H")
  TARGET_LINK_LIBRARIES(httpdunit libhttpd ${APR_LIBRARIES} ${CHECK_LIBRARIES})

  # Rules for generating the .tests stubs.
  FILE(GENERATE OUTPUT "${CMAKE_BINARY_DIR}/httpdunit_gen_stubs.bat"
                CONTENT "perl \"${CMAKE_SOURCE_DIR}/build/httpdunit_gen_stubs.pl\" < %1 > %2")
  FILE(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/test/unit")

  FOREACH(case ${httpdunit_cases})
    STRING(REGEX REPLACE "^${CMAKE_SOURCE_DIR}" "${CMAKE_BINARY_DIR}"
                 stub "${case}")
    STRING(REGEX REPLACE "\\.c$" ".tests"
                 stub "${stub}")

    ADD_CUSTOM_COMMAND(TARGET httpdunit
                       PRE_BUILD
                       COMMAND "${CMAKE_BINARY_DIR}/httpdunit_gen_stubs.bat" "\"${case}\"" "\"${stub}\""
                       BYPRODUCTS "${stub}")
  ENDFOREACH()

  # Rule for generating the .cases file.
  FILE(GENERATE OUTPUT "${CMAKE_BINARY_DIR}/httpdunit_gen_cases.bat"
                CONTENT "type \"${CMAKE_SOURCE_DIR}\"\\test\\unit\\*.c 2>NUL | perl \"${CMAKE_SOURCE_DIR}/build/httpdunit_gen_cases.pl\" --declaration > \"${CMAKE_BINARY_DIR}/test/httpdunit.cases\"
                         type \"${CMAKE_SOURCE_DIR}\"\\test\\unit\\*.c 2>NUL | perl \"${CMAKE_SOURCE_DIR}/build/httpdunit_gen_cases.pl\" >> \"${CMAKE_BINARY_DIR}/test/httpdunit.cases\"")
  ADD_CUSTOM_COMMAND(TARGET httpdunit
                     PRE_BUILD
                     COMMAND "${CMAKE_BINARY_DIR}/httpdunit_gen_cases.bat"
                     BYPRODUCTS "${CMAKE_BINARY_DIR}/test/httpdunit.cases")
ENDIF()

# getting duplicate manifest error with ApacheMonitor
# ADD_EXECUTABLE(ApacheMonitor support/win32/ApacheMonitor.c support/win32/ApacheMonitor.rc)
# SET(install_targets ${install_targets} ApacheMonitor)
@@ -991,6 +1056,8 @@ MESSAGE(STATUS " libxml2 iconv prereq include dir. : ${LIBXML2_ICONV_INCLUDE_DI
MESSAGE(STATUS "  libxml2 iconv prereq libraries .. : ${LIBXML2_ICONV_LIBRARIES}")
MESSAGE(STATUS "  Brotli include directory......... : ${BROTLI_INCLUDE_DIR}")
MESSAGE(STATUS "  Brotli libraries ................ : ${BROTLI_LIBRARIES}")
MESSAGE(STATUS "  Check include directory.......... : ${CHECK_INCLUDE_DIR}")
MESSAGE(STATUS "  Check libraries ................. : ${CHECK_LIBRARIES}")
MESSAGE(STATUS "  Extra include directories ....... : ${EXTRA_INCLUDES}")
MESSAGE(STATUS "  Extra compile flags ............. : ${EXTRA_COMPILE_FLAGS}")
MESSAGE(STATUS "  Extra libraries ................. : ${EXTRA_LIBS}")
+38 −2
Original line number Diff line number Diff line
@@ -20,7 +20,8 @@ INSTALL_TARGETS = install-conf install-htdocs install-error install-icons \

CLEAN_TARGETS      = check/apxs check/build/config_vars.mk \
	check/conf/$(PROGRAM_NAME).conf check/conf/magic check/conf/mime.types \
	check/conf/extra/* check/include/*
	check/conf/extra/* check/include/* $(testcase_OBJECTS) $(testcase_STUBS) \
	test/httpdunit.cases test/unit/*.o
DISTCLEAN_TARGETS  = include/ap_config_auto.h include/ap_config_layout.h \
	include/apache_probes.h \
	modules.c config.cache config.log config.status build/config_vars.mk \
@@ -28,7 +29,7 @@ DISTCLEAN_TARGETS = include/ap_config_auto.h include/ap_config_layout.h \
	build/pkg/pkginfo build/config_vars.sh bsd_converted
EXTRACLEAN_TARGETS = configure include/ap_config_auto.h.in generated_lists \
	httpd.spec
PHONY_TARGETS := check check-conf check-dirs check-include
PHONY_TARGETS := check check-conf check-dirs check-include unittest-objdir

include $(top_builddir)/build/rules.mk
include $(top_srcdir)/build/program.mk
@@ -431,3 +432,38 @@ check: check-include check-dirs check-conf check/build/config_vars.mk check/apxs
	    ./t/TEST -clean && \
	    ./t/TEST -config && \
	    ./t/TEST

#
# Unit Test Suite
#

# Make sure the object subdirectories we use exist in the build directory during
# VPATH builds.
unittest-objdir:
	@mkdir -p test/unit

# Normally I don't like wildcard sources, but for tests, autodiscovery is the
# way to go.
testcase_SOURCES := $(patsubst $(top_srcdir)/%,%,$(wildcard $(top_srcdir)/test/unit/*.c))
testcase_OBJECTS := $(testcase_SOURCES:%.c=%.lo)
testcase_STUBS   := $(testcase_SOURCES:%.c=%.tests)

# Each testcase depends on the source file as well as the autogenerated .tests
# stub.
$(testcase_OBJECTS): %.lo: %.c %.tests | unittest-objdir

$(testcase_STUBS): %.tests: %.c
	$(top_srcdir)/build/httpdunit_gen_stubs.pl < "$<" > "$@"

test/httpdunit.cases: $(testcase_SOURCES) | unittest-objdir
	cat $^ | $(top_srcdir)/build/httpdunit_gen_cases.pl --declaration > $@
	cat $^ | $(top_srcdir)/build/httpdunit_gen_cases.pl >> $@

test/httpdunit.lo: test/httpdunit.c test/httpdunit.cases | unittest-objdir

# httpdunit is only added to $(other_targets) if configure detects a working
# libcheck on the system.
httpdunit_OBJECTS := test/httpdunit.lo $(testcase_OBJECTS)
$(httpdunit_OBJECTS): override LTCFLAGS += $(UNITTEST_CFLAGS)
test/httpdunit: $(httpdunit_OBJECTS) $(PROGRAM_DEPENDENCIES) $(PROGRAM_OBJECTS)
	$(LINK) $(httpdunit_OBJECTS) $(PROGRAM_OBJECTS) $(UNITTEST_LIBS) $(PROGRAM_LDADD)
+34 −0
Original line number Diff line number Diff line
#! /usr/bin/env perl

#
# Generates a list of test cases to be pulled into the httpdunit main test
# suite.
#
# Supply all the test cases' source file contents on stdin; the resulting code
# will be printed to stdout. Normally you will want to call this twice: once
# with --declaration to print the function declarations of all the test cases,
# and once without any options to produce the code that actually adds each test
# case to the main suite.
#

use strict;
use warnings;

use Getopt::Long;

my $print_declaration = 0;

GetOptions("declaration" => \$print_declaration)
    or die("unknown option");

while (my $line = <>) {
    if ($line =~ /^HTTPD_BEGIN_TEST_CASE(?:\w+)?\((\w+)/) {
        my $name = "$1_test_case";

        if ($print_declaration) {
            print "TCase *$name(void);\n";
        } else {
            print "suite_add_tcase(suite, $name());\n";
        }
    }
}
+22 −0
Original line number Diff line number Diff line
#! /usr/bin/env perl

#
# Generates a code stub that adds unit tests to a Check test case.
#
# Supply the test case's source file contents on stdin; the resulting code will
# be printed to stdout. This code is designed to be included as part of the
# boilerplate at the end of each test case.
#

use strict;
use warnings;

while (my $line = <>) {
    # FIXME: this does not correctly handle macro invocations that are split
    # over multiple lines.
    if ($line =~ /^HTTPD_START_LOOP_TEST\((\w+),(.*)\)/) {
        print "tcase_add_loop_test(testcase, $1, 0, ($2));\n";
    } elsif ($line =~ /^START_TEST\((\w+)\)/) {
        print "tcase_add_test(testcase, $1);\n"
    }
}
+2 −2
Original line number Diff line number Diff line
@@ -44,8 +44,8 @@ CXX_COMPILE = $(BASE_CXX) $(PICFLAGS)
SH_COMPILE     = $(LIBTOOL) --mode=compile $(BASE_CC) $(SHLTCFLAGS) -c $< && touch $@
SH_CXX_COMPILE = $(LIBTOOL) --mode=compile $(BASE_CXX) $(SHLTCFLAGS) -c $< && touch $@

LT_COMPILE     = $(LIBTOOL) --mode=compile $(COMPILE) $(LTCFLAGS) -c $< && touch $@
LT_CXX_COMPILE = $(LIBTOOL) --mode=compile $(CXX_COMPILE) $(LTCFLAGS) -c $< && touch $@
LT_COMPILE     = $(LIBTOOL) --mode=compile $(COMPILE) $(LTCFLAGS) -c $< -o $@
LT_CXX_COMPILE = $(LIBTOOL) --mode=compile $(CXX_COMPILE) $(LTCFLAGS) -c $< -o $@

# Link-related commands

Loading