Skip to content

Commit b229c37

Browse files
committed
build and run most c-blosc2 tests
1 parent a6a7f86 commit b229c37

File tree

4 files changed

+149
-1
lines changed

4 files changed

+149
-1
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
.zig-cache
1+
.zig-cache/
22
zig-out/

build.zig

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
const std = @import("std");
22

33
pub fn build(b: *std.Build) void {
4+
const test_step = b.step("test", "Run all tests");
5+
46
const target = b.standardTargetOptions(.{});
57
const optimize = b.standardOptimizeOption(.{});
68
const linkage = b.option(std.builtin.LinkMode, "linkage", "linkage to use (default: static)") orelse .static;
@@ -62,6 +64,9 @@ pub fn build(b: *std.Build) void {
6264
"b2nd.c",
6365
"b2nd_utils.c",
6466
},
67+
.flags = &.{
68+
"-fno-sanitize=alignment",
69+
},
6570
});
6671

6772
c_blosc2_module.addCSourceFile(.{ .file = c_blosc2_source.path("blosc/shuffle.c") });
@@ -121,6 +126,43 @@ pub fn build(b: *std.Build) void {
121126
addExample(b, "frame_roundtrip", c_blosc2_source.path("examples/frame_roundtrip.c"), example_options);
122127
addExample(b, "get_set_slice", c_blosc2_source.path("examples/get_set_slice.c"), example_options);
123128
addExample(b, "get_blocksize", c_blosc2_source.path("examples/get_blocksize.c"), example_options);
129+
130+
// Tests
131+
const test_root = c_blosc2_source.path(test_root_filename);
132+
const test_include_path = c_blosc2_source.path("blosc");
133+
134+
const testing_template_dir = b.path("testing_template_dir/");
135+
136+
for (test_files) |test_filename| {
137+
const name = std.fs.path.stem(test_filename);
138+
139+
const exe = addTestExe(
140+
b,
141+
name,
142+
test_root.path(b, test_filename),
143+
test_include_path,
144+
example_options,
145+
);
146+
147+
const run = b.addRunArtifact(exe);
148+
run.expectExitCode(0);
149+
150+
// We need a separate path for each of the tests,
151+
// because some of the tests use the same filename.
152+
//
153+
// A `WriteFiles` step creates a unique directory for each one,
154+
// and unlike using `b.makeTempDirectory`,
155+
// still allows the Zig build system to cache the result.
156+
const test_write_files = b.addWriteFiles();
157+
const test_dir = test_write_files.addCopyDirectory(testing_template_dir, name, .{
158+
.exclude_extensions = &.{".md"},
159+
});
160+
run.setCwd(test_dir);
161+
162+
test_step.dependOn(&run.step);
163+
}
164+
165+
// TODO: support parameterized tests
124166
}
125167

