[Openvpn-devel,v3,2/3] Build unit tests in mingw Windows build

Message ID 20230208005925.393200-1-selva.nair@gmail.com
State Accepted
Headers show
Series None | expand

Commit Message

Selva Nair Feb. 8, 2023, 12:59 a.m. UTC
From: Selva Nair <selva.nair@gmail.com>

- Minor changes to the build system to include some
  dependencies for Windows build

- test_tls_crypt not built as it will pull in win32.c and
  its dependencies

- If cross-compiling, "make check" will only build the tests but not
  run any. Copy to Windows and run manually. Executables are in
  <buid-dir>/tests/unit_tests/openvpn/.libs/ and these depend on
  cmocka.dll in addition to openssl libs that some tests link to.

  Building with mingw on Windows should run the tests (untested).

v2: networking_testdriver was mistakenly enabled to run, while
originally it was only set to build. Corrected.

v3: exclude check_engine_keys.sh when cross-compiling
As suggested by Arne Schwabe <arne@rfc2549.org>

Signed-off-by: Selva Nair <selva.nair@gmail.com>
---
 configure.ac                              |  2 ++
 tests/Makefile.am                         |  2 ++
 tests/unit_tests/engine-key/Makefile.am   |  2 ++
 tests/unit_tests/example_test/Makefile.am |  2 ++
 tests/unit_tests/openvpn/Makefile.am      | 28 +++++++++++++++++++----
 5 files changed, 31 insertions(+), 5 deletions(-)

Comments

Arne Schwabe Feb. 8, 2023, 11:41 a.m. UTC | #1
Am 08.02.23 um 01:59 schrieb selva.nair@gmail.com:
> From: Selva Nair <selva.nair@gmail.com>
> 
> - Minor changes to the build system to include some
>    dependencies for Windows build
> 
> - test_tls_crypt not built as it will pull in win32.c and
>    its dependencies
> 
> - If cross-compiling, "make check" will only build the tests but not
>    run any. Copy to Windows and run manually. Executables are in
>    <buid-dir>/tests/unit_tests/openvpn/.libs/ and these depend on
>    cmocka.dll in addition to openssl libs that some tests link to.
> 
>    Building with mingw on Windows should run the tests (untested).
> 
> v2: networking_testdriver was mistakenly enabled to run, while
> originally it was only set to build. Corrected.
> 
> v3: exclude check_engine_keys.sh when cross-compiling
> As suggested by Arne Schwabe <arne@rfc2549.org>


Acked-By: Arne Schwabe <arne@rfc2549.org>

Arne
Gert Doering Feb. 10, 2023, 9:13 p.m. UTC | #2
Hi,

On Tue, Feb 07, 2023 at 07:59:25PM -0500, selva.nair@gmail.com wrote:
> From: Selva Nair <selva.nair@gmail.com>
> 
> - Minor changes to the build system to include some
>   dependencies for Windows build
> 
> - test_tls_crypt not built as it will pull in win32.c and
>   its dependencies
> 
> - If cross-compiling, "make check" will only build the tests but not
>   run any. Copy to Windows and run manually. Executables are in
>   <buid-dir>/tests/unit_tests/openvpn/.libs/ and these depend on
>   cmocka.dll in addition to openssl libs that some tests link to.

I am something wrong, or I'm missing some bits.

