Blame SOURCES/0007-tests-Add-a-libparted-test-for-ped_partition_set_sys.patch

04e2fe
From 8b4a30cc60ecbe9b7bc966e70560e5ce0fc0c1ad Mon Sep 17 00:00:00 2001
04e2fe
From: "Brian C. Lane" <bcl@redhat.com>
04e2fe
Date: Mon, 8 Aug 2022 13:49:09 -0700
04e2fe
Subject: [PATCH 7/9] tests: Add a libparted test for ped_partition_set_system
04e2fe
 on gpt
04e2fe
04e2fe
Test the libparted API to make sure the flag is not cleared by calling
04e2fe
ped_partition_set_system.
04e2fe
---
04e2fe
 libparted/tests/Makefile.am    |  6 ++-
04e2fe
 libparted/tests/flags.c        | 81 ++++++++++++++++++++++++++++++++++
04e2fe
 libparted/tests/t1001-flags.sh | 23 ++++++++++
04e2fe
 3 files changed, 108 insertions(+), 2 deletions(-)
04e2fe
 create mode 100644 libparted/tests/flags.c
04e2fe
 create mode 100755 libparted/tests/t1001-flags.sh
04e2fe
04e2fe
diff --git a/libparted/tests/Makefile.am b/libparted/tests/Makefile.am
04e2fe
index fd5cba5..260b692 100644
04e2fe
--- a/libparted/tests/Makefile.am
04e2fe
+++ b/libparted/tests/Makefile.am
04e2fe
@@ -3,9 +3,10 @@
04e2fe
 #
04e2fe
 # This file may be modified and/or distributed without restriction.
04e2fe
 
04e2fe
-TESTS = t1000-label.sh t2000-disk.sh t2100-zerolen.sh t3000-symlink.sh t4000-volser.sh
04e2fe
+TESTS = t1000-label.sh t1001-flags.sh t2000-disk.sh t2100-zerolen.sh \
04e2fe
+	t3000-symlink.sh t4000-volser.sh
04e2fe
 EXTRA_DIST = $(TESTS)
04e2fe
-check_PROGRAMS = label disk zerolen symlink volser
04e2fe
+check_PROGRAMS = label disk zerolen symlink volser flags
04e2fe
 AM_CFLAGS = $(WARN_CFLAGS) $(WERROR_CFLAGS)
04e2fe
 
04e2fe
 LDADD = \
04e2fe
@@ -24,6 +25,7 @@ disk_SOURCES  = common.h common.c disk.c
04e2fe
 zerolen_SOURCES = common.h common.c zerolen.c
04e2fe
 symlink_SOURCES = common.h common.c symlink.c
04e2fe
 volser_SOURCES = common.h common.c volser.c
04e2fe
+flags_SOURCES = common.h common.c flags.c
04e2fe
 
04e2fe
 # Arrange to symlink to tests/init.sh.
04e2fe
 CLEANFILES = init.sh
