/*
* Copyright (C) 2011 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 .
*/
#include "portable.h"
#include "snapraid.h"
#include "util.h"
#include "raid.h"
#include "cpu.h"
#include "elem.h"
#include "state.h"
#include "combo.h"
struct hash_test_vector {
const char* data;
int len;
unsigned char digest[HASH_SIZE];
};
/**
* Test vectors for MurmorHash3_x86_128
*/
static struct hash_test_vector TEST_MURMUR3[] = {
#include "murmur3test.c"
{ 0, 0, { 0 } }
};
/**
* Test vectors for SpookyHash_128
*/
static struct hash_test_vector TEST_SPOOKY2[] = {
#include "spooky2test.c"
{ 0, 0, { 0 } }
};
/**
* Binomial coefficient of n over r.
*/
static unsigned bc(unsigned n, unsigned r)
{
if (r == 0 || n == r)
return 1;
else
return bc(n - 1, r - 1) + bc(n - 1, r);
}
static void combotest(void)
{
unsigned r;
unsigned count;
int p[LEV_MAX];
/* all parities */
for(r=1;r<=LEV_MAX;++r) {
/* count combination (r of LEV_MAX) parities */
count = 0;
combination_first(r, LEV_MAX, p);
do {
++count;
} while (combination_next(r, LEV_MAX, p));
if (count != bc(LEV_MAX, r)) {
fprintf(stderr, "Failed COMBO test\n");
exit(EXIT_FAILURE);
}
}
}
static void recovtest(unsigned mode, unsigned nd, unsigned block_size)
{
void* buffer_alloc;
void** buffer;
void** data;
void** parity;
void** test;
void* data_save[LEV_MAX];
void* parity_save[LEV_MAX];
void* zero;
void* waste;
unsigned buffermax;
int id[LEV_MAX];
int ip[LEV_MAX];
unsigned i;
unsigned j;
unsigned nr;
void (*map[LEV_MAX][4])(int nr, const int* id, const int* ip, int nd, size_t size, void** vbuf);
unsigned mac[LEV_MAX];
unsigned np;
raid_mode(mode);
if (mode == RAID_MODE_CAUCHY)
np = RAID_PARITY_MAX;
else
np = 3;
buffermax = nd + np * 2 + 2;
buffer = malloc_nofail_vector_align(nd, buffermax, block_size, &buffer_alloc);
mtest_vector(buffer, buffermax, block_size);
data = buffer;
parity = buffer + nd;
test = buffer + nd + np;
for(i=0;i