[Parted-maintainers] Bug#294520: Cannot reproduce the problem

Samuel Thibault samuel.thibault at ens-lyon.org
Fri Aug 31 17:57:33 BST 2007


Hi,

Otavio Salvador, le Fri 31 Aug 2007 09:16:02 -0300, a écrit :
> Can you try to make it to fail properly?

I'm in the train so I couldn't download version 1.8 of parted with its
test engine, but the attached program fails without the patch.

Samuel
-------------- next part --------------
// cc -std=c99 test.c -lparted -o test

//#include <config.h>
#include <unistd.h>

//#include <check.h>

#include <parted/parted.h>

//#include "common.h"
#define  fail_if(expr, fmt, ...) if (expr) fprintf(stderr,fmt,##__VA_ARGS__)

static char* temporary_disk = "testpart";

#if 0
static void
create_disk (void)
{
        temporary_disk = _create_disk (20);
        fail_if (temporary_disk == NULL, "Failed to create temporary disk");
}

static void
destroy_disk (void)
{
        unlink (temporary_disk);
        free (temporary_disk);
}
#endif

/* TEST: Create a disklabel on a simple disk image */
void START_TEST (void)
{
        PedDevice* dev = ped_device_get (temporary_disk);
        if (dev == NULL)
                return;

        PedDiskType* type;
        PedDisk* disk;
		PedDisk* disk_dup;
		PedPartition *part;
		PedPartition *part_dup;
		PedConstraint *constraint;

		//disk = _create_disk_label (dev, ped_disk_type_get ("msdos"));
		disk = ped_disk_new_fresh (dev, ped_disk_type_get ("msdos"));
		
		constraint = ped_constraint_any (dev);

		/* Primary partition from 16,4kB to 15MB */
		part = ped_partition_new (disk, PED_PARTITION_EXTENDED,
								  NULL,
								  32, 29311);
		ped_disk_add_partition (disk, part, constraint);
		
		/* Logical partition from 10MB to 15MB */
		part = ped_partition_new (disk, PED_PARTITION_LOGICAL,
								  ped_file_system_type_get ("ext2"),
								  19584, 29311);
		ped_disk_add_partition (disk, part, constraint);
		
		/* Logical partition from 16,4kB to 4981kB */
		part = ped_partition_new (disk, PED_PARTITION_LOGICAL,
								  ped_file_system_type_get ("ext2"),
								  32, 9727);
		ped_disk_add_partition (disk, part, constraint);

		ped_disk_commit (disk);

		ped_constraint_destroy (constraint);

		disk_dup = ped_disk_duplicate (disk);

		/* Checks if all partitions match */
#define compar(i) \
			part = ped_disk_get_partition (disk, i); \
			part_dup = ped_disk_get_partition (disk_dup, i); \
\
			fail_if (part->num != part_dup->num || \
				 	 part->geom.start != part_dup->geom.start || \
					 part->geom.end != part_dup->geom.end, \
					 "Duplicated partition %d/%d/%d doesn't match. " \
					 "Details are start: %lld/%lld end: %lld/%lld\n", \
					 i, part->num, part_dup->num, part->geom.start, part_dup->geom.start, \
					 part->geom.end, part_dup->geom.end);
		compar(1);
		compar(5);
		compar(6);

        ped_disk_destroy (disk);
        ped_device_destroy (dev);
}
//END_TEST

int
main (void)
{
	system("dd < /dev/zero > testpart bs=1024 seek=20000 count=1");
	START_TEST();
#if 0
        int number_failed;
        Suite* suite = suite_create ("Disk");
        TCase* tcase_duplicate = tcase_create ("Duplicate");

        /* Fail when an exception is raised */
        ped_exception_set_handler (_test_exception_handler);

        //tcase_add_checked_fixture (tcase_duplicate, create_disk, destroy_disk);
        tcase_add_test (tcase_duplicate, test_duplicate);
        /* Disable timeout for this test */
        tcase_set_timeout (tcase_duplicate, 0);
        suite_add_tcase (suite, tcase_duplicate);

        SRunner* srunner = srunner_create (suite);
        srunner_run_all (srunner, CK_VERBOSE);

        number_failed = srunner_ntests_failed (srunner);
        srunner_free (srunner);

        return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
#endif
}


More information about the Parted-maintainers mailing list