From 140637fc7fd3eb1c94a32387131c227243c2ec8d Mon Sep 17 00:00:00 2001 From: Vojtech Trefny Date: Thu, 15 Jan 2026 15:23:43 +0100 Subject: [PATCH 1/8] spec: Remove build dependency on mpfr-devel --- dist/libbytesize.spec.in | 1 - 1 file changed, 1 deletion(-) 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} From 428ba93a2749ac8f35eedce700e1b6a1d2f7e854 Mon Sep 17 00:00:00 2001 From: Vojtech Trefny Date: Thu, 15 Jan 2026 15:24:04 +0100 Subject: [PATCH 2/8] ci: Run tests on pull requests using packit and tmt --- .fmf/version | 1 + .packit.yaml | 28 ++++++++++++++++++++++++++++ plans/blivet.fmf | 35 +++++++++++++++++++++++++++++++++++ plans/tests.fmf | 14 ++++++++++++++ 4 files changed, 78 insertions(+) create mode 100644 .fmf/version create mode 100644 plans/blivet.fmf create mode 100644 plans/tests.fmf 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..ce515cc 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 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 From 75b5fefaccb5ece4a6e31ddd1248d70321c4006d Mon Sep 17 00:00:00 2001 From: Vojtech Trefny Date: Thu, 15 Jan 2026 15:24:43 +0100 Subject: [PATCH 3/8] Fix memory leak in bs_size_get_bytes --- src/bs_size.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/bs_size.c b/src/bs_size.c index c9e2163..367210a 100644 --- a/src/bs_size.c +++ b/src/bs_size.c @@ -701,6 +701,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; } From 3afeab498e74635ea453e210dbeebd34366302ca Mon Sep 17 00:00:00 2001 From: Vojtech Trefny Date: Thu, 15 Jan 2026 15:32:43 +0100 Subject: [PATCH 4/8] Fix wrong returns in bs_size_true_div and bs_size_true_div_int --- src/bs_size.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bs_size.c b/src/bs_size.c index 367210a..2732c21 100644 --- a/src/bs_size.c +++ b/src/bs_size.c @@ -1213,7 +1213,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); @@ -1249,7 +1249,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; From 5d2d1cf3b5f096b7916bc7f9ba73c4b290fc3243 Mon Sep 17 00:00:00 2001 From: Vojtech Trefny Date: Thu, 15 Jan 2026 15:35:28 +0100 Subject: [PATCH 5/8] ci: Add configuration file for CodeRabbit --- .coderabbit.yaml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 .coderabbit.yaml 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 From 41aa5f91b6c5233811a48c65e0bc4c804f13093c Mon Sep 17 00:00:00 2001 From: Vojtech Trefny Date: Thu, 15 Jan 2026 16:02:34 +0100 Subject: [PATCH 6/8] ci: Remove mpfr-devel from Packit SRPM build dependencies --- .packit.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.packit.yaml b/.packit.yaml index ce515cc..5f361d8 100644 --- a/.packit.yaml +++ b/.packit.yaml @@ -112,7 +112,6 @@ srpm_build_deps: - autoconf - automake - gmp-devel - - mpfr-devel - pcre2-devel - gettext-devel - python3-devel From 3fd6023c9b251eb14aa617e085132369c62aeb5b Mon Sep 17 00:00:00 2001 From: Vojtech Trefny Date: Thu, 15 Jan 2026 16:14:43 +0100 Subject: [PATCH 7/8] Abort if we fail to allocate memory in bs_size_new Mostly to make static analysis happy, but we'll also crash a bit more nicely than after the NULL dereference in bs_size_init. --- src/bs_size.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bs_size.c b/src/bs_size.c index 2732c21..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; } From 26631d8dd22143e33bd0fd08787a7b04a1cbb886 Mon Sep 17 00:00:00 2001 From: Vojtech Trefny Date: Thu, 15 Jan 2026 16:27:57 +0100 Subject: [PATCH 8/8] Fix some documentation issues and typos discovered by codespell --- src/bs_size.h | 5 +++-- tests/libbytesize_unittest.py | 16 ++++++++-------- 2 files changed, 11 insertions(+), 10 deletions(-) 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()