From 3a3088b2704eec5858c1b36ac990ca6c6a15d646 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sun, 24 Feb 2019 13:04:36 +0100 Subject: [PATCH] more code cleanup, better error handing in tests --- po/POTFILES.in | 114 +++++++------- src/namestore/test_hostkey | Bin 827 -> 0 bytes .../test_namestore_api_monitoring_existing.c | 10 +- .../test_namestore_api_zone_iteration_nick.c | 136 +++++------------ ...mestore_api_zone_iteration_specific_zone.c | 16 +- .../test_namestore_api_zone_iteration_stop.c | 142 ++++++------------ 6 files changed, 147 insertions(+), 271 deletions(-) diff --git a/po/POTFILES.in b/po/POTFILES.in index 09e4c533d..0d4569514 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -4,14 +4,6 @@ src/arm/arm_monitor_api.c src/arm/gnunet-arm.c src/arm/gnunet-service-arm.c src/arm/mockup-service.c -src/ats-tests/ats-testing-experiment.c -src/ats-tests/ats-testing-log.c -src/ats-tests/ats-testing-preferences.c -src/ats-tests/ats-testing-traffic.c -src/ats-tests/ats-testing.c -src/ats-tests/gnunet-ats-sim.c -src/ats-tests/gnunet-solver-eval.c -src/ats-tool/gnunet-ats.c src/ats/ats_api2_application.c src/ats/ats_api2_transport.c src/ats/ats_api_connectivity.c @@ -19,10 +11,10 @@ src/ats/ats_api_performance.c src/ats/ats_api_scanner.c src/ats/ats_api_scheduling.c src/ats/gnunet-ats-solver-eval.c -src/ats/gnunet-service-ats-new.c -src/ats/gnunet-service-ats.c src/ats/gnunet-service-ats_addresses.c +src/ats/gnunet-service-ats.c src/ats/gnunet-service-ats_connectivity.c +src/ats/gnunet-service-ats-new.c src/ats/gnunet-service-ats_normalization.c src/ats/gnunet-service-ats_performance.c src/ats/gnunet-service-ats_plugins.c @@ -34,6 +26,14 @@ src/ats/plugin_ats2_simple.c src/ats/plugin_ats_mlp.c src/ats/plugin_ats_proportional.c src/ats/plugin_ats_ril.c +src/ats-tests/ats-testing.c +src/ats-tests/ats-testing-experiment.c +src/ats-tests/ats-testing-log.c +src/ats-tests/ats-testing-preferences.c +src/ats-tests/ats-testing-traffic.c +src/ats-tests/gnunet-ats-sim.c +src/ats-tests/gnunet-solver-eval.c +src/ats-tool/gnunet-ats.c src/auction/gnunet-auction-create.c src/auction/gnunet-auction-info.c src/auction/gnunet-auction-join.c @@ -50,8 +50,8 @@ src/cadet/cadet_api_list_peers.c src/cadet/cadet_api_list_tunnels.c src/cadet/cadet_test_lib.c src/cadet/desirability_table.c -src/cadet/gnunet-cadet-profiler.c src/cadet/gnunet-cadet.c +src/cadet/gnunet-cadet-profiler.c src/cadet/gnunet-service-cadet.c src/cadet/gnunet-service-cadet_channel.c src/cadet/gnunet-service-cadet_connection.c @@ -67,15 +67,15 @@ src/consensus/gnunet-service-consensus.c src/consensus/plugin_block_consensus.c src/conversation/conversation_api.c src/conversation/conversation_api_call.c -src/conversation/gnunet-conversation-test.c src/conversation/gnunet-conversation.c -src/conversation/gnunet-helper-audio-playback-gst.c +src/conversation/gnunet-conversation-test.c +src/conversation/gnunet_gst.c +src/conversation/gnunet_gst_test.c src/conversation/gnunet-helper-audio-playback.c -src/conversation/gnunet-helper-audio-record-gst.c +src/conversation/gnunet-helper-audio-playback-gst.c src/conversation/gnunet-helper-audio-record.c +src/conversation/gnunet-helper-audio-record-gst.c src/conversation/gnunet-service-conversation.c -src/conversation/gnunet_gst.c -src/conversation/gnunet_gst_test.c src/conversation/microphone.c src/conversation/plugin_gnsrecord_conversation.c src/conversation/speaker.c @@ -111,6 +111,7 @@ src/dht/dht_api.c src/dht/dht_test_lib.c src/dht/gnunet-dht-get.c src/dht/gnunet-dht-monitor.c +src/dht/gnunet_dht_profiler.c src/dht/gnunet-dht-put.c src/dht/gnunet-service-dht.c src/dht/gnunet-service-dht_clients.c @@ -119,7 +120,6 @@ src/dht/gnunet-service-dht_hello.c src/dht/gnunet-service-dht_neighbours.c src/dht/gnunet-service-dht_nse.c src/dht/gnunet-service-dht_routing.c -src/dht/gnunet_dht_profiler.c src/dht/plugin_block_dht.c src/dns/dns_api.c src/dns/gnunet-dns-monitor.c @@ -129,8 +129,8 @@ src/dns/gnunet-service-dns.c src/dns/gnunet-zonewalk.c src/dns/plugin_block_dns.c src/exit/gnunet-daemon-exit.c -src/exit/gnunet-helper-exit-windows.c src/exit/gnunet-helper-exit.c +src/exit/gnunet-helper-exit-windows.c src/fragmentation/defragmentation.c src/fragmentation/fragmentation.c src/fs/fs_api.c @@ -155,8 +155,8 @@ src/fs/gnunet-auto-share.c src/fs/gnunet-daemon-fsprofiler.c src/fs/gnunet-directory.c src/fs/gnunet-download.c -src/fs/gnunet-fs-profiler.c src/fs/gnunet-fs.c +src/fs/gnunet-fs-profiler.c src/fs/gnunet-helper-fs-publish.c src/fs/gnunet-publish.c src/fs/gnunet-search.c @@ -176,10 +176,10 @@ src/gns/gns_tld_api.c src/gns/gnunet-bcd.c src/gns/gnunet-dns2gns.c src/gns/gnunet-gns-benchmark.c +src/gns/gnunet-gns.c src/gns/gnunet-gns-helper-service-w32.c src/gns/gnunet-gns-import.c src/gns/gnunet-gns-proxy.c -src/gns/gnunet-gns.c src/gns/gnunet-service-gns.c src/gns/gnunet-service-gns_interceptor.c src/gns/gnunet-service-gns_resolver.c @@ -187,19 +187,19 @@ src/gns/nss/nss_gns.c src/gns/nss/nss_gns_query.c src/gns/plugin_block_gns.c src/gns/plugin_gnsrecord_gns.c -src/gns/w32nsp-install.c -src/gns/w32nsp-resolve.c -src/gns/w32nsp-uninstall.c -src/gns/w32nsp.c src/gnsrecord/gnsrecord.c src/gnsrecord/gnsrecord_crypto.c src/gnsrecord/gnsrecord_misc.c src/gnsrecord/gnsrecord_serialization.c src/gnsrecord/plugin_gnsrecord_dns.c +src/gns/w32nsp.c +src/gns/w32nsp-install.c +src/gns/w32nsp-resolve.c +src/gns/w32nsp-uninstall.c src/hello/address.c src/hello/gnunet-hello.c -src/hello/hello-ng.c src/hello/hello.c +src/hello/hello-ng.c src/hostlist/gnunet-daemon-hostlist.c src/hostlist/gnunet-daemon-hostlist_client.c src/hostlist/gnunet-daemon-hostlist_server.c @@ -222,8 +222,8 @@ src/namecache/namecache_api.c src/namecache/plugin_namecache_flat.c src/namecache/plugin_namecache_postgres.c src/namecache/plugin_namecache_sqlite.c -src/namestore/gnunet-namestore-fcfsd.c src/namestore/gnunet-namestore.c +src/namestore/gnunet-namestore-fcfsd.c src/namestore/gnunet-service-namestore.c src/namestore/gnunet-zoneimport.c src/namestore/namestore_api.c @@ -238,10 +238,10 @@ src/nat-auto/gnunet-service-nat-auto.c src/nat-auto/gnunet-service-nat-auto_legacy.c src/nat-auto/nat_auto_api.c src/nat-auto/nat_auto_api_test.c -src/nat/gnunet-helper-nat-client-windows.c src/nat/gnunet-helper-nat-client.c -src/nat/gnunet-helper-nat-server-windows.c +src/nat/gnunet-helper-nat-client-windows.c src/nat/gnunet-helper-nat-server.c +src/nat/gnunet-helper-nat-server-windows.c src/nat/gnunet-nat.c src/nat/gnunet-service-nat.c src/nat/gnunet-service-nat_externalip.c @@ -250,16 +250,16 @@ src/nat/gnunet-service-nat_mini.c src/nat/gnunet-service-nat_stun.c src/nat/nat_api.c src/nat/nat_api_stun.c -src/nse/gnunet-nse-profiler.c src/nse/gnunet-nse.c +src/nse/gnunet-nse-profiler.c src/nse/gnunet-service-nse.c src/nse/nse_api.c src/nt/nt.c -src/peerinfo-tool/gnunet-peerinfo.c -src/peerinfo-tool/gnunet-peerinfo_plugins.c src/peerinfo/gnunet-service-peerinfo.c src/peerinfo/peerinfo_api.c src/peerinfo/peerinfo_api_notify.c +src/peerinfo-tool/gnunet-peerinfo.c +src/peerinfo-tool/gnunet-peerinfo_plugins.c src/peerstore/gnunet-peerstore.c src/peerstore/gnunet-service-peerstore.c src/peerstore/peerstore_api.c @@ -295,6 +295,7 @@ src/regex/regex_internal_dht.c src/regex/regex_test_graph.c src/regex/regex_test_lib.c src/regex/regex_test_random.c +src/rest/gnunet-rest-server.c src/rest-plugins/json_reclaim.c src/rest-plugins/oidc_helper.c src/rest-plugins/plugin_rest_copying.c @@ -305,28 +306,27 @@ src/rest-plugins/plugin_rest_namestore.c src/rest-plugins/plugin_rest_openid_connect.c src/rest-plugins/plugin_rest_peerinfo.c src/rest-plugins/plugin_rest_reclaim.c -src/rest/gnunet-rest-server.c src/rest/rest.c src/revocation/gnunet-revocation.c src/revocation/gnunet-service-revocation.c src/revocation/plugin_block_revocation.c src/revocation/revocation_api.c -src/rps/gnunet-rps-profiler.c src/rps/gnunet-rps.c +src/rps/gnunet-rps-profiler.c src/rps/gnunet-service-rps.c src/rps/gnunet-service-rps_custommap.c src/rps/gnunet-service-rps_sampler.c src/rps/gnunet-service-rps_sampler_elem.c src/rps/gnunet-service-rps_view.c +src/rps/rps_api.c src/rps/rps-sampler_client.c src/rps/rps-sampler_common.c src/rps/rps-test_util.c -src/rps/rps_api.c src/scalarproduct/gnunet-scalarproduct.c -src/scalarproduct/gnunet-service-scalarproduct-ecc_alice.c -src/scalarproduct/gnunet-service-scalarproduct-ecc_bob.c src/scalarproduct/gnunet-service-scalarproduct_alice.c src/scalarproduct/gnunet-service-scalarproduct_bob.c +src/scalarproduct/gnunet-service-scalarproduct-ecc_alice.c +src/scalarproduct/gnunet-service-scalarproduct-ecc_bob.c src/scalarproduct/scalarproduct_api.c src/secretsharing/gnunet-secretsharing-profiler.c src/secretsharing/gnunet-service-secretsharing.c @@ -352,16 +352,15 @@ src/statistics/gnunet-statistics.c src/statistics/statistics_api.c src/template/gnunet-service-template.c src/template/gnunet-template.c -src/testbed-logger/gnunet-service-testbed-logger.c -src/testbed-logger/testbed_logger_api.c src/testbed/generate-underlay-topology.c src/testbed/gnunet-daemon-latency-logger.c src/testbed/gnunet-daemon-testbed-blacklist.c src/testbed/gnunet-daemon-testbed-underlay.c src/testbed/gnunet-helper-testbed.c +src/testbed/gnunet_mpi_test.c src/testbed/gnunet-service-test-barriers.c -src/testbed/gnunet-service-testbed.c src/testbed/gnunet-service-testbed_barriers.c +src/testbed/gnunet-service-testbed.c src/testbed/gnunet-service-testbed_cache.c src/testbed/gnunet-service-testbed_connectionpool.c src/testbed/gnunet-service-testbed_cpustatus.c @@ -369,19 +368,20 @@ src/testbed/gnunet-service-testbed_links.c src/testbed/gnunet-service-testbed_meminfo.c src/testbed/gnunet-service-testbed_oc.c src/testbed/gnunet-service-testbed_peers.c -src/testbed/gnunet-testbed-profiler.c -src/testbed/gnunet_mpi_test.c src/testbed/gnunet_testbed_mpi_spawn.c -src/testbed/testbed_api.c +src/testbed/gnunet-testbed-profiler.c +src/testbed-logger/gnunet-service-testbed-logger.c +src/testbed-logger/testbed_logger_api.c src/testbed/testbed_api_barriers.c +src/testbed/testbed_api.c src/testbed/testbed_api_hosts.c src/testbed/testbed_api_operations.c src/testbed/testbed_api_peers.c src/testbed/testbed_api_sd.c src/testbed/testbed_api_services.c src/testbed/testbed_api_statistics.c -src/testbed/testbed_api_test.c src/testbed/testbed_api_testbed.c +src/testbed/testbed_api_test.c src/testbed/testbed_api_topology.c src/testbed/testbed_api_underlay.c src/testing/gnunet-testing.c @@ -393,29 +393,29 @@ src/transport/gnunet-communicator-tcp.c src/transport/gnunet-communicator-udp.c src/transport/gnunet-communicator-unix.c src/transport/gnunet-helper-transport-bluetooth.c -src/transport/gnunet-helper-transport-wlan-dummy.c src/transport/gnunet-helper-transport-wlan.c +src/transport/gnunet-helper-transport-wlan-dummy.c src/transport/gnunet-service-tng.c -src/transport/gnunet-service-transport.c src/transport/gnunet-service-transport_ats.c +src/transport/gnunet-service-transport.c src/transport/gnunet-service-transport_hello.c src/transport/gnunet-service-transport_manipulation.c src/transport/gnunet-service-transport_neighbours.c src/transport/gnunet-service-transport_plugins.c src/transport/gnunet-service-transport_validation.c +src/transport/gnunet-transport.c src/transport/gnunet-transport-certificate-creation.c src/transport/gnunet-transport-profiler.c src/transport/gnunet-transport-wlan-receiver.c src/transport/gnunet-transport-wlan-sender.c -src/transport/gnunet-transport.c src/transport/plugin_transport_http_client.c src/transport/plugin_transport_http_common.c src/transport/plugin_transport_http_server.c src/transport/plugin_transport_smtp.c src/transport/plugin_transport_tcp.c src/transport/plugin_transport_template.c -src/transport/plugin_transport_udp.c src/transport/plugin_transport_udp_broadcasting.c +src/transport/plugin_transport_udp.c src/transport/plugin_transport_unix.c src/transport/plugin_transport_wlan.c src/transport/plugin_transport_xt.c @@ -424,11 +424,6 @@ src/transport/tcp_connection_legacy.c src/transport/tcp_server_legacy.c src/transport/tcp_server_mst_legacy.c src/transport/tcp_service_legacy.c -src/transport/transport-testing-filenames.c -src/transport/transport-testing-loggers.c -src/transport/transport-testing-main.c -src/transport/transport-testing-send.c -src/transport/transport-testing.c src/transport/transport_api2_address.c src/transport/transport_api2_communication.c src/transport/transport_api2_core.c @@ -441,6 +436,11 @@ src/transport/transport_api_manipulation.c src/transport/transport_api_monitor_peers.c src/transport/transport_api_monitor_plugins.c src/transport/transport_api_offer_hello.c +src/transport/transport-testing.c +src/transport/transport-testing-filenames.c +src/transport/transport-testing-loggers.c +src/transport/transport-testing-main.c +src/transport/transport-testing-send.c src/util/bandwidth.c src/util/benchmark.c src/util/bio.c @@ -453,8 +453,8 @@ src/util/configuration_loader.c src/util/container_bloomfilter.c src/util/container_heap.c src/util/container_meta_data.c -src/util/container_multihashmap.c src/util/container_multihashmap32.c +src/util/container_multihashmap.c src/util/container_multipeermap.c src/util/container_multishortmap.c src/util/crypto_abe.c @@ -476,15 +476,15 @@ src/util/dnsparser.c src/util/dnsstub.c src/util/getopt.c src/util/getopt_helpers.c -src/util/gnunet-config-diff.c src/util/gnunet-config.c +src/util/gnunet-config-diff.c src/util/gnunet-ecc.c src/util/gnunet-helper-w32-console.c src/util/gnunet-resolver.c src/util/gnunet-scrypt.c src/util/gnunet-service-resolver.c -src/util/gnunet-timeout-w32.c src/util/gnunet-timeout.c +src/util/gnunet-timeout-w32.c src/util/gnunet-uri.c src/util/helper.c src/util/load.c @@ -513,13 +513,13 @@ src/util/tun.c src/util/w32cat.c src/util/win.c src/util/winproc.c -src/vpn/gnunet-helper-vpn-windows.c src/vpn/gnunet-helper-vpn.c +src/vpn/gnunet-helper-vpn-windows.c src/vpn/gnunet-service-vpn.c src/vpn/gnunet-vpn.c src/vpn/vpn_api.c -src/zonemaster/gnunet-service-zonemaster-monitor.c src/zonemaster/gnunet-service-zonemaster.c +src/zonemaster/gnunet-service-zonemaster-monitor.c src/fs/fs_api.h src/include/compat.h src/include/gnunet_common.h diff --git a/src/namestore/test_hostkey b/src/namestore/test_hostkey index 81f461e7d3af45971bf3c3ab95cdff32a3b16873..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 100644 GIT binary patch literal 0 HcmV?d00001 literal 827 zcmZR!*08Y3POa2UNi0d^QqV9ouqr4`%E?UD1qyO0C}@~kr6#8o1Eqj$L#qN~V=IRL zK)}GjzzD=}01|@%O{n5TA{76DDNZsrvWhxpdSjK<@|=#_B{KwcDeYxmd`s+ z9r}~38VFNd2(no)X7aDzh>t7Y?@p__b^Y+Xs(^wv-dAp4AAD}A*%|rWM%Uy>5=*jp zdata); - GNUNET_free (s_rd_1); + privkey = NULL; } - if (s_rd_2 != NULL) - { - GNUNET_free ((void *)s_rd_2->data); - GNUNET_free (s_rd_2); - } - if (s_rd_3 != NULL) + if (privkey2 != NULL) { - GNUNET_free ((void *)s_rd_3->data); - GNUNET_free (s_rd_3); + GNUNET_free (privkey2); + privkey2 = NULL; } - if (nsh != NULL) - GNUNET_NAMESTORE_disconnect (nsh); - nsh = NULL; } static int check_zone_1 (const char *label, unsigned int rd_count, - const struct GNUNET_GNSRECORD_Data *rd) + const struct GNUNET_GNSRECORD_Data *rd) { - int failed = GNUNET_NO; - int c; - for (c = 0; c< rd_count ; c++) + for (unsigned int c = 0; c< rd_count ; c++) { - if (rd[c].record_type == GNUNET_GNSRECORD_TYPE_NICK) - if (0 != strcmp (rd[c].data, ZONE_NICK_1)) - { - GNUNET_break (0); - return GNUNET_YES; - } + if ( (rd[c].record_type == GNUNET_GNSRECORD_TYPE_NICK) && + (0 != strcmp (rd[c].data, ZONE_NICK_1)) ) + { + GNUNET_break (0); + return GNUNET_YES; + } } - return failed; + return GNUNET_NO; } + static int check_zone_2 (const char *label, - unsigned int rd_count, - const struct GNUNET_GNSRECORD_Data *rd) + unsigned int rd_count, + const struct GNUNET_GNSRECORD_Data *rd) { - int failed = GNUNET_NO; - int c; - - for (c = 0; c< rd_count ; c++) + for (unsigned int c = 0; c< rd_count ; c++) { - if (rd[c].record_type == GNUNET_GNSRECORD_TYPE_NICK) - if (0 != strcmp (rd[c].data, ZONE_NICK_2)) - { - GNUNET_break (0); - return GNUNET_YES; - } + if ( (rd[c].record_type == GNUNET_GNSRECORD_TYPE_NICK) && + (0 != strcmp (rd[c].data, ZONE_NICK_2)) ) + { + GNUNET_break (0); + return GNUNET_YES; + } } - - return failed; + return GNUNET_NO; } @@ -208,7 +157,7 @@ zone_proc_end (void *cls) GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received last result, iteration done after receing %u results\n", returned_records); - GNUNET_SCHEDULER_add_now (&end, NULL); + GNUNET_SCHEDULER_shutdown (); } @@ -254,7 +203,7 @@ zone_proc (void *cls, { GNUNET_break (0); res = 1; - GNUNET_SCHEDULER_add_now (&end, NULL); + GNUNET_SCHEDULER_shutdown (); } } @@ -283,9 +232,7 @@ put_cont (void *cls, GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to created records: `%s'\n", emsg); GNUNET_break (0); - if (NULL != endbadly_task) - GNUNET_SCHEDULER_cancel (endbadly_task); - endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); + GNUNET_SCHEDULER_shutdown (); return; } @@ -306,9 +253,7 @@ put_cont (void *cls, { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to create zone iterator\n"); GNUNET_break (0); - if (NULL != endbadly_task) - GNUNET_SCHEDULER_cancel (endbadly_task); - endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); + GNUNET_SCHEDULER_shutdown (); return; } } @@ -406,9 +351,7 @@ empty_zone_proc (void *cls, GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Expected empty zone but received zone private key\n")); GNUNET_break (0); - if (endbadly_task != NULL) - GNUNET_SCHEDULER_cancel (endbadly_task); - endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); + GNUNET_SCHEDULER_shutdown (); return; } if ((NULL != label) || (NULL != rd) || (0 != rd_count)) @@ -416,9 +359,7 @@ empty_zone_proc (void *cls, GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Expected no zone content but received data\n")); GNUNET_break (0); - if (endbadly_task != NULL) - GNUNET_SCHEDULER_cancel (endbadly_task); - endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); + GNUNET_SCHEDULER_shutdown (); return; } GNUNET_assert (0); @@ -454,12 +395,10 @@ run (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, struct GNUNET_TESTING_Peer *peer) { - endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, - &endbadly, - NULL); nsh = GNUNET_NAMESTORE_connect (cfg); GNUNET_break (NULL != nsh); - + GNUNET_SCHEDULER_add_shutdown (&end, + NULL); /* first, iterate over empty namestore */ zi = GNUNET_NAMESTORE_zone_iteration_start(nsh, NULL, @@ -474,8 +413,7 @@ run (void *cls, GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to create zone iterator\n"); GNUNET_break (0); - GNUNET_SCHEDULER_cancel (endbadly_task); - endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); + GNUNET_SCHEDULER_shutdown (); } } diff --git a/src/namestore/test_namestore_api_zone_iteration_specific_zone.c b/src/namestore/test_namestore_api_zone_iteration_specific_zone.c index 0be9bab98..cbcd94cd5 100644 --- a/src/namestore/test_namestore_api_zone_iteration_specific_zone.c +++ b/src/namestore/test_namestore_api_zone_iteration_specific_zone.c @@ -98,9 +98,9 @@ end (void *cls) GNUNET_free (privkey2); privkey2 = NULL; } - GNUNET_free (s_name_1); - GNUNET_free (s_name_2); - GNUNET_free (s_name_3); + GNUNET_free_non_null (s_name_1); + GNUNET_free_non_null (s_name_2); + GNUNET_free_non_null (s_name_3); if (s_rd_1 != NULL) { GNUNET_free ((void *)s_rd_1->data); @@ -429,19 +429,17 @@ run (void *cls, } +#include "test_common.c" + + int main (int argc, char *argv[]) { const char *plugin_name; char *cfg_name; - plugin_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]); - GNUNET_asprintf (&cfg_name, - "test_namestore_api_%s.conf", - plugin_name); + SETUP_CFG (plugin_name, cfg_name); res = 1; - GNUNET_DISK_purge_cfg_dir (cfg_name, - "GNUNET_TEST_HOME"); if (0 != GNUNET_TESTING_peer_run ("test-namestore-api-zone-iteration-specific-zone", cfg_name, diff --git a/src/namestore/test_namestore_api_zone_iteration_stop.c b/src/namestore/test_namestore_api_zone_iteration_stop.c index 5b54e100e..38da3136c 100644 --- a/src/namestore/test_namestore_api_zone_iteration_stop.c +++ b/src/namestore/test_namestore_api_zone_iteration_stop.c @@ -18,7 +18,7 @@ SPDX-License-Identifier: AGPL3.0-or-later */ /** - * @file namestore/test_namestore_api_zone_iteration.c + * @file namestore/test_namestore_api_zone_iteration_stop.c * @brief testcase for zone iteration functionality: stop iterating of zones */ #include "platform.h" @@ -34,8 +34,6 @@ static struct GNUNET_NAMESTORE_Handle * nsh; -static struct GNUNET_SCHEDULER_Task * endbadly_task; - static struct GNUNET_CRYPTO_EcdsaPrivateKey * privkey; static struct GNUNET_CRYPTO_EcdsaPrivateKey * privkey2; @@ -59,29 +57,27 @@ static char * s_name_3; static struct GNUNET_GNSRECORD_Data *s_rd_3; - /** * Re-establish the connection to the service. * * @param cls handle to use to re-connect. */ static void -endbadly (void *cls) +end (void *cls) { if (NULL != zi) { GNUNET_NAMESTORE_zone_iteration_stop (zi); zi = NULL; } - if (nsh != NULL) + { GNUNET_NAMESTORE_disconnect (nsh); - nsh = NULL; - - GNUNET_free_non_null(s_name_1); - GNUNET_free_non_null(s_name_2); - GNUNET_free_non_null(s_name_3); - + nsh = NULL; + } + GNUNET_free_non_null (s_name_1); + GNUNET_free_non_null (s_name_2); + GNUNET_free_non_null (s_name_3); if (s_rd_1 != NULL) { GNUNET_free ((void *)s_rd_1->data); @@ -97,62 +93,23 @@ endbadly (void *cls) GNUNET_free ((void *)s_rd_3->data); GNUNET_free (s_rd_3); } - if (privkey != NULL) + { GNUNET_free (privkey); - privkey = NULL; - + privkey = NULL; + } if (privkey2 != NULL) + { GNUNET_free (privkey2); - privkey2 = NULL; - res = 1; + privkey2 = NULL; + } } static void -end (void *cls) +delayed_end (void *cls) { - if (NULL != zi) - { - GNUNET_NAMESTORE_zone_iteration_stop (zi); - zi = NULL; - } - - if (endbadly_task != NULL) - { - GNUNET_SCHEDULER_cancel (endbadly_task); - endbadly_task = NULL; - } - - if (privkey != NULL) - GNUNET_free (privkey); - privkey = NULL; - - if (privkey2 != NULL) - GNUNET_free (privkey2); - privkey2 = NULL; - - GNUNET_free (s_name_1); - GNUNET_free (s_name_2); - GNUNET_free (s_name_3); - if (s_rd_1 != NULL) - { - GNUNET_free ((void *)s_rd_1->data); - GNUNET_free (s_rd_1); - } - if (s_rd_2 != NULL) - { - GNUNET_free ((void *)s_rd_2->data); - GNUNET_free (s_rd_2); - } - if (s_rd_3 != NULL) - { - GNUNET_free ((void *)s_rd_3->data); - GNUNET_free (s_rd_3); - } - if (nsh != NULL) - GNUNET_NAMESTORE_disconnect (nsh); - nsh = NULL; + GNUNET_SCHEDULER_shutdown (); } @@ -257,16 +214,13 @@ zone_proc (void *cls, if (1 == returned_records) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Telling namestore to stop zone iteration\n"); - GNUNET_NAMESTORE_zone_iteration_stop (zi); - zi = NULL; - if (NULL != endbadly_task) - { - GNUNET_SCHEDULER_cancel (endbadly_task); - endbadly_task = NULL; - } + "Telling namestore to stop zone iteration\n"); + GNUNET_NAMESTORE_zone_iteration_stop (zi); + zi = NULL; res = 0; - GNUNET_SCHEDULER_add_delayed (WAIT, &end, NULL); + GNUNET_SCHEDULER_add_delayed (WAIT, + &delayed_end, + NULL); return; } returned_records ++; @@ -278,7 +232,7 @@ zone_proc (void *cls, else { GNUNET_break (0); - GNUNET_SCHEDULER_add_now (&end, NULL); + GNUNET_SCHEDULER_shutdown (); } } @@ -314,9 +268,7 @@ put_cont (void *cls, int32_t success, const char *emsg) GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to created records: `%s'\n", emsg); GNUNET_break (0); - if (NULL != endbadly_task) - GNUNET_SCHEDULER_cancel (endbadly_task); - endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); + GNUNET_SCHEDULER_shutdown (); return; } @@ -339,9 +291,7 @@ put_cont (void *cls, int32_t success, const char *emsg) GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to create zone iterator\n"); GNUNET_break (0); - if (NULL != endbadly_task) - GNUNET_SCHEDULER_cancel (endbadly_task); - endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); + GNUNET_SCHEDULER_shutdown (); return; } } @@ -387,9 +337,7 @@ empty_zone_proc (void *cls, GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Expected empty zone but received zone private key\n")); GNUNET_break (0); - if (endbadly_task != NULL) - GNUNET_SCHEDULER_cancel (endbadly_task); - endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); + GNUNET_SCHEDULER_shutdown (); return; } if ((NULL != label) || (NULL != rd) || (0 != rd_count)) @@ -397,9 +345,7 @@ empty_zone_proc (void *cls, GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Expected no zone content but received data\n")); GNUNET_break (0); - if (endbadly_task != NULL) - GNUNET_SCHEDULER_cancel (endbadly_task); - endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); + GNUNET_SCHEDULER_shutdown (); return; } GNUNET_assert (0); @@ -476,43 +422,39 @@ run (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, struct GNUNET_TESTING_Peer *peer) { - endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, - &endbadly, - NULL); nsh = GNUNET_NAMESTORE_connect (cfg); GNUNET_break (NULL != nsh); + GNUNET_SCHEDULER_add_shutdown (&end, + NULL); /* first, iterate over empty namestore */ - zi = GNUNET_NAMESTORE_zone_iteration_start(nsh, - NULL, - &fail_cb, - NULL, - &empty_zone_proc, - nsh, - &empty_zone_proc_end, - nsh); + zi = GNUNET_NAMESTORE_zone_iteration_start (nsh, + NULL, + &fail_cb, + NULL, + &empty_zone_proc, + nsh, + &empty_zone_proc_end, + nsh); if (NULL == zi) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to create zone iterator\n"); GNUNET_break (0); - GNUNET_SCHEDULER_cancel (endbadly_task); - endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); + GNUNET_SCHEDULER_shutdown (); } } +#include "test_common.c" + + int main (int argc, char *argv[]) { const char *plugin_name; char *cfg_name; - plugin_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]); - GNUNET_asprintf (&cfg_name, - "test_namestore_api_%s.conf", - plugin_name); - GNUNET_DISK_purge_cfg_dir (cfg_name, - "GNUNET_TEST_HOME"); + SETUP_CFG (plugin_name, cfg_name); res = 1; if (0 != GNUNET_TESTING_peer_run ("test-namestore-api-zone-iteration-stop", -- 2.25.1