commit 53e8129e6ae73e0041e6e6953f1255facf0b9847
parent 3bb31d7cb9712a1bf4a22bbb0ba5b36c6ebc91c9
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Wed, 30 Mar 2022 09:28:08 +0200
Perform even more load tests
Diffstat:
| M | src/test_sbuf_load.c | | | 106 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------- |
1 file changed, 86 insertions(+), 20 deletions(-)
diff --git a/src/test_sbuf_load.c b/src/test_sbuf_load.c
@@ -21,8 +21,8 @@ struct type_desc {
void (*set)(void* data, const size_t i);
int (*eq)(const void* a, const void* b);
- size_t size;
- size_t alignment;
+ uint64_t size;
+ uint64_t alignment;
};
/*******************************************************************************
@@ -74,6 +74,52 @@ char7_eq(const void* a, const void* b)
}
/*******************************************************************************
+ * ui32_f32 type
+ ******************************************************************************/
+struct ui32_f32 {
+ uint32_t ui32;
+ float f32;
+};
+
+static void
+ui32_f32_set(void* data, const size_t i)
+{
+ struct ui32_f32* t = data;
+ CHK(t);
+ t->ui32 = (uint32_t)i;
+ t->f32 = (float)i/100.f;
+}
+
+static int
+ui32_f32_eq(const void* a, const void* b)
+{
+ const struct ui32_f32* t0 = a;
+ const struct ui32_f32* t1 = b;
+ CHK(t0 && t1);
+ return t0->ui32 == t1->ui32 && t0->f32 == t1->f32;
+}
+
+/*******************************************************************************
+ * float
+ ******************************************************************************/
+static void
+f32_set(void* data, const size_t i)
+{
+ float* f = data;
+ CHK(f);
+ *f = (float)i;
+}
+
+static int
+f32_eq(const void* a, const void* b)
+{
+ const float* f0 = a;
+ const float* f1 = b;
+ CHK(f0 && f1);
+ return *f0 == *f1;
+}
+
+/*******************************************************************************
* Helper functions
******************************************************************************/
static void
@@ -102,34 +148,25 @@ check_sbuf_desc
}
static void
-test_load(struct sbuf* buf, const struct type_desc* type)
+write_buffer
+ (FILE* fp,
+ const uint64_t pagesize,
+ const uint64_t count,
+ const struct type_desc* type)
{
char ALIGN(512) mem[512] = {0};
- struct sbuf_desc desc = SBUF_DESC_NULL;
- FILE* fp = NULL;
- const char* filename = "test_file.sbuf";
- const uint64_t pagesize = 16384;
- const uint64_t count = 287;
- uint64_t szelmt;
- uint64_t alelmt;
size_t i;
- char byte = 0;
-
- CHK(buf && type);
+ const char byte = 0;
+ CHK(type);
CHK(type->size <= sizeof(mem));
CHK(type->alignment <= ALIGNOF(mem));
- fp = fopen(filename, "w+");
- CHK(fp);
-
/* Write file header */
- szelmt = (uint64_t)type->size;
- alelmt = (uint64_t)type->alignment;
CHK(fwrite(&pagesize, sizeof(pagesize), 1, fp) == 1);
CHK(fwrite(&count, sizeof(count), 1, fp) == 1);
- CHK(fwrite(&szelmt, sizeof(szelmt), 1, fp) == 1);
- CHK(fwrite(&alelmt, sizeof(alelmt), 1, fp) == 1);
+ CHK(fwrite(&type->size, sizeof(type->size), 1, fp) == 1);
+ CHK(fwrite(&type->alignment, sizeof(type->size), 1, fp) == 1);
/* Padding */
CHK(fseek(fp, (long)ALIGN_SIZE((size_t)ftell(fp), pagesize), SEEK_SET) == 0);
@@ -146,6 +183,23 @@ test_load(struct sbuf* buf, const struct type_desc* type)
CHK(fseek(fp, (long)ALIGN_SIZE((size_t)ftell(fp), pagesize)-1, SEEK_SET) == 0);
CHK(fwrite(&byte, sizeof(byte), 1, fp) == 1);
CHK(fflush(fp) == 0);
+}
+
+static void
+test_load(struct sbuf* buf, const struct type_desc* type)
+{
+ struct sbuf_desc desc = SBUF_DESC_NULL;
+ FILE* fp = NULL;
+ const char* filename = "test_file.sbuf";
+ const uint64_t pagesize = 16384;
+ const uint64_t count = 287;
+
+ CHK(buf && type);
+
+ fp = fopen(filename, "w+");
+ CHK(fp);
+
+ write_buffer(fp, pagesize, count, type);
rewind(fp);
CHK(sbuf_load_stream(NULL, fp, filename) == RES_BAD_ARG);
@@ -188,6 +242,18 @@ main(int argc, char** argv)
type.alignment = ALIGNOF(char7_T);
test_load(buf, &type);
+ type.set = ui32_f32_set;
+ type.eq = ui32_f32_eq;
+ type.size = sizeof(struct ui32_f32);
+ type.alignment = ALIGNOF(struct ui32_f32);
+ test_load(buf, &type);
+
+ type.set = f32_set;
+ type.eq = f32_eq;
+ type.size = sizeof(float);
+ type.alignment = ALIGNOF(float);
+ test_load(buf, &type);
+
/*test_load_fail(smsh);
test_load_files(smsh, argc, argv);*/