From ed9ca7439c835620e334fc5aea6896b7991cb213 Mon Sep 17 00:00:00 2001
From: Veronique Legrand <vlegrand@pasteur.fr>
Date: Tue, 31 May 2016 16:35:48 +0200
Subject: [PATCH] now check that the machine has enough memory before running
 tests that require it.

---
 src/unit_test_cms.cpp | 13 ++++++-----
 test/Makefile.am      |  2 +-
 test/rock.sh          | 52 +++++--------------------------------------
 3 files changed, 15 insertions(+), 52 deletions(-)

diff --git a/src/unit_test_cms.cpp b/src/unit_test_cms.cpp
index 50093df..3ae712c 100644
--- a/src/unit_test_cms.cpp
+++ b/src/unit_test_cms.cpp
@@ -81,16 +81,19 @@ int main(int argc, char **argv) {
 
     cout<<"checking that your machine has enough RAM to run test"<<endl;
     unsigned long ram=getNodePhysMemory();
+    cout<<"machine has: "<<ram<<" GB of RAM"<<endl;
 
     if (ram<5) {
         cout<<"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"<<endl;
         cout<<" WARNING: skipping this test, it requires at least 4 gigabytes of RAM to run."<<endl;
         cout<<"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"<<endl;
-        return 0;
+        return -1;
     }
-
-    cout<<"testing CMS with lambda="<<lambda<<endl;
-    test_CMS(lambda,kappa,kappa_prime); // Finally using C arrays (maps implied storing hash keys : 4 Bytes per k_mer overhead) but each array is of size INT_MAX...
     
-    cout<<"done"<<endl;
+    if (argc==1) {
+        cout<<"testing CMS with lambda="<<lambda<<endl;
+        test_CMS(lambda,kappa,kappa_prime); // Finally using C arrays (maps implied storing hash keys : 4 Bytes per k_mer overhead) but each array is of size INT_MAX...
+        cout<<"done"<<endl;
+    }
+    return 0;
 }
diff --git a/test/Makefile.am b/test/Makefile.am
index 7e30e82..234b737 100755
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -4,6 +4,6 @@ LOG_COMPILER = $(SHELL)
 
 TESTS = rock.sh
 
-EXTRA_DIST = $(TESTS) data/extract_klebsiella_long_reads_100.txt data/extract_klebsiella_long_reads_100_filtered.txt data/fastq.raw/klebsiella_100_1.fq data/fastq.raw/klebsiella_100_2.fq data/unit/klebsiella_PE1.fq data/unit/klebsiella_PE2.fq data/unit/test_PE1.fq data/unit/test_PE2.fq data/unit/test_PE1_2.fq data/unit/test_PE2_2.fq data/unit/test_single2.fq data/unit/test_single.fq data/unit/list_input1.txt data/unit/list_output1.txt data/unit/list_input2.txt data/unit/list_output2.txt data/unit/list_input3.txt data/unit/list_output3.txt
+EXTRA_DIST = $(TESTS) rock_mem.sh data/extract_klebsiella_long_reads_100.txt data/extract_klebsiella_long_reads_100_filtered.txt data/fastq.raw/klebsiella_100_1.fq data/fastq.raw/klebsiella_100_2.fq data/unit/klebsiella_PE1.fq data/unit/klebsiella_PE2.fq data/unit/test_PE1.fq data/unit/test_PE2.fq data/unit/test_PE1_2.fq data/unit/test_PE2_2.fq data/unit/test_single2.fq data/unit/test_single.fq data/unit/list_input1.txt data/unit/list_output1.txt data/unit/list_input2.txt data/unit/list_output2.txt data/unit/list_input3.txt data/unit/list_output3.txt
 
 
diff --git a/test/rock.sh b/test/rock.sh
index 649fdbf..cf75e52 100755
--- a/test/rock.sh
+++ b/test/rock.sh
@@ -53,48 +53,12 @@ echo "doing more checks on options and error messages"
 ../src/rock -C 500 -c 400 -k 10 -g 10000 -i ${srcdir}/data/extract_klebsiella_long_reads_100.txt -o ${srcdir}/data/extract_klebsiella_long_reads_100_filtered.txt|grep "This machine only has" >/dev/null || exit 13
 ../src/rock -C 500 -c 400 -k 10 -l 12 -n 85000000 -i ${srcdir}/data/extract_klebsiella_long_reads_100.txt -o ${srcdir}/data/extract_klebsiella_long_reads_100_filtered.txt|grep "options are mutually exclusive">/dev/null || exit 14
 
-## do real work
-## Test high filter
-echo " "
-echo "##################################################################################"
-echo "testing high filter"
-
-#echo "I want to check if I can write to a file ">../test/data/fastq.filtered/SRR1222430_1.filtered.fastq
-#cat ../test/data/fastq.filtered/SRR1222430_1.filtered.fastq
-../src/rock -C 100 -l 2 -i ${srcdir}/data/extract_klebsiella_long_reads_100.txt -o ${srcdir}/data/extract_klebsiella_long_reads_100_filtered.txt >/dev/null || exit 15
-# output files should be the same size, contain the same elements but not in the same order.
-nb_PE1=`grep -c "@" ${srcdir}/data/fastq.raw/klebsiella_100_1.fq`
-nb_PE2=`grep -c "@" ${srcdir}/data/fastq.raw/klebsiella_100_2.fq`
-
-
-ls -l ${srcdir}/
-ls -l ${srcdir}/data/
-ls -l data/fastq.filtered/
-
-[ -f "data/fastq.filtered/SRR1222430_1.filtered.fastq" ] || exit 151
-[ -f "data/fastq.filtered/SRR1222430_2.filtered.fastq" ] || exit 152
-
-nb_PE1_filtered=`grep -c "@" data/fastq.filtered/SRR1222430_1.filtered.fastq`
-nb_PE2_filtered=`grep -c "@" data/fastq.filtered/SRR1222430_2.filtered.fastq`
-
-test $nb_PE1=$nb_PE1_filtered || exit 16
-test $nb_PE2=$nb_PE2_filtered || exit 17
-
-# test low filter.
-echo " "
-echo "##################################################################################"
-echo "testing low filter"
-../src/rock -C 100 -c 99 -l 2 -i ${srcdir}/data/extract_klebsiella_long_reads_100.txt -o ${srcdir}/data/extract_klebsiella_long_reads_100_filtered.txt >/dev/null || exit 18
-
-[ -f "data/fastq.filtered/SRR1222430_1.filtered.fastq" ] || exit 181
-[ -f "data/fastq.filtered/SRR1222430_2.filtered.fastq" ] || exit 182
-
-nb_PE1_filtered=`grep -c "@" data/fastq.filtered/SRR1222430_1.filtered.fastq`
-nb_PE2_filtered=`grep -c "@" data/fastq.filtered/SRR1222430_2.filtered.fastq`
-
-test $nb_PE1_filtered=0 || exit 19
-test $nb_PE2_filtered=0 || exit 20
-
+# here check that we have enough memory for running the tests.
+../src/unit_test_cms CHECK_MEM
+if [ $? == 0 ] ## we have enough memory to run the tests in rock_mem.sh
+then 
+    ${srcdir}/rock_mem.sh
+fi
 
 # unit tests
 echo " "
@@ -108,10 +72,6 @@ echo "##########################################################################
 echo "unit testing for read utils"
 ../src/unit_test_read_utils || exit 23
 
-echo " "
-echo "##################################################################################"
-echo "unit testing for cms component"
-../src/unit_test_cms || exit 24
 
 echo " "
 echo "##################################################################################"
-- 
GitLab