static void ssslaba_test0(void) { ssa a; ss_aopen(&a, &ss_slaba, &st_r.vfs, 1024, 16); void *chunks[64]; int chunks_size = 64; int iteration = 0; while (iteration < 8) { int i = 0; while ( i < chunks_size) { chunks[i] = ss_malloc(&a, 16); t( chunks[i] != NULL ); i++; } t(i == 64); t( ss_malloc(&a, 16) == NULL ); i = 0; while ( i < chunks_size) { ss_free(&a, chunks[i]); t( chunks[i] != NULL ); i++; } iteration++; } ss_aclose(&a); }
static void ss_rq_test3(void) { ssa a; ss_aopen(&a, &ss_stda); ssrq q; t( ss_rqinit(&q, &a, 1, 10) == 0 ); ssrqnode *an = ss_malloc(&a, sizeof(ssrqnode)); ssrqnode *bn = ss_malloc(&a, sizeof(ssrqnode)); ssrqnode *cn = ss_malloc(&a, sizeof(ssrqnode)); t( an != NULL ); t( bn != NULL ); t( cn != NULL ); ss_rqinitnode(an); ss_rqinitnode(bn); ss_rqinitnode(cn); ss_rqadd(&q, an, 1); ss_rqadd(&q, bn, 2); ss_rqdelete(&q, bn); ss_rqadd(&q, cn, 3); int i = 3; ssrqnode *n = NULL; while ((n = ss_rqprev(&q, n))) { t( i == n->v ); i = 1; } ss_rqfree(&q, &a); ss_free(&a, an); ss_free(&a, bn); ss_free(&a, cn); }
static void ss_rq_test8(void) { ssa a; ss_aopen(&a, &ss_stda); ssrq q; t( ss_rqinit(&q, &a, 10, 100) == 0 ); ssrqnode *an = ss_malloc(&a, sizeof(ssrqnode)); ssrqnode *bn = ss_malloc(&a, sizeof(ssrqnode)); ssrqnode *cn = ss_malloc(&a, sizeof(ssrqnode)); ssrqnode *dn = ss_malloc(&a, sizeof(ssrqnode)); t( an != NULL ); t( bn != NULL ); t( cn != NULL ); t( dn != NULL ); ss_rqinitnode(an); ss_rqinitnode(bn); ss_rqinitnode(cn); ss_rqinitnode(dn); ss_rqadd(&q, an, 0); ss_rqadd(&q, bn, 10); ss_rqadd(&q, cn, 20); ss_rqadd(&q, dn, 30); int i = 30; ssrqnode *n = NULL; while ((n = ss_rqprev(&q, n))) i -= 10; ss_rqfree(&q, &a); ss_free(&a, an); ss_free(&a, bn); ss_free(&a, cn); ss_free(&a, dn); }
static void ssa_malloc(void) { ssa a; ss_aopen(&a, &ss_stda); void *buf = ss_malloc(&a, 123); t( buf != NULL ); ss_free(&a, buf); ss_aclose(&a); }
static void ss_rq_test0(void) { ssa a; ss_aopen(&a, &ss_stda); ssrq q; t( ss_rqinit(&q, &a, 1, 10) == 0 ); ss_rqfree(&q, &a); }
static void mt_multi_stmt(stc *cx) { cx->env = sp_env(); t( cx->env != NULL ); void *c = sp_ctl(cx->env); t( c != NULL ); t( sp_set(c, "sophia.path", cx->suite->sophiadir) == 0 ); t( sp_set(c, "scheduler.threads", "3") == 0 ); t( sp_set(c, "log.path", cx->suite->logdir) == 0 ); t( sp_set(c, "log.sync", "0") == 0 ); t( sp_set(c, "log.rotate_sync", "0") == 0 ); t( sp_set(c, "db", "test") == 0 ); t( sp_set(c, "db.test.path", cx->suite->dir) == 0 ); t( sp_set(c, "db.test.sync", "0") == 0 ); cx->db = sp_get(c, "db.test"); t( cx->db != NULL ); t( sp_open(cx->env) == 0 ); ssa a; ss_aopen(&a, &ss_stda); srscheme cmp; sr_schemeinit(&cmp); srkey *part = sr_schemeadd(&cmp, &a); t( sr_keysetname(part, &a, "key") == 0 ); t( sr_keyset(part, &a, "u32") == 0 ); ssinjection ij; memset(&ij, 0, sizeof(ij)); srerror error; sr_errorinit(&error); srseq seq; sr_seqinit(&seq); sscrcf crc = ss_crc32c_function(); sr r; sr_init(&r, &error, &a, &seq, SF_KV, SF_SRAW, &cmp, &ij, crc, NULL); soworkers w; so_workersinit(&w); void *ptr[2] = { cx->env, cx->db }; t( so_workersnew(&w, &r, 5, multi_stmt_thread, (void*)ptr) == 0 ); t( so_workersshutdown(&w, &r) == 0 ); sr_schemefree(&cmp, &a); void *o = sp_get(c, "db.test.index.count"); t( o != NULL ); t( strcmp( sp_get(o, "value", NULL), "100000") == 0 ); sp_destroy(o); t( sp_destroy(cx->env) == 0 ); }
static void ssaslab_reuse(stc *cx) { sspager p; ss_pagerinit(&p, 3, 1024); ssa slab; t( ss_aopen(&slab, &ss_slaba, &p, 32) == 0 ); void *alloc0[1000]; void *alloc1[1000]; memset(alloc0, 0, sizeof(alloc0)); memset(alloc1, 0, sizeof(alloc1)); int i = 0; while (i < 1000) { alloc0[i] = ss_malloc(&slab, 0); t( alloc0[i] != NULL ); i++; } i--; int pools = p.pools; while (i >= 0) { ss_free(&slab, alloc0[i]); i--; } t( p.pools == pools ); i++; while (i < 1000) { alloc1[i] = ss_malloc(&slab, 0); t( alloc0[i] == alloc1[i] ); i++; } t( p.pools == pools ); ss_aclose(&slab); ss_pagerfree(&p); }
static void sd_read_gt0(void) { sdbuild b; sd_buildinit(&b); t( sd_buildbegin(&b, &st_r.r, 1, 0, 0, 0, NULL) == 0); int key = 7; addv(&b, &st_r.r, 3, 0, &key); key = 8; addv(&b, &st_r.r, 4, 0, &key); key = 9; addv(&b, &st_r.r, 5, 0, &key); sd_buildend(&b, &st_r.r); sdindex index; sd_indexinit(&index); t( sd_indexbegin(&index, &st_r.r) == 0 ); int rc; rc = sd_indexadd(&index, &st_r.r, &b, sizeof(sdseal)); t( rc == 0 ); sdid id; memset(&id, 0, sizeof(id)); ssfile f; ss_fileinit(&f, &st_r.vfs); t( ss_filenew(&f, "./0000.db") == 0 ); t( sd_writeseal(&st_r.r, &f, NULL) == 0 ); t( sd_writepage(&st_r.r, &f, NULL, &b) == 0 ); t( sd_indexcommit(&index, &st_r.r, &id, NULL, f.size) == 0 ); t( sd_writeindex(&st_r.r, &f, NULL, &index) == 0 ); t( sd_seal(&st_r.r, &f, NULL, &index, 0) == 0 ); ssmmap map; t( ss_vfsmmap(&st_r.vfs, &map, f.fd, f.size, 1) == 0 ); ssbuf buf; ss_bufinit(&buf); ssbuf xfbuf; ss_bufinit(&xfbuf); t( ss_bufensure(&xfbuf, &st_r.a, 1024) == 0 ); ssiter index_iter; ssiter page_iter; sdreadarg arg = { .index = &index, .buf = &buf, .buf_xf = &xfbuf, .buf_read = NULL, .index_iter = &index_iter, .page_iter = &page_iter, .mmap = &map, .memory = NULL, .file = NULL, .o = SS_GT, .use_memory = 0, .use_mmap = 1, .use_mmap_copy = 0, .use_compression = 0, .compression_if = NULL, .has = 0, .has_vlsn = 0, .r = &st_r.r }; ssiter it; ss_iterinit(sd_read, &it); ss_iteropen(sd_read, &it, &arg, NULL, 0); t( ss_iteratorhas(&it) == 1 ); sv *v = ss_iteratorof(&it); t( *(int*)sv_field(v, &st_r.r, 0, NULL) == 7); ss_iteratornext(&it); v = ss_iteratorof(&it); t( *(int*)sv_field(v, &st_r.r, 0, NULL) == 8); ss_iteratornext(&it); v = ss_iteratorof(&it); t( *(int*)sv_field(v, &st_r.r, 0, NULL) == 9); ss_iteratornext(&it); t( ss_iteratorhas(&it) == 0 ); ss_iteratorclose(&it); ss_fileclose(&f); t( ss_vfsmunmap(&st_r.vfs, &map) == 0 ); t( ss_vfsunlink(&st_r.vfs, "./0000.db") == 0 ); sd_indexfree(&index, &st_r.r); sd_buildfree(&b, &st_r.r); ss_buffree(&xfbuf, &st_r.a); ss_buffree(&buf, &st_r.a); } static void sd_read_gt1(void) { ssfile f; ss_fileinit(&f, &st_r.vfs); t( ss_filenew(&f, "./0000.db") == 0 ); t( sd_writeseal(&st_r.r, &f, NULL) == 0 ); sdbuild b; sd_buildinit(&b); t( sd_buildbegin(&b, &st_r.r, 1, 0, 0, 0, NULL) == 0); int key = 7; addv(&b, &st_r.r, 3, 0, &key); key = 8; addv(&b, &st_r.r, 4, 0, &key); key = 9; addv(&b, &st_r.r, 5, 0, &key); sd_buildend(&b, &st_r.r); uint64_t poff = f.size; t( sd_writepage(&st_r.r, &f, NULL, &b) == 0 ); sdindex index; sd_indexinit(&index); t( sd_indexbegin(&index, &st_r.r) == 0 ); int rc; rc = sd_indexadd(&index, &st_r.r, &b, poff); t( rc == 0 ); t( sd_buildcommit(&b, &st_r.r) == 0 ); t( sd_buildbegin(&b, &st_r.r, 1, 0, 0, 0, NULL) == 0); key = 10; addv(&b, &st_r.r, 6, 0, &key); key = 11; addv(&b, &st_r.r, 7, 0, &key); key = 13; addv(&b, &st_r.r, 8, 0, &key); sd_buildend(&b, &st_r.r); poff = f.size; t( sd_writepage(&st_r.r, &f, NULL, &b) == 0 ); rc = sd_indexadd(&index, &st_r.r, &b, poff); t( rc == 0 ); t( sd_buildcommit(&b, &st_r.r) == 0 ); t( sd_buildbegin(&b, &st_r.r, 1, 0, 0, 0, NULL) == 0); key = 15; addv(&b, &st_r.r, 9, 0, &key); key = 18; addv(&b, &st_r.r, 10, 0, &key); key = 20; addv(&b, &st_r.r, 11, 0, &key); sd_buildend(&b, &st_r.r); poff = f.size; t( sd_writepage(&st_r.r, &f, NULL, &b) == 0 ); rc = sd_indexadd(&index, &st_r.r, &b, poff); t( rc == 0 ); t( sd_buildcommit(&b, &st_r.r) == 0 ); sdid id; memset(&id, 0, sizeof(id)); t( sd_indexcommit(&index, &st_r.r, &id, NULL, f.size) == 0 ); t( sd_writeindex(&st_r.r, &f, NULL, &index) == 0 ); t( sd_seal(&st_r.r, &f, NULL, &index, 0) == 0 ); ssmmap map; t( ss_vfsmmap(&st_r.vfs, &map, f.fd, f.size, 1) == 0 ); ssbuf buf; ss_bufinit(&buf); ssbuf xfbuf; ss_bufinit(&xfbuf); t( ss_bufensure(&xfbuf, &st_r.a, 1024) == 0 ); ssiter index_iter; ssiter page_iter; sdreadarg arg = { .index = &index, .buf = &buf, .buf_xf = &xfbuf, .buf_read = NULL, .index_iter = &index_iter, .page_iter = &page_iter, .mmap = &map, .memory = NULL, .file = NULL, .o = SS_GT, .use_memory = 0, .use_mmap = 1, .use_mmap_copy = 0, .use_compression = 0, .compression_if = NULL, .has = 0, .has_vlsn = 0, .r = &st_r.r }; ssiter it; ss_iterinit(sd_read, &it); ss_iteropen(sd_read, &it, &arg, NULL, 0); t( ss_iteratorhas(&it) == 1 ); /* page 0 */ t( ss_iteratorhas(&it) != 0 ); sv *v = ss_iteratorof(&it); t( *(int*)sv_field(v, &st_r.r, 0, NULL) == 7); ss_iteratornext(&it); v = ss_iteratorof(&it); t( *(int*)sv_field(v, &st_r.r, 0, NULL) == 8); ss_iteratornext(&it); v = ss_iteratorof(&it); t( *(int*)sv_field(v, &st_r.r, 0, NULL) == 9); ss_iteratornext(&it); /* page 1 */ v = ss_iteratorof(&it); t( *(int*)sv_field(v, &st_r.r, 0, NULL) == 10); ss_iteratornext(&it); v = ss_iteratorof(&it); t( *(int*)sv_field(v, &st_r.r, 0, NULL) == 11); ss_iteratornext(&it); v = ss_iteratorof(&it); t( *(int*)sv_field(v, &st_r.r, 0, NULL) == 13); ss_iteratornext(&it); /* page 2 */ v = ss_iteratorof(&it); t( *(int*)sv_field(v, &st_r.r, 0, NULL) == 15); ss_iteratornext(&it); v = ss_iteratorof(&it); t( *(int*)sv_field(v, &st_r.r, 0, NULL) == 18); ss_iteratornext(&it); v = ss_iteratorof(&it); t( *(int*)sv_field(v, &st_r.r, 0, NULL) == 20); ss_iteratornext(&it); t( ss_iteratorhas(&it) == 0 ); ss_iteratorclose(&it); ss_fileclose(&f); t( ss_vfsmunmap(&st_r.vfs, &map) == 0 ); t( ss_vfsunlink(&st_r.vfs, "./0000.db") == 0 ); sd_indexfree(&index, &st_r.r); sd_buildfree(&b, &st_r.r); ss_buffree(&xfbuf, &st_r.a); ss_buffree(&buf, &st_r.a); } static void sd_read_gt0_compression_zstd(void) { ssa a; ss_aopen(&a, &ss_stda); ssa aref; ss_aopen(&aref, &ss_stda); ssvfs vfs; ss_vfsinit(&vfs, &ss_stdvfs); sfscheme cmp; sf_schemeinit(&cmp); sffield *field = sf_fieldnew(&a, "key"); t( sf_fieldoptions(field, &a, "u32,key(0)") == 0 ); t( sf_schemeadd(&cmp, &a, field) == 0 ); field = sf_fieldnew(&a, "value"); t( sf_fieldoptions(field, &a, "string") == 0 ); t( sf_schemeadd(&cmp, &a, field) == 0 ); t( sf_schemevalidate(&cmp, &a) == 0 ); ssinjection ij; memset(&ij, 0, sizeof(ij)); srstat stat; memset(&stat, 0, sizeof(stat)); srerror error; sr_errorinit(&error); srseq seq; sr_seqinit(&seq); sscrcf crc = ss_crc32c_function(); sr r; sr_init(&r, NULL, &error, &a, &aref, &vfs, NULL, NULL, &seq, SF_RAW, NULL, &cmp, &ij, &stat, crc); sdbuild b; sd_buildinit(&b); t( sd_buildbegin(&b, &r, 1, 0, 0, 1, &ss_zstdfilter) == 0); int key = 7; addv(&b, &r, 3, 0, &key); key = 8; addv(&b, &r, 4, 0, &key); key = 9; addv(&b, &r, 5, 0, &key); t( sd_buildend(&b, &r) == 0 ); sdindex index; sd_indexinit(&index); t( sd_indexbegin(&index, &r) == 0 ); int rc; rc = sd_indexadd(&index, &r, &b, sizeof(sdseal)); t( rc == 0 ); sdid id; memset(&id, 0, sizeof(id)); ssfile f; ss_fileinit(&f, &vfs); t( ss_filenew(&f, "./0000.db") == 0 ); t( sd_writeseal(&r, &f, NULL) == 0 ); t( sd_writepage(&r, &f, NULL, &b) == 0 ); t( sd_indexcommit(&index, &r, &id, NULL, f.size) == 0 ); t( sd_writeindex(&r, &f, NULL, &index) == 0 ); t( sd_seal(&r, &f, NULL, &index, 0) == 0 ); t( sd_buildcommit(&b, &r) == 0 ); ssmmap map; t( ss_vfsmmap(&st_r.vfs, &map, f.fd, f.size, 1) == 0 ); ssbuf buf; ss_bufinit(&buf); ssbuf xfbuf; ss_bufinit(&xfbuf); t( ss_bufensure(&xfbuf, &a, 1024) == 0 ); ssiter index_iter; ssiter page_iter; sdreadarg arg = { .index = &index, .buf = &buf, .buf_xf = &xfbuf, .buf_read = NULL, .index_iter = &index_iter, .page_iter = &page_iter, .mmap = &map, .memory = NULL, .file = NULL, .o = SS_GT, .use_memory = 0, .use_mmap = 1, .use_mmap_copy = 0, .use_compression = 1, .compression_if = &ss_zstdfilter, .has = 0, .has_vlsn = 0, .r = &r }; ssiter it; ss_iterinit(sd_read, &it); ss_iteropen(sd_read, &it, &arg, NULL, 0); t( ss_iteratorhas(&it) == 1 ); sv *v = ss_iteratorof(&it); t( *(int*)sv_field(v, &r, 0, NULL) == 7); ss_iteratornext(&it); v = ss_iteratorof(&it); t( *(int*)sv_field(v, &r, 0, NULL) == 8); ss_iteratornext(&it); v = ss_iteratorof(&it); t( *(int*)sv_field(v, &r, 0, NULL) == 9); ss_iteratornext(&it); t( ss_iteratorhas(&it) == 0 ); ss_iteratorclose(&it); ss_fileclose(&f); t( ss_vfsmunmap(&st_r.vfs, &map) == 0 ); t( ss_vfsunlink(&vfs, "./0000.db") == 0 ); sd_indexfree(&index, &r); sd_buildfree(&b, &r); ss_buffree(&xfbuf, &a); ss_buffree(&buf, &a); sf_schemefree(&cmp, &a); } static void sd_read_gt0_compression_lz4(void) { ssa a; ss_aopen(&a, &ss_stda); ssa aref; ss_aopen(&aref, &ss_stda); ssvfs vfs; ss_vfsinit(&vfs, &ss_stdvfs); sfscheme cmp; sf_schemeinit(&cmp); sffield *field = sf_fieldnew(&a, "key"); t( sf_fieldoptions(field, &a, "u32,key(0)") == 0 ); t( sf_schemeadd(&cmp, &a, field) == 0 ); field = sf_fieldnew(&a, "value"); t( sf_fieldoptions(field, &a, "string") == 0 ); t( sf_schemeadd(&cmp, &a, field) == 0 ); t( sf_schemevalidate(&cmp, &a) == 0 ); ssinjection ij; memset(&ij, 0, sizeof(ij)); srstat stat; memset(&stat, 0, sizeof(stat)); srerror error; sr_errorinit(&error); srseq seq; sr_seqinit(&seq); sscrcf crc = ss_crc32c_function(); sr r; sr_init(&r, NULL, &error, &a, &aref, &vfs, NULL, NULL, &seq, SF_RAW, NULL, &cmp, &ij, &stat, crc); sdbuild b; sd_buildinit(&b); t( sd_buildbegin(&b, &r, 1, 0, 0, 1, &ss_lz4filter) == 0); int key = 7; addv(&b, &r, 3, 0, &key); key = 8; addv(&b, &r, 4, 0, &key); key = 9; addv(&b, &r, 5, 0, &key); t( sd_buildend(&b, &r) == 0 ); sdindex index; sd_indexinit(&index); t( sd_indexbegin(&index, &r) == 0 ); int rc; rc = sd_indexadd(&index, &r, &b, sizeof(sdseal)); t( rc == 0 ); sdid id; memset(&id, 0, sizeof(id)); t( sd_indexcommit(&index, &r, &id, NULL, 0) == 0 ); ssfile f; ss_fileinit(&f, &vfs); t( ss_filenew(&f, "./0000.db") == 0 ); t( sd_writeseal(&r, &f, NULL) == 0 ); t( sd_writepage(&r, &f, NULL, &b) == 0 ); t( sd_indexcommit(&index, &r, &id, NULL, f.size) == 0 ); t( sd_writeindex(&r, &f, NULL, &index) == 0 ); t( sd_seal(&r, &f, NULL, &index, 0) == 0 ); ssmmap map; t( ss_vfsmmap(&st_r.vfs, &map, f.fd, f.size, 1) == 0 ); t( sd_buildcommit(&b, &r) == 0 ); ssbuf buf; ss_bufinit(&buf); ssbuf xfbuf; ss_bufinit(&xfbuf); t( ss_bufensure(&xfbuf, &a, 1024) == 0 ); ssiter index_iter; ssiter page_iter; sdreadarg arg = { .index = &index, .buf = &buf, .buf_xf = &xfbuf, .buf_read = NULL, .index_iter = &index_iter, .page_iter = &page_iter, .mmap = &map, .memory = NULL, .file = NULL, .o = SS_GT, .use_memory = 0, .use_mmap = 1, .use_mmap_copy = 0, .use_compression = 1, .compression_if = &ss_lz4filter, .has = 0, .has_vlsn = 0, .r = &r }; ssiter it; ss_iterinit(sd_read, &it); ss_iteropen(sd_read, &it, &arg, NULL, 0); t( ss_iteratorhas(&it) == 1 ); sv *v = ss_iteratorof(&it); t( *(int*)sv_field(v, &r, 0, NULL) == 7); ss_iteratornext(&it); v = ss_iteratorof(&it); t( *(int*)sv_field(v, &r, 0, NULL) == 8); ss_iteratornext(&it); v = ss_iteratorof(&it); t( *(int*)sv_field(v, &r, 0, NULL) == 9); ss_iteratornext(&it); t( ss_iteratorhas(&it) == 0 ); ss_iteratorclose(&it); ss_fileclose(&f); t( ss_vfsmunmap(&st_r.vfs, &map) == 0 ); t( ss_vfsunlink(&vfs, "./0000.db") == 0 ); sd_indexfree(&index, &r); sd_buildfree(&b, &r); ss_buffree(&xfbuf, &a); ss_buffree(&buf, &a); sf_schemefree(&cmp, &a); } static void sd_read_gt1_compression_zstd(void) { ssa a; ss_aopen(&a, &ss_stda); ssa aref; ss_aopen(&aref, &ss_stda); ssvfs vfs; ss_vfsinit(&vfs, &ss_stdvfs); sfscheme cmp; sf_schemeinit(&cmp); sffield *field = sf_fieldnew(&a, "key"); t( sf_fieldoptions(field, &a, "u32,key(0)") == 0 ); t( sf_schemeadd(&cmp, &a, field) == 0 ); field = sf_fieldnew(&a, "value"); t( sf_fieldoptions(field, &a, "string") == 0 ); t( sf_schemeadd(&cmp, &a, field) == 0 ); t( sf_schemevalidate(&cmp, &a) == 0 ); ssinjection ij; memset(&ij, 0, sizeof(ij)); srstat stat; memset(&stat, 0, sizeof(stat)); srerror error; sr_errorinit(&error); srseq seq; sr_seqinit(&seq); sscrcf crc = ss_crc32c_function(); sr r; sr_init(&r, NULL, &error, &a, &aref, &vfs, NULL, NULL, &seq, SF_RAW, NULL, &cmp, &ij, &stat, crc); ssfile f; ss_fileinit(&f, &vfs); t( ss_filenew(&f, "./0000.db") == 0 ); t( sd_writeseal(&r, &f, NULL) == 0 ); sdbuild b; sd_buildinit(&b); t( sd_buildbegin(&b, &r, 1, 0, 0, 1, &ss_zstdfilter) == 0); int key = 7; addv(&b, &r, 3, 0, &key); key = 8; addv(&b, &r, 4, 0, &key); key = 9; addv(&b, &r, 5, 0, &key); sd_buildend(&b, &r); uint64_t poff = f.size; t( sd_writepage(&r, &f, NULL, &b) == 0 ); sdindex index; sd_indexinit(&index); t( sd_indexbegin(&index, &r) == 0 ); int rc; rc = sd_indexadd(&index, &r, &b, poff); t( rc == 0 ); t( sd_buildcommit(&b, &r) == 0 ); sd_buildreset(&b, &r); t( sd_buildbegin(&b, &r, 1, 0, 0, 1, &ss_zstdfilter) == 0); key = 10; addv(&b, &r, 6, 0, &key); key = 11; addv(&b, &r, 7, 0, &key); key = 13; addv(&b, &r, 8, 0, &key); sd_buildend(&b, &r); poff = f.size; t( sd_writepage(&r, &f, NULL, &b) == 0 ); rc = sd_indexadd(&index, &r, &b, poff); t( rc == 0 ); t( sd_buildcommit(&b, &r) == 0 ); sd_buildreset(&b, &r); t( sd_buildbegin(&b, &r, 1, 0, 0, 1, &ss_zstdfilter) == 0); key = 15; addv(&b, &r, 9, 0, &key); key = 18; addv(&b, &r, 10, 0, &key); key = 20; addv(&b, &r, 11, 0, &key); sd_buildend(&b, &r); poff = f.size; t( sd_writepage(&r, &f, NULL, &b) == 0 ); rc = sd_indexadd(&index, &r, &b, poff); t( rc == 0 ); t( sd_buildcommit(&b, &r) == 0 ); sdid id; memset(&id, 0, sizeof(id)); t( sd_indexcommit(&index, &r, &id, NULL, f.size) == 0 ); t( sd_writeindex(&r, &f, NULL, &index) == 0 ); t( sd_seal(&r, &f, NULL, &index, 0) == 0 ); ssmmap map; t( ss_vfsmmap(&st_r.vfs, &map, f.fd, f.size, 1) == 0 ); ssbuf buf; ss_bufinit(&buf); ssbuf xfbuf; ss_bufinit(&xfbuf); t( ss_bufensure(&xfbuf, &a, 1024) == 0 ); ssiter index_iter; ssiter page_iter; sdreadarg arg = { .index = &index, .buf = &buf, .buf_xf = &xfbuf, .buf_read = NULL, .index_iter = &index_iter, .page_iter = &page_iter, .mmap = &map, .memory = NULL, .file = NULL, .o = SS_GT, .use_memory = 0, .use_mmap = 1, .use_mmap_copy = 0, .use_compression = 1, .compression_if = &ss_zstdfilter, .has = 0, .has_vlsn = 0, .r = &r }; ssiter it; ss_iterinit(sd_read, &it); ss_iteropen(sd_read, &it, &arg, NULL, 0); t( ss_iteratorhas(&it) == 1 ); /* page 0 */ t( ss_iteratorhas(&it) != 0 ); sv *v = ss_iteratorof(&it); t( *(int*)sv_field(v, &r, 0, NULL) == 7); ss_iteratornext(&it); v = ss_iteratorof(&it); t( *(int*)sv_field(v, &r, 0, NULL) == 8); ss_iteratornext(&it); v = ss_iteratorof(&it); t( *(int*)sv_field(v, &r, 0, NULL) == 9); ss_iteratornext(&it); /* page 1 */ v = ss_iteratorof(&it); t( *(int*)sv_field(v, &r, 0, NULL) == 10); ss_iteratornext(&it); v = ss_iteratorof(&it); t( *(int*)sv_field(v, &r, 0, NULL) == 11); ss_iteratornext(&it); v = ss_iteratorof(&it); t( *(int*)sv_field(v, &r, 0, NULL) == 13); ss_iteratornext(&it); /* page 2 */ v = ss_iteratorof(&it); t( *(int*)sv_field(v, &r, 0, NULL) == 15); ss_iteratornext(&it); v = ss_iteratorof(&it); t( *(int*)sv_field(v, &r, 0, NULL) == 18); ss_iteratornext(&it); v = ss_iteratorof(&it); t( *(int*)sv_field(v, &r, 0, NULL) == 20); ss_iteratornext(&it); t( ss_iteratorhas(&it) == 0 ); ss_iteratorclose(&it); ss_fileclose(&f); t( ss_vfsmunmap(&st_r.vfs, &map) == 0 ); t( ss_vfsunlink(&vfs, "./0000.db") == 0 ); sd_indexfree(&index, &r); sd_buildfree(&b, &r); ss_buffree(&buf, &a); ss_buffree(&xfbuf, &a); sf_schemefree(&cmp, &a); } static void sd_read_gt1_compression_lz4(void) { ssa a; ss_aopen(&a, &ss_stda); ssa aref; ss_aopen(&aref, &ss_stda); ssvfs vfs; ss_vfsinit(&vfs, &ss_stdvfs); sfscheme cmp; sf_schemeinit(&cmp); sffield *field = sf_fieldnew(&a, "key"); t( sf_fieldoptions(field, &a, "u32,key(0)") == 0 ); t( sf_schemeadd(&cmp, &a, field) == 0 ); field = sf_fieldnew(&a, "value"); t( sf_fieldoptions(field, &a, "string") == 0 ); t( sf_schemeadd(&cmp, &a, field) == 0 ); t( sf_schemevalidate(&cmp, &a) == 0 ); ssinjection ij; memset(&ij, 0, sizeof(ij)); srstat stat; memset(&stat, 0, sizeof(stat)); srerror error; sr_errorinit(&error); srseq seq; sr_seqinit(&seq); sscrcf crc = ss_crc32c_function(); sr r; sr_init(&r, NULL, &error, &a, &aref, &vfs, NULL, NULL, &seq, SF_RAW, NULL, &cmp, &ij, &stat, crc); ssfile f; ss_fileinit(&f, &vfs); t( ss_filenew(&f, "./0000.db") == 0 ); t( sd_writeseal(&r, &f, NULL) == 0 ); sdbuild b; sd_buildinit(&b); t( sd_buildbegin(&b, &r, 1, 0, 0, 1, &ss_lz4filter) == 0); int key = 7; addv(&b, &r, 3, 0, &key); key = 8; addv(&b, &r, 4, 0, &key); key = 9; addv(&b, &r, 5, 0, &key); sd_buildend(&b, &r); uint64_t poff = f.size; t( sd_writepage(&r, &f, NULL, &b) == 0 ); sdindex index; sd_indexinit(&index); t( sd_indexbegin(&index, &r) == 0 ); int rc; rc = sd_indexadd(&index, &r, &b, poff); t( rc == 0 ); t( sd_buildcommit(&b, &r) == 0 ); sd_buildreset(&b, &r); t( sd_buildbegin(&b, &r, 1, 0, 0, 1, &ss_lz4filter) == 0); key = 10; addv(&b, &r, 6, 0, &key); key = 11; addv(&b, &r, 7, 0, &key); key = 13; addv(&b, &r, 8, 0, &key); sd_buildend(&b, &r); poff = f.size; t( sd_writepage(&r, &f, NULL, &b) == 0 ); rc = sd_indexadd(&index, &r, &b, poff); t( rc == 0 ); t( sd_buildcommit(&b, &r) == 0 ); sd_buildreset(&b, &r); t( sd_buildbegin(&b, &r, 1, 0, 0, 1, &ss_lz4filter) == 0); key = 15; addv(&b, &r, 9, 0, &key); key = 18; addv(&b, &r, 10, 0, &key); key = 20; addv(&b, &r, 11, 0, &key); sd_buildend(&b, &r); poff = f.size; t( sd_writepage(&r, &f, NULL, &b) == 0 ); rc = sd_indexadd(&index, &r, &b, poff); t( rc == 0 ); t( sd_buildcommit(&b, &r) == 0 ); sdid id; memset(&id, 0, sizeof(id)); t( sd_indexcommit(&index, &r, &id, NULL, f.size) == 0 ); t( sd_writeindex(&r, &f, NULL, &index) == 0 ); t( sd_seal(&r, &f, NULL, &index, 0) == 0 ); ssmmap map; t( ss_vfsmmap(&st_r.vfs, &map, f.fd, f.size, 1) == 0 ); ssbuf buf; ss_bufinit(&buf); ssbuf xfbuf; ss_bufinit(&xfbuf); t( ss_bufensure(&xfbuf, &a, 1024) == 0 ); ssiter index_iter; ssiter page_iter; sdreadarg arg = { .index = &index, .buf = &buf, .buf_xf = &xfbuf, .buf_read = NULL, .index_iter = &index_iter, .page_iter = &page_iter, .mmap = &map, .memory = NULL, .file = NULL, .o = SS_GT, .use_memory = 0, .use_mmap = 1, .use_mmap_copy = 0, .use_compression = 1, .compression_if = &ss_lz4filter, .has = 0, .has_vlsn = 0, .r = &r }; ssiter it; ss_iterinit(sd_read, &it); ss_iteropen(sd_read, &it, &arg, NULL, 0); t( ss_iteratorhas(&it) == 1 ); /* page 0 */ t( ss_iteratorhas(&it) != 0 ); sv *v = ss_iteratorof(&it); t( *(int*)sv_field(v, &r, 0, NULL) == 7); ss_iteratornext(&it); v = ss_iteratorof(&it); t( *(int*)sv_field(v, &r, 0, NULL) == 8); ss_iteratornext(&it); v = ss_iteratorof(&it); t( *(int*)sv_field(v, &r, 0, NULL) == 9); ss_iteratornext(&it); /* page 1 */ v = ss_iteratorof(&it); t( *(int*)sv_field(v, &r, 0, NULL) == 10); ss_iteratornext(&it); v = ss_iteratorof(&it); t( *(int*)sv_field(v, &r, 0, NULL) == 11); ss_iteratornext(&it); v = ss_iteratorof(&it); t( *(int*)sv_field(v, &r, 0, NULL) == 13); ss_iteratornext(&it); /* page 2 */ v = ss_iteratorof(&it); t( *(int*)sv_field(v, &r, 0, NULL) == 15); ss_iteratornext(&it); v = ss_iteratorof(&it); t( *(int*)sv_field(v, &r, 0, NULL) == 18); ss_iteratornext(&it); v = ss_iteratorof(&it); t( *(int*)sv_field(v, &r, 0, NULL) == 20); ss_iteratornext(&it); t( ss_iteratorhas(&it) == 0 ); ss_iteratorclose(&it); ss_fileclose(&f); t( ss_vfsmunmap(&st_r.vfs, &map) == 0 ); t( ss_vfsunlink(&vfs, "./0000.db") == 0 ); sd_indexfree(&index, &r); sd_buildfree(&b, &r); ss_buffree(&buf, &a); ss_buffree(&xfbuf, &a); sf_schemefree(&cmp, &a); } stgroup *sd_read_group(void) { stgroup *group = st_group("sdread"); st_groupadd(group, st_test("gt0", sd_read_gt0)); st_groupadd(group, st_test("gt1", sd_read_gt1)); st_groupadd(group, st_test("gt0_compression_zstd", sd_read_gt0_compression_zstd)); st_groupadd(group, st_test("gt0_compression_lz4", sd_read_gt0_compression_lz4)); st_groupadd(group, st_test("gt1_compression_zstd", sd_read_gt1_compression_zstd)); st_groupadd(group, st_test("gt1_compression_lz4", sd_read_gt1_compression_lz4)); return group; }