I took this patch, on top of commit e80720ef939 ("top of master as of
now").  MinGW on Ubuntu.  "autoreconf -iv", make clean, then
make && make check.

make check claims

make[4]: Entering directory '/home/gert/mingw/openvpn.git/tests'
==================
All 0 tests passed
==================

... but it seems to have done... nothing?

gert@ubuntu2204:~/mingw/openvpn.git$ ls -l tests/unit_test/openvpn/.libs
ls: cannot access 'tests/unit_test/openvpn/.libs': No such file or directory

... given argv_testdriver exists, I should find "something" with argv*.o*
here...

gert@ubuntu2204:~/mingw/openvpn.git$ find . -name "*argv*o"
./tests/unit_tests/openvpn/.deps/argv_testdriver-mock_get_random.Po
./tests/unit_tests/openvpn/.deps/tls_crypt_testdriver-argv.Po
./tests/unit_tests/openvpn/.deps/argv_testdriver-test_argv.Po
./tests/unit_tests/openvpn/.deps/argv_testdriver-mock_msg.Po
./tests/unit_tests/openvpn/.deps/argv_testdriver-platform.Po
./tests/unit_tests/openvpn/.deps/argv_testdriver-buffer.Po
./tests/unit_tests/openvpn/.deps/pkt_testdriver-argv.Po
./tests/unit_tests/openvpn/.deps/argv_testdriver-argv.Po
./src/openvpn/.deps/tls_crypt_testdriver-argv.Po
./src/openvpn/.deps/argv.Po
./src/openvpn/.deps/argv_testdriver-win32-util.Po
./src/openvpn/.deps/argv_testdriver-platform.Po
./src/openvpn/.deps/argv_testdriver-buffer.Po
./src/openvpn/.deps/pkt_testdriver-argv.Po
./src/openvpn/.deps/argv_testdriver-argv.Po
./src/openvpn/argv.o

... so it seems as if it did the "make depend" dance for the unit_tests,
but then didn't compile anything for real.


Did I apply stuff in the wrong order?  Do I need to more forcefully clean
my build tree?

slightly puzzled...

gert
Selva Nair Feb. 10, 2023, 9:58 p.m. UTC | #3
On Fri, Feb 10, 2023 at 4:13 PM Gert Doering <gert@greenie.muc.de> wrote:

> Hi,
>
> On Tue, Feb 07, 2023 at 07:59:25PM -0500, selva.nair@gmail.com wrote:
> > From: Selva Nair <selva.nair@gmail.com>
> >
> > - Minor changes to the build system to include some
> >   dependencies for Windows build
> >
> > - test_tls_crypt not built as it will pull in win32.c and
> >   its dependencies
> >
> > - If cross-compiling, "make check" will only build the tests but not
> >   run any. Copy to Windows and run manually. Executables are in
> >   <buid-dir>/tests/unit_tests/openvpn/.libs/ and these depend on
> >   cmocka.dll in addition to openssl libs that some tests link to.
>
> I am something wrong, or I'm missing some bits.
>
> I took this patch, on top of commit e80720ef939 ("top of master as of
> now").  MinGW on Ubuntu.  "autoreconf -iv", make clean, then
> make && make check.
>
> make check claims
>
> make[4]: Entering directory '/home/gert/mingw/openvpn.git/tests'
> ==================
> All 0 tests passed
> ==================
>
> ... but it seems to have done... nothing?
>

My patch only enables to build the tests while cross-compiling but disables
running them. As the executables  are not native, you have to manually copy
them to Windows and run there.

With the next patch from Arne, GHA actions will copy it automagically to
Windows and run there. But that works only for github actions.

Selva
Selva Nair Feb. 10, 2023, 11:10 p.m. UTC | #4
Hi

On Fri, Feb 10, 2023 at 4:13 PM Gert Doering <gert@greenie.muc.de> wrote:

> Hi,
>
> On Tue, Feb 07, 2023 at 07:59:25PM -0500, selva.nair@gmail.com wrote:
> > From: Selva Nair <selva.nair@gmail.com>
> >
> > - Minor changes to the build system to include some
> >   dependencies for Windows build
> >
> > - test_tls_crypt not built as it will pull in win32.c and
> >   its dependencies
> >
> > - If cross-compiling, "make check" will only build the tests but not
> >   run any. Copy to Windows and run manually. Executables are in
> >   <buid-dir>/tests/unit_tests/openvpn/.libs/ and these depend on
> >   cmocka.dll in addition to openssl libs that some tests link to.
>
> I am something wrong, or I'm missing some bits.
>
> I took this patch, on top of commit e80720ef939 ("top of master as of
> now").  MinGW on Ubuntu.  "autoreconf -iv", make clean, then
> make && make check.
>
> make check claims
>
> make[4]: Entering directory '/home/gert/mingw/openvpn.git/tests'
> ==================
> All 0 tests passed
> ==================
>
> ... but it seems to have done... nothing?
>
> gert@ubuntu2204:~/mingw/openvpn.git$ ls -l tests/unit_test/openvpn/.libs
> ls: cannot access 'tests/unit_test/openvpn/.libs': No such file or
> directory
>
> ... given argv_testdriver exists, I should find "something" with argv*.o*
> here...
>
> gert@ubuntu2204:~/mingw/openvpn.git$ find . -name "*argv*o"
> ./tests/unit_tests/openvpn/.deps/argv_testdriver-mock_get_random.Po
> ./tests/unit_tests/openvpn/.deps/tls_crypt_testdriver-argv.Po
> ./tests/unit_tests/openvpn/.deps/argv_testdriver-test_argv.Po
> ./tests/unit_tests/openvpn/.deps/argv_testdriver-mock_msg.Po
> ./tests/unit_tests/openvpn/.deps/argv_testdriver-platform.Po
> ./tests/unit_tests/openvpn/.deps/argv_testdriver-buffer.Po
> ./tests/unit_tests/openvpn/.deps/pkt_testdriver-argv.Po
> ./tests/unit_tests/openvpn/.deps/argv_testdriver-argv.Po
> ./src/openvpn/.deps/tls_crypt_testdriver-argv.Po
> ./src/openvpn/.deps/argv.Po
> ./src/openvpn/.deps/argv_testdriver-win32-util.Po
> ./src/openvpn/.deps/argv_testdriver-platform.Po
> ./src/openvpn/.deps/argv_testdriver-buffer.Po
> ./src/openvpn/.deps/pkt_testdriver-argv.Po
> ./src/openvpn/.deps/argv_testdriver-argv.Po
> ./src/openvpn/argv.o
>
> ... so it seems as if it did the "make depend" dance for the unit_tests,
> but then didn't compile anything for real.
>
>
> Did I apply stuff in the wrong order?  Do I need to more forcefully clean
> my build tree?
>

Ignore the previous email  -- (I behaved as if I can't read more than a
pageful).

Looks like unit-tests are not enabled during configure. For that, cmocka
should be available in the search path or set using CMOCKA_LIBS and
CMOCKA_INCLUDES.

It took a while for me to figure out how to cross-compile cmocka using
cmake and mingw on Linux. Finally what worked was pretty simple:

git clone https://github.com/clibs/cmocka.git
cd cmocka
checkout cmocka-1.1.5
mkdir build
cd build
cmake -DCMAKE_SYSTEM_NAME=Windows -DCMAKE_C_COMPILER=x86_64-w64-mingw32-gcc
\
            -DCMAKE_SHARED_LINKER_FLAGS=-static-libgcc \
            -DCMAKE_INSTALL_PREFIX=$HOME/mingw-cmocka/ -S .. -B .
make install

Selva
Gert Doering Feb. 11, 2023, 6:32 p.m. UTC | #5
Hi,

On Fri, Feb 10, 2023 at 06:10:41PM -0500, Selva Nair wrote:
> Ignore the previous email  -- (I behaved as if I can't read more than a
> pageful).

:-)

> Looks like unit-tests are not enabled during configure. For that, cmocka
> should be available in the search path or set using CMOCKA_LIBS and
> CMOCKA_INCLUDES.

Yes, that's the conclusion I arrived at, after I sent yesterday's
mail and went to bed - "oh no, it can't do anything, there is no cmocka
in that cross-compile environment".  But I didn't want to get up again
just to send that followup mail ;-)

> It took a while for me to figure out how to cross-compile cmocka using
> cmake and mingw on Linux. Finally what worked was pretty simple:
> 
> git clone https://github.com/clibs/cmocka.git
> cd cmocka
> checkout cmocka-1.1.5
> mkdir build
> cd build
> cmake -DCMAKE_SYSTEM_NAME=Windows -DCMAKE_C_COMPILER=x86_64-w64-mingw32-gcc
> \
>             -DCMAKE_SHARED_LINKER_FLAGS=-static-libgcc \
>             -DCMAKE_INSTALL_PREFIX=$HOME/mingw-cmocka/ -S .. -B .
> make install

This would have been my next question "how do I build this?" :-)

