build: add pytest targets
It enables running pytests in cmake jobs, regardless of underlying build tool choice (= makes it work with ninja.) Also: - drop pytest logic launching `make` and exiting in case of failure. Maybe there is a better way and keep this functionality somehow, bind it to a command-line option? make it fail softly? - GHA/linux: invoke pytest via the build, not directly. - autotools: add missing dummy runtests targets when cross-compiling. Closes #15034
This commit is contained in:
parent
ed766751cc
commit
d82f9f965c
13
.github/workflows/linux.yml
vendored
13
.github/workflows/linux.yml
vendored
@ -652,14 +652,17 @@ jobs:
|
|||||||
fi
|
fi
|
||||||
make V=1 VERBOSE=1 test-ci
|
make V=1 VERBOSE=1 test-ci
|
||||||
|
|
||||||
- if: contains(matrix.build.install_steps, 'pytest')
|
- name: 'run pytest'
|
||||||
# run for `tests/http` directory, so pytest does not pick up any other
|
if: contains(matrix.build.install_steps, 'pytest')
|
||||||
# packages we might have built here
|
|
||||||
run: pytest -v tests/http
|
|
||||||
name: 'run pytest'
|
|
||||||
env:
|
env:
|
||||||
TFLAGS: "${{ matrix.build.tflags }}"
|
TFLAGS: "${{ matrix.build.tflags }}"
|
||||||
CURL_CI: github
|
CURL_CI: github
|
||||||
|
run: |
|
||||||
|
if [ -n '${{ matrix.build.generate }}' ]; then
|
||||||
|
cmake --build . --verbose --target curl-pytest-ci
|
||||||
|
else
|
||||||
|
make V=1 pytest-ci
|
||||||
|
fi
|
||||||
|
|
||||||
- run: ${{ matrix.build.make-prefix }} make V=1 examples
|
- run: ${{ matrix.build.make-prefix }} make V=1 examples
|
||||||
if: ${{ matrix.build.configure }}
|
if: ${{ matrix.build.configure }}
|
||||||
|
|||||||
12
Makefile.am
12
Makefile.am
@ -118,7 +118,13 @@ check: test examples check-docs
|
|||||||
|
|
||||||
if CROSSCOMPILING
|
if CROSSCOMPILING
|
||||||
test-full: test
|
test-full: test
|
||||||
|
test-nonflaky: test
|
||||||
test-torture: test
|
test-torture: test
|
||||||
|
test-event: test
|
||||||
|
test-am: test
|
||||||
|
test-ci: test
|
||||||
|
pytest: test
|
||||||
|
pytest-ci: test
|
||||||
|
|
||||||
test:
|
test:
|
||||||
@echo "NOTICE: we can't run the tests when cross-compiling!"
|
@echo "NOTICE: we can't run the tests when cross-compiling!"
|
||||||
@ -146,6 +152,12 @@ test-am:
|
|||||||
test-ci:
|
test-ci:
|
||||||
@(cd tests; $(MAKE) all ci-test)
|
@(cd tests; $(MAKE) all ci-test)
|
||||||
|
|
||||||
|
pytest:
|
||||||
|
@(cd tests; $(MAKE) all default-pytest)
|
||||||
|
|
||||||
|
pytest-ci:
|
||||||
|
@(cd tests; $(MAKE) all ci-pytest)
|
||||||
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
examples:
|
examples:
|
||||||
|
|||||||
@ -43,10 +43,10 @@ function(add_runtests _targetname _test_flags)
|
|||||||
if(CURL_TEST_BUNDLES)
|
if(CURL_TEST_BUNDLES)
|
||||||
set(_test_flags "${_test_flags} -bundle")
|
set(_test_flags "${_test_flags} -bundle")
|
||||||
endif()
|
endif()
|
||||||
unset(_depends)
|
|
||||||
# Skip walking through dependent targets before running tests in CI.
|
# Skip walking through dependent targets before running tests in CI.
|
||||||
# This avoids: GNU Make doing a slow re-evaluation of all targets and
|
# This avoids: GNU Make doing a slow re-evaluation of all targets and
|
||||||
# skipping them, MSBuild doing a re-evaluation, and actually rebuilding them.
|
# skipping them, MSBuild doing a re-evaluation, and actually rebuilding them.
|
||||||
|
unset(_depends)
|
||||||
if(NOT _targetname STREQUAL "test-ci")
|
if(NOT _targetname STREQUAL "test-ci")
|
||||||
set(_depends "testdeps")
|
set(_depends "testdeps")
|
||||||
endif()
|
endif()
|
||||||
@ -65,6 +65,20 @@ function(add_runtests _targetname _test_flags)
|
|||||||
)
|
)
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
|
function(add_pytest _targetname _test_flags)
|
||||||
|
unset(_depends)
|
||||||
|
if(NOT _targetname STREQUAL "pytest-ci")
|
||||||
|
set(_depends "test-http-clients")
|
||||||
|
endif()
|
||||||
|
string(REPLACE " " ";" _test_flags_list "${_test_flags}")
|
||||||
|
add_custom_target(${_targetname}
|
||||||
|
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||||
|
COMMAND pytest ${_test_flags_list} "${CMAKE_CURRENT_SOURCE_DIR}/http"
|
||||||
|
DEPENDS "${_depends}"
|
||||||
|
VERBATIM USES_TERMINAL
|
||||||
|
)
|
||||||
|
endfunction()
|
||||||
|
|
||||||
# Create configurehelp.pm, used by tests needing to run the C preprocessor.
|
# Create configurehelp.pm, used by tests needing to run the C preprocessor.
|
||||||
if(MSVC OR CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang")
|
if(MSVC OR CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang")
|
||||||
set(CURL_CPP "\"${CMAKE_C_COMPILER}\" -E")
|
set(CURL_CPP "\"${CMAKE_C_COMPILER}\" -E")
|
||||||
@ -94,3 +108,6 @@ add_runtests(test-nonflaky "-a -p ~flaky ~timing-dependent")
|
|||||||
add_runtests(test-ci "-a -p ~flaky ~timing-dependent -r -rm -j2")
|
add_runtests(test-ci "-a -p ~flaky ~timing-dependent -r -rm -j2")
|
||||||
add_runtests(test-torture "-a -t -j2")
|
add_runtests(test-torture "-a -t -j2")
|
||||||
add_runtests(test-event "-a -e")
|
add_runtests(test-event "-a -e")
|
||||||
|
|
||||||
|
add_pytest(curl-pytest "")
|
||||||
|
add_pytest(curl-pytest-ci "-v")
|
||||||
|
|||||||
@ -122,6 +122,7 @@ TEST_COMMON =
|
|||||||
|
|
||||||
if CROSSCOMPILING
|
if CROSSCOMPILING
|
||||||
TEST = @echo "NOTICE: we can't run the tests when cross-compiling!"
|
TEST = @echo "NOTICE: we can't run the tests when cross-compiling!"
|
||||||
|
PYTEST = $(TEST)
|
||||||
else # if not cross-compiling:
|
else # if not cross-compiling:
|
||||||
if USE_TEST_BUNDLES
|
if USE_TEST_BUNDLES
|
||||||
TEST_COMMON += -bundle
|
TEST_COMMON += -bundle
|
||||||
@ -140,6 +141,8 @@ TEST_NF = -a -p ~flaky ~timing-dependent
|
|||||||
|
|
||||||
# special CI target derived from nonflaky with CI-specific flags
|
# special CI target derived from nonflaky with CI-specific flags
|
||||||
TEST_CI = $(TEST_NF) -r -rm -j2
|
TEST_CI = $(TEST_NF) -r -rm -j2
|
||||||
|
|
||||||
|
PYTEST = pytest
|
||||||
endif
|
endif
|
||||||
|
|
||||||
CD2NROFF = $(top_srcdir)/scripts/cd2nroff $< >$@
|
CD2NROFF = $(top_srcdir)/scripts/cd2nroff $< >$@
|
||||||
@ -177,6 +180,11 @@ torture-test: perlcheck all
|
|||||||
event-test: perlcheck all
|
event-test: perlcheck all
|
||||||
$(TEST) $(TEST_E) $(TFLAGS)
|
$(TEST) $(TEST_E) $(TFLAGS)
|
||||||
|
|
||||||
|
default-pytest: ci-pytest
|
||||||
|
|
||||||
|
ci-pytest: all
|
||||||
|
srcdir=$(srcdir) $(PYTEST) -v $(srcdir)/http
|
||||||
|
|
||||||
checksrc:
|
checksrc:
|
||||||
(cd libtest && $(MAKE) checksrc)
|
(cd libtest && $(MAKE) checksrc)
|
||||||
(cd unit && $(MAKE) checksrc)
|
(cd unit && $(MAKE) checksrc)
|
||||||
|
|||||||
@ -22,6 +22,8 @@
|
|||||||
#
|
#
|
||||||
###########################################################################
|
###########################################################################
|
||||||
|
|
||||||
|
add_custom_target(test-http-clients)
|
||||||
|
|
||||||
# Get 'check_PROGRAMS' variable
|
# Get 'check_PROGRAMS' variable
|
||||||
transform_makefile_inc("Makefile.inc" "${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake")
|
transform_makefile_inc("Makefile.inc" "${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake")
|
||||||
include("${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake")
|
include("${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake")
|
||||||
@ -30,6 +32,7 @@ foreach(_target IN LISTS check_PROGRAMS)
|
|||||||
set(_target_name "curlt-client-${_target}")
|
set(_target_name "curlt-client-${_target}")
|
||||||
add_executable(${_target_name} EXCLUDE_FROM_ALL "${_target}.c")
|
add_executable(${_target_name} EXCLUDE_FROM_ALL "${_target}.c")
|
||||||
add_dependencies(testdeps ${_target_name})
|
add_dependencies(testdeps ${_target_name})
|
||||||
|
add_dependencies(test-http-clients ${_target_name})
|
||||||
target_include_directories(${_target_name} PRIVATE
|
target_include_directories(${_target_name} PRIVATE
|
||||||
"${CURL_BINARY_DIR}/lib" # for "curl_config.h"
|
"${CURL_BINARY_DIR}/lib" # for "curl_config.h"
|
||||||
"${CURL_SOURCE_DIR}/lib" # for "curl_setup.h"
|
"${CURL_SOURCE_DIR}/lib" # for "curl_setup.h"
|
||||||
|
|||||||
@ -73,8 +73,6 @@ def env(pytestconfig) -> Env:
|
|||||||
pytest.skip(env.incomplete_reason())
|
pytest.skip(env.incomplete_reason())
|
||||||
|
|
||||||
env.setup()
|
env.setup()
|
||||||
if not env.make_clients():
|
|
||||||
pytest.exit(1)
|
|
||||||
return env
|
return env
|
||||||
|
|
||||||
@pytest.fixture(scope="package", autouse=True)
|
@pytest.fixture(scope="package", autouse=True)
|
||||||
|
|||||||
@ -579,12 +579,3 @@ class Env:
|
|||||||
i = int(fsize / line_length) + 1
|
i = int(fsize / line_length) + 1
|
||||||
fd.write(f"{i:09d}-{s}"[0:remain-1] + "\n")
|
fd.write(f"{i:09d}-{s}"[0:remain-1] + "\n")
|
||||||
return fpath
|
return fpath
|
||||||
|
|
||||||
def make_clients(self):
|
|
||||||
client_dir = os.path.join(self.project_dir, 'tests/http/clients')
|
|
||||||
p = subprocess.run(['make'], capture_output=True, text=True,
|
|
||||||
cwd=client_dir)
|
|
||||||
if p.returncode != 0:
|
|
||||||
pytest.exit(f"`make`in {client_dir} failed:\n{p.stderr}")
|
|
||||||
return False
|
|
||||||
return True
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user