From fdf824d6f4c945bb28d825ae173a1b390bb8ceed Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sat, 22 Apr 2023 08:58:57 +0000 Subject: [PATCH] ci: reduce algo test runtime on AppVeyor Make the block count customizable in `test_read` via environment `FIXTURE_XFER_COUNT`. Set the custom count lower than the default when running on AppVeyor. The goal is to reduce CI roundtrip times. Closes #995 --- appveyor.yml | 1 + tests/test_read.c | 56 ++++++++++++++++++++++++++++------------------- 2 files changed, 34 insertions(+), 23 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 6ea97a53..a8bb9ff8 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -26,6 +26,7 @@ environment: CONFIGURATION: "Release" + FIXTURE_XFER_COUNT: 35020 matrix: - job_name: "VS2022, OpenSSL3, x64, Server 2019" APPVEYOR_BUILD_WORKER_IMAGE: "Visual Studio 2022" diff --git a/tests/test_read.c b/tests/test_read.c index 2058e63d..24160b85 100644 --- a/tests/test_read.c +++ b/tests/test_read.c @@ -2,33 +2,32 @@ #include "runner.h" +#include /* for getenv() */ + /* set in Dockerfile */ static const char *USERNAME = "libssh2"; static const char *KEY_FILE_PRIVATE = "key_rsa"; static const char *KEY_FILE_PUBLIC = "key_rsa.pub"; -/* Size and number of blocks to transfer - * This needs to be large to increase the chance of timing effects causing - * different code paths to be hit in the unframing code, but not so long that - * the integration tests take too long. 5 seconds of run time is probably a - * reasonable compromise. The block size is an odd number to increase the - * chance that various internal buffer and block boundaries are overlapped. */ -#define XFER_BS 997 -#define XFER_COUNT 140080 - -#define STRINGIFY(x) STRINGIFY2(x) -#define STRINGIFY2(x) #x - -/* command to transfer the desired amount of data */ -#define REMOTE_COMMAND "dd if=/dev/zero bs=" STRINGIFY(XFER_BS) \ - " count=" STRINGIFY(XFER_COUNT) " status=none" - int test(LIBSSH2_SESSION *session) { int rc; - long xfer_bytes = 0; + unsigned long xfer_bytes = 0; LIBSSH2_CHANNEL *channel; + /* Size and number of blocks to transfer + * This needs to be large to increase the chance of timing effects causing + * different code paths to be hit in the unframing code, but not so long + * that the integration tests take too long. 5 seconds of run time is + * probably a reasonable compromise. The block size is an odd number to + * increase the chance that various internal buffer and block boundaries + * are overlapped. */ + const unsigned long xfer_bs = 997; + unsigned long xfer_count = 140080; + + char remote_command[256]; + const char *env; + const char *userauth_list = libssh2_userauth_list(session, USERNAME, (unsigned int)strlen(USERNAME)); @@ -60,8 +59,19 @@ int test(LIBSSH2_SESSION *session) goto shutdown; } + env = getenv("FIXTURE_XFER_COUNT"); + if(env) { + xfer_count = (unsigned long)strtol(env, NULL, 0); + fprintf(stderr, "Custom xfer_count: %lu\n", xfer_count); + } + + /* command to transfer the desired amount of data */ + snprintf(remote_command, sizeof(remote_command), + "dd if=/dev/zero bs=%lu count=%lu status=none", + xfer_bs, xfer_count); + /* Send the command to transfer data */ - if(libssh2_channel_exec(channel, REMOTE_COMMAND)) { + if(libssh2_channel_exec(channel, remote_command)) { fprintf(stderr, "Unable to request command on channel\n"); goto shutdown; } @@ -73,8 +83,8 @@ int test(LIBSSH2_SESSION *session) if(err < 0) fprintf(stderr, "Unable to read response: %d\n", (int)err); else { - int i; - for(i = 0; i < err; ++i) { + unsigned int i; + for(i = 0; i < (unsigned long)err; ++i) { if(buf[i]) { fprintf(stderr, "Bad data received\n"); /* Test will fail below due to bad data length */ @@ -97,9 +107,9 @@ int test(LIBSSH2_SESSION *session) shutdown: /* Test check */ - if(xfer_bytes != XFER_COUNT * XFER_BS) { - fprintf(stderr, "Not enough bytes received: %ld not %ld\n", - xfer_bytes, (long)XFER_COUNT * XFER_BS); + if(xfer_bytes != xfer_count * xfer_bs) { + fprintf(stderr, "Not enough bytes received: %lu not %lu\n", + xfer_bytes, xfer_count * xfer_bs); return 1; /* error */ } return 0;