Exemple #1
0
ATF_TC_BODY(mmap__map_at_zero, tc)
{
	void *p;
	size_t len;
	unsigned int i;
	int map_at_zero;

	len = sizeof(map_at_zero);
	if (sysctlbyname(MAP_AT_ZERO, &map_at_zero, &len, NULL, 0) == -1) {
		atf_tc_skip("sysctl for %s failed: %s\n", MAP_AT_ZERO,
		    strerror(errno));
		return;
	}

	/* Normalize to 0 or 1 for array access. */
	map_at_zero = !!map_at_zero;

	for (i = 0; i < nitems(map_at_zero_tests); i++) {
		p = mmap((void *)map_at_zero_tests[i].addr, PAGE_SIZE,
		    PROT_READ | PROT_WRITE | PROT_EXEC, MAP_ANON | MAP_FIXED,
		    -1, 0);
		if (p == MAP_FAILED) {
			ATF_CHECK_MSG(map_at_zero_tests[i].ok[map_at_zero] == 0,
			    "mmap(%p, ...) failed", map_at_zero_tests[i].addr);
		} else {
			ATF_CHECK_MSG(map_at_zero_tests[i].ok[map_at_zero] == 1,
			    "mmap(%p, ...) succeeded: p=%p\n",
			    map_at_zero_tests[i].addr, p);
		}
	}
}
static void
_testfmt(const char *result, const char *argstr, const char *fmt,...)
{
#define	BUF	100
	wchar_t ws[BUF], wfmt[BUF], wresult[BUF];
	char s[BUF];
	va_list ap, ap2;

	va_start(ap, fmt);
	va_copy(ap2, ap);
	smash_stack();
	vsnprintf(s, sizeof(s), fmt, ap);
	ATF_CHECK_MSG(strcmp(result, s) == 0,
	    "printf(\"%s\", %s) ==> [%s], expected [%s]",
	    fmt, argstr, s, result);

	smash_stack();
	mbstowcs(ws, s, BUF - 1);
	mbstowcs(wfmt, fmt, BUF - 1);
	mbstowcs(wresult, result, BUF - 1);
	vswprintf(ws, sizeof(ws) / sizeof(ws[0]), wfmt, ap2);
	ATF_CHECK_MSG(wcscmp(wresult, ws) == 0,
	    "wprintf(\"%ls\", %s) ==> [%ls], expected [%ls]",
	    wfmt, argstr, ws, wresult);

	va_end(ap);
	va_end(ap2);
}
Exemple #3
0
static void
checked_mmap(int prot, int flags, int fd, int error, const char *msg)
{
	void *p;

	p = mmap(NULL, getpagesize(), prot, flags, fd, 0);
	if (p == MAP_FAILED) {
		if (error == 0)
			ATF_CHECK_MSG(0, "%s failed with errno %d", msg,
			    errno);
		else
			ATF_CHECK_EQ_MSG(error, errno,
			    "%s failed with wrong errno %d (expected %d)", msg,
			    errno, error);
	} else {
		ATF_CHECK_MSG(error == 0, "%s succeeded", msg);
		munmap(p, getpagesize());
	}
}
Exemple #4
0
ATF_TC_BODY(cam_getccb_positive_test, tc)
{
	union ccb *cam_ccb;
	struct cam_device *cam_dev;
	const char *cam_test_device;

	cam_test_device = get_cam_test_device(tc);

	cam_clear_error();
	cam_dev = cam_open_device(cam_test_device, O_RDWR);
	ATF_CHECK_MSG(cam_dev != NULL, "cam_open_device failed: %s",
	    cam_errbuf);
	ATF_REQUIRE(!cam_has_error());
	cam_ccb = cam_getccb(cam_dev);
	ATF_CHECK_MSG(cam_ccb != NULL, "get_camccb failed: %s", cam_errbuf);
	ATF_REQUIRE(!cam_has_error());
	cam_freeccb(cam_ccb);
	cam_close_device(cam_dev);
}
Exemple #5
0
static
void
check_line(int fd, const char *exp)
{
    atf_dynstr_t line;

    atf_dynstr_init(&line);
    ATF_CHECK(!read_line(fd, &line));
    ATF_CHECK_MSG(atf_equal_dynstr_cstring(&line, exp),
                  "read: '%s', expected: '%s'",
                  atf_dynstr_cstring(&line), exp);
    atf_dynstr_fini(&line);
}
Exemple #6
0
static void
h_fail(const char *buf, const char *fmt)
{
	struct tm tm = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, NULL };

