All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kevin Wolf <kwolf@redhat.com>
To: qemu-block@nongnu.org
Cc: kwolf@redhat.com, qemu-devel@nongnu.org, armbru@redhat.com,
	marcandre.lureau@redhat.com, pbonzini@redhat.com
Subject: [PATCH 5/6] tests/qapi-schema: Flat representation of simple unions
Date: Fri, 23 Oct 2020 12:12:21 +0200	[thread overview]
Message-ID: <20201023101222.250147-6-kwolf@redhat.com> (raw)
In-Reply-To: <20201023101222.250147-1-kwolf@redhat.com>

This adds some test cases related to flat representation of simple
unions and the 'allow-flat' option for union branches.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 tests/qapi-schema/flat-union-allow-flat.err        |  2 ++
 tests/qapi-schema/flat-union-allow-flat.json       | 10 ++++++++++
 tests/qapi-schema/flat-union-allow-flat.out        |  0
 tests/qapi-schema/meson.build                      |  4 ++++
 tests/qapi-schema/qapi-schema-test.json            | 10 ++++++++++
 tests/qapi-schema/qapi-schema-test.out             | 14 ++++++++++++++
 tests/qapi-schema/union-allow-flat-bad.err         |  2 ++
 tests/qapi-schema/union-allow-flat-bad.json        |  5 +++++
 tests/qapi-schema/union-allow-flat-bad.out         |  0
 .../qapi-schema/union-allow-flat-builtin-type.err  |  2 ++
 .../qapi-schema/union-allow-flat-builtin-type.json |  5 +++++
 .../qapi-schema/union-allow-flat-builtin-type.out  |  0
 tests/qapi-schema/union-clash-member.err           |  2 ++
 tests/qapi-schema/union-clash-member.json          |  6 ++++++
 tests/qapi-schema/union-clash-member.out           |  0
 15 files changed, 62 insertions(+)
 create mode 100644 tests/qapi-schema/flat-union-allow-flat.err
 create mode 100644 tests/qapi-schema/flat-union-allow-flat.json
 create mode 100644 tests/qapi-schema/flat-union-allow-flat.out
 create mode 100644 tests/qapi-schema/union-allow-flat-bad.err
 create mode 100644 tests/qapi-schema/union-allow-flat-bad.json
 create mode 100644 tests/qapi-schema/union-allow-flat-bad.out
 create mode 100644 tests/qapi-schema/union-allow-flat-builtin-type.err
 create mode 100644 tests/qapi-schema/union-allow-flat-builtin-type.json
 create mode 100644 tests/qapi-schema/union-allow-flat-builtin-type.out
 create mode 100644 tests/qapi-schema/union-clash-member.err
 create mode 100644 tests/qapi-schema/union-clash-member.json
 create mode 100644 tests/qapi-schema/union-clash-member.out

