From f4af35cec5be4d0e4fe0d6888d35c4ea179d44f9 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Tue, 15 Jul 2008 12:51:25 +0200 Subject: [PATCH] fix >512-byte sector label/disk-test failure * libparted/tests/disk.c: Include xstrtol.h. (get_sector_size): New function: get sector size from the environment. (create_disk): Use the new function to calculate a usable size, rather than hard-coding the 512-byte-sector-specific size of 20MB. * libparted/tests/common.c (_create_disk): Change meaning (and name) of parameter to be size in bytes, not MiB. Adjust callers. * po/POTFILES.in: Add lib/xstrtol-error.c. --- libparted/tests/common.c | 6 ++---- libparted/tests/disk.c | 17 ++++++++++++++++- libparted/tests/label.c | 2 +- po/POTFILES.in | 2 +- 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/libparted/tests/common.c b/libparted/tests/common.c index f759745..b892ee3 100644 --- a/libparted/tests/common.c +++ b/libparted/tests/common.c @@ -19,7 +19,7 @@ _test_exception_handler (PedException* e) } char* -_create_disk (const off_t size) +_create_disk (const off_t n_bytes) { char* filename = strdup ("parted-test-XXXXXX"); @@ -37,9 +37,7 @@ _create_disk (const off_t size) if (disk == NULL) goto free_filename; - off_t total_size = size * 1024 * 1024; /* Mb */ - - int fail = (fseek (disk, total_size, SEEK_SET) != 0 + int fail = (fseek (disk, n_bytes, SEEK_SET) != 0 || fwrite ("", sizeof (char), 1, disk) != 1); if (fclose (disk) != 0 || fail) diff --git a/libparted/tests/disk.c b/libparted/tests/disk.c index 6e6d483..48561b9 100644 --- a/libparted/tests/disk.c +++ b/libparted/tests/disk.c @@ -7,13 +7,28 @@ #include "common.h" #include "progname.h" +#include "xstrtol.h" static char* temporary_disk; +static +size_t get_sector_size (void) +{ + char *p = getenv ("PARTED_SECTOR_SIZE"); + size_t ss = 512; + unsigned long val; + if (p + && xstrtoul (p, NULL, 10, &val, NULL) == LONGINT_OK + && val % 512 == 0) + ss = val; + + return ss; +} + static void create_disk (void) { - temporary_disk = _create_disk (20); + temporary_disk = _create_disk (get_sector_size () * 4 * 10 * 1024); fail_if (temporary_disk == NULL, "Failed to create temporary disk"); } diff --git a/libparted/tests/label.c b/libparted/tests/label.c index fb61e2e..a1991e4 100644 --- a/libparted/tests/label.c +++ b/libparted/tests/label.c @@ -15,7 +15,7 @@ static char* temporary_disk; static void create_disk (void) { - temporary_disk = _create_disk (20); + temporary_disk = _create_disk (20 * 1024 * 1024); fail_if (temporary_disk == NULL, "Failed to create temporary disk"); } diff --git a/po/POTFILES.in b/po/POTFILES.in index 8b2a9e2..33f4979 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -1,5 +1,5 @@ # libparted -# Copyright (C) 1999-2001, 2006-2007, 2009 Free Software Foundation, Inc. +# Copyright (C) 1999-2001, 2006-2009 Free Software Foundation, Inc. # This file may be modified and/or copied without restriction. # list of files containing translatable strings -- 2.11.0