Add more tests (broken, needs a refactoring of the build script)
authorKim Nguyễn <kn@lri.fr>
Wed, 24 Jul 2013 15:21:56 +0000 (17:21 +0200)
committerKim Nguyễn <kn@lri.fr>
Wed, 24 Jul 2013 15:21:56 +0000 (17:21 +0200)
Remakefile.in
tools/ocamlmoduledep.sh [new file with mode: 0755]
tools/split_path.ml [new file with mode: 0644]

index e599827..8f6dbb7 100644 (file)
@@ -21,7 +21,7 @@ OCAMLYACC = @OCAMLYACC@
 
 all: $(BIN)
 
 
 all: $(BIN)
 
-tools: tools/xml_diff.native$(EXE) tools/XPathEval.class
+tools: tools/xml_diff.native$(EXE) tools/XPathEval.class tools/split_path.native$(EXE)
 
 Remakefile: Remakefile.in config.status
        ./config.status Remakefile
 
 Remakefile: Remakefile.in config.status
        ./config.status Remakefile
@@ -59,7 +59,7 @@ distclean: clean test_clean
        base=$*
        src=${base}.ml
        obj=${base}.cmx
        base=$*
        src=${base}.ml
        obj=${base}.cmx
-       dir=`dirname "$@"`
+       dir=src
        $(REMAKE) -v OCAMLDEPNATIVE=-native "$obj"
        srcs=`ls "$dir"/*.cmx | sed 's/\.cmx/.ml/g'`
        objs=`$(OCAMLDEP) $(OCAMLDEPNATIVE) $(OCAMLFINDFLAGS) -modules $srcs | tools/osort.sh cmx`
        $(REMAKE) -v OCAMLDEPNATIVE=-native "$obj"
        srcs=`ls "$dir"/*.cmx | sed 's/\.cmx/.ml/g'`
        objs=`$(OCAMLDEP) $(OCAMLDEPNATIVE) $(OCAMLFINDFLAGS) -modules $srcs | tools/osort.sh cmx`
@@ -69,7 +69,7 @@ distclean: clean test_clean
        base=$*
        src=${base}.ml
        obj=${base}.cmo
        base=$*
        src=${base}.ml
        obj=${base}.cmo
