check_rb.c   check_rb.c 
skipping to change at line 33 skipping to change at line 33
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <syslog.h> #include <syslog.h>
#include <errno.h> #include <errno.h>
#include <check.h> #include <check.h>
#include <qb/qbdefs.h> #include <qb/qbdefs.h>
#include <qb/qbrb.h> #include <qb/qbrb.h>
#include <qb/qbipc_common.h> #include <qb/qbipc_common.h>
#include <qb/qbutil.h> #include <qb/qblog.h>
START_TEST(test_ring_buffer1) START_TEST(test_ring_buffer1)
{ {
char my_buf[512]; char my_buf[512];
struct qb_ipc_request_header *hdr; struct qb_ipc_request_header hdr;
char *str; char *str;
qb_ringbuffer_t *rb; qb_ringbuffer_t *rb;
int32_t i; int32_t i;
int32_t b; int32_t b;
ssize_t actual; ssize_t actual;
ssize_t avail; ssize_t avail;
rb = qb_rb_open("test1", 200, QB_RB_FLAG_CREATE, 0); rb = qb_rb_open("test1", 200, QB_RB_FLAG_CREATE, 0);
fail_if(rb == NULL); fail_if(rb == NULL);
for (b = 0; b < 3; b++) { for (b = 0; b < 3; b++) {
hdr = (struct qb_ipc_request_header *) my_buf; memcpy(&hdr, my_buf, sizeof(struct qb_ipc_request_header));
str = my_buf + sizeof(struct qb_ipc_request_header); str = my_buf + sizeof(struct qb_ipc_request_header);
for (i = 0; i < 900; i++) { for (i = 0; i < 900; i++) {
hdr->id = __LINE__ + i; hdr.id = __LINE__ + i;
hdr->size = hdr.size =
sprintf(str, "ID: %d (%s + i(%d)) -- %s-%s!", sprintf(str, "ID: %d (%s + i(%d)) -- %s-%s!",
hdr->id, "actually the line number", i, hdr.id, "actually the line number", i,
__func__, __FILE__) + 1; __func__, __FILE__) + 1;
hdr->size += sizeof(struct qb_ipc_request_header); hdr.size += sizeof(struct qb_ipc_request_header);
avail = qb_rb_space_free(rb); avail = qb_rb_space_free(rb);
actual = qb_rb_chunk_write(rb, hdr, hdr->size); actual = qb_rb_chunk_write(rb, &hdr, hdr.size);
if (avail < (hdr->size + (2 * sizeof(uint32_t)))) { if (avail < (hdr.size + (2 * sizeof(uint32_t)))) {
ck_assert_int_eq(actual, -EAGAIN); ck_assert_int_eq(actual, -EAGAIN);
} else { } else {
ck_assert_int_eq(actual, hdr->size); ck_assert_int_eq(actual, hdr.size);
} }
} }
memset(my_buf, 0, sizeof(my_buf)); memset(my_buf, 0, sizeof(my_buf));
hdr = (struct qb_ipc_request_header *) my_buf; memcpy(&hdr, my_buf, sizeof(struct qb_ipc_request_header));
str = my_buf + sizeof(struct qb_ipc_request_header); str = my_buf + sizeof(struct qb_ipc_request_header);
for (i = 0; i < 15; i++) { for (i = 0; i < 15; i++) {
actual = qb_rb_chunk_read(rb, hdr, 512, 0); actual = qb_rb_chunk_read(rb, &hdr, 512, 0);
if (actual < 0) { if (actual < 0) {
ck_assert_int_eq(0, qb_rb_chunks_used(rb)); ck_assert_int_eq(0, qb_rb_chunks_used(rb));
break; break;
} }
str[actual - sizeof(struct qb_ipc_request_header)] = '\0'; str[actual - sizeof(struct qb_ipc_request_header)] = '\0';
ck_assert_int_eq(actual, hdr->size); ck_assert_int_eq(actual, hdr.size);
} }
} }
qb_rb_close(rb); qb_rb_close(rb);
} }
END_TEST END_TEST
/* /*
* nice size (int64) * nice size (int64)
*/ */
START_TEST(test_ring_buffer2) START_TEST(test_ring_buffer2)
skipping to change at line 218 skipping to change at line 218
tcase_add_test(tc, test_ring_buffer3); tcase_add_test(tc, test_ring_buffer3);
suite_add_tcase(s, tc); suite_add_tcase(s, tc);
tc = tcase_create("test04"); tc = tcase_create("test04");
tcase_add_test(tc, test_ring_buffer4); tcase_add_test(tc, test_ring_buffer4);
suite_add_tcase(s, tc); suite_add_tcase(s, tc);
return s; return s;
} }
static void libqb_log_fn(const char *file_name,
int32_t file_line, int32_t severity, const char *ms
g)
{
if (severity < LOG_INFO)
printf("libqb: %s:%d %s\n", file_name, file_line, msg);
}
int32_t main(void) int32_t main(void)
{ {
int32_t number_failed; int32_t number_failed;
Suite *s = rb_suite(); Suite *s = rb_suite();
SRunner *sr = srunner_create(s); SRunner *sr = srunner_create(s);
qb_util_set_log_function(libqb_log_fn); qb_log_init("check", LOG_USER, LOG_EMERG);
qb_log_ctl(QB_LOG_SYSLOG, QB_LOG_CONF_ENABLED, QB_FALSE);
qb_log_filter_ctl(QB_LOG_STDERR, QB_LOG_FILTER_ADD,
QB_LOG_FILTER_FILE, "*", LOG_INFO);
qb_log_ctl(QB_LOG_STDERR, QB_LOG_CONF_ENABLED, QB_TRUE);
srunner_run_all(sr, CK_VERBOSE); srunner_run_all(sr, CK_VERBOSE);
number_failed = srunner_ntests_failed(sr); number_failed = srunner_ntests_failed(sr);
srunner_free(sr); srunner_free(sr);
return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
} }
 End of changes. 13 change blocks. 
22 lines changed or deleted 18 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/