mirror of
https://gitlab.isc.org/isc-projects/dhcp
synced 2025-08-23 02:17:31 +00:00
[25901_atf] Existing alloc tests in common converted to ATF
This commit is contained in:
parent
c08a70750c
commit
db81cc0ca0
@ -10,4 +10,8 @@ libdhcp_a_SOURCES = alloc.c bpf.c comapi.c conflex.c ctrace.c discover.c \
|
|||||||
man_MANS = dhcp-eval.5 dhcp-options.5
|
man_MANS = dhcp-eval.5 dhcp-options.5
|
||||||
EXTRA_DIST = $(man_MANS)
|
EXTRA_DIST = $(man_MANS)
|
||||||
|
|
||||||
SUBDIRS = tests
|
SUBDIRS = .
|
||||||
|
|
||||||
|
if HAVE_ATF
|
||||||
|
SUBDIRS += tests
|
||||||
|
endif
|
||||||
|
@ -1,11 +1,16 @@
|
|||||||
AM_CPPFLAGS = -I../..
|
SUBDIRS = .
|
||||||
|
|
||||||
check_PROGRAMS = test_alloc
|
AM_CPPFLAGS = $(ATF_CFLAGS) -I$(top_srcdir)/includes
|
||||||
|
|
||||||
TESTS = test_alloc
|
ATF_TESTS = alloc_unittest
|
||||||
|
|
||||||
test_alloc_SOURCES = test_alloc.c
|
check_PROGRAMS = $(ATF_TESTS)
|
||||||
test_alloc_LDADD = ../libdhcp.a ../../tests/libt_api.a \
|
|
||||||
|
alloc_unittest_SOURCES = test_alloc.c $(top_srcdir)/tests/t_api_dhcp.c
|
||||||
|
alloc_unittest_LDADD = $(ATF_LDFLAGS)
|
||||||
|
alloc_unittest_LDADD += ../libdhcp.a \
|
||||||
../../omapip/libomapi.a ../../bind/lib/libdns.a \
|
../../omapip/libomapi.a ../../bind/lib/libdns.a \
|
||||||
../../bind/lib/libisc.a
|
../../bind/lib/libisc.a
|
||||||
|
|
||||||
|
check: $(ATF_TESTS)
|
||||||
|
atf-run | atf-report
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
|
* Copyright (c) 2007,2009,2012 by Internet Systems Consortium, Inc. ("ISC")
|
||||||
|
*
|
||||||
* We test the functions provided in alloc.c here. These are very
|
* We test the functions provided in alloc.c here. These are very
|
||||||
* basic functions, and it is very important that they work correctly.
|
* basic functions, and it is very important that they work correctly.
|
||||||
*
|
*
|
||||||
@ -19,69 +21,33 @@
|
|||||||
* hard to fix for example), then
|
* hard to fix for example), then
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* TODO: dmalloc() test */
|
/** @TODO: dmalloc() test */
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "t_api.h"
|
#include <atf-c.h>
|
||||||
|
|
||||||
#include "dhcpd.h"
|
#include "dhcpd.h"
|
||||||
|
|
||||||
static void test_buffer_allocate(void);
|
ATF_TC(buffer_allocate);
|
||||||
static void test_buffer_reference(void);
|
|
||||||
static void test_buffer_dereference(void);
|
|
||||||
static void test_data_string_forget(void);
|
|
||||||
static void test_data_string_forget_nobuf(void);
|
|
||||||
static void test_data_string_copy(void);
|
|
||||||
static void test_data_string_copy_nobuf(void);
|
|
||||||
|
|
||||||
/*
|
ATF_TC_HEAD(buffer_allocate, tc) {
|
||||||
* T_testlist is a list of tests that are invoked.
|
atf_tc_set_md_var(tc, "descr", "buffer_allocate basic test");
|
||||||
*/
|
}
|
||||||
testspec_t T_testlist[] = {
|
|
||||||
{ test_buffer_allocate,
|
|
||||||
"buffer_allocate()" },
|
|
||||||
{ test_buffer_reference,
|
|
||||||
"buffer_reference()" },
|
|
||||||
{ test_buffer_dereference,
|
|
||||||
"buffer_dereference()" },
|
|
||||||
{ test_data_string_forget,
|
|
||||||
"data_string_forget()" },
|
|
||||||
{ test_data_string_forget_nobuf,
|
|
||||||
"data_string_forget(), no buffer" },
|
|
||||||
{ test_data_string_copy,
|
|
||||||
"data_string_copy()" },
|
|
||||||
{ test_data_string_copy_nobuf,
|
|
||||||
"data_string_copy(), no buffer" },
|
|
||||||
{ NULL, NULL }
|
|
||||||
};
|
|
||||||
|
|
||||||
static void
|
ATF_TC_BODY(buffer_allocate, tc) {
|
||||||
test_buffer_allocate(void) {
|
struct buffer *buf = 0;
|
||||||
static const char *test_desc =
|
|
||||||
"buffer_allocate basic test";
|
|
||||||
|
|
||||||
struct buffer *buf;
|
|
||||||
|
|
||||||
t_assert("buffer_allocate", 1, T_REQUIRED, "%s", test_desc);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Check a 0-length buffer.
|
* Check a 0-length buffer.
|
||||||
*/
|
*/
|
||||||
buf = NULL;
|
buf = NULL;
|
||||||
if (!buffer_allocate(&buf, 0, MDL)) {
|
if (!buffer_allocate(&buf, 0, MDL)) {
|
||||||
t_info("failed on 0-len buffer\n");
|
atf_tc_fail("failed on 0-len buffer");
|
||||||
t_result(T_FAIL);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
if (!buffer_dereference(&buf, MDL)) {
|
if (!buffer_dereference(&buf, MDL)) {
|
||||||
t_info("buffer_dereference() failed\n");
|
atf_tc_fail("buffer_dereference() failed");
|
||||||
t_result(T_FAIL);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
if (buf != NULL) {
|
if (buf != NULL) {
|
||||||
t_info("buffer_dereference() did not NULL-out buffer\n");
|
atf_tc_fail("buffer_dereference() did not NULL-out buffer");
|
||||||
t_result(T_FAIL);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -89,60 +55,50 @@ test_buffer_allocate(void) {
|
|||||||
*/
|
*/
|
||||||
buf = NULL;
|
buf = NULL;
|
||||||
if (!buffer_allocate(&buf, 100, MDL)) {
|
if (!buffer_allocate(&buf, 100, MDL)) {
|
||||||
t_info("failed on allocate\n");
|
atf_tc_fail("failed on allocate 100 bytes\n");
|
||||||
t_result(T_FAIL);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
if (!buffer_dereference(&buf, MDL)) {
|
if (!buffer_dereference(&buf, MDL)) {
|
||||||
t_info("buffer_dereference() failed\n");
|
atf_tc_fail("buffer_dereference() failed");
|
||||||
t_result(T_FAIL);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
if (buf != NULL) {
|
if (buf != NULL) {
|
||||||
t_info("buffer_dereference() did not NULL-out buffer\n");
|
atf_tc_fail("buffer_dereference() did not NULL-out buffer");
|
||||||
t_result(T_FAIL);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Okay, we're happy.
|
* Okay, we're happy.
|
||||||
*/
|
*/
|
||||||
t_result(T_PASS);
|
atf_tc_pass();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
ATF_TC(buffer_reference);
|
||||||
test_buffer_reference(void) {
|
|
||||||
static const char *test_desc =
|
ATF_TC_HEAD(buffer_reference, tc) {
|
||||||
"buffer_reference basic test";
|
atf_tc_set_md_var(tc, "descr", "buffer_reference basic test");
|
||||||
int result = T_PASS;
|
}
|
||||||
|
|
||||||
|
ATF_TC_BODY(buffer_reference, tc) {
|
||||||
|
|
||||||
struct buffer *a, *b;
|
struct buffer *a, *b;
|
||||||
|
|
||||||
t_assert("buffer_reference", 1, T_REQUIRED, "%s", test_desc);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Create a buffer.
|
* Create a buffer.
|
||||||
*/
|
*/
|
||||||
a = NULL;
|
a = NULL;
|
||||||
if (!buffer_allocate(&a, 100, MDL)) {
|
if (!buffer_allocate(&a, 100, MDL)) {
|
||||||
t_info("failed on allocate\n");
|
atf_tc_fail("failed on allocate 100 bytes");
|
||||||
t_result(T_FAIL);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* Confirm buffer_reference() doesn't work if we pass in NULL.
|
* Confirm buffer_reference() doesn't work if we pass in NULL.
|
||||||
*
|
*
|
||||||
* TODO: we should confirm we get an error message here.
|
* @TODO: we should confirm we get an error message here.
|
||||||
*/
|
*/
|
||||||
if (buffer_reference(NULL, a, MDL)) {
|
if (buffer_reference(NULL, a, MDL)) {
|
||||||
t_info("succeeded on an error input\n");
|
atf_tc_fail("succeeded on an error input");
|
||||||
t_result(T_FAIL);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* TODO: we should confirm we get an error message if we pass
|
* @TODO: we should confirm we get an error message if we pass
|
||||||
* a non-NULL target.
|
* a non-NULL target.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -151,68 +107,57 @@ test_buffer_reference(void) {
|
|||||||
*/
|
*/
|
||||||
b = NULL;
|
b = NULL;
|
||||||
if (!buffer_reference(&b, a, MDL)) {
|
if (!buffer_reference(&b, a, MDL)) {
|
||||||
t_info("buffer_reference() failed\n");
|
atf_tc_fail("buffer_reference() failed");
|
||||||
t_result(T_FAIL);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (b != a) {
|
if (b != a) {
|
||||||
t_info("incorrect pointer\n");
|
atf_tc_fail("incorrect pointer returned");
|
||||||
result = T_FAIL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (b->refcnt != 2) {
|
if (b->refcnt != 2) {
|
||||||
t_info("incorrect refcnt\n");
|
atf_tc_fail("incorrect refcnt");
|
||||||
result = T_FAIL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Clean up.
|
* Clean up.
|
||||||
*/
|
*/
|
||||||
if (!buffer_dereference(&b, MDL)) {
|
if (!buffer_dereference(&b, MDL)) {
|
||||||
t_info("buffer_dereference() failed\n");
|
atf_tc_fail("buffer_dereference() failed");
|
||||||
t_result(T_FAIL);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
if (!buffer_dereference(&a, MDL)) {
|
if (!buffer_dereference(&a, MDL)) {
|
||||||
t_info("buffer_dereference() failed\n");
|
atf_tc_fail("buffer_dereference() failed");
|
||||||
t_result(T_FAIL);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
t_result(result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
test_buffer_dereference(void) {
|
|
||||||
static const char *test_desc =
|
|
||||||
"buffer_dereference basic test";
|
|
||||||
|
|
||||||
|
ATF_TC(buffer_dereference);
|
||||||
|
|
||||||
|
ATF_TC_HEAD(buffer_dereference, tc) {
|
||||||
|
atf_tc_set_md_var(tc, "descr", "buffer_dereference basic test");
|
||||||
|
}
|
||||||
|
|
||||||
|
ATF_TC_BODY(buffer_dereference, tc) {
|
||||||
struct buffer *a, *b;
|
struct buffer *a, *b;
|
||||||
|
|
||||||
t_assert("buffer_dereference", 1, T_REQUIRED, "%s", test_desc);
|
/**
|
||||||
|
|
||||||
/*
|
|
||||||
* Confirm buffer_dereference() doesn't work if we pass in NULL.
|
* Confirm buffer_dereference() doesn't work if we pass in NULL.
|
||||||
*
|
*
|
||||||
* TODO: we should confirm we get an error message here.
|
* TODO: we should confirm we get an error message here.
|
||||||
*/
|
*/
|
||||||
if (buffer_dereference(NULL, MDL)) {
|
if (buffer_dereference(NULL, MDL)) {
|
||||||
t_info("succeeded on an error input\n");
|
atf_tc_fail("succeeded on an error input");
|
||||||
t_result(T_FAIL);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* Confirm buffer_dereference() doesn't work if we pass in
|
* Confirm buffer_dereference() doesn't work if we pass in
|
||||||
* a pointer to NULL.
|
* a pointer to NULL.
|
||||||
*
|
*
|
||||||
* TODO: we should confirm we get an error message here.
|
* @TODO: we should confirm we get an error message here.
|
||||||
*/
|
*/
|
||||||
a = NULL;
|
a = NULL;
|
||||||
if (buffer_dereference(&a, MDL)) {
|
if (buffer_dereference(&a, MDL)) {
|
||||||
t_info("succeeded on an error input\n");
|
atf_tc_fail("succeeded on an error input");
|
||||||
t_result(T_FAIL);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -220,71 +165,52 @@ test_buffer_dereference(void) {
|
|||||||
*/
|
*/
|
||||||
a = NULL;
|
a = NULL;
|
||||||
if (!buffer_allocate(&a, 100, MDL)) {
|
if (!buffer_allocate(&a, 100, MDL)) {
|
||||||
t_info("failed on allocate\n");
|
atf_tc_fail("failed on allocate");
|
||||||
t_result(T_FAIL);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
if (!buffer_dereference(&a, MDL)) {
|
if (!buffer_dereference(&a, MDL)) {
|
||||||
t_info("buffer_dereference() failed\n");
|
atf_tc_fail("buffer_dereference() failed");
|
||||||
t_result(T_FAIL);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
if (a != NULL) {
|
if (a != NULL) {
|
||||||
t_info("non-null buffer after buffer_dereference()\n");
|
atf_tc_fail("non-null buffer after buffer_dereference()");
|
||||||
t_result(T_FAIL);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* Confirm we get an error from negative refcnt.
|
* Confirm we get an error from negative refcnt.
|
||||||
*
|
*
|
||||||
* TODO: we should confirm we get an error message here.
|
* @TODO: we should confirm we get an error message here.
|
||||||
*/
|
*/
|
||||||
a = NULL;
|
a = NULL;
|
||||||
if (!buffer_allocate(&a, 100, MDL)) {
|
if (!buffer_allocate(&a, 100, MDL)) {
|
||||||
t_info("failed on allocate\n");
|
atf_tc_fail("failed on allocate");
|
||||||
t_result(T_FAIL);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
b = NULL;
|
b = NULL;
|
||||||
if (!buffer_reference(&b, a, MDL)) {
|
if (!buffer_reference(&b, a, MDL)) {
|
||||||
t_info("buffer_reference() failed\n");
|
atf_tc_fail("buffer_reference() failed");
|
||||||
t_result(T_FAIL);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
a->refcnt = 0; /* purposely set to invalid value */
|
a->refcnt = 0; /* purposely set to invalid value */
|
||||||
if (buffer_dereference(&a, MDL)) {
|
if (buffer_dereference(&a, MDL)) {
|
||||||
t_info("buffer_dereference() succeeded on error input\n");
|
atf_tc_fail("buffer_dereference() succeeded on error input");
|
||||||
t_result(T_FAIL);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
a->refcnt = 2;
|
a->refcnt = 2;
|
||||||
if (!buffer_dereference(&b, MDL)) {
|
if (!buffer_dereference(&b, MDL)) {
|
||||||
t_info("buffer_dereference() failed\n");
|
atf_tc_fail("buffer_dereference() failed");
|
||||||
t_result(T_FAIL);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
if (!buffer_dereference(&a, MDL)) {
|
if (!buffer_dereference(&a, MDL)) {
|
||||||
t_info("buffer_dereference() failed\n");
|
atf_tc_fail("buffer_dereference() failed");
|
||||||
t_result(T_FAIL);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
t_result(T_PASS);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
ATF_TC(data_string_forget);
|
||||||
test_data_string_forget(void) {
|
|
||||||
static const char *test_desc =
|
|
||||||
"data_string_forget basic test";
|
|
||||||
int result = T_PASS;
|
|
||||||
|
|
||||||
|
ATF_TC_HEAD(data_string_forget, tc) {
|
||||||
|
atf_tc_set_md_var(tc, "descr", "data_string_forget basic test");
|
||||||
|
}
|
||||||
|
|
||||||
|
ATF_TC_BODY(data_string_forget, tc) {
|
||||||
struct buffer *buf;
|
struct buffer *buf;
|
||||||
struct data_string a;
|
struct data_string a;
|
||||||
const char *str = "Lorem ipsum dolor sit amet turpis duis.";
|
const char *str = "Lorem ipsum dolor sit amet turpis duis.";
|
||||||
|
|
||||||
t_assert("data_string_forget", 1, T_REQUIRED, "%s", test_desc);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Create the string we want to forget.
|
* Create the string we want to forget.
|
||||||
*/
|
*/
|
||||||
@ -292,14 +218,10 @@ test_data_string_forget(void) {
|
|||||||
a.len = strlen(str);
|
a.len = strlen(str);
|
||||||
buf = NULL;
|
buf = NULL;
|
||||||
if (!buffer_allocate(&buf, a.len, MDL)) {
|
if (!buffer_allocate(&buf, a.len, MDL)) {
|
||||||
t_info("out of memory\n");
|
atf_tc_fail("out of memory");
|
||||||
t_result(T_FAIL);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
if (!buffer_reference(&a.buffer, buf, MDL)) {
|
if (!buffer_reference(&a.buffer, buf, MDL)) {
|
||||||
t_info("buffer_reference() failed\n");
|
atf_tc_fail("buffer_reference() failed");
|
||||||
t_result(T_FAIL);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
a.data = a.buffer->data;
|
a.data = a.buffer->data;
|
||||||
memcpy(a.buffer->data, str, a.len);
|
memcpy(a.buffer->data, str, a.len);
|
||||||
@ -310,49 +232,41 @@ test_data_string_forget(void) {
|
|||||||
data_string_forget(&a, MDL);
|
data_string_forget(&a, MDL);
|
||||||
|
|
||||||
if (a.len != 0) {
|
if (a.len != 0) {
|
||||||
t_info("incorrect length\n");
|
atf_tc_fail("incorrect length");
|
||||||
result = T_FAIL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (a.data != NULL) {
|
if (a.data != NULL) {
|
||||||
t_info("incorrect data\n");
|
atf_tc_fail("incorrect data");
|
||||||
result = T_FAIL;
|
|
||||||
}
|
}
|
||||||
if (a.terminated) {
|
if (a.terminated) {
|
||||||
t_info("incorrect terminated\n");
|
atf_tc_fail("incorrect terminated");
|
||||||
result = T_FAIL;
|
|
||||||
}
|
}
|
||||||
if (a.buffer != NULL) {
|
if (a.buffer != NULL) {
|
||||||
t_info("incorrect buffer\n");
|
atf_tc_fail("incorrect buffer");
|
||||||
result = T_FAIL;
|
|
||||||
}
|
}
|
||||||
if (buf->refcnt != 1) {
|
if (buf->refcnt != 1) {
|
||||||
t_info("too many references to buf\n");
|
atf_tc_fail("too many references to buf");
|
||||||
result = T_FAIL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Clean up buffer.
|
* Clean up buffer.
|
||||||
*/
|
*/
|
||||||
if (!buffer_dereference(&buf, MDL)) {
|
if (!buffer_dereference(&buf, MDL)) {
|
||||||
t_info("buffer_reference() failed\n");
|
atf_tc_fail("buffer_reference() failed");
|
||||||
t_result(T_FAIL);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
t_result(result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
ATF_TC(data_string_forget_nobuf);
|
||||||
test_data_string_forget_nobuf(void) {
|
|
||||||
static const char *test_desc =
|
|
||||||
"data_string_forget test, data_string without buffer";
|
|
||||||
int result = T_PASS;
|
|
||||||
|
|
||||||
|
ATF_TC_HEAD(data_string_forget_nobuf, tc) {
|
||||||
|
atf_tc_set_md_var(tc, "descr", "data_string_forget test, "
|
||||||
|
"data_string without buffer");
|
||||||
|
}
|
||||||
|
|
||||||
|
ATF_TC_BODY(data_string_forget_nobuf, tc) {
|
||||||
struct data_string a;
|
struct data_string a;
|
||||||
const char *str = "Lorem ipsum dolor sit amet massa nunc.";
|
const char *str = "Lorem ipsum dolor sit amet massa nunc.";
|
||||||
|
|
||||||
t_assert("data_string_forget, no buffer", 1, T_REQUIRED, "%s", test_desc);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Create the string we want to forget.
|
* Create the string we want to forget.
|
||||||
*/
|
*/
|
||||||
@ -367,46 +281,36 @@ test_data_string_forget_nobuf(void) {
|
|||||||
data_string_forget(&a, MDL);
|
data_string_forget(&a, MDL);
|
||||||
|
|
||||||
if (a.len != 0) {
|
if (a.len != 0) {
|
||||||
t_info("incorrect length\n");
|
atf_tc_fail("incorrect length");
|
||||||
result = T_FAIL;
|
|
||||||
}
|
}
|
||||||
if (a.data != NULL) {
|
if (a.data != NULL) {
|
||||||
t_info("incorrect data\n");
|
atf_tc_fail("incorrect data");
|
||||||
result = T_FAIL;
|
|
||||||
}
|
}
|
||||||
if (a.terminated) {
|
if (a.terminated) {
|
||||||
t_info("incorrect terminated\n");
|
atf_tc_fail("incorrect terminated");
|
||||||
result = T_FAIL;
|
|
||||||
}
|
}
|
||||||
if (a.buffer != NULL) {
|
if (a.buffer != NULL) {
|
||||||
t_info("incorrect buffer\n");
|
atf_tc_fail("incorrect buffer");
|
||||||
result = T_FAIL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
t_result(result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
ATF_TC(data_string_copy);
|
||||||
test_data_string_copy(void) {
|
|
||||||
static const char *test_desc =
|
|
||||||
"data_string_copy basic test";
|
|
||||||
int result = T_PASS;
|
|
||||||
|
|
||||||
|
ATF_TC_HEAD(data_string_copy, tc) {
|
||||||
|
atf_tc_set_md_var(tc, "descr", "data_string_copy basic test");
|
||||||
|
}
|
||||||
|
|
||||||
|
ATF_TC_BODY(data_string_copy, tc) {
|
||||||
struct data_string a, b;
|
struct data_string a, b;
|
||||||
const char *str = "Lorem ipsum dolor sit amet orci aliquam.";
|
const char *str = "Lorem ipsum dolor sit amet orci aliquam.";
|
||||||
|
|
||||||
t_assert("data_string_copy", 1, T_REQUIRED, "%s", test_desc);
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Create the string we want to copy.
|
* Create the string we want to copy.
|
||||||
*/
|
*/
|
||||||
memset(&a, 0, sizeof(a));
|
memset(&a, 0, sizeof(a));
|
||||||
a.len = strlen(str);
|
a.len = strlen(str);
|
||||||
if (!buffer_allocate(&a.buffer, a.len, MDL)) {
|
if (!buffer_allocate(&a.buffer, a.len, MDL)) {
|
||||||
t_info("out of memory\n");
|
atf_tc_fail("out of memory");
|
||||||
t_result(T_FAIL);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
a.data = a.buffer->data;
|
a.data = a.buffer->data;
|
||||||
memcpy(a.buffer->data, str, a.len);
|
memcpy(a.buffer->data, str, a.len);
|
||||||
@ -418,20 +322,16 @@ test_data_string_copy(void) {
|
|||||||
data_string_copy(&b, &a, MDL);
|
data_string_copy(&b, &a, MDL);
|
||||||
|
|
||||||
if (b.len != a.len) {
|
if (b.len != a.len) {
|
||||||
t_info("incorrect length\n");
|
atf_tc_fail("incorrect length");
|
||||||
result = T_FAIL;
|
|
||||||
}
|
}
|
||||||
if (b.data != a.data) {
|
if (b.data != a.data) {
|
||||||
t_info("incorrect data\n");
|
atf_tc_fail("incorrect data");
|
||||||
result = T_FAIL;
|
|
||||||
}
|
}
|
||||||
if (b.terminated != a.terminated) {
|
if (b.terminated != a.terminated) {
|
||||||
t_info("incorrect terminated\n");
|
atf_tc_fail("incorrect terminated");
|
||||||
result = T_FAIL;
|
|
||||||
}
|
}
|
||||||
if (b.buffer != a.buffer) {
|
if (b.buffer != a.buffer) {
|
||||||
t_info("incorrect buffer\n");
|
atf_tc_fail("incorrect buffer");
|
||||||
result = T_FAIL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -439,23 +339,19 @@ test_data_string_copy(void) {
|
|||||||
*/
|
*/
|
||||||
data_string_forget(&b, MDL);
|
data_string_forget(&b, MDL);
|
||||||
data_string_forget(&a, MDL);
|
data_string_forget(&a, MDL);
|
||||||
|
|
||||||
t_result(result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
ATF_TC(data_string_copy_nobuf);
|
||||||
test_data_string_copy_nobuf(void) {
|
|
||||||
static const char *test_desc =
|
|
||||||
"data_string_copy test, data_string without buffer";
|
|
||||||
int result = T_PASS;
|
|
||||||
|
|
||||||
|
ATF_TC_HEAD(data_string_copy_nobuf, tc) {
|
||||||
|
atf_tc_set_md_var(tc, "descr", "data_string_copy test, "
|
||||||
|
"data_string without buffer");
|
||||||
|
}
|
||||||
|
|
||||||
|
ATF_TC_BODY(data_string_copy_nobuf, tc) {
|
||||||
struct data_string a, b;
|
struct data_string a, b;
|
||||||
const char *str = "Lorem ipsum dolor sit amet cras amet.";
|
const char *str = "Lorem ipsum dolor sit amet cras amet.";
|
||||||
|
|
||||||
t_assert("data_string_copy, no buffer", 1, T_REQUIRED, "%s",
|
|
||||||
test_desc);
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Create the string we want to copy.
|
* Create the string we want to copy.
|
||||||
*/
|
*/
|
||||||
@ -471,20 +367,16 @@ test_data_string_copy_nobuf(void) {
|
|||||||
data_string_copy(&b, &a, MDL);
|
data_string_copy(&b, &a, MDL);
|
||||||
|
|
||||||
if (b.len != a.len) {
|
if (b.len != a.len) {
|
||||||
t_info("incorrect length\n");
|
atf_tc_fail("incorrect length");
|
||||||
result = T_FAIL;
|
|
||||||
}
|
}
|
||||||
if (b.data != a.data) {
|
if (b.data != a.data) {
|
||||||
t_info("incorrect data\n");
|
atf_tc_fail("incorrect data");
|
||||||
result = T_FAIL;
|
|
||||||
}
|
}
|
||||||
if (b.terminated != a.terminated) {
|
if (b.terminated != a.terminated) {
|
||||||
t_info("incorrect terminated\n");
|
atf_tc_fail("incorrect terminated");
|
||||||
result = T_FAIL;
|
|
||||||
}
|
}
|
||||||
if (b.buffer != a.buffer) {
|
if (b.buffer != a.buffer) {
|
||||||
t_info("incorrect buffer\n");
|
atf_tc_fail("incorrect buffer");
|
||||||
result = T_FAIL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -493,5 +385,17 @@ test_data_string_copy_nobuf(void) {
|
|||||||
data_string_forget(&b, MDL);
|
data_string_forget(&b, MDL);
|
||||||
data_string_forget(&a, MDL);
|
data_string_forget(&a, MDL);
|
||||||
|
|
||||||
t_result(result);
|
}
|
||||||
|
|
||||||
|
ATF_TP_ADD_TCS(tp)
|
||||||
|
{
|
||||||
|
ATF_TP_ADD_TC(tp, buffer_allocate);
|
||||||
|
ATF_TP_ADD_TC(tp, buffer_reference);
|
||||||
|
ATF_TP_ADD_TC(tp, buffer_dereference);
|
||||||
|
ATF_TP_ADD_TC(tp, data_string_forget);
|
||||||
|
ATF_TP_ADD_TC(tp, data_string_forget_nobuf);
|
||||||
|
ATF_TP_ADD_TC(tp, data_string_copy);
|
||||||
|
ATF_TP_ADD_TC(tp, data_string_copy_nobuf);
|
||||||
|
|
||||||
|
return (atf_no_error());
|
||||||
}
|
}
|
||||||
|
@ -651,7 +651,6 @@ Developer:
|
|||||||
ATF unittests : $enable_atf
|
ATF unittests : $enable_atf
|
||||||
|
|
||||||
END
|
END
|
||||||
# TODO: Add unit tests
|
|
||||||
# TODO: Add Perl system tests
|
# TODO: Add Perl system tests
|
||||||
|
|
||||||
if test "$enable_atf" != "no"
|
if test "$enable_atf" != "no"
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
SUBDIRS = .
|
SUBDIRS = .
|
||||||
|
|
||||||
AM_CPPFLAGS = $(ATF_CFLAGS) -DUNIT_TEST -I$((top_srcdir)/includes
|
AM_CPPFLAGS = $(ATF_CFLAGS) -DUNIT_TEST -I$(top_srcdir)/includes
|
||||||
AM_CPPFLAGS += -I$(top_srcdir)/bind/include -I$(top_srcdir)
|
AM_CPPFLAGS += -I$(top_srcdir)/bind/include -I$(top_srcdir)
|
||||||
AM_CPPFLAGS += -DLOCALSTATEDIR='"."' -Wno-unused-function -Wno-error=unused-variable
|
AM_CPPFLAGS += -DLOCALSTATEDIR='"."' -Wno-unused-function -Wno-error=unused-variable
|
||||||
|
|
||||||
@ -42,4 +42,4 @@ legacy_unittests_LDADD = $(DHCPLIBS) $(ATF_LDFLAGS)
|
|||||||
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
noinst_PROGRAMS = $(ATF_TESTS) $(TESTS)
|
check_PROGRAMS = $(ATF_TESTS) $(TESTS)
|
@ -17,27 +17,61 @@
|
|||||||
#include <config.h>
|
#include <config.h>
|
||||||
#include <atf-c.h>
|
#include <atf-c.h>
|
||||||
|
|
||||||
|
/* That is an example ATF test case, tailored to ISC DHCP sources.
|
||||||
|
For detailed description with examples, see man 3 atf-c-api. */
|
||||||
|
|
||||||
|
/* this macro defines a name of a test case. Typical test case constists
|
||||||
|
of an initial test declaration (ATF_TC()) followed by 3 phases:
|
||||||
|
|
||||||
|
- Initialization: ATF_TC_HEAD()
|
||||||
|
- Main body: ATF_TC_BODY()
|
||||||
|
- Cleanup: ATF_TC_CLEANUP()
|
||||||
|
|
||||||
|
In many cases initialization or cleanup are not needed. Use
|
||||||
|
ATF_TC_WITHOUT_HEAD() or ATF_TC_WITH_CLEANUP() as needed. */
|
||||||
ATF_TC(simple_test_case);
|
ATF_TC(simple_test_case);
|
||||||
|
|
||||||
|
|
||||||
ATF_TC_HEAD(simple_test_case, tc)
|
ATF_TC_HEAD(simple_test_case, tc)
|
||||||
{
|
{
|
||||||
atf_tc_set_md_var(tc, "descr", "This test case is a simple DHCP test.");
|
atf_tc_set_md_var(tc, "descr", "This test case is a simple DHCP test.");
|
||||||
}
|
}
|
||||||
ATF_TC_BODY(simple_test_case, tc)
|
ATF_TC_BODY(simple_test_case, tc)
|
||||||
{
|
{
|
||||||
//ATF_CHECK(returns_a_boolean()); /* Non-fatal test. */
|
int condition = 1;
|
||||||
//ATF_REQUIRE(returns_a_boolean()); /* Fatal test. */
|
int this_is_linux = 1;
|
||||||
|
/* Failing condition will fail the test, but the code
|
||||||
|
itself will continue */
|
||||||
|
ATF_CHECK( 2 > 1 );
|
||||||
|
|
||||||
//ATF_CHECK_EQ(4, 2 + 2); /* Non-fatal test. */
|
/* assert style check. Test will abort if the condition is not met. */
|
||||||
//ATF_REQUIRE_EQ(4, 2 + 2); /* Fatal test. */
|
ATF_REQUIRE( 5 > 4 );
|
||||||
|
|
||||||
|
ATF_CHECK_EQ(4, 2 + 2); /* Non-fatal test. */
|
||||||
|
ATF_REQUIRE_EQ(4, 2 + 2); /* Fatal test. */
|
||||||
|
|
||||||
|
/* tests can also explicitly report test result */
|
||||||
|
if (!condition) {
|
||||||
|
atf_tc_fail("Condition not met!"); /* Explicit failure. */
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this_is_linux) {
|
||||||
|
atf_tc_skip("Skipping test. This Linux-only test.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (condition && linux) {
|
||||||
|
/* no extra comments for pass needed. It just passed. */
|
||||||
|
atf_tc_pass();
|
||||||
|
}
|
||||||
|
|
||||||
//if (!condition)
|
|
||||||
// atf_tc_fail("Condition not met!"); /* Explicit failure. */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* This macro defines main() method that will call specified
|
||||||
|
test cases. tp and simple_test_case names can be whatever you want
|
||||||
|
as long as it is a valid variable identifier. */
|
||||||
ATF_TP_ADD_TCS(tp)
|
ATF_TP_ADD_TCS(tp)
|
||||||
{
|
{
|
||||||
ATF_TP_ADD_TC(tp, simple_test_case);
|
ATF_TP_ADD_TC(tp, simple_test_case);
|
||||||
|
|
||||||
return (atf_no_error());
|
return (atf_no_error());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user