diff --git a/.github/workflows/other-perls.yml b/.github/workflows/other-perls.yml index 9d3adec..c45bbff 100644 --- a/.github/workflows/other-perls.yml +++ b/.github/workflows/other-perls.yml @@ -6,9 +6,10 @@ jobs: build: runs-on: ${{ matrix.os }} strategy: + fail-fast: false # Ensures that one failing job does not cancel others matrix: - os: ["ubuntu-latest"] - perl: ["5.40","5.38","5.36","5.34","5.32","5.30","5.28","5.26","5.24","5.22","5.20"] + os: ["ubuntu-latest","ubuntu-22.04"] + perl: ["5.40","5.38","5.36","5.34","5.32","5.30","5.28","5.26","5.24","5.22","5.20","5.18","5.16","5.14","5.12"] name: Perl ${{ matrix.perl }} on ${{ matrix.os }} steps: @@ -26,12 +27,8 @@ jobs: run: | cpanm --verbose --notest Module::Build Inline::C Alien::OpenMP \ Util::H2O::More File::Temp Test::Exception Test::Deep \ - OpenMP::Environment File::ShareDir Dist::Zilla - - - name: Set Dist::Zilla for 'dzil test' command - run: | - dzil authordeps --missing | cpanm --verbose # Install required author dependencies - cpanm --verbose --notest Dist::Zilla::Plugin::VersionFromModule # this may be redundant + OpenMP::Environment File::ShareDir - name: Run Tests - run: dzil test + run: ./test-runner.sh + if: always() # Ensures tests run even if a previous step failed diff --git a/Makefile b/Makefile index 3c2eff2..8211844 100644 --- a/Makefile +++ b/Makefile @@ -4,6 +4,11 @@ clean: rm -rf t/_Inline rm -rf blib +clean2: + rm -rf _Inline + rm -rf t/_Inline + rm -rf blib + test: clean ./test-runner.sh diff --git a/share/openmp-simple.h b/share/openmp-simple.h index cab06e6..87ea31c 100644 --- a/share/openmp-simple.h +++ b/share/openmp-simple.h @@ -454,22 +454,34 @@ void PerlOMP_VERIFY_2D_AoA(SV *AoA) { } } -/* Helper function to verify element types */ -bool is_float(SV *sv) { return SvNOK(sv); } -bool is_int(SV *sv) { return SvIOK(sv); } -bool is_string(SV *sv) { return SvPOK(sv); } +/* Checks if an SV is an integer, allowing for stored floats that are whole numbers */ +bool is_int(SV *sv) { + return SvIOK(sv) || (SvNOK(sv) && SvIV(sv) == SvNV(sv)); +} + +/* Checks if an SV is a float, including cases where Perl stores it as an integer */ +bool is_float(SV *sv) { + return SvNOK(sv) || (SvIOK(sv) && SvIV(sv) != SvNV(sv)); +} + +/* Checks if an SV is a string, ensuring it's not just a numeric representation */ +bool is_string(SV *sv) { + return SvPOK(sv) || (!SvNOK(sv) && !SvIOK(sv)); +} -/* Generic function to verify a 1D array's element type */ void verify_1D_array_type(SV *array, bool (*type_check)(SV *), const char *type_name) { if (!is_array_ref(array)) { croak("Expected a 1D array reference"); } AV *av = (AV *)SvRV(array); - I32 len = av_len(av) + 1; + I32 len = av_len(av); + if (len == -1) return; // Handle empty arrays safely + len++; // Convert last index to total count + for (I32 i = 0; i < len; i++) { SV **element = av_fetch(av, i, 0); - if (!element || !type_check(*element)) { - croak("Expected all elements to be %s at index %d", type_name, i); + if (!element || !*element || !type_check(*element)) { + croak("Expected all elements to be %s at index %" IVdf, type_name, (IV)i); } } } @@ -477,22 +489,36 @@ void verify_1D_array_type(SV *array, bool (*type_check)(SV *), const char *type_ /* Implement type-specific 1D array verifications */ void PerlOMP_VERIFY_1D_FLOAT_ARRAY(SV *array) { verify_1D_array_type(array, is_float, "float"); } void PerlOMP_VERIFY_1D_INT_ARRAY(SV *array) { verify_1D_array_type(array, is_int, "integer"); } -void PerlOMP_VERIFY_1D_DOUBLE_ARRAY(SV *array) { verify_1D_array_type(array, is_float, "double"); } void PerlOMP_VERIFY_1D_STRING_ARRAY(SV *array) { verify_1D_array_type(array, is_string, "string"); } /* Generic function to verify a 2D array's element type */ void verify_2D_array_type(SV *AoA, bool (*type_check)(SV *), const char *type_name) { - PerlOMP_VERIFY_2D_AoA(AoA); + PerlOMP_VERIFY_2D_AoA(AoA); // Assuming this macro validates AoA correctly + + if (!is_array_ref(AoA)) { + croak("Expected a 2D array reference"); + } + AV *outer = (AV *)SvRV(AoA); - I32 rows = av_len(outer) + 1; + I32 rows = av_len(outer); + if (rows == -1) return; // Handle empty outer array safely + rows++; // Convert last index to total count + for (I32 i = 0; i < rows; i++) { SV **inner_ref = av_fetch(outer, i, 0); + if (!inner_ref || !*inner_ref || !is_array_ref(*inner_ref)) { + croak("Expected an array reference at row %" IVdf, (IV)i); + } + AV *inner = (AV *)SvRV(*inner_ref); - I32 cols = av_len(inner) + 1; + I32 cols = av_len(inner); + if (cols == -1) continue; // Handle empty inner arrays safely + cols++; // Convert last index to total count + for (I32 j = 0; j < cols; j++) { SV **element = av_fetch(inner, j, 0); - if (!element || !type_check(*element)) { - croak("Expected all elements to be %s at [%d][%d]", type_name, i, j); + if (!element || !*element || !type_check(*element)) { + croak("Expected all elements to be %s at [%" IVdf "][%" IVdf "]", type_name, (IV)i, (IV)j); } } } @@ -501,6 +527,5 @@ void verify_2D_array_type(SV *AoA, bool (*type_check)(SV *), const char *type_na /* Implement type-specific 2D array verifications */ void PerlOMP_VERIFY_2D_FLOAT_ARRAY(SV *AoA) { verify_2D_array_type(AoA, is_float, "float"); } void PerlOMP_VERIFY_2D_INT_ARRAY(SV *AoA) { verify_2D_array_type(AoA, is_int, "integer"); } -void PerlOMP_VERIFY_2D_DOUBLE_ARRAY(SV *AoA) { verify_2D_array_type(AoA, is_float, "double"); } void PerlOMP_VERIFY_2D_STRING_ARRAY(SV *AoA) { verify_2D_array_type(AoA, is_string, "string"); } diff --git a/test-runner.sh b/test-runner.sh index 1b6bc9a..9e684e7 100755 --- a/test-runner.sh +++ b/test-runner.sh @@ -1,7 +1,21 @@ #!/usr/bin/env bash +TESTS=$@ + +if [ -z "$TESTS" ]; then + TESTS=$(ls -1 ./t) +fi + rm -rf blib > /dev/null 2>&1 mkdir -p blib/lib/auto/share/dist/OpenMP-Simple/ cp -f share/openmp-simple.h blib/lib/auto/share/dist/OpenMP-Simple/openmp-simple.h cp -f share/ppport.h blib/lib/auto/share/dist/OpenMP-Simple/ppport.h -PERL_DL_NONLAZY=1 perl -Ilib -MExtUtils::Command::MM -MTest::Harness -e "undef *Test::Harness::Switches; test_harness(1, 'blib/lib', 'blib/arch')" t/*.t | grep '\.\.\.\.' +EXIT=0 +for FILE in $TESTS; do + PERL_DL_NONLAZY=1 perl -Ilib -MExtUtils::Command::MM -MTest::Harness -e "undef *Test::Harness::Switches; test_harness(1, 'blib/lib', 'blib/arch')" t/$FILE + if [ $? != 0 ]; then + EXIT=$(($EXIT+1)) + fi +done + +exit $EXIT