Add tests.
authorKim Nguyễn <kn@lri.fr>
Fri, 4 Mar 2016 16:25:28 +0000 (17:25 +0100)
committerKim Nguyễn <kn@lri.fr>
Fri, 4 Mar 2016 16:25:28 +0000 (17:25 +0100)
12 files changed:
tests/xpath/XPathEvalSaxon.java [new file with mode: 0644]
tests/xpath/gen_ref.sh [new file with mode: 0755]
tests/xpath/gen_ref_saxon.sh [new file with mode: 0755]
tests/xpath/test1.sh [new file with mode: 0644]
tests/xpath/test2.sh [new file with mode: 0644]
tests/xpath/test3.sh [new file with mode: 0644]
tests/xpath/test_complexity.sh [new file with mode: 0755]
tests/xpath/test_correction.sh [new file with mode: 0644]
tests/xpath/xmark_0.00.xml.queries [new file with mode: 0644]
tests/xpath/xmark_0.05.xml.queries [new file with mode: 0644]
tests/xpath/xmark_0.50.xml.queries [new file with mode: 0644]
tests/xpath/xmark_queries.template [new file with mode: 0644]

diff --git a/tests/xpath/XPathEvalSaxon.java b/tests/xpath/XPathEvalSaxon.java
new file mode 100644 (file)
index 0000000..6d1d6e6
--- /dev/null
@@ -0,0 +1,58 @@
+//import javax.xml.xpath.*;
+import javax.xml.xpath.XPathConstants;
+import javax.xml.xpath.XPath;
+import javax.xml.xpath.XPathException;
+import net.sf.saxon.xpath.XPathFactoryImpl;
+import net.sf.saxon.om.NodeInfo;
+import net.sf.saxon.type.Type;
+import org.xml.sax.*;
+import org.w3c.dom.*;
+import javax.xml.transform.*;
+import javax.xml.transform.dom.*;
+import javax.xml.transform.stream.*;
+import java.util.ArrayList;
+
+public class XPathEvalSaxon {
+
+
+  public static void main(String args[]) {
+    try {
+
+
+      XPath xpath = (new XPathFactoryImpl()).newXPath();
+      String expression = args[1];
+      InputSource inputSource = new InputSource(args[0]);
+      long startTime = System.nanoTime();
+      @SuppressWarnings("unchecked")
+      ArrayList<NodeInfo> nodes = (ArrayList<NodeInfo>) xpath.evaluate(expression, inputSource, XPathConstants.NODESET);
+      long evalTime = (System.nanoTime() - startTime) / 1000000;
+      Transformer serializer = TransformerFactory.newInstance().newTransformer();
+      serializer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
+      StreamResult o = new StreamResult(System.out);
+      startTime = System.nanoTime();
+      System.out.println("<xml_result num=\"1\">");
+      for(int i = 0; i < nodes.size(); i++){
+        NodeInfo n = nodes.get(i);
+        switch (n.getNodeKind()) {
+        case Type.ATTRIBUTE:
+          System.out.print (n.getLocalPart() + "=" + n.getStringValue());
+          break;
+        default:
+          serializer.transform(n, o);
+          break;
+        };
+        System.out.println();
+      };
+      System.out.println("</xml_result>");
+      long printTime = (System.nanoTime() - startTime) / 1000000;
+      System.err.println("evaluation time: " + evalTime + "ms");
+      System.err.println("serialization time: " + printTime + "ms");
+    } catch (XPathException e) {
+      System.out.println (e.getCause());
+    } catch (Exception e) {
+      System.out.println(e);
+    };
+
+
+  }
+}
diff --git a/tests/xpath/gen_ref.sh b/tests/xpath/gen_ref.sh
new file mode 100755 (executable)
index 0000000..b6d8c3b
--- /dev/null
@@ -0,0 +1,19 @@
+#!/bin/sh
+
+javac XPathEval.java
+for xml in *.xml
+do
+    QUERIES="${xml}.queries"
+    RESULTS="${xml}.results"
+    cat "$QUERIES" | grep -v '^#' | while read qname query
+    do
+        printf "Generating reference for %s, %s ... " "${xml}" "${qname}"
+        java XPathEval "${xml}" "${query}" > "$RESULTS"/"${qname}_reference.xml" 2> "$RESULTS"/"${qname}_reference.log"
+        if [ $? -eq 0 ]
+        then
+            printf "ok\\n"
+        else
+            printf "ERROR\\n"
+        fi
+    done
+done
diff --git a/tests/xpath/gen_ref_saxon.sh b/tests/xpath/gen_ref_saxon.sh
new file mode 100755 (executable)
index 0000000..d695d06
--- /dev/null
@@ -0,0 +1,19 @@
+#!/bin/sh
+
+javac -cp .:/tmp/saxon9he.jar XPathEvalSaxon.java
+for xml in *.xml
+do
+    QUERIES="${xml}.queries"
+    RESULTS="${xml}.results"
+    cat "$QUERIES" | grep -v '^#' | while read qname query
+    do
+        printf "Generating reference for %s, %s ... " "${xml}" "${qname}"
+        java -cp .:/tmp/saxon9he.jar XPathEvalSaxon "${xml}" "${query}" > "$RESULTS"/"${qname}_saxon.xml" 2> "$RESULTS"/"${qname}_saxon.log"
+        if [ $? -eq 0 ]
+        then
+            printf "ok\\n"
+        else
+            printf "ERROR\\n"
+        fi
+    done
+done
diff --git a/tests/xpath/test1.sh b/tests/xpath/test1.sh
new file mode 100644 (file)
index 0000000..4cc2da4
--- /dev/null
@@ -0,0 +1,24 @@
+#!/bin/sh
+
+MSG="Test 1 (single query: tatoo vs java implementation)"
+echo "$MSG" >> "$target"
+echo "$MSG"
+cat ${xml}.queries | grep -v '^#' | while read q query; do
+    echo -n "${xml} $q $query ... "
+    REF=${xml}.results/"$q"_jaxp.xml
+    OUTPUT=${xml}.results/"$q"_"$PACKAGE"_test1.xml
+    LOG=${xml}.results/"$q"_"$PACKAGE"_test1.log
+    "$BIN" -s -d ${xml} "$query" -o "$OUTPUT" > "$LOG" 2>&1
+    echo "Query: $q : $query" >> "$target"
+    cat  "$LOG" | grep '^STATS' >> "$target"
+    echo -n "Diff: " >> "$target"
+    if $XMLDIFF "$REF" "$OUTPUT" >/dev/null 2>&1; then
+       echo ok
+       echo ok >> "$target"
+    else
+       echo failed
+       echo failed >> "$target"
+       exit 1
+    fi
+    echo '-------------------------------------------' >> "$target"
+done
diff --git a/tests/xpath/test2.sh b/tests/xpath/test2.sh
new file mode 100644 (file)
index 0000000..9b0ef34
--- /dev/null
@@ -0,0 +1,28 @@
+#!/bin/sh
+
+MSG="Test 2 (all queries sequentially vs all queries in parallel)"
+echo "$MSG" >> "$target"
+echo "$MSG"
+allqueries=`cat "${xml}".queries | grep -v '^#' | while read q query; do echo "'$query'"; done`
+echo -n "Running all queries ... "
+OUTPUTA="$xml".results/test2a_"$PACKAGE".xml
+LOG="$xml".results/test2a_"$PACKAGE".log
+echo -n "sequential ... "
+echo "$allqueries" | xargs $BIN -s -d "$xml" -o "$OUTPUTA" > "$LOG" 2>&1
+cat  "$LOG" | grep '^STATS' >> "$target"
+
+OUTPUTB="$xml".results/test2b_"$PACKAGE".xml
+LOG="$xml".results/test2b_"$PACKAGE".log
+echo -n "parallel ... "
+echo "$allqueries" | xargs $BIN -p -s -d "$xml" -o "$OUTPUTB" > "$LOG" 2>&1
+cat  "$LOG" | grep '^STATS' >> "$target"
+echo -n "Diff: " >> "$target"
+if diff "$OUTPUTA" "$OUTPUTB" >/dev/null 2>&1; then
+    echo ok
+    echo ok >> "$target"
+else
+    echo failed
+    echo failed >> "$target"
+    exit 1
+fi
+echo '-------------------------------------------' >> "$target"
diff --git a/tests/xpath/test3.sh b/tests/xpath/test3.sh
new file mode 100644 (file)
index 0000000..d10bf04
--- /dev/null
@@ -0,0 +1,31 @@
+#!/bin/sh
+
+MSG="Test 3 (multiple queries composition: sequential vs parallel)"
+echo "$MSG" >> "$target"
+echo "$MSG"
+cat "${xml}".queries | grep -v '^#' | while read q query; do
+    echo -n "${xml} $q $query ... sequential ... "
+    OUTPUTA="${xml}".results/"$q"_"$PACKAGE"_test3a.xml
+    LOG="${xml}".results/"$q"_"$PACKAGE"_test3a.log
+    $SPLIT "$query" | xargs $BIN -s -C -d "${xml}" -o "$OUTPUTA"  > "$LOG" 2>&1
+    echo "Query: $q : $query" >> "$target"
+    cat  "$LOG" | grep '^STATS' >> "$target"
+
+    echo -n "parallel ... "
+    OUTPUTB="${xml}".results/"$q"_"$PACKAGE"_test3b.xml
+    LOG="${xml}".results/"$q"_"$PACKAGE"_test3b.log
+    $SPLIT "$query" | xargs $BIN -s -p -C -d  "${xml}" -o "$OUTPUTB"  > "$LOG" 2>&1
+    echo "Query: $q : $query" >> "$target"
+    cat  "$LOG" | grep '^STATS' >> "$target"
+
+    echo -n "Diff: " >> "$target"
+    if diff  "$OUTPUTA" "$OUTPUTB" >/dev/null 2>&1; then
+       echo ok
+       echo ok >> "$target"
+    else
+       echo failed
+       echo failed >> "$target"
+       exit 1
+    fi
+    echo '-------------------------------------------' >> "$target"
+done
diff --git a/tests/xpath/test_complexity.sh b/tests/xpath/test_complexity.sh
new file mode 100755 (executable)
index 0000000..f3cc8f0
--- /dev/null
@@ -0,0 +1,15 @@
+#!/bin/sh
+
+S="//M/ancestor::A"
+Q="$S"
+
+for i in `seq 1 30`
+do
+    src/tatoo.native -s -d tests/alphabet.xml -o /dev/null -c "$Q" 2> /tmp/log
+    ST=`grep 'Number of states' /tmp/log  | cut -f 2 -d :`
+    TM=`grep 'evaluating query in' /tmp/log  | cut -f 3 -d : | cut -f 1 -d m`
+    RU=`grep 'traversals' /tmp/log  | cut -f 2 -d :`
+    echo "$i", "$ST", "$TM", "$RU"
+    Q="$Q""$S"
+done
+rm -f /tmp/log
diff --git a/tests/xpath/test_correction.sh b/tests/xpath/test_correction.sh
new file mode 100644 (file)
index 0000000..7801b63
--- /dev/null
@@ -0,0 +1,37 @@
+#!/bin/sh
+
+
+PROG="$1"
+BASEDIR="$2"
+SUMMARY=""
+
+output ()
+{
+    echo "$1"
+    if [ -f "$SUMMARY" ]
+    then
+        echo "$1" >> "$SUMMARY"
+    fi
+}
+
+for xml in "$BASEDIR"/*.xml
+do
+    QUERIES="$xml".queries
+    RESULTS="$xml".results
+    if [ -f "$QUERIES" -a -d "$RESULTS" ]
+    then
+        SUMMARY="$xml".summary
+        rm -f "$SUMMARY"
+        touch "$SUMMARY"
+        output "-- Testing file ${xml} -----------------"
+
+        cat "$QUERIES" | grep -v '^#' | while read QNAME QUERY
+        do
+
+        done
+
+
+    fi
+
+
+done
diff --git a/tests/xpath/xmark_0.00.xml.queries b/tests/xpath/xmark_0.00.xml.queries
new file mode 100644 (file)
index 0000000..237bba7
--- /dev/null
@@ -0,0 +1,21 @@
+A1 /site/closed_auctions/closed_auction/annotation/description/text/keyword
+A2 //closed_auction//keyword
+A3 /site/closed_auctions/closed_auction//keyword
+A4 /site/closed_auctions/closed_auction[annotation/description/text/keyword]/date
+A5 /site/closed_auctions/closed_auction[descendant::keyword]/date
+A6 /site/people/person[profile/gender and profile/age]/name
+A7 /site/people/person[phone or homepage]/name
+A8 /site/people/person[address and (phone or homepage) and (creditcard or profile)]/name
+B1 /site/regions/*/item[parent::namerica or parent::samerica]/name
+B2 //keyword/ancestor::listitem/text/keyword
+B3 /site/open_auctions/open_auction/bidder[following-sibling::bidder]
+B4 /site/open_auctions/open_auction/bidder[preceding-sibling::bidder]
+B5 /site/regions/*/item[following::item]/name
+B6 /site/regions/*/item[preceding::item]/name
+B7 //person[profile/@income]/name
+B8 /site/open_auctions/open_auction[bidder and not(bidder/preceding-sibling::bidder)]/interval
+B9 /site/open_auctions/open_auction[(not(bidder/following::bidder) or not(bidder/preceding::bidder)) or (bidder/following::bidder and bidder/preceding::bidder)]/interval
+B10 /site/open_auctions/open_auction[(not(bidder/following::bidder) or not(bidder/preceding::bidder)) and (bidder/following::bidder and bidder/preceding::bidder)]/interval
+B11 //open_auction/bidder/../bidder/../bidder/../interval
+B12 //item/@id/../@id/../@id/../@id/../name
+B13 //keyword/ancestor::parlist/descendant::keyword/ancestor::parlist/descendant::keyword/ancestor::parlist/descendant::keyword
diff --git a/tests/xpath/xmark_0.05.xml.queries b/tests/xpath/xmark_0.05.xml.queries
new file mode 100644 (file)
index 0000000..237bba7
--- /dev/null
@@ -0,0 +1,21 @@
+A1 /site/closed_auctions/closed_auction/annotation/description/text/keyword
+A2 //closed_auction//keyword
+A3 /site/closed_auctions/closed_auction//keyword
+A4 /site/closed_auctions/closed_auction[annotation/description/text/keyword]/date
+A5 /site/closed_auctions/closed_auction[descendant::keyword]/date
+A6 /site/people/person[profile/gender and profile/age]/name
+A7 /site/people/person[phone or homepage]/name
+A8 /site/people/person[address and (phone or homepage) and (creditcard or profile)]/name
+B1 /site/regions/*/item[parent::namerica or parent::samerica]/name
+B2 //keyword/ancestor::listitem/text/keyword
+B3 /site/open_auctions/open_auction/bidder[following-sibling::bidder]
+B4 /site/open_auctions/open_auction/bidder[preceding-sibling::bidder]
+B5 /site/regions/*/item[following::item]/name
+B6 /site/regions/*/item[preceding::item]/name
+B7 //person[profile/@income]/name
+B8 /site/open_auctions/open_auction[bidder and not(bidder/preceding-sibling::bidder)]/interval
+B9 /site/open_auctions/open_auction[(not(bidder/following::bidder) or not(bidder/preceding::bidder)) or (bidder/following::bidder and bidder/preceding::bidder)]/interval
+B10 /site/open_auctions/open_auction[(not(bidder/following::bidder) or not(bidder/preceding::bidder)) and (bidder/following::bidder and bidder/preceding::bidder)]/interval
+B11 //open_auction/bidder/../bidder/../bidder/../interval
+B12 //item/@id/../@id/../@id/../@id/../name
+B13 //keyword/ancestor::parlist/descendant::keyword/ancestor::parlist/descendant::keyword/ancestor::parlist/descendant::keyword
diff --git a/tests/xpath/xmark_0.50.xml.queries b/tests/xpath/xmark_0.50.xml.queries
new file mode 100644 (file)
index 0000000..237bba7
--- /dev/null
@@ -0,0 +1,21 @@
+A1 /site/closed_auctions/closed_auction/annotation/description/text/keyword
+A2 //closed_auction//keyword
+A3 /site/closed_auctions/closed_auction//keyword
+A4 /site/closed_auctions/closed_auction[annotation/description/text/keyword]/date
+A5 /site/closed_auctions/closed_auction[descendant::keyword]/date
+A6 /site/people/person[profile/gender and profile/age]/name
+A7 /site/people/person[phone or homepage]/name
+A8 /site/people/person[address and (phone or homepage) and (creditcard or profile)]/name
+B1 /site/regions/*/item[parent::namerica or parent::samerica]/name
+B2 //keyword/ancestor::listitem/text/keyword
+B3 /site/open_auctions/open_auction/bidder[following-sibling::bidder]
+B4 /site/open_auctions/open_auction/bidder[preceding-sibling::bidder]
+B5 /site/regions/*/item[following::item]/name
+B6 /site/regions/*/item[preceding::item]/name
+B7 //person[profile/@income]/name
+B8 /site/open_auctions/open_auction[bidder and not(bidder/preceding-sibling::bidder)]/interval
+B9 /site/open_auctions/open_auction[(not(bidder/following::bidder) or not(bidder/preceding::bidder)) or (bidder/following::bidder and bidder/preceding::bidder)]/interval
+B10 /site/open_auctions/open_auction[(not(bidder/following::bidder) or not(bidder/preceding::bidder)) and (bidder/following::bidder and bidder/preceding::bidder)]/interval
+B11 //open_auction/bidder/../bidder/../bidder/../interval
+B12 //item/@id/../@id/../@id/../@id/../name
+B13 //keyword/ancestor::parlist/descendant::keyword/ancestor::parlist/descendant::keyword/ancestor::parlist/descendant::keyword
diff --git a/tests/xpath/xmark_queries.template b/tests/xpath/xmark_queries.template
new file mode 100644 (file)
index 0000000..237bba7
--- /dev/null
@@ -0,0 +1,21 @@
+A1 /site/closed_auctions/closed_auction/annotation/description/text/keyword
+A2 //closed_auction//keyword
+A3 /site/closed_auctions/closed_auction//keyword
+A4 /site/closed_auctions/closed_auction[annotation/description/text/keyword]/date
+A5 /site/closed_auctions/closed_auction[descendant::keyword]/date
+A6 /site/people/person[profile/gender and profile/age]/name
+A7 /site/people/person[phone or homepage]/name
+A8 /site/people/person[address and (phone or homepage) and (creditcard or profile)]/name
+B1 /site/regions/*/item[parent::namerica or parent::samerica]/name
+B2 //keyword/ancestor::listitem/text/keyword
+B3 /site/open_auctions/open_auction/bidder[following-sibling::bidder]
+B4 /site/open_auctions/open_auction/bidder[preceding-sibling::bidder]
+B5 /site/regions/*/item[following::item]/name
+B6 /site/regions/*/item[preceding::item]/name
+B7 //person[profile/@income]/name
+B8 /site/open_auctions/open_auction[bidder and not(bidder/preceding-sibling::bidder)]/interval
+B9 /site/open_auctions/open_auction[(not(bidder/following::bidder) or not(bidder/preceding::bidder)) or (bidder/following::bidder and bidder/preceding::bidder)]/interval
+B10 /site/open_auctions/open_auction[(not(bidder/following::bidder) or not(bidder/preceding::bidder)) and (bidder/following::bidder and bidder/preceding::bidder)]/interval
+B11 //open_auction/bidder/../bidder/../bidder/../interval
+B12 //item/@id/../@id/../@id/../@id/../name
+B13 //keyword/ancestor::parlist/descendant::keyword/ancestor::parlist/descendant::keyword/ancestor::parlist/descendant::keyword