... adapted to my build environment...

-- Installing: /home/gert/mingw/opt/include/cmocka.h
-- Installing: /home/gert/mingw/opt/bin/cmocka.dll

... then returning to openvpn & re-running configure, it will
still not find it :-(

checking for CMOCKA... no
configure: WARNING: cmocka.pc not found on the system.  Unit tests disabled

... so, configure CMOCKA_CFLAGS/CMOCKA_LIBS it is...

checking for CMOCKA... yes

... but then trying to build the test drivers fails, and from the looks
of it, it's finding but not utilizing the cmocka lib...

/bin/bash ../../../libtool  --tag=CC   --mode=link i686-w64-mingw32-gcc -I/home/gert/mingw/opt/include  -I/home/gert/mingw/opt/include -I../../../include -I/home/gert/mingw/opt/include -Wall -Wno-stringop-truncation -I/home/gert/mingw/opt/include -std=c99 -L/home/gert/mingw/lib -L/home/gert/mingw/opt/lib64 -lssl -lcrypto  -L/home/gert/mingw/opt/lib -llzo2 -L/home/gert/mingw/opt/lib -lcmocka -L/home/gert/mingw/opt/lib -o example_testdriver.exe example_testdriver-test.o  
libtool: link: i686-w64-mingw32-gcc -I/home/gert/mingw/opt/include -I/home/gert/mingw/opt/include -I../../../include -I/home/gert/mingw/opt/include -Wall -Wno-stringop-truncation -I/home/gert/mingw/opt/include -std=c99 -o .libs/example_testdriver.exe example_testdriver-test.o  -L/home/gert/mingw/lib -L/home/gert/mingw/opt/lib64 -lssl -lcrypto -L/home/gert/mingw/opt/lib /home/gert/mingw/opt/lib/liblzo2.a -lwinmm -lcmocka
/usr/bin/i686-w64-mingw32-ld: example_testdriver-test.o:test.c:(.text+0x89): undefined reference to `_assert_int_equal'
/usr/bin/i686-w64-mingw32-ld: example_testdriver-test.o:test.c:(.text+0xc6): undefined reference to `_assert_int_equal'
/usr/bin/i686-w64-mingw32-ld: example_testdriver-test.o:test.c:(.text+0x153): undefined reference to `_cmocka_run_group_tests'
collect2: error: ld returned 1 exit status
make[5]: *** [Makefile:461: example_testdriver.exe] Error 1

... tried various permutations of "-L$path -lcmocka", putting the
actual path to "libcmocka.dll.a" on the link/libtool command line, but
the error never changes...

*scratch head*

Need to debug this more tonight...

gert
Selva Nair Feb. 11, 2023, 6:44 p.m. UTC | #6
Hi,

On Sat, Feb 11, 2023 at 1:32 PM Gert Doering <gert@greenie.muc.de> wrote:

>
>
> /bin/bash ../../../libtool  --tag=CC   --mode=link i686-w64-mingw32-gcc


This is a 32 bit build which I never tried. Maybe cmocka is not built for
32 bit?


> -I/home/gert/mingw/opt/include  -I/home/gert/mingw/opt/include
> -I../../../include -I/home/gert/mingw/opt/include -Wall
> -Wno-stringop-truncation -I/home/gert/mingw/opt/include -std=c99
> -L/home/gert/mingw/lib -L/home/gert/mingw/opt/lib64 -lssl -lcrypto
> -L/home/gert/mingw/opt/lib -llzo2 -L/home/gert/mingw/opt/lib -lcmocka
> -L/home/gert/mingw/opt/lib -o example_testdriver.exe
> example_testdriver-test.o
> libtool: link: i686-w64-mingw32-gcc -I/home/gert/mingw/opt/include
> -I/home/gert/mingw/opt/include -I../../../include
> -I/home/gert/mingw/opt/include -Wall -Wno-stringop-truncation
> -I/home/gert/mingw/opt/include -std=c99 -o .libs/example_testdriver.exe
> example_testdriver-test.o  -L/home/gert/mingw/lib
> -L/home/gert/mingw/opt/lib64 -lssl -lcrypto -L/home/gert/mingw/opt/lib
> /home/gert/mingw/opt/lib/liblzo2.a -lwinmm -lcmocka
> /usr/bin/i686-w64-mingw32-ld:
> example_testdriver-test.o:test.c:(.text+0x89): undefined reference to
> `_assert_int_equal'
> /usr/bin/i686-w64-mingw32-ld:
> example_testdriver-test.o:test.c:(.text+0xc6): undefined reference to
> `_assert_int_equal'
> /usr/bin/i686-w64-mingw32-ld:
> example_testdriver-test.o:test.c:(.text+0x153): undefined reference to
> `_cmocka_run_group_tests'
>

I had seen something similar with  the master branch -- the def had some
functions missing. But 1.1.5 worked out of the box.

Selva
Gert Doering Feb. 13, 2023, 6:52 p.m. UTC | #7
Tested on Linux (native), Linux / MinGW, AIX.  Native platforms still
run the tests (and succeed / fail as before).

On MinGW, if there is no cross-built libcmocka, this patch will not change
anything.  If there is, it tries to build the tests, which fails for me,
but this seems to be a local install issue with cross-built cmocka and
32/64 bit compilers.  It's not a problem introduced by this patch (the
difference here is "do not *run* the resulting binaries") so I've decided
to move forward with merging it.

