Make it possible to build curl for Windows CE using the CeGCC toolchain.
With both CMake and autotools, including tests and examples, also in CI.
The build configuration is the default one with Schannel enabled. No
3rd-party dependencies have been tested.
Also revive old code to make Schannel build with Windows CE, including
certificate verification.
Builds have been throughougly tested. But, I've made no functional tests
for this PR. Some parts (esp. file operations, like truncate and seek)
are stubbed out and likely broken as a result. Test servers build, but
they do not work on Windows CE. This patch substitutes `fstat()` calls
with `stat()`, which operate on filenames, not file handles. This may or
may not work and/or may not be secure.
About CeGCC: I used the latest available macOS binary build v0.59.1
r1397 from 2009, in native `mingw32ce` build mode. CeGCC is in effect
MinGW + GCC 4.4.0 + old/classic-mingw Windows headers. It targets
Windows CE v3.0 according to its `_WIN32_WCE` value. It means this PR
restores portions of old/classic-mingw support. It makes the Windows CE
codepath compatible with GCC 4.4.0. It also adds workaround for CMake,
which cannot identify and configure this toolchain out of the box.
Notes:
- CMake doesn't recognize CeGCC/mingw32ce, necessitating tricks as seen
with Amiga and MS-DOS.
- CMake doesn't set `MINGW` for mingw32ce. Set it and `MINGW32CE`
manually as a helper variable, in addition to `WINCE` which CMake sets
based on `CMAKE_SYSTEM_NAME`.
- CMake fails to create an implib for `libcurl.dll`, due to not
recognizing the platform as a Windowsy one. This patch adds the
necessary workaround to make it work.
- headers shipping with CeGCC miss some things curl needs for Schannel
support. Fixed by restoring and renovating code previously deleted
old-mingw code.
- it's sometime non-trivial to figure out if a fallout is WinCE,
mingw32ce, old-mingw, or GCC version-specific.
- WinCE is always Unicode. With exceptions: no `wmain`,
`GetProcAddress()`.
- `_fileno()` is said to convert from `FILE *` to `void *` which is
a Win32 file `HANDLE`. (This patch doesn't use this, but with further
effort it probably could be.)
https://stackoverflow.com/questions/3989545/how-do-i-get-the-file-handle-from-the-fopen-file-structure
- WinCE has no signals, current directory, stdio/CRT file handles, no
`_get_osfhandle()`, no `errno`, no `errno.h`. Some of this stuff is
standard C89, yet missing from this platform. Microsoft expects
Windows CE apps to use Win32 file API and `FILE *` exclusively.
- revived CeGCC here (not tested for this PR):
https://building.enlyze.com/posts/a-new-windows-ce-x86-compiler-in-2024/
On `UNDER_CE` vs. `_WIN32_WCE`: (This patch settled on `UNDER_CE`)
- A custom VS2008 WinCE toolchain does not set any of these.
The compiler binaries don't contain these strings, and has no compiler
option for targeting WinCE, hinting that a vanilla toolchain isn't
setting any of them either.
- `UNDER_CE` is automatically defined by the CeGCC compiler.
https://cegcc.sourceforge.net/docs/details.html
- `UNDER_CE` is similar to `_WIN32`, except it's not set automatically
by all compilers. It's not supposed to have any value, like a version.
(Though e.g. OpenSSL sets it to a version)
- `_WIN32_WCE` is the CE counterpart of the non-CE `_WIN32_WINNT` macro.
That does return the targeted Windows CE version.
- `_WIN32_WCE` is not defined by compilers, and relies on a header
setting it to a default, or the build to set it to the desired target
version. This is also how `_WIN32_WINNT` works.
- `_WIN32_WCE` default is set by `windef.h` in CeGCC.
- `_WIN32_WCE` isn't set to a default by MSVC Windows CE headers (the
ones I checked at least).
- CMake sets `_WIN32_WCE=<ver>`, `UNDER_CE`, `WINCE` for MSVC WinCE.
- `_WIN32_WCE` seems more popular in other projects, including CeGCC
itself. `zlib` is a notable exception amongst curl dependencies,
which uses `UNDER_CE`.
- Since `_WIN32_WCE` needs "certain" headers to have it defined, it's
undefined depending on headers included beforehand.
- `curl/curl.h` re-uses `_WIN32_WCE`'s as a self-guard, relying on
its not-(necessarily)-defined-by-default property:
|
||
|---|---|---|
| .. | ||
| clients | ||
| testenv | ||
| .gitignore | ||
| CMakeLists.txt | ||
| config.ini.in | ||
| conftest.py | ||
| Makefile.am | ||
| README.md | ||
| requirements.txt | ||
| scorecard.py | ||
| test_01_basic.py | ||
| test_02_download.py | ||
| test_03_goaway.py | ||
| test_04_stuttered.py | ||
| test_05_errors.py | ||
| test_06_eyeballs.py | ||
| test_07_upload.py | ||
| test_08_caddy.py | ||
| test_09_push.py | ||
| test_10_proxy.py | ||
| test_11_unix.py | ||
| test_12_reuse.py | ||
| test_13_proxy_auth.py | ||
| test_14_auth.py | ||
| test_15_tracing.py | ||
| test_16_info.py | ||
| test_17_ssl_use.py | ||
| test_18_methods.py | ||
| test_19_shutdown.py | ||
| test_20_websockets.py | ||
| test_30_vsftpd.py | ||
| test_31_vsftpds.py | ||
| test_32_ftps_vsftpd.py | ||
The curl HTTP Test Suite
This is an additional test suite using a combination of Apache httpd and nghttpx servers to perform various tests beyond the capabilities of the standard curl test suite.
Usage
The test cases and necessary files are in tests/http. You can invoke
pytest from there or from the top level curl checkout and it finds all
tests.
curl> pytest test/http
platform darwin -- Python 3.9.15, pytest-6.2.0, py-1.10.0, pluggy-0.13.1
rootdir: /Users/sei/projects/curl
collected 5 items
tests/http/test_01_basic.py .....
Pytest takes arguments. -v increases its verbosity and can be used several times. -k <expr> can be used to run only matching test cases. The expr can be something resembling a python test or just a string that needs to match test cases in their names.
curl/tests/http> pytest -vv -k test_01_02
runs all test cases that have test_01_02 in their name. This does not have to be the start of the name.
Depending on your setup, some test cases may be skipped and appear as s in
the output. If you run pytest verbose, it also gives you the reason for
skipping.
Prerequisites
You need:
- a recent Python, the
cryptographymodule and, of course,pytest - an apache httpd development version. On Debian/Ubuntu, the package
apache2-devhas this - a local
curlproject build - optionally, a
nghttpxwith HTTP/3 enabled or h3 test cases are skipped
Configuration
Via curl's configure script you may specify:
--with-test-nghttpx=<path-of-nghttpx>if you have nghttpx to use somewhere outside your$PATH.--with-test-httpd=<httpd-install-path>if you have an Apache httpd installed somewhere else. On Debian/Ubuntu it will otherwise look into/usr/binand/usr/sbinto find those.--with-test-caddy=<caddy-install-path>if you have a Caddy web server installed somewhere else.--with-test-vsftpd=<vsftpd-install-path>if you have a vsftpd ftp server installed somewhere else.
Usage Tips
Several test cases are parameterized, for example with the HTTP version to use. If you want to run a test with a particular protocol only, use a command line like:
curl/tests/http> pytest -k "test_02_06 and h2"
Test cases can be repeated, with the pytest-repeat module (pip install pytest-repeat). Like in:
curl/tests/http> pytest -k "test_02_06 and h2" --count=100
which then runs this test case a hundred times. In case of flaky tests, you can make pytest stop on the first one with:
curl/tests/http> pytest -k "test_02_06 and h2" --count=100 --maxfail=1
which allow you to inspect output and log files for the failed run. Speaking of log files, the verbosity of pytest is also used to collect curl trace output. If you specify -v three times, the curl command is started with --trace:
curl/tests/http> pytest -vvv -k "test_02_06 and h2" --count=100 --maxfail=1
all of curl's output and trace file are found in tests/http/gen/curl.
Writing Tests
There is a lot of pytest documentation with examples. No use in repeating that here. Assuming you are somewhat familiar with it, it is useful how this general test suite is setup. Especially if you want to add test cases.
Servers
In conftest.py 3 "fixtures" are defined that are used by all test cases:
env: the test environment. It is an instance of classtestenv/env.py:Env. It holds all information about paths, availability of features (HTTP/3), port numbers to use, domains and SSL certificates for those.httpd: the Apache httpd instance, configured and started, then stopped at the end of the test suite. It has sites configured for the domains fromenv. It also loads a local modulemod_curltest?and makes it available in certain locations. (more on mod_curltest below).nghttpx: an instance of nghttpx that provides HTTP/3 support.nghttpxproxies those requests to thehttpdserver. In a direct mapping, so you may access all the resources under the same path as with HTTP/2. Only the port number used for HTTP/3 requests are different.
pytest manages these fixture so that they are created once and terminated
before exit. This means you can Ctrl-C a running pytest and the server then
shutdowns. Only when you brutally chop its head off, might there be servers
left behind.
Test Cases
Tests making use of these fixtures have them in their parameter list. This tells pytest that a particular test needs them, so it has to create them. Since one can invoke pytest for just a single test, it is important that a test references the ones it needs.
All test cases start with test_ in their name. We use a double number scheme to group them. This makes it ease to run only specific tests and also give a short mnemonic to communicate trouble with others in the project. Otherwise you are free to name test cases as you think fitting.
Tests are grouped thematically in a file with a single Python test class. This is convenient if you need a special "fixture" for several tests. "fixtures" can have "class" scope.
There is a curl helper class that knows how to invoke curl and interpret its output. Among other things, it does add the local CA to the command line, so that SSL connections to the test servers are verified. Nothing prevents anyone from running curl directly, for specific uses not covered by the CurlClient class.
mod_curltest
The module source code is found in testenv/mod_curltest. It is compiled using the apxs command, commonly provided via the apache2-dev package. Compilation is quick and done once at the start of a test run.
The module adds 2 "handlers" to the Apache server (right now). Handler are pieces of code that receive HTTP requests and generate the response. Those handlers are:
curltest-echo: hooked up on the path/curltest/echo. This one echoes a request and copies all data from the request body to the response body. Useful for simulating upload and checking that the data arrived as intended.curltest-tweak: hooked up on the path/curltest/tweak. This handler is more of a Swiss army knife. It interprets parameters from the URL query string to drive its behavior.status=nnn: generate a response with HTTP status codennn.chunks=n: generatenchunks of data in the response body, defaults to 3.chunk_size=nnn: each chunk should containnnnbytes of data. Maximum is 16KB right now.chunkd_delay=duration: waitdurationtime between writing chunksdelay=duration: waitdurationtime to send the response headersbody_error=(timeout|reset): produce an error after the first chunk in the response bodyid=str: addstrin the response headerrequest-id
duration values are integers, optionally followed by a unit. Units are:
d: days (probably not useful here)h: hoursmi: minutess: seconds (the default)ms: milliseconds
As you can see, mod_curltest's tweak handler allow to simulate many kinds of
responses. An example of its use is test_03_01 where responses are delayed
using chunk_delay. This gives the response a defined duration and the test
uses that to reload httpd in the middle of the first request. A graceful
reload in httpd lets ongoing requests finish, but closes the connection
afterwards and tears down the serving process. The following request then
needs to open a new connection. This is verified by the test case.