Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions .github/workflows/other-perls.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
55 changes: 40 additions & 15 deletions share/openmp-simple.h
Original file line number Diff line number Diff line change
Expand Up @@ -454,45 +454,71 @@ 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);
}
}
}

/* 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);
}
}
}
Expand All @@ -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"); }

16 changes: 15 additions & 1 deletion test-runner.sh
Original file line number Diff line number Diff line change
@@ -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
Loading