Add support for zerofree command.
[libguestfs.git] / tests.c
diff --git a/tests.c b/tests.c
index 000dbac..11a1568 100644 (file)
--- a/tests.c
+++ b/tests.c
@@ -118,6 +118,97 @@ static void no_test_warnings (void)
   fprintf (stderr, "warning: \"guestfs_get_e2uuid\" has no tests\n");
 }
 
+static int test_zerofree_0 (void)
+{
+  /* TestOutput for zerofree (0) */
+  char expected[] = "test file";
+  {
+    char device[] = "/dev/sda";
+    device[5] = devchar;
+    char lines_0[] = ",";
+    char *lines[] = {
+      lines_0,
+      NULL
+    };
+    int r;
+    suppress_error = 0;
+    r = guestfs_sfdisk (g, device, 0, 0, 0, lines);
+    if (r == -1)
+      return -1;
+  }
+  {
+    char fstype[] = "ext3";
+    char device[] = "/dev/sda1";
+    device[5] = devchar;
+    int r;
+    suppress_error = 0;
+    r = guestfs_mkfs (g, fstype, device);
+    if (r == -1)
+      return -1;
+  }
+  {
+    char device[] = "/dev/sda1";
+    device[5] = devchar;
+    char mountpoint[] = "/";
+    int r;
+    suppress_error = 0;
+    r = guestfs_mount (g, device, mountpoint);
+    if (r == -1)
+      return -1;
+  }
+  {
+    char path[] = "/new";
+    char content[] = "test file";
+    int r;
+    suppress_error = 0;
+    r = guestfs_write_file (g, path, content, 0);
+    if (r == -1)
+      return -1;
+  }
+  {
+    char pathordevice[] = "/dev/sda1";
+    pathordevice[5] = devchar;
+    int r;
+    suppress_error = 0;
+    r = guestfs_umount (g, pathordevice);
+    if (r == -1)
+      return -1;
+  }
+  {
+    char device[] = "/dev/sda1";
+    device[5] = devchar;
+    int r;
+    suppress_error = 0;
+    r = guestfs_zerofree (g, device);
+    if (r == -1)
+      return -1;
+  }
+  {
+    char device[] = "/dev/sda1";
+    device[5] = devchar;
+    char mountpoint[] = "/";
+    int r;
+    suppress_error = 0;
+    r = guestfs_mount (g, device, mountpoint);
+    if (r == -1)
+      return -1;
+  }
+  {
+    char path[] = "/new";
+    char *r;
+    suppress_error = 0;
+    r = guestfs_cat (g, path);
+    if (r == NULL)
+      return -1;
+    if (strcmp (r, expected) != 0) {
+      fprintf (stderr, "test_zerofree_0: expected \"%s\" but got \"%s\"\n", expected, r);
+      return -1;
+    }
+    free (r);
+  }
+  return 0;
+}
+
 static int test_hexdump_0 (void)
 {
   /* InitBasicFS for hexdump (0): create ext2 on /dev/sda1 */
@@ -298,7 +389,7 @@ static int test_strings_e_0 (void)
 
 static int test_strings_e_1 (void)
 {
-  printf ("%s skipped (test disabled in generator)\n", "test_strings_e_1");
+  printf ("%s skipped (reason: test disabled in generator)\n", "test_strings_e_1");
   return 0;
 }
 
@@ -4981,8 +5072,15 @@ static int test_stat_0 (void)
   return 0;
 }
 
+static int test_command_lines_0_prereq (void)
+{
+  const char *str = getenv ("SKIP_TEST_COMMAND");
+  return str && strcmp (str, "1") == 0;
+}
+
 static int test_command_lines_0 (void)
 {
+  if (! test_command_lines_0_prereq ()) {
   /* InitBasicFS for command_lines (0): create ext2 on /dev/sda1 */
   {
     char device[] = "/dev/sda";
@@ -5093,11 +5191,20 @@ static int test_command_lines_0 (void)
       free (r[i]);
     free (r);
   }
+  } else
+    printf ("%s skipped (reason: test prerequisite)\n", "test_command_lines_0");
   return 0;
 }
 
+static int test_command_lines_1_prereq (void)
+{
+  const char *str = getenv ("SKIP_TEST_COMMAND");
+  return str && strcmp (str, "1") == 0;
+}
+
 static int test_command_lines_1 (void)
 {
+  if (! test_command_lines_1_prereq ()) {
   /* InitBasicFS for command_lines (1): create ext2 on /dev/sda1 */
   {
     char device[] = "/dev/sda";
@@ -5208,11 +5315,20 @@ static int test_command_lines_1 (void)
       free (r[i]);
     free (r);
   }
+  } else
+    printf ("%s skipped (reason: test prerequisite)\n", "test_command_lines_1");
   return 0;
 }
 
