Skip to contentSkip to conversation

Fixes gcrypt testing on msys2/mingw

PATCH In review Yonggang Luo 2 participants 4 messages Oct 13, 2020

lore
Share & tools
lore
#0 lore raw

cover Fixes gcrypt testing on msys2/mingw

gcrypt: test_tls_psk_init should write binary file instead text file.
gcrypt: Enable crypto tests under msys2/mingw by implement custom qemu_socket= pair

Yonggang Luo (2):
gcrypt: test_tls_psk_init should write binary file instead text file.
gcrypt: Enable crypto tests under msys2/mingw

 include/qemu/osdep.h             |  1 +
 include/sysemu/os-win32.h        |  5 +++
 tests/crypto-tls-psk-helpers.c   |  6 ++-
 tests/crypto-tls-x509-helpers.c  |  6 ++-
 tests/crypto-tls-x509-helpers.h  |  5 ++-
 tests/test-crypto-tlscredsx509.c | 47 +++++++++++---------
 tests/test-crypto-tlssession.c   | 64 +++++++++++++++------------
 tests/test-io-channel-tls.c      | 49 +++++++++++---------
 util/osdep.c                     | 16 +++++++
 util/oslib-win32.c               | 76 ++++++++++++++++++++++++++++++++
 10 files changed, 198 insertions(+), 77 deletions(-)

--=20
2.28.0.windows.1

#1 lore raw

PATCH 1/2 gcrypt: test_tls_psk_init should write binary file instead text file.

On windows, if open file with "w", it's will automatically convert "\n" to "\r\n" when writing to file.

---
 tests/crypto-tls-psk-helpers.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tests/crypto-tls-psk-helpers.c +1 -1
