Skip to content

Commit

Permalink
#145: CI/AVX512: fix typo, allow skipping CI tests
Browse files Browse the repository at this point in the history
- Fix a typo in the AVX512 codec selector.
- Allow the user to inhibit CI tests for any codec by setting environment
  variables. This is needed because CI does not support AVX512 yet.

Resolves #145.
  • Loading branch information
aklomp committed Sep 11, 2024
2 parents d3e8a79 + 30f81db commit 22a3e9d
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 26 deletions.
9 changes: 6 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,12 @@ jobs:
-DBASE64_BUILD_TESTS=ON
${{ runner.os != 'Windows' && '-DCMAKE_BUILD_TYPE=Release' || '' }}
${{ runner.os == 'Windows' && matrix.platform == 'i686' && '-A Win32' || '' }}
-DBASE64_WITH_AVX512=OFF
- name: CMake Build
run: cmake --build out --config Release --verbose
- name: CTest
run: ctest --no-tests=error --test-dir out -VV --build-config Release
env:
BASE64_TEST_SKIP_AVX512: "1"

alpine-makefile-test:
name: makefile-alpine-amd64-gcc
Expand Down Expand Up @@ -112,13 +113,14 @@ jobs:
-B out
-Werror=dev
-DBASE64_BUILD_TESTS=ON
-DBASE64_WITH_AVX512=OFF
-DCMAKE_BUILD_TYPE=Release
- name: CMake Build
run: cmake --build out --config Release --verbose
- name: CTest
run: ctest --no-tests=error -VV --build-config Release
working-directory: ./out
env:
BASE64_TEST_SKIP_AVX512: "1"

alpine-alt-arch-makefile-test:
name: makefile-alpine-${{matrix.arch}}-${{matrix.cc}}
Expand Down Expand Up @@ -206,13 +208,14 @@ jobs:
-Werror=dev
-DBASE64_BUILD_TESTS=ON
-DCMAKE_BUILD_TYPE=Release
-DBASE64_WITH_AVX512=OFF
- name: CMake Build
shell: msys2 {0}
run: cmake --build out --config Release --verbose
- name: CTest
shell: msys2 {0}
run: ctest --no-tests=error --test-dir out -VV --build-config Release
env:
BASE64_TEST_SKIP_AVX512: "1"
- name: Test demo utility with unicode filenames and file contents on Windows
shell: msys2 {0}
run: |
Expand Down
2 changes: 1 addition & 1 deletion lib/codec_choose.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@

#define _XCR_XMM_AND_YMM_STATE_ENABLED_BY_OS (bit_XMM | bit_YMM)

#define _AVX_512_ENABLED_BY_OS (bit_XMM | bit_YMM | bit_OPMASK | bit_ZMM | bit bit_HIGH_ZMM)
#define _AVX_512_ENABLED_BY_OS (bit_XMM | bit_YMM | bit_OPMASK | bit_ZMM | bit_HIGH_ZMM)

#endif

Expand Down
10 changes: 6 additions & 4 deletions test/benchmark.c
Original file line number Diff line number Diff line change
Expand Up @@ -271,10 +271,12 @@ main ()
sizes[i].label, sizes[i].repeat, sizes[i].batch);

// Loop over all codecs:
for (size_t j = 0; codecs[j]; j++)
if (codec_supported(1 << j))
codec_bench(&b, &sizes[i], codecs[j], 1 << j);
};
for (size_t j = 0; codecs[j]; j++) {
int flags = codec_supported(j);
if (flags)
codec_bench(&b, &sizes[i], codecs[j], flags);
}
}

