Merge branch 'dev' of ssh://box.fiane.intra/var/lib/git/libucore into dev

Conflicts:
	test/test_runner.c
This commit is contained in:
Nils O. Selåsdal
2013-07-07 03:19:12 +02:00
26 changed files with 729 additions and 49 deletions
+61
View File
@@ -410,6 +410,64 @@ START_TEST (test_logfile_dest_mask)
fail_if(st.st_size != 14*2, "was %ld\n", (long)st.st_size);
END_TEST
START_TEST (test_loglevel_module_none)
struct uc_log_module m = {
.id = 0,
.short_name = "MOD1",
.long_name = "Module 1",
.log_level = UC_LL_NONE,
};
struct uc_log_modules mods = {
.mods = &m,
.cnt = 1,
};
struct stat st;
struct uc_log_destination *dest;
int rc;
uc_log_init(&mods);
dest = uc_log_new_file(FILE_NAME, UC_LL_DEBUG, 1);
fail_if(dest == NULL);
uc_log_add_destination(dest);
UC_LOGFR(UC_LL_ERROR, 0, "Lorum ipson %d\n", 1);
rc = stat(FILE_NAME, &st);
fail_if(rc != 0, "stat failed: %s\n", strerror(errno));
fail_if(st.st_size != 0, "was %ld\n", (long)st.st_size);
END_TEST
START_TEST (test_loglevel_dest_none)
struct uc_log_module m = {
.id = 0,
.short_name = "MOD1",
.long_name = "Module 1",
.log_level = UC_LL_DEBUG,
};
struct uc_log_modules mods = {
.mods = &m,
.cnt = 1,
};
struct stat st;
struct uc_log_destination *dest;
int rc;
uc_log_init(&mods);
dest = uc_log_new_file(FILE_NAME, UC_LL_NONE, 1);
fail_if(dest == NULL);
uc_log_add_destination(dest);
UC_LOGFR(UC_LL_WARNING, 0, "Lorum ipson %d\n", 1);
rc = stat(FILE_NAME, &st);
fail_if(rc != 0, "stat failed: %s\n", strerror(errno));
fail_if(st.st_size != 0, "was %ld\n", (long)st.st_size);
END_TEST
Suite *logging_suite(void)
{
@@ -435,6 +493,9 @@ Suite *logging_suite(void)
tcase_add_test(tc2, test_logfile_invalid_file_after_reopen);
tcase_add_test(tc1, test_logfile_raw);
tcase_add_test(tc1, test_loglevel_module_none);
tcase_add_test(tc1, test_loglevel_dest_none);
tcase_add_checked_fixture(tc1, logging_rm_files, logging_rm_files);
tcase_add_checked_fixture(tc2, logging_setup_subdir, logging_rm_subdir);
+222
View File
@@ -0,0 +1,222 @@
#include <check.h>
#include <string.h>
#include <ucore/mbuf.h>
START_TEST (test_mbuf_new)
struct MBuf *mbuf;
mbuf = uc_mbuf_new(110);
fail_if(mbuf == NULL);
fail_if(uc_mbuf_len(mbuf) != 0);
fail_if(uc_mbuf_headroom(mbuf) != 0);
fail_if(uc_mbuf_tailroom(mbuf) != 110);
fail_if(mbuf->next != NULL);
fail_if(mbuf->p1 != NULL);
fail_if(mbuf->p2 != NULL);
fail_if(mbuf->p3 != NULL);
fail_if(mbuf->p4 != NULL);
fail_if(mbuf->cookie != NULL);
fail_if(mbuf->head != mbuf->tail);
uc_mbuf_free(mbuf);
END_TEST
START_TEST (test_mbuf_new_inline)
struct MBuf *mbuf;
mbuf = uc_mbuf_new_inline(110);
fail_if(mbuf == NULL);
fail_if(uc_mbuf_len(mbuf) != 0);
fail_if(uc_mbuf_headroom(mbuf) != 0);
fail_if(uc_mbuf_tailroom(mbuf) != 110);
fail_if(mbuf->next != NULL);
fail_if(mbuf->p1 != NULL);
fail_if(mbuf->p2 != NULL);
fail_if(mbuf->p3 != NULL);
fail_if(mbuf->p4 != NULL);
fail_if(mbuf->cookie != NULL);
fail_if(mbuf->head != mbuf->tail);
uc_mbuf_free(mbuf);
END_TEST
START_TEST (test_mbuf_new_headroom)
struct MBuf *mbuf;
mbuf = uc_mbuf_new_hr(110,20);
fail_if(mbuf == NULL);
fail_if(uc_mbuf_len(mbuf) != 0);
fail_if(uc_mbuf_headroom(mbuf) != 20);
fail_if(uc_mbuf_tailroom(mbuf) != 110);
fail_if(mbuf->next != NULL);
fail_if(mbuf->p1 != NULL);
fail_if(mbuf->p2 != NULL);
fail_if(mbuf->p3 != NULL);
fail_if(mbuf->p4 != NULL);
fail_if(mbuf->cookie != NULL);
fail_if(mbuf->head != mbuf->tail);
uc_mbuf_free(mbuf);
END_TEST
START_TEST (test_mbuf_put)
struct MBuf *mbuf;
uint8_t *data;
mbuf = uc_mbuf_new_inline(111);
fail_if(mbuf == NULL);
data = uc_mbuf_put(mbuf, 111);
fail_if(data == NULL);
fail_if(uc_mbuf_len(mbuf) != 111);
fail_if(uc_mbuf_tailroom(mbuf) != 0);
memset(data, 0, 111);
uc_mbuf_free(mbuf);
END_TEST
START_TEST (test_mbuf_put_fail)
struct MBuf *mbuf;
uint8_t *data;
mbuf = uc_mbuf_new_inline(10);
fail_if(mbuf == NULL);
data = uc_mbuf_put(mbuf, 11);
fail_if(data != NULL);
uc_mbuf_free(mbuf);
END_TEST
START_TEST (test_mbuf_push)
struct MBuf *mbuf;
uint8_t *data;
mbuf = uc_mbuf_new_hr(10,1);
fail_if(mbuf == NULL);
data = uc_mbuf_push(mbuf, 1);
fail_if(data == NULL);
fail_if(uc_mbuf_len(mbuf) != 1);
fail_if(uc_mbuf_headroom(mbuf) != 0);
*data = 0;
uc_mbuf_free(mbuf);
END_TEST
START_TEST (test_mbuf_push_fail)
struct MBuf *mbuf;
uint8_t *data;
mbuf = uc_mbuf_new_hr(1,2);
fail_if(mbuf == NULL);
data = uc_mbuf_push(mbuf, 3);
fail_if(data != NULL);
uc_mbuf_free(mbuf);
END_TEST
START_TEST (test_mbuf_pull)
struct MBuf *mbuf;
uint8_t *data1;
uint8_t *data2;
mbuf = uc_mbuf_new_inline(10);
fail_if(mbuf == NULL);
data1 = uc_mbuf_put(mbuf, 10);
fail_if(data1 == NULL);
fail_if(uc_mbuf_tailroom(mbuf) != 0);
fail_if(uc_mbuf_len(mbuf) != 10);
data2 = uc_mbuf_pull(mbuf,10);
fail_if(data2 == NULL);
fail_if(data1 != data2);
fail_if(uc_mbuf_len(mbuf) != 0);
uc_mbuf_free(mbuf);
END_TEST
START_TEST (test_mbuf_pull_fail)
struct MBuf *mbuf;
uint8_t *data1;
uint8_t *data2;
mbuf = uc_mbuf_new_inline(10);
fail_if(mbuf == NULL);
data1 = uc_mbuf_put(mbuf, 10);
fail_if(data1 == NULL);
fail_if(uc_mbuf_len(mbuf) != 10);
data2 = uc_mbuf_pull(mbuf,11);
fail_if(data2 != NULL);
fail_if(uc_mbuf_len(mbuf) != 10);
uc_mbuf_free(mbuf);
END_TEST
START_TEST (test_mbuf_copy)
struct MBuf *mbuf;
uint8_t *data1;
struct MBuf *copy;
mbuf = uc_mbuf_new_inline_hr(10,5);
fail_if(mbuf == NULL);
data1 = uc_mbuf_put(mbuf, 10);
fail_if(data1 == NULL);
strcpy((char*)data1, "123456789");
copy = uc_mbuf_copy_data(mbuf);
fail_if(copy == NULL);
fail_if(uc_mbuf_len(copy) != 10);
fail_if(uc_mbuf_headroom(copy) != 5);
fail_if(memcmp(mbuf->head, copy->head, 10) != 0);
uc_mbuf_free(mbuf);
uc_mbuf_free(copy);
END_TEST
Suite *mbuf_suite(void)
{
Suite *s = suite_create("mbuf");
TCase *tc = tcase_create("mbuf tests");
tcase_add_test(tc, test_mbuf_new);
tcase_add_test(tc, test_mbuf_new_inline);
tcase_add_test(tc, test_mbuf_new_headroom);
tcase_add_test(tc, test_mbuf_put);
tcase_add_test(tc, test_mbuf_put_fail);
tcase_add_test(tc, test_mbuf_push);
tcase_add_test(tc, test_mbuf_push_fail);
tcase_add_test(tc, test_mbuf_pull);
tcase_add_test(tc, test_mbuf_pull_fail);
tcase_add_test(tc, test_mbuf_copy);
suite_add_tcase(s, tc);
return s;
}
+63
View File
@@ -91,6 +91,65 @@ START_TEST (test_read_file_boundary)
free(content);
END_TEST
START_TEST (test_read_file_devnull)
char *content;
size_t len = 123;
content = uc_read_file("/dev/null", &len, 1024);
fail_if(content == NULL);
fail_if(len != 0);
free(content);
END_TEST
START_TEST (test_read_file_too_big)
char *content;
const char *filename = "test_read_file_too_big";
size_t len;
ssize_t rc;
int fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0664);
fail_if(fd == -1);
rc = write(fd, "hello", 5);
fail_if(rc != 5, "rc was %ld", (long)rc);
close(fd);
content = uc_read_file(filename, &len, 4);
fail_if(errno != EMSGSIZE);
fail_if(content != NULL);
unlink(filename);
END_TEST
START_TEST (test_read_file_big)
char *content;
const char *filename = "test_read_file_big";
char buf[4096 * 16];
size_t len;
ssize_t rc;
int fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0664);
fail_if(fd == -1);
memset(buf, 'a', sizeof buf);
rc = write(fd, buf, sizeof buf);
fail_if(rc != sizeof buf, "rc was %ld", (long)rc);
close(fd);
content = uc_read_file(filename, &len, 4096*16);
fail_if(content == NULL);
fail_if(len != sizeof buf);
fail_if(memcmp(content, buf, sizeof buf) != 0);
free(content);
unlink(filename);
END_TEST
Suite *read_file_suite(void)
{
Suite *s = suite_create("read_file");
@@ -99,6 +158,10 @@ Suite *read_file_suite(void)
tcase_add_test(tc, test_read_file_simple);
tcase_add_test(tc, test_read_file_greater_than_max);
tcase_add_test(tc, test_read_file_boundary);
tcase_add_test(tc, test_read_file_devnull);
tcase_add_test(tc, test_read_file_too_big);
tcase_add_test(tc, test_read_file_big);
suite_add_tcase(s, tc);
+2
View File
@@ -19,6 +19,7 @@ extern Suite *clock_suite(void);
extern Suite *seq_suite(void);
extern Suite *sat_math_suite(void);
extern Suite *timers_suite(void);
extern Suite *mbuf_suite(void);
extern Suite *human_bytesz_suite(void);
static suite_func suites[] = {
@@ -35,6 +36,7 @@ static suite_func suites[] = {
seq_suite,
sat_math_suite,
timers_suite,
mbuf_suite,
human_bytesz_suite
};