Your patch has been applied to the master and release/2.6 branch.

commit e3ad1fc4230fb3a08b484e76ce0a31f2479d3c8f (master)
commit a6d7e8843154bfca8b98a9eb11a11b320a03db36 (release/2.6)
Author: Selva Nair
Date:   Tue Feb 7 19:59:25 2023 -0500

     Build unit tests in mingw Windows build

     Signed-off-by: Selva Nair <selva.nair@gmail.com>
     Acked-by: Arne Schwabe <arne@rfc2549.org>
     Message-Id: <20230208005925.393200-1-selva.nair@gmail.com>
     URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg26188.html
     Signed-off-by: Gert Doering <gert@greenie.muc.de>


--
kind regards,

Gert Doering
Gert Doering Feb. 14, 2023, 10:21 a.m. UTC | #8
Hi,

On Sat, Feb 11, 2023 at 01:44:04PM -0500, Selva Nair wrote:
> On Sat, Feb 11, 2023 at 1:32 PM Gert Doering <gert@greenie.muc.de> wrote:
> 
> > /bin/bash ../../../libtool  --tag=CC   --mode=link i686-w64-mingw32-gcc
> 
> This is a 32 bit build which I never tried. Maybe cmocka is not built for
> 32 bit?

Yes, that was spot-on.