+static int test_command_lines_2_prereq (void)
+{
+  const char *str = getenv ("SKIP_TEST_COMMAND");
+  return str && strcmp (str, "1") == 0;
+}
+
 static int test_command_lines_2 (void)
 {
+  if (! test_command_lines_2_prereq ()) {
   /* InitBasicFS for command_lines (2): create ext2 on /dev/sda1 */
   {
     char device[] = "/dev/sda";
@@ -5335,11 +5451,20 @@ static int test_command_lines_2 (void)
       free (r[i]);
     free (r);
   }
+  } else
+    printf ("%s skipped (reason: test prerequisite)\n", "test_command_lines_2");
   return 0;
 }
 
+static int test_command_lines_3_prereq (void)
+{
+  const char *str = getenv ("SKIP_TEST_COMMAND");
+  return str && strcmp (str, "1") == 0;
+}
+
 static int test_command_lines_3 (void)
 {
+  if (! test_command_lines_3_prereq ()) {
   /* InitBasicFS for command_lines (3): create ext2 on /dev/sda1 */
   {
     char device[] = "/dev/sda";
@@ -5462,11 +5587,20 @@ static int test_command_lines_3 (void)
       free (r[i]);
     free (r);
   }
+  } else
+    printf ("%s skipped (reason: test prerequisite)\n", "test_command_lines_3");
   return 0;
 }
 
+static int test_command_lines_4_prereq (void)
+{
+  const char *str = getenv ("SKIP_TEST_COMMAND");
+  return str && strcmp (str, "1") == 0;
+}
+
 static int test_command_lines_4 (void)
 {
+  if (! test_command_lines_4_prereq ()) {
   /* InitBasicFS for command_lines (4): create ext2 on /dev/sda1 */
   {
     char device[] = "/dev/sda";
@@ -5601,11 +5735,20 @@ static int test_command_lines_4 (void)
       free (r[i]);
     free (r);
   }
+  } else
+    printf ("%s skipped (reason: test prerequisite)\n", "test_command_lines_4");
   return 0;
 }
 
+static int test_command_lines_5_prereq (void)
+{
+  const char *str = getenv ("SKIP_TEST_COMMAND");
+  return str && strcmp (str, "1") == 0;
+}
+
 static int test_command_lines_5 (void)
 {
+  if (! test_command_lines_5_prereq ()) {
   /* InitBasicFS for command_lines (5): create ext2 on /dev/sda1 */
   {
     char device[] = "/dev/sda";
@@ -5752,11 +5895,20 @@ static int test_command_lines_5 (void)
       free (r[i]);
     free (r);
   }
+  } else
+    printf ("%s skipped (reason: test prerequisite)\n", "test_command_lines_5");
   return 0;
 }
 
+static int test_command_lines_6_prereq (void)
+{
+  const char *str = getenv ("SKIP_TEST_COMMAND");
+  return str && strcmp (str, "1") == 0;
+}
+
 static int test_command_lines_6 (void)
 {
+  if (! test_command_lines_6_prereq ()) {
   /* InitBasicFS for command_lines (6): create ext2 on /dev/sda1 */
   {
     char device[] = "/dev/sda";
@@ -5855,11 +6007,20 @@ static int test_command_lines_6 (void)
       free (r[i]);
     free (r);
   }
+  } else
+    printf ("%s skipped (reason: test prerequisite)\n", "test_command_lines_6");
   return 0;
 }
 
+static int test_command_lines_7_prereq (void)
+{
+  const char *str = getenv ("SKIP_TEST_COMMAND");
+  return str && strcmp (str, "1") == 0;
+}
+
 static int test_command_lines_7 (void)
 {
+  if (! test_command_lines_7_prereq ()) {
   /* InitBasicFS for command_lines (7): create ext2 on /dev/sda1 */
   {
     char device[] = "/dev/sda";
@@ -5970,11 +6131,20 @@ static int test_command_lines_7 (void)
       free (r[i]);
     free (r);
   }
+  } else
+    printf ("%s skipped (reason: test prerequisite)\n", "test_command_lines_7");
   return 0;
 }
 
+static int test_command_lines_8_prereq (void)
+{
+  const char *str = getenv ("SKIP_TEST_COMMAND");
+  return str && strcmp (str, "1") == 0;
+}
+
 static int test_command_lines_8 (void)
 {
+  if (! test_command_lines_8_prereq ()) {
   /* InitBasicFS for command_lines (8): create ext2 on /dev/sda1 */
   {
     char device[] = "/dev/sda";
@@ -6097,11 +6267,20 @@ static int test_command_lines_8 (void)
       free (r[i]);
     free (r);
   }
+  } else
+    printf ("%s skipped (reason: test prerequisite)\n", "test_command_lines_8");
   return 0;
 }
 
