Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 50 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,5 +118,53 @@ jobs:
conda activate anaconda-client-env
pytest -xv -n2



msys2:
runs-on: windows-latest
strategy:
matrix:
include:
- { sys: mingw32, env: i686 }
- { sys: mingw64, env: x86_64 }
name: Windows (${{ matrix.sys }}, ${{ matrix.env }})
defaults:
run:
shell: msys2 {0}
steps:
- name: Cancel Previous Runs
uses: styfle/cancel-workflow-action@0.6.0
with:
access_token: ${{ github.token }}

- name: 'Checkout'
uses: actions/checkout@v2
with:
submodules: true

- name: Setup MSYS2 ${{matrix.sys}}
uses: msys2/setup-msys2@v2
with:
msystem: ${{matrix.sys}}
update: true
install: >-
git
mingw-w64-${{matrix.env}}-toolchain
mingw-w64-${{matrix.env}}-ninja
mingw-w64-${{matrix.env}}-meson
mingw-w64-${{matrix.env}}-cunit

- name: Fix windows symlinks
working-directory: c
run: |
rm -f subprojects/kastore
cp -r --dereference subprojects/full-projects/kastore/c subprojects/kastore

- name: Build
working-directory: c
run: |
meson build -Dbuild_examples=false
ninja -C build

- name: Run tests
working-directory: c
run: |
ninja -C build test
2 changes: 2 additions & 0 deletions c/CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
space for 1024 additional entries each time we run out of space in the ragged column.
(:user:`benjeffery`, :issue:`1703`, :pr:`1709`)

- Support for compiling the C library on Windows using msys2 (:user:`jeromekelleher`,
:pr:`1742`).

**Fixes**

Expand Down
57 changes: 33 additions & 24 deletions c/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -85,28 +85,37 @@ if not meson.is_subproject()
dependencies: kastore_dep)
test('minimal_cpp', test_minimal_cpp)

# The development CLI. Don't use extra C args because argtable code won't pass
executable('dev-cli',
sources: ['dev-tools/dev-cli.c', 'dev-tools/argtable3.c'],
link_with: [tskit_lib], c_args:['-Dlint'], dependencies: kastore_dep)

# Example programs.
executable('api_structure',
sources: ['examples/api_structure.c'], link_with: [tskit_lib], dependencies: lib_deps)
executable('error_handling',
sources: ['examples/error_handling.c'], link_with: [tskit_lib], dependencies: lib_deps)
executable('tree_iteration',
sources: ['examples/tree_iteration.c'], link_with: [tskit_lib], dependencies: lib_deps)
executable('tree_traversal',
sources: ['examples/tree_traversal.c'], link_with: [tskit_lib], dependencies: lib_deps)
executable('streaming',
sources: ['examples/streaming.c'], link_with: [tskit_lib], dependencies: lib_deps)
executable('cpp_sorting_example',
sources: ['examples/cpp_sorting_example.cpp'], link_with: [tskit_lib], dependencies: lib_deps)
executable('haploid_wright_fisher',
sources: ['examples/haploid_wright_fisher.c'], link_with: [tskit_lib], dependencies: lib_deps)
if get_option('build_examples')
# These example programs and the dev-cli use less portable features,
# and we don't want to always compile them. Use, e.g.,
# meson build -Dbuild_examples=false

# The development CLI. Don't use extra C args because argtable code won't pass
executable('dev-cli',
sources: ['dev-tools/dev-cli.c', 'dev-tools/argtable3.c'],
link_with: [tskit_lib], c_args:['-Dlint'], dependencies: kastore_dep)

# Example programs.
executable('api_structure',
sources: ['examples/api_structure.c'],
link_with: [tskit_lib], dependencies: lib_deps)
executable('error_handling',
sources: ['examples/error_handling.c'],
link_with: [tskit_lib], dependencies: lib_deps)
executable('tree_iteration',
sources: ['examples/tree_iteration.c'],
link_with: [tskit_lib], dependencies: lib_deps)
executable('tree_traversal',
sources: ['examples/tree_traversal.c'],
link_with: [tskit_lib], dependencies: lib_deps)
executable('streaming',
sources: ['examples/streaming.c'],
link_with: [tskit_lib], dependencies: lib_deps)
executable('cpp_sorting_example',
sources: ['examples/cpp_sorting_example.cpp'],
link_with: [tskit_lib], dependencies: lib_deps)
executable('haploid_wright_fisher',
sources: ['examples/haploid_wright_fisher.c'],
link_with: [tskit_lib], dependencies: lib_deps)
endif
endif

# TMP: until we've ported all the tests, keep this compilable.
# gsl_dep = dependency('gsl')
# executable('old_tests', sources: ['tests/old_tests.c'], link_with: tskit_lib, # dependencies: [cunit_dep, gsl_dep])
1 change: 1 addition & 0 deletions c/meson_options.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
option('build_examples', type : 'boolean', value : true)
34 changes: 33 additions & 1 deletion c/tests/test_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ test_blkalloc(void)
static void
test_unknown_time(void)
{
CU_ASSERT_TRUE(isnan(TSK_UNKNOWN_TIME));
CU_ASSERT_TRUE(tsk_isnan(TSK_UNKNOWN_TIME));
CU_ASSERT_TRUE(tsk_is_unknown_time(TSK_UNKNOWN_TIME));
CU_ASSERT_FALSE(tsk_is_unknown_time(NAN));
CU_ASSERT_FALSE(tsk_is_unknown_time(0));
Expand Down Expand Up @@ -371,6 +371,36 @@ test_malloc_overflow(void)
#endif
}

