diff --git a/.coderabbit.yaml b/.coderabbit.yaml new file mode 100644 index 0000000..8a31c7a --- /dev/null +++ b/.coderabbit.yaml @@ -0,0 +1,14 @@ +language: "en-US" +early_access: false +reviews: + profile: "chill" + poem: false + in_progress_fortune: false + sequence_diagrams: false + related_issues: false + related_prs: false + suggested_labels: false + suggested_reviewers: false + path_filters: ["!po/**", "!plans/**", "!.github/**", "!.fmf/**"] +chat: + art: false diff --git a/.fmf/version b/.fmf/version new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/.fmf/version @@ -0,0 +1 @@ +1 diff --git a/.packit.yaml b/.packit.yaml index a5e5a08..5f361d8 100644 --- a/.packit.yaml +++ b/.packit.yaml @@ -77,6 +77,34 @@ jobs: dist_git_branches: - fedora-branched +- job: tests + trigger: pull_request + targets: + - fedora-latest-x86_64 + - fedora-latest-aarch64 + - fedora-latest-stable-x86_64 + - fedora-latest-stable-aarch64 + branch: main + +# run tests for libbytesize consumers, see plans/ with `revdeps_blivet == yes` +- job: tests + identifier: revdeps_blivet + trigger: pull_request + notifications: + failure_comment: + message: "Blivet tests failed for commit {commit_sha}. @vojtechtrefny please check." + targets: + - fedora-latest-stable + branch: main + tf_extra_params: + environments: + - artifacts: + - type: repository-file + id: https://copr.fedorainfracloud.org/coprs/g/storage/blivet-daily/repo/fedora-$releasever/group_storage-blivet-daily-fedora-$releasever.repo + tmt: + context: + revdeps_blivet: "yes" + srpm_build_deps: - make - gcc @@ -84,7 +112,6 @@ srpm_build_deps: - autoconf - automake - gmp-devel - - mpfr-devel - pcre2-devel - gettext-devel - python3-devel diff --git a/dist/libbytesize.spec.in b/dist/libbytesize.spec.in index 1c350a8..5f50854 100644 --- a/dist/libbytesize.spec.in +++ b/dist/libbytesize.spec.in @@ -26,7 +26,6 @@ Source0: https://github.com/storaged-project/libbytesize/releases/download/% BuildRequires: make BuildRequires: gcc BuildRequires: gmp-devel -BuildRequires: mpfr-devel BuildRequires: pcre2-devel BuildRequires: gettext-devel %if %{with_python3} diff --git a/plans/blivet.fmf b/plans/blivet.fmf new file mode 100644 index 0000000..6d6a632 --- /dev/null +++ b/plans/blivet.fmf @@ -0,0 +1,35 @@ +# reverse dependency test for blivet +enabled: false + +adjust+: + when: revdeps_blivet == yes + enabled: true + +prepare: + - name: copr + how: shell + script: + - sudo dnf install -y python3-libdnf5 'dnf-command(copr)' + - sudo dnf copr enable -y @storage/udisks-daily + # TF prioritizes Fedora tag repo over all others, in particular our daily COPR + - for f in $(grep -l -r 'testing-farm-tag-repository' /etc/yum.repos.d); do sed -i '/priority/d' "$f" ;done + - sudo dnf -y update + + - name: ansible + how: shell + script: + - sudo dnf install -y curl ansible + - curl -Ok https://raw.githubusercontent.com/storaged-project/blivet/main/misc/install-test-dependencies.yml + - curl -Ok https://raw.githubusercontent.com/storaged-project/blivet/main/misc/blivet-tasks.yml + - ansible-playbook -K -i "localhost," -c local install-test-dependencies.yml + +discover: + how: shell + url: https://github.com/storaged-project/blivet + ref: main + tests: + - name: all + test: make test + +execute: + how: tmt diff --git a/plans/tests.fmf b/plans/tests.fmf new file mode 100644 index 0000000..0873400 --- /dev/null +++ b/plans/tests.fmf @@ -0,0 +1,14 @@ +summary: Run tests + +adjust+: + - when: revdeps_blivet == yes + enabled: false + +prepare: + - name: ansible + how: ansible + playbook: misc/install-test-dependencies.yml + +execute: + how: tmt + script: ./autogen.sh && ./configure && make -j && make ci diff --git a/src/bs_size.c b/src/bs_size.c index c9e2163..7d17be2 100644 --- a/src/bs_size.c +++ b/src/bs_size.c @@ -7,6 +7,7 @@ #include #include #include +#include /* set code unit width to 8 so we can use generic macros like 'pcre2_compile' * instead of 'pcre2_compile_8' @@ -398,6 +399,7 @@ void bs_clear_error (BSError **error) { */ BSSize bs_size_new (void) { BSSize ret = (BSSize) malloc (sizeof(struct _BSSize)); + assert (ret); bs_size_init (ret); return ret; } @@ -701,6 +703,7 @@ uint64_t bs_size_get_bytes (const BSSize size, int *sgn, BSError **error) { mpz_set_str (max, num_str, 10); free (num_str); if (mpz_cmp (size->bytes, max) > 0) { + mpz_clear (max); set_error (error, BS_ERROR_OVER, strdup("The size is too big, cannot be returned as a 64bit number of bytes")); return 0; } @@ -1212,7 +1215,7 @@ char* bs_size_true_div (const BSSize size1, const BSSize size2, BSError **error) if (mpz_cmp_ui (size2->bytes, 0) == 0) { set_error (error, BS_ERROR_ZERO_DIV, strdup_printf("Division by zero")); - return 0; + return NULL; } mpf_init2 (op1, BS_FLOAT_PREC_BITS); @@ -1248,7 +1251,7 @@ char* bs_size_true_div_int (const BSSize size, uint64_t divisor, BSError **error if (divisor == 0) { set_error (error, BS_ERROR_ZERO_DIV, strdup_printf ("Division by zero")); - return 0; + return NULL; } else if (divisor > ULONG_MAX) { set_error (error, BS_ERROR_OVER, strdup_printf ("Divisor too big, must be less or equal to %lu", ULONG_MAX)); return NULL; diff --git a/src/bs_size.h b/src/bs_size.h index beeefe1..87ee8ac 100644 --- a/src/bs_size.h +++ b/src/bs_size.h @@ -16,6 +16,7 @@ typedef struct _BSSize * BSSize; * @BS_ERROR_INVALID_SPEC: invalid size or unit spec provided * @BS_ERROR_OVER: a value is over the limits imposed by a type * @BS_ERROR_ZERO_DIV: an attempt to do division by zero + * @BS_ERROR_FAIL: generic failure error code * * Error codes that identify various errors that can occur while working with * #BSSize instances. @@ -74,14 +75,14 @@ typedef enum { * @bunit: a binary unit * @dunit: a decimal unit * - * Generic unit fo size in bytes. + * Generic unit for size in bytes. */ typedef union { BSBunit bunit; BSDunit dunit; } BSUnit; -/* use 256 bits of precision for floating point numbets, that should be more +/* use 256 bits of precision for floating point numbers, that should be more than enough */ /** * BS_FLOAT_PREC_BITS: diff --git a/tests/libbytesize_unittest.py b/tests/libbytesize_unittest.py index ab26517..13a187e 100755 --- a/tests/libbytesize_unittest.py +++ b/tests/libbytesize_unittest.py @@ -436,12 +436,12 @@ def testSgn(self): def testTrueDiv(self): x = SizeStruct.new_from_str("1024 B") y = SizeStruct.new_from_str("-102.4 B") # rounds to whole bytes - divResult = float(x.true_div(y)[:15].replace(locale.nl_langinfo(locale.RADIXCHAR), ".")) # just some number to cover accurancy and not cross max float range + divResult = float(x.true_div(y)[:15].replace(locale.nl_langinfo(locale.RADIXCHAR), ".")) # just some number to cover accuracy and not cross max float range self.assertAlmostEqual(divResult, 1024.0/-102.0) x = SizeStruct.new_from_str("1 MiB") y = SizeStruct.new_from_str("1 KiB") - divResult = float(x.true_div(y)[:15].replace(locale.nl_langinfo(locale.RADIXCHAR), ".")) # just some number to cover accurancy and not cross max float range + divResult = float(x.true_div(y)[:15].replace(locale.nl_langinfo(locale.RADIXCHAR), ".")) # just some number to cover accuracy and not cross max float range self.assertAlmostEqual(divResult, 1024.0) #enddef @@ -774,8 +774,8 @@ def testTrueDivInt(self): @requires_locales({'en_US.UTF-8'}) def testPowerComputationRoundingIssues(self): """Test cases that expose rounding differences when using floating-point arithmetic. - - These test cases were discovered by fuzzing and demonstrate that both GMP and MPFR + + These test cases were discovered by fuzzing and demonstrate that both GMP and MPFR can produce incorrect results due to floating-point rounding errors: half of these fail using GMP floating-point arithmetic, and half fail using MPFR floating-point arithmetic. They all pass using rational arithmetic, so this can be considered a @@ -794,7 +794,7 @@ def testPowerComputationRoundingIssues(self): ('0.0042875429 EB', 4287542900000000), ('0.0324645967 YB', 32464596700000000000000), ('0.1417885628 ZB', 141788562800000000000), - + # Medium values ('1.2558302853 TB', 1255830285300), ('1.2808632839 TB', 1280863283900), @@ -857,7 +857,7 @@ def testPowerComputationRoundingIssues(self): ('128.1037376252 PB', 128103737625200000), ('130.4743561323 ZB', 130474356132300000000000), ('138.2867513494 YB', 138286751349400000000000000), - + # Large values ('18258.0630890156 PB', 18258063089015600000), ('18800.1176214700 EB', 18800117621470000000000), @@ -865,7 +865,7 @@ def testPowerComputationRoundingIssues(self): ('276686.6833125990 YB', 276686683312599000000000000000), ('535817.4105711933 EB', 535817410571193300000000), ] - + for test_str, expected_bytes in test_cases: with self.subTest(test_str=test_str): size = SizeStruct.new_from_str(test_str) @@ -891,7 +891,7 @@ def testPowerComputationRoundingIssues(self): if __name__=='__main__': if len(sys.argv) > 1: DEFAULT_LOCALE = sys.argv[1] - # the unittest module would try to intepret the argument too, let's + # the unittest module would try to interpret the argument too, let's # remove it sys.argv = [sys.argv[0]] unittest.main()