[PATCH 5/5] tests: exercise the new interfaces

Jim Meyering meyering at redhat.com
Fri Dec 4 18:36:58 UTC 2009


* tests/print-max.c: New file.
* tests/t9021-maxima.sh: New file.
* tests/Makefile.am (TESTS): Add t9021-maxima.sh.
(check_PROGRAMS): Add print-max.
---
 tests/Makefile.am     |    3 +-
 tests/print-max.c     |   35 +++++++++++++++++++++++++++++++
 tests/t9021-maxima.sh |   54 +++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 91 insertions(+), 1 deletions(-)
 create mode 100644 tests/print-max.c
 create mode 100755 tests/t9021-maxima.sh

diff --git a/tests/Makefile.am b/tests/Makefile.am
index b6d8ca2..7bfb22e 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -31,12 +31,13 @@ TESTS = \
   t8000-loop.sh \
   t9010-big-sector.sh \
   t9020-alignment.sh \
+  t9021-maxima.sh \
   t9030-align-check.sh

 EXTRA_DIST = \
   $(TESTS) test-lib.sh t-lib.sh lvm-utils.sh t-local.sh t-lvm.sh

-check_PROGRAMS = print-align
+check_PROGRAMS = print-align print-max
 LDADD = \
   $(top_builddir)/libparted/libparted.la
 AM_CPPFLAGS = \
diff --git a/tests/print-max.c b/tests/print-max.c
new file mode 100644
index 0000000..7560d49
--- /dev/null
+++ b/tests/print-max.c
@@ -0,0 +1,35 @@
+#include <config.h>
+#include <parted/parted.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "closeout.h"
+#include "progname.h"
+
+int
+main (int argc, char **argv)
+{
+  atexit (close_stdout);
+  set_program_name (argv[0]);
+
+  if (argc != 2)
+    return EXIT_FAILURE;
+
+  char const *dev_name = argv[1];
+  PedDevice *dev = ped_device_get (dev_name);
+  if (dev == NULL)
+    return EXIT_FAILURE;
+  PedDisk *disk = ped_disk_new (dev);
+  if (disk == NULL)
+    return EXIT_FAILURE;
+
+  PedSector max_length = ped_disk_max_partition_length (disk);
+  PedSector max_start_sector = ped_disk_max_partition_start_sector (disk);
+
+  printf ("max len: %llu\n", (unsigned long long) max_length);
+  printf ("max start sector: %llu\n", (unsigned long long) max_start_sector);
+
+  ped_disk_destroy (disk);
+  ped_device_destroy (dev);
+  return EXIT_SUCCESS;
+}
diff --git a/tests/t9021-maxima.sh b/tests/t9021-maxima.sh
new file mode 100755
index 0000000..dbd4d3e
--- /dev/null
+++ b/tests/t9021-maxima.sh
@@ -0,0 +1,54 @@
+#!/bin/sh
+# verify that partition maxima-querying functions work
+
+# Copyright (C) 2009 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/>.
+
+if test "$VERBOSE" = yes; then
+  set -x
+  parted --version
+fi
+
+: ${srcdir=.}
+. $srcdir/t-lib.sh
+
+fail=0
+dev=dev-file
+PATH="..:$PATH"
+export PATH
+
+# FIXME: add aix when/if it's supported again
+for t in msdos gpt dvh sun mac bsd amiga loop pc98; do
+    echo $t
+    rm -f $dev
+    dd if=/dev/zero of=$dev bs=512 count=1 seek=10000 || { fail=1; continue; }
+    parted -s $dev mklabel $t || { fail=1; continue; }
+
+    #case $t in pc98) sleep 999d;; esac
+
+    max_start=4294967295
+    max_len=4294967295
+    case $t in
+	gpt) max_start=18446744073709551615; max_len=$max_start;;
+	sun) max_start=549755813760;; # 128 * (2^32-1)
+    esac
+
+    print-max $dev > out 2>&1 || fail=1
+    printf '%s\n' "max len: $max_len" \
+	"max start sector: $max_start" > exp || fail=1
+    compare out exp || fail=1
+done
+
+Exit $fail
--
1.6.6.rc0.285.g73651



More information about the parted-devel mailing list