1test_env = environment() 2test_env.set('PYTHONPATH', meson.project_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-lists.json', 15 'alternate-conflict-string.json', 16 'alternate-conflict-bool-string.json', 17 'alternate-conflict-num-string.json', 18 'alternate-data-invalid.json', 19 'alternate-empty.json', 20 'alternate-invalid-dict.json', 21 'alternate-nested.json', 22 'alternate-unknown.json', 23 'args-alternate.json', 24 'args-any.json', 25 'args-array-empty.json', 26 'args-array-unknown.json', 27 'args-bad-boxed.json', 28 'args-boxed-anon.json', 29 'args-boxed-string.json', 30 'args-int.json', 31 'args-invalid.json', 32 'args-member-array-bad.json', 33 'args-member-case.json', 34 'args-member-unknown.json', 35 'args-union.json', 36 'args-unknown.json', 37 'bad-base.json', 38 'bad-data.json', 39 'bad-ident.json', 40 'bad-if.json', 41 'bad-if-all.json', 42 'bad-if-empty.json', 43 'bad-if-empty-list.json', 44 'bad-if-key.json', 45 'bad-if-keys.json', 46 'bad-if-list.json', 47 'bad-if-not.json', 48 'bad-type-bool.json', 49 'bad-type-dict.json', 50 'bad-type-int.json', 51 'base-cycle-direct.json', 52 'base-cycle-indirect.json', 53 'command-int.json', 54 'comments.json', 55 'doc-bad-alternate-member.json', 56 'doc-bad-boxed-command-arg.json', 57 'doc-bad-command-arg.json', 58 'doc-bad-enum-member.json', 59 'doc-bad-event-arg.json', 60 'doc-bad-feature.json', 61 'doc-bad-indent.json', 62 'doc-bad-section.json', 63 'doc-bad-symbol.json', 64 'doc-bad-union-member.json', 65 'doc-before-include.json', 66 'doc-before-pragma.json', 67 'doc-duplicated-arg.json', 68 'doc-duplicated-return.json', 69 'doc-duplicated-since.json', 70 'doc-empty-arg.json', 71 'doc-empty-section.json', 72 'doc-empty-symbol.json', 73 'doc-good.json', 74 'doc-interleaved-section.json', 75 'doc-invalid-end.json', 76 'doc-invalid-end2.json', 77 'doc-invalid-return.json', 78 'doc-invalid-section.json', 79 'doc-invalid-start.json', 80 'doc-missing-colon.json', 81 'doc-missing-expr.json', 82 'doc-missing-space.json', 83 'doc-missing.json', 84 'doc-no-symbol.json', 85 'doc-undoc-feature.json', 86 'double-type.json', 87 'duplicate-key.json', 88 'empty.json', 89 'enum-bad-member.json', 90 'enum-bad-name.json', 91 'enum-bad-prefix.json', 92 'enum-clash-member.json', 93 'enum-dict-member-unknown.json', 94 'enum-if-invalid.json', 95 'enum-int-member.json', 96 'enum-member-case.json', 97 'enum-missing-data.json', 98 'enum-wrong-data.json', 99 'event-boxed-empty.json', 100 'event-case.json', 101 'event-member-invalid-dict.json', 102 'event-nest-struct.json', 103 'features-bad-type.json', 104 'features-deprecated-type.json', 105 'features-duplicate-name.json', 106 'features-if-invalid.json', 107 'features-missing-name.json', 108 'features-name-bad-type.json', 109 'features-no-list.json', 110 'features-unknown-key.json', 111 'funny-char.json', 112 'funny-word.json', 113 'ident-with-escape.json', 114 'include-before-err.json', 115 'include-cycle.json', 116 'include-extra-junk.json', 117 'include-nested-err.json', 118 'include-no-file.json', 119 'include-non-file.json', 120 'include-repetition.json', 121 'include-self-cycle.json', 122 'include-simple.json', 123 'indented-expr.json', 124 'leading-comma-list.json', 125 'leading-comma-object.json', 126 'missing-array-rsqb.json', 127 'missing-colon.json', 128 'missing-comma-list.json', 129 'missing-comma-object.json', 130 'missing-object-member-element.json', 131 'missing-type.json', 132 'nested-struct-data.json', 133 'nested-struct-data-invalid-dict.json', 134 'non-objects.json', 135 'oob-coroutine.json', 136 'oob-test.json', 137 'allow-preconfig-test.json', 138 'pragma-extra-junk.json', 139 'pragma-non-dict.json', 140 'pragma-unknown.json', 141 'pragma-value-not-bool.json', 142 'pragma-value-not-list-of-str.json', 143 'pragma-value-not-list.json', 144 'qapi-schema-test.json', 145 'quoted-structural-chars.json', 146 'redefined-command.json', 147 'redefined-event.json', 148 'redefined-predefined.json', 149 'redefined-type.json', 150 'reserved-command-q.json', 151 'reserved-enum-q.json', 152 'reserved-member-has.json', 153 'reserved-member-q.json', 154 'reserved-member-u.json', 155 'reserved-member-underscore.json', 156 'reserved-type-list.json', 157 'returns-alternate.json', 158 'returns-array-bad.json', 159 'returns-bad-type.json', 160 'returns-dict.json', 161 'returns-unknown.json', 162 'string-code-point-31.json', 163 'string-code-point-127.json', 164 'struct-base-clash-deep.json', 165 'struct-base-clash.json', 166 'struct-data-invalid.json', 167 'struct-member-if-invalid.json', 168 'struct-member-invalid-dict.json', 169 'struct-member-invalid.json', 170 'struct-member-name-clash.json', 171 'trailing-comma-list.json', 172 'trailing-comma-object.json', 173 'type-bypass-bad-gen.json', 174 'type-case.json', 175 'unclosed-list.json', 176 'unclosed-object.json', 177 'unclosed-string.json', 178 'union-array-branch.json', 179 'union-bad-base.json', 180 'union-bad-discriminator.json', 181 'union-base-any.json', 182 'union-base-empty.json', 183 'union-base-no-discriminator.json', 184 'union-base-union.json', 185 'union-branch-if-invalid.json', 186 'union-branch-invalid-dict.json', 187 'union-clash-member.json', 188 'union-discriminator-bad-name.json', 189 'union-empty.json', 190 'union-inline-invalid-dict.json', 191 'union-int-branch.json', 192 'union-invalid-base.json', 193 'union-invalid-branch-key.json', 194 'union-invalid-data.json', 195 'union-invalid-discriminator.json', 196 'union-invalid-if-discriminator.json', 197 'union-no-base.json', 198 'union-optional-discriminator.json', 199 'union-string-discriminator.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 218custom_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 depfile: 'docs.d', 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.project_source_root() / 'docs', 253 '-D', 'master_doc=doc-good', 254 '-Ddepfile=@DEPFILE@', 255 '-Ddepfile_stamp=doc-good.stamp', 256 meson.current_source_dir(), 257 meson.current_build_dir()]) 258 259 # Fix possible inconsistency in line endings in generated output and 260 # in the golden reference (which could otherwise cause test failures 261 # on Windows hosts). Unfortunately diff --strip-trailing-cr 262 # is GNU-diff only. The odd-looking python is because we must avoid 263 # using an explicit '\' character in the command arguments to 264 # a custom_target(), as Meson will unhelpfully replace it with a '/' 265 # (https://github.com/mesonbuild/meson/issues/1564) 266 remove_cr = [python, '-c', 'import sys;[sys.stdout.write(line.replace(chr(13), "")) for line in sys.stdin]'] 267 qapi_doc_out_nocr = custom_target('QAPI rST doc newline-sanitized', 268 output: ['doc-good.txt.nocr'], 269 input: qapi_doc_out[0], 270 build_by_default: true, 271 command: [remove_cr, '@INPUT@'], 272 capture: true) 273 274 qapi_doc_ref_nocr = custom_target('QAPI rST doc reference newline-sanitized', 275 output: ['doc-good.ref.nocr'], 276 input: files('doc-good.txt'), 277 build_by_default: true, 278 command: [remove_cr, '@INPUT@'], 279 capture: true) 280 281 test('QAPI rST doc', diff, args: ['-u', qapi_doc_ref_nocr[0], qapi_doc_out_nocr[0]], 282 suite: ['qapi-schema', 'qapi-doc']) 283endif 284