diff --git a/add-test-c-result-print.patch b/add-test-c-result-print.patch new file mode 100644 index 0000000..d9299e4 --- /dev/null +++ b/add-test-c-result-print.patch @@ -0,0 +1,521 @@ +From 7409f10fed50978ad5dff36540dc0a7aae688688 Mon Sep 17 00:00:00 2001 +From: zhangying +Date: Thu, 2 Feb 2023 14:59:55 +0800 +Subject: [PATCH] zstd-add-test-c-result-print.patch + +Displays statistics about the execution of all zstd test cases. +--- + tests/decodecorpus.c | 17 +++++++++-- + tests/fullbench.c | 61 ++++++++++++++++++++++++++++++++++--- + tests/fuzzer.c | 16 ++++++++++ + tests/invalidDictionaries.c | 10 ++++++ + tests/legacy.c | 10 ++++-- + tests/playTests.sh | 2 ++ + tests/poolTests.c | 24 ++++++++++++--- + tests/zstreamtest.c | 18 +++++++++++ + 8 files changed, 144 insertions(+), 14 deletions(-) + +diff --git a/tests/decodecorpus.c b/tests/decodecorpus.c +index 1037a36..5d053aa 100644 +--- a/tests/decodecorpus.c ++++ b/tests/decodecorpus.c +@@ -1538,6 +1538,7 @@ static int runTestMode(U32 seed, unsigned numFiles, unsigned const testDurationS + + if (numFiles == 0 && !testDurationS) numFiles = 1; + ++ DISPLAY("==== test/decodecorpus/runTestMode ====\n"); + DISPLAY("seed: %u\n", (unsigned)seed); + + for (fnum = 0; fnum < numFiles || UTIL_clockSpanMicro(startClock) < maxClockSpan; fnum++) { +@@ -1549,12 +1550,13 @@ static int runTestMode(U32 seed, unsigned numFiles, unsigned const testDurationS + { int const ret = (genType == gt_frame) ? + runFrameTest(&seed) : + runBlockTest(&seed); +- if (ret) return ret; ++ if (ret) {DISPLAY("==== results: passed: 0/1, failed: 1/1, skipped: 0/1 ====\n");return ret;} + } + } + + DISPLAY("\r%u tests completed: ", fnum); + DISPLAY("OK\n"); ++ DISPLAY("==== results: passed: 1/1, failed: 0/1, skipped: 0/1 ====\n"); + + return 0; + } +@@ -1568,6 +1570,7 @@ static int generateFile(U32 seed, const char* const path, + { + frame_t fr; + ++ DISPLAY("==== test/decodecorpus/gerenateFile ====\n"); + DISPLAY("seed: %u\n", (unsigned)seed); + + { dictInfo const info = initDictInfo(0, 0, NULL, 0); +@@ -1581,6 +1584,7 @@ static int generateFile(U32 seed, const char* const path, + if (origPath) { + outputBuffer(fr.srcStart, (BYTE*)fr.src - (BYTE*)fr.srcStart, origPath); + } ++ DISPLAY("==== results: passed: 1/1, failed: 0/1, skipped: 0/1 ====\n"); + return 0; + } + +@@ -1590,6 +1594,7 @@ static int generateCorpus(U32 seed, unsigned numFiles, const char* const path, + char outPath[MAX_PATH]; + unsigned fnum; + ++ DISPLAY("==== test/decodecorpus/generateCorpus ====\n"); + DISPLAY("seed: %u\n", (unsigned)seed); + + for (fnum = 0; fnum < numFiles; fnum++) { +@@ -1607,6 +1612,7 @@ static int generateCorpus(U32 seed, unsigned numFiles, const char* const path, + + if (snprintf(outPath, MAX_PATH, "%s/z%06u.zst", path, fnum) + 1 > MAX_PATH) { + DISPLAY("Error: path too long\n"); ++ DISPLAY("==== results: passed: 0/1, failed: 1/1, skipped: 0/1 ====\n"); + return 1; + } + outputBuffer(fr.dataStart, (BYTE*)fr.data - (BYTE*)fr.dataStart, outPath); +@@ -1614,6 +1620,7 @@ static int generateCorpus(U32 seed, unsigned numFiles, const char* const path, + if (origPath) { + if (snprintf(outPath, MAX_PATH, "%s/z%06u", origPath, fnum) + 1 > MAX_PATH) { + DISPLAY("Error: path too long\n"); ++ DISPLAY("==== results: passed: 0/1, failed: 1/1, skipped: 0/1 ====\n"); + return 1; + } + outputBuffer(fr.srcStart, (BYTE*)fr.src - (BYTE*)fr.srcStart, outPath); +@@ -1621,7 +1628,7 @@ static int generateCorpus(U32 seed, unsigned numFiles, const char* const path, + } + + DISPLAY("\r%u/%u \n", fnum, numFiles); +- ++ DISPLAY("==== results: passed: 1/1, failed: 0/1, skipped: 0/1 ====\n"); + return 0; + } + +@@ -1634,8 +1641,11 @@ static int generateCorpusWithDict(U32 seed, unsigned numFiles, const char* const + U32 const dictID = RAND(&seed); + int errorDetected = 0; + ++ DISPLAY("==== test/decodecorpus/generateCorpusWithDict ====\n"); ++ + if (snprintf(outPath, MAX_PATH, "%s/dictionary", path) + 1 > MAX_PATH) { + DISPLAY("Error: path too long\n"); ++ DISPLAY("==== results: passed: 0/1, failed: 1/1, skipped: 0/1 ====\n"); + return 1; + } + +@@ -1643,6 +1653,7 @@ static int generateCorpusWithDict(U32 seed, unsigned numFiles, const char* const + fullDict = malloc(dictSize); + if (fullDict == NULL) { + DISPLAY("Error: could not allocate space for full dictionary.\n"); ++ DISPLAY("==== results: passed: 0/1, failed: 1/1, skipped: 0/1 ====\n"); + return 1; + } + +@@ -1711,6 +1722,8 @@ static int generateCorpusWithDict(U32 seed, unsigned numFiles, const char* const + } + + dictCleanup: ++ DISPLAY("==== results: passed: %d/1, failed: %d/1, skipped: 0/1 ====\n", ++ (1-errorDetected), errorDetected); + free(fullDict); + return errorDetected; + } +diff --git a/tests/fullbench.c b/tests/fullbench.c +index b55ff76..3a6ce2b 100644 +--- a/tests/fullbench.c ++++ b/tests/fullbench.c +@@ -500,7 +500,7 @@ static int benchMem(unsigned benchNb, + benchFunction = local_ZSTD_compress_generic_T2_end; benchName = "compress_generic, -T2, end"; + break; + default : +- return 0; ++ return -1; + } + + /* Allocation */ +@@ -700,8 +700,15 @@ static int benchSample(U32 benchNb, + size_t benchedSize, double compressibility, + int cLevel, ZSTD_compressionParameters cparams) + { ++ int ret = 0; ++ int testOk = 0; ++ int testEr = 0; ++ + /* Allocation */ + void* const origBuff = malloc(benchedSize); ++ ++ DISPLAY("==== test/fullbench/benchSample[compressibility:%f] ====\n", compressibility); ++ + if (!origBuff) { DISPLAY("\nError: not enough memory!\n"); return 12; } + + /* Fill buffer */ +@@ -711,12 +718,31 @@ static int benchSample(U32 benchNb, + DISPLAY("\r%70s\r", ""); + DISPLAY(" Sample %u bytes : \n", (unsigned)benchedSize); + if (benchNb) { +- benchMem(benchNb, origBuff, benchedSize, cLevel, cparams); ++ ret = benchMem(benchNb, origBuff, benchedSize, cLevel, cparams); ++ if ( 0 == ret ) ++ { ++ testOk++; ++ } ++ else if ( 1 == ret ) ++ { ++ testEr++; ++ } + } else { /* 0 == run all tests */ + for (benchNb=0; benchNb<100; benchNb++) { +- benchMem(benchNb, origBuff, benchedSize, cLevel, cparams); ++ ret = benchMem(benchNb, origBuff, benchedSize, cLevel, cparams); ++ if ( 0 == ret ) ++ { ++ testOk++; ++ } ++ else if ( 1 == ret ) ++ { ++ testEr++; ++ } + } } + ++ DISPLAY("==== results: passed: %d/%d, failed: %d/%d, skipped: 0/%d ====\n", ++ testOk, (testOk+testEr), testEr, (testOk+testEr), (testOk+testEr)); ++ + free(origBuff); + return 0; + } +@@ -728,6 +754,12 @@ static int benchFiles(U32 benchNb, + { + /* Loop for each file */ + int fileIdx; ++ int ret = 0; ++ int testOk = 0; ++ int testEr = 0; ++ ++ DISPLAY("==== test/fullbench/benchFiles ====\n"); ++ + for (fileIdx=0; fileIdx ++#include + #include "zstd.h" + + static const char invalidRepCode[] = { +@@ -38,23 +39,32 @@ static const dictionary dictionaries[] = { + {NULL, 0}, + }; + ++#define DISPLAY(...) fprintf(stderr, __VA_ARGS__) ++ + int main(int argc, const char** argv) { + const dictionary *dict; + for (dict = dictionaries; dict->data != NULL; ++dict) { + ZSTD_CDict *cdict; + ZSTD_DDict *ddict; ++ ++ DISPLAY("==== test/invalidDictionaries ====\n"); ++ + cdict = ZSTD_createCDict(dict->data, dict->size, 1); + if (cdict) { + ZSTD_freeCDict(cdict); ++ DISPLAY("==== results: passed: 0/2, failed: 1/2, skipped: 1/2 ====\n"); + return 1; + } + ddict = ZSTD_createDDict(dict->data, dict->size); + if (ddict) { + ZSTD_freeDDict(ddict); ++ DISPLAY("==== results: passed: 1/2, failed: 1/2, skipped: 0/2 ====\n"); + return 2; + } + } + ++ DISPLAY("==== results: passed: 2/2, failed: 0/2, skipped: 0/2 ====\n"); ++ + (void)argc; + (void)argv; + return 0; +diff --git a/tests/legacy.c b/tests/legacy.c +index ac4938f..5ebb1cc 100644 +--- a/tests/legacy.c ++++ b/tests/legacy.c +@@ -160,14 +160,18 @@ static int testFrameDecoding(void) + + int main(void) + { ++ DISPLAY ("==== test/legacy ====\n"); ++ + { int const ret = testSimpleAPI(); +- if (ret) return ret; } ++ if (ret) {DISPLAY("==== results: passed: 0/3, failed: 1/3, skipped: 2/3 ====\n");return ret;} } + { int const ret = testStreamingAPI(); +- if (ret) return ret; } ++ if (ret) {DISPLAY("==== results: passed: 1/3, failed: 1/3, skipped: 1/3 ====\n");return ret;} } + { int const ret = testFrameDecoding(); +- if (ret) return ret; } ++ if (ret) {DISPLAY("==== results: passed: 2/3, failed: 1/3, skipped: 0/3 ====\n");return ret;} } + + DISPLAY("OK\n"); ++ DISPLAY("==== results: passed: 3/3, failed: 0/3, skipped: 0/3 ====\n"); ++ + return 0; + } + +diff --git a/tests/playTests.sh b/tests/playTests.sh +index b7a3d88..c152162 100755 +--- a/tests/playTests.sh ++++ b/tests/playTests.sh +@@ -1743,3 +1743,5 @@ test -f dictionary + rm -f tmp* dictionary + + rm -f tmp* ++ ++println "all zstd cli tests passed" +diff --git a/tests/poolTests.c b/tests/poolTests.c +index 08f31c0..972e5c9 100644 +--- a/tests/poolTests.c ++++ b/tests/poolTests.c +@@ -24,6 +24,7 @@ + } while (0) + #define ASSERT_FALSE(p) ASSERT_TRUE(!(p)) + #define ASSERT_EQ(lhs, rhs) ASSERT_TRUE((lhs) == (rhs)) ++#define DISPLAY(...) fprintf(stderr, __VA_ARGS__) + + struct data { + ZSTD_pthread_mutex_t mutex; +@@ -225,11 +226,16 @@ static int testAbruptEnding(void) { + + int main(int argc, const char **argv) { + size_t numThreads; ++ unsigned testNb = 0; ++ + (void)argc; + (void)argv; + ++ DISPLAY("==== test/poolTests ====\n"); ++ + if (POOL_create(0, 1)) { /* should not be possible */ + printf("FAIL: should not create POOL with 0 threads\n"); ++ DISPLAY("==== results: passed: 0/1, failed: 0/1, skipped: 0/1 ====\n"); + return 1; + } + +@@ -240,32 +246,42 @@ int main(int argc, const char **argv) { + (unsigned)queueSize, (unsigned)numThreads); + if (testOrder(numThreads, queueSize)) { + printf("FAIL: testOrder\n"); ++ DISPLAY("==== results: passed: %d/%d, failed: 1/%d, skipped: 0/%d ====\n", ++ testNb, (testNb+1), (testNb+1), (testNb+1)); + return 1; + } +- printf("SUCCESS: testOrder\n"); ++ printf("SUCCESS: testOrder\n");testNb++; + if (testWait(numThreads, queueSize)) { + printf("FAIL: testWait\n"); ++ DISPLAY("==== results: passed: %d/%d, failed: 1/%d, skipped: 0/%d ====\n", ++ testNb, (testNb+1), (testNb+1), (testNb+1)); + return 1; + } +- printf("SUCCESS: testWait\n"); ++ printf("SUCCESS: testWait\n");testNb++; + } + } + + if (testThreadReduction()) { + printf("FAIL: thread reduction not effective \n"); ++ DISPLAY("==== results: passed: %d/%d, failed: 1/%d, skipped: 0/%d ====\n", ++ testNb, (testNb+1), (testNb+1), (testNb+1)); + return 1; + } else { +- printf("SUCCESS: thread reduction effective \n"); ++ printf("SUCCESS: thread reduction effective \n");testNb++; + } + + if (testAbruptEnding()) { + printf("FAIL: jobs in queue not completed on early end \n"); ++ DISPLAY("==== results: passed: %d/%d, failed: 1/%d, skipped: 0/%d ====\n", ++ testNb, (testNb+1), (testNb+1), (testNb+1)); + return 1; + } else { +- printf("SUCCESS: all jobs in queue completed on early end \n"); ++ printf("SUCCESS: all jobs in queue completed on early end \n");testNb++; + } + + printf("PASS: all POOL tests\n"); ++ DISPLAY("==== results: passed: %d/%d, failed: 0/%d, skipped: 0/%d ====\n", ++ testNb, testNb, testNb, testNb); + + return 0; + } +diff --git a/tests/zstreamtest.c b/tests/zstreamtest.c +index 72fd72e..be300b6 100644 +--- a/tests/zstreamtest.c ++++ b/tests/zstreamtest.c +@@ -282,6 +282,8 @@ static int basicUnitTests(U32 seed, double compressibility) + size_t const dictSize = 128 KB; + unsigned dictID = 0; + ++ DISPLAY("==== test/zstreamtest/basicUnitTests ====\n"); ++ + /* Create compressible test buffer */ + if (!CNBuffer || !compressedBuffer || !decodedBuffer || !zc || !zd || !mtctx) { + DISPLAY("Not enough memory, aborting \n"); +@@ -1691,6 +1693,10 @@ static int basicUnitTests(U32 seed, double compressibility) + DISPLAYLEVEL(3, "OK \n"); + + _end: ++ ++ DISPLAY("==== results: passed: %d/%d, failed: %d/%d, skipped: 0/%d ====\n", ++ (testNb-testResult), testNb, testResult, testNb, testNb); ++ + FUZ_freeDictionary(dictionary); + ZSTD_freeCStream(zc); + ZSTD_freeDStream(zd); +@@ -1778,6 +1784,8 @@ static int fuzzerTests(U32 seed, unsigned nbTests, unsigned startTest, double co + U32 oldTestLog = 0; + U32 const cLevelMax = bigTests ? (U32)ZSTD_maxCLevel() : g_cLevelMax_smallTests; + ++ DISPLAY("==== test/zstreamtest/fuzzerTests ====\n"); ++ + /* allocations */ + cNoiseBuffer[0] = (BYTE*)malloc (srcBufferSize); + cNoiseBuffer[1] = (BYTE*)malloc (srcBufferSize); +@@ -1989,6 +1997,10 @@ static int fuzzerTests(U32 seed, unsigned nbTests, unsigned startTest, double co + DISPLAY("\r%u fuzzer tests completed \n", testNb); + + _cleanup: ++ ++ DISPLAY("==== results: passed: %d/1, failed: %d/1, skipped: 0/1 ====\n", ++ (1-result), result); ++ + ZSTD_freeCStream(zc); + ZSTD_freeDStream(zd); + ZSTD_freeDStream(zd_noise); +@@ -2049,6 +2061,8 @@ static int fuzzerTests_newAPI(U32 seed, int nbTests, int startTest, + U32 const nbThreadsMax = bigTests ? 4 : 2; + ZSTD_CCtx_params* cctxParams = ZSTD_createCCtxParams(); + ++ DISPLAY("==== test/zstreamtest/fuzzerTests_newAPI ====\n"); ++ + /* allocations */ + cNoiseBuffer[0] = (BYTE*)malloc (srcBufferSize); + cNoiseBuffer[1] = (BYTE*)malloc (srcBufferSize); +@@ -2423,6 +2437,10 @@ static int fuzzerTests_newAPI(U32 seed, int nbTests, int startTest, + DISPLAY("\r%u fuzzer tests completed \n", testNb-1); + + _cleanup: ++ ++ DISPLAY("==== results: passed: %d/1, failed: %d/1, skipped: 0/1 ====\n", ++ (1-result), result); ++ + ZSTD_freeCCtx(zc); + ZSTD_freeDStream(zd); + ZSTD_freeDStream(zd_noise); +-- +2.33.0 + diff --git a/zstd.spec b/zstd.spec index 5a78fd7..5e9c092 100644 --- a/zstd.spec +++ b/zstd.spec @@ -8,6 +8,8 @@ License: BSD and GPLv2 URL: https://github.com/facebook/zstd Source0: https://github.com/facebook/zstd/archive/v%{version}.tar.gz#/%{name}-%{version}.tar.gz +Patch9000: add-test-c-result-print.patch + BuildRequires: gtest-devel gcc-c++ pkg-config Provides: libzstd