Skip to content

Commit

Permalink
Merge pull request #272 from PJK/circlewin
Browse files Browse the repository at this point in the history
Set up Windows CI including tests, make tests cross-platform
  • Loading branch information
PJK committed Jan 29, 2023
2 parents 4ebc7a0 + 331545c commit cb4162f
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 3 deletions.
20 changes: 20 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,25 @@ jobs:
- build
- test


build-and-test-win:
resource_class: 'windows.medium'
machine:
image: 'windows-server-2022-gui:current'
shell: 'bash.exe'
steps:
- checkout
- run: choco install cmake -y
- run: git clone https://git.cryptomilk.org/projects/cmocka.git
- run: cd cmocka && git checkout tags/cmocka-1.1.5
- run: /c/Program\ Files/Cmake/bin/cmake -S cmocka -B cmocka_build
- run: /c/Program\ Files/Cmake/bin/cmake --build cmocka_build
- run: /c/Program\ Files/Cmake/bin/cmake -S . -B libcbor_build -DWITH_TESTS=ON -DCMOCKA_INCLUDE_DIR=cmocka/include -DCMOCKA_LIBRARIES=$(pwd)/cmocka_build/src/Debug/cmocka.lib
- run: /c/Program\ Files/Cmake/bin/cmake --build libcbor_build
- run: >
export PATH="$(pwd)/cmocka_build/src/Debug/:$PATH" &&
/c/Program\ Files/Cmake/bin/ctest.exe --test-dir libcbor_build --output-on-failure
workflows:
build-and-test:
jobs:
Expand All @@ -193,6 +212,7 @@ workflows:
- build-and-test-32b
- build-and-test-release-clang
- build-and-test-arm
- build-and-test-win
- build-bazel
- llvm-coverage
# OSX builds are expensive, run only on master
Expand Down
2 changes: 2 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ message(STATUS "CMocka vars: ${CMOCKA_LIBRARIES} ${CMOCKA_INCLUDE_DIR}")

find_library(MATH_LIBRARY m)

CHECK_INCLUDE_FILE("execinfo.h" HAS_EXECINFO)

foreach (TEST ${TESTS})
string(REGEX REPLACE ".*/([^/]+).c" "\\1" NAME ${TEST})
message("Adding test ${NAME}")
Expand Down
5 changes: 2 additions & 3 deletions test/cbor_serialize_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#include <stddef.h>
#include <stdint.h>
#include <string.h>
#include <strings.h>

#include <cmocka.h>

Expand Down Expand Up @@ -131,8 +130,8 @@ static void test_serialize_negint64(void **_CBOR_UNUSED(_state)) {
static void test_serialize_definite_bytestring(void **_CBOR_UNUSED(_state)) {
cbor_item_t *item = cbor_new_definite_bytestring();
unsigned char *data = malloc(256);
bzero(data, 256); /* Prevent undefined behavior in comparison */
cbor_bytestring_set_handle(item, data, 256);
memset(data, 0, 256); /* Prevent undefined behavior in comparison */
assert_size_equal(256 + 3, cbor_serialize(item, buffer, 512));
assert_memory_equal(buffer, ((unsigned char[]){0x59, 0x01, 0x00}), 3);
assert_memory_equal(buffer + 3, data, 256);
Expand All @@ -145,7 +144,7 @@ static void test_serialize_indefinite_bytestring(void **_CBOR_UNUSED(_state)) {

cbor_item_t *chunk = cbor_new_definite_bytestring();
unsigned char *data = malloc(256);
bzero(data, 256); /* Prevent undefined behavior in comparison */
memset(data, 0, 256); /* Prevent undefined behavior in comparison */
cbor_bytestring_set_handle(chunk, data, 256);

assert_true(cbor_bytestring_add_chunk(item, cbor_move(chunk)));
Expand Down
6 changes: 6 additions & 0 deletions test/float_ctrl_encoders_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,12 @@ static void test_float(void **_CBOR_UNUSED(_state)) {
assert_memory_equal(buffer, ((unsigned char[]){0xFA, 0x7F, 0xC0, 0x00, 0x00}),
5);

#ifndef _WIN32
// TODO: https://github.com/PJK/libcbor/issues/271
assert_size_equal(5, cbor_encode_single(nanf("3"), buffer, 512));
assert_memory_equal(buffer, ((unsigned char[]){0xFA, 0x7F, 0xC0, 0x00, 0x03}),
5);
#endif

assert_size_equal(5, cbor_encode_single(strtof("Inf", NULL), buffer, 512));
assert_memory_equal(buffer, ((unsigned char[]){0xFA, 0x7F, 0x80, 0x00, 0x00}),
Expand All @@ -176,11 +179,14 @@ static void test_double(void **_CBOR_UNUSED(_state)) {
((unsigned char[]){0xFB, 0x7F, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}),
9);

#ifndef _WIN32
// TODO: https://github.com/PJK/libcbor/issues/271
assert_size_equal(9, cbor_encode_double(nan("3"), buffer, 512));
assert_memory_equal(
buffer,
((unsigned char[]){0xFB, 0x7F, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03}),
9);
#endif

assert_size_equal(9, cbor_encode_double(strtod("Inf", NULL), buffer, 512));
assert_memory_equal(
Expand Down
4 changes: 4 additions & 0 deletions test/test_allocator.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "test_allocator.h"

#ifdef HAS_EXECINFO
#include <execinfo.h>
#endif

// How many alloc calls we expect
int alloc_calls_expected;
Expand Down Expand Up @@ -28,6 +30,7 @@ void finalize_mock_malloc(void) {
}

void print_backtrace() {
#if HAS_EXECINFO
void *buffer[128];
int frames = backtrace(buffer, 128);
char **symbols = backtrace_symbols(buffer, frames);
Expand All @@ -36,6 +39,7 @@ void print_backtrace() {
printf("%s\n", symbols[i]);
}
free(symbols);
#endif
}

void *instrumented_malloc(size_t size) {
Expand Down

0 comments on commit cb4162f

Please sign in to comment.