static void
test_debug_stream(void)
{
FILE *f = fopen(_tmp_file_name, "w");
CU_ASSERT_FATAL(tsk_get_debug_stream() == stdout);
CU_ASSERT_FATAL(tsk_get_debug_stream() == stdout);

tsk_set_debug_stream(f);
CU_ASSERT_FATAL(tsk_get_debug_stream() == f);
tsk_set_debug_stream(stdout);
CU_ASSERT_FATAL(tsk_get_debug_stream() == stdout);

fclose(f);
}

static void
test_warn_stream(void)
{
FILE *f = fopen(_tmp_file_name, "w");
CU_ASSERT_FATAL(tsk_get_warn_stream() == stderr);
CU_ASSERT_FATAL(tsk_get_warn_stream() == stderr);

tsk_set_warn_stream(f);
CU_ASSERT_FATAL(tsk_get_warn_stream() == f);
tsk_set_warn_stream(stderr);
CU_ASSERT_FATAL(tsk_get_warn_stream() == stderr);

fclose(f);
}

static int
validate_avl_node(tsk_avl_node_int_t *node)
{
Expand Down Expand Up @@ -521,6 +551,8 @@ main(int argc, char **argv)
{ "test_unknown_time", test_unknown_time },
{ "test_malloc_zero", test_malloc_zero },
{ "test_malloc_overflow", test_malloc_overflow },
{ "test_debug_stream", test_debug_stream },
{ "test_warn_stream", test_warn_stream },
{ "test_avl_empty", test_avl_empty },
{ "test_avl_sequential", test_avl_sequential },
{ "test_avl_interleaved", test_avl_interleaved },
Expand Down
5 changes: 5 additions & 0 deletions c/tests/test_file_format.c
Original file line number Diff line number Diff line change
Expand Up @@ -787,9 +787,13 @@ test_metadata_schemas_optional(void)
free(ts);
}

/* This test is problematic on windows because of the different off_t
* types. Doesn't seem worth the trouble of getting it working.
*/
static void
test_load_bad_file_formats(void)
{
#if !defined(_WIN32)
tsk_table_collection_t tables;
tsk_treeseq_t ts;
int ret, ret2;
Expand Down Expand Up @@ -818,6 +822,7 @@ test_load_bad_file_formats(void)
CU_ASSERT_EQUAL_FATAL(ret ^ (1 << TSK_KAS_ERR_BIT), KAS_ERR_BAD_FILE_FORMAT);
tsk_table_collection_free(&tables);
}
#endif
}

static void
Expand Down
14 changes: 7 additions & 7 deletions c/tests/test_stats.c
Original file line number Diff line number Diff line change
Expand Up @@ -1102,7 +1102,7 @@ test_paper_ex_diversity(void)
ret = tsk_treeseq_diversity(
&ts, 1, &sample_set_sizes, samples, 0, NULL, &pi, TSK_STAT_SITE);
CU_ASSERT_EQUAL_FATAL(ret, 0);
CU_ASSERT(isnan((float) pi));
CU_ASSERT(tsk_isnan(pi));

tsk_treeseq_free(&ts);
}
Expand Down Expand Up @@ -1292,7 +1292,7 @@ test_paper_ex_Y1(void)
sample_set_sizes = 1;
ret = tsk_treeseq_Y1(&ts, 1, &sample_set_sizes, samples, 0, NULL, &result, 0);
CU_ASSERT_EQUAL_FATAL(ret, 0);
CU_ASSERT(isnan((float) result));
CU_ASSERT(tsk_isnan(result));

tsk_treeseq_free(&ts);
}
Expand Down Expand Up @@ -1331,7 +1331,7 @@ test_paper_ex_divergence(void)
ret = tsk_treeseq_divergence(&ts, 2, sample_set_sizes, samples, 1, set_indexes, 0,
NULL, &result, TSK_STAT_SITE);
CU_ASSERT_EQUAL_FATAL(ret, 0);
CU_ASSERT(isnan((float) result));
CU_ASSERT(tsk_isnan(result));

tsk_treeseq_free(&ts);
}
Expand Down Expand Up @@ -1399,7 +1399,7 @@ test_paper_ex_Y2(void)
ret = tsk_treeseq_Y2(&ts, 2, sample_set_sizes, samples, 1, set_indexes, 0, NULL,
&result, TSK_STAT_SITE);
CU_ASSERT_EQUAL_FATAL(ret, 0);
CU_ASSERT(isnan((float) result));
CU_ASSERT(tsk_isnan(result));

