qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Daniel P. Berrangé" <berrange@redhat.com>
To: Yonggang Luo <luoyonggang@gmail.com>
Cc: Kevin Wolf <kwolf@redhat.com>, Ed Maste <emaste@freebsd.org>,
	qemu-block@nongnu.org, Stefan Weil <sw@weilnetz.de>,
	Xie Changlong <xiechanglong.d@gmail.com>,
	Peter Lieven <pl@kamp.de>,
	qemu-devel@nongnu.org, Michael Roth <mdroth@linux.vnet.ibm.com>,
	Richard Henderson <richard.henderson@linaro.org>,
	Gerd Hoffmann <kraxel@redhat.com>,
	Wen Congyang <wencongyang2@huawei.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Max Reitz <mreitz@redhat.com>, Li-Wen Hsu <lwhsu@freebsd.org>,
	Markus Armbruster <armbru@redhat.com>
Subject: Re: [PATCH v9 12/26] tests: Enable crypto tests under msys2/mingw
Date: Tue, 15 Sep 2020 14:11:59 +0100	[thread overview]
Message-ID: <20200915131159.GH1502912@redhat.com> (raw)
In-Reply-To: <20200915121318.247-13-luoyonggang@gmail.com>

On Tue, Sep 15, 2020 at 08:13:04PM +0800, Yonggang Luo wrote:
> 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
> 
> Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
> ---
>  tests/crypto-tls-psk-helpers.c   |   2 +-
>  tests/crypto-tls-x509-helpers.c  | 106 ++++++++++++++++++++++++++++++-
>  tests/crypto-tls-x509-helpers.h  |   9 ++-
>  tests/test-crypto-tlscredsx509.c |  47 +++++++-------
>  tests/test-crypto-tlssession.c   |  68 +++++++++++---------
>  tests/test-io-channel-tls.c      |  51 ++++++++-------
>  6 files changed, 204 insertions(+), 79 deletions(-)
> 
> diff --git a/tests/crypto-tls-psk-helpers.c b/tests/crypto-tls-psk-helpers.c
> index 4f3bd446ad..58888d5537 100644
> --- a/tests/crypto-tls-psk-helpers.c
> +++ b/tests/crypto-tls-psk-helpers.c
> @@ -46,7 +46,7 @@ void test_tls_psk_init(const char *pskfile)
>  
>  void test_tls_psk_cleanup(const char *pskfile)
>  {
> -    unlink(pskfile);
> +    g_remove(pskfile);
>  }
>  
>  #endif /* QCRYPTO_HAVE_TLS_TEST_SUPPORT */
> diff --git a/tests/crypto-tls-x509-helpers.c b/tests/crypto-tls-x509-helpers.c
> index 01b3daf358..1238983755 100644
> --- a/tests/crypto-tls-x509-helpers.c
> +++ b/tests/crypto-tls-x509-helpers.c
> @@ -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);
> +    g_remove(keyfile);
>  }
>  
>  /*
> @@ -501,8 +503,108 @@ void test_tls_discard_cert(QCryptoTLSTestCertReq *req)
>      req->crt = NULL;
>  
>      if (getenv("QEMU_TEST_DEBUG_CERTS") == NULL) {
> -        unlink(req->filename);
> +        g_remove(req->filename);
>      }
>  }
>  
> +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
> +}
> +
> +#if defined(_WIN32)
> +
> +int qemu_socketpair(int family, int type, int protocol, int channel[2])
> +{
> +    struct addrinfo addr_data;
> +    struct addrinfo *addr = NULL;
> +    int sock_listener = -1;
> +    int sock_client = -1;
> +    int sock_server = -1;
> +    int one = 1;
> +
> +    memset(&addr_data, 0, sizeof(addr_data));
> +    addr_data.ai_family = AF_INET;
> +    addr_data.ai_socktype = type;
> +    addr_data.ai_protocol = protocol;
> +    if (0 != getaddrinfo("127.0.0.1", "0", &addr_data, &addr)) {


This test is backwards - QEMU style is "getaddrinfo(...) != 0"


> +        goto error;
> +    }
> +
> +    if (NULL == addr) {
> +        goto error;
> +    }
> +
> +    sock_listener = socket(addr->ai_family, addr->ai_socktype, addr->ai_protocol);
> +    if (-1 == sock_listener) {
> +        goto error;
> +    }

Normal code style is  "sock_listener < 0"

> +
> +    if (-1 == setsockopt(sock_listener, SOL_SOCKET, SO_REUSEADDR, (const char *)&one, sizeof(one))) {
> +        goto error;
> +    }

SO_REUSEADDR is not desirable on Windows -  see os-win32.c comments about
it.

> +    if (-1 == bind(sock_listener, addr->ai_addr, addr->ai_addrlen)) {
> +        goto error;
> +    }
> +    if (-1 == getsockname(sock_listener, addr->ai_addr, (int *)&(addr->ai_addrlen))) {
> +        goto error;
> +    }
> +    if (-1 == listen(sock_listener, 1)) {
> +        goto error;
> +    }
> +
> +    sock_client = socket(addr->ai_family, addr->ai_socktype, addr->ai_protocol);
> +
> +    if (-1 == sock_client) {
> +        goto error;
> +    }
> +
> +    if (-1 == connect(sock_client, addr->ai_addr, addr->ai_addrlen)) {
> +        goto error;
> +    }
> +
> +    sock_server = accept(sock_listener, 0, 0);
> +
> +    if (-1 == sock_server) {
> +        goto error;
> +    }
> +
> +    closesocket(sock_listener);
> +
> +    channel[0] = sock_client;
> +    channel[1] = sock_server;
> +    return 0;
> +
> +error:
> +    if (-1 != sock_server) {
> +        closesocket(sock_server);
> +    }
> +    if (-1 != sock_client) {
> +        closesocket(sock_client);
> +    }
> +    if (-1 != sock_listener) {
> +        closesocket(sock_listener);
> +    }
> +    if (NULL != addr) {
> +        freeaddrinfo(addr);
> +    }
> +    return -1;
> +}
> +
> +#else
> +
> +int qemu_socketpair(int family, int type, int protocol, int recv[2])
> +{
> +    return socketpair(family, type, protocol, recv);
> +}
> +
> +#endif
> +
>  #endif /* QCRYPTO_HAVE_TLS_TEST_SUPPORT */
> diff --git a/tests/crypto-tls-x509-helpers.h b/tests/crypto-tls-x509-helpers.h
> index 08efba4e19..6902d43af7 100644
> --- a/tests/crypto-tls-x509-helpers.h
> +++ b/tests/crypto-tls-x509-helpers.h
> @@ -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
>  
> @@ -127,6 +128,10 @@ void test_tls_cleanup(const char *keyfile);
>  
>  extern const ASN1_ARRAY_TYPE pkix_asn1_tab[];
>  
> +int qemu_link(const char *exist_path1, const char *new_path2);
> +
> +int qemu_socketpair(int family, int type, int protocol, int channel[2]);
> +

