107 lines
2.7 KiB
C
107 lines
2.7 KiB
C
#include <stdint.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
#include "spdk_engine/io_engine.h"
|
|
#include "test_common.h"
|
|
|
|
#define MULTI_BLOB_COUNT 3
|
|
|
|
int main(void) {
|
|
int rc = 0;
|
|
const char *bdev_name = getenv("SPDK_BDEV_NAME");
|
|
struct zvfs_blob_handle *handles[MULTI_BLOB_COUNT] = {0};
|
|
uint64_t ids[MULTI_BLOB_COUNT] = {0};
|
|
uint64_t cluster = 0;
|
|
void *wbuf = NULL;
|
|
void *rbuf = NULL;
|
|
int i = 0;
|
|
|
|
if (!bdev_name) {
|
|
bdev_name = "Malloc0";
|
|
}
|
|
if (io_engine_init(bdev_name) != 0) {
|
|
fprintf(stderr, "TEST2: io_engine_init failed (bdev=%s)\n", bdev_name);
|
|
return 1;
|
|
}
|
|
|
|
printf("[TEST2] single thread / multi blob\n");
|
|
|
|
handles[0] = blob_create(0);
|
|
if (!handles[0]) {
|
|
fprintf(stderr, "TEST2: create first blob failed\n");
|
|
return 1;
|
|
}
|
|
ids[0] = handles[0]->id;
|
|
cluster = handles[0]->size;
|
|
if (cluster == 0) {
|
|
fprintf(stderr, "TEST2: invalid cluster size\n");
|
|
rc = 1;
|
|
goto out;
|
|
}
|
|
if (blob_resize(handles[0], cluster * 2) != 0) {
|
|
fprintf(stderr, "TEST2: resize first blob failed\n");
|
|
rc = 1;
|
|
goto out;
|
|
}
|
|
|
|
for (i = 1; i < MULTI_BLOB_COUNT; i++) {
|
|
handles[i] = blob_create(cluster * 2);
|
|
if (!handles[i]) {
|
|
fprintf(stderr, "TEST2: create blob %d failed\n", i);
|
|
rc = 1;
|
|
goto out;
|
|
}
|
|
ids[i] = handles[i]->id;
|
|
}
|
|
|
|
if (alloc_aligned_buf(&wbuf, cluster) != 0 || alloc_aligned_buf(&rbuf, cluster) != 0) {
|
|
fprintf(stderr, "TEST2: alloc aligned buffer failed\n");
|
|
rc = 1;
|
|
goto out;
|
|
}
|
|
|
|
for (i = 0; i < MULTI_BLOB_COUNT; i++) {
|
|
fill_pattern((uint8_t *)wbuf, cluster, (uint8_t)(0x20 + i));
|
|
memset(rbuf, 0, cluster);
|
|
|
|
if (blob_write(handles[i], 0, wbuf, cluster) != 0) {
|
|
fprintf(stderr, "TEST2: blob_write[%d] failed\n", i);
|
|
rc = 1;
|
|
goto out;
|
|
}
|
|
if (blob_read(handles[i], 0, rbuf, cluster) != 0) {
|
|
fprintf(stderr, "TEST2: blob_read[%d] failed\n", i);
|
|
rc = 1;
|
|
goto out;
|
|
}
|
|
if (memcmp(wbuf, rbuf, cluster) != 0) {
|
|
fprintf(stderr, "TEST2: blob[%d] readback mismatch\n", i);
|
|
rc = 1;
|
|
goto out;
|
|
}
|
|
}
|
|
|
|
out:
|
|
for (i = 0; i < MULTI_BLOB_COUNT; i++) {
|
|
if (handles[i]) {
|
|
(void)blob_close(handles[i]);
|
|
}
|
|
}
|
|
for (i = 0; i < MULTI_BLOB_COUNT; i++) {
|
|
if (ids[i] != 0) {
|
|
(void)blob_delete(ids[i]);
|
|
}
|
|
}
|
|
free(wbuf);
|
|
free(rbuf);
|
|
|
|
if (rc == 0) {
|
|
printf("[TEST2] PASS\n");
|
|
return 0;
|
|
}
|
|
printf("[TEST2] FAIL\n");
|
|
return 1;
|
|
}
|