diff --git a/tests/qapi-schema/flat-union-allow-flat.err b/tests/qapi-schema/flat-union-allow-flat.err
new file mode 100644
index 0000000000..f3f3d2384b
--- /dev/null
+++ b/tests/qapi-schema/flat-union-allow-flat.err
@@ -0,0 +1,2 @@
+flat-union-allow-flat.json: In union 'MyUnion':
+flat-union-allow-flat.json:6: 'allow-flat' requires simple union
diff --git a/tests/qapi-schema/flat-union-allow-flat.json b/tests/qapi-schema/flat-union-allow-flat.json
new file mode 100644
index 0000000000..114acaad86
--- /dev/null
+++ b/tests/qapi-schema/flat-union-allow-flat.json
@@ -0,0 +1,10 @@
+# Flat unions must not use allow-flat
+{ 'enum': 'Enum', 'data': [ 'one', 'two' ] }
+{ 'struct': 'Base',
+  'data': { 'switch': 'Enum' } }
+{ 'struct': 'Branch', 'data': { 'name': 'str' } }
+{ 'union': 'MyUnion',
+  'base': 'Base',
+  'discriminator': 'switch',
+  'data': { 'one': { 'type': 'Branch', 'allow-flat': true },
+            'two': 'Branch' } }
diff --git a/tests/qapi-schema/flat-union-allow-flat.out b/tests/qapi-schema/flat-union-allow-flat.out
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/tests/qapi-schema/meson.build b/tests/qapi-schema/meson.build
index 304ef939bd..4973a9b57a 100644
--- a/tests/qapi-schema/meson.build
+++ b/tests/qapi-schema/meson.build
@@ -103,6 +103,7 @@ schemas = [
   'features-name-bad-type.json',
   'features-no-list.json',
   'features-unknown-key.json',
+  'flat-union-allow-flat.json',
   'flat-union-array-branch.json',
   'flat-union-bad-base.json',
   'flat-union-bad-discriminator.json',
@@ -184,12 +185,15 @@ schemas = [
   'unclosed-list.json',
   'unclosed-object.json',
   'unclosed-string.json',
+  'union-allow-flat-bad.json',
+  'union-allow-flat-builtin-type.json',
   'union-base-empty.json',
   'union-base-no-discriminator.json',
   'union-branch-case.json',
   'union-branch-if-invalid.json',
   'union-branch-invalid-dict.json',
   'union-clash-branches.json',
+  'union-clash-member.json',
   'union-empty.json',
   'union-invalid-base.json',
   'union-optional-branch.json',
diff --git a/tests/qapi-schema/qapi-schema-test.json b/tests/qapi-schema/qapi-schema-test.json
index 63f92adf68..1c29576ae9 100644
--- a/tests/qapi-schema/qapi-schema-test.json
+++ b/tests/qapi-schema/qapi-schema-test.json
@@ -110,6 +110,16 @@
 { 'struct': 'UserDefC',
   'data': { 'string1': 'str', 'string2': 'str' } }
 
+{ 'struct': 'UserDefD',
+  'data': { 'type': 'str' } }
+
+{ 'union': 'UserDefSimpleUnion',
+  'data': { 'value1' : {'type': 'UserDefA'},
+            'value2' : 'UserDefB',
+            'value3' : 'UserDefB',
+            'value4' : { 'type': 'UserDefD', 'allow-flat': false }
+  } }
+
 # for testing use of 'number' within alternates
 { 'alternate': 'AltEnumBool', 'data': { 'e': 'EnumOne', 'b': 'bool' } }
 { 'alternate': 'AltEnumNum', 'data': { 'e': 'EnumOne', 'n': 'number' } }
diff --git a/tests/qapi-schema/qapi-schema-test.out b/tests/qapi-schema/qapi-schema-test.out
index a4e4051c61..7521e86e9f 100644
--- a/tests/qapi-schema/qapi-schema-test.out
+++ b/tests/qapi-schema/qapi-schema-test.out
@@ -105,6 +105,20 @@ alternate UserDefAlternate
 object UserDefC
     member string1: str optional=False
     member string2: str optional=False
+object UserDefD
+    member type: str optional=False
+enum UserDefSimpleUnionKind
+    member value1
+    member value2
+    member value3
+    member value4
+object UserDefSimpleUnion
+    member type: UserDefSimpleUnionKind optional=False
+    tag type
+    case value1: UserDefA
+    case value2: UserDefB
+    case value3: UserDefB
+    case value4: UserDefD
 alternate AltEnumBool
     tag type
     case e: EnumOne
diff --git a/tests/qapi-schema/union-allow-flat-bad.err b/tests/qapi-schema/union-allow-flat-bad.err
new file mode 100644
index 0000000000..561fd338e1
--- /dev/null
+++ b/tests/qapi-schema/union-allow-flat-bad.err
@@ -0,0 +1,2 @@
+union-allow-flat-bad.json: In union 'MyUnion':
+union-allow-flat-bad.json:3: 'allow-flat' must be a boolean
diff --git a/tests/qapi-schema/union-allow-flat-bad.json b/tests/qapi-schema/union-allow-flat-bad.json
new file mode 100644
index 0000000000..6e02e8312b
--- /dev/null
+++ b/tests/qapi-schema/union-allow-flat-bad.json
@@ -0,0 +1,5 @@
+# allow-flat must be a boolean
+{ 'struct': 'Branch', 'data': { 'name': 'str' } }
+{ 'union': 'MyUnion',
+  'data': { 'one': { 'type': 'Branch', 'allow-flat': 'maybe' },
+            'two': 'Branch' } }
diff --git a/tests/qapi-schema/union-allow-flat-bad.out b/tests/qapi-schema/union-allow-flat-bad.out
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/tests/qapi-schema/union-allow-flat-builtin-type.err b/tests/qapi-schema/union-allow-flat-builtin-type.err
new file mode 100644
index 0000000000..4163d2426e
--- /dev/null
+++ b/tests/qapi-schema/union-allow-flat-builtin-type.err
@@ -0,0 +1,2 @@
+union-allow-flat-builtin-type.json: In union 'MyUnion':
+union-allow-flat-builtin-type.json:3: branch 'one' cannot use built-in type 'int'
diff --git a/tests/qapi-schema/union-allow-flat-builtin-type.json b/tests/qapi-schema/union-allow-flat-builtin-type.json
new file mode 100644
index 0000000000..21eb25c48a
--- /dev/null
+++ b/tests/qapi-schema/union-allow-flat-builtin-type.json
@@ -0,0 +1,5 @@
+# Can't use built-in types for branches with 'allow-flat': true
+{ 'struct': 'Branch', 'data': { 'name': 'str' } }
+{ 'union': 'MyUnion',
+  'data': { 'one': { 'type': 'int', 'allow-flat': true },
+            'two': 'Branch' } }
diff --git a/tests/qapi-schema/union-allow-flat-builtin-type.out b/tests/qapi-schema/union-allow-flat-builtin-type.out
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/tests/qapi-schema/union-clash-member.err b/tests/qapi-schema/union-clash-member.err
new file mode 100644
index 0000000000..7fe51b0285
--- /dev/null
+++ b/tests/qapi-schema/union-clash-member.err
@@ -0,0 +1,2 @@
+union-clash-member.json: In union 'MyUnion':
+union-clash-member.json:4: member 'type' of type 'Branch' collides with member 'type'
diff --git a/tests/qapi-schema/union-clash-member.json b/tests/qapi-schema/union-clash-member.json
new file mode 100644
index 0000000000..cb09cd7d89
--- /dev/null
+++ b/tests/qapi-schema/union-clash-member.json
@@ -0,0 +1,6 @@
+# 'type' is in the implicit base type and clashes with a 'type' member
+# in branches if flat representation is not disabled
+{ 'struct': 'Branch', 'data': { 'type': 'str' } }
+{ 'union': 'MyUnion',
+  'data': { 'one': 'Branch',
+            'two': 'Branch' } }
diff --git a/tests/qapi-schema/union-clash-member.out b/tests/qapi-schema/union-clash-member.out
new file mode 100644
index 0000000000..e69de29bb2
-- 
2.28.0



  parent reply	other threads:[~2020-10-23 10:18 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-23 10:12 [PATCH 0/6] qemu-storage-daemon: QAPIfy --chardev Kevin Wolf
2020-10-23 10:12 ` [PATCH 1/6] char/stdio: Fix QMP default for 'signal' Kevin Wolf
2020-10-23 10:38   ` Marc-André Lureau
2020-10-23 12:12   ` Markus Armbruster
2020-10-23 10:12 ` [PATCH 2/6] char: Factor out qemu_chr_print_types() Kevin Wolf
2020-10-23 10:38   ` Marc-André Lureau
2020-10-23 12:15     ` Markus Armbruster
2020-10-23 10:12 ` [PATCH 3/6] qapi: Remove wrapper struct for simple unions Kevin Wolf
2020-10-23 10:40   ` Marc-André Lureau
2020-10-23 11:06     ` Marc-André Lureau
2020-10-23 12:28       ` Kevin Wolf
2020-10-23 12:49     ` Markus Armbruster
2020-10-23 14:06       ` Kevin Wolf
2020-10-23 10:12 ` [PATCH 4/6] qapi: Optionally parse simple unions as flat Kevin Wolf
2020-10-23 10:12 ` Kevin Wolf [this message]
2020-10-23 10:12 ` [PATCH 6/6] qemu-storage-daemon: Use qmp_chardev_add() for --chardev Kevin Wolf
2020-10-26 13:33   ` Markus Armbruster
2020-10-23 10:36 ` [PATCH 0/6] qemu-storage-daemon: QAPIfy --chardev Daniel P. Berrangé
2020-10-23 11:05   ` Paolo Bonzini
2020-10-23 11:56   ` Kevin Wolf
2020-10-23 13:40   ` Markus Armbruster
2020-10-23 16:08     ` Paolo Bonzini
2020-10-25 17:42       ` Markus Armbruster

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201023101222.250147-6-kwolf@redhat.com \
    --to=kwolf@redhat.com \
    --cc=armbru@redhat.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.