Found time to debug this with Arne today, and all the "non-cmocka" stuff
was built with "configure --host=i686-w64-mingw32" while cmocka got
"-DCMAKE_C_COMPILER=x86_64-w64-mingw32-gcc", so the resulting .a library
was full of 64 bit objects... which, of course, "file" doesn't tell on
the .a, but unpacking libcmocka.dll.a + libcrypto.dll.a and looking at 
some of the contained .o told me...

gert@ubuntu2204:/tmp$ file cmocka_dll_d000001.o libcrypto_3_dll_d000001.o
cmocka_dll_d000001.o:      Intel amd64 COFF object file, no line number info, not stripped, 5 sections, symbol offset=0x138, 8 symbols, 1st section name ".text"
libcrypto_3_dll_d000001.o: Intel 80386 COFF object file, no line number info, not stripped, 5 sections, symbol offset=0x134, 9 symbols, 1st section name ".text"


... so, changed the cmocka CMAKE invocation to 

    cmake -DCMAKE_SYSTEM_NAME=Windows \
            -DCMAKE_C_COMPILER=i686-w64-mingw32-gcc \
            -DCMAKE_CXX_COMPILER=i686-w64-mingw32-g++ \
...

rebuilt cmocka, and "make test" now does what we expect it to do - build
something

gert@ubuntu2204:~/mingw/openvpn.git$ ls -l ./tests/unit_tests/openvpn/.libs
total 6504
-rwxrwxr-x 1 gert gert 541621 Feb 14 10:11 argv_testdriver.exe
-rw-rw-r-- 1 gert gert   6229 Feb 14 10:11 argv_testdriver_ltshwrapper
-rwxrwxr-x 1 gert gert 816794 Feb 14 10:12 auth_token_testdriver.exe
-rw-rw-r-- 1 gert gert   6248 Feb 14 10:12 auth_token_testdriver_ltshwrapper
-rwxrwxr-x 1 gert gert 536193 Feb 14 10:11 buffer_testdriver.exe
...

and not fail :-)


So, I can confirm that the yesterday-merged patch will make "make check"
on a MinGW system do the right thing.  I didn't test 64 bit compiles, as
that wouldn't add insights on "it's make / configure specific" changes.

Thanks for your assistence and patience,

gert

Patch

diff --git a/configure.ac b/configure.ac
index 95d795c3..66ba6f38 100644
--- a/configure.ac
+++ b/configure.ac
@@ -364,6 +364,8 @@  case "$host" in
 		;;
 esac
 
