AtlatestRepositorysigil-quic
sigil-quic / tree / scriptsnative-tls-tests.mjs
1
// Generate a native test entry from the same test bodies used by sigil test.2
// The custom-runtime CLI test harness does not forward native build-fn yet.3
// Run this generator and the resulting build only on the test machine.4
import { readFileSync, writeFileSync, mkdirSync } from 'node:fs';5
import { dirname, join, resolve } from 'node:path';6
import { fileURLToPath } from 'node:url';8
const root = resolve(dirname(fileURLToPath(import.meta.url)), '..');9
const output = join(root, 'build', 'native-tests');10
const source = join(output, 'src', 'sigil', 'quic', 'tests');11
mkdirSync(source, { recursive: true });12
const files = [13
'test-tls-codec.sgl', 'test-tls-extensions.sgl',14
'test-tls-seen.sgl',15
'test-tls-negotiation.sgl',16
'test-tls-certificate-policy.sgl',17
'test-tls-retry-policy.sgl',18
'test-tls-authentication.sgl', 'test-tls-handshake.sgl',19
'test-tls-input-bounds.sgl',20
'test-tls-alerts.sgl',21
'test-frame.sgl',22
'test-datagram-codec.sgl',23
'test-reassembly.sgl',24
'test-packet.sgl',25
'test-retry-packet.sgl',26
'test-client-retry.sgl',27
'test-retry-token.sgl',28
'test-server-retry.sgl',29
'test-connection-space.sgl',30
'test-connection.sgl',31
'test-connection-network.sgl',32
'test-addressed-output.sgl',33
'test-network-confirmation.sgl',34
'test-network-receive.sgl',35
'test-random-ids.sgl',36
'test-datagram.sgl',37
'test-aead-limits.sgl',38
'test-application-close.sgl',39
'test-transport-errors.sgl',40
'test-frame-work.sgl',41
'test-close-levels.sgl',42
'test-closing.sgl',43
'test-api-validation.sgl',44
'test-quic-conformance.sgl',45
'test-ticket-validation.sgl',46
'test-psk-fallback.sgl',47
'test-sni-fallback.sgl',48
'test-tls-identity.sgl',49
'test-path-response.sgl',50
'test-path-validation.sgl',51
'test-path-manager.sgl',52
'test-cid-zero.sgl',53
'test-cid-sequence.sgl',54
'test-local-ids.sgl',55
'test-peer-ids.sgl',56
'test-handler-readiness.sgl',57
'test-early-packets.sgl',58
'test-receive-bounds.sgl',59
'test-handshake-probes.sgl',60
'test-idle-timeout.sgl',61
'test-stream.sgl',62
'test-stream-sequence.sgl',63
'test-endpoint.sgl',64
'test-endpoint-admission.sgl',65
'test-endpoint-retry.sgl',66
'test-endpoint-network.sgl',67
'test-address.sgl',68
'test-endpoint-bind.sgl',69
];70
const cleanupFaults = process.argv.includes('--cleanup-faults');71
const secretCleanup = process.argv.includes('--secret-cleanup');72
const secretRetention = process.argv.includes('--secret-retention');73
const handshakeCleanup = process.argv.includes('--handshake-cleanup');74
const packetRetention = process.argv.includes('--packet-retention');75
const factoryCleanup = process.argv.includes('--factory-cleanup');76
const eventCleanup = process.argv.includes('--event-cleanup');77
const constructionCleanup = process.argv.includes('--construction-cleanup');78
const pathResponse = process.argv.includes('--path-response');79
const cidZero = process.argv.includes('--cid-zero');80
const cidSequence = process.argv.includes('--cid-sequence');81
const handlerReadiness = process.argv.includes('--handler-readiness');82
const seenBudget = process.argv.includes('--seen-budget');83
const ticketValidation = process.argv.includes('--ticket-validation');84
const negotiation = process.argv.includes('--negotiation');85
const certificatePolicy = process.argv.includes('--certificate-policy');86
const retryPolicy = process.argv.includes('--retry-policy');87
const earlyPackets = process.argv.includes('--early-packets');88
const retryPacket = process.argv.includes('--retry-packet');89
const clientRetry = process.argv.includes('--client-retry');90
const retryToken = process.argv.includes('--retry-token');91
const serverRetry = process.argv.includes('--server-retry');92
const endpointRetry = process.argv.includes('--endpoint-retry');93
const retryCleanup = process.argv.includes('--retry-cleanup');94
const datagram = process.argv.includes('--datagram');95
const pathValidation = process.argv.includes('--path-validation');96
const localIds = process.argv.includes('--local-ids');97
const peerIds = process.argv.includes('--peer-ids');98
const pathManager = process.argv.includes('--path-manager');99
const connectionNetwork = process.argv.includes('--connection-network');100
const networkIntegration = process.argv.includes('--network-integration');101
const endpointNetwork = process.argv.includes('--endpoint-network');102
const endpointBind = process.argv.includes('--endpoint-bind');103
if ([cleanupFaults, secretCleanup, secretRetention, handshakeCleanup, packetRetention, factoryCleanup, eventCleanup, constructionCleanup, pathResponse, cidZero, cidSequence, handlerReadiness, seenBudget, ticketValidation, negotiation, certificatePolicy, retryPolicy, earlyPackets, retryPacket, clientRetry, retryToken, serverRetry, endpointRetry, retryCleanup, datagram, pathValidation, localIds, peerIds, pathManager, connectionNetwork, networkIntegration, endpointNetwork, endpointBind].filter(Boolean).length > 1) {104
throw new Error('Select one focused test suite');105
}106
if (cleanupFaults) {107
files.splice(0, files.length, '../scripts/cleanup-failure-tests.sgl');108
}109
if (secretCleanup) {110
files.splice(0, files.length, '../scripts/secret-cleanup-tests.sgl');111
}112
if (secretRetention) {113
files.splice(0, files.length, '../scripts/secret-retention-tests.sgl');114
}115
if (handshakeCleanup) {116
files.splice(0, files.length, '../scripts/handshake-cleanup-tests.sgl');117
}118
if (packetRetention) {119
files.splice(0, files.length, '../scripts/packet-retention-tests.sgl');120
}121
if (factoryCleanup) {122
files.splice(0, files.length, '../scripts/factory-cleanup-tests.sgl');123
}124
if (eventCleanup) {125
files.splice(0, files.length, '../scripts/event-cleanup-tests.sgl');126
}127
if (constructionCleanup) {128
files.splice(0, files.length, '../scripts/construction-cleanup-tests.sgl');129
}130
if (pathResponse) {131
files.splice(0, files.length, 'test-path-response.sgl');132
}133
if (cidZero) {134
files.splice(0, files.length, 'test-cid-zero.sgl');135
}136
if (cidSequence) {137
files.splice(0, files.length, 'test-cid-sequence.sgl');138
}139
if (handlerReadiness) {140
files.splice(0, files.length, 'test-handler-readiness.sgl');141
}142
if (seenBudget) {143
files.splice(0, files.length, 'test-tls-seen.sgl', '../scripts/seen-budget-tests.sgl');144
}145
if (ticketValidation) {146
files.splice(0, files.length, 'test-ticket-validation.sgl');147
}148
if (negotiation) {149
files.splice(0, files.length, 'test-tls-negotiation.sgl');150
}151
if (certificatePolicy) {152
files.splice(0, files.length, 'test-tls-certificate-policy.sgl');153
}154
if (retryPolicy) {155
files.splice(0, files.length, 'test-tls-retry-policy.sgl');156
}157
if (earlyPackets) {158
files.splice(0, files.length, 'test-early-packets.sgl');159
}160
if (retryPacket) {161
files.splice(0, files.length, 'test-retry-packet.sgl');162
}163
if (clientRetry) {164
files.splice(0, files.length, 'test-client-retry.sgl');165
}166
if (retryToken) {167
files.splice(0, files.length, 'test-retry-token.sgl');168
}169
if (serverRetry) {170
files.splice(0, files.length, 'test-server-retry.sgl');171
}172
if (endpointRetry) {173
files.splice(0, files.length, 'test-endpoint-retry.sgl');174
}175
if (retryCleanup) {176
files.splice(0, files.length, '../scripts/retry-cleanup-tests.sgl');177
}178
if (datagram) {179
files.splice(0, files.length, 'test-datagram-codec.sgl', 'test-datagram.sgl');180
}181
if (pathValidation) {182
files.splice(0, files.length, 'test-path-validation.sgl');183
}184
if (localIds) {185
files.splice(0, files.length, 'test-local-ids.sgl');186
}187
if (peerIds) {188
files.splice(0, files.length, 'test-peer-ids.sgl');189
}190
if (pathManager) {191
files.splice(0, files.length, 'test-path-manager.sgl');192
}193
if (connectionNetwork) {194
files.splice(0, files.length, 'test-connection-network.sgl');195
}196
if (networkIntegration) {197
files.splice(0, files.length, 'test-addressed-output.sgl', 'test-network-confirmation.sgl', 'test-network-receive.sgl', 'test-random-ids.sgl');198
}199
if (endpointNetwork) {200
files.splice(0, files.length, 'test-endpoint.sgl', 'test-endpoint-admission.sgl', 'test-endpoint-retry.sgl', 'test-endpoint-network.sgl');201
}202
if (endpointBind) {203
files.splice(0, files.length, 'test-endpoint.sgl', 'test-endpoint-admission.sgl', 'test-endpoint-retry.sgl', 'test-endpoint-network.sgl', 'test-address.sgl', 'test-endpoint-bind.sgl');204
}205
const bodies = files.map(file => {206
const text = readFileSync(join(root, 'test', file), 'utf8');207
const boundary = text.indexOf('\n\n');208
if (!text.startsWith('(import ') || boundary < 0) {209
throw new Error(`Unexpected import header in ${file}`);210
}211
return text.slice(boundary + 2).trimEnd();212
});213
writeFileSync(join(source, 'native.sgl'), `(define-library (sigil quic tests native)214
(import (sigil test)215
(sigil math)216
(sigil io)217
(sigil socket)218
(sigil process)${files.includes('test-endpoint-retry.sgl') || retryCleanup ? '\n (sigil time)' : ''}219
(sigil crypto)220
(sigil quic bytes)221
(sigil quic vectors)222
(sigil quic wire)223
(sigil quic frame)224
(sigil quic reassembly)225
(sigil quic packet)${files.includes('test-retry-token.sgl') || retryCleanup ? '\n (sigil quic retry token)' : ''}226
(sigil quic error)227
(sigil quic connection space)228
(sigil quic connection)${(files.includes('test-local-ids.sgl') || files.includes('test-random-ids.sgl')) ? '\n (sigil quic connection ids)' : ''}${files.includes('test-peer-ids.sgl') ? '\n (sigil quic connection peer ids)' : ''}${(files.includes('test-connection-network.sgl') || files.includes('test-network-confirmation.sgl')) ? '\n (sigil quic connection network)' : ''}229
(sigil quic stream)230
(sigil quic endpoint)${files.includes('test-address.sgl') || files.includes('test-endpoint-bind.sgl') ? '\n (sigil quic address)' : ''}${files.includes('test-path-validation.sgl') ? '\n (sigil quic path validation)' : ''}${files.includes('test-path-manager.sgl') ? '\n (sigil quic path manager)' : ''}231
(sigil quic stream state)232
(sigil quic transport parameters)233
(sigil quic tls)234
(sigil quic tls codec)235
(sigil quic tls messages)236
(sigil quic tls identity)237
(sigil quic tls signature)238
(sigil quic tls extensions)239
(sigil quic tls authentication)240
(sigil quic tls transcript)241
(sigil quic tls vectors)${secretCleanup || secretRetention ? '\n (sigil quic tests secret spy)' : ''}${handshakeCleanup ? '\n (sigil quic tests handshake spy)' : ''}${packetRetention ? '\n (sigil quic tests packet spy)' : ''}${factoryCleanup ? '\n (sigil quic tests factory spy)' : ''}${eventCleanup ? '\n (sigil quic tests event spy)' : ''}${constructionCleanup ? '\n (sigil quic tests construction spy)' : ''}${seenBudget ? '\n (sigil quic tests seen spy)' : ''}${retryCleanup ? '\n (sigil quic tests retry spy)\n (sigil quic tests retry fixture)' : ''})242
(export main)243
(begin244
${bodies.map(body => body.split('\n').map(line => ' ' + line).join('\n')).join('\n\n')}246
(define (main . args)247
(let ((summary (run-tests-filtered (lambda (descriptor) #t))))248
(for-each249
(lambda (result)250
(unless (test-result-passed? result)251
(println "NATIVE-FAIL ~a: ~a"252
(test-result-name result) (test-result-message result))))253
(test-summary-results summary))254
(println "NATIVE-TLS total=~a passed=~a failed=~a"255
(test-summary-total summary)256
(test-summary-passed summary)257
(test-summary-failed summary))258
(exit259
(if (and (> (test-summary-total summary) 0)260
(= (test-summary-failed summary) 0))261
0262
1))))))263
`);264
writeFileSync(join(output, 'package.sgl'), `(package265
name: "sigil-quic-native-tests"266
version: "0.1.0"267
sigil: "0.22"268
entry: '(sigil quic tests native)269
dependencies: (list270
(from-path dir: "../.." name: "sigil-quic")271
(from-git url: "codeberg:sigil/sigil-crypto" version: "^0.18.1")272
(from-git url: "codeberg:sigil/sigil" package: "sigil-test" version: "^0.22")273
(from-git url: "codeberg:sigil/sigil" package: "sigil-lib" version: "^0.22")274
(from-git url: "codeberg:sigil/sigil" package: "sigil-stdlib" version: "^0.22"))275
configs: (list276
(config277
name: 'native278
backend: 'native279
debug?: #f280
optimize: 2281
bundle?: #t282
output-dir: "build/native"))283
bundle-name: "quic-native-tests")284
`);285
process.stdout.write(`Native test source generated in ${output}\n`);