diff options
author | Yann Collet <cyan@fb.com> | 2018-01-15 00:57:25 (GMT) |
---|---|---|
committer | Yann Collet <cyan@fb.com> | 2018-01-15 00:57:25 (GMT) |
commit | b077a99347a384225d03f5458c2b57bedb134c62 (patch) | |
tree | ca1440d172263fcb4964f7b5e8cb6ba8a3072b9b | |
parent | dfed9fa1d77f0434306d377c4da1f7191d3ba08a (diff) | |
download | lz4-b077a99347a384225d03f5458c2b57bedb134c62.zip lz4-b077a99347a384225d03f5458c2b57bedb134c62.tar.gz lz4-b077a99347a384225d03f5458c2b57bedb134c62.tar.bz2 |
added checkTag
checkTag verifies that provided tag and library version match.
It's started automatically in circleCI when a new tag is created.
-rw-r--r-- | .travis.yml | 8 | ||||
-rw-r--r-- | tests/.gitignore | 1 | ||||
-rw-r--r-- | tests/Makefile | 5 | ||||
-rw-r--r-- | tests/checkTag.c | 79 |
4 files changed, 92 insertions, 1 deletions
diff --git a/.travis.yml b/.travis.yml index 3353dee..9dea485 100644 --- a/.travis.yml +++ b/.travis.yml @@ -145,7 +145,15 @@ matrix: - gcc-multilib - gcc-4.4 + # tag-specific test + - if: tag =~ ^v[0-9]\.[0-9] + os: linux + sudo: false + env: Cmd="make -C tests checkTag && tests/checkTag $TRAVIS_BRANCH " COMPILER=cc + + script: + - uname -a - echo Cmd=$Cmd - $COMPILER -v - sh -c "$Cmd" diff --git a/tests/.gitignore b/tests/.gitignore index 4c0f311..36dff42 100644 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -8,6 +8,7 @@ fullbench32 fuzzer fuzzer32 fasttest +checkTag # test artefacts tmp* diff --git a/tests/Makefile b/tests/Makefile index 819ba43..ddc0d2e 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -111,7 +111,7 @@ clean: fullbench$(EXT) fullbench32$(EXT) \ fuzzer$(EXT) fuzzer32$(EXT) \ frametest$(EXT) frametest32$(EXT) \ - fasttest$(EXT) datagen$(EXT) + fasttest$(EXT) datagen$(EXT) checkTag$(EXT) @rm -fR $(TESTDIR) @echo Cleaning completed @@ -119,6 +119,9 @@ clean: versionsTest: $(PYTHON) test-lz4-versions.py +checkTag: checkTag.c $(LZ4DIR)/lz4.h + $(CC) $(FLAGS) $< -o $@$(EXT) + #----------------------------------------------------------------------------- # validated only for Linux, OSX, BSD, Hurd and Solaris targets diff --git a/tests/checkTag.c b/tests/checkTag.c new file mode 100644 index 0000000..4a33415 --- /dev/null +++ b/tests/checkTag.c @@ -0,0 +1,79 @@ +/* + checkTag.c - Version validation tool for LZ4 + Copyright (C) Yann Collet 2018 - present + + GPL v2 License + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + + You can contact the author at : + - LZ4 homepage : http://www.lz4.org + - LZ4 source repo : https://github.com/lz4/lz4 +*/ + +/* checkTag command : + * $ ./checkTag tag + * checkTag validates tags of following format : v[0-9].[0-9].[0-9]{any} + * The tag is then compared to LZ4 version number. + * They are compatible if first 3 digits are identical. + * Anything beyond that is free, and doesn't impact validation. + * Example : tag v1.8.1.2 is compatible with version 1.8.1 + * When tag and version are not compatible, program exits with error code 1. + * When they are compatible, it exists with a code 0. + * checkTag is intended to be used in automated testing environment. + */ + +#include <stdio.h> /* printf */ +#include <string.h> /* strlen, strncmp */ +#include "lz4.h" /* LZ4_VERSION_STRING */ + + +/* validate() : + * @return 1 if tag is compatible, 0 if not. + */ +static int validate(const char* const tag) +{ + size_t const tagLength = strlen(tag); + size_t const verLength = strlen(LZ4_VERSION_STRING); + + if (tagLength < 2) return 0; + if (tag[0] != 'v') return 0; + if (tagLength <= verLength) return 0; + + if (strncmp(LZ4_VERSION_STRING, tag+1, verLength)) return 0; + + return 1; +} + +int main(int argc, const char** argv) +{ + const char* const exeName = argv[0]; + const char* const tag = argv[1]; + if (argc!=2) { + printf("incorrect usage : %s tag \n", exeName); + return 2; + } + + printf("Version : %s \n", LZ4_VERSION_STRING); + printf("Tag : %s \n", tag); + + if (validate(tag)) { + printf("OK : tag is compatible with lz4 version \n"); + return 0; + } + + printf("!! error : tag and versions are not compatible !! \n"); + return 1; +} |