/*
protocol tests - common functions - basic types
Copyright (C) Amitay Isaacs 2015-2017
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 "replace.h"
#include
#include "tests/src/protocol_common_basic.h"
uint8_t BUFFER[1024*1024];
/*
* Functions to generation random data
*/
int rand_int(int max)
{
return random() % max;
}
uint8_t rand8(void)
{
uint8_t val = rand_int(256) & 0xff;
return val;
}
uint16_t rand16(void)
{
uint16_t val = rand_int(0xffff) & 0xffff;
return val;
}
int32_t rand32i(void)
{
return INT_MIN + random();
}
uint32_t rand32(void)
{
return random();
}
uint64_t rand64(void)
{
uint64_t t = random();
t = (t << 32) | random();
return t;
}
double rand_double(void)
{
return 1.0 / rand64();
}
void fill_buffer(void *p, size_t len)
{
size_t i;
uint8_t *ptr = p;
for (i=0; i 0) {
assert(memcmp(p1, p2, len) == 0);
}
}
void fill_string(char *p, size_t len)
{
size_t i;
for (i=0; itv_sec = rand32();
p->tv_usec = rand_int(1000000);
}
void verify_ctdb_timeval(struct timeval *p1, struct timeval *p2)
{
assert(p1->tv_sec == p2->tv_sec);
assert(p1->tv_usec == p2->tv_usec);
}