// Free memory:
err2: free(b.enc);
Expand Down
3 changes: 2 additions & 1 deletion test/ci/analysis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ for USE_ASSEMBLY in 0 1; do
export SSE42_CFLAGS="-msse4.2 -DBASE64_SSE42_USE_ASM=${USE_ASSEMBLY}"
export AVX_CFLAGS="-mavx -DBASE64_AVX_USE_ASM=${USE_ASSEMBLY}"
export AVX2_CFLAGS="-mavx2 -DBASE64_AVX2_USE_ASM=${USE_ASSEMBLY}"
export AVX512_CFLAGS="-mavx512vl -mavx512vbmi"
# Temporarily disable AVX512; it is not available in CI yet.
# export AVX512_CFLAGS="-mavx512vl -mavx512vbmi"
export BASE64_TEST_SKIP_AVX512=1
elif [ "${MACHINE}" == "aarch64" ]; then
export NEON64_CFLAGS="-march=armv8-a"
elif [ "${MACHINE}" == "armv7l" ]; then
Expand Down
10 changes: 4 additions & 6 deletions test/ci/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@ if [ "${MACHINE}" == "x86_64" ]; then
export SSE41_CFLAGS=-msse4.1
export SSE42_CFLAGS=-msse4.2
export AVX_CFLAGS=-mavx
# no AVX2 or AVX512 on GHA macOS
if [ "$(uname -s)" != "Darwin" ]; then
export AVX2_CFLAGS=-mavx2
# Temporarily disable AVX512; it is not available in CI yet.
# export AVX512_CFLAGS="-mavx512vl -mavx512vbmi"
fi
export AVX2_CFLAGS=-mavx2
export AVX512_CFLAGS="-mavx512vl -mavx512vbmi"
# Temporarily disable AVX512; it is not available in CI yet.
export BASE64_TEST_SKIP_AVX512=1
elif [ "${MACHINE}" == "aarch64" ]; then
export NEON64_CFLAGS="-march=armv8-a"
elif [ "${MACHINE}" == "armv7l" ]; then
Expand Down
17 changes: 14 additions & 3 deletions test/codec_supported.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "../include/libbase64.h"
Expand All @@ -18,12 +20,21 @@ static char *_codecs[] =
char **codecs = _codecs;

int
codec_supported (int flags)
codec_supported (size_t index)
{
if (index >= (sizeof(_codecs) / sizeof(_codecs[0])) - 1) {
return 0;
}
// Check if given codec is supported by trying to decode a test string:
char *a = "aGVsbG8=";
char b[10];
size_t outlen;

return (base64_decode(a, strlen(a), b, &outlen, flags) != -1);
char envVariable[32];
sprintf(envVariable, "BASE64_TEST_SKIP_%s", _codecs[index]);
const char* envOverride = getenv(envVariable);
if ((envOverride != NULL) && (strcmp(envOverride, "1") == 0)) {
return 0;
}
int flags = 1 << index;
return (base64_decode(a, strlen(a), b, &outlen, flags) != -1) ? flags : 0;
}
2 changes: 1 addition & 1 deletion test/codec_supported.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
extern char **codecs;

int codec_supported (int flags);
int codec_supported (size_t index);
12 changes: 5 additions & 7 deletions test/test_base64.c
Original file line number Diff line number Diff line change
Expand Up @@ -313,14 +313,16 @@ test_invalid_dec_input (int flags)
}

static int
test_one_codec (const char *codec, int flags)
test_one_codec (size_t codec_index)
{
bool fail = false;
const char *codec = codecs[codec_index];

printf("Codec %s:\n", codec);

// Skip if this codec is not supported:
if (!codec_supported(flags)) {
int flags = codec_supported(codec_index);
if (flags == 0) {
puts(" skipping");
return false;
}
Expand Down Expand Up @@ -376,12 +378,8 @@ main ()

// Loop over all codecs:
for (size_t i = 0; codecs[i]; i++) {

// Flags to invoke this codec:
int codec_flags = (1 << i);

// Test this codec, merge the results:
fail |= test_one_codec(codecs[i], codec_flags);
fail |= test_one_codec(i);
}

return (fail) ? 1 : 0;
Expand Down

0 comments on commit 22a3e9d

Please sign in to comment.