+static int test_command_lines_9_prereq (void)
+{
+  const char *str = getenv ("SKIP_TEST_COMMAND");
+  return str && strcmp (str, "1") == 0;
+}
+
 static int test_command_lines_9 (void)
 {
+  if (! test_command_lines_9_prereq ()) {
   /* InitBasicFS for command_lines (9): create ext2 on /dev/sda1 */
   {
     char device[] = "/dev/sda";
@@ -6224,11 +6403,20 @@ static int test_command_lines_9 (void)
       free (r[i]);
     free (r);
   }
+  } else
+    printf ("%s skipped (reason: test prerequisite)\n", "test_command_lines_9");
   return 0;
 }
 
+static int test_command_lines_10_prereq (void)
+{
+  const char *str = getenv ("SKIP_TEST_COMMAND");
+  return str && strcmp (str, "1") == 0;
+}
+
 static int test_command_lines_10 (void)
 {
+  if (! test_command_lines_10_prereq ()) {
   /* InitBasicFS for command_lines (10): create ext2 on /dev/sda1 */
   {
     char device[] = "/dev/sda";
@@ -6351,11 +6539,20 @@ static int test_command_lines_10 (void)
       free (r[i]);
     free (r);
   }
+  } else
+    printf ("%s skipped (reason: test prerequisite)\n", "test_command_lines_10");
   return 0;
 }
 
+static int test_command_0_prereq (void)
+{
+  const char *str = getenv ("SKIP_TEST_COMMAND");
+  return str && strcmp (str, "1") == 0;
+}
+
 static int test_command_0 (void)
 {
+  if (! test_command_0_prereq ()) {
   /* InitBasicFS for command (0): create ext2 on /dev/sda1 */
   {
     char device[] = "/dev/sda";
@@ -6451,11 +6648,20 @@ static int test_command_0 (void)
     }
     free (r);
   }
+  } else
+    printf ("%s skipped (reason: test prerequisite)\n", "test_command_0");
   return 0;
 }
 
+static int test_command_1_prereq (void)
+{
+  const char *str = getenv ("SKIP_TEST_COMMAND");
+  return str && strcmp (str, "1") == 0;
+}
+
 static int test_command_1 (void)
 {
+  if (! test_command_1_prereq ()) {
   /* InitBasicFS for command (1): create ext2 on /dev/sda1 */
   {
     char device[] = "/dev/sda";
@@ -6551,11 +6757,20 @@ static int test_command_1 (void)
     }
     free (r);
   }
+  } else
+    printf ("%s skipped (reason: test prerequisite)\n", "test_command_1");
   return 0;
 }
 
+static int test_command_2_prereq (void)
+{
+  const char *str = getenv ("SKIP_TEST_COMMAND");
+  return str && strcmp (str, "1") == 0;
+}
+
 static int test_command_2 (void)
 {
+  if (! test_command_2_prereq ()) {
   /* InitBasicFS for command (2): create ext2 on /dev/sda1 */
   {
     char device[] = "/dev/sda";
@@ -6651,11 +6866,20 @@ static int test_command_2 (void)
     }
     free (r);
   }
+  } else
+    printf ("%s skipped (reason: test prerequisite)\n", "test_command_2");
   return 0;
 }
 
+static int test_command_3_prereq (void)
+{
+  const char *str = getenv ("SKIP_TEST_COMMAND");
+  return str && strcmp (str, "1") == 0;
+}
+
 static int test_command_3 (void)
 {
+  if (! test_command_3_prereq ()) {
   /* InitBasicFS for command (3): create ext2 on /dev/sda1 */
   {
     char device[] = "/dev/sda";
@@ -6751,11 +6975,20 @@ static int test_command_3 (void)
     }
     free (r);
   }
+  } else
+    printf ("%s skipped (reason: test prerequisite)\n", "test_command_3");
   return 0;
 }
 
+static int test_command_4_prereq (void)
+{
+  const char *str = getenv ("SKIP_TEST_COMMAND");
+  return str && strcmp (str, "1") == 0;
+}
+
 static int test_command_4 (void)
 {
+  if (! test_command_4_prereq ()) {
   /* InitBasicFS for command (4): create ext2 on /dev/sda1 */
   {
     char device[] = "/dev/sda";
@@ -6851,11 +7084,20 @@ static int test_command_4 (void)
     }
     free (r);
   }
+  } else
+    printf ("%s skipped (reason: test prerequisite)\n", "test_command_4");
   return 0;
 }
 