+AM_CONDITIONAL([CROSS_COMPILING], test "${cross_compiling}" = "yes")
+
 PKG_PROG_PKG_CONFIG
 AC_PROG_CPP
 AC_PROG_INSTALL
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 87dd7e17..a46f2573 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -14,10 +14,12 @@  MAINTAINERCLEANFILES = \
 
 SUBDIRS = unit_tests
 
+if !WIN32
 test_scripts = t_client.sh t_lpback.sh t_cltsrv.sh
 if HAVE_SITNL
 test_scripts += t_net.sh
 endif
+endif
 
 TESTS_ENVIRONMENT = top_srcdir="$(top_srcdir)"
 TESTS = $(test_scripts)
diff --git a/tests/unit_tests/engine-key/Makefile.am b/tests/unit_tests/engine-key/Makefile.am
index 24622251..0c288857 100644
--- a/tests/unit_tests/engine-key/Makefile.am
+++ b/tests/unit_tests/engine-key/Makefile.am
@@ -12,7 +12,9 @@  TESTS_ENVIRONMENT = srcdir="$(abs_srcdir)"; \
 	top_srcdir="$(top_srcdir)"; \
 	export srcdir builddir top_builddir top_srcdir;
 
+if !CROSS_COMPILING
 TESTS = check_engine_keys.sh
+endif
 check_engine_keys.sh: $(conffiles)
 
 CLEANFILES = \
diff --git a/tests/unit_tests/example_test/Makefile.am b/tests/unit_tests/example_test/Makefile.am
index 04a5ad35..24eb0ba1 100644
--- a/tests/unit_tests/example_test/Makefile.am
+++ b/tests/unit_tests/example_test/Makefile.am
@@ -2,7 +2,9 @@  AUTOMAKE_OPTIONS = foreign
 
 check_PROGRAMS = example_testdriver example2_testdriver
 
+if !CROSS_COMPILING
 TESTS = $(check_PROGRAMS)
+endif
 
 example_testdriver_CFLAGS  = @TEST_CFLAGS@
 example_testdriver_LDFLAGS = @TEST_LDFLAGS@
diff --git a/tests/unit_tests/openvpn/Makefile.am b/tests/unit_tests/openvpn/Makefile.am
index 7720a85d..8d2386e0 100644
--- a/tests/unit_tests/openvpn/Makefile.am
+++ b/tests/unit_tests/openvpn/Makefile.am
@@ -7,14 +7,22 @@  test_binaries += argv_testdriver buffer_testdriver
 endif
 
 test_binaries += crypto_testdriver packet_id_testdriver auth_token_testdriver ncp_testdriver misc_testdriver \
-    pkt_testdriver
+	pkt_testdriver
 if HAVE_LD_WRAP_SUPPORT
+if !WIN32
 test_binaries += tls_crypt_testdriver
 endif
+endif
 
 test_binaries += provider_testdriver
 
+if WIN32
+LDADD = -lws2_32
+endif
+
+if !CROSS_COMPILING
 TESTS = $(test_binaries)
+endif
 check_PROGRAMS = $(test_binaries)
 
 if HAVE_SITNL
@@ -31,12 +39,14 @@  argv_testdriver_SOURCES = test_argv.c mock_msg.c mock_msg.h \
 	mock_get_random.c \
 	$(openvpn_srcdir)/platform.c \
 	$(openvpn_srcdir)/buffer.c \
+	$(openvpn_srcdir)/win32-util.c \
 	$(openvpn_srcdir)/argv.c
 
 buffer_testdriver_CFLAGS  = @TEST_CFLAGS@ -I$(openvpn_srcdir) -I$(compat_srcdir)
 buffer_testdriver_LDFLAGS = @TEST_LDFLAGS@ -L$(openvpn_srcdir) -Wl,--wrap=parse_line
 buffer_testdriver_SOURCES = test_buffer.c mock_msg.c mock_msg.h \
 	mock_get_random.c \
+	$(openvpn_srcdir)/win32-util.c \
 	$(openvpn_srcdir)/platform.c
 
 crypto_testdriver_CFLAGS  = @TEST_CFLAGS@ \
@@ -51,6 +61,7 @@  crypto_testdriver_SOURCES = test_crypto.c mock_msg.c mock_msg.h \
 	$(openvpn_srcdir)/packet_id.c \
 	$(openvpn_srcdir)/platform.c \
 	$(openvpn_srcdir)/mtu.c \
