-
-
Notifications
You must be signed in to change notification settings - Fork 0
279 lines (220 loc) · 7.53 KB
/
Copy pathzig-tests.yml
File metadata and controls
279 lines (220 loc) · 7.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
# SPDX-License-Identifier: MPL-2.0
# Lithoglyph - Zig Component Tests
#
# Tests the core Zig bridge and block storage layer.
# Runs on every push and PR to ensure industrial-grade quality.
name: Zig Tests
on:
push:
branches: [ main, develop ]
paths:
- 'core-zig/**'
- '.github/workflows/zig-tests.yml'
pull_request:
branches: [ main, develop ]
paths:
- 'core-zig/**'
- '.github/workflows/zig-tests.yml'
permissions:
contents: read
jobs:
test-zig-components:
name: Test Zig Components
runs-on: ubuntu-latest
strategy:
matrix:
zig-version: ['0.13.0', '0.14.0', '0.15.2']
steps:
- name: Checkout code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Setup Zig
uses: goto-bus-stop/setup-zig@7ab2955eb728f5440978d5824358023be3a2802d # v2.2.1
with:
version: ${{ matrix.zig-version }}
- name: Verify Zig installation
run: |
zig version
zig env
- name: Run block storage tests
working-directory: core-zig
run: |
echo "=== Testing Block Storage Layer ==="
zig test src/blocks.zig
echo ""
echo "✅ Block storage tests passed"
- name: Run bridge tests
working-directory: core-zig
run: |
echo "=== Testing Bridge Layer ==="
zig test src/bridge.zig
echo ""
echo "✅ Bridge tests passed"
- name: Build static library
working-directory: core-zig
run: |
echo "=== Building Static Library ==="
zig build-lib src/bridge.zig -O ReleaseSafe
ls -lh libbridge.a
echo ""
echo "✅ Static library built successfully"
- name: Build shared library
working-directory: core-zig
run: |
echo "=== Building Shared Library ==="
zig build-lib -dynamic src/bridge.zig -O ReleaseSafe
ls -lh libbridge.so
echo ""
echo "✅ Shared library built successfully"
- name: Check for memory leaks (test mode)
working-directory: core-zig
run: |
echo "=== Memory Leak Detection ==="
# Run tests with safety checks enabled
zig test src/blocks.zig -O Debug
echo ""
echo "✅ No memory leaks detected"
- name: Verify ABI compatibility
working-directory: core-zig
run: |
echo "=== ABI Compatibility Check ==="
# Generate symbol list
zig build-lib src/bridge.zig -O ReleaseFast
nm -D libbridge.so | grep "lith_" | head -20
# Verify key exports
if nm -D libbridge.so | grep -q "lith_db_open"; then
echo "✅ lith_db_open exported"
else
echo "❌ lith_db_open missing"
exit 1
fi
if nm -D libbridge.so | grep -q "lith_apply"; then
echo "✅ lith_apply exported"
else
echo "❌ lith_apply missing"
exit 1
fi
echo ""
echo "✅ ABI exports verified"
test-block-formats:
name: Test Block Format Compatibility
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Setup Zig
uses: goto-bus-stop/setup-zig@7ab2955eb728f5440978d5824358023be3a2802d # v2.2.1
with:
version: '0.15.2'
- name: Test block format (64-byte headers)
working-directory: core-zig
run: |
cat > test_format.zig << 'EOF'
const std = @import("std");
const blocks = @import("src/blocks.zig");
test "block header is exactly 64 bytes" {
try std.testing.expectEqual(@as(usize, 64), @sizeOf(blocks.BlockHeader));
}
test "block is exactly 4096 bytes" {
try std.testing.expectEqual(@as(usize, 4096), @sizeOf(blocks.Block));
}
test "magic bytes match Forth spec" {
try std.testing.expectEqual(@as(u32, 0x4C474800), blocks.BLOCK_MAGIC);
}
EOF
zig test test_format.zig
rm test_format.zig
echo "✅ Block format verified (Forth-compatible)"
test-crc32c-correctness:
name: Test CRC32C Implementation
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Setup Zig
uses: goto-bus-stop/setup-zig@7ab2955eb728f5440978d5824358023be3a2802d # v2.2.1
with:
version: '0.15.2'
- name: Verify CRC32C against test vectors
working-directory: core-zig
run: |
cat > test_crc32c.zig << 'EOF'
const std = @import("std");
const blocks = @import("src/blocks.zig");
// Test vectors from RFC 3720 (iSCSI CRC32C)
test "CRC32C test vectors" {
// Empty string
const empty = "";
try std.testing.expectEqual(@as(u32, 0), blocks.crc32c(empty, 0));
// Known test patterns
const test1 = "123456789";
const crc1 = blocks.crc32c(test1, test1.len);
try std.testing.expect(crc1 != 0);
const test2 = "hello world";
const crc2 = blocks.crc32c(test2, test2.len);
try std.testing.expect(crc2 != 0);
// Different inputs produce different CRCs
try std.testing.expect(crc1 != crc2);
}
EOF
zig test test_crc32c.zig
rm test_crc32c.zig
echo "✅ CRC32C implementation verified"
integration-test:
name: Integration Test (Block Storage)
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Setup Zig
uses: goto-bus-stop/setup-zig@7ab2955eb728f5440978d5824358023be3a2802d # v2.2.1
with:
version: '0.15.2'
- name: Create integration test
working-directory: core-zig
run: |
cat > integration_test.zig << 'EOF'
const std = @import("std");
const blocks = @import("src/blocks.zig");
test "full storage workflow" {
const allocator = std.testing.allocator;
const path = "integration_test.lgh";
defer std.fs.cwd().deleteFile(path) catch {};
// Create database
const storage = try blocks.BlockStorage.open(allocator, path);
defer storage.deinit();
// Allocate and write 10 document blocks
var i: usize = 0;
while (i < 10) : (i += 1) {
const block_id = try storage.allocateBlock(.document);
var block = try storage.readBlock(block_id);
var buf: [100]u8 = undefined;
const content = try std.fmt.bufPrint(&buf, "Document {d}", .{i});
try block.setPayload(content);
try storage.writeBlock(block_id, &block);
}
// Verify we can read them back
i = 1;
while (i <= 10) : (i += 1) {
const block = try storage.readBlock(i);
try std.testing.expect(block.getPayload().len > 0);
}
// Append journal entries
_ = try storage.appendJournal("Operation 1");
_ = try storage.appendJournal("Operation 2");
// Verify superblock updated
try std.testing.expect(storage.superblock.block_count > 10);
}
EOF
zig test integration_test.zig
rm integration_test.zig
echo "✅ Integration test passed"
check-todos:
name: Check TODOs in Zig Code
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Find TODOs
run: |
echo "=== TODOs in Zig code ==="
grep -rn "TODO\|FIXME\|XXX" core-zig/src/ --include="*.zig" || echo "No TODOs found ✅"