#ifdef __FreeBSD__
	ATF_CHECK_MSG(strptime(buf, fmt, &tm) == NULL, "strptime(\"%s\", "
	    "\"%s\", &tm) should fail, but it didn't", buf, fmt);
#else
	ATF_REQUIRE_MSG(strptime(buf, fmt, &tm) == NULL, "strptime(\"%s\", "
	    "\"%s\", &tm) should fail, but it didn't", buf, fmt);
#endif
}
Exemple #7
0
ATF_TC_BODY(msg_embedded_fmt, tc)
{
    struct test {
        void (*head)(atf_tc_t *);
        void (*body)(const atf_tc_t *);
        bool fatal;
        const char *msg;
    } *t, tests[] = {
       {  H_CHECK_HEAD_NAME(msg), H_CHECK_BODY_NAME(msg), false,
          "aux_bool\\(\"%d\"\\) not met" },
       {  H_REQUIRE_HEAD_NAME(msg), H_REQUIRE_BODY_NAME(msg), true,
          "aux_bool\\(\"%d\"\\) not met" },
       {  H_CHECK_STREQ_HEAD_NAME(msg), H_CHECK_STREQ_BODY_NAME(msg), false,
          "aux_str\\(\"%d\"\\) != \"\" \\(foo != \\)" },
       {  H_REQUIRE_STREQ_HEAD_NAME(msg), H_REQUIRE_STREQ_BODY_NAME(msg), true,
          "aux_str\\(\"%d\"\\) != \"\" \\(foo != \\)" },
       { NULL, NULL, false, NULL }
    };

    for (t = &tests[0]; t->head != NULL; t++) {
        printf("Checking with an expected '%s' message\n", t->msg);

        init_and_run_h_tc("h_check", t->head, t->body);

        if (t->fatal) {
            bool matched =
                grep_file("result", "^failed: .*macros_test.c:[0-9]+: "
                          "%s$", t->msg);
            ATF_CHECK_MSG(matched, "couldn't find error string in result");
        } else {
            bool matched = grep_file("error", "Check failed: .*"
                "macros_test.c:[0-9]+: %s$", t->msg);
            ATF_CHECK_MSG(matched, "couldn't find error string in output");
        }
    }
}
Exemple #8
0
ATF_TC_BODY(neworigin, tc) {
	isc_result_t result;

	UNUSED(tc);

	result = dns_test_begin(NULL, ISC_FALSE);
	ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);

	warn_expect_value = "record with inherited owner";
	warn_expect_result = ISC_FALSE;
	result = test_master("testdata/master/master17.data",
			     dns_masterformat_text, warn_expect, NULL);
	ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
	ATF_CHECK_MSG(warn_expect_result, "'%s' warning not emitted",
		      warn_expect_value);

	dns_test_end();
}
Exemple #9
0
static void
h_pass(const char *buf, const char *fmt, int len,
    int tm_sec, int tm_min, int tm_hour, int tm_mday,
    int tm_mon, int tm_year, int tm_wday, int tm_yday)
{
	struct tm tm = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, NULL };
	const char *ret, *exp;

	exp = buf + len;
	ret = strptime(buf, fmt, &tm);

#ifdef __FreeBSD__
	ATF_CHECK_MSG(ret == exp,
	    "strptime(\"%s\", \"%s\", tm): incorrect return code: "
	    "expected: %p, got: %p", buf, fmt, exp, ret);

#define H_REQUIRE_FIELD(field)						\
		ATF_CHECK_MSG(tm.field == field,			\
		    "strptime(\"%s\", \"%s\", tm): incorrect %s: "	\
		    "expected: %d, but got: %d", buf, fmt,		\
		    ___STRING(field), field, tm.field)
#else
	ATF_REQUIRE_MSG(ret == exp,
	    "strptime(\"%s\", \"%s\", tm): incorrect return code: "
	    "expected: %p, got: %p", buf, fmt, exp, ret);

#define H_REQUIRE_FIELD(field)						\
		ATF_REQUIRE_MSG(tm.field == field,			\
		    "strptime(\"%s\", \"%s\", tm): incorrect %s: "	\
		    "expected: %d, but got: %d", buf, fmt,		\
		    ___STRING(field), field, tm.field)
