1. 09 11月, 2015 2 次提交
    • E
      qapi: Share test_init code in test-qmp-input* · 0920a171
      Eric Blake 提交于
      Rather than duplicate the body of two functions just to
      decide between qobject_from_jsonv() and qobject_from_json(),
      exploit the fact that qobject_from_jsonv() intentionally
      takes 'va_list *' instead of the more common 'va_list', and
      that qobject_from_json() just calls qobject_from_jsonv(,NULL).
      For each file, our two existing init functions then become
      thin wrappers around a new internal function, and future
      updates to initialization don't have to be duplicated.
      Suggested-by: NMarkus Armbruster <armbru@redhat.com>
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Message-Id: <1446791754-23823-5-git-send-email-eblake@redhat.com>
      [Two old comment typos fixed]
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      0920a171
    • E
      qapi: Use generated TestStruct machinery in tests · 748053c9
      Eric Blake 提交于
      Commit d88f5fd1 and friends first introduced the various test-qmp-*
      tests in 2011, with duplicated hand-rolled TestStruct machinery,
      to make sure the qapi visitor interface was tested.  Later, commit
      4f193e34 in 2013 added a .json file for further testing use by the
      files, but without consolidating any of the existing hand-rolled
      visitors.  And with four copies, subtle differences have crept in,
      between the tests themselves (mainly whitespace differences, but
      also a question of whether to use NULL or "TestStruct" when
      calling visit_start_struct()) and from what the generator produces
      (the hand-rolled versions did not cater to partially-allocated
      objects, because they did not have a deallocation usage).
      
      Of course, just because the visitor interface is tested does not
      mean it is a sane interface; and future patches will be changing
      some of the visitor contracts.  Rather than having to duplicate
      the cleanup work in each copy of the TestStruct visitor, and keep
      each hand-rolled copy in sync with what the generator supplies, we
      might as well just test what the generator should give us in the
      first place.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Message-Id: <1446791754-23823-2-git-send-email-eblake@redhat.com>
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      748053c9
  2. 21 9月, 2015 2 次提交
    • M
      qapi: New QMP command query-qmp-schema for QMP introspection · 39a18158
      Markus Armbruster 提交于
      qapi/introspect.json defines the introspection schema.  It's designed
      for QMP introspection, but should do for similar uses, such as QGA.
      
      The introspection schema does not reflect all the rules and
      restrictions that apply to QAPI schemata.  A valid QAPI schema has an
      introspection value conforming to the introspection schema, but the
      converse is not true.
      
      Introspection lowers away a number of schema details, and makes
      implicit things explicit:
      
      * The built-in types are declared with their JSON type.
      
        All integer types are mapped to 'int', because how many bits we use
        internally is an implementation detail.  It could be pressed into
        external interface service as very approximate range information,
        but that's a bad idea.  If we need range information, we better do
        it properly.
      
      * Implicit type definitions are made explicit, and given
        auto-generated names:
      
        - Array types, named by appending "List" to the name of their
          element type, like in generated C.
      
        - The enumeration types implicitly defined by simple union types,
          named by appending "Kind" to the name of their simple union type,
          like in generated C.
      
        - Types that don't occur in generated C.  Their names start with ':'
          so they don't clash with the user's names.
      
      * All type references are by name.
      
      * The struct and union types are generalized into an object type.
      
      * Base types are flattened.
      
      * Commands take a single argument and return a single result.
      
        Dictionary argument or list result is an implicit type definition.
      
        The empty object type is used when a command takes no arguments or
        produces no results.
      
        The argument is always of object type, but the introspection schema
        doesn't reflect that.
      
        The 'gen': false directive is omitted as implementation detail.
      
        The 'success-response' directive is omitted as well for now, even
        though it's not an implementation detail, because it's not used by
        QMP.
      
      * Events carry a single data value.
      
        Implicit type definition and empty object type use, just like for
        commands.
      
        The value is of object type, but the introspection schema doesn't
        reflect that.
      
      * Types not used by commands or events are omitted.
      
        Indirect use counts as use.
      
      * Optional members have a default, which can only be null right now
      
        Instead of a mandatory "optional" flag, we have an optional default.
        No default means mandatory, default null means optional without
        default value.  Non-null is available for optional with default
        (possible future extension).
      
      * Clients should *not* look up types by name, because type names are
        not ABI.  Look up the command or event you're interested in, then
        follow the references.
      
        TODO Should we hide the type names to eliminate the temptation?
      
      New generator scripts/qapi-introspect.py computes an introspection
      value for its input, and generates a C variable holding it.
      
      It can generate awfully long lines.  Marked TODO.
      
      A new test-qmp-input-visitor test case feeds its result for both
      tests/qapi-schema/qapi-schema-test.json and qapi-schema.json to a
      QmpInputVisitor to verify it actually conforms to the schema.
      
      New QMP command query-qmp-schema takes its return value from that
      variable.  Its reply is some 85KiBytes for me right now.
      
      If this turns out to be too much, we have a couple of options:
      
      * We can use shorter names in the JSON.  Not the QMP style.
      
      * Optionally return the sub-schema for commands and events given as
        arguments.
      
        Right now qmp_query_schema() sends the string literal computed by
        qmp-introspect.py.  To compute sub-schema at run time, we'd have to
        duplicate parts of qapi-introspect.py in C.  Unattractive.
      
      * Let clients cache the output of query-qmp-schema.
      
        It changes only on QEMU upgrades, i.e. rarely.  Provide a command
        query-qmp-schema-hash.  Clients can have a cache indexed by hash,
        and re-query the schema only when they don't have it cached.  Even
        simpler: put the hash in the QMP greeting.
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: NEric Blake <eblake@redhat.com>
      39a18158
    • M
      qapi-visit: Convert to QAPISchemaVisitor, fixing bugs · 441cbac0
      Markus Armbruster 提交于
      Fixes flat unions to visit the base's base members (the previous
      commit merely added them to the struct).  Same test case.
      
      Patch's effect on visit_type_UserDefFlatUnion():
      
           static void visit_type_UserDefFlatUnion_fields(Visitor *m, UserDefFlatUnion **obj, Error **errp)
           {
               Error *err = NULL;
      
          +    visit_type_int(m, &(*obj)->integer, "integer", &err);
          +    if (err) {
          +        goto out;
          +    }
               visit_type_str(m, &(*obj)->string, "string", &err);
               if (err) {
                   goto out;
      
      Test cases updated for the bug fix.
      
      Fixes alternates to generate a visitor for their implicit enumeration
      type.  None of them are currently used, obviously.  Example:
      block-core.json's BlockdevRef now generates
      visit_type_BlockdevRefKind().
      
      Code is generated in a different order now, and therefore has got a
      few new forward declarations.  Doesn't matter.
      
      The guard QAPI_VISIT_BUILTIN_VISITOR_DECL is renamed to
      QAPI_VISIT_BUILTIN.
      
      The previous commit's two ugly special cases exist here, too.  Mark
      both TODO.
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: NDaniel P. Berrange <berrange@redhat.com>
      Reviewed-by: NEric Blake <eblake@redhat.com>
      441cbac0
  3. 06 5月, 2015 3 次提交
  4. 27 9月, 2014 1 次提交
  5. 16 5月, 2014 2 次提交
    • M
      qapi: Replace uncommon use of the error API by the common one · 297a3646
      Markus Armbruster 提交于
      We commonly use the error API like this:
      
          err = NULL;
          foo(..., &err);
          if (err) {
              goto out;
          }
          bar(..., &err);
      
      Every error source is checked separately.  The second function is only
      called when the first one succeeds.  Both functions are free to pass
      their argument to error_set().  Because error_set() asserts no error
      has been set, this effectively means they must not be called with an
      error set.
      
      The qapi-generated code uses the error API differently:
      
          // *errp was initialized to NULL somewhere up the call chain
          frob(..., errp);
          gnat(..., errp);
      
      Errors accumulate in *errp: first error wins, subsequent errors get
      dropped.  To make this work, the second function does nothing when
      called with an error set.  Requires non-null errp, or else the second
      function can't see the first one fail.
      
      This usage has also bled into visitor tests, and two device model
      object property getters rtc_get_date() and balloon_stats_get_all().
      
      With the "accumulate" technique, you need fewer error checks in
      callers, and buy that with an error check in every callee.  Can be
      nice.
      
      However, mixing the two techniques is confusing.  You can't use the
      "accumulate" technique with functions designed for the "check
      separately" technique.  You can use the "check separately" technique
      with functions designed for the "accumulate" technique, but then
      error_set() can't catch you setting an error more than once.
      
      Standardize on the "check separately" technique for now, because it's
      overwhelmingly prevalent.
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: NEric Blake <eblake@redhat.com>
      Signed-off-by: NLuiz Capitulino <lcapitulino@redhat.com>
      297a3646
    • M
      tests: Don't call visit_end_struct() after visit_start_struct() fails · cdaec380
      Markus Armbruster 提交于
      When visit_start_struct() fails, visit_end_struct() must not be
      called.  Three out of four visit_type_TestStruct() call it anyway.  As
      far as I can tell, visit_start_struct() doesn't actually fail there.
      Fix them anyway.
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: NEric Blake <eblake@redhat.com>
      Signed-off-by: NLuiz Capitulino <lcapitulino@redhat.com>
      cdaec380
  6. 09 5月, 2014 1 次提交
  7. 26 4月, 2014 1 次提交
  8. 11 3月, 2014 1 次提交
  9. 04 3月, 2014 3 次提交
  10. 18 2月, 2014 1 次提交
  11. 19 12月, 2012 2 次提交
  12. 30 3月, 2012 1 次提交
  13. 27 3月, 2012 1 次提交