Skip to content

Commit 039b74a

Browse files
Merge pull request #166 from vojtechtrefny/main_various-fixes
Various small fixes and reverse dependency tests using packit
2 parents 7e8e395 + 26631d8 commit 039b74a

9 files changed

Lines changed: 108 additions & 14 deletions

File tree

.coderabbit.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
language: "en-US"
2+
early_access: false
3+
reviews:
4+
profile: "chill"
5+
poem: false
6+
in_progress_fortune: false
7+
sequence_diagrams: false
8+
related_issues: false
9+
related_prs: false
10+
suggested_labels: false
11+
suggested_reviewers: false
12+
path_filters: ["!po/**", "!plans/**", "!.github/**", "!.fmf/**"]
13+
chat:
14+
art: false

.fmf/version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1

.packit.yaml

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,41 @@ jobs:
7777
dist_git_branches:
7878
- fedora-branched
7979

80+
- job: tests
81+
trigger: pull_request
82+
targets:
83+
- fedora-latest-x86_64
84+
- fedora-latest-aarch64
85+
- fedora-latest-stable-x86_64
86+
- fedora-latest-stable-aarch64
87+
branch: main
88+
89+
# run tests for libbytesize consumers, see plans/ with `revdeps_blivet == yes`
90+
- job: tests
91+
identifier: revdeps_blivet
92+
trigger: pull_request
93+
notifications:
94+
failure_comment:
95+
message: "Blivet tests failed for commit {commit_sha}. @vojtechtrefny please check."
96+
targets:
97+
- fedora-latest-stable
98+
branch: main
99+
tf_extra_params:
100+
environments:
101+
- artifacts:
102+
- type: repository-file
103+
id: https://copr.fedorainfracloud.org/coprs/g/storage/blivet-daily/repo/fedora-$releasever/group_storage-blivet-daily-fedora-$releasever.repo
104+
tmt:
105+
context:
106+
revdeps_blivet: "yes"
107+
80108
srpm_build_deps:
81109
- make
82110
- gcc
83111
- libtool
84112
- autoconf
85113
- automake
86114
- gmp-devel
87-
- mpfr-devel
88115
- pcre2-devel
89116
- gettext-devel
90117
- python3-devel

dist/libbytesize.spec.in

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ Source0: https://github.com/storaged-project/libbytesize/releases/download/%
2626
BuildRequires: make
2727
BuildRequires: gcc
2828
BuildRequires: gmp-devel
29-
BuildRequires: mpfr-devel
3029
BuildRequires: pcre2-devel
3130
BuildRequires: gettext-devel
3231
%if %{with_python3}

plans/blivet.fmf

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# reverse dependency test for blivet
2+
enabled: false
3+
4+
adjust+:
5+
when: revdeps_blivet == yes
6+
enabled: true
7+
8+
prepare:
9+
- name: copr
10+
how: shell
11+
script:
12+
- sudo dnf install -y python3-libdnf5 'dnf-command(copr)'
13+
- sudo dnf copr enable -y @storage/udisks-daily
14+
# TF prioritizes Fedora tag repo over all others, in particular our daily COPR
15+
- for f in $(grep -l -r 'testing-farm-tag-repository' /etc/yum.repos.d); do sed -i '/priority/d' "$f" ;done
16+
- sudo dnf -y update
17+
18+
- name: ansible
19+
how: shell
20+
script:
21+
- sudo dnf install -y curl ansible
22+
- curl -Ok https://raw.githubusercontent.com/storaged-project/blivet/main/misc/install-test-dependencies.yml
23+
- curl -Ok https://raw.githubusercontent.com/storaged-project/blivet/main/misc/blivet-tasks.yml
24+
- ansible-playbook -K -i "localhost," -c local install-test-dependencies.yml
25+
26+
discover:
27+
how: shell
28+
url: https://github.com/storaged-project/blivet
29+
ref: main
30+
tests:
31+
- name: all
32+
test: make test
33+
34+
execute:
35+
how: tmt

plans/tests.fmf

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
summary: Run tests
2+
3+
adjust+:
4+
- when: revdeps_blivet == yes
5+
enabled: false
6+
7+
prepare:
8+
- name: ansible
9+
how: ansible
10+
playbook: misc/install-test-dependencies.yml
11+
12+
execute:
13+
how: tmt
14+
script: ./autogen.sh && ./configure && make -j && make ci

src/bs_size.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <string.h>
88
#include <ctype.h>
99
#include <limits.h>
10+
#include <assert.h>
1011

