1# Copyright (c) Meta Platforms, Inc. and affiliates. 2# All rights reserved. 3# 4# This source code is licensed under the BSD-style license found in the 5# LICENSE file in the root directory of this source tree. 6 7# pyre-strict 8 9import unittest 10 11from executorch.devtools.bundled_program.core import BundledProgram 12 13from executorch.devtools.bundled_program.serialize import ( 14 deserialize_from_flatbuffer_to_bundled_program, 15 serialize_from_bundled_program_to_flatbuffer, 16) 17from executorch.devtools.bundled_program.util.test_util import ( 18 get_common_executorch_program, 19) 20 21 22class TestSerialize(unittest.TestCase): 23 def test_bundled_program_serialization(self) -> None: 24 executorch_program, method_test_suites = get_common_executorch_program() 25 26 bundled_program = BundledProgram(executorch_program, method_test_suites) 27 flat_buffer_bundled_program = serialize_from_bundled_program_to_flatbuffer( 28 bundled_program 29 ) 30 regenerate_bundled_program_in_schema = ( 31 deserialize_from_flatbuffer_to_bundled_program(flat_buffer_bundled_program) 32 ) 33 self.assertEqual( 34 bundled_program.serialize_to_schema(), 35 regenerate_bundled_program_in_schema, 36 "Regenerated bundled program mismatches original one", 37 ) 38