Skip to content

Commit c3d0a97

Browse files
committed
all: fix more tests
1 parent 493890a commit c3d0a97

5 files changed

Lines changed: 100 additions & 36 deletions

File tree

cmd/tools/modules/testing/common.v

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,17 +302,20 @@ pub fn (mut ts TestSession) system(cmd string, mtc MessageThreadContext) int {
302302

303303
pub fn new_test_session(_vargs string, will_compile bool) TestSession {
304304
mut skip_files := []string{}
305+
vexe := pref.vexe_path()
306+
vroot := os.dir(vexe)
305307
if will_compile {
306308
if runner_os != 'Linux' || !github_job.starts_with('tcc-') {
307309
if !os.exists('/usr/local/include/wkhtmltox/pdf.h') {
308310
skip_files << 'examples/c_interop_wkhtmltopdf.v' // needs installation of wkhtmltopdf from https://github.com/wkhtmltopdf/packaging/releases
309311
}
310312
}
311313
}
314+
if os.user_os() == 'windows' {
315+
skip_files << windows_disabled_fasthttp_veb_tests(vroot)
316+
}
312317
skip_files = skip_files.map(os.abs_path)
313318
vargs := _vargs.replace('-progress', '')
314-
vexe := pref.vexe_path()
315-
vroot := os.dir(vexe)
316319
hash := '${sync.thread_id().hex()}_${rand.ulid()}'
317320
new_vtmp_dir := setup_new_vtmp_folder(hash)
318321
if term.can_show_color_on_stderr() {
@@ -340,6 +343,29 @@ pub fn new_test_session(_vargs string, will_compile bool) TestSession {
340343
return ts
341344
}
342345

346+
fn windows_disabled_fasthttp_veb_tests(vroot string) []string {
347+
mut files := []string{}
348+
for dir in [
349+
os.join_path(vroot, 'vlib', 'fasthttp'),
350+
os.join_path(vroot, 'vlib', 'veb'),
351+
] {
352+
if !os.is_dir(dir) {
353+
continue
354+
}
355+
os.walk(dir, fn [mut files] (path string) {
356+
if path.ends_with('_test.v') || path.ends_with('_test.c.v')
357+
|| path.ends_with('_test.js.v') {
358+
files << path
359+
}
360+
})
361+
}
362+
session_app_test := os.join_path(vroot, 'vlib', 'x', 'sessions', 'tests', 'session_app_test.v')
363+
if os.exists(session_app_test) {
364+
files << session_app_test
365+
}
366+
return files
367+
}
368+
343369
fn (mut ts TestSession) handle_test_runner_option() {
344370
test_runner := cmdline.option(os.args, '-test-runner', 'normal')
345371
if test_runner !in pref.supported_test_runners {

vlib/fasthttp/fasthttp_linux.v

Lines changed: 42 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ fn handle_accept_loop(epoll_fd int, listen_fd int, mut client_fds map[int]bool)
201201
}
202202
}
203203

204-
fn handle_client_closure(epoll_fd int, client_fd int, mut client_fds map[int]bool) {
204+
fn handle_client_closure(epoll_fd int, client_fd int, mut client_fds map[int]bool, mut client_buffers map[int][]u8) {
205205
// Never close the listening socket here
206206
if client_fd == 0 {
207207
return
@@ -211,17 +211,18 @@ fn handle_client_closure(epoll_fd int, client_fd int, mut client_fds map[int]boo
211211
return
212212
}
213213
client_fds.delete(client_fd)
214+
client_buffers.delete(client_fd)
214215
remove_fd_from_epoll(epoll_fd, client_fd)
215216
close_socket(client_fd)
216217
}
217218

218-
fn close_worker_clients(epoll_fd int, mut client_fds map[int]bool) {
219+
fn close_worker_clients(epoll_fd int, mut client_fds map[int]bool, mut client_buffers map[int][]u8) {
219220
for client_fd in client_fds.keys() {
220-
handle_client_closure(epoll_fd, client_fd, mut client_fds)
221+
handle_client_closure(epoll_fd, client_fd, mut client_fds, mut client_buffers)
221222
}
222223
}
223224

224-
fn process_request(server &Server, epoll_fd int, client_fd int, request_buffer []u8, mut client_fds map[int]bool) {
225+
fn process_request(server &Server, epoll_fd int, client_fd int, request_buffer []u8, mut client_fds map[int]bool, mut client_buffers map[int][]u8) {
225226
server.begin_request()
226227
defer {
227228
server.end_request()
@@ -230,7 +231,7 @@ fn process_request(server &Server, epoll_fd int, client_fd int, request_buffer [
230231
eprintln('Error decoding request ${err}')
231232
C.send(client_fd, tiny_bad_request_response.data, tiny_bad_request_response.len,
232233
C.MSG_NOSIGNAL)
233-
handle_client_closure(epoll_fd, client_fd, mut client_fds)
234+
handle_client_closure(epoll_fd, client_fd, mut client_fds, mut client_buffers)
234235
return
235236
}
236237
decoded_http_request.client_conn_fd = client_fd
@@ -239,14 +240,15 @@ fn process_request(server &Server, epoll_fd int, client_fd int, request_buffer [
239240
eprintln('Error handling request ${err}')
240241
C.send(client_fd, tiny_bad_request_response.data, tiny_bad_request_response.len,
241242
C.MSG_NOSIGNAL)
242-
handle_client_closure(epoll_fd, client_fd, mut client_fds)
243+
handle_client_closure(epoll_fd, client_fd, mut client_fds, mut client_buffers)
243244
return
244245
}
245246

246247
if response.takeover {
247248
// The handler has taken ownership of the connection.
248249
// Remove from epoll and tracking, but do NOT close the fd.
249250
client_fds.delete(client_fd)
251+
client_buffers.delete(client_fd)
250252
remove_fd_from_epoll(epoll_fd, client_fd)
251253
return
252254
}
@@ -265,7 +267,7 @@ fn process_request(server &Server, epoll_fd int, client_fd int, request_buffer [
265267
pos += sent
266268
}
267269
if send_error {
268-
handle_client_closure(epoll_fd, client_fd, mut client_fds)
270+
handle_client_closure(epoll_fd, client_fd, mut client_fds, mut client_buffers)
269271
return
270272
}
271273
}
@@ -274,7 +276,7 @@ fn process_request(server &Server, epoll_fd int, client_fd int, request_buffer [
274276
mut fd := C.open(response.file_path.str, C.O_RDONLY, 0)
275277
if fd == -1 {
276278
eprintln('ERROR: open file failed')
277-
handle_client_closure(epoll_fd, client_fd, mut client_fds)
279+
handle_client_closure(epoll_fd, client_fd, mut client_fds, mut client_buffers)
278280
return
279281
}
280282
defer {
@@ -285,7 +287,7 @@ fn process_request(server &Server, epoll_fd int, client_fd int, request_buffer [
285287
mut st := C.stat{}
286288
if C.fstat(fd, &st) != 0 {
287289
eprintln('ERROR: fstat failed')
288-
handle_client_closure(epoll_fd, client_fd, mut client_fds)
290+
handle_client_closure(epoll_fd, client_fd, mut client_fds, mut client_buffers)
289291
return
290292
}
291293
mut offset := i64(0)
@@ -333,26 +335,28 @@ fn process_request(server &Server, epoll_fd int, client_fd int, request_buffer [
333335
}
334336
}
335337

336-
handle_client_closure(epoll_fd, client_fd, mut client_fds)
338+
handle_client_closure(epoll_fd, client_fd, mut client_fds, mut client_buffers)
337339
return
338340
}
339341
}
340342

343+
client_buffers.delete(client_fd)
341344
if server.is_shutting_down() || response.should_close {
342-
handle_client_closure(epoll_fd, client_fd, mut client_fds)
345+
handle_client_closure(epoll_fd, client_fd, mut client_fds, mut client_buffers)
343346
}
344347
}
345348

346349
fn process_events(server &Server, epoll_fd int, listen_fd int) {
347350
mut events := [max_connection_size]C.epoll_event{}
348351
mut request_buffer := []u8{len: server.max_request_buffer_size, cap: server.max_request_buffer_size}
349352
mut client_fds := map[int]bool{}
353+
mut client_buffers := map[int][]u8{}
350354
unsafe {
351355
request_buffer.flags.set(.noslices | .nogrow | .noshrink)
352356
}
353357
for {
354358
if server.is_shutting_down() && server.active_request_count() == 0 {
355-
close_worker_clients(epoll_fd, mut client_fds)
359+
close_worker_clients(epoll_fd, mut client_fds, mut client_buffers)
356360
return
357361
}
358362
num_events := C.epoll_wait(epoll_fd, &events[0], max_connection_size, epoll_wait_timeout_ms)
@@ -386,23 +390,28 @@ fn process_events(server &Server, epoll_fd int, listen_fd int) {
386390
// Try to send 444 No Response before closing abnormal connection
387391
C.send(client_fd, status_444_response.data, status_444_response.len,
388392
C.MSG_NOSIGNAL)
389-
handle_client_closure(epoll_fd, client_fd, mut client_fds)
393+
handle_client_closure(epoll_fd, client_fd, mut client_fds, mut client_buffers)
390394
} else {
391395
eprintln('ERROR: Invalid FD from epoll: ${client_fd}')
392396
}
393397
continue
394398
}
395399
if events[i].events & u32(C.EPOLLIN) != 0 {
396400
if server.is_shutting_down() {
397-
handle_client_closure(epoll_fd, client_fd, mut client_fds)
401+
handle_client_closure(epoll_fd, client_fd, mut client_fds, mut client_buffers)
398402
continue
399403
}
400404
// Read all available data from the socket
401405
mut total_bytes_read := 0
402-
mut readed_request_buffer := []u8{cap: server.max_request_buffer_size}
406+
mut readed_request_buffer := client_buffers[client_fd] or {
407+
[]u8{cap: server.max_request_buffer_size}
408+
}
403409
mut headers_complete := false
404410
mut header_too_large := false
405411
mut header_end_pos := -1
412+
mut request_complete := false
413+
mut peer_closed := false
414+
mut recv_error := false
406415

407416
for {
408417
bytes_read := C.recv(client_fd, unsafe { &request_buffer[0] },
@@ -414,9 +423,11 @@ fn process_events(server &Server, epoll_fd int, listen_fd int) {
414423
}
415424
// Error occurred
416425
eprintln('ERROR: recv() failed with errno=${C.errno}')
426+
recv_error = true
417427
break
418428
} else if bytes_read == 0 {
419429
// Connection closed by client
430+
peer_closed = true
420431
break
421432
}
422433

@@ -426,11 +437,12 @@ fn process_events(server &Server, epoll_fd int, listen_fd int) {
426437
total_bytes_read += bytes_read
427438

428439
// Enforce the configured limit on request headers, not on the whole body.
429-
if !headers_complete && total_bytes_read >= 4 {
440+
buffer_len := readed_request_buffer.len
441+
if !headers_complete && buffer_len >= 4 {
430442
header_end_pos = find_header_end_in_buf(readed_request_buffer.data,
431-
total_bytes_read)
443+
buffer_len)
432444
if header_end_pos == -1 {
433-
if total_bytes_read >= server.max_request_buffer_size {
445+
if buffer_len >= server.max_request_buffer_size {
434446
header_too_large = true
435447
break
436448
}
@@ -443,29 +455,31 @@ fn process_events(server &Server, epoll_fd int, listen_fd int) {
443455
}
444456
}
445457

446-
if headers_complete
447-
&& has_complete_body(readed_request_buffer.data, total_bytes_read) {
458+
if headers_complete && has_complete_body(readed_request_buffer.data, buffer_len) {
459+
request_complete = true
448460
break
449461
}
450462
}
451463

452464
if header_too_large {
453465
C.send(client_fd, status_413_response.data, status_413_response.len,
454466
C.MSG_NOSIGNAL)
455-
handle_client_closure(epoll_fd, client_fd, mut client_fds)
467+
handle_client_closure(epoll_fd, client_fd, mut client_fds, mut client_buffers)
456468
continue
457469
}
458-
if total_bytes_read > 0 {
470+
if request_complete {
459471
process_request(server, epoll_fd, client_fd, readed_request_buffer, mut
460-
client_fds)
461-
} else if total_bytes_read == 0 {
462-
// Normal client closure (FIN received)
463-
handle_client_closure(epoll_fd, client_fd, mut client_fds)
464-
} else if total_bytes_read < 0 && C.errno != C.EAGAIN && C.errno != C.EWOULDBLOCK {
472+
client_fds, mut client_buffers)
473+
} else if recv_error {
465474
// Unexpected recv error - send 444 No Response
466475
C.send(client_fd, status_444_response.data, status_444_response.len,
467476
C.MSG_NOSIGNAL)
468-
handle_client_closure(epoll_fd, client_fd, mut client_fds)
477+
handle_client_closure(epoll_fd, client_fd, mut client_fds, mut client_buffers)
478+
} else if peer_closed || (total_bytes_read == 0 && readed_request_buffer.len == 0) {
479+
// Normal client closure (FIN received)
480+
handle_client_closure(epoll_fd, client_fd, mut client_fds, mut client_buffers)
481+
} else if readed_request_buffer.len > 0 {
482+
client_buffers[client_fd] = readed_request_buffer
469483
}
470484
}
471485
}

vlib/v/builder/cbuilder/parallel_cc.v

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,14 @@ fn parallel_cc(mut b builder.Builder, result c.GenOutput) ! {
7979
cc := b.quote_compiler_name(parallel_cc_compiler_path(b))
8080
mut compile_args := b.get_compile_args()
8181
mut linker_args := b.get_linker_args()
82+
if b.ccoptions.cc == .tcc {
83+
tcc_root := os.join_path(@VEXEROOT, 'thirdparty', 'tcc')
84+
if os.is_dir(tcc_root) {
85+
tcc_base_arg := '-B${b.tcc_quoted_path(tcc_root)}'
86+
compile_args << tcc_base_arg
87+
linker_args << tcc_base_arg
88+
}
89+
}
8290
scompile_args := compile_args.join(' ')
8391
slinker_args := linker_args.join(' ')
8492
scompile_args_for_linker := compile_args.filter(it != '-x objective-c').join(' ')

vlib/v/builder/cc_test.v

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ fn test_thirdparty_cross_compile_config_for_linux_matches_target() {
353353
return
354354
}
355355
assert cfg.target_args == ['-target x86_64-linux-gnu']
356-
assert cfg.sysroot.ends_with('/linuxroot')
356+
assert normalized_test_path(cfg.sysroot).ends_with('/linuxroot')
357357
assert cfg.trailing_include_args == [
358358
'-I',
359359
os.quoted_path('${cfg.sysroot}/include'),
@@ -370,7 +370,7 @@ fn test_thirdparty_cross_compile_config_for_freebsd_matches_target() {
370370
return
371371
}
372372
assert cfg.target_args == ['-target x86_64-unknown-freebsd14.0']
373-
assert cfg.sysroot.ends_with('/freebsdroot')
373+
assert normalized_test_path(cfg.sysroot).ends_with('/freebsdroot')
374374
assert cfg.trailing_include_args == [
375375
'-I',
376376
os.quoted_path('${cfg.sysroot}/include'),
@@ -419,7 +419,7 @@ fn test_live_windows_main_linker_args_export_host_symbols() {
419419
])
420420
assert linker_args.contains('-Wl,--export-all-symbols')
421421
assert linker_args.contains('-Wl,--out-implib,')
422-
assert linker_args.contains(live_windows_import_lib_path(hot_reload_graph_example()))
422+
assert normalized_test_path(linker_args).contains(normalized_test_path(live_windows_import_lib_path(hot_reload_graph_example())))
423423
}
424424

425425
fn test_live_windows_shared_linker_args_include_host_import_lib() {
@@ -432,7 +432,7 @@ fn test_live_windows_shared_linker_args_include_host_import_lib() {
432432
'-shared',
433433
hot_reload_graph_example(),
434434
])
435-
assert linker_args.contains(live_windows_import_lib_path(hot_reload_graph_example()))
435+
assert normalized_test_path(linker_args).contains(normalized_test_path(live_windows_import_lib_path(hot_reload_graph_example())))
436436
}
437437

438438
fn test_windows_cross_compile_args_match_shared_prod_args() {
@@ -560,6 +560,10 @@ fn hot_reload_graph_example() string {
560560
return os.join_path(@VEXEROOT, 'examples', 'hot_reload', 'graph.v')
561561
}
562562

563+
fn normalized_test_path(path string) string {
564+
return path.replace('\\', '/')
565+
}
566+
563567
fn test_c_output_suggests_missing_typedef_for_c_struct_with_issue_19050_output() {
564568
c_output := [
565569
"/tmp/v_501/c_struct.6580681062929530137.tmp.c:12966:17: error: incomplete result type 'struct string_c' in function definition",

vlib/v/builder/msvc_windows_test.v

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ module builder
22

33
import os
44
import v.cflag
5+
import v.pref
56

67
fn test_msvc_string_flags_uses_cached_thirdparty_obj_path() {
78
obj_file := os.join_path(@VEXEROOT, 'thirdparty', 'mbedtls', 'library', 'bignum.o')
8-
mut builder := new_builder_for_args(['-cc', 'msvc', '-m32', hello_world_example()])
9+
mut builder := msvc_new_builder_for_args(['-cc', 'msvc', '-m32', msvc_hello_world_example()])
910
cached_obj := builder.pref.cache_manager.mod_postfix_with_key2cpath('mbedtls', '.o',
1011
os.real_path(obj_file))
1112
expected_obj := builder.msvc_thirdparty_obj_path('mbedtls', obj_file, cached_obj)
@@ -27,7 +28,7 @@ fn test_msvc_string_flags_rewrites_obj_flags_through_cached_path() {
2728
defer {
2829
os.rmdir_all(test_dir) or {}
2930
}
30-
mut builder := new_builder_for_args(['-cc', 'msvc', '-m64', hello_world_example()])
31+
mut builder := msvc_new_builder_for_args(['-cc', 'msvc', '-m64', msvc_hello_world_example()])
3132
builder.table.cflags = [
3233
cflag.CFlag{
3334
mod: 'builtin'
@@ -43,3 +44,14 @@ fn test_msvc_string_flags_rewrites_obj_flags_through_cached_path() {
4344
sflags := builder.msvc_string_flags(flags)
4445
assert sflags.other_flags == ['"${expected_obj}"']
4546
}
47+
48+
fn msvc_new_builder_for_args(args []string) Builder {
49+
mut full_args := ['']
50+
full_args << args
51+
prefs, _ := pref.parse_args_and_show_errors([], full_args, false)
52+
return new_builder(prefs)
53+
}
54+
55+
fn msvc_hello_world_example() string {
56+
return os.join_path(@VEXEROOT, 'examples', 'hello_world.v')
57+
}

0 commit comments

Comments
 (0)