1test_env = environment() 2test_env.set('PYTHONPATH', meson.source_root() / 'scripts') 3test_env.set('PYTHONIOENCODING', 'utf-8') 4 5schemas = [ 6 'alternate-any.json', 7 'alternate-array.json', 8 'alternate-base.json', 9 'alternate-branch-if-invalid.json', 10 'alternate-clash.json', 11 'alternate-conflict-dict.json', 12 'alternate-conflict-enum-bool.json', 13 'alternate-conflict-enum-int.json', 14 'alternate-conflict-string.json', 15 'alternate-conflict-bool-string.json', 16 'alternate-conflict-num-string.json', 17 'alternate-data-invalid.json', 18 'alternate-empty.json', 19 'alternate-invalid-dict.json', 20 'alternate-nested.json', 21 'alternate-unknown.json', 22 'args-alternate.json', 23 'args-any.json', 24 'args-array-empty.json', 25 'args-array-unknown.json', 26 'args-bad-boxed.json', 27 'args-boxed-anon.json', 28 'args-boxed-string.json', 29 'args-int.json', 30 'args-invalid.json', 31 'args-member-array-bad.json', 32 'args-member-case.json', 33 'args-member-unknown.json', 34 'args-union.json', 35 'args-unknown.json', 36 'bad-base.json', 37 'bad-data.json', 38 'bad-ident.json', 39 'bad-if.json', 40 'bad-if-empty.json', 41 'bad-if-empty-list.json', 42 'bad-if-list.json', 43 'bad-type-bool.json', 44 'bad-type-dict.json', 45 'bad-type-int.json', 46 'base-cycle-direct.json', 47 'base-cycle-indirect.json', 48 'command-int.json', 49 'comments.json', 50 'doc-bad-alternate-member.json', 51 'doc-bad-boxed-command-arg.json', 52 'doc-bad-command-arg.json', 53 'doc-bad-enum-member.json', 54 'doc-bad-event-arg.json', 55 'doc-bad-feature.json', 56 'doc-bad-indent.json', 57 'doc-bad-section.json', 58 'doc-bad-symbol.json', 59 'doc-bad-union-member.json', 60 'doc-before-include.json', 61 'doc-before-pragma.json', 62 'doc-duplicated-arg.json', 63 'doc-duplicated-return.json', 64 'doc-duplicated-since.json', 65 'doc-empty-arg.json', 66 'doc-empty-section.json', 67 'doc-empty-symbol.json', 68 'doc-good.json', 69 'doc-interleaved-section.json', 70 'doc-invalid-end.json', 71 'doc-invalid-end2.json', 72 'doc-invalid-return.json', 73 'doc-invalid-section.json', 74 'doc-invalid-start.json', 75 'doc-missing-colon.json', 76 'doc-missing-expr.json', 77 'doc-missing-space.json', 78 'doc-missing.json', 79 'doc-no-symbol.json', 80 'doc-undoc-feature.json', 81 'double-type.json', 82 'duplicate-key.json', 83 'empty.json', 84 'enum-bad-member.json', 85 'enum-bad-name.json', 86 'enum-bad-prefix.json', 87 'enum-clash-member.json', 88 'enum-dict-member-unknown.json', 89 'enum-if-invalid.json', 90 'enum-int-member.json', 91 'enum-member-case.json', 92 'enum-missing-data.json', 93 'enum-wrong-data.json', 94 'event-boxed-empty.json', 95 'event-case.json', 96 'event-member-invalid-dict.json', 97 'event-nest-struct.json', 98 'features-bad-type.json', 99 'features-deprecated-type.json', 100 'features-duplicate-name.json', 101 'features-if-invalid.json', 102 'features-missing-name.json', 103 'features-name-bad-type.json', 104 'features-no-list.json', 105 'features-unknown-key.json', 106 'flat-union-array-branch.json', 107 'flat-union-bad-base.json', 108 'flat-union-bad-discriminator.json', 109 'flat-union-base-any.json', 110 'flat-union-base-union.json', 111 'flat-union-clash-member.json', 112 'flat-union-discriminator-bad-name.json', 113 'flat-union-empty.json', 114 'flat-union-inline-invalid-dict.json', 115 'flat-union-int-branch.json', 116 'flat-union-invalid-branch-key.json', 117 'flat-union-invalid-discriminator.json', 118 'flat-union-invalid-if-discriminator.json', 119 'flat-union-no-base.json', 120 'flat-union-optional-discriminator.json', 121 'flat-union-string-discriminator.json', 122 'funny-char.json', 123 'funny-word.json', 124 'ident-with-escape.json', 125 'include-before-err.json', 126 'include-cycle.json', 127 'include-extra-junk.json', 128 'include-nested-err.json', 129 'include-no-file.json', 130 'include-non-file.json', 131 'include-repetition.json', 132 'include-self-cycle.json', 133 'include-simple.json', 134 'indented-expr.json', 135 'leading-comma-list.json', 136 'leading-comma-object.json', 137 'missing-colon.json', 138 'missing-comma-list.json', 139 'missing-comma-object.json', 140 'missing-type.json', 141 'nested-struct-data.json', 142 'nested-struct-data-invalid-dict.json', 143 'non-objects.json', 144 'oob-coroutine.json', 145 'oob-test.json', 146 'allow-preconfig-test.json', 147 'pragma-extra-junk.json', 148 'pragma-non-dict.json', 149 'pragma-unknown.json', 150 'pragma-value-not-bool.json', 151 'pragma-value-not-list-of-str.json', 152 'pragma-value-not-list.json', 153 'qapi-schema-test.json', 154 'quoted-structural-chars.json', 155 'redefined-command.json', 156 'redefined-event.json', 157 'redefined-predefined.json', 158 'redefined-type.json', 159 'reserved-command-q.json', 160 'reserved-enum-q.json', 161 'reserved-member-has.json', 162 'reserved-member-q.json', 163 'reserved-member-u.json', 164 'reserved-member-underscore.json', 165 'reserved-type-kind.json', 166 'reserved-type-list.json', 167 'returns-alternate.json', 168 'returns-array-bad.json', 169 'returns-bad-type.json', 170 'returns-dict.json', 171 'returns-unknown.json', 172 'string-code-point-31.json', 173 'string-code-point-127.json', 174 'struct-base-clash-deep.json', 175 'struct-base-clash.json', 176 'struct-data-invalid.json', 177 'struct-member-if-invalid.json', 178 'struct-member-invalid-dict.json', 179 'struct-member-invalid.json', 180 'struct-member-name-clash.json', 181 'trailing-comma-list.json', 182 'trailing-comma-object.json', 183 'type-bypass-bad-gen.json', 184 'type-case.json', 185 'unclosed-list.json', 186 'unclosed-object.json', 187 'unclosed-string.json', 188 'union-base-empty.json', 189 'union-base-no-discriminator.json', 190 'union-branch-case.json', 191 'union-branch-if-invalid.json', 192 'union-branch-invalid-dict.json', 193 'union-clash-branches.json', 194 'union-empty.json', 195 'union-invalid-base.json', 196 'union-invalid-data.json', 197 'union-optional-branch.json', 198 'union-unknown.json', 199 'unknown-escape.json', 200 'unknown-expr-key.json', 201] 202 203# Because people may want to use test-qapi.py from the command line, we 204# are not using the "#! /usr/bin/env python3" trick here. See 205# docs/devel/build-system.txt 206test('QAPI schema regression tests', python, args: files('test-qapi.py', schemas), 207 env: test_env, suite: ['qapi-schema', 'qapi-frontend']) 208 209diff = find_program('diff') 210 211qapi_doc = custom_target('QAPI doc', 212 output: ['doc-good-qapi-commands.c', 'doc-good-qapi-commands.h', 213 'doc-good-qapi-emit-events.c', 'doc-good-qapi-emit-events.h', 214 'doc-good-qapi-events.c', 'doc-good-qapi-events.h', 215 'doc-good-qapi-init-commands.c', 'doc-good-qapi-init-commands.h', 216 'doc-good-qapi-introspect.c', 'doc-good-qapi-introspect.h', 217 'doc-good-qapi-types.c', 'doc-good-qapi-types.h', 218 'doc-good-qapi-visit.c', 'doc-good-qapi-visit.h' ], 219 input: files('doc-good.json'), 220 command: [ qapi_gen, '-o', meson.current_build_dir(), 221 '-p', 'doc-good-', '@INPUT0@' ], 222 depend_files: qapi_gen_depends) 223 224if build_docs 225 # Test the document-comment document generation code by running a test schema 226 # file through Sphinx's plain-text builder and comparing the result against 227 # a golden reference. This is in theory susceptible to failures if Sphinx 228 # changes its output, but the text output has historically been very stable 229 # (no changes between Sphinx 1.6 and 3.0), so it is a better bet than 230 # texinfo or HTML generation, both of which have had changes. We might 231 # need to add more sophisticated logic here in future for some sort of 232 # fuzzy comparison if future Sphinx versions produce different text, 233 # but for now the simple comparison suffices. 234 qapi_doc_out = custom_target('QAPI rST doc', 235 output: ['doc-good.txt'], 236 input: files('doc-good.json', 'doc-good.rst'), 237 build_by_default: true, 238 depend_files: sphinx_extn_depends, 239 # We use -E to suppress Sphinx's caching, because 240 # we want it to always really run the QAPI doc 241 # generation code. It also means we don't 242 # clutter up the build dir with the cache. 243 command: [SPHINX_ARGS, 244 '-b', 'text', '-E', 245 '-c', meson.source_root() / 'docs', 246 '-D', 'master_doc=doc-good', 247 meson.current_source_dir(), 248 meson.current_build_dir()]) 249 250 # Fix possible inconsistency in line endings in generated output and 251 # in the golden reference (which could otherwise cause test failures 252 # on Windows hosts). Unfortunately diff --strip-trailing-cr 253 # is GNU-diff only. The odd-looking perl is because we must avoid 254 # using an explicit '\' character in the command arguments to 255 # a custom_target(), as Meson will unhelpfully replace it with a '/' 256 # (https://github.com/mesonbuild/meson/issues/1564) 257 qapi_doc_out_nocr = custom_target('QAPI rST doc newline-sanitized', 258 output: ['doc-good.txt.nocr'], 259 input: qapi_doc_out[0], 260 build_by_default: true, 261 command: ['perl', '-pe', '$x = chr 13; s/$x$//', '@INPUT@'], 262 capture: true) 263 264 qapi_doc_ref_nocr = custom_target('QAPI rST doc reference newline-sanitized', 265 output: ['doc-good.ref.nocr'], 266 input: files('doc-good.txt'), 267 build_by_default: true, 268 command: ['perl', '-pe', '$x = chr 13; s/$x$//', '@INPUT@'], 269 capture: true) 270 271 # "full_path()" needed here to work around 272 # https://github.com/mesonbuild/meson/issues/7585 273 test('QAPI rST doc', diff, args: ['-u', qapi_doc_ref_nocr[0].full_path(), 274 qapi_doc_out_nocr[0].full_path()], 275 depends: [qapi_doc_ref_nocr, qapi_doc_out_nocr], 276 suite: ['qapi-schema', 'qapi-doc']) 277endif 278