Fixed code based on comments from pull request
authorJennifer Liu <jenniferliu620@fb.com>
Wed, 27 Jun 2018 00:31:15 +0000 (17:31 -0700)
committerJennifer Liu <jenniferliu620@fb.com>
Wed, 27 Jun 2018 00:31:15 +0000 (17:31 -0700)
programs/bench.c
programs/lz4cli.c
tests/Makefile

index 1ab1b92..770191c 100644 (file)
@@ -407,6 +407,8 @@ static void BMK_benchCLevel(void* srcBuffer, size_t benchedSize,
     if (g_displayLevel == 1 && !g_additionalParam)
         DISPLAY("bench %s %s: input %u bytes, %u seconds, %u KB blocks\n", LZ4_VERSION_STRING, LZ4_GIT_COMMIT_STRING, (U32)benchedSize, g_nbSeconds, (U32)(g_blockSize>>10));
 
+    if (cLevelLast < cLevel) cLevelLast = cLevel;
+
     for (l=cLevel; l <= cLevelLast; l++) {
         BMK_benchMem(srcBuffer, benchedSize,
                      displayName, l,
index 94e3b14..669b585 100644 (file)
@@ -288,8 +288,6 @@ static unsigned longCommandWArg(const char** stringPtr, const char* longCommand)
 
 typedef enum { om_auto, om_compress, om_decompress, om_test, om_bench } operationMode_e;
 
-#define CLEAN_RETURN(i) { operationResult = (i); goto _cleanup; }
-
 int main(int argc, const char** argv)
 {
     int i,
@@ -380,7 +378,7 @@ int main(int argc, const char** argv)
                 if (!strcmp(argument,  "--keep")) { LZ4IO_setRemoveSrcFile(0); continue; }   /* keep source file (default) */
                 if (!strcmp(argument,  "--rm")) { LZ4IO_setRemoveSrcFile(1); continue; }
                 if (longCommandWArg(&argument, "--fast")) {
-                        /* Parse optional window log */
+                        /* Parse optional acceleration factor */
                         if (*argument == '=') {
                             U32 fastLevel;
                             ++argument;
@@ -388,9 +386,12 @@ int main(int argc, const char** argv)
                             if (fastLevel) {
                               cLevel = -(int)fastLevel;
                             }
+                            else {
+                              badusage(exeName);
+                            }
                         } else if (*argument != 0) {
                             /* Invalid character following --fast */
-                            CLEAN_RETURN(badusage(exeName));
+                            badusage(exeName);
                         } else {
                             cLevel = -1;  /* default for --fast */
                         }
index 70e1864..abaf648 100644 (file)
@@ -262,9 +262,14 @@ test-lz4-basic: lz4 datagen unlz4 lz4cat
        cat tmp-tlb-hw >> tmp-tlb-hw.lz4
        $(LZ4) -f tmp-tlb-hw.lz4               # uncompress valid frame followed by invalid data
        $(LZ4) -BX tmp-tlb-hw -c -q | $(LZ4) -tv  # test block checksum
-       test "$(shell ./datagen -g20KB | $(LZ4) -c --fast | wc -c)" -lt "$(shell ./datagen -g20KB | $(LZ4) -c --fast=9 | wc -c)" # compressed size of compression level -1 should be lower than -9
+       # ./datagen -g20KB generates the same file every single time
+       # cannot save output of ./datagen -g20KB as input file to lz4 because the following shell commands are run before ./datagen -g20KB
+       test "$(shell ./datagen -g20KB | $(LZ4) -c --fast | wc -c)" -lt "$(shell ./datagen -g20KB | $(LZ4) -c --fast=9 | wc -c)" # -1 vs -9
        test "$(shell ./datagen -g20KB | $(LZ4) -c --fast=1 | wc -c)" -eq "$(shell ./datagen -g20KB| $(LZ4) -c --fast| wc -c)" # checks default fast compression is -1
-       test "$(shell ./datagen -g20KB | $(LZ4) -c -9 | wc -c)" -lt "$(shell ./datagen -g20KB| $(LZ4) -c --fast=1 | wc -c)" # compressed size of compression level 9 should be lower than -1
+       test "$(shell ./datagen -g20KB | $(LZ4) -c -3 | wc -c)" -lt "$(shell ./datagen -g20KB| $(LZ4) -c --fast=1 | wc -c)" # 3 vs -1
+       test "$(shell ./datagen -g20KB | $(LZ4) -c -1 | wc -c)" -lt "$(shell ./datagen -g20KB| $(LZ4) -c --fast=2 | wc -c)" # 1 vs -2
+       test "$(shell $(LZ4) -c --fast=0 tmp-tlb-dg20k | wc -c)" -eq 0 # lz4 should fail when fast=0
+       test "$(shell $(LZ4) -c --fast=-1 tmp-tlb-dg20k | wc -c)" -eq 0 # lz4 should fail when fast=-1
        @$(RM) tmp-tlb*