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-array-rsqb.json', 138 'missing-colon.json', 139 'missing-comma-list.json', 140 'missing-comma-object.json', 141 'missing-object-member-element.json', 142 'missing-type.json', 143 'nested-struct-data.json', 144 'nested-struct-data-invalid-dict.json', 145 'non-objects.json', 146 'oob-coroutine.json', 147 'oob-test.json', 148 'allow-preconfig-test.json', 149 'pragma-extra-junk.json', 150 'pragma-non-dict.json', 151 'pragma-unknown.json', 152 'pragma-value-not-bool.json', 153 'pragma-value-not-list-of-str.json', 154 'pragma-value-not-list.json', 155 'qapi-schema-test.json', 156 'quoted-structural-chars.json', 157 'redefined-command.json', 158 'redefined-event.json', 159 'redefined-predefined.json', 160 'redefined-type.json', 161 'reserved-command-q.json', 162 'reserved-enum-q.json', 163 'reserved-member-has.json', 164 'reserved-member-q.json', 165 'reserved-member-u.json', 166 'reserved-member-underscore.json', 167 'reserved-type-kind.json', 168 'reserved-type-list.json', 169 'returns-alternate.json', 170 'returns-array-bad.json', 171 'returns-bad-type.json', 172 'returns-dict.json', 173 'returns-unknown.json', 174 'string-code-point-31.json', 175 'string-code-point-127.json', 176 'struct-base-clash-deep.json', 177 'struct-base-clash.json', 178 'struct-data-invalid.json', 179 'struct-member-if-invalid.json', 180 'struct-member-invalid-dict.json', 181 'struct-member-invalid.json', 182 'struct-member-name-clash.json', 183 'trailing-comma-list.json', 184 'trailing-comma-object.json', 185 'type-bypass-bad-gen.json', 186 'type-case.json', 187 'unclosed-list.json', 188 'unclosed-object.json', 189 'unclosed-string.json', 190 'union-base-empty.json', 191 'union-base-no-discriminator.json', 192 'union-branch-case.json', 193 'union-branch-if-invalid.json', 194 'union-branch-invalid-dict.json', 195 'union-clash-branches.json', 196 'union-empty.json', 197 'union-invalid-base.json', 198 'union-invalid-data.json', 199 'union-optional-branch.json', 200 'union-unknown.json', 201 'unknown-escape.json', 202 'unknown-expr-key.json', 203] 204schemas = files(schemas) 205 206# Intentionally missing schema file test -- not passed through files(): 207schemas += [meson.current_source_dir() / 'missing-schema.json'] 208 209# Because people may want to use test-qapi.py from the command line, we 210# are not using the "#! /usr/bin/env python3" trick here. See 211# docs/devel/build-system.rst 212test('QAPI schema regression tests', python, 213 args: files('test-qapi.py') + schemas, 214 env: test_env, suite: ['qapi-schema', 'qapi-frontend']) 215 216diff = find_program('diff') 217 218qapi_doc = custom_target('QAPI doc', 219 output: ['doc-good-qapi-commands.c', 'doc-good-qapi-commands.h', 220 'doc-good-qapi-emit-events.c', 'doc-good-qapi-emit-events.h', 221 'doc-good-qapi-events.c', 'doc-good-qapi-events.h', 222 'doc-good-qapi-init-commands.c', 'doc-good-qapi-init-commands.h', 223 'doc-good-qapi-introspect.c', 'doc-good-qapi-introspect.h', 224 'doc-good-qapi-types.c', 'doc-good-qapi-types.h', 225 'doc-good-qapi-visit.c', 'doc-good-qapi-visit.h' ], 226 input: files('doc-good.json'), 227 command: [ qapi_gen, '-o', meson.current_build_dir(), 228 '-p', 'doc-good-', '@INPUT0@' ], 229 depend_files: qapi_gen_depends) 230 231if build_docs 232 # Test the document-comment document generation code by running a test schema 233 # file through Sphinx's plain-text builder and comparing the result against 234 # a golden reference. This is in theory susceptible to failures if Sphinx 235 # changes its output, but the text output has historically been very stable 236 # (no changes between Sphinx 1.6 and 3.0), so it is a better bet than 237 # texinfo or HTML generation, both of which have had changes. We might 238 # need to add more sophisticated logic here in future for some sort of 239 # fuzzy comparison if future Sphinx versions produce different text, 240 # but for now the simple comparison suffices. 241 qapi_doc_out = custom_target('QAPI rST doc', 242 output: ['doc-good.txt'], 243 input: files('doc-good.json', 'doc-good.rst'), 244 build_by_default: true, 245 depend_files: sphinx_extn_depends, 246 # We use -E to suppress Sphinx's caching, because 247 # we want it to always really run the QAPI doc 248 # generation code. It also means we don't 249 # clutter up the build dir with the cache. 250 command: [SPHINX_ARGS, 251 '-b', 'text', '-E', 252 '-c', meson.source_root() / 'docs', 253 '-D', 'master_doc=doc-good', 254 meson.current_source_dir(), 255 meson.current_build_dir()]) 256 257 # Fix possible inconsistency in line endings in generated output and 258 # in the golden reference (which could otherwise cause test failures 259 # on Windows hosts). Unfortunately diff --strip-trailing-cr 260 # is GNU-diff only. The odd-looking perl is because we must avoid 261 # using an explicit '\' character in the command arguments to 262 # a custom_target(), as Meson will unhelpfully replace it with a '/' 263 # (https://github.com/mesonbuild/meson/issues/1564) 264 qapi_doc_out_nocr = custom_target('QAPI rST doc newline-sanitized', 265 output: ['doc-good.txt.nocr'], 266 input: qapi_doc_out[0], 267 build_by_default: true, 268 command: ['perl', '-pe', '$x = chr 13; s/$x$//', '@INPUT@'], 269 capture: true) 270 271 qapi_doc_ref_nocr = custom_target('QAPI rST doc reference newline-sanitized', 272 output: ['doc-good.ref.nocr'], 273 input: files('doc-good.txt'), 274 build_by_default: true, 275 command: ['perl', '-pe', '$x = chr 13; s/$x$//', '@INPUT@'], 276 capture: true) 277 278 # "full_path()" needed here to work around 279 # https://github.com/mesonbuild/meson/issues/7585 280 test('QAPI rST doc', diff, args: ['-u', qapi_doc_ref_nocr[0].full_path(), 281 qapi_doc_out_nocr[0].full_path()], 282 depends: [qapi_doc_ref_nocr, qapi_doc_out_nocr], 283 suite: ['qapi-schema', 'qapi-doc']) 284endif 285