+static int test_command_5_prereq (void)
+{
+  const char *str = getenv ("SKIP_TEST_COMMAND");
+  return str && strcmp (str, "1") == 0;
+}
+
 static int test_command_5 (void)
 {
+  if (! test_command_5_prereq ()) {
   /* InitBasicFS for command (5): create ext2 on /dev/sda1 */
   {
     char device[] = "/dev/sda";
@@ -6951,11 +7193,20 @@ static int test_command_5 (void)
     }
     free (r);
   }
+  } else
+    printf ("%s skipped (reason: test prerequisite)\n", "test_command_5");
   return 0;
 }
 
+static int test_command_6_prereq (void)
+{
+  const char *str = getenv ("SKIP_TEST_COMMAND");
+  return str && strcmp (str, "1") == 0;
+}
+
 static int test_command_6 (void)
 {
+  if (! test_command_6_prereq ()) {
   /* InitBasicFS for command (6): create ext2 on /dev/sda1 */
   {
     char device[] = "/dev/sda";
@@ -7051,11 +7302,20 @@ static int test_command_6 (void)
     }
     free (r);
   }
+  } else
+    printf ("%s skipped (reason: test prerequisite)\n", "test_command_6");
   return 0;
 }
 
+static int test_command_7_prereq (void)
+{
+  const char *str = getenv ("SKIP_TEST_COMMAND");
+  return str && strcmp (str, "1") == 0;
+}
+
 static int test_command_7 (void)
 {
+  if (! test_command_7_prereq ()) {
   /* InitBasicFS for command (7): create ext2 on /dev/sda1 */
   {
     char device[] = "/dev/sda";
@@ -7151,11 +7411,20 @@ static int test_command_7 (void)
     }
     free (r);
   }
+  } else
+    printf ("%s skipped (reason: test prerequisite)\n", "test_command_7");
   return 0;
 }
 
+static int test_command_8_prereq (void)
+{
+  const char *str = getenv ("SKIP_TEST_COMMAND");
+  return str && strcmp (str, "1") == 0;
+}
+
 static int test_command_8 (void)
 {
+  if (! test_command_8_prereq ()) {
   /* InitBasicFS for command (8): create ext2 on /dev/sda1 */
   {
     char device[] = "/dev/sda";
@@ -7251,11 +7520,20 @@ static int test_command_8 (void)
     }
     free (r);
   }
+  } else
+    printf ("%s skipped (reason: test prerequisite)\n", "test_command_8");
   return 0;
 }
 
+static int test_command_9_prereq (void)
+{
+  const char *str = getenv ("SKIP_TEST_COMMAND");
+  return str && strcmp (str, "1") == 0;
+}
+
 static int test_command_9 (void)
 {
+  if (! test_command_9_prereq ()) {
   /* InitBasicFS for command (9): create ext2 on /dev/sda1 */
   {
     char device[] = "/dev/sda";
@@ -7351,11 +7629,20 @@ static int test_command_9 (void)
     }
     free (r);
   }
+  } else
+    printf ("%s skipped (reason: test prerequisite)\n", "test_command_9");
   return 0;
 }
 
+static int test_command_10_prereq (void)
+{
+  const char *str = getenv ("SKIP_TEST_COMMAND");
+  return str && strcmp (str, "1") == 0;
+}
+
 static int test_command_10 (void)
 {
+  if (! test_command_10_prereq ()) {
   /* InitBasicFS for command (10): create ext2 on /dev/sda1 */
   {
     char device[] = "/dev/sda";
@@ -7451,11 +7738,20 @@ static int test_command_10 (void)
     }
     free (r);
   }
+  } else
+    printf ("%s skipped (reason: test prerequisite)\n", "test_command_10");
   return 0;
 }
 
+static int test_command_11_prereq (void)
+{
+  const char *str = getenv ("SKIP_TEST_COMMAND");
+  return str && strcmp (str, "1") == 0;
+}
+
 static int test_command_11 (void)
 {
+  if (! test_command_11_prereq ()) {
   /* InitBasicFS for command (11): create ext2 on /dev/sda1 */
   {
     char device[] = "/dev/sda";
@@ -7544,6 +7840,8 @@ static int test_command_11 (void)
       return -1;
     free (r);
   }
+  } else
+    printf ("%s skipped (reason: test prerequisite)\n", "test_command_11");
   return 0;
 }
 
@@ -12818,9 +13116,15 @@ int main (int argc, char *argv[])
     free (devs[i]);
   free (devs);
 
-  nr_tests = 135;
+  nr_tests = 136;
 
   test_num++;
+  printf ("%3d/%3d test_zerofree_0\n", test_num, nr_tests);
+  if (test_zerofree_0 () == -1) {
+    printf ("test_zerofree_0 FAILED\n");
+    failed++;
+  }
+  test_num++;
   printf ("%3d/%3d test_hexdump_0\n", test_num, nr_tests);
   if (test_hexdump_0 () == -1) {
     printf ("test_hexdump_0 FAILED\n");