1. 06 5月, 2015 23 次提交
    • E
      qapi: Add some type check tests · 0d8b9fb5
      Eric Blake 提交于
      Demonstrate that the qapi generator silently parses confusing
      types, which may cause other errors later on. Later patches
      will update the expected results as the generator is made stricter.
      
      Most of the new tests focus on blatant errors.  But
      returns-whitelist is a case where we have historically allowed
      returning something other than a JSON object from particular
      commands; we have to keep that behavior to avoid breaking clients,
      but it would be nicer to avoid adding such commands in the future,
      because any return that is not an (array of) object cannot be
      easily extended if future qemu wants to return additional
      information.  The QMP protocol already documents that clients
      should ignore unknown dictionary keys, but does not require
      clients to have to handle more than one type of JSON object.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Reviewed-by: NMarkus Armbruster <armbru@redhat.com>
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      0d8b9fb5
    • E
      qapi: Unify type bypass and add tests · d708cdbe
      Eric Blake 提交于
      For a few QMP commands, we are forced to pass an arbitrary type
      without tracking it properly in QAPI.  Among the existing clients,
      this unnamed type was spelled 'dict', 'visitor', and '**'; this
      patch standardizes on '**', matching the documentation changes
      earlier in the series.
      
      Meanwhile, for the 'gen' key, we have been ignoring the value,
      although the schema consistently used "'no'" ('success-response'
      was hard-coded to checking for 'no').  But now that we can support
      a literal "false" in the schema, we might as well use that rather
      than ignoring the value or special-casing a random string.  Note
      that these are one-way switches (use of 'gen':true is not the same
      as omitting 'gen'). Also, the use of '**' requires 'gen':false,
      but the use of 'gen':false does not mandate the use of '**'.
      
      There is no difference to the generated code.  Add some tests on
      what we'd like to guarantee, although it will take later patches
      to clean up test results and actually enforce the use of a bool
      parameter.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Reviewed-by: NMarkus Armbruster <armbru@redhat.com>
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      d708cdbe
    • F
      qapi: Allow true, false and null in schema json · e53188ad
      Fam Zheng 提交于
      In the near term, we will use it for a sensible-looking
      'gen':false inside command declarations, instead of the
      current ugly 'gen':'no'.
      
      In the long term, it will allow conversion from shorthand
      with defaults mentioned only in side-band documentation:
       'data':{'*flag':'bool', '*string':'str'}
      into an explicit default value documentation, as in:
       'data':{'flag':{'type':'bool', 'optional':true, 'default':true},
               'string':{'type':'str', 'optional':true, 'default':null}}
      
      We still don't parse integer values (also necessary before
      we can allow explicit defaults), but that can come in a later
      series.
      
      Update the testsuite to match an improved error message.
      Signed-off-by: NFam Zheng <famz@redhat.com>
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Reviewed-by: NMarkus Armbruster <armbru@redhat.com>
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      e53188ad
    • E
      qapi: Better error messages for duplicated expressions · 4dc2e690
      Eric Blake 提交于
      The previous commit demonstrated that the generator overlooked
      duplicate expressions:
      - a complex type or command reusing a built-in type name
      - redeclaration of a type name, whether by the same or different
      metatype
      - redeclaration of a command or event
      - collision of a type with implicit 'Kind' enum for a union
      - collision with an implicit MAX enum constant
      
      Since the c_type() function in the generator treats all names
      as being in the same namespace, this patch adds a global array
      to track all known names and their source, to prevent collisions
      before it can cause further problems.  While valid .json files
      won't trigger any of these cases, we might as well be nicer to
      developers that make a typo while trying to add new QAPI code.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Reviewed-by: NMarkus Armbruster <armbru@redhat.com>
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      4dc2e690
    • E
      qapi: Add tests of redefined expressions · cfdd5bca
      Eric Blake 提交于
      Demonstrate that the qapi generator doesn't deal very well with
      redefined expressions.  At the parse level, they are silently
      accepted; and while the testsuite just stops at parsing, I've
      further tested that many of them cause generator crashes or
      invalid C code if they were appended to qapi-schema-test.json.
      A later patch will tighten things up and adjust the testsuite
      to match.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Reviewed-by: NMarkus Armbruster <armbru@redhat.com>
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      cfdd5bca
    • E
      qapi: Better error messages for bad expressions · 0545f6b8
      Eric Blake 提交于
      The previous commit demonstrated that the generator overlooked some
      fairly basic broken expressions:
      - missing metataype
      - metatype key has a non-string value
      - unknown key in relation to the metatype
      - conflicting metatype (this patch treats the second metatype as an
      unknown key of the first key visited, which is not necessarily the
      first key the user typed)
      
      Add check_keys to cover these situations, and update testcases to
      match.  A couple other tests (enum-missing-data, indented-expr) had
      to change since the validation added here occurs so early.
      Conversely, changes to ident-with-escape results show that we still
      have problems where our handling of escape sequences differs from
      true JSON, which will matter down the road if we allow arbitrary
      default string values for optional parameters (but for now is not
      too bad, as we currently can avoid unicode escaping as we don't
      need to represent anything beyond C identifier material).
      
      While valid .json files won't trigger any of these cases, we might
      as well be nicer to developers that make a typo while trying to add
      new QAPI code.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Reviewed-by: NMarkus Armbruster <armbru@redhat.com>
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      0545f6b8
    • E
      qapi: Add some expr tests · 9050c65b
      Eric Blake 提交于
      Demonstrate that the qapi generator doesn't deal well with
      expressions that aren't up to par. Later patches will improve
      the expected results as the generator is made stricter.  Only
      a few of the the added tests actually behave sanely at
      rejecting obvious problems or demonstrating success.
      
      Note that in some cases, we reject bad QAPI merely because our
      pseudo-JSON parser does not yet know how to parse numbers.  This
      series does not address that, but when a later series adds support
      for numeric defaults of integer fields, the testsuite will ensure
      that we don't lose the error (and hopefully that the error
      message quality is improved).
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Reviewed-by: NMarkus Armbruster <armbru@redhat.com>
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      9050c65b
    • E
      qapi: Use 'alternate' to replace anonymous union · ab916fad
      Eric Blake 提交于
      Previous patches have led up to the point where I create the
      new meta-type "'alternate':'Foo'".  See the previous patches
      for documentation; I intentionally split as much work into
      earlier patches to minimize the size of this patch, but a lot
      of it is churn due to testsuite fallout after updating to the
      new type.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Reviewed-by: NMarkus Armbruster <armbru@redhat.com>
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      ab916fad
    • E
      qapi: Document new 'alternate' meta-type · 7b1b98c4
      Eric Blake 提交于
      The next patch will quit special-casing "'union':'Foo',
      'discriminator':{}" and instead use "'alternate':'Foo'".
      
      Separating docs from implementation makes it easier to focus
      on wording without holding up code.  In particular, making
      alternate a separate type makes for a nice type hierarchy:
      
                /-------- meta-type ------\
               /              |            \
          simple types    alternate     complex types
          |         |                   |           |
       built-in   enum             type(struct)   union
       |       \    /                            /    \
      numeric  string                         simple  flat
      
      A later patch will then clean up 'type' vs. 'struct'
      confusion.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Reviewed-by: NMarkus Armbruster <armbru@redhat.com>
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      7b1b98c4
    • E
      qapi: Rename anonymous union type in test · ab045267
      Eric Blake 提交于
      Reduce churn in the future patch that replaces anonymous unions
      with a new metatype 'alternate' by changing 'AnonUnion' to
      'Alternate'.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Reviewed-by: NMarkus Armbruster <armbru@redhat.com>
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      ab045267
    • E
      qapi: Segregate anonymous unions into alternates in generator · 811d04fd
      Eric Blake 提交于
      Special-casing 'discriminator == {}' for handling anonymous unions
      is getting awkward; since this particular type is not always a
      dictionary on the wire, it is easier to treat it as a completely
      different class of type, "alternate", so that if a type is listed
      in the union_types array, we know it is not an anonymous union.
      
      This patch just further segregates union handling, to make sure that
      anonymous unions are not stored in union_types, and splitting up
      check_union() into separate functions.  A future patch will change
      the qapi grammar, and having the segregation already in place will
      make it easier to deal with the distinct meta-type.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Reviewed-by: NMarkus Armbruster <armbru@redhat.com>
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      811d04fd
    • E
      qapi: Prepare for catching more semantic parse errors · 268a1c5e
      Eric Blake 提交于
      This patch widens the scope of a try block (with the attending
      reindentation required by Python) in preparation for a future
      patch adding more instances of QAPIExprError inside the block.
      It's easier to separate indentation from semantic changes, so
      this patch has no real behavior change.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Reviewed-by: NMarkus Armbruster <armbru@redhat.com>
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      268a1c5e
    • E
      qapi: Tighten checking of unions · 44bd1276
      Eric Blake 提交于
      Previous commits demonstrated that the generator had several
      flaws with less-than-perfect unions:
      - a simple union that listed the same branch twice (or two variant
      names that map to the same C enumerator, including the implicit
      MAX sentinel) ended up generating invalid C code
      - an anonymous union that listed two branches with the same qtype
      ended up generating invalid C code
      - the generator crashed on anonymous union attempts to use an
      array type
      - the generator was silently ignoring a base type for anonymous
      unions
      - the generator allowed unknown types or nested anonymous unions
      as a branch in an anonymous union
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Reviewed-by: NMarkus Armbruster <armbru@redhat.com>
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      44bd1276
    • E
      qapi: Forbid base without discriminator in unions · a8d4a2e4
      Eric Blake 提交于
      None of the existing QMP or QGA interfaces uses a union with a
      base type but no discriminator; it is easier to avoid this in the
      generator to save room for other future extensions more likely to
      be useful.  An earlier commit added a union-base-no-discriminator
      test to ensure that we eventually give a decent error message;
      likewise, removing UserDefUnion outright is okay, because we moved
      all the tests we wish to keep into the tests of the simple union
      UserDefNativeListUnion in the previous commit.  Now is the time to
      actually forbid simple union with base, and remove the last
      vestiges from the testsuite.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Reviewed-by: NMarkus Armbruster <armbru@redhat.com>
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      a8d4a2e4
    • E
      qapi: Clean up test coverage of simple unions · 805017b7
      Eric Blake 提交于
      The tests of UserDefNativeListUnion serve to validate code
      generation of simple unions without a base type, except that it
      did not have full coverage in the strict test.  The next commits
      will remove tests and support for simple unions with a base type,
      so there is no real loss at repurposing that test here as
      opposed to churn of adding a new test then deleting the old one.
      
      Fix some indentation and long lines while at it.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Reviewed-by: NMarkus Armbruster <armbru@redhat.com>
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      805017b7
    • E
      qapi: Add some union tests · 3d0c4829
      Eric Blake 提交于
      Demonstrate that the qapi generator doesn't deal well with unions
      that aren't up to par. Later patches will update the expected
      reseults as the generator is made stricter.  A few tests work
      as planned, but most show poor or missing error messages.
      
      Of particular note, qapi-code-gen.txt documents 'base' only for
      flat unions, but the tests here demonstrate that we currently allow
      a 'base' to a simple union, although it is exercised only in the
      testsuite.  Later patches will remove this undocumented feature, to
      give us more flexibility in adding other future extensions to union
      types.  For example, one possible extension is the idea of a
      type-safe simple enum, where added fields tie the discriminator to
      a user-defined enum type rather than creating an implicit enum from
      the names in 'data'.  But adding such safety on top of a simple
      enum with a base type could look ambiguous with a flat enum;
      besides, the documentation also mentions how any simple union can
      be represented by an equivalent flat union.  So it will be simpler
      to just outlaw support for something we aren't using.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Reviewed-by: NMarkus Armbruster <armbru@redhat.com>
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      3d0c4829
    • E
      qapi: Better error messages for bad enums · cf393590
      Eric Blake 提交于
      The previous commit demonstrated that the generator had several
      flaws with less-than-perfect enums:
      - an enum that listed the same string twice (or two variant
      strings that map to the same C enumerator) ended up generating
      an invalid C enum
      - because the generator adds a _MAX terminator to each enum,
      the use of an enum member 'max' can also cause this clash
      - if an enum omits 'data', the generator left a python stack
      trace rather than a graceful message
      - an enum that used a non-array 'data' was silently accepted by
      the parser
      - an enum that used non-string members in the 'data' member
      was silently accepted by the parser
      
      Add check_enum to cover these situations, and update testcases
      to match.  While valid .json files won't trigger any of these
      cases, we might as well be nicer to developers that make a typo
      while trying to add new QAPI code.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Reviewed-by: NMarkus Armbruster <armbru@redhat.com>
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      cf393590
    • E
      qapi: Add some enum tests · ad11dbb9
      Eric Blake 提交于
      Demonstrate that the qapi generator doesn't deal well with enums
      that aren't up to par. Later patches will update the expected
      results as the generator is made stricter.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Reviewed-by: NMarkus Armbruster <armbru@redhat.com>
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      ad11dbb9
    • E
      qapi: Require ASCII in schema · fe2a9303
      Eric Blake 提交于
      Python 2 and Python 3 have a wild history of whether strings
      default to ascii or unicode, where Python 3 requires checking
      isinstance(foo, basestr) to cover all strings, but where that
      code is not portable to Python 2.  It's simpler to just state
      that we don't care about Unicode strings, and to just always
      use the simpler isinstance(foo, str) everywhere.
      
      I'm no python expert, so I'm basing it on this conversation:
      https://lists.gnu.org/archive/html/qemu-devel/2014-09/msg05278.htmlSigned-off-by: NEric Blake <eblake@redhat.com>
      Reviewed-by: NMarkus Armbruster <armbru@redhat.com>
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      fe2a9303
    • E
      qapi: Fix generation of 'size' builtin type · cb17f79e
      Eric Blake 提交于
      We were missing the 'size' builtin type (which means that QAPI using
      [ 'size' ] would fail to compile).
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Reviewed-by: NMarkus Armbruster <armbru@redhat.com>
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      cb17f79e
    • E
      qapi: Simplify builtin type handling · b52c4b9c
      Eric Blake 提交于
      There was some redundancy between builtin_types[] and
      builtin_type_qtypes{}.  Merge them into one.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Reviewed-by: NMarkus Armbruster <armbru@redhat.com>
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      b52c4b9c
    • E
      qapi: Document type-safety considerations · e790e666
      Eric Blake 提交于
      Go into more details about the various types of valid expressions
      in a qapi schema, including tweaks to document fixes being done
      later in the current patch series.  Also fix some stale and missing
      documentation in the QMP specification.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Reviewed-by: NMarkus Armbruster <armbru@redhat.com>
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      e790e666
    • E
      qapi: Add copyright declaration on docs · 6fb55451
      Eric Blake 提交于
      While our top-level COPYING with its GPLv2+ license applies to
      any documentation file that omits explicit instructions, these
      days it's better to be a good example of calling out our
      intentions.  Correct use of GPL requires the use of a copyright
      statement, so I'm adding notice to two QAPI documents, by
      attributing these files to the initial authors and major
      contributors.  I used:
      
      $ git blame --line-porcelain $file \
        | sed -n 's/^author //p' | sort | uniq -c | sort -rn
      
      to determine authorship of these two files.  qmp-spec.txt blames
      entirely to Red Hat (easy, since my contribution falls in that
      category); while qapi-code-gen.txt has multiple contributors
      representing multiple entities.  But since it was originally
      supplied by Michael Roth, the notice I added there copies the
      notice he has used in other files.  As there is no intended
      change in license from the implicit one previously present from
      the top level, I have not bothered to CC other contributors;
      if we want to weaken things to something looser (such as LGPL)
      so that there is no question that someone re-implementing the
      spec is not forced to use GPL, that would be a different commit.
      
      CC: Michael Roth <mdroth@linux.vnet.ibm.com>
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Reviewed-by: NMarkus Armbruster <armbru@redhat.com>
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      6fb55451
  2. 05 5月, 2015 9 次提交
  3. 01 5月, 2015 1 次提交
    • P
      Merge remote-tracking branch 'remotes/kevin/tags/for-upstream' into staging · 5bccbb04
      Peter Maydell 提交于
      Block patches
      
      # gpg: Signature made Thu Apr 30 19:51:16 2015 BST using RSA key ID C88F2FD6
      # gpg: Good signature from "Kevin Wolf <kwolf@redhat.com>"
      
      * remotes/kevin/tags/for-upstream:
        Enable NVMe start controller for Windows guest.
        MAINTAINERS: Add qemu-block list where missing
        MAINTAINERS: make block layer core Kevin Wolf's responsibility
        MAINTAINERS: make image fuzzer Stefan Hajnoczi's responsibility
        MAINTAINERS: make block I/O path Stefan Hajnoczi's responsibility
        MAINTAINERS: split out image formats
        MAINTAINERS: make virtio-blk Stefan Hajnoczi's responsibility
      Signed-off-by: NPeter Maydell <peter.maydell@linaro.org>
      5bccbb04
  4. 30 4月, 2015 7 次提交