Add some randomness for data tests

Co-Authored-By: Tim Burke <tim.burke@gmail.com>
Change-Id:  Id6001e6e0a3a0a293308928be5fa4bef71fe6bac
This commit is contained in:
aitassou
2025-09-11 15:04:18 +02:00
committed by Tim Burke
parent b657f46fa3
commit 2ce8139766
2 changed files with 23 additions and 2 deletions

View File

@@ -27,7 +27,9 @@
*/
#include <assert.h>
#include <fcntl.h>
#include <stdbool.h>
#include <unistd.h>
#include "erasurecode.h"
#include "erasurecode_helpers.h"
#include "erasurecode_helpers_ext.h"
@@ -40,7 +42,14 @@ char *create_buffer(int size, int fill)
if (buf == NULL) {
return NULL;
}
memset(buf, fill, size);
int urand = open("/dev/urandom", O_RDONLY);
if (urand < 0 || read(urand, buf, size) != size) {
for(size_t i = 0; i < size; i++)
buf[i] = rand() % 256;
}
if (urand >= 0) {
close(urand);
}
return buf;
}

View File

@@ -27,7 +27,9 @@
*/
#include <assert.h>
#include <fcntl.h>
#include <stdbool.h>
#include <unistd.h>
#include <zlib.h>
#include "erasurecode.h"
#include "erasurecode_helpers.h"
@@ -391,7 +393,17 @@ struct ec_args *create_ec_args(ec_backend_id_t be, ec_checksum_type_t ct, int ba
char *create_buffer(int size, int fill)
{
char *buf = malloc(size);
memset(buf, fill, size);
if (buf == NULL) {
return NULL;
}
int urand = open("/dev/urandom", O_RDONLY);
if (urand < 0 || read(urand, buf, size) != size) {
for(size_t i = 0; i < size; i++)
buf[i] = rand() % 256;
}
if (urand >= 0) {
close(urand);
}
return buf;
}