Search in sources :

Example 1 with CheckEventAdapter

use of org.eclipse.linuxtools.internal.oprofile.core.opxml.checkevent.CheckEventAdapter in project linuxtools by eclipse.

the class TestCheckEventsPreParse method assertValidity.

public void assertValidity(String path) {
    IFileStore fileStore = null;
    String infoAbsFilePath = null;
    Path infoFilePath = new Path(REL_PATH_TO_INFO_PRE_PARSE_RAW);
    URL infoFileURL = FileLocator.find(FrameworkUtil.getBundle(this.getClass()), infoFilePath, null);
    try {
        infoAbsFilePath = FileLocator.toFileURL(infoFileURL).getFile();
        fileStore = EFS.getLocalFileSystem().getStore(new Path(infoAbsFilePath));
    } catch (IOException e) {
        fail("Failed to convert the resource file's path.");
    }
    InfoAdapter ia = new InfoAdapter(fileStore);
    ia.process();
    cea = new CheckEventAdapter(ctr, "CPU_CLK_UNHALTED", umask);
    cea.process();
    Document actualDocument = cea.getDocument();
    Element actualRoot = (Element) actualDocument.getElementsByTagName(CheckEventAdapter.CHECK_EVENTS).item(0);
    Path filePath = new Path(path);
    URL fileURL = FileLocator.find(FrameworkUtil.getBundle(this.getClass()), filePath, null);
    Element expectedRoot = null;
    try {
        String absFilePath = FileLocator.toFileURL(fileURL).getFile();
        File file = new File(absFilePath);
        FileInputStream inp = new FileInputStream(file);
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder;
        builder = factory.newDocumentBuilder();
        Document expectedDocument = builder.parse(inp);
        expectedRoot = (Element) expectedDocument.getElementsByTagName(CheckEventAdapter.CHECK_EVENTS).item(0);
    } catch (FileNotFoundException e) {
        fail("File was not found.");
    } catch (IOException e) {
        fail("Failed to convert the resource file's path.");
    } catch (SAXException e) {
        fail("Failed to parse the XML.");
    } catch (ParserConfigurationException e) {
        fail("Failed to create a document builder.");
    }
    Element expectedResultTag = (Element) expectedRoot.getElementsByTagName(CheckEventAdapter.RESULT).item(0);
    Element actualResultTag = (Element) actualRoot.getElementsByTagName(CheckEventAdapter.RESULT).item(0);
    assertEquals(expectedResultTag.getTextContent(), actualResultTag.getTextContent());
}
Also used : Path(org.eclipse.core.runtime.Path) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) Element(org.w3c.dom.Element) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) Document(org.w3c.dom.Document) URL(java.net.URL) FileInputStream(java.io.FileInputStream) SAXException(org.xml.sax.SAXException) InfoAdapter(org.eclipse.linuxtools.internal.oprofile.core.opxml.info.InfoAdapter) DocumentBuilder(javax.xml.parsers.DocumentBuilder) CheckEventAdapter(org.eclipse.linuxtools.internal.oprofile.core.opxml.checkevent.CheckEventAdapter) IFileStore(org.eclipse.core.filesystem.IFileStore) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) File(java.io.File)

Example 2 with CheckEventAdapter

use of org.eclipse.linuxtools.internal.oprofile.core.opxml.checkevent.CheckEventAdapter in project linuxtools by eclipse.

the class OpxmlRunner method run.

/**
 * Runs opxml with the given arguments.
 *
 * @param args
 *            the arguments to pass to opxml
 * @param callData
 *            any callData to pass to the processor
 * @return boolean indicating the success/failure of opxml
 */
