Path: blob/master/test/hotspot/jtreg/gtest/GTestResultParser.java
41144 views
/*1* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import javax.xml.XMLConstants;24import javax.xml.stream.XMLInputFactory;25import javax.xml.stream.XMLStreamConstants;26import javax.xml.stream.XMLStreamException;27import javax.xml.stream.XMLStreamReader;28import java.io.IOException;29import java.io.Reader;30import java.nio.file.Files;31import java.nio.file.Path;32import java.util.ArrayList;33import java.util.Collections;34import java.util.List;3536public class GTestResultParser {37private final List<String> _failedTests;3839public GTestResultParser(Path file) {40List<String> failedTests = new ArrayList<>();41try (Reader r = Files.newBufferedReader(file)) {42XMLInputFactory factory = XMLInputFactory.newInstance();43factory.setProperty(XMLConstants.ACCESS_EXTERNAL_DTD, "");44factory.setProperty(XMLConstants.ACCESS_EXTERNAL_SCHEMA, "");45XMLStreamReader xmlReader = factory.createXMLStreamReader(r);46String testSuite = null;47String testCase = null;48while (xmlReader.hasNext()) {49int code = xmlReader.next();50if (code == XMLStreamConstants.START_ELEMENT) {51switch (xmlReader.getLocalName()) {52case "testsuite":53testSuite = xmlReader.getAttributeValue("", "name");54break;55case "testcase":56testCase = xmlReader.getAttributeValue("", "name");57break;58case "failure":59failedTests.add(testSuite + "::" + testCase);60break;61default:62// ignore63}64}65}66} catch (XMLStreamException e) {67throw new IllegalArgumentException("can't open parse xml " + file, e);68} catch (IOException e) {69throw new IllegalArgumentException("can't open result file " + file, e);70}71_failedTests = Collections.unmodifiableList(failedTests);72}7374public List<String> failedTests() {75return _failedTests;76}77}787980