tsk_treeseq_free(&ts);
}
Expand Down Expand Up @@ -1437,15 +1437,15 @@ test_paper_ex_f2(void)
ret = tsk_treeseq_f2(&ts, 2, sample_set_sizes, samples, 1, set_indexes, 0, NULL,
&result, TSK_STAT_SITE);
CU_ASSERT_EQUAL_FATAL(ret, 0);
CU_ASSERT(isnan((float) result));
CU_ASSERT(tsk_isnan(result));

/* sample_set_size of 1 leads to NaN */
sample_set_sizes[0] = 2;
sample_set_sizes[1] = 1;
ret = tsk_treeseq_f2(&ts, 2, sample_set_sizes, samples, 1, set_indexes, 0, NULL,
&result, TSK_STAT_SITE);
CU_ASSERT_EQUAL_FATAL(ret, 0);
CU_ASSERT(isnan((float) result));
CU_ASSERT(tsk_isnan(result));

tsk_treeseq_free(&ts);
}
Expand Down Expand Up @@ -1514,7 +1514,7 @@ test_paper_ex_f3(void)
ret = tsk_treeseq_f3(&ts, 3, sample_set_sizes, samples, 1, set_indexes, 0, NULL,
&result, TSK_STAT_SITE);
CU_ASSERT_EQUAL_FATAL(ret, 0);
CU_ASSERT(isnan((float) result));
CU_ASSERT(tsk_isnan(result));

tsk_treeseq_free(&ts);
}
Expand Down
5 changes: 2 additions & 3 deletions c/tests/test_tables.c
Original file line number Diff line number Diff line change
Expand Up @@ -5422,16 +5422,15 @@ test_ibd_segments_debug(void)
tsk_treeseq_t ts;
int ret;
tsk_ibd_segments_t result;
FILE *tmp = stdout;

tsk_treeseq_from_text(&ts, 1, single_tree_ex_nodes, single_tree_ex_edges, NULL, NULL,
NULL, NULL, NULL, 0);

/* Run the DEBUG code */
stdout = _devnull;
tsk_set_debug_stream(_devnull);
ret = tsk_table_collection_ibd_segments(
ts.tables, &result, NULL, 0, 0.0, DBL_MAX, TSK_DEBUG);
stdout = tmp;
tsk_set_debug_stream(stdout);
CU_ASSERT_EQUAL_FATAL(ret, 0);

tsk_ibd_segments_free(&result);
Expand Down
12 changes: 5 additions & 7 deletions c/tests/test_trees.c
Original file line number Diff line number Diff line change
Expand Up @@ -1977,7 +1977,7 @@ test_simplest_individuals(void)
CU_ASSERT_EQUAL(ret, 0);
ret = tsk_treeseq_get_individual(&ts, 0, &individual);
CU_ASSERT_EQUAL_FATAL(ret, 0);
CU_ASSERT(!isfinite(individual.location[0]));
CU_ASSERT(!tsk_isfinite(individual.location[0]));
tsk_treeseq_free(&ts);

tsk_table_collection_free(&tables);
Expand Down Expand Up @@ -3957,16 +3957,15 @@ test_single_tree_simplify_debug(void)
tsk_treeseq_t ts, simplified;
tsk_id_t samples[] = { 0, 1 };
int ret;
FILE *save_stdout = stdout;
FILE *tmp = fopen(_tmp_file_name, "w");

CU_ASSERT_FATAL(tmp != NULL);
tsk_treeseq_from_text(&ts, 1, single_tree_ex_nodes, single_tree_ex_edges, NULL,
single_tree_ex_sites, single_tree_ex_mutations, NULL, NULL, 0);

stdout = tmp;
tsk_set_debug_stream(tmp);
ret = tsk_treeseq_simplify(&ts, samples, 2, TSK_DEBUG, &simplified, NULL);
stdout = save_stdout;
tsk_set_debug_stream(stdout);
CU_ASSERT_EQUAL_FATAL(ret, 0);
CU_ASSERT_TRUE(ftell(tmp) > 0);

Expand Down Expand Up @@ -6143,15 +6142,14 @@ test_sample_counts_deprecated(void)
tsk_tree_t tree;
int ret;
FILE *f = fopen(_tmp_file_name, "w");
FILE *tmp = stderr;

tsk_treeseq_from_text(&ts, 1, single_tree_ex_nodes, single_tree_ex_edges, NULL, NULL,
NULL, NULL, NULL, 0);
CU_ASSERT_EQUAL(tsk_treeseq_get_num_samples(&ts), 4);

stderr = f;
tsk_set_warn_stream(f);
ret = tsk_tree_init(&tree, &ts, TSK_SAMPLE_COUNTS);
stderr = tmp;
tsk_set_warn_stream(stderr);
CU_ASSERT_EQUAL_FATAL(ret, 0);

CU_ASSERT_FATAL(ftell(f) > 0);
Expand Down
1 change: 0 additions & 1 deletion c/tests/testlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
#include <stdlib.h>

#include <CUnit/Basic.h>
#define _TSK_WORKAROUND_FALSE_CLANG_WARNING
#include <tskit/trees.h>

/* Global variables used in the test suite */
Expand Down
Loading