Tidy up ringbuf and make tests
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
#include <check.h>
|
||||
#include <unistd.h>
|
||||
#include "ucore/ringbuf.h"
|
||||
|
||||
START_TEST (test_ringbuf)
|
||||
{
|
||||
|
||||
UCRingBuf rb;
|
||||
int rc;
|
||||
int pgsize = getpagesize();
|
||||
rc = uc_ringbuf_init(&rb, pgsize);
|
||||
ck_assert_int_eq(rc, 0);
|
||||
ck_assert_int_eq(uc_ringbuf_available(&rb), pgsize);
|
||||
|
||||
|
||||
for (int i = 0 ; i < pgsize; i++) {
|
||||
unsigned char data = i % 256;
|
||||
rc = uc_ringbuf_write(&rb, &data, 1);
|
||||
ck_assert_int_eq(rc, 0);
|
||||
|
||||
}
|
||||
ck_assert_int_eq(uc_ringbuf_available(&rb), 0);
|
||||
|
||||
|
||||
for (int i = 0; i < pgsize; i++) {
|
||||
unsigned char data = 0;
|
||||
rc = uc_ringbuf_read(&rb, &data, 1);
|
||||
ck_assert_int_eq(rc, 0);
|
||||
ck_assert_int_eq(data, i % 256);
|
||||
}
|
||||
ck_assert_int_eq(uc_ringbuf_available(&rb), pgsize);
|
||||
|
||||
}
|
||||
|
||||
Suite *ringbuf_suite(void)
|
||||
{
|
||||
Suite *s = suite_create("ringbuf");
|
||||
TCase *tc1 = tcase_create("ringbuf");
|
||||
|
||||
tcase_add_test(tc1, test_ringbuf);
|
||||
#ifndef __APPLE__
|
||||
#endif
|
||||
|
||||
suite_add_tcase(s, tc1);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
+6
-4
@@ -34,6 +34,7 @@ extern Suite *ticket_lock_suite(void);
|
||||
extern Suite *restart_counter_suite(void);
|
||||
extern Suite *iomux_suite(void);
|
||||
extern Suite *iomux_signal_suite(void);
|
||||
extern Suite *ringbuf_suite(void);
|
||||
|
||||
static suite_func suites[] = {
|
||||
bitvec_suite,
|
||||
@@ -62,7 +63,8 @@ static suite_func suites[] = {
|
||||
ticket_lock_suite,
|
||||
restart_counter_suite,
|
||||
iomux_suite,
|
||||
iomux_signal_suite
|
||||
iomux_signal_suite,
|
||||
ringbuf_suite
|
||||
|
||||
};
|
||||
|
||||
@@ -105,7 +107,7 @@ main (int argc, char *argv[])
|
||||
size_t i;
|
||||
|
||||
SRunner *sr = srunner_create (NULL);
|
||||
if (xml_output)
|
||||
if (xml_output)
|
||||
srunner_set_xml(sr, "result.xml");
|
||||
|
||||
//set the environment variable CK_FORK=no which means don't fork().
|
||||
@@ -131,10 +133,10 @@ main (int argc, char *argv[])
|
||||
number_run = srunner_ntests_run(sr);
|
||||
number_failed = srunner_ntests_failed (sr);
|
||||
srunner_free (sr);
|
||||
|
||||
|
||||
if (!number_run)
|
||||
puts("ERROR: no tests were run");
|
||||
if (number_failed)
|
||||
if (number_failed)
|
||||
printf("ERROR: %d tests failed\n", number_failed);
|
||||
|
||||
return (number_failed != 0) ;
|
||||
|
||||
Reference in New Issue
Block a user