Skip to contentSkip to conversation

Mock openvpn_exece on win32 also for test_tls_crypt

PATCH Superseded Arne Schwabe 3 participants 5 messages Jul 4, 2023 – Jul 17, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Mock openvpn_exece on win32 also for test_tls_crypt

This function is needed to commpile on win32 as run_command.c defines it on Unix Linux but on windows it is defined in win32.c which pulls in too many other unresolvable symbols.

Change-Id I8c8fe298eb30e211279f3fc010584b9d3bc14b4a
---
 CMakeLists.txt                               |  2 ++
 tests/unit_tests/openvpn/mock_win32_execve.c | 37 ++++++++++++++++++++
 tests/unit_tests/openvpn/test_pkt.c          |  8 -----
 3 files changed, 39 insertions(+), 8 deletions(-)
 create mode 100644 tests/unit_tests/openvpn/mock_win32_execve.c
CMakeLists.txt +2 -0
index 597dc9074..2d0cd5dd0 100644
@@ -679,6 +679,7 @@ if (BUILD_TESTING)
         )
 
     target_sources(test_pkt PRIVATE
+        tests/unit_tests/openvpn/mock_win32_execve.c
         src/openvpn/argv.c
         src/openvpn/base64.c
         src/openvpn/crypto_mbedtls.c
@@ -740,6 +741,7 @@ if (BUILD_TESTING)
             -Wl,--wrap=buffer_write_file
             -Wl,--wrap=rand_bytes)
         target_sources(test_tls_crypt PRIVATE
+            tests/unit_tests/openvpn/mock_win32_execve.c
             src/openvpn/argv.c
             src/openvpn/base64.c
             src/openvpn/crypto_mbedtls.c
tests/unit_tests/openvpn/mock_win32_execve.c new file +37 -0
new file mode 100644
index 000000000..4d37ebe33
@@ -0,0 +1,37 @@
+/*
+ *  OpenVPN -- An application to securely tunnel IP networks
+ *             over a single TCP/UDP port, with support for SSL/TLS-based
+ *             session authentication and key exchange,
+ *             packet encryption, packet authentication, and
+ *             packet compression.
+ *
+ *  Copyright (C) 2023 OpenVPN Inc <[email protected]...>
+ *  Copyright (C) 2023 Arne Schwabe <[email protected]...>
+ *
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2
+ *  as published by the Free Software Foundation.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, write to the Free Software Foundation, Inc.,
+ *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "config.h"
+#include "syshead.h"
+
+#include "win32.h"
+
+#ifdef _WIN32
+int
+openvpn_execve(const struct argv *a, const struct env_set *es, const unsigned int flags)
+{
+    ASSERT(0);
+}
+#endif
tests/unit_tests/openvpn/test_pkt.c +0 -8
index 5a53f702e..9f49ee7bd 100644
@@ -69,14 +69,6 @@ print_link_socket_actual(const struct link_socket_actual *act, struct gc_arena *
     return "dummy print_link_socket_actual from unit test";
 }
 
-#ifdef _WIN32
-int
-openvpn_execve(const struct argv *a, const struct env_set *es, const unsigned int flags)
-{
-    ASSERT(0);
-}
-#endif
-
 struct test_pkt_context {
     struct tls_auth_standalone tas_tls_auth;
     struct tls_auth_standalone tas_crypt;
Signature · 1 line
2.39.2 (Apple Git-143)
#1 lore raw
Quoted 3 lines · Arne Schwabe

This function is needed to commpile on win32 as run_command.c defines it on Unix Linux but on windows it is defined in win32.c which pulls in too many other unresolvable symbols.

Also need to add mock_win32_execve.c in Makefile.am.

Regards,

Signature · 1 line
  Frank Lichtenheld
#2 lore raw

PATCH v2 1/1 Mock openvpn_exece on win32 also for test_tls_crypt

In reply to Arne Schwabe

This function is needed to commpile on win32 as run_command.c defines it on Unix Linux but on windows it is defined in win32.c which pulls in too many other unresolvable symbols.

Patch v2: Also add mock_win32_execve.c to automake files

Change-Id I8c8fe298eb30e211279f3fc010584b9d3bc14b4a
---
 CMakeLists.txt                               |  2 ++
 tests/unit_tests/openvpn/Makefile.am         |  3 +-
 tests/unit_tests/openvpn/mock_win32_execve.c | 37 ++++++++++++++++++++
 tests/unit_tests/openvpn/test_pkt.c          |  8 -----
 4 files changed, 41 insertions(+), 9 deletions(-)
 create mode 100644 tests/unit_tests/openvpn/mock_win32_execve.c
CMakeLists.txt +2 -0
index 597dc9074..2d0cd5dd0 100644
@@ -679,6 +679,7 @@ if (BUILD_TESTING)
         )
 
     target_sources(test_pkt PRIVATE
+        tests/unit_tests/openvpn/mock_win32_execve.c
         src/openvpn/argv.c
         src/openvpn/base64.c
         src/openvpn/crypto_mbedtls.c
@@ -740,6 +741,7 @@ if (BUILD_TESTING)
             -Wl,--wrap=buffer_write_file
             -Wl,--wrap=rand_bytes)
         target_sources(test_tls_crypt PRIVATE
+            tests/unit_tests/openvpn/mock_win32_execve.c
             src/openvpn/argv.c
             src/openvpn/base64.c
             src/openvpn/crypto_mbedtls.c
tests/unit_tests/openvpn/Makefile.am +2 -1
index dbf658ac7..6b56f8480 100644
@@ -83,7 +83,7 @@ packet_id_testdriver_SOURCES = test_packet_id.c mock_msg.c mock_msg.h \
 pkt_testdriver_CFLAGS  = @TEST_CFLAGS@ \
 	-I$(top_srcdir)/include -I$(top_srcdir)/src/compat -I$(top_srcdir)/src/openvpn
 pkt_testdriver_LDFLAGS = @TEST_LDFLAGS@
-pkt_testdriver_SOURCES = test_pkt.c mock_msg.c mock_msg.h \
+pkt_testdriver_SOURCES = test_pkt.c mock_msg.c mock_msg.h mock_win32_execve.c \
 	$(top_srcdir)/src/openvpn/argv.c \
 	$(top_srcdir)/src/openvpn/base64.c \
 	$(top_srcdir)/src/openvpn/buffer.c \
@@ -110,6 +110,7 @@ tls_crypt_testdriver_LDFLAGS = @TEST_LDFLAGS@ \
 	-Wl,--wrap=parse_line \
 	-Wl,--wrap=rand_bytes
 tls_crypt_testdriver_SOURCES = test_tls_crypt.c mock_msg.c mock_msg.h \
+    mock_win32_execve.c \
 	$(top_srcdir)/src/openvpn/argv.c \
 	$(top_srcdir)/src/openvpn/base64.c \
 	$(top_srcdir)/src/openvpn/buffer.c \
tests/unit_tests/openvpn/mock_win32_execve.c new file +37 -0
new file mode 100644
index 000000000..4d37ebe33
@@ -0,0 +1,37 @@
+/*
+ *  OpenVPN -- An application to securely tunnel IP networks
+ *             over a single TCP/UDP port, with support for SSL/TLS-based
+ *             session authentication and key exchange,
+ *             packet encryption, packet authentication, and
+ *             packet compression.
+ *
+ *  Copyright (C) 2023 OpenVPN Inc <[email protected]...>
+ *  Copyright (C) 2023 Arne Schwabe <[email protected]...>
+ *
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2
+ *  as published by the Free Software Foundation.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, write to the Free Software Foundation, Inc.,
+ *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "config.h"
+#include "syshead.h"
+
+#include "win32.h"
+
+#ifdef _WIN32
+int
+openvpn_execve(const struct argv *a, const struct env_set *es, const unsigned int flags)
+{
+    ASSERT(0);
+}
+#endif
tests/unit_tests/openvpn/test_pkt.c +0 -8
index 5a53f702e..9f49ee7bd 100644
@@ -69,14 +69,6 @@ print_link_socket_actual(const struct link_socket_actual *act, struct gc_arena *
     return "dummy print_link_socket_actual from unit test";
 }
 
-#ifdef _WIN32
-int
-openvpn_execve(const struct argv *a, const struct env_set *es, const unsigned int flags)
-{
-    ASSERT(0);
-}
-#endif
-
 struct test_pkt_context {
     struct tls_auth_standalone tas_tls_auth;
     struct tls_auth_standalone tas_crypt;
Signature · 1 line
2.39.2 (Apple Git-143)
Acked-by on v2 1/1
#3 lore raw
Quoted 5 lines · Arne Schwabe

This function is needed to commpile on win32 as run_command.c defines it on Unix Linux but on windows it is defined in win32.c which pulls in too many other unresolvable symbols.

Patch v2: Also add mock_win32_execve.c to automake files

I checked "make distdir" and the file now appears in there.

Please note that this should be merged BEFORE
"Check if the -wrap argument is actually supported by the platform's ld" since it fixes the MinGW build issue that arises from that.

Signature · 1 line
  Frank Lichtenheld
#4 lore raw
In reply to Arne Schwabe

As requested, merged BEFORE that other thing, whatever it is, I'll find out :-)

I had some confusion about this patch at first ("why is it moving that single function into a new file") and then I saw that it's being linked to two different test drivers now. So, makes sense.

Tested by pushing to GHA and having the windows + linux builders see if they are happy with it...

Your patch has been applied to the master branch.

release/2.6 will see this as part of the grand unified cmake patch, I think.

commit ede590e57c96c2b16d9bf462c4b1dd967b37c432 (master)

Author: Arne Schwabe
Date:   Wed Jul 12 11:54:12 2023 +0200
     Mock openvpn_exece on win32 also for test_tls_crypt

     Signed-off-by: Arne Schwabe <[email protected]...>
     Acked-by: Frank Lichtenheld <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg26849.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering