This commit is contained in:
Nils O. Selåsdal
2025-07-16 00:10:44 +02:00
39 changed files with 773 additions and 91 deletions
+4 -4
View File
@@ -11,7 +11,7 @@ version_info = {
'version_revision': revision, 'version_revision': revision,
#version_abi is the abi version of the shared library. Only bump it when #version_abi is the abi version of the shared library. Only bump it when
#backwards compatibility breaks. Strive to not break the ABI. #backwards compatibility breaks. Strive to not break the ABI.
'version_abi': '1.0.0' 'version_abi': '1.0.0'
} }
version_info['version_str'] = "%d.%d.%d.%s" % ( version_info['version_str'] = "%d.%d.%d.%s" % (
version_info['version_major'], version_info['version_major'],
@@ -20,7 +20,7 @@ version_info['version_str'] = "%d.%d.%d.%s" % (
version_info['version_revision']) version_info['version_revision'])
AddOption('--build_type', AddOption('--build_type',
dest = 'build_type', dest = 'build_type',
type = 'choice', type = 'choice',
nargs = 1, nargs = 1,
@@ -87,7 +87,7 @@ test_xml = GetOption('test_xml')
prefix = GetOption('prefix') prefix = GetOption('prefix')
lib_suffix = '' lib_suffix = ''
if not (build_type in ['debug', 'release']): if not (build_type in ['debug', 'release']):
print "Error: expected 'debug' or 'release', found: " + build_type print("Error: expected 'debug' or 'release', found: " + build_type)
Exit(1) Exit(1)
def InstallPerm(env, dest, files, perm): def InstallPerm(env, dest, files, perm):
@@ -100,7 +100,7 @@ def InstallPerm(env, dest, files, perm):
env = Environment(tools = ['default', 'textfile', 'packaging']) env = Environment(tools = ['default', 'textfile', 'packaging'])
#allow shell environment to override compiler #allow shell environment to override compiler
if os.environ.has_key('CC'): if os.environ.get('CC'):
env['CC'] = os.environ['CC'] env['CC'] = os.environ['CC']
env.AddMethod(InstallPerm) env.AddMethod(InstallPerm)
+2 -2
View File
@@ -8,6 +8,6 @@ headers = ucore_env.Glob('ucore/*.h')
#install targets #install targets
ucore_env.Alias('install', ucore_env.Alias('install',
ucore_env.InstallPerm(os.path.join(prefix, 'include', 'ucore'), headers, 0644)) ucore_env.InstallPerm(os.path.join(prefix, 'include', 'ucore'), headers, 0o0644))
+98
View File
@@ -0,0 +1,98 @@
#ifndef UC_RINGBUG_H_
#define UC_RINGBUG_H_
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct UCRingBuf UCRingBuf;
struct UCRingBuf {
char *base;
uint32_t sz;
uint32_t read_idx;
uint32_t write_idx;
};
/**
* Creates a new ringbuffer of at least @sz length.
* The length will be rounded up to the neares page size
*
* The ringbuffer is implementd by mapping the same physical memory
* twice into virtual memory adjacent to eachother, avoiding
* a splitting up read/writes when the ringbuffer wraps around.
*
* This means accessing rb.base[rb.len] up to rb.base[rb.len * 2 - 1]
* is accessing the same memory as rb.base[0] up to rb.base[rb.len -1]
*
* @param rb UCRingBuf to initialize
* @param sz minimum length of the ring buffer
* @returns 0 on success
*/
int uc_ringbuf_init(UCRingBuf *rb, uint32_t sz);
/** Free resources used by the ring buffer.
*
* @return 0 on success
*/
int uc_ringbuf_destroy(UCRingBuf *rb);
/**
* Write data to the ringbuffer. The number of bytes to write must fit
* in the free space of the ringbuffer
*
* @param rb UCRingBuf to write to.
* @param data data to write
* @param sz number of bytes to write from data
* @return 0 on success
*/
int uc_ringbuf_write(UCRingBuf *rb, const void *restrict data, uint32_t sz);
/** Read data from the ringbuffer
*
* @param rb UCRingBuf to write to.
* @param data buffer to copy data into
* @param sz number of bytes to read, must not exceed available data
* in the buffer
* @return 0 on success
*/
int uc_ringbuf_read(UCRingBuf *rb, void *restrict data, uint32_t sz);
/** Inspect how much free space is available for writing to the ring buffer
*
* @param rb UCRingBuf to inspect
* @returns number of free bytes
*/
uint32_t uc_ringbuf_available(const UCRingBuf *rb);
/**
* Length of available data in the ringbuffer
*
* @param rb UCRingBuf get length of
*
* @return length of data available to read
*/
static inline uint32_t uc_ringbuf_len(const UCRingBuf *rb)
{
return rb->write_idx - rb->read_idx;
}
/**
* Get a pointer to the first unread byte
* Caller is responsible for reading no more than the available
* data
*
* @param rb UCRingBuf to peek into
*
* @returns pointer to first unread byte
*/
static inline void *uc_ringbuf_peek(const UCRingBuf *rb)
{
return &rb->base[rb->read_idx];
}
#ifdef __cplusplus
}
#endif
#endif
+11 -13
View File
@@ -18,22 +18,21 @@ static inline int bit_index(int b)
} }
static inline int bit_offset(int b) static inline int bit_offset(int b)
{ {
return b % (sizeof(uc_bv_integer) * CHAR_BIT); return b % (sizeof(uc_bv_integer) * CHAR_BIT);
} }
struct UCBitVec *uc_bv_new(size_t nbits) struct UCBitVec *uc_bv_new(size_t nbits)
{ {
struct UCBitVec *v = malloc(sizeof *v); size_t vec_len = UC_BV_LEN(nbits);
struct UCBitVec *v;
void *mem = malloc(sizeof *v + vec_len * sizeof(uc_bv_integer));
v = mem;
if (v == NULL) if (v == NULL)
return NULL; return NULL;
v->vec_len = UC_BV_LEN(nbits); v->vec_len = vec_len;
v->vec = malloc(v->vec_len * sizeof(uc_bv_integer)); v->vec = mem + sizeof *v;
if (v->vec == NULL) {
free(v);
return NULL;
}
uc_bv_clr_all(v); uc_bv_clr_all(v);
@@ -43,24 +42,23 @@ struct UCBitVec *uc_bv_new(size_t nbits)
void uc_bv_free(struct UCBitVec *v) void uc_bv_free(struct UCBitVec *v)
{ {
if (v) { if (v) {
free(v->vec);
free(v); free(v);
} }
} }
void uc_bv_clr_bit(struct UCBitVec *v,int b) void uc_bv_clr_bit(struct UCBitVec *v,int b)
{ {
v->vec[bit_index(b)] &= ~(1UL << (bit_offset(b))); v->vec[bit_index(b)] &= ~(1UL << (bit_offset(b)));
} }
int uc_bv_get_bit(const struct UCBitVec *v,int b) int uc_bv_get_bit(const struct UCBitVec *v,int b)
{ {
return !!(v->vec[bit_index(b)] & (1UL << bit_offset(b))); return !!(v->vec[bit_index(b)] & (1UL << bit_offset(b)));
} }
void uc_bv_set_bit(struct UCBitVec *v,int b) void uc_bv_set_bit(struct UCBitVec *v,int b)
{ {
v->vec[bit_index(b)] |= 1UL << (bit_offset(b)); v->vec[bit_index(b)] |= 1UL << (bit_offset(b));
} }
void uc_bv_set_bits_from_array(struct UCBitVec *v,const char *array,size_t array_len) void uc_bv_set_bits_from_array(struct UCBitVec *v,const char *array,size_t array_len)
+5
View File
@@ -7,6 +7,11 @@
#include <sys/types.h> #include <sys/types.h>
#include "ucore/fd_utils.h" #include "ucore/fd_utils.h"
/* bsd variants use TCP_KEEPALIVE */
#if defined(TCP_KEEPALIVE) && !defined(TCP_KEEPIDLE)
#define TCP_KEEPIDLE TCP_KEEPALIVE
#endif
int uc_set_nonblocking(int fd) int uc_set_nonblocking(int fd)
{ {
int flags = fcntl(fd,F_GETFL,NULL); int flags = fcntl(fd,F_GETFL,NULL);
+23 -13
View File
@@ -1,12 +1,13 @@
#ifdef __linux__
#include <sys/epoll.h> #include <sys/epoll.h>
#include <unistd.h> #include <unistd.h>
#include <stdlib.h> #include <stdlib.h>
#include <errno.h>
#include <string.h> #include <string.h>
#include <assert.h> #include <assert.h>
#include <errno.h>
#include "iomux_impl.h" #include "iomux_impl.h"
//epoll (linux specific) IO mux. //epoll (linux specific) IO mux.
//We stuff the struct IOMuxFD pointer in the event.data.ptr slot //We stuff the struct IOMuxFD pointer in the event.data.ptr slot
//for the kernel to keep track of, so we don't have to. //for the kernel to keep track of, so we don't have to.
///we do not use edge triggered mode ///we do not use edge triggered mode
@@ -29,10 +30,10 @@ static inline uint32_t mux_2_epoll_events(unsigned int events)
{ {
uint32_t epoll_events = 0; uint32_t epoll_events = 0;
if (events & MUX_EV_READ) if (events & MUX_EV_READ)
epoll_events |= EPOLLIN; epoll_events |= EPOLLIN;
if (events & MUX_EV_WRITE) if (events & MUX_EV_WRITE)
epoll_events |= EPOLLOUT; epoll_events |= EPOLLOUT;
return epoll_events; return epoll_events;
@@ -47,7 +48,7 @@ static inline unsigned int epoll_2_mux_events(uint32_t events)
if (events & (EPOLLIN | EPOLLHUP | EPOLLERR)) if (events & (EPOLLIN | EPOLLHUP | EPOLLERR))
mux_events |= MUX_EV_READ; mux_events |= MUX_EV_READ;
if (events & EPOLLOUT) if (events & EPOLLOUT)
mux_events |= MUX_EV_WRITE; mux_events |= MUX_EV_WRITE;
return mux_events; return mux_events;
@@ -58,10 +59,10 @@ static int iomux_epoll_update_events(struct IOMux *mux_, struct IOMuxFD *fd)
struct IOMuxEpoll *mux = mux_->instance; struct IOMuxEpoll *mux = mux_->instance;
struct epoll_event e_event = {0, {0}}; struct epoll_event e_event = {0, {0}};
int rc; int rc;
e_event.events = mux_2_epoll_events(fd->what); e_event.events = mux_2_epoll_events(fd->what);
e_event.data.ptr = fd; e_event.data.ptr = fd;
rc = epoll_ctl(mux->epoll_fd, EPOLL_CTL_MOD, fd->fd, &e_event); rc = epoll_ctl(mux->epoll_fd, EPOLL_CTL_MOD, fd->fd, &e_event);
assert(rc == 0); assert(rc == 0);
if (rc != 0) if (rc != 0)
@@ -117,7 +118,7 @@ static int iomux_epoll_unregister_fd(struct IOMux *mux_, struct IOMuxFD *fd)
break; break;
} }
} }
mux->num_descriptors--; mux->num_descriptors--;
return rc; return rc;
@@ -145,10 +146,10 @@ static int iomux_epoll_run(struct IOMux *mux_, struct timeval *timeout)
//epoll takes the timeout in miliseconds //epoll takes the timeout in miliseconds
if (timeout) if (timeout)
timeout_ms = timeval_to_ms(timeout); timeout_ms = timeval_to_ms(timeout);
else else
timeout_ms = -1; timeout_ms = -1;
do { do {
rc = epoll_wait(mux->epoll_fd, mux->pending_events, EPOLL_WAIT_EVENTS, timeout_ms); rc = epoll_wait(mux->epoll_fd, mux->pending_events, EPOLL_WAIT_EVENTS, timeout_ms);
@@ -173,14 +174,14 @@ static int iomux_epoll_run(struct IOMux *mux_, struct timeval *timeout)
//we want to deliver only one event at a time to simplify //we want to deliver only one event at a time to simplify
//application programming. //application programming.
if (events & MUX_EV_READ && fd != NULL) { if (events & MUX_EV_READ && fd != NULL) {
assert(fd->callback != NULL); assert(fd->callback != NULL);
fd->callback(mux_, fd, MUX_EV_READ); fd->callback(mux_, fd, MUX_EV_READ);
} }
//now re-check, in case the IOMuxFD was removed //now re-check, in case the IOMuxFD was removed
fd = mux->pending_events[i].data.ptr; fd = mux->pending_events[i].data.ptr;
if (events & MUX_EV_WRITE && fd != NULL) { if (events & MUX_EV_WRITE && fd != NULL) {
assert(fd->callback != NULL); assert(fd->callback != NULL);
fd->callback(mux_, fd, MUX_EV_WRITE); fd->callback(mux_, fd, MUX_EV_WRITE);
} }
@@ -211,7 +212,7 @@ static const struct IOMuxOps epoll_ops = {
.unregister_fd_impl = iomux_epoll_unregister_fd, .unregister_fd_impl = iomux_epoll_unregister_fd,
.update_events_impl = iomux_epoll_update_events, .update_events_impl = iomux_epoll_update_events,
}; };
int iomux_epoll_init(struct IOMux *mux) int iomux_epoll_init(struct IOMux *mux)
{ {
struct IOMuxEpoll *mux_epoll = calloc(1, sizeof *mux_epoll); struct IOMuxEpoll *mux_epoll = calloc(1, sizeof *mux_epoll);
@@ -230,3 +231,12 @@ int iomux_epoll_init(struct IOMux *mux)
return 0; return 0;
} }
#else
#include <errno.h>
#include "iomux_impl.h"
int iomux_epoll_init(struct IOMux *mux)
{
return ENOSYS;
}
#endif
+7 -7
View File
@@ -54,8 +54,8 @@ void iomux_delete(struct IOMux *mux)
} }
//convert the difference between future and now //convert the difference between future and now
static inline void future_to_interval(const struct timeval *future, static inline void future_to_interval(const struct timeval *future,
const struct timeval *now, const struct timeval *now,
struct timeval *result) struct timeval *result)
{ {
if (timercmp(future, now, >)) { if (timercmp(future, now, >)) {
@@ -66,7 +66,7 @@ static inline void future_to_interval(const struct timeval *future,
} }
} }
static int iomux_run_timers(struct IOMux *mux, struct timeval *timeout) static int iomux_next_timer_timeout(struct IOMux *mux, struct timeval *timeout)
{ {
struct timeval first_timer; struct timeval first_timer;
@@ -78,12 +78,12 @@ static int iomux_run_timers(struct IOMux *mux, struct timeval *timeout)
first_timer.tv_sec, first_timer.tv_usec, first_timer.tv_sec, first_timer.tv_usec,
timeout->tv_sec, timeout->tv_usec); timeout->tv_sec, timeout->tv_usec);
*/ */
assert(timeout->tv_sec >= 0); assert(timeout->tv_sec >= 0);
assert(timeout->tv_usec >= 0); assert(timeout->tv_usec >= 0);
return 1; return 1;
} }
return 0; return 0;
} }
@@ -95,7 +95,7 @@ int iomux_run(struct IOMux *mux)
struct timeval timeout; struct timeval timeout;
struct timeval *timeoutp; struct timeval *timeoutp;
if (iomux_run_timers(mux, &timeout)) { if (iomux_next_timer_timeout(mux, &timeout)) {
timeoutp = &timeout; timeoutp = &timeout;
} else { } else {
timeoutp = NULL; timeoutp = NULL;
@@ -147,7 +147,7 @@ int iomux_update_events(struct IOMux *mux, struct IOMuxFD *fd, unsigned int what
assert(fd != NULL); assert(fd != NULL);
assert(fd->callback != NULL); assert(fd->callback != NULL);
assert(fd->fd >= 0); assert(fd->fd >= 0);
if (fd->what != what) { if (fd->what != what) {
fd->what = what; fd->what = what;
rc = mux->ops.update_events_impl(mux, fd); rc = mux->ops.update_events_impl(mux, fd);
+93
View File
@@ -0,0 +1,93 @@
#ifdef __linux
#define _GNU_SOURCE
#include <unistd.h>
#include <sys/mman.h>
#include <errno.h>
#include <string.h>
#include <stdio.h>
#include "ucore/ringbuf.h"
int uc_ringbuf_init(UCRingBuf *rb, uint32_t sz)
{
uint32_t pagesz = getpagesize();
// Round up to page size
sz = ((sz + pagesz - 1) / pagesz) * pagesz;
/* Reserve contiguous address space*/
void *base = mmap(NULL, sz * 2, PROT_NONE, MAP_POPULATE|MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
if (base == NULL) {
return -errno;
}
/* MAP_PRIVATE doesn't work */
base = mmap(base, sz * 1, PROT_READ|PROT_WRITE, MAP_POPULATE|MAP_ANONYMOUS|MAP_FIXED|MAP_SHARED, -1, 0);
if (base == MAP_FAILED) {
return -errno;
}
void *mbase = mremap(base, sz * 1, sz, MREMAP_FIXED|MREMAP_MAYMOVE|MREMAP_DONTUNMAP, base + sz);
if (mbase == MAP_FAILED) {
munmap(base, sz);
return -errno;
}
rb->base = base;
rb->sz = sz;
rb->read_idx = 0;
rb->write_idx = 0;
return 0;
}
int uc_ringbuf_destroy(UCRingBuf *rb)
{
int rc = munmap(rb->base, rb->sz);
if (rc != 0) {
return -errno;
}
rc = munmap(rb->base + rb->sz, rb->sz);
if (rc != 0) {
return -errno;
}
rb->base = NULL;
return 0;
}
uint32_t uc_ringbuf_available(const UCRingBuf *rb)
{
return rb->sz - rb->write_idx + rb->read_idx;
}
int uc_ringbuf_write(UCRingBuf *rb, const void *restrict data, uint32_t len)
{
if (rb->write_idx - rb->read_idx + len > rb->sz) {
return -ENOMEM;
}
memcpy(&rb->base[rb->write_idx], data, len);
rb->write_idx += len;
return 0;
}
int uc_ringbuf_read(UCRingBuf *rb, void *restrict data, uint32_t len)
{
if (uc_ringbuf_len(rb) < len) {
return -ENOMEM;
}
memcpy(data, &rb->base[rb->read_idx], len);
rb->read_idx += len;
if (rb->read_idx == rb->write_idx) {
rb->read_idx = rb->write_idx = 0;
} else if (rb->read_idx > rb->sz) {
rb->read_idx -= rb->sz;
rb->write_idx -= rb->sz;
}
return 0;
}
#endif
+39 -35
View File
@@ -21,27 +21,32 @@ struct Chunk {
struct SAlloc { struct SAlloc {
size_t chunksz; //data size of each chunk size_t chunksz; //data size of each chunk
Chunk *first; //head of the chunk list Chunk *first; //head of the chunk list
Chunk *current; Chunk *current;
}; };
static Chunk * static inline Chunk *
add_chunk(SAlloc *p) alloc_chunk(size_t sz)
{ {
Chunk *newchunk; Chunk *newchunk;
newchunk = malloc(sizeof *newchunk + p->chunksz - (sizeof *newchunk - offsetof(Chunk, data.data))); newchunk = malloc(sizeof *newchunk + sz - (sizeof *newchunk - offsetof(Chunk, data.data)));
if (newchunk == NULL)
return NULL;
if (p->current != NULL)
p->current->next = newchunk;
newchunk->next = NULL;
newchunk->firstfree = 0;
return newchunk; return newchunk;
} }
static Chunk *
add_chunk(SAlloc *p, Chunk *c)
{
if (c == NULL)
return c;
p->current->next = c;
c->next = NULL;
c->firstfree = 0;
return c;
}
static Chunk * static Chunk *
next_chunk(SAlloc *p) next_chunk(SAlloc *p)
{ {
@@ -50,8 +55,10 @@ next_chunk(SAlloc *p)
if (p->current->next) { if (p->current->next) {
newchunk = p->current->next; newchunk = p->current->next;
newchunk->firstfree = 0; newchunk->firstfree = 0;
} else } else {
newchunk = add_chunk(p); Chunk *c = alloc_chunk(p->chunksz);
newchunk = add_chunk(p, c);
}
if (newchunk) if (newchunk)
p->current = newchunk; p->current = newchunk;
@@ -63,19 +70,16 @@ SAlloc *
uc_new_salloc(size_t chunksz) uc_new_salloc(size_t chunksz)
{ {
SAlloc *p; SAlloc *p;
Chunk *first; Chunk *first;
p = malloc(sizeof *p); first = alloc_chunk(sizeof *p + chunksz);
if (p == NULL) if (first == NULL) {
return NULL;
p->chunksz = chunksz;
p->current = NULL;
if ((first = add_chunk(p)) == NULL) {
free(p);
return NULL; return NULL;
} }
first->next = NULL;
first->firstfree = sizeof *p;
p = (SAlloc *)&first->data.data[0];
p->chunksz = chunksz;
p->first = p->current = first; p->first = p->current = first;
return p; return p;
@@ -86,7 +90,9 @@ uc_reset_salloc(SAlloc *p)
{ {
Chunk *tmp; Chunk *tmp;
for(tmp = p->first; tmp; tmp = tmp->next) tmp = p->first;
tmp->firstfree = sizeof *p;
for(tmp = tmp->next; tmp; tmp = tmp->next)
tmp->firstfree = 0; tmp->firstfree = 0;
p->current = p->first; p->current = p->first;
@@ -97,9 +103,9 @@ uc_s_alloc(SAlloc *p,size_t sz)
{ {
Chunk *chunk; Chunk *chunk;
void *newmem; void *newmem;
chunk = p->current; chunk = p->current;
if (chunk->firstfree + sz > p->chunksz) { if (chunk->firstfree + sz > p->chunksz) {
if (sz > p->chunksz) if (sz > p->chunksz)
return NULL; return NULL;
@@ -107,7 +113,7 @@ uc_s_alloc(SAlloc *p,size_t sz)
if (chunk == NULL) if (chunk == NULL)
return NULL; return NULL;
} }
newmem = &chunk->data.data[chunk->firstfree]; newmem = &chunk->data.data[chunk->firstfree];
chunk->firstfree += sz; chunk->firstfree += sz;
@@ -119,17 +125,17 @@ uc_s_allocz(SAlloc *p,size_t sz)
{ {
void *newmem = uc_s_alloc(p, sz); void *newmem = uc_s_alloc(p, sz);
if (newmem != NULL) if (newmem != NULL)
memset(newmem, 0, sz); memset(newmem, 0, sz);
return newmem; return newmem;
} }
static void static void
free_chunks(Chunk *chunk) free_chunks(Chunk *chunk)
{ {
Chunk *next; Chunk *next;
for (next = NULL; chunk != NULL; chunk = next) { for (next = NULL; chunk != NULL; chunk = next) {
next = chunk->next; next = chunk->next;
free(chunk); free(chunk);
@@ -140,7 +146,5 @@ void
uc_free_salloc(SAlloc *p) uc_free_salloc(SAlloc *p)
{ {
free_chunks(p->first); free_chunks(p->first);
free(p);
} }
+13 -6
View File
@@ -1,20 +1,27 @@
import platform import platform
Import('env', 'build_type', 'prefix', 'lib_suffix', 'version_info', 'test_xml') Import('env', 'build_type', 'prefix', 'lib_suffix', 'version_info', 'test_xml')
test_env = env.Clone() test_env = env.Clone()
test_env.Append(LIBPATH = ['#build/src']); test_env.Append(LIBPATH = ['#build/src']);
test_env.Append(LIBS = ['ucore' + lib_suffix, 'check','m','rt']) test_env.Append(LIBS = ['ucore' + lib_suffix, 'check','m'])
system = platform.system() system = platform.system()
#NetBSD needs /usr/pkg/... #NetBSD needs /usr/pkg/...
if 'netbsd' in system.lower(): if 'netbsd' in system.lower():
test_env.Append(LIBPATH = ['/usr/pkg/lib']) test_env.Append(LIBPATH = ['/usr/pkg/lib'])
test_env.Append(LINKFLAGS = ['-Wl,-rpath,/usr/pkg/lib']) test_env.Append(LINKFLAGS = ['-Wl,-rpath,/usr/pkg/lib'])
test_env.Append(CPPPATH = ['/usr/pkg/include']) test_env.Append(CPPPATH = ['/usr/pkg/include'])
if 'darwin' in system.lower():
test_env.Append(LIBPATH = ['/opt/homebrew/lib'])
test_env.Append(LINKFLAGS = ['-Wl,-rpath,/opt/homebrew/lib'])
test_env.Append(CPPPATH = ['/opt/homebrew/include'])
if 'darwin' not in system.lower():
test_env.Append(LIBS = ['rt'])
tests = test_env.Glob('test_*.c') tests = test_env.Glob('test_*.c')
@@ -27,8 +34,8 @@ if test_xml:
test_env.Append(LINKFLAGS = ['-Wl,-rpath,\\$$ORIGIN/../src']) test_env.Append(LINKFLAGS = ['-Wl,-rpath,\\$$ORIGIN/../src'])
prog = test_env.Program('test_runner', tests) prog = test_env.Program('test_runner', tests)
cmd = test_env.Command(target='test_phony' , cmd = test_env.Command(target='test_phony' ,
source = None, source = None,
action= test_env.Dir('.').abspath + '/' + test_executable) action= test_env.Dir('.').abspath + '/' + test_executable)
test_env.Depends(cmd, prog) test_env.Depends(cmd, prog)
test_env.AlwaysBuild(cmd) test_env.AlwaysBuild(cmd)
+22
View File
@@ -3,6 +3,7 @@
START_TEST (test_2bcd_1234567890) START_TEST (test_2bcd_1234567890)
{
char ascii[] = "1234567890"; char ascii[] = "1234567890";
unsigned char bcd[5]; unsigned char bcd[5];
size_t len = uc_ascii2bcd(ascii, bcd, 0); size_t len = uc_ascii2bcd(ascii, bcd, 0);
@@ -13,26 +14,32 @@ START_TEST (test_2bcd_1234567890)
fail_if(bcd[2] != 0x65,"was 0x%x",bcd[2]); fail_if(bcd[2] != 0x65,"was 0x%x",bcd[2]);
fail_if(bcd[3] != 0x87,"was 0x%x",bcd[3]); fail_if(bcd[3] != 0x87,"was 0x%x",bcd[3]);
fail_if(bcd[4] != 0x09,"was 0x%x",bcd[4]); fail_if(bcd[4] != 0x09,"was 0x%x",bcd[4]);
}
END_TEST END_TEST
START_TEST (test_2bcd_empty) START_TEST (test_2bcd_empty)
{
char ascii[] = ""; char ascii[] = "";
unsigned char bcd[1]; unsigned char bcd[1];
size_t len = uc_ascii2bcd(ascii, bcd, 3); size_t len = uc_ascii2bcd(ascii, bcd, 3);
fail_if(len != 0, "len is %zu", len); fail_if(len != 0, "len is %zu", len);
}
END_TEST END_TEST
START_TEST (test_2bcd_1_filler) START_TEST (test_2bcd_1_filler)
{
char ascii[] = "1"; char ascii[] = "1";
unsigned char bcd[1]; unsigned char bcd[1];
size_t len = uc_ascii2bcd(ascii, bcd, 0xa); size_t len = uc_ascii2bcd(ascii, bcd, 0xa);
fail_if(len != 1, "len is %zu", len); fail_if(len != 1, "len is %zu", len);
fail_if(bcd[0] != 0xa1,"was 0x%x",bcd[0]); fail_if(bcd[0] != 0xa1,"was 0x%x",bcd[0]);
}
END_TEST END_TEST
START_TEST (test_2bcd_2_filler) START_TEST (test_2bcd_2_filler)
{
char ascii[] = "123"; char ascii[] = "123";
unsigned char bcd[2]; unsigned char bcd[2];
size_t len = uc_ascii2bcd(ascii, bcd, 0xf); size_t len = uc_ascii2bcd(ascii, bcd, 0xf);
@@ -41,9 +48,11 @@ START_TEST (test_2bcd_2_filler)
fail_if(bcd[0] != 0x21,"was 0x%x",bcd[0]); fail_if(bcd[0] != 0x21,"was 0x%x",bcd[0]);
fail_if(bcd[1] != 0xf3,"was 0x%x",bcd[1]); fail_if(bcd[1] != 0xf3,"was 0x%x",bcd[1]);
fail_if(UC_BCD_LEN(strlen(ascii)) != len); fail_if(UC_BCD_LEN(strlen(ascii)) != len);
}
END_TEST END_TEST
START_TEST (test_2bcd_3_filler) START_TEST (test_2bcd_3_filler)
{
char ascii[] = "123"; char ascii[] = "123";
unsigned char bcd[2]; unsigned char bcd[2];
@@ -52,18 +61,22 @@ START_TEST (test_2bcd_3_filler)
fail_if(len != 2, "len is %zu", len); fail_if(len != 2, "len is %zu", len);
fail_if(bcd[0] != 0x21,"was 0x%x",bcd[0]); fail_if(bcd[0] != 0x21,"was 0x%x",bcd[0]);
fail_if(bcd[1] != 0x03,"was 0x%x",bcd[1]); fail_if(bcd[1] != 0x03,"was 0x%x",bcd[1]);
}
END_TEST END_TEST
START_TEST (test_2bcd_non_digits) START_TEST (test_2bcd_non_digits)
{
char ascii[] = "a,b{ }="; char ascii[] = "a,b{ }=";
unsigned char bcd[10]; unsigned char bcd[10];
size_t len = uc_ascii2bcd(ascii, bcd, 0x0); size_t len = uc_ascii2bcd(ascii, bcd, 0x0);
fail_if(len != 0, "len is %zu", len); fail_if(len != 0, "len is %zu", len);
}
END_TEST END_TEST
START_TEST (test_2bcd_phoneno) START_TEST (test_2bcd_phoneno)
{
char ascii[] = "0047-3233-4"; char ascii[] = "0047-3233-4";
unsigned char bcd[24]; unsigned char bcd[24];
@@ -75,9 +88,11 @@ START_TEST (test_2bcd_phoneno)
fail_if(bcd[2] != 0x23,"was 0x%x",bcd[1]); fail_if(bcd[2] != 0x23,"was 0x%x",bcd[1]);
fail_if(bcd[3] != 0x33,"was 0x%x",bcd[1]); fail_if(bcd[3] != 0x33,"was 0x%x",bcd[1]);
fail_if(bcd[4] != 0xf4,"was 0x%x",bcd[1]); fail_if(bcd[4] != 0xf4,"was 0x%x",bcd[1]);
}
END_TEST END_TEST
START_TEST (test_2bcd_binary) START_TEST (test_2bcd_binary)
{
char ascii[] = {0x32,0x01,0xAF,0xFF,0x00}; char ascii[] = {0x32,0x01,0xAF,0xFF,0x00};
unsigned char bcd[24]; unsigned char bcd[24];
@@ -85,9 +100,11 @@ START_TEST (test_2bcd_binary)
fail_if(len != 1, "len is %zu", len); fail_if(len != 1, "len is %zu", len);
fail_if(bcd[0] != 0xf2,"0 was 0x%x",bcd[0]); fail_if(bcd[0] != 0xf2,"0 was 0x%x",bcd[0]);
}
END_TEST END_TEST
START_TEST (test_2hex_1) START_TEST (test_2hex_1)
{
unsigned char bcd[] = {0x21, 0x43 }; unsigned char bcd[] = {0x21, 0x43 };
char ascii[sizeof bcd * 2 + 1]; char ascii[sizeof bcd * 2 + 1];
@@ -100,9 +117,11 @@ START_TEST (test_2hex_1)
fail_if(ascii[3] != '4',"3 was %c",ascii[3]); fail_if(ascii[3] != '4',"3 was %c",ascii[3]);
fail_if(ascii[4] != 0, "4 was %c",ascii[4]); fail_if(ascii[4] != 0, "4 was %c",ascii[4]);
fail_if(UC_ASCII_LEN(sizeof bcd) != len); fail_if(UC_ASCII_LEN(sizeof bcd) != len);
}
END_TEST END_TEST
START_TEST (test_2hex_2) START_TEST (test_2hex_2)
{
unsigned char bcd[] = {0xF0, 0xFF, 0x00}; unsigned char bcd[] = {0xF0, 0xFF, 0x00};
char ascii[sizeof bcd * 2 + 1]; char ascii[sizeof bcd * 2 + 1];
@@ -116,9 +135,11 @@ START_TEST (test_2hex_2)
fail_if(ascii[4] != '0', "4 was %c",ascii[4]); fail_if(ascii[4] != '0', "4 was %c",ascii[4]);
fail_if(ascii[5] != '0', "5 was %c",ascii[5]); fail_if(ascii[5] != '0', "5 was %c",ascii[5]);
fail_if(ascii[6] != 0, "6 was %c",ascii[6]); fail_if(ascii[6] != 0, "6 was %c",ascii[6]);
}
END_TEST END_TEST
START_TEST (test_2hex_empty) START_TEST (test_2hex_empty)
{
unsigned char bcd[] = {0xF0, 0xFF, 0x00}; unsigned char bcd[] = {0xF0, 0xFF, 0x00};
char ascii[sizeof bcd * 2 + 1]; char ascii[sizeof bcd * 2 + 1];
@@ -127,6 +148,7 @@ START_TEST (test_2hex_empty)
fail_if(len != 0, "len is %zu", len); fail_if(len != 0, "len is %zu", len);
fail_if(ascii[0] != 0, "0 was %c",ascii[0]); fail_if(ascii[0] != 0, "0 was %c",ascii[0]);
}
END_TEST END_TEST
Suite *bcd_suite(void) Suite *bcd_suite(void)
+10
View File
@@ -3,15 +3,18 @@
START_TEST (test_bitvec_1) START_TEST (test_bitvec_1)
{
uc_bv_integer s[3] = {0}; uc_bv_integer s[3] = {0};
struct UCBitVec v = UC_BV_STATIC_INIT(s); struct UCBitVec v = UC_BV_STATIC_INIT(s);
size_t i; size_t i;
for (i = 0; i < sizeof s * 8; i++) for (i = 0; i < sizeof s * 8; i++)
fail_if(uc_bv_get_bit(&v, i), "bit %zu is not 0", i); fail_if(uc_bv_get_bit(&v, i), "bit %zu is not 0", i);
}
END_TEST END_TEST
START_TEST (test_bitvec_2) START_TEST (test_bitvec_2)
{
uc_bv_integer s[3] = {0}; uc_bv_integer s[3] = {0};
struct UCBitVec v = UC_BV_STATIC_INIT(s); struct UCBitVec v = UC_BV_STATIC_INIT(s);
size_t i; size_t i;
@@ -21,9 +24,11 @@ START_TEST (test_bitvec_2)
for (i = 0; i < sizeof s * 8; i++) for (i = 0; i < sizeof s * 8; i++)
fail_if(uc_bv_get_bit(&v, i) != 1 , "bit %zu is not 1", i); fail_if(uc_bv_get_bit(&v, i) != 1 , "bit %zu is not 1", i);
}
END_TEST END_TEST
START_TEST (test_bitvec_clearbit) START_TEST (test_bitvec_clearbit)
{
uc_bv_integer s[3] = {-1, -1, -1}; uc_bv_integer s[3] = {-1, -1, -1};
struct UCBitVec v = UC_BV_STATIC_INIT(s); struct UCBitVec v = UC_BV_STATIC_INIT(s);
size_t i; size_t i;
@@ -37,9 +42,11 @@ START_TEST (test_bitvec_clearbit)
for (i = 0; i < sizeof(uc_bv_integer) * 8; i++) for (i = 0; i < sizeof(uc_bv_integer) * 8; i++)
fail_if(uc_bv_get_bit(&v, i) != 0 , "bit %zu is not 0", i); fail_if(uc_bv_get_bit(&v, i) != 0 , "bit %zu is not 0", i);
}
END_TEST END_TEST
START_TEST (test_bitvec_set_bits_from_array) START_TEST (test_bitvec_set_bits_from_array)
{
struct UCBitVec *v = uc_bv_new(5); struct UCBitVec *v = uc_bv_new(5);
char a[] = {1, 0,1 ,0, 1}; char a[] = {1, 0,1 ,0, 1};
@@ -51,10 +58,12 @@ START_TEST (test_bitvec_set_bits_from_array)
fail_if(uc_bv_get_bit(v, 4) != 1 , "bit 4 is wrong"); fail_if(uc_bv_get_bit(v, 4) != 1 , "bit 4 is wrong");
uc_bv_free(v); uc_bv_free(v);
}
END_TEST END_TEST
START_TEST (test_bitvec_setall_clearall) START_TEST (test_bitvec_setall_clearall)
{
struct UCBitVec *v = uc_bv_new(511); struct UCBitVec *v = uc_bv_new(511);
size_t i; size_t i;
@@ -70,6 +79,7 @@ START_TEST (test_bitvec_setall_clearall)
uc_bv_free(v); uc_bv_free(v);
}
END_TEST END_TEST
Suite *bitvec_suite(void) Suite *bitvec_suite(void)
+14
View File
@@ -4,6 +4,7 @@
START_TEST (test_new_gbuf) START_TEST (test_new_gbuf)
{
GBuf *buf = uc_new_gbuf(11); GBuf *buf = uc_new_gbuf(11);
fail_if(buf == NULL); fail_if(buf == NULL);
@@ -13,9 +14,11 @@ START_TEST (test_new_gbuf)
fail_if(buf->used != 0); fail_if(buf->used != 0);
uc_gbuf_unref(buf); uc_gbuf_unref(buf);
}
END_TEST END_TEST
START_TEST (test_gbuf_grow) START_TEST (test_gbuf_grow)
{
GBuf *buf = uc_new_gbuf(33); GBuf *buf = uc_new_gbuf(33);
int rc; int rc;
@@ -29,9 +32,11 @@ START_TEST (test_gbuf_grow)
fail_if(buf->used != 0); fail_if(buf->used != 0);
uc_gbuf_unref(buf); uc_gbuf_unref(buf);
}
END_TEST END_TEST
START_TEST (test_gbuf_append1) START_TEST (test_gbuf_append1)
{
const char *data = "lorum_ ipson 1234567890"; const char *data = "lorum_ ipson 1234567890";
int rc; int rc;
GBuf *buf = uc_new_gbuf(11); GBuf *buf = uc_new_gbuf(11);
@@ -44,9 +49,11 @@ START_TEST (test_gbuf_append1)
fail_if(strcmp(data, buf->buf) != 0); fail_if(strcmp(data, buf->buf) != 0);
uc_gbuf_unref(buf); uc_gbuf_unref(buf);
}
END_TEST END_TEST
START_TEST (test_gbuf_printf1) START_TEST (test_gbuf_printf1)
{
int rc; int rc;
GBuf *buf = uc_new_gbuf(10); GBuf *buf = uc_new_gbuf(10);
@@ -58,9 +65,11 @@ START_TEST (test_gbuf_printf1)
fail_if(strcmp("test 1", buf->buf) != 0); fail_if(strcmp("test 1", buf->buf) != 0);
uc_gbuf_unref(buf); uc_gbuf_unref(buf);
}
END_TEST END_TEST
START_TEST (test_gbuf_printf2) START_TEST (test_gbuf_printf2)
{
int rc; int rc;
GBuf *buf = uc_new_gbuf(8); GBuf *buf = uc_new_gbuf(8);
@@ -72,9 +81,11 @@ START_TEST (test_gbuf_printf2)
fail_if(strcmp("test 1 test 2 test 3", buf->buf) != 0); fail_if(strcmp("test 1 test 2 test 3", buf->buf) != 0);
uc_gbuf_unref(buf); uc_gbuf_unref(buf);
}
END_TEST END_TEST
START_TEST (test_gbuf_printf3) START_TEST (test_gbuf_printf3)
{
int rc; int rc;
GBuf *buf = uc_new_gbuf(8); GBuf *buf = uc_new_gbuf(8);
@@ -92,9 +103,11 @@ START_TEST (test_gbuf_printf3)
fail_if(strcmp("test 1 test 2 test 3 test 4 test 5", buf->buf) != 0); fail_if(strcmp("test 1 test 2 test 3 test 4 test 5", buf->buf) != 0);
uc_gbuf_unref(buf); uc_gbuf_unref(buf);
}
END_TEST END_TEST
START_TEST (test_gbuf_printf_empty_string) START_TEST (test_gbuf_printf_empty_string)
{
int rc; int rc;
GBuf *buf = uc_new_gbuf(1); GBuf *buf = uc_new_gbuf(1);
const char *fmt = ""; //tricks gcc to not warn about empty format string const char *fmt = ""; //tricks gcc to not warn about empty format string
@@ -106,6 +119,7 @@ START_TEST (test_gbuf_printf_empty_string)
fail_if(buf->used != 0); fail_if(buf->used != 0);
uc_gbuf_unref(buf); uc_gbuf_unref(buf);
}
END_TEST END_TEST
+4
View File
@@ -4,6 +4,7 @@
START_TEST (test_settable_clock) START_TEST (test_settable_clock)
{
struct UCoreSettableClock my_clock; struct UCoreSettableClock my_clock;
struct timeval tv; struct timeval tv;
struct timeval tv_tmp; struct timeval tv_tmp;
@@ -34,9 +35,11 @@ START_TEST (test_settable_clock)
fail_if(tv.tv_sec != 123456789); fail_if(tv.tv_sec != 123456789);
fail_if(tv.tv_usec != 44); fail_if(tv.tv_usec != 44);
}
END_TEST END_TEST
START_TEST (test_cached_clock) START_TEST (test_cached_clock)
{
struct UCoreCachedClock my_clock; struct UCoreCachedClock my_clock;
struct timeval tv1,tv2; struct timeval tv1,tv2;
@@ -60,6 +63,7 @@ START_TEST (test_cached_clock)
fail_if(!timercmp(&tv1, &tv2, !=)); fail_if(!timercmp(&tv1, &tv2, !=));
}
END_TEST END_TEST
+2
View File
@@ -15,6 +15,7 @@ struct Outer {
}; };
START_TEST (test_container_of) START_TEST (test_container_of)
{
struct Outer outer = { struct Outer outer = {
.tag1 = 1, .tag1 = 1,
.tag2 = 2, .tag2 = 2,
@@ -29,6 +30,7 @@ START_TEST (test_container_of)
fail_if(outerp != &outer); fail_if(outerp != &outer);
}
END_TEST END_TEST
Suite *container_of_suite(void) Suite *container_of_suite(void)
+8
View File
@@ -5,6 +5,7 @@
START_TEST (test_dbuf) START_TEST (test_dbuf)
{
DBuf buf; DBuf buf;
int rc; int rc;
@@ -59,9 +60,11 @@ START_TEST (test_dbuf)
uc_dbuf_free(&buf); uc_dbuf_free(&buf);
}
END_TEST END_TEST
START_TEST (test_dbuf_take_fail) START_TEST (test_dbuf_take_fail)
{
DBuf buf; DBuf buf;
int rc; int rc;
@@ -80,10 +83,12 @@ START_TEST (test_dbuf_take_fail)
fail_if(rc == 0); fail_if(rc == 0);
uc_dbuf_free(&buf); uc_dbuf_free(&buf);
}
END_TEST END_TEST
START_TEST (test_dbuf_take_all) START_TEST (test_dbuf_take_all)
{
DBuf buf; DBuf buf;
int rc; int rc;
@@ -104,9 +109,11 @@ START_TEST (test_dbuf_take_all)
fail_if(uc_dbuf_remaining(&buf) != 10); fail_if(uc_dbuf_remaining(&buf) != 10);
uc_dbuf_free(&buf); uc_dbuf_free(&buf);
}
END_TEST END_TEST
START_TEST (test_dbuf_add_ensure_take) START_TEST (test_dbuf_add_ensure_take)
{
DBuf *buf; DBuf *buf;
int rc; int rc;
@@ -155,6 +162,7 @@ START_TEST (test_dbuf_add_ensure_take)
uc_dbuf_free(buf); uc_dbuf_free(buf);
free(buf); free(buf);
}
END_TEST END_TEST
+18
View File
@@ -6,6 +6,7 @@
START_TEST (test_dstr_basics) START_TEST (test_dstr_basics)
{
struct DStr str; struct DStr str;
int rc; int rc;
@@ -46,9 +47,11 @@ START_TEST (test_dstr_basics)
//just test that this doesn't crash: //just test that this doesn't crash:
uc_dstr_init(&str); uc_dstr_init(&str);
uc_dstr_destroy(&str); uc_dstr_destroy(&str);
}
END_TEST END_TEST
START_TEST (test_dstr_init) START_TEST (test_dstr_init)
{
struct DStr str; struct DStr str;
int rc; int rc;
@@ -65,9 +68,11 @@ START_TEST (test_dstr_init)
ck_assert_str_eq(uc_dstr_str(&str), "He"); ck_assert_str_eq(uc_dstr_str(&str), "He");
uc_dstr_destroy(&str); uc_dstr_destroy(&str);
}
END_TEST END_TEST
START_TEST (test_dstr_own) START_TEST (test_dstr_own)
{
struct DStr str; struct DStr str;
uc_dstr_init_str(&str, "init"); uc_dstr_init_str(&str, "init");
@@ -76,8 +81,10 @@ START_TEST (test_dstr_own)
ck_assert_str_eq(uc_dstr_str(&str), "Hello !"); ck_assert_str_eq(uc_dstr_str(&str), "Hello !");
uc_dstr_destroy(&str); uc_dstr_destroy(&str);
}
END_TEST END_TEST
START_TEST (test_dstr_own_steal) START_TEST (test_dstr_own_steal)
{
struct DStr str; struct DStr str;
char *s; char *s;
@@ -93,9 +100,11 @@ START_TEST (test_dstr_own_steal)
free(s); free(s);
uc_dstr_destroy(&str); uc_dstr_destroy(&str);
}
END_TEST END_TEST
START_TEST (test_dstr_trim) START_TEST (test_dstr_trim)
{
struct DStr str = UC_DSTR_INITIALIZER; struct DStr str = UC_DSTR_INITIALIZER;
uc_dstr_append_str(&str, " \t \nHello !\r\n"); uc_dstr_append_str(&str, " \t \nHello !\r\n");
@@ -118,9 +127,11 @@ START_TEST (test_dstr_trim)
uc_dstr_destroy(&str); uc_dstr_destroy(&str);
}
END_TEST END_TEST
START_TEST (test_dstr_replace) START_TEST (test_dstr_replace)
{
struct DStr str; struct DStr str;
size_t rc; size_t rc;
@@ -136,9 +147,11 @@ START_TEST (test_dstr_replace)
uc_dstr_destroy(&str); uc_dstr_destroy(&str);
}
END_TEST END_TEST
START_TEST (test_dstr_filter) START_TEST (test_dstr_filter)
{
struct DStr str; struct DStr str;
size_t rc; size_t rc;
@@ -151,9 +164,11 @@ START_TEST (test_dstr_filter)
uc_dstr_destroy(&str); uc_dstr_destroy(&str);
}
END_TEST END_TEST
START_TEST (test_dstr_sprintf) START_TEST (test_dstr_sprintf)
{
struct DStr str; struct DStr str;
size_t rc; size_t rc;
@@ -168,9 +183,11 @@ START_TEST (test_dstr_sprintf)
uc_dstr_destroy(&str); uc_dstr_destroy(&str);
}
END_TEST END_TEST
START_TEST (test_dstr_copy) START_TEST (test_dstr_copy)
{
struct DStr str; struct DStr str;
struct DStr copy; struct DStr copy;
size_t rc; size_t rc;
@@ -195,6 +212,7 @@ START_TEST (test_dstr_copy)
uc_dstr_destroy(&str); uc_dstr_destroy(&str);
uc_dstr_destroy(&copy); uc_dstr_destroy(&copy);
}
END_TEST END_TEST
Suite *dstr_suite(void) Suite *dstr_suite(void)
+6
View File
@@ -52,6 +52,7 @@ static int cmp_stuff_array(const struct Stuff *a, const struct Stuff *b, size_t
} }
START_TEST (test_heapsort_odd) START_TEST (test_heapsort_odd)
{
struct Stuff unordered[] = { struct Stuff unordered[] = {
{"2", 2}, {"2", 2},
{"1", 1}, {"1", 1},
@@ -72,9 +73,11 @@ START_TEST (test_heapsort_odd)
cmp_stuff, swap_stuff, NULL); cmp_stuff, swap_stuff, NULL);
print_stuff(unordered, ARRAY_SIZE(unordered)); print_stuff(unordered, ARRAY_SIZE(unordered));
fail_if(cmp_stuff_array(unordered, ordered, ARRAY_SIZE(unordered)) != 0); fail_if(cmp_stuff_array(unordered, ordered, ARRAY_SIZE(unordered)) != 0);
}
END_TEST END_TEST
START_TEST (test_heapsort_even) START_TEST (test_heapsort_even)
{
struct Stuff unordered[] = { struct Stuff unordered[] = {
{"1", 1}, {"1", 1},
{"7", 7}, {"7", 7},
@@ -96,9 +99,11 @@ START_TEST (test_heapsort_even)
uc_heapsort(unordered, ARRAY_SIZE(unordered), sizeof(struct Stuff), uc_heapsort(unordered, ARRAY_SIZE(unordered), sizeof(struct Stuff),
cmp_stuff, swap_stuff, NULL); cmp_stuff, swap_stuff, NULL);
fail_if(cmp_stuff_array(unordered, ordered, ARRAY_SIZE(unordered)) != 0); fail_if(cmp_stuff_array(unordered, ordered, ARRAY_SIZE(unordered)) != 0);
}
END_TEST END_TEST
START_TEST (test_heapsort_zero_one) START_TEST (test_heapsort_zero_one)
{
struct Stuff unordered[] = { struct Stuff unordered[] = {
{"1", 1}, {"1", 1},
{"7", 7}, {"7", 7},
@@ -128,6 +133,7 @@ START_TEST (test_heapsort_zero_one)
uc_heapsort(unordered, 1, sizeof(struct Stuff), uc_heapsort(unordered, 1, sizeof(struct Stuff),
cmp_stuff, swap_stuff, NULL); cmp_stuff, swap_stuff, NULL);
fail_if(cmp_stuff_array(unordered, same, ARRAY_SIZE(unordered)) != 0); fail_if(cmp_stuff_array(unordered, same, ARRAY_SIZE(unordered)) != 0);
}
END_TEST END_TEST
Suite *heapsort_suite(void) Suite *heapsort_suite(void)
+34
View File
@@ -4,6 +4,7 @@
START_TEST (test_uc_hex_encode_1) START_TEST (test_uc_hex_encode_1)
{
uint8_t binary[] = {0xff}; uint8_t binary[] = {0xff};
char hex[3] = ""; char hex[3] = "";
@@ -11,9 +12,11 @@ START_TEST (test_uc_hex_encode_1)
fail_if(strcmp(hex,"FF") != 0); fail_if(strcmp(hex,"FF") != 0);
}
END_TEST END_TEST
START_TEST (test_uc_hex_encode_2) START_TEST (test_uc_hex_encode_2)
{
uint8_t binary[] = {127, 128, 129}; uint8_t binary[] = {127, 128, 129};
char hex[sizeof binary * 2 + 1] = ""; char hex[sizeof binary * 2 + 1] = "";
@@ -21,9 +24,11 @@ START_TEST (test_uc_hex_encode_2)
fail_if(strcmp(hex,"7F8081") != 0, "was %s", hex); fail_if(strcmp(hex,"7F8081") != 0, "was %s", hex);
}
END_TEST END_TEST
START_TEST (test_uc_hex_encode_3) START_TEST (test_uc_hex_encode_3)
{
uint8_t binary[] = {0, 1, 9, 11}; uint8_t binary[] = {0, 1, 9, 11};
char hex[sizeof binary * 2 + 1] = ""; char hex[sizeof binary * 2 + 1] = "";
@@ -31,9 +36,11 @@ START_TEST (test_uc_hex_encode_3)
fail_if(strcmp(hex,"0001090B") != 0, "was %s", hex); fail_if(strcmp(hex,"0001090B") != 0, "was %s", hex);
}
END_TEST END_TEST
START_TEST (test_uc_hex_encode_zero_len) START_TEST (test_uc_hex_encode_zero_len)
{
uint8_t binary[1] = {0xff}; uint8_t binary[1] = {0xff};
char hex[3] = "aa"; char hex[3] = "aa";
@@ -42,9 +49,11 @@ START_TEST (test_uc_hex_encode_zero_len)
fail_if(hex[0] != 0); fail_if(hex[0] != 0);
fail_if(hex[1] != 'a'); fail_if(hex[1] != 'a');
}
END_TEST END_TEST
START_TEST (test_uc_hex_decode_1) START_TEST (test_uc_hex_decode_1)
{
char hex[] = "1F"; char hex[] = "1F";
uint8_t binary[2] = {0x11,0x22}; uint8_t binary[2] = {0x11,0x22};
uint8_t *res; uint8_t *res;
@@ -55,9 +64,11 @@ START_TEST (test_uc_hex_decode_1)
fail_if(binary[1] != 0x22); fail_if(binary[1] != 0x22);
fail_if(res != binary + 1, "binary %p, res %p", &binary[0], res); fail_if(res != binary + 1, "binary %p, res %p", &binary[0], res);
}
END_TEST END_TEST
START_TEST (test_uc_hex_decode_2) START_TEST (test_uc_hex_decode_2)
{
char hex[] = "00FF80"; char hex[] = "00FF80";
uint8_t binary[4] = {0x11, 0x11, 0x11}; uint8_t binary[4] = {0x11, 0x11, 0x11};
uint8_t *res; uint8_t *res;
@@ -69,9 +80,11 @@ START_TEST (test_uc_hex_decode_2)
fail_if(binary[2] != 0x80); fail_if(binary[2] != 0x80);
fail_if(res != binary + 3, "binary %p, res %p", &binary[0], res); fail_if(res != binary + 3, "binary %p, res %p", &binary[0], res);
}
END_TEST END_TEST
START_TEST (test_uc_hex_decode_zero_length) START_TEST (test_uc_hex_decode_zero_length)
{
char hex[] = "00FF80"; char hex[] = "00FF80";
uint8_t binary[4] = {0x11, 0x11, 0x11}; uint8_t binary[4] = {0x11, 0x11, 0x11};
uint8_t *res; uint8_t *res;
@@ -83,9 +96,11 @@ START_TEST (test_uc_hex_decode_zero_length)
fail_if(binary[2] != 0x11); fail_if(binary[2] != 0x11);
fail_if(res != binary); fail_if(res != binary);
}
END_TEST END_TEST
START_TEST (test_uc_hex_decode_empty_string) START_TEST (test_uc_hex_decode_empty_string)
{
char hex[] = ""; char hex[] = "";
uint8_t binary[] = {0x11, 0x11, 0x11}; uint8_t binary[] = {0x11, 0x11, 0x11};
uint8_t *res; uint8_t *res;
@@ -97,8 +112,10 @@ START_TEST (test_uc_hex_decode_empty_string)
fail_if(binary[2] != 0x11); fail_if(binary[2] != 0x11);
fail_if(res != binary, "length %zu\n", res - binary); fail_if(res != binary, "length %zu\n", res - binary);
}
END_TEST END_TEST
START_TEST (test_uc_hex_decode_spaces) START_TEST (test_uc_hex_decode_spaces)
{
char hex[] = " 11 1213"; char hex[] = " 11 1213";
uint8_t binary[3]; uint8_t binary[3];
uint8_t *res; uint8_t *res;
@@ -110,9 +127,11 @@ START_TEST (test_uc_hex_decode_spaces)
fail_if(binary[2] != 0x13); fail_if(binary[2] != 0x13);
fail_if(res != binary+3, "length %zu\n", res - binary); fail_if(res != binary+3, "length %zu\n", res - binary);
}
END_TEST END_TEST
START_TEST (test_uc_hex_decode_spaces2) START_TEST (test_uc_hex_decode_spaces2)
{
char hex[] = "1112 13\r\n"; char hex[] = "1112 13\r\n";
uint8_t binary[3]; uint8_t binary[3];
uint8_t *res; uint8_t *res;
@@ -124,9 +143,11 @@ START_TEST (test_uc_hex_decode_spaces2)
fail_if(binary[2] != 0x13); fail_if(binary[2] != 0x13);
fail_if(res != binary+3, "length %zu\n", res - binary); fail_if(res != binary+3, "length %zu\n", res - binary);
}
END_TEST END_TEST
START_TEST (test_uc_hex_decode_spaces_empty) START_TEST (test_uc_hex_decode_spaces_empty)
{
char hex[] = " \r\n "; char hex[] = " \r\n ";
uint8_t binary[] = {0x11,0x12}; uint8_t binary[] = {0x11,0x12};
uint8_t *res; uint8_t *res;
@@ -137,9 +158,11 @@ START_TEST (test_uc_hex_decode_spaces_empty)
fail_if(binary[1] != 0x12); fail_if(binary[1] != 0x12);
fail_if(res != binary, "length %zu\n", res - binary); fail_if(res != binary, "length %zu\n", res - binary);
}
END_TEST END_TEST
START_TEST (test_uc_hex_decode_odd_length) START_TEST (test_uc_hex_decode_odd_length)
{
char hex[] = "33FF80"; char hex[] = "33FF80";
uint8_t binary[4] = {0x11, 0x11, 0x11}; uint8_t binary[4] = {0x11, 0x11, 0x11};
uint8_t *res; uint8_t *res;
@@ -151,9 +174,11 @@ START_TEST (test_uc_hex_decode_odd_length)
fail_if(binary[2] != 0x11); fail_if(binary[2] != 0x11);
fail_if(res != &binary[1]); fail_if(res != &binary[1]);
}
END_TEST END_TEST
START_TEST (test_uc_hex_decode_invalid) START_TEST (test_uc_hex_decode_invalid)
{
char hex[] = "TEST "; char hex[] = "TEST ";
uint8_t binary[4] = {0x11, 0x11, 0x11}; uint8_t binary[4] = {0x11, 0x11, 0x11};
uint8_t *res; uint8_t *res;
@@ -165,9 +190,11 @@ START_TEST (test_uc_hex_decode_invalid)
fail_if(binary[2] != 0x11); fail_if(binary[2] != 0x11);
fail_if(res != NULL); fail_if(res != NULL);
}
END_TEST END_TEST
START_TEST (test_uc_hex_encode_delim_1) START_TEST (test_uc_hex_encode_delim_1)
{
uint8_t binary[4] = {0xFF, 0x00, 0x7F, 0x0A}; uint8_t binary[4] = {0xFF, 0x00, 0x7F, 0x0A};
char hex[17] = ""; char hex[17] = "";
char *res; char *res;
@@ -178,9 +205,11 @@ START_TEST (test_uc_hex_encode_delim_1)
*res = 0; *res = 0;
fail_if(res != hex + 12); fail_if(res != hex + 12);
}
END_TEST END_TEST
START_TEST (test_uc_hex_encode_delim_2) START_TEST (test_uc_hex_encode_delim_2)
{
uint8_t binary[] = {0xFF, 0x00}; uint8_t binary[] = {0xFF, 0x00};
char hex[8] = ""; char hex[8] = "";
char *res; char *res;
@@ -190,9 +219,11 @@ START_TEST (test_uc_hex_encode_delim_2)
fail_if(strcmp(hex, "FF \n00 ") != 0, "hex was '%s'", hex); fail_if(strcmp(hex, "FF \n00 ") != 0, "hex was '%s'", hex);
fail_if(res != hex + 7, "sz was %zu", res - hex); fail_if(res != hex + 7, "sz was %zu", res - hex);
}
END_TEST END_TEST
START_TEST (test_uc_hex_encode_delim_zero_len) START_TEST (test_uc_hex_encode_delim_zero_len)
{
uint8_t binary[] = {0xFF, 0x00}; uint8_t binary[] = {0xFF, 0x00};
char hex[8] = "......"; char hex[8] = "......";
char *res; char *res;
@@ -202,10 +233,12 @@ START_TEST (test_uc_hex_encode_delim_zero_len)
fail_if(strcmp(hex, "") != 0, "hex was '%s'", hex); fail_if(strcmp(hex, "") != 0, "hex was '%s'", hex);
fail_if(res != hex); fail_if(res != hex);
}
END_TEST END_TEST
START_TEST (test_uc_hex_decode_lowercase) START_TEST (test_uc_hex_decode_lowercase)
{
char hex[] = "1f"; char hex[] = "1f";
uint8_t binary[2] = {0x11,0x22}; uint8_t binary[2] = {0x11,0x22};
uint8_t *res; uint8_t *res;
@@ -216,6 +249,7 @@ START_TEST (test_uc_hex_decode_lowercase)
fail_if(binary[1] != 0x22); fail_if(binary[1] != 0x22);
fail_if(res != binary + 1, "binary %p, res %p", &binary[0], res); fail_if(res != binary + 1, "binary %p, res %p", &binary[0], res);
}
END_TEST END_TEST
Suite *hex_suite(void) Suite *hex_suite(void)
{ {
+20
View File
@@ -40,6 +40,7 @@ struct MyString *my_find(struct UHTable *table, const char *str, size_t hash)
START_TEST (test_htable1) START_TEST (test_htable1)
{
struct MyString str[5] = { struct MyString str[5] = {
{"One", {0,NULL}}, {"One", {0,NULL}},
{"Two", {0,NULL}}, {"Two", {0,NULL}},
@@ -67,9 +68,11 @@ START_TEST (test_htable1)
uc_htable_destroy(&table); uc_htable_destroy(&table);
}
END_TEST END_TEST
START_TEST (test_htable_hash_collision) START_TEST (test_htable_hash_collision)
{
//same as test1 but with a bad hash to force equal hash //same as test1 but with a bad hash to force equal hash
struct MyString str[5] = { struct MyString str[5] = {
{"...", {0,NULL}}, {"...", {0,NULL}},
@@ -97,9 +100,11 @@ START_TEST (test_htable_hash_collision)
uc_htable_destroy(&table); uc_htable_destroy(&table);
}
END_TEST END_TEST
START_TEST (test_htable_resize) START_TEST (test_htable_resize)
{
struct MyString str[5] = { struct MyString str[5] = {
{"One", {0,NULL}}, {"One", {0,NULL}},
{"Two", {0,NULL}}, {"Two", {0,NULL}},
@@ -132,9 +137,11 @@ START_TEST (test_htable_resize)
uc_htable_destroy(&table); uc_htable_destroy(&table);
}
END_TEST END_TEST
START_TEST (test_htable_fail_init_resize) START_TEST (test_htable_fail_init_resize)
{
int rc; int rc;
struct UHTable table; struct UHTable table;
rc = uc_htable_init(&table, 0); rc = uc_htable_init(&table, 0);
@@ -148,9 +155,11 @@ START_TEST (test_htable_fail_init_resize)
uc_htable_destroy(&table); uc_htable_destroy(&table);
}
END_TEST END_TEST
START_TEST (test_htable_has_node) START_TEST (test_htable_has_node)
{
struct MyString str1 = {"One", {0,NULL}}; struct MyString str1 = {"One", {0,NULL}};
struct MyString str2 = {"Two", {0,NULL}}; struct MyString str2 = {"Two", {0,NULL}};
@@ -171,9 +180,11 @@ START_TEST (test_htable_has_node)
uc_htable_destroy(&table); uc_htable_destroy(&table);
}
END_TEST END_TEST
START_TEST (test_htable_remove) START_TEST (test_htable_remove)
{
struct MyString str1 = {"One", {0,NULL}}; struct MyString str1 = {"One", {0,NULL}};
struct MyString str2 = {"One", {0,NULL}}; struct MyString str2 = {"One", {0,NULL}};
struct MyString str3 = {"Other", {0,NULL}}; struct MyString str3 = {"Other", {0,NULL}};
@@ -216,9 +227,11 @@ START_TEST (test_htable_remove)
uc_htable_destroy(&table); uc_htable_destroy(&table);
}
END_TEST END_TEST
START_TEST (test_htable_remove_foreach) START_TEST (test_htable_remove_foreach)
{
struct MyString str1 = {"One", {0,NULL}}; struct MyString str1 = {"One", {0,NULL}};
struct MyString str2 = {"One", {0,NULL}}; struct MyString str2 = {"One", {0,NULL}};
struct MyString str3 = {"Other", {0,NULL}}; struct MyString str3 = {"Other", {0,NULL}};
@@ -254,9 +267,11 @@ START_TEST (test_htable_remove_foreach)
uc_htable_destroy(&table); uc_htable_destroy(&table);
}
END_TEST END_TEST
START_TEST (test_htable_clear) START_TEST (test_htable_clear)
{
struct MyString str1 = {"One", {0,NULL}}; struct MyString str1 = {"One", {0,NULL}};
struct UHTable table; struct UHTable table;
@@ -276,9 +291,11 @@ START_TEST (test_htable_clear)
uc_htable_destroy(&table); uc_htable_destroy(&table);
}
END_TEST END_TEST
START_TEST (test_htable_foreach) START_TEST (test_htable_foreach)
{
struct MyString str1 = {"One", {0,NULL}}; struct MyString str1 = {"One", {0,NULL}};
struct MyString str2 = {"One", {0,NULL}}; struct MyString str2 = {"One", {0,NULL}};
struct MyString str3 = {"Other",{0,NULL}}; struct MyString str3 = {"Other",{0,NULL}};
@@ -318,9 +335,11 @@ START_TEST (test_htable_foreach)
uc_htable_destroy(&table); uc_htable_destroy(&table);
}
END_TEST END_TEST
START_TEST (test_htable_foreach_safe) START_TEST (test_htable_foreach_safe)
{
struct MyString str1 = {"One", {0,NULL}}; struct MyString str1 = {"One", {0,NULL}};
struct MyString str2 = {"One", {0,NULL}}; struct MyString str2 = {"One", {0,NULL}};
struct MyString str3 = {"Other",{0,NULL}}; struct MyString str3 = {"Other",{0,NULL}};
@@ -353,6 +372,7 @@ START_TEST (test_htable_foreach_safe)
uc_htable_destroy(&table); uc_htable_destroy(&table);
}
END_TEST END_TEST
Suite *htable_suite(void) Suite *htable_suite(void)
+14
View File
@@ -3,6 +3,7 @@
START_TEST (test_human_bytesz_bytes) START_TEST (test_human_bytesz_bytes)
{
char result[128]; char result[128];
char *rc; char *rc;
@@ -13,9 +14,11 @@ START_TEST (test_human_bytesz_bytes)
rc = uc_human_bytesz_bin(999, result, sizeof result); rc = uc_human_bytesz_bin(999, result, sizeof result);
fail_if(rc == NULL); fail_if(rc == NULL);
ck_assert_str_eq(result, "999 b"); ck_assert_str_eq(result, "999 b");
}
END_TEST END_TEST
START_TEST (test_human_bytesz_bytes_0) START_TEST (test_human_bytesz_bytes_0)
{
char result[128]; char result[128];
char *rc; char *rc;
@@ -26,9 +29,11 @@ START_TEST (test_human_bytesz_bytes_0)
rc = uc_human_bytesz_bin(0, result, sizeof result); rc = uc_human_bytesz_bin(0, result, sizeof result);
fail_if(rc == NULL); fail_if(rc == NULL);
ck_assert_str_eq(result, "0 b"); ck_assert_str_eq(result, "0 b");
}
END_TEST END_TEST
START_TEST (test_human_bytesz_kilobytes) START_TEST (test_human_bytesz_kilobytes)
{
char result[128]; char result[128];
char *rc; char *rc;
@@ -39,9 +44,11 @@ START_TEST (test_human_bytesz_kilobytes)
rc = uc_human_bytesz_bin(64000, result, sizeof result); rc = uc_human_bytesz_bin(64000, result, sizeof result);
fail_if(rc == NULL); fail_if(rc == NULL);
ck_assert_str_eq(result, "62.50 KiB"); ck_assert_str_eq(result, "62.50 KiB");
}
END_TEST END_TEST
START_TEST (test_human_bytesz_megabytes) START_TEST (test_human_bytesz_megabytes)
{
char result[128]; char result[128];
char *rc; char *rc;
@@ -52,9 +59,11 @@ START_TEST (test_human_bytesz_megabytes)
rc = uc_human_bytesz_bin(6409000, result, sizeof result); rc = uc_human_bytesz_bin(6409000, result, sizeof result);
fail_if(rc == NULL); fail_if(rc == NULL);
ck_assert_str_eq(result, "6.11 MiB"); ck_assert_str_eq(result, "6.11 MiB");
}
END_TEST END_TEST
START_TEST (test_human_bytesz_gigabytes) START_TEST (test_human_bytesz_gigabytes)
{
char result[128]; char result[128];
char *rc; char *rc;
@@ -65,9 +74,11 @@ START_TEST (test_human_bytesz_gigabytes)
rc = uc_human_bytesz_bin(126999400000, result, sizeof result); rc = uc_human_bytesz_bin(126999400000, result, sizeof result);
fail_if(rc == NULL); fail_if(rc == NULL);
ck_assert_str_eq(result, "118.28 GiB"); ck_assert_str_eq(result, "118.28 GiB");
}
END_TEST END_TEST
START_TEST (test_human_bytesz_terrabytes) START_TEST (test_human_bytesz_terrabytes)
{
char result[128]; char result[128];
char *rc; char *rc;
@@ -78,9 +89,11 @@ START_TEST (test_human_bytesz_terrabytes)
rc = uc_human_bytesz_bin(12453400030000, result, sizeof result); rc = uc_human_bytesz_bin(12453400030000, result, sizeof result);
fail_if(rc == NULL); fail_if(rc == NULL);
ck_assert_str_eq(result, "11.33 TiB"); ck_assert_str_eq(result, "11.33 TiB");
}
END_TEST END_TEST
START_TEST (test_human_bytesz_petabytes) START_TEST (test_human_bytesz_petabytes)
{
char result[128]; char result[128];
char *rc; char *rc;
@@ -91,6 +104,7 @@ START_TEST (test_human_bytesz_petabytes)
rc = uc_human_bytesz_bin(~0ULL, result, sizeof result); rc = uc_human_bytesz_bin(~0ULL, result, sizeof result);
fail_if(rc == NULL); fail_if(rc == NULL);
ck_assert_str_eq(result, "16384.00 PiB"); ck_assert_str_eq(result, "16384.00 PiB");
}
END_TEST END_TEST
+2
View File
@@ -67,6 +67,7 @@ static void simple_wcb(struct IOMux *mux, struct IOMuxFD *fd, unsigned int event
START_TEST (test_iomux_pipe_simple) START_TEST (test_iomux_pipe_simple)
{
struct IOMux *mux; struct IOMux *mux;
struct IOMuxFD rfd; struct IOMuxFD rfd;
struct IOMuxFD wfd; struct IOMuxFD wfd;
@@ -106,6 +107,7 @@ START_TEST (test_iomux_pipe_simple)
iomux_delete(mux); iomux_delete(mux);
}
END_TEST END_TEST
+2
View File
@@ -46,6 +46,7 @@ static void usr2_handler(struct IOMux *mux, int signo, void *cookie)
} }
START_TEST (test_iomux_signal_simple) START_TEST (test_iomux_signal_simple)
{
struct IOMux *mux = iomux_create(g_iomux_type); struct IOMux *mux = iomux_create(g_iomux_type);
@@ -87,6 +88,7 @@ START_TEST (test_iomux_signal_simple)
ck_assert_int_eq(g_usr1_seen, 1); ck_assert_int_eq(g_usr1_seen, 1);
ck_assert_int_eq(g_usr2_seen, 1); ck_assert_int_eq(g_usr2_seen, 1);
}
END_TEST END_TEST
+28
View File
@@ -31,6 +31,7 @@ static void logging_rm_subdir(void)
} }
START_TEST (test_logfile_location) START_TEST (test_logfile_location)
{
struct UCLogModule m = { struct UCLogModule m = {
.id = 0, .id = 0,
@@ -62,9 +63,11 @@ START_TEST (test_logfile_location)
rc = stat(FILE_NAME, &st); rc = stat(FILE_NAME, &st);
fail_if(rc != 0, "stat failed: %s", strerror(errno)); fail_if(rc != 0, "stat failed: %s", strerror(errno));
fail_if(st.st_size != 380, "was %ld", (long)st.st_size); fail_if(st.st_size != 380, "was %ld", (long)st.st_size);
}
END_TEST END_TEST
START_TEST (test_logfile_delete_destination) START_TEST (test_logfile_delete_destination)
{
struct UCLogModule m = { struct UCLogModule m = {
.id = 0, .id = 0,
@@ -110,9 +113,11 @@ START_TEST (test_logfile_delete_destination)
fail_if(rc != 0, "stat failed: %s", strerror(errno)); fail_if(rc != 0, "stat failed: %s", strerror(errno));
fail_if(st.st_size != 380, "was %ld", (long)st.st_size); fail_if(st.st_size != 380, "was %ld", (long)st.st_size);
}
END_TEST END_TEST
START_TEST (test_logfile_no_location) START_TEST (test_logfile_no_location)
{
struct UCLogModule m = { struct UCLogModule m = {
.id = 0, .id = 0,
@@ -140,9 +145,11 @@ START_TEST (test_logfile_no_location)
rc = stat(FILE_NAME, &st); rc = stat(FILE_NAME, &st);
fail_if(rc != 0, "stat failed: %s", strerror(errno)); fail_if(rc != 0, "stat failed: %s", strerror(errno));
fail_if(st.st_size != 52*2, "was %ld", (long)st.st_size); fail_if(st.st_size != 52*2, "was %ld", (long)st.st_size);
}
END_TEST END_TEST
START_TEST (test_logfile_loglevel_surpressed_dest) START_TEST (test_logfile_loglevel_surpressed_dest)
{
struct UCLogModule m = { struct UCLogModule m = {
.id = 0, .id = 0,
@@ -172,9 +179,11 @@ START_TEST (test_logfile_loglevel_surpressed_dest)
fail_if(rc != 0, "stat failed: %s", strerror(errno)); fail_if(rc != 0, "stat failed: %s", strerror(errno));
fail_if(st.st_size != 0, "was %ld", (long)st.st_size); fail_if(st.st_size != 0, "was %ld", (long)st.st_size);
}
END_TEST END_TEST
START_TEST (test_logfile_loglevel_surpressed_module) START_TEST (test_logfile_loglevel_surpressed_module)
{
struct UCLogModule m = { struct UCLogModule m = {
.id = 0, .id = 0,
@@ -204,9 +213,11 @@ START_TEST (test_logfile_loglevel_surpressed_module)
fail_if(rc != 0, "stat failed: %s", strerror(errno)); fail_if(rc != 0, "stat failed: %s", strerror(errno));
fail_if(st.st_size != 0, "was %ld", (long)st.st_size); fail_if(st.st_size != 0, "was %ld", (long)st.st_size);
}
END_TEST END_TEST
START_TEST (test_logfile_reopen_files) START_TEST (test_logfile_reopen_files)
{
struct UCLogModule m = { struct UCLogModule m = {
.id = 0, .id = 0,
@@ -247,9 +258,11 @@ START_TEST (test_logfile_reopen_files)
fail_if(rc != 0, "2. stat failed: %s", strerror(errno)); fail_if(rc != 0, "2. stat failed: %s", strerror(errno));
fail_if(st.st_size != 77, "was %ld", (long)st.st_size);//should only one line there now fail_if(st.st_size != 77, "was %ld", (long)st.st_size);//should only one line there now
}
END_TEST END_TEST
START_TEST (test_logfile_remove_dest) START_TEST (test_logfile_remove_dest)
{
struct UCLogModule m = { struct UCLogModule m = {
.id = 0, .id = 0,
@@ -301,9 +314,11 @@ START_TEST (test_logfile_remove_dest)
fail_if(rc != 0, "2. stat failed: %s", strerror(errno)); fail_if(rc != 0, "2. stat failed: %s", strerror(errno));
fail_if(st.st_size != 77*2, "was %ld", (long)st.st_size);//should be same size fail_if(st.st_size != 77*2, "was %ld", (long)st.st_size);//should be same size
}
END_TEST END_TEST
START_TEST (test_logfile_full_filesystem) START_TEST (test_logfile_full_filesystem)
{
//logging to a full filesystem shouldn't crash //logging to a full filesystem shouldn't crash
struct UCLogModule m = { struct UCLogModule m = {
.id = 0, .id = 0,
@@ -331,9 +346,11 @@ START_TEST (test_logfile_full_filesystem)
UC_LOGF(UC_LL_INFO, 0, "Lorum ipson %d", 1); UC_LOGF(UC_LL_INFO, 0, "Lorum ipson %d", 1);
} }
}
END_TEST END_TEST
START_TEST (test_logfile_invalid_file) START_TEST (test_logfile_invalid_file)
{
//check behavior when a log file cannot be opened //check behavior when a log file cannot be opened
struct UCLogModule m = { struct UCLogModule m = {
.id = 0, .id = 0,
@@ -352,9 +369,11 @@ START_TEST (test_logfile_invalid_file)
dest = uc_log_new_file("PATH/to/nonexisting.log", UC_LL_DEBUG, 1); dest = uc_log_new_file("PATH/to/nonexisting.log", UC_LL_DEBUG, 1);
fail_if(dest != NULL); fail_if(dest != NULL);
}
END_TEST END_TEST
START_TEST (test_logfile_invalid_file_after_reopen) START_TEST (test_logfile_invalid_file_after_reopen)
{
//check behavior when a log file cannot be re-opened //check behavior when a log file cannot be re-opened
struct UCLogModule m = { struct UCLogModule m = {
.id = 0, .id = 0,
@@ -391,9 +410,11 @@ START_TEST (test_logfile_invalid_file_after_reopen)
UC_LOGF(UC_LL_WARNING, 0, "Lorum ipson %d", 1); UC_LOGF(UC_LL_WARNING, 0, "Lorum ipson %d", 1);
UC_LOGF(UC_LL_INFO, 0, "Lorum ipson %d", 1); UC_LOGF(UC_LL_INFO, 0, "Lorum ipson %d", 1);
}
END_TEST END_TEST
START_TEST (test_logfile_raw) START_TEST (test_logfile_raw)
{
struct UCLogModule m = { struct UCLogModule m = {
.id = 0, .id = 0,
@@ -421,9 +442,11 @@ START_TEST (test_logfile_raw)
rc = stat(FILE_NAME, &st); rc = stat(FILE_NAME, &st);
fail_if(rc != 0, "stat failed: %s", strerror(errno)); fail_if(rc != 0, "stat failed: %s", strerror(errno));
fail_if(st.st_size != 14*2, "was %ld", (long)st.st_size); fail_if(st.st_size != 14*2, "was %ld", (long)st.st_size);
}
END_TEST END_TEST
START_TEST (test_logfile_dest_mask) START_TEST (test_logfile_dest_mask)
{
struct UCLogModule m[] = { struct UCLogModule m[] = {
{ {
@@ -467,9 +490,11 @@ START_TEST (test_logfile_dest_mask)
rc = stat(FILE_NAME, &st); rc = stat(FILE_NAME, &st);
fail_if(rc != 0, "stat failed: %s", strerror(errno)); fail_if(rc != 0, "stat failed: %s", strerror(errno));
fail_if(st.st_size != 14*2, "was %ld", (long)st.st_size); fail_if(st.st_size != 14*2, "was %ld", (long)st.st_size);
}
END_TEST END_TEST
START_TEST (test_loglevel_module_none) START_TEST (test_loglevel_module_none)
{
struct UCLogModule m = { struct UCLogModule m = {
.id = 0, .id = 0,
@@ -496,9 +521,11 @@ START_TEST (test_loglevel_module_none)
rc = stat(FILE_NAME, &st); rc = stat(FILE_NAME, &st);
fail_if(rc != 0, "stat failed: %s", strerror(errno)); fail_if(rc != 0, "stat failed: %s", strerror(errno));
fail_if(st.st_size != 0, "was %ld", (long)st.st_size); fail_if(st.st_size != 0, "was %ld", (long)st.st_size);
}
END_TEST END_TEST
START_TEST (test_loglevel_dest_none) START_TEST (test_loglevel_dest_none)
{
struct UCLogModule m = { struct UCLogModule m = {
.id = 0, .id = 0,
@@ -525,6 +552,7 @@ START_TEST (test_loglevel_dest_none)
rc = stat(FILE_NAME, &st); rc = stat(FILE_NAME, &st);
fail_if(rc != 0, "stat failed: %s", strerror(errno)); fail_if(rc != 0, "stat failed: %s", strerror(errno));
fail_if(st.st_size != 0, "was %ld", (long)st.st_size); fail_if(st.st_size != 0, "was %ld", (long)st.st_size);
}
END_TEST END_TEST
+30
View File
@@ -5,6 +5,7 @@
START_TEST (test_mbuf_new) START_TEST (test_mbuf_new)
{
struct MBuf *mbuf; struct MBuf *mbuf;
mbuf = uc_mbuf_new(110); mbuf = uc_mbuf_new(110);
@@ -22,9 +23,11 @@ START_TEST (test_mbuf_new)
uc_mbuf_free(mbuf); uc_mbuf_free(mbuf);
}
END_TEST END_TEST
START_TEST (test_mbuf_new_inline) START_TEST (test_mbuf_new_inline)
{
struct MBuf *mbuf; struct MBuf *mbuf;
mbuf = uc_mbuf_new_inline(110); mbuf = uc_mbuf_new_inline(110);
@@ -44,9 +47,11 @@ START_TEST (test_mbuf_new_inline)
uc_mbuf_free(mbuf); uc_mbuf_free(mbuf);
}
END_TEST END_TEST
START_TEST (test_mbuf_new_headroom) START_TEST (test_mbuf_new_headroom)
{
struct MBuf *mbuf; struct MBuf *mbuf;
mbuf = uc_mbuf_new_hr(110,20); mbuf = uc_mbuf_new_hr(110,20);
@@ -64,9 +69,11 @@ START_TEST (test_mbuf_new_headroom)
uc_mbuf_free(mbuf); uc_mbuf_free(mbuf);
}
END_TEST END_TEST
START_TEST (test_mbuf_put) START_TEST (test_mbuf_put)
{
struct MBuf *mbuf; struct MBuf *mbuf;
uint8_t *data; uint8_t *data;
@@ -82,9 +89,11 @@ START_TEST (test_mbuf_put)
uc_mbuf_free(mbuf); uc_mbuf_free(mbuf);
}
END_TEST END_TEST
START_TEST (test_mbuf_put_fail) START_TEST (test_mbuf_put_fail)
{
struct MBuf *mbuf; struct MBuf *mbuf;
uint8_t *data; uint8_t *data;
@@ -96,9 +105,11 @@ START_TEST (test_mbuf_put_fail)
uc_mbuf_free(mbuf); uc_mbuf_free(mbuf);
}
END_TEST END_TEST
START_TEST (test_mbuf_push) START_TEST (test_mbuf_push)
{
struct MBuf *mbuf; struct MBuf *mbuf;
uint8_t *data; uint8_t *data;
@@ -114,10 +125,12 @@ START_TEST (test_mbuf_push)
uc_mbuf_free(mbuf); uc_mbuf_free(mbuf);
}
END_TEST END_TEST
START_TEST (test_mbuf_push_fail) START_TEST (test_mbuf_push_fail)
{
struct MBuf *mbuf; struct MBuf *mbuf;
uint8_t *data; uint8_t *data;
@@ -129,9 +142,11 @@ START_TEST (test_mbuf_push_fail)
uc_mbuf_free(mbuf); uc_mbuf_free(mbuf);
}
END_TEST END_TEST
START_TEST (test_mbuf_pull) START_TEST (test_mbuf_pull)
{
struct MBuf *mbuf; struct MBuf *mbuf;
uint8_t *data1; uint8_t *data1;
uint8_t *data2; uint8_t *data2;
@@ -151,9 +166,11 @@ START_TEST (test_mbuf_pull)
uc_mbuf_free(mbuf); uc_mbuf_free(mbuf);
}
END_TEST END_TEST
START_TEST (test_mbuf_pull_fail) START_TEST (test_mbuf_pull_fail)
{
struct MBuf *mbuf; struct MBuf *mbuf;
uint8_t *data1; uint8_t *data1;
uint8_t *data2; uint8_t *data2;
@@ -172,9 +189,11 @@ START_TEST (test_mbuf_pull_fail)
uc_mbuf_free(mbuf); uc_mbuf_free(mbuf);
}
END_TEST END_TEST
START_TEST (test_mbuf_copy) START_TEST (test_mbuf_copy)
{
struct MBuf *mbuf; struct MBuf *mbuf;
uint8_t *data1; uint8_t *data1;
struct MBuf *copy; struct MBuf *copy;
@@ -196,9 +215,11 @@ START_TEST (test_mbuf_copy)
uc_mbuf_free(mbuf); uc_mbuf_free(mbuf);
uc_mbuf_free(copy); uc_mbuf_free(copy);
}
END_TEST END_TEST
START_TEST (test_mbuf_zero) START_TEST (test_mbuf_zero)
{
struct MBuf *mbuf; struct MBuf *mbuf;
uint8_t *data1; uint8_t *data1;
@@ -215,9 +236,11 @@ START_TEST (test_mbuf_zero)
uc_mbuf_free(mbuf); uc_mbuf_free(mbuf);
}
END_TEST END_TEST
START_TEST (test_mbuf_static) START_TEST (test_mbuf_static)
{
uint8_t data[1024]; uint8_t data[1024];
struct MBuf mbuf; struct MBuf mbuf;
@@ -245,9 +268,11 @@ START_TEST (test_mbuf_static)
uc_mbuf_free(&mbuf); uc_mbuf_free(&mbuf);
}
END_TEST END_TEST
START_TEST (test_mbuf_extend_tailroom) START_TEST (test_mbuf_extend_tailroom)
{
struct MBuf *mbuf; struct MBuf *mbuf;
uint8_t *data; uint8_t *data;
void *filler; void *filler;
@@ -281,9 +306,11 @@ START_TEST (test_mbuf_extend_tailroom)
uc_mbuf_free(mbuf); uc_mbuf_free(mbuf);
free(filler); free(filler);
}
END_TEST END_TEST
START_TEST (test_mbuf_extend_tailroom_wrong_type) START_TEST (test_mbuf_extend_tailroom_wrong_type)
{
struct MBuf *mbuf; struct MBuf *mbuf;
int rc; int rc;
@@ -295,9 +322,11 @@ START_TEST (test_mbuf_extend_tailroom_wrong_type)
uc_mbuf_free(mbuf); uc_mbuf_free(mbuf);
}
END_TEST END_TEST
START_TEST (test_mbuf_queue) START_TEST (test_mbuf_queue)
{
struct MBuf *m1; struct MBuf *m1;
struct MBuf *m2; struct MBuf *m2;
struct MBuf *q; struct MBuf *q;
@@ -337,6 +366,7 @@ START_TEST (test_mbuf_queue)
uc_mbuf_free(m1); uc_mbuf_free(m1);
uc_mbuf_free(m2); uc_mbuf_free(m2);
}
END_TEST END_TEST
Suite *mbuf_suite(void) Suite *mbuf_suite(void)
+64
View File
@@ -3,6 +3,7 @@
START_TEST (test_pack16_le_1) START_TEST (test_pack16_le_1)
{
uint16_t v = 0x1234; uint16_t v = 0x1234;
uint8_t r[2]; uint8_t r[2];
@@ -10,9 +11,11 @@ START_TEST (test_pack16_le_1)
fail_if(r[0] != 0x34,"was 0x%x",r[0]); fail_if(r[0] != 0x34,"was 0x%x",r[0]);
fail_if(r[1] != 0x12,"was 0x%x",r[1]); fail_if(r[1] != 0x12,"was 0x%x",r[1]);
}
END_TEST END_TEST
START_TEST (test_pack16_le_2) START_TEST (test_pack16_le_2)
{
uint16_t v = 0xFEEF; uint16_t v = 0xFEEF;
uint8_t r[2]; uint8_t r[2];
@@ -20,9 +23,11 @@ START_TEST (test_pack16_le_2)
fail_if(r[0] != 0xEF,"was 0x%x",r[0]); fail_if(r[0] != 0xEF,"was 0x%x",r[0]);
fail_if(r[1] != 0xFE,"was 0x%x",r[1]); fail_if(r[1] != 0xFE,"was 0x%x",r[1]);
}
END_TEST END_TEST
START_TEST (test_pack16_be_1) START_TEST (test_pack16_be_1)
{
uint16_t v = 0x1234; uint16_t v = 0x1234;
uint8_t r[2]; uint8_t r[2];
@@ -30,9 +35,11 @@ START_TEST (test_pack16_be_1)
fail_if(r[0] != 0x12,"was 0x%x",r[0]); fail_if(r[0] != 0x12,"was 0x%x",r[0]);
fail_if(r[1] != 0x34,"was 0x%x",r[1]); fail_if(r[1] != 0x34,"was 0x%x",r[1]);
}
END_TEST END_TEST
START_TEST (test_pack16_be_2) START_TEST (test_pack16_be_2)
{
uint16_t v = 0xFEEF; uint16_t v = 0xFEEF;
uint8_t r[2]; uint8_t r[2];
@@ -40,45 +47,55 @@ START_TEST (test_pack16_be_2)
fail_if(r[0] != 0xFE,"was 0x%x",r[0]); fail_if(r[0] != 0xFE,"was 0x%x",r[0]);
fail_if(r[1] != 0xEF,"was 0x%x",r[1]); fail_if(r[1] != 0xEF,"was 0x%x",r[1]);
}
END_TEST END_TEST
START_TEST (test_unpack16_le_1) START_TEST (test_unpack16_le_1)
{
uint16_t v; uint16_t v;
uint8_t r[2] = {0x12, 0x34}; uint8_t r[2] = {0x12, 0x34};
v = uc_unpack_16_le(r); v = uc_unpack_16_le(r);
fail_if(v != 0x3412,"was 0x%x",v); fail_if(v != 0x3412,"was 0x%x",v);
}
END_TEST END_TEST
START_TEST (test_unpack16_le_2) START_TEST (test_unpack16_le_2)
{
uint16_t v; uint16_t v;
uint8_t r[2] = {0xFE, 0xEF}; uint8_t r[2] = {0xFE, 0xEF};
v = uc_unpack_16_le(r); v = uc_unpack_16_le(r);
fail_if(v != 0xEFFE,"was 0x%x",v); fail_if(v != 0xEFFE,"was 0x%x",v);
}
END_TEST END_TEST
START_TEST (test_unpack16_be_1) START_TEST (test_unpack16_be_1)
{
uint16_t v; uint16_t v;
uint8_t r[2] = {0x12, 0x34}; uint8_t r[2] = {0x12, 0x34};
v = uc_unpack_16_be(r); v = uc_unpack_16_be(r);
fail_if(v != 0x1234,"was 0x%x",v); fail_if(v != 0x1234,"was 0x%x",v);
}
END_TEST END_TEST
START_TEST (test_unpack16_be_2) START_TEST (test_unpack16_be_2)
{
uint16_t v; uint16_t v;
uint8_t r[2] = {0xFE, 0xEF}; uint8_t r[2] = {0xFE, 0xEF};
v = uc_unpack_16_be(r); v = uc_unpack_16_be(r);
fail_if(v != 0xFEEF,"was 0x%x",v); fail_if(v != 0xFEEF,"was 0x%x",v);
}
END_TEST END_TEST
START_TEST (test_pack24_le_1) START_TEST (test_pack24_le_1)
{
uint32_t v = 0x123456; uint32_t v = 0x123456;
uint8_t r[3]; uint8_t r[3];
@@ -87,9 +104,11 @@ START_TEST (test_pack24_le_1)
fail_if(r[0] != 0x56,"was 0x%x",r[0]); fail_if(r[0] != 0x56,"was 0x%x",r[0]);
fail_if(r[1] != 0x34,"was 0x%x",r[1]); fail_if(r[1] != 0x34,"was 0x%x",r[1]);
fail_if(r[2] != 0x12,"was 0x%x",r[2]); fail_if(r[2] != 0x12,"was 0x%x",r[2]);
}
END_TEST END_TEST
START_TEST (test_pack24_le_2) START_TEST (test_pack24_le_2)
{
uint32_t v = 0xF8F7F6; uint32_t v = 0xF8F7F6;
uint8_t r[3]; uint8_t r[3];
@@ -98,9 +117,11 @@ START_TEST (test_pack24_le_2)
fail_if(r[0] != 0xF6,"was 0x%x",r[0]); fail_if(r[0] != 0xF6,"was 0x%x",r[0]);
fail_if(r[1] != 0xF7,"was 0x%x",r[1]); fail_if(r[1] != 0xF7,"was 0x%x",r[1]);
fail_if(r[2] != 0xF8,"was 0x%x",r[2]); fail_if(r[2] != 0xF8,"was 0x%x",r[2]);
}
END_TEST END_TEST
START_TEST (test_pack24_be_1) START_TEST (test_pack24_be_1)
{
uint32_t v = 0x123456; uint32_t v = 0x123456;
uint8_t r[3]; uint8_t r[3];
@@ -109,9 +130,11 @@ START_TEST (test_pack24_be_1)
fail_if(r[0] != 0x12,"was 0x%x",r[0]); fail_if(r[0] != 0x12,"was 0x%x",r[0]);
fail_if(r[1] != 0x34,"was 0x%x",r[1]); fail_if(r[1] != 0x34,"was 0x%x",r[1]);
fail_if(r[2] != 0x56,"was 0x%x",r[2]); fail_if(r[2] != 0x56,"was 0x%x",r[2]);
}
END_TEST END_TEST
START_TEST (test_pack24_be_2) START_TEST (test_pack24_be_2)
{
uint32_t v = 0xF8F7F6; uint32_t v = 0xF8F7F6;
uint8_t r[3]; uint8_t r[3];
@@ -120,9 +143,11 @@ START_TEST (test_pack24_be_2)
fail_if(r[0] != 0xF8,"was 0x%x",r[0]); fail_if(r[0] != 0xF8,"was 0x%x",r[0]);
fail_if(r[1] != 0xF7,"was 0x%x",r[1]); fail_if(r[1] != 0xF7,"was 0x%x",r[1]);
fail_if(r[2] != 0xF6,"was 0x%x",r[2]); fail_if(r[2] != 0xF6,"was 0x%x",r[2]);
}
END_TEST END_TEST
START_TEST (test_pack32_le_1) START_TEST (test_pack32_le_1)
{
uint32_t v = 0x12345678; uint32_t v = 0x12345678;
uint8_t r[4]; uint8_t r[4];
@@ -132,9 +157,11 @@ START_TEST (test_pack32_le_1)
fail_if(r[1] != 0x56,"was 0x%x",r[1]); fail_if(r[1] != 0x56,"was 0x%x",r[1]);
fail_if(r[2] != 0x34,"was 0x%x",r[2]); fail_if(r[2] != 0x34,"was 0x%x",r[2]);
fail_if(r[3] != 0x12,"was 0x%x",r[3]); fail_if(r[3] != 0x12,"was 0x%x",r[3]);
}
END_TEST END_TEST
START_TEST (test_pack32_le_2) START_TEST (test_pack32_le_2)
{
uint32_t v = 0xF8F7F6F4; uint32_t v = 0xF8F7F6F4;
uint8_t r[4]; uint8_t r[4];
@@ -144,9 +171,11 @@ START_TEST (test_pack32_le_2)
fail_if(r[1] != 0xF6,"was 0x%x",r[1]); fail_if(r[1] != 0xF6,"was 0x%x",r[1]);
fail_if(r[2] != 0xF7,"was 0x%x",r[2]); fail_if(r[2] != 0xF7,"was 0x%x",r[2]);
fail_if(r[3] != 0xF8,"was 0x%x",r[3]); fail_if(r[3] != 0xF8,"was 0x%x",r[3]);
}
END_TEST END_TEST
START_TEST (test_pack32_be_1) START_TEST (test_pack32_be_1)
{
uint32_t v = 0x12345678; uint32_t v = 0x12345678;
uint8_t r[4]; uint8_t r[4];
@@ -156,9 +185,11 @@ START_TEST (test_pack32_be_1)
fail_if(r[2] != 0x56,"was 0x%x",r[2]); fail_if(r[2] != 0x56,"was 0x%x",r[2]);
fail_if(r[1] != 0x34,"was 0x%x",r[1]); fail_if(r[1] != 0x34,"was 0x%x",r[1]);
fail_if(r[0] != 0x12,"was 0x%x",r[0]); fail_if(r[0] != 0x12,"was 0x%x",r[0]);
}
END_TEST END_TEST
START_TEST (test_pack32_be_2) START_TEST (test_pack32_be_2)
{
uint32_t v = 0xF8F7F6F4; uint32_t v = 0xF8F7F6F4;
uint8_t r[4]; uint8_t r[4];
@@ -168,81 +199,99 @@ START_TEST (test_pack32_be_2)
fail_if(r[2] != 0xF6,"was 0x%x",r[2]); fail_if(r[2] != 0xF6,"was 0x%x",r[2]);
fail_if(r[1] != 0xF7,"was 0x%x",r[1]); fail_if(r[1] != 0xF7,"was 0x%x",r[1]);
fail_if(r[0] != 0xF8,"was 0x%x",r[0]); fail_if(r[0] != 0xF8,"was 0x%x",r[0]);
}
END_TEST END_TEST
START_TEST (test_unpack24_le_1) START_TEST (test_unpack24_le_1)
{
uint32_t v; uint32_t v;
uint8_t r[3] = {0x12, 0x34, 0x56 }; uint8_t r[3] = {0x12, 0x34, 0x56 };
v = uc_unpack_24_le(r); v = uc_unpack_24_le(r);
fail_if(v != 0x563412,"was 0x%x",v); fail_if(v != 0x563412,"was 0x%x",v);
}
END_TEST END_TEST
START_TEST (test_unpack24_le_2) START_TEST (test_unpack24_le_2)
{
uint32_t v; uint32_t v;
uint8_t r[4] = {0xF8, 0xF7, 0xF6}; uint8_t r[4] = {0xF8, 0xF7, 0xF6};
v = uc_unpack_24_le(r); v = uc_unpack_24_le(r);
fail_if(v != 0xF6F7F8,"was 0x%x",v); fail_if(v != 0xF6F7F8,"was 0x%x",v);
}
END_TEST END_TEST
START_TEST (test_unpack24_be_1) START_TEST (test_unpack24_be_1)
{
uint32_t v; uint32_t v;
uint8_t r[3] = {0x12, 0x34, 0x56 }; uint8_t r[3] = {0x12, 0x34, 0x56 };
v = uc_unpack_24_be(r); v = uc_unpack_24_be(r);
fail_if(v != 0x123456,"was 0x%x",v); fail_if(v != 0x123456,"was 0x%x",v);
}
END_TEST END_TEST
START_TEST (test_unpack24_be_2) START_TEST (test_unpack24_be_2)
{
uint32_t v; uint32_t v;
uint8_t r[4] = {0xF8, 0xF7, 0xF6}; uint8_t r[4] = {0xF8, 0xF7, 0xF6};
v = uc_unpack_24_be(r); v = uc_unpack_24_be(r);
fail_if(v != 0xF8F7F6,"was 0x%x",v); fail_if(v != 0xF8F7F6,"was 0x%x",v);
}
END_TEST END_TEST
START_TEST (test_unpack32_le_1) START_TEST (test_unpack32_le_1)
{
uint32_t v; uint32_t v;
uint8_t r[4] = {0x12, 0x34, 0x56, 0x78}; uint8_t r[4] = {0x12, 0x34, 0x56, 0x78};
v = uc_unpack_32_le(r); v = uc_unpack_32_le(r);
fail_if(v != 0x78563412,"was 0x%x",v); fail_if(v != 0x78563412,"was 0x%x",v);
}
END_TEST END_TEST
START_TEST (test_unpack32_le_2) START_TEST (test_unpack32_le_2)
{
uint32_t v; uint32_t v;
uint8_t r[4] = {0xF8, 0xF7, 0xF6, 0xF4 }; uint8_t r[4] = {0xF8, 0xF7, 0xF6, 0xF4 };
v = uc_unpack_32_le(r); v = uc_unpack_32_le(r);
fail_if(v != 0xF4F6F7F8,"was 0x%x",v); fail_if(v != 0xF4F6F7F8,"was 0x%x",v);
}
END_TEST END_TEST
START_TEST (test_unpack32_be_1) START_TEST (test_unpack32_be_1)
{
uint32_t v; uint32_t v;
uint8_t r[4] = {0x12, 0x34, 0x56, 0x78}; uint8_t r[4] = {0x12, 0x34, 0x56, 0x78};
v = uc_unpack_32_be(r); v = uc_unpack_32_be(r);
fail_if(v != 0x12345678,"was 0x%x",v); fail_if(v != 0x12345678,"was 0x%x",v);
}
END_TEST END_TEST
START_TEST (test_unpack32_be_2) START_TEST (test_unpack32_be_2)
{
uint32_t v; uint32_t v;
uint8_t r[4] = {0xF8, 0xF7, 0xF6, 0xF4 }; uint8_t r[4] = {0xF8, 0xF7, 0xF6, 0xF4 };
v = uc_unpack_32_be(r); v = uc_unpack_32_be(r);
fail_if(v != 0xF8F7F6F4,"was 0x%x",v); fail_if(v != 0xF8F7F6F4,"was 0x%x",v);
}
END_TEST END_TEST
START_TEST (test_pack64_le_1) START_TEST (test_pack64_le_1)
{
uint64_t v = 0x1122334455667788ULL; uint64_t v = 0x1122334455667788ULL;
uint8_t r[8] = {}; uint8_t r[8] = {};
@@ -256,9 +305,11 @@ START_TEST (test_pack64_le_1)
fail_if(r[5] != 0x33,"was 0x%x",r[5]); fail_if(r[5] != 0x33,"was 0x%x",r[5]);
fail_if(r[6] != 0x22,"was 0x%x",r[6]); fail_if(r[6] != 0x22,"was 0x%x",r[6]);
fail_if(r[7] != 0x11,"was 0x%x",r[7]); fail_if(r[7] != 0x11,"was 0x%x",r[7]);
}
END_TEST END_TEST
START_TEST (test_pack64_le_2) START_TEST (test_pack64_le_2)
{
uint64_t v = 0xFFFEFDFCFBFAF9F8ULL; uint64_t v = 0xFFFEFDFCFBFAF9F8ULL;
uint8_t r[8] = {}; uint8_t r[8] = {};
@@ -272,28 +323,34 @@ START_TEST (test_pack64_le_2)
fail_if(r[5] != 0xFD,"was 0x%x",r[5]); fail_if(r[5] != 0xFD,"was 0x%x",r[5]);
fail_if(r[6] != 0xFE,"was 0x%x",r[6]); fail_if(r[6] != 0xFE,"was 0x%x",r[6]);
fail_if(r[7] != 0xFF,"was 0x%x",r[7]); fail_if(r[7] != 0xFF,"was 0x%x",r[7]);
}
END_TEST END_TEST
START_TEST (test_unpack64_le_1) START_TEST (test_unpack64_le_1)
{
uint64_t v; uint64_t v;
uint8_t r[8] = {0x11 ,0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88}; uint8_t r[8] = {0x11 ,0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88};
v = uc_unpack_64_le(r); v = uc_unpack_64_le(r);
fail_if(v != 0x8877665544332211ULL,"was 0x%llx",v); fail_if(v != 0x8877665544332211ULL,"was 0x%llx",v);
}
END_TEST END_TEST
START_TEST (test_unpack64_le_2) START_TEST (test_unpack64_le_2)
{
uint64_t v; uint64_t v;
uint8_t r[8] = {0xFF ,0xFE, 0xFD, 0xFC, 0xFB, 0xFA, 0xF9, 0xF8}; uint8_t r[8] = {0xFF ,0xFE, 0xFD, 0xFC, 0xFB, 0xFA, 0xF9, 0xF8};
v = uc_unpack_64_le(r); v = uc_unpack_64_le(r);
fail_if(v != 0xF8F9FAFBFCFDFEFFULL,"was 0x%llx",v); fail_if(v != 0xF8F9FAFBFCFDFEFFULL,"was 0x%llx",v);
}
END_TEST END_TEST
START_TEST (test_pack64_be_1) START_TEST (test_pack64_be_1)
{
uint64_t v = 0x1122334455667788ULL; uint64_t v = 0x1122334455667788ULL;
uint8_t r[8] = {}; uint8_t r[8] = {};
@@ -307,9 +364,11 @@ START_TEST (test_pack64_be_1)
fail_if(r[5] != 0x66,"was 0x%x",r[5]); fail_if(r[5] != 0x66,"was 0x%x",r[5]);
fail_if(r[6] != 0x77,"was 0x%x",r[6]); fail_if(r[6] != 0x77,"was 0x%x",r[6]);
fail_if(r[7] != 0x88,"was 0x%x",r[7]); fail_if(r[7] != 0x88,"was 0x%x",r[7]);
}
END_TEST END_TEST
START_TEST (test_pack64_be_2) START_TEST (test_pack64_be_2)
{
uint64_t v = 0xFFFEFDFCFBFAF9F8ULL; uint64_t v = 0xFFFEFDFCFBFAF9F8ULL;
uint8_t r[8] = {}; uint8_t r[8] = {};
@@ -323,24 +382,29 @@ START_TEST (test_pack64_be_2)
fail_if(r[5] != 0xFA,"was 0x%x",r[5]); fail_if(r[5] != 0xFA,"was 0x%x",r[5]);
fail_if(r[6] != 0xF9,"was 0x%x",r[6]); fail_if(r[6] != 0xF9,"was 0x%x",r[6]);
fail_if(r[7] != 0xF8,"was 0x%x",r[7]); fail_if(r[7] != 0xF8,"was 0x%x",r[7]);
}
END_TEST END_TEST
START_TEST (test_unpack64_be_1) START_TEST (test_unpack64_be_1)
{
uint64_t v; uint64_t v;
uint8_t r[8] = {0x11 ,0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88}; uint8_t r[8] = {0x11 ,0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88};
v = uc_unpack_64_be(r); v = uc_unpack_64_be(r);
fail_if(v != 0x1122334455667788ULL,"was 0x%llx",v); fail_if(v != 0x1122334455667788ULL,"was 0x%llx",v);
}
END_TEST END_TEST
START_TEST (test_unpack64_be_2) START_TEST (test_unpack64_be_2)
{
uint64_t v; uint64_t v;
uint8_t r[8] = {0xFF ,0xFE, 0xFD, 0xFC, 0xFB, 0xFA, 0xF9, 0xF8}; uint8_t r[8] = {0xFF ,0xFE, 0xFD, 0xFC, 0xFB, 0xFA, 0xF9, 0xF8};
v = uc_unpack_64_be(r); v = uc_unpack_64_be(r);
fail_if(v != 0xFFFEFDFCFBFAF9F8ULL,"was 0x%llx",v); fail_if(v != 0xFFFEFDFCFBFAF9F8ULL,"was 0x%llx",v);
}
END_TEST END_TEST
Suite *pack_suite(void) Suite *pack_suite(void)
+12
View File
@@ -3,6 +3,7 @@
START_TEST (test_ratelimit_1) START_TEST (test_ratelimit_1)
{
struct RateLimit r; struct RateLimit r;
long now = 10; long now = 10;
int i; int i;
@@ -12,9 +13,11 @@ START_TEST (test_ratelimit_1)
fail_if(!uc_ratelimit_allow(&r, now), "i = %d", i); fail_if(!uc_ratelimit_allow(&r, now), "i = %d", i);
} }
fail_if(uc_ratelimit_allow(&r, now)); fail_if(uc_ratelimit_allow(&r, now));
}
END_TEST END_TEST
START_TEST (test_ratelimit_2) START_TEST (test_ratelimit_2)
{
struct RateLimit r; struct RateLimit r;
long now = 10; long now = 10;
@@ -27,9 +30,11 @@ START_TEST (test_ratelimit_2)
fail_if(!uc_ratelimit_allow(&r, now)); fail_if(!uc_ratelimit_allow(&r, now));
fail_if(uc_ratelimit_allow(&r, now)); fail_if(uc_ratelimit_allow(&r, now));
}
END_TEST END_TEST
START_TEST (test_ratelimit_3) START_TEST (test_ratelimit_3)
{
struct RateLimit r; struct RateLimit r;
long now = 10; long now = 10;
int i; int i;
@@ -63,9 +68,11 @@ START_TEST (test_ratelimit_3)
fail_if(uc_ratelimit_allow(&r, now)); fail_if(uc_ratelimit_allow(&r, now));
}
END_TEST END_TEST
START_TEST (test_ratelimit_4) START_TEST (test_ratelimit_4)
{
struct RateLimit r; struct RateLimit r;
long now = 10; long now = 10;
int i; int i;
@@ -86,9 +93,11 @@ START_TEST (test_ratelimit_4)
} }
fail_if(uc_ratelimit_allow(&r, now)); fail_if(uc_ratelimit_allow(&r, now));
}
END_TEST END_TEST
START_TEST (test_ratelimit_5) START_TEST (test_ratelimit_5)
{
struct RateLimit r; struct RateLimit r;
long now = 1400000000; long now = 1400000000;
@@ -111,9 +120,11 @@ START_TEST (test_ratelimit_5)
fail_if(!uc_ratelimit_allow(&r, now)); fail_if(!uc_ratelimit_allow(&r, now));
fail_if(uc_ratelimit_allow(&r, now)); fail_if(uc_ratelimit_allow(&r, now));
}
END_TEST END_TEST
START_TEST (test_ratelimit_time_backward) START_TEST (test_ratelimit_time_backward)
{
struct RateLimit r; struct RateLimit r;
long now = 1400000000; long now = 1400000000;
@@ -126,6 +137,7 @@ START_TEST (test_ratelimit_time_backward)
fail_if(uc_ratelimit_allow(&r, now)); fail_if(uc_ratelimit_allow(&r, now));
}
END_TEST END_TEST
+14
View File
@@ -9,6 +9,7 @@
START_TEST (test_read_file_non_existing_file) START_TEST (test_read_file_non_existing_file)
{
char *content; char *content;
size_t len; size_t len;
int saved_errno; int saved_errno;
@@ -19,9 +20,11 @@ START_TEST (test_read_file_non_existing_file)
fail_if(content != NULL); fail_if(content != NULL);
fail_if(saved_errno == 0); fail_if(saved_errno == 0);
}
END_TEST END_TEST
START_TEST (test_read_file_simple) START_TEST (test_read_file_simple)
{
char *content; char *content;
const char *filename = "test_read_file_simple"; const char *filename = "test_read_file_simple";
size_t len; size_t len;
@@ -43,9 +46,11 @@ START_TEST (test_read_file_simple)
fail_if(strlen(content) != 5); fail_if(strlen(content) != 5);
fail_if(strcmp("hello", content) != 0); fail_if(strcmp("hello", content) != 0);
free(content); free(content);
}
END_TEST END_TEST
START_TEST (test_read_file_greater_than_max) START_TEST (test_read_file_greater_than_max)
{
char *content; char *content;
const char *filename = "test_read_file_simple"; const char *filename = "test_read_file_simple";
size_t len; size_t len;
@@ -66,9 +71,11 @@ START_TEST (test_read_file_greater_than_max)
fail_if(content != NULL); fail_if(content != NULL);
fail_if(saved_errno != EMSGSIZE, "was %d", saved_errno); fail_if(saved_errno != EMSGSIZE, "was %d", saved_errno);
}
END_TEST END_TEST
START_TEST (test_read_file_boundary) START_TEST (test_read_file_boundary)
{
char *content; char *content;
const char *filename = "test_read_file_boundary"; const char *filename = "test_read_file_boundary";
size_t len; size_t len;
@@ -91,9 +98,11 @@ START_TEST (test_read_file_boundary)
fail_if(len != sizeof buf); fail_if(len != sizeof buf);
fail_if(strcmp("foobar", &content[1022]) != 0); fail_if(strcmp("foobar", &content[1022]) != 0);
free(content); free(content);
}
END_TEST END_TEST
START_TEST (test_read_file_devnull) START_TEST (test_read_file_devnull)
{
char *content; char *content;
size_t len = 123; size_t len = 123;
@@ -102,9 +111,11 @@ START_TEST (test_read_file_devnull)
fail_if(len != 0); fail_if(len != 0);
free(content); free(content);
}
END_TEST END_TEST
START_TEST (test_read_file_too_big) START_TEST (test_read_file_too_big)
{
char *content; char *content;
const char *filename = "test_read_file_too_big"; const char *filename = "test_read_file_too_big";
size_t len; size_t len;
@@ -124,9 +135,11 @@ START_TEST (test_read_file_too_big)
fail_if(content != NULL); fail_if(content != NULL);
unlink(filename); unlink(filename);
}
END_TEST END_TEST
START_TEST (test_read_file_big) START_TEST (test_read_file_big)
{
char *content; char *content;
const char *filename = "test_read_file_big"; const char *filename = "test_read_file_big";
char buf[4096 * 16]; char buf[4096 * 16];
@@ -150,6 +163,7 @@ START_TEST (test_read_file_big)
free(content); free(content);
unlink(filename); unlink(filename);
}
END_TEST END_TEST
Suite *read_file_suite(void) Suite *read_file_suite(void)
+17 -4
View File
@@ -10,7 +10,7 @@
#include "ucore/restart_counter.h" #include "ucore/restart_counter.h"
#define FILE_NAME "restart_counter_test" #define FILE_NAME "restart_counter_test"
//Note that these tests are comewhat fragile as they depend on the //Note that these tests are comewhat fragile as they depend on the
//file sizes that are created, which depends on the (relative)paths of this file. //file sizes that are created, which depends on the (relative)paths of this file.
//for cleaning the created log files.. //for cleaning the created log files..
static void logging_rm_files(void) static void logging_rm_files(void)
@@ -20,6 +20,7 @@ static void logging_rm_files(void)
START_TEST (test_restart_counter) START_TEST (test_restart_counter)
{
UCRCResult rc; UCRCResult rc;
struct UCRestartCounter cnt; struct UCRestartCounter cnt;
@@ -33,9 +34,11 @@ START_TEST (test_restart_counter)
ck_assert_int_eq(1, uc_restart_counter_get(&cnt)); ck_assert_int_eq(1, uc_restart_counter_get(&cnt));
}
END_TEST END_TEST
START_TEST (test_restart_counter_existing) START_TEST (test_restart_counter_existing)
{
UCRCResult rc; UCRCResult rc;
struct UCRestartCounter cnt; struct UCRestartCounter cnt;
@@ -50,9 +53,11 @@ START_TEST (test_restart_counter_existing)
fail_if(rc != UC_RC_OK); fail_if(rc != UC_RC_OK);
ck_assert_int_eq(100000, uc_restart_counter_get(&cnt)); ck_assert_int_eq(100000, uc_restart_counter_get(&cnt));
}
END_TEST END_TEST
START_TEST (test_restart_counter_inaccessible_file) START_TEST (test_restart_counter_inaccessible_file)
{
UCRCResult rc; UCRCResult rc;
struct UCRestartCounter cnt; struct UCRestartCounter cnt;
@@ -60,8 +65,10 @@ START_TEST (test_restart_counter_inaccessible_file)
rc = uc_restart_counter_init(&cnt, "/should/not/exist/abc", 0); rc = uc_restart_counter_init(&cnt, "/should/not/exist/abc", 0);
fail_if(rc != UC_RC_ERR_FILE_ACCESS_ERROR); fail_if(rc != UC_RC_ERR_FILE_ACCESS_ERROR);
}
END_TEST END_TEST
START_TEST (test_restart_counter_garble) START_TEST (test_restart_counter_garble)
{
UCRCResult rc; UCRCResult rc;
struct UCRestartCounter cnt; struct UCRestartCounter cnt;
@@ -78,9 +85,11 @@ START_TEST (test_restart_counter_garble)
fail_if(rc != UC_RC_OK, "%d", rc); fail_if(rc != UC_RC_OK, "%d", rc);
ck_assert_int_eq(1, uc_restart_counter_get(&cnt)); ck_assert_int_eq(1, uc_restart_counter_get(&cnt));
}
END_TEST END_TEST
START_TEST (test_restart_counter_full_filesystem) START_TEST (test_restart_counter_full_filesystem)
{
UCRCResult rc; UCRCResult rc;
struct UCRestartCounter cnt; struct UCRestartCounter cnt;
@@ -88,9 +97,11 @@ START_TEST (test_restart_counter_full_filesystem)
rc = uc_restart_counter_init(&cnt, "/dev/full", 0); rc = uc_restart_counter_init(&cnt, "/dev/full", 0);
fail_if(rc != UC_RC_ERR_UNSPECIFIED); fail_if(rc != UC_RC_ERR_UNSPECIFIED);
}
END_TEST END_TEST
#ifndef __APPLE__
START_TEST (test_restart_counter_lock_file) START_TEST (test_restart_counter_lock_file)
{
UCRCResult rc; UCRCResult rc;
struct UCRestartCounter cnt; struct UCRestartCounter cnt;
@@ -126,8 +137,9 @@ START_TEST (test_restart_counter_lock_file)
_exit(0); _exit(0);
} }
}
END_TEST END_TEST
#endif
Suite *restart_counter_suite(void) Suite *restart_counter_suite(void)
{ {
@@ -143,8 +155,9 @@ Suite *restart_counter_suite(void)
} else { } else {
puts("Cannot access /dev/full. Not testing test_logfile_full_filesystem"); puts("Cannot access /dev/full. Not testing test_logfile_full_filesystem");
} }
#ifndef __APPLE__
tcase_add_test(tc1, test_restart_counter_lock_file); tcase_add_test(tc1, test_restart_counter_lock_file);
#endif
tcase_add_checked_fixture(tc1, logging_rm_files, logging_rm_files); tcase_add_checked_fixture(tc1, logging_rm_files, logging_rm_files);
suite_add_tcase(s, tc1); suite_add_tcase(s, tc1);
+48
View File
@@ -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;
}
+5 -3
View File
@@ -35,6 +35,7 @@ extern Suite *restart_counter_suite(void);
extern Suite *iomux_suite(void); extern Suite *iomux_suite(void);
extern Suite *iomux_signal_suite(void); extern Suite *iomux_signal_suite(void);
extern Suite *string_suite(void); extern Suite *string_suite(void);
extern Suite *ringbuf_suite(void);
static suite_func suites[] = { static suite_func suites[] = {
bitvec_suite, bitvec_suite,
@@ -65,6 +66,7 @@ static suite_func suites[] = {
iomux_suite, iomux_suite,
iomux_signal_suite, iomux_signal_suite,
string_suite string_suite
ringbuf_suite
}; };
@@ -107,7 +109,7 @@ main (int argc, char *argv[])
size_t i; size_t i;
SRunner *sr = srunner_create (NULL); SRunner *sr = srunner_create (NULL);
if (xml_output) if (xml_output)
srunner_set_xml(sr, "result.xml"); srunner_set_xml(sr, "result.xml");
//set the environment variable CK_FORK=no which means don't fork(). //set the environment variable CK_FORK=no which means don't fork().
@@ -133,10 +135,10 @@ main (int argc, char *argv[])
number_run = srunner_ntests_run(sr); number_run = srunner_ntests_run(sr);
number_failed = srunner_ntests_failed (sr); number_failed = srunner_ntests_failed (sr);
srunner_free (sr); srunner_free (sr);
if (!number_run) if (!number_run)
puts("ERROR: no tests were run"); puts("ERROR: no tests were run");
if (number_failed) if (number_failed)
printf("ERROR: %d tests failed\n", number_failed); printf("ERROR: %d tests failed\n", number_failed);
return (number_failed != 0) ; return (number_failed != 0) ;
+24
View File
@@ -3,6 +3,7 @@
START_TEST (test_sat_uc_addu8) START_TEST (test_sat_uc_addu8)
{
uint8_t a; uint8_t a;
uint8_t b; uint8_t b;
@@ -49,9 +50,11 @@ START_TEST (test_sat_uc_addu8)
a = 100; a = 100;
b = 100; b = 100;
fail_if(uc_sat_addu8(a,b) != 200); fail_if(uc_sat_addu8(a,b) != 200);
}
END_TEST END_TEST
START_TEST (test_sat_uc_subu8) START_TEST (test_sat_uc_subu8)
{
uint8_t a; uint8_t a;
uint8_t b; uint8_t b;
@@ -82,9 +85,11 @@ START_TEST (test_sat_uc_subu8)
a = 100; a = 100;
b = 100; b = 100;
fail_if(uc_sat_subu8(a,b) != 0); fail_if(uc_sat_subu8(a,b) != 0);
}
END_TEST END_TEST
START_TEST (test_sat_uc_multu8) START_TEST (test_sat_uc_multu8)
{
uint8_t a; uint8_t a;
uint8_t b; uint8_t b;
@@ -120,10 +125,12 @@ START_TEST (test_sat_uc_multu8)
b = 10; b = 10;
fail_if(uc_sat_multu8(a,b) != 100); fail_if(uc_sat_multu8(a,b) != 100);
}
END_TEST END_TEST
START_TEST (test_sat_uc_addu16) START_TEST (test_sat_uc_addu16)
{
uint16_t a; uint16_t a;
uint16_t b; uint16_t b;
@@ -170,9 +177,11 @@ START_TEST (test_sat_uc_addu16)
a = 100; a = 100;
b = 100; b = 100;
fail_if(uc_sat_addu16(a,b) != 200); fail_if(uc_sat_addu16(a,b) != 200);
}
END_TEST END_TEST
START_TEST (test_sat_uc_subu16) START_TEST (test_sat_uc_subu16)
{
uint16_t a; uint16_t a;
uint16_t b; uint16_t b;
@@ -203,9 +212,11 @@ START_TEST (test_sat_uc_subu16)
a = 100; a = 100;
b = 100; b = 100;
fail_if(uc_sat_subu16(a,b) != 0); fail_if(uc_sat_subu16(a,b) != 0);
}
END_TEST END_TEST
START_TEST (test_sat_uc_multu16) START_TEST (test_sat_uc_multu16)
{
uint16_t a; uint16_t a;
uint16_t b; uint16_t b;
@@ -241,9 +252,11 @@ START_TEST (test_sat_uc_multu16)
b = 10; b = 10;
fail_if(uc_sat_multu16(a,b) != 100); fail_if(uc_sat_multu16(a,b) != 100);
}
END_TEST END_TEST
START_TEST (test_sat_uc_addu32) START_TEST (test_sat_uc_addu32)
{
uint32_t a; uint32_t a;
uint32_t b; uint32_t b;
@@ -290,9 +303,11 @@ START_TEST (test_sat_uc_addu32)
a = 0x1fffffff; a = 0x1fffffff;
b = 0x80000000; b = 0x80000000;
fail_if(uc_sat_addu32(a,b) != 0x9fffffff); fail_if(uc_sat_addu32(a,b) != 0x9fffffff);
}
END_TEST END_TEST
START_TEST (test_sat_uc_subu32) START_TEST (test_sat_uc_subu32)
{
uint32_t a; uint32_t a;
uint32_t b; uint32_t b;
@@ -323,9 +338,11 @@ START_TEST (test_sat_uc_subu32)
a = 100; a = 100;
b = 100; b = 100;
fail_if(uc_sat_subu32(a,b) != 0); fail_if(uc_sat_subu32(a,b) != 0);
}
END_TEST END_TEST
START_TEST (test_sat_uc_multu32) START_TEST (test_sat_uc_multu32)
{
uint32_t a; uint32_t a;
uint32_t b; uint32_t b;
@@ -361,8 +378,10 @@ START_TEST (test_sat_uc_multu32)
b = 10; b = 10;
fail_if(uc_sat_multu32(a,b) != 100); fail_if(uc_sat_multu32(a,b) != 100);
}
END_TEST END_TEST
START_TEST (test_sat_uc_addu64) START_TEST (test_sat_uc_addu64)
{
uint64_t a; uint64_t a;
uint64_t b; uint64_t b;
@@ -409,9 +428,11 @@ START_TEST (test_sat_uc_addu64)
a = 0x1fffffffffffffffULL; a = 0x1fffffffffffffffULL;
b = 0x8000000000000000ULL; b = 0x8000000000000000ULL;
fail_if(uc_sat_addu64(a,b) != 0x9fffffffffffffffULL); fail_if(uc_sat_addu64(a,b) != 0x9fffffffffffffffULL);
}
END_TEST END_TEST
START_TEST (test_sat_uc_subu64) START_TEST (test_sat_uc_subu64)
{
uint64_t a; uint64_t a;
uint64_t b; uint64_t b;
@@ -442,9 +463,11 @@ START_TEST (test_sat_uc_subu64)
a = 100; a = 100;
b = 100; b = 100;
fail_if(uc_sat_subu64(a,b) != 0); fail_if(uc_sat_subu64(a,b) != 0);
}
END_TEST END_TEST
START_TEST (test_sat_uc_multu64) START_TEST (test_sat_uc_multu64)
{
uint64_t a; uint64_t a;
uint64_t b; uint64_t b;
@@ -480,6 +503,7 @@ START_TEST (test_sat_uc_multu64)
b = 10; b = 10;
fail_if(uc_sat_multu64(a,b) != 100); fail_if(uc_sat_multu64(a,b) != 100);
}
END_TEST END_TEST
Suite *sat_math_suite(void) Suite *sat_math_suite(void)
{ {
+8
View File
@@ -3,6 +3,7 @@
START_TEST (test_uc_seq_lt) START_TEST (test_uc_seq_lt)
{
fail_if(uc_seq_lt(0, 1) != 1); fail_if(uc_seq_lt(0, 1) != 1);
fail_if(uc_seq_lt(0x7fffffffU, 0x80000000U) != 1); fail_if(uc_seq_lt(0x7fffffffU, 0x80000000U) != 1);
fail_if(uc_seq_lt(0xfffffffeU, 2) != 1); fail_if(uc_seq_lt(0xfffffffeU, 2) != 1);
@@ -15,9 +16,11 @@ START_TEST (test_uc_seq_lt)
fail_if(uc_seq_lt(0, 0) != 0); fail_if(uc_seq_lt(0, 0) != 0);
fail_if(uc_seq_lt(1, 1) != 0); fail_if(uc_seq_lt(1, 1) != 0);
fail_if(uc_seq_lt(0xffffffffU, 0xffffffffU) != 0); fail_if(uc_seq_lt(0xffffffffU, 0xffffffffU) != 0);
}
END_TEST END_TEST
START_TEST (test_uc_seq_gt) START_TEST (test_uc_seq_gt)
{
fail_if(uc_seq_gt(1, 0) != 1); fail_if(uc_seq_gt(1, 0) != 1);
fail_if(uc_seq_gt(0x80000000U,0x7fffffffU) != 1); fail_if(uc_seq_gt(0x80000000U,0x7fffffffU) != 1);
fail_if(uc_seq_gt(2, 0xfffffffeU) != 1); fail_if(uc_seq_gt(2, 0xfffffffeU) != 1);
@@ -30,9 +33,11 @@ START_TEST (test_uc_seq_gt)
fail_if(uc_seq_gt(0, 0) != 0); fail_if(uc_seq_gt(0, 0) != 0);
fail_if(uc_seq_gt(1, 1) != 0); fail_if(uc_seq_gt(1, 1) != 0);
fail_if(uc_seq_gt(0xffffffffU, 0xffffffffU) != 0); fail_if(uc_seq_gt(0xffffffffU, 0xffffffffU) != 0);
}
END_TEST END_TEST
START_TEST (test_uc_seq_leq) START_TEST (test_uc_seq_leq)
{
fail_if(uc_seq_leq(0, 1) != 1); fail_if(uc_seq_leq(0, 1) != 1);
fail_if(uc_seq_leq(0x7fffffffU, 0x80000000U) != 1); fail_if(uc_seq_leq(0x7fffffffU, 0x80000000U) != 1);
fail_if(uc_seq_leq(0xfffffffeU, 2) != 1); fail_if(uc_seq_leq(0xfffffffeU, 2) != 1);
@@ -47,9 +52,11 @@ START_TEST (test_uc_seq_leq)
fail_if(uc_seq_leq(0x80000000U,0x7fffffffU) != 0); fail_if(uc_seq_leq(0x80000000U,0x7fffffffU) != 0);
fail_if(uc_seq_leq(2, 0xfffffffeU) != 0); fail_if(uc_seq_leq(2, 0xfffffffeU) != 0);
fail_if(uc_seq_leq(0, 0xffffffffU) != 0); fail_if(uc_seq_leq(0, 0xffffffffU) != 0);
}
END_TEST END_TEST
START_TEST (test_uc_seq_geq) START_TEST (test_uc_seq_geq)
{
fail_if(uc_seq_geq(1, 0) != 1); fail_if(uc_seq_geq(1, 0) != 1);
fail_if(uc_seq_geq(0x80000000U,0x7fffffffU) != 1); fail_if(uc_seq_geq(0x80000000U,0x7fffffffU) != 1);
fail_if(uc_seq_geq(2, 0xfffffffeU) != 1); fail_if(uc_seq_geq(2, 0xfffffffeU) != 1);
@@ -65,6 +72,7 @@ START_TEST (test_uc_seq_geq)
fail_if(uc_seq_geq(0xfffffffeU, 2) != 0); fail_if(uc_seq_geq(0xfffffffeU, 2) != 0);
fail_if(uc_seq_geq(0xffffffffU, 0) != 0); fail_if(uc_seq_geq(0xffffffffU, 0) != 0);
}
END_TEST END_TEST
+8
View File
@@ -9,6 +9,7 @@
// long long 64 bit // long long 64 bit
START_TEST (test_sprintb) START_TEST (test_sprintb)
{
char result[128]; char result[128];
char *rc; char *rc;
@@ -24,9 +25,11 @@ START_TEST (test_sprintb)
rc = uc_sprintb(result, 1); rc = uc_sprintb(result, 1);
ck_assert_str_eq(rc, "00000000000000000000000000000001"); ck_assert_str_eq(rc, "00000000000000000000000000000001");
}
END_TEST END_TEST
START_TEST (test_sprintbc) START_TEST (test_sprintbc)
{
char result[128]; char result[128];
char *rc; char *rc;
@@ -42,9 +45,11 @@ START_TEST (test_sprintbc)
rc = uc_sprintbc(result, 1); rc = uc_sprintbc(result, 1);
ck_assert_str_eq(rc, "00000001"); ck_assert_str_eq(rc, "00000001");
}
END_TEST END_TEST
START_TEST (test_sprintbs) START_TEST (test_sprintbs)
{
char result[128]; char result[128];
char *rc; char *rc;
@@ -60,9 +65,11 @@ START_TEST (test_sprintbs)
rc = uc_sprintbs(result, 1); rc = uc_sprintbs(result, 1);
ck_assert_str_eq(rc, "0000000000000001"); ck_assert_str_eq(rc, "0000000000000001");
}
END_TEST END_TEST
START_TEST (test_sprintbll) START_TEST (test_sprintbll)
{
char result[128]; char result[128];
char *rc; char *rc;
@@ -78,6 +85,7 @@ START_TEST (test_sprintbll)
rc = uc_sprintbll(result, 1); rc = uc_sprintbll(result, 1);
ck_assert_str_eq(rc, "0000000000000000000000000000000000000000000000000000000000000001"); ck_assert_str_eq(rc, "0000000000000000000000000000000000000000000000000000000000000001");
}
END_TEST END_TEST
Suite *sprintb_suite(void) Suite *sprintb_suite(void)
+12
View File
@@ -5,6 +5,7 @@
START_TEST (test_strv_append) START_TEST (test_strv_append)
{
struct UCStrv strv; struct UCStrv strv;
int rc; int rc;
@@ -22,9 +23,11 @@ START_TEST (test_strv_append)
uc_strv_destroy(&strv); uc_strv_destroy(&strv);
}
END_TEST END_TEST
START_TEST (test_strv_clear) START_TEST (test_strv_clear)
{
struct UCStrv strv; struct UCStrv strv;
int rc; int rc;
@@ -38,9 +41,11 @@ START_TEST (test_strv_clear)
fail_if(strv.cnt != 0); fail_if(strv.cnt != 0);
uc_strv_destroy(&strv); uc_strv_destroy(&strv);
}
END_TEST END_TEST
START_TEST (test_strv_nocopy) START_TEST (test_strv_nocopy)
{
struct UCStrv strv; struct UCStrv strv;
char *str = strdup("string"); char *str = strdup("string");
int rc; int rc;
@@ -54,9 +59,11 @@ START_TEST (test_strv_nocopy)
uc_strv_destroy(&strv); uc_strv_destroy(&strv);
}
END_TEST END_TEST
START_TEST (test_strv_null_terminate) START_TEST (test_strv_null_terminate)
{
struct UCStrv strv; struct UCStrv strv;
int rc; int rc;
@@ -73,9 +80,11 @@ START_TEST (test_strv_null_terminate)
uc_strv_destroy(&strv); uc_strv_destroy(&strv);
}
END_TEST END_TEST
START_TEST (test_strv_append_all_copy) START_TEST (test_strv_append_all_copy)
{
struct UCStrv src; struct UCStrv src;
struct UCStrv dst; struct UCStrv dst;
int rc; int rc;
@@ -97,9 +106,11 @@ START_TEST (test_strv_append_all_copy)
uc_strv_destroy(&src); uc_strv_destroy(&src);
uc_strv_destroy(&dst); uc_strv_destroy(&dst);
}
END_TEST END_TEST
START_TEST (test_strv_append_all_nocopy) START_TEST (test_strv_append_all_nocopy)
{
struct UCStrv src; struct UCStrv src;
struct UCStrv dst; struct UCStrv dst;
int rc; int rc;
@@ -121,6 +132,7 @@ START_TEST (test_strv_append_all_nocopy)
uc_strv_destroy(&dst); uc_strv_destroy(&dst);
free(src.strings); free(src.strings);
}
END_TEST END_TEST
START_TEST (test_strv_reverse) START_TEST (test_strv_reverse)
+30 -4
View File
@@ -12,6 +12,7 @@ struct thr_msg {
}; };
START_TEST (test_thread_queue_length) START_TEST (test_thread_queue_length)
{
struct uc_threadqueue queue; struct uc_threadqueue queue;
int i; int i;
@@ -26,9 +27,11 @@ START_TEST (test_thread_queue_length)
fail_if(uc_thread_queue_length(&queue) != 51); fail_if(uc_thread_queue_length(&queue) != 51);
}
END_TEST END_TEST
START_TEST (test_thread_queue_one_thread) START_TEST (test_thread_queue_one_thread)
{
struct uc_threadqueue queue; struct uc_threadqueue queue;
int i; int i;
@@ -52,9 +55,11 @@ START_TEST (test_thread_queue_one_thread)
} }
fail_if(uc_thread_queue_destroy(&queue, NULL, NULL) != 0); fail_if(uc_thread_queue_destroy(&queue, NULL, NULL) != 0);
}
END_TEST END_TEST
START_TEST (test_thread_queue_priority_msg) START_TEST (test_thread_queue_priority_msg)
{
struct uc_threadqueue queue; struct uc_threadqueue queue;
int i; int i;
@@ -79,6 +84,7 @@ START_TEST (test_thread_queue_priority_msg)
fail_if(uc_thread_queue_destroy(&queue, NULL, NULL) != 0); fail_if(uc_thread_queue_destroy(&queue, NULL, NULL) != 0);
}
END_TEST END_TEST
@@ -94,6 +100,7 @@ static void test_thread_queue_walk_func(struct uc_threadmsg *msg, void *cookie)
} }
START_TEST (test_thread_queue_walk) START_TEST (test_thread_queue_walk)
{
struct uc_threadqueue queue; struct uc_threadqueue queue;
int i; int i;
@@ -111,6 +118,7 @@ START_TEST (test_thread_queue_walk)
uc_thread_queue_walk(&queue, test_thread_queue_walk_func, NULL); uc_thread_queue_walk(&queue, test_thread_queue_walk_func, NULL);
}
END_TEST END_TEST
#define READER_WRITER_NUM_MSG 20000 #define READER_WRITER_NUM_MSG 20000
@@ -133,6 +141,7 @@ static void *test_thread_queue_reader_writer_func(void *arg)
} }
START_TEST (test_thread_queue_reader_writer) START_TEST (test_thread_queue_reader_writer)
{
struct uc_threadqueue queue; struct uc_threadqueue queue;
int i; int i;
@@ -154,9 +163,11 @@ START_TEST (test_thread_queue_reader_writer)
fail_if(uc_thread_queue_destroy(&queue, NULL, NULL) != 0); fail_if(uc_thread_queue_destroy(&queue, NULL, NULL) != 0);
}
END_TEST END_TEST
START_TEST (test_thread_queue_reader_writer_len_1) START_TEST (test_thread_queue_reader_writer_len_1)
{
struct uc_threadqueue queue; struct uc_threadqueue queue;
int i; int i;
@@ -176,14 +187,16 @@ START_TEST (test_thread_queue_reader_writer_len_1)
pthread_join(tid, NULL); pthread_join(tid, NULL);
}
END_TEST END_TEST
START_TEST (test_thread_queue_zero_len) START_TEST (test_thread_queue_zero_len)
{
struct uc_threadqueue queue; struct uc_threadqueue queue;
fail_if(uc_thread_queue_init(&queue, 0) == 0); //thread_queue_init should fail fail_if(uc_thread_queue_init(&queue, 0) == 0); //thread_queue_init should fail
}
END_TEST END_TEST
void *test_thread_queue_multiple_writers_func(void *arg) void *test_thread_queue_multiple_writers_func(void *arg)
@@ -203,6 +216,7 @@ void *test_thread_queue_multiple_writers_func(void *arg)
} }
START_TEST (test_thread_queue_multiple_writers) START_TEST (test_thread_queue_multiple_writers)
{
struct uc_threadqueue queue; struct uc_threadqueue queue;
int i; int i;
@@ -232,9 +246,11 @@ START_TEST (test_thread_queue_multiple_writers)
fail_if(count_max != 3); fail_if(count_max != 3);
}
END_TEST END_TEST
START_TEST (test_thread_queue_timeout1) START_TEST (test_thread_queue_timeout1)
{
struct uc_threadqueue queue; struct uc_threadqueue queue;
struct timespec timeout = {0, 1000}; struct timespec timeout = {0, 1000};
@@ -245,6 +261,7 @@ START_TEST (test_thread_queue_timeout1)
fail_if(uc_thread_queue_tryget(&queue, &timeout, &msg) != ETIMEDOUT); fail_if(uc_thread_queue_tryget(&queue, &timeout, &msg) != ETIMEDOUT);
uc_thread_queue_destroy(&queue, NULL, NULL); uc_thread_queue_destroy(&queue, NULL, NULL);
}
END_TEST END_TEST
void *thread_test_thread_queue_timeout2(void *arg) void *thread_test_thread_queue_timeout2(void *arg)
@@ -264,6 +281,7 @@ void *thread_test_thread_queue_timeout2(void *arg)
return NULL; return NULL;
} }
START_TEST (test_thread_queue_timeout2) START_TEST (test_thread_queue_timeout2)
{
struct uc_threadqueue queue; struct uc_threadqueue queue;
pthread_t tid1; pthread_t tid1;
@@ -280,9 +298,12 @@ START_TEST (test_thread_queue_timeout2)
uc_thread_queue_destroy(&queue, NULL, NULL); uc_thread_queue_destroy(&queue, NULL, NULL);
}
END_TEST END_TEST
START_TEST (test_thread_queue_tryadd_timeout_0_0) START_TEST (test_thread_queue_tryadd_timeout_0_0)
{
struct uc_threadqueue queue; struct uc_threadqueue queue;
int i; int i;
@@ -298,10 +319,12 @@ START_TEST (test_thread_queue_tryadd_timeout_0_0)
fail_if(uc_thread_queue_tryadd(&queue, &timeout, &msg[2].msg) != ETIMEDOUT); fail_if(uc_thread_queue_tryadd(&queue, &timeout, &msg[2].msg) != ETIMEDOUT);
fail_if(uc_thread_queue_destroy(&queue, NULL, NULL) != 0); fail_if(uc_thread_queue_destroy(&queue, NULL, NULL) != 0);
}
END_TEST END_TEST
START_TEST (test_thread_queue_tryadd_timeout_0_100) START_TEST (test_thread_queue_tryadd_timeout_0_100)
{
struct uc_threadqueue queue; struct uc_threadqueue queue;
int i; int i;
@@ -318,9 +341,11 @@ START_TEST (test_thread_queue_tryadd_timeout_0_100)
fail_if(uc_thread_queue_destroy(&queue, NULL, NULL) != 0); fail_if(uc_thread_queue_destroy(&queue, NULL, NULL) != 0);
}
END_TEST END_TEST
START_TEST (test_thread_queue_tryadd_no_timeout_0_100) START_TEST (test_thread_queue_tryadd_no_timeout_0_100)
{
struct uc_threadqueue queue; struct uc_threadqueue queue;
int i; int i;
@@ -336,7 +361,7 @@ START_TEST (test_thread_queue_tryadd_no_timeout_0_100)
fail_if(uc_thread_queue_tryadd(&queue, &timeout, &msg[2].msg) != 0); fail_if(uc_thread_queue_tryadd(&queue, &timeout, &msg[2].msg) != 0);
fail_if(uc_thread_queue_destroy(&queue, NULL, NULL) != 0); fail_if(uc_thread_queue_destroy(&queue, NULL, NULL) != 0);
}
END_TEST END_TEST
void clear_cb(struct uc_threadmsg *msg, void *cookie) void clear_cb(struct uc_threadmsg *msg, void *cookie)
@@ -347,6 +372,7 @@ void clear_cb(struct uc_threadmsg *msg, void *cookie)
} }
START_TEST (test_thread_queue_clear) START_TEST (test_thread_queue_clear)
{
struct uc_threadqueue queue; struct uc_threadqueue queue;
int i; int i;
@@ -365,7 +391,7 @@ START_TEST (test_thread_queue_clear)
fail_if(uc_thread_queue_length(&queue) != 0); fail_if(uc_thread_queue_length(&queue) != 0);
fail_if(uc_thread_queue_destroy(&queue, NULL, NULL) != 0); fail_if(uc_thread_queue_destroy(&queue, NULL, NULL) != 0);
}
END_TEST END_TEST
+2
View File
@@ -29,6 +29,7 @@ static void *update_thread(void *arg)
#define NR_THREADS 5 #define NR_THREADS 5
START_TEST(test_ticket_lock1) START_TEST(test_ticket_lock1)
{
struct ThreadArg threads[NR_THREADS]; struct ThreadArg threads[NR_THREADS];
int i; int i;
int lrc; int lrc;
@@ -53,6 +54,7 @@ START_TEST(test_ticket_lock1)
ck_assert_int_eq((NR_THREADS * (NR_THREADS + 1)) / 2, g_counter); ck_assert_int_eq((NR_THREADS * (NR_THREADS + 1)) / 2, g_counter);
}
END_TEST END_TEST
Suite *ticket_lock_suite(void) Suite *ticket_lock_suite(void)
+8
View File
@@ -43,6 +43,7 @@ static void common_init(struct UCoreSettableClock *clk,
} }
START_TEST (test_timers_simple) START_TEST (test_timers_simple)
{
struct UCoreSettableClock clk; struct UCoreSettableClock clk;
struct TimerTest tt; struct TimerTest tt;
struct UCTimers timers; struct UCTimers timers;
@@ -80,9 +81,11 @@ START_TEST (test_timers_simple)
ck_assert_int_eq(uc_timers_count(&timers), 0); ck_assert_int_eq(uc_timers_count(&timers), 0);
fail_if(uc_timer_running(&timer) != 0); fail_if(uc_timer_running(&timer) != 0);
}
END_TEST END_TEST
START_TEST (test_timers_add_from_callback) START_TEST (test_timers_add_from_callback)
{
struct UCoreSettableClock clk; struct UCoreSettableClock clk;
struct TimerTest tt; struct TimerTest tt;
struct UCTimers timers; struct UCTimers timers;
@@ -114,9 +117,11 @@ START_TEST (test_timers_add_from_callback)
fail_if(uc_timer_running(&timer) == 0); fail_if(uc_timer_running(&timer) == 0);
ck_assert_int_eq(uc_timers_count(&timers), 1); ck_assert_int_eq(uc_timers_count(&timers), 1);
}
END_TEST END_TEST
START_TEST (test_timers_remove_from_callback) START_TEST (test_timers_remove_from_callback)
{
struct UCoreSettableClock clk; struct UCoreSettableClock clk;
struct TimerTest tt; struct TimerTest tt;
struct UCTimers timers; struct UCTimers timers;
@@ -158,9 +163,11 @@ START_TEST (test_timers_remove_from_callback)
rc = uc_timers_first(&timers, &tv); rc = uc_timers_first(&timers, &tv);
fail_if(rc == 0); fail_if(rc == 0);
}
END_TEST END_TEST
START_TEST (test_timers_add_remove) START_TEST (test_timers_add_remove)
{
struct UCoreSettableClock clk; struct UCoreSettableClock clk;
struct TimerTest tt; struct TimerTest tt;
struct UCTimers timers; struct UCTimers timers;
@@ -193,6 +200,7 @@ START_TEST (test_timers_add_remove)
ck_assert_int_eq(uc_timers_count(&timers), 0); ck_assert_int_eq(uc_timers_count(&timers), 0);
fail_if(uc_timers_first(&timers, &first) == 0); fail_if(uc_timers_first(&timers, &first) == 0);
}
END_TEST END_TEST
+12
View File
@@ -3,6 +3,7 @@
START_TEST (test_val_str_search) START_TEST (test_val_str_search)
{
struct UCValStr vals[] = { struct UCValStr vals[] = {
UC_VS_ENTRY(1), UC_VS_ENTRY(1),
UC_VS_ENTRY(5), UC_VS_ENTRY(5),
@@ -14,9 +15,11 @@ START_TEST (test_val_str_search)
ck_assert_str_eq(uc_val_2_str(5 , vals) , "5"); ck_assert_str_eq(uc_val_2_str(5 , vals) , "5");
fail_if(uc_val_2_str(10, vals) != NULL); fail_if(uc_val_2_str(10, vals) != NULL);
}
END_TEST END_TEST
START_TEST (test_val_str_vs_search) START_TEST (test_val_str_vs_search)
{
struct UCValStr vals[] = { struct UCValStr vals[] = {
UC_VS_ENTRY(1), UC_VS_ENTRY(1),
UC_VS_ENTRY(5), UC_VS_ENTRY(5),
@@ -28,9 +31,11 @@ START_TEST (test_val_str_vs_search)
ck_assert_str_eq(uc_val_2_str_vs(5 , vals)->str , "5"); ck_assert_str_eq(uc_val_2_str_vs(5 , vals)->str , "5");
fail_if(uc_val_2_str(10, vals) != NULL); fail_if(uc_val_2_str(10, vals) != NULL);
}
END_TEST END_TEST
START_TEST (test_val_str_bsearch_odd) START_TEST (test_val_str_bsearch_odd)
{
struct UCValStr vals[] = { struct UCValStr vals[] = {
UC_VS_ENTRY(1), UC_VS_ENTRY(1),
UC_VS_ENTRY(2), UC_VS_ENTRY(2),
@@ -49,9 +54,11 @@ START_TEST (test_val_str_bsearch_odd)
fail_if(uc_val_2_str_bs(0 , vals , len) != NULL); fail_if(uc_val_2_str_bs(0 , vals , len) != NULL);
fail_if(uc_val_2_str_bs(55 , vals , len) != NULL); fail_if(uc_val_2_str_bs(55 , vals , len) != NULL);
fail_if(uc_val_2_str_bs(999 , vals , len) != NULL); fail_if(uc_val_2_str_bs(999 , vals , len) != NULL);
}
END_TEST END_TEST
START_TEST (test_val_str_bsearch_even) START_TEST (test_val_str_bsearch_even)
{
struct UCValStr vals[] = { struct UCValStr vals[] = {
UC_VS_ENTRY(1), UC_VS_ENTRY(1),
UC_VS_ENTRY(2), UC_VS_ENTRY(2),
@@ -68,9 +75,11 @@ START_TEST (test_val_str_bsearch_even)
fail_if(uc_val_2_str_bs(0 , vals , len) != NULL); fail_if(uc_val_2_str_bs(0 , vals , len) != NULL);
fail_if(uc_val_2_str_bs(55 , vals , len) != NULL); fail_if(uc_val_2_str_bs(55 , vals , len) != NULL);
fail_if(uc_val_2_str_bs(999 , vals , len) != NULL); fail_if(uc_val_2_str_bs(999 , vals , len) != NULL);
}
END_TEST END_TEST
START_TEST (test_str_str_search) START_TEST (test_str_str_search)
{
struct UCStrStr vals[] = { struct UCStrStr vals[] = {
{"1", "A"}, {"1", "A"},
{"2", "B"}, {"2", "B"},
@@ -82,9 +91,11 @@ START_TEST (test_str_str_search)
ck_assert_str_eq(uc_str_2_str("3" , vals) , "C"); ck_assert_str_eq(uc_str_2_str("3" , vals) , "C");
fail_if(uc_str_2_str("10", vals) != NULL); fail_if(uc_str_2_str("10", vals) != NULL);
}
END_TEST END_TEST
START_TEST (test_str_str_ci_search) START_TEST (test_str_str_ci_search)
{
struct UCStrStr vals[] = { struct UCStrStr vals[] = {
{"A", "1"}, {"A", "1"},
{"az","2"}, {"az","2"},
@@ -96,6 +107,7 @@ START_TEST (test_str_str_ci_search)
ck_assert_str_eq(uc_str_2_str_ci("C" , vals) , "3"); ck_assert_str_eq(uc_str_2_str_ci("C" , vals) , "3");
fail_if(uc_str_2_str_ci("aza", vals) != NULL); fail_if(uc_str_2_str_ci("aza", vals) != NULL);
}
END_TEST END_TEST
Suite *val_str_suite(void) Suite *val_str_suite(void)
{ {