1112
/* set code unit width to 8 so we can use generic macros like 'pcre2_compile'
1213
* instead of 'pcre2_compile_8'
@@ -398,6 +399,7 @@ void bs_clear_error (BSError **error) {
398399
*/
399400
BSSize bs_size_new (void) {
400401
BSSize ret = (BSSize) malloc (sizeof(struct _BSSize));
402+
assert (ret);
401403
bs_size_init (ret);
402404
return ret;
403405
}
@@ -701,6 +703,7 @@ uint64_t bs_size_get_bytes (const BSSize size, int *sgn, BSError **error) {
701703
mpz_set_str (max, num_str, 10);
702704
free (num_str);
703705
if (mpz_cmp (size->bytes, max) > 0) {
706+
mpz_clear (max);
704707
set_error (error, BS_ERROR_OVER, strdup("The size is too big, cannot be returned as a 64bit number of bytes"));
705708
return 0;
706709
}
@@ -1212,7 +1215,7 @@ char* bs_size_true_div (const BSSize size1, const BSSize size2, BSError **error)
12121215

12131216
if (mpz_cmp_ui (size2->bytes, 0) == 0) {
12141217
set_error (error, BS_ERROR_ZERO_DIV, strdup_printf("Division by zero"));
1215-
return 0;
1218+
return NULL;
12161219
}
12171220

12181221
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
12481251

12491252
if (divisor == 0) {
12501253
set_error (error, BS_ERROR_ZERO_DIV, strdup_printf ("Division by zero"));
1251-
return 0;
1254+
return NULL;
12521255
} else if (divisor > ULONG_MAX) {
12531256
set_error (error, BS_ERROR_OVER, strdup_printf ("Divisor too big, must be less or equal to %lu", ULONG_MAX));
12541257
return NULL;

src/bs_size.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ typedef struct _BSSize * BSSize;
1616
* @BS_ERROR_INVALID_SPEC: invalid size or unit spec provided
1717
* @BS_ERROR_OVER: a value is over the limits imposed by a type
1818
* @BS_ERROR_ZERO_DIV: an attempt to do division by zero
19+
* @BS_ERROR_FAIL: generic failure error code
1920
*
2021
* Error codes that identify various errors that can occur while working with
2122
* #BSSize instances.
@@ -74,14 +75,14 @@ typedef enum {
7475
* @bunit: a binary unit
7576
* @dunit: a decimal unit
7677
*
77-
* Generic unit fo size in bytes.
78+
* Generic unit for size in bytes.
7879
*/
7980
typedef union {
8081
BSBunit bunit;
8182
BSDunit dunit;
8283
} BSUnit;
8384

84-
/* use 256 bits of precision for floating point numbets, that should be more
85+
/* use 256 bits of precision for floating point numbers, that should be more
8586
than enough */
8687
/**
8788
* BS_FLOAT_PREC_BITS:

tests/libbytesize_unittest.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -436,12 +436,12 @@ def testSgn(self):
436436
def testTrueDiv(self):
437437
x = SizeStruct.new_from_str("1024 B")
438438
y = SizeStruct.new_from_str("-102.4 B") # rounds to whole bytes
439-
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
439+
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
440440
self.assertAlmostEqual(divResult, 1024.0/-102.0)
441441

442442
x = SizeStruct.new_from_str("1 MiB")
443443
y = SizeStruct.new_from_str("1 KiB")
444-
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
444+
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
445445
self.assertAlmostEqual(divResult, 1024.0)
446446
#enddef
447447

@@ -774,8 +774,8 @@ def testTrueDivInt(self):
774774
@requires_locales({'en_US.UTF-8'})
775775
def testPowerComputationRoundingIssues(self):
776776
"""Test cases that expose rounding differences when using floating-point arithmetic.
777-
778-
These test cases were discovered by fuzzing and demonstrate that both GMP and MPFR
777+
778+
These test cases were discovered by fuzzing and demonstrate that both GMP and MPFR
779779
can produce incorrect results due to floating-point rounding errors: half of these
780780
fail using GMP floating-point arithmetic, and half fail using MPFR floating-point
781781
arithmetic. They all pass using rational arithmetic, so this can be considered a
@@ -794,7 +794,7 @@ def testPowerComputationRoundingIssues(self):
794794
('0.0042875429 EB', 4287542900000000),
795795
('0.0324645967 YB', 32464596700000000000000),
796796
('0.1417885628 ZB', 141788562800000000000),
797-
797+
798798
# Medium values
799799
('1.2558302853 TB', 1255830285300),
800800
('1.2808632839 TB', 1280863283900),
@@ -857,15 +857,15 @@ def testPowerComputationRoundingIssues(self):
857857
('128.1037376252 PB', 128103737625200000),
858858
('130.4743561323 ZB', 130474356132300000000000),
859859
('138.2867513494 YB', 138286751349400000000000000),
860-
860+
861861
# Large values
862862
('18258.0630890156 PB', 18258063089015600000),
863863
('18800.1176214700 EB', 18800117621470000000000),
864864
('269636.0318459886 YB', 269636031845988600000000000000),
865865
('276686.6833125990 YB', 276686683312599000000000000000),
866866
('535817.4105711933 EB', 535817410571193300000000),
867867
]
868-
868+
869869
for test_str, expected_bytes in test_cases:
870870
with self.subTest(test_str=test_str):
871871
size = SizeStruct.new_from_str(test_str)
@@ -891,7 +891,7 @@ def testPowerComputationRoundingIssues(self):
891891
if __name__=='__main__':
892892
if len(sys.argv) > 1:
893893
DEFAULT_LOCALE = sys.argv[1]
894-
# the unittest module would try to intepret the argument too, let's
894+
# the unittest module would try to interpret the argument too, let's
895895
# remove it
896896
sys.argv = [sys.argv[0]]
897897
unittest.main()

0 commit comments

Comments
 (0)