-       dir=`dirname "$@"`
+       dir=src
        $(REMAKE) "$obj"
        objs=""
        for i in "$dir"/*.cmi; do
        $(REMAKE) "$obj"
        objs=""
        for i in "$dir"/*.cmi; do
@@ -157,22 +157,22 @@ distclean: clean test_clean
 
 ## Tests
 
 
 ## Tests
 
-test:
+test: tools $(BIN)
        for i in tests/*.xml
        do
        for i in tests/*.xml
        do
-         for j in 1 2
+         for j in 1 2 3
          do
                $(REMAKE) "$i".test"$j".summary
          done
        done
 
 test_clean:
          do
                $(REMAKE) "$i".test"$j".summary
          done
        done
 
 test_clean:
-       rm -rf tests/*.summary tests/*.results/*_"$(PACKAGE)".*
+       rm -rf tests/*.summary tests/*.results/*_"$(PACKAGE)"_*.*
 
 %.test1.summary:
                base="$@"
                base=${base%.xml.test1.summary}
 
 %.test1.summary:
                base="$@"
                base=${base%.xml.test1.summary}
-               $(REMAKE) "$base".xml "$base".xml.queries tools "$(BIN)"
+               $(REMAKE) "$base".xml "$base".xml.queries
                rm -f "$@"
                MSG="Test 1 (single query: tatoo vs java implementation)" 
                echo "$MSG" >> "$@"
                rm -f "$@"
                MSG="Test 1 (single query: tatoo vs java implementation)" 
                echo "$MSG" >> "$@"
@@ -182,9 +182,11 @@ test_clean:
                        REF="$base".xml.results/"$q"_jaxp.xml
                        $(REMAKE) "$REF"
                        OUTPUT="$base".xml.results/"$q"_"$(PACKAGE)"_test1.xml
                        REF="$base".xml.results/"$q"_jaxp.xml
                        $(REMAKE) "$REF"
                        OUTPUT="$base".xml.results/"$q"_"$(PACKAGE)"_test1.xml
-                       LOG="$base".xml.results/"$q"_"$(PACKAGE)".log
+                       LOG="$base".xml.results/"$q"_"$(PACKAGE)"_test1.log
+                       cp "$@" /tmp
                        src/@PACKAGE_TARNAME@.native@EXE@ -s -d "$base".xml \
                                "$query" -o "$OUTPUT" > "$LOG" 2>&1
                        src/@PACKAGE_TARNAME@.native@EXE@ -s -d "$base".xml \
                                "$query" -o "$OUTPUT" > "$LOG" 2>&1
+                       cp "$@" /tmp
                        echo "Query: $q : $query" >> "$@"
                        cat  "$LOG" | grep '^STATS' >> "$@"
                        echo -n "Diff: " >> "$@"
                        echo "Query: $q : $query" >> "$@"
                        cat  "$LOG" | grep '^STATS' >> "$@"
                        echo -n "Diff: " >> "$@"
@@ -202,7 +204,7 @@ test_clean:
 %.test2.summary:
                base="$@"
                base=${base%.xml.test2.summary}
 %.test2.summary:
                base="$@"
                base=${base%.xml.test2.summary}
-               $(REMAKE) "$base".xml "$base".xml.queries tools "$(BIN)"
+               $(REMAKE) "$base".xml "$base".xml.queries
                rm -f "$@"
                MSG="Test 2 (all queries sequentially vs all queries in parallel)"
                echo "$MSG" >> "$@"
                rm -f "$@"
                MSG="Test 2 (all queries sequentially vs all queries in parallel)"
                echo "$MSG" >> "$@"
@@ -232,3 +234,41 @@ test_clean:
                        exit 1
                fi
                echo '-------------------------------------------' >> "$@"
                        exit 1
                fi
                echo '-------------------------------------------' >> "$@"
+
+%.test3.summary:
+               base="$@"
+               base=${base%.xml.test3.summary}
+               $(REMAKE) "$base".xml "$base".xml.queries
+               rm -f "$@"
+               MSG="Test 3 (multiple queries composition: sequential vs parallel)" 
+               echo "$MSG" >> "$@"
+               echo "$MSG"
+               cat "$base".xml.queries | grep -v '^#' | while read q query; do
+                       echo -n "$base"".xml $q $query ... sequential ... "
+                       OUTPUTA="$base".xml.results/"$q"_"$(PACKAGE)"_test3a.xml
+                       LOG="$base".xml.results/"$q"_"$(PACKAGE)"_test3a.log
+                       src/@PACKAGE_TARNAME@.native@EXE@ -s -d -C "$base".xml \
+                                -o "$OUTPUTA" $(src/split_path.native$(EXE) "$query") > "$LOG" 2>&1
+                       echo "Query: $q : $query" >> "$@"
+                       cat  "$LOG" | grep '^STATS' >> "$@"
+
+                       echo -n "parallel ... "
+                       OUTPUTB="$base".xml.results/"$q"_"$(PACKAGE)"_test3a.xml
+                       LOG="$base".xml.results/"$q"_"$(PACKAGE)"_test3a.log
+                       src/@PACKAGE_TARNAME@.native@EXE@ -s -d -p -C "$base".xml \
+                                -o "$OUTPUTB" $(src/split_path.native$(EXE) "$query") > "$LOG" 2>&1
+                       echo "Query: $q : $query" >> "$@"
+                       cat  "$LOG" | grep '^STATS' >> "$@"
+
+
+                       echo -n "Diff: " >> "$@"
+                       if diff  "$OUTPUTA" "$OUTPUTB" >/dev/null 2>&1; then
+                               echo ok
+                               echo ok >> "$@"
+                       else
+                               echo failed
+                               echo failed >> "$@"
+                               exit 1
+                       fi
+                       echo '-------------------------------------------' >> "$@"
+               done
diff --git a/tools/ocamlmoduledep.sh b/tools/ocamlmoduledep.sh
new file mode 100755 (executable)
index 0000000..3102e1e
--- /dev/null
@@ -0,0 +1,57 @@
+#!/bin/sh
+
+
+PROG="$0"
+CMDLINE="$*"
+usage() {
+    echo "$PROG [-native] [-I dir .. -I dir] Module"
+}
+
+INCLUDES=""
+MODULE=""
+NATIVE=0
+while true; do
+    case $1 in
+        -I)
+            dir=`echo "$2" | sed "s:^+:$(ocamlc -where)/:"`
+            INCLUDES="$INCLUDES
+$2"
+            shift
+            ;;
+        -native)
+            NATIVE=1
+            ;;
+        [A-Z]*)
+            if test -z "$MODULE"; then
+                MODULE=$1
+            else
+                usage
+                exit 1
+            fi
+            ;;
+        *)
+            echo "ERROR: '$1'"
+            usage
+            exit 2
+            ;;
+    esac
+    shift
+    if test "$#" -eq 0; then break; fi
+done
+module="$(echo $MODULE | cut -b1 | tr A-Z a-z)$(echo $MODULE | cut -b2-)"
+if test "$NATIVE" = "1"; then
+    ext=cmx
+else
+    ext=cmo
+fi
+
+echo "$INCLUDES" | while read include; do
+    base="$include/$module"
+    if test -f "$base".ml -o -f "$base".mly -o -f "$base".mll -o -d "$base"; then
+        echo "$base"."$ext"
+        break
+    elif test -f "$base".mli; then
+        echo "$base".cmi
+        break
+    fi
+done
diff --git a/tools/split_path.ml b/tools/split_path.ml
new file mode 100644 (file)
index 0000000..65a93cb
--- /dev/null
@@ -0,0 +1,30 @@
+let parse q =
+  let p = Xpath.Parser.parse (Ulexing.from_utf8_string q) in
+  match p with
+    [ _ ] ->
+      List.map (fun p ->
+        let steps =
+          match p with
+            Xpath.Ast.Absolute l
+          | Xpath.Ast.Relative l ->  l
+        in
+        let nl =
+          List.map (fun s ->
+            let _ = Format.flush_str_formatter () in
+            Xpath.Ast.print_step Format.str_formatter s;
+            Format.flush_str_formatter()) steps
+        in
+        nl) p
+  | _ -> let _ = Format.flush_str_formatter () in
+         Xpath.Ast.print_path Format.str_formatter p;
+         [[ Format.flush_str_formatter() ]]
+
+let main () =
+  if Array.length Sys.argv <> 2 then exit 1
+  else
+    let l = parse Sys.argv.(1) in
+    List.iter (fun s ->  Printf.printf "'%s' " s) (List.hd l);
+    Printf.printf "\n%!"
+
+let () = main ()
+