Commit 7b9084d4 authored by Ondřej Surý's avatar Ondřej Surý
Browse files

Use atomic_bool for variables shared among threads to make zt_test.c thread-safe

parent 6858ef9a
Pipeline #25717 failed with stages
in 50 minutes and 44 seconds
......@@ -25,6 +25,7 @@
#include <cmocka.h>
#include <isc/app.h>
#include <isc/atomic.h>
#include <isc/buffer.h>
#include <isc/print.h>
#include <isc/task.h>
......@@ -79,21 +80,21 @@ count_zone(dns_zone_t *zone, void *uap) {
static isc_result_t
load_done(dns_zt_t *zt, dns_zone_t *zone, isc_task_t *task) {
/* We treat zt as a pointer to a boolean for testing purposes */
bool *done = (bool *) zt;
atomic_bool *done = (atomic_bool *) zt;
UNUSED(zone);
UNUSED(task);
*done = true;
atomic_store(done, true);
isc_app_shutdown();
return (ISC_R_SUCCESS);
}
static isc_result_t
all_done(void *arg) {
bool *done = (bool *) arg;
atomic_bool *done = (atomic_bool *) arg;
*done = true;
atomic_store(done, true);
isc_app_shutdown();
return (ISC_R_SUCCESS);
}
......@@ -164,7 +165,7 @@ asyncload_zone(void **state) {
dns_db_t *db = NULL;
FILE* zonefile, *origfile;
char buf[4096];
bool done = false;
atomic_bool done = ATOMIC_VAR_INIT(false);
int i = 0;
struct args args;
......@@ -182,7 +183,7 @@ asyncload_zone(void **state) {
assert_non_null(view->zonetable);
assert_false(dns__zone_loadpending(zone));
assert_false(done);
assert_false(atomic_load(&done));
zonefile = fopen("./zone.data", "wb");
assert_non_null(zonefile);
origfile = fopen("./testdata/zt/zone1.db", "r+b");
......@@ -203,7 +204,7 @@ asyncload_zone(void **state) {
isc_app_run();
while (dns__zone_loadpending(zone) && i++ < 5000)
dns_test_nap(1000);
assert_true(done);
assert_true(atomic_load(&done));
/* The zone should now be loaded; test it */
result = dns_zone_getdb(zone, &db);
assert_int_equal(result, ISC_R_SUCCESS);
......@@ -225,7 +226,7 @@ asyncload_zone(void **state) {
while (dns__zone_loadpending(zone) && i++ < 5000)
dns_test_nap(1000);
assert_true(done);
assert_true(atomic_load(&done));
/* The zone should now be loaded; test it */
result = dns_zone_getdb(zone, &db);
assert_int_equal(result, ISC_R_SUCCESS);
......@@ -241,7 +242,7 @@ asyncload_zone(void **state) {
while (dns__zone_loadpending(zone) && i++ < 5000)
dns_test_nap(1000);
assert_true(done);
assert_true(atomic_load(&done));
/* The zone should now be loaded; test it */
result = dns_zone_getdb(zone, &db);
assert_int_equal(result, ISC_R_SUCCESS);
......@@ -265,7 +266,7 @@ asyncload_zt(void **state) {
dns_view_t *view;
dns_zt_t *zt = NULL;
dns_db_t *db = NULL;
bool done = false;
atomic_bool done = ATOMIC_VAR_INIT(false);
int i = 0;
struct args args;
......@@ -302,16 +303,17 @@ asyncload_zt(void **state) {
assert_false(dns__zone_loadpending(zone1));
assert_false(dns__zone_loadpending(zone2));
assert_false(done);
assert_false(atomic_load(&done));
args.arg1 = zt;
args.arg2 = &done;
isc_app_onrun(dt_mctx, maintask, start_zt_asyncload, &args);
isc_app_run();
while (!done && i++ < 5000)
while (!atomic_load(&done) && i++ < 5000) {
dns_test_nap(1000);
assert_true(done);
}
assert_true(atomic_load(&done));
/* Both zones should now be loaded; test them */
result = dns_zone_getdb(zone1, &db);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment