110 lines
2.6 KiB
C
110 lines
2.6 KiB
C
|
|
#ifndef _POSIX_C_SOURCE
|
||
|
|
#define _POSIX_C_SOURCE 200809L
|
||
|
|
#endif
|
||
|
|
|
||
|
|
#include "amduatd_store.h"
|
||
|
|
|
||
|
|
#include "amduat/asl/asl_store_fs_meta.h"
|
||
|
|
#include "amduat/enc/asl_log.h"
|
||
|
|
|
||
|
|
#include <stdio.h>
|
||
|
|
#include <stdlib.h>
|
||
|
|
#include <string.h>
|
||
|
|
|
||
|
|
static char *amduatd_test_make_temp_dir(void) {
|
||
|
|
char tmpl[] = "/tmp/amduatd-store-XXXXXX";
|
||
|
|
char *dir = mkdtemp(tmpl);
|
||
|
|
size_t len;
|
||
|
|
char *copy;
|
||
|
|
if (dir == NULL) {
|
||
|
|
perror("mkdtemp");
|
||
|
|
return NULL;
|
||
|
|
}
|
||
|
|
len = strlen(dir);
|
||
|
|
copy = (char *)malloc(len + 1u);
|
||
|
|
if (copy == NULL) {
|
||
|
|
fprintf(stderr, "failed to allocate temp dir copy\n");
|
||
|
|
return NULL;
|
||
|
|
}
|
||
|
|
memcpy(copy, dir, len + 1u);
|
||
|
|
return copy;
|
||
|
|
}
|
||
|
|
|
||
|
|
int main(void) {
|
||
|
|
char *root = amduatd_test_make_temp_dir();
|
||
|
|
amduat_asl_store_fs_config_t cfg;
|
||
|
|
amduatd_store_ctx_t store_ctx;
|
||
|
|
amduat_asl_store_t store;
|
||
|
|
amduat_asl_log_record_t *records = NULL;
|
||
|
|
size_t record_count = 0;
|
||
|
|
amduat_asl_store_error_t scan_err;
|
||
|
|
|
||
|
|
if (root == NULL) {
|
||
|
|
return 1;
|
||
|
|
}
|
||
|
|
|
||
|
|
memset(&cfg, 0, sizeof(cfg));
|
||
|
|
if (!amduat_asl_store_fs_init_root(root, NULL, &cfg)) {
|
||
|
|
fprintf(stderr, "failed to init store root\n");
|
||
|
|
free(root);
|
||
|
|
return 1;
|
||
|
|
}
|
||
|
|
|
||
|
|
memset(&store_ctx, 0, sizeof(store_ctx));
|
||
|
|
memset(&store, 0, sizeof(store));
|
||
|
|
if (!amduatd_store_init(&store,
|
||
|
|
&cfg,
|
||
|
|
&store_ctx,
|
||
|
|
root,
|
||
|
|
AMDUATD_STORE_BACKEND_FS)) {
|
||
|
|
fprintf(stderr, "failed to init fs backend\n");
|
||
|
|
free(root);
|
||
|
|
return 1;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (store.ops.log_scan != NULL) {
|
||
|
|
fprintf(stderr, "fs backend unexpectedly supports log_scan\n");
|
||
|
|
free(root);
|
||
|
|
return 1;
|
||
|
|
}
|
||
|
|
|
||
|
|
scan_err = amduat_asl_log_scan(&store, &records, &record_count);
|
||
|
|
if (scan_err != AMDUAT_ASL_STORE_ERR_UNSUPPORTED) {
|
||
|
|
fprintf(stderr, "fs backend log_scan returned %d\n", (int)scan_err);
|
||
|
|
free(root);
|
||
|
|
return 1;
|
||
|
|
}
|
||
|
|
|
||
|
|
memset(&store_ctx, 0, sizeof(store_ctx));
|
||
|
|
memset(&store, 0, sizeof(store));
|
||
|
|
if (!amduatd_store_init(&store,
|
||
|
|
&cfg,
|
||
|
|
&store_ctx,
|
||
|
|
root,
|
||
|
|
AMDUATD_STORE_BACKEND_INDEX)) {
|
||
|
|
fprintf(stderr, "failed to init index backend\n");
|
||
|
|
free(root);
|
||
|
|
return 1;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (store.ops.log_scan == NULL) {
|
||
|
|
fprintf(stderr, "index backend missing log_scan\n");
|
||
|
|
free(root);
|
||
|
|
return 1;
|
||
|
|
}
|
||
|
|
|
||
|
|
scan_err = amduat_asl_log_scan(&store, &records, &record_count);
|
||
|
|
if (scan_err != AMDUAT_ASL_STORE_OK) {
|
||
|
|
fprintf(stderr, "index backend log_scan returned %d\n", (int)scan_err);
|
||
|
|
free(root);
|
||
|
|
return 1;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (records != NULL) {
|
||
|
|
amduat_enc_asl_log_free(records, record_count);
|
||
|
|
}
|
||
|
|
|
||
|
|
free(root);
|
||
|
|
return 0;
|
||
|
|
}
|