From be07369d4cb51ceb1db17cb8bda762db90e56113 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Albin=20Ahlb=C3=A4ck?= Date: Wed, 15 Nov 2023 14:04:43 +0100 Subject: [PATCH] Check examples in CI --- .github/workflows/CI.yml | 16 ++- Makefile.in | 7 +- dev/check_examples.sh | 283 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 300 insertions(+), 6 deletions(-) create mode 100755 dev/check_examples.sh diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index ea7ba1b5a5..fca4984df4 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -329,7 +329,7 @@ jobs: # ubuntu with clang ############################################################################# ubuntu-clang: - name: Ubuntu Clang (x5) + name: Ubuntu Clang with examples (x5) runs-on: ubuntu-latest @@ -344,14 +344,12 @@ jobs: - name: "Setup" run: | - sudo apt-get install -y libgmp-dev - sudo apt-get install -y libmpfr-dev - sudo apt-get install -y autoconf - sudo apt-get install -y libtool-bin + sudo apt-get install -y libgmp-dev libmpfr-dev autoconf libtool-bin perl clang --version make --version autoconf --version libtool --version + perl --version echo "MAKE=make -j$(expr $(nproc) + 1) --output-sync=target" >> $GITHUB_ENV - name: "Configure" @@ -375,6 +373,14 @@ jobs: run: | $MAKE check + - name: "Compile examples" + run: | + $MAKE examples + + - name: "Check examples" + run: | + $MAKE checkexamples + ############################################################################# diff --git a/Makefile.in b/Makefile.in index 408cd1e9c9..87e5d12ddb 100644 --- a/Makefile.in +++ b/Makefile.in @@ -655,6 +655,11 @@ endif examples: library $(EXMPS) +%_EXMP_RUN: % + @$(FLINT_DIR)/dev/check_examples.sh $(patsubst $(BUILD_DIR)/examples/%,%,$<) $(BUILD_DIR)/examples + +checkexamples: examples $(EXMPS:%=%_EXMP_RUN) + ################################################################################ # profiling ################################################################################ @@ -801,4 +806,4 @@ dist: print-%: @echo "$*=$($*)" -.PHONY: all library shared static examples profile tests check tune valgrind clean distclean install uninstall dist %_TEST_RUN %_VALGRIND_RUN print-% coverage +.PHONY: all library shared static examples checkexamples profile tests check tune valgrind clean distclean install uninstall dist %_TEST_RUN %_VALGRIND_RUN print-% coverage diff --git a/dev/check_examples.sh b/dev/check_examples.sh new file mode 100755 index 0000000000..fa250d1be8 --- /dev/null +++ b/dev/check_examples.sh @@ -0,0 +1,283 @@ +#!/usr/bin/env bash + +# Copyright (C) 2023 Albin Ahlbäck +# +# This file is part of FLINT. +# +# FLINT is free software: you can redistribute it and/or modify it under +# the terms of the GNU Lesser General Public License (LGPL) as published +# by the Free Software Foundation; either version 2.1 of the License, or +# (at your option) any later version. See . + +if test "$1" = "bernoulli"; +then + echo -n "bernoulli...." + res=$($2/bernoulli 20 -threads 2) + if test "$?" != "0"; + then + echo "FAIL" + exit 1 + fi + echo $res | perl -0ne 'if (/-174611\/330/) { $found=1; last } END { exit !$found }' + if test "$?" != "0"; + then + echo "FAIL" + exit 2 + fi + echo "PASS" + exit 0 +elif test "$1" = "binet"; +then + echo -n "binet...." + res=$($2/binet -limit 2 8) + if test "$?" != "0"; + then + echo "FAIL" + exit 1 + fi + echo $res | perl -0ne 'if (/21 cpu/) { $found=1; last } END { exit !$found }' + if test "$?" != "0"; + then + echo "FAIL" + exit 2 + fi + echo "PASS" + exit 0 +elif test "$1" = "class_poly"; +then + echo "class_poly....SKIPPED" + exit 0 +elif test "$1" = "complex_plot"; +then + echo "complex_plot....SKIPPED" + exit 0 +elif test "$1" = "crt"; +then + echo "crt....SKIPPED" + exit 0 +elif test "$1" = "delta_qexp"; +then + echo "delta_qexp....SKIPPED" + exit 0 +elif test "$1" = "dft"; +then + echo "dft....SKIPPED" + exit 0 +elif test "$1" = "elementary"; +then + echo -n "elementary...." + res=$($2/elementary) + if test "$?" != "0"; + then + echo "FAIL" + exit 1 + fi + # Check that the first and last expression prints as intended + echo "$res" | perl -0ne 'if (/>>> Exp\(Pi\*I\) \+ 1\n0\n/) { $found=1; last } END { exit !$found }' + if test "$?" != "0"; + then + echo "FAIL" + exit 2 + fi + echo "$res" | perl -0ne 'if (/>>> Erf\(2\*Log\(Sqrt\(1\/2-Sqrt\(2\)\/4\)\)\+Log\(4\)\) - Erf\(Log\(2-Sqrt\(2\)\)\)\n0\n/) { $found=1; last } END { exit !$found }' + if test "$?" != "0"; + then + echo "FAIL" + exit 2 + fi + echo "PASS" + exit 0 +elif test "$1" = "factor_integer"; +then + echo -n "factor_integer...." + res=$($2/factor_integer -threads 3 144) + if test "$?" != "0"; + then + echo "FAIL" + exit 1 + fi + echo "$res" | perl -0ne 'if (/144 =\n2\^4 \* 3\^2/) { $found=1; last } END { exit !$found }' + if test "$?" != "0"; + then + echo "FAIL" + exit 2 + fi + echo "PASS" + exit 0 +elif test "$1" = "factor_polynomial"; +then + echo -n "factor_polynomial...." + res=$($2/factor_polynomial -threads 2 "4*x*(1+x^2+y^2*x^3+z^4)^2") + if test "$?" != "0"; + then + echo "FAIL" + exit 1 + fi + echo "$res" | perl -0ne 'if (/4\*x\^7\*y\^4\+8\*x\^6\*y\^2\+4\*x\^5\+8\*x\^4\*y\^2\*z\^4\+8\*x\^4\*y\^2\+8\*x\^3\*z\^4\+8\*x\^3\+4\*x\*z\^8\+8\*x\*z\^4\+4\*x =\n4\*\(x\)\^1\*\(x\^3\*y\^2\+x\^2\+z\^4\+1\)\^2/) { $found=1; last } END { exit !$found }' + if test "$?" != "0"; + then + echo "FAIL" + exit 2 + fi + echo "PASS" + exit 0 +elif test "$1" = "fmpq_poly"; +then + echo "fmpq_poly....SKIPPED" +elif test "$1" = "fmpz_mod_poly"; +then + echo "fmpz_mod_poly....SKIPPED" +elif test "$1" = "fmpz_poly_factor_zassenhaus"; +then + echo "fmpz_poly_factor_zassenhaus....SKIPPED" +elif test "$1" = "fmpz_poly_q"; +then + echo "fmpz_poly_q....SKIPPED" +elif test "$1" = "fpwrap"; +then + echo "fpwrap....SKIPPED" +elif test "$1" = "fq_poly"; +then + echo "fq_poly....SKIPPED" +elif test "$1" = "functions_benchmark"; +then + echo "functions_benchmark....SKIPPED" +elif test "$1" = "hilbert_matrix"; +then + echo -n "hilbert_matrix...." + res=$($2/hilbert_matrix -eig 20) + if test "$?" != "0"; + then + echo "FAIL" + exit 1 + fi + echo "$res" | perl -0ne 'if (/prec=20: nan\nprec=40: nan\nprec=80: nan\nprec=160: nan\nprec=320: \[7\.777377397e-29 \+\/- 1.44e-39\]\nsuccess!\n/) { $found=1; last } END { exit !$found }' + if test "$?" != "0"; + then + echo "FAIL" + exit 2 + fi + echo "PASS" + exit 0 +elif test "$1" = "hilbert_matrix_ca"; +then + echo "hilbert_matrix_ca....SKIPPED" +elif test "$1" = "huge_expr"; +then + echo "huge_expr....SKIPPED" +elif test "$1" = "integrals"; +then + echo -n "integrals...." + res=$($2/integrals -i 21 -threads 3) + if test "$?" != "0"; + then + echo "FAIL" + exit 1 + fi + echo "$res" | perl -0ne 'if (/I21 = \[43\.3273391411077 \+\/- 4\.52e-14] \+ \[\+\/- 1\.95e-14\]\*I/) { $found=1; last } END { exit !$found }' + if test "$?" != "0"; + then + echo "FAIL" + exit 2 + fi + echo "PASS" + exit 0 +elif test "$1" = "keiper_li"; +then + echo "keiper_li....SKIPPED" +elif test "$1" = "lcentral"; +then + echo "lcentral....SKIPPED" +elif test "$1" = "logistic"; +then + echo "logistic....SKIPPED" +elif test "$1" = "lvalue"; +then + echo "lvalue....SKIPPED" +elif test "$1" = "machin"; +then + echo "machin....SKIPPED" +elif test "$1" = "multi_crt"; +then + echo "multi_crt....SKIPPED" +elif test "$1" = "padic"; +then + echo "padic....SKIPPED" +elif test "$1" = "partitions"; +then + echo "partitions....SKIPPED" +elif test "$1" = "pi"; +then + echo -n "pi...." + res=$($2/pi 1000 -threads 2) + if test "$?" != "0"; + then + echo "FAIL" + exit 1 + fi + echo "$res" | perl -0ne 'if (/\[3\.14159265358979323846\{\.\.\.959 digits\.\.\.\}76611195909216420199 \+\/- 8\.09e-1001\]/) { $found=1; last } END { exit !$found }' + if test "$?" != "0"; + then + echo "FAIL" + exit 2 + fi + echo "PASS" + exit 0 +elif test "$1" = "poly_roots"; +then + echo -n "poly_roots...." + res=$($2/poly_roots t 10) + if test "$?" != "0"; + then + echo "FAIL" + exit 1 + fi + echo "$res" | perl -0ne 'if (/\n10 roots with multiplicity 1\nsearching for 10 roots, 5 deflated\nprec=32: 5 isolated roots/) { $found=1; last } END { exit !$found }' + if test "$?" != "0"; + then + echo "FAIL" + exit 2 + fi + echo "PASS" + exit 0 +elif test "$1" = "primegen"; +then + echo "primegen....SKIPPED" +elif test "$1" = "qadic"; +then + echo "qadic....SKIPPED" +elif test "$1" = "radix"; +then + echo "radix....SKIPPED" +elif test "$1" = "real_roots"; +then + echo "real_roots....SKIPPED" +elif test "$1" = "stirling_matrix"; +then + echo "stirling_matrix....SKIPPED" +elif test "$1" = "swinnerton_dyer_poly"; +then + echo "swinnerton_dyer_poly....SKIPPED" +elif test "$1" = "taylor_integrals"; +then + echo "taylor_integrals....SKIPPED" +elif test "$1" = "zeta_zeros"; +then + echo -n "zeta_zeros...." + res=$($2/zeta_zeros -count 100 -threads 3) + if test "$?" != "0"; + then + echo "FAIL" + exit 1 + fi + echo "$res" | perl -0ne 'if (/97\t231\.2501887004991648\n98\t231\.9872352531802486\n99\t233\.6934041789083006\n100\t236\.5242296658162058/) { $found=1; last } END { exit !$found }' + if test "$?" != "0"; + then + echo "FAIL" + exit 2 + fi + echo "PASS" + exit 0 +else + exit 3 +fi