From 82ba73535c0966e8ae8fb50db1ea23534d827717 Mon Sep 17 00:00:00 2001 From: Paul Elder Date: Tue, 8 Sep 2020 20:47:19 +0900 Subject: utils: ipc: import mojo MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Import mojo from the Chromium repository, so that we can use it for generating code for the IPC mechanism. The commit from which this was taken is: a079161ec8c6907b883f9cb84fc8c4e7896cb1d0 "Add PPAPI constructs for sending focus object to PdfAccessibilityTree" This tree has been pruned to remove directories that didn't have any necessary code: - mojo/* except for mojo/public - mojo core, docs, and misc files - mojo/public/* except for mojo/public/{tools,LICENSE} - language bindings for IPC, tests, and some mojo internals - mojo/public/tools/{fuzzers,chrome_ipc} - mojo/public/tools/bindings/generators - code generation for other languages No files were modified. Signed-off-by: Paul Elder Acked-by: Laurent Pinchart Acked-by: Niklas Söderlund Acked-by: Kieran Bingham --- .../public/tools/mojom/mojom_parser_unittest.py | 171 +++++++++++++++++++++ 1 file changed, 171 insertions(+) create mode 100644 utils/ipc/mojo/public/tools/mojom/mojom_parser_unittest.py (limited to 'utils/ipc/mojo/public/tools/mojom/mojom_parser_unittest.py') diff --git a/utils/ipc/mojo/public/tools/mojom/mojom_parser_unittest.py b/utils/ipc/mojo/public/tools/mojom/mojom_parser_unittest.py new file mode 100644 index 00000000..a93f34ba --- /dev/null +++ b/utils/ipc/mojo/public/tools/mojom/mojom_parser_unittest.py @@ -0,0 +1,171 @@ +# Copyright 2020 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +from mojom_parser_test_case import MojomParserTestCase + + +class MojomParserTest(MojomParserTestCase): + """Tests covering the behavior defined by the main mojom_parser.py script. + This includes behavior around input and output path manipulation, dependency + resolution, and module serialization and deserialization.""" + + def testBasicParse(self): + """Basic test to verify that we can parse a mojom file and get a module.""" + mojom = 'foo/bar.mojom' + self.WriteFile( + mojom, """\ + module test; + enum TestEnum { kFoo }; + """) + self.ParseMojoms([mojom]) + + m = self.LoadModule(mojom) + self.assertEqual('foo/bar.mojom', m.path) + self.assertEqual('test', m.mojom_namespace) + self.assertEqual(1, len(m.enums)) + + def testBasicParseWithAbsolutePaths(self): + """Verifies that we can parse a mojom file given an absolute path input.""" + mojom = 'foo/bar.mojom' + self.WriteFile( + mojom, """\ + module test; + enum TestEnum { kFoo }; + """) + self.ParseMojoms([self.GetPath(mojom)]) + + m = self.LoadModule(mojom) + self.assertEqual('foo/bar.mojom', m.path) + self.assertEqual('test', m.mojom_namespace) + self.assertEqual(1, len(m.enums)) + + def testImport(self): + """Verify imports within the same set of mojom inputs.""" + a = 'a.mojom' + b = 'b.mojom' + self.WriteFile( + a, """\ + module a; + import "b.mojom"; + struct Foo { b.Bar bar; };""") + self.WriteFile(b, """\ + module b; + struct Bar {};""") + self.ParseMojoms([a, b]) + + ma = self.LoadModule(a) + mb = self.LoadModule(b) + self.assertEqual('a.mojom', ma.path) + self.assertEqual('b.mojom', mb.path) + self.assertEqual(1, len(ma.imports)) + self.assertEqual(mb, ma.imports[0]) + + def testPreProcessedImport(self): + """Verify imports processed by a previous parser execution can be loaded + properly when parsing a dependent mojom.""" + a = 'a.mojom' + self.WriteFile(a, """\ + module a; + struct Bar {};""") + self.ParseMojoms([a]) + + b = 'b.mojom' + self.WriteFile( + b, """\ + module b; + import "a.mojom"; + struct Foo { a.Bar bar; };""") + self.ParseMojoms([b]) + + def testMissingImport(self): + """Verify that an import fails if the imported mojom does not exist.""" + a = 'a.mojom' + self.WriteFile( + a, """\ + module a; + import "non-existent.mojom"; + struct Bar {};""") + with self.assertRaisesRegexp(ValueError, "does not exist"): + self.ParseMojoms([a]) + + def testUnparsedImport(self): + """Verify that an import fails if the imported mojom is not in the set of + mojoms provided to the parser on this execution AND there is no pre-existing + parsed output module already on disk for it.""" + a = 'a.mojom' + b = 'b.mojom' + self.WriteFile(a, """\ + module a; + struct Bar {};""") + self.WriteFile( + b, """\ + module b; + import "a.mojom"; + struct Foo { a.Bar bar; };""") + + # a.mojom has not been parsed yet, so its import will fail when processing + # b.mojom here. + with self.assertRaisesRegexp(ValueError, "does not exist"): + self.ParseMojoms([b]) + + def testCheckImportsBasic(self): + """Verify that the parser can handle --check-imports with a valid set of + inputs, including support for transitive dependency resolution.""" + a = 'a.mojom' + a_metadata = 'out/a.build_metadata' + b = 'b.mojom' + b_metadata = 'out/b.build_metadata' + c = 'c.mojom' + c_metadata = 'out/c.build_metadata' + self.WriteFile(a_metadata, + '{"sources": ["%s"], "deps": []}\n' % self.GetPath(a)) + self.WriteFile( + b_metadata, + '{"sources": ["%s"], "deps": ["%s"]}\n' % (self.GetPath(b), + self.GetPath(a_metadata))) + self.WriteFile( + c_metadata, + '{"sources": ["%s"], "deps": ["%s"]}\n' % (self.GetPath(c), + self.GetPath(b_metadata))) + self.WriteFile(a, """\ + module a; + struct Bar {};""") + self.WriteFile( + b, """\ + module b; + import "a.mojom"; + struct Foo { a.Bar bar; };""") + self.WriteFile( + c, """\ + module c; + import "a.mojom"; + import "b.mojom"; + struct Baz { b.Foo foo; };""") + self.ParseMojoms([a], metadata=a_metadata) + self.ParseMojoms([b], metadata=b_metadata) + self.ParseMojoms([c], metadata=c_metadata) + + def testCheckImportsMissing(self): + """Verify that the parser rejects valid input mojoms when imports don't + agree with build metadata given via --check-imports.""" + a = 'a.mojom' + a_metadata = 'out/a.build_metadata' + b = 'b.mojom' + b_metadata = 'out/b.build_metadata' + self.WriteFile(a_metadata, + '{"sources": ["%s"], "deps": []}\n' % self.GetPath(a)) + self.WriteFile(b_metadata, + '{"sources": ["%s"], "deps": []}\n' % self.GetPath(b)) + self.WriteFile(a, """\ + module a; + struct Bar {};""") + self.WriteFile( + b, """\ + module b; + import "a.mojom"; + struct Foo { a.Bar bar; };""") + + self.ParseMojoms([a], metadata=a_metadata) + with self.assertRaisesRegexp(ValueError, "not allowed by build"): + self.ParseMojoms([b], metadata=b_metadata) -- cgit v1.2.1