04e2fe
diff --git a/libparted/tests/flags.c b/libparted/tests/flags.c
04e2fe
new file mode 100644
04e2fe
index 0000000..c83a361
04e2fe
--- /dev/null
04e2fe
+++ b/libparted/tests/flags.c
04e2fe
@@ -0,0 +1,81 @@
04e2fe
+#include <config.h>
04e2fe
+#include <unistd.h>
04e2fe
+
04e2fe
+#include <check.h>
04e2fe
+
04e2fe
+#include <parted/parted.h>
04e2fe
+
04e2fe
+#include "common.h"
04e2fe
+#include "progname.h"
04e2fe
+
04e2fe
+#define STREQ(a, b) (strcmp (a, b) == 0)
04e2fe
+
04e2fe
+static char* temporary_disk;
04e2fe
+
04e2fe
+static void
04e2fe
+create_disk (void)
04e2fe
+{
04e2fe
+        temporary_disk = _create_disk (80 * 1024 * 1024);
04e2fe
+        fail_if (temporary_disk == NULL, "Failed to create temporary disk");
04e2fe
+}
04e2fe
+
04e2fe
+static void
04e2fe
+destroy_disk (void)
04e2fe
+{
04e2fe
+        unlink (temporary_disk);
04e2fe
+        free (temporary_disk);
04e2fe
+}
04e2fe
+
04e2fe
+/* TEST: Test partition type flag on gpt disklabel */
04e2fe
+START_TEST (test_gpt_flag)
04e2fe
+{
04e2fe
+        PedDevice* dev = ped_device_get (temporary_disk);
04e2fe
+        if (dev == NULL)
04e2fe
+                return;
04e2fe
+
04e2fe
+        PedDisk* disk = ped_disk_new_fresh (dev, ped_disk_type_get ("gpt"));
04e2fe
+        PedConstraint *constraint = ped_constraint_any (dev);
04e2fe
+        PedPartition *part = ped_partition_new (disk, PED_PARTITION_NORMAL,
04e2fe
+            ped_file_system_type_get("ext4"), 2048, 4096);
04e2fe
+        ped_partition_set_flag(part, PED_PARTITION_BIOS_GRUB, 1);
04e2fe
+        // Type should remain set to BIOS_GRUB
04e2fe
+        ped_partition_set_system(part, ped_file_system_type_get("ext4"));
04e2fe
+
04e2fe
+        ped_disk_add_partition (disk, part, constraint);
04e2fe
+        ped_disk_commit (disk);
04e2fe
+        ped_constraint_destroy (constraint);
04e2fe
+
04e2fe
+        // Check flag to confirm it is still set
04e2fe
+        part = ped_disk_get_partition (disk, 1);
04e2fe
+        fail_if (ped_partition_get_flag(part, PED_PARTITION_BIOS_GRUB) != 1, "BIOS_GRUB flag not set");
04e2fe
+
04e2fe
+        ped_disk_destroy (disk);
04e2fe
+        ped_device_destroy (dev);
04e2fe
+}
04e2fe
+END_TEST
04e2fe
+
04e2fe
+int
04e2fe
+main (int argc, char **argv)
04e2fe
+{
04e2fe
+        set_program_name (argv[0]);
04e2fe
+        int number_failed;
04e2fe
+        Suite* suite = suite_create ("Partition Flags");
04e2fe
+        TCase* tcase_gpt = tcase_create ("GPT");
04e2fe
+
04e2fe
+        /* Fail when an exception is raised */
04e2fe
+        ped_exception_set_handler (_test_exception_handler);
04e2fe
+
04e2fe
+        tcase_add_checked_fixture (tcase_gpt, create_disk, destroy_disk);
04e2fe
+        tcase_add_test (tcase_gpt, test_gpt_flag);
04e2fe
+        /* Disable timeout for this test */
04e2fe
+        tcase_set_timeout (tcase_gpt, 0);
04e2fe
+        suite_add_tcase (suite, tcase_gpt);
04e2fe
+
04e2fe
+        SRunner* srunner = srunner_create (suite);
04e2fe
+        srunner_run_all (srunner, CK_VERBOSE);
04e2fe
+
04e2fe
+        number_failed = srunner_ntests_failed (srunner);
04e2fe
+        srunner_free (srunner);
04e2fe
+
04e2fe
+        return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
04e2fe
+}
04e2fe
diff --git a/libparted/tests/t1001-flags.sh b/libparted/tests/t1001-flags.sh
04e2fe
new file mode 100755
04e2fe
index 0000000..60a6248
04e2fe
--- /dev/null
04e2fe
+++ b/libparted/tests/t1001-flags.sh
04e2fe
@@ -0,0 +1,23 @@
04e2fe
+#!/bin/sh
04e2fe
+# run the flags unittest
04e2fe
+
04e2fe
+# Copyright (C) 2007-2014, 2019-2022 Free Software Foundation, Inc.
04e2fe
+
04e2fe
+# This program is free software; you can redistribute it and/or modify
04e2fe
+# it under the terms of the GNU General Public License as published by
04e2fe
+# the Free Software Foundation; either version 3 of the License, or
04e2fe
+# (at your option) any later version.
04e2fe
+
04e2fe
+# This program is distributed in the hope that it will be useful,
04e2fe
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
04e2fe
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
04e2fe
+# GNU General Public License for more details.
04e2fe
+
04e2fe
+# You should have received a copy of the GNU General Public License
04e2fe
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
04e2fe
+
04e2fe
+. "${top_srcdir=../..}/tests/init.sh"; path_prepend_ .
04e2fe
+
04e2fe
+flags || fail=1
04e2fe
+
04e2fe
+Exit $fail
04e2fe
-- 
04e2fe
2.37.1
04e2fe