def main(): """Prints the owners of histograms in a specific file or of all histograms. Args: argv[1]: Optional argument that is the relative path to a specific histograms.xml. Example usage to print owners of histograms_xml/Accessibility/histograms.xml: python histogram_ownership.py histograms_xml/Accessibility/histograms.xml Example usage to print owners of all histograms: python histogram_ownership.py """ if len(sys.argv) == 1: merged_xml_string = merge_xml.PrettyPrintMergedFiles( histogram_paths.ALL_XMLS) root = ET.fromstring(merged_xml_string) else: rel_path = sys.argv[1] if not os.path.exists(rel_path): raise FileNotFoundError(errno.ENOENT, os.strerror(errno.ENOENT)) tree = ET.parse(rel_path) root = tree.getroot() PrintOwners(root)
def testMergeFiles_WithXmlEvents(self): """Checks that the UkmEventNameHash enum is populated correctly. If ukm.xml is provided, populate a list of ints to the UkmEventNameHash enum where each value is a truncated hash of the event name and each label is the corresponding event name, with obsolete label when applicable. """ merged = merge_xml.PrettyPrintMergedFiles( histogram_paths.ALL_TEST_XMLS) expected_merged_xml = """ <histogram-configuration> <enums> <enum name="Enum1"> <int value="0" label="Value0"/> <int value="1" label="Value1"/> </enum> <enum name="TestEnum"> <int value="0" label="Value0"/> <int value="1" label="Value1"/> </enum> <enum name="UkmEventNameHash"> <summary> Placeholder enum. The values are UKM event name hashes truncated to 31 bits. This gets populated by the GetEnumsNodes function in merge_xml.py when producing the merged XML file. </summary> <int value="151676257" label="AbusiveExperienceHeuristic.TestEvent1"/> <int value="898353372" label="AbusiveExperienceHeuristic.TestEvent2 (Obsolete)"/> <int value="1052089961" label="Autofill.TestEvent3"/> <int value="1758741469" label="FullyObsolete.TestEvent4 (Obsolete)"/> </enum> </enums> <histograms> <variants name="TestToken"> <variant name="Variant1" summary="Label1"/> <variant name="Variant2" summary="Label2"/> </variants> <histogram name="Foo.Bar" units="xxxxxxxxxxxxxxxxxxyyyyyyyyyyyyyyyyyyyyyyzzzz" expires_after="M85"> <owner>[email protected]</owner> <component>Component</component> <summary>Foo</summary> </histogram> <histogram name="Test.EnumHistogram" enum="TestEnum" expires_after="M81"> <obsolete> Obsolete message </obsolete> <owner>[email protected]</owner> <summary>A enum histogram.</summary> </histogram> <histogram name="Test.Histogram" units="microseconds" expires_after="M85"> <obsolete> Removed 6/2020. </obsolete> <owner>[email protected]</owner> <summary>Summary 2</summary> </histogram> <histogram name="Test.TokenHistogram{TestToken}" units="microseconds" expires_after="M85"> <obsolete> Removed 6/2020. </obsolete> <owner>[email protected]</owner> <summary>Summary 2</summary> <token key="TestToken" variants="TestToken"/> </histogram> </histograms> <histogram_suffixes_list> <histogram_suffixes name="Test.EnumHistogramSuffixes" separator="." ordering="prefix,2"> <suffix name="TestEnumSuffix" label="The enum histogram_suffixes"/> <affected-histogram name="Test.EnumHistogram"/> </histogram_suffixes> <histogram_suffixes name="Test.HistogramSuffixes" separator="."> <suffix name="TestSuffix" label="A histogram_suffixes"/> <affected-histogram name="Test.Histogram"/> </histogram_suffixes> </histogram_suffixes_list> </histogram-configuration> """ self.maxDiff = None self.assertMultiLineEqual(expected_merged_xml.strip(), merged.strip())
def testMergeFiles(self): """Checks that enums.xml and histograms.xml can merge successfully.""" merged = merge_xml.PrettyPrintMergedFiles([ histogram_paths.TEST_ENUMS_XML, histogram_paths.TEST_HISTOGRAMS_XML, histogram_paths.TEST_SUFFIXES_XML ]) # If ukm.xml is not provided, there is no need to populate the # UkmEventNameHash enum. expected_merged_xml = """ <histogram-configuration> <enums> <enum name="Enum1"> <int value="0" label="Value0"/> <int value="1" label="Value1"/> </enum> <enum name="TestEnum"> <int value="0" label="Value0"/> <int value="1" label="Value1"/> </enum> <enum name="UkmEventNameHash"> <summary> Placeholder enum. The values are UKM event name hashes truncated to 31 bits. This gets populated by the GetEnumsNodes function in merge_xml.py when producing the merged XML file. </summary> </enum> </enums> <histograms> <variants name="TestToken"> <variant name="Variant1" summary="Label1"/> <variant name="Variant2" summary="Label2"/> </variants> <histogram name="Foo.Bar" units="xxxxxxxxxxxxxxxxxxyyyyyyyyyyyyyyyyyyyyyyzzzz" expires_after="M85"> <owner>[email protected]</owner> <component>Component</component> <summary>Foo</summary> </histogram> <histogram name="Test.EnumHistogram" enum="TestEnum" expires_after="M81"> <obsolete> Obsolete message </obsolete> <owner>[email protected]</owner> <summary>A enum histogram.</summary> </histogram> <histogram name="Test.Histogram" units="microseconds" expires_after="M85"> <obsolete> Removed 6/2020. </obsolete> <owner>[email protected]</owner> <summary>Summary 2</summary> </histogram> <histogram name="Test.TokenHistogram{TestToken}" units="microseconds" expires_after="M85"> <obsolete> Removed 6/2020. </obsolete> <owner>[email protected]</owner> <summary>Summary 2</summary> <token key="TestToken" variants="TestToken"/> </histogram> </histograms> <histogram_suffixes_list> <histogram_suffixes name="Test.EnumHistogramSuffixes" separator="." ordering="prefix,2"> <suffix name="TestEnumSuffix" label="The enum histogram_suffixes"/> <affected-histogram name="Test.EnumHistogram"/> </histogram_suffixes> <histogram_suffixes name="Test.HistogramSuffixes" separator="."> <suffix name="TestSuffix" label="A histogram_suffixes"/> <affected-histogram name="Test.Histogram"/> </histogram_suffixes> </histogram_suffixes_list> </histogram-configuration> """ self.maxDiff = None self.assertMultiLineEqual(expected_merged_xml.strip(), merged.strip())
def testMergeFiles_WithXmlEvents(self): """Checks that the UkmEventNameHash enum is populated correctly. If ukm.xml is provided, populate a list of ints to the UkmEventNameHash enum where where each value is a xml event name hash truncated to 31 bits and each label is the corresponding event name. """ merged = merge_xml.PrettyPrintMergedFiles( histogram_paths.ALL_TEST_XMLS) expected_merged_xml = """ <histogram-configuration> <enums> <enum name="Enum1"> <int value="0" label="Value0"/> <int value="1" label="Value1"/> </enum> <enum name="TestEnum"> <int value="0" label="Value0"/> <int value="1" label="Value1"/> </enum> <enum name="UkmEventNameHash"> <summary> Placeholder enum. The values are UKM event name hashes truncated to 31 bits. This gets populated by the GetEnumsNodes function in merge_xml.py when producing the merged XML file. </summary> <int value="324605288" label="AbusiveExperienceHeuristic.WindowOpen"/> <int value="1621538456" label="AbusiveExperienceHeuristic.TabUnder"/> <int value="1913876024" label="Autofill.SelectedMaskedServerCard (Obsolete)"/> </enum> </enums> <histograms> <histogram name="Foo.Bar" units="xxxxxxxxxxxxxxxxxxyyyyyyyyyyyyyyyyyyyyyyzzzz"> <owner>[email protected]</owner> <summary>Foo</summary> </histogram> <histogram name="Test.EnumHistogram" enum="TestEnum" expires_after="M81"> <obsolete> Obsolete message </obsolete> <owner>[email protected]</owner> <summary>A enum histogram.</summary> </histogram> <histogram name="Test.Histogram" units="microseconds"> <obsolete> Removed 6/2020. </obsolete> <owner>[email protected]</owner> <summary>Summary 2</summary> </histogram> </histograms> <histogram_suffixes_list> <histogram_suffixes name="Test.HistogramSuffixes" separator="."> <suffix name="TestSuffix" label="A histogram_suffixes"/> <affected-histogram name="Test.Histogram"/> </histogram_suffixes> </histogram_suffixes_list> </histogram-configuration> """ self.maxDiff = None self.assertMultiLineEqual(expected_merged_xml.strip(), merged.strip())