- libparted: Fix problem with creating 1s partitions
- tests: Fixing libparted test framework usage
This commit is contained in:
parent
fb7cd25e73
commit
dc75c40906
133
0016-libparted-Fix-problem-with-creating-1s-partitions.patch
Normal file
133
0016-libparted-Fix-problem-with-creating-1s-partitions.patch
Normal file
@ -0,0 +1,133 @@
|
||||
From 9b009985da2e5eee5b5c179acfafab3aa1624f8b Mon Sep 17 00:00:00 2001
|
||||
From: "Brian C. Lane" <bcl@redhat.com>
|
||||
Date: Tue, 10 May 2022 15:04:12 -0700
|
||||
Subject: [PATCH 16/17] libparted: Fix problem with creating 1s partitions
|
||||
|
||||
There was a 1-off error in _partition_get_overlap_constraint that
|
||||
prevented partitions from being created in 1s free space. You could
|
||||
create 1s partitions as long they were done in order, but not after
|
||||
leaving 'holes'.
|
||||
|
||||
This fixes this and adds tests for it on msdos and gpt disklabels.
|
||||
---
|
||||
libparted/disk.c | 2 +-
|
||||
tests/Makefile.am | 2 ++
|
||||
tests/t9024-msdos-1s-partition.sh | 36 +++++++++++++++++++++++++++++++
|
||||
tests/t9025-gpt-1s-partition.sh | 36 +++++++++++++++++++++++++++++++
|
||||
4 files changed, 75 insertions(+), 1 deletion(-)
|
||||
create mode 100644 tests/t9024-msdos-1s-partition.sh
|
||||
create mode 100644 tests/t9025-gpt-1s-partition.sh
|
||||
|
||||
diff --git a/libparted/disk.c b/libparted/disk.c
|
||||
index 45f35fd..e1a3489 100644
|
||||
--- a/libparted/disk.c
|
||||
+++ b/libparted/disk.c
|
||||
@@ -1960,7 +1960,7 @@ _partition_get_overlap_constraint (PedPartition* part, PedGeometry* geom)
|
||||
if (walk)
|
||||
max_end = walk->geom.start - 1;
|
||||
|
||||
- if (min_start >= max_end)
|
||||
+ if (min_start > max_end)
|
||||
return NULL;
|
||||
|
||||
ped_geometry_init (&free_space, part->disk->dev,
|
||||
diff --git a/tests/Makefile.am b/tests/Makefile.am
|
||||
index 1d109d7..fa27b44 100644
|
||||
--- a/tests/Makefile.am
|
||||
+++ b/tests/Makefile.am
|
||||
@@ -91,6 +91,8 @@ TESTS = \
|
||||
t9021-maxima.sh \
|
||||
t9022-one-unit-snap.sh \
|
||||
t9023-value-lt-one.sh \
|
||||
+ t9024-msdos-1s-partition.sh \
|
||||
+ t9025-gpt-1s-partition.sh \
|
||||
t9030-align-check.sh \
|
||||
t9040-many-partitions.sh \
|
||||
t9041-undetected-in-use-16th-partition.sh \
|
||||
diff --git a/tests/t9024-msdos-1s-partition.sh b/tests/t9024-msdos-1s-partition.sh
|
||||
new file mode 100644
|
||||
index 0000000..7115156
|
||||
--- /dev/null
|
||||
+++ b/tests/t9024-msdos-1s-partition.sh
|
||||
@@ -0,0 +1,36 @@
|
||||
+#!/bin/sh
|
||||
+# Test creating 1s partitions in 1s free space
|
||||
+
|
||||
+# Copyright (C) 2022 Free Software Foundation, Inc.
|
||||
+
|
||||
+# This program is free software; you can redistribute it and/or modify
|
||||
+# it under the terms of the GNU General Public License as published by
|
||||
+# the Free Software Foundation; either version 3 of the License, or
|
||||
+# (at your option) any later version.
|
||||
+
|
||||
+# This program is distributed in the hope that it will be useful,
|
||||
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
+# GNU General Public License for more details.
|
||||
+
|
||||
+# You should have received a copy of the GNU General Public License
|
||||
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
+
|
||||
+. "${srcdir=.}/init.sh"; path_prepend_ ../parted
|
||||
+
|
||||
+dev=loop-file
|
||||
+
|
||||
+# create device
|
||||
+truncate --size 10MiB "$dev" || fail=1
|
||||
+
|
||||
+# create msdos label and some partitions with 1s free space between
|
||||
+parted --script "$dev" mklabel msdos > out 2>&1 || fail=1
|
||||
+parted --script "$dev" mkpart primary ext4 64s 128s > out 2>&1 || fail=1
|
||||
+parted --script "$dev" mkpart primary ext4 130s 200s > out 2>&1 || fail=1
|
||||
+parted --script "$dev" u s p free
|
||||
+
|
||||
+# Free space is at 129s
|
||||
+parted --script "$dev" mkpart primary ext4 129s 129s > out 2>&1 || fail=1
|
||||
+parted --script "$dev" u s p free
|
||||
+
|
||||
+Exit $fail
|
||||
diff --git a/tests/t9025-gpt-1s-partition.sh b/tests/t9025-gpt-1s-partition.sh
|
||||
new file mode 100644
|
||||
index 0000000..c97ab8b
|
||||
--- /dev/null
|
||||
+++ b/tests/t9025-gpt-1s-partition.sh
|
||||
@@ -0,0 +1,36 @@
|
||||
+#!/bin/sh
|
||||
+# Test creating 1s partitions in 1s free space
|
||||
+
|
||||
+# Copyright (C) 2022 Free Software Foundation, Inc.
|
||||
+
|
||||
+# This program is free software; you can redistribute it and/or modify
|
||||
+# it under the terms of the GNU General Public License as published by
|
||||
+# the Free Software Foundation; either version 3 of the License, or
|
||||
+# (at your option) any later version.
|
||||
+
|
||||
+# This program is distributed in the hope that it will be useful,
|
||||
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
+# GNU General Public License for more details.
|
||||
+
|
||||
+# You should have received a copy of the GNU General Public License
|
||||
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
+
|
||||
+. "${srcdir=.}/init.sh"; path_prepend_ ../parted
|
||||
+
|
||||
+dev=loop-file
|
||||
+
|
||||
+# create device
|
||||
+truncate --size 10MiB "$dev" || fail=1
|
||||
+
|
||||
+# create msdos label and some partitions with 1s free space between
|
||||
+parted --script "$dev" mklabel gpt > out 2>&1 || fail=1
|
||||
+parted --script "$dev" mkpart p1 ext4 64s 128s > out 2>&1 || fail=1
|
||||
+parted --script "$dev" mkpart p2 ext4 130s 200s > out 2>&1 || fail=1
|
||||
+parted --script "$dev" u s p free
|
||||
+
|
||||
+# Free space is at 129s
|
||||
+parted --script "$dev" mkpart p3 ext4 129s 129s > out 2>&1 || fail=1
|
||||
+parted --script "$dev" u s p free
|
||||
+
|
||||
+Exit $fail
|
||||
--
|
||||
2.39.1
|
||||
|
262
0017-tests-Fixing-libparted-test-framework-usage.patch
Normal file
262
0017-tests-Fixing-libparted-test-framework-usage.patch
Normal file
@ -0,0 +1,262 @@
|
||||
From 7b555132be63172a2d621afcdedfa7797185d3b5 Mon Sep 17 00:00:00 2001
|
||||
From: "Brian C. Lane" <bcl@redhat.com>
|
||||
Date: Tue, 7 Feb 2023 09:31:42 -0800
|
||||
Subject: [PATCH 17/17] tests: Fixing libparted test framework usage
|
||||
|
||||
The fail and fail_if functions from libcheck are deprecated, replace
|
||||
them with ck_abort_msg and ck_assert_msg. Note that the logic of assert
|
||||
is the opposite of fail_if.
|
||||
---
|
||||
libparted/tests/common.c | 8 ++++----
|
||||
libparted/tests/disk.c | 6 +++---
|
||||
libparted/tests/flags.c | 6 +++---
|
||||
libparted/tests/label.c | 14 ++++++--------
|
||||
libparted/tests/symlink.c | 31 +++++++++++++++++++++----------
|
||||
libparted/tests/volser.c | 2 +-
|
||||
libparted/tests/zerolen.c | 2 +-
|
||||
7 files changed, 39 insertions(+), 30 deletions(-)
|
||||
|
||||
diff --git a/libparted/tests/common.c b/libparted/tests/common.c
|
||||
index 2be0e3a..8c42ece 100644
|
||||
--- a/libparted/tests/common.c
|
||||
+++ b/libparted/tests/common.c
|
||||
@@ -27,7 +27,7 @@ size_t get_sector_size (void)
|
||||
PedExceptionOption
|
||||
_test_exception_handler (PedException* e)
|
||||
{
|
||||
- fail ("Exception of type %s has been raised: %s",
|
||||
+ ck_abort_msg("Exception of type %s has been raised: %s",
|
||||
ped_exception_get_type_string (e->type),
|
||||
e->message);
|
||||
|
||||
@@ -69,10 +69,10 @@ _create_disk_label (PedDevice *dev, PedDiskType *type)
|
||||
|
||||
/* Create the label */
|
||||
disk = ped_disk_new_fresh (dev, type);
|
||||
- fail_if (!disk, "Failed to create a label of type: %s",
|
||||
+ ck_assert_msg(disk != NULL, "Failed to create a label of type: %s",
|
||||
type->name);
|
||||
- fail_if (!ped_disk_commit(disk),
|
||||
- "Failed to commit label to device");
|
||||
+ ck_assert_msg(ped_disk_commit(disk) != 0,
|
||||
+ "Failed to commit label to device");
|
||||
|
||||
return disk;
|
||||
}
|
||||
diff --git a/libparted/tests/disk.c b/libparted/tests/disk.c
|
||||
index 62d20c1..f7b16a5 100644
|
||||
--- a/libparted/tests/disk.c
|
||||
+++ b/libparted/tests/disk.c
|
||||
@@ -14,7 +14,7 @@ static void
|
||||
create_disk (void)
|
||||
{
|
||||
temporary_disk = _create_disk (get_sector_size () * 4 * 10 * 1024);
|
||||
- fail_if (temporary_disk == NULL, "Failed to create temporary disk");
|
||||
+ ck_assert_msg(temporary_disk != NULL, "Failed to create temporary disk");
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -72,8 +72,8 @@ START_TEST (test_duplicate)
|
||||
part = ped_disk_get_partition (disk, *i);
|
||||
part_dup = ped_disk_get_partition (disk_dup, *i);
|
||||
|
||||
- fail_if (part->geom.start != part_dup->geom.start ||
|
||||
- part->geom.end != part_dup->geom.end,
|
||||
+ ck_assert_msg(part->geom.start == part_dup->geom.start &&
|
||||
+ part->geom.end == part_dup->geom.end,
|
||||
"Duplicated partition %d doesn't match. "
|
||||
"Details are start: %d/%d end: %d/%d\n",
|
||||
*i, part->geom.start, part_dup->geom.start,
|
||||
diff --git a/libparted/tests/flags.c b/libparted/tests/flags.c
|
||||
index c4b290b..ff4ae71 100644
|
||||
--- a/libparted/tests/flags.c
|
||||
+++ b/libparted/tests/flags.c
|
||||
@@ -16,7 +16,7 @@ static void
|
||||
create_disk (void)
|
||||
{
|
||||
temporary_disk = _create_disk (80 * 1024 * 1024);
|
||||
- fail_if (temporary_disk == NULL, "Failed to create temporary disk");
|
||||
+ ck_assert_msg(temporary_disk != NULL, "Failed to create temporary disk");
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -47,7 +47,7 @@ START_TEST (test_gpt_flag)
|
||||
|
||||
// Check flag to confirm it is still set
|
||||
part = ped_disk_get_partition (disk, 1);
|
||||
- fail_if (ped_partition_get_flag(part, PED_PARTITION_BIOS_GRUB) != 1, "BIOS_GRUB flag not set");
|
||||
+ ck_assert_msg(ped_partition_get_flag(part, PED_PARTITION_BIOS_GRUB) == 1, "BIOS_GRUB flag not set");
|
||||
|
||||
ped_disk_destroy (disk);
|
||||
ped_device_destroy (dev);
|
||||
@@ -75,7 +75,7 @@ START_TEST (test_msdos_flag)
|
||||
|
||||
// Check flag to confirm it is still set
|
||||
part = ped_disk_get_partition (disk, 1);
|
||||
- fail_if (ped_partition_get_flag(part, PED_PARTITION_BLS_BOOT) != 1, "BLS_BOOT flag not set");
|
||||
+ ck_assert_msg(ped_partition_get_flag(part, PED_PARTITION_BLS_BOOT) == 1, "BLS_BOOT flag not set");
|
||||
|
||||
ped_disk_destroy (disk);
|
||||
ped_device_destroy (dev);
|
||||
diff --git a/libparted/tests/label.c b/libparted/tests/label.c
|
||||
index e0d63c7..67b1b07 100644
|
||||
--- a/libparted/tests/label.c
|
||||
+++ b/libparted/tests/label.c
|
||||
@@ -16,7 +16,7 @@ static void
|
||||
create_disk (void)
|
||||
{
|
||||
temporary_disk = _create_disk (80 * 1024 * 1024);
|
||||
- fail_if (temporary_disk == NULL, "Failed to create temporary disk");
|
||||
+ ck_assert_msg(temporary_disk != NULL, "Failed to create temporary disk");
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -72,12 +72,11 @@ START_TEST (test_probe_label)
|
||||
|
||||
/* Try to probe the disk label. */
|
||||
probed = ped_disk_probe (dev);
|
||||
- fail_if (!probed,
|
||||
+ ck_assert_msg(probed,
|
||||
"Failed to probe the just created label of type: %s",
|
||||
type->name);
|
||||
if (probed && !STREQ (probed->name, type->name))
|
||||
- fail_if (1,
|
||||
- "Probe returned label of type: %s as type: %s",
|
||||
+ ck_abort_msg("Probe returned label of type: %s as type: %s",
|
||||
type->name, probed->name);
|
||||
}
|
||||
ped_device_destroy (dev);
|
||||
@@ -105,12 +104,11 @@ START_TEST (test_read_label)
|
||||
|
||||
/* Try to read the disk label. */
|
||||
disk = ped_disk_new (dev);
|
||||
- fail_if (!disk,
|
||||
+ ck_assert_msg(disk,
|
||||
"Failed to read the just created label of type: %s",
|
||||
type->name);
|
||||
if (disk && !STREQ (disk->type->name, type->name))
|
||||
- fail_if (1,
|
||||
- "Read returned label of type: %s as type: %s",
|
||||
+ ck_abort_msg("Read returned label of type: %s as type: %s",
|
||||
type->name, disk->type->name);
|
||||
|
||||
ped_disk_destroy (disk);
|
||||
@@ -138,7 +136,7 @@ START_TEST (test_clone_label)
|
||||
|
||||
/* Try to clone the disk label. */
|
||||
PedDisk* clone = ped_disk_duplicate (disk);
|
||||
- fail_if (!clone,
|
||||
+ ck_assert_msg(clone,
|
||||
"Failed to clone the just created label of type: %s",
|
||||
type->name);
|
||||
|
||||
diff --git a/libparted/tests/symlink.c b/libparted/tests/symlink.c
|
||||
index 52e99ca..da6bef8 100644
|
||||
--- a/libparted/tests/symlink.c
|
||||
+++ b/libparted/tests/symlink.c
|
||||
@@ -30,7 +30,7 @@ static void
|
||||
create_disk (void)
|
||||
{
|
||||
temporary_disk = _create_disk (4096 * 1024);
|
||||
- fail_if (temporary_disk == NULL, "Failed to create temporary disk");
|
||||
+ ck_assert_msg(temporary_disk != NULL, "Failed to create temporary disk");
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -45,7 +45,7 @@ START_TEST (test_symlink)
|
||||
char cwd[256], ln[256] = "/dev/mapper/parted-test-XXXXXX";
|
||||
|
||||
if (!getcwd (cwd, sizeof cwd)) {
|
||||
- fail ("Could not get cwd");
|
||||
+ ck_abort_msg("Could not get cwd");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ START_TEST (test_symlink)
|
||||
temporary disk */
|
||||
int tmp_fd = mkstemp (ln);
|
||||
if (tmp_fd == -1) {
|
||||
- fail ("Could not create tempfile");
|
||||
+ ck_abort_msg("Could not create tempfile");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -62,11 +62,17 @@ START_TEST (test_symlink)
|
||||
close (tmp_fd);
|
||||
unlink (ln);
|
||||
char temp_disk_path[256];
|
||||
- snprintf (temp_disk_path, sizeof temp_disk_path, "%s/%s", cwd,
|
||||
- temporary_disk);
|
||||
+ int r = snprintf(temp_disk_path, sizeof temp_disk_path, "%s/%s",
|
||||
+ cwd,
|
||||
+ temporary_disk);
|
||||
+ if (r < 0 || r >= sizeof temp_disk_path) {
|
||||
+ ck_abort_msg("symlink truncated");
|
||||
+ return;
|
||||
+ }
|
||||
+
|
||||
int res = symlink (temp_disk_path, ln);
|
||||
if (res) {
|
||||
- fail ("could not create symlink");
|
||||
+ ck_abort_msg("could not create symlink");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -77,7 +83,7 @@ START_TEST (test_symlink)
|
||||
/* Create a second temporary_disk */
|
||||
char *temporary_disk2 = _create_disk (4096 * 1024);
|
||||
if (temporary_disk2 == NULL) {
|
||||
- fail ("Failed to create 2nd temporary disk");
|
||||
+ ck_abort_msg("Failed to create 2nd temporary disk");
|
||||
goto exit_destroy_dev;
|
||||
}
|
||||
|
||||
@@ -89,11 +95,16 @@ START_TEST (test_symlink)
|
||||
|
||||
/* Update symlink to point to our new / second temporary disk */
|
||||
unlink (ln);
|
||||
- snprintf (temp_disk_path, sizeof temp_disk_path, "%s/%s", cwd,
|
||||
- temporary_disk);
|
||||
+ r = snprintf (temp_disk_path, sizeof temp_disk_path, "%s/%s",
|
||||
+ cwd, temporary_disk);
|
||||
+ if (r < 0 || r >= sizeof temp_disk_path) {
|
||||
+ ck_abort_msg("2nd symlink truncated");
|
||||
+ goto exit_destroy_dev;
|
||||
+ }
|
||||
+
|
||||
res = symlink (temp_disk_path, ln);
|
||||
if (res) {
|
||||
- fail ("could not create 2nd symlink");
|
||||
+ ck_abort_msg("could not create 2nd symlink");
|
||||
goto exit_destroy_dev;
|
||||
}
|
||||
|
||||
diff --git a/libparted/tests/volser.c b/libparted/tests/volser.c
|
||||
index c6efa5f..4b6e2d1 100644
|
||||
--- a/libparted/tests/volser.c
|
||||
+++ b/libparted/tests/volser.c
|
||||
@@ -34,7 +34,7 @@ static void set_test (void)
|
||||
type = ped_disk_type_get ("dasd");
|
||||
|
||||
tmp_disk = _create_disk (20*1024*1024);
|
||||
- fail_if (tmp_disk == NULL, "Failed to create temporary disk");
|
||||
+ ck_assert_msg(tmp_disk != NULL, "Failed to create temporary disk");
|
||||
dev = ped_device_get (tmp_disk);
|
||||
if (dev == NULL)
|
||||
return;
|
||||
diff --git a/libparted/tests/zerolen.c b/libparted/tests/zerolen.c
|
||||
index cf2bd1c..2d9b424 100644
|
||||
--- a/libparted/tests/zerolen.c
|
||||
+++ b/libparted/tests/zerolen.c
|
||||
@@ -28,7 +28,7 @@ main (int argc, char **argv)
|
||||
TCase* tcase_probe = tcase_create ("Probe");
|
||||
|
||||
if (argc < 2) {
|
||||
- fail ("Insufficient arguments");
|
||||
+ ck_abort_msg("Insufficient arguments");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
temporary_disk = argv[1];
|
||||
--
|
||||
2.39.1
|
||||
|
@ -1,7 +1,7 @@
|
||||
Summary: The GNU disk partition manipulation program
|
||||
Name: parted
|
||||
Version: 3.5
|
||||
Release: 9%{?dist}
|
||||
Release: 10%{?dist}
|
||||
License: GPL-3.0-or-later
|
||||
URL: http://www.gnu.org/software/parted
|
||||
|
||||
@ -26,6 +26,8 @@ Patch0012: 0012-tests-Add-a-libparted-test-for-ped_partition_set_sys.patch
|
||||
Patch0013: 0013-show-GPT-UUIDs-in-JSON-output.patch
|
||||
Patch0014: 0014-gpt-Add-no_automount-partition-flag.patch
|
||||
Patch0015: 0015-tests-XFS-requires-a-minimum-size-of-300M.patch
|
||||
Patch0016: 0016-libparted-Fix-problem-with-creating-1s-partitions.patch
|
||||
Patch0017: 0017-tests-Fixing-libparted-test-framework-usage.patch
|
||||
|
||||
BuildRequires: gcc
|
||||
BuildRequires: e2fsprogs-devel
|
||||
@ -130,6 +132,10 @@ make check
|
||||
|
||||
|
||||
%changelog
|
||||
* Tue Feb 07 2023 Brian C. Lane <bcl@redhat.com> - 3.5-9.bcl.1
|
||||
- libparted: Fix problem with creating 1s partitions
|
||||
- tests: Fixing libparted test framework usage
|
||||
|
||||
* Mon Jan 30 2023 Brian C. Lane <bcl@redhat.com> - 3.5-9
|
||||
- SPDX migration
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user