Compare commits
39 Commits
b74a4ab663
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 66dfd956da | |||
| c7d175d90f | |||
| fb0efd9cbb | |||
| 735c5cb77e | |||
| d58e24f6a9 | |||
| d1a45cf8e0 | |||
| 36457f775f | |||
| afc3148de3 | |||
| a695653e27 | |||
| a4cae42114 | |||
| 24d9994c87 | |||
| d85735add9 | |||
| 0c6301954f | |||
| fc418f6163 | |||
| aba9cba602 | |||
| 64a5b20941 | |||
| 0073924050 | |||
| 0ca7f64c83 | |||
| 1b61b3c6d0 | |||
| 055338b1e9 | |||
| 271c2a611f | |||
| 88e9f95988 | |||
| a4547f6736 | |||
| 4e28b2255c | |||
| b2f834b7cd | |||
| 85713d25c1 | |||
| 7cf73fe561 | |||
| 3e4826cf36 | |||
| 309787bc48 | |||
| 82e2337ecc | |||
| b2d56f8094 | |||
| 251246924d | |||
| 7408c48dff | |||
| 5b5ca445e9 | |||
| cfe647f85d | |||
| abf430dabb | |||
| 2bd91ae751 | |||
| 2278080b69 | |||
| 393106ea4e |
@@ -8,3 +8,6 @@ log_subdir/
|
|||||||
coverage/
|
coverage/
|
||||||
install/
|
install/
|
||||||
libucore-*
|
libucore-*
|
||||||
|
src/version.c
|
||||||
|
.cache/
|
||||||
|
compile_commands.json
|
||||||
|
|||||||
Vendored
+15
@@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"name": "Mac",
|
||||||
|
"includePath": [
|
||||||
|
"${default}",
|
||||||
|
"${workspaceFolder}/include"
|
||||||
|
],
|
||||||
|
"defines": [],
|
||||||
|
"compilerPath": "/usr/bin/clang",
|
||||||
|
"intelliSenseMode": "macos-clang-arm64"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"version": 4
|
||||||
|
}
|
||||||
Vendored
+11
@@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"files.associations": {
|
||||||
|
"*.h": "c",
|
||||||
|
},
|
||||||
|
"C_Cpp.default.includePath": [
|
||||||
|
"/opt/homebrew/include/",
|
||||||
|
"$(workspaceFolder)/include/",
|
||||||
|
|
||||||
|
],
|
||||||
|
"C_Cpp.default.cStandard": "gnu17"
|
||||||
|
}
|
||||||
Vendored
+19
@@ -0,0 +1,19 @@
|
|||||||
|
{
|
||||||
|
"version": "2.0.0",
|
||||||
|
"tasks": [
|
||||||
|
{
|
||||||
|
"type": "cmake",
|
||||||
|
"label": "CMake: build",
|
||||||
|
"command": "build",
|
||||||
|
"targets": [
|
||||||
|
"all"
|
||||||
|
],
|
||||||
|
"group": {
|
||||||
|
"kind": "build",
|
||||||
|
"isDefault": true
|
||||||
|
},
|
||||||
|
"problemMatcher": [],
|
||||||
|
"detail": "CMake template build task"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
+19
-9
@@ -1,9 +1,8 @@
|
|||||||
cmake_minimum_required(VERSION 4.0.0)
|
cmake_minimum_required(VERSION 3.12)
|
||||||
project(libucore C)
|
project(libucore C)
|
||||||
|
|
||||||
execute_process(COMMAND git -C ${CMAKE_SOURCE_DIR} describe --abbrev=5 --dirty --always OUTPUT_VARIABLE version_revision WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} OUTPUT_STRIP_TRAILING_WHITESPACE)
|
execute_process(COMMAND git -C ${CMAKE_SOURCE_DIR} describe --abbrev=5 --dirty --always OUTPUT_VARIABLE version_revision WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||||
execute_process(COMMAND hostname OUTPUT_VARIABLE build_host OUTPUT_STRIP_TRAILING_WHITESPACE)
|
cmake_host_system_information(RESULT build_host QUERY HOSTNAME)
|
||||||
|
|
||||||
set(libucore_VERSION_MAJOR 1)
|
set(libucore_VERSION_MAJOR 1)
|
||||||
set(libucore_VERSION_MINOR 0)
|
set(libucore_VERSION_MINOR 0)
|
||||||
set(libucore_VERSION_PATCH 0)
|
set(libucore_VERSION_PATCH 0)
|
||||||
@@ -11,23 +10,34 @@ set(libucore_VERSION ${libucore_VERSION_MAJOR}.${libucore_VERSION_MINOR}.${libuc
|
|||||||
|
|
||||||
set(CMAKE_VERBOSE_MAKEFILE ON)
|
set(CMAKE_VERBOSE_MAKEFILE ON)
|
||||||
|
|
||||||
set(CMAKE_C_STANDARD 99)
|
set(CMAKE_C_STANDARD 17)
|
||||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wundef -Wcast-qual -Wshadow -Wcast-align -pipe -Wno-unused-parameter -Werror=implicit-function-declaration -Winit-self -pthread")
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wundef -Wcast-qual -Wshadow -Wcast-align -pipe -Wno-unused-parameter -Werror=implicit-function-declaration -Winit-self")
|
||||||
add_definitions(-D_FILE_OFFSET_BITS=64)
|
add_definitions(-D_FILE_OFFSET_BITS=64)
|
||||||
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -O2 -pthread")
|
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -O2")
|
||||||
|
set(THREADS_PREFER_PTHREAD_FLAG ON)
|
||||||
|
find_package(Threads REQUIRED)
|
||||||
option(CODE_COVERAGE "build with code coverage intrumentation" OFF)
|
option(CODE_COVERAGE "build with code coverage intrumentation" OFF)
|
||||||
|
|
||||||
|
if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
|
||||||
|
set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "Choose the type of build." FORCE)
|
||||||
|
# Set the property for multi-config generators as well, if applicable
|
||||||
|
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS Debug Release RelWithDebInfo MinSizeRel)
|
||||||
|
endif()
|
||||||
|
set(build_type ${CMAKE_BUILD_TYPE})
|
||||||
if (CODE_COVERAGE)
|
if (CODE_COVERAGE)
|
||||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --coverage")
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --coverage")
|
||||||
add_definitions(-DCOVERAGE)
|
add_definitions(-DCOVERAGE)
|
||||||
|
set(build_type "${build_type}-coverage")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
add_compile_definitions($<$<CONFIG:Debug>:DEBUG>)
|
||||||
option(BUILD_SANITIZE "build with address sanitizer" OFF)
|
option(BUILD_SANITIZE "build with address sanitizer" OFF)
|
||||||
if (BUILD_SANITIZE)
|
if (BUILD_SANITIZE)
|
||||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address")
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address")
|
||||||
|
set(build_type "${build_type}-sanitize")
|
||||||
endif()
|
endif()
|
||||||
|
find_package(PkgConfig REQUIRED)
|
||||||
|
pkg_check_modules(CHECK REQUIRED IMPORTED_TARGET check)
|
||||||
include_directories(include)
|
include_directories(include)
|
||||||
|
|
||||||
add_subdirectory(src)
|
add_subdirectory(src)
|
||||||
|
|||||||
-177
@@ -1,177 +0,0 @@
|
|||||||
import os
|
|
||||||
import platform
|
|
||||||
|
|
||||||
#version info of the library, we use 5 chars from the git hash
|
|
||||||
revision = os.popen('git describe --abbrev=5 --dirty --always').read()[:-1]
|
|
||||||
|
|
||||||
version_info = {
|
|
||||||
'version_major': 1 ,
|
|
||||||
'version_minor': 0 ,
|
|
||||||
'version_patch': 0 ,
|
|
||||||
'version_revision': revision,
|
|
||||||
#version_abi is the abi version of the shared library. Only bump it when
|
|
||||||
#backwards compatibility breaks. Strive to not break the ABI.
|
|
||||||
'version_abi': '1.0.0'
|
|
||||||
}
|
|
||||||
version_info['version_str'] = "%d.%d.%d.%s" % (
|
|
||||||
version_info['version_major'],
|
|
||||||
version_info['version_minor'],
|
|
||||||
version_info['version_patch'],
|
|
||||||
version_info['version_revision'])
|
|
||||||
|
|
||||||
|
|
||||||
AddOption('--build_type',
|
|
||||||
dest = 'build_type',
|
|
||||||
type = 'choice',
|
|
||||||
nargs = 1,
|
|
||||||
action='store',
|
|
||||||
default='debug',
|
|
||||||
metavar='TYPE',
|
|
||||||
choices = ['debug', 'release'],
|
|
||||||
help = 'debug|release - Build a Debug (default) or Release variant'
|
|
||||||
)
|
|
||||||
AddOption('--prefix',
|
|
||||||
dest='prefix',
|
|
||||||
type='string',
|
|
||||||
nargs=1,
|
|
||||||
action='store',
|
|
||||||
metavar='DIR',
|
|
||||||
default='/usr',
|
|
||||||
help='installation prefix'
|
|
||||||
)
|
|
||||||
|
|
||||||
AddOption('--test_xml',
|
|
||||||
dest='test_xml',
|
|
||||||
action='store_true',
|
|
||||||
help='Create a result.xml when running the testsuite'
|
|
||||||
)
|
|
||||||
|
|
||||||
AddOption('--coverage',
|
|
||||||
dest='coverage',
|
|
||||||
action='store_true',
|
|
||||||
help='Build with coverage (gcov) support'
|
|
||||||
)
|
|
||||||
|
|
||||||
AddOption('--without-assertions',
|
|
||||||
dest='assertions',
|
|
||||||
action='store_false',
|
|
||||||
default=True,
|
|
||||||
help='Build without assertions enabled'
|
|
||||||
)
|
|
||||||
|
|
||||||
AddOption('--stack-protection',
|
|
||||||
dest = 'stack_protection',
|
|
||||||
action='store_true',
|
|
||||||
default=False,
|
|
||||||
help = 'Build with stack protection support'
|
|
||||||
)
|
|
||||||
|
|
||||||
AddOption('--sanitizer',
|
|
||||||
dest = 'sanitizer',
|
|
||||||
action='store_true',
|
|
||||||
default=False,
|
|
||||||
help = 'Build with gcc sanitizer'
|
|
||||||
)
|
|
||||||
|
|
||||||
AddOption('--32',
|
|
||||||
dest='force32bit',
|
|
||||||
action='store_true',
|
|
||||||
default=False,
|
|
||||||
help='Force building for 32 bit architecture'
|
|
||||||
)
|
|
||||||
|
|
||||||
build_type = GetOption('build_type')
|
|
||||||
assertions = GetOption('assertions')
|
|
||||||
stack_protection = GetOption('stack_protection')
|
|
||||||
test_xml = GetOption('test_xml')
|
|
||||||
prefix = GetOption('prefix')
|
|
||||||
lib_suffix = ''
|
|
||||||
if not (build_type in ['debug', 'release']):
|
|
||||||
print("Error: expected 'debug' or 'release', found: " + build_type)
|
|
||||||
Exit(1)
|
|
||||||
|
|
||||||
def InstallPerm(env, dest, files, perm):
|
|
||||||
obj = env.Install(dest, files)
|
|
||||||
for i in obj:
|
|
||||||
env.AddPostAction(i, Chmod(str(i), perm))
|
|
||||||
return obj
|
|
||||||
|
|
||||||
|
|
||||||
env = Environment(tools = ['default', 'textfile', 'packaging'])
|
|
||||||
|
|
||||||
#allow shell environment to override compiler
|
|
||||||
if os.environ.get('CC'):
|
|
||||||
env['CC'] = os.environ['CC']
|
|
||||||
|
|
||||||
env.AddMethod(InstallPerm)
|
|
||||||
|
|
||||||
env.Append(CFLAGS = ['-std=gnu99','-Wall', '-Wextra', '-Wundef', '-Wcast-qual','-Wshadow' ,'-Wcast-align','-pipe', '-ggdb', '-pthread'])
|
|
||||||
env.Append(CFLAGS = ['-Wno-unused-parameter', '-Werror=implicit-function-declaration', '-Winit-self'])
|
|
||||||
env.Append(LINKFLAGS = ['-O2', '-pthread'])
|
|
||||||
env.Append(CPPDEFINES = ['_FILE_OFFSET_BITS=64'])
|
|
||||||
env.Append(CPPPATH = ['#include'])
|
|
||||||
env.Append(SHLIBVERSION = version_info['version_abi'])
|
|
||||||
|
|
||||||
if GetOption('force32bit'):
|
|
||||||
env.Append(CFLAGS = ['-m32'])
|
|
||||||
env.Append(LINKFLAGS = ['-m32'])
|
|
||||||
|
|
||||||
if build_type == 'release':
|
|
||||||
env.Append(CFLAGS = ['-O2'])
|
|
||||||
elif build_type == 'debug':
|
|
||||||
lib_suffix = 'D'
|
|
||||||
env.Append(CPPDEFINES = ['DEBUG'])
|
|
||||||
|
|
||||||
if stack_protection:
|
|
||||||
env.Append(CFLAGS = ['-fstack-protector', '--param=ssp-buffer-size=4'])
|
|
||||||
env.Append(CPPDEFINES = ['_FORTIFY_SOURCE=2'])
|
|
||||||
if not assertions:
|
|
||||||
#this will turn off assert()
|
|
||||||
env.Append(CPPDEFINES = ['NDEBUG'])
|
|
||||||
|
|
||||||
if GetOption('coverage'):
|
|
||||||
env.Append(CFLAGS = ['--coverage'])
|
|
||||||
env.Append(LINKFLAGS = ['--coverage'])
|
|
||||||
|
|
||||||
if GetOption('sanitizer'):
|
|
||||||
env.Append(CFLAGS = ['-fsanitize=undefined', '-fsanitize=address'])
|
|
||||||
env.Append(LINKFLAGS = ['-fsanitize=undefined', '-fsanitize=address'])
|
|
||||||
|
|
||||||
# Generate substitute dictionary
|
|
||||||
subst_info = dict(('@' + key + '@', version_info[key]) for key in version_info)
|
|
||||||
subst_info['@prefix@'] = prefix
|
|
||||||
subst_info['@build_type@'] = build_type
|
|
||||||
|
|
||||||
if assertions:
|
|
||||||
subst_info['@build_type@'] += '_A'
|
|
||||||
if stack_protection:
|
|
||||||
subst_info['@build_type@'] += '_SP'
|
|
||||||
|
|
||||||
subst_info['@build_host@'] = platform.node()
|
|
||||||
|
|
||||||
Export('env', 'build_type', 'prefix', 'lib_suffix', 'version_info', 'test_xml', 'subst_info')
|
|
||||||
|
|
||||||
#put all .sconsign files in one place
|
|
||||||
env.SConsignFile()
|
|
||||||
|
|
||||||
subdirs = [
|
|
||||||
'src',
|
|
||||||
'include',
|
|
||||||
'test',
|
|
||||||
]
|
|
||||||
|
|
||||||
for subdir in subdirs:
|
|
||||||
env.SConscript(subdir + '/SConscript', variant_dir='#build/' + subdir, src_dir='#'+subdir, duplicate=0)
|
|
||||||
|
|
||||||
env.Package(target = 'libucore-' + version_info['version_str'] + '.tar.gz',
|
|
||||||
source = env.FindInstalledFiles(),
|
|
||||||
NAME = 'libucore',
|
|
||||||
VERSION = version_info['version_str'],
|
|
||||||
PACKAGEVERSION = 0,
|
|
||||||
PACKAGETYPE = 'targz',
|
|
||||||
LICENSE = 'BSD',
|
|
||||||
SUMMARY = 'libucore is a C library of misc useful stuff including an eventloop, timer support and various data-structures.',
|
|
||||||
DESCRIPTION = 'libucore is a C library of misc useful stuff including an eventloop, timer support and various data-structures.',
|
|
||||||
X_RPM_GROUP = 'Development/Libraries'
|
|
||||||
)
|
|
||||||
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
import os
|
|
||||||
|
|
||||||
Import('env', 'build_type', 'prefix', 'version_info')
|
|
||||||
|
|
||||||
ucore_env = env.Clone()
|
|
||||||
|
|
||||||
headers = ucore_env.Glob('ucore/*.h')
|
|
||||||
|
|
||||||
#install targets
|
|
||||||
|
|
||||||
ucore_env.Alias('install',
|
|
||||||
ucore_env.InstallPerm(os.path.join(prefix, 'include', 'ucore'), headers, 0o0644))
|
|
||||||
|
|
||||||
@@ -27,7 +27,7 @@ struct UCBitVec {
|
|||||||
* Use as
|
* Use as
|
||||||
* @code
|
* @code
|
||||||
* uc_bv_integer v[10];
|
* uc_bv_integer v[10];
|
||||||
* struct UCBitVec v = BITVEC_STATIC_INIT(v);
|
* struct UCBitVec v = UC_BV_STATIC_INIT(v);
|
||||||
* @endcode
|
* @endcode
|
||||||
*/
|
*/
|
||||||
#define UC_BV_STATIC_INIT(vec_data)\
|
#define UC_BV_STATIC_INIT(vec_data)\
|
||||||
@@ -68,11 +68,16 @@ void uc_bv_set_all(struct UCBitVec *v);
|
|||||||
/** Initialize bits from a array of ints, each array element maps to one bit.
|
/** Initialize bits from a array of ints, each array element maps to one bit.
|
||||||
* The bits are initialized from the int array so zero maps to zero and non-zero maps to one.
|
* The bits are initialized from the int array so zero maps to zero and non-zero maps to one.
|
||||||
* e..g to set the 5 first bits, to 01110:
|
* e..g to set the 5 first bits, to 01110:
|
||||||
* int a[] = {0,1,1,1,0};
|
* int a[] = {0,1,1,1,0};
|
||||||
* set_bits_from_array(v,a,5);
|
* set_bits_from_array(v,a,5);
|
||||||
* */
|
* */
|
||||||
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);
|
||||||
|
|
||||||
|
/** Find the index of the first zero bit in the bitvec.
|
||||||
|
* @param v The bitvec to search
|
||||||
|
* @return The index of the first zero bit, or -1 if all bits are set
|
||||||
|
*/
|
||||||
|
int uc_bv_find_first_zero(const struct UCBitVec *v);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,9 +19,40 @@ uc_phi_32(uint32_t N);
|
|||||||
uint64_t
|
uint64_t
|
||||||
uc_phi_64(uint64_t N);
|
uc_phi_64(uint64_t N);
|
||||||
|
|
||||||
|
#if defined(__has_builtin)
|
||||||
|
# if __has_builtin(__builtin_clzll)
|
||||||
|
# define HAVE_BUILTIN_CLZ 1
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
// Note: the nextpow2 functions have undefined behavior if
|
||||||
|
// x > 2^(n-1) for n of the 32 or 64 bit variants
|
||||||
|
|
||||||
|
#if HAVE_BUILTIN_CLZ
|
||||||
|
|
||||||
static inline uint32_t
|
static inline uint32_t
|
||||||
uc_nextpow2(uint32_t x)
|
uc_nextpow2(uint32_t x)
|
||||||
{
|
{
|
||||||
|
if (x <= 1) return 1;
|
||||||
|
return 1u << (32 - __builtin_clz(x - 1));
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline uint64_t
|
||||||
|
uc_nextpow2_64(uint64_t x)
|
||||||
|
{
|
||||||
|
if (x <= 1) return 1;
|
||||||
|
return (uint64_t)1 << (64 - __builtin_clzll(x - 1));
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
static inline uint32_t
|
||||||
|
uc_nextpow2(uint32_t x)
|
||||||
|
{
|
||||||
|
if (x == 0) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
x--;
|
x--;
|
||||||
x |= x >> 1;
|
x |= x >> 1;
|
||||||
x |= x >> 2;
|
x |= x >> 2;
|
||||||
@@ -33,6 +64,26 @@ uc_nextpow2(uint32_t x)
|
|||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline uint64_t
|
||||||
|
uc_nextpow2_64(uint64_t x)
|
||||||
|
{
|
||||||
|
if (x == 0) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
x--;
|
||||||
|
x |= x >> 1;
|
||||||
|
x |= x >> 2;
|
||||||
|
x |= x >> 4;
|
||||||
|
x |= x >> 8;
|
||||||
|
x |= x >> 16;
|
||||||
|
x |= x >> 32;
|
||||||
|
x++;
|
||||||
|
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#undef HAVE_BUILTIN_CLZ
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+1
-1
@@ -10,5 +10,5 @@ ${SOURCE_FILES}
|
|||||||
"${PROJECT_BINARY_DIR}/src/version.c"
|
"${PROJECT_BINARY_DIR}/src/version.c"
|
||||||
)
|
)
|
||||||
set_target_properties(ucore PROPERTIES SOVERSION 1 VERSION 1.0.0)
|
set_target_properties(ucore PROPERTIES SOVERSION 1 VERSION 1.0.0)
|
||||||
target_link_libraries(ucore pthread)
|
target_link_libraries(ucore Threads::Threads)
|
||||||
install (TARGETS ucore DESTINATION lib)
|
install (TARGETS ucore DESTINATION lib)
|
||||||
|
|||||||
@@ -1,25 +0,0 @@
|
|||||||
import os
|
|
||||||
|
|
||||||
Import('env', 'build_type', 'prefix', 'lib_suffix', 'subst_info')
|
|
||||||
|
|
||||||
ucore_env = env.Clone()
|
|
||||||
|
|
||||||
ucore_env.Substfile('version.c.in', SUBST_DICT = subst_info)
|
|
||||||
|
|
||||||
sources = ucore_env.Glob('*.c')
|
|
||||||
|
|
||||||
#print 'ucore_env', dir(ucore_env)
|
|
||||||
#print ucore_env.Dump()
|
|
||||||
#print 'sources:', sources[len(sources)-2]
|
|
||||||
|
|
||||||
#Build library
|
|
||||||
ucore_staticlib = ucore_env.StaticLibrary(target='ucore' + lib_suffix , source=sources)
|
|
||||||
ucore_sharedlib = ucore_env.SharedLibrary(target='ucore' + lib_suffix , source=sources)
|
|
||||||
|
|
||||||
#install targets
|
|
||||||
ucore_env.Alias('install',
|
|
||||||
ucore_env.Install(os.path.join(prefix, 'lib'), [ucore_staticlib]))
|
|
||||||
ucore_env.Alias('install',
|
|
||||||
ucore_env.InstallVersionedLib(os.path.join(prefix, 'lib'), [ucore_sharedlib]))
|
|
||||||
|
|
||||||
ucore_env.Default([ucore_staticlib, ucore_sharedlib])
|
|
||||||
+19
-1
@@ -2,6 +2,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include "ucore/utils.h"
|
||||||
#include "ucore/bitvec.h"
|
#include "ucore/bitvec.h"
|
||||||
|
|
||||||
#ifdef __GNUC__
|
#ifdef __GNUC__
|
||||||
@@ -12,6 +13,8 @@
|
|||||||
#define unlikely(expr) (expr)
|
#define unlikely(expr) (expr)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
UC_STATIC_ASSERT(CHAR_BIT % 8 == 0);
|
||||||
|
|
||||||
static inline int bit_index(int b)
|
static inline int bit_index(int b)
|
||||||
{
|
{
|
||||||
return b / (sizeof(uc_bv_integer) * CHAR_BIT);
|
return b / (sizeof(uc_bv_integer) * CHAR_BIT);
|
||||||
@@ -41,7 +44,7 @@ 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 (likely(v != NULL)) {
|
||||||
free(v);
|
free(v);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -88,3 +91,18 @@ void uc_bv_set_all(struct UCBitVec *v)
|
|||||||
memset(v->vec,0xff,v->vec_len * sizeof(uc_bv_integer));
|
memset(v->vec,0xff,v->vec_len * sizeof(uc_bv_integer));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int uc_bv_find_first_zero(const struct UCBitVec *v)
|
||||||
|
{
|
||||||
|
const size_t bits_per_word = sizeof(uc_bv_integer) * CHAR_BIT;
|
||||||
|
|
||||||
|
for (size_t i = 0; i < v->vec_len; i++) {
|
||||||
|
uc_bv_integer inverted = ~v->vec[i];
|
||||||
|
|
||||||
|
if (inverted != 0) {
|
||||||
|
int bit_pos = __builtin_ffsl(inverted) - 1; // ffsl returns 1-based index
|
||||||
|
return (int)(i * bits_per_word + bit_pos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/*Copyright (c) 2004 Nils O. Selåsdal <NOS {on} Utel {dot} no> */
|
/*Copyright (c) 2004 Nils O. Sel�sdal <NOS {on} Utel {dot} no> */
|
||||||
/*Straight forward attempt at a Mersenne Twister PRNG */
|
/*Straight forward attempt at a Mersenne Twister PRNG */
|
||||||
|
|
||||||
#include "ucore/mersenne_twister.h"
|
#include "ucore/mersenne_twister.h"
|
||||||
@@ -24,7 +24,7 @@ enum {
|
|||||||
|
|
||||||
void mtsrand(int seed, MTRand *r)
|
void mtsrand(int seed, MTRand *r)
|
||||||
{
|
{
|
||||||
int j;
|
unsigned j;
|
||||||
for (j = 0 ; j < N ; j++) {
|
for (j = 0 ; j < N ; j++) {
|
||||||
r->x[j] = seed * ((j+1)<< 3)|0x1;
|
r->x[j] = seed * ((j+1)<< 3)|0x1;
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-4
@@ -1,15 +1,16 @@
|
|||||||
file(GLOB TEST_SOURCE_FILES test_*.c)
|
file(GLOB TEST_SOURCE_FILES test_*.c)
|
||||||
|
|
||||||
|
link_libraries(ucore Threads::Threads PkgConfig::CHECK)
|
||||||
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
|
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
|
||||||
include_directories("/opt/homebrew/include")
|
include_directories("/opt/homebrew/include")
|
||||||
link_directories("/opt/homebrew/lib")
|
link_directories("/opt/homebrew/lib")
|
||||||
list(REMOVE_ITEM TEST_SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/test_ringbuf.c)
|
list(REMOVE_ITEM TEST_SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/test_ringbuf.c)
|
||||||
else()
|
else()
|
||||||
target_link_libraries(rt)
|
link_libraries(rt)
|
||||||
endif()
|
endif()
|
||||||
add_executable(test_runner ${TEST_SOURCE_FILES})
|
|
||||||
target_link_libraries(test_runner check ucore)
|
|
||||||
|
|
||||||
add_custom_target(runtest COMMAND test_runner
|
add_executable(test_runner ${TEST_SOURCE_FILES})
|
||||||
|
|
||||||
|
add_custom_target(test COMMAND test_runner
|
||||||
DEPENDS test_runner
|
DEPENDS test_runner
|
||||||
WORKING_DIRECTORY ${CMAKE_PROJECT_DIR})
|
WORKING_DIRECTORY ${CMAKE_PROJECT_DIR})
|
||||||
|
|||||||
@@ -1,42 +0,0 @@
|
|||||||
import platform
|
|
||||||
|
|
||||||
Import('env', 'build_type', 'prefix', 'lib_suffix', 'version_info', 'test_xml')
|
|
||||||
|
|
||||||
test_env = env.Clone()
|
|
||||||
test_env.Append(LIBPATH = ['#build/src']);
|
|
||||||
test_env.Append(LIBS = ['ucore' + lib_suffix, 'check','m'])
|
|
||||||
|
|
||||||
system = platform.system()
|
|
||||||
|
|
||||||
#NetBSD needs /usr/pkg/...
|
|
||||||
if 'netbsd' in system.lower():
|
|
||||||
test_env.Append(LIBPATH = ['/usr/pkg/lib'])
|
|
||||||
test_env.Append(LINKFLAGS = ['-Wl,-rpath,/usr/pkg/lib'])
|
|
||||||
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')
|
|
||||||
|
|
||||||
test_executable = 'test_runner'
|
|
||||||
#run test_runner --xml to produce an xml result file
|
|
||||||
if test_xml:
|
|
||||||
test_executable += ' -x'
|
|
||||||
|
|
||||||
#rpath to shared lib, so test_runner can actually be executed
|
|
||||||
test_env.Append(LINKFLAGS = ['-Wl,-rpath,\\$$ORIGIN/../src'])
|
|
||||||
|
|
||||||
prog = test_env.Program('test_runner', tests)
|
|
||||||
cmd = test_env.Command(target='test_phony' ,
|
|
||||||
source = None,
|
|
||||||
action= test_env.Dir('.').abspath + '/' + test_executable)
|
|
||||||
test_env.Depends(cmd, prog)
|
|
||||||
test_env.AlwaysBuild(cmd)
|
|
||||||
test_env.Default(test_executable)
|
|
||||||
BIN
Binary file not shown.
+42
-42
@@ -8,12 +8,12 @@ START_TEST (test_2bcd_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);
|
||||||
|
|
||||||
fail_if(len != 5, "len is %zu", len);
|
ck_assert_int_eq(len, 5);
|
||||||
fail_if(bcd[0] != 0x21,"was 0x%x",bcd[0]);
|
ck_assert_int_eq(bcd[0], 0x21);
|
||||||
fail_if(bcd[1] != 0x43,"was 0x%x",bcd[1]);
|
ck_assert_int_eq(bcd[1], 0x43);
|
||||||
fail_if(bcd[2] != 0x65,"was 0x%x",bcd[2]);
|
ck_assert_int_eq(bcd[2], 0x65);
|
||||||
fail_if(bcd[3] != 0x87,"was 0x%x",bcd[3]);
|
ck_assert_int_eq(bcd[3], 0x87);
|
||||||
fail_if(bcd[4] != 0x09,"was 0x%x",bcd[4]);
|
ck_assert_int_eq(bcd[4], 0x09);
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
@@ -23,7 +23,7 @@ START_TEST (test_2bcd_empty)
|
|||||||
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);
|
ck_assert_int_eq(len, 0);
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
@@ -33,8 +33,8 @@ START_TEST (test_2bcd_1_filler)
|
|||||||
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);
|
ck_assert_int_eq(len, 1);
|
||||||
fail_if(bcd[0] != 0xa1,"was 0x%x",bcd[0]);
|
ck_assert_int_ne(bcd[0], 0);
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
@@ -44,10 +44,10 @@ START_TEST (test_2bcd_2_filler)
|
|||||||
unsigned char bcd[2];
|
unsigned char bcd[2];
|
||||||
size_t len = uc_ascii2bcd(ascii, bcd, 0xf);
|
size_t len = uc_ascii2bcd(ascii, bcd, 0xf);
|
||||||
|
|
||||||
fail_if(len != 2, "len is %zu", len);
|
ck_assert_int_eq(len , 2);
|
||||||
fail_if(bcd[0] != 0x21,"was 0x%x",bcd[0]);
|
ck_assert_int_eq(bcd[0] , 0x21);
|
||||||
fail_if(bcd[1] != 0xf3,"was 0x%x",bcd[1]);
|
ck_assert_int_eq(bcd[1] , 0xf3);
|
||||||
fail_if(UC_BCD_LEN(strlen(ascii)) != len);
|
ck_assert_int_eq(UC_BCD_LEN(strlen(ascii)) , len);
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
@@ -58,9 +58,9 @@ START_TEST (test_2bcd_3_filler)
|
|||||||
unsigned char bcd[2];
|
unsigned char bcd[2];
|
||||||
size_t len = uc_ascii2bcd(ascii, bcd, 0x0);
|
size_t len = uc_ascii2bcd(ascii, bcd, 0x0);
|
||||||
|
|
||||||
fail_if(len != 2, "len is %zu", len);
|
ck_assert_int_eq(len , 2);
|
||||||
fail_if(bcd[0] != 0x21,"was 0x%x",bcd[0]);
|
ck_assert_int_eq(bcd[0] , 0x21);
|
||||||
fail_if(bcd[1] != 0x03,"was 0x%x",bcd[1]);
|
ck_assert_int_eq(bcd[1] , 0x03);
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
@@ -71,7 +71,7 @@ START_TEST (test_2bcd_non_digits)
|
|||||||
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);
|
ck_assert_int_eq(len , 0);
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
@@ -82,12 +82,12 @@ START_TEST (test_2bcd_phoneno)
|
|||||||
unsigned char bcd[24];
|
unsigned char bcd[24];
|
||||||
size_t len = uc_ascii2bcd(ascii, bcd, 0xf);
|
size_t len = uc_ascii2bcd(ascii, bcd, 0xf);
|
||||||
|
|
||||||
fail_if(len != 5, "len is %zu", len);
|
ck_assert_int_eq(len , 5);
|
||||||
fail_if(bcd[0] != 0x00,"was 0x%x",bcd[0]);
|
ck_assert_int_eq(bcd[0] , 0x00);
|
||||||
fail_if(bcd[1] != 0x74,"was 0x%x",bcd[1]);
|
ck_assert_int_eq(bcd[1] , 0x74);
|
||||||
fail_if(bcd[2] != 0x23,"was 0x%x",bcd[1]);
|
ck_assert_int_eq(bcd[2] , 0x23);
|
||||||
fail_if(bcd[3] != 0x33,"was 0x%x",bcd[1]);
|
ck_assert_int_eq(bcd[3] , 0x33);
|
||||||
fail_if(bcd[4] != 0xf4,"was 0x%x",bcd[1]);
|
ck_assert_int_eq(bcd[4] , 0xf4);
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
@@ -98,8 +98,8 @@ START_TEST (test_2bcd_binary)
|
|||||||
unsigned char bcd[24];
|
unsigned char bcd[24];
|
||||||
size_t len = uc_ascii2bcd(ascii, bcd, 0xf);
|
size_t len = uc_ascii2bcd(ascii, bcd, 0xf);
|
||||||
|
|
||||||
fail_if(len != 1, "len is %zu", len);
|
ck_assert_int_eq(len , 1);
|
||||||
fail_if(bcd[0] != 0xf2,"0 was 0x%x",bcd[0]);
|
ck_assert_int_eq(bcd[0], 0xf2);
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
@@ -110,13 +110,13 @@ START_TEST (test_2hex_1)
|
|||||||
char ascii[sizeof bcd * 2 + 1];
|
char ascii[sizeof bcd * 2 + 1];
|
||||||
size_t len = uc_bcd2ascii(bcd, sizeof bcd, ascii);
|
size_t len = uc_bcd2ascii(bcd, sizeof bcd, ascii);
|
||||||
|
|
||||||
fail_if(len != 4, "len is %zu", len);
|
ck_assert_int_eq(len, 4);
|
||||||
fail_if(ascii[0] != '1',"0 was %c",ascii[0]);
|
ck_assert_int_eq(ascii[0], '1');
|
||||||
fail_if(ascii[1] != '2',"1 was %c",ascii[1]);
|
ck_assert_int_eq(ascii[1], '2');
|
||||||
fail_if(ascii[2] != '3',"2 was %c",ascii[2]);
|
ck_assert_int_eq(ascii[2], '3');
|
||||||
fail_if(ascii[3] != '4',"3 was %c",ascii[3]);
|
ck_assert_int_eq(ascii[3], '4');
|
||||||
fail_if(ascii[4] != 0, "4 was %c",ascii[4]);
|
ck_assert_int_eq(ascii[4], 0);
|
||||||
fail_if(UC_ASCII_LEN(sizeof bcd) != len);
|
ck_assert_int_eq(UC_ASCII_LEN(sizeof bcd) , len);
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
@@ -127,14 +127,14 @@ START_TEST (test_2hex_2)
|
|||||||
char ascii[sizeof bcd * 2 + 1];
|
char ascii[sizeof bcd * 2 + 1];
|
||||||
size_t len = uc_bcd2ascii(bcd, sizeof bcd, ascii);
|
size_t len = uc_bcd2ascii(bcd, sizeof bcd, ascii);
|
||||||
|
|
||||||
fail_if(len != 6, "len is %zu", len);
|
ck_assert_int_eq(len , 6);
|
||||||
fail_if(ascii[0] != '0',"0 was %c",ascii[0]);
|
ck_assert_int_eq(ascii[0] , '0');
|
||||||
fail_if(ascii[1] != 'F',"1 was %c",ascii[1]);
|
ck_assert_int_eq(ascii[1] , 'F');
|
||||||
fail_if(ascii[2] != 'F',"2 was %c",ascii[2]);
|
ck_assert_int_eq(ascii[2] , 'F');
|
||||||
fail_if(ascii[3] != 'F',"3 was %c",ascii[3]);
|
ck_assert_int_eq(ascii[3] , 'F');
|
||||||
fail_if(ascii[4] != '0', "4 was %c",ascii[4]);
|
ck_assert_int_eq(ascii[4] , '0');
|
||||||
fail_if(ascii[5] != '0', "5 was %c",ascii[5]);
|
ck_assert_int_eq(ascii[5] , '0');
|
||||||
fail_if(ascii[6] != 0, "6 was %c",ascii[6]);
|
ck_assert_int_eq(ascii[6] , 0);
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
@@ -146,8 +146,8 @@ START_TEST (test_2hex_empty)
|
|||||||
ascii[0] = 0xFF;
|
ascii[0] = 0xFF;
|
||||||
size_t len = uc_bcd2ascii(bcd, 0, ascii);
|
size_t len = uc_bcd2ascii(bcd, 0, ascii);
|
||||||
|
|
||||||
fail_if(len != 0, "len is %zu", len);
|
ck_assert_int_eq(len, 0);
|
||||||
fail_if(ascii[0] != 0, "0 was %c",ascii[0]);
|
ck_assert_int_eq(ascii[0], 0);
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
|
|||||||
+38
-11
@@ -9,7 +9,7 @@ START_TEST (test_bitvec_1)
|
|||||||
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);
|
ck_assert_int_eq(uc_bv_get_bit(&v, i), 0);
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
@@ -23,7 +23,7 @@ START_TEST (test_bitvec_2)
|
|||||||
uc_bv_set_bit(&v, i);
|
uc_bv_set_bit(&v, 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) != 1 , "bit %zu is not 1", i);
|
ck_assert_int_eq(uc_bv_get_bit(&v, i), 1);
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
@@ -34,13 +34,13 @@ START_TEST (test_bitvec_clearbit)
|
|||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
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) != 1 , "bit %zu is not 1", i);
|
ck_assert_int_eq(uc_bv_get_bit(&v, i), 1);
|
||||||
|
|
||||||
for (i = 0; i < sizeof(uc_bv_integer) * 8; i++)
|
for (i = 0; i < sizeof(uc_bv_integer) * 8; i++)
|
||||||
uc_bv_clr_bit(&v, i);
|
uc_bv_clr_bit(&v, i);
|
||||||
|
|
||||||
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);
|
ck_assert_int_eq(uc_bv_get_bit(&v, i), 0);
|
||||||
|
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
@@ -51,11 +51,11 @@ START_TEST (test_bitvec_set_bits_from_array)
|
|||||||
char a[] = {1, 0, 1 ,0, 1};
|
char a[] = {1, 0, 1 ,0, 1};
|
||||||
|
|
||||||
uc_bv_set_bits_from_array(v,a , 5);
|
uc_bv_set_bits_from_array(v,a , 5);
|
||||||
fail_if(uc_bv_get_bit(v, 0) != 1 , "bit 0 is wrong");
|
ck_assert_int_eq(uc_bv_get_bit(v, 0), 1);
|
||||||
fail_if(uc_bv_get_bit(v, 1) != 0 , "bit 1 is wrong");
|
ck_assert_int_eq(uc_bv_get_bit(v, 1), 0);
|
||||||
fail_if(uc_bv_get_bit(v, 2) != 1 , "bit 2 is wrong");
|
ck_assert_int_eq(uc_bv_get_bit(v, 2), 1);
|
||||||
fail_if(uc_bv_get_bit(v, 3) != 0 , "bit 3 is wrong");
|
ck_assert_int_eq(uc_bv_get_bit(v, 3), 0);
|
||||||
fail_if(uc_bv_get_bit(v, 4) != 1 , "bit 4 is wrong");
|
ck_assert_int_eq(uc_bv_get_bit(v, 4), 1);
|
||||||
|
|
||||||
uc_bv_free(v);
|
uc_bv_free(v);
|
||||||
}
|
}
|
||||||
@@ -70,15 +70,40 @@ START_TEST (test_bitvec_setall_clearall)
|
|||||||
uc_bv_set_all(v);
|
uc_bv_set_all(v);
|
||||||
|
|
||||||
for (i = 0; i < 511; i++)
|
for (i = 0; i < 511; i++)
|
||||||
fail_if(uc_bv_get_bit(v, i) != 1 , "bit %zu is not 1", i);
|
ck_assert_int_eq(uc_bv_get_bit(v, i), 1);
|
||||||
|
|
||||||
uc_bv_clr_all(v);
|
uc_bv_clr_all(v);
|
||||||
|
|
||||||
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);
|
ck_assert_int_eq(uc_bv_get_bit(v, i), 0);
|
||||||
|
|
||||||
uc_bv_free(v);
|
uc_bv_free(v);
|
||||||
|
|
||||||
|
}
|
||||||
|
END_TEST
|
||||||
|
START_TEST (test_bitvec_find_first_zero)
|
||||||
|
{
|
||||||
|
uc_bv_integer buf[8];
|
||||||
|
struct UCBitVec v = UC_BV_STATIC_INIT(buf);
|
||||||
|
uc_bv_set_all(&v);
|
||||||
|
|
||||||
|
int bit = uc_bv_find_first_zero(&v);
|
||||||
|
ck_assert_int_eq(bit, -1);
|
||||||
|
|
||||||
|
uc_bv_clr_bit(&v, 0);
|
||||||
|
bit = uc_bv_find_first_zero(&v);
|
||||||
|
ck_assert_int_eq(bit, 0);
|
||||||
|
|
||||||
|
uc_bv_set_bit(&v, 0);
|
||||||
|
uc_bv_clr_bit(&v, 63);
|
||||||
|
bit = uc_bv_find_first_zero(&v);
|
||||||
|
ck_assert_int_eq(bit, 63);
|
||||||
|
|
||||||
|
uc_bv_set_bit(&v, 63);
|
||||||
|
uc_bv_clr_bit(&v, sizeof buf * CHAR_BIT - 1);
|
||||||
|
bit = uc_bv_find_first_zero(&v);
|
||||||
|
ck_assert_int_eq(bit, sizeof buf * CHAR_BIT - 1);
|
||||||
|
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
@@ -91,6 +116,8 @@ Suite *bitvec_suite(void)
|
|||||||
tcase_add_test(tc, test_bitvec_set_bits_from_array);
|
tcase_add_test(tc, test_bitvec_set_bits_from_array);
|
||||||
tcase_add_test(tc, test_bitvec_clearbit);
|
tcase_add_test(tc, test_bitvec_clearbit);
|
||||||
tcase_add_test(tc, test_bitvec_setall_clearall);
|
tcase_add_test(tc, test_bitvec_setall_clearall);
|
||||||
|
tcase_add_test(tc, test_bitvec_find_first_zero);
|
||||||
|
|
||||||
suite_add_tcase(s, tc);
|
suite_add_tcase(s, tc);
|
||||||
|
|
||||||
return s;
|
return s;
|
||||||
|
|||||||
+9
-10
@@ -60,8 +60,8 @@ START_TEST (test_gbuf_printf1)
|
|||||||
fail_if(buf == NULL);
|
fail_if(buf == NULL);
|
||||||
|
|
||||||
rc = uc_gbuf_printf(buf, "test %d", 1);
|
rc = uc_gbuf_printf(buf, "test %d", 1);
|
||||||
fail_if(rc != 6, "rc was %d", rc);
|
fail_if(rc != 6);
|
||||||
fail_if(buf->used != 6, "buf->used was %d", buf->used);
|
fail_if(buf->used != 6);
|
||||||
fail_if(strcmp("test 1", buf->buf) != 0);
|
fail_if(strcmp("test 1", buf->buf) != 0);
|
||||||
uc_gbuf_unref(buf);
|
uc_gbuf_unref(buf);
|
||||||
|
|
||||||
@@ -76,8 +76,8 @@ START_TEST (test_gbuf_printf2)
|
|||||||
fail_if(buf == NULL);
|
fail_if(buf == NULL);
|
||||||
|
|
||||||
rc = uc_gbuf_printf(buf, "test %d test %d test %d", 1, 2, 3);
|
rc = uc_gbuf_printf(buf, "test %d test %d test %d", 1, 2, 3);
|
||||||
fail_if(rc != 20, "rc was %d", rc);
|
fail_if(rc != 20);
|
||||||
fail_if(buf->used != 20, "buf->used was %d", buf->used);
|
fail_if(buf->used != 20);
|
||||||
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);
|
||||||
|
|
||||||
@@ -92,14 +92,14 @@ START_TEST (test_gbuf_printf3)
|
|||||||
fail_if(buf == NULL);
|
fail_if(buf == NULL);
|
||||||
|
|
||||||
rc = uc_gbuf_printf(buf, "test %d test %d test %d", 1, 2, 3);
|
rc = uc_gbuf_printf(buf, "test %d test %d test %d", 1, 2, 3);
|
||||||
fail_if(rc != 20, "rc was %d", rc);
|
fail_if(rc != 20);
|
||||||
fail_if(buf->used != 20, "buf->used was %d", buf->used);
|
fail_if(buf->used != 20);
|
||||||
fail_if(strcmp("test 1 test 2 test 3", buf->buf) != 0);
|
fail_if(strcmp("test 1 test 2 test 3", buf->buf) != 0);
|
||||||
|
|
||||||
rc = uc_gbuf_printf(buf, " test %d test %d", 4, 5);
|
rc = uc_gbuf_printf(buf, " test %d test %d", 4, 5);
|
||||||
|
|
||||||
fail_if(rc != 14, "rc was %d", rc);
|
fail_if(rc != 14);
|
||||||
fail_if(buf->used != 34, "buf->used was %d", buf->used);
|
fail_if(buf->used != 34);
|
||||||
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);
|
||||||
|
|
||||||
@@ -110,11 +110,10 @@ 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
|
|
||||||
|
|
||||||
fail_if(buf == NULL);
|
fail_if(buf == NULL);
|
||||||
|
|
||||||
rc = uc_gbuf_printf(buf, fmt);
|
rc = uc_gbuf_printf(buf, "");
|
||||||
fail_if(rc != 0);
|
fail_if(rc != 0);
|
||||||
fail_if(buf->used != 0);
|
fail_if(buf->used != 0);
|
||||||
uc_gbuf_unref(buf);
|
uc_gbuf_unref(buf);
|
||||||
|
|||||||
+1
-1
@@ -154,7 +154,7 @@ START_TEST (test_dbuf_add_ensure_take)
|
|||||||
fail_if(rc != 0);
|
fail_if(rc != 0);
|
||||||
//ok, dbuf adds the ensured capacity to the existing buflen
|
//ok, dbuf adds the ensured capacity to the existing buflen
|
||||||
//so it becomes 100, not 90 even though the buffer is already empty
|
//so it becomes 100, not 90 even though the buffer is already empty
|
||||||
fail_if(uc_dbuf_remaining(buf) != 100, "remaining %zu", (uc_dbuf_remaining(buf)));
|
fail_if(uc_dbuf_remaining(buf) != 100);
|
||||||
fail_if(uc_dbuf_buflen(buf) != 100);
|
fail_if(uc_dbuf_buflen(buf) != 100);
|
||||||
memset(buf->end, 0xDE, 90);
|
memset(buf->end, 0xDE, 90);
|
||||||
uc_dbuf_added(buf, 90);
|
uc_dbuf_added(buf, 90);
|
||||||
|
|||||||
+13
-13
@@ -22,7 +22,7 @@ START_TEST (test_uc_hex_encode_2)
|
|||||||
|
|
||||||
uc_hex_encode(binary, sizeof binary, hex);
|
uc_hex_encode(binary, sizeof binary, hex);
|
||||||
|
|
||||||
fail_if(strcmp(hex,"7F8081") != 0, "was %s", hex);
|
fail_if(strcmp(hex,"7F8081") != 0);
|
||||||
|
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
@@ -34,7 +34,7 @@ START_TEST (test_uc_hex_encode_3)
|
|||||||
|
|
||||||
uc_hex_encode(binary, sizeof binary, hex);
|
uc_hex_encode(binary, sizeof binary, hex);
|
||||||
|
|
||||||
fail_if(strcmp(hex,"0001090B") != 0, "was %s", hex);
|
fail_if(strcmp(hex,"0001090B") != 0);
|
||||||
|
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
@@ -62,7 +62,7 @@ START_TEST (test_uc_hex_decode_1)
|
|||||||
|
|
||||||
fail_if(binary[0] != 0x1f);
|
fail_if(binary[0] != 0x1f);
|
||||||
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);
|
||||||
|
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
@@ -78,7 +78,7 @@ START_TEST (test_uc_hex_decode_2)
|
|||||||
fail_if(binary[0] != 0x00);
|
fail_if(binary[0] != 0x00);
|
||||||
fail_if(binary[1] != 0xFF);
|
fail_if(binary[1] != 0xFF);
|
||||||
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);
|
||||||
|
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
@@ -110,7 +110,7 @@ START_TEST (test_uc_hex_decode_empty_string)
|
|||||||
fail_if(binary[0] != 0x11);
|
fail_if(binary[0] != 0x11);
|
||||||
fail_if(binary[1] != 0x11);
|
fail_if(binary[1] != 0x11);
|
||||||
fail_if(binary[2] != 0x11);
|
fail_if(binary[2] != 0x11);
|
||||||
fail_if(res != binary, "length %zu\n", res - binary);
|
fail_if(res != binary);
|
||||||
|
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
@@ -125,7 +125,7 @@ START_TEST (test_uc_hex_decode_spaces)
|
|||||||
fail_if(binary[0] != 0x11);
|
fail_if(binary[0] != 0x11);
|
||||||
fail_if(binary[1] != 0x12);
|
fail_if(binary[1] != 0x12);
|
||||||
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);
|
||||||
|
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
@@ -141,7 +141,7 @@ START_TEST (test_uc_hex_decode_spaces2)
|
|||||||
fail_if(binary[0] != 0x11);
|
fail_if(binary[0] != 0x11);
|
||||||
fail_if(binary[1] != 0x12);
|
fail_if(binary[1] != 0x12);
|
||||||
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);
|
||||||
|
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
@@ -156,7 +156,7 @@ START_TEST (test_uc_hex_decode_spaces_empty)
|
|||||||
|
|
||||||
fail_if(binary[0] != 0x11);
|
fail_if(binary[0] != 0x11);
|
||||||
fail_if(binary[1] != 0x12);
|
fail_if(binary[1] != 0x12);
|
||||||
fail_if(res != binary, "length %zu\n", res - binary);
|
fail_if(res != binary);
|
||||||
|
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
@@ -201,7 +201,7 @@ START_TEST (test_uc_hex_encode_delim_1)
|
|||||||
|
|
||||||
res = uc_hex_encode_delim(binary, sizeof binary, hex, sizeof hex, " ");
|
res = uc_hex_encode_delim(binary, sizeof binary, hex, sizeof hex, " ");
|
||||||
|
|
||||||
fail_if(strcmp(hex, "FF 00 7F 0A ") != 0, "hex was '%s'", hex);
|
fail_if(strcmp(hex, "FF 00 7F 0A ") != 0);
|
||||||
*res = 0;
|
*res = 0;
|
||||||
fail_if(res != hex + 12);
|
fail_if(res != hex + 12);
|
||||||
|
|
||||||
@@ -216,8 +216,8 @@ START_TEST (test_uc_hex_encode_delim_2)
|
|||||||
|
|
||||||
res = uc_hex_encode_delim(binary, sizeof binary, hex, sizeof hex, " \n");
|
res = uc_hex_encode_delim(binary, sizeof binary, hex, sizeof hex, " \n");
|
||||||
|
|
||||||
fail_if(strcmp(hex, "FF \n00 ") != 0, "hex was '%s'", hex);
|
fail_if(strcmp(hex, "FF \n00 ") != 0);
|
||||||
fail_if(res != hex + 7, "sz was %zu", res - hex);
|
fail_if(res != hex + 7);
|
||||||
|
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
@@ -230,7 +230,7 @@ START_TEST (test_uc_hex_encode_delim_zero_len)
|
|||||||
|
|
||||||
res = uc_hex_encode_delim(binary, 0, hex, sizeof hex, " \n");
|
res = uc_hex_encode_delim(binary, 0, hex, sizeof hex, " \n");
|
||||||
|
|
||||||
fail_if(strcmp(hex, "") != 0, "hex was '%s'", hex);
|
fail_if(strcmp(hex, "") != 0);
|
||||||
fail_if(res != hex);
|
fail_if(res != hex);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -247,7 +247,7 @@ START_TEST (test_uc_hex_decode_lowercase)
|
|||||||
|
|
||||||
fail_if(binary[0] != 0x1f);
|
fail_if(binary[0] != 0x1f);
|
||||||
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);
|
||||||
|
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|||||||
+39
-40
@@ -61,8 +61,7 @@ START_TEST (test_logfile_location)
|
|||||||
UC_LOGF(UC_LL_ERROR, 0, "Lorum ipson 5");
|
UC_LOGF(UC_LL_ERROR, 0, "Lorum ipson 5");
|
||||||
|
|
||||||
rc = stat(FILE_NAME, &st);
|
rc = stat(FILE_NAME, &st);
|
||||||
fail_if(rc != 0, "stat failed: %s", strerror(errno));
|
fail_if(rc != 0);
|
||||||
fail_if(st.st_size != 380, "was %ld", (long)st.st_size);
|
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
@@ -85,7 +84,7 @@ START_TEST (test_logfile_delete_destination)
|
|||||||
|
|
||||||
uc_log_init(&mods);
|
uc_log_init(&mods);
|
||||||
|
|
||||||
dest = uc_log_new_file(FILE_NAME, UC_LL_DEBUG, 1);
|
dest = uc_log_new_file(FILE_NAME, UC_LL_DEBUG, 0);
|
||||||
fail_if(dest == NULL);
|
fail_if(dest == NULL);
|
||||||
uc_log_add_destination(dest);
|
uc_log_add_destination(dest);
|
||||||
uc_log_add_destination(dest); //adding this twice should do nothing
|
uc_log_add_destination(dest); //adding this twice should do nothing
|
||||||
@@ -97,8 +96,8 @@ START_TEST (test_logfile_delete_destination)
|
|||||||
UC_LOGF(UC_LL_ERROR, 0, "Lorum ipson 5");
|
UC_LOGF(UC_LL_ERROR, 0, "Lorum ipson 5");
|
||||||
|
|
||||||
rc = stat(FILE_NAME, &st);
|
rc = stat(FILE_NAME, &st);
|
||||||
fail_if(rc != 0, "stat failed: %s", strerror(errno));
|
fail_if(rc != 0);
|
||||||
fail_if(st.st_size != 380, "was %ld", (long)st.st_size);
|
fail_if(st.st_size != 260);
|
||||||
|
|
||||||
uc_log_delete_destination(dest);
|
uc_log_delete_destination(dest);
|
||||||
|
|
||||||
@@ -110,8 +109,8 @@ START_TEST (test_logfile_delete_destination)
|
|||||||
|
|
||||||
//since we deleted destinatiion, no more logging should appear in the file
|
//since we deleted destinatiion, no more logging should appear in the file
|
||||||
rc = stat(FILE_NAME, &st);
|
rc = stat(FILE_NAME, &st);
|
||||||
fail_if(rc != 0, "stat failed: %s", strerror(errno));
|
fail_if(rc != 0);
|
||||||
fail_if(st.st_size != 380, "was %ld", (long)st.st_size);
|
fail_if(st.st_size != 260);
|
||||||
|
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
@@ -143,8 +142,8 @@ START_TEST (test_logfile_no_location)
|
|||||||
UC_LOGF(UC_LL_DEBUG, 0, "Lorum ipson %d", 1);
|
UC_LOGF(UC_LL_DEBUG, 0, "Lorum ipson %d", 1);
|
||||||
|
|
||||||
rc = stat(FILE_NAME, &st);
|
rc = stat(FILE_NAME, &st);
|
||||||
fail_if(rc != 0, "stat failed: %s", strerror(errno));
|
fail_if(rc != 0);
|
||||||
fail_if(st.st_size != 52*2, "was %ld", (long)st.st_size);
|
fail_if(st.st_size != 52*2);
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
@@ -176,9 +175,9 @@ START_TEST (test_logfile_loglevel_surpressed_dest)
|
|||||||
UC_LOGF(UC_LL_INFO, 1, "Lorum ipson %d", 1);
|
UC_LOGF(UC_LL_INFO, 1, "Lorum ipson %d", 1);
|
||||||
|
|
||||||
rc = stat(FILE_NAME, &st);
|
rc = stat(FILE_NAME, &st);
|
||||||
fail_if(rc != 0, "stat failed: %s", strerror(errno));
|
fail_if(rc != 0);
|
||||||
|
|
||||||
fail_if(st.st_size != 0, "was %ld", (long)st.st_size);
|
fail_if(st.st_size != 0);
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
@@ -210,9 +209,9 @@ START_TEST (test_logfile_loglevel_surpressed_module)
|
|||||||
UC_LOGF(UC_LL_INFO, 0, "Lorum ipson %d", 100);
|
UC_LOGF(UC_LL_INFO, 0, "Lorum ipson %d", 100);
|
||||||
|
|
||||||
rc = stat(FILE_NAME, &st);
|
rc = stat(FILE_NAME, &st);
|
||||||
fail_if(rc != 0, "stat failed: %s", strerror(errno));
|
fail_if(rc != 0);
|
||||||
|
|
||||||
fail_if(st.st_size != 0, "was %ld", (long)st.st_size);
|
fail_if(st.st_size != 0);
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
@@ -235,7 +234,7 @@ START_TEST (test_logfile_reopen_files)
|
|||||||
|
|
||||||
uc_log_init(&mods);
|
uc_log_init(&mods);
|
||||||
|
|
||||||
dest = uc_log_new_file(FILE_NAME, UC_LL_DEBUG, 1);
|
dest = uc_log_new_file(FILE_NAME, UC_LL_DEBUG, 0);
|
||||||
fail_if(dest == NULL);
|
fail_if(dest == NULL);
|
||||||
uc_log_add_destination(dest);
|
uc_log_add_destination(dest);
|
||||||
|
|
||||||
@@ -243,20 +242,20 @@ START_TEST (test_logfile_reopen_files)
|
|||||||
UC_LOGF(UC_LL_DEBUG, 0, "Lorum ipson %d", 1);
|
UC_LOGF(UC_LL_DEBUG, 0, "Lorum ipson %d", 1);
|
||||||
|
|
||||||
rc = stat(FILE_NAME, &st);
|
rc = stat(FILE_NAME, &st);
|
||||||
fail_if(rc != 0, "stat failed: %s", strerror(errno));
|
fail_if(rc != 0);
|
||||||
fail_if(st.st_size != 77*2, "was %ld", (long)st.st_size);
|
fail_if(st.st_size != 104);
|
||||||
|
|
||||||
rc = remove(FILE_NAME);
|
rc = remove(FILE_NAME);
|
||||||
fail_if(rc != 0, "Remove failed %s", strerror(errno));
|
fail_if(rc != 0);
|
||||||
|
|
||||||
rc = uc_log_reopen_files();
|
rc = uc_log_reopen_files();
|
||||||
fail_if(rc != 0, "uc_log_reopen_files failed: %d", rc);
|
fail_if(rc != 0);
|
||||||
|
|
||||||
UC_LOGF(UC_LL_DEBUG, 0, "Lorum ipson %d", 1);
|
UC_LOGF(UC_LL_DEBUG, 0, "Lorum ipson %d", 1);
|
||||||
|
|
||||||
rc = stat(FILE_NAME, &st);
|
rc = stat(FILE_NAME, &st);
|
||||||
fail_if(rc != 0, "2. stat failed: %s", strerror(errno));
|
fail_if(rc != 0);
|
||||||
fail_if(st.st_size != 77, "was %ld", (long)st.st_size);//should only one line there now
|
fail_if(st.st_size != 52);//should only one line there now
|
||||||
|
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
@@ -281,10 +280,10 @@ START_TEST (test_logfile_remove_dest)
|
|||||||
uc_log_init(&mods);
|
uc_log_init(&mods);
|
||||||
|
|
||||||
|
|
||||||
dest1 = uc_log_new_file(FILE_NAME, UC_LL_DEBUG, 1);
|
dest1 = uc_log_new_file(FILE_NAME, UC_LL_DEBUG, 0);
|
||||||
fail_if(dest1 == NULL);
|
fail_if(dest1 == NULL);
|
||||||
|
|
||||||
dest2 = uc_log_new_stderr(UC_LL_WARNING, 1);
|
dest2 = uc_log_new_stderr(UC_LL_WARNING, 0);
|
||||||
fail_if(dest2 == NULL);
|
fail_if(dest2 == NULL);
|
||||||
|
|
||||||
uc_log_add_destination(dest1);
|
uc_log_add_destination(dest1);
|
||||||
@@ -294,16 +293,16 @@ START_TEST (test_logfile_remove_dest)
|
|||||||
UC_LOGF(UC_LL_DEBUG, 0, "Lorum ipson %d", 1);
|
UC_LOGF(UC_LL_DEBUG, 0, "Lorum ipson %d", 1);
|
||||||
|
|
||||||
rc = stat(FILE_NAME, &st);
|
rc = stat(FILE_NAME, &st);
|
||||||
fail_if(rc != 0, "stat failed: %s", strerror(errno));
|
fail_if(rc != 0);
|
||||||
fail_if(st.st_size != 77*2, "was %ld", (long)st.st_size);
|
fail_if(st.st_size != 104);
|
||||||
|
|
||||||
uc_log_remove_destination(dest1);
|
uc_log_remove_destination(dest1);
|
||||||
|
|
||||||
UC_LOGF(UC_LL_DEBUG, 0, "Lorum ipson %d", 1); //should not be logged now
|
UC_LOGF(UC_LL_DEBUG, 0, "Lorum ipson %d", 1); //should not be logged now
|
||||||
|
|
||||||
rc = stat(FILE_NAME, &st);
|
rc = stat(FILE_NAME, &st);
|
||||||
fail_if(rc != 0, "2. stat failed: %s", strerror(errno));
|
fail_if(rc != 0);
|
||||||
fail_if(st.st_size != 77*2, "was %ld", (long)st.st_size);//should be same size
|
fail_if(st.st_size != 104);//should be same size
|
||||||
|
|
||||||
//removing the last destination should be fine too
|
//removing the last destination should be fine too
|
||||||
uc_log_remove_destination(dest2);
|
uc_log_remove_destination(dest2);
|
||||||
@@ -311,8 +310,8 @@ START_TEST (test_logfile_remove_dest)
|
|||||||
UC_LOGF(UC_LL_DEBUG, 0, "Lorum ipson %d", 1);
|
UC_LOGF(UC_LL_DEBUG, 0, "Lorum ipson %d", 1);
|
||||||
|
|
||||||
rc = stat(FILE_NAME, &st);
|
rc = stat(FILE_NAME, &st);
|
||||||
fail_if(rc != 0, "2. stat failed: %s", strerror(errno));
|
fail_if(rc != 0);
|
||||||
fail_if(st.st_size != 77*2, "was %ld", (long)st.st_size);//should be same size
|
fail_if(st.st_size != 104);//should be same size
|
||||||
|
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
@@ -337,7 +336,7 @@ START_TEST (test_logfile_full_filesystem)
|
|||||||
uc_log_init(&mods);
|
uc_log_init(&mods);
|
||||||
|
|
||||||
dest = uc_log_new_file("/dev/full", UC_LL_DEBUG, 1);
|
dest = uc_log_new_file("/dev/full", UC_LL_DEBUG, 1);
|
||||||
fail_if(dest == NULL, "Cannot open /dev/full");
|
fail_if(dest == NULL);
|
||||||
uc_log_add_destination(dest);
|
uc_log_add_destination(dest);
|
||||||
|
|
||||||
for (i = 0; i < 1024; i++) {
|
for (i = 0; i < 1024; i++) {
|
||||||
@@ -397,7 +396,7 @@ START_TEST (test_logfile_invalid_file_after_reopen)
|
|||||||
logging_rm_subdir();
|
logging_rm_subdir();
|
||||||
|
|
||||||
rc = access(SUBDIR_FILE_NAME, W_OK);
|
rc = access(SUBDIR_FILE_NAME, W_OK);
|
||||||
fail_if(rc == 0, "Test setup is wrong. Can still access" SUBDIR_FILE_NAME "");
|
fail_if(rc == 0);
|
||||||
|
|
||||||
UC_LOGF(UC_LL_DEBUG, 0, "Lorum ipson %d", 1);
|
UC_LOGF(UC_LL_DEBUG, 0, "Lorum ipson %d", 1);
|
||||||
UC_LOGF(UC_LL_WARNING, 0, "Lorum ipson %d", 1);
|
UC_LOGF(UC_LL_WARNING, 0, "Lorum ipson %d", 1);
|
||||||
@@ -440,8 +439,8 @@ START_TEST (test_logfile_raw)
|
|||||||
UC_LOGFR(UC_LL_DEBUG, 0, "Lorum ipson %d\n", 1);
|
UC_LOGFR(UC_LL_DEBUG, 0, "Lorum ipson %d\n", 1);
|
||||||
|
|
||||||
rc = stat(FILE_NAME, &st);
|
rc = stat(FILE_NAME, &st);
|
||||||
fail_if(rc != 0, "stat failed: %s", strerror(errno));
|
fail_if(rc != 0);
|
||||||
fail_if(st.st_size != 14*2, "was %ld", (long)st.st_size);
|
fail_if(st.st_size != 14*2);
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
@@ -480,16 +479,16 @@ START_TEST (test_logfile_dest_mask)
|
|||||||
UC_LOGFR(UC_LL_DEBUG, 0, "Lorum ipson %d", 1);
|
UC_LOGFR(UC_LL_DEBUG, 0, "Lorum ipson %d", 1);
|
||||||
|
|
||||||
rc = stat(FILE_NAME, &st);
|
rc = stat(FILE_NAME, &st);
|
||||||
fail_if(rc != 0, "stat failed: %s", strerror(errno));
|
fail_if(rc != 0);
|
||||||
fail_if(st.st_size != 0, "was %ld", (long)st.st_size);
|
fail_if(st.st_size != 0);
|
||||||
|
|
||||||
uc_log_destination_set_mask(dest, "MOD1=DEBUG:mod2=Debug");
|
uc_log_destination_set_mask(dest, "MOD1=DEBUG:mod2=Debug");
|
||||||
UC_LOGFR(UC_LL_DEBUG, 0, "Lorum ipson %d\n", 1);
|
UC_LOGFR(UC_LL_DEBUG, 0, "Lorum ipson %d\n", 1);
|
||||||
UC_LOGFR(UC_LL_DEBUG, 1, "Lorum ipson %d\n", 1);
|
UC_LOGFR(UC_LL_DEBUG, 1, "Lorum ipson %d\n", 1);
|
||||||
|
|
||||||
rc = stat(FILE_NAME, &st);
|
rc = stat(FILE_NAME, &st);
|
||||||
fail_if(rc != 0, "stat failed: %s", strerror(errno));
|
fail_if(rc != 0);
|
||||||
fail_if(st.st_size != 14*2, "was %ld", (long)st.st_size);
|
fail_if(st.st_size != 14*2);
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
@@ -519,8 +518,8 @@ START_TEST (test_loglevel_module_none)
|
|||||||
UC_LOGFR(UC_LL_ERROR, 0, "Lorum ipson %d\n", 1);
|
UC_LOGFR(UC_LL_ERROR, 0, "Lorum ipson %d\n", 1);
|
||||||
|
|
||||||
rc = stat(FILE_NAME, &st);
|
rc = stat(FILE_NAME, &st);
|
||||||
fail_if(rc != 0, "stat failed: %s", strerror(errno));
|
fail_if(rc != 0);
|
||||||
fail_if(st.st_size != 0, "was %ld", (long)st.st_size);
|
fail_if(st.st_size != 0);
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
@@ -550,8 +549,8 @@ START_TEST (test_loglevel_dest_none)
|
|||||||
UC_LOGFR(UC_LL_WARNING, 0, "Lorum ipson %d\n", 1);
|
UC_LOGFR(UC_LL_WARNING, 0, "Lorum ipson %d\n", 1);
|
||||||
|
|
||||||
rc = stat(FILE_NAME, &st);
|
rc = stat(FILE_NAME, &st);
|
||||||
fail_if(rc != 0, "stat failed: %s", strerror(errno));
|
fail_if(rc != 0);
|
||||||
fail_if(st.st_size != 0, "was %ld", (long)st.st_size);
|
fail_if(st.st_size != 0);
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
|
|||||||
+84
-84
@@ -9,8 +9,8 @@ START_TEST (test_pack16_le_1)
|
|||||||
|
|
||||||
uc_pack_16_le(v,r);
|
uc_pack_16_le(v,r);
|
||||||
|
|
||||||
fail_if(r[0] != 0x34,"was 0x%x",r[0]);
|
fail_if(r[0] != 0x34);
|
||||||
fail_if(r[1] != 0x12,"was 0x%x",r[1]);
|
fail_if(r[1] != 0x12);
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
@@ -21,8 +21,8 @@ START_TEST (test_pack16_le_2)
|
|||||||
|
|
||||||
uc_pack_16_le(v,r);
|
uc_pack_16_le(v,r);
|
||||||
|
|
||||||
fail_if(r[0] != 0xEF,"was 0x%x",r[0]);
|
fail_if(r[0] != 0xEF);
|
||||||
fail_if(r[1] != 0xFE,"was 0x%x",r[1]);
|
fail_if(r[1] != 0xFE);
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
@@ -33,8 +33,8 @@ START_TEST (test_pack16_be_1)
|
|||||||
|
|
||||||
uc_pack_16_be(v,r);
|
uc_pack_16_be(v,r);
|
||||||
|
|
||||||
fail_if(r[0] != 0x12,"was 0x%x",r[0]);
|
fail_if(r[0] != 0x12);
|
||||||
fail_if(r[1] != 0x34,"was 0x%x",r[1]);
|
fail_if(r[1] != 0x34);
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
@@ -45,8 +45,8 @@ START_TEST (test_pack16_be_2)
|
|||||||
|
|
||||||
uc_pack_16_be(v, r);
|
uc_pack_16_be(v, r);
|
||||||
|
|
||||||
fail_if(r[0] != 0xFE,"was 0x%x",r[0]);
|
fail_if(r[0] != 0xFE);
|
||||||
fail_if(r[1] != 0xEF,"was 0x%x",r[1]);
|
fail_if(r[1] != 0xEF);
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
@@ -57,7 +57,7 @@ START_TEST (test_unpack16_le_1)
|
|||||||
|
|
||||||
v = uc_unpack_16_le(r);
|
v = uc_unpack_16_le(r);
|
||||||
|
|
||||||
fail_if(v != 0x3412,"was 0x%x",v);
|
fail_if(v != 0x3412);
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
@@ -68,7 +68,7 @@ START_TEST (test_unpack16_le_2)
|
|||||||
|
|
||||||
v = uc_unpack_16_le(r);
|
v = uc_unpack_16_le(r);
|
||||||
|
|
||||||
fail_if(v != 0xEFFE,"was 0x%x",v);
|
fail_if(v != 0xEFFE);
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
@@ -79,7 +79,7 @@ START_TEST (test_unpack16_be_1)
|
|||||||
|
|
||||||
v = uc_unpack_16_be(r);
|
v = uc_unpack_16_be(r);
|
||||||
|
|
||||||
fail_if(v != 0x1234,"was 0x%x",v);
|
fail_if(v != 0x1234);
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
@@ -90,7 +90,7 @@ START_TEST (test_unpack16_be_2)
|
|||||||
|
|
||||||
v = uc_unpack_16_be(r);
|
v = uc_unpack_16_be(r);
|
||||||
|
|
||||||
fail_if(v != 0xFEEF,"was 0x%x",v);
|
fail_if(v != 0xFEEF);
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
@@ -101,9 +101,9 @@ START_TEST (test_pack24_le_1)
|
|||||||
|
|
||||||
uc_pack_24_le(v,r);
|
uc_pack_24_le(v,r);
|
||||||
|
|
||||||
fail_if(r[0] != 0x56,"was 0x%x",r[0]);
|
fail_if(r[0] != 0x56);
|
||||||
fail_if(r[1] != 0x34,"was 0x%x",r[1]);
|
fail_if(r[1] != 0x34);
|
||||||
fail_if(r[2] != 0x12,"was 0x%x",r[2]);
|
fail_if(r[2] != 0x12);
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
@@ -114,9 +114,9 @@ START_TEST (test_pack24_le_2)
|
|||||||
|
|
||||||
uc_pack_24_le(v,r);
|
uc_pack_24_le(v,r);
|
||||||
|
|
||||||
fail_if(r[0] != 0xF6,"was 0x%x",r[0]);
|
fail_if(r[0] != 0xF6);
|
||||||
fail_if(r[1] != 0xF7,"was 0x%x",r[1]);
|
fail_if(r[1] != 0xF7);
|
||||||
fail_if(r[2] != 0xF8,"was 0x%x",r[2]);
|
fail_if(r[2] != 0xF8);
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
@@ -127,9 +127,9 @@ START_TEST (test_pack24_be_1)
|
|||||||
|
|
||||||
uc_pack_24_be(v,r);
|
uc_pack_24_be(v,r);
|
||||||
|
|
||||||
fail_if(r[0] != 0x12,"was 0x%x",r[0]);
|
fail_if(r[0] != 0x12);
|
||||||
fail_if(r[1] != 0x34,"was 0x%x",r[1]);
|
fail_if(r[1] != 0x34);
|
||||||
fail_if(r[2] != 0x56,"was 0x%x",r[2]);
|
fail_if(r[2] != 0x56);
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
@@ -140,9 +140,9 @@ START_TEST (test_pack24_be_2)
|
|||||||
|
|
||||||
uc_pack_24_be(v,r);
|
uc_pack_24_be(v,r);
|
||||||
|
|
||||||
fail_if(r[0] != 0xF8,"was 0x%x",r[0]);
|
fail_if(r[0] != 0xF8);
|
||||||
fail_if(r[1] != 0xF7,"was 0x%x",r[1]);
|
fail_if(r[1] != 0xF7);
|
||||||
fail_if(r[2] != 0xF6,"was 0x%x",r[2]);
|
fail_if(r[2] != 0xF6);
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
@@ -153,10 +153,10 @@ START_TEST (test_pack32_le_1)
|
|||||||
|
|
||||||
uc_pack_32_le(v,r);
|
uc_pack_32_le(v,r);
|
||||||
|
|
||||||
fail_if(r[0] != 0x78,"was 0x%x",r[0]);
|
fail_if(r[0] != 0x78);
|
||||||
fail_if(r[1] != 0x56,"was 0x%x",r[1]);
|
fail_if(r[1] != 0x56);
|
||||||
fail_if(r[2] != 0x34,"was 0x%x",r[2]);
|
fail_if(r[2] != 0x34);
|
||||||
fail_if(r[3] != 0x12,"was 0x%x",r[3]);
|
fail_if(r[3] != 0x12);
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
@@ -167,10 +167,10 @@ START_TEST (test_pack32_le_2)
|
|||||||
|
|
||||||
uc_pack_32_le(v,r);
|
uc_pack_32_le(v,r);
|
||||||
|
|
||||||
fail_if(r[0] != 0xF4,"was 0x%x",r[0]);
|
fail_if(r[0] != 0xF4);
|
||||||
fail_if(r[1] != 0xF6,"was 0x%x",r[1]);
|
fail_if(r[1] != 0xF6);
|
||||||
fail_if(r[2] != 0xF7,"was 0x%x",r[2]);
|
fail_if(r[2] != 0xF7);
|
||||||
fail_if(r[3] != 0xF8,"was 0x%x",r[3]);
|
fail_if(r[3] != 0xF8);
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
@@ -181,10 +181,10 @@ START_TEST (test_pack32_be_1)
|
|||||||
|
|
||||||
uc_pack_32_be(v,r);
|
uc_pack_32_be(v,r);
|
||||||
|
|
||||||
fail_if(r[3] != 0x78,"was 0x%x",r[3]);
|
fail_if(r[3] != 0x78);
|
||||||
fail_if(r[2] != 0x56,"was 0x%x",r[2]);
|
fail_if(r[2] != 0x56);
|
||||||
fail_if(r[1] != 0x34,"was 0x%x",r[1]);
|
fail_if(r[1] != 0x34);
|
||||||
fail_if(r[0] != 0x12,"was 0x%x",r[0]);
|
fail_if(r[0] != 0x12);
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
@@ -195,10 +195,10 @@ START_TEST (test_pack32_be_2)
|
|||||||
|
|
||||||
uc_pack_32_be(v,r);
|
uc_pack_32_be(v,r);
|
||||||
|
|
||||||
fail_if(r[3] != 0xF4,"was 0x%x",r[3]);
|
fail_if(r[3] != 0xF4);
|
||||||
fail_if(r[2] != 0xF6,"was 0x%x",r[2]);
|
fail_if(r[2] != 0xF6);
|
||||||
fail_if(r[1] != 0xF7,"was 0x%x",r[1]);
|
fail_if(r[1] != 0xF7);
|
||||||
fail_if(r[0] != 0xF8,"was 0x%x",r[0]);
|
fail_if(r[0] != 0xF8);
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
@@ -209,7 +209,7 @@ START_TEST (test_unpack24_le_1)
|
|||||||
|
|
||||||
v = uc_unpack_24_le(r);
|
v = uc_unpack_24_le(r);
|
||||||
|
|
||||||
fail_if(v != 0x563412,"was 0x%x",v);
|
fail_if(v != 0x563412);
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
@@ -220,7 +220,7 @@ START_TEST (test_unpack24_le_2)
|
|||||||
|
|
||||||
v = uc_unpack_24_le(r);
|
v = uc_unpack_24_le(r);
|
||||||
|
|
||||||
fail_if(v != 0xF6F7F8,"was 0x%x",v);
|
fail_if(v != 0xF6F7F8);
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
@@ -231,7 +231,7 @@ START_TEST (test_unpack24_be_1)
|
|||||||
|
|
||||||
v = uc_unpack_24_be(r);
|
v = uc_unpack_24_be(r);
|
||||||
|
|
||||||
fail_if(v != 0x123456,"was 0x%x",v);
|
fail_if(v != 0x123456);
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
@@ -242,7 +242,7 @@ START_TEST (test_unpack24_be_2)
|
|||||||
|
|
||||||
v = uc_unpack_24_be(r);
|
v = uc_unpack_24_be(r);
|
||||||
|
|
||||||
fail_if(v != 0xF8F7F6,"was 0x%x",v);
|
fail_if(v != 0xF8F7F6);
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
@@ -253,7 +253,7 @@ START_TEST (test_unpack32_le_1)
|
|||||||
|
|
||||||
v = uc_unpack_32_le(r);
|
v = uc_unpack_32_le(r);
|
||||||
|
|
||||||
fail_if(v != 0x78563412,"was 0x%x",v);
|
fail_if(v != 0x78563412);
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
@@ -264,7 +264,7 @@ START_TEST (test_unpack32_le_2)
|
|||||||
|
|
||||||
v = uc_unpack_32_le(r);
|
v = uc_unpack_32_le(r);
|
||||||
|
|
||||||
fail_if(v != 0xF4F6F7F8,"was 0x%x",v);
|
fail_if(v != 0xF4F6F7F8);
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
@@ -275,7 +275,7 @@ START_TEST (test_unpack32_be_1)
|
|||||||
|
|
||||||
v = uc_unpack_32_be(r);
|
v = uc_unpack_32_be(r);
|
||||||
|
|
||||||
fail_if(v != 0x12345678,"was 0x%x",v);
|
fail_if(v != 0x12345678);
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
@@ -286,7 +286,7 @@ START_TEST (test_unpack32_be_2)
|
|||||||
|
|
||||||
v = uc_unpack_32_be(r);
|
v = uc_unpack_32_be(r);
|
||||||
|
|
||||||
fail_if(v != 0xF8F7F6F4,"was 0x%x",v);
|
fail_if(v != 0xF8F7F6F4);
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
@@ -297,14 +297,14 @@ START_TEST (test_pack64_le_1)
|
|||||||
|
|
||||||
uc_pack_64_le(v, r);
|
uc_pack_64_le(v, r);
|
||||||
|
|
||||||
fail_if(r[0] != 0x88,"was 0x%x",r[0]);
|
fail_if(r[0] != 0x88);
|
||||||
fail_if(r[1] != 0x77,"was 0x%x",r[1]);
|
fail_if(r[1] != 0x77);
|
||||||
fail_if(r[2] != 0x66,"was 0x%x",r[2]);
|
fail_if(r[2] != 0x66);
|
||||||
fail_if(r[3] != 0x55,"was 0x%x",r[3]);
|
fail_if(r[3] != 0x55);
|
||||||
fail_if(r[4] != 0x44,"was 0x%x",r[4]);
|
fail_if(r[4] != 0x44);
|
||||||
fail_if(r[5] != 0x33,"was 0x%x",r[5]);
|
fail_if(r[5] != 0x33);
|
||||||
fail_if(r[6] != 0x22,"was 0x%x",r[6]);
|
fail_if(r[6] != 0x22);
|
||||||
fail_if(r[7] != 0x11,"was 0x%x",r[7]);
|
fail_if(r[7] != 0x11);
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
@@ -315,14 +315,14 @@ START_TEST (test_pack64_le_2)
|
|||||||
|
|
||||||
uc_pack_64_le(v, r);
|
uc_pack_64_le(v, r);
|
||||||
|
|
||||||
fail_if(r[0] != 0xF8,"was 0x%x",r[0]);
|
fail_if(r[0] != 0xF8);
|
||||||
fail_if(r[1] != 0xF9,"was 0x%x",r[1]);
|
fail_if(r[1] != 0xF9);
|
||||||
fail_if(r[2] != 0xFA,"was 0x%x",r[2]);
|
fail_if(r[2] != 0xFA);
|
||||||
fail_if(r[3] != 0xFB,"was 0x%x",r[3]);
|
fail_if(r[3] != 0xFB);
|
||||||
fail_if(r[4] != 0xFC,"was 0x%x",r[4]);
|
fail_if(r[4] != 0xFC);
|
||||||
fail_if(r[5] != 0xFD,"was 0x%x",r[5]);
|
fail_if(r[5] != 0xFD);
|
||||||
fail_if(r[6] != 0xFE,"was 0x%x",r[6]);
|
fail_if(r[6] != 0xFE);
|
||||||
fail_if(r[7] != 0xFF,"was 0x%x",r[7]);
|
fail_if(r[7] != 0xFF);
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
@@ -333,7 +333,7 @@ START_TEST (test_unpack64_le_1)
|
|||||||
|
|
||||||
v = uc_unpack_64_le(r);
|
v = uc_unpack_64_le(r);
|
||||||
|
|
||||||
fail_if(v != 0x8877665544332211ULL,"was 0x%llx",v);
|
fail_if(v != 0x8877665544332211ULL);
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
@@ -345,7 +345,7 @@ START_TEST (test_unpack64_le_2)
|
|||||||
|
|
||||||
v = uc_unpack_64_le(r);
|
v = uc_unpack_64_le(r);
|
||||||
|
|
||||||
fail_if(v != 0xF8F9FAFBFCFDFEFFULL,"was 0x%llx",v);
|
fail_if(v != 0xF8F9FAFBFCFDFEFFULL);
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
@@ -356,14 +356,14 @@ START_TEST (test_pack64_be_1)
|
|||||||
|
|
||||||
uc_pack_64_be(v, r);
|
uc_pack_64_be(v, r);
|
||||||
|
|
||||||
fail_if(r[0] != 0x11,"was 0x%x",r[0]);
|
fail_if(r[0] != 0x11);
|
||||||
fail_if(r[1] != 0x22,"was 0x%x",r[1]);
|
fail_if(r[1] != 0x22);
|
||||||
fail_if(r[2] != 0x33,"was 0x%x",r[2]);
|
fail_if(r[2] != 0x33);
|
||||||
fail_if(r[3] != 0x44,"was 0x%x",r[3]);
|
fail_if(r[3] != 0x44);
|
||||||
fail_if(r[4] != 0x55,"was 0x%x",r[4]);
|
fail_if(r[4] != 0x55);
|
||||||
fail_if(r[5] != 0x66,"was 0x%x",r[5]);
|
fail_if(r[5] != 0x66);
|
||||||
fail_if(r[6] != 0x77,"was 0x%x",r[6]);
|
fail_if(r[6] != 0x77);
|
||||||
fail_if(r[7] != 0x88,"was 0x%x",r[7]);
|
fail_if(r[7] != 0x88);
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
@@ -374,14 +374,14 @@ START_TEST (test_pack64_be_2)
|
|||||||
|
|
||||||
uc_pack_64_be(v, r);
|
uc_pack_64_be(v, r);
|
||||||
|
|
||||||
fail_if(r[0] != 0xFF,"was 0x%x",r[0]);
|
fail_if(r[0] != 0xFF);
|
||||||
fail_if(r[1] != 0xFE,"was 0x%x",r[1]);
|
fail_if(r[1] != 0xFE);
|
||||||
fail_if(r[2] != 0xFD,"was 0x%x",r[2]);
|
fail_if(r[2] != 0xFD);
|
||||||
fail_if(r[3] != 0xFC,"was 0x%x",r[3]);
|
fail_if(r[3] != 0xFC);
|
||||||
fail_if(r[4] != 0xFB,"was 0x%x",r[4]);
|
fail_if(r[4] != 0xFB);
|
||||||
fail_if(r[5] != 0xFA,"was 0x%x",r[5]);
|
fail_if(r[5] != 0xFA);
|
||||||
fail_if(r[6] != 0xF9,"was 0x%x",r[6]);
|
fail_if(r[6] != 0xF9);
|
||||||
fail_if(r[7] != 0xF8,"was 0x%x",r[7]);
|
fail_if(r[7] != 0xF8);
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
@@ -392,7 +392,7 @@ START_TEST (test_unpack64_be_1)
|
|||||||
|
|
||||||
v = uc_unpack_64_be(r);
|
v = uc_unpack_64_be(r);
|
||||||
|
|
||||||
fail_if(v != 0x1122334455667788ULL,"was 0x%llx",v);
|
fail_if(v != 0x1122334455667788ULL);
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
@@ -403,7 +403,7 @@ START_TEST (test_unpack64_be_2)
|
|||||||
|
|
||||||
v = uc_unpack_64_be(r);
|
v = uc_unpack_64_be(r);
|
||||||
|
|
||||||
fail_if(v != 0xFFFEFDFCFBFAF9F8ULL,"was 0x%llx",v);
|
fail_if(v != 0xFFFEFDFCFBFAF9F8ULL);
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ START_TEST (test_ratelimit_1)
|
|||||||
|
|
||||||
uc_ratelimit_init(&r, 30, 2);
|
uc_ratelimit_init(&r, 30, 2);
|
||||||
for (i = 0; i < 30; i++) {
|
for (i = 0; i < 30; 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));
|
fail_if(uc_ratelimit_allow(&r, now));
|
||||||
}
|
}
|
||||||
|
|||||||
+24
-24
@@ -18,8 +18,8 @@ START_TEST (test_read_file_non_existing_file)
|
|||||||
content = uc_read_file("non existing file 123765", &len, 1000000000);
|
content = uc_read_file("non existing file 123765", &len, 1000000000);
|
||||||
saved_errno = errno;
|
saved_errno = errno;
|
||||||
|
|
||||||
fail_if(content != NULL);
|
ck_assert_ptr_null(content);
|
||||||
fail_if(saved_errno == 0);
|
ck_assert_int_ne(saved_errno, 0);
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
@@ -31,20 +31,20 @@ START_TEST (test_read_file_simple)
|
|||||||
ssize_t rc;
|
ssize_t rc;
|
||||||
|
|
||||||
int fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0664);
|
int fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0664);
|
||||||
fail_if(fd == -1);
|
ck_assert_int_ne(fd, -1);
|
||||||
|
|
||||||
rc = write(fd, "hello", 5);
|
rc = write(fd, "hello", 5);
|
||||||
fail_if(rc != 5, "rc was %ld", (long)rc);
|
ck_assert_int_eq(rc, 5);
|
||||||
|
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
||||||
content = uc_read_file(filename, &len, 1000000000);
|
content = uc_read_file(filename, &len, 1000000000);
|
||||||
unlink(filename);
|
unlink(filename);
|
||||||
|
|
||||||
fail_if(content == NULL);
|
ck_assert_ptr_nonnull(content);
|
||||||
fail_if(len != 5);
|
ck_assert_uint_eq(len, 5);
|
||||||
fail_if(strlen(content) != 5);
|
ck_assert_uint_eq(strlen(content), 5);
|
||||||
fail_if(strcmp("hello", content) != 0);
|
ck_assert_str_eq("hello", content);
|
||||||
free(content);
|
free(content);
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
@@ -61,7 +61,7 @@ START_TEST (test_read_file_greater_than_max)
|
|||||||
fail_if(fd == -1);
|
fail_if(fd == -1);
|
||||||
|
|
||||||
rc = write(fd, "hello", 5);
|
rc = write(fd, "hello", 5);
|
||||||
fail_if(rc != 5, "rc was %ld", (long)rc);
|
fail_if(rc != 5);
|
||||||
|
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
||||||
@@ -69,8 +69,8 @@ START_TEST (test_read_file_greater_than_max)
|
|||||||
saved_errno = errno;
|
saved_errno = errno;
|
||||||
unlink(filename);
|
unlink(filename);
|
||||||
|
|
||||||
fail_if(content != NULL);
|
ck_assert_ptr_null(content);
|
||||||
fail_if(saved_errno != EMSGSIZE, "was %d", saved_errno);
|
ck_assert_int_eq(saved_errno, EMSGSIZE);
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
@@ -87,16 +87,16 @@ START_TEST (test_read_file_boundary)
|
|||||||
fail_if(fd == -1);
|
fail_if(fd == -1);
|
||||||
|
|
||||||
rc = write(fd, buf, sizeof buf);
|
rc = write(fd, buf, sizeof buf);
|
||||||
fail_if(rc != sizeof buf, "rc was %ld", (long)rc);
|
ck_assert_uint_eq(rc, sizeof buf);
|
||||||
|
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
||||||
content = uc_read_file(filename, &len, 1000000000);
|
content = uc_read_file(filename, &len, 1000000000);
|
||||||
unlink(filename);
|
unlink(filename);
|
||||||
|
|
||||||
fail_if(content == NULL);
|
ck_assert_ptr_nonnull(content);
|
||||||
fail_if(len != sizeof buf);
|
ck_assert_uint_eq(len, sizeof buf);
|
||||||
fail_if(strcmp("foobar", &content[1022]) != 0);
|
ck_assert_str_eq("foobar", &content[1022]);
|
||||||
free(content);
|
free(content);
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
@@ -107,8 +107,8 @@ START_TEST (test_read_file_devnull)
|
|||||||
size_t len = 123;
|
size_t len = 123;
|
||||||
|
|
||||||
content = uc_read_file("/dev/null", &len, 1024);
|
content = uc_read_file("/dev/null", &len, 1024);
|
||||||
fail_if(content == NULL);
|
ck_assert_ptr_nonnull(content);
|
||||||
fail_if(len != 0);
|
ck_assert_uint_eq(len, 0);
|
||||||
free(content);
|
free(content);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -125,14 +125,14 @@ START_TEST (test_read_file_too_big)
|
|||||||
fail_if(fd == -1);
|
fail_if(fd == -1);
|
||||||
|
|
||||||
rc = write(fd, "hello", 5);
|
rc = write(fd, "hello", 5);
|
||||||
fail_if(rc != 5, "rc was %ld", (long)rc);
|
fail_if(rc != 5);
|
||||||
|
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
||||||
content = uc_read_file(filename, &len, 4);
|
content = uc_read_file(filename, &len, 4);
|
||||||
|
|
||||||
fail_if(errno != EMSGSIZE);
|
ck_assert_int_eq(errno, EMSGSIZE);
|
||||||
fail_if(content != NULL);
|
ck_assert_ptr_null(content);
|
||||||
|
|
||||||
unlink(filename);
|
unlink(filename);
|
||||||
}
|
}
|
||||||
@@ -147,18 +147,18 @@ START_TEST (test_read_file_big)
|
|||||||
ssize_t rc;
|
ssize_t rc;
|
||||||
|
|
||||||
int fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0664);
|
int fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0664);
|
||||||
fail_if(fd == -1);
|
ck_assert_int_ne(fd, -1);
|
||||||
memset(buf, 'a', sizeof buf);
|
memset(buf, 'a', sizeof buf);
|
||||||
|
|
||||||
rc = write(fd, buf, sizeof buf);
|
rc = write(fd, buf, sizeof buf);
|
||||||
fail_if(rc != sizeof buf, "rc was %ld", (long)rc);
|
ck_assert_uint_eq(rc, sizeof buf);
|
||||||
|
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
||||||
content = uc_read_file(filename, &len, 4096*16);
|
content = uc_read_file(filename, &len, 4096*16);
|
||||||
fail_if(content == NULL);
|
fail_if(content == NULL);
|
||||||
fail_if(len != sizeof buf);
|
ck_assert_uint_eq(len, sizeof buf);
|
||||||
fail_if(memcmp(content, buf, sizeof buf) != 0);
|
ck_assert_int_eq(memcmp(content, buf, sizeof buf), 0);
|
||||||
|
|
||||||
free(content);
|
free(content);
|
||||||
|
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ START_TEST (test_restart_counter_garble)
|
|||||||
ck_assert_int_eq(0, uc_restart_counter_get(&cnt));
|
ck_assert_int_eq(0, uc_restart_counter_get(&cnt));
|
||||||
|
|
||||||
rc = uc_restart_counter_init(&cnt, FILE_NAME, 0);
|
rc = uc_restart_counter_init(&cnt, FILE_NAME, 0);
|
||||||
fail_if(rc != UC_RC_OK, "%d", rc);
|
fail_if(rc != UC_RC_OK);
|
||||||
ck_assert_int_eq(1, uc_restart_counter_get(&cnt));
|
ck_assert_int_eq(1, uc_restart_counter_get(&cnt));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user