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