126168
pub const ExampleOptions = struct {
@@ -144,3 +186,106 @@ fn addExample(b: *std.Build, name: []const u8, path: std.Build.LazyPath, options
144186
});
145187
b.installArtifact(exe);
146188
}
189+
190+
fn addTestExe(b: *std.Build, name: []const u8, path: std.Build.LazyPath, blosc_include_path: std.Build.LazyPath, options: ExampleOptions) *std.Build.Step.Compile {
191+
const exe = b.addExecutable(.{
192+
.name = name,
193+
.root_module = b.createModule(.{
194+
.target = options.target,
195+
.optimize = options.optimize,
196+
.link_libc = true,
197+
}),
198+
});
199+
exe.root_module.addIncludePath(blosc_include_path);
200+
exe.root_module.linkLibrary(options.c_blosc2);
201+
exe.root_module.addCSourceFile(.{
202+
.file = path,
203+
});
204+
return exe;
205+
}
206+
207+
const test_root_filename = "tests";
208+
const test_files: []const []const u8 = &.{
209+
"test_api.c",
210+
"test_bitshuffle_leftovers.c",
211+
"test_blosc1_compat.c",
212+
"test_change_nthreads_append.c",
213+
"test_compressor.c",
214+
"test_contexts.c",
215+
"test_copy.c",
216+
"test_delete_chunk.c",
217+
"test_delta.c",
218+
"test_delta_schunk.c",
219+
"test_dict_schunk.c",
220+
"test_empty_buffer.c",
221+
"test_fill_special.c",
222+
"test_filters.c",
223+
"test_frame.c",
224+
"test_frame_get_offsets.c",
225+
"test_frame_offset.c",
226+
"test_get_slice_buffer.c",
227+
"test_get_slice_nchunks.c",
228+
"test_getitem_delta.c",
229+
"test_insert_chunk.c",
230+
"test_lazychunk.c",
231+
"test_lazychunk_memcpyed.c",
232+
"test_maskout.c",
233+
"test_maxout.c",
234+
"test_mmap.c",
235+
"test_noinit.c",
236+
"test_nolock.c",
237+
"test_nthreads.c",
238+
"test_postfilter.c",
239+
"test_prefilter.c",
240+
"test_reorder_offsets.c",
241+
"test_schunk.c",
242+
"test_schunk_frame.c",
243+
"test_schunk_header.c",
244+
"test_set_slice_buffer.c",
245+
"test_sframe.c",
246+
"test_sframe_lazychunk.c",
247+
"test_small_chunks.c",
248+
"test_udio.c",
249+
"test_update_chunk.c",
250+
"test_urcodecs.c",
251+
"test_urfilters.c",
252+
"test_zero_runlen.c",
253+
254+
// b2nd tests
255+
"b2nd/test_b2nd_append.c",
256+
"b2nd/test_b2nd_concatenate.c",
257+
"b2nd/test_b2nd_copy.c",
258+
"b2nd/test_b2nd_copy_buffer.c",
259+
"b2nd/test_b2nd_delete.c",
260+
// "b2nd/test_b2nd_expand_dims.c", // Fails with "index -1 out of bounds"
261+
// "b2nd/test_b2nd_full.c", // Fails with "index -1 out of bounds"
262+
// "b2nd/test_b2nd_get_slice.c", // Fails with "index -1 out of bounds"
263+
// "b2nd/test_b2nd_get_slice_buffer.c", // Fails with "index -1 out of bounds"
264+
"b2nd/test_b2nd_insert.c",
265+
// "b2nd/test_b2nd_metalayers.c", // Fails with "index -1 out of bounds"
266+
// "b2nd/test_b2nd_nans.c", // Fails with "index -1 out of bounds"
267+
"b2nd/test_b2nd_open_offset.c",
268+
// "b2nd/test_b2nd_persistency.c", // Fails with "index -1 out of bounds"
269+
"b2nd/test_b2nd_resize.c",
270+
"b2nd/test_b2nd_roundtrip.c",
271+
// "b2nd/test_b2nd_save.c", // Fails with "index -1 out of bounds"
272+
// "b2nd/test_b2nd_save_append.c", // Fails with "index -1 out of bounds"
273+
// "b2nd/test_b2nd_serialize.c", // Fails with "index -1 out of bounds"
274+
// "b2nd/test_b2nd_set_slice_buffer.c", // Fails with "index -1 out of bounds"
275+
// "b2nd/test_b2nd_squeeze.c", // Fails with "index -1 out of bounds"
276+
// "b2nd/test_b2nd_squeeze_index.c", // Fails with "index -1 out of bounds"
277+
// "b2nd/test_b2nd_uninit.c", // Fails with "index -1 out of bounds"
278+
// "b2nd/test_b2nd_zeros.c", // Fails with "index -1 out of bounds"
279+
};
280+
281+
const parameterized_test_files: []const []const u8 = &.{
282+
"test_bitshuffle_roundtrip.c",
283+
"test_compress_roundtrip.c",
284+
"test_getitem.c",
285+
"test_shuffle_roundtrip.c",
286+
"test_shuffle_roundtrip_altivec.c",
287+
"test_shuffle_roundtrip_avx2.c",
288+
"test_shuffle_roundtrip_generic.c",
289+
"test_shuffle_roundtrip_neon.c",
290+
"test_shuffle_roundtrip_sse2.c",
291+
};

build.zig.zon

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
.paths = .{
2020
"build.zig",
2121
"build.zig.zon",
22+
"testing_template_dir",
2223
},
2324
.fingerprint = 0x44d08dca0c10c5a2,
2425
}

testing_template_dir/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
This is part of a hack to get the zig build system to create separate directories for each c-blosc2.
2+
See `build.zig` for more info.

0 commit comments

Comments
 (0)