Add test for loading JSON dump
- Add a test that compares protobuf and JSON dumps. - Add input-format=Json to header-abi-linker and diff. Bug: 112877706 Test: ./test.py Change-Id: Ic9be304b565a2ac58ed76e1a0fcc96530395b750
This commit is contained in:
@@ -92,19 +92,20 @@ static llvm::cl::opt<bool> consider_opaque_types_different(
|
|||||||
" ABIs"),
|
" ABIs"),
|
||||||
llvm::cl::Optional, llvm::cl::cat(header_checker_category));
|
llvm::cl::Optional, llvm::cl::cat(header_checker_category));
|
||||||
|
|
||||||
|
|
||||||
static llvm::cl::opt<abi_util::TextFormatIR> text_format_old(
|
static llvm::cl::opt<abi_util::TextFormatIR> text_format_old(
|
||||||
"text-format-old", llvm::cl::desc("Specify text format of old abi dump"),
|
"input-format-old", llvm::cl::desc("Specify input format of old abi dump"),
|
||||||
llvm::cl::values(clEnumValN(abi_util::TextFormatIR::ProtobufTextFormat,
|
llvm::cl::values(clEnumValN(abi_util::TextFormatIR::ProtobufTextFormat,
|
||||||
"ProtobufTextFormat", "ProtobufTextFormat"),
|
"ProtobufTextFormat", "ProtobufTextFormat"),
|
||||||
|
clEnumValN(abi_util::TextFormatIR::Json, "Json", "JSON"),
|
||||||
clEnumValEnd),
|
clEnumValEnd),
|
||||||
llvm::cl::init(abi_util::TextFormatIR::ProtobufTextFormat),
|
llvm::cl::init(abi_util::TextFormatIR::ProtobufTextFormat),
|
||||||
llvm::cl::cat(header_checker_category));
|
llvm::cl::cat(header_checker_category));
|
||||||
|
|
||||||
static llvm::cl::opt<abi_util::TextFormatIR> text_format_new(
|
static llvm::cl::opt<abi_util::TextFormatIR> text_format_new(
|
||||||
"text-format-new", llvm::cl::desc("Specify text format of new abi dump"),
|
"input-format-new", llvm::cl::desc("Specify input format of new abi dump"),
|
||||||
llvm::cl::values(clEnumValN(abi_util::TextFormatIR::ProtobufTextFormat,
|
llvm::cl::values(clEnumValN(abi_util::TextFormatIR::ProtobufTextFormat,
|
||||||
"ProtobufTextFormat", "ProtobugTextFormat"),
|
"ProtobufTextFormat", "ProtobugTextFormat"),
|
||||||
|
clEnumValN(abi_util::TextFormatIR::Json, "Json", "JSON"),
|
||||||
clEnumValEnd),
|
clEnumValEnd),
|
||||||
llvm::cl::init(abi_util::TextFormatIR::ProtobufTextFormat),
|
llvm::cl::init(abi_util::TextFormatIR::ProtobufTextFormat),
|
||||||
llvm::cl::cat(header_checker_category));
|
llvm::cl::cat(header_checker_category));
|
||||||
|
|||||||
@@ -70,6 +70,7 @@ static llvm::cl::opt<abi_util::TextFormatIR> input_format(
|
|||||||
"input-format", llvm::cl::desc("Specify format of input dump files"),
|
"input-format", llvm::cl::desc("Specify format of input dump files"),
|
||||||
llvm::cl::values(clEnumValN(abi_util::TextFormatIR::ProtobufTextFormat,
|
llvm::cl::values(clEnumValN(abi_util::TextFormatIR::ProtobufTextFormat,
|
||||||
"ProtobufTextFormat", "ProtobufTextFormat"),
|
"ProtobufTextFormat", "ProtobufTextFormat"),
|
||||||
|
clEnumValN(abi_util::TextFormatIR::Json, "Json", "JSON"),
|
||||||
clEnumValEnd),
|
clEnumValEnd),
|
||||||
llvm::cl::init(abi_util::TextFormatIR::ProtobufTextFormat),
|
llvm::cl::init(abi_util::TextFormatIR::ProtobufTextFormat),
|
||||||
llvm::cl::cat(header_linker_category));
|
llvm::cl::cat(header_linker_category));
|
||||||
|
|||||||
@@ -67,8 +67,9 @@ TextFormatToIRReader::CreateTextFormatToIRReader(
|
|||||||
switch (text_format) {
|
switch (text_format) {
|
||||||
case TextFormatIR::ProtobufTextFormat:
|
case TextFormatIR::ProtobufTextFormat:
|
||||||
return std::make_unique<ProtobufTextFormatToIRReader>(exported_headers);
|
return std::make_unique<ProtobufTextFormatToIRReader>(exported_headers);
|
||||||
|
case TextFormatIR::Json:
|
||||||
|
return std::make_unique<JsonToIRReader>(exported_headers);
|
||||||
default:
|
default:
|
||||||
// Nothing else is supported yet.
|
|
||||||
llvm::errs() << "Text format not supported yet\n";
|
llvm::errs() << "Text format not supported yet\n";
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ def relative_to_abs_path_list(relative_path_list):
|
|||||||
|
|
||||||
class Module(object):
|
class Module(object):
|
||||||
def __init__(self, name, arch, srcs, version_script, cflags,
|
def __init__(self, name, arch, srcs, version_script, cflags,
|
||||||
export_include_dirs, api, output_format=None):
|
export_include_dirs, api, dumper_flags=[], linker_flags=[]):
|
||||||
self.name = name
|
self.name = name
|
||||||
self.arch = arch
|
self.arch = arch
|
||||||
self.srcs = relative_to_abs_path_list(srcs)
|
self.srcs = relative_to_abs_path_list(srcs)
|
||||||
@@ -46,7 +46,8 @@ class Module(object):
|
|||||||
self.arch_cflags = ARCH_TARGET_CFLAGS.get(self.arch)
|
self.arch_cflags = ARCH_TARGET_CFLAGS.get(self.arch)
|
||||||
self.export_include_dirs = relative_to_abs_path_list(export_include_dirs)
|
self.export_include_dirs = relative_to_abs_path_list(export_include_dirs)
|
||||||
self.api = api
|
self.api = api
|
||||||
self.output_format = output_format
|
self.dumper_flags = dumper_flags
|
||||||
|
self.linker_flags = linker_flags
|
||||||
|
|
||||||
def get_name(self):
|
def get_name(self):
|
||||||
return self.name
|
return self.name
|
||||||
@@ -69,8 +70,11 @@ class Module(object):
|
|||||||
def get_api(self):
|
def get_api(self):
|
||||||
return self.api
|
return self.api
|
||||||
|
|
||||||
def get_output_format(self):
|
def get_dumper_flags(self):
|
||||||
return self.output_format
|
return self.dumper_flags
|
||||||
|
|
||||||
|
def get_linker_flags(self):
|
||||||
|
return self.linker_flags
|
||||||
|
|
||||||
def make_lsdump(self, default_cflags):
|
def make_lsdump(self, default_cflags):
|
||||||
""" For each source file, produce a .sdump file, and link them to form
|
""" For each source file, produce a .sdump file, and link them to form
|
||||||
@@ -83,10 +87,11 @@ class Module(object):
|
|||||||
dumps_to_link.append(output_path)
|
dumps_to_link.append(output_path)
|
||||||
run_header_abi_dumper_on_file(
|
run_header_abi_dumper_on_file(
|
||||||
src, output_path, self.export_include_dirs,
|
src, output_path, self.export_include_dirs,
|
||||||
self.cflags + self.arch_cflags + default_cflags)
|
self.cflags + self.arch_cflags + default_cflags,
|
||||||
|
self.dumper_flags)
|
||||||
return run_header_abi_linker(output_lsdump, dumps_to_link,
|
return run_header_abi_linker(output_lsdump, dumps_to_link,
|
||||||
self.version_script, self.api,
|
self.version_script, self.api,
|
||||||
self.arch, self.output_format)
|
self.arch, self.linker_flags)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def mutate_module_for_arch(module, target_arch):
|
def mutate_module_for_arch(module, target_arch):
|
||||||
@@ -96,9 +101,10 @@ class Module(object):
|
|||||||
cflags = module.get_cflags()
|
cflags = module.get_cflags()
|
||||||
export_include_dirs = module.get_export_include_dirs()
|
export_include_dirs = module.get_export_include_dirs()
|
||||||
api = module.get_api()
|
api = module.get_api()
|
||||||
output_format = module.get_output_format()
|
dumper_flags = module.get_dumper_flags()
|
||||||
|
linker_flags = module.get_linker_flags()
|
||||||
return Module(name, target_arch, srcs, version_script, cflags,
|
return Module(name, target_arch, srcs, version_script, cflags,
|
||||||
export_include_dirs, api, output_format)
|
export_include_dirs, api, dumper_flags, linker_flags)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def mutate_module_for_all_arches(module):
|
def mutate_module_for_all_arches(module):
|
||||||
@@ -496,7 +502,8 @@ TEST_MODULES = [
|
|||||||
cflags = [],
|
cflags = [],
|
||||||
arch = '',
|
arch = '',
|
||||||
api = 'current',
|
api = 'current',
|
||||||
output_format = 'Json'
|
dumper_flags = ['-output-format', 'Json'],
|
||||||
|
linker_flags = ['-input-format', 'Json', '-output-format', 'Json']
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
@@ -282,6 +282,12 @@ class MyTest(unittest.TestCase):
|
|||||||
self.prepare_and_absolute_diff_all_archs(
|
self.prepare_and_absolute_diff_all_archs(
|
||||||
"libgolden_cpp_json", "libgolden_cpp_json")
|
"libgolden_cpp_json", "libgolden_cpp_json")
|
||||||
|
|
||||||
|
def test_libc_and_cpp_in_protobuf_and_json(self):
|
||||||
|
self.prepare_and_run_abi_diff_all_archs(
|
||||||
|
"libgolden_cpp", "libgolden_cpp_json", 0,
|
||||||
|
["-input-format-old", "ProtobufTextFormat",
|
||||||
|
"-input-format-new", "Json"])
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|||||||
@@ -93,11 +93,12 @@ def run_header_abi_dumper(input_path, remove_absolute_paths, cflags=[],
|
|||||||
return f.read()
|
return f.read()
|
||||||
|
|
||||||
def run_header_abi_dumper_on_file(input_path, output_path,
|
def run_header_abi_dumper_on_file(input_path, output_path,
|
||||||
export_include_dirs = [], cflags =[]):
|
export_include_dirs=[], cflags=[], flags=[]):
|
||||||
input_name, input_ext = os.path.splitext(input_path)
|
input_name, input_ext = os.path.splitext(input_path)
|
||||||
cmd = ['header-abi-dumper', '-o', output_path, input_path,]
|
cmd = ['header-abi-dumper', '-o', output_path, input_path,]
|
||||||
for dir in export_include_dirs:
|
for dir in export_include_dirs:
|
||||||
cmd += ['-I', dir]
|
cmd += ['-I', dir]
|
||||||
|
cmd += flags
|
||||||
cmd += ['--']
|
cmd += ['--']
|
||||||
cmd += cflags
|
cmd += cflags
|
||||||
if input_ext == '.cpp' or input_ext == '.cc' or input_ext == '.h':
|
if input_ext == '.cpp' or input_ext == '.cc' or input_ext == '.h':
|
||||||
@@ -113,13 +114,12 @@ def run_header_abi_dumper_on_file(input_path, output_path,
|
|||||||
subprocess.check_call(cmd)
|
subprocess.check_call(cmd)
|
||||||
|
|
||||||
def run_header_abi_linker(output_path, inputs, version_script, api, arch,
|
def run_header_abi_linker(output_path, inputs, version_script, api, arch,
|
||||||
output_format=None):
|
flags=[]):
|
||||||
"""Link inputs, taking version_script into account"""
|
"""Link inputs, taking version_script into account"""
|
||||||
with tempfile.TemporaryDirectory() as tmp:
|
with tempfile.TemporaryDirectory() as tmp:
|
||||||
cmd = ['header-abi-linker', '-o', output_path, '-v', version_script,
|
cmd = ['header-abi-linker', '-o', output_path, '-v', version_script,
|
||||||
'-api', api, '-arch', arch]
|
'-api', api, '-arch', arch]
|
||||||
if output_format:
|
cmd += flags
|
||||||
cmd += ['-output-format', output_format]
|
|
||||||
cmd += inputs
|
cmd += inputs
|
||||||
subprocess.check_call(cmd)
|
subprocess.check_call(cmd)
|
||||||
with open(output_path, 'r') as f:
|
with open(output_path, 'r') as f:
|
||||||
|
|||||||
Reference in New Issue
Block a user