THese aren't really related t the TLS tests - they're platform
portability wrappers, so osdep.{ch} and qemu-sockets.c is where
they ought to live

>  #endif /* QCRYPTO_HAVE_TLS_TEST_SUPPORT */
>  
>  #endif


Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|



  reply	other threads:[~2020-09-15 13:19 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-15 12:12 [PATCH v9 00/26] W32, W64 msys2/mingw patches Yonggang Luo
2020-09-15 12:12 ` [PATCH v9 01/26] rcu: Implement drain_call_rcu Yonggang Luo
2020-09-15 12:12 ` [PATCH v9 02/26] ci: fixes msys2 build by upgrading capstone to 4.0.2 Yonggang Luo
2020-09-15 12:12 ` [PATCH v9 03/26] configure: Fixes ncursesw detection under msys2/mingw and enable curses Yonggang Luo
2020-09-15 12:12 ` [PATCH v9 04/26] win32: Simplify gmtime_r detection direct base on _POSIX_THREAD_SAFE_FUNCTIONS Yonggang Luo
2020-09-15 13:00   ` Daniel P. Berrangé
2020-09-15 13:23     ` 罗勇刚(Yonggang Luo)
2020-09-15 12:12 ` [PATCH v9 05/26] curses: Fixes curses compiling errors Yonggang Luo
2020-09-15 12:12 ` [PATCH v9 06/26] tests: disable /char/stdio/* tests in test-char.c on win32 Yonggang Luo
2020-09-15 12:12 ` [PATCH v9 07/26] tests: Fixes test-replication.c on msys2/mingw Yonggang Luo
2020-09-15 12:13 ` [PATCH v9 08/26] tests: test-replication disable /replication/secondary/* " Yonggang Luo
2020-09-15 12:13 ` [PATCH v9 09/26] osdep: file locking functions are not available on Win32 Yonggang Luo
2020-09-15 12:13 ` [PATCH v9 10/26] meson: Use -b to ignore CR vs. CR-LF issues on Windows Yonggang Luo
2020-09-15 12:13 ` [PATCH v9 11/26] gcrypt: test_tls_psk_init should write binary file instead text file Yonggang Luo
2020-09-15 12:13 ` [PATCH v9 12/26] tests: Enable crypto tests under msys2/mingw Yonggang Luo
2020-09-15 13:11   ` Daniel P. Berrangé [this message]
2020-09-15 12:13 ` [PATCH v9 13/26] meson: remove empty else and duplicated gio deps Yonggang Luo
2020-09-15 12:13 ` [PATCH v9 14/26] vmstate: Fixes test-vmstate.c on msys2/mingw Yonggang Luo
2020-09-15 12:13 ` [PATCH v9 15/26] cirrus: Building freebsd in a single short Yonggang Luo
2020-09-15 12:13 ` [PATCH v9 16/26] tests: Convert g_free to g_autofree macro in test-logging.c Yonggang Luo
2020-09-15 12:13 ` [PATCH v9 17/26] tests: Fixes test-io-channel-socket.c tests under msys2/mingw Yonggang Luo
2020-09-15 12:13 ` [PATCH v9 18/26] tests: fixes aio-win32 about aio_remove_fd_handler, get it consistence with aio-posix.c Yonggang Luo
2020-09-15 12:13 ` [PATCH v9 19/26] tests: Fixes test-io-channel-file by mask only owner file state mask bits Yonggang Luo
2020-09-15 13:15   ` Daniel P. Berrangé
2020-09-15 12:13 ` [PATCH v9 20/26] tests: fix test-util-sockets.c Yonggang Luo
2020-09-15 12:13 ` [PATCH v9 21/26] tests: Fixes test-qdev-global-props.c Yonggang Luo
2020-09-15 12:13 ` [PATCH v9 22/26] rcu: fixes test-logging.c by call drain_call_rcu before rmdir_full Yonggang Luo
2020-09-15 12:13 ` [PATCH v9 23/26] meson: upgrade meson for execute custom ninjatool under msys2 properly Yonggang Luo
2020-09-15 12:13 ` [PATCH v9 24/26] ci: Enable msys2 ci in cirrus Yonggang Luo
2020-09-15 12:13 ` [PATCH v9 25/26] block: Fixes nfs compiling error on msys2/mingw Yonggang Luo
2020-09-15 12:13 ` [PATCH v9 26/26] block: enable libnfs on msys2/mingw in cirrus.yml Yonggang Luo
2020-09-15 13:00 ` [PATCH v9 00/26] W32, W64 msys2/mingw patches no-reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200915131159.GH1502912@redhat.com \
    --to=berrange@redhat.com \
    --cc=armbru@redhat.com \
    --cc=emaste@freebsd.org \
    --cc=kraxel@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=luoyonggang@gmail.com \
    --cc=lwhsu@freebsd.org \
    --cc=mdroth@linux.vnet.ibm.com \
    --cc=mreitz@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=pl@kamp.de \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    --cc=sw@weilnetz.de \
    --cc=wencongyang2@huawei.com \
    --cc=xiechanglong.d@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).