Skip to content

Commit f6e17b8

Browse files
committed
added tests/checkTag
compared provided tag with current libzstd version
1 parent 4792ac6 commit f6e17b8

File tree

3 files changed

+71
-1
lines changed

3 files changed

+71
-1
lines changed

tests/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ decodecorpus
2323
pool
2424
poolTests
2525
invalidDictionaries
26+
checkTag
2627

2728
# Tmp test directory
2829
zstdtest

tests/Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,9 +236,13 @@ endif
236236
poolTests : poolTests.c $(ZSTDDIR)/common/pool.c $(ZSTDDIR)/common/threading.c $(ZSTDDIR)/common/zstd_common.c $(ZSTDDIR)/common/error_private.c
237237
$(CC) $(FLAGS) $(MULTITHREAD) $^ -o $@$(EXT)
238238

239+
.PHONY: versionsTest
239240
versionsTest: clean
240241
$(PYTHON) test-zstd-versions.py
241242

243+
checkTag: checkTag.c $(ZSTDDIR)/zstd.h
244+
$(CC) $(FLAGS) $< -o $@$(EXT)
245+
242246
clean:
243247
$(MAKE) -C $(ZSTDDIR) clean
244248
@$(RM) -fR $(TESTARTEFACT)
@@ -251,7 +255,7 @@ clean:
251255
zstreamtest$(EXT) zstreamtest32$(EXT) \
252256
datagen$(EXT) paramgrill$(EXT) roundTripCrash$(EXT) longmatch$(EXT) \
253257
symbols$(EXT) invalidDictionaries$(EXT) legacy$(EXT) poolTests$(EXT) \
254-
decodecorpus$(EXT)
258+
decodecorpus$(EXT) checkTag$(EXT)
255259
@echo Cleaning completed
256260

257261

tests/checkTag.c

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* Copyright (c) 2018-present, Yann Collet, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under both the BSD-style license (found in the
6+
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
7+
* in the COPYING file in the root directory of this source tree).
8+
* You may select, at your option, one of the above-listed licenses.
9+
*/
10+
11+
/* checkTag : validation tool for libzstd
12+
* command :
13+
* $ ./checkTag tag
14+
* checkTag validates tags of following format : v[0-9].[0-9].[0-9]{any}
15+
* The tag is then compared to zstd version number.
16+
* They are compatible if first 3 digits are identical.
17+
* Anything beyond that is free, and doesn't impact validation.
18+
* Example : tag v1.8.1.2 is compatible with version 1.8.1
19+
* When tag and version are not compatible, program exits with error code 1.
20+
* When they are compatible, it exists with a code 0.
21+
* checkTag is intended to be used in automated testing environment.
22+
*/
23+
24+
#include <stdio.h> /* printf */
25+
#include <string.h> /* strlen, strncmp */
26+
#include "zstd.h" /* ZSTD_VERSION_STRING */
27+
28+
29+
/* validate() :
30+
* @return 1 if tag is compatible, 0 if not.
31+
*/
32+
static int validate(const char* const tag)
33+
{
34+
size_t const tagLength = strlen(tag);
35+
size_t const verLength = strlen(ZSTD_VERSION_STRING);
36+
37+
if (tagLength < 2) return 0;
38+
if (tag[0] != 'v') return 0;
39+
if (tagLength <= verLength) return 0;
40+
41+
if (strncmp(ZSTD_VERSION_STRING, tag+1, verLength)) return 0;
42+
43+
return 1;
44+
}
45+
46+
int main(int argc, const char** argv)
47+
{
48+
const char* const exeName = argv[0];
49+
const char* const tag = argv[1];
50+
if (argc!=2) {
51+
printf("incorrect usage : %s tag \n", exeName);
52+
return 2;
53+
}
54+
55+
printf("Version : %s \n", ZSTD_VERSION_STRING);
56+
printf("Tag : %s \n", tag);
57+
58+
if (validate(tag)) {
59+
printf("OK : tag is compatible with zstd version \n");
60+
return 0;
61+
}
62+
63+
printf("!! error : tag and versions are not compatible !! \n");
64+
return 1;
65+
}

0 commit comments

Comments
 (0)