public boolean run(String[] args, Object callData) {
    XMLReader reader = null;
    OprofileSAXHandler handler = OprofileSAXHandler.getInstance(callData);
    // Create XMLReader
    SAXParserFactory factory = SAXParserFactory.newInstance();
    try {
        reader = factory.newSAXParser().getXMLReader();
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
    // Set content/error handlers
    reader.setContentHandler(handler);
    reader.setErrorHandler(handler);
    // Check for timer support
    InfoAdapter.checkTimerSupport();
    // Run opxml
    try {
        File file = constructFile(args);
        // handle the opxml_session file
        if (args[0].equals(SessionManager.SESSIONS)) {
            SessionManager sessManNew = new SessionManager(SessionManager.SESSION_LOCATION);
            populateWithCurrentSession(sessManNew);
            sessManNew.write();
            FileReader fr = new FileReader(file);
            reader.parse(new InputSource(fr));
        // file has not been saved
        } else if (!file.exists()) {
            AbstractDataAdapter aea;
            if (args[0].equals(CheckEventAdapter.CHECK_EVENTS)) {
                aea = new CheckEventAdapter(args[1], args[2], args[3]);
                aea.process();
                BufferedReader bi = new BufferedReader(new InputStreamReader(aea.getInputStream()));
                reader.parse(new InputSource(bi));
            } else if (args[0].equals(InfoAdapter.INFO)) {
                aea = new InfoAdapter();
                aea.process();
                BufferedReader bi = new BufferedReader(new InputStreamReader(aea.getInputStream()));
                reader.parse(new InputSource(bi));
            } else if (args[0].equals(ModelDataAdapter.MODEL_DATA)) {
                // has not been generated
                if (!handleModelData(args)) {
                    return false;
                }
                FileReader fr = new FileReader(file);
                reader.parse(new InputSource(fr));
            } else {
                // $NON-NLS-1$
                throw new RuntimeException("Unrecognized argument encountered");
            }
        } else {
            // always regenerate the 'current' session file
            if (args.length == 3 && args[0].equals(SessionManager.MODEL_DATA) && args[2].equals(SessionManager.CURRENT)) {
                if (!handleModelData(args)) {
                    return false;
                }
            }
            FileReader fr = new FileReader(file);
            reader.parse(new InputSource(fr));
        }
        return true;
    } catch (SAXException e) {
        e.printStackTrace();
        // $NON-NLS-1$
        OprofileCorePlugin.showErrorDialog("opxmlSAXParseException", null);
    } catch (IOException e) {
        e.printStackTrace();
        // $NON-NLS-1$
        OprofileCorePlugin.showErrorDialog("opxmlParse", null);
    }
    return false;
}
Also used : InputSource(org.xml.sax.InputSource) InputStreamReader(java.io.InputStreamReader) SessionManager(org.eclipse.linuxtools.internal.oprofile.core.opxml.sessions.SessionManager) OprofileSAXHandler(org.eclipse.linuxtools.internal.oprofile.core.opxml.OprofileSAXHandler) IOException(java.io.IOException) CoreException(org.eclipse.core.runtime.CoreException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException) SAXException(org.xml.sax.SAXException) InfoAdapter(org.eclipse.linuxtools.internal.oprofile.core.opxml.info.InfoAdapter) CheckEventAdapter(org.eclipse.linuxtools.internal.oprofile.core.opxml.checkevent.CheckEventAdapter) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) AbstractDataAdapter(org.eclipse.linuxtools.internal.oprofile.core.opxml.AbstractDataAdapter) File(java.io.File) XMLReader(org.xml.sax.XMLReader) SAXParserFactory(javax.xml.parsers.SAXParserFactory)

Aggregations

File (java.io.File)2 IOException (java.io.IOException)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 CheckEventAdapter (org.eclipse.linuxtools.internal.oprofile.core.opxml.checkevent.CheckEventAdapter)2 InfoAdapter (org.eclipse.linuxtools.internal.oprofile.core.opxml.info.InfoAdapter)2 SAXException (org.xml.sax.SAXException)2 BufferedReader (java.io.BufferedReader)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 FileReader (java.io.FileReader)1 InputStreamReader (java.io.InputStreamReader)1 URL (java.net.URL)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1 SAXParserFactory (javax.xml.parsers.SAXParserFactory)1 IFileStore (org.eclipse.core.filesystem.IFileStore)1 CoreException (org.eclipse.core.runtime.CoreException)1 Path (org.eclipse.core.runtime.Path)1 AbstractDataAdapter (org.eclipse.linuxtools.internal.oprofile.core.opxml.AbstractDataAdapter)1 OprofileSAXHandler (org.eclipse.linuxtools.internal.oprofile.core.opxml.OprofileSAXHandler)1