[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [Libguestfs] [PATCH V4] NEW API:ext:mke2fs



On Wed, Sep 19, 2012 at 04:54:28PM +0800, Wanlong Gao wrote:
> > +  { defaults with
> > +    name = "mke2fs";
> > +    style = RErr, [Device "device"], [OInt64 "blockscount"; OInt64 "blocksize"; OInt64 "fragsize"; OInt64 "blockspergroup"; OInt64 "numberofgroups"; OInt64 "bytesperinode"; OInt64 "inodesize"; OInt64 "journalsize"; OInt64 "numberofinodes"; OInt64 "stridesize"; OInt64 "stripewidth"; OInt64 "maxonlineresize"; OInt "reservedblockspercentage"; OInt "mmpupdateinterval"; OString "journaldevice"; OString "label"; OString "lastmounteddir"; OString "creatoros"; OString "fstype"; OString "usagetype"; OString "uuid"; OBool "forcecreate"; OBool "writesbandgrouponly"; OBool "lazyitableinit"; OBool "lazyjournalinit"; OBool "testfs"; OBool "discard"; OBool "quotatype";  OBool "extent"; OBool "filetype"; OBool "flexbg"; OBool "hasjournal"; OBool "journaldev"; OBool "largefile"; OBool "quota"; OBool "resizeinode"; OBool "sparsesuper"; OBool "uninitbg"];
> > +    proc_nr = Some 368;
> > +    tests = [
> > +      InitEmpty, Always, TestOutput (
> > +        [["part_init"; "/dev/sda"; "mbr"];
> > +         ["part_add"; "/dev/sda"; "p"; "64"; "204799"];
> > +         ["part_add"; "/dev/sda"; "p"; "204800"; "-64"];
> > +         ["mke2fs"; "/dev/sda1"; ""; "4096"; ""; ""; "";
> > +            ""; ""; ""; ""; "";
> > +            ""; ""; ""; ""; "NOARG";
> > +            "NOARG"; "NOARG"; "NOARG"; "NOARG"; "NOARG";
> > +            "NOARG"; "true"; ""; ""; "";
> > +            ""; ""; ""; ""; "";
> > +            ""; ""; "true"; ""; "";
> > +            ""; ""; ""];
> > +         ["mke2fs"; "/dev/sda2"; ""; "4096"; ""; ""; "";
> > +            ""; ""; ""; ""; "";
> > +            ""; ""; ""; ""; "/dev/sda1";
> > +            "NOARG"; "NOARG"; "NOARG"; "ext2"; "NOARG";
> > +            "NOARG"; "true"; ""; ""; "";
> > +            ""; ""; ""; ""; "";
> > +            ""; ""; ""; ""; "";
> > +            ""; ""; ""];
> > +         ["mount"; "/dev/sda2"; "/"];
> > +         ["write"; "/new"; "new file contents"];
> > +         ["cat"; "/new"]], "new file contents");
> > +      InitEmpty, Always, TestOutput (
> > +        [["part_init"; "/dev/sda"; "mbr"];
> > +         ["part_add"; "/dev/sda"; "p"; "64"; "204799"];
> > +         ["part_add"; "/dev/sda"; "p"; "204800"; "-64"];
> > +         ["mke2fs"; "/dev/sda1"; ""; "4096"; ""; ""; "";
> > +            ""; ""; ""; ""; "";
> > +            ""; ""; ""; ""; "/dev/sda1";
> > +            "JOURNAL"; "NOARG"; "NOARG"; "ext2"; "NOARG";
> > +            "NOARG"; "true"; ""; ""; "";
> > +            ""; ""; ""; ""; "";
> > +            ""; ""; "true"; ""; "";
> > +            ""; ""; ""];
> > +         ["mke2fs"; "/dev/sda2"; ""; "4096"; ""; ""; "";
> > +            ""; ""; ""; ""; "";
> > +            ""; ""; ""; ""; "LABEL=JOURNAL";
> > +            "JOURNAL"; "NOARG"; "NOARG"; "ext2"; "NOARG";
> > +            "NOARG"; "true"; ""; ""; "";
> > +            ""; ""; ""; ""; "";
> > +            ""; ""; ""; ""; "";
> > +            ""; ""; ""];
> > +         ["mount"; "/dev/sda2"; "/"];
> > +         ["write"; "/new"; "new file contents"];
> > +         ["cat"; "/new"]], "new file contents");
> > +        InitEmpty, Always, TestOutput (
> > +          [["part_init"; "/dev/sda"; "mbr"];
> > +           ["part_add"; "/dev/sda"; "p"; "64"; "204799"];
> > +           ["part_add"; "/dev/sda"; "p"; "204800"; "-64"];
> > +           ["mke2fs"; "/dev/sda1"; ""; "4096"; ""; ""; "";
> > +              ""; ""; ""; ""; "";
> > +              ""; ""; ""; ""; "NOARG";
> > +              "NOARG"; "NOARG"; "NOARG"; "NOARG"; "NOARG";
> > +(* there is something wrong with uuid *)
> 
> Can you teach me how to test the "uuid" here?

Probably the best thing is to look at the tests for set_e2uuid:

    tests =
      (let uuid = uuidgen () in [
        InitBasicFS, Always, TestOutput (
          [["set_e2uuid"; "/dev/sda1"; uuid];
           ["get_e2uuid"; "/dev/sda1"]], uuid);

'tests = (let uuid = uuidgen () in [...])' causes a fresh uuid to be
generated (by 'uuidgen ()') and returned in 'uuid', and then
substituted in the list of tests.  In this case, 'uuid' is used as a
parameter to 'set_e2uuid', and to test the return value from
'get_e2uuid'.

Note that the random UUID changes each time the generator runs.

The actual C code generated by the above test (ie. in
tests/c-api/tests.c) is below.  In this case, the value of the 'uuid'
variable in the OCaml code was "d62333[..]".

  /* TestOutput for set_e2uuid (0) */
  const char *expected = "d623335b-b2c7-461c-46a8-05a4f2af7bee";
  {
    const char *device = "/dev/sda1";
    const char *uuid = "d623335b-b2c7-461c-46a8-05a4f2af7bee";
    int r;
    suppress_error = 0;
    r = guestfs_set_e2uuid (g, device, uuid);
    if (r == -1)
      return -1;
  }
  {
    const char *device = "/dev/sda1";
    char *r;
    suppress_error = 0;
    r = guestfs_get_e2uuid (g, device);
    if (r == NULL)
      return -1;
    if (STRNEQ (r, expected)) {
      fprintf (stderr, "test_set_e2uuid_0: expected \"%s\" but got \"%s\"\n", expected, r);
      return -1;
    }
    free (r);
  }

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
libguestfs lets you edit virtual machines.  Supports shell scripting,
bindings from many languages.  http://libguestfs.org


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]