mirror of
https://github.com/amadvance/snapraid.git
synced 2026-10-26 19:01:57 -04:00
Add additional regression test for streams
This commit is contained in:
parent
f6611557d0
commit
d4a92f4918
5 changed files with 231 additions and 3 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
|
@ -1,12 +1,14 @@
|
|||
# archives
|
||||
*.zip
|
||||
*.tar.gz
|
||||
*.tgz
|
||||
|
||||
# backups
|
||||
*~
|
||||
|
||||
# logs
|
||||
*.log
|
||||
stream*.bin
|
||||
|
||||
# autotools
|
||||
Makefile
|
||||
|
|
@ -29,6 +31,7 @@ stamp-h1
|
|||
# objects
|
||||
snapraid
|
||||
mktest
|
||||
mkstream
|
||||
*.o
|
||||
*.gcda
|
||||
*.gcno
|
||||
|
|
@ -46,4 +49,5 @@ paper/
|
|||
kernel/
|
||||
obj/
|
||||
bench/
|
||||
support/
|
||||
|
||||
|
|
|
|||
13
Makefile.am
13
Makefile.am
|
|
@ -1,5 +1,5 @@
|
|||
bin_PROGRAMS = snapraid
|
||||
check_PROGRAMS = mktest
|
||||
check_PROGRAMS = mktest mkstream
|
||||
|
||||
snapraid_SOURCES = \
|
||||
raid/raid.c \
|
||||
|
|
@ -87,6 +87,13 @@ mktest_SOURCES = \
|
|||
cmdline/mingw.c \
|
||||
cmdline/support.c
|
||||
|
||||
mkstream_SOURCES = \
|
||||
cmdline/mkstream.c \
|
||||
cmdline/mingw.c \
|
||||
cmdline/support.c \
|
||||
cmdline/util.c \
|
||||
raid/memory.c
|
||||
|
||||
EXTRA_DIST = \
|
||||
autogen.sh \
|
||||
README AUTHORS HISTORY INSTALL COPYING TODO CHECK INSTALL.windows \
|
||||
|
|
@ -114,7 +121,7 @@ man_MANS = snapraid.1
|
|||
clean-local:
|
||||
rm -f valgrind.log callgrind.log cachegrind.log
|
||||
rm -rf bench
|
||||
rm -f test*.log output.log
|
||||
rm -f test*.log output.log stream*.bin
|
||||
rm -f cmdline/*.gcda cmdline/*.gcno cmdline/*.gcov
|
||||
rm -f raid/*.gcda raid/*.gcno raid/*.gcov
|
||||
rm -f tommyds/*.gcda tommyds/*.gcno tommyds/*.gcov
|
||||
|
|
@ -174,6 +181,8 @@ check-local:
|
|||
mkdir bench/disk5
|
||||
mkdir bench/disk6
|
||||
mkdir bench/pool
|
||||
echo --- Stream
|
||||
$(TESTENV) ./mkstream$(EXEEXT)
|
||||
echo --- Help
|
||||
$(TESTENV) ./snapraid$(EXEEXT) --test-skip-device -H
|
||||
$(TESTENV) ./snapraid$(EXEEXT) --test-skip-device -V
|
||||
|
|
|
|||
213
cmdline/mkstream.c
Normal file
213
cmdline/mkstream.c
Normal file
|
|
@ -0,0 +1,213 @@
|
|||
/*
|
||||
* Copyright (C) 2015 Andrea Mazzoleni
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "portable.h"
|
||||
|
||||
#include "support.h"
|
||||
#include "util.h"
|
||||
|
||||
#define STREAM_MAX 8
|
||||
#define BUFFER_MAX 64
|
||||
#define STR_MAX 128
|
||||
|
||||
void test(void)
|
||||
{
|
||||
struct stream* s;
|
||||
char file[32];
|
||||
unsigned char buffer[BUFFER_MAX];
|
||||
char str[STR_MAX];
|
||||
unsigned i, j;
|
||||
uint32_t u32 = -1L;
|
||||
uint64_t u64 = -1LL;
|
||||
uint32_t crc_stored;
|
||||
uint32_t crc_computed;
|
||||
|
||||
crc32c_init();
|
||||
|
||||
s = sopen_multi_write(STREAM_MAX);
|
||||
for (i = 0;i < STREAM_MAX; ++i) {
|
||||
snprintf(file, sizeof(file), "stream%u.bin", i);
|
||||
if (sopen_multi_file(s, i, file) != 0) {
|
||||
/* LCOV_EXCL_START */
|
||||
exit(EXIT_FAILURE);
|
||||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
}
|
||||
|
||||
for(j=0;j<256;++j) {
|
||||
if (sputc(j, s) != 0) {
|
||||
/* LCOV_EXCL_START */
|
||||
exit(EXIT_FAILURE);
|
||||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
}
|
||||
|
||||
for(j=0;j<32;++j) {
|
||||
if (sputb32(u32 >> j, s) != 0) {
|
||||
/* LCOV_EXCL_START */
|
||||
exit(EXIT_FAILURE);
|
||||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
}
|
||||
|
||||
for(j=0;j<64;++j) {
|
||||
if (sputb64(u64 >> j, s) != 0) {
|
||||
/* LCOV_EXCL_START */
|
||||
exit(EXIT_FAILURE);
|
||||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
}
|
||||
|
||||
for(j=0;j<BUFFER_MAX;++j) {
|
||||
memset(buffer, j, j);
|
||||
if (swrite(buffer, j, s) != 0) {
|
||||
/* LCOV_EXCL_START */
|
||||
exit(EXIT_FAILURE);
|
||||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
}
|
||||
|
||||
for(j=1;j<STR_MAX;++j) {
|
||||
memset(str, ' ' + j, j-1);
|
||||
str[j-1] = 0;
|
||||
if (sputbs(str, s) != 0) {
|
||||
/* LCOV_EXCL_START */
|
||||
exit(EXIT_FAILURE);
|
||||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
crc_stored = scrc(s);
|
||||
crc_computed = scrc_stream(s);
|
||||
|
||||
if (crc_stored != crc_computed) {
|
||||
/* LCOV_EXCL_START */
|
||||
exit(EXIT_FAILURE);
|
||||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
|
||||
if (sputble32(crc_stored, s) != 0) {
|
||||
/* LCOV_EXCL_START */
|
||||
exit(EXIT_FAILURE);
|
||||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
|
||||
if (sclose(s) != 0) {
|
||||
/* LCOV_EXCL_START */
|
||||
exit(EXIT_FAILURE);
|
||||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
|
||||
for (i = 0; i < STREAM_MAX; ++i) {
|
||||
uint32_t crc_stored;
|
||||
uint32_t crc_computed;
|
||||
snprintf(file, sizeof(file), "stream%u.bin", i);
|
||||
|
||||
s = sopen_read(file);
|
||||
if (s == 0) {
|
||||
/* LCOV_EXCL_START */
|
||||
exit(EXIT_FAILURE);
|
||||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
|
||||
for(j=0;j<256;++j) {
|
||||
int c = sgetc(s);
|
||||
if (c == EOF || (unsigned char)c != j) {
|
||||
/* LCOV_EXCL_START */
|
||||
exit(EXIT_FAILURE);
|
||||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
}
|
||||
|
||||
for(j=0;j<32;++j) {
|
||||
uint32_t v32;
|
||||
if (sgetb32(s, &v32) != 0 || v32 != (u32 >> j)) {
|
||||
/* LCOV_EXCL_START */
|
||||
exit(EXIT_FAILURE);
|
||||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
}
|
||||
|
||||
for(j=0;j<64;++j) {
|
||||
uint64_t v64;
|
||||
if (sgetb64(s, &v64) != 0 || v64 != (u64 >> j)) {
|
||||
/* LCOV_EXCL_START */
|
||||
exit(EXIT_FAILURE);
|
||||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
}
|
||||
|
||||
for(j=1;j<BUFFER_MAX;++j) {
|
||||
char copy[BUFFER_MAX];
|
||||
memset(buffer, j, j);
|
||||
if (sread(s, copy, j) != 0 || memcmp(copy, buffer, j) != 0) {
|
||||
/* LCOV_EXCL_START */
|
||||
exit(EXIT_FAILURE);
|
||||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
}
|
||||
|
||||
for(j=1;j<STR_MAX;++j) {
|
||||
char copy[STR_MAX];
|
||||
memset(str, ' ' + j, j-1);
|
||||
str[j-1] = 0;
|
||||
if (sgetbs(s, copy, sizeof(copy)) != 0 || strcmp(copy, str) != 0) {
|
||||
/* LCOV_EXCL_START */
|
||||
exit(EXIT_FAILURE);
|
||||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
}
|
||||
|
||||
crc_computed = scrc(s);
|
||||
|
||||
if (sgetble32(s, &crc_stored) != 0) {
|
||||
/* LCOV_EXCL_START */
|
||||
exit(EXIT_FAILURE);
|
||||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
|
||||
if (crc_stored != crc_computed) {
|
||||
/* LCOV_EXCL_START */
|
||||
exit(EXIT_FAILURE);
|
||||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
|
||||
if (sclose(s) != 0) {
|
||||
/* LCOV_EXCL_START */
|
||||
exit(EXIT_FAILURE);
|
||||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
unsigned i;
|
||||
for (i = 1; i <= 16; ++i) {
|
||||
|
||||
/* test with different stream buffer size */
|
||||
STREAM_SIZE = i;
|
||||
|
||||
printf("Test stream buffer size %u\n", i);
|
||||
|
||||
test();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -50,6 +50,8 @@ static unsigned strdecset[256] =
|
|||
/****************************************************************************/
|
||||
/* stream */
|
||||
|
||||
unsigned STREAM_SIZE = 1024 * 64;
|
||||
|
||||
STREAM* sopen_read(const char* file)
|
||||
{
|
||||
#if HAVE_POSIX_FADVISE
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ void crc32c_init(void);
|
|||
/****************************************************************************/
|
||||
/* stream */
|
||||
|
||||
#define STREAM_SIZE (64 * 1024) /**< Size of the buffer of the stream. */
|
||||
unsigned STREAM_SIZE; /**< Size of the buffer of the stream. */
|
||||
|
||||
#define STREAM_STATE_READ 0 /**< The stream is in a normal state of read. */
|
||||
#define STREAM_STATE_WRITE 1 /**< The stream is in a normal state of write. */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue