END_TEST /* * Check whether three nested sr_init() and sr_exit() calls work. * The three functions have three different contexts. * If any function returns != SR_OK (or segfaults) this test will fail. */ START_TEST(test_init_exit_3) { int ret; struct sr_context *sr_ctx1, *sr_ctx2, *sr_ctx3; ret = sr_init(&sr_ctx1); fail_unless(ret == SR_OK, "sr_init() 1 failed: %d.", ret); ret = sr_init(&sr_ctx2); fail_unless(ret == SR_OK, "sr_init() 2 failed: %d.", ret); ret = sr_init(&sr_ctx3); fail_unless(ret == SR_OK, "sr_init() 3 failed: %d.", ret); ret = sr_exit(sr_ctx3); fail_unless(ret == SR_OK, "sr_exit() 3 failed: %d.", ret); ret = sr_exit(sr_ctx2); fail_unless(ret == SR_OK, "sr_exit() 2 failed: %d.", ret); ret = sr_exit(sr_ctx1); fail_unless(ret == SR_OK, "sr_exit() 1 failed: %d.", ret); }
int main(int argc, char *argv[]) { QString locale = QLocale::system().name(); QApplication a(argc, argv); QTranslator translator; translator.load(QString("locale/sigrok-gui_") + locale); a.installTranslator(&translator); /* Set some application metadata. */ QApplication::setApplicationVersion(APP_VERSION); QApplication::setApplicationName("sigrok-gui"); QApplication::setOrganizationDomain("http://www.sigrok.org"); /* Disable this to actually allow running the (pre-alpha!) GUI. */ qDebug() << "The GUI is not yet usable, aborting."; // return 1; if (sr_init() != SR_OK) { qDebug() << "ERROR: libsigrok init failed."; return 1; } qDebug() << "libsigrok initialized successfully."; if (srd_init() != SRD_OK) { qDebug() << "ERROR: libsigrokdecode init failed."; return 1; } qDebug() << "libsigrokdecode initialized successfully."; w = new MainWindow; w->show(); return a.exec(); }
/** Do common setup for test_timely_consensus() and * test_early_consensus(). Call networkstatus_set_current_consensus() * on a constructed consensus and with an appropriately-modified * approx_time. Callers expect presence or absence of appropriate log * messages and control events. */ static int test_skew_common(void *arg, time_t now, unsigned long *offset) { char *consensus = NULL; int retval = 0; *offset = strtoul(arg, NULL, 10); /* Initialize the SRV subsystem */ MOCK(get_my_v3_authority_cert, get_my_v3_authority_cert_m); mock_cert = authority_cert_parse_from_string(AUTHORITY_CERT_1, strlen(AUTHORITY_CERT_1), NULL); sr_init(0); UNMOCK(get_my_v3_authority_cert); construct_consensus(&consensus, now); tt_assert(consensus); update_approx_time(now + *offset); mock_apparent_skew = 0; /* Caller will call UNMOCK() */ MOCK(clock_skew_warning, mock_clock_skew_warning); /* Caller will call teardown_capture_of_logs() */ setup_capture_of_logs(LOG_WARN); retval = networkstatus_set_current_consensus(consensus, strlen(consensus), "microdesc", 0, NULL); done: tor_free(consensus); return retval; }
void tcpipinit() { prog_name= "kernel TCP/IP"; mu_init(&mu_generic); mu_lock(&mu_generic); tcpip_dirinit(); sr_init_cap_names(); sr_set_cap_name(ETH_DEV0, "eth"); sr_set_cap_name(IP_DEV0, "ip"); sr_set_cap_name(TCP_DEV0, "tcp"); sr_set_cap_name(UDP_DEV0, "udp"); #if 0 sr_enable_linger_right(); #endif bf_init(); clck_init(); sr_init(); eth_init(); arp_init(); ip_init(); tcp_init(); udp_init(); add_default_gws(); mu_unlock(&mu_generic); tcpip_chmod(); }
void srtest_setup(void) { int ret; ret = sr_init(&srtest_ctx); fail_unless(ret == SR_OK, "sr_init() failed: %d.", ret); }
int main (int argc, char **argv) { g_type_init (); //sr_init_local ("/tmp/aa"); //test (); sr_init (); test (); return 0; }
END_TEST /* * Same as above, but sr_exit() in the "wrong" order. * This should work fine, it's not a bug to do this. */ START_TEST(test_init_exit_2_reverse) { int ret; struct sr_context *sr_ctx1, *sr_ctx2; ret = sr_init(&sr_ctx1); fail_unless(ret == SR_OK, "sr_init() 1 failed: %d.", ret); ret = sr_init(&sr_ctx2); fail_unless(ret == SR_OK, "sr_init() 2 failed: %d.", ret); ret = sr_exit(sr_ctx1); fail_unless(ret == SR_OK, "sr_exit() 1 failed: %d.", ret); ret = sr_exit(sr_ctx2); fail_unless(ret == SR_OK, "sr_exit() 2 failed: %d.", ret); }
END_TEST /* Check whether sr_init(NULL) fails as it should. */ START_TEST(test_init_null) { int ret; ret = sr_log_loglevel_set(SR_LOG_NONE); fail_unless(ret == SR_OK, "sr_log_loglevel_set() failed: %d.", ret); ret = sr_init(NULL); fail_unless(ret != SR_OK, "sr_init(NULL) should have failed."); }
PRIVATE void nw_init() { mq_init(); qp_init(); bf_init(); clck_init(); sr_init(); eth_init(); arp_init(); psip_init(); ip_init(); tcp_init(); udp_init(); }
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 ); }
PRIVATE void nw_init() { #if DEBUG & 256 { where(); printf("starting mq_init()\n"); } #endif mq_init(); #if DEBUG & 256 { where(); printf("starting bf_init()\n"); } #endif bf_init(); #if DEBUG & 256 { where(); printf("starting clck_init()\n"); } #endif clck_init(); #if DEBUG & 256 { where(); printf("starting sr_init()\n"); } #endif sr_init(); #if DEBUG & 256 { where(); printf("starting eth_init()\n"); } #endif eth_init(); #if DEBUG & 256 { where(); printf("starting arp_init()\n"); } #endif #if ENABLE_ARP arp_init(); #endif #if DEBUG & 256 { where(); printf("starting ip_init()\n"); } #endif #if ENABLE_IP ip_init(); #endif #if DEBUG & 256 { where(); printf("starting tcp_init()\n"); } #endif #if ENABLE_TCP tcp_init(); #endif #if DEBUG & 256 { where(); printf("starting udp_init()\n"); } #endif #if ENABLE_UDP udp_init(); #endif }
int main() { sr_init(SER_Pin, RCLK_Pin, SRCLK_Pin); int cycle = 0; while (1) { if (cycle > (1 << 8)) cycle = 0; display_bit_pattern(cycle); _delay_ms(DELAY_MS); cycle++; } return 0; }
static void svv_kv(stc *cx) { sra a; sr_aopen(&a, &sr_stda); srkey cmp; sr_keyinit(&cmp); srkeypart *part = sr_keyadd(&cmp, &a); t( sr_keypart_setname(part, &a, "key") == 0 ); t( sr_keypart_set(part, &a, "u32") == 0 ); sr r; sr_init(&r, NULL, &a, NULL, SR_FKV, &cmp, NULL, NULL, NULL); uint32_t key = 123; uint32_t value = 321; srformatv pv; pv.key = (char*)&key; pv.r.size = sizeof(key); pv.r.offset = 0; svv *vv = sv_vbuild(&r, &pv, 1, (char*)&value, sizeof(value)); t( vv != NULL ); vv->flags = SVSET; vv->lsn = 10; sv v; sv_init(&v, &sv_vif, vv, NULL); t( sv_flags(&v) == SVSET ); t( sv_lsn(&v) == 10 ); sv_lsnset(&v, 8); t( sv_lsn(&v) == 8 ); t( *(uint32_t*)sr_formatkey(sv_pointer(&v), 0) == key ); t( sr_formatkey_size(sv_pointer(&v), 0) == sizeof(key) ); t( *(uint32_t*)sr_formatvalue(SR_FKV, &cmp, sv_pointer(&v)) == value ); t( sr_formatvalue_size(SR_FKV, &cmp, sv_pointer(&v), sv_size(&v) ) == sizeof(value) ); sv_vfree(&a, vv); sr_keyfree(&cmp, &a); }
int main(int argc, char **argv) { GOptionContext *context; GError *error; g_log_set_default_handler(logger, NULL); error = NULL; context = g_option_context_new(NULL); g_option_context_add_main_entries(context, optargs, NULL); if (!g_option_context_parse(context, &argc, &argv, &error)) { g_critical("%s", error->message); return 1; } /* Set the loglevel (amount of messages to output) for libsigrok. */ if (sr_log_loglevel_set(opt_loglevel) != SR_OK) return 1; /* Set the loglevel (amount of messages to output) for libsigrokdecode. */ if (srd_log_loglevel_set(opt_loglevel) != SRD_OK) return 1; if (sr_init() != SR_OK) return 1; if (opt_pds) { if (srd_init(NULL) != SRD_OK) return 1; if (register_pds(NULL, opt_pds) != 0) return 1; if (srd_pd_output_callback_add(SRD_OUTPUT_ANN, show_pd_annotations, NULL) != SRD_OK) return 1; if (setup_pd_stack() != 0) return 1; if (setup_pd_annotations() != 0) return 1; } if (setup_output_format() != 0) return 1; if (opt_version) show_version(); else if (opt_list_devs) show_dev_list(); else if (opt_input_file) load_input_file(); else if (opt_samples || opt_time || opt_frames || opt_continuous) run_session(); else if (opt_dev) show_dev_detail(); else if (opt_pds) show_pd_detail(); else printf("%s", g_option_context_get_help(context, TRUE, NULL)); if (opt_pds) srd_exit(); g_option_context_free(context); sr_exit(); return 0; }
static void test_router_pick_directory_server_impl(void *arg) { (void)arg; networkstatus_t *con_md = NULL; char *consensus_text_md = NULL; int flags = PDS_IGNORE_FASCISTFIREWALL|PDS_RETRY_IF_NO_SERVERS; or_options_t *options = get_options_mutable(); const routerstatus_t *rs = NULL; options->UseMicrodescriptors = 1; char *router1_id = NULL, *router2_id = NULL, *router3_id = NULL; node_t *node_router1 = NULL, *node_router2 = NULL, *node_router3 = NULL; config_line_t *policy_line = NULL; time_t now = time(NULL); int tmp_dirport1, tmp_dirport3; (void)arg; MOCK(usable_consensus_flavor, mock_usable_consensus_flavor); /* With no consensus, we must be bootstrapping, regardless of time or flavor */ mock_usable_consensus_flavor_value = FLAV_NS; tt_assert(networkstatus_consensus_is_bootstrapping(now)); tt_assert(networkstatus_consensus_is_bootstrapping(now + 2000)); tt_assert(networkstatus_consensus_is_bootstrapping(now + 2*24*60*60)); tt_assert(networkstatus_consensus_is_bootstrapping(now - 2*24*60*60)); mock_usable_consensus_flavor_value = FLAV_MICRODESC; tt_assert(networkstatus_consensus_is_bootstrapping(now)); tt_assert(networkstatus_consensus_is_bootstrapping(now + 2000)); tt_assert(networkstatus_consensus_is_bootstrapping(now + 2*24*60*60)); tt_assert(networkstatus_consensus_is_bootstrapping(now - 2*24*60*60)); /* Init SR subsystem. */ MOCK(get_my_v3_authority_cert, get_my_v3_authority_cert_m); mock_cert = authority_cert_parse_from_string(AUTHORITY_CERT_1, strlen(AUTHORITY_CERT_1), NULL); sr_init(0); UNMOCK(get_my_v3_authority_cert); /* No consensus available, fail early */ rs = router_pick_directory_server_impl(V3_DIRINFO, (const int) 0, NULL); tt_ptr_op(rs, OP_EQ, NULL); construct_consensus(&consensus_text_md, now); tt_assert(consensus_text_md); con_md = networkstatus_parse_vote_from_string(consensus_text_md, strlen(consensus_text_md), NULL, NS_TYPE_CONSENSUS); tt_assert(con_md); tt_int_op(con_md->flavor,OP_EQ, FLAV_MICRODESC); tt_assert(con_md->routerstatus_list); tt_int_op(smartlist_len(con_md->routerstatus_list), OP_EQ, 3); tt_assert(!networkstatus_set_current_consensus_from_ns(con_md, "microdesc")); /* If the consensus time or flavor doesn't match, we are still * bootstrapping */ mock_usable_consensus_flavor_value = FLAV_NS; tt_assert(networkstatus_consensus_is_bootstrapping(now)); tt_assert(networkstatus_consensus_is_bootstrapping(now + 2000)); tt_assert(networkstatus_consensus_is_bootstrapping(now + 2*24*60*60)); tt_assert(networkstatus_consensus_is_bootstrapping(now - 2*24*60*60)); /* With a valid consensus for the current time and flavor, we stop * bootstrapping, even if we have no certificates */ mock_usable_consensus_flavor_value = FLAV_MICRODESC; tt_assert(!networkstatus_consensus_is_bootstrapping(now + 2000)); tt_assert(!networkstatus_consensus_is_bootstrapping(con_md->valid_after)); tt_assert(!networkstatus_consensus_is_bootstrapping(con_md->valid_until)); tt_assert(!networkstatus_consensus_is_bootstrapping(con_md->valid_until + 24*60*60)); /* These times are outside the test validity period */ tt_assert(networkstatus_consensus_is_bootstrapping(now + 2*24*60*60)); tt_assert(networkstatus_consensus_is_bootstrapping(now - 2*24*60*60)); nodelist_set_consensus(con_md); nodelist_assert_ok(); rs = router_pick_directory_server_impl(V3_DIRINFO, flags, NULL); /* We should not fail now we have a consensus and routerstatus_list * and nodelist are populated. */ tt_ptr_op(rs, OP_NE, NULL); /* Manipulate the nodes so we get the dir server we expect */ router1_id = tor_malloc(DIGEST_LEN); memset(router1_id, TEST_DIR_ROUTER_ID_1, DIGEST_LEN); router2_id = tor_malloc(DIGEST_LEN); memset(router2_id, TEST_DIR_ROUTER_ID_2, DIGEST_LEN); router3_id = tor_malloc(DIGEST_LEN); memset(router3_id, TEST_DIR_ROUTER_ID_3, DIGEST_LEN); node_router1 = node_get_mutable_by_id(router1_id); node_router2 = node_get_mutable_by_id(router2_id); node_router3 = node_get_mutable_by_id(router3_id); node_router1->is_possible_guard = 1; node_router1->is_running = 0; node_router3->is_running = 0; rs = router_pick_directory_server_impl(V3_DIRINFO, flags, NULL); tt_ptr_op(rs, OP_NE, NULL); tt_assert(tor_memeq(rs->identity_digest, router2_id, DIGEST_LEN)); rs = NULL; node_router1->is_running = 1; node_router3->is_running = 1; node_router1->rs->is_v2_dir = 0; node_router3->rs->is_v2_dir = 0; tmp_dirport1 = node_router1->rs->dir_port; tmp_dirport3 = node_router3->rs->dir_port; node_router1->rs->dir_port = 0; node_router3->rs->dir_port = 0; rs = router_pick_directory_server_impl(V3_DIRINFO, flags, NULL); tt_ptr_op(rs, OP_NE, NULL); tt_assert(tor_memeq(rs->identity_digest, router2_id, DIGEST_LEN)); rs = NULL; node_router1->rs->is_v2_dir = 1; node_router3->rs->is_v2_dir = 1; node_router1->rs->dir_port = tmp_dirport1; node_router3->rs->dir_port = tmp_dirport3; node_router1->is_valid = 0; node_router3->is_valid = 0; rs = router_pick_directory_server_impl(V3_DIRINFO, flags, NULL); tt_ptr_op(rs, OP_NE, NULL); tt_assert(tor_memeq(rs->identity_digest, router2_id, DIGEST_LEN)); rs = NULL; node_router1->is_valid = 1; node_router3->is_valid = 1; /* Manipulate overloaded */ node_router2->rs->last_dir_503_at = now; node_router3->rs->last_dir_503_at = now; rs = router_pick_directory_server_impl(V3_DIRINFO, flags, NULL); tt_ptr_op(rs, OP_NE, NULL); tt_assert(tor_memeq(rs->identity_digest, router1_id, DIGEST_LEN)); node_router2->rs->last_dir_503_at = 0; node_router3->rs->last_dir_503_at = 0; /* Set a Fascist firewall */ flags &= ~ PDS_IGNORE_FASCISTFIREWALL; policy_line = tor_malloc_zero(sizeof(config_line_t)); policy_line->key = tor_strdup("ReachableORAddresses"); policy_line->value = tor_strdup("accept *:442, reject *:*"); options->ReachableORAddresses = policy_line; policies_parse_from_options(options); node_router1->rs->or_port = 444; node_router2->rs->or_port = 443; node_router3->rs->or_port = 442; rs = router_pick_directory_server_impl(V3_DIRINFO, flags, NULL); tt_ptr_op(rs, OP_NE, NULL); tt_assert(tor_memeq(rs->identity_digest, router3_id, DIGEST_LEN)); node_router1->rs->or_port = 442; node_router2->rs->or_port = 443; node_router3->rs->or_port = 444; rs = router_pick_directory_server_impl(V3_DIRINFO, flags, NULL); tt_ptr_op(rs, OP_NE, NULL); tt_assert(tor_memeq(rs->identity_digest, router1_id, DIGEST_LEN)); /* Fascist firewall and overloaded */ node_router1->rs->or_port = 442; node_router2->rs->or_port = 443; node_router3->rs->or_port = 442; node_router3->rs->last_dir_503_at = now; rs = router_pick_directory_server_impl(V3_DIRINFO, flags, NULL); tt_ptr_op(rs, OP_NE, NULL); tt_assert(tor_memeq(rs->identity_digest, router1_id, DIGEST_LEN)); node_router3->rs->last_dir_503_at = 0; /* Fascists against OR and Dir */ policy_line = tor_malloc_zero(sizeof(config_line_t)); policy_line->key = tor_strdup("ReachableAddresses"); policy_line->value = tor_strdup("accept *:80, reject *:*"); options->ReachableDirAddresses = policy_line; policies_parse_from_options(options); node_router1->rs->or_port = 442; node_router2->rs->or_port = 441; node_router3->rs->or_port = 443; node_router1->rs->dir_port = 80; node_router2->rs->dir_port = 80; node_router3->rs->dir_port = 81; node_router1->rs->last_dir_503_at = now; rs = router_pick_directory_server_impl(V3_DIRINFO, flags, NULL); tt_ptr_op(rs, OP_NE, NULL); tt_assert(tor_memeq(rs->identity_digest, router1_id, DIGEST_LEN)); node_router1->rs->last_dir_503_at = 0; done: UNMOCK(usable_consensus_flavor); if (router1_id) tor_free(router1_id); if (router2_id) tor_free(router2_id); if (router3_id) tor_free(router3_id); if (options->ReachableORAddresses || options->ReachableDirAddresses) policies_free_all(); tor_free(consensus_text_md); networkstatus_vote_free(con_md); }
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; }
/** Test that we will use our directory guards to fetch mds even if we don't * have any dirinfo (tests bug #23862). */ static void test_directory_guard_fetch_with_no_dirinfo(void *arg) { int retval; char *consensus_text_md = NULL; or_options_t *options = get_options_mutable(); time_t now = time(NULL); (void) arg; hibernate_set_state_for_testing_(HIBERNATE_STATE_LIVE); /* Initialize the SRV subsystem */ MOCK(get_my_v3_authority_cert, get_my_v3_authority_cert_m); mock_cert = authority_cert_parse_from_string(AUTHORITY_CERT_1, strlen(AUTHORITY_CERT_1), NULL); sr_init(0); UNMOCK(get_my_v3_authority_cert); /* Initialize the entry node configuration from the ticket */ options->UseEntryGuards = 1; options->StrictNodes = 1; get_options_mutable()->EntryNodes = routerset_new(); routerset_parse(get_options_mutable()->EntryNodes, "2121212121212121212121212121212121212121", "foo"); /* Mock some functions */ dummy_state = tor_malloc_zero(sizeof(or_state_t)); MOCK(get_or_state, get_or_state_replacement); MOCK(directory_initiate_request, mock_directory_initiate_request); /* we need to mock this one to avoid memleaks */ MOCK(circuit_guard_state_new, mock_circuit_guard_state_new); /* Call guards_update_all() to simulate loading our state file (see * entry_guards_load_guards_from_state() and ticket #23989). */ guards_update_all(); /* Test logic: Simulate the arrival of a new consensus when we have no * dirinfo at all. Tor will need to fetch the mds from the consensus. Make * sure that Tor will use the specified entry guard instead of relying on the * fallback directories. */ /* Fixup the dirconn that will deliver the consensus */ dir_connection_t *conn = dir_connection_new(AF_INET); tor_addr_from_ipv4h(&conn->base_.addr, 0x7f000001); conn->base_.port = 8800; TO_CONN(conn)->address = tor_strdup("127.0.0.1"); conn->base_.purpose = DIR_PURPOSE_FETCH_CONSENSUS; conn->requested_resource = tor_strdup("ns"); /* Construct a consensus */ construct_consensus(&consensus_text_md, now); tt_assert(consensus_text_md); /* Place the consensus in the dirconn */ response_handler_args_t args; memset(&args, 0, sizeof(response_handler_args_t)); args.status_code = 200; args.body = consensus_text_md; args.body_len = strlen(consensus_text_md); /* Update approx time so that the consensus is considered live */ update_approx_time(now+1010); setup_capture_of_logs(LOG_DEBUG); /* Now handle the consensus */ retval = handle_response_fetch_consensus(conn, &args); tt_int_op(retval, OP_EQ, 0); /* Make sure that our primary guard was chosen */ expect_log_msg_containing("Selected primary guard router3"); done: tor_free(consensus_text_md); tor_free(dummy_state); connection_free_minimal(TO_CONN(conn)); entry_guards_free_all(); teardown_capture_of_logs(); }
int main(int argc, char **argv) { g_log_set_default_handler(logger, NULL); if (parse_options(argc, argv)) { return 1; } /* Set the loglevel (amount of messages to output) for libsigrok. */ if (sr_log_loglevel_set(opt_loglevel) != SR_OK) goto done; if (sr_init(&sr_ctx) != SR_OK) goto done; #ifdef HAVE_SRD /* Set the loglevel (amount of messages to output) for libsigrokdecode. */ if (srd_log_loglevel_set(opt_loglevel) != SRD_OK) goto done; if (opt_pds) { if (srd_init(NULL) != SRD_OK) goto done; if (srd_session_new(&srd_sess) != SRD_OK) { g_critical("Failed to create new decode session."); goto done; } if (register_pds(opt_pds, opt_pd_annotations) != 0) goto done; if (setup_pd_stack(opt_pds, opt_pd_stack, opt_pd_annotations) != 0) goto done; /* Only one output type is ever shown. */ if (opt_pd_binary) { if (setup_pd_binary(opt_pd_binary) != 0) goto done; if (srd_pd_output_callback_add(srd_sess, SRD_OUTPUT_BINARY, show_pd_binary, NULL) != SRD_OK) goto done; } else if (opt_pd_meta) { if (setup_pd_meta(opt_pd_meta) != 0) goto done; if (srd_pd_output_callback_add(srd_sess, SRD_OUTPUT_META, show_pd_meta, NULL) != SRD_OK) goto done; } else { if (opt_pd_annotations) if (setup_pd_annotations(opt_pd_annotations) != 0) goto done; if (srd_pd_output_callback_add(srd_sess, SRD_OUTPUT_ANN, show_pd_annotations, NULL) != SRD_OK) goto done; } } #endif if (opt_version) show_version(); else if (opt_input_format && opt_show) show_input(); else if (opt_output_format && opt_show) show_output(); else if (opt_transform_module && opt_show) show_transform(); else if (opt_scan_devs) show_dev_list(); #ifdef HAVE_SRD else if (opt_pds && opt_show) show_pd_detail(); #endif else if (opt_show) show_dev_detail(); else if (opt_input_file) load_input_file(); else if (opt_get) get_option(); else if (opt_set) set_options(); else if (opt_samples || opt_time || opt_frames || opt_continuous) run_session(); else show_help(); #ifdef HAVE_SRD if (opt_pds) srd_exit(); #endif done: if (sr_ctx) sr_exit(sr_ctx); return 0; }
int main(int argc, char **argv) { int c; char *host = ((char*)(DEFAULT_HOST)); char *user = 0; char *server = ((char*)(DEFAULT_SERVER)); char *rtable = ((char*)(DEFAULT_RTABLE)); char *sr_template = NULL; unsigned int port = DEFAULT_PORT; unsigned int topo = DEFAULT_TOPO; char *logfile = 0; struct sr_instance sr; sr.f_interface[0] = 'n'; sr.f_interface[1] = 'o'; sr.f_interface[2] = '\0'; sr.number_of_lsus = 5; printf("Using %s\n", VERSION_INFO); while ((c = getopt(argc, argv, "hs:v:p:u:t:r:l:T:f:c:")) != EOF) { switch (c) { case 'h': usage(argv[0]); exit(0); break; case 'p': port = atoi((char *) optarg); break; case 't': topo = atoi((char *) optarg); break; case 'v': host = optarg; break; case 'u': user = optarg; break; case 's': server = optarg; break; case 'l': logfile = optarg; break; case 'r': rtable = optarg; break; case 'T': sr_template = optarg; break; case 'f': for (unsigned int i = 0; i < strlen(optarg); i++) { sr.f_interface[i] = optarg[i]; } sr.f_interface[strlen(optarg)] = '\0'; break; case 'c': sr.number_of_lsus = atoi((char *) optarg); break; } /* switch */ } /* -- while -- */ /* -- zero out sr instance -- */ sr_init_instance(&sr); /* -- set up routing table from file -- */ if(sr_template == NULL) { sr.sr_template[0] = '\0'; sr_load_rt_wrap(&sr, rtable); } else strncpy(sr.sr_template, sr_template, 30); sr.topo_id = topo; strncpy(sr.host,host,32); if(! user ) { sr_set_user(&sr); } else { strncpy(sr.user, user, 32); } /* -- set up file pointer for logging of raw packets -- */ if(logfile != 0) { sr.logfile = sr_dump_open(logfile,0,PACKET_DUMP_SIZE); if(!sr.logfile) { fprintf(stderr,"Error opening up dump file %s\n", logfile); exit(1); } } Debug("Client %s connecting to Server %s:%d\n", sr.user, server, port); if(sr_template) Debug("Requesting topology template %s\n", sr_template); else { Debug("Requesting topology %d\n", topo); port = 12345; /* DGU TMP: use old port (no auth needed) */ Debug("(falling back to original port for -t type connection)\n"); } /* connect to server and negotiate session */ if(sr_connect_to_server(&sr,port,server) == -1) { return 1; } if(sr_template != NULL) { /* we've recv'd the rtable now, so read it in */ Debug("Connected to new instantiation of topology template %s\n", sr_template); sr_load_rt_wrap(&sr, ((char*)("rtable.vrhost"))); } /* call router init (for arp subsystem etc.) */ sr_init(&sr); /* -- whizbang main loop ;-) */ while( sr_read_from_server(&sr) == 1); sr_destroy_instance(&sr); return 0; }/* -- main -- */
void sr_unit_tests(void) { sr_init(); tg.communications_mode = STAT_JSON_MODE; sr_run_status_report(); }
int main(int argc, char **argv) { int c; char *host = DEFAULT_HOST; char *client = 0; char *server = DEFAULT_SERVER; char *rtable = DEFAULT_RTABLE; unsigned int port = DEFAULT_PORT; unsigned int topo = DEFAULT_TOPO; char *logfile = 0; struct sr_instance sr; while ((c = getopt(argc, argv, "hs:v:p:c:t:r:l:")) != EOF) { switch (c) { case 'h': usage(argv[0]); exit(0); break; case 'p': port = atoi((char *) optarg); break; case 't': topo = atoi((char *) optarg); break; case 'v': host = optarg; break; case 'c': client = optarg; break; case 's': server = optarg; break; case 'l': logfile = optarg; break; case 'r': rtable = optarg; break; } /* switch */ } /* -- while -- */ /* -- zero out sr instance -- */ sr_init_instance(&sr); /* -- set up routing table from file -- */ if(sr_load_rt(&sr, rtable) != 0) { fprintf(stderr,"Error setting up routing table from file %s\n", rtable); exit(1); } printf("Loading routing table\n"); printf("---------------------------------------------\n"); sr_print_routing_table(&sr); printf("---------------------------------------------\n"); sr.topo_id = topo; strncpy(sr.host,host,32); if(! client ) { sr_set_user(&sr); } else { strncpy(sr.user, client, 32); } /* -- set up file pointer for logging of raw packets -- */ if(logfile != 0) { sr.logfile = sr_dump_open(logfile,0,PACKET_DUMP_SIZE); if(!sr.logfile) { fprintf(stderr,"Error opening up dump file %s\n", logfile); exit(1); } } Debug("Client %s connecting to Server %s:%d\n", sr.user, server, port); Debug("Requesting topology %d\n", topo); /* connect to server and negotiate session */ if(sr_connect_to_server(&sr,port,server) == -1) { return 1; } /* call router init (for arp subsystem etc.) */ sr_init(&sr); /* -- whizbang main loop ;-) */ while( sr_read_from_server(&sr) == 1); sr_destroy_instance(&sr); return 0; }/* -- main -- */
int main( int argc, char **argv ) { /* these could also be declared as "void *" */ simple_reader *srd, *sri; int index = -1; int nindex = 0, nindex_used = 0; int ndata = 0, nkeep = 0; if( argc < 3 ) { fprintf( stderr, "Usage: %s FILE INDEX > TRIMMED_FILE\n", argv[0] ); fprintf( stderr, " **NOTE: assumes sorted INDEX (monotonically increasing)\n" ); return EXIT_FAILURE; } srd = sr_init( argv[1] ); /* input DATA file */ sri = sr_init( argv[2] ); /* input INDEX file */ fprintf( stderr, "TRIMMING: %s\n", sr_filename( srd ) ); fprintf( stderr, "FROM INDEX: %s\n", sr_filename( sri ) ); /* loop over input data file */ while( sr_readline( srd ) ) { char *line; line = sr_line( srd ); if( sr_line_isempty( srd ) ) continue; if( '#' == line[0] ) continue; ndata += 1; /* ndata is the appropriate 1-based input index, comments and blank lines skipped */ while( index < ndata ) { index = get_next_index( sri, index ); if( index < 1 ) break; nindex += 1; } if( ndata == index ) { nkeep += 1; fprintf( stdout, "%s\n", line ); } if( sr_eof( sri ) ) break; } nindex_used = nindex; /* check to see how much longer index is */ while( !sr_eof( sri ) ) { index = get_next_index( sri, index ); if( index < 1 ) break; nindex += 1; } fprintf( stderr, "INDEX: used %d of %d entries\n", nindex_used, nindex ); srd = sr_kill( srd ); sri = sr_kill( sri ); fprintf( stderr, "INPUT: kept %d of %d read (could be truncated due to short INDEX)\n", nkeep, ndata ); return EXIT_SUCCESS; }
int main(int argc, char *argv[]) { int ret = 0; struct sr_context *sr_ctx = NULL; const char *open_file = NULL; QApplication a(argc, argv); // Set some application metadata QApplication::setApplicationVersion(DS_VERSION_STRING); QApplication::setApplicationName("DSLogic(Beta)"); QApplication::setOrganizationDomain("http://www.DreamSourceLab.com"); // Parse arguments while (1) { static const struct option long_options[] = { {"loglevel", required_argument, 0, 'l'}, {"version", no_argument, 0, 'V'}, {"help", no_argument, 0, 'h'}, {0, 0, 0, 0} }; const int c = getopt_long(argc, argv, "l:Vh?", long_options, NULL); if (c == -1) break; switch (c) { case 'l': { const int loglevel = atoi(optarg); sr_log_loglevel_set(loglevel); #ifdef ENABLE_DECODE srd_log_loglevel_set(loglevel); #endif break; } case 'V': // Print version info fprintf(stdout, "%s %s\n", DS_TITLE, DS_VERSION_STRING); return 0; case 'h': case '?': usage(); return 0; } } if (argc - optind > 1) { fprintf(stderr, "Only one file can be openened.\n"); return 1; } else if (argc - optind == 1) open_file = argv[argc - 1]; // Initialise libsigrok if (sr_init(&sr_ctx) != SR_OK) { qDebug() << "ERROR: libsigrok init failed."; return 1; } do { #ifdef ENABLE_DECODE QDir dir(QCoreApplication::applicationDirPath()); assert(dir.cd("decoders")); std::string str = dir.absolutePath().toStdString() + "/"; strcpy(decoders_path, str.c_str()); // Initialise libsigrokdecode if (srd_init(NULL) != SRD_OK) { qDebug() << "ERROR: libsigrokdecode init failed."; break; } // Load the protocol decoders srd_decoder_load_all(); #endif try { // Create the device manager, initialise the drivers pv::DeviceManager device_manager(sr_ctx); // Initialise the main window pv::MainWindow w(device_manager, open_file); QFile qss(":/stylesheet.qss"); qss.open(QFile::ReadOnly); a.setStyleSheet(qss.readAll()); qss.close(); w.show(); // Run the application ret = a.exec(); } catch(std::exception e) { qDebug() << e.what(); } #ifdef ENABLE_DECODE // Destroy libsigrokdecode srd_exit(); #endif } while (0); // Destroy libsigrok if (sr_ctx) sr_exit(sr_ctx); return ret; }