diff --git a/bindings/java/build-unix.xml b/bindings/java/build-unix.xml index 9699738f8e8d66a8d0a9f1f72ff24733c84ea38f..bdec8aaa7d3634094caeb2ec46117805345c665a 100644 --- a/bindings/java/build-unix.xml +++ b/bindings/java/build-unix.xml @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="windows-1252"?> <project name="TSKTestTargets"> <target name="test-precond" - description="Traverses the Images stored in the path represented by test-input variable, creates results files stored in the path represented by test-results, and compares them to the standards stored in the path represented by the test-standards variable, always run test-create-standards at least once before before running test." + description="Performs regression tests." depends="compile-test, copyTSKLibs"> <junit fork="on" haltonfailure="yes" dir="."> <sysproperty key="rslt" value="${test-results}"/> @@ -12,8 +12,9 @@ <test name="org.sleuthkit.datamodel.DataModelTestSuite" /> </junit> </target> - <target name="test-create-standards-precond" - description="Traverses the Images stored in the path represented by test-input variable and creates then stores them to the path represented by the test-standards variable, run test-download-imgs at least once before this." + + <target name="test-rebuild-precond" + description="Rebuilds regression tests." depends="compile-test, copyTSKLibs"> <java classname="org.sleuthkit.datamodel.DataModelTestSuite" classpathref="libraries" fork="true" failonerror="true"> <sysproperty key="gold" value="${test-standards}"/> diff --git a/bindings/java/build-windows.xml b/bindings/java/build-windows.xml index b2d7d2257b9a28b6d0fafb6a9c157df1769fceaa..1f5ad4675ff9af87166cc603bd732f3e0cdcc732 100644 --- a/bindings/java/build-windows.xml +++ b/bindings/java/build-windows.xml @@ -6,8 +6,9 @@ <isset property="env.LIBEWF_HOME"/> </condition> <property name="dlls" value="${env.LIBEWF_HOME}/msvscpp/zlib;${env.LIBEWF_HOME}/msvscpp/Release;../../win32/Release"/> + <target name="test-precond" - description="Traverses the Images stored in the path represented by test-input variable, creates results files stored in the path represented by test-results, and compares them to the standards stored in the path represented by the test-standards variable, always run test-create-standards at least once before before running test." + description="Runs the regression tests." depends="compile-test" > <fail unless="ewfFound" message="LIBEWF_HOME must be set as an environment variable."/> <junit fork="on" haltonfailure="yes" dir="."> @@ -20,8 +21,9 @@ <test name="org.sleuthkit.datamodel.DataModelTestSuite" /> </junit> </target> - <target name="test-create-standards-precond" - description="Traverses the Images stored in the path represented by test-input variable and creates then stores them to the path represented by the test-standards variable, run test-download-imgs at least once before this." + + <target name="test-rebuild-precond" + description="Rebuilds gold standards for tests." depends="compile-test" > <fail unless="ewfFound" message="LIBEWF_HOME must be set as an environment variable."/> <java classname="org.sleuthkit.datamodel.DataModelTestSuite" classpathref="libraries" fork="true" failonerror="true"> diff --git a/bindings/java/build.xml b/bindings/java/build.xml index cb00dc104d945933ced8d68e3aa9c5542d36ecce..c1315e072075cb9a48d50b5e8a14c6a4adc7dae7 100755 --- a/bindings/java/build.xml +++ b/bindings/java/build.xml @@ -112,17 +112,23 @@ pattern="lib/[artifact]-[revision](-[classifier]).[ext]" /> <mkdir dir="javadoc"/> <javadoc sourcepath="src" destdir="javadoc" overview="src/overview.html" /> </target> - <target name="test-download-imgs" description="Get test images and store them in the path represented by the test-input variable."> + + <target name="test-download" description="download test images."> <mkdir dir="${test-input}" /> <get src="http://digitalcorpora.org/corp/nps/drives/nps-2009-canon2/nps-2009-canon2-gen6.E01" dest="${test-input}"/> <get src="http://digitalcorpora.org/corp/nps/drives/nps-2009-ntfs1/ntfs1-gen2.E01" dest="${test-input}"/> + <!--<get src="http://www.cfreds.nist.gov/dfr-images/dfr-16-ext.dd.bz2" dest="${test-input}"/> + <bunzip2 src="${test-input}/dfr-16-ext.dd.bz2" /> --> </target> + + <!-- all of the work is done in test-precond --> <target name="test" - description="Traverses the Images stored in the path represented by test-input variable, creates results files stored in the path represented by test-results, and compares them to the standards stored in the path represented by the test-standards variable, always run test-create-standards at least once before before running test." - depends="compile-test, test-precond"> + description="Runs set of regression tests." + depends="compile-test, test-precond"> </target> - <target name="test-create-standards" - description="Traverses the Images stored in the path represented by test-input variable and creates then stores them to the path represented by the test-standards variable, run test-download-imgs at least once before this." - depends="compile-test, test-create-standards-precond"> + + <target name="test-rebuild" + description="Rebuilds gold standards." + depends="compile-test, test-rebuild-precond"> </target> </project> diff --git a/bindings/java/test/README.txt b/bindings/java/test/README.txt new file mode 100644 index 0000000000000000000000000000000000000000..5c08eaef1a0e05cc0b7cd4cde56b12e65ee33282 --- /dev/null +++ b/bindings/java/test/README.txt @@ -0,0 +1,11 @@ +This file describes the tests. There are several test that are run, including: +- TopDown that tests getChildren() on each object. +- BottomUp that tests getParent() on each object. +- Sequentail that tests accessing random objects. +- CPPvsJava that verifies that the C++ output is the same as Java. + +Not all test compare with a gold standard. Refer to each class for details. The following names are used in the output folder though: +- _TD: TopDown data that contains metadata about each file reached from getChildren(). This is checked in. +- _Seq: Sequentail test data that contains metadata about each file. This is checked in. +- _CPP: Body file format of files. This is not checked in. +- _BU: BottomUp data that contains paths to root from leaf nodes (i.e. files). This is not checked in. diff --git a/bindings/java/test/org/sleuthkit/datamodel/BottomUpTest.java b/bindings/java/test/org/sleuthkit/datamodel/BottomUpTest.java index 09ebae050d09e03b736919d067a85e2ccdc7242c..38db43ee8aca1644bac21195cd51397b9581e82e 100644 --- a/bindings/java/test/org/sleuthkit/datamodel/BottomUpTest.java +++ b/bindings/java/test/org/sleuthkit/datamodel/BottomUpTest.java @@ -30,10 +30,13 @@ import org.junit.runners.Parameterized; /** - * - * Verifies that getParent works as intended by verifying that it gets the - * same structure as we got from the TopDown tests. Does not compare against - * a gold standard. + * Performs a "Bottom Up" test by verifying that calls to getParent() are + * the same as calls to getChildren() from the root (i.e. the TopDown test). + * Does not compare against a gold standard. + * Basic concept is that TopDown test makes a "leaf file" + * with a line for each file that contains the list of parent IDs for the file. + * The code in this test starts at each leaf file, calls getParent() recursively, + * and verifies that the same IDs are reached. */ @RunWith(Parameterized.class) public class BottomUpTest { @@ -103,7 +106,7 @@ public void testBottomUpDiff() { } } catch (NumberFormatException ex) { System.out.println(ex.toString()); - fail("Failed to run BottomUp test"); + fail("Failed to run BottomUp test: " + ex.getMessage()); } catch (TskCoreException ex) { List<Exception> inp = new ArrayList<Exception>(); inp.add(ex); diff --git a/bindings/java/test/org/sleuthkit/datamodel/CPPtoJavaCompare.java b/bindings/java/test/org/sleuthkit/datamodel/CPPtoJavaCompare.java index f42894004e6d51ebfa52dbfdc98c4b50e056c07d..16b21e44bedb53df6a3e0201eedf606896ecb4d4 100644 --- a/bindings/java/test/org/sleuthkit/datamodel/CPPtoJavaCompare.java +++ b/bindings/java/test/org/sleuthkit/datamodel/CPPtoJavaCompare.java @@ -36,8 +36,10 @@ import org.junit.runners.Parameterized; /** - * - * Compares the Java test output to the C++ test output + * Compares the Java test output to the C++ test output. + * Basic concept is to run tsk_gettimes on an image to get the body + * file format and then make equivalent output from Java code. Diff. + * Does not use gold standards. */ @RunWith(Parameterized.class) public class CPPtoJavaCompare extends ImgTraverser { @@ -90,7 +92,7 @@ public void testCppToJavaDiff() { ret.add(DataModelTestSuite.comparecontent(goldFilePathSorted, outputFilePathSorted)); assertEquals("Java output (" + outputFilePathSorted + ") differ with C++ results (" + goldFilePathSorted + ") .", ret.get(0), true); } catch (Exception ex) { - fail("Couldn't open gold standard file."); + fail("Couldn't open gold standard file. " + ex.getMessage()); } } diff --git a/bindings/java/test/org/sleuthkit/datamodel/ImgTraverser.java b/bindings/java/test/org/sleuthkit/datamodel/ImgTraverser.java index eacb5b6fb199f608940be9ad968728aa3a42e718..7caf7eccff91380b84bf0e6e0775b5ac468f22aa 100644 --- a/bindings/java/test/org/sleuthkit/datamodel/ImgTraverser.java +++ b/bindings/java/test/org/sleuthkit/datamodel/ImgTraverser.java @@ -38,7 +38,7 @@ public abstract class ImgTraverser{ /** * Run a test and compare the unsorted results. * - * @return List of test results. Entry 0 is content and 1 is for exceptions. True if test passed. + * @return List of test results. Entry 0 is exceptions and 1 is for content. True if test passed. */ public List<Boolean> basicTest() { String title = DataModelTestSuite.getImgName(imagePaths.get(0)); @@ -51,7 +51,7 @@ public List<Boolean> basicTest() { goldFilePath = DataModelTestSuite.standardFilePath(imagePaths, this.testName); goldExceptionsPath = DataModelTestSuite.exceptionPath(goldFilePath); - // Generate the sorted output needed for the test + // Generate the sorted and unsorted output needed for the test DataModelTestSuite.createOutput(outputFilePath, outputFolder.getAbsolutePath(), imagePaths, this); // compare the unsorted results diff --git a/bindings/java/test/org/sleuthkit/datamodel/SequentialTraversal.java b/bindings/java/test/org/sleuthkit/datamodel/SequentialTraversal.java index 35b645709b06e842e616c5cc6ad2abb59f0f5ff9..c8d870704a29c04d4e1c2a784fc8fa3c72f6e57b 100644 --- a/bindings/java/test/org/sleuthkit/datamodel/SequentialTraversal.java +++ b/bindings/java/test/org/sleuthkit/datamodel/SequentialTraversal.java @@ -34,12 +34,13 @@ import org.junit.runners.Parameterized; /** - * - * Traverses an image by running through item Ids ascending. + * Tests that we get all of the results by directly requesting a specific + * object. Basic concept of test is to sequentially request objects, starting + * at 1. Details of each object are printed and results are compared with + * gold standard. */ @RunWith(Parameterized.class) public class SequentialTraversal extends ImgTraverser { - private static final Logger logg = Logger.getLogger(SequentialTraversal.class.getName()); public SequentialTraversal(List<String> imagePaths) { @@ -75,7 +76,7 @@ public void testSequentialDiff() { assertEquals("Generated results (" + outputExceptionsPath + ") differ with gold standard (" + goldExceptionsPath + ") .", test.get(0), true); assertEquals("Generated results (" + outputFilePath + ") differ with gold standard (" + goldFilePath + ") .", test.get(1), true); } catch (Exception ex) { - fail("Couldn't open gold standard file."); + fail("Couldn't open gold standard file." + ex.getMessage()); } } @@ -85,8 +86,6 @@ public void testSequentialDiff() { * * @param sk the sleuthkit case used for the traversal * @param path the location of the output file - * @param outputExceptionsPath the outputExceptionsPath to store exceptions, is only used for - * compatability with basic test * @return the file writer to be closed by testStandard */ @Override @@ -95,10 +94,14 @@ public OutputStreamWriter traverse(SleuthkitCase sk, String path) { try { Charset chr = Charset.forName("UTF-8"); OutputStreamWriter reslt = new OutputStreamWriter(new BufferedOutputStream(new FileOutputStream(path), 8192*4), chr); - int x = 1; - Content c; + try { - while ((c = sk.getContentById(x)) != null) { + for (int x = 1; ;x++) { + Content c = sk.getContentById(x); + if (c == null) { + break; + } + reslt.append(((AbstractContent) c).toString(false).replaceAll("paths \\[([A-z]:)?.+?\\]", "")); if (c instanceof File) { DataModelTestSuite.hashContent(c, reslt, outputExceptionsPath); diff --git a/bindings/java/test/org/sleuthkit/datamodel/TopDownTraversal.java b/bindings/java/test/org/sleuthkit/datamodel/TopDownTraversal.java index 63fbae36378ab235bffcb5b39761d4cf1f83a4ea..db879c941b81ef99072dc1ca49b424e6059bbd38 100644 --- a/bindings/java/test/org/sleuthkit/datamodel/TopDownTraversal.java +++ b/bindings/java/test/org/sleuthkit/datamodel/TopDownTraversal.java @@ -35,9 +35,9 @@ import org.junit.runners.Parameterized.Parameters; /** - * * Verifies that the current version of TSK produces the same output of previous * versions by doing a TopDown Depth first traversal of the given images. + * Compares data to gold standards. * Also generates the leaf file that is used by the BottomUp Test */ @RunWith(Parameterized.class) @@ -78,7 +78,7 @@ public void testTopDownDiff() { assertEquals("Generated results (" + outputExceptionsPath + ") differ with gold standard (" + goldExceptionsPath + ") .", test.get(0), true); assertEquals("Generated results (" + outputFilePath + ") differ with gold standard (" + goldFilePath + ") .", test.get(1), true); } catch (Exception ex) { - fail("Couldn't open gold standard file."); + fail("Couldn't open gold standard file. " + ex.getMessage()); } }