#endif

	H_REQUIRE_FIELD(tm_sec);
	H_REQUIRE_FIELD(tm_min);
	H_REQUIRE_FIELD(tm_hour);
	H_REQUIRE_FIELD(tm_mday);
	H_REQUIRE_FIELD(tm_mon);
	H_REQUIRE_FIELD(tm_year);
	H_REQUIRE_FIELD(tm_wday);
	H_REQUIRE_FIELD(tm_yday);

#undef H_REQUIRE_FIELD
}
Exemple #10
0
ATF_TC_BODY(qsort_test, tc)
{
	int testvector[IVEC_LEN];
	int sresvector[IVEC_LEN];
	int i, j;

	for (j = 2; j < IVEC_LEN; j++) {
		/* Populate test vectors */
		for (i = 0; i < j; i++)
			testvector[i] = sresvector[i] = initvector[i];

		/* Sort using qsort(3) */
		qsort(testvector, j, sizeof(testvector[0]), sorthelp);
		/* Sort using reference slow sorting routine */
		ssort(sresvector, j);

		/* Compare results */
		for (i = 0; i < j; i++)
			ATF_CHECK_MSG(testvector[i] == sresvector[i],
			    "item at index %d didn't match: %d != %d",
			    i, testvector[i], sresvector[i]);
	}
}
Exemple #11
0
/// @brief executes uid hash test for specified client-ids (3 hosts)
///
/// Creates three host structures, adds first host to the uid hash,
/// then adds second host to the hash, then removes first host,
/// then removed the second. Many checks are performed during all
/// operations.
///
/// @param clientid1 client-id of the first host
/// @param clientid1_len client-id1 length (may be 0 for strings)
/// @param clientid2 client-id of the second host
/// @param clientid2_len client-id2 length (may be 0 for strings)
/// @param clientid3 client-id of the second host
/// @param clientid3_len client-id2 length (may be 0 for strings)
void lease_hash_test_3hosts(unsigned char clientid1[], size_t clientid1_len,
                            unsigned char clientid2[], size_t clientid2_len,
                            unsigned char clientid3[], size_t clientid3_len) {

    printf("Checking hash operation for 3 hosts: clientid1-len=%lu"
           " clientid2-len=%lu clientid3-len=%lu\n",
           (unsigned long) clientid1_len, (unsigned long) clientid2_len,
           (unsigned long) clientid3_len);

    dhcp_db_objects_setup ();
    dhcp_common_objects_setup ();

    /* check that there is actually zero hosts in the hash */
    /* @todo: host_hash_for_each() */

    struct host_decl *host1 = 0, *host2 = 0, *host3 = 0;
    struct host_decl *check = 0;

    /* === step 1: allocate hosts === */
    ATF_CHECK_MSG(host_allocate(&host1, MDL) == ISC_R_SUCCESS,
                  "Failed to allocate host");
    ATF_CHECK_MSG(host_allocate(&host2, MDL) == ISC_R_SUCCESS,
                  "Failed to allocate host");
    ATF_CHECK_MSG(host_allocate(&host3, MDL) == ISC_R_SUCCESS,
                  "Failed to allocate host");

    ATF_CHECK_MSG(host_new_hash(&host_uid_hash, HOST_HASH_SIZE, MDL) != 0,
                  "Unable to create new hash");

    ATF_CHECK_MSG(buffer_allocate(&host1->client_identifier.buffer,
                                  clientid1_len, MDL) != 0,
                  "Can't allocate uid buffer for host1");
    ATF_CHECK_MSG(buffer_allocate(&host2->client_identifier.buffer,
                                  clientid2_len, MDL) != 0,
                  "Can't allocate uid buffer for host2");
    ATF_CHECK_MSG(buffer_allocate(&host3->client_identifier.buffer,
                                  clientid3_len, MDL) != 0,
                  "Can't allocate uid buffer for host3");

    /* verify that our hosts are not in the hash yet */
    ATF_CHECK_MSG(host_hash_lookup(&check, host_uid_hash, clientid1,
                                   clientid1_len, MDL) == 0,
                   "Host1 is not supposed to be in the uid_hash.");

    ATF_CHECK_MSG(!check, "Host1 is not supposed to be in the uid_hash.");

    ATF_CHECK_MSG(host_hash_lookup(&check, host_uid_hash, clientid2,
                                   clientid2_len, MDL) == 0,
                  "Host2 is not supposed to be in the uid_hash.");
    ATF_CHECK_MSG(!check, "Host2 is not supposed to be in the uid_hash.");

    ATF_CHECK_MSG(host_hash_lookup(&check, host_uid_hash, clientid3,
                                   clientid3_len, MDL) == 0,
                  "Host3 is not supposed to be in the uid_hash.");
    ATF_CHECK_MSG(!check, "Host3 is not supposed to be in the uid_hash.");

    /* === step 2: add hosts to the hash === */
    host_hash_add(host_uid_hash, clientid1, clientid1_len, host1, MDL);
    host_hash_add(host_uid_hash, clientid2, clientid2_len, host2, MDL);
    host_hash_add(host_uid_hash, clientid3, clientid3_len, host3, MDL);

    ATF_CHECK_MSG(host_hash_lookup(&check, host_uid_hash, clientid1,
                                   clientid1_len, MDL),
                  "Host1 was supposed to be in the uid_hash.");
    /* Hey! That's not the host we were looking for! */
    ATF_CHECK_MSG(check == host1, "Wrong host returned by host_hash_lookup");
    host_dereference(&check, MDL); /* we don't need it now */

    ATF_CHECK_MSG(host_hash_lookup(&check, host_uid_hash, clientid2,
                                   clientid2_len, MDL),
                  "Host2 was supposed to be in the uid_hash.");
    ATF_CHECK_MSG(check, "Host2 was supposed to be in the uid_hash.");
    /* Hey! That's not the host we were looking for! */
    ATF_CHECK_MSG(check == host2, "Wrong host returned by host_hash_lookup");
    host_dereference(&check, MDL); /* we don't need it now */

    ATF_CHECK_MSG(host_hash_lookup(&check, host_uid_hash, clientid3,
                                   clientid3_len, MDL),
                  "Host3 was supposed to be in the uid_hash.");
    ATF_CHECK_MSG(check, "Host3 was supposed to be in the uid_hash.");
    /* Hey! That's not the host we were looking for! */
    ATF_CHECK_MSG(check == host3, "Wrong host returned by host_hash_lookup");
    host_dereference(&check, MDL); /* we don't need it now */

    /* === step 4: remove first host from the hash === */

    /* delete host from hash */
    host_hash_delete(host_uid_hash, clientid1, clientid1_len, MDL);

    /* verify that host1 is no longer in the hash */
    ATF_CHECK_MSG(host_hash_lookup(&check, host_uid_hash, clientid1,
                                   clientid1_len, MDL) == 0,
                   "Host1 is not supposed to be in the uid_hash.");
    ATF_CHECK_MSG(!check, "Host1 is not supposed to be in the uid_hash.");

    /* host2 and host3 should be still there, though */
    ATF_CHECK_MSG(host_hash_lookup(&check, host_uid_hash, clientid2,
                                   clientid2_len, MDL),
                   "Host2 was supposed to still be in the uid_hash.");
    host_dereference(&check, MDL);
    ATF_CHECK_MSG(host_hash_lookup(&check, host_uid_hash, clientid3,
                                   clientid3_len, MDL),
                   "Host3 was supposed to still be in the uid_hash.");
    host_dereference(&check, MDL);

    /* === step 5: remove second host from the hash === */
    host_hash_delete(host_uid_hash, clientid2, clientid2_len, MDL);

    ATF_CHECK_MSG(host_hash_lookup(&check, host_uid_hash, clientid2,
                                   clientid2_len, MDL) == 0,
                   "Host2 was not supposed to be in the uid_hash anymore.");
    ATF_CHECK_MSG(host_hash_lookup(&check, host_uid_hash, clientid3,
                                   clientid3_len, MDL),
                   "Host3 was supposed to still be in the uid_hash.");
    host_dereference(&check, MDL);

    /* === step 6: remove the last (third) host from the hash === */
    host_hash_delete(host_uid_hash, clientid3, clientid3_len, MDL);

    ATF_CHECK_MSG(host_hash_lookup(&check, host_uid_hash, clientid3,
                                   clientid3_len, MDL) == 0,
                   "Host3 was not supposed to be in the uid_hash anymore.");
    host_dereference(&check, MDL);


    host_dereference(&host1, MDL);
    host_dereference(&host2, MDL);
    host_dereference(&host3, MDL);

    /*
     * No easy way to check if the host object were actually released.
     * We could run it in valgrind and check for memory leaks.
     */

#if defined (DEBUG_MEMORY_LEAKAGE) && defined (DEBUG_MEMORY_LEAKAGE_ON_EXIT)
    /* @todo: Should be called in cleanup */
    free_everything ();
#endif
}
Exemple #12
0
/// @brief executes uid hash test for specified client-ids (2 hosts)
///
/// Creates two host structures, adds first host to the uid hash,
/// then adds second host to the hash, then removes first host,
/// then removed the second. Many checks are performed during all
/// operations.
///
/// @param clientid1 client-id of the first host
/// @param clientid1_len client-id1 length (may be 0 for strings)
/// @param clientid2 client-id of the second host
/// @param clientid2_len client-id2 length (may be 0 for strings)
void lease_hash_test_2hosts(unsigned char clientid1[], size_t clientid1_len,
                            unsigned char clientid2[], size_t clientid2_len) {

    printf("Checking hash operation for 2 hosts: clientid1-len=%lu"
           "clientid2-len=%lu\n", (unsigned long) clientid1_len,
           (unsigned long) clientid2_len);

    dhcp_db_objects_setup ();
    dhcp_common_objects_setup ();

    /* check that there is actually zero hosts in the hash */
    /* @todo: host_hash_for_each() */

    struct host_decl *host1 = 0, *host2 = 0;
    struct host_decl *check = 0;

    /* === step 1: allocate hosts === */
    ATF_CHECK_MSG(host_allocate(&host1, MDL) == ISC_R_SUCCESS,
                  "Failed to allocate host");
    ATF_CHECK_MSG(host_allocate(&host2, MDL) == ISC_R_SUCCESS,
                  "Failed to allocate host");

    ATF_CHECK_MSG(host_new_hash(&host_uid_hash, HOST_HASH_SIZE, MDL) != 0,
                  "Unable to create new hash");

    ATF_CHECK_MSG(buffer_allocate(&host1->client_identifier.buffer,
                                  clientid1_len, MDL) != 0,
                  "Can't allocate uid buffer for host1");

    ATF_CHECK_MSG(buffer_allocate(&host2->client_identifier.buffer,
                                  clientid2_len, MDL) != 0,
                  "Can't allocate uid buffer for host2");

    /* setting up host1->client_identifier is actually not needed */
    /*
    ATF_CHECK_MSG(lease_set_clientid(host1, clientid1, actual1_len) != 0,
                  "Failed to set client-id for host1");

    ATF_CHECK_MSG(lease_set_clientid(host2, clientid2, actual2_len) != 0,
                  "Failed to set client-id for host2");
    */

    ATF_CHECK_MSG(host1->refcnt == 1, "Invalid refcnt for host1");
    ATF_CHECK_MSG(host2->refcnt == 1, "Invalid refcnt for host2");

    /* verify that our hosts are not in the hash yet */
    ATF_CHECK_MSG(host_hash_lookup(&check, host_uid_hash, clientid1,
                                   clientid1_len, MDL) == 0,
                   "Host1 is not supposed to be in the uid_hash.");

    ATF_CHECK_MSG(!check, "Host1 is not supposed to be in the uid_hash.");

    ATF_CHECK_MSG(host_hash_lookup(&check, host_uid_hash, clientid2,
                                   clientid2_len, MDL) == 0,
                  "Host2 is not supposed to be in the uid_hash.");
    ATF_CHECK_MSG(!check, "Host2 is not supposed to be in the uid_hash.");


    /* === step 2: add first host to the hash === */
    host_hash_add(host_uid_hash, clientid1, clientid1_len, host1, MDL);

    /* 2 pointers expected: ours (host1) and the one stored in hash */
    ATF_CHECK_MSG(host1->refcnt == 2, "Invalid refcnt for host1");
    /* 1 pointer expected: just ours (host2) */
    ATF_CHECK_MSG(host2->refcnt == 1, "Invalid refcnt for host2");

    /* verify that host1 is really in the hash and the we can find it */
    ATF_CHECK_MSG(host_hash_lookup(&check, host_uid_hash, clientid1,
                                   clientid1_len, MDL),
                  "Host1 was supposed to be in the uid_hash.");
    ATF_CHECK_MSG(check, "Host1 was supposed to be in the uid_hash.");

    /* Hey! That's not the host we were looking for! */
    ATF_CHECK_MSG(check == host1, "Wrong host returned by host_hash_lookup");

    /* 3 pointers: host1, (stored in hash), check */
    ATF_CHECK_MSG(host1->refcnt == 3, "Invalid refcnt for host1");

    /* reference count should be increased because we not have a pointer */

    host_dereference(&check, MDL); /* we don't need it now */

    ATF_CHECK_MSG(check == NULL, "check pointer is supposed to be NULL");

    /* 2 pointers: host1, (stored in hash) */
    ATF_CHECK_MSG(host1->refcnt == 2, "Invalid refcnt for host1");

    /* verify that host2 is not in the hash */
    ATF_CHECK_MSG(host_hash_lookup(&check, host_uid_hash, clientid2,
                                   clientid2_len, MDL) == 0,
                  "Host2 was not supposed to be in the uid_hash[2].");
    ATF_CHECK_MSG(check == NULL, "Host2 was not supposed to be in the hash.");


    /* === step 3: add second hot to the hash === */
    host_hash_add(host_uid_hash, clientid2, clientid2_len, host2, MDL);

    /* 2 pointers expected: ours (host1) and the one stored in hash */
    ATF_CHECK_MSG(host2->refcnt == 2, "Invalid refcnt for host2");

    ATF_CHECK_MSG(host_hash_lookup(&check, host_uid_hash, clientid2,
                                   clientid2_len, MDL),
                  "Host2 was supposed to be in the uid_hash.");
    ATF_CHECK_MSG(check, "Host2 was supposed to be in the uid_hash.");

    /* Hey! That's not the host we were looking for! */
    ATF_CHECK_MSG(check == host2, "Wrong host returned by host_hash_lookup");

    /* 3 pointers: host1, (stored in hash), check */
    ATF_CHECK_MSG(host2->refcnt == 3, "Invalid refcnt for host1");

    host_dereference(&check, MDL); /* we don't need it now */

    /* now we have 2 hosts in the hash */

    /* verify that host1 is still in the hash and the we can find it */
    ATF_CHECK_MSG(host_hash_lookup(&check, host_uid_hash, clientid1,
                                   clientid1_len, MDL),
                  "Host1 was supposed to be in the uid_hash.");
    ATF_CHECK_MSG(check, "Host1 was supposed to be in the uid_hash.");

    /* Hey! That's not the host we were looking for! */
    ATF_CHECK_MSG(check == host1, "Wrong host returned by host_hash_lookup");

    /* 3 pointers: host1, (stored in hash), check */
    ATF_CHECK_MSG(host1->refcnt == 3, "Invalid refcnt for host1");

    host_dereference(&check, MDL); /* we don't need it now */


    /**
     * @todo check that there is actually two hosts in the hash.
     * Use host_hash_for_each() for that.
     */

    /* === step 4: remove first host from the hash === */

    /* delete host from hash */
    host_hash_delete(host_uid_hash, clientid1, clientid1_len, MDL);

    ATF_CHECK_MSG(host1->refcnt == 1, "Invalid refcnt for host1");
    ATF_CHECK_MSG(host2->refcnt == 2, "Invalid refcnt for host2");

    /* verify that host1 is no longer in the hash */
    ATF_CHECK_MSG(host_hash_lookup(&check, host_uid_hash, clientid1,
                                   clientid1_len, MDL) == 0,
                   "Host1 is not supposed to be in the uid_hash.");
    ATF_CHECK_MSG(!check, "Host1 is not supposed to be in the uid_hash.");

    /* host2 should be still there, though */
    ATF_CHECK_MSG(host_hash_lookup(&check, host_uid_hash, clientid2,
                                   clientid2_len, MDL),
                   "Host2 was supposed to still be in the uid_hash.");
    host_dereference(&check, MDL);

    /* === step 5: remove second host from the hash === */
    host_hash_delete(host_uid_hash, clientid2, clientid2_len, MDL);

    ATF_CHECK_MSG(host1->refcnt == 1, "Invalid refcnt for host1");
    ATF_CHECK_MSG(host2->refcnt == 1, "Invalid refcnt for host2");

    ATF_CHECK_MSG(host_hash_lookup(&check, host_uid_hash, clientid2,
                                   clientid2_len, MDL) == 0,
                   "Host2 was not supposed to be in the uid_hash anymore.");

    host_dereference(&host1, MDL);
    host_dereference(&host2, MDL);

    /*
     * No easy way to check if the host object were actually released.
     * We could run it in valgrind and check for memory leaks.
     */

#if defined (DEBUG_MEMORY_LEAKAGE) && defined (DEBUG_MEMORY_LEAKAGE_ON_EXIT)
    /* @todo: Should be called in cleanup */
    free_everything ();
#endif
}