]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
Preparing to run tests
authorCarl Woffenden <cwoffenden@gmail.com>
Sun, 25 Aug 2019 20:49:01 +0000 (22:49 +0200)
committerCarl Woffenden <cwoffenden@gmail.com>
Sun, 25 Aug 2019 20:49:01 +0000 (22:49 +0200)
Combine script more robust and can output to a specified file. Initial buck files added (work in progress).

contrib/declib/BUCK [new file with mode: 0644]
contrib/declib/README.md
contrib/declib/combine.sh
contrib/declib/tests/BUCK [new file with mode: 0644]
contrib/declib/tests/simple.c
contrib/declib/zstddeclib-in.c

diff --git a/contrib/declib/BUCK b/contrib/declib/BUCK
new file mode 100644 (file)
index 0000000..e04f5e8
--- /dev/null
@@ -0,0 +1,11 @@
+sh_test(
+    name='combine',
+    visibility=['PUBLIC'],
+    test='combine.sh',
+    args=[
+        '-r', '../../lib',
+        '-r', '../../lib/common',
+        '-r', '../../lib/decompress',
+        '-o', 'zstddeclib.c',
+        'zstddeclib-in.c']
+)
index 727b3e8fa7e377814fffe873e22d159c9232f8ba..bb22c2423c18ca35d37c29dee24e5bc8cc7e915a 100644 (file)
@@ -3,6 +3,6 @@
 Create the file using the shell script:
 ```
 cd zstd/contrib/declib
-./combine.sh -r "../../lib ../../lib/common ../../lib/decompress" zstddeclib-in.c > zstddeclib.c
+./combine.sh -r ../../lib -r ../../lib/common -r ../../lib/decompress -o zstddeclib.c zstddeclib-in.c
 ```
 Then add the resulting file to your project (see the [test sources](tests) for examples).
index ba05028bada8f938fe9f6bf2acdf9ff78b2e463e..b95977e32f51dbc9b895ed305761c287528f48af 100755 (executable)
@@ -1,6 +1,8 @@
 #!/bin/bash
 
 # Tool to bundle multiple C/C++ source files, inlining any includes.
+# 
+# TODO: ROOTS and FOUND as arrays (since they fail on paths with spaces)
 
 # Common file roots
 ROOTS="./"
@@ -8,11 +10,15 @@ ROOTS="./"
 # Files previously visited
 FOUND=""
 
+# Optional destination file (empty string to write to stdout)
+DESTN=""
+
 # Prints the script usage then exits
 function usage {
-  echo "Usage: $0 [-r <paths>] infile"
+  echo "Usage: $0 [-r <path>] [-o <outfile>] infile"
   echo "  -r file root search paths"
-  echo "Example: $0 -r \"../my/path ../my/other\" in.c > out.c"
+  echo "  -o output file (otherwise stdout)"
+  echo "Example: $0 -r ../my/path - r ../other/path -o out.c in.c"
   exit 1
 }
 
@@ -26,6 +32,15 @@ function list_has_item {
   return 1
 }
 
+# Adds a new line with the supplied arguments to $DESTN (or stdout)
+function write_line {
+  if [ -n "$DESTN" ]; then
+    printf "%s\n" "$@" >> "$DESTN"
+  else
+    printf "%s\n" "$@"
+  fi
+}
+
 # Adds the contents of $1 with any of its includes inlined
 function add_file {
   # Match the path
@@ -35,7 +50,7 @@ function add_file {
       file="$root/$1"
     fi
   done
-  if [ "$file" != "" ]; then
+  if [ -n "$file" ]; then
     # Read the file
     local line
     while IFS= read -r line; do
@@ -45,26 +60,29 @@ function add_file {
         if ! `list_has_item "$FOUND" "$inc"`; then
           # And we've not previously encountered it
           FOUND="$FOUND $inc"
-          echo "/**** start inlining $inc ****/"
+          write_line "/**** start inlining $inc ****/"
           add_file "$inc"
-          echo "/**** ended inlining $inc ****/"
+          write_line "/**** ended inlining $inc ****/"
         else
-          echo "/**** skipping file: $inc ****/"
+          write_line "/**** skipping file: $inc ****/"
         fi
       else
         # Otherwise write the source line
-        echo "$line"
+        write_line "$line"
       fi
     done < "$file"
   else
-    echo "#error Unable to find \"$1\""
+    write_line "#error Unable to find \"$1\""
   fi
 }
 
-while getopts ":r:" opts; do
+while getopts ":r:o:" opts; do
   case $opts in
   r)
-    ROOTS="$ROOTS $OPTARG"
+    ROOTS="$OPTARG $ROOTS"
+    ;;
+  o)
+    DESTN="$OPTARG"
     ;;
   *)
     usage
@@ -73,8 +91,17 @@ while getopts ":r:" opts; do
 done
 shift $((OPTIND-1))
 
-if [ "$1" != "" ]; then
-  add_file $1
+if [ -n "$1" ]; then
+  if [ -f "$1" ]; then
+    if [ -n "$DESTN" ]; then
+      printf "" > "$DESTN"
+    fi
+    add_file $1
+  else
+    echo "Input file not found: '$1'"
+    exit 1
+  fi
 else
   usage
 fi
+exit 0
diff --git a/contrib/declib/tests/BUCK b/contrib/declib/tests/BUCK
new file mode 100644 (file)
index 0000000..9e3621a
--- /dev/null
@@ -0,0 +1,5 @@
+cxx_test(
+    name='simple',
+    srcs=['simple.c'],
+    deps=['//contrib/declib:combine']
+)
index cb200c9381c5be85f1610ecd1ed166c726518c83..2dda4b06e60451e07f20a65a8b1c328aa998bce4 100644 (file)
@@ -3385,8 +3385,12 @@ size_t ZSTD_decompress(void* dst, size_t dstLen, const void* src, size_t srcLen)
  * the binary by 74kB.
  */
 int main() {
-       size_t bytes = ZSTD_decompress(dstDxt1, sizeof dstDxt1, srcZstd, sizeof srcZstd);
-       printf("Decompressed size: %ld (expected %ld)\n", bytes, sizeof dstDxt1);
-       printf("Byte comparison: %s\n", (memcmp(rawDxt1, dstDxt1, sizeof dstDxt1)) ? "failed" : "succeeded");
-       return 0;
+       size_t size = ZSTD_decompress(dstDxt1, sizeof dstDxt1, srcZstd, sizeof srcZstd);
+       int compare = memcmp(rawDxt1, dstDxt1, sizeof dstDxt1);
+       printf("Decompressed size: %ld (expected %ld)\n", size, sizeof dstDxt1);
+       printf("Byte comparison: %s\n", (compare) ? "failed" : "succeeded");
+       if (size == sizeof dstDxt1 && compare == 0) {
+               return EXIT_SUCCESS;
+       }
+       return EXIT_FAILURE;
 }
index 73320af7fc15fb6bf9b8b630424a613af5f87d2a..e0c8d51a02827b78c4abf8524c396b0d8b136bce 100755 (executable)
@@ -4,7 +4,7 @@
  * 
  * Generate using:
  * \code
- *     combine.sh -r "../../lib ../../lib/common ../../lib/decompress" zstddeclib-in.c > zstddeclib.c
+ *     combine.sh -r ../../lib -r ../../lib/common -r ../../lib/decompress -o zstddeclib.c zstddeclib-in.c
  * \endcode
  */
 /*