index a8395477c3..11ae26368c 100644
@@ -32,7 +32,7 @@ void test_tls_psk_init(const char *pskfile)
 {
     FILE *fp;
 
-    fp = fopen(pskfile, "w");
+    fp = fopen(pskfile, "wb");
     if (fp == NULL) {
         g_critical("Failed to create pskfile %s", pskfile);
         abort();
Signature · 1 line
2.28.0.windows.1
Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] gcrypt: test_tls_psk_init should write binary file instead text file.

Quoted 14 lines · Yonggang Luo

On windows, if open file with "w", it's will automatically convert "\n" to "\r\n" when writing to file.

---
  tests/crypto-tls-psk-helpers.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
tests/crypto-tls-psk-helpers.c +0 -0
index a8395477c3..11ae26368c 100644

tests/crypto-tls-psk-helpers.c void test_tls_psk_init(const char *pskfile) · line 38

Quoted 8 lines
tests/crypto-tls-psk-helpers.c +1 -1
@@ -32,7 +32,7 @@ void test_tls_psk_init(const char *pskfile)
  {
      FILE *fp;
 
-    fp = fopen(pskfile, "w");
+    fp = fopen(pskfile, "wb");
      if (fp == NULL) {
          g_critical("Failed to create pskfile %s", pskfile);
          abort();
#3 lore raw

PATCH 2/2 gcrypt: Enable crypto tests under msys2/mingw

In reply to Yonggang Luo

Fixes following tests on msys2/mingw
'test-crypto-tlscredsx509'
test-crypto-tlssession'
'test-io-channel-tls'

These tests are failure with:
ERROR test-crypto-tlscredsx509 - missing test plan ERROR test-crypto-tlssession - missing test plan ERROR test-io-channel-tls - missing test plan

Because on win32 those test case are all disabled in the header

Add qemu_socket_pair for cross platform support
Convert file system handling functions to glib
Add qemu_link function instead posix only link function.
Use send ad recv from qemu that convert Windows Socks error to errno properly. Use g_remove instead unlink
Use g_mkdir instead mkdir

---
 include/qemu/osdep.h             |  1 +
 include/sysemu/os-win32.h        |  5 +++
 tests/crypto-tls-psk-helpers.c   |  4 +-
 tests/crypto-tls-x509-helpers.c  |  6 ++-
 tests/crypto-tls-x509-helpers.h  |  5 ++-
 tests/test-crypto-tlscredsx509.c | 47 +++++++++++---------
 tests/test-crypto-tlssession.c   | 64 +++++++++++++++------------
 tests/test-io-channel-tls.c      | 49 +++++++++++---------
 util/osdep.c                     | 16 +++++++
 util/oslib-win32.c               | 76 ++++++++++++++++++++++++++++++++
 10 files changed, 197 insertions(+), 76 deletions(-)
include/qemu/osdep.h +1 -0
index f9ec8c84e9..b090b1d2b8 100644
@@ -505,6 +505,7 @@ int qemu_open_old(const char *name, int flags, ...);
 int qemu_open(const char *name, int flags, Error **errp);
 int qemu_create(const char *name, int flags, mode_t mode, Error **errp);
 int qemu_close(int fd);
+int qemu_link(const char *exist_path1, const char *new_path2);
 int qemu_unlink(const char *name);
 #ifndef _WIN32
 int qemu_dup_flags(int fd, int flags);
include/sysemu/os-win32.h +5 -0
index 5346d51e89..38869cad92 100644
@@ -194,4 +194,9 @@ ssize_t qemu_recv_wrap(int sockfd, void *buf, size_t len, int flags);
 ssize_t qemu_recvfrom_wrap(int sockfd, void *buf, size_t len, int flags,
                            struct sockaddr *addr, socklen_t *addrlen);
 
+#undef socketpair
+#define socketpair qemu_socketpair
+int qemu_socketpair(int family, int type, int protocol, int channel[2]);
+
+
 #endif
tests/crypto-tls-psk-helpers.c +3 -1
index 11ae26368c..6f82bfceb2 100644
@@ -26,6 +26,8 @@
 #include "crypto-tls-psk-helpers.h"
 #include "qemu/sockets.h"
 
+#include <glib/gstdio.h>
+
 #ifdef QCRYPTO_HAVE_TLS_TEST_SUPPORT
 
 void test_tls_psk_init(const char *pskfile)
@@ -44,7 +46,7 @@ void test_tls_psk_init(const char *pskfile)
 
 void test_tls_psk_cleanup(const char *pskfile)
 {
-    unlink(pskfile);
+    qemu_unlink(pskfile);
 }
 
 #endif /* QCRYPTO_HAVE_TLS_TEST_SUPPORT */
tests/crypto-tls-x509-helpers.c +4 -2
index 01b3daf358..051f045657 100644
@@ -23,6 +23,8 @@
 #include "crypto-tls-x509-helpers.h"
 #include "crypto/init.h"
 #include "qemu/sockets.h"
+#include <glib.h>
+#include <glib/gstdio.h>
 
 #ifdef QCRYPTO_HAVE_TLS_TEST_SUPPORT
 
@@ -133,7 +135,7 @@ void test_tls_init(const char *keyfile)
 void test_tls_cleanup(const char *keyfile)
 {
     asn1_delete_structure(&pkix_asn1);
-    unlink(keyfile);
+    qemu_unlink(keyfile);
 }
 
 /*
@@ -501,7 +503,7 @@ void test_tls_discard_cert(QCryptoTLSTestCertReq *req)
     req->crt = NULL;
 
     if (getenv("QEMU_TEST_DEBUG_CERTS") == NULL) {
-        unlink(req->filename);
+        qemu_unlink(req->filename);
     }
 }
 
tests/crypto-tls-x509-helpers.h +3 -2
index 08efba4e19..0856934a70 100644
@@ -24,8 +24,9 @@
 #include <gnutls/gnutls.h>
 #include <gnutls/x509.h>
 
-#if !(defined WIN32) && \
-    defined(CONFIG_TASN1)
+#include "qemu/osdep.h"
+
+#if defined(CONFIG_TASN1)
 # define QCRYPTO_HAVE_TLS_TEST_SUPPORT
 #endif
 
tests/test-crypto-tlscredsx509.c +25 -22

94 lines not on this page · raw message

tests/test-crypto-tlssession.c +36 -28

126 lines not on this page · raw message

tests/test-io-channel-tls.c +28 -21

89 lines not on this page · raw message

util/osdep.c +16 -0
index 66d01b9160..5877a27572 100644
@@ -414,6 +414,22 @@ int qemu_close(int fd)
     return close(fd);
 }
 
+/*
+ * Create a symbolic link file from new_path2 to exist_path1
+ */
+int qemu_link(const char *exist_path1, const char *new_path2)
+{
+#if defined(_WIN32)
+    g_autofree gchar *current_dir = g_get_current_dir();
+    g_autofree gchar *full_path = g_build_filename(
+        current_dir, exist_path1, NULL);
+    return CreateSymbolicLinkA(new_path2, full_path,
+        0 | SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE) ? 0 : -1;
+#else
+    return link(exist_path1, new_path2);
+#endif
+}
+
 /*
  * Delete a file from the filesystem, unless the filename is /dev/fdset/...
  *
util/oslib-win32.c +76 -0

79 lines not on this page · raw message

Signature · 1 line
2.28.0.windows.1