+	$(openvpn_srcdir)/win32-util.c \
 	$(openvpn_srcdir)/mss.c
 
 packet_id_testdriver_CFLAGS  = @TEST_CFLAGS@ \
@@ -63,14 +74,14 @@  packet_id_testdriver_SOURCES = test_packet_id.c mock_msg.c mock_msg.h \
 	$(openvpn_srcdir)/packet_id.c \
 	$(openvpn_srcdir)/platform.c \
 	$(openvpn_srcdir)/reliable.c \
+	$(openvpn_srcdir)/win32-util.c \
 	$(openvpn_srcdir)/session_id.c
 
-
 pkt_testdriver_CFLAGS  = @TEST_CFLAGS@ \
 	-I$(openvpn_includedir) -I$(compat_srcdir) -I$(openvpn_srcdir)
 pkt_testdriver_LDFLAGS = @TEST_LDFLAGS@
 pkt_testdriver_SOURCES = test_pkt.c mock_msg.c mock_msg.h \
-$(openvpn_srcdir)/argv.c \
+	$(openvpn_srcdir)/argv.c \
 	$(openvpn_srcdir)/base64.c \
 	$(openvpn_srcdir)/buffer.c \
 	$(openvpn_srcdir)/crypto.c \
@@ -84,9 +95,10 @@  $(openvpn_srcdir)/argv.c \
 	$(openvpn_srcdir)/run_command.c \
 	$(openvpn_srcdir)/session_id.c \
 	$(openvpn_srcdir)/ssl_pkt.c \
+	$(openvpn_srcdir)/win32-util.c \
 	$(openvpn_srcdir)/tls_crypt.c
 
-
+if !WIN32
 tls_crypt_testdriver_CFLAGS  = @TEST_CFLAGS@ \
 	-I$(openvpn_includedir) -I$(compat_srcdir) -I$(openvpn_srcdir)
 tls_crypt_testdriver_LDFLAGS = @TEST_LDFLAGS@ \
@@ -106,6 +118,7 @@  tls_crypt_testdriver_SOURCES = test_tls_crypt.c mock_msg.c mock_msg.h \
 	$(openvpn_srcdir)/packet_id.c \
 	$(openvpn_srcdir)/platform.c \
 	$(openvpn_srcdir)/run_command.c
+endif
 
 if HAVE_SITNL
 networking_testdriver_CFLAGS = @TEST_CFLAGS@ \
@@ -136,6 +149,7 @@  provider_testdriver_SOURCES = test_provider.c mock_msg.c \
 	$(openvpn_srcdir)/buffer.c \
 	$(openvpn_srcdir)/base64.c \
 	mock_get_random.c \
+	$(openvpn_srcdir)/win32-util.c \
 	$(openvpn_srcdir)/platform.c
 
 auth_token_testdriver_CFLAGS  = @TEST_CFLAGS@ \
@@ -152,6 +166,7 @@  auth_token_testdriver_SOURCES = test_auth_token.c mock_msg.c \
 	$(openvpn_srcdir)/otime.c \
 	$(openvpn_srcdir)/packet_id.c \
 	$(openvpn_srcdir)/platform.c \
+	$(openvpn_srcdir)/win32-util.c \
 	$(openvpn_srcdir)/base64.c
 
 
@@ -169,6 +184,8 @@  ncp_testdriver_SOURCES = test_ncp.c mock_msg.c \
 	$(openvpn_srcdir)/otime.c \
 	$(openvpn_srcdir)/packet_id.c \
 	$(openvpn_srcdir)/platform.c \
+	$(openvpn_srcdir)/win32-util.c \
+	$(compat_srcdir)/compat-strsep.c \
 	$(openvpn_srcdir)/ssl_util.c
 
 misc_testdriver_CFLAGS  = @TEST_CFLAGS@ \
@@ -177,8 +194,9 @@  misc_testdriver_CFLAGS  = @TEST_CFLAGS@ \
 misc_testdriver_LDFLAGS = @TEST_LDFLAGS@
 
 misc_testdriver_SOURCES = test_misc.c mock_msg.c \
-    mock_get_random.c \
+	mock_get_random.c \
 	$(openvpn_srcdir)/buffer.c \
 	$(openvpn_srcdir)/options_util.c \
 	$(openvpn_srcdir)/ssl_util.c \
+	$(openvpn_srcdir)/win32-util.c \
 	$(openvpn_srcdir)/platform.c