Skip to content

Commit

Permalink
chore: allow to skip specific simd test using environment variable
Browse files Browse the repository at this point in the history
  • Loading branch information
mayeut committed Jul 6, 2024
1 parent 6280462 commit 8f76b75
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 14 deletions.
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
15 changes: 13 additions & 2 deletions test/codec_supported.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <stdlib.h>
#include <string.h>

#include "../include/libbase64.h"
Expand All @@ -18,12 +19,22 @@ 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;
char envVariable[32];

return (base64_decode(a, strlen(a), b, &outlen, flags) != -1);
sprintf(envVariable, "BASE64_TEST_SKIP_%s", _codecs[index]);
const char* envOverride = getenv(envVariable);
if (envOverride != NULL) {
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 8f76b75

Please sign in to comment.