From ce3a25a0b4419016f673a021db6413261218df9c Mon Sep 17 00:00:00 2001 From: Hojun-Cho Date: Mon, 22 Jun 2026 23:29:39 +0900 Subject: [PATCH] test: contain sepwork scratch per-driver tmpdir, fix /tmp+in-repo leak (#8) The wcc test drivers ran `ww build ` with no -o, so the compiler's .sepwork scratch landed beside the source and was never cleaned: unbounded /tmp growth (2195 stale dirs observed) that fills tmpfs and fabricates phantom test failures + silent harness aborts, and for in-repo fixture builds leaked .sepwork into the tracked tree. Each leaking build now writes its source + output inside a per-invocation tmpdir, passes -o / so the .sepwork lands inside it, and rm -rf's the tmpdir on every exit path -- including fopen-fail and the expected-fail reject builds (scratch is mkdir'd before the build can fail). `ww run` and explicit-`-o`/byte-id helpers are left as-is; the 990/993 byte-id comparison logic is byte-for-byte unchanged. Two items filed separately (this commit holds the no-Makefile / no-main.c rail): - #13: a stale .s byte-id readback (749) silently no-ops since separate-compile emits .s to .sepwork/__root.s; documented inline. - #14: build-system Makefile recipes build selfhost/cmd/*/main.ww with no -o and leak main.sepwork in-tree (bounded, gitignored; own commit). One concern -- sepwork leak hygiene -- across 228 drivers; uniform transform applied per-file and two-round reviewed. make test: all 402 passed, zero net-new /tmp scratch, zero test-driven in-repo .sepwork. --- test/wcc/110_uniesc_run.c | 36 ++++----- test/wcc/631_def_neg_global.c | 25 +++---- test/wcc/640_int_cast_signed.c | 24 +++--- test/wcc/650_dot_chain.c | 25 +++---- test/wcc/660_field_signed.c | 25 +++---- test/wcc/670_frame_argcount.c | 24 +++--- test/wcc/671_struct_packed.c | 37 ++++----- test/wcc/680_arr_elem_field.c | 25 +++---- test/wcc/681_arr_elem_field_write.c | 24 +++--- test/wcc/682_arr_enum_elem.c | 25 +++---- test/wcc/683_arr_strslice_elem.c | 25 +++---- test/wcc/684_arr_infer_len.c | 50 +++++-------- test/wcc/685_arr_tagged_elem.c | 49 +++++------- test/wcc/686_slice_str_global_zero.c | 25 +++---- test/wcc/687_slice_literal_global.c | 53 ++++++------- test/wcc/688_global_arr_elem_field.c | 25 +++---- test/wcc/689_arrglob_nodup_run.c | 24 +++--- test/wcc/689_structlit_slice_field.c | 25 +++---- test/wcc/690_amp_dot.c | 24 +++--- test/wcc/691_dot_slice_arg.c | 24 +++--- test/wcc/692_dot_str_chained_arg.c | 25 +++---- test/wcc/693_dot_tagged_source.c | 24 +++--- test/wcc/694_tagged_store_intlit.c | 24 +++--- test/wcc/695_match_bind_struct.c | 25 +++---- test/wcc/696_modtype_leaf_collision.c | 34 ++++++--- test/wcc/697_samemod_prefer.c | 20 +++-- test/wcc/698_cgreturn_struct.c | 24 +++--- test/wcc/699_use_promote_alias.c | 20 +++-- test/wcc/700_e2e.c | 36 ++++----- test/wcc/701_cgassign_struct.c | 24 +++--- test/wcc/702_dot_explicit_deref.c | 24 +++--- test/wcc/703_nested_structlit.c | 24 +++--- test/wcc/704_dot_structlit.c | 24 +++--- test/wcc/705_nested_call_rhs.c | 24 +++--- test/wcc/706_fnlabel_mangle.c | 17 ++++- test/wcc/707_cgreturn_variant_zero.c | 24 +++--- test/wcc/708_param_shadow_mod.c | 44 ++++++++--- test/wcc/709_localoff_scope.c | 25 +++---- test/wcc/710_cast_enum_movl.c | 25 +++---- test/wcc/711_arrlit_str_full.c | 24 +++--- test/wcc/712_redecl.c | 48 +++--------- test/wcc/713_struct_field_index.c | 25 +++---- test/wcc/714_tagged_return_scratch.c | 25 +++---- test/wcc/715_tagged_widen_f64.c | 24 +++--- test/wcc/716_match_spill_pointer_payload.c | 24 +++--- test/wcc/717_struct_byval_param.c | 24 +++--- test/wcc/718_struct_multi_return_scratch.c | 24 +++--- test/wcc/729_empty_alloc_infer.c | 75 ++++++++++--------- test/wcc/732_def_const_fold.c | 24 +++--- test/wcc/737_direnum.c | 52 ++++++++++--- test/wcc/744_letcopy_struct.c | 29 +++---- test/wcc/748_size_strategy_convergence.c | 35 ++++----- test/wcc/749_sumtype_forward.c | 51 +++++-------- test/wcc/751_vararg_seq_percall.c | 35 ++++----- test/wcc/756_alias_chain_unwrap.c | 24 +++--- test/wcc/757_letbind_void_bang_void.c | 24 +++--- test/wcc/758_cgalloc_str_field.c | 23 +++--- test/wcc/759_check_enum_fold.c | 25 +++---- test/wcc/760_def_widen_const.c | 25 +++---- test/wcc/761_inferred_struct_arg_push.c | 25 +++---- test/wcc/762_struct_abi_size.c | 25 +++---- test/wcc/763_typeeq_fn_ast.c | 25 +++---- test/wcc/765_star_fn_deref.c | 28 +++---- test/wcc/768_io_types_run.c | 38 ++++------ test/wcc/795_xmod_valglobal_run.c | 49 ++++++------ test/wcc/796_xmod_valglobal_dot_run.c | 45 +++++------ test/wcc/800_append_wide_elem.c | 25 +++---- test/wcc/804_delete_elem.c | 27 +++---- test/wcc/805_placeaddr_store.c | 27 +++---- test/wcc/806_append_place.c | 27 +++---- test/wcc/806_tryprop_multisuccess.c | 26 +++---- test/wcc/807_insert_elem.c | 26 +++---- test/wcc/808_arrlit_overlong.c | 52 +++++-------- test/wcc/809_delete_range.c | 27 +++---- test/wcc/809_idx_structlit_store.c | 31 ++++---- test/wcc/810_dyn.c | 23 ++---- test/wcc/811_inferred_let_struct.c | 25 +++---- test/wcc/812_agg_assign_width.c | 25 +++---- test/wcc/813_arrlit_infer_elem_run.c | 25 +++---- test/wcc/814_def_arr_infer_len.c | 52 +++++-------- test/wcc/816_def_arr_len.c | 25 +++---- test/wcc/817_arr_cap_reject.c | 52 +++++-------- test/wcc/818_arr_ptr_global.c | 25 +++---- test/wcc/819_def_str_table.c | 25 +++---- test/wcc/820_arr_zero_vs_infer.c | 50 +++++-------- test/wcc/821_def_str_index_reject.c | 56 ++++++-------- test/wcc/822_struct_global_byval_arg.c | 25 +++---- test/wcc/823_inferred_global_let.c | 25 +++---- test/wcc/824_inferred_float_global.c | 25 +++---- test/wcc/825_errfirst_union_try.c | 25 +++---- test/wcc/826_alias_tuple_coerce.c | 49 +++++------- test/wcc/827_str_eq.c | 25 +++---- test/wcc/828_overlong_arrlit.c | 52 ++++++------- test/wcc/829_slice_str_global_arg.c | 25 +++---- test/wcc/830_cast_base_index.c | 25 +++---- test/wcc/831_match_field_inplace.c | 24 +++--- test/wcc/832_tuple_elem_overlong.c | 49 +++++------- test/wcc/833_inferred_array_global.c | 25 +++---- test/wcc/834_tagged_arr_variant.c | 49 +++++------- test/wcc/835_nested_union_int_box.c | 49 +++++------- test/wcc/836_tagged_assignable_cluster.c | 49 +++++------- test/wcc/837_idcast_tagged_return.c | 25 +++---- test/wcc/838_global_tagged_castinit.c | 45 +++++------ test/wcc/840_zeroinit_run.c | 47 +++++------- test/wcc/841_match_global_field.c | 24 +++--- test/wcc/842_dup_main_reject.c | 51 +++++-------- test/wcc/843_tagged_staticinit.c | 49 +++++------- test/wcc/844_size_untyped_int.c | 25 +++---- test/wcc/845_tuple_trailing_comma_reject.c | 44 +++++------ test/wcc/846_voidless_return_reject.c | 51 +++++-------- test/wcc/847_const_reassign_reject.c | 41 +++++----- test/wcc/849_dupfield_reject.c | 41 +++++----- test/wcc/850_enum_reject.c | 51 +++++-------- test/wcc/851_index_int_reject.c | 41 +++++----- test/wcc/852_variadic_body_reject.c | 41 +++++----- test/wcc/905_tupparam_run.c | 59 ++++++--------- test/wcc/907_f32arg_run.c | 52 ++++++------- test/wcc/911_continue_run.c | 52 +++++++------ test/wcc/913_def_mangle_run.c | 50 ++++++------- test/wcc/914_arr_u16_store_run.c | 50 ++++++------- test/wcc/916_arr_float_call_index_run.c | 52 ++++++------- test/wcc/917_def_float_lit_run.c | 52 ++++++------- test/wcc/918_struct_composite_init_run.c | 50 ++++++------- test/wcc/919_array_static_init_run.c | 52 +++++++------ test/wcc/919_strarray_static_run.c | 45 +++++------ test/wcc/920_array_init_acceptiffits_run.c | 48 ++++++------ test/wcc/921_amp_def_global_run.c | 59 +++++++-------- test/wcc/923_signed_data_emit_run.c | 24 +++--- test/wcc/924_tagged_call_arg_run.c | 25 +++---- test/wcc/926_match_slice_variant_run.c | 24 +++--- test/wcc/926_tagged_sret_run.c | 20 ++--- test/wcc/926_tagscr_sizes_run.c | 50 ++++++------- test/wcc/927_is_nonident_run.c | 19 ++--- test/wcc/928_match_nonident_idx_run.c | 51 ++++++------- test/wcc/929_tagged_memarg_run.c | 18 ++--- test/wcc/930_free_noop_run.c | 53 +++++++------ test/wcc/936_tagged_tuple_widen_run.c | 28 +++---- test/wcc/937_forrange_fieldbase_run.c | 28 +++---- test/wcc/938_tagged_structlit_payload_run.c | 27 +++---- test/wcc/940_mixed_scalar_tuple_sret_run.c | 27 +++---- test/wcc/940_overcap_tuple_field_store_run.c | 28 +++---- test/wcc/940_str_forrange_loopvar_run.c | 24 +++--- test/wcc/940_tuple_in_union_run.c | 28 +++---- test/wcc/941_tuple_slot_layout_run.c | 29 ++++--- test/wcc/944_alias_accept_run.c | 30 ++++---- test/wcc/944_alias_cgen_b5_run.c | 28 +++---- test/wcc/944_alias_cgen_b6_run.c | 29 ++++--- test/wcc/944_alias_decl_order_size_run.c | 28 +++---- test/wcc/944_alias_emit_b7_run.c | 28 +++---- test/wcc/944_alias_global_decl_run.c | 27 +++---- test/wcc/944_alias_idx_family_run.c | 27 +++---- test/wcc/944_alias_structlit_init_run.c | 27 +++---- test/wcc/944_array_zeroinit_run.c | 27 +++---- test/wcc/944_idx_tagged_field_run.c | 43 +++++------ test/wcc/944_nonlit_tuple_widen_run.c | 25 +++---- test/wcc/944_tagged_widen_arg_run.c | 27 +++---- test/wcc/944_tuple_tagged_union_run.c | 27 +++---- test/wcc/944_variant_chain_b95_run.c | 29 ++++--- test/wcc/945_rvalue_tuple_destructure_run.c | 27 +++---- test/wcc/945_tuple_lit_declblind_run.c | 29 +++---- test/wcc/945_tuple_nary_destructure_run.c | 28 +++---- test/wcc/946_append_structlit_evalorder_run.c | 27 +++---- test/wcc/946_const_slice_aggregate_run.c | 28 +++---- test/wcc/946_floatarr_run.c | 52 ++++++------- test/wcc/946_structparam_run.c | 55 +++++++------- test/wcc/946_structret_run.c | 58 +++++++------- test/wcc/947_inferred_scalar_global_run.c | 61 +++++++-------- test/wcc/947_tuple_index_read_run.c | 28 +++---- test/wcc/949_errtype_compare.c | 28 +++---- test/wcc/949_f9_float_run.c | 27 +++---- test/wcc/949_intbinop_mismatch.c | 28 +++---- test/wcc/949_missingpkg.c | 52 ++++++++----- test/wcc/949_structlit_arrfield_run.c | 50 ++++++------- test/wcc/949_valstruct_subsize_run.c | 52 ++++++------- test/wcc/949_void_error_singleton_run.c | 62 +++++++-------- test/wcc/951_arrlit_elem_narrow_run.c | 50 ++++++------- test/wcc/951_f64cgen_run.c | 34 ++++----- test/wcc/952_floats_run.c | 34 ++++----- test/wcc/953_arraytoslice_run.c | 51 ++++++------- test/wcc/953_arrlit_slice_run.c | 52 ++++++------- test/wcc/953_f64crossmod_run.c | 57 +++++++------- test/wcc/953_globalslice_arg_run.c | 36 ++++----- test/wcc/954_tuprecv_run.c | 66 ++++++++-------- test/wcc/955_f64xmm_run.c | 53 ++++++------- test/wcc/956_modqualdestr_run.c | 61 ++++++++------- test/wcc/956_tuprecv_f64_run.c | 49 +++++------- test/wcc/957_assert_builtin_run.c | 52 ++++++------- test/wcc/958_types_sizelim_run.c | 33 ++++---- test/wcc/959_types_intlim_run.c | 34 ++++----- test/wcc/960_opaque_decl_run.c | 34 ++++----- test/wcc/961_opaque_guards.c | 40 +++------- test/wcc/962_opaque_assign_cast_run.c | 56 +++++++------- test/wcc/963_sort_run.c | 34 ++++----- test/wcc/964_f32lit_run.c | 52 ++++++------- test/wcc/965_f32stamp_run.c | 55 +++++++------- test/wcc/975_dirs_toolong_run.c | 21 +++--- test/wcc/978_intdiv_signed.c | 25 +++---- test/wcc/989_allocalias_run.c | 24 +++--- test/wcc/989_ampfncollide_run.c | 24 +++--- test/wcc/989_arrlit_tail_zero_run.c | 24 +++--- test/wcc/989_callarg_typecheck.c | 58 ++++++-------- test/wcc/989_catA_f2_reject.c | 50 +++++-------- test/wcc/989_defercap_run.c | 26 +++---- test/wcc/989_ffivariadic_run.c | 28 +++---- test/wcc/989_floatlit_run.c | 33 ++++---- test/wcc/989_globfloatstructarg_run.c | 24 +++--- test/wcc/989_globstructwiden_run.c | 24 +++--- test/wcc/989_globtagisas_run.c | 24 +++--- test/wcc/989_globtagreassign_run.c | 24 +++--- test/wcc/989_globtagwiden_run.c | 24 +++--- test/wcc/989_intoverflow_reject.c | 50 +++++-------- test/wcc/989_libprecond_abort.c | 26 +++---- test/wcc/989_loopcap_run.c | 24 +++--- test/wcc/989_nestfield_run.c | 24 +++--- test/wcc/989_nullableglobal_reject.c | 49 +++++------- test/wcc/989_tagged_subset_reject.c | 53 ++++++------- test/wcc/989_taggedcompoundderef_reject.c | 50 +++++-------- test/wcc/989_taggedcompoundplace_reject.c | 49 +++++------- test/wcc/989_taggedderefstore_run.c | 24 +++--- test/wcc/989_taggedglobalindex_run.c | 24 +++--- test/wcc/989_taggedidx_run.c | 24 +++--- test/wcc/989_tagnorm_run.c | 24 +++--- test/wcc/989_tagtupfieldsize_run.c | 24 +++--- test/wcc/989_trycallcollide_run.c | 24 +++--- test/wcc/989_tupfieldsize_run.c | 24 +++--- test/wcc/989_unknowndecl_reject.c | 50 +++++-------- test/wcc/990_selfhost.c | 17 +++-- test/wcc/993_ww_ww.c | 23 ++++-- 228 files changed, 3387 insertions(+), 4484 deletions(-) diff --git a/test/wcc/110_uniesc_run.c b/test/wcc/110_uniesc_run.c index d43b70bc..57e606db 100644 --- a/test/wcc/110_uniesc_run.c +++ b/test/wcc/110_uniesc_run.c @@ -18,7 +18,6 @@ */ #include #include -#include #include #include #include @@ -109,34 +108,29 @@ static const struct row rows[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/wwue_%d_%d.ww", getpid(), i); + char src[128], tmpdir[64], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/wwue_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/wwue_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/wwue_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s", driver, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return got; } @@ -156,7 +150,11 @@ run_roundtrip(const char *driver, int id) snprintf(mainp, sizeof mainp, "%s/main.ww", dir); FILE *f = fopen(wrp, "wb"); - if (!f) return -1; + if (!f) { + snprintf(cmd, sizeof cmd, "rm -rf %s", dir); + (void)system(cmd); + return -1; + } /* one def per serializer branch: \x (<=0xFF), \u (<=0xFFFF), \U. */ fputs("package wr;\n" "export def EACUTE: rune = '\\u00e9';\n" @@ -164,7 +162,11 @@ run_roundtrip(const char *driver, int id) "export def SMILEY: rune = '\\U0001F600';\n", f); fclose(f); f = fopen(mainp, "wb"); - if (!f) return -1; + if (!f) { + snprintf(cmd, sizeof cmd, "rm -rf %s", dir); + (void)system(cmd); + return -1; + } fputs("package main;\n" "import wr;\n" "fn main() i32 = {\n" diff --git a/test/wcc/631_def_neg_global.c b/test/wcc/631_def_neg_global.c index e741043c..59f2e36c 100644 --- a/test/wcc/631_def_neg_global.c +++ b/test/wcc/631_def_neg_global.c @@ -39,7 +39,6 @@ */ #include #include -#include #include #include #include @@ -134,34 +133,30 @@ static const struct row rows[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/dng_%d_%d.ww", getpid(), i); + char tmpdir[64], src[128], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/dng_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/dng_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/dng_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>/dev/null", + driver, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return got; } diff --git a/test/wcc/640_int_cast_signed.c b/test/wcc/640_int_cast_signed.c index 405e26db..ed94bfbb 100644 --- a/test/wcc/640_int_cast_signed.c +++ b/test/wcc/640_int_cast_signed.c @@ -13,7 +13,6 @@ */ #include #include -#include #include #include #include @@ -141,34 +140,29 @@ static const struct row rows[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/wwic_%d_%d.ww", getpid(), i); + char tmpdir[64], src[128], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/wwic_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/wwic_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/wwic_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s", driver, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return got; } diff --git a/test/wcc/650_dot_chain.c b/test/wcc/650_dot_chain.c index 79fe78d3..528f4f05 100644 --- a/test/wcc/650_dot_chain.c +++ b/test/wcc/650_dot_chain.c @@ -16,7 +16,6 @@ */ #include #include -#include #include #include #include @@ -347,34 +346,30 @@ static const struct row rows[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/wdc_%d_%d.ww", getpid(), i); + char tmpdir[64], src[128], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/wdc_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/wdc_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/wdc_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s", + driver, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return got; } diff --git a/test/wcc/660_field_signed.c b/test/wcc/660_field_signed.c index 807bb98d..c041d3d8 100644 --- a/test/wcc/660_field_signed.c +++ b/test/wcc/660_field_signed.c @@ -11,7 +11,6 @@ */ #include #include -#include #include #include #include @@ -289,34 +288,30 @@ static const struct row rows[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/wwfs_%d_%d.ww", getpid(), i); + char src[128], tmpdir[64], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/wwfs_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/wwfs_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/wwfs_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s", + driver, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return got; } diff --git a/test/wcc/670_frame_argcount.c b/test/wcc/670_frame_argcount.c index 5ef42ffb..6b1ec2f5 100644 --- a/test/wcc/670_frame_argcount.c +++ b/test/wcc/670_frame_argcount.c @@ -15,7 +15,6 @@ */ #include #include -#include #include #include #include @@ -286,34 +285,29 @@ static const struct row rows[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/wwfa_%d_%d.ww", getpid(), i); + char tmpdir[64], src[128], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/wwfa_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/wwfa_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/wwfa_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s", driver, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return got; } diff --git a/test/wcc/671_struct_packed.c b/test/wcc/671_struct_packed.c index bfccbbc2..82fdc3ff 100644 --- a/test/wcc/671_struct_packed.c +++ b/test/wcc/671_struct_packed.c @@ -224,34 +224,30 @@ static const struct row rows[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/pk51_%d_%d.ww", getpid(), i); + char tmpdir[64], src[128], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/pk51_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/pk51_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/pk51_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -2; + if (!f) { runwait(rmcmd); return -2; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>/dev/null", + driver, outbin, src); int built = runwait(cmd); if (built != 0) { /* build failed (a reject, or a real error). Caller decides. */ - unlink(src); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return got; } @@ -312,19 +308,20 @@ asm_byte_identical(const char *bin, const struct row *r, int i) static int wwi_roundtrip(const char *driver, int idx) { - char root[80], libdir[128], appww[160], cmd[1024], outbin[200]; + char root[80], libdir[128], appww[160], cmd[1024], outbin[200], rm[200]; snprintf(root, sizeof root, "/tmp/pk51w_%d_%d", getpid(), idx); snprintf(libdir, sizeof libdir, "%s/lib/pk2", root); snprintf(appww, sizeof appww, "%s/app/main.ww", root); + snprintf(rm, sizeof rm, "rm -rf %s", root); char mk[256]; snprintf(mk, sizeof mk, "mkdir -p %s/lib/pk2 %s/app", root, root); - if (runwait(mk) != 0) return -1; + if (runwait(mk) != 0) { runwait(rm); return -1; } char pk2[256]; snprintf(pk2, sizeof pk2, "%s/lib/pk2/pk2.ww", root); FILE *f = fopen(pk2, "wb"); - if (!f) return -1; + if (!f) { runwait(rm); return -1; } /* pk2 exports ONLY the packed type — no helper fns. The size/offset * are computed on the IMPORTER side (below), so the value depends on * the .wwi re-parse laying Ev out packed. (If evsize()/evoff() lived @@ -335,7 +332,7 @@ wwi_roundtrip(const char *driver, int idx) fclose(f); f = fopen(appww, "wb"); - if (!f) return -1; + if (!f) { runwait(rm); return -1; } /* importer computes layout from the re-parsed .wwi: packed → 9*10+1 * = 91; a dropped @packed (unpacked Ev) would give 16*10+8 = 168. */ fputs("package main;\n" @@ -350,16 +347,12 @@ wwi_roundtrip(const char *driver, int idx) "cd %s/app && %s build -I %s/lib -o m main.ww 2>/dev/null", root, driver, root); if (runwait(cmd) != 0) { - char rm[200]; - snprintf(rm, sizeof rm, "rm -rf %s", root); runwait(rm); return -1; } snprintf(outbin, sizeof outbin, "%s/app/m", root); int got = runwait(outbin); - char rm[200]; - snprintf(rm, sizeof rm, "rm -rf %s", root); runwait(rm); return got; } diff --git a/test/wcc/680_arr_elem_field.c b/test/wcc/680_arr_elem_field.c index 7f66f4a7..b433b629 100644 --- a/test/wcc/680_arr_elem_field.c +++ b/test/wcc/680_arr_elem_field.c @@ -21,7 +21,6 @@ */ #include #include -#include #include #include #include @@ -145,34 +144,30 @@ static const struct row rows[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/wae_%d_%d.ww", getpid(), i); + char tmpdir[64], src[128], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/wae_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/wae_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/wae_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s", + driver, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return got; } diff --git a/test/wcc/681_arr_elem_field_write.c b/test/wcc/681_arr_elem_field_write.c index eb1f8191..37a92883 100644 --- a/test/wcc/681_arr_elem_field_write.c +++ b/test/wcc/681_arr_elem_field_write.c @@ -19,7 +19,6 @@ */ #include #include -#include #include #include #include @@ -496,34 +495,29 @@ static const struct row rows[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/waew_%d_%d.ww", getpid(), i); + char tmpdir[64], src[128], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/waew_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/waew_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/waew_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s", driver, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return got; } diff --git a/test/wcc/682_arr_enum_elem.c b/test/wcc/682_arr_enum_elem.c index 7f59b77b..d4a08b84 100644 --- a/test/wcc/682_arr_enum_elem.c +++ b/test/wcc/682_arr_enum_elem.c @@ -68,7 +68,6 @@ */ #include #include -#include #include #include #include @@ -154,34 +153,30 @@ static const struct row rows[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/aee_%d_%d.ww", getpid(), i); + char tmpdir[64], src[128], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/aee_%d_d_%d", getpid(), i); + snprintf(src, sizeof src, "%s/aee_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/aee_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); + mkdir(tmpdir, 0755); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>/dev/null", + driver, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return got; } diff --git a/test/wcc/683_arr_strslice_elem.c b/test/wcc/683_arr_strslice_elem.c index cfee2fed..3795aec6 100644 --- a/test/wcc/683_arr_strslice_elem.c +++ b/test/wcc/683_arr_strslice_elem.c @@ -68,7 +68,6 @@ */ #include #include -#include #include #include #include @@ -248,34 +247,30 @@ static const struct row rows[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/asse_%d_%d.ww", getpid(), i); + char tmpdir[64], src[128], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/asse_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/asse_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/asse_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>/dev/null", + driver, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return got; } diff --git a/test/wcc/684_arr_infer_len.c b/test/wcc/684_arr_infer_len.c index 791aa4f6..07d1d203 100644 --- a/test/wcc/684_arr_infer_len.c +++ b/test/wcc/684_arr_infer_len.c @@ -47,7 +47,6 @@ */ #include #include -#include #include #include #include @@ -188,34 +187,30 @@ static const char *neg[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/ail_%d_%d.ww", getpid(), i); + char tmpdir[64], src[128], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/ail_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/ail_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/ail_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>/dev/null", + driver, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return got; } @@ -225,29 +220,22 @@ run_driver(const char *driver, const struct row *r, int i) static int build_should_fail(const char *driver, const char *src, int i) { - char s[64], tmpdir[64], cmd[1024]; - snprintf(s, sizeof s, "/tmp/ailn_%d_%d.ww", getpid(), i); + char tmpdir[64], s[128], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/ailn_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(s, sizeof s, "%s/ailn_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/ailn_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(s, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null", - tmpdir, driver, s); + snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>/dev/null", + driver, outbin, s); int rc = runwait(cmd); - unlink(s); - /* clean any emitted binary */ - const char *base = strrchr(s, '/'); - base = base ? base + 1 : s; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; - unlink(outbin); - rmdir(tmpdir); + runwait(rmcmd); return rc == 0 ? -1 : 0; /* build must NOT succeed */ } diff --git a/test/wcc/685_arr_tagged_elem.c b/test/wcc/685_arr_tagged_elem.c index 914ec587..d8d68c13 100644 --- a/test/wcc/685_arr_tagged_elem.c +++ b/test/wcc/685_arr_tagged_elem.c @@ -51,7 +51,6 @@ */ #include #include -#include #include #include #include @@ -189,34 +188,30 @@ static const char *neg[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/atag_%d_%d.ww", getpid(), i); + char src[128], tmpdir[64], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/atag_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/atag_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/atag_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>/dev/null", + driver, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return got; } @@ -226,28 +221,22 @@ run_driver(const char *driver, const struct row *r, int i) static int build_should_fail(const char *driver, const char *src, int i) { - char s[64], tmpdir[64], cmd[1024]; - snprintf(s, sizeof s, "/tmp/atagn_%d_%d.ww", getpid(), i); + char s[128], tmpdir[64], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/atagn_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(s, sizeof s, "%s/atagn_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/atagn_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(s, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null", - tmpdir, driver, s); + snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>/dev/null", + driver, outbin, s); int rc = runwait(cmd); - unlink(s); - const char *base = strrchr(s, '/'); - base = base ? base + 1 : s; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; - unlink(outbin); - rmdir(tmpdir); + runwait(rmcmd); return rc == 0 ? -1 : 0; /* build must NOT succeed */ } diff --git a/test/wcc/686_slice_str_global_zero.c b/test/wcc/686_slice_str_global_zero.c index 8cef21ba..e58bbf21 100644 --- a/test/wcc/686_slice_str_global_zero.c +++ b/test/wcc/686_slice_str_global_zero.c @@ -26,7 +26,6 @@ */ #include #include -#include #include #include #include @@ -83,34 +82,30 @@ static const struct row rows[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/ssgz_%d_%d.ww", getpid(), i); + char src[128], tmpdir[64], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/ssgz_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/ssgz_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/ssgz_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>/dev/null", + driver, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return got; } diff --git a/test/wcc/687_slice_literal_global.c b/test/wcc/687_slice_literal_global.c index 869989f2..8518b3ca 100644 --- a/test/wcc/687_slice_literal_global.c +++ b/test/wcc/687_slice_literal_global.c @@ -50,7 +50,6 @@ */ #include #include -#include #include #include #include @@ -195,34 +194,32 @@ static const char *neg[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/slg_%d_%d.ww", getpid(), i); + char tmpdir[64], src[128], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/slg_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/slg_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/slg_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null", - tmpdir, driver, src); + /* #8: -o pins binary + .sepwork scratch under tmpdir; rm -rf on + * every exit path removes the now-non-empty dir. */ + snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>/dev/null", + driver, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return got; } @@ -230,28 +227,24 @@ run_driver(const char *driver, const struct row *r, int i) static int build_should_fail(const char *driver, const char *src, int i) { - char s[64], tmpdir[64], cmd[1024]; - snprintf(s, sizeof s, "/tmp/slgn_%d_%d.ww", getpid(), i); + char tmpdir[64], s[128], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/slgn_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(s, sizeof s, "%s/slgn_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/slgn_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(s, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null", - tmpdir, driver, s); + /* #8: -o pins binary + .sepwork scratch under tmpdir; a reject build + * still mkdir's scratch, so rm -rf must run on this path too. */ + snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>/dev/null", + driver, outbin, s); int rc = runwait(cmd); - unlink(s); - const char *base = strrchr(s, '/'); - base = base ? base + 1 : s; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; - unlink(outbin); - rmdir(tmpdir); + runwait(rmcmd); return rc == 0 ? -1 : 0; /* build must NOT succeed */ } diff --git a/test/wcc/688_global_arr_elem_field.c b/test/wcc/688_global_arr_elem_field.c index 322060c5..4637229e 100644 --- a/test/wcc/688_global_arr_elem_field.c +++ b/test/wcc/688_global_arr_elem_field.c @@ -45,7 +45,6 @@ */ #include #include -#include #include #include #include @@ -130,34 +129,30 @@ static const struct row rows[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/gae_%d_%d.ww", getpid(), i); + char tmpdir[64], src[128], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/gae_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/gae_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/gae_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>/dev/null", + driver, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return got; } diff --git a/test/wcc/689_arrglob_nodup_run.c b/test/wcc/689_arrglob_nodup_run.c index c9c3a79f..b3135ce1 100644 --- a/test/wcc/689_arrglob_nodup_run.c +++ b/test/wcc/689_arrglob_nodup_run.c @@ -50,29 +50,25 @@ static const char *SRC = static int run_driver(const char *driver) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/agnd_%d.ww", getpid()); + char tmpdir[64], src[128], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/agnd_%d_d", getpid()); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/agnd_%d.ww", tmpdir, getpid()); + snprintf(outbin, sizeof outbin, "%s/agnd_%d", tmpdir, getpid()); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(SRC, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null", - tmpdir, driver, src); - if (runwait(cmd) != 0) { unlink(src); rmdir(tmpdir); return -1; } + snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>/dev/null", + driver, outbin, src); + if (runwait(cmd) != 0) { runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return got; } diff --git a/test/wcc/689_structlit_slice_field.c b/test/wcc/689_structlit_slice_field.c index 32f2a39d..da6d08c1 100644 --- a/test/wcc/689_structlit_slice_field.c +++ b/test/wcc/689_structlit_slice_field.c @@ -48,7 +48,6 @@ */ #include #include -#include #include #include #include @@ -198,34 +197,30 @@ static const struct row rows[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/slf_%d_%d.ww", getpid(), i); + char tmpdir[64], src[128], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/slf_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/slf_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/slf_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>/dev/null", + driver, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return got; } diff --git a/test/wcc/690_amp_dot.c b/test/wcc/690_amp_dot.c index d35634cd..e3ec9a47 100644 --- a/test/wcc/690_amp_dot.c +++ b/test/wcc/690_amp_dot.c @@ -22,7 +22,6 @@ */ #include #include -#include #include #include #include @@ -242,34 +241,29 @@ static const struct row rows[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/wad_%d_%d.ww", getpid(), i); + char src[128], tmpdir[64], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/wad_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/wad_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/wad_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s", driver, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return got; } diff --git a/test/wcc/691_dot_slice_arg.c b/test/wcc/691_dot_slice_arg.c index f5ebb65a..8de9c1ad 100644 --- a/test/wcc/691_dot_slice_arg.c +++ b/test/wcc/691_dot_slice_arg.c @@ -31,7 +31,6 @@ */ #include #include -#include #include #include #include @@ -220,34 +219,29 @@ static const struct row rows[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/wdsa_%d_%d.ww", getpid(), i); + char tmpdir[64], src[128], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/wdsa_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/wdsa_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/wdsa_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s", driver, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return got; } diff --git a/test/wcc/692_dot_str_chained_arg.c b/test/wcc/692_dot_str_chained_arg.c index ad882990..4eaf218b 100644 --- a/test/wcc/692_dot_str_chained_arg.c +++ b/test/wcc/692_dot_str_chained_arg.c @@ -27,7 +27,6 @@ */ #include #include -#include #include #include #include @@ -93,34 +92,30 @@ static const struct row rows[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/wdsc_%d_%d.ww", getpid(), i); + char tmpdir[64], src[128], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/wdsc_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/wdsc_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/wdsc_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s", + driver, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return got; } diff --git a/test/wcc/693_dot_tagged_source.c b/test/wcc/693_dot_tagged_source.c index f5edac4c..02171f91 100644 --- a/test/wcc/693_dot_tagged_source.c +++ b/test/wcc/693_dot_tagged_source.c @@ -40,7 +40,6 @@ */ #include #include -#include #include #include #include @@ -308,34 +307,29 @@ static const struct row rows[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/waew_%d_%d.ww", getpid(), i); + char tmpdir[64], src[128], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/waew_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/waew_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/waew_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s", driver, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return got; } diff --git a/test/wcc/694_tagged_store_intlit.c b/test/wcc/694_tagged_store_intlit.c index 4f8d9543..bd88c5bd 100644 --- a/test/wcc/694_tagged_store_intlit.c +++ b/test/wcc/694_tagged_store_intlit.c @@ -47,7 +47,6 @@ */ #include #include -#include #include #include #include @@ -269,34 +268,29 @@ static const struct row rows[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/waew_%d_%d.ww", getpid(), i); + char tmpdir[64], src[128], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/waew_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/waew_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/waew_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s", driver, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return got; } diff --git a/test/wcc/695_match_bind_struct.c b/test/wcc/695_match_bind_struct.c index 5a2f52b2..4ea846e7 100644 --- a/test/wcc/695_match_bind_struct.c +++ b/test/wcc/695_match_bind_struct.c @@ -42,7 +42,6 @@ */ #include #include -#include #include #include #include @@ -215,34 +214,30 @@ static const struct row rows[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/wmbs_%d_%d.ww", getpid(), i); + char src[128], tmpdir[64], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/wmbs_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/wmbs_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/wmbs_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s", + driver, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return got; } diff --git a/test/wcc/696_modtype_leaf_collision.c b/test/wcc/696_modtype_leaf_collision.c index 2364836a..035a9823 100644 --- a/test/wcc/696_modtype_leaf_collision.c +++ b/test/wcc/696_modtype_leaf_collision.c @@ -37,19 +37,28 @@ runwait(const char *cmd) static int run_pos(const char *driver, const char *fixdir, const char *tag) { + char td[1024]; + snprintf(td, sizeof td, "/tmp/modcol_pos_%d_%s", getpid(), tag); + mkdir(td, 0755); + char rmcmd[1100]; + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", td); + char cmd[2048]; /* cd into the fixture dir so the driver's source-dir-first import - * search resolves `use mod1; use mod2;`. */ + * search resolves `use mod1; use mod2;`; -o moves the binary and its + * .sepwork OUT of the tracked fixture tree into the /tmp tmpdir. */ snprintf(cmd, sizeof cmd, - "cd %s && %s build pos.ww >/dev/null 2>&1", fixdir, driver); + "cd %s && %s build -o %s/pos pos.ww >/dev/null 2>&1", + fixdir, driver, td); if (runwait(cmd) != 0) { fprintf(stderr, "modtype_leaf[%s]: pos.ww build failed\n", tag); + runwait(rmcmd); return 1; } char bin[2048]; - snprintf(bin, sizeof bin, "%s/pos", fixdir); + snprintf(bin, sizeof bin, "%s/pos", td); int got = runwait(bin); - unlink(bin); + runwait(rmcmd); /* 3 + 5 (mod1.stream) + 7 + 11 (mod2.stream) = 26. */ if (got != 26) { fprintf(stderr, @@ -62,17 +71,24 @@ run_pos(const char *driver, const char *fixdir, const char *tag) static int run_neg(const char *driver, const char *fixdir, const char *tag) { + char td[1024]; + snprintf(td, sizeof td, "/tmp/modcol_neg_%d_%s", getpid(), tag); + mkdir(td, 0755); + char rmcmd[1100]; + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", td); + char cmd[2048]; /* Build must fail with a field-resolution error: the `c` field * lives on mod2.stream, not mod1.stream. If pre-fix sym-binding * smashed mod1.stream's identity into mod2.stream's slot, this - * would silently succeed. */ + * would silently succeed. -o moves the binary and its .sepwork (the + * scratch dir is created even on the expected build failure) OUT of + * the tracked fixture tree into the /tmp tmpdir. */ snprintf(cmd, sizeof cmd, - "cd %s && %s build neg.ww >/dev/null 2>&1", fixdir, driver); + "cd %s && %s build -o %s/neg neg.ww >/dev/null 2>&1", + fixdir, driver, td); int rc = runwait(cmd); - char bin[2048]; - snprintf(bin, sizeof bin, "%s/neg", fixdir); - unlink(bin); + runwait(rmcmd); if (rc == 0) { fprintf(stderr, "modtype_leaf[%s]: neg.ww built but should have errored\n", diff --git a/test/wcc/697_samemod_prefer.c b/test/wcc/697_samemod_prefer.c index f6930a97..2494a268 100644 --- a/test/wcc/697_samemod_prefer.c +++ b/test/wcc/697_samemod_prefer.c @@ -40,20 +40,28 @@ runwait(const char *cmd) static int run_pos(const char *driver, const char *fixdir, const char *tag) { + /* -o into a /tmp tmpdir so the binary AND `.sepwork/` land + * outside the repo; the cd keeps source-dir-first import search + * resolving `use mod1; use mod2;`. */ + char td[1024]; + snprintf(td, sizeof td, "/tmp/smprefer_%d_%s", getpid(), tag); + mkdir(td, 0755); + + char rmcmd[1152]; + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", td); + char cmd[2048]; - /* cd into the fixture dir so the driver's source-dir-first - * import search resolves `use mod1; use mod2;`. */ snprintf(cmd, sizeof cmd, - "cd %s && %s build pos.ww >/dev/null 2>&1", fixdir, driver); + "cd %s && %s build -o %s/pos pos.ww >/dev/null 2>&1", + fixdir, driver, td); if (runwait(cmd) != 0) { fprintf(stderr, "samemod_prefer[%s]: pos.ww build failed — bare-leaf " "`read` lookup likely cross-bound\n", tag); + runwait(rmcmd); return 1; } - char bin[2048]; - snprintf(bin, sizeof bin, "%s/pos", fixdir); - unlink(bin); + runwait(rmcmd); return 0; } diff --git a/test/wcc/698_cgreturn_struct.c b/test/wcc/698_cgreturn_struct.c index 2b810fc2..a2dde9cf 100644 --- a/test/wcc/698_cgreturn_struct.c +++ b/test/wcc/698_cgreturn_struct.c @@ -37,7 +37,6 @@ */ #include #include -#include #include #include #include @@ -293,34 +292,29 @@ static const struct row rows[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/wcrs_%d_%d.ww", getpid(), i); + char tmpdir[64], src[128], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/wcrs_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/wcrs_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/wcrs_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s", driver, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return got; } diff --git a/test/wcc/699_use_promote_alias.c b/test/wcc/699_use_promote_alias.c index 8d523430..c3a55684 100644 --- a/test/wcc/699_use_promote_alias.c +++ b/test/wcc/699_use_promote_alias.c @@ -53,23 +53,33 @@ runwait(const char *cmd) static int run_row(const char *driver, const char *fixdir, const char *tag) { + /* Scratch dir OUT of the repo: the driver's sep `.sepwork/` + * follows the build output stem, so point -o into /tmp so both the + * binary and its .sepwork land there and die with rm -rf. */ + char td[64]; + snprintf(td, sizeof td, "/tmp/usepr_%d_%s", getpid(), tag); + mkdir(td, 0755); + char rmcmd[128]; + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", td); + char src[64]; snprintf(src, sizeof src, "pos_%s.ww", tag); + char bin[2048]; + snprintf(bin, sizeof bin, "%s/out", td); char cmd[2048]; /* cd into the fixture dir so the driver's source-dir-first - * import search resolves `use mod;`. */ + * import search resolves `use mod;`; -o points OUT of the repo. */ snprintf(cmd, sizeof cmd, - "cd %s && %s build %s >/dev/null 2>&1", fixdir, driver, src); + "cd %s && %s build -o %s %s >/dev/null 2>&1", fixdir, driver, bin, src); if (runwait(cmd) != 0) { fprintf(stderr, "use_promote_alias[%s]: build failed — SK_USE→SK_X " "promotion likely dropped use_alias\n", tag); + runwait(rmcmd); return 1; } - char bin[2048]; - snprintf(bin, sizeof bin, "%s/pos_%s", fixdir, tag); int got = runwait(bin); - unlink(bin); + runwait(rmcmd); if (got != 42) { fprintf(stderr, "use_promote_alias[%s]: exit=%d want=42\n", tag, got); diff --git a/test/wcc/700_e2e.c b/test/wcc/700_e2e.c index d5235343..1341d8ff 100644 --- a/test/wcc/700_e2e.c +++ b/test/wcc/700_e2e.c @@ -5,7 +5,6 @@ */ #include #include -#include #include #include #include @@ -1800,30 +1799,26 @@ main(void) int n = 0, fail = 0; for (int i = 0; rows[i].src; i++, n++) { - char src[64], exe[64]; - snprintf(src, sizeof src, "/tmp/wwe2e_%d_%d.ww", getpid(), i); - snprintf(exe, sizeof exe, "/tmp/wwe2e_%d_%d", getpid(), i); + char tmpdir[64]; + snprintf(tmpdir, sizeof tmpdir, "/tmp/wwe2e_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + + /* #8: source + binary + .sepwork scratch all live INSIDE tmpdir + * (`-o` pins the binary, scratch lands next to the in-tmpdir + * source) so the recursive cleanup removes everything. */ + char src[128], outbin[128], rmcmd[160]; + snprintf(src, sizeof src, "%s/wwe2e_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/wwe2e_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); fputs(rows[i].src, f); fclose(f); char cmd[1024]; - /* ww build writes the binary to the current working dir, - * named after the source basename. We override by chdir. */ - char tmpdir[64]; - snprintf(tmpdir, sizeof tmpdir, "/tmp/wwe2e_%d_d_%d", getpid(), i); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s/ww build %s", - tmpdir, bin, src); - if (runwait(cmd) != 0) { fail++; continue; } - - char outbin[128]; - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; + snprintf(cmd, sizeof cmd, "%s/ww build -o %s %s", + bin, outbin, src); + if (runwait(cmd) != 0) { runwait(rmcmd); fail++; continue; } int got = runwait(outbin); if (got != rows[i].want_exit) { @@ -1831,8 +1826,7 @@ main(void) i, got, rows[i].want_exit, rows[i].src); fail++; } - unlink(src); unlink(outbin); rmdir(tmpdir); - (void)exe; + runwait(rmcmd); } if (fail) { fprintf(stderr, "%d/%d e2e tests failed\n", fail, n); return 1; } printf("e2e: %d/%d ok\n", n, n); diff --git a/test/wcc/701_cgassign_struct.c b/test/wcc/701_cgassign_struct.c index b583eda7..24009eb4 100644 --- a/test/wcc/701_cgassign_struct.c +++ b/test/wcc/701_cgassign_struct.c @@ -47,7 +47,6 @@ */ #include #include -#include #include #include #include @@ -283,34 +282,29 @@ static const struct row rows[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/wcas_%d_%d.ww", getpid(), i); + char tmpdir[64], src[128], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/wcas_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/wcas_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/wcas_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s", driver, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return got; } diff --git a/test/wcc/702_dot_explicit_deref.c b/test/wcc/702_dot_explicit_deref.c index b3b3b536..c3ef26ec 100644 --- a/test/wcc/702_dot_explicit_deref.c +++ b/test/wcc/702_dot_explicit_deref.c @@ -30,7 +30,6 @@ */ #include #include -#include #include #include #include @@ -148,34 +147,29 @@ static const struct row rows[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/wded_%d_%d.ww", getpid(), i); + char tmpdir[64], src[128], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/wded_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/wded_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/wded_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s", driver, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return got; } diff --git a/test/wcc/703_nested_structlit.c b/test/wcc/703_nested_structlit.c index ae1b8f1c..c594e7cc 100644 --- a/test/wcc/703_nested_structlit.c +++ b/test/wcc/703_nested_structlit.c @@ -33,7 +33,6 @@ */ #include #include -#include #include #include #include @@ -141,34 +140,29 @@ static const struct row rows[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/wcns_%d_%d.ww", getpid(), i); + char tmpdir[64], src[128], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/wcns_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/wcns_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/wcns_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s", driver, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return got; } diff --git a/test/wcc/704_dot_structlit.c b/test/wcc/704_dot_structlit.c index d350dab7..232f96b5 100644 --- a/test/wcc/704_dot_structlit.c +++ b/test/wcc/704_dot_structlit.c @@ -38,7 +38,6 @@ */ #include #include -#include #include #include #include @@ -193,34 +192,29 @@ static const struct row rows[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/wcds_%d_%d.ww", getpid(), i); + char tmpdir[64], src[128], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/wcds_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/wcds_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/wcds_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s", driver, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return got; } diff --git a/test/wcc/705_nested_call_rhs.c b/test/wcc/705_nested_call_rhs.c index 3f3cdda3..23c589bc 100644 --- a/test/wcc/705_nested_call_rhs.c +++ b/test/wcc/705_nested_call_rhs.c @@ -50,7 +50,6 @@ */ #include #include -#include #include #include #include @@ -213,34 +212,29 @@ static const struct row rows[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/wcnc_%d_%d.ww", getpid(), i); + char tmpdir[64], src[128], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/wcnc_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/wcnc_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/wcnc_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s", driver, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return got; } diff --git a/test/wcc/706_fnlabel_mangle.c b/test/wcc/706_fnlabel_mangle.c index 55e6c114..77c37432 100644 --- a/test/wcc/706_fnlabel_mangle.c +++ b/test/wcc/706_fnlabel_mangle.c @@ -61,18 +61,29 @@ runwait(const char *cmd) static int run_pos(const char *driver, const char *fixdir, const char *tag) { + /* -o into a /tmp tmpdir so pos.sepwork follows the OUTPUT stem out + * of the tracked fixture tree; cd stays — pos.ww imports + * siblings mod1/mod2 via source-dir-first resolution. */ + char td[1024]; + snprintf(td, sizeof td, "/tmp/fnlbl_%d_%s", getpid(), tag); + mkdir(td, 0755); + char rmcmd[1088]; + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", td); + char cmd[2048]; snprintf(cmd, sizeof cmd, - "cd %s && %s build pos.ww >/dev/null 2>&1", fixdir, driver); + "cd %s && %s build -o %s/pos pos.ww >/dev/null 2>&1", + fixdir, driver, td); if (runwait(cmd) != 0) { fprintf(stderr, "fnlabel_mangle[%s]: pos.ww build failed\n", tag); + runwait(rmcmd); return 1; } char bin[2048]; - snprintf(bin, sizeof bin, "%s/pos", fixdir); + snprintf(bin, sizeof bin, "%s/pos", td); int got = runwait(bin); - unlink(bin); + runwait(rmcmd); if (got != 112) { fprintf(stderr, "fnlabel_mangle[%s]: pos.ww exit=%d want=112 — " diff --git a/test/wcc/707_cgreturn_variant_zero.c b/test/wcc/707_cgreturn_variant_zero.c index 65a33957..20a0f5a0 100644 --- a/test/wcc/707_cgreturn_variant_zero.c +++ b/test/wcc/707_cgreturn_variant_zero.c @@ -62,7 +62,6 @@ */ #include #include -#include #include #include #include @@ -302,34 +301,29 @@ static const struct row rows[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/wcrv_%d_%d.ww", getpid(), i); + char tmpdir[64], src[128], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/wcrv_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/wcrv_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/wcrv_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s", driver, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return got; } diff --git a/test/wcc/708_param_shadow_mod.c b/test/wcc/708_param_shadow_mod.c index 2f967e90..4d56025b 100644 --- a/test/wcc/708_param_shadow_mod.c +++ b/test/wcc/708_param_shadow_mod.c @@ -67,12 +67,20 @@ run_neg(const char *driver, const char *fixdir, const char *tag) { char src[64]; snprintf(src, sizeof src, "neg_%s.ww", tag); + char td[128]; + snprintf(td, sizeof td, "/tmp/psm_neg_%d_%s", getpid(), tag); + mkdir(td, 0755); char cmd[2048]; /* cd into the fixture dir so the driver's source-dir-first - * import search resolves `use shadowmod;`. */ + * import search resolves `use shadowmod;`; -o moves the binary + * and its .sepwork OUT of the tracked fixture tree. */ snprintf(cmd, sizeof cmd, - "cd %s && %s build %s >/dev/null 2>&1", fixdir, driver, src); + "cd %s && %s build -o %s/out %s >/dev/null 2>&1", + fixdir, driver, td, src); int rc = runwait(cmd); + char rmcmd[256]; + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", td); + runwait(rmcmd); if (rc == 0) { fprintf(stderr, "param_shadow_mod[neg_%s]: build unexpectedly succeeded " @@ -85,20 +93,28 @@ run_neg(const char *driver, const char *fixdir, const char *tag) static int run_pos(const char *driver, const char *fixdir) { + char td[128]; + snprintf(td, sizeof td, "/tmp/psm_pos_%d", getpid()); + mkdir(td, 0755); + char rmcmd[256]; + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", td); char cmd[2048]; + /* keep cd for sibling-import resolution; -o moves the binary and + * its pos_rename.sepwork OUT of the tracked fixture tree. */ snprintf(cmd, sizeof cmd, - "cd %s && %s build pos_rename.ww >/dev/null 2>&1", - fixdir, driver); + "cd %s && %s build -o %s/out pos_rename.ww >/dev/null 2>&1", + fixdir, driver, td); if (runwait(cmd) != 0) { + runwait(rmcmd); fprintf(stderr, "param_shadow_mod[pos_rename]: build failed — rule " "over-triggered on the rename\n"); return 1; } char bin[2048]; - snprintf(bin, sizeof bin, "%s/pos_rename", fixdir); + snprintf(bin, sizeof bin, "%s/out", td); int got = runwait(bin); - unlink(bin); + runwait(rmcmd); if (got != 42) { fprintf(stderr, "param_shadow_mod[pos_rename]: exit=%d want=42\n", got); @@ -159,20 +175,28 @@ run_neg_selfimp(const char *comp, const char *fixdir, const char *tag) static int run_pos_crossmod(const char *driver, const char *fixdir) { + char td[128]; + snprintf(td, sizeof td, "/tmp/psm_crossmod_%d", getpid()); + mkdir(td, 0755); + char rmcmd[256]; + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", td); char cmd[2048]; + /* keep cd for sibling-import resolution; -o moves the binary and + * its pos_crossmod.sepwork OUT of the tracked fixture tree. */ snprintf(cmd, sizeof cmd, - "cd %s && %s build pos_crossmod.ww >/dev/null 2>&1", - fixdir, driver); + "cd %s && %s build -o %s/out pos_crossmod.ww >/dev/null 2>&1", + fixdir, driver, td); if (runwait(cmd) != 0) { + runwait(rmcmd); fprintf(stderr, "param_shadow_mod[pos_crossmod]: build failed — shadow " "rule over-triggered on a cross-module param\n"); return 1; } char bin[2048]; - snprintf(bin, sizeof bin, "%s/pos_crossmod", fixdir); + snprintf(bin, sizeof bin, "%s/out", td); int got = runwait(bin); - unlink(bin); + runwait(rmcmd); if (got != 2) { fprintf(stderr, "param_shadow_mod[pos_crossmod]: exit=%d want=2\n", got); diff --git a/test/wcc/709_localoff_scope.c b/test/wcc/709_localoff_scope.c index 1e504371..0e7a760d 100644 --- a/test/wcc/709_localoff_scope.c +++ b/test/wcc/709_localoff_scope.c @@ -77,7 +77,6 @@ */ #include #include -#include #include #include #include @@ -265,34 +264,30 @@ static const struct row rows[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/wclo_%d_%d.ww", getpid(), i); + char tmpdir[64], src[128], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/wclo_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/wclo_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/wclo_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s", + driver, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return got; } diff --git a/test/wcc/710_cast_enum_movl.c b/test/wcc/710_cast_enum_movl.c index 2e423c52..06eef541 100644 --- a/test/wcc/710_cast_enum_movl.c +++ b/test/wcc/710_cast_enum_movl.c @@ -107,7 +107,6 @@ */ #include #include -#include #include #include #include @@ -339,34 +338,30 @@ static const struct row rows[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/cem_%d_%d.ww", getpid(), i); + char tmpdir[64], src[128], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/cem_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/cem_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/cem_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>/dev/null", + driver, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return got; } diff --git a/test/wcc/711_arrlit_str_full.c b/test/wcc/711_arrlit_str_full.c index 3a629c51..c64eaab9 100644 --- a/test/wcc/711_arrlit_str_full.c +++ b/test/wcc/711_arrlit_str_full.c @@ -44,7 +44,6 @@ */ #include #include -#include #include #include #include @@ -208,34 +207,29 @@ static const struct row rows[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/wcrarrs_%d_%d.ww", getpid(), i); + char src[128], tmpdir[64], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/wcrarrs_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/wcrarrs_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/wcrarrs_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s", driver, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return got; } diff --git a/test/wcc/712_redecl.c b/test/wcc/712_redecl.c index 907f0f00..ef24e463 100644 --- a/test/wcc/712_redecl.c +++ b/test/wcc/712_redecl.c @@ -50,7 +50,6 @@ */ #include #include -#include #include #include #include @@ -185,63 +184,40 @@ static const struct row rows[] = { static int run_row(const char *driver, const struct row *r, int i) { - char src[128], tmpdir[128], cmd[2048]; - snprintf(src, sizeof src, "/tmp/wcredecl_%d_%d.ww", getpid(), i); + char src[128], tmpdir[128], outbin[128], rmcmd[160], cmd[2048]; snprintf(tmpdir, sizeof tmpdir, "/tmp/wcredecl_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/wcredecl_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/wcredecl_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s >/dev/null 2>&1", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s >/dev/null 2>&1", + driver, outbin, src); int rc = runwait(cmd); - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[256]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; - if (r->kind == 0) { /* Negative — build must fail. */ - if (rc == 0) { + if (rc == 0) fprintf(stderr, "redecl[%s]: build unexpectedly succeeded\n", r->label); - unlink(outbin); - } - unlink(src); - /* combined.ww left next to src by the driver */ - char combined[256]; - snprintf(combined, sizeof combined, "%s.combined.ww", src); - dot = strrchr(combined, '.'); - (void)dot; - snprintf(combined, sizeof combined, "/tmp/wcredecl_%d_%d.combined.ww", - getpid(), i); - unlink(combined); - rmdir(tmpdir); + runwait(rmcmd); return rc == 0 ? -1 : 0; } /* Positive — build then run. */ if (rc != 0) { fprintf(stderr, "redecl[%s]: build failed\n", r->label); - unlink(src); - rmdir(tmpdir); + runwait(rmcmd); return -1; } int got = runwait(outbin); - unlink(src); - unlink(outbin); - char combined[256]; - snprintf(combined, sizeof combined, "/tmp/wcredecl_%d_%d.combined.ww", - getpid(), i); - unlink(combined); - rmdir(tmpdir); + runwait(rmcmd); if (got != r->want) { fprintf(stderr, "redecl[%s]: exit=%d want=%d\n", r->label, got, r->want); diff --git a/test/wcc/713_struct_field_index.c b/test/wcc/713_struct_field_index.c index 96e4af72..73261cf6 100644 --- a/test/wcc/713_struct_field_index.c +++ b/test/wcc/713_struct_field_index.c @@ -49,7 +49,6 @@ */ #include #include -#include #include #include #include @@ -140,34 +139,30 @@ static const struct row rows[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/wcrsfi_%d_%d.ww", getpid(), i); + char src[128], tmpdir[64], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/wcrsfi_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/wcrsfi_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/wcrsfi_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s", + driver, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return got; } diff --git a/test/wcc/714_tagged_return_scratch.c b/test/wcc/714_tagged_return_scratch.c index 7e631ece..a874bb32 100644 --- a/test/wcc/714_tagged_return_scratch.c +++ b/test/wcc/714_tagged_return_scratch.c @@ -70,7 +70,6 @@ */ #include #include -#include #include #include #include @@ -214,34 +213,30 @@ static const struct row rows[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/wctrs_%d_%d.ww", getpid(), i); + char tmpdir[64], src[128], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/wctrs_%d_d_%d", getpid(), i); + snprintf(src, sizeof src, "%s/wctrs_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/wctrs_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); + mkdir(tmpdir, 0755); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s", + driver, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return got; } diff --git a/test/wcc/715_tagged_widen_f64.c b/test/wcc/715_tagged_widen_f64.c index c8a8e40d..b39c342a 100644 --- a/test/wcc/715_tagged_widen_f64.c +++ b/test/wcc/715_tagged_widen_f64.c @@ -50,7 +50,6 @@ */ #include #include -#include #include #include #include @@ -182,34 +181,29 @@ static const struct row rows[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/twf64_%d_%d.ww", getpid(), i); + char src[128], tmpdir[64], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/twf64_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/twf64_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/twf64_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s", driver, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return got; } diff --git a/test/wcc/716_match_spill_pointer_payload.c b/test/wcc/716_match_spill_pointer_payload.c index e2b5cc8b..20961c4e 100644 --- a/test/wcc/716_match_spill_pointer_payload.c +++ b/test/wcc/716_match_spill_pointer_payload.c @@ -39,7 +39,6 @@ */ #include #include -#include #include #include #include @@ -136,34 +135,29 @@ static const struct row rows[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/wcmsp_%d_%d.ww", getpid(), i); + char src[128], tmpdir[64], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/wcmsp_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/wcmsp_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/wcmsp_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s", driver, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return got; } diff --git a/test/wcc/717_struct_byval_param.c b/test/wcc/717_struct_byval_param.c index 26ab8ad8..70fc39f0 100644 --- a/test/wcc/717_struct_byval_param.c +++ b/test/wcc/717_struct_byval_param.c @@ -50,7 +50,6 @@ */ #include #include -#include #include #include #include @@ -138,34 +137,29 @@ static const struct row rows[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/wcsbp_%d_%d.ww", getpid(), i); + char tmpdir[64], src[128], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/wcsbp_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/wcsbp_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/wcsbp_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s", driver, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return got; } diff --git a/test/wcc/718_struct_multi_return_scratch.c b/test/wcc/718_struct_multi_return_scratch.c index cd9f9966..c5819f1c 100644 --- a/test/wcc/718_struct_multi_return_scratch.c +++ b/test/wcc/718_struct_multi_return_scratch.c @@ -223,34 +223,30 @@ static const struct row rows[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/wcsmr_%d_%d.ww", getpid(), i); + char src[128], tmpdir[64], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/wcsmr_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/wcsmr_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/wcsmr_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s", + driver, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return got; } diff --git a/test/wcc/729_empty_alloc_infer.c b/test/wcc/729_empty_alloc_infer.c index 31465119..9d53984b 100644 --- a/test/wcc/729_empty_alloc_infer.c +++ b/test/wcc/729_empty_alloc_infer.c @@ -33,7 +33,6 @@ */ #include #include -#include #include #include #include @@ -113,52 +112,56 @@ static const struct row rows[] = { static int run_row(const char *driver, const struct row *r, int i) { - char src[128], tmpdir[128], cmd[2048]; + char cmd[2048]; + + if (r->kind == 0) { + /* Negative — build must fail. Source + outbin live inside a + * per-row tmpdir so the compiler's .sepwork (mkdir'd + * before the build fails) lands there and is rm -rf'd, not + * leaked next to a bare-/tmp source. */ + char tmpdir[128], src[160], outbin[160], rmcmd[192]; + snprintf(tmpdir, sizeof tmpdir, "/tmp/wcealloc_%d_d_%d", + getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/wcealloc_%d_%d.ww", + tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/wcealloc_%d_%d", + tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); + + FILE *f = fopen(src, "wb"); + if (!f) { runwait(rmcmd); return -1; } + fputs(r->src, f); + fclose(f); + + snprintf(cmd, sizeof cmd, + "%s build -o %s %s >/dev/null 2>&1", driver, outbin, src); + int rc = runwait(cmd); + if (rc == 0) + fprintf(stderr, + "ealloc[%s]: build unexpectedly succeeded\n", + r->label); + runwait(rmcmd); + return rc == 0 ? -1 : 0; + } + + /* Positive — build (with rt linked via `ww run`) then check exit. + * `ww run` self-cleans its scratch (/tmp/ww_run_.sepwork), so the + * bare-/tmp source leaks nothing; left unwrapped. */ + char src[128], combined[160]; snprintf(src, sizeof src, "/tmp/wcealloc_%d_%d.ww", getpid(), i); - snprintf(tmpdir, sizeof tmpdir, "/tmp/wcealloc_%d_d_%d", getpid(), i); + snprintf(combined, sizeof combined, "/tmp/wcealloc_%d_%d.combined.ww", + getpid(), i); FILE *f = fopen(src, "wb"); if (!f) return -1; fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[256]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; - - char combined[256]; - snprintf(combined, sizeof combined, "/tmp/wcealloc_%d_%d.combined.ww", - getpid(), i); - - if (r->kind == 0) { - /* Negative — build must fail. */ - snprintf(cmd, sizeof cmd, - "cd %s && %s build %s >/dev/null 2>&1", tmpdir, driver, src); - int rc = runwait(cmd); - if (rc == 0) { - fprintf(stderr, - "ealloc[%s]: build unexpectedly succeeded\n", - r->label); - unlink(outbin); - } - unlink(src); - unlink(combined); - rmdir(tmpdir); - return rc == 0 ? -1 : 0; - } - - /* Positive — build (with rt linked via `ww run`) then check exit. */ snprintf(cmd, sizeof cmd, "%s run %s >/dev/null 2>&1", driver, src); int got = runwait(cmd); unlink(src); - unlink(outbin); unlink(combined); - rmdir(tmpdir); if (got != r->want) { fprintf(stderr, "ealloc[%s]: exit=%d want=%d\n", r->label, got, r->want); diff --git a/test/wcc/732_def_const_fold.c b/test/wcc/732_def_const_fold.c index 6aefad10..971f2d46 100644 --- a/test/wcc/732_def_const_fold.c +++ b/test/wcc/732_def_const_fold.c @@ -124,36 +124,32 @@ static const struct row exec_rows[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/dcf_%d_%d.ww", getpid(), i); + char tmpdir[64], src[128], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/dcf_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/dcf_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/dcf_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); /* timeout 180 per repo convention (990-997); test/run does not bound * individual binaries, so an unguarded hang would stall make test. */ - snprintf(cmd, sizeof cmd, "cd %s && timeout 180 %s build %s 2>/dev/null", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "timeout 180 %s build -o %s %s 2>/dev/null", + driver, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return got; } diff --git a/test/wcc/737_direnum.c b/test/wcc/737_direnum.c index 6a76ba86..e40fb6c3 100644 --- a/test/wcc/737_direnum.c +++ b/test/wcc/737_direnum.c @@ -19,6 +19,7 @@ #include #include #include +#include #include static int @@ -62,11 +63,11 @@ main(void) int total = 0, fail = 0; char errp[64]; - /* ok: cross-pkg bare-leaf via dir-enum, both stages. */ + /* ok: cross-pkg bare-leaf via dir-enum, both stages. `ww run` routes + * its scratch through /tmp/ww_run_.sepwork and removes it itself + * (do_run keepscratch 0), so no per-invocation tmpdir is needed here. */ { const char *src = "test/wcc/data/direnum/entry.ww"; - char tmp[64]; - snprintf(tmp, sizeof tmp, "/tmp/direnum_%d_ok", getpid()); char cmd[2048]; snprintf(cmd, sizeof cmd, "%s run %s >/dev/null 2>&1", ww, src); @@ -85,7 +86,6 @@ main(void) fail++; } } - (void)tmp; } /* bad: mismatched package decls in same dir → import-path mismatch @@ -98,10 +98,21 @@ main(void) const char *src = "test/wcc/data/direnum/bad_entry.ww"; snprintf(errp, sizeof errp, "/tmp/direnum_%d_bad.err", getpid()); + /* CLASS B: build INPUT stays the in-repo fixture, but -o points the + * output stem (and thus its .sepwork scratch) at a unique /tmp + * tmpdir so nothing leaks into the tracked tree — even on the + * expected build failure, since scratch is mkdir'd before the reject. + * rm -rf the tmpdir on every exit path. */ + char td[64], rmcmd[128]; char cmd[2048]; - snprintf(cmd, sizeof cmd, "%s build %s 2>%s >/dev/null", - ww, src, errp); + + snprintf(td, sizeof td, "/tmp/direnum_%d_bad_c", getpid()); + mkdir(td, 0755); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", td); + snprintf(cmd, sizeof cmd, "%s build -o %s/out %s 2>%s >/dev/null", + ww, td, src, errp); int rc = runwait(cmd); + runwait(rmcmd); total++; if (rc == 0) { fprintf(stderr, "737[bad-cstage]: expected build failure, succeeded\n"); @@ -113,9 +124,13 @@ main(void) unlink(errp); if (access(ww_ww, X_OK) == 0) { - snprintf(cmd, sizeof cmd, "%s build %s 2>%s >/dev/null", - ww_ww, src, errp); + snprintf(td, sizeof td, "/tmp/direnum_%d_bad_w", getpid()); + mkdir(td, 0755); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", td); + snprintf(cmd, sizeof cmd, "%s build -o %s/out %s 2>%s >/dev/null", + ww_ww, td, src, errp); rc = runwait(cmd); + runwait(rmcmd); total++; if (rc == 0) { fprintf(stderr, "737[bad-wwstage]: expected build failure, succeeded\n"); @@ -138,10 +153,19 @@ main(void) const char *src = "test/wcc/data/direnum/bad_deep_entry.ww"; snprintf(errp, sizeof errp, "/tmp/direnum_%d_baddeep.err", getpid()); + /* CLASS B (see bad block): -o into a unique /tmp tmpdir keeps the + * .sepwork scratch out of the tracked tree on the expected + * reject; rm -rf on every exit path. */ + char td[64], rmcmd[128]; char cmd[2048]; - snprintf(cmd, sizeof cmd, "%s build %s 2>%s >/dev/null", - ww, src, errp); + + snprintf(td, sizeof td, "/tmp/direnum_%d_baddeep_c", getpid()); + mkdir(td, 0755); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", td); + snprintf(cmd, sizeof cmd, "%s build -o %s/out %s 2>%s >/dev/null", + ww, td, src, errp); int rc = runwait(cmd); + runwait(rmcmd); total++; if (rc == 0) { fprintf(stderr, "737[bad-deep-cstage]: expected build failure, succeeded\n"); @@ -153,9 +177,13 @@ main(void) unlink(errp); if (access(ww_ww, X_OK) == 0) { - snprintf(cmd, sizeof cmd, "%s build %s 2>%s >/dev/null", - ww_ww, src, errp); + snprintf(td, sizeof td, "/tmp/direnum_%d_baddeep_w", getpid()); + mkdir(td, 0755); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", td); + snprintf(cmd, sizeof cmd, "%s build -o %s/out %s 2>%s >/dev/null", + ww_ww, td, src, errp); rc = runwait(cmd); + runwait(rmcmd); total++; if (rc == 0) { fprintf(stderr, "737[bad-deep-wwstage]: expected build failure, succeeded\n"); diff --git a/test/wcc/744_letcopy_struct.c b/test/wcc/744_letcopy_struct.c index 966759af..ed8cbe6a 100644 --- a/test/wcc/744_letcopy_struct.c +++ b/test/wcc/744_letcopy_struct.c @@ -245,38 +245,33 @@ emit_s(const char *w6c, const struct row *r, int i, int stage, static int run_driver(const char *driver, const struct row *r, int i, int stage) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/lcs_run_%d_%d_%d.ww", - getpid(), i, stage); + char tmpdir[64], src[128], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/lcs_run_%d_d_%d_%d", getpid(), i, stage); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/lcs_run_%d_%d_%d.ww", + tmpdir, getpid(), i, stage); + snprintf(outbin, sizeof outbin, "%s/lcs_run_%d_%d_%d", + tmpdir, getpid(), i, stage); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->run_src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>/dev/null", + driver, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s] build via %s failed\n", r->label, driver); - unlink(src); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[160]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - /* Best-effort cleanup; the .s / .o / .combined.ww side files share - * the same stem and don't interfere with the next row. */ - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return got; } diff --git a/test/wcc/748_size_strategy_convergence.c b/test/wcc/748_size_strategy_convergence.c index 1385bcca..cc154ca6 100644 --- a/test/wcc/748_size_strategy_convergence.c +++ b/test/wcc/748_size_strategy_convergence.c @@ -55,7 +55,6 @@ */ #include #include -#include #include #include #include @@ -185,11 +184,11 @@ static const struct row rows[] = { }; static int -build_with(const char *driver, const char *src_path, const char *tmpdir) +build_with(const char *driver, const char *outbin, const char *src_path) { char cmd[1024]; - snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null", - tmpdir, driver, src_path); + snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>/dev/null", + driver, outbin, src_path); return runwait(cmd); } @@ -223,26 +222,23 @@ main(void) for (int i = 0; i < n; i++) { const struct row *r = &rows[i]; - char src[64], tmpdir[64]; - snprintf(src, sizeof src, "/tmp/sz_conv_%d_%d.ww", getpid(), i); + char src[128], tmpdir[64], outbin[128], rmcmd[160]; snprintf(tmpdir, sizeof tmpdir, "/tmp/sz_conv_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/sz_conv_%d_%d.ww", + tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/sz_conv_%d_%d", + tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) { fail++; total++; continue; } + if (!f) { fail++; total++; runwait(rmcmd); continue; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; /* Runtime parity (cstage). */ total++; - if (build_with(cdrv, src, tmpdir) != 0) { + if (build_with(cdrv, outbin, src) != 0) { fprintf(stderr, "size_strategy_convergence[cs][%s]: build failed\n", r->label); @@ -256,12 +252,11 @@ main(void) fail++; } } - unlink(outbin); /* Runtime parity (wwstage). */ if (have_ww) { total++; - if (build_with(wdrv, src, tmpdir) != 0) { + if (build_with(wdrv, outbin, src) != 0) { fprintf(stderr, "size_strategy_convergence[ws][%s]: build failed\n", r->label); @@ -275,11 +270,9 @@ main(void) fail++; } } - unlink(outbin); } - unlink(src); - rmdir(tmpdir); + runwait(rmcmd); } if (fail) { diff --git a/test/wcc/749_sumtype_forward.c b/test/wcc/749_sumtype_forward.c index 64e4b77e..59b1fcc2 100644 --- a/test/wcc/749_sumtype_forward.c +++ b/test/wcc/749_sumtype_forward.c @@ -128,11 +128,11 @@ static const struct row rows[] = { }; static int -build_with(const char *driver, const char *src_path, const char *tmpdir) +build_with(const char *driver, const char *src_path, const char *outbin) { char cmd[1024]; - snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null", - tmpdir, driver, src_path); + snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>/dev/null", + driver, outbin, src_path); return runwait(cmd); } @@ -206,24 +206,24 @@ main(void) for (int i = 0; i < n; i++) { const struct row *r = &rows[i]; - char src[64], tmpdir[64]; - snprintf(src, sizeof src, "/tmp/sumtype_fwd_%d_%d.ww", - getpid(), i); + char src[128], tmpdir[64], outbin[128], rmcmd[160]; snprintf(tmpdir, sizeof tmpdir, "/tmp/sumtype_fwd_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); + snprintf(src, sizeof src, "%s/sumtype_fwd_%d_%d.ww", + tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/sumtype_fwd_%d_%d", + tmpdir, getpid(), i); FILE *f = fopen(src, "wb"); - if (!f) { fail++; total++; continue; } + if (!f) { runwait(rmcmd); fail++; total++; continue; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128], outasm[160]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; - /* .s lands alongside the .ww source per `ww build`. */ + char outasm[160]; + /* DEAD readback (task #13): separate-compile now lands the .s + * at .sepwork/__root.s, not .s, so read_file below + * returns NULL and the byte-id phase silently skips. */ snprintf(outasm, sizeof outasm, "%s", src); char *dot2 = strrchr(outasm, '.'); if (dot2 && strcmp(dot2, ".ww") == 0) { @@ -235,7 +235,7 @@ main(void) /* Runtime parity (cstage). */ total++; - if (build_with(cdrv, src, tmpdir) != 0) { + if (build_with(cdrv, src, outbin) != 0) { fprintf(stderr, "sumtype_forward[cs][%s]: build failed\n", r->label); @@ -257,7 +257,7 @@ main(void) size_t ws_n = 0; if (have_ww) { total++; - if (build_with(wdrv, src, tmpdir) != 0) { + if (build_with(wdrv, src, outbin) != 0) { fprintf(stderr, "sumtype_forward[ws][%s]: build failed\n", r->label); @@ -299,22 +299,7 @@ main(void) free(cs_asm); free(ws_asm); - char extra[160]; - unlink(outasm); - snprintf(extra, sizeof extra, "%s", src); - char *d3 = strrchr(extra, '.'); - if (d3 && strcmp(d3, ".ww") == 0) { - strcpy(d3, ".o"); - unlink(extra); - } - snprintf(extra, sizeof extra, "%s", src); - d3 = strrchr(extra, '.'); - if (d3 && strcmp(d3, ".ww") == 0) { - strcpy(d3, ".combined.ww"); - unlink(extra); - } - unlink(src); - rmdir(tmpdir); + runwait(rmcmd); } if (fail) { diff --git a/test/wcc/751_vararg_seq_percall.c b/test/wcc/751_vararg_seq_percall.c index 17695a7f..a6e1dddf 100644 --- a/test/wcc/751_vararg_seq_percall.c +++ b/test/wcc/751_vararg_seq_percall.c @@ -29,7 +29,6 @@ */ #include #include -#include #include #include #include @@ -92,11 +91,11 @@ static const struct row rows[] = { }; static int -build_with(const char *driver, const char *src_path, const char *tmpdir) +build_with(const char *driver, const char *src_path, const char *outbin) { char cmd[1024]; - snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null", - tmpdir, driver, src_path); + snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>/dev/null", + driver, outbin, src_path); return runwait(cmd); } @@ -130,26 +129,22 @@ main(void) for (int i = 0; i < n; i++) { const struct row *r = &rows[i]; - char src[64], tmpdir[64]; - snprintf(src, sizeof src, "/tmp/vararg_seq_%d_%d.ww", - getpid(), i); + char tmpdir[64], src[128], outbin[128], rmcmd[160]; snprintf(tmpdir, sizeof tmpdir, "/tmp/vararg_seq_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/vararg_seq_%d_%d.ww", + tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/vararg_seq_%d_%d", + tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) { fail++; total++; continue; } + if (!f) { runwait(rmcmd); fail++; total++; continue; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; total++; - if (build_with(cdrv, src, tmpdir) != 0) { + if (build_with(cdrv, src, outbin) != 0) { fprintf(stderr, "vararg_seq_percall[cs][%s]: build failed\n", r->label); @@ -167,7 +162,7 @@ main(void) if (have_ww) { total++; - if (build_with(wdrv, src, tmpdir) != 0) { + if (build_with(wdrv, src, outbin) != 0) { fprintf(stderr, "vararg_seq_percall[ws][%s]: build failed\n", r->label); @@ -181,11 +176,9 @@ main(void) fail++; } } - unlink(outbin); } - unlink(src); - rmdir(tmpdir); + runwait(rmcmd); } if (fail) { diff --git a/test/wcc/756_alias_chain_unwrap.c b/test/wcc/756_alias_chain_unwrap.c index e04ecfe5..1f42939a 100644 --- a/test/wcc/756_alias_chain_unwrap.c +++ b/test/wcc/756_alias_chain_unwrap.c @@ -138,34 +138,30 @@ static const struct row rows[] = { static int build_and_run(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/acu_%d_%d.ww", getpid(), i); + char tmpdir[64], src[128], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/acu_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/acu_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/acu_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s", + driver, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return got; } diff --git a/test/wcc/757_letbind_void_bang_void.c b/test/wcc/757_letbind_void_bang_void.c index 3dcb5594..f57f245a 100644 --- a/test/wcc/757_letbind_void_bang_void.c +++ b/test/wcc/757_letbind_void_bang_void.c @@ -35,7 +35,6 @@ */ #include #include -#include #include #include #include @@ -113,34 +112,29 @@ static const struct row rows[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/wclbvv_%d_%d.ww", getpid(), i); + char tmpdir[64], src[128], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/wclbvv_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/wclbvv_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/wclbvv_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s", driver, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return got; } diff --git a/test/wcc/758_cgalloc_str_field.c b/test/wcc/758_cgalloc_str_field.c index 357b3e93..c50c8ae2 100644 --- a/test/wcc/758_cgalloc_str_field.c +++ b/test/wcc/758_cgalloc_str_field.c @@ -141,34 +141,29 @@ static const struct row rows[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/wcas_%d_%d.ww", getpid(), i); + char tmpdir[64], src[128], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/wcas_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/wcas_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/wcas_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s", driver, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return got; } diff --git a/test/wcc/759_check_enum_fold.c b/test/wcc/759_check_enum_fold.c index 266fa2f8..815e1073 100644 --- a/test/wcc/759_check_enum_fold.c +++ b/test/wcc/759_check_enum_fold.c @@ -24,7 +24,6 @@ */ #include #include -#include #include #include #include @@ -150,34 +149,30 @@ static const struct row rows[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/cef_%d_%d.ww", getpid(), i); + char tmpdir[64], src[128], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/cef_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/cef_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/cef_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>/dev/null", + driver, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return got; } diff --git a/test/wcc/760_def_widen_const.c b/test/wcc/760_def_widen_const.c index 2d4369d0..d30fc06c 100644 --- a/test/wcc/760_def_widen_const.c +++ b/test/wcc/760_def_widen_const.c @@ -39,7 +39,6 @@ */ #include #include -#include #include #include #include @@ -99,36 +98,32 @@ static const struct row exec_rows[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/dwc_%d_%d.ww", getpid(), i); + char tmpdir[64], src[128], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/dwc_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/dwc_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/dwc_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); /* timeout 180 per repo convention; test/run does not bound * individual binaries, so an unguarded hang would stall make test. */ - snprintf(cmd, sizeof cmd, "cd %s && timeout 180 %s build %s 2>/dev/null", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "timeout 180 %s build -o %s %s 2>/dev/null", + driver, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return got; } diff --git a/test/wcc/761_inferred_struct_arg_push.c b/test/wcc/761_inferred_struct_arg_push.c index d294d22b..4abb43c0 100644 --- a/test/wcc/761_inferred_struct_arg_push.c +++ b/test/wcc/761_inferred_struct_arg_push.c @@ -59,7 +59,6 @@ */ #include #include -#include #include #include #include @@ -200,37 +199,33 @@ static const struct row rows[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/wcisp_%d_%d.ww", getpid(), i); + char tmpdir[64], src[128], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/wcisp_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/wcisp_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/wcisp_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); /* timeout 180 per repo convention (cf. 760); test/run does not * bound individual binaries, so an unguarded hang from a future * cgen regression would stall make test instead of redding here. */ - snprintf(cmd, sizeof cmd, "cd %s && timeout 180 %s build %s 2>/dev/null", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "timeout 180 %s build -o %s %s 2>/dev/null", + driver, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return got; } diff --git a/test/wcc/762_struct_abi_size.c b/test/wcc/762_struct_abi_size.c index ada58c46..5d4a9e52 100644 --- a/test/wcc/762_struct_abi_size.c +++ b/test/wcc/762_struct_abi_size.c @@ -43,7 +43,6 @@ */ #include #include -#include #include #include #include @@ -133,36 +132,32 @@ static const struct row rows[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/wcabi_%d_%d.ww", getpid(), i); + char src[128], tmpdir[64], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/wcabi_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/wcabi_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/wcabi_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); /* timeout 180 per repo convention (cf. 760, 761); test/run does * not bound individual binaries. */ - snprintf(cmd, sizeof cmd, "cd %s && timeout 180 %s build %s 2>/dev/null", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "timeout 180 %s build -o %s %s 2>/dev/null", + driver, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return got; } diff --git a/test/wcc/763_typeeq_fn_ast.c b/test/wcc/763_typeeq_fn_ast.c index 61f8a14b..a871d3d5 100644 --- a/test/wcc/763_typeeq_fn_ast.c +++ b/test/wcc/763_typeeq_fn_ast.c @@ -54,7 +54,6 @@ */ #include #include -#include #include #include #include @@ -173,36 +172,32 @@ static const struct row rows[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/wctyfn_%d_%d.ww", getpid(), i); + char src[128], tmpdir[64], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/wctyfn_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/wctyfn_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/wctyfn_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); /* timeout 180 per repo convention (cf. 761, 762); test/run does * not bound individual binaries. */ - snprintf(cmd, sizeof cmd, "cd %s && timeout 180 %s build %s 2>/dev/null", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "timeout 180 %s build -o %s %s 2>/dev/null", + driver, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return got; } diff --git a/test/wcc/765_star_fn_deref.c b/test/wcc/765_star_fn_deref.c index d49cd15c..35bacfbb 100644 --- a/test/wcc/765_star_fn_deref.c +++ b/test/wcc/765_star_fn_deref.c @@ -150,23 +150,19 @@ write_source(const char *src_path, const char *src) } static void -cleanup_tmp(const char *tmpdir, const char *base) +cleanup_tmp(const char *tmpdir) { char p[512]; - snprintf(p, sizeof p, "%s/%s.ww", tmpdir, base); unlink(p); - snprintf(p, sizeof p, "%s/%s.s", tmpdir, base); unlink(p); - snprintf(p, sizeof p, "%s/%s.o", tmpdir, base); unlink(p); - snprintf(p, sizeof p, "%s/%s.combined.ww", tmpdir, base); unlink(p); - snprintf(p, sizeof p, "%s/%s", tmpdir, base); unlink(p); - rmdir(tmpdir); + snprintf(p, sizeof p, "rm -rf %s", tmpdir); + runwait(p); } static int -build_via_driver(const char *driver, const char *tmpdir, const char *src) +build_via_driver(const char *driver, const char *outbin, const char *src) { char cmd[1024]; - snprintf(cmd, sizeof cmd, "cd %s && timeout 180 %s build %s 2>/dev/null", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "timeout 180 %s build -o %s %s 2>/dev/null", + driver, outbin, src); return runwait(cmd); } @@ -175,21 +171,19 @@ build_via_driver(const char *driver, const char *tmpdir, const char *src) static int run_row(const char *driver, const struct row *r, int seq) { - char tmpdir[256], src[256], base[64], outbin[512]; + char tmpdir[256], src[256], outbin[512]; snprintf(tmpdir, sizeof tmpdir, "/tmp/wcsfd_%d_d_%d", getpid(), seq); snprintf(src, sizeof src, "%s/main765.ww", tmpdir); - snprintf(base, sizeof base, "main765"); + snprintf(outbin, sizeof outbin, "%s/main765", tmpdir); mkdir(tmpdir, 0755); if (write_source(src, r->src) != 0) { - cleanup_tmp(tmpdir, base); + cleanup_tmp(tmpdir); return -1; } int rc = -1; - if (build_via_driver(driver, tmpdir, src) == 0) { - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); + if (build_via_driver(driver, outbin, src) == 0) rc = runwait(outbin); - } - cleanup_tmp(tmpdir, base); + cleanup_tmp(tmpdir); return rc; } diff --git a/test/wcc/768_io_types_run.c b/test/wcc/768_io_types_run.c index a06181ab..c2f40a05 100644 --- a/test/wcc/768_io_types_run.c +++ b/test/wcc/768_io_types_run.c @@ -59,7 +59,6 @@ */ #include #include -#include #include #include #include @@ -164,13 +163,15 @@ static const struct row rows[] = { }; static int -build_with(const char *driver, const char *src_path, const char *tmpdir, +build_with(const char *driver, const char *src_path, const char *outbin, const char *cwd) { char cmd[2048]; + /* explicit -o keeps both the binary and .sepwork inside the + * per-row tmpdir so rm -rf tmpdir reclaims the sep scratch */ snprintf(cmd, sizeof cmd, - "cd %s && %s build -I %s/lib %s 2>/dev/null", - tmpdir, driver, cwd, src_path); + "%s build -I %s/lib -o %s %s 2>/dev/null", + driver, cwd, outbin, src_path); return runwait(cmd); } @@ -198,27 +199,23 @@ main(void) for (int i = 0; i < n; i++) { const struct row *r = &rows[i]; - char src[64], tmpdir[64]; - snprintf(src, sizeof src, "/tmp/iotyp_%d_%d.ww", - getpid(), i); + char src[128], tmpdir[64], outbin[160], rmcmd[256]; snprintf(tmpdir, sizeof tmpdir, "/tmp/iotyp_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/iotyp_%d_%d.ww", + tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/out", tmpdir); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); + FILE *f = fopen(src, "wb"); - if (!f) { fail++; total++; continue; } + if (!f) { runwait(rmcmd); fail++; total++; continue; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; if (r->stage_mask & STAGE_CS) { total++; - if (build_with(cdrv, src, tmpdir, cwd) != 0) { + if (build_with(cdrv, src, outbin, cwd) != 0) { fprintf(stderr, "io_types_run[cs][%s]: build failed\n", r->label); @@ -232,12 +229,11 @@ main(void) fail++; } } - unlink(outbin); } if (have_ww && (r->stage_mask & STAGE_WW)) { total++; - if (build_with(wdrv, src, tmpdir, cwd) != 0) { + if (build_with(wdrv, src, outbin, cwd) != 0) { fprintf(stderr, "io_types_run[ww][%s]: build failed\n", r->label); @@ -251,11 +247,9 @@ main(void) fail++; } } - unlink(outbin); } - unlink(src); - rmdir(tmpdir); + runwait(rmcmd); } if (fail) { diff --git a/test/wcc/795_xmod_valglobal_run.c b/test/wcc/795_xmod_valglobal_run.c index 2035c5a4..178dc5de 100644 --- a/test/wcc/795_xmod_valglobal_run.c +++ b/test/wcc/795_xmod_valglobal_run.c @@ -54,7 +54,6 @@ */ #include #include -#include #include #include #include @@ -144,67 +143,63 @@ main(void) int n = 0, fail = 0; for (int i = 0; rows[i].src; i++, n++) { - char src[64]; - snprintf(src, sizeof src, "/tmp/wwxmv_%d_%d.ww", getpid(), i); - FILE *f = fopen(src, "wb"); - if (f == NULL) { fail++; continue; } - fputs(rows[i].src, f); - fclose(f); - - /* (a) cstage build + run in a scratch dir so intermediates and - * the output binary land there. */ + /* src + binary + both .s land under one tmpdir so the + * compiler's .sepwork scratch stays inside it; a single + * rm -rf at the end reclaims everything. */ char tmpdir[64]; snprintf(tmpdir, sizeof tmpdir, "/tmp/wwxmv_%d_d_%d", getpid(), i); mkdir(tmpdir, 0755); + char src[128], outbin[128], rmcmd[160]; + snprintf(src, sizeof src, "%s/wwxmv_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/wwxmv_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); + + FILE *f = fopen(src, "wb"); + if (f == NULL) { fail++; runwait(rmcmd); continue; } + fputs(rows[i].src, f); + fclose(f); + + /* (a) cstage build + run. */ char cmd[2048]; - snprintf(cmd, sizeof cmd, "cd %s && %s/ww build %s", - tmpdir, bin, src); + snprintf(cmd, sizeof cmd, "%s/ww build -o %s %s", bin, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: cstage build failed\n", rows[i].label); fail++; - unlink(src); rmdir(tmpdir); + runwait(rmcmd); continue; } - char outbin[128]; - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; - int got = runwait(outbin); if (got != rows[i].want_exit) { fprintf(stderr, "row[%s]: cstage exit %d, want %d\n", rows[i].label, got, rows[i].want_exit); fail++; } - unlink(outbin); rmdir(tmpdir); /* (b) cs==ww byte-id gate. */ - char cs_s[64], ws_s[64]; - snprintf(cs_s, sizeof cs_s, "/tmp/wwxmv_%d_%d_cs.s", getpid(), i); - snprintf(ws_s, sizeof ws_s, "/tmp/wwxmv_%d_%d_ww.s", getpid(), i); + char cs_s[128], ws_s[128]; + snprintf(cs_s, sizeof cs_s, "%s/wwxmv_%d_%d_cs.s", tmpdir, getpid(), i); + snprintf(ws_s, sizeof ws_s, "%s/wwxmv_%d_%d_ww.s", tmpdir, getpid(), i); snprintf(cmd, sizeof cmd, "%s -o %s %s 2>/dev/null", w6c, cs_s, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: w6c failed\n", rows[i].label); - fail++; unlink(src); continue; + fail++; runwait(rmcmd); continue; } snprintf(cmd, sizeof cmd, "%s -o %s %s 2>/dev/null", w6c_ww, ws_s, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: w6c_ww failed\n", rows[i].label); - fail++; unlink(src); unlink(cs_s); continue; + fail++; runwait(rmcmd); continue; } if (slurp_eq(cs_s, ws_s) != 0) { fprintf(stderr, "row[%s]: cstage/wwstage .s DIFFER " "(rule-10 byte-id violation)\n", rows[i].label); fail++; } - unlink(src); unlink(cs_s); unlink(ws_s); + runwait(rmcmd); } if (fail) { diff --git a/test/wcc/796_xmod_valglobal_dot_run.c b/test/wcc/796_xmod_valglobal_dot_run.c index 5a1a535a..73d0c4ab 100644 --- a/test/wcc/796_xmod_valglobal_dot_run.c +++ b/test/wcc/796_xmod_valglobal_dot_run.c @@ -31,7 +31,6 @@ */ #include #include -#include #include #include #include @@ -108,66 +107,58 @@ main(void) int n = 0, fail = 0; for (int i = 0; rows[i].src; i++, n++) { - char src[64]; - snprintf(src, sizeof src, "/tmp/wwxmvd_%d_%d.ww", getpid(), i); - FILE *f = fopen(src, "wb"); - if (f == NULL) { fail++; continue; } - fputs(rows[i].src, f); - fclose(f); - - /* (a) cstage build + run in a scratch dir. */ char tmpdir[64]; snprintf(tmpdir, sizeof tmpdir, "/tmp/wwxmvd_%d_d_%d", getpid(), i); mkdir(tmpdir, 0755); + char src[128], outbin[128], cs_s[128], ws_s[128], rmcmd[160]; + snprintf(src, sizeof src, "%s/wwxmvd_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/wwxmvd_%d_%d", tmpdir, getpid(), i); + snprintf(cs_s, sizeof cs_s, "%s/wwxmvd_%d_%d_cs.s", tmpdir, getpid(), i); + snprintf(ws_s, sizeof ws_s, "%s/wwxmvd_%d_%d_ww.s", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); + + FILE *f = fopen(src, "wb"); + if (f == NULL) { fail++; runwait(rmcmd); continue; } + fputs(rows[i].src, f); + fclose(f); + + /* (a) cstage build + run. */ char cmd[2048]; - snprintf(cmd, sizeof cmd, "cd %s && %s/ww build %s", - tmpdir, bin, src); + snprintf(cmd, sizeof cmd, "%s/ww build -o %s %s", bin, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: cstage build failed\n", rows[i].label); fail++; - unlink(src); rmdir(tmpdir); + runwait(rmcmd); continue; } - char outbin[128]; - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; - int got = runwait(outbin); if (got != rows[i].want_exit) { fprintf(stderr, "row[%s]: cstage exit %d, want %d\n", rows[i].label, got, rows[i].want_exit); fail++; } - unlink(outbin); rmdir(tmpdir); /* (b) cs==ww byte-id gate. */ - char cs_s[64], ws_s[64]; - snprintf(cs_s, sizeof cs_s, "/tmp/wwxmvd_%d_%d_cs.s", getpid(), i); - snprintf(ws_s, sizeof ws_s, "/tmp/wwxmvd_%d_%d_ww.s", getpid(), i); - snprintf(cmd, sizeof cmd, "%s -o %s %s 2>/dev/null", w6c, cs_s, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: w6c failed\n", rows[i].label); - fail++; unlink(src); continue; + fail++; runwait(rmcmd); continue; } snprintf(cmd, sizeof cmd, "%s -o %s %s 2>/dev/null", w6c_ww, ws_s, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: w6c_ww failed\n", rows[i].label); - fail++; unlink(src); unlink(cs_s); continue; + fail++; runwait(rmcmd); continue; } if (slurp_eq(cs_s, ws_s) != 0) { fprintf(stderr, "row[%s]: cstage/wwstage .s DIFFER " "(rule-10 byte-id violation)\n", rows[i].label); fail++; } - unlink(src); unlink(cs_s); unlink(ws_s); + runwait(rmcmd); } if (fail) { diff --git a/test/wcc/800_append_wide_elem.c b/test/wcc/800_append_wide_elem.c index d7036e68..15c942c7 100644 --- a/test/wcc/800_append_wide_elem.c +++ b/test/wcc/800_append_wide_elem.c @@ -89,7 +89,6 @@ */ #include #include -#include #include #include #include @@ -339,35 +338,31 @@ static const struct row rows[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/apwe_%d_%d.ww", getpid(), i); + char tmpdir[64], src[128], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/apwe_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/apwe_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/apwe_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>/dev/null", + driver, outbin, src); if (runwait(cmd) != 0) { if (r->want != BUILD_FAIL) fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return got; } diff --git a/test/wcc/804_delete_elem.c b/test/wcc/804_delete_elem.c index e85a185a..297946bd 100644 --- a/test/wcc/804_delete_elem.c +++ b/test/wcc/804_delete_elem.c @@ -321,19 +321,22 @@ errlog_has(const char *path, const char *needle) static int run_driver(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], errlog[80], cmd[1200]; - snprintf(src, sizeof src, "/tmp/dele_%d_%d.ww", getpid(), i); + char tmpdir[64], src[128], outbin[128], errlog[160], rmcmd[160]; + char cmd[1200]; snprintf(tmpdir, sizeof tmpdir, "/tmp/dele_%d_d_%d", getpid(), i); - snprintf(errlog, sizeof errlog, "%s.err", src); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/dele_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/dele_%d_%d", tmpdir, getpid(), i); + snprintf(errlog, sizeof errlog, "%s/err", tmpdir); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>%s", - tmpdir, driver, src, errlog); + snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>%s", + driver, outbin, src, errlog); if (runwait(cmd) != 0) { int rc = -1; if (r->want != BUILD_FAIL) { @@ -346,19 +349,13 @@ run_driver(const char *driver, const struct row *r, int i) r->label, driver, r->expect_err); rc = -3; /* failed, but for the wrong reason */ } - unlink(src); unlink(errlog); rmdir(tmpdir); + runwait(rmcmd); return rc; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(errlog); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return got; } diff --git a/test/wcc/805_placeaddr_store.c b/test/wcc/805_placeaddr_store.c index 8b9599ae..60cfe854 100644 --- a/test/wcc/805_placeaddr_store.c +++ b/test/wcc/805_placeaddr_store.c @@ -1326,19 +1326,22 @@ errlog_has(const char *path, const char *needle) static int run_driver(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], errlog[80], cmd[1200]; - snprintf(src, sizeof src, "/tmp/plad_%d_%d.ww", getpid(), i); + char tmpdir[64], src[128], outbin[128], errlog[128], rmcmd[160]; + char cmd[1200]; snprintf(tmpdir, sizeof tmpdir, "/tmp/plad_%d_d_%d", getpid(), i); - snprintf(errlog, sizeof errlog, "%s.err", src); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/plad_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/plad_%d_%d", tmpdir, getpid(), i); + snprintf(errlog, sizeof errlog, "%s/err", tmpdir); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>%s", - tmpdir, driver, src, errlog); + snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>%s", + driver, outbin, src, errlog); if (runwait(cmd) != 0) { int rc = -1; if (r->want != BUILD_FAIL) { @@ -1351,19 +1354,13 @@ run_driver(const char *driver, const struct row *r, int i) r->label, driver, r->expect_err); rc = -3; /* failed, but for the wrong reason */ } - unlink(src); unlink(errlog); rmdir(tmpdir); + runwait(rmcmd); return rc; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(errlog); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return got; } diff --git a/test/wcc/806_append_place.c b/test/wcc/806_append_place.c index 3626d53c..6272a284 100644 --- a/test/wcc/806_append_place.c +++ b/test/wcc/806_append_place.c @@ -806,19 +806,22 @@ errlog_has(const char *path, const char *needle) static int run_driver(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], errlog[80], cmd[1200]; - snprintf(src, sizeof src, "/tmp/applp_%d_%d.ww", getpid(), i); + char tmpdir[64], src[128], outbin[128], errlog[160]; + char rmcmd[160], cmd[1200]; snprintf(tmpdir, sizeof tmpdir, "/tmp/applp_%d_d_%d", getpid(), i); - snprintf(errlog, sizeof errlog, "%s.err", src); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/applp_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/applp_%d_%d", tmpdir, getpid(), i); + snprintf(errlog, sizeof errlog, "%s/err", tmpdir); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>%s", - tmpdir, driver, src, errlog); + snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>%s", + driver, outbin, src, errlog); if (runwait(cmd) != 0) { int rc = -1; if (r->want != BUILD_FAIL) { @@ -831,19 +834,13 @@ run_driver(const char *driver, const struct row *r, int i) r->label, driver, r->expect_err); rc = -3; /* failed, but for the wrong reason */ } - unlink(src); unlink(errlog); rmdir(tmpdir); + runwait(rmcmd); return rc; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(errlog); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return got; } diff --git a/test/wcc/806_tryprop_multisuccess.c b/test/wcc/806_tryprop_multisuccess.c index 612ec7cb..bd5a747f 100644 --- a/test/wcc/806_tryprop_multisuccess.c +++ b/test/wcc/806_tryprop_multisuccess.c @@ -307,19 +307,21 @@ errlog_has(const char *path, const char *needle) static int run_driver(const char *driver, const char *expect, const struct row *r, int i) { - char src[64], tmpdir[64], errlog[80], cmd[1200]; - snprintf(src, sizeof src, "/tmp/tpms_%d_%d.ww", getpid(), i); + char tmpdir[64], src[128], outbin[128], errlog[128], rmcmd[160], cmd[1200]; snprintf(tmpdir, sizeof tmpdir, "/tmp/tpms_%d_d_%d", getpid(), i); - snprintf(errlog, sizeof errlog, "%s.err", src); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/tpms_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/tpms_%d_%d", tmpdir, getpid(), i); + snprintf(errlog, sizeof errlog, "%s/err", tmpdir); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>%s", - tmpdir, driver, src, errlog); + snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>%s", + driver, outbin, src, errlog); if (runwait(cmd) != 0) { int rc = -1; if (r->want != BUILD_FAIL) { @@ -331,19 +333,13 @@ run_driver(const char *driver, const char *expect, const struct row *r, int i) r->label, driver, expect); rc = -3; /* failed, but for the wrong reason */ } - unlink(src); unlink(errlog); rmdir(tmpdir); + runwait(rmcmd); return rc; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(errlog); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return got; } diff --git a/test/wcc/807_insert_elem.c b/test/wcc/807_insert_elem.c index 92dc4801..cd4713a8 100644 --- a/test/wcc/807_insert_elem.c +++ b/test/wcc/807_insert_elem.c @@ -683,19 +683,21 @@ errlog_has(const char *path, const char *needle) static int run_driver(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], errlog[80], cmd[1200]; - snprintf(src, sizeof src, "/tmp/inse_%d_%d.ww", getpid(), i); + char tmpdir[64], src[128], outbin[128], errlog[128], rmcmd[160], cmd[1200]; snprintf(tmpdir, sizeof tmpdir, "/tmp/inse_%d_d_%d", getpid(), i); - snprintf(errlog, sizeof errlog, "%s.err", src); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/inse_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/inse_%d_%d", tmpdir, getpid(), i); + snprintf(errlog, sizeof errlog, "%s/err", tmpdir); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>%s", - tmpdir, driver, src, errlog); + snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>%s", + driver, outbin, src, errlog); if (runwait(cmd) != 0) { int rc = -1; if (r->want != BUILD_FAIL) { @@ -708,19 +710,13 @@ run_driver(const char *driver, const struct row *r, int i) r->label, driver, r->expect_err); rc = -3; /* failed, but for the wrong reason */ } - unlink(src); unlink(errlog); rmdir(tmpdir); + runwait(rmcmd); return rc; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(errlog); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return got; } diff --git a/test/wcc/808_arrlit_overlong.c b/test/wcc/808_arrlit_overlong.c index fb021859..fc8e4a9a 100644 --- a/test/wcc/808_arrlit_overlong.c +++ b/test/wcc/808_arrlit_overlong.c @@ -305,34 +305,30 @@ static const struct negrow neg[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/aol_%d_%d.ww", getpid(), i); + char src[128], tmpdir[64], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/aol_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/aol_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/aol_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>/dev/null", + driver, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return got; } @@ -343,30 +339,22 @@ static int build_should_fail(const char *dname, const char *driver, const struct negrow *r, const char *diag, int i) { - char s[64], tmpdir[64], errf[64], cmd[1024]; - snprintf(s, sizeof s, "/tmp/aoln_%d_%d.ww", getpid(), i); + char s[128], tmpdir[64], errf[128], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/aoln_%d_d_%d", getpid(), i); - snprintf(errf, sizeof errf, "/tmp/aoln_%d_%d.err", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(s, sizeof s, "%s/aoln_%d_%d.ww", tmpdir, getpid(), i); + snprintf(errf, sizeof errf, "%s/aoln_%d_%d.err", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/aoln_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(s, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>%s", - tmpdir, driver, s, errf); + snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>%s", + driver, outbin, s, errf); int rc = runwait(cmd); - unlink(s); - /* clean any emitted binary */ - const char *base = strrchr(s, '/'); - base = base ? base + 1 : s; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; - unlink(outbin); - rmdir(tmpdir); int bad = 0; if (rc == 0) { @@ -389,7 +377,7 @@ build_should_fail(const char *dname, const char *driver, bad = 1; } } - unlink(errf); + runwait(rmcmd); return bad; } diff --git a/test/wcc/809_delete_range.c b/test/wcc/809_delete_range.c index 73fdb86b..dcd1aa81 100644 --- a/test/wcc/809_delete_range.c +++ b/test/wcc/809_delete_range.c @@ -442,19 +442,22 @@ errlog_has(const char *path, const char *needle) static int run_driver(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], errlog[80], cmd[1200]; - snprintf(src, sizeof src, "/tmp/delr_%d_%d.ww", getpid(), i); + char tmpdir[64], src[128], outbin[128], errlog[128], rmcmd[160]; + char cmd[1200]; snprintf(tmpdir, sizeof tmpdir, "/tmp/delr_%d_d_%d", getpid(), i); - snprintf(errlog, sizeof errlog, "%s.err", src); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/delr_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/delr_%d_%d", tmpdir, getpid(), i); + snprintf(errlog, sizeof errlog, "%s/err", tmpdir); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>%s", - tmpdir, driver, src, errlog); + snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>%s", + driver, outbin, src, errlog); if (runwait(cmd) != 0) { int rc = -1; if (r->want != BUILD_FAIL) { @@ -467,19 +470,13 @@ run_driver(const char *driver, const struct row *r, int i) r->label, driver, r->expect_err); rc = -3; /* failed, but for the wrong reason */ } - unlink(src); unlink(errlog); rmdir(tmpdir); + runwait(rmcmd); return rc; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(errlog); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return got; } diff --git a/test/wcc/809_idx_structlit_store.c b/test/wcc/809_idx_structlit_store.c index f0b4018e..f8308c5f 100644 --- a/test/wcc/809_idx_structlit_store.c +++ b/test/wcc/809_idx_structlit_store.c @@ -75,7 +75,6 @@ */ #include #include -#include #include #include #include @@ -369,36 +368,32 @@ static const struct row rows[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/isls_%d_%d.ww", getpid(), i); + char tmpdir[64], src[128], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/isls_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/isls_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/isls_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>/dev/null", + driver, outbin, src); if (runwait(cmd) != 0) { /* want == -1 rows pin a LOUD build refusal (task #32). */ if (r->want != -1) fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return got; } @@ -429,7 +424,11 @@ asm_byte_identical(const char *bin, const struct row *r, int i) mkdir(tmpdir, 0755); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { + snprintf(cmd, sizeof cmd, "rm -rf %s", tmpdir); + if (system(cmd)) {} + return -1; + } fputs(r->src, f); fclose(f); diff --git a/test/wcc/810_dyn.c b/test/wcc/810_dyn.c index 92a4c38b..624285f2 100644 --- a/test/wcc/810_dyn.c +++ b/test/wcc/810_dyn.c @@ -17,7 +17,6 @@ */ #include #include -#include #include #include #include @@ -129,11 +128,12 @@ main(void) int n = 0, fail = 0; for (int i = 0; rows[i].src; i++, n++) { - char src[80], exe[80], tmpdir[80]; - snprintf(src, sizeof src, "/tmp/wwdyn_%d_%d.ww", getpid(), i); - snprintf(exe, sizeof exe, "/tmp/wwdyn_%d_%d", getpid(), i); + char tmpdir[80], src[128], outbin[128], rmcmd[160]; snprintf(tmpdir, sizeof tmpdir, "/tmp/wwdyn_%d_d_%d", getpid(), i); mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/wwdyn_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/wwdyn_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); fputs(rows[i].src, f); @@ -141,29 +141,22 @@ main(void) char cmd[1024]; snprintf(cmd, sizeof cmd, - "cd %s && %s/ww build %s -L %s -l c", - tmpdir, bin, src, libdir); + "%s/ww build -o %s %s -L %s -l c", + bin, outbin, src, libdir); if (runwait(cmd) != 0) { fprintf(stderr, "dyn row %d: build failed\n", i); fail++; - unlink(src); rmdir(tmpdir); + runwait(rmcmd); continue; } - char outbin[160]; - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; - int got = runwait(outbin); if (got != rows[i].want_exit) { fprintf(stderr, "dyn row %d: exit %d, want %d\n", i, got, rows[i].want_exit); fail++; } - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); } if (fail) { fprintf(stderr, "%d/%d dyn tests failed\n", fail, n); diff --git a/test/wcc/811_inferred_let_struct.c b/test/wcc/811_inferred_let_struct.c index 92d273b7..86212757 100644 --- a/test/wcc/811_inferred_let_struct.c +++ b/test/wcc/811_inferred_let_struct.c @@ -49,7 +49,6 @@ */ #include #include -#include #include #include #include @@ -217,34 +216,30 @@ static const struct row rows[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/ils_%d_%d.ww", getpid(), i); + char tmpdir[64], src[128], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/ils_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/ils_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/ils_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>/dev/null", + driver, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return got; } diff --git a/test/wcc/812_agg_assign_width.c b/test/wcc/812_agg_assign_width.c index 293f8cf3..680fde86 100644 --- a/test/wcc/812_agg_assign_width.c +++ b/test/wcc/812_agg_assign_width.c @@ -61,7 +61,6 @@ */ #include #include -#include #include #include #include @@ -348,34 +347,30 @@ static const struct row rows[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/aggas_%d_%d.ww", getpid(), i); + char tmpdir[64], src[128], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/aggas_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/aggas_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/aggas_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>/dev/null", + driver, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return got; } diff --git a/test/wcc/813_arrlit_infer_elem_run.c b/test/wcc/813_arrlit_infer_elem_run.c index 59bc6ed9..db08667a 100644 --- a/test/wcc/813_arrlit_infer_elem_run.c +++ b/test/wcc/813_arrlit_infer_elem_run.c @@ -69,7 +69,6 @@ */ #include #include -#include #include #include #include @@ -217,34 +216,30 @@ static const struct row rows[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[80], cmd[1024]; - snprintf(src, sizeof src, "/tmp/aie_%d_%d.ww", getpid(), i); + char tmpdir[64], src[128], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/aie_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/aie_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/aie_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>/dev/null", + driver, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[160]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return got; } diff --git a/test/wcc/814_def_arr_infer_len.c b/test/wcc/814_def_arr_infer_len.c index e27aab41..8fe1678a 100644 --- a/test/wcc/814_def_arr_infer_len.c +++ b/test/wcc/814_def_arr_infer_len.c @@ -167,34 +167,30 @@ static const char *neg_diag[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/dail_%d_%d.ww", getpid(), i); + char tmpdir[64], src[128], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/dail_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/dail_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/dail_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>/dev/null", + driver, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return got; } @@ -218,32 +214,24 @@ static int build_should_fail(const char *driver, const char *src, const char *diag, int i) { - char s[64], tmpdir[64], cmd[1024], errf[64]; - snprintf(s, sizeof s, "/tmp/dailn_%d_%d.ww", getpid(), i); + char tmpdir[64], s[128], outbin[128], errf[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/dailn_%d_d_%d", getpid(), i); - snprintf(errf, sizeof errf, "/tmp/dailn_%d_e_%d.txt", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(s, sizeof s, "%s/dailn_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/dailn_%d_%d", tmpdir, getpid(), i); + snprintf(errf, sizeof errf, "%s/err", tmpdir); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(s, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s >/dev/null 2>%s", - tmpdir, driver, s, errf); + snprintf(cmd, sizeof cmd, "%s build -o %s %s >/dev/null 2>%s", + driver, outbin, s, errf); int rc = runwait(cmd); int hasmsg = filehas(errf, diag); - unlink(s); - unlink(errf); - /* clean any emitted binary */ - const char *base = strrchr(s, '/'); - base = base ? base + 1 : s; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; - unlink(outbin); - rmdir(tmpdir); + runwait(rmcmd); /* build must NOT succeed AND must emit its diagnostic. */ return (rc != 0 && hasmsg) ? 0 : -1; } diff --git a/test/wcc/816_def_arr_len.c b/test/wcc/816_def_arr_len.c index 6b6d97e9..2aacb762 100644 --- a/test/wcc/816_def_arr_len.c +++ b/test/wcc/816_def_arr_len.c @@ -29,7 +29,6 @@ */ #include #include -#include #include #include #include @@ -93,34 +92,30 @@ static const struct row rows[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/dal_%d_%d.ww", getpid(), i); + char tmpdir[64], src[128], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/dal_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/dal_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/dal_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>/dev/null", + driver, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return got; } diff --git a/test/wcc/817_arr_cap_reject.c b/test/wcc/817_arr_cap_reject.c index fe3de25c..622ddb01 100644 --- a/test/wcc/817_arr_cap_reject.c +++ b/test/wcc/817_arr_cap_reject.c @@ -133,34 +133,30 @@ static const char *neg_diag[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/acr_%d_%d.ww", getpid(), i); + char tmpdir[64], src[128], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/acr_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/acr_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/acr_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>/dev/null", + driver, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return got; } @@ -184,32 +180,24 @@ static int build_should_fail(const char *driver, const char *src, const char *diag, int i) { - char s[64], tmpdir[64], cmd[1024], errf[64]; - snprintf(s, sizeof s, "/tmp/acrn_%d_%d.ww", getpid(), i); + char tmpdir[64], s[128], outbin[128], errf[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/acrn_%d_d_%d", getpid(), i); - snprintf(errf, sizeof errf, "/tmp/acrn_%d_e_%d.txt", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(s, sizeof s, "%s/acrn_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/acrn_%d_%d", tmpdir, getpid(), i); + snprintf(errf, sizeof errf, "%s/err", tmpdir); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(s, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s >/dev/null 2>%s", - tmpdir, driver, s, errf); + snprintf(cmd, sizeof cmd, "%s build -o %s %s >/dev/null 2>%s", + driver, outbin, s, errf); int rc = runwait(cmd); int hasmsg = filehas(errf, diag); - unlink(s); - unlink(errf); - /* clean any emitted binary */ - const char *base = strrchr(s, '/'); - base = base ? base + 1 : s; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; - unlink(outbin); - rmdir(tmpdir); + runwait(rmcmd); /* build must NOT succeed AND must emit its diagnostic. */ return (rc != 0 && hasmsg) ? 0 : -1; } diff --git a/test/wcc/818_arr_ptr_global.c b/test/wcc/818_arr_ptr_global.c index 7df44914..91b0d605 100644 --- a/test/wcc/818_arr_ptr_global.c +++ b/test/wcc/818_arr_ptr_global.c @@ -29,7 +29,6 @@ */ #include #include -#include #include #include #include @@ -83,34 +82,30 @@ static const struct row rows[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/apg_%d_%d.ww", getpid(), i); + char tmpdir[64], src[128], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/apg_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/apg_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/apg_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>/dev/null", + driver, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return got; } diff --git a/test/wcc/819_def_str_table.c b/test/wcc/819_def_str_table.c index 2cde150b..5bd298cf 100644 --- a/test/wcc/819_def_str_table.c +++ b/test/wcc/819_def_str_table.c @@ -36,7 +36,6 @@ */ #include #include -#include #include #include #include @@ -127,34 +126,30 @@ static const struct row rows[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/dst_%d_%d.ww", getpid(), i); + char tmpdir[64], src[128], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/dst_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/dst_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/dst_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>/dev/null", + driver, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return got; } diff --git a/test/wcc/820_arr_zero_vs_infer.c b/test/wcc/820_arr_zero_vs_infer.c index ba0aafd1..b7a1e112 100644 --- a/test/wcc/820_arr_zero_vs_infer.c +++ b/test/wcc/820_arr_zero_vs_infer.c @@ -42,7 +42,6 @@ */ #include #include -#include #include #include #include @@ -160,34 +159,30 @@ static const char *neg[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/azi_%d_%d.ww", getpid(), i); + char tmpdir[64], src[128], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/azi_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/azi_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/azi_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>/dev/null", + driver, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return got; } @@ -196,29 +191,22 @@ run_driver(const char *driver, const struct row *r, int i) static int build_should_fail(const char *driver, const char *src, int i) { - char s[64], tmpdir[64], cmd[1024]; - snprintf(s, sizeof s, "/tmp/azin_%d_%d.ww", getpid(), i); + char tmpdir[64], s[128], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/azin_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(s, sizeof s, "%s/azin_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/out", tmpdir); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(s, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null", - tmpdir, driver, s); + snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>/dev/null", + driver, outbin, s); int rc = runwait(cmd); - unlink(s); - /* clean any emitted binary */ - const char *base = strrchr(s, '/'); - base = base ? base + 1 : s; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; - unlink(outbin); - rmdir(tmpdir); + runwait(rmcmd); return rc == 0 ? -1 : 0; /* build must NOT succeed */ } diff --git a/test/wcc/821_def_str_index_reject.c b/test/wcc/821_def_str_index_reject.c index 5b12ab1d..11f6ea0d 100644 --- a/test/wcc/821_def_str_index_reject.c +++ b/test/wcc/821_def_str_index_reject.c @@ -151,34 +151,32 @@ static const char *neg_diag[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/dsi_%d_%d.ww", getpid(), i); + char tmpdir[64], src[128], outbin[128], cmd[1024], rmcmd[160]; snprintf(tmpdir, sizeof tmpdir, "/tmp/dsi_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/dsi_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/dsi_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null", - tmpdir, driver, src); + /* #8: -o pins binary + .sepwork scratch under tmpdir; rm -rf on + * every exit path removes the now-non-empty dir. */ + snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>/dev/null", + driver, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return got; } @@ -202,32 +200,26 @@ static int build_should_fail(const char *driver, const char *src, const char *diag, int i) { - char s[64], tmpdir[64], cmd[1024], errf[64]; - snprintf(s, sizeof s, "/tmp/dsin_%d_%d.ww", getpid(), i); + char tmpdir[64], s[128], outbin[128], cmd[1024], errf[128], rmcmd[160]; snprintf(tmpdir, sizeof tmpdir, "/tmp/dsin_%d_d_%d", getpid(), i); - snprintf(errf, sizeof errf, "/tmp/dsin_%d_e_%d.txt", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(s, sizeof s, "%s/dsin_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/dsin_%d_%d", tmpdir, getpid(), i); + snprintf(errf, sizeof errf, "%s/err", tmpdir); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(s, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s >/dev/null 2>%s", - tmpdir, driver, s, errf); + /* #8: -o pins binary + any .sepwork scratch under tmpdir; rm -rf + * removes the now-non-empty dir. */ + snprintf(cmd, sizeof cmd, "%s build -o %s %s >/dev/null 2>%s", + driver, outbin, s, errf); int rc = runwait(cmd); int hasmsg = filehas(errf, diag); - unlink(s); - unlink(errf); - /* clean any emitted binary */ - const char *base = strrchr(s, '/'); - base = base ? base + 1 : s; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; - unlink(outbin); - rmdir(tmpdir); + runwait(rmcmd); /* build must NOT succeed AND must emit its diagnostic. */ return (rc != 0 && hasmsg) ? 0 : -1; } diff --git a/test/wcc/822_struct_global_byval_arg.c b/test/wcc/822_struct_global_byval_arg.c index 95419def..35e94346 100644 --- a/test/wcc/822_struct_global_byval_arg.c +++ b/test/wcc/822_struct_global_byval_arg.c @@ -37,7 +37,6 @@ */ #include #include -#include #include #include #include @@ -100,34 +99,30 @@ static const struct row rows[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/sga_%d_%d.ww", getpid(), i); + char tmpdir[64], src[128], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/sga_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/sga_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/sga_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>/dev/null", + driver, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return got; } diff --git a/test/wcc/823_inferred_global_let.c b/test/wcc/823_inferred_global_let.c index eba66038..bff8daf7 100644 --- a/test/wcc/823_inferred_global_let.c +++ b/test/wcc/823_inferred_global_let.c @@ -29,7 +29,6 @@ */ #include #include -#include #include #include #include @@ -89,34 +88,30 @@ static const struct row rows[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/igl_%d_%d.ww", getpid(), i); + char tmpdir[64], src[128], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/igl_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/igl_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/igl_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>/dev/null", + driver, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return got; } diff --git a/test/wcc/824_inferred_float_global.c b/test/wcc/824_inferred_float_global.c index ffef52a5..8647f8a7 100644 --- a/test/wcc/824_inferred_float_global.c +++ b/test/wcc/824_inferred_float_global.c @@ -41,7 +41,6 @@ */ #include #include -#include #include #include #include @@ -124,34 +123,30 @@ static const struct row rows[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/ifg_%d_%d.ww", getpid(), i); + char src[128], tmpdir[64], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/ifg_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/ifg_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/ifg_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>/dev/null", + driver, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return got; } diff --git a/test/wcc/825_errfirst_union_try.c b/test/wcc/825_errfirst_union_try.c index 582313ae..ad88a359 100644 --- a/test/wcc/825_errfirst_union_try.c +++ b/test/wcc/825_errfirst_union_try.c @@ -41,7 +41,6 @@ */ #include #include -#include #include #include #include @@ -132,34 +131,30 @@ static const struct row rows[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/efu_%d_%d.ww", getpid(), i); + char tmpdir[64], src[128], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/efu_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/efu_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/efu_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>/dev/null", + driver, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return got; } diff --git a/test/wcc/826_alias_tuple_coerce.c b/test/wcc/826_alias_tuple_coerce.c index a3906346..fe0e9167 100644 --- a/test/wcc/826_alias_tuple_coerce.c +++ b/test/wcc/826_alias_tuple_coerce.c @@ -50,7 +50,6 @@ */ #include #include -#include #include #include #include @@ -167,34 +166,30 @@ static const char *neg[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/atc_%d_%d.ww", getpid(), i); + char tmpdir[64], src[128], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/atc_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/atc_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/atc_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>/dev/null", + driver, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return got; } @@ -203,28 +198,22 @@ run_driver(const char *driver, const struct row *r, int i) static int build_should_fail(const char *driver, const char *src, int i) { - char s[64], tmpdir[64], cmd[1024]; - snprintf(s, sizeof s, "/tmp/atc_neg_%d_%d.ww", getpid(), i); + char tmpdir[64], s[128], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/atc_neg_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(s, sizeof s, "%s/atc_neg_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/atc_neg_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(s, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null", - tmpdir, driver, s); + snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>/dev/null", + driver, outbin, s); int rc = runwait(cmd); - unlink(s); - const char *base = strrchr(s, '/'); - base = base ? base + 1 : s; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; - unlink(outbin); - rmdir(tmpdir); + runwait(rmcmd); return rc == 0 ? -1 : 0; /* build must NOT succeed */ } diff --git a/test/wcc/827_str_eq.c b/test/wcc/827_str_eq.c index d63b0b7e..dc39a9d1 100644 --- a/test/wcc/827_str_eq.c +++ b/test/wcc/827_str_eq.c @@ -38,7 +38,6 @@ */ #include #include -#include #include #include #include @@ -168,34 +167,30 @@ static const struct row asmrows[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/seq_%d_%d.ww", getpid(), i); + char tmpdir[64], src[128], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/seq_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/seq_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/seq_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>/dev/null", + driver, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return got; } diff --git a/test/wcc/828_overlong_arrlit.c b/test/wcc/828_overlong_arrlit.c index b3c3d700..e70b51de 100644 --- a/test/wcc/828_overlong_arrlit.c +++ b/test/wcc/828_overlong_arrlit.c @@ -34,7 +34,6 @@ */ #include #include -#include #include #include #include @@ -130,34 +129,30 @@ static const char *neg[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/oal_%d_%d.ww", getpid(), i); + char src[128], tmpdir[64], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/oal_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/oal_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/oal_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>/dev/null", + driver, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return got; } @@ -167,28 +162,25 @@ run_driver(const char *driver, const struct row *r, int i) static int build_should_fail(const char *driver, const char *src, int i) { - char s[64], tmpdir[64], cmd[1024]; - snprintf(s, sizeof s, "/tmp/oaln_%d_%d.ww", getpid(), i); + char s[128], tmpdir[64], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/oaln_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(s, sizeof s, "%s/oaln_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/oaln_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(s, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null", - tmpdir, driver, s); + /* explicit -o inside tmpdir so the binary AND .sepwork both land + * in tmpdir and die with rm -rf (the stem follows the output, not the + * source). */ + snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>/dev/null", + driver, outbin, s); int rc = runwait(cmd); - unlink(s); - const char *base = strrchr(s, '/'); - base = base ? base + 1 : s; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; - unlink(outbin); - rmdir(tmpdir); + runwait(rmcmd); return rc == 0 ? -1 : 0; /* build must NOT succeed */ } diff --git a/test/wcc/829_slice_str_global_arg.c b/test/wcc/829_slice_str_global_arg.c index c21b7762..b08c4eac 100644 --- a/test/wcc/829_slice_str_global_arg.c +++ b/test/wcc/829_slice_str_global_arg.c @@ -61,7 +61,6 @@ */ #include #include -#include #include #include #include @@ -176,34 +175,30 @@ static const struct row rows[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/ssg_%d_%d.ww", getpid(), i); + char src[128], tmpdir[64], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/ssg_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/ssg_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/ssg_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>/dev/null", + driver, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return got; } diff --git a/test/wcc/830_cast_base_index.c b/test/wcc/830_cast_base_index.c index 3f62d3cd..bd597289 100644 --- a/test/wcc/830_cast_base_index.c +++ b/test/wcc/830_cast_base_index.c @@ -38,7 +38,6 @@ */ #include #include -#include #include #include #include @@ -137,34 +136,30 @@ static const struct row rows[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/cbi_%d_%d.ww", getpid(), i); + char tmpdir[64], src[128], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/cbi_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/cbi_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/cbi_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>/dev/null", + driver, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return got; } diff --git a/test/wcc/831_match_field_inplace.c b/test/wcc/831_match_field_inplace.c index 9950d41e..27959578 100644 --- a/test/wcc/831_match_field_inplace.c +++ b/test/wcc/831_match_field_inplace.c @@ -39,7 +39,6 @@ */ #include #include -#include #include #include #include @@ -150,34 +149,29 @@ static const struct row rows[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/wcmfi_%d_%d.ww", getpid(), i); + char src[128], tmpdir[64], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/wcmfi_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/wcmfi_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/wcmfi_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s", driver, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return got; } diff --git a/test/wcc/832_tuple_elem_overlong.c b/test/wcc/832_tuple_elem_overlong.c index c5fd8bf3..65c7f9aa 100644 --- a/test/wcc/832_tuple_elem_overlong.c +++ b/test/wcc/832_tuple_elem_overlong.c @@ -51,7 +51,6 @@ */ #include #include -#include #include #include #include @@ -182,34 +181,30 @@ static const char *neg[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/teo_%d_%d.ww", getpid(), i); + char tmpdir[64], src[128], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/teo_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/teo_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/teo_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>/dev/null", + driver, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return got; } @@ -219,28 +214,22 @@ run_driver(const char *driver, const struct row *r, int i) static int build_should_fail(const char *driver, const char *src, int i) { - char s[64], tmpdir[64], cmd[1024]; - snprintf(s, sizeof s, "/tmp/teon_%d_%d.ww", getpid(), i); + char tmpdir[64], s[128], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/teon_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(s, sizeof s, "%s/teon_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/teon_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(s, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null", - tmpdir, driver, s); + snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>/dev/null", + driver, outbin, s); int rc = runwait(cmd); - unlink(s); - const char *base = strrchr(s, '/'); - base = base ? base + 1 : s; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; - unlink(outbin); - rmdir(tmpdir); + runwait(rmcmd); return rc == 0 ? -1 : 0; /* build must NOT succeed */ } diff --git a/test/wcc/833_inferred_array_global.c b/test/wcc/833_inferred_array_global.c index add9fb96..890151ab 100644 --- a/test/wcc/833_inferred_array_global.c +++ b/test/wcc/833_inferred_array_global.c @@ -36,7 +36,6 @@ */ #include #include -#include #include #include #include @@ -96,34 +95,30 @@ static const struct row rows[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/iag_%d_%d.ww", getpid(), i); + char tmpdir[64], src[128], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/iag_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/iag_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/iag_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>/dev/null", + driver, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return got; } diff --git a/test/wcc/834_tagged_arr_variant.c b/test/wcc/834_tagged_arr_variant.c index e05fd93e..e9046503 100644 --- a/test/wcc/834_tagged_arr_variant.c +++ b/test/wcc/834_tagged_arr_variant.c @@ -36,7 +36,6 @@ */ #include #include -#include #include #include #include @@ -161,34 +160,30 @@ static const char *neg[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/tav_%d_%d.ww", getpid(), i); + char tmpdir[64], src[128], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/tav_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/tav_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/tav_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>/dev/null", + driver, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return got; } @@ -198,28 +193,22 @@ run_driver(const char *driver, const struct row *r, int i) static int build_should_fail(const char *driver, const char *src, int i) { - char s[64], tmpdir[64], cmd[1024]; - snprintf(s, sizeof s, "/tmp/tavn_%d_%d.ww", getpid(), i); + char tmpdir[64], s[128], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/tavn_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(s, sizeof s, "%s/tavn_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/tavn_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(s, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null", - tmpdir, driver, s); + snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>/dev/null", + driver, outbin, s); int rc = runwait(cmd); - unlink(s); - const char *base = strrchr(s, '/'); - base = base ? base + 1 : s; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; - unlink(outbin); - rmdir(tmpdir); + runwait(rmcmd); return rc == 0 ? -1 : 0; /* build must NOT succeed */ } diff --git a/test/wcc/835_nested_union_int_box.c b/test/wcc/835_nested_union_int_box.c index 291f5790..5624524a 100644 --- a/test/wcc/835_nested_union_int_box.c +++ b/test/wcc/835_nested_union_int_box.c @@ -47,7 +47,6 @@ */ #include #include -#include #include #include #include @@ -163,34 +162,30 @@ static const char *neg[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/nui_%d_%d.ww", getpid(), i); + char tmpdir[64], src[128], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/nui_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/nui_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/nui_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>/dev/null", + driver, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return got; } @@ -199,28 +194,22 @@ run_driver(const char *driver, const struct row *r, int i) static int build_should_fail(const char *driver, const char *src, int i) { - char s[64], tmpdir[64], cmd[1024]; - snprintf(s, sizeof s, "/tmp/nuin_%d_%d.ww", getpid(), i); + char tmpdir[64], s[128], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/nuin_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(s, sizeof s, "%s/nuin_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/nuin_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(s, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null", - tmpdir, driver, s); + snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>/dev/null", + driver, outbin, s); int rc = runwait(cmd); - unlink(s); - const char *base = strrchr(s, '/'); - base = base ? base + 1 : s; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; - unlink(outbin); - rmdir(tmpdir); + runwait(rmcmd); return rc == 0 ? -1 : 0; /* build must NOT succeed */ } diff --git a/test/wcc/836_tagged_assignable_cluster.c b/test/wcc/836_tagged_assignable_cluster.c index 8aee0afd..32867b62 100644 --- a/test/wcc/836_tagged_assignable_cluster.c +++ b/test/wcc/836_tagged_assignable_cluster.c @@ -48,7 +48,6 @@ */ #include #include -#include #include #include #include @@ -138,34 +137,30 @@ static const char *neg[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/tac_%d_%d.ww", getpid(), i); + char src[128], tmpdir[64], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/tac_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/tac_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/tac_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>/dev/null", + driver, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return got; } @@ -174,28 +169,22 @@ run_driver(const char *driver, const struct row *r, int i) static int build_should_fail(const char *driver, const char *src, int i) { - char s[64], tmpdir[64], cmd[1024]; - snprintf(s, sizeof s, "/tmp/tacn_%d_%d.ww", getpid(), i); + char s[128], tmpdir[64], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/tacn_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(s, sizeof s, "%s/tacn_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/tacn_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(s, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null", - tmpdir, driver, s); + snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>/dev/null", + driver, outbin, s); int rc = runwait(cmd); - unlink(s); - const char *base = strrchr(s, '/'); - base = base ? base + 1 : s; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; - unlink(outbin); - rmdir(tmpdir); + runwait(rmcmd); return rc == 0 ? -1 : 0; /* build must NOT succeed */ } diff --git a/test/wcc/837_idcast_tagged_return.c b/test/wcc/837_idcast_tagged_return.c index cdb806cd..b3d7ac48 100644 --- a/test/wcc/837_idcast_tagged_return.c +++ b/test/wcc/837_idcast_tagged_return.c @@ -31,7 +31,6 @@ */ #include #include -#include #include #include #include @@ -101,34 +100,30 @@ static const struct row rows[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/idc_%d_%d.ww", getpid(), i); + char tmpdir[64], src[128], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/idc_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/idc_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/idc_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>/dev/null", + driver, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return got; } diff --git a/test/wcc/838_global_tagged_castinit.c b/test/wcc/838_global_tagged_castinit.c index 2d6c0746..0d68f5cf 100644 --- a/test/wcc/838_global_tagged_castinit.c +++ b/test/wcc/838_global_tagged_castinit.c @@ -42,7 +42,6 @@ */ #include #include -#include #include #include #include @@ -98,56 +97,46 @@ write_src(const char *path, const char *mid) static int run_driver(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/gtc_%d_%d.ww", getpid(), i); + char src[128], tmpdir[64], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/gtc_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/gtc_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/gtc_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); write_src(src, r->src); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>/dev/null", + driver, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return got; } static int build_should_fail(const char *driver, const char *mid, int i) { - char s[64], tmpdir[64], cmd[1024]; - snprintf(s, sizeof s, "/tmp/gtcn_%d_%d.ww", getpid(), i); + char s[128], tmpdir[64], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/gtcn_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(s, sizeof s, "%s/gtcn_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/gtcn_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); write_src(s, mid); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null", - tmpdir, driver, s); + snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>/dev/null", + driver, outbin, s); int rc = runwait(cmd); - unlink(s); - const char *base = strrchr(s, '/'); - base = base ? base + 1 : s; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; - unlink(outbin); - rmdir(tmpdir); + runwait(rmcmd); return rc == 0 ? -1 : 0; /* build must NOT succeed */ } diff --git a/test/wcc/840_zeroinit_run.c b/test/wcc/840_zeroinit_run.c index a7d4ba8b..aa99c0e0 100644 --- a/test/wcc/840_zeroinit_run.c +++ b/test/wcc/840_zeroinit_run.c @@ -38,7 +38,6 @@ */ #include #include -#include #include #include #include @@ -199,36 +198,31 @@ main(void) int n = 0, fail = 0; for (int i = 0; rows[i].src; i++, n++) { - char src[64]; - snprintf(src, sizeof src, "/tmp/wwzi_%d_%d.ww", getpid(), i); - FILE *f = fopen(src, "wb"); - if (f == NULL) { fail++; continue; } - fputs(rows[i].src, f); - fclose(f); - - /* (a) cstage build + run in a scratch dir. */ char tmpdir[64]; snprintf(tmpdir, sizeof tmpdir, "/tmp/wwzi_%d_d_%d", getpid(), i); mkdir(tmpdir, 0755); + char src[128], outbin[128], cs_s[128], ws_s[128], rmcmd[160]; + snprintf(src, sizeof src, "%s/wwzi_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/wwzi_%d_%d", tmpdir, getpid(), i); + snprintf(cs_s, sizeof cs_s, "%s/wwzi_%d_%d_cs.s", tmpdir, getpid(), i); + snprintf(ws_s, sizeof ws_s, "%s/wwzi_%d_%d_ww.s", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); + + FILE *f = fopen(src, "wb"); + if (f == NULL) { fail++; runwait(rmcmd); continue; } + fputs(rows[i].src, f); + fclose(f); + + /* (a) cstage build + run. */ char cmd[2048]; - snprintf(cmd, sizeof cmd, "cd %s && %s/ww build %s", - tmpdir, bin, src); + snprintf(cmd, sizeof cmd, "%s/ww build -o %s %s", bin, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: cstage build failed\n", rows[i].label); - fail++; - unlink(src); rmdir(tmpdir); - continue; + fail++; runwait(rmcmd); continue; } - char outbin[128]; - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; - int got = runwait(outbin); if (got != rows[i].want_exit) { fprintf(stderr, "row[%s]: cstage exit %d, want %d " @@ -236,30 +230,25 @@ main(void) rows[i].label, got, rows[i].want_exit); fail++; } - unlink(outbin); rmdir(tmpdir); /* (b) cs==ww byte-id gate. */ - char cs_s[64], ws_s[64]; - snprintf(cs_s, sizeof cs_s, "/tmp/wwzi_%d_%d_cs.s", getpid(), i); - snprintf(ws_s, sizeof ws_s, "/tmp/wwzi_%d_%d_ww.s", getpid(), i); - snprintf(cmd, sizeof cmd, "%s -o %s %s 2>/dev/null", w6c, cs_s, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: w6c failed\n", rows[i].label); - fail++; unlink(src); continue; + fail++; runwait(rmcmd); continue; } snprintf(cmd, sizeof cmd, "%s -o %s %s 2>/dev/null", w6c_ww, ws_s, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: w6c_ww failed\n", rows[i].label); - fail++; unlink(src); unlink(cs_s); continue; + fail++; runwait(rmcmd); continue; } if (slurp_eq(cs_s, ws_s) != 0) { fprintf(stderr, "row[%s]: cstage/wwstage .s DIFFER " "(rule-10 byte-id violation)\n", rows[i].label); fail++; } - unlink(src); unlink(cs_s); unlink(ws_s); + runwait(rmcmd); } if (fail) { diff --git a/test/wcc/841_match_global_field.c b/test/wcc/841_match_global_field.c index b24e6d61..d800f166 100644 --- a/test/wcc/841_match_global_field.c +++ b/test/wcc/841_match_global_field.c @@ -32,7 +32,6 @@ */ #include #include -#include #include #include #include @@ -117,34 +116,29 @@ static const struct row rows[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/wcmgf_%d_%d.ww", getpid(), i); + char tmpdir[64], src[128], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/wcmgf_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/wcmgf_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/wcmgf_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s", driver, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return got; } diff --git a/test/wcc/842_dup_main_reject.c b/test/wcc/842_dup_main_reject.c index ec2dda27..7073d0b7 100644 --- a/test/wcc/842_dup_main_reject.c +++ b/test/wcc/842_dup_main_reject.c @@ -84,32 +84,25 @@ static int build_should_fail(const char *driver, const char *label, const char *src, const char *diag, int i) { - char s[64], tmpdir[64], cmd[1024], errf[64]; - snprintf(s, sizeof s, "/tmp/dupmain_%d_%d.ww", getpid(), i); + char s[128], tmpdir[64], outbin[128], errf[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/dupmain_%d_d_%d", getpid(), i); - snprintf(errf, sizeof errf, "/tmp/dupmain_%d_e_%d.txt", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(s, sizeof s, "%s/dupmain_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/out", tmpdir); + snprintf(errf, sizeof errf, "%s/err.txt", tmpdir); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(s, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s >/dev/null 2>%s", - tmpdir, driver, s, errf); + snprintf(cmd, sizeof cmd, "%s build -o %s %s >/dev/null 2>%s", + driver, outbin, s, errf); int rc = runwait(cmd); int hasmsg = filehas(errf, diag); - const char *base = strrchr(s, '/'); - base = base ? base + 1 : s; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; - unlink(s); - unlink(errf); - unlink(outbin); - rmdir(tmpdir); + runwait(rmcmd); if (rc == 0) { fprintf(stderr, "dup_main[%s][%s]: built ok, expected a loud reject\n", @@ -130,32 +123,28 @@ build_should_fail(const char *driver, const char *label, const char *src, static int run_build(const char *driver, const char *label, const char *src, int i) { - char s[64], tmpdir[64], cmd[1024]; - snprintf(s, sizeof s, "/tmp/dupmain_ok_%d_%d.ww", getpid(), i); + char s[128], tmpdir[64], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/dupmain_ok_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(s, sizeof s, "%s/dupmain_ok_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/dupmain_ok_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(s, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null", - tmpdir, driver, s); + snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>/dev/null", + driver, outbin, s); if (runwait(cmd) != 0) { fprintf(stderr, "dup_main[%s][%s]: build failed (corpus " "regression — a lone main must compile)\n", driver, label); - unlink(s); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(s, '/'); - base = base ? base + 1 : s; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(s); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return got; } diff --git a/test/wcc/843_tagged_staticinit.c b/test/wcc/843_tagged_staticinit.c index e81bf0e7..0a580cb2 100644 --- a/test/wcc/843_tagged_staticinit.c +++ b/test/wcc/843_tagged_staticinit.c @@ -174,31 +174,26 @@ static const struct row rows[] = { static int run_build(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/tsi_%d_%d.ww", getpid(), i); + char src[128], tmpdir[64], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/tsi_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/tsi_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/tsi_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -2; + if (!f) { runwait(rmcmd); return -2; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>/dev/null", + driver, outbin, src); int brc = runwait(cmd); - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; - int got = -1; if (brc == 0) got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return brc == 0 ? got : -1; } @@ -207,19 +202,21 @@ run_build(const char *driver, const struct row *r, int i) static int build_should_reject(const char *driver, const struct row *r, int i) { - char s[64], tmpdir[64], errf[80], cmd[1280]; - snprintf(s, sizeof s, "/tmp/tsn_%d_%d.ww", getpid(), i); + char s[96], tmpdir[64], outbin[128], errf[112], rmcmd[160], cmd[1280]; snprintf(tmpdir, sizeof tmpdir, "/tmp/tsn_%d_d_%d", getpid(), i); - snprintf(errf, sizeof errf, "/tmp/tsn_%d_%d.err", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(s, sizeof s, "%s/tsn_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/tsn_%d_%d", tmpdir, getpid(), i); + snprintf(errf, sizeof errf, "%s/tsn_%d_%d.err", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(s, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>%s", - tmpdir, driver, s, errf); + snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>%s", + driver, outbin, s, errf); int rc = runwait(cmd); int have_diag = 0; @@ -232,15 +229,7 @@ build_should_reject(const char *driver, const struct row *r, int i) have_diag = (strstr(buf, r->diag) != NULL); } - unlink(s); unlink(errf); - const char *base = strrchr(s, '/'); - base = base ? base + 1 : s; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; - unlink(outbin); - rmdir(tmpdir); + runwait(rmcmd); /* build must NOT succeed AND the shared diagnostic must appear. */ return (rc != 0 && have_diag) ? 0 : -1; diff --git a/test/wcc/844_size_untyped_int.c b/test/wcc/844_size_untyped_int.c index ebb5012c..14b5071e 100644 --- a/test/wcc/844_size_untyped_int.c +++ b/test/wcc/844_size_untyped_int.c @@ -44,7 +44,6 @@ */ #include #include -#include #include #include #include @@ -104,34 +103,30 @@ static const char *bid_src = static int run_driver(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/szui_%d_%d.ww", getpid(), i); + char tmpdir[64], src[128], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/szui_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/szui_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/szui_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>/dev/null", + driver, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return got; } diff --git a/test/wcc/845_tuple_trailing_comma_reject.c b/test/wcc/845_tuple_trailing_comma_reject.c index 632be4bf..a0353623 100644 --- a/test/wcc/845_tuple_trailing_comma_reject.c +++ b/test/wcc/845_tuple_trailing_comma_reject.c @@ -73,24 +73,25 @@ static int build_should_fail(const char *driver, const char *label, const char *src, const char *diag, int i) { - char s[64], tmpdir[64], cmd[1024], bin[128], errf[64]; - snprintf(s, sizeof s, "/tmp/tuptc_%d_%d.ww", getpid(), i); + char s[128], tmpdir[64], cmd[1024], bin[128], errf[128], rmcmd[160]; snprintf(tmpdir, sizeof tmpdir, "/tmp/tuptc_%d_d_%d", getpid(), i); - snprintf(errf, sizeof errf, "/tmp/tuptc_%d_e_%d.txt", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(s, sizeof s, "%s/tuptc_%d_%d.ww", tmpdir, getpid(), i); + snprintf(errf, sizeof errf, "%s/tuptc_%d_e_%d.txt", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(s, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s >/dev/null 2>%s", - tmpdir, driver, s, errf); + /* explicit -o INSIDE tmpdir so the binary AND its .sepwork land + * under tmpdir and die with rm -rf; a reject leaks the mkdir'd scratch + * too, so clean on every exit path. */ + outbin(bin, sizeof bin, tmpdir, s); + snprintf(cmd, sizeof cmd, "%s build -o %s %s >/dev/null 2>%s", + driver, bin, s, errf); int rc = runwait(cmd); int hasmsg = filehas(errf, diag); - outbin(bin, sizeof bin, tmpdir, s); - unlink(s); - unlink(bin); - unlink(errf); - rmdir(tmpdir); + runwait(rmcmd); if (rc == 0) { fprintf(stderr, "tuptc[%s][%s]: built ok, expected a reject\n", driver, label); @@ -109,25 +110,26 @@ build_should_fail(const char *driver, const char *label, const char *src, static int run_build(const char *driver, const char *label, const char *src, int i) { - char s[64], tmpdir[64], cmd[1024], bin[128]; - snprintf(s, sizeof s, "/tmp/tuptc_ok_%d_%d.ww", getpid(), i); + char s[128], tmpdir[64], cmd[1024], bin[128], rmcmd[160]; snprintf(tmpdir, sizeof tmpdir, "/tmp/tuptc_ok_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(s, sizeof s, "%s/tuptc_ok_%d_%d.ww", tmpdir, getpid(), i); + snprintf(bin, sizeof bin, "%s/tuptc_ok_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(s, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null", - tmpdir, driver, s); + snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>/dev/null", + driver, bin, s); if (runwait(cmd) != 0) { fprintf(stderr, "tuptc[%s][%s]: build failed (a valid tuple " "must compile)\n", driver, label); - unlink(s); rmdir(tmpdir); + runwait(rmcmd); return -1; } - outbin(bin, sizeof bin, tmpdir, s); int got = runwait(bin); - unlink(s); unlink(bin); rmdir(tmpdir); + runwait(rmcmd); return got; } diff --git a/test/wcc/846_voidless_return_reject.c b/test/wcc/846_voidless_return_reject.c index 25cb6657..d4d23290 100644 --- a/test/wcc/846_voidless_return_reject.c +++ b/test/wcc/846_voidless_return_reject.c @@ -34,16 +34,6 @@ runwait(const char *cmd) return -1; } -static void -outbin(char *dst, size_t n, const char *tmpdir, const char *src) -{ - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - snprintf(dst, n, "%s/%s", tmpdir, base); - char *dot = strrchr(dst, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; -} - static int filehas(const char *path, const char *needle) { @@ -65,24 +55,22 @@ static int build_should_fail(const char *driver, const char *label, const char *src, const char *diag, int i) { - char s[64], tmpdir[64], cmd[1024], bin[128], errf[64]; - snprintf(s, sizeof s, "/tmp/vret_%d_%d.ww", getpid(), i); + char s[128], tmpdir[64], cmd[1024], bin[128], errf[128], rmcmd[160]; snprintf(tmpdir, sizeof tmpdir, "/tmp/vret_%d_d_%d", getpid(), i); - snprintf(errf, sizeof errf, "/tmp/vret_%d_e_%d.txt", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(s, sizeof s, "%s/vret_%d_%d.ww", tmpdir, getpid(), i); + snprintf(bin, sizeof bin, "%s/vret_%d_%d", tmpdir, getpid(), i); + snprintf(errf, sizeof errf, "%s/vret_%d_e_%d.txt", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(s, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s >/dev/null 2>%s", - tmpdir, driver, s, errf); + snprintf(cmd, sizeof cmd, "%s build -o %s %s >/dev/null 2>%s", + driver, bin, s, errf); int rc = runwait(cmd); int hasmsg = filehas(errf, diag); - outbin(bin, sizeof bin, tmpdir, s); - unlink(s); - unlink(bin); - unlink(errf); - rmdir(tmpdir); + runwait(rmcmd); if (rc == 0) { fprintf(stderr, "vret[%s][%s]: built ok, expected a reject\n", driver, label); @@ -100,25 +88,26 @@ build_should_fail(const char *driver, const char *label, const char *src, static int run_build(const char *driver, const char *label, const char *src, int i) { - char s[64], tmpdir[64], cmd[1024], bin[128]; - snprintf(s, sizeof s, "/tmp/vret_ok_%d_%d.ww", getpid(), i); + char s[128], tmpdir[64], cmd[1024], bin[128], rmcmd[160]; snprintf(tmpdir, sizeof tmpdir, "/tmp/vret_ok_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(s, sizeof s, "%s/vret_ok_%d_%d.ww", tmpdir, getpid(), i); + snprintf(bin, sizeof bin, "%s/vret_ok_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(s, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null", - tmpdir, driver, s); + snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>/dev/null", + driver, bin, s); if (runwait(cmd) != 0) { fprintf(stderr, "vret[%s][%s]: build failed (a valid return " "must compile)\n", driver, label); - unlink(s); rmdir(tmpdir); + runwait(rmcmd); return -1; } - outbin(bin, sizeof bin, tmpdir, s); int got = runwait(bin); - unlink(s); unlink(bin); rmdir(tmpdir); + runwait(rmcmd); return got; } diff --git a/test/wcc/847_const_reassign_reject.c b/test/wcc/847_const_reassign_reject.c index 87378049..be462875 100644 --- a/test/wcc/847_const_reassign_reject.c +++ b/test/wcc/847_const_reassign_reject.c @@ -66,24 +66,22 @@ static int build_should_fail(const char *driver, const char *label, const char *src, const char *diag, int i) { - char s[64], tmpdir[64], cmd[1024], bin[128], errf[64]; - snprintf(s, sizeof s, "/tmp/creas_%d_%d.ww", getpid(), i); + char s[128], tmpdir[64], cmd[1024], bin[128], errf[128], rmcmd[160]; snprintf(tmpdir, sizeof tmpdir, "/tmp/creas_%d_d_%d", getpid(), i); - snprintf(errf, sizeof errf, "/tmp/creas_%d_e_%d.txt", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(s, sizeof s, "%s/creas_%d_%d.ww", tmpdir, getpid(), i); + snprintf(errf, sizeof errf, "%s/creas_%d_e_%d.txt", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(s, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s >/dev/null 2>%s", - tmpdir, driver, s, errf); + outbin(bin, sizeof bin, tmpdir, s); + snprintf(cmd, sizeof cmd, "%s build -o %s %s >/dev/null 2>%s", + driver, bin, s, errf); int rc = runwait(cmd); int hasmsg = filehas(errf, diag); - outbin(bin, sizeof bin, tmpdir, s); - unlink(s); - unlink(bin); - unlink(errf); - rmdir(tmpdir); + runwait(rmcmd); if (rc == 0) { fprintf(stderr, "creas[%s][%s]: built ok, expected a reject\n", driver, label); @@ -101,25 +99,26 @@ build_should_fail(const char *driver, const char *label, const char *src, static int run_build(const char *driver, const char *label, const char *src, int i) { - char s[64], tmpdir[64], cmd[1024], bin[128]; - snprintf(s, sizeof s, "/tmp/creas_ok_%d_%d.ww", getpid(), i); + char tmpdir[64], s[128], bin[128], cmd[1024], rmcmd[160]; snprintf(tmpdir, sizeof tmpdir, "/tmp/creas_ok_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(s, sizeof s, "%s/creas_ok_%d_%d.ww", tmpdir, getpid(), i); + snprintf(bin, sizeof bin, "%s/creas_ok_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(s, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null", - tmpdir, driver, s); + snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>/dev/null", + driver, bin, s); if (runwait(cmd) != 0) { fprintf(stderr, "creas[%s][%s]: build failed (a mutable let " "must compile)\n", driver, label); - unlink(s); rmdir(tmpdir); + runwait(rmcmd); return -1; } - outbin(bin, sizeof bin, tmpdir, s); int got = runwait(bin); - unlink(s); unlink(bin); rmdir(tmpdir); + runwait(rmcmd); return got; } diff --git a/test/wcc/849_dupfield_reject.c b/test/wcc/849_dupfield_reject.c index 137ee26c..6a676cbb 100644 --- a/test/wcc/849_dupfield_reject.c +++ b/test/wcc/849_dupfield_reject.c @@ -67,24 +67,22 @@ static int build_should_fail(const char *driver, const char *label, const char *src, const char *diag, int i) { - char s[64], tmpdir[64], cmd[1024], bin[128], errf[64]; - snprintf(s, sizeof s, "/tmp/dupf_%d_%d.ww", getpid(), i); + char s[128], tmpdir[64], cmd[1024], bin[128], errf[128], rmcmd[160]; snprintf(tmpdir, sizeof tmpdir, "/tmp/dupf_%d_d_%d", getpid(), i); - snprintf(errf, sizeof errf, "/tmp/dupf_%d_e_%d.txt", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(s, sizeof s, "%s/dupf_%d_%d.ww", tmpdir, getpid(), i); + snprintf(errf, sizeof errf, "%s/dupf_%d_e_%d.txt", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(s, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s >/dev/null 2>%s", - tmpdir, driver, s, errf); + outbin(bin, sizeof bin, tmpdir, s); + snprintf(cmd, sizeof cmd, "%s build -o %s %s >/dev/null 2>%s", + driver, bin, s, errf); int rc = runwait(cmd); int hasmsg = filehas(errf, diag); - outbin(bin, sizeof bin, tmpdir, s); - unlink(s); - unlink(bin); - unlink(errf); - rmdir(tmpdir); + runwait(rmcmd); if (rc == 0) { fprintf(stderr, "dupf[%s][%s]: built ok, expected a reject\n", driver, label); @@ -102,25 +100,26 @@ build_should_fail(const char *driver, const char *label, const char *src, static int run_build(const char *driver, const char *label, const char *src, int i) { - char s[64], tmpdir[64], cmd[1024], bin[128]; - snprintf(s, sizeof s, "/tmp/dupf_ok_%d_%d.ww", getpid(), i); + char s[128], tmpdir[64], cmd[1024], bin[128], rmcmd[160]; snprintf(tmpdir, sizeof tmpdir, "/tmp/dupf_ok_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(s, sizeof s, "%s/dupf_ok_%d_%d.ww", tmpdir, getpid(), i); + snprintf(bin, sizeof bin, "%s/dupf_ok_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(s, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null", - tmpdir, driver, s); + snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>/dev/null", + driver, bin, s); if (runwait(cmd) != 0) { fprintf(stderr, "dupf[%s][%s]: build failed (distinct fields " "must compile)\n", driver, label); - unlink(s); rmdir(tmpdir); + runwait(rmcmd); return -1; } - outbin(bin, sizeof bin, tmpdir, s); int got = runwait(bin); - unlink(s); unlink(bin); rmdir(tmpdir); + runwait(rmcmd); return got; } diff --git a/test/wcc/850_enum_reject.c b/test/wcc/850_enum_reject.c index e094f305..a1262c35 100644 --- a/test/wcc/850_enum_reject.c +++ b/test/wcc/850_enum_reject.c @@ -40,16 +40,6 @@ runwait(const char *cmd) return -1; } -static void -outbin(char *dst, size_t n, const char *tmpdir, const char *src) -{ - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - snprintf(dst, n, "%s/%s", tmpdir, base); - char *dot = strrchr(dst, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; -} - static int filehas(const char *path, const char *needle) { @@ -69,24 +59,22 @@ static int build_should_fail(const char *driver, const char *label, const char *src, const char *diag, int i) { - char s[64], tmpdir[64], cmd[1024], bin[128], errf[64]; - snprintf(s, sizeof s, "/tmp/enr_%d_%d.ww", getpid(), i); + char s[128], tmpdir[64], cmd[1024], bin[128], errf[128], rmcmd[160]; snprintf(tmpdir, sizeof tmpdir, "/tmp/enr_%d_d_%d", getpid(), i); - snprintf(errf, sizeof errf, "/tmp/enr_%d_e_%d.txt", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(s, sizeof s, "%s/enr_%d_%d.ww", tmpdir, getpid(), i); + snprintf(bin, sizeof bin, "%s/enr_%d_%d", tmpdir, getpid(), i); + snprintf(errf, sizeof errf, "%s/enr_%d_e_%d.txt", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(s, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s >/dev/null 2>%s", - tmpdir, driver, s, errf); + snprintf(cmd, sizeof cmd, "%s build -o %s %s >/dev/null 2>%s", + driver, bin, s, errf); int rc = runwait(cmd); int hasmsg = filehas(errf, diag); - outbin(bin, sizeof bin, tmpdir, s); - unlink(s); - unlink(bin); - unlink(errf); - rmdir(tmpdir); + runwait(rmcmd); if (rc == 0) { fprintf(stderr, "enr[%s][%s]: built ok, expected a reject\n", driver, label); @@ -104,25 +92,26 @@ build_should_fail(const char *driver, const char *label, const char *src, static int run_build(const char *driver, const char *label, const char *src, int i) { - char s[64], tmpdir[64], cmd[1024], bin[128]; - snprintf(s, sizeof s, "/tmp/enr_ok_%d_%d.ww", getpid(), i); + char s[128], tmpdir[64], cmd[1024], bin[128], rmcmd[160]; snprintf(tmpdir, sizeof tmpdir, "/tmp/enr_ok_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(s, sizeof s, "%s/enr_ok_%d_%d.ww", tmpdir, getpid(), i); + snprintf(bin, sizeof bin, "%s/enr_ok_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(s, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null", - tmpdir, driver, s); + snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>/dev/null", + driver, bin, s); if (runwait(cmd) != 0) { fprintf(stderr, "enr[%s][%s]: build failed (valid enum must " "compile)\n", driver, label); - unlink(s); rmdir(tmpdir); + runwait(rmcmd); return -1; } - outbin(bin, sizeof bin, tmpdir, s); int got = runwait(bin); - unlink(s); unlink(bin); rmdir(tmpdir); + runwait(rmcmd); return got; } diff --git a/test/wcc/851_index_int_reject.c b/test/wcc/851_index_int_reject.c index 3abafeb1..b27c527e 100644 --- a/test/wcc/851_index_int_reject.c +++ b/test/wcc/851_index_int_reject.c @@ -78,24 +78,22 @@ static int build_should_fail(const char *driver, const char *label, const char *src, const char *diag, int i) { - char s[64], tmpdir[64], cmd[1024], bin[128], errf[64]; - snprintf(s, sizeof s, "/tmp/idxr_%d_%d.ww", getpid(), i); + char s[128], tmpdir[64], cmd[1024], bin[128], errf[128], rmcmd[160]; snprintf(tmpdir, sizeof tmpdir, "/tmp/idxr_%d_d_%d", getpid(), i); - snprintf(errf, sizeof errf, "/tmp/idxr_%d_e_%d.txt", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(s, sizeof s, "%s/idxr_%d_%d.ww", tmpdir, getpid(), i); + snprintf(errf, sizeof errf, "%s/idxr_%d_e_%d.txt", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); + outbin(bin, sizeof bin, tmpdir, s); FILE *f = fopen(s, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s >/dev/null 2>%s", - tmpdir, driver, s, errf); + snprintf(cmd, sizeof cmd, "%s build -o %s %s >/dev/null 2>%s", + driver, bin, s, errf); int rc = runwait(cmd); int hasmsg = filehas(errf, diag); - outbin(bin, sizeof bin, tmpdir, s); - unlink(s); - unlink(bin); - unlink(errf); - rmdir(tmpdir); + runwait(rmcmd); if (rc == 0) { fprintf(stderr, "idxr[%s][%s]: built ok, expected a reject\n", driver, label); @@ -113,25 +111,26 @@ build_should_fail(const char *driver, const char *label, const char *src, static int run_build(const char *driver, const char *label, const char *src, int i) { - char s[64], tmpdir[64], cmd[1024], bin[128]; - snprintf(s, sizeof s, "/tmp/idxr_ok_%d_%d.ww", getpid(), i); + char s[128], tmpdir[64], cmd[1024], bin[128], rmcmd[160]; snprintf(tmpdir, sizeof tmpdir, "/tmp/idxr_ok_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(s, sizeof s, "%s/idxr_ok_%d_%d.ww", tmpdir, getpid(), i); + snprintf(bin, sizeof bin, "%s/idxr_ok_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(s, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null", - tmpdir, driver, s); + snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>/dev/null", + driver, bin, s); if (runwait(cmd) != 0) { fprintf(stderr, "idxr[%s][%s]: build failed (integer index " "must compile)\n", driver, label); - unlink(s); rmdir(tmpdir); + runwait(rmcmd); return -1; } - outbin(bin, sizeof bin, tmpdir, s); int got = runwait(bin); - unlink(s); unlink(bin); rmdir(tmpdir); + runwait(rmcmd); return got; } diff --git a/test/wcc/852_variadic_body_reject.c b/test/wcc/852_variadic_body_reject.c index ee47dc66..3736682d 100644 --- a/test/wcc/852_variadic_body_reject.c +++ b/test/wcc/852_variadic_body_reject.c @@ -79,24 +79,22 @@ static int build_should_fail(const char *driver, const char *label, const char *src, int i) { - char s[64], tmpdir[64], cmd[1024], bin[128], errf[64]; - snprintf(s, sizeof s, "/tmp/vbr_%d_%d.ww", getpid(), i); + char s[128], tmpdir[64], cmd[1024], bin[128], errf[128], rmcmd[160]; snprintf(tmpdir, sizeof tmpdir, "/tmp/vbr_%d_d_%d", getpid(), i); - snprintf(errf, sizeof errf, "/tmp/vbr_%d_e_%d.txt", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(s, sizeof s, "%s/vbr_%d_%d.ww", tmpdir, getpid(), i); + snprintf(errf, sizeof errf, "%s/vbr_%d_e_%d.txt", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(s, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s >/dev/null 2>%s", - tmpdir, driver, s, errf); + outbin(bin, sizeof bin, tmpdir, s); + snprintf(cmd, sizeof cmd, "%s build -o %s %s >/dev/null 2>%s", + driver, bin, s, errf); int rc = runwait(cmd); int hasmsg = filehas(errf, rejmsg); - outbin(bin, sizeof bin, tmpdir, s); - unlink(s); - unlink(bin); - unlink(errf); - rmdir(tmpdir); + runwait(rmcmd); if (rc == 0) { fprintf(stderr, "vbr[%s][%s]: built ok, expected a reject\n", driver, label); @@ -113,25 +111,26 @@ build_should_fail(const char *driver, const char *label, const char *src, static int run_build(const char *driver, const char *label, const char *src, int i) { - char s[64], tmpdir[64], cmd[1024], bin[128]; - snprintf(s, sizeof s, "/tmp/vbr_ok_%d_%d.ww", getpid(), i); + char s[128], tmpdir[64], cmd[1024], bin[128], rmcmd[160]; snprintf(tmpdir, sizeof tmpdir, "/tmp/vbr_ok_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(s, sizeof s, "%s/vbr_ok_%d_%d.ww", tmpdir, getpid(), i); + snprintf(bin, sizeof bin, "%s/vbr_ok_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(s, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null", - tmpdir, driver, s); + snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>/dev/null", + driver, bin, s); if (runwait(cmd) != 0) { fprintf(stderr, "vbr[%s][%s]: build failed (valid variadic " "must compile)\n", driver, label); - unlink(s); rmdir(tmpdir); + runwait(rmcmd); return -1; } - outbin(bin, sizeof bin, tmpdir, s); int got = runwait(bin); - unlink(s); unlink(bin); rmdir(tmpdir); + runwait(rmcmd); return got; } diff --git a/test/wcc/905_tupparam_run.c b/test/wcc/905_tupparam_run.c index 78255c85..dfc7f4d9 100644 --- a/test/wcc/905_tupparam_run.c +++ b/test/wcc/905_tupparam_run.c @@ -40,7 +40,6 @@ */ #include #include -#include #include #include #include @@ -205,10 +204,17 @@ main(void) int n = 0, fail = 0; for (int i = 0; rows[i].src; i++, n++) { - char src[64]; - snprintf(src, sizeof src, "/tmp/wwtupp_%d_%d.ww", getpid(), i); + char tmpdir[64], src[128], outbin[128], rmcmd[160]; + snprintf(tmpdir, sizeof tmpdir, "/tmp/wwtupp_%d_d_%d", + getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/wwtupp_%d_%d.ww", + tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/wwtupp_%d_%d", + tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (f == NULL) { fail++; continue; } + if (f == NULL) { fail++; runwait(rmcmd); continue; } fputs(rows[i].src, f); fclose(f); @@ -219,13 +225,9 @@ main(void) * (b) w6c AND w6c_ww each return non-zero. No .s is produced, so * the byte-id cmp is skipped. */ if (rows[i].want_compile_fail) { - char ldir[64]; - snprintf(ldir, sizeof ldir, "/tmp/wwtupp_%d_l_%d", - getpid(), i); - mkdir(ldir, 0755); snprintf(cmd, sizeof cmd, - "cd %s && %s/ww build %s >/dev/null 2>&1", - ldir, bin, src); + "%s/ww build -o %s %s >/dev/null 2>&1", + bin, outbin, src); if (runwait(cmd) == 0) { fprintf(stderr, "row[%s]: cstage build SUCCEEDED, " "want loud-stop (arg-reg overflow)\n", @@ -246,60 +248,47 @@ main(void) "loud-stop\n", rows[i].label); fail++; } - unlink(src); rmdir(ldir); + runwait(rmcmd); continue; } /* (a) cstage build + run in a scratch dir. */ - char tmpdir[64]; - snprintf(tmpdir, sizeof tmpdir, "/tmp/wwtupp_%d_d_%d", - getpid(), i); - mkdir(tmpdir, 0755); - - snprintf(cmd, sizeof cmd, "cd %s && %s/ww build %s", - tmpdir, bin, src); + snprintf(cmd, sizeof cmd, "%s/ww build -o %s %s", + bin, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: cstage build failed\n", rows[i].label); fail++; - unlink(src); rmdir(tmpdir); + runwait(rmcmd); continue; } - char outbin[128]; - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; - int got = runwait(outbin); if (got != rows[i].want_exit) { fprintf(stderr, "row[%s]: cstage exit %d, want %d\n", rows[i].label, got, rows[i].want_exit); fail++; } - unlink(outbin); rmdir(tmpdir); /* (b) cs==ww byte-id gate: emit .s from both stages, cmp. */ - char cs_s[64], ws_s[64]; - snprintf(cs_s, sizeof cs_s, "/tmp/wwtupp_%d_%d_cs.s", - getpid(), i); - snprintf(ws_s, sizeof ws_s, "/tmp/wwtupp_%d_%d_ww.s", - getpid(), i); + char cs_s[160], ws_s[160]; + snprintf(cs_s, sizeof cs_s, "%s/wwtupp_%d_%d_cs.s", + tmpdir, getpid(), i); + snprintf(ws_s, sizeof ws_s, "%s/wwtupp_%d_%d_ww.s", + tmpdir, getpid(), i); snprintf(cmd, sizeof cmd, "%s -o %s %s 2>/dev/null", w6c, cs_s, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: w6c failed\n", rows[i].label); - fail++; unlink(src); continue; + fail++; runwait(rmcmd); continue; } snprintf(cmd, sizeof cmd, "%s -o %s %s 2>/dev/null", w6c_ww, ws_s, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: w6c_ww failed\n", rows[i].label); - fail++; unlink(src); unlink(cs_s); continue; + fail++; runwait(rmcmd); continue; } if (slurp_eq(cs_s, ws_s) != 0) { fprintf(stderr, @@ -307,7 +296,7 @@ main(void) "byte-id violation)\n", rows[i].label); fail++; } - unlink(src); unlink(cs_s); unlink(ws_s); + runwait(rmcmd); } if (fail) { diff --git a/test/wcc/907_f32arg_run.c b/test/wcc/907_f32arg_run.c index 4e6cc69e..2c6545a7 100644 --- a/test/wcc/907_f32arg_run.c +++ b/test/wcc/907_f32arg_run.c @@ -31,7 +31,6 @@ */ #include #include -#include #include #include #include @@ -152,64 +151,61 @@ main(void) int n = 0, fail = 0; for (int i = 0; rows[i].src; i++, n++) { - char src[64]; - snprintf(src, sizeof src, "/tmp/wwf32a_%d_%d.ww", getpid(), i); - FILE *f = fopen(src, "wb"); - if (f == NULL) { fail++; continue; } - fputs(rows[i].src, f); - fclose(f); - - /* (a) cstage build + run. */ char tmpdir[64]; snprintf(tmpdir, sizeof tmpdir, "/tmp/wwf32a_%d_d_%d", getpid(), i); mkdir(tmpdir, 0755); + char src[128], outbin[128], rmcmd[160]; + snprintf(src, sizeof src, "%s/wwf32a_%d_%d.ww", + tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/wwf32a_%d_%d", + tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); + + FILE *f = fopen(src, "wb"); + if (f == NULL) { fail++; runwait(rmcmd); continue; } + fputs(rows[i].src, f); + fclose(f); + + /* (a) cstage build + run. */ char cmd[2048]; - snprintf(cmd, sizeof cmd, "cd %s && %s/ww build %s", - tmpdir, bin, src); + snprintf(cmd, sizeof cmd, "%s/ww build -o %s %s", + bin, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: cstage build failed\n", rows[i].label); fail++; - unlink(src); rmdir(tmpdir); + runwait(rmcmd); continue; } - char outbin[128]; - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; - int got = runwait(outbin); if (got != rows[i].want_exit) { fprintf(stderr, "row[%s]: cstage exit %d, want %d\n", rows[i].label, got, rows[i].want_exit); fail++; } - unlink(outbin); rmdir(tmpdir); /* (b) cs==ww byte-id gate: emit .s from both stages, cmp. */ - char cs_s[64], ws_s[64]; - snprintf(cs_s, sizeof cs_s, "/tmp/wwf32a_%d_%d_cs.s", - getpid(), i); - snprintf(ws_s, sizeof ws_s, "/tmp/wwf32a_%d_%d_ww.s", - getpid(), i); + char cs_s[128], ws_s[128]; + snprintf(cs_s, sizeof cs_s, "%s/wwf32a_%d_%d_cs.s", + tmpdir, getpid(), i); + snprintf(ws_s, sizeof ws_s, "%s/wwf32a_%d_%d_ww.s", + tmpdir, getpid(), i); snprintf(cmd, sizeof cmd, "%s -o %s %s 2>/dev/null", w6c, cs_s, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: w6c failed\n", rows[i].label); - fail++; unlink(src); continue; + fail++; runwait(rmcmd); continue; } snprintf(cmd, sizeof cmd, "%s -o %s %s 2>/dev/null", w6c_ww, ws_s, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: w6c_ww failed\n", rows[i].label); - fail++; unlink(src); unlink(cs_s); continue; + fail++; runwait(rmcmd); continue; } if (slurp_eq(cs_s, ws_s) != 0) { fprintf(stderr, @@ -217,7 +213,7 @@ main(void) "byte-id violation)\n", rows[i].label); fail++; } - unlink(src); unlink(cs_s); unlink(ws_s); + runwait(rmcmd); } if (fail) { diff --git a/test/wcc/911_continue_run.c b/test/wcc/911_continue_run.c index b26d6217..e25dedad 100644 --- a/test/wcc/911_continue_run.c +++ b/test/wcc/911_continue_run.c @@ -27,7 +27,6 @@ */ #include #include -#include #include #include #include @@ -145,38 +144,38 @@ main(void) int n = 0, fail = 0; for (int i = 0; rows[i].src; i++, n++) { - char src[64]; - snprintf(src, sizeof src, "/tmp/wwcont_%d_%d.ww", getpid(), i); - FILE *f = fopen(src, "wb"); - if (f == NULL) { fail++; continue; } - fputs(rows[i].src, f); - fclose(f); - char tmpdir[64]; snprintf(tmpdir, sizeof tmpdir, "/tmp/wwcont_%d_d_%d", getpid(), i); mkdir(tmpdir, 0755); + char rmcmd[128]; + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); + + char src[128]; + snprintf(src, sizeof src, "%s/wwcont_%d_%d.ww", + tmpdir, getpid(), i); + FILE *f = fopen(src, "wb"); + if (f == NULL) { runwait(rmcmd); fail++; continue; } + fputs(rows[i].src, f); + fclose(f); + + char outbin[128]; + snprintf(outbin, sizeof outbin, "%s/wwcont_%d_%d", + tmpdir, getpid(), i); /* Build with 5s timeout — pre-fix the buggy rows infinite- * looped; post-fix all rows must exit cleanly under it. */ char cmd[2048]; - snprintf(cmd, sizeof cmd, "cd %s && %s/ww build %s", - tmpdir, bin, src); + snprintf(cmd, sizeof cmd, "%s/ww build -o %s %s", + bin, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: cstage build failed\n", rows[i].label); fail++; - unlink(src); rmdir(tmpdir); + runwait(rmcmd); continue; } - char outbin[128]; - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; - /* timeout wrapper: pre-fix bug = infinite loop; want clean * exit. exit 124 = timeout/hang. */ char rcmd[256]; @@ -188,26 +187,25 @@ main(void) rows[i].label, got, rows[i].want_exit); fail++; } - unlink(outbin); rmdir(tmpdir); - char cs_s[64], ws_s[64]; - snprintf(cs_s, sizeof cs_s, "/tmp/wwcont_%d_%d_cs.s", - getpid(), i); - snprintf(ws_s, sizeof ws_s, "/tmp/wwcont_%d_%d_ww.s", - getpid(), i); + char cs_s[128], ws_s[128]; + snprintf(cs_s, sizeof cs_s, "%s/wwcont_%d_%d_cs.s", + tmpdir, getpid(), i); + snprintf(ws_s, sizeof ws_s, "%s/wwcont_%d_%d_ww.s", + tmpdir, getpid(), i); snprintf(cmd, sizeof cmd, "%s -o %s %s 2>/dev/null", w6c, cs_s, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: w6c failed\n", rows[i].label); - fail++; unlink(src); continue; + fail++; runwait(rmcmd); continue; } snprintf(cmd, sizeof cmd, "%s -o %s %s 2>/dev/null", w6c_ww, ws_s, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: w6c_ww failed\n", rows[i].label); - fail++; unlink(src); unlink(cs_s); continue; + fail++; runwait(rmcmd); continue; } if (slurp_eq(cs_s, ws_s) != 0) { fprintf(stderr, @@ -215,7 +213,7 @@ main(void) "byte-id violation)\n", rows[i].label); fail++; } - unlink(src); unlink(cs_s); unlink(ws_s); + runwait(rmcmd); } if (fail) { diff --git a/test/wcc/913_def_mangle_run.c b/test/wcc/913_def_mangle_run.c index 247a931b..e4d83d8f 100644 --- a/test/wcc/913_def_mangle_run.c +++ b/test/wcc/913_def_mangle_run.c @@ -43,7 +43,6 @@ */ #include #include -#include #include #include #include @@ -137,62 +136,57 @@ main(void) int n = 0, fail = 0; for (int i = 0; rows[i].src; i++, n++) { - char src[64]; - snprintf(src, sizeof src, "/tmp/wwdef_%d_%d.ww", getpid(), i); - FILE *f = fopen(src, "wb"); - if (f == NULL) { fail++; continue; } - fputs(rows[i].src, f); - fclose(f); - char tmpdir[64]; snprintf(tmpdir, sizeof tmpdir, "/tmp/wwdef_%d_d_%d", getpid(), i); mkdir(tmpdir, 0755); + /* #8: source, binary, .sepwork scratch and the byte-id .s + * dumps all live under tmpdir; rm -rf on every exit path. + * Symbol mangling is package/import-derived, not entry-path + * derived, so the in-tmpdir source keeps the cs==ww .s identical. */ + char src[128], outbin[128], cs_s[128], ws_s[128], rmcmd[160]; + snprintf(src, sizeof src, "%s/wwdef_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/wwdef_%d_%d", tmpdir, getpid(), i); + snprintf(cs_s, sizeof cs_s, "%s/cs.s", tmpdir); + snprintf(ws_s, sizeof ws_s, "%s/ww.s", tmpdir); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); + + FILE *f = fopen(src, "wb"); + if (f == NULL) { runwait(rmcmd); fail++; continue; } + fputs(rows[i].src, f); + fclose(f); + char cmd[2048]; - snprintf(cmd, sizeof cmd, "cd %s && %s/ww build %s", - tmpdir, bin, src); + snprintf(cmd, sizeof cmd, "%s/ww build -o %s %s", + bin, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: cstage build failed\n", rows[i].label); fail++; - unlink(src); rmdir(tmpdir); + runwait(rmcmd); continue; } - char outbin[128]; - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; - int got = runwait(outbin); if (got != rows[i].want_exit) { fprintf(stderr, "row[%s]: cstage exit %d, want %d\n", rows[i].label, got, rows[i].want_exit); fail++; } - unlink(outbin); rmdir(tmpdir); - - char cs_s[64], ws_s[64]; - snprintf(cs_s, sizeof cs_s, "/tmp/wwdef_%d_%d_cs.s", - getpid(), i); - snprintf(ws_s, sizeof ws_s, "/tmp/wwdef_%d_%d_ww.s", - getpid(), i); snprintf(cmd, sizeof cmd, "%s -o %s %s 2>/dev/null", w6c, cs_s, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: w6c failed\n", rows[i].label); - fail++; unlink(src); continue; + fail++; runwait(rmcmd); continue; } snprintf(cmd, sizeof cmd, "%s -o %s %s 2>/dev/null", w6c_ww, ws_s, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: w6c_ww failed\n", rows[i].label); - fail++; unlink(src); unlink(cs_s); continue; + fail++; runwait(rmcmd); continue; } if (slurp_eq(cs_s, ws_s) != 0) { fprintf(stderr, @@ -200,7 +194,7 @@ main(void) "byte-id violation)\n", rows[i].label); fail++; } - unlink(src); unlink(cs_s); unlink(ws_s); + runwait(rmcmd); } if (fail) { diff --git a/test/wcc/914_arr_u16_store_run.c b/test/wcc/914_arr_u16_store_run.c index 623a220f..02fa9638 100644 --- a/test/wcc/914_arr_u16_store_run.c +++ b/test/wcc/914_arr_u16_store_run.c @@ -38,7 +38,6 @@ */ #include #include -#include #include #include #include @@ -145,62 +144,59 @@ main(void) int n = 0, fail = 0; for (int i = 0; rows[i].src; i++, n++) { - char src[64]; - snprintf(src, sizeof src, "/tmp/wwau16_%d_%d.ww", getpid(), i); - FILE *f = fopen(src, "wb"); - if (f == NULL) { fail++; continue; } - fputs(rows[i].src, f); - fclose(f); - char tmpdir[64]; snprintf(tmpdir, sizeof tmpdir, "/tmp/wwau16_%d_d_%d", getpid(), i); mkdir(tmpdir, 0755); + char src[128], outbin[128], rmcmd[160]; + snprintf(src, sizeof src, "%s/wwau16_%d_%d.ww", + tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/wwau16_%d_%d", + tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); + + FILE *f = fopen(src, "wb"); + if (f == NULL) { runwait(rmcmd); fail++; continue; } + fputs(rows[i].src, f); + fclose(f); + char cmd[2048]; - snprintf(cmd, sizeof cmd, "cd %s && %s/ww build %s", - tmpdir, bin, src); + snprintf(cmd, sizeof cmd, "%s/ww build -o %s %s", + bin, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: cstage build failed\n", rows[i].label); fail++; - unlink(src); rmdir(tmpdir); + runwait(rmcmd); continue; } - char outbin[128]; - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; - int got = runwait(outbin); if (got != rows[i].want_exit) { fprintf(stderr, "row[%s]: cstage exit %d, want %d\n", rows[i].label, got, rows[i].want_exit); fail++; } - unlink(outbin); rmdir(tmpdir); - char cs_s[64], ws_s[64]; - snprintf(cs_s, sizeof cs_s, "/tmp/wwau16_%d_%d_cs.s", - getpid(), i); - snprintf(ws_s, sizeof ws_s, "/tmp/wwau16_%d_%d_ww.s", - getpid(), i); + char cs_s[128], ws_s[128]; + snprintf(cs_s, sizeof cs_s, "%s/wwau16_%d_%d_cs.s", + tmpdir, getpid(), i); + snprintf(ws_s, sizeof ws_s, "%s/wwau16_%d_%d_ww.s", + tmpdir, getpid(), i); snprintf(cmd, sizeof cmd, "%s -o %s %s 2>/dev/null", w6c, cs_s, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: w6c failed\n", rows[i].label); - fail++; unlink(src); continue; + fail++; runwait(rmcmd); continue; } snprintf(cmd, sizeof cmd, "%s -o %s %s 2>/dev/null", w6c_ww, ws_s, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: w6c_ww failed\n", rows[i].label); - fail++; unlink(src); unlink(cs_s); continue; + fail++; runwait(rmcmd); continue; } if (slurp_eq(cs_s, ws_s) != 0) { fprintf(stderr, @@ -208,7 +204,7 @@ main(void) "byte-id violation)\n", rows[i].label); fail++; } - unlink(src); unlink(cs_s); unlink(ws_s); + runwait(rmcmd); } if (fail) { diff --git a/test/wcc/916_arr_float_call_index_run.c b/test/wcc/916_arr_float_call_index_run.c index e2ce866f..83b8c0b3 100644 --- a/test/wcc/916_arr_float_call_index_run.c +++ b/test/wcc/916_arr_float_call_index_run.c @@ -44,7 +44,6 @@ */ #include #include -#include #include #include #include @@ -163,62 +162,59 @@ main(void) int n = 0, fail = 0; for (int i = 0; rows[i].src; i++, n++) { - char src[64]; - snprintf(src, sizeof src, "/tmp/wwafc_%d_%d.ww", getpid(), i); - FILE *f = fopen(src, "wb"); - if (f == NULL) { fail++; continue; } - fputs(rows[i].src, f); - fclose(f); - char tmpdir[64]; snprintf(tmpdir, sizeof tmpdir, "/tmp/wwafc_%d_d_%d", getpid(), i); mkdir(tmpdir, 0755); + char rmcmd[160]; + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); + + char src[128], outbin[128], cs_s[128], ws_s[128]; + snprintf(src, sizeof src, "%s/wwafc_%d_%d.ww", + tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/wwafc_%d_%d", + tmpdir, getpid(), i); + snprintf(cs_s, sizeof cs_s, "%s/wwafc_%d_%d_cs.s", + tmpdir, getpid(), i); + snprintf(ws_s, sizeof ws_s, "%s/wwafc_%d_%d_ww.s", + tmpdir, getpid(), i); + + FILE *f = fopen(src, "wb"); + if (f == NULL) { runwait(rmcmd); fail++; continue; } + fputs(rows[i].src, f); + fclose(f); + char cmd[2048]; - snprintf(cmd, sizeof cmd, "cd %s && %s/ww build %s", - tmpdir, bin, src); + snprintf(cmd, sizeof cmd, "%s/ww build -o %s %s", + bin, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: cstage build failed\n", rows[i].label); fail++; - unlink(src); rmdir(tmpdir); + runwait(rmcmd); continue; } - char outbin[128]; - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; - int got = runwait(outbin); if (got != rows[i].want_exit) { fprintf(stderr, "row[%s]: cstage exit %d, want %d\n", rows[i].label, got, rows[i].want_exit); fail++; } - unlink(outbin); rmdir(tmpdir); - - char cs_s[64], ws_s[64]; - snprintf(cs_s, sizeof cs_s, "/tmp/wwafc_%d_%d_cs.s", - getpid(), i); - snprintf(ws_s, sizeof ws_s, "/tmp/wwafc_%d_%d_ww.s", - getpid(), i); snprintf(cmd, sizeof cmd, "%s -o %s %s 2>/dev/null", w6c, cs_s, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: w6c failed\n", rows[i].label); - fail++; unlink(src); continue; + fail++; runwait(rmcmd); continue; } snprintf(cmd, sizeof cmd, "%s -o %s %s 2>/dev/null", w6c_ww, ws_s, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: w6c_ww failed\n", rows[i].label); - fail++; unlink(src); unlink(cs_s); continue; + fail++; runwait(rmcmd); continue; } if (slurp_eq(cs_s, ws_s) != 0) { fprintf(stderr, @@ -226,7 +222,7 @@ main(void) "byte-id violation)\n", rows[i].label); fail++; } - unlink(src); unlink(cs_s); unlink(ws_s); + runwait(rmcmd); } if (fail) { diff --git a/test/wcc/917_def_float_lit_run.c b/test/wcc/917_def_float_lit_run.c index f0bc55f5..25e67d3b 100644 --- a/test/wcc/917_def_float_lit_run.c +++ b/test/wcc/917_def_float_lit_run.c @@ -44,7 +44,6 @@ */ #include #include -#include #include #include #include @@ -159,62 +158,59 @@ main(void) int n = 0, fail = 0; for (int i = 0; rows[i].src; i++, n++) { - char src[64]; - snprintf(src, sizeof src, "/tmp/wwdflf_%d_%d.ww", getpid(), i); - FILE *f = fopen(src, "wb"); - if (f == NULL) { fail++; continue; } - fputs(rows[i].src, f); - fclose(f); - char tmpdir[64]; snprintf(tmpdir, sizeof tmpdir, "/tmp/wwdflf_%d_d_%d", getpid(), i); mkdir(tmpdir, 0755); + char rmcmd[128]; + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); + + char src[128], outbin[128], cs_s[128], ws_s[128]; + snprintf(src, sizeof src, "%s/wwdflf_%d_%d.ww", + tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/wwdflf_%d_%d", + tmpdir, getpid(), i); + snprintf(cs_s, sizeof cs_s, "%s/wwdflf_%d_%d_cs.s", + tmpdir, getpid(), i); + snprintf(ws_s, sizeof ws_s, "%s/wwdflf_%d_%d_ww.s", + tmpdir, getpid(), i); + + FILE *f = fopen(src, "wb"); + if (f == NULL) { fail++; runwait(rmcmd); continue; } + fputs(rows[i].src, f); + fclose(f); + char cmd[2048]; - snprintf(cmd, sizeof cmd, "cd %s && %s/ww build %s", - tmpdir, bin, src); + snprintf(cmd, sizeof cmd, "%s/ww build -o %s %s", + bin, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: cstage build failed\n", rows[i].label); fail++; - unlink(src); rmdir(tmpdir); + runwait(rmcmd); continue; } - char outbin[128]; - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; - int got = runwait(outbin); if (got != rows[i].want_exit) { fprintf(stderr, "row[%s]: cstage exit %d, want %d\n", rows[i].label, got, rows[i].want_exit); fail++; } - unlink(outbin); rmdir(tmpdir); - - char cs_s[64], ws_s[64]; - snprintf(cs_s, sizeof cs_s, "/tmp/wwdflf_%d_%d_cs.s", - getpid(), i); - snprintf(ws_s, sizeof ws_s, "/tmp/wwdflf_%d_%d_ww.s", - getpid(), i); snprintf(cmd, sizeof cmd, "%s -o %s %s 2>/dev/null", w6c, cs_s, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: w6c failed\n", rows[i].label); - fail++; unlink(src); continue; + fail++; runwait(rmcmd); continue; } snprintf(cmd, sizeof cmd, "%s -o %s %s 2>/dev/null", w6c_ww, ws_s, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: w6c_ww failed\n", rows[i].label); - fail++; unlink(src); unlink(cs_s); continue; + fail++; runwait(rmcmd); continue; } if (slurp_eq(cs_s, ws_s) != 0) { fprintf(stderr, @@ -222,7 +218,7 @@ main(void) "byte-id violation)\n", rows[i].label); fail++; } - unlink(src); unlink(cs_s); unlink(ws_s); + runwait(rmcmd); } if (fail) { diff --git a/test/wcc/918_struct_composite_init_run.c b/test/wcc/918_struct_composite_init_run.c index e4c2bb01..ca14ca90 100644 --- a/test/wcc/918_struct_composite_init_run.c +++ b/test/wcc/918_struct_composite_init_run.c @@ -55,7 +55,6 @@ */ #include #include -#include #include #include #include @@ -171,62 +170,57 @@ main(void) int n = 0, fail = 0; for (int i = 0; rows[i].src; i++, n++) { - char src[64]; - snprintf(src, sizeof src, "/tmp/wwstrc_%d_%d.ww", getpid(), i); - FILE *f = fopen(src, "wb"); - if (f == NULL) { fail++; continue; } - fputs(rows[i].src, f); - fclose(f); - char tmpdir[64]; snprintf(tmpdir, sizeof tmpdir, "/tmp/wwstrc_%d_d_%d", getpid(), i); mkdir(tmpdir, 0755); + char src[128], outbin[128], cs_s[128], ws_s[128], rmcmd[160]; + snprintf(src, sizeof src, "%s/wwstrc_%d_%d.ww", + tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/wwstrc_%d_%d", + tmpdir, getpid(), i); + snprintf(cs_s, sizeof cs_s, "%s/wwstrc_%d_%d_cs.s", + tmpdir, getpid(), i); + snprintf(ws_s, sizeof ws_s, "%s/wwstrc_%d_%d_ww.s", + tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); + + FILE *f = fopen(src, "wb"); + if (f == NULL) { fail++; runwait(rmcmd); continue; } + fputs(rows[i].src, f); + fclose(f); + char cmd[2048]; - snprintf(cmd, sizeof cmd, "cd %s && %s/ww build %s", - tmpdir, bin, src); + snprintf(cmd, sizeof cmd, "%s/ww build -o %s %s", + bin, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: cstage build failed\n", rows[i].label); fail++; - unlink(src); rmdir(tmpdir); + runwait(rmcmd); continue; } - char outbin[128]; - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; - int got = runwait(outbin); if (got != rows[i].want_exit) { fprintf(stderr, "row[%s]: cstage exit %d, want %d\n", rows[i].label, got, rows[i].want_exit); fail++; } - unlink(outbin); rmdir(tmpdir); - - char cs_s[64], ws_s[64]; - snprintf(cs_s, sizeof cs_s, "/tmp/wwstrc_%d_%d_cs.s", - getpid(), i); - snprintf(ws_s, sizeof ws_s, "/tmp/wwstrc_%d_%d_ww.s", - getpid(), i); snprintf(cmd, sizeof cmd, "%s -o %s %s 2>/dev/null", w6c, cs_s, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: w6c failed\n", rows[i].label); - fail++; unlink(src); continue; + fail++; runwait(rmcmd); continue; } snprintf(cmd, sizeof cmd, "%s -o %s %s 2>/dev/null", w6c_ww, ws_s, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: w6c_ww failed\n", rows[i].label); - fail++; unlink(src); unlink(cs_s); continue; + fail++; runwait(rmcmd); continue; } if (slurp_eq(cs_s, ws_s) != 0) { fprintf(stderr, @@ -234,7 +228,7 @@ main(void) "byte-id violation)\n", rows[i].label); fail++; } - unlink(src); unlink(cs_s); unlink(ws_s); + runwait(rmcmd); } if (fail) { diff --git a/test/wcc/919_array_static_init_run.c b/test/wcc/919_array_static_init_run.c index 2570436a..f02cff53 100644 --- a/test/wcc/919_array_static_init_run.c +++ b/test/wcc/919_array_static_init_run.c @@ -83,7 +83,6 @@ */ #include #include -#include #include #include #include @@ -248,62 +247,61 @@ main(void) int n = 0, fail = 0; for (int i = 0; rows[i].src; i++, n++) { - char src[64]; - snprintf(src, sizeof src, "/tmp/wwari_%d_%d.ww", getpid(), i); - FILE *f = fopen(src, "wb"); - if (f == NULL) { fail++; continue; } - fputs(rows[i].src, f); - fclose(f); - char tmpdir[64]; snprintf(tmpdir, sizeof tmpdir, "/tmp/wwari_%d_d_%d", getpid(), i); mkdir(tmpdir, 0755); + char rmcmd[160]; + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); + + char src[128]; + snprintf(src, sizeof src, "%s/wwari_%d_%d.ww", + tmpdir, getpid(), i); + FILE *f = fopen(src, "wb"); + if (f == NULL) { fail++; runwait(rmcmd); continue; } + fputs(rows[i].src, f); + fclose(f); + + char outbin[128]; + snprintf(outbin, sizeof outbin, "%s/wwari_%d_%d", + tmpdir, getpid(), i); char cmd[2048]; - snprintf(cmd, sizeof cmd, "cd %s && %s/ww build %s", - tmpdir, bin, src); + snprintf(cmd, sizeof cmd, "%s/ww build -o %s %s", + bin, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: cstage build failed\n", rows[i].label); fail++; - unlink(src); rmdir(tmpdir); + runwait(rmcmd); continue; } - char outbin[128]; - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; - int got = runwait(outbin); if (got != rows[i].want_exit) { fprintf(stderr, "row[%s]: cstage exit %d, want %d\n", rows[i].label, got, rows[i].want_exit); fail++; } - unlink(outbin); rmdir(tmpdir); - char cs_s[64], ws_s[64]; - snprintf(cs_s, sizeof cs_s, "/tmp/wwari_%d_%d_cs.s", - getpid(), i); - snprintf(ws_s, sizeof ws_s, "/tmp/wwari_%d_%d_ww.s", - getpid(), i); + char cs_s[128], ws_s[128]; + snprintf(cs_s, sizeof cs_s, "%s/wwari_%d_%d_cs.s", + tmpdir, getpid(), i); + snprintf(ws_s, sizeof ws_s, "%s/wwari_%d_%d_ww.s", + tmpdir, getpid(), i); snprintf(cmd, sizeof cmd, "%s -o %s %s 2>/dev/null", w6c, cs_s, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: w6c failed\n", rows[i].label); - fail++; unlink(src); continue; + fail++; runwait(rmcmd); continue; } snprintf(cmd, sizeof cmd, "%s -o %s %s 2>/dev/null", w6c_ww, ws_s, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: w6c_ww failed\n", rows[i].label); - fail++; unlink(src); unlink(cs_s); continue; + fail++; runwait(rmcmd); continue; } if (slurp_eq(cs_s, ws_s) != 0) { fprintf(stderr, @@ -311,7 +309,7 @@ main(void) "byte-id violation)\n", rows[i].label); fail++; } - unlink(src); unlink(cs_s); unlink(ws_s); + runwait(rmcmd); } /* #156 rule-7: a `...` repeat marker with a nested-array element is diff --git a/test/wcc/919_strarray_static_run.c b/test/wcc/919_strarray_static_run.c index 1254948c..9b8cdd96 100644 --- a/test/wcc/919_strarray_static_run.c +++ b/test/wcc/919_strarray_static_run.c @@ -37,7 +37,6 @@ */ #include #include -#include #include #include #include @@ -138,66 +137,60 @@ main(void) int n = 0, fail = 0; for (int i = 0; rows[i].src; i++, n++) { - char src[64]; - snprintf(src, sizeof src, "/tmp/wwsas_%d_%d.ww", getpid(), i); - FILE *f = fopen(src, "wb"); - if (f == NULL) { fail++; continue; } - fputs(rows[i].src, f); - fclose(f); - - /* (a) cstage build + run in a scratch dir. */ char tmpdir[64]; snprintf(tmpdir, sizeof tmpdir, "/tmp/wwsas_%d_d_%d", getpid(), i); mkdir(tmpdir, 0755); + char rmcmd[160]; + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); + char src[128], outbin[128]; + snprintf(src, sizeof src, "%s/wwsas_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/wwsas_%d_%d", tmpdir, getpid(), i); + FILE *f = fopen(src, "wb"); + if (f == NULL) { runwait(rmcmd); fail++; continue; } + fputs(rows[i].src, f); + fclose(f); + + /* (a) cstage build + run. */ char cmd[2048]; - snprintf(cmd, sizeof cmd, "cd %s && %s/ww build %s", - tmpdir, bin, src); + snprintf(cmd, sizeof cmd, "%s/ww build -o %s %s", bin, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: cstage build failed\n", rows[i].label); fail++; - unlink(src); rmdir(tmpdir); + runwait(rmcmd); continue; } - char outbin[128]; - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; - int got = runwait(outbin); if (got != rows[i].want_exit) { fprintf(stderr, "row[%s]: cstage exit %d, want %d\n", rows[i].label, got, rows[i].want_exit); fail++; } - unlink(outbin); rmdir(tmpdir); /* (b) cs==ww byte-id gate. */ - char cs_s[64], ws_s[64]; - snprintf(cs_s, sizeof cs_s, "/tmp/wwsas_%d_%d_cs.s", getpid(), i); - snprintf(ws_s, sizeof ws_s, "/tmp/wwsas_%d_%d_ww.s", getpid(), i); + char cs_s[128], ws_s[128]; + snprintf(cs_s, sizeof cs_s, "%s/wwsas_%d_%d_cs.s", tmpdir, getpid(), i); + snprintf(ws_s, sizeof ws_s, "%s/wwsas_%d_%d_ww.s", tmpdir, getpid(), i); snprintf(cmd, sizeof cmd, "%s -o %s %s 2>/dev/null", w6c, cs_s, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: w6c failed\n", rows[i].label); - fail++; unlink(src); continue; + fail++; runwait(rmcmd); continue; } snprintf(cmd, sizeof cmd, "%s -o %s %s 2>/dev/null", w6c_ww, ws_s, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: w6c_ww failed\n", rows[i].label); - fail++; unlink(src); unlink(cs_s); continue; + fail++; runwait(rmcmd); continue; } if (slurp_eq(cs_s, ws_s) != 0) { fprintf(stderr, "row[%s]: cstage/wwstage .s DIFFER " "(rule-10 byte-id violation)\n", rows[i].label); fail++; } - unlink(src); unlink(cs_s); unlink(ws_s); + runwait(rmcmd); } if (fail) { diff --git a/test/wcc/920_array_init_acceptiffits_run.c b/test/wcc/920_array_init_acceptiffits_run.c index b531a13c..81fe8f39 100644 --- a/test/wcc/920_array_init_acceptiffits_run.c +++ b/test/wcc/920_array_init_acceptiffits_run.c @@ -46,7 +46,6 @@ */ #include #include -#include #include #include #include @@ -187,61 +186,58 @@ main(void) /* Accept rows: cstage build + run + cs==ww byte-id. */ for (int i = 0; accept_rows[i].src; i++, n++) { - char src[64]; - snprintf(src, sizeof src, "/tmp/wwafit_%d_%d.ww", getpid(), i); - FILE *f = fopen(src, "wb"); - if (f == NULL) { fail++; continue; } - fputs(accept_rows[i].src, f); - fclose(f); - char tmpdir[64]; snprintf(tmpdir, sizeof tmpdir, "/tmp/wwafit_%d_d_%d", getpid(), i); mkdir(tmpdir, 0755); + char src[128], outbin[128], cs_s[128], ws_s[128], rmcmd[160]; + snprintf(src, sizeof src, "%s/wwafit_%d_%d.ww", + tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/wwafit_%d_%d", + tmpdir, getpid(), i); + snprintf(cs_s, sizeof cs_s, "%s/wwafit_%d_%d_cs.s", + tmpdir, getpid(), i); + snprintf(ws_s, sizeof ws_s, "%s/wwafit_%d_%d_ww.s", + tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); + + FILE *f = fopen(src, "wb"); + if (f == NULL) { fail++; runwait(rmcmd); continue; } + fputs(accept_rows[i].src, f); + fclose(f); + char cmd[2048]; - snprintf(cmd, sizeof cmd, "cd %s && %s/ww build %s", - tmpdir, bin, src); + snprintf(cmd, sizeof cmd, "%s/ww build -o %s %s", + bin, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "accept[%s]: cstage build failed\n", accept_rows[i].label); - fail++; unlink(src); rmdir(tmpdir); continue; + fail++; runwait(rmcmd); continue; } - char outbin[128]; - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); if (got != accept_rows[i].want_exit) { fprintf(stderr, "accept[%s]: exit %d, want %d\n", accept_rows[i].label, got, accept_rows[i].want_exit); fail++; } - unlink(outbin); rmdir(tmpdir); - char cs_s[64], ws_s[64]; - snprintf(cs_s, sizeof cs_s, "/tmp/wwafit_%d_%d_cs.s", - getpid(), i); - snprintf(ws_s, sizeof ws_s, "/tmp/wwafit_%d_%d_ww.s", - getpid(), i); snprintf(cmd, sizeof cmd, "%s -o %s %s 2>/dev/null", w6c, cs_s, src); if (runwait(cmd) != 0) { fprintf(stderr, "accept[%s]: w6c failed\n", accept_rows[i].label); - fail++; unlink(src); continue; + fail++; runwait(rmcmd); continue; } snprintf(cmd, sizeof cmd, "%s -o %s %s 2>/dev/null", w6c_ww, ws_s, src); if (runwait(cmd) != 0) { fprintf(stderr, "accept[%s]: w6c_ww failed\n", accept_rows[i].label); - fail++; unlink(src); unlink(cs_s); continue; + fail++; runwait(rmcmd); continue; } if (slurp_eq(cs_s, ws_s) != 0) { fprintf(stderr, "accept[%s]: cs/ww .s DIFFER (rule-10)\n", accept_rows[i].label); fail++; } - unlink(src); unlink(cs_s); unlink(ws_s); + runwait(rmcmd); } /* Reject rows: BOTH stages must fail to build (loud reject). */ diff --git a/test/wcc/921_amp_def_global_run.c b/test/wcc/921_amp_def_global_run.c index f28a3605..94cc1003 100644 --- a/test/wcc/921_amp_def_global_run.c +++ b/test/wcc/921_amp_def_global_run.c @@ -36,7 +36,6 @@ */ #include #include -#include #include #include #include @@ -184,10 +183,17 @@ main(void) int n = 0, fail = 0; for (int i = 0; rows[i].src; i++, n++) { - char src[64]; - snprintf(src, sizeof src, "/tmp/wwamp_%d_%d.ww", getpid(), i); + char tmpdir[64], rmcmd[80]; + snprintf(tmpdir, sizeof tmpdir, "/tmp/wwamp_%d_d_%d", + getpid(), i); + mkdir(tmpdir, 0755); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); + + char src[128]; + snprintf(src, sizeof src, "%s/wwamp_%d_%d.ww", + tmpdir, getpid(), i); FILE *f = fopen(src, "wb"); - if (f == NULL) { fail++; continue; } + if (f == NULL) { runwait(rmcmd); fail++; continue; } fputs(rows[i].src, f); fclose(f); @@ -195,9 +201,9 @@ main(void) /* rule-7 LOUD: both stages must REJECT (`&` of a non- * addressable def has no DATA symbol). Build to .s and * assert non-zero exit on each stage. */ - char cmd[2048], dump[64]; - snprintf(dump, sizeof dump, "/tmp/wwamp_%d_%d.s", - getpid(), i); + char cmd[2048], dump[128]; + snprintf(dump, sizeof dump, "%s/wwamp_%d_%d.s", + tmpdir, getpid(), i); snprintf(cmd, sizeof cmd, "%s -o %s %s 2>/dev/null", w6c, dump, src); if (runwait(cmd) == 0) { @@ -214,62 +220,53 @@ main(void) rows[i].label); fail++; } - unlink(src); unlink(dump); + runwait(rmcmd); continue; } /* (a) cstage build + run; assert exit == value reached * through the pointer. */ - char tmpdir[64]; - snprintf(tmpdir, sizeof tmpdir, "/tmp/wwamp_%d_d_%d", - getpid(), i); - mkdir(tmpdir, 0755); + char outbin[128]; + snprintf(outbin, sizeof outbin, "%s/wwamp_%d_%d", + tmpdir, getpid(), i); char cmd[2048]; - snprintf(cmd, sizeof cmd, "cd %s && %s/ww build %s", - tmpdir, bin, src); + snprintf(cmd, sizeof cmd, "%s/ww build -o %s %s", + bin, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: cstage build failed\n", rows[i].label); fail++; - unlink(src); rmdir(tmpdir); + runwait(rmcmd); continue; } - char outbin[128]; - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; - int got = runwait(outbin); if (got != rows[i].want_exit) { fprintf(stderr, "row[%s]: cstage exit %d, want %d\n", rows[i].label, got, rows[i].want_exit); fail++; } - unlink(outbin); rmdir(tmpdir); /* (b) cs==ww byte-id gate. */ - char cs_s[64], ws_s[64]; - snprintf(cs_s, sizeof cs_s, "/tmp/wwamp_%d_%d_cs.s", - getpid(), i); - snprintf(ws_s, sizeof ws_s, "/tmp/wwamp_%d_%d_ww.s", - getpid(), i); + char cs_s[128], ws_s[128]; + snprintf(cs_s, sizeof cs_s, "%s/wwamp_%d_%d_cs.s", + tmpdir, getpid(), i); + snprintf(ws_s, sizeof ws_s, "%s/wwamp_%d_%d_ww.s", + tmpdir, getpid(), i); snprintf(cmd, sizeof cmd, "%s -o %s %s 2>/dev/null", w6c, cs_s, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: w6c failed\n", rows[i].label); - fail++; unlink(src); continue; + fail++; runwait(rmcmd); continue; } snprintf(cmd, sizeof cmd, "%s -o %s %s 2>/dev/null", w6c_ww, ws_s, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: w6c_ww failed\n", rows[i].label); - fail++; unlink(src); unlink(cs_s); continue; + fail++; runwait(rmcmd); continue; } if (slurp_eq(cs_s, ws_s) != 0) { fprintf(stderr, @@ -277,7 +274,7 @@ main(void) "byte-id violation)\n", rows[i].label); fail++; } - unlink(src); unlink(cs_s); unlink(ws_s); + runwait(rmcmd); } if (fail) { diff --git a/test/wcc/923_signed_data_emit_run.c b/test/wcc/923_signed_data_emit_run.c index dc0d4094..45477d12 100644 --- a/test/wcc/923_signed_data_emit_run.c +++ b/test/wcc/923_signed_data_emit_run.c @@ -35,7 +35,6 @@ */ #include #include -#include #include #include #include @@ -140,34 +139,29 @@ static const struct row rows[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/sde_%d_%d.ww", getpid(), i); + char src[128], tmpdir[64], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/sde_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/sde_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/sde_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s", driver, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return got; } diff --git a/test/wcc/924_tagged_call_arg_run.c b/test/wcc/924_tagged_call_arg_run.c index 2b6b5004..5f0ca72e 100644 --- a/test/wcc/924_tagged_call_arg_run.c +++ b/test/wcc/924_tagged_call_arg_run.c @@ -39,7 +39,6 @@ */ #include #include -#include #include #include #include @@ -156,34 +155,30 @@ static const struct row rows[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/tca_%d_%d.ww", getpid(), i); + char src[128], tmpdir[64], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/tca_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/tca_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/tca_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s", + driver, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return got; } diff --git a/test/wcc/926_match_slice_variant_run.c b/test/wcc/926_match_slice_variant_run.c index c05bf28d..84b6926e 100644 --- a/test/wcc/926_match_slice_variant_run.c +++ b/test/wcc/926_match_slice_variant_run.c @@ -16,7 +16,6 @@ */ #include #include -#include #include #include #include @@ -174,34 +173,29 @@ static const struct row rows[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[96], tmpdir[96], cmd[1024]; - snprintf(src, sizeof src, "/tmp/msv_run_%d_%d.ww", getpid(), i); + char src[128], tmpdir[96], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/msv_run_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/msv_run_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/msv_run_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s", driver, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[160]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return got; } diff --git a/test/wcc/926_tagged_sret_run.c b/test/wcc/926_tagged_sret_run.c index b1069e53..75a0d6ec 100644 --- a/test/wcc/926_tagged_sret_run.c +++ b/test/wcc/926_tagged_sret_run.c @@ -472,25 +472,21 @@ file_has(const char *path, const char *needle) static int run_driver(const char *driver, const char *src, const char *label) { - char tmpdir[128], cmd[1024]; - snprintf(tmpdir, sizeof tmpdir, "/tmp/tsret_%d_d", getpid()); + char tmpdir[128], outbin[256], rmcmd[160], cmd[1024]; + snprintf(tmpdir, sizeof tmpdir, "/tmp/tsret_%d_%s_d", getpid(), driver); mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s/%s build %s >/dev/null 2>&1", - tmpdir, g_bin, driver, src); + snprintf(outbin, sizeof outbin, "%s/m", tmpdir); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); + snprintf(cmd, sizeof cmd, "%s/%s build -o %s %s >/dev/null 2>&1", + g_bin, driver, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", label, driver); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[256]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(outbin); - rmdir(tmpdir); + runwait(rmcmd); return got; } diff --git a/test/wcc/926_tagscr_sizes_run.c b/test/wcc/926_tagscr_sizes_run.c index 9b32f558..2276ac4f 100644 --- a/test/wcc/926_tagscr_sizes_run.c +++ b/test/wcc/926_tagscr_sizes_run.c @@ -25,7 +25,6 @@ */ #include #include -#include #include #include #include @@ -192,28 +191,19 @@ file_eq(const char *a, const char *b) } static int -run_driver(const char *driver, const char *src, const char *label) +run_driver(const char *driver, const char *src, const char *tmpdir, + const char *label) { - char tmpdir[128], cmd[1024]; - snprintf(tmpdir, sizeof tmpdir, "/tmp/tagscr_%d_d", getpid()); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s/%s build %s >/dev/null 2>&1", - tmpdir, g_bin, driver, src); + char cmd[1024], outbin[256]; + snprintf(outbin, sizeof outbin, "%s/drvout", tmpdir); + snprintf(cmd, sizeof cmd, "%s/%s build -o %s %s >/dev/null 2>&1", + g_bin, driver, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", label, driver); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[256]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; - int got = runwait(outbin); - unlink(outbin); - rmdir(tmpdir); - return got; + return runwait(outbin); } int @@ -234,15 +224,19 @@ main(void) int total = 0, fail = 0; for (int i = 0; i < n; i++) { const struct row *r = &rows[i]; - char src[128], cs_s[128], ww_s[128]; - snprintf(src, sizeof src, "/tmp/tagscr_%d_%d.ww", - getpid(), i); - snprintf(cs_s, sizeof cs_s, "/tmp/tagscr_%d_%d_cs.s", - getpid(), i); - snprintf(ww_s, sizeof ww_s, "/tmp/tagscr_%d_%d_ww.s", + char tmpdir[96], src[160], cs_s[160], ww_s[160], rmcmd[160]; + snprintf(tmpdir, sizeof tmpdir, "/tmp/tagscr_%d_%d_d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/tagscr_%d_%d.ww", + tmpdir, getpid(), i); + snprintf(cs_s, sizeof cs_s, "%s/tagscr_%d_%d_cs.s", + tmpdir, getpid(), i); + snprintf(ww_s, sizeof ww_s, "%s/tagscr_%d_%d_ww.s", + tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return 1; + if (!f) { runwait(rmcmd); return 1; } fputs("package main;\n\n", f); fputs(r->src, f); fclose(f); @@ -254,7 +248,7 @@ main(void) fprintf(stderr, "FAIL row[%s]: compile rc cs=%d " "ww=%d\n", r->label, cs_rc, ww_rc); fail++; - unlink(src); unlink(cs_s); unlink(ww_s); + runwait(rmcmd); continue; } if (!file_eq(cs_s, ww_s)) { @@ -262,7 +256,7 @@ main(void) r->label); fail++; } - int got_cs = run_driver("ww", src, r->label); + int got_cs = run_driver("ww", src, tmpdir, r->label); if (got_cs != r->want) { fprintf(stderr, "FAIL row[%s] cstage: want %d " "got %d\n", r->label, r->want, got_cs); @@ -271,7 +265,7 @@ main(void) char wwdrv[600]; snprintf(wwdrv, sizeof wwdrv, "%s/ww_ww", g_bin); if (access(wwdrv, X_OK) == 0) { - int got_ww = run_driver("ww_ww", src, r->label); + int got_ww = run_driver("ww_ww", src, tmpdir, r->label); if (got_ww != r->want) { fprintf(stderr, "FAIL row[%s] wwstage: " "want %d got %d\n", @@ -279,7 +273,7 @@ main(void) fail++; } } - unlink(src); unlink(cs_s); unlink(ww_s); + runwait(rmcmd); } if (fail) { fprintf(stderr, "tagscr_sizes_run: %d/%d rows failed\n", diff --git a/test/wcc/927_is_nonident_run.c b/test/wcc/927_is_nonident_run.c index e8d2e535..9a370591 100644 --- a/test/wcc/927_is_nonident_run.c +++ b/test/wcc/927_is_nonident_run.c @@ -25,7 +25,6 @@ */ #include #include -#include #include #include #include @@ -196,25 +195,21 @@ file_eq(const char *a, const char *b) static int run_driver(const char *driver, const char *src, const char *label) { - char tmpdir[128], cmd[1024]; + char tmpdir[128], outbin[160], rmcmd[200], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/isnonid_%d_d", getpid()); mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s/%s build %s >/dev/null 2>&1", - tmpdir, g_bin, driver, src); + snprintf(outbin, sizeof outbin, "%s/m", tmpdir); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); + snprintf(cmd, sizeof cmd, "%s/%s build -o %s %s >/dev/null 2>&1", + g_bin, driver, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", label, driver); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[256]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(outbin); - rmdir(tmpdir); + runwait(rmcmd); return got; } diff --git a/test/wcc/928_match_nonident_idx_run.c b/test/wcc/928_match_nonident_idx_run.c index 2b78700f..dd68c782 100644 --- a/test/wcc/928_match_nonident_idx_run.c +++ b/test/wcc/928_match_nonident_idx_run.c @@ -31,7 +31,6 @@ */ #include #include -#include #include #include #include @@ -196,28 +195,19 @@ file_eq(const char *a, const char *b) } static int -run_driver(const char *driver, const char *src, const char *label) +run_driver(const char *driver, const char *tmpdir, const char *src, + const char *label) { - char tmpdir[128], cmd[1024]; - snprintf(tmpdir, sizeof tmpdir, "/tmp/matchnidx_%d_d", getpid()); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s/%s build %s >/dev/null 2>&1", - tmpdir, g_bin, driver, src); + char outbin[256], cmd[1024]; + snprintf(outbin, sizeof outbin, "%s/%s_bin", tmpdir, driver); + snprintf(cmd, sizeof cmd, "%s/%s build -o %s %s >/dev/null 2>&1", + g_bin, driver, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", label, driver); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[256]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; - int got = runwait(outbin); - unlink(outbin); - rmdir(tmpdir); - return got; + return runwait(outbin); } int @@ -238,15 +228,19 @@ main(void) int total = 0, fail = 0; for (int i = 0; i < n; i++) { const struct row *r = &rows[i]; - char src[128], cs_s[128], ww_s[128]; - snprintf(src, sizeof src, "/tmp/matchnidx_%d_%d.ww", - getpid(), i); - snprintf(cs_s, sizeof cs_s, "/tmp/matchnidx_%d_%d_cs.s", - getpid(), i); - snprintf(ww_s, sizeof ww_s, "/tmp/matchnidx_%d_%d_ww.s", + char tmpdir[128], src[160], cs_s[160], ww_s[160], rmcmd[192]; + snprintf(tmpdir, sizeof tmpdir, "/tmp/matchnidx_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/matchnidx_%d_%d.ww", + tmpdir, getpid(), i); + snprintf(cs_s, sizeof cs_s, "%s/matchnidx_%d_%d_cs.s", + tmpdir, getpid(), i); + snprintf(ww_s, sizeof ww_s, "%s/matchnidx_%d_%d_ww.s", + tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return 1; + if (!f) { runwait(rmcmd); return 1; } fputs("package main;\n\n", f); fputs(r->src, f); fclose(f); @@ -258,7 +252,7 @@ main(void) fprintf(stderr, "FAIL row[%s]: compile rc cs=%d " "ww=%d\n", r->label, cs_rc, ww_rc); fail++; - unlink(src); unlink(cs_s); unlink(ww_s); + runwait(rmcmd); continue; } if (!file_eq(cs_s, ww_s)) { @@ -266,7 +260,7 @@ main(void) r->label); fail++; } - int got_cs = run_driver("ww", src, r->label); + int got_cs = run_driver("ww", tmpdir, src, r->label); if (got_cs != r->want) { fprintf(stderr, "FAIL row[%s] cstage: want %d " "got %d\n", r->label, r->want, got_cs); @@ -275,7 +269,8 @@ main(void) char wwdrv[600]; snprintf(wwdrv, sizeof wwdrv, "%s/ww_ww", g_bin); if (access(wwdrv, X_OK) == 0) { - int got_ww = run_driver("ww_ww", src, r->label); + int got_ww = run_driver("ww_ww", tmpdir, src, + r->label); if (got_ww != r->want) { fprintf(stderr, "FAIL row[%s] wwstage: " "want %d got %d\n", @@ -283,7 +278,7 @@ main(void) fail++; } } - unlink(src); unlink(cs_s); unlink(ww_s); + runwait(rmcmd); } if (fail) { fprintf(stderr, "match_nonident_idx_run: %d/%d rows failed\n", diff --git a/test/wcc/929_tagged_memarg_run.c b/test/wcc/929_tagged_memarg_run.c index d9286ffb..9dda5d76 100644 --- a/test/wcc/929_tagged_memarg_run.c +++ b/test/wcc/929_tagged_memarg_run.c @@ -625,25 +625,21 @@ file_has(const char *path, const char *needle) static int run_driver(const char *driver, const char *src, const char *label) { - char tmpdir[128], cmd[1024]; + char tmpdir[128], outbin[160], rmcmd[200], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/tmemarg_%d_d", getpid()); mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s/%s build %s >/dev/null 2>&1", - tmpdir, g_bin, driver, src); + snprintf(outbin, sizeof outbin, "%s/m", tmpdir); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); + snprintf(cmd, sizeof cmd, "%s/%s build -o %s %s >/dev/null 2>&1", + g_bin, driver, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", label, driver); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[256]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(outbin); - rmdir(tmpdir); + runwait(rmcmd); return got; } diff --git a/test/wcc/930_free_noop_run.c b/test/wcc/930_free_noop_run.c index 69f7d174..c52d93ee 100644 --- a/test/wcc/930_free_noop_run.c +++ b/test/wcc/930_free_noop_run.c @@ -32,7 +32,6 @@ */ #include #include -#include #include #include #include @@ -156,28 +155,19 @@ has_free_sym(const char *s_path) } static int -run_driver(const char *driver, const char *src, const char *label) +run_driver(const char *driver, const char *src, const char *tmpdir, + const char *label) { - char tmpdir[128], cmd[1024]; - snprintf(tmpdir, sizeof tmpdir, "/tmp/freenoop_%d_d", getpid()); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s/%s build %s >/dev/null 2>&1", - tmpdir, g_bin, driver, src); + char cmd[1024], outbin[256]; + snprintf(outbin, sizeof outbin, "%s/%s_out", tmpdir, driver); + snprintf(cmd, sizeof cmd, "%s/%s build -o %s %s >/dev/null 2>&1", + g_bin, driver, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", label, driver); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[256]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; - int got = runwait(outbin); - unlink(outbin); - rmdir(tmpdir); - return got; + return runwait(outbin); } int @@ -198,15 +188,22 @@ main(void) int total = 0, fail = 0; for (int i = 0; i < n; i++) { const struct row *r = &rows[i]; - char src[128], cs_s[128], ww_s[128]; - snprintf(src, sizeof src, "/tmp/freenoop_%d_%d.ww", - getpid(), i); - snprintf(cs_s, sizeof cs_s, "/tmp/freenoop_%d_%d_cs.s", - getpid(), i); - snprintf(ww_s, sizeof ww_s, "/tmp/freenoop_%d_%d_ww.s", + /* #8: source, .sepwork scratch, both driver binaries and the + * byte-id .s dumps all live under one tmpdir; rm -rf on every + * exit path. Symbol mangling is package/import-derived, not + * entry-path derived, so the in-tmpdir source keeps the cs==ww + * .s identical. */ + char tmpdir[64], src[128], cs_s[128], ww_s[128], rmcmd[160]; + snprintf(tmpdir, sizeof tmpdir, "/tmp/freenoop_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/freenoop_%d_%d.ww", + tmpdir, getpid(), i); + snprintf(cs_s, sizeof cs_s, "%s/cs.s", tmpdir); + snprintf(ww_s, sizeof ww_s, "%s/ww.s", tmpdir); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return 1; + if (!f) { runwait(rmcmd); return 1; } fputs("package main;\n\n", f); fputs(r->src, f); fclose(f); @@ -218,7 +215,7 @@ main(void) fprintf(stderr, "FAIL row[%s]: compile rc cs=%d " "ww=%d\n", r->label, cs_rc, ww_rc); fail++; - unlink(src); unlink(cs_s); unlink(ww_s); + runwait(rmcmd); continue; } if (!file_eq(cs_s, ww_s)) { @@ -231,7 +228,7 @@ main(void) "the .s — lowering is not a no-op\n", r->label); fail++; } - int got_cs = run_driver("ww", src, r->label); + int got_cs = run_driver("ww", src, tmpdir, r->label); if (got_cs != r->want) { fprintf(stderr, "FAIL row[%s] cstage: want %d " "got %d\n", r->label, r->want, got_cs); @@ -240,7 +237,7 @@ main(void) char wwdrv[600]; snprintf(wwdrv, sizeof wwdrv, "%s/ww_ww", g_bin); if (access(wwdrv, X_OK) == 0) { - int got_ww = run_driver("ww_ww", src, r->label); + int got_ww = run_driver("ww_ww", src, tmpdir, r->label); if (got_ww != r->want) { fprintf(stderr, "FAIL row[%s] wwstage: " "want %d got %d\n", @@ -248,7 +245,7 @@ main(void) fail++; } } - unlink(src); unlink(cs_s); unlink(ww_s); + runwait(rmcmd); } if (fail) { fprintf(stderr, "free_noop_run: %d/%d rows failed\n", diff --git a/test/wcc/936_tagged_tuple_widen_run.c b/test/wcc/936_tagged_tuple_widen_run.c index 9fd0afa3..1fc1c643 100644 --- a/test/wcc/936_tagged_tuple_widen_run.c +++ b/test/wcc/936_tagged_tuple_widen_run.c @@ -400,19 +400,21 @@ static const struct row rows[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[96], tmpdir[96], errf[96], cmd[1024]; - snprintf(src, sizeof src, "/tmp/ttw_%d_%d.ww", getpid(), i); + char tmpdir[96], src[160], outbin[160], errf[160], rmcmd[176], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/ttw_%d_d_%d", getpid(), i); - snprintf(errf, sizeof errf, "/tmp/ttw_%d_e_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/ttw_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/ttw_%d_%d", tmpdir, getpid(), i); + snprintf(errf, sizeof errf, "%s/err", tmpdir); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s >/dev/null 2>%s", - tmpdir, driver, src, errf); + snprintf(cmd, sizeof cmd, "%s build -o %s %s >/dev/null 2>%s", + driver, outbin, src, errf); int brc = runwait(cmd); if (r->kind == K_BUILDERR) { int ok = (brc != 0) @@ -421,25 +423,19 @@ run_driver(const char *driver, const struct row *r, int i) fprintf(stderr, "row[%s]: %s expected loud builderr " "\"%s\" (brc=%d)\n", r->label, driver, r->experr ? r->experr : "", brc); - unlink(src); unlink(errf); rmdir(tmpdir); + runwait(rmcmd); return ok ? 0 : 1; } if (brc != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); unlink(errf); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[256]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); unlink(errf); rmdir(tmpdir); + runwait(rmcmd); if (got != r->want) { fprintf(stderr, "row[%s]: %s exit %d, want %d\n", r->label, driver, got, r->want); diff --git a/test/wcc/937_forrange_fieldbase_run.c b/test/wcc/937_forrange_fieldbase_run.c index 96858bca..fc07338f 100644 --- a/test/wcc/937_forrange_fieldbase_run.c +++ b/test/wcc/937_forrange_fieldbase_run.c @@ -215,19 +215,21 @@ static const struct row rows[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[96], tmpdir[96], errf[96], cmd[1024]; - snprintf(src, sizeof src, "/tmp/tfr_%d_%d.ww", getpid(), i); + char tmpdir[96], src[128], outbin[128], errf[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/tfr_%d_d_%d", getpid(), i); - snprintf(errf, sizeof errf, "/tmp/tfr_%d_e_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/tfr_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/tfr_%d_%d", tmpdir, getpid(), i); + snprintf(errf, sizeof errf, "%s/tfr_%d_e_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s >/dev/null 2>%s", - tmpdir, driver, src, errf); + snprintf(cmd, sizeof cmd, "%s build -o %s %s >/dev/null 2>%s", + driver, outbin, src, errf); int brc = runwait(cmd); if (r->kind == K_BUILDERR) { int ok = (brc != 0) @@ -236,25 +238,19 @@ run_driver(const char *driver, const struct row *r, int i) fprintf(stderr, "row[%s]: %s expected loud builderr " "\"%s\" (brc=%d)\n", r->label, driver, r->experr ? r->experr : "", brc); - unlink(src); unlink(errf); rmdir(tmpdir); + runwait(rmcmd); return ok ? 0 : 1; } if (brc != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); unlink(errf); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[256]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); unlink(errf); rmdir(tmpdir); + runwait(rmcmd); if (got != r->want) { fprintf(stderr, "row[%s]: %s exit %d, want %d\n", r->label, driver, got, r->want); diff --git a/test/wcc/938_tagged_structlit_payload_run.c b/test/wcc/938_tagged_structlit_payload_run.c index 43c0f970..4c382a3b 100644 --- a/test/wcc/938_tagged_structlit_payload_run.c +++ b/test/wcc/938_tagged_structlit_payload_run.c @@ -68,7 +68,6 @@ */ #include #include -#include #include #include #include @@ -559,36 +558,32 @@ static const struct row rows[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[96], tmpdir[96], errf[96], cmd[1024]; - snprintf(src, sizeof src, "/tmp/tsp_%d_%d.ww", getpid(), i); + char tmpdir[96], src[128], outbin[128], errf[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/tsp_%d_d_%d", getpid(), i); - snprintf(errf, sizeof errf, "/tmp/tsp_%d_e_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/tsp_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/tsp_%d_%d", tmpdir, getpid(), i); + snprintf(errf, sizeof errf, "%s/err", tmpdir); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s >/dev/null 2>%s", - tmpdir, driver, src, errf); + snprintf(cmd, sizeof cmd, "%s build -o %s %s >/dev/null 2>%s", + driver, outbin, src, errf); int brc = runwait(cmd); if (brc != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); unlink(errf); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[256]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); unlink(errf); rmdir(tmpdir); + runwait(rmcmd); if (got != r->want) { fprintf(stderr, "row[%s]: %s exit %d, want %d\n", r->label, driver, got, r->want); diff --git a/test/wcc/940_mixed_scalar_tuple_sret_run.c b/test/wcc/940_mixed_scalar_tuple_sret_run.c index f0687ae4..2ad79c55 100644 --- a/test/wcc/940_mixed_scalar_tuple_sret_run.c +++ b/test/wcc/940_mixed_scalar_tuple_sret_run.c @@ -35,7 +35,6 @@ */ #include #include -#include #include #include #include @@ -135,36 +134,32 @@ static const struct row rows[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[96], tmpdir[96], errf[96], cmd[1024]; - snprintf(src, sizeof src, "/tmp/mxst_%d_%d.ww", getpid(), i); + char tmpdir[96], src[128], outbin[128], errf[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/mxst_%d_d_%d", getpid(), i); - snprintf(errf, sizeof errf, "/tmp/mxst_%d_e_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/mxst_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/mxst_%d_%d", tmpdir, getpid(), i); + snprintf(errf, sizeof errf, "%s/err", tmpdir); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s >/dev/null 2>%s", - tmpdir, driver, src, errf); + snprintf(cmd, sizeof cmd, "%s build -o %s %s >/dev/null 2>%s", + driver, outbin, src, errf); int brc = runwait(cmd); if (brc != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); unlink(errf); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[256]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); unlink(errf); rmdir(tmpdir); + runwait(rmcmd); if (got != r->want) { fprintf(stderr, "row[%s]: %s exit %d, want %d\n", r->label, driver, got, r->want); diff --git a/test/wcc/940_overcap_tuple_field_store_run.c b/test/wcc/940_overcap_tuple_field_store_run.c index 5bb46ae7..44a34e43 100644 --- a/test/wcc/940_overcap_tuple_field_store_run.c +++ b/test/wcc/940_overcap_tuple_field_store_run.c @@ -212,19 +212,21 @@ static const struct row rows[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[96], tmpdir[96], errf[96], cmd[1024]; - snprintf(src, sizeof src, "/tmp/ocf_%d_%d.ww", getpid(), i); + char src[128], tmpdir[96], errf[128], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/ocf_%d_d_%d", getpid(), i); - snprintf(errf, sizeof errf, "/tmp/ocf_%d_e_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/ocf_%d_%d.ww", tmpdir, getpid(), i); + snprintf(errf, sizeof errf, "%s/ocf_%d_e_%d", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/ocf_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s >/dev/null 2>%s", - tmpdir, driver, src, errf); + snprintf(cmd, sizeof cmd, "%s build -o %s %s >/dev/null 2>%s", + driver, outbin, src, errf); int brc = runwait(cmd); if (r->kind == K_BUILDERR) { @@ -233,26 +235,20 @@ run_driver(const char *driver, const struct row *r, int i) if (!ok) fprintf(stderr, "row[%s]: %s expected loud #234-tail " "builderr (brc=%d)\n", r->label, driver, brc); - unlink(src); unlink(errf); rmdir(tmpdir); + runwait(rmcmd); return ok ? 0 : 1; } if (brc != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); unlink(errf); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[256]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); unlink(errf); rmdir(tmpdir); + runwait(rmcmd); if (got != r->want) { fprintf(stderr, "row[%s]: %s exit %d, want %d\n", r->label, driver, got, r->want); diff --git a/test/wcc/940_str_forrange_loopvar_run.c b/test/wcc/940_str_forrange_loopvar_run.c index 3e28df1a..223db149 100644 --- a/test/wcc/940_str_forrange_loopvar_run.c +++ b/test/wcc/940_str_forrange_loopvar_run.c @@ -28,7 +28,6 @@ */ #include #include -#include #include #include #include @@ -80,34 +79,29 @@ static const struct row rows[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[96], tmpdir[96], cmd[1024]; - snprintf(src, sizeof src, "/tmp/strforrange_%d_%d.ww", getpid(), i); + char tmpdir[96], src[160], outbin[160], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/strforrange_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/strforrange_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/strforrange_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s", driver, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[160]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return got; } diff --git a/test/wcc/940_tuple_in_union_run.c b/test/wcc/940_tuple_in_union_run.c index 02e27077..ab5e12ea 100644 --- a/test/wcc/940_tuple_in_union_run.c +++ b/test/wcc/940_tuple_in_union_run.c @@ -207,19 +207,21 @@ static const struct row rows[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[96], tmpdir[96], errf[96], cmd[1024]; - snprintf(src, sizeof src, "/tmp/tiu_%d_%d.ww", getpid(), i); + char src[128], tmpdir[96], errf[128], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/tiu_%d_d_%d", getpid(), i); - snprintf(errf, sizeof errf, "/tmp/tiu_%d_e_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/tiu_%d_%d.ww", tmpdir, getpid(), i); + snprintf(errf, sizeof errf, "%s/tiu_%d_e_%d", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/tiu_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s >/dev/null 2>%s", - tmpdir, driver, src, errf); + snprintf(cmd, sizeof cmd, "%s build -o %s %s >/dev/null 2>%s", + driver, outbin, src, errf); int brc = runwait(cmd); if (r->kind == K_BUILDERR) { @@ -228,26 +230,20 @@ run_driver(const char *driver, const struct row *r, int i) if (!ok) fprintf(stderr, "row[%s]: %s expected loud #242 builderr " "(brc=%d)\n", r->label, driver, brc); - unlink(src); unlink(errf); rmdir(tmpdir); + runwait(rmcmd); return ok ? 0 : 1; } if (brc != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); unlink(errf); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[256]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); unlink(errf); rmdir(tmpdir); + runwait(rmcmd); if (got != r->want) { fprintf(stderr, "row[%s]: %s exit %d, want %d\n", r->label, driver, got, r->want); diff --git a/test/wcc/941_tuple_slot_layout_run.c b/test/wcc/941_tuple_slot_layout_run.c index 463d2682..9f525c7b 100644 --- a/test/wcc/941_tuple_slot_layout_run.c +++ b/test/wcc/941_tuple_slot_layout_run.c @@ -2137,19 +2137,22 @@ static const struct row rows[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[96], tmpdir[96], errf[96], cmd[1024]; - snprintf(src, sizeof src, "/tmp/tsl_%d_%d.ww", getpid(), i); + char tmpdir[96], src[128], outbin[128], errf[128]; + char rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/tsl_%d_d_%d", getpid(), i); - snprintf(errf, sizeof errf, "/tmp/tsl_%d_e_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/tsl_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/tsl_%d_%d", tmpdir, getpid(), i); + snprintf(errf, sizeof errf, "%s/err", tmpdir); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s >/dev/null 2>%s", - tmpdir, driver, src, errf); + snprintf(cmd, sizeof cmd, "%s build -o %s %s >/dev/null 2>%s", + driver, outbin, src, errf); int brc = runwait(cmd); if (r->kind == K_BUILDERR) { int ok = (brc != 0) @@ -2158,25 +2161,19 @@ run_driver(const char *driver, const struct row *r, int i) fprintf(stderr, "row[%s]: %s expected loud builderr " "\"%s\" (brc=%d)\n", r->label, driver, r->experr ? r->experr : "", brc); - unlink(src); unlink(errf); rmdir(tmpdir); + runwait(rmcmd); return ok ? 0 : 1; } if (brc != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); unlink(errf); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[256]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); unlink(errf); rmdir(tmpdir); + runwait(rmcmd); if (got != r->want) { fprintf(stderr, "row[%s]: %s exit %d, want %d\n", r->label, driver, got, r->want); diff --git a/test/wcc/944_alias_accept_run.c b/test/wcc/944_alias_accept_run.c index 5e567026..2e7cdd97 100644 --- a/test/wcc/944_alias_accept_run.c +++ b/test/wcc/944_alias_accept_run.c @@ -1212,20 +1212,24 @@ static const struct row rows[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[96], tmpdir[96], errf[96], cmd[1024]; - snprintf(src, sizeof src, "/tmp/aac_%d_%d.ww", getpid(), i); + char tmpdir[96], src[160], errf[160], outbin[160], cmd[1024], rmcmd[200]; snprintf(tmpdir, sizeof tmpdir, "/tmp/aac_%d_d_%d", getpid(), i); - snprintf(errf, sizeof errf, "/tmp/aac_%d_e_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/aac_%d_%d.ww", tmpdir, getpid(), i); + snprintf(errf, sizeof errf, "%s/err", tmpdir); + snprintf(outbin, sizeof outbin, "%s/aac_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); + /* #8: -o pins binary + .sepwork scratch under tmpdir; rm -rf on + * every exit path removes the now-non-empty dir. */ snprintf(cmd, sizeof cmd, - "cd %s && timeout 20 %s build %s >/dev/null 2>%s", - tmpdir, driver, src, errf); + "timeout 20 %s build -o %s %s >/dev/null 2>%s", + driver, outbin, src, errf); int brc = runwait(cmd); if (r->kind == K_BUILDERR || r->kind == K_BUILDERR_CS) { int ok = (brc != 0) @@ -1234,25 +1238,19 @@ run_driver(const char *driver, const struct row *r, int i) fprintf(stderr, "row[%s]: %s expected loud builderr " "\"%s\" (brc=%d)\n", r->label, driver, r->experr ? r->experr : "", brc); - unlink(src); unlink(errf); rmdir(tmpdir); + runwait(rmcmd); return ok ? 0 : 1; } if (brc != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); unlink(errf); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[256]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); unlink(errf); rmdir(tmpdir); + runwait(rmcmd); if (got != r->want) { fprintf(stderr, "row[%s]: %s exit %d, want %d\n", r->label, driver, got, r->want); diff --git a/test/wcc/944_alias_cgen_b5_run.c b/test/wcc/944_alias_cgen_b5_run.c index c3b5241e..d14b54a4 100644 --- a/test/wcc/944_alias_cgen_b5_run.c +++ b/test/wcc/944_alias_cgen_b5_run.c @@ -651,20 +651,22 @@ static int run_driver(const char *driver, const struct row *r, int i, int expect_err, int want) { - char src[96], tmpdir[96], errf[96], cmd[1024]; - snprintf(src, sizeof src, "/tmp/ab5_%d_%d.ww", getpid(), i); + char tmpdir[96], src[160], outbin[160], errf[160], rmcmd[176], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/ab5_%d_d_%d", getpid(), i); - snprintf(errf, sizeof errf, "/tmp/ab5_%d_e_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/ab5_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/ab5_%d_%d", tmpdir, getpid(), i); + snprintf(errf, sizeof errf, "%s/err", tmpdir); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); snprintf(cmd, sizeof cmd, - "cd %s && timeout 20 %s build %s >/dev/null 2>%s", - tmpdir, driver, src, errf); + "timeout 20 %s build -o %s %s >/dev/null 2>%s", + driver, outbin, src, errf); int brc = runwait(cmd); if (expect_err) { int ok = (brc != 0) @@ -673,25 +675,19 @@ run_driver(const char *driver, const struct row *r, int i, int expect_err, fprintf(stderr, "row[%s]: %s expected loud builderr " "\"%s\" (brc=%d)\n", r->label, driver, r->experr ? r->experr : "", brc); - unlink(src); unlink(errf); rmdir(tmpdir); + runwait(rmcmd); return ok ? 0 : 1; } if (brc != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); unlink(errf); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[256]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); unlink(errf); rmdir(tmpdir); + runwait(rmcmd); if (got != want) { fprintf(stderr, "row[%s]: %s exit %d, want %d\n", r->label, driver, got, want); diff --git a/test/wcc/944_alias_cgen_b6_run.c b/test/wcc/944_alias_cgen_b6_run.c index 538fe088..0e5af5bb 100644 --- a/test/wcc/944_alias_cgen_b6_run.c +++ b/test/wcc/944_alias_cgen_b6_run.c @@ -556,20 +556,23 @@ static int run_driver(const char *driver, const struct row *r, int i, int expect_err, int want, const char *experr) { - char src[96], tmpdir[96], errf[96], cmd[1024]; - snprintf(src, sizeof src, "/tmp/ab6_%d_%d.ww", getpid(), i); + char tmpdir[96], src[128], outbin[128], errf[128], rmcmd[160]; + char cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/ab6_%d_d_%d", getpid(), i); - snprintf(errf, sizeof errf, "/tmp/ab6_%d_e_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/ab6_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/ab6_%d_%d", tmpdir, getpid(), i); + snprintf(errf, sizeof errf, "%s/err", tmpdir); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); snprintf(cmd, sizeof cmd, - "cd %s && timeout 20 %s build %s >/dev/null 2>%s", - tmpdir, driver, src, errf); + "timeout 20 %s build -o %s %s >/dev/null 2>%s", + driver, outbin, src, errf); int brc = runwait(cmd); if (expect_err) { int ok = (brc != 0) @@ -578,25 +581,19 @@ run_driver(const char *driver, const struct row *r, int i, int expect_err, fprintf(stderr, "row[%s]: %s expected loud builderr " "\"%s\" (brc=%d)\n", r->label, driver, experr ? experr : "", brc); - unlink(src); unlink(errf); rmdir(tmpdir); + runwait(rmcmd); return ok ? 0 : 1; } if (brc != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); unlink(errf); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[256]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); unlink(errf); rmdir(tmpdir); + runwait(rmcmd); if (got != want) { fprintf(stderr, "row[%s]: %s exit %d, want %d\n", r->label, driver, got, want); diff --git a/test/wcc/944_alias_decl_order_size_run.c b/test/wcc/944_alias_decl_order_size_run.c index c464850b..be90315f 100644 --- a/test/wcc/944_alias_decl_order_size_run.c +++ b/test/wcc/944_alias_decl_order_size_run.c @@ -297,22 +297,24 @@ static const struct row rows[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[96], tmpdir[96], errf[96], cmd[1024]; - snprintf(src, sizeof src, "/tmp/ados_%d_%d.ww", getpid(), i); + char tmpdir[96], src[160], outbin[160], errf[160], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/ados_%d_d_%d", getpid(), i); - snprintf(errf, sizeof errf, "/tmp/ados_%d_e_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/ados_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/ados_%d_%d", tmpdir, getpid(), i); + snprintf(errf, sizeof errf, "%s/err", tmpdir); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); /* timeout: the pre-#69 wwstage HANG on a cycle must fail the row, * not wedge the suite. */ snprintf(cmd, sizeof cmd, - "cd %s && timeout 20 %s build %s >/dev/null 2>%s", - tmpdir, driver, src, errf); + "timeout 20 %s build -o %s %s >/dev/null 2>%s", + driver, outbin, src, errf); int brc = runwait(cmd); if (r->kind == K_BUILDERR) { int ok = (brc != 0) @@ -321,25 +323,19 @@ run_driver(const char *driver, const struct row *r, int i) fprintf(stderr, "row[%s]: %s expected loud builderr " "\"%s\" (brc=%d)\n", r->label, driver, r->experr ? r->experr : "", brc); - unlink(src); unlink(errf); rmdir(tmpdir); + runwait(rmcmd); return ok ? 0 : 1; } if (brc != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); unlink(errf); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[256]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); unlink(errf); rmdir(tmpdir); + runwait(rmcmd); if (got != r->want) { fprintf(stderr, "row[%s]: %s exit %d, want %d\n", r->label, driver, got, r->want); diff --git a/test/wcc/944_alias_emit_b7_run.c b/test/wcc/944_alias_emit_b7_run.c index dc2bf783..42a98032 100644 --- a/test/wcc/944_alias_emit_b7_run.c +++ b/test/wcc/944_alias_emit_b7_run.c @@ -299,20 +299,22 @@ static int run_driver(const char *driver, const struct row *r, int i, int expect_err, int want, const char *experr) { - char src[96], tmpdir[96], errf[96], cmd[1024]; - snprintf(src, sizeof src, "/tmp/ab7_%d_%d.ww", getpid(), i); + char tmpdir[96], src[160], outbin[160], errf[160], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/ab7_%d_d_%d", getpid(), i); - snprintf(errf, sizeof errf, "/tmp/ab7_%d_e_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/ab7_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/ab7_%d_%d", tmpdir, getpid(), i); + snprintf(errf, sizeof errf, "%s/err", tmpdir); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); snprintf(cmd, sizeof cmd, - "cd %s && timeout 20 %s build %s >/dev/null 2>%s", - tmpdir, driver, src, errf); + "timeout 20 %s build -o %s %s >/dev/null 2>%s", + driver, outbin, src, errf); int brc = runwait(cmd); if (expect_err) { int ok = (brc != 0) @@ -321,25 +323,19 @@ run_driver(const char *driver, const struct row *r, int i, int expect_err, fprintf(stderr, "row[%s]: %s expected loud builderr " "\"%s\" (brc=%d)\n", r->label, driver, experr ? experr : "", brc); - unlink(src); unlink(errf); rmdir(tmpdir); + runwait(rmcmd); return ok ? 0 : 1; } if (brc != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); unlink(errf); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[256]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); unlink(errf); rmdir(tmpdir); + runwait(rmcmd); if (got != want) { fprintf(stderr, "row[%s]: %s exit %d, want %d\n", r->label, driver, got, want); diff --git a/test/wcc/944_alias_global_decl_run.c b/test/wcc/944_alias_global_decl_run.c index 972de889..10b3249a 100644 --- a/test/wcc/944_alias_global_decl_run.c +++ b/test/wcc/944_alias_global_decl_run.c @@ -72,7 +72,6 @@ */ #include #include -#include #include #include #include @@ -338,37 +337,33 @@ static const struct row rows[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[96], tmpdir[96], errf[96], cmd[1024]; - snprintf(src, sizeof src, "/tmp/agd_%d_%d.ww", getpid(), i); + char tmpdir[96], src[160], outbin[160], errf[160], rmcmd[176], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/agd_%d_d_%d", getpid(), i); - snprintf(errf, sizeof errf, "/tmp/agd_%d_e_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/agd_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/agd_%d_%d", tmpdir, getpid(), i); + snprintf(errf, sizeof errf, "%s/err", tmpdir); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); snprintf(cmd, sizeof cmd, - "cd %s && timeout 20 %s build %s >/dev/null 2>%s", - tmpdir, driver, src, errf); + "timeout 20 %s build -o %s %s >/dev/null 2>%s", + driver, outbin, src, errf); int brc = runwait(cmd); if (brc != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); unlink(errf); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[256]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); unlink(errf); rmdir(tmpdir); + runwait(rmcmd); if (got != r->want) { fprintf(stderr, "row[%s]: %s exit %d, want %d\n", r->label, driver, got, r->want); diff --git a/test/wcc/944_alias_idx_family_run.c b/test/wcc/944_alias_idx_family_run.c index cfb76c61..d67f7000 100644 --- a/test/wcc/944_alias_idx_family_run.c +++ b/test/wcc/944_alias_idx_family_run.c @@ -59,7 +59,6 @@ */ #include #include -#include #include #include #include @@ -357,37 +356,33 @@ static const struct row rows[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[96], tmpdir[96], errf[96], cmd[1024]; - snprintf(src, sizeof src, "/tmp/aif_%d_%d.ww", getpid(), i); + char src[128], tmpdir[96], outbin[128], errf[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/aif_%d_d_%d", getpid(), i); - snprintf(errf, sizeof errf, "/tmp/aif_%d_e_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/aif_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/aif_%d_%d", tmpdir, getpid(), i); + snprintf(errf, sizeof errf, "%s/err", tmpdir); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); snprintf(cmd, sizeof cmd, - "cd %s && timeout 20 %s build %s >/dev/null 2>%s", - tmpdir, driver, src, errf); + "timeout 20 %s build -o %s %s >/dev/null 2>%s", + driver, outbin, src, errf); int brc = runwait(cmd); if (brc != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); unlink(errf); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[256]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); unlink(errf); rmdir(tmpdir); + runwait(rmcmd); if (got != r->want) { fprintf(stderr, "row[%s]: %s exit %d, want %d\n", r->label, driver, got, r->want); diff --git a/test/wcc/944_alias_structlit_init_run.c b/test/wcc/944_alias_structlit_init_run.c index b5862c2c..42d905d3 100644 --- a/test/wcc/944_alias_structlit_init_run.c +++ b/test/wcc/944_alias_structlit_init_run.c @@ -48,7 +48,6 @@ */ #include #include -#include #include #include #include @@ -134,37 +133,33 @@ static const struct row rows[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[96], tmpdir[96], errf[96], cmd[1024]; - snprintf(src, sizeof src, "/tmp/asli_%d_%d.ww", getpid(), i); + char tmpdir[96], src[128], outbin[128], errf[128], rmcmd[128], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/asli_%d_d_%d", getpid(), i); - snprintf(errf, sizeof errf, "/tmp/asli_%d_e_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/asli_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/asli_%d_%d", tmpdir, getpid(), i); + snprintf(errf, sizeof errf, "%s/err", tmpdir); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); snprintf(cmd, sizeof cmd, - "cd %s && timeout 20 %s build %s >/dev/null 2>%s", - tmpdir, driver, src, errf); + "timeout 20 %s build -o %s %s >/dev/null 2>%s", + driver, outbin, src, errf); int brc = runwait(cmd); if (brc != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); unlink(errf); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[256]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); unlink(errf); rmdir(tmpdir); + runwait(rmcmd); if (got != r->want) { fprintf(stderr, "row[%s]: %s exit %d, want %d\n", r->label, driver, got, r->want); diff --git a/test/wcc/944_array_zeroinit_run.c b/test/wcc/944_array_zeroinit_run.c index e7cb85fb..8c45076e 100644 --- a/test/wcc/944_array_zeroinit_run.c +++ b/test/wcc/944_array_zeroinit_run.c @@ -34,7 +34,6 @@ */ #include #include -#include #include #include #include @@ -108,37 +107,33 @@ static const struct row rows[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[96], tmpdir[96], errf[96], cmd[1024]; - snprintf(src, sizeof src, "/tmp/azi_%d_%d.ww", getpid(), i); + char tmpdir[96], src[160], outbin[160], errf[160], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/azi_%d_d_%d", getpid(), i); - snprintf(errf, sizeof errf, "/tmp/azi_%d_e_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/azi_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/azi_%d_%d", tmpdir, getpid(), i); + snprintf(errf, sizeof errf, "%s/err", tmpdir); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); snprintf(cmd, sizeof cmd, - "cd %s && timeout 20 %s build %s >/dev/null 2>%s", - tmpdir, driver, src, errf); + "timeout 20 %s build -o %s %s >/dev/null 2>%s", + driver, outbin, src, errf); int brc = runwait(cmd); if (brc != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); unlink(errf); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[256]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); unlink(errf); rmdir(tmpdir); + runwait(rmcmd); if (got != r->want) { fprintf(stderr, "row[%s]: %s exit %d, want %d\n", r->label, driver, got, r->want); diff --git a/test/wcc/944_idx_tagged_field_run.c b/test/wcc/944_idx_tagged_field_run.c index 9afeedb9..4ede87a8 100644 --- a/test/wcc/944_idx_tagged_field_run.c +++ b/test/wcc/944_idx_tagged_field_run.c @@ -215,61 +215,62 @@ file_has(const char *path, const char *needle) static int run_cfail(const char *driver, const struct cfrow *r, int i) { - char src[96], errf[96], cmd[1024]; - snprintf(src, sizeof src, "/tmp/itf_cf_%d_%d.ww", getpid(), i); - snprintf(errf, sizeof errf, "/tmp/itf_cf_%d_e_%d", getpid(), i); + char tmpdir[96], src[160], outbin[160], errf[160], rmcmd[176], cmd[1024]; + snprintf(tmpdir, sizeof tmpdir, "/tmp/itf_cf_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/itf_cf_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/itf_cf_%d_%d", tmpdir, getpid(), i); + snprintf(errf, sizeof errf, "%s/err", tmpdir); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); snprintf(cmd, sizeof cmd, - "timeout 20 %s build %s >/dev/null 2>%s", driver, src, errf); + "timeout 20 %s build -o %s %s >/dev/null 2>%s", + driver, outbin, src, errf); int brc = runwait(cmd); int ok = (brc != 0) && file_has(errf, "#58"); if (!ok) fprintf(stderr, "row[%s]: %s build rc=%d, want CFAIL with \"#58\" tripwire\n", r->label, driver, brc); - unlink(src); unlink(errf); + runwait(rmcmd); return ok ? 0 : 1; } static int run_driver(const char *driver, const struct row *r, int i) { - char src[96], tmpdir[96], errf[96], cmd[1024]; - snprintf(src, sizeof src, "/tmp/itf_%d_%d.ww", getpid(), i); + char tmpdir[96], src[160], outbin[160], errf[160], rmcmd[176], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/itf_%d_d_%d", getpid(), i); - snprintf(errf, sizeof errf, "/tmp/itf_%d_e_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/itf_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/itf_%d_%d", tmpdir, getpid(), i); + snprintf(errf, sizeof errf, "%s/err", tmpdir); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); snprintf(cmd, sizeof cmd, - "cd %s && timeout 20 %s build %s >/dev/null 2>%s", - tmpdir, driver, src, errf); + "timeout 20 %s build -o %s %s >/dev/null 2>%s", + driver, outbin, src, errf); int brc = runwait(cmd); if (brc != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); unlink(errf); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[256]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); unlink(errf); rmdir(tmpdir); + runwait(rmcmd); if (got != r->want) { fprintf(stderr, "row[%s]: %s exit %d, want %d\n", r->label, driver, got, r->want); diff --git a/test/wcc/944_nonlit_tuple_widen_run.c b/test/wcc/944_nonlit_tuple_widen_run.c index aeeebb77..857b89f8 100644 --- a/test/wcc/944_nonlit_tuple_widen_run.c +++ b/test/wcc/944_nonlit_tuple_widen_run.c @@ -41,7 +41,6 @@ */ #include #include -#include #include #include #include @@ -181,35 +180,31 @@ static const struct row rows[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[96], tmpdir[96], cmd[1024]; - snprintf(src, sizeof src, "/tmp/ntw_%d_%d.ww", getpid(), i); + char tmpdir[96], src[128], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/ntw_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/ntw_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/ntw_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s >/dev/null 2>&1", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s >/dev/null 2>&1", + driver, outbin, src); int brc = runwait(cmd); if (brc != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[256]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); if (got != r->want) { fprintf(stderr, "row[%s]: %s exit %d, want %d\n", r->label, driver, got, r->want); diff --git a/test/wcc/944_tagged_widen_arg_run.c b/test/wcc/944_tagged_widen_arg_run.c index 9d1164b4..ef106163 100644 --- a/test/wcc/944_tagged_widen_arg_run.c +++ b/test/wcc/944_tagged_widen_arg_run.c @@ -45,7 +45,6 @@ */ #include #include -#include #include #include #include @@ -169,37 +168,33 @@ static const struct row rows[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[96], tmpdir[96], errf[96], cmd[1024]; - snprintf(src, sizeof src, "/tmp/twa_%d_%d.ww", getpid(), i); + char src[128], tmpdir[96], errf[128], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/twa_%d_d_%d", getpid(), i); - snprintf(errf, sizeof errf, "/tmp/twa_%d_e_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/twa_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/twa_%d_%d", tmpdir, getpid(), i); + snprintf(errf, sizeof errf, "%s/err", tmpdir); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); snprintf(cmd, sizeof cmd, - "cd %s && timeout 20 %s build %s >/dev/null 2>%s", - tmpdir, driver, src, errf); + "timeout 20 %s build -o %s %s >/dev/null 2>%s", + driver, outbin, src, errf); int brc = runwait(cmd); if (brc != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); unlink(errf); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[256]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); unlink(errf); rmdir(tmpdir); + runwait(rmcmd); if (got != r->want) { fprintf(stderr, "row[%s]: %s exit %d, want %d\n", r->label, driver, got, r->want); diff --git a/test/wcc/944_tuple_tagged_union_run.c b/test/wcc/944_tuple_tagged_union_run.c index 45c3b0b7..868cf43b 100644 --- a/test/wcc/944_tuple_tagged_union_run.c +++ b/test/wcc/944_tuple_tagged_union_run.c @@ -33,7 +33,6 @@ */ #include #include -#include #include #include #include @@ -183,37 +182,33 @@ static const struct row rows[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[96], tmpdir[96], errf[96], cmd[1024]; + char src[128], tmpdir[96], outbin[128], errf[128], rmcmd[160], cmd[1024]; - snprintf(src, sizeof src, "/tmp/ttu_%d_%d.ww", getpid(), i); snprintf(tmpdir, sizeof tmpdir, "/tmp/ttu_%d_d_%d", getpid(), i); - snprintf(errf, sizeof errf, "/tmp/ttu_%d_e_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/ttu_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/ttu_%d_%d", tmpdir, getpid(), i); + snprintf(errf, sizeof errf, "%s/err", tmpdir); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s >/dev/null 2>%s", - tmpdir, driver, src, errf); + snprintf(cmd, sizeof cmd, "%s build -o %s %s >/dev/null 2>%s", + driver, outbin, src, errf); int brc = runwait(cmd); if (brc != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); unlink(errf); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[256]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); unlink(errf); rmdir(tmpdir); + runwait(rmcmd); if (got != r->want) { fprintf(stderr, "row[%s]: %s exit %d, want %d\n", r->label, driver, got, r->want); diff --git a/test/wcc/944_variant_chain_b95_run.c b/test/wcc/944_variant_chain_b95_run.c index feda503d..266580dc 100644 --- a/test/wcc/944_variant_chain_b95_run.c +++ b/test/wcc/944_variant_chain_b95_run.c @@ -435,20 +435,23 @@ static int run_driver(const char *driver, const struct row *r, int i, int expect_err, int want) { - char src[96], tmpdir[96], errf[96], cmd[1024]; - snprintf(src, sizeof src, "/tmp/vc95_%d_%d.ww", getpid(), i); + char tmpdir[96], src[128], outbin[128], errf[128], rmcmd[160]; + char cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/vc95_%d_d_%d", getpid(), i); - snprintf(errf, sizeof errf, "/tmp/vc95_%d_e_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/vc95_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/vc95_%d_%d", tmpdir, getpid(), i); + snprintf(errf, sizeof errf, "%s/err", tmpdir); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); snprintf(cmd, sizeof cmd, - "cd %s && timeout 20 %s build %s >/dev/null 2>%s", - tmpdir, driver, src, errf); + "timeout 20 %s build -o %s %s >/dev/null 2>%s", + driver, outbin, src, errf); int brc = runwait(cmd); if (expect_err) { int ok = (brc != 0) @@ -457,25 +460,19 @@ run_driver(const char *driver, const struct row *r, int i, int expect_err, fprintf(stderr, "row[%s]: %s expected loud builderr " "\"%s\" (brc=%d)\n", r->label, driver, r->experr ? r->experr : "", brc); - unlink(src); unlink(errf); rmdir(tmpdir); + runwait(rmcmd); return ok ? 0 : 1; } if (brc != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); unlink(errf); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[256]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); unlink(errf); rmdir(tmpdir); + runwait(rmcmd); if (got != want) { fprintf(stderr, "row[%s]: %s exit %d, want %d\n", r->label, driver, got, want); diff --git a/test/wcc/945_rvalue_tuple_destructure_run.c b/test/wcc/945_rvalue_tuple_destructure_run.c index 83c6f130..8471b565 100644 --- a/test/wcc/945_rvalue_tuple_destructure_run.c +++ b/test/wcc/945_rvalue_tuple_destructure_run.c @@ -35,7 +35,6 @@ */ #include #include -#include #include #include #include @@ -115,36 +114,32 @@ static const struct row rows[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[96], tmpdir[96], errf[96], cmd[1024]; - snprintf(src, sizeof src, "/tmp/rvtd_%d_%d.ww", getpid(), i); + char src[128], tmpdir[96], errf[128], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/rvtd_%d_d_%d", getpid(), i); - snprintf(errf, sizeof errf, "/tmp/rvtd_%d_e_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/rvtd_%d_%d.ww", tmpdir, getpid(), i); + snprintf(errf, sizeof errf, "%s/err", tmpdir); + snprintf(outbin, sizeof outbin, "%s/rvtd_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s >/dev/null 2>%s", - tmpdir, driver, src, errf); + snprintf(cmd, sizeof cmd, "%s build -o %s %s >/dev/null 2>%s", + driver, outbin, src, errf); int brc = runwait(cmd); if (brc != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); unlink(errf); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[256]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); unlink(errf); rmdir(tmpdir); + runwait(rmcmd); if (got != r->want) { fprintf(stderr, "row[%s]: %s exit %d, want %d\n", r->label, driver, got, r->want); diff --git a/test/wcc/945_tuple_lit_declblind_run.c b/test/wcc/945_tuple_lit_declblind_run.c index e7d68357..8ff70b57 100644 --- a/test/wcc/945_tuple_lit_declblind_run.c +++ b/test/wcc/945_tuple_lit_declblind_run.c @@ -48,7 +48,6 @@ */ #include #include -#include #include #include #include @@ -148,19 +147,21 @@ static const struct row rows[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[96], tmpdir[96], errf[96], cmd[1024]; - snprintf(src, sizeof src, "/tmp/tldb_%d_%d.ww", getpid(), i); + char tmpdir[96], src[128], outbin[128], errf[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/tldb_%d_d_%d", getpid(), i); - snprintf(errf, sizeof errf, "/tmp/tldb_%d_e_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/tldb_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/tldb_%d_%d", tmpdir, getpid(), i); + snprintf(errf, sizeof errf, "%s/err", tmpdir); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s >/dev/null 2>%s", - tmpdir, driver, src, errf); + snprintf(cmd, sizeof cmd, "%s build -o %s %s >/dev/null 2>%s", + driver, outbin, src, errf); int brc = runwait(cmd); /* ERR row: the rule-7 loud arm must fire — build FAILS (nonzero). A * clean build means the preserved loudness regressed. */ @@ -169,25 +170,19 @@ run_driver(const char *driver, const struct row *r, int i) if (!ok) fprintf(stderr, "row[%s]: %s built clean, expected " "rule-7 loud build-fail\n", r->label, driver); - unlink(src); unlink(errf); rmdir(tmpdir); + runwait(rmcmd); return ok ? 0 : 1; } if (brc != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); unlink(errf); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[256]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); unlink(errf); rmdir(tmpdir); + runwait(rmcmd); if (got != r->want) { fprintf(stderr, "row[%s]: %s exit %d, want %d\n", r->label, driver, got, r->want); diff --git a/test/wcc/945_tuple_nary_destructure_run.c b/test/wcc/945_tuple_nary_destructure_run.c index 19f9b19d..6d649265 100644 --- a/test/wcc/945_tuple_nary_destructure_run.c +++ b/test/wcc/945_tuple_nary_destructure_run.c @@ -248,19 +248,21 @@ file_contains(const char *path, const char *needle) static int run_driver(const char *driver, const struct row *r, int i) { - char src[96], tmpdir[96], errf[96], cmd[1024]; - snprintf(src, sizeof src, "/tmp/tuplenary_%d_%d.ww", getpid(), i); + char tmpdir[96], src[128], outbin[128], errf[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/tuplenary_%d_d_%d", getpid(), i); - snprintf(errf, sizeof errf, "/tmp/tuplenary_%d_e_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/tuplenary_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/tuplenary_%d_%d", tmpdir, getpid(), i); + snprintf(errf, sizeof errf, "%s/err", tmpdir); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s >/dev/null 2>%s", - tmpdir, driver, src, errf); + snprintf(cmd, sizeof cmd, "%s build -o %s %s >/dev/null 2>%s", + driver, outbin, src, errf); int brc = runwait(cmd); if (r->builderr) { @@ -270,26 +272,20 @@ run_driver(const char *driver, const struct row *r, int i) fprintf(stderr, "row[%s]: %s expected loud-stop builderr (brc=%d)\n", r->label, driver, brc); - unlink(src); unlink(errf); rmdir(tmpdir); + runwait(rmcmd); return ok ? 0 : 1; } if (brc != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); unlink(errf); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[160]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); unlink(errf); rmdir(tmpdir); + runwait(rmcmd); return (got == r->want) ? 0 : (got ? got : 1); } diff --git a/test/wcc/946_append_structlit_evalorder_run.c b/test/wcc/946_append_structlit_evalorder_run.c index 2c33ab11..17ea21b6 100644 --- a/test/wcc/946_append_structlit_evalorder_run.c +++ b/test/wcc/946_append_structlit_evalorder_run.c @@ -27,7 +27,6 @@ */ #include #include -#include #include #include #include @@ -126,36 +125,32 @@ static const struct row rows[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[96], tmpdir[96], errf[96], cmd[1024]; - snprintf(src, sizeof src, "/tmp/ase_%d_%d.ww", getpid(), i); + char src[128], tmpdir[96], errf[128], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/ase_%d_d_%d", getpid(), i); - snprintf(errf, sizeof errf, "/tmp/ase_%d_e_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/ase_%d_%d.ww", tmpdir, getpid(), i); + snprintf(errf, sizeof errf, "%s/ase_%d_e_%d", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/ase_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s >/dev/null 2>%s", - tmpdir, driver, src, errf); + snprintf(cmd, sizeof cmd, "%s build -o %s %s >/dev/null 2>%s", + driver, outbin, src, errf); int brc = runwait(cmd); if (brc != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); unlink(errf); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[256]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); unlink(errf); rmdir(tmpdir); + runwait(rmcmd); if (got != r->want) { fprintf(stderr, "row[%s]: %s exit %d, want %d\n", r->label, driver, got, r->want); diff --git a/test/wcc/946_const_slice_aggregate_run.c b/test/wcc/946_const_slice_aggregate_run.c index 039026d4..62044b45 100644 --- a/test/wcc/946_const_slice_aggregate_run.c +++ b/test/wcc/946_const_slice_aggregate_run.c @@ -178,19 +178,21 @@ static const struct row rows[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[96], tmpdir[96], errf[96], cmd[1024]; - snprintf(src, sizeof src, "/tmp/csa_%d_%d.ww", getpid(), i); + char tmpdir[96], src[128], outbin[128], errf[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/csa_%d_d_%d", getpid(), i); - snprintf(errf, sizeof errf, "/tmp/csa_%d_e_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/csa_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/csa_%d_%d", tmpdir, getpid(), i); + snprintf(errf, sizeof errf, "%s/err", tmpdir); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s >/dev/null 2>%s", - tmpdir, driver, src, errf); + snprintf(cmd, sizeof cmd, "%s build -o %s %s >/dev/null 2>%s", + driver, outbin, src, errf); int brc = runwait(cmd); if (r->kind == K_BUILDERR) { int ok = (brc != 0) @@ -199,25 +201,19 @@ run_driver(const char *driver, const struct row *r, int i) fprintf(stderr, "row[%s]: %s expected loud builderr " "\"%s\" (brc=%d)\n", r->label, driver, r->experr ? r->experr : "", brc); - unlink(src); unlink(errf); rmdir(tmpdir); + runwait(rmcmd); return ok ? 0 : 1; } if (brc != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); unlink(errf); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[256]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); unlink(errf); rmdir(tmpdir); + runwait(rmcmd); if (got != r->want) { fprintf(stderr, "row[%s]: %s exit %d, want %d\n", r->label, driver, got, r->want); diff --git a/test/wcc/946_floatarr_run.c b/test/wcc/946_floatarr_run.c index 6cee6a96..dafefe2f 100644 --- a/test/wcc/946_floatarr_run.c +++ b/test/wcc/946_floatarr_run.c @@ -34,7 +34,6 @@ */ #include #include -#include #include #include #include @@ -158,67 +157,62 @@ main(void) int n = 0, fail = 0; for (int i = 0; rows[i].src; i++, n++) { - char src[64]; - snprintf(src, sizeof src, "/tmp/wwfarr_%d_%d.ww", getpid(), i); + char tmpdir[64]; + snprintf(tmpdir, sizeof tmpdir, "/tmp/wwfarr_%d_d_%d", + getpid(), i); + mkdir(tmpdir, 0755); + + char src[128], outbin[128], cs_s[128], ws_s[128], rmcmd[160]; + snprintf(src, sizeof src, "%s/wwfarr_%d_%d.ww", + tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/wwfarr_%d_%d", + tmpdir, getpid(), i); + snprintf(cs_s, sizeof cs_s, "%s/wwfarr_%d_%d_cs.s", + tmpdir, getpid(), i); + snprintf(ws_s, sizeof ws_s, "%s/wwfarr_%d_%d_ww.s", + tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); + FILE *f = fopen(src, "wb"); - if (f == NULL) { fail++; continue; } + if (f == NULL) { fail++; runwait(rmcmd); continue; } fputs(rows[i].src, f); fclose(f); /* (a) cstage build + run (skipped for byte-id-only rows). */ if (rows[i].want_exit != RUN_SKIP) { - char tmpdir[64]; - snprintf(tmpdir, sizeof tmpdir, "/tmp/wwfarr_%d_d_%d", - getpid(), i); - mkdir(tmpdir, 0755); - char cmd[2048]; - snprintf(cmd, sizeof cmd, "cd %s && %s/ww build %s", - tmpdir, bin, src); + snprintf(cmd, sizeof cmd, "%s/ww build -o %s %s", + bin, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: cstage build failed\n", rows[i].label); fail++; - unlink(src); rmdir(tmpdir); + runwait(rmcmd); continue; } - char outbin[128]; - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; - int got = runwait(outbin); if (got != rows[i].want_exit) { fprintf(stderr, "row[%s]: cstage exit %d, want %d\n", rows[i].label, got, rows[i].want_exit); fail++; } - unlink(outbin); rmdir(tmpdir); } /* (b) cs==ww byte-id gate: emit .s from both stages, cmp. */ - char cs_s[64], ws_s[64]; - snprintf(cs_s, sizeof cs_s, "/tmp/wwfarr_%d_%d_cs.s", - getpid(), i); - snprintf(ws_s, sizeof ws_s, "/tmp/wwfarr_%d_%d_ww.s", - getpid(), i); - char cmd[2048]; snprintf(cmd, sizeof cmd, "%s -o %s %s 2>/dev/null", w6c, cs_s, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: w6c failed\n", rows[i].label); - fail++; unlink(src); continue; + fail++; runwait(rmcmd); continue; } snprintf(cmd, sizeof cmd, "%s -o %s %s 2>/dev/null", w6c_ww, ws_s, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: w6c_ww failed\n", rows[i].label); - fail++; unlink(src); unlink(cs_s); continue; + fail++; runwait(rmcmd); continue; } if (slurp_eq(cs_s, ws_s) != 0) { fprintf(stderr, @@ -226,7 +220,7 @@ main(void) "byte-id violation)\n", rows[i].label); fail++; } - unlink(src); unlink(cs_s); unlink(ws_s); + runwait(rmcmd); } if (fail) { diff --git a/test/wcc/946_structparam_run.c b/test/wcc/946_structparam_run.c index 312a80e4..dbb893e5 100644 --- a/test/wcc/946_structparam_run.c +++ b/test/wcc/946_structparam_run.c @@ -213,65 +213,62 @@ main(void) int n = 0, fail = 0; for (int i = 0; rows[i].src; i++, n++) { - char src[64]; - snprintf(src, sizeof src, "/tmp/wwstp_%d_%d.ww", getpid(), i); + /* src, binary, and both .s files all live under one tmpdir so + * the compiler's path-derived .sepwork scratch stays inside it; + * a single `rm -rf` at the end of all phases reclaims it. */ + char tmpdir[64], src[128], outbin[128]; + char cs_s[128], ws_s[128], rmcmd[160]; + snprintf(tmpdir, sizeof tmpdir, "/tmp/wwstp_%d_d_%d", + getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/wwstp_%d_%d.ww", + tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/wwstp_%d_%d", + tmpdir, getpid(), i); + snprintf(cs_s, sizeof cs_s, "%s/wwstp_%d_%d_cs.s", + tmpdir, getpid(), i); + snprintf(ws_s, sizeof ws_s, "%s/wwstp_%d_%d_ww.s", + tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); + FILE *f = fopen(src, "wb"); - if (f == NULL) { fail++; continue; } + if (f == NULL) { runwait(rmcmd); fail++; continue; } fputs(rows[i].src, f); fclose(f); char cmd[4096]; - /* (a) cstage build + run in a scratch dir. */ - char tmpdir[64]; - snprintf(tmpdir, sizeof tmpdir, "/tmp/wwstp_%d_d_%d", - getpid(), i); - mkdir(tmpdir, 0755); - - snprintf(cmd, sizeof cmd, "cd %s && %s/ww build %s", - tmpdir, bin, src); + /* (a) cstage build + run. */ + snprintf(cmd, sizeof cmd, "%s/ww build -o %s %s", + bin, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: cstage build failed\n", rows[i].label); fail++; - unlink(src); rmdir(tmpdir); + runwait(rmcmd); continue; } - char outbin[128]; - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; - int got = runwait(outbin); if (got != rows[i].want_exit) { fprintf(stderr, "row[%s]: cstage exit %d, want %d\n", rows[i].label, got, rows[i].want_exit); fail++; } - unlink(outbin); rmdir(tmpdir); /* (b) cs==ww byte-id gate: emit .s from both stages, cmp. */ - char cs_s[64], ws_s[64]; - snprintf(cs_s, sizeof cs_s, "/tmp/wwstp_%d_%d_cs.s", - getpid(), i); - snprintf(ws_s, sizeof ws_s, "/tmp/wwstp_%d_%d_ww.s", - getpid(), i); - snprintf(cmd, sizeof cmd, "%s -o %s %s 2>/dev/null", w6c, cs_s, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: w6c failed\n", rows[i].label); - fail++; unlink(src); continue; + fail++; runwait(rmcmd); continue; } snprintf(cmd, sizeof cmd, "%s -o %s %s 2>/dev/null", w6c_ww, ws_s, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: w6c_ww failed\n", rows[i].label); - fail++; unlink(src); unlink(cs_s); continue; + fail++; runwait(rmcmd); continue; } if (slurp_eq(cs_s, ws_s) != 0) { fprintf(stderr, @@ -295,7 +292,7 @@ main(void) rows[i].want_sse ? "present" : "absent"); fail++; } - unlink(src); unlink(cs_s); unlink(ws_s); + runwait(rmcmd); } if (fail) { diff --git a/test/wcc/946_structret_run.c b/test/wcc/946_structret_run.c index 6a2c5eee..eae7d292 100644 --- a/test/wcc/946_structret_run.c +++ b/test/wcc/946_structret_run.c @@ -224,65 +224,63 @@ main(void) int n = 0, fail = 0; for (int i = 0; rows[i].src; i++, n++) { - char src[64]; - snprintf(src, sizeof src, "/tmp/wwsrt_%d_%d.ww", getpid(), i); - FILE *f = fopen(src, "wb"); - if (f == NULL) { fail++; continue; } - fputs(rows[i].src, f); - fclose(f); - - char cmd[4096]; - - /* (a) cstage build + run in a scratch dir. */ + /* src + outbin + cs.s + ww.s all live under one tmpdir so the + * compiler's .sepwork scratch (derived from the src path) lands + * inside it; a single rm -rf at the end clears every phase. */ char tmpdir[64]; snprintf(tmpdir, sizeof tmpdir, "/tmp/wwsrt_%d_d_%d", getpid(), i); mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s/ww build %s", - tmpdir, bin, src); + char src[128], outbin[128], cs_s[128], ws_s[128], rmcmd[160]; + snprintf(src, sizeof src, "%s/wwsrt_%d_%d.ww", + tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/wwsrt_%d_%d", + tmpdir, getpid(), i); + snprintf(cs_s, sizeof cs_s, "%s/wwsrt_%d_%d_cs.s", + tmpdir, getpid(), i); + snprintf(ws_s, sizeof ws_s, "%s/wwsrt_%d_%d_ww.s", + tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); + + FILE *f = fopen(src, "wb"); + if (f == NULL) { runwait(rmcmd); fail++; continue; } + fputs(rows[i].src, f); + fclose(f); + + char cmd[4096]; + + /* (a) cstage build + run. */ + snprintf(cmd, sizeof cmd, "%s/ww build -o %s %s", + bin, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: cstage build failed\n", rows[i].label); fail++; - unlink(src); rmdir(tmpdir); + runwait(rmcmd); continue; } - char outbin[128]; - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; - int got = runwait(outbin); if (got != rows[i].want_exit) { fprintf(stderr, "row[%s]: cstage exit %d, want %d\n", rows[i].label, got, rows[i].want_exit); fail++; } - unlink(outbin); rmdir(tmpdir); /* (b) cs==ww byte-id gate: emit .s from both stages, cmp. */ - char cs_s[64], ws_s[64]; - snprintf(cs_s, sizeof cs_s, "/tmp/wwsrt_%d_%d_cs.s", - getpid(), i); - snprintf(ws_s, sizeof ws_s, "/tmp/wwsrt_%d_%d_ww.s", - getpid(), i); - snprintf(cmd, sizeof cmd, "%s -o %s %s 2>/dev/null", w6c, cs_s, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: w6c failed\n", rows[i].label); - fail++; unlink(src); continue; + fail++; runwait(rmcmd); continue; } snprintf(cmd, sizeof cmd, "%s -o %s %s 2>/dev/null", w6c_ww, ws_s, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: w6c_ww failed\n", rows[i].label); - fail++; unlink(src); unlink(cs_s); continue; + fail++; runwait(rmcmd); continue; } if (slurp_eq(cs_s, ws_s) != 0) { fprintf(stderr, @@ -306,7 +304,7 @@ main(void) rows[i].want_sse ? "present" : "absent"); fail++; } - unlink(src); unlink(cs_s); unlink(ws_s); + runwait(rmcmd); } if (fail) { diff --git a/test/wcc/947_inferred_scalar_global_run.c b/test/wcc/947_inferred_scalar_global_run.c index 92a9143e..5e891a3d 100644 --- a/test/wcc/947_inferred_scalar_global_run.c +++ b/test/wcc/947_inferred_scalar_global_run.c @@ -25,7 +25,6 @@ */ #include #include -#include #include #include #include @@ -175,23 +174,32 @@ main(void) int n = 0, fail = 0; for (int i = 0; rows[i].src; i++, n++) { - char src[64]; - snprintf(src, sizeof src, "/tmp/wwisg_%d_%d.ww", getpid(), i); + char tmpdir[64]; + snprintf(tmpdir, sizeof tmpdir, "/tmp/wwisg_%d_d_%d", + getpid(), i); + mkdir(tmpdir, 0755); + + char src[128], rmcmd[160]; + snprintf(src, sizeof src, "%s/wwisg_%d_%d.ww", + tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (f == NULL) { fail++; continue; } + if (f == NULL) { runwait(rmcmd); fail++; continue; } fputs(rows[i].src, f); fclose(f); + char cs_s[128], ws_s[128]; + snprintf(cs_s, sizeof cs_s, "%s/wwisg_%d_%d_cs.s", + tmpdir, getpid(), i); + snprintf(ws_s, sizeof ws_s, "%s/wwisg_%d_%d_ww.s", + tmpdir, getpid(), i); + /* Loud-guard rows (#133 R5): both stages must REJECT the * source at compile (e.g. a div-by-zero const-expr init). No * value to run / no byte-id — only the error-path preservation * matters. Assert raw w6c AND w6c_ww both emit non-zero. */ if (rows[i].want_err) { - char cs_s[64], ws_s[64], cmd[2048]; - snprintf(cs_s, sizeof cs_s, "/tmp/wwisg_%d_%d_cs.s", - getpid(), i); - snprintf(ws_s, sizeof ws_s, "/tmp/wwisg_%d_%d_ww.s", - getpid(), i); + char cmd[2048]; snprintf(cmd, sizeof cmd, "%s -o %s %s 2>/dev/null", w6c, cs_s, src); if (runwait(cmd) == 0) { @@ -208,61 +216,46 @@ main(void) "guard)\n", rows[i].label); fail++; } - unlink(src); unlink(cs_s); unlink(ws_s); + runwait(rmcmd); continue; } /* (a) cstage build + run. */ - char tmpdir[64]; - snprintf(tmpdir, sizeof tmpdir, "/tmp/wwisg_%d_d_%d", - getpid(), i); - mkdir(tmpdir, 0755); + char outbin[128]; + snprintf(outbin, sizeof outbin, "%s/wwisg_%d_%d", + tmpdir, getpid(), i); char cmd[2048]; - snprintf(cmd, sizeof cmd, "cd %s && %s/ww build %s", - tmpdir, bin, src); + snprintf(cmd, sizeof cmd, "%s/ww build -o %s %s", + bin, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: cstage build failed\n", rows[i].label); fail++; - unlink(src); rmdir(tmpdir); + runwait(rmcmd); continue; } - char outbin[128]; - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; - int got = runwait(outbin); if (got != rows[i].want_exit) { fprintf(stderr, "row[%s]: cstage exit %d, want %d\n", rows[i].label, got, rows[i].want_exit); fail++; } - unlink(outbin); rmdir(tmpdir); /* (b) cs==ww byte-id gate. */ - char cs_s[64], ws_s[64]; - snprintf(cs_s, sizeof cs_s, "/tmp/wwisg_%d_%d_cs.s", - getpid(), i); - snprintf(ws_s, sizeof ws_s, "/tmp/wwisg_%d_%d_ww.s", - getpid(), i); - snprintf(cmd, sizeof cmd, "%s -o %s %s 2>/dev/null", w6c, cs_s, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: w6c failed\n", rows[i].label); - fail++; unlink(src); continue; + fail++; runwait(rmcmd); continue; } snprintf(cmd, sizeof cmd, "%s -o %s %s 2>/dev/null", w6c_ww, ws_s, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: w6c_ww failed\n", rows[i].label); - fail++; unlink(src); unlink(cs_s); continue; + fail++; runwait(rmcmd); continue; } if (slurp_eq(cs_s, ws_s) != 0) { fprintf(stderr, @@ -270,7 +263,7 @@ main(void) "byte-id violation)\n", rows[i].label); fail++; } - unlink(src); unlink(cs_s); unlink(ws_s); + runwait(rmcmd); } if (fail) { diff --git a/test/wcc/947_tuple_index_read_run.c b/test/wcc/947_tuple_index_read_run.c index ea113754..b9b20631 100644 --- a/test/wcc/947_tuple_index_read_run.c +++ b/test/wcc/947_tuple_index_read_run.c @@ -168,19 +168,21 @@ static const struct row rows[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[96], tmpdir[96], errf[96], cmd[1024]; - snprintf(src, sizeof src, "/tmp/tir_%d_%d.ww", getpid(), i); + char tmpdir[96], src[160], errf[160], outbin[160], rmcmd[176], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/tir_%d_d_%d", getpid(), i); - snprintf(errf, sizeof errf, "/tmp/tir_%d_e_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/tir_%d_%d.ww", tmpdir, getpid(), i); + snprintf(errf, sizeof errf, "%s/tir_%d_e_%d", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/tir_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s >/dev/null 2>%s", - tmpdir, driver, src, errf); + snprintf(cmd, sizeof cmd, "%s build -o %s %s >/dev/null 2>%s", + driver, outbin, src, errf); int brc = runwait(cmd); if (r->kind == K_BUILDERR) { int ok = (brc != 0) @@ -189,25 +191,19 @@ run_driver(const char *driver, const struct row *r, int i) fprintf(stderr, "row[%s]: %s expected loud builderr " "\"%s\" (brc=%d)\n", r->label, driver, r->experr ? r->experr : "", brc); - unlink(src); unlink(errf); rmdir(tmpdir); + runwait(rmcmd); return ok ? 0 : 1; } if (brc != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); unlink(errf); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[256]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); unlink(errf); rmdir(tmpdir); + runwait(rmcmd); if (got != r->want) { fprintf(stderr, "row[%s]: %s exit %d, want %d\n", r->label, driver, got, r->want); diff --git a/test/wcc/949_errtype_compare.c b/test/wcc/949_errtype_compare.c index 1f29190f..1c9fbbe2 100644 --- a/test/wcc/949_errtype_compare.c +++ b/test/wcc/949_errtype_compare.c @@ -137,19 +137,21 @@ static const struct row rows[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[96], tmpdir[96], errf[96], cmd[1024]; - snprintf(src, sizeof src, "/tmp/etc_%d_%d.ww", getpid(), i); + char src[128], tmpdir[96], errf[128], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/etc_%d_d_%d", getpid(), i); - snprintf(errf, sizeof errf, "/tmp/etc_%d_e_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/etc_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/etc_%d_%d", tmpdir, getpid(), i); + snprintf(errf, sizeof errf, "%s/err", tmpdir); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s >/dev/null 2>%s", - tmpdir, driver, src, errf); + snprintf(cmd, sizeof cmd, "%s build -o %s %s >/dev/null 2>%s", + driver, outbin, src, errf); int brc = runwait(cmd); if (r->kind == K_BUILDERR) { @@ -158,26 +160,20 @@ run_driver(const char *driver, const struct row *r, int i) if (!ok) fprintf(stderr, "row[%s]: %s expected loud #246 builderr " "(brc=%d)\n", r->label, driver, brc); - unlink(src); unlink(errf); rmdir(tmpdir); + runwait(rmcmd); return ok ? 0 : 1; } if (brc != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); unlink(errf); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[256]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); unlink(errf); rmdir(tmpdir); + runwait(rmcmd); if (got != r->want) { fprintf(stderr, "row[%s]: %s exit %d, want %d\n", r->label, driver, got, r->want); diff --git a/test/wcc/949_f9_float_run.c b/test/wcc/949_f9_float_run.c index 44235d66..3d15d2c1 100644 --- a/test/wcc/949_f9_float_run.c +++ b/test/wcc/949_f9_float_run.c @@ -31,7 +31,6 @@ */ #include #include -#include #include #include #include @@ -128,36 +127,32 @@ static const struct row rows[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[96], tmpdir[96], errf[96], cmd[1024]; - snprintf(src, sizeof src, "/tmp/f9f_%d_%d.ww", getpid(), i); + char tmpdir[96], src[128], outbin[128], errf[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/f9f_%d_d_%d", getpid(), i); - snprintf(errf, sizeof errf, "/tmp/f9f_%d_e_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/f9f_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/f9f_%d_%d", tmpdir, getpid(), i); + snprintf(errf, sizeof errf, "%s/err", tmpdir); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s >/dev/null 2>%s", - tmpdir, driver, src, errf); + snprintf(cmd, sizeof cmd, "%s build -o %s %s >/dev/null 2>%s", + driver, outbin, src, errf); int brc = runwait(cmd); if (brc != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); unlink(errf); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[256]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); unlink(errf); rmdir(tmpdir); + runwait(rmcmd); if (got != r->want) { fprintf(stderr, "row[%s]: %s exit %d, want %d\n", r->label, driver, got, r->want); diff --git a/test/wcc/949_intbinop_mismatch.c b/test/wcc/949_intbinop_mismatch.c index 38b7c87c..a481dfb1 100644 --- a/test/wcc/949_intbinop_mismatch.c +++ b/test/wcc/949_intbinop_mismatch.c @@ -202,19 +202,21 @@ static const struct row rows[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[96], tmpdir[96], errf[96], cmd[1024]; - snprintf(src, sizeof src, "/tmp/ibm_%d_%d.ww", getpid(), i); + char tmpdir[96], src[128], outbin[128], errf[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/ibm_%d_d_%d", getpid(), i); - snprintf(errf, sizeof errf, "/tmp/ibm_%d_e_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/ibm_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/ibm_%d_%d", tmpdir, getpid(), i); + snprintf(errf, sizeof errf, "%s/err", tmpdir); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s >/dev/null 2>%s", - tmpdir, driver, src, errf); + snprintf(cmd, sizeof cmd, "%s build -o %s %s >/dev/null 2>%s", + driver, outbin, src, errf); int brc = runwait(cmd); if (r->kind == K_BUILDERR) { @@ -223,26 +225,20 @@ run_driver(const char *driver, const struct row *r, int i) if (!ok) fprintf(stderr, "row[%s]: %s expected loud #26 builderr " "(brc=%d)\n", r->label, driver, brc); - unlink(src); unlink(errf); rmdir(tmpdir); + runwait(rmcmd); return ok ? 0 : 1; } if (brc != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); unlink(errf); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[256]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); unlink(errf); rmdir(tmpdir); + runwait(rmcmd); if (got != r->want) { fprintf(stderr, "row[%s]: %s exit %d, want %d\n", r->label, driver, got, r->want); diff --git a/test/wcc/949_missingpkg.c b/test/wcc/949_missingpkg.c index e0dd350a..856ad436 100644 --- a/test/wcc/949_missingpkg.c +++ b/test/wcc/949_missingpkg.c @@ -18,6 +18,7 @@ #include #include #include +#include #include static int @@ -35,16 +36,23 @@ static int run_miss(const char *bin) { int pid = getpid(); - char src[64], errf[64], outb[64], comb[80], cmd[2048], line[4096]; - snprintf(src, sizeof src, "/tmp/mp949_miss_%d.ww", pid); - snprintf(errf, sizeof errf, "/tmp/mp949_miss_%d.err", pid); - /* -o a writable /tmp stem (not /dev/null): post-T3 the intermediate - * .combined.ww/.s/.o follow -o, so /dev/null would yield an - * uncreatable /dev/null.combined.ww and mask the missing-pkg fatal. */ - snprintf(outb, sizeof outb, "/tmp/mp949_miss_%d.out", pid); - snprintf(comb, sizeof comb, "/tmp/mp949_miss_%d.out.combined.ww", pid); + char tmpdir[64], src[128], errf[128], outb[128], cmd[2048]; + char rmcmd[160], line[4096]; + /* source + binary + intermediates + .sepwork all under one tmpdir so + * the compiler's output-derived .sepwork scratch lands here (not bare + * /tmp where unlink/rmdir would never name it) and the single rm -rf + * reclaims it on every exit path. */ + snprintf(tmpdir, sizeof tmpdir, "/tmp/mp949_miss_%d_d", pid); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/mp949_miss_%d.ww", tmpdir, pid); + snprintf(errf, sizeof errf, "%s/mp949_miss_%d.err", tmpdir, pid); + /* -o a writable stem inside tmpdir (not /dev/null): post-T3 the + * intermediate .combined.ww/.s/.o follow -o, so /dev/null would yield + * an uncreatable /dev/null.combined.ww and mask the missing-pkg fatal. */ + snprintf(outb, sizeof outb, "%s/mp949_miss_%d.out", tmpdir, pid); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "w"); - if (!f) { fprintf(stderr, "949 FAIL: stage miss\n"); return 1; } + if (!f) { fprintf(stderr, "949 FAIL: stage miss\n"); runwait(rmcmd); return 1; } fputs("import nosuchpkg;\n" "export fn main() i32 = { return 0; };\n", f); fclose(f); @@ -54,7 +62,7 @@ run_miss(const char *bin) int rc = runwait(cmd); if (rc == 0) { fprintf(stderr, "949 FAIL: ww accepted a missing import\n"); - unlink(src); unlink(errf); unlink(outb); unlink(comb); + runwait(rmcmd); return 1; } int found = 0; @@ -66,7 +74,7 @@ run_miss(const char *bin) } fclose(f); } - unlink(src); unlink(errf); unlink(outb); unlink(comb); + runwait(rmcmd); if (!found) { fprintf(stderr, "949 FAIL: no 'cannot find package nosuchpkg' " "on stderr\n"); @@ -82,11 +90,17 @@ static int run_inline(const char *bin) { int pid = getpid(); - char src[64], outb[64], cmd[2048]; - snprintf(src, sizeof src, "/tmp/mp949_inl_%d.ww", pid); - snprintf(outb, sizeof outb, "/tmp/mp949_inl_%d", pid); + char tmpdir[64], src[128], outb[128], cmd[2048], rmcmd[160]; + /* source + binary + .sepwork all under one tmpdir so the compiler's + * source-derived .sepwork scratch lands here (not bare /tmp) and the + * single rm -rf reclaims it. */ + snprintf(tmpdir, sizeof tmpdir, "/tmp/mp949_inl_%d_d", pid); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/mp949_inl_%d.ww", tmpdir, pid); + snprintf(outb, sizeof outb, "%s/mp949_inl_%d", tmpdir, pid); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "w"); - if (!f) { fprintf(stderr, "949 FAIL: stage inline\n"); return 1; } + if (!f) { fprintf(stderr, "949 FAIL: stage inline\n"); runwait(rmcmd); return 1; } fputs("package aa;\n" "export fn getv() i32 = { return 7; };\n" "package main;\n" @@ -94,19 +108,17 @@ run_inline(const char *bin) "export fn main() i32 = { return aa.getv(); };\n", f); fclose(f); - /* `ww build` emits the binary by basename in the cwd, so build from - * /tmp to keep both source and output out of the tree. */ snprintf(cmd, sizeof cmd, - "cd /tmp && %s/ww build mp949_inl_%d.ww >/dev/null 2>&1", bin, pid); + "%s/ww build -o %s %s >/dev/null 2>&1", bin, outb, src); int rc = runwait(cmd); if (rc != 0) { fprintf(stderr, "949 FAIL: inline-package build failed " "(inline-skip branch regressed)\n"); - unlink(src); + runwait(rmcmd); return 1; } int got = runwait(outb); - unlink(src); unlink(outb); + runwait(rmcmd); if (got != 7) { fprintf(stderr, "949 FAIL: inline-package exit=%d want=7\n", got); return 1; diff --git a/test/wcc/949_structlit_arrfield_run.c b/test/wcc/949_structlit_arrfield_run.c index f5270f0b..90021385 100644 --- a/test/wcc/949_structlit_arrfield_run.c +++ b/test/wcc/949_structlit_arrfield_run.c @@ -29,7 +29,6 @@ */ #include #include -#include #include #include #include @@ -135,62 +134,57 @@ main(void) int n = 0, fail = 0; for (int i = 0; rows[i].src; i++, n++) { - char src[64]; - snprintf(src, sizeof src, "/tmp/wwsaf_%d_%d.ww", getpid(), i); - FILE *f = fopen(src, "wb"); - if (f == NULL) { fail++; continue; } - fputs(rows[i].src, f); - fclose(f); - char tmpdir[64]; snprintf(tmpdir, sizeof tmpdir, "/tmp/wwsaf_%d_d_%d", getpid(), i); mkdir(tmpdir, 0755); + char src[128], outbin[128], cs_s[160], ws_s[160], rmcmd[160]; + snprintf(src, sizeof src, "%s/wwsaf_%d_%d.ww", + tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/wwsaf_%d_%d", + tmpdir, getpid(), i); + snprintf(cs_s, sizeof cs_s, "%s/wwsaf_%d_%d_cs.s", + tmpdir, getpid(), i); + snprintf(ws_s, sizeof ws_s, "%s/wwsaf_%d_%d_ww.s", + tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); + + FILE *f = fopen(src, "wb"); + if (f == NULL) { fail++; runwait(rmcmd); continue; } + fputs(rows[i].src, f); + fclose(f); + char cmd[2048]; - snprintf(cmd, sizeof cmd, "cd %s && %s/ww build %s", - tmpdir, bin, src); + snprintf(cmd, sizeof cmd, "%s/ww build -o %s %s", + bin, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: cstage build failed\n", rows[i].label); fail++; - unlink(src); rmdir(tmpdir); + runwait(rmcmd); continue; } - char outbin[128]; - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; - int got = runwait(outbin); if (got != rows[i].want_exit) { fprintf(stderr, "row[%s]: cstage exit %d, want %d\n", rows[i].label, got, rows[i].want_exit); fail++; } - unlink(outbin); rmdir(tmpdir); - - char cs_s[64], ws_s[64]; - snprintf(cs_s, sizeof cs_s, "/tmp/wwsaf_%d_%d_cs.s", - getpid(), i); - snprintf(ws_s, sizeof ws_s, "/tmp/wwsaf_%d_%d_ww.s", - getpid(), i); snprintf(cmd, sizeof cmd, "%s -o %s %s 2>/dev/null", w6c, cs_s, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: w6c failed\n", rows[i].label); - fail++; unlink(src); continue; + fail++; runwait(rmcmd); continue; } snprintf(cmd, sizeof cmd, "%s -o %s %s 2>/dev/null", w6c_ww, ws_s, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: w6c_ww failed\n", rows[i].label); - fail++; unlink(src); unlink(cs_s); continue; + fail++; runwait(rmcmd); continue; } if (slurp_eq(cs_s, ws_s) != 0) { fprintf(stderr, @@ -198,7 +192,7 @@ main(void) "byte-id violation)\n", rows[i].label); fail++; } - unlink(src); unlink(cs_s); unlink(ws_s); + runwait(rmcmd); } if (fail) { diff --git a/test/wcc/949_valstruct_subsize_run.c b/test/wcc/949_valstruct_subsize_run.c index a4539764..23e0d884 100644 --- a/test/wcc/949_valstruct_subsize_run.c +++ b/test/wcc/949_valstruct_subsize_run.c @@ -32,7 +32,6 @@ */ #include #include -#include #include #include #include @@ -178,62 +177,59 @@ main(void) int n = 0, fail = 0; for (int i = 0; rows[i].src; i++, n++) { - char src[64]; - snprintf(src, sizeof src, "/tmp/wwvss_%d_%d.ww", getpid(), i); - FILE *f = fopen(src, "wb"); - if (f == NULL) { fail++; continue; } - fputs(rows[i].src, f); - fclose(f); - char tmpdir[64]; snprintf(tmpdir, sizeof tmpdir, "/tmp/wwvss_%d_d_%d", getpid(), i); mkdir(tmpdir, 0755); + char rmcmd[160]; + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); + + char src[128], outbin[128], cs_s[128], ws_s[128]; + snprintf(src, sizeof src, "%s/wwvss_%d_%d.ww", + tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/wwvss_%d_%d", + tmpdir, getpid(), i); + snprintf(cs_s, sizeof cs_s, "%s/wwvss_%d_%d_cs.s", + tmpdir, getpid(), i); + snprintf(ws_s, sizeof ws_s, "%s/wwvss_%d_%d_ww.s", + tmpdir, getpid(), i); + + FILE *f = fopen(src, "wb"); + if (f == NULL) { fail++; runwait(rmcmd); continue; } + fputs(rows[i].src, f); + fclose(f); + char cmd[2048]; - snprintf(cmd, sizeof cmd, "cd %s && %s/ww build %s", - tmpdir, bin, src); + snprintf(cmd, sizeof cmd, "%s/ww build -o %s %s", + bin, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: cstage build failed\n", rows[i].label); fail++; - unlink(src); rmdir(tmpdir); + runwait(rmcmd); continue; } - char outbin[128]; - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; - int got = runwait(outbin); if (got != rows[i].want_exit) { fprintf(stderr, "row[%s]: cstage exit %d, want %d\n", rows[i].label, got, rows[i].want_exit); fail++; } - unlink(outbin); rmdir(tmpdir); - - char cs_s[64], ws_s[64]; - snprintf(cs_s, sizeof cs_s, "/tmp/wwvss_%d_%d_cs.s", - getpid(), i); - snprintf(ws_s, sizeof ws_s, "/tmp/wwvss_%d_%d_ww.s", - getpid(), i); snprintf(cmd, sizeof cmd, "%s -o %s %s 2>/dev/null", w6c, cs_s, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: w6c failed\n", rows[i].label); - fail++; unlink(src); continue; + fail++; runwait(rmcmd); continue; } snprintf(cmd, sizeof cmd, "%s -o %s %s 2>/dev/null", w6c_ww, ws_s, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: w6c_ww failed\n", rows[i].label); - fail++; unlink(src); unlink(cs_s); continue; + fail++; runwait(rmcmd); continue; } if (slurp_eq(cs_s, ws_s) != 0) { fprintf(stderr, @@ -241,7 +237,7 @@ main(void) "byte-id violation)\n", rows[i].label); fail++; } - unlink(src); unlink(cs_s); unlink(ws_s); + runwait(rmcmd); } if (fail) { diff --git a/test/wcc/949_void_error_singleton_run.c b/test/wcc/949_void_error_singleton_run.c index 79eb82a1..ebe94b05 100644 --- a/test/wcc/949_void_error_singleton_run.c +++ b/test/wcc/949_void_error_singleton_run.c @@ -177,28 +177,19 @@ file_has(const char *path, const char *needle) } static int -run_driver(const char *driver, const char *src, const char *label) +run_driver(const char *driver, const char *tmpdir, const char *src, + const char *label) { - char tmpdir[128], cmd[1024]; - snprintf(tmpdir, sizeof tmpdir, "/tmp/tves_%d_d", getpid()); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s/%s build %s >/dev/null 2>&1", - tmpdir, g_bin, driver, src); + char cmd[1024], outbin[256]; + snprintf(outbin, sizeof outbin, "%s/out_%s", tmpdir, driver); + snprintf(cmd, sizeof cmd, "%s/%s build -o %s %s >/dev/null 2>&1", + g_bin, driver, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", label, driver); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[256]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; - int got = runwait(outbin); - unlink(outbin); - rmdir(tmpdir); - return got; + return runwait(outbin); } int @@ -219,20 +210,25 @@ main(void) int total = 0, fail = 0; for (int i = 0; i < n; i++) { const struct row *r = &rows[i]; - char src[128], cs_s[128], ww_s[128]; - char cs_e[128], ww_e[128]; - snprintf(src, sizeof src, "/tmp/tves_%d_%d.ww", - getpid(), i); - snprintf(cs_s, sizeof cs_s, "/tmp/tves_%d_%d_cs.s", - getpid(), i); - snprintf(ww_s, sizeof ww_s, "/tmp/tves_%d_%d_ww.s", - getpid(), i); - snprintf(cs_e, sizeof cs_e, "/tmp/tves_%d_%d_cs.err", - getpid(), i); - snprintf(ww_e, sizeof ww_e, "/tmp/tves_%d_%d_ww.err", + char tmpdir[128], rmcmd[160]; + char src[160], cs_s[160], ww_s[160]; + char cs_e[160], ww_e[160]; + snprintf(tmpdir, sizeof tmpdir, "/tmp/tves_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); + snprintf(src, sizeof src, "%s/tves_%d_%d.ww", + tmpdir, getpid(), i); + snprintf(cs_s, sizeof cs_s, "%s/tves_%d_%d_cs.s", + tmpdir, getpid(), i); + snprintf(ww_s, sizeof ww_s, "%s/tves_%d_%d_ww.s", + tmpdir, getpid(), i); + snprintf(cs_e, sizeof cs_e, "%s/tves_%d_%d_cs.err", + tmpdir, getpid(), i); + snprintf(ww_e, sizeof ww_e, "%s/tves_%d_%d_ww.err", + tmpdir, getpid(), i); FILE *f = fopen(src, "wb"); - if (!f) return 1; + if (!f) { runwait(rmcmd); return 1; } fputs("package main;\n\n", f); fputs(r->src, f); fclose(f); @@ -244,8 +240,7 @@ main(void) fprintf(stderr, "FAIL row[%s]: compile rc cs=%d " "ww=%d\n", r->label, cs_rc, ww_rc); fail++; - unlink(src); unlink(cs_s); unlink(ww_s); - unlink(cs_e); unlink(ww_e); + runwait(rmcmd); continue; } if (!file_eq(cs_s, ww_s)) { @@ -263,7 +258,7 @@ main(void) r->label); fail++; } - int got_cs = run_driver("ww", src, r->label); + int got_cs = run_driver("ww", tmpdir, src, r->label); if (got_cs != r->want) { fprintf(stderr, "FAIL row[%s] cstage: want %d " "got %d\n", r->label, r->want, got_cs); @@ -272,7 +267,7 @@ main(void) char wwdrv[600]; snprintf(wwdrv, sizeof wwdrv, "%s/ww_ww", g_bin); if (access(wwdrv, X_OK) == 0) { - int got_ww = run_driver("ww_ww", src, r->label); + int got_ww = run_driver("ww_ww", tmpdir, src, r->label); if (got_ww != r->want) { fprintf(stderr, "FAIL row[%s] wwstage: " "want %d got %d\n", @@ -280,8 +275,7 @@ main(void) fail++; } } - unlink(src); unlink(cs_s); unlink(ww_s); - unlink(cs_e); unlink(ww_e); + runwait(rmcmd); } if (fail) { fprintf(stderr, "void_error_singleton_run: %d/%d rows " diff --git a/test/wcc/951_arrlit_elem_narrow_run.c b/test/wcc/951_arrlit_elem_narrow_run.c index f3a7be5b..5ecdd9e9 100644 --- a/test/wcc/951_arrlit_elem_narrow_run.c +++ b/test/wcc/951_arrlit_elem_narrow_run.c @@ -58,7 +58,6 @@ */ #include #include -#include #include #include #include @@ -182,61 +181,60 @@ main(void) /* Accept rows: cstage build + run + cs==ww byte-id. */ for (int i = 0; accept_rows[i].src; i++, n++) { - char src[64]; - snprintf(src, sizeof src, "/tmp/wwan_%d_%d.ww", getpid(), i); - FILE *f = fopen(src, "wb"); - if (f == NULL) { fail++; continue; } - fputs(accept_rows[i].src, f); - fclose(f); - char tmpdir[64]; snprintf(tmpdir, sizeof tmpdir, "/tmp/wwan_%d_d_%d", getpid(), i); mkdir(tmpdir, 0755); + char rmcmd[160]; + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); + + char src[128], outbin[128]; + snprintf(src, sizeof src, "%s/wwan_%d_%d.ww", + tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/wwan_%d_%d", + tmpdir, getpid(), i); + FILE *f = fopen(src, "wb"); + if (f == NULL) { fail++; runwait(rmcmd); continue; } + fputs(accept_rows[i].src, f); + fclose(f); + char cmd[2048]; - snprintf(cmd, sizeof cmd, "cd %s && %s/ww build %s", - tmpdir, bin, src); + snprintf(cmd, sizeof cmd, "%s/ww build -o %s %s", + bin, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "accept[%s]: cstage build failed\n", accept_rows[i].label); - fail++; unlink(src); rmdir(tmpdir); continue; + fail++; runwait(rmcmd); continue; } - char outbin[128]; - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); if (got != accept_rows[i].want_exit) { fprintf(stderr, "accept[%s]: exit %d, want %d\n", accept_rows[i].label, got, accept_rows[i].want_exit); fail++; } - unlink(outbin); rmdir(tmpdir); - char cs_s[64], ws_s[64]; - snprintf(cs_s, sizeof cs_s, "/tmp/wwan_%d_%d_cs.s", - getpid(), i); - snprintf(ws_s, sizeof ws_s, "/tmp/wwan_%d_%d_ww.s", - getpid(), i); + char cs_s[128], ws_s[128]; + snprintf(cs_s, sizeof cs_s, "%s/wwan_%d_%d_cs.s", + tmpdir, getpid(), i); + snprintf(ws_s, sizeof ws_s, "%s/wwan_%d_%d_ww.s", + tmpdir, getpid(), i); snprintf(cmd, sizeof cmd, "%s -o %s %s 2>/dev/null", w6c, cs_s, src); if (runwait(cmd) != 0) { fprintf(stderr, "accept[%s]: w6c failed\n", accept_rows[i].label); - fail++; unlink(src); continue; + fail++; runwait(rmcmd); continue; } snprintf(cmd, sizeof cmd, "%s -o %s %s 2>/dev/null", w6c_ww, ws_s, src); if (runwait(cmd) != 0) { fprintf(stderr, "accept[%s]: w6c_ww failed\n", accept_rows[i].label); - fail++; unlink(src); unlink(cs_s); continue; + fail++; runwait(rmcmd); continue; } if (slurp_eq(cs_s, ws_s) != 0) { fprintf(stderr, "accept[%s]: cs/ww .s DIFFER (rule-10)\n", accept_rows[i].label); fail++; } - unlink(src); unlink(cs_s); unlink(ws_s); + runwait(rmcmd); } /* Reject rows: BOTH stages must fail to build (loud reject). */ diff --git a/test/wcc/951_f64cgen_run.c b/test/wcc/951_f64cgen_run.c index c5a9e0f0..71fd2e53 100644 --- a/test/wcc/951_f64cgen_run.c +++ b/test/wcc/951_f64cgen_run.c @@ -21,7 +21,6 @@ */ #include #include -#include #include #include #include @@ -205,43 +204,38 @@ main(void) int n = 0, fail = 0; for (int i = 0; rows[i].src; i++, n++) { - char src[64]; - snprintf(src, sizeof src, "/tmp/wwf64_%d_%d.ww", getpid(), i); - - FILE *f = fopen(src, "wb"); - if (f == NULL) { fail++; continue; } - fputs(rows[i].src, f); - fclose(f); - char tmpdir[64]; snprintf(tmpdir, sizeof tmpdir, "/tmp/wwf64_%d_d_%d", getpid(), i); mkdir(tmpdir, 0755); + char src[128], outbin[128], rmcmd[160]; + snprintf(src, sizeof src, "%s/wwf64_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/wwf64_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); + + FILE *f = fopen(src, "wb"); + if (f == NULL) { runwait(rmcmd); fail++; continue; } + fputs(rows[i].src, f); + fclose(f); + char cmd[1024]; - snprintf(cmd, sizeof cmd, "cd %s && %s/ww build %s", - tmpdir, bin, src); + snprintf(cmd, sizeof cmd, "%s/ww build -o %s %s", + bin, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row %d: build failed\n src: %s\n", i, rows[i].src); fail++; - unlink(src); rmdir(tmpdir); + runwait(rmcmd); continue; } - char outbin[128]; - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; - int got = runwait(outbin); if (got != rows[i].want_exit) { fprintf(stderr, "row %d: exit %d, want %d\n src: %s\n", i, got, rows[i].want_exit, rows[i].src); fail++; } - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); } if (fail) { fprintf(stderr, "%d/%d f64cgen tests failed\n", fail, n); diff --git a/test/wcc/952_floats_run.c b/test/wcc/952_floats_run.c index 4a1656a6..d37d2957 100644 --- a/test/wcc/952_floats_run.c +++ b/test/wcc/952_floats_run.c @@ -33,7 +33,6 @@ */ #include #include -#include #include #include #include @@ -373,43 +372,42 @@ main(void) int n = 0, fail = 0; for (int i = 0; rows[i].src; i++, n++) { - char src[64]; - snprintf(src, sizeof src, "/tmp/wwflt_%d_%d.ww", getpid(), i); + char tmpdir[64]; + snprintf(tmpdir, sizeof tmpdir, "/tmp/wwflt_%d_%d", getpid(), i); + mkdir(tmpdir, 0755); + + char rmcmd[128]; + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); + + char src[128]; + snprintf(src, sizeof src, "%s/wwflt_%d_%d.ww", tmpdir, getpid(), i); FILE *f = fopen(src, "wb"); - if (f == NULL) { fail++; continue; } + if (f == NULL) { fail++; runwait(rmcmd); continue; } fputs(rows[i].src, f); fclose(f); - char tmpdir[64]; - snprintf(tmpdir, sizeof tmpdir, "/tmp/wwflt_%d_d_%d", getpid(), i); - mkdir(tmpdir, 0755); + char outbin[128]; + snprintf(outbin, sizeof outbin, "%s/out", tmpdir); char cmd[2048]; - snprintf(cmd, sizeof cmd, "cd %s && %s/ww build -I %s/lib %s", - tmpdir, bin, cwd, src); + snprintf(cmd, sizeof cmd, "%s/ww build -I %s/lib -o %s %s", + bin, cwd, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row %d: build failed\n src: %s\n", i, rows[i].src); fail++; - unlink(src); rmdir(tmpdir); + runwait(rmcmd); continue; } - char outbin[128]; - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; - int got = runwait(outbin); if (got != rows[i].want_exit) { fprintf(stderr, "row %d: exit %d, want %d\n src: %s\n", i, got, rows[i].want_exit, rows[i].src); fail++; } - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); } if (fail) { fprintf(stderr, "%d/%d floats tests failed\n", fail, n); diff --git a/test/wcc/953_arraytoslice_run.c b/test/wcc/953_arraytoslice_run.c index 50f7a2c6..d258c0a7 100644 --- a/test/wcc/953_arraytoslice_run.c +++ b/test/wcc/953_arraytoslice_run.c @@ -38,7 +38,6 @@ */ #include #include -#include #include #include #include @@ -177,16 +176,26 @@ main(void) int n = 0, fail = 0; for (int i = 0; rows[i].src; i++, n++) { - char src[64]; - snprintf(src, sizeof src, "/tmp/wwa2s_%d_%d.ww", getpid(), i); + char tmpdir[64]; + snprintf(tmpdir, sizeof tmpdir, "/tmp/wwa2s_%d_d_%d", + getpid(), i); + mkdir(tmpdir, 0755); + char rmcmd[128]; + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); + + char src[128]; + snprintf(src, sizeof src, "%s/wwa2s_%d_%d.ww", + tmpdir, getpid(), i); FILE *f = fopen(src, "wb"); - if (f == NULL) { fail++; continue; } + if (f == NULL) { fail++; runwait(rmcmd); continue; } fputs(rows[i].src, f); fclose(f); - char cs_s[64], ws_s[64]; - snprintf(cs_s, sizeof cs_s, "/tmp/wwa2s_%d_%d_cs.s", getpid(), i); - snprintf(ws_s, sizeof ws_s, "/tmp/wwa2s_%d_%d_ww.s", getpid(), i); + char cs_s[128], ws_s[128]; + snprintf(cs_s, sizeof cs_s, "%s/wwa2s_%d_%d_cs.s", + tmpdir, getpid(), i); + snprintf(ws_s, sizeof ws_s, "%s/wwa2s_%d_%d_ww.s", + tmpdir, getpid(), i); char cmd[2048]; if (rows[i].reject) { @@ -207,51 +216,43 @@ main(void) rows[i].label); fail++; } - unlink(src); unlink(cs_s); unlink(ws_s); + runwait(rmcmd); continue; } /* Positive row: cstage build + run for exit code. */ - char tmpdir[64]; - snprintf(tmpdir, sizeof tmpdir, "/tmp/wwa2s_%d_d_%d", - getpid(), i); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s/ww build %s", - tmpdir, bin, src); + char outbin[128]; + snprintf(outbin, sizeof outbin, "%s/wwa2s_%d_%d", + tmpdir, getpid(), i); + snprintf(cmd, sizeof cmd, "%s/ww build -o %s %s", + bin, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: cstage build failed\n", rows[i].label); fail++; - unlink(src); rmdir(tmpdir); + runwait(rmcmd); continue; } - char outbin[128]; - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); if (got != rows[i].want_exit) { fprintf(stderr, "row[%s]: cstage exit %d, want %d\n", rows[i].label, got, rows[i].want_exit); fail++; } - unlink(outbin); rmdir(tmpdir); /* rule-10 byte-id: w6c vs w6c_ww .s. */ snprintf(cmd, sizeof cmd, "%s -o %s %s 2>/dev/null", w6c, cs_s, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: w6c failed\n", rows[i].label); - fail++; unlink(src); continue; + fail++; runwait(rmcmd); continue; } snprintf(cmd, sizeof cmd, "%s -o %s %s 2>/dev/null", w6c_ww, ws_s, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: w6c_ww failed\n", rows[i].label); - fail++; unlink(src); unlink(cs_s); continue; + fail++; runwait(rmcmd); continue; } if (slurp_eq(cs_s, ws_s) != 0) { fprintf(stderr, @@ -259,7 +260,7 @@ main(void) "byte-id violation)\n", rows[i].label); fail++; } - unlink(src); unlink(cs_s); unlink(ws_s); + runwait(rmcmd); } if (fail) { diff --git a/test/wcc/953_arrlit_slice_run.c b/test/wcc/953_arrlit_slice_run.c index 96f46c2a..9688ed81 100644 --- a/test/wcc/953_arrlit_slice_run.c +++ b/test/wcc/953_arrlit_slice_run.c @@ -41,7 +41,6 @@ */ #include #include -#include #include #include #include @@ -187,16 +186,30 @@ main(void) int n = 0, fail = 0; for (int i = 0; rows[i].src; i++, n++) { - char src[64]; - snprintf(src, sizeof src, "/tmp/wwas_%d_%d.ww", getpid(), i); + /* src + outbin + cs.s + ws.s all under one tmpdir so the + * compiler's source-derived .sepwork scratch stays inside it; + * single rm -rf deferred to the end of the row. */ + char tmpdir[64], rmcmd[160]; + snprintf(tmpdir, sizeof tmpdir, "/tmp/wwas_%d_d_%d", + getpid(), i); + mkdir(tmpdir, 0755); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); + + char src[128], outbin[128]; + snprintf(src, sizeof src, "%s/wwas_%d_%d.ww", tmpdir, + getpid(), i); + snprintf(outbin, sizeof outbin, "%s/wwas_%d_%d", tmpdir, + getpid(), i); FILE *f = fopen(src, "wb"); - if (f == NULL) { fail++; continue; } + if (f == NULL) { runwait(rmcmd); fail++; continue; } fputs(rows[i].src, f); fclose(f); - char cs_s[64], ws_s[64]; - snprintf(cs_s, sizeof cs_s, "/tmp/wwas_%d_%d_cs.s", getpid(), i); - snprintf(ws_s, sizeof ws_s, "/tmp/wwas_%d_%d_ww.s", getpid(), i); + char cs_s[128], ws_s[128]; + snprintf(cs_s, sizeof cs_s, "%s/wwas_%d_%d_cs.s", tmpdir, + getpid(), i); + snprintf(ws_s, sizeof ws_s, "%s/wwas_%d_%d_ww.s", tmpdir, + getpid(), i); char cmd[2048]; if (rows[i].reject) { @@ -215,51 +228,40 @@ main(void) "that must reject\n", rows[i].label); fail++; } - unlink(src); unlink(cs_s); unlink(ws_s); + runwait(rmcmd); continue; } /* Positive row: cstage build + run for exit code. */ - char tmpdir[64]; - snprintf(tmpdir, sizeof tmpdir, "/tmp/wwas_%d_d_%d", - getpid(), i); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s/ww build %s", - tmpdir, bin, src); + snprintf(cmd, sizeof cmd, "%s/ww build -o %s %s", + bin, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: cstage build failed\n", rows[i].label); fail++; - unlink(src); rmdir(tmpdir); + runwait(rmcmd); continue; } - char outbin[128]; - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); if (got != rows[i].want_exit) { fprintf(stderr, "row[%s]: cstage exit %d, want %d\n", rows[i].label, got, rows[i].want_exit); fail++; } - unlink(outbin); rmdir(tmpdir); /* rule-10 byte-id: w6c vs w6c_ww .s. */ snprintf(cmd, sizeof cmd, "%s -o %s %s 2>/dev/null", w6c, cs_s, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: w6c failed\n", rows[i].label); - fail++; unlink(src); continue; + fail++; runwait(rmcmd); continue; } snprintf(cmd, sizeof cmd, "%s -o %s %s 2>/dev/null", w6c_ww, ws_s, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: w6c_ww failed\n", rows[i].label); - fail++; unlink(src); unlink(cs_s); continue; + fail++; runwait(rmcmd); continue; } if (slurp_eq(cs_s, ws_s) != 0) { fprintf(stderr, @@ -267,7 +269,7 @@ main(void) "byte-id violation)\n", rows[i].label); fail++; } - unlink(src); unlink(cs_s); unlink(ws_s); + runwait(rmcmd); } if (fail) { diff --git a/test/wcc/953_f64crossmod_run.c b/test/wcc/953_f64crossmod_run.c index eafd5a6c..a1abf63b 100644 --- a/test/wcc/953_f64crossmod_run.c +++ b/test/wcc/953_f64crossmod_run.c @@ -32,7 +32,6 @@ */ #include #include -#include #include #include #include @@ -135,66 +134,66 @@ main(void) int n = 0, fail = 0; for (int i = 0; rows[i].src; i++, n++) { - char src[64]; - snprintf(src, sizeof src, "/tmp/wwf64x_%d_%d.ww", getpid(), i); - FILE *f = fopen(src, "wb"); - if (f == NULL) { fail++; continue; } - fputs(rows[i].src, f); - fclose(f); - - /* (a) cstage build + run. Build cwd is a scratch dir so the - * output binary (and any intermediates) land there. */ + /* src, the build output, and both .s files all live under one + * tmpdir so the compiler's .sepwork scratch (derived from the + * source path) stays inside it; a single rm -rf at the end of + * both phases reclaims everything. */ char tmpdir[64]; snprintf(tmpdir, sizeof tmpdir, "/tmp/wwf64x_%d_d_%d", getpid(), i); mkdir(tmpdir, 0755); + char src[128], outbin[128], rmcmd[160]; + snprintf(src, sizeof src, "%s/wwf64x_%d_%d.ww", + tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/wwf64x_%d_%d", + tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); + + FILE *f = fopen(src, "wb"); + if (f == NULL) { fail++; runwait(rmcmd); continue; } + fputs(rows[i].src, f); + fclose(f); + + /* (a) cstage build + run. */ char cmd[2048]; - snprintf(cmd, sizeof cmd, "cd %s && %s/ww build %s", - tmpdir, bin, src); + snprintf(cmd, sizeof cmd, "%s/ww build -o %s %s", + bin, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: cstage build failed\n", rows[i].label); fail++; - unlink(src); rmdir(tmpdir); + runwait(rmcmd); continue; } - char outbin[128]; - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; - int got = runwait(outbin); if (got != rows[i].want_exit) { fprintf(stderr, "row[%s]: cstage exit %d, want %d\n", rows[i].label, got, rows[i].want_exit); fail++; } - unlink(outbin); rmdir(tmpdir); /* (b) cs==ww byte-id gate: emit .s from both stages, cmp. * FAILS on the pre-fix wwstage divergence. */ - char cs_s[64], ws_s[64]; - snprintf(cs_s, sizeof cs_s, "/tmp/wwf64x_%d_%d_cs.s", - getpid(), i); - snprintf(ws_s, sizeof ws_s, "/tmp/wwf64x_%d_%d_ww.s", - getpid(), i); + char cs_s[160], ws_s[160]; + snprintf(cs_s, sizeof cs_s, "%s/wwf64x_%d_%d_cs.s", + tmpdir, getpid(), i); + snprintf(ws_s, sizeof ws_s, "%s/wwf64x_%d_%d_ww.s", + tmpdir, getpid(), i); snprintf(cmd, sizeof cmd, "%s -o %s %s 2>/dev/null", w6c, cs_s, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: w6c failed\n", rows[i].label); - fail++; unlink(src); continue; + fail++; runwait(rmcmd); continue; } snprintf(cmd, sizeof cmd, "%s -o %s %s 2>/dev/null", w6c_ww, ws_s, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: w6c_ww failed\n", rows[i].label); - fail++; unlink(src); unlink(cs_s); continue; + fail++; runwait(rmcmd); continue; } if (slurp_eq(cs_s, ws_s) != 0) { fprintf(stderr, @@ -202,7 +201,7 @@ main(void) "byte-id violation)\n", rows[i].label); fail++; } - unlink(src); unlink(cs_s); unlink(ws_s); + runwait(rmcmd); } if (fail) { diff --git a/test/wcc/953_globalslice_arg_run.c b/test/wcc/953_globalslice_arg_run.c index a6183195..d374ca43 100644 --- a/test/wcc/953_globalslice_arg_run.c +++ b/test/wcc/953_globalslice_arg_run.c @@ -23,7 +23,6 @@ */ #include #include -#include #include #include #include @@ -119,44 +118,41 @@ main(void) int n = 0, fail = 0; for (int i = 0; rows[i].src; i++, n++) { - char src[64]; - snprintf(src, sizeof src, "/tmp/wwgsa_%d_%d.ww", getpid(), i); - FILE *f = fopen(src, "wb"); - if (f == NULL) { fail++; continue; } - fputs(rows[i].src, f); - fclose(f); - char tmpdir[64]; snprintf(tmpdir, sizeof tmpdir, "/tmp/wwgsa_%d_d_%d", getpid(), i); mkdir(tmpdir, 0755); + char src[128], outbin[128], rmcmd[160]; + snprintf(src, sizeof src, "%s/wwgsa_%d_%d.ww", + tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/wwgsa_%d_%d", + tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); + + FILE *f = fopen(src, "wb"); + if (f == NULL) { runwait(rmcmd); fail++; continue; } + fputs(rows[i].src, f); + fclose(f); + char cmd[2048]; - snprintf(cmd, sizeof cmd, "cd %s && %s/ww build %s", - tmpdir, bin, src); + snprintf(cmd, sizeof cmd, "%s/ww build -o %s %s", + bin, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: cstage build failed\n", rows[i].label); fail++; - unlink(src); rmdir(tmpdir); + runwait(rmcmd); continue; } - char outbin[128]; - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; - int got = runwait(outbin); if (got != rows[i].want_exit) { fprintf(stderr, "row[%s]: cstage exit %d, want %d\n", rows[i].label, got, rows[i].want_exit); fail++; } - unlink(outbin); rmdir(tmpdir); - unlink(src); + runwait(rmcmd); } if (fail) { diff --git a/test/wcc/954_tuprecv_run.c b/test/wcc/954_tuprecv_run.c index 58000a59..0c92ced2 100644 --- a/test/wcc/954_tuprecv_run.c +++ b/test/wcc/954_tuprecv_run.c @@ -41,7 +41,6 @@ */ #include #include -#include #include #include #include @@ -174,66 +173,68 @@ main(void) int n = 0, fail = 0; for (int i = 0; rows[i].src; i++, n++) { - char src[64]; - snprintf(src, sizeof src, "/tmp/wwtup_%d_%d.ww", getpid(), i); - FILE *f = fopen(src, "wb"); - if (f == NULL) { fail++; continue; } - fputs(rows[i].src, f); - fclose(f); - - /* (a) cstage build + run in a scratch dir so the output binary - * (and any intermediates) land there. */ - char tmpdir[64]; + /* src reused across the build-phase (a) AND the w6c/w6c_ww + * byte-id phase (b)/(c); keep src, outbin and both .s under one + * tmpdir and defer a single rm -rf to the end so the compiler's + * .sepwork scratch (derived from the source path) lands in + * tmpdir, not bare /tmp. */ + char tmpdir[64], rmcmd[160]; snprintf(tmpdir, sizeof tmpdir, "/tmp/wwtup_%d_d_%d", getpid(), i); mkdir(tmpdir, 0755); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); + + char src[128]; + snprintf(src, sizeof src, "%s/wwtup_%d_%d.ww", + tmpdir, getpid(), i); + FILE *f = fopen(src, "wb"); + if (f == NULL) { fail++; runwait(rmcmd); continue; } + fputs(rows[i].src, f); + fclose(f); + + /* (a) cstage build + run; -o pins the binary into tmpdir. */ + char outbin[128]; + snprintf(outbin, sizeof outbin, "%s/wwtup_%d_%d", + tmpdir, getpid(), i); char cmd[2048]; - snprintf(cmd, sizeof cmd, "cd %s && %s/ww build %s", - tmpdir, bin, src); + snprintf(cmd, sizeof cmd, "%s/ww build -o %s %s", + bin, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: cstage build failed\n", rows[i].label); fail++; - unlink(src); rmdir(tmpdir); + runwait(rmcmd); continue; } - char outbin[128]; - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; - int got = runwait(outbin); if (got != rows[i].want_exit) { fprintf(stderr, "row[%s]: cstage exit %d, want %d\n", rows[i].label, got, rows[i].want_exit); fail++; } - unlink(outbin); rmdir(tmpdir); /* (b) cs==ww byte-id gate: emit .s from both stages, cmp. * FAILS on the pre-fix wwstage divergence (dropped MOVQ DX). */ - char cs_s[64], ws_s[64]; - snprintf(cs_s, sizeof cs_s, "/tmp/wwtup_%d_%d_cs.s", - getpid(), i); - snprintf(ws_s, sizeof ws_s, "/tmp/wwtup_%d_%d_ww.s", - getpid(), i); + char cs_s[128], ws_s[128]; + snprintf(cs_s, sizeof cs_s, "%s/wwtup_%d_%d_cs.s", + tmpdir, getpid(), i); + snprintf(ws_s, sizeof ws_s, "%s/wwtup_%d_%d_ww.s", + tmpdir, getpid(), i); snprintf(cmd, sizeof cmd, "%s -o %s %s 2>/dev/null", w6c, cs_s, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: w6c failed\n", rows[i].label); - fail++; unlink(src); continue; + fail++; runwait(rmcmd); continue; } snprintf(cmd, sizeof cmd, "%s -o %s %s 2>/dev/null", w6c_ww, ws_s, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: w6c_ww failed\n", rows[i].label); - fail++; unlink(src); unlink(cs_s); continue; + fail++; runwait(rmcmd); continue; } if (slurp_eq(cs_s, ws_s) != 0) { fprintf(stderr, @@ -248,9 +249,9 @@ main(void) * pre-stamp (HEAD) w6c_ww fires asserttyped on the f64 binding * ident (nil n.type_). */ if (rows[i].chk_stamped) { - char errf[80]; + char errf[128]; snprintf(errf, sizeof errf, - "/tmp/wwtup_%d_%d_err.txt", getpid(), i); + "%s/wwtup_%d_%d_err.txt", tmpdir, getpid(), i); snprintf(cmd, sizeof cmd, "%s -o /dev/null %s 2>%s", w6c_ww, src, errf); runwait(cmd); @@ -262,9 +263,8 @@ main(void) "unstamped)\n", rows[i].label); fail++; } - unlink(errf); } - unlink(src); unlink(cs_s); unlink(ws_s); + runwait(rmcmd); } if (fail) { diff --git a/test/wcc/955_f64xmm_run.c b/test/wcc/955_f64xmm_run.c index d3707012..e5c0358a 100644 --- a/test/wcc/955_f64xmm_run.c +++ b/test/wcc/955_f64xmm_run.c @@ -29,7 +29,6 @@ */ #include #include -#include #include #include #include @@ -146,64 +145,60 @@ main(void) int n = 0, fail = 0; for (int i = 0; rows[i].src; i++, n++) { - char src[64]; - snprintf(src, sizeof src, "/tmp/wwf64m_%d_%d.ww", getpid(), i); - FILE *f = fopen(src, "wb"); - if (f == NULL) { fail++; continue; } - fputs(rows[i].src, f); - fclose(f); - - /* (a) cstage build + run. */ char tmpdir[64]; snprintf(tmpdir, sizeof tmpdir, "/tmp/wwf64m_%d_d_%d", getpid(), i); mkdir(tmpdir, 0755); + char rmcmd[160]; + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); + char src[128], outbin[128], cs_s[128], ws_s[128]; + snprintf(src, sizeof src, "%s/wwf64m_%d_%d.ww", + tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/wwf64m_%d_%d", + tmpdir, getpid(), i); + snprintf(cs_s, sizeof cs_s, "%s/wwf64m_%d_%d_cs.s", + tmpdir, getpid(), i); + snprintf(ws_s, sizeof ws_s, "%s/wwf64m_%d_%d_ww.s", + tmpdir, getpid(), i); + + FILE *f = fopen(src, "wb"); + if (f == NULL) { fail++; runwait(rmcmd); continue; } + fputs(rows[i].src, f); + fclose(f); + + /* (a) cstage build + run. */ char cmd[2048]; - snprintf(cmd, sizeof cmd, "cd %s && %s/ww build %s", - tmpdir, bin, src); + snprintf(cmd, sizeof cmd, "%s/ww build -o %s %s", + bin, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: cstage build failed\n", rows[i].label); fail++; - unlink(src); rmdir(tmpdir); + runwait(rmcmd); continue; } - char outbin[128]; - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; - int got = runwait(outbin); if (got != rows[i].want_exit) { fprintf(stderr, "row[%s]: cstage exit %d, want %d\n", rows[i].label, got, rows[i].want_exit); fail++; } - unlink(outbin); rmdir(tmpdir); /* (b) cs==ww byte-id gate: emit .s from both stages, cmp. */ - char cs_s[64], ws_s[64]; - snprintf(cs_s, sizeof cs_s, "/tmp/wwf64m_%d_%d_cs.s", - getpid(), i); - snprintf(ws_s, sizeof ws_s, "/tmp/wwf64m_%d_%d_ww.s", - getpid(), i); - snprintf(cmd, sizeof cmd, "%s -o %s %s 2>/dev/null", w6c, cs_s, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: w6c failed\n", rows[i].label); - fail++; unlink(src); continue; + fail++; runwait(rmcmd); continue; } snprintf(cmd, sizeof cmd, "%s -o %s %s 2>/dev/null", w6c_ww, ws_s, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: w6c_ww failed\n", rows[i].label); - fail++; unlink(src); unlink(cs_s); continue; + fail++; runwait(rmcmd); continue; } if (slurp_eq(cs_s, ws_s) != 0) { fprintf(stderr, @@ -211,7 +206,7 @@ main(void) "byte-id violation)\n", rows[i].label); fail++; } - unlink(src); unlink(cs_s); unlink(ws_s); + runwait(rmcmd); } if (fail) { diff --git a/test/wcc/956_modqualdestr_run.c b/test/wcc/956_modqualdestr_run.c index 6e85651a..f43649a3 100644 --- a/test/wcc/956_modqualdestr_run.c +++ b/test/wcc/956_modqualdestr_run.c @@ -34,7 +34,6 @@ */ #include #include -#include #include #include #include @@ -181,65 +180,66 @@ main(void) int n = 0, fail = 0; for (int i = 0; rows[i].src; i++, n++) { - char src[64]; - snprintf(src, sizeof src, "/tmp/wwmqd_%d_%d.ww", getpid(), i); + /* src, outbin, cs.s, ww.s, err all live under one tmpdir so + * the compiler's path-derived .sepwork scratch stays inside it + * and a single rm -rf reclaims everything (V3). */ + char tmpdir[64], rmcmd[160]; + snprintf(tmpdir, sizeof tmpdir, "/tmp/wwmqd_%d_d_%d", + getpid(), i); + mkdir(tmpdir, 0755); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); + + char src[128]; + snprintf(src, sizeof src, "%s/wwmqd_%d_%d.ww", + tmpdir, getpid(), i); FILE *f = fopen(src, "wb"); - if (f == NULL) { fail++; continue; } + if (f == NULL) { fail++; runwait(rmcmd); continue; } fputs(rows[i].src, f); fclose(f); char cmd[2048]; - /* (a) cstage build + run in a scratch dir. */ - char tmpdir[64]; - snprintf(tmpdir, sizeof tmpdir, "/tmp/wwmqd_%d_d_%d", - getpid(), i); - mkdir(tmpdir, 0755); + /* (a) cstage build + run. */ + char outbin[128]; + snprintf(outbin, sizeof outbin, "%s/wwmqd_%d_%d", + tmpdir, getpid(), i); - snprintf(cmd, sizeof cmd, "cd %s && %s/ww build %s", - tmpdir, bin, src); + snprintf(cmd, sizeof cmd, "%s/ww build -o %s %s", + bin, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: cstage build failed\n", rows[i].label); fail++; - unlink(src); rmdir(tmpdir); + runwait(rmcmd); continue; } - char outbin[128]; - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; - int got = runwait(outbin); if (got != rows[i].want_exit) { fprintf(stderr, "row[%s]: cstage exit %d, want %d\n", rows[i].label, got, rows[i].want_exit); fail++; } - unlink(outbin); rmdir(tmpdir); /* (b) cs==ww byte-id gate: emit .s from both stages, cmp. */ - char cs_s[64], ws_s[64]; - snprintf(cs_s, sizeof cs_s, "/tmp/wwmqd_%d_%d_cs.s", - getpid(), i); - snprintf(ws_s, sizeof ws_s, "/tmp/wwmqd_%d_%d_ww.s", - getpid(), i); + char cs_s[128], ws_s[128]; + snprintf(cs_s, sizeof cs_s, "%s/wwmqd_%d_%d_cs.s", + tmpdir, getpid(), i); + snprintf(ws_s, sizeof ws_s, "%s/wwmqd_%d_%d_ww.s", + tmpdir, getpid(), i); snprintf(cmd, sizeof cmd, "%s -o %s %s 2>/dev/null", w6c, cs_s, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: w6c failed\n", rows[i].label); - fail++; unlink(src); continue; + fail++; runwait(rmcmd); continue; } snprintf(cmd, sizeof cmd, "%s -o %s %s 2>/dev/null", w6c_ww, ws_s, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: w6c_ww failed\n", rows[i].label); - fail++; unlink(src); unlink(cs_s); continue; + fail++; runwait(rmcmd); continue; } if (slurp_eq(cs_s, ws_s) != 0) { fprintf(stderr, @@ -253,9 +253,9 @@ main(void) * `asserttyped:` diagnostic on its idents. Non-vacuous — * pre-fix (HEAD) w6c_ww fires asserttyped on every binding use * (and the float row loud-aborts in cgen above). */ - char errf[80]; + char errf[128]; snprintf(errf, sizeof errf, - "/tmp/wwmqd_%d_%d_err.txt", getpid(), i); + "%s/wwmqd_%d_%d_err.txt", tmpdir, getpid(), i); snprintf(cmd, sizeof cmd, "%s -o /dev/null %s 2>%s", w6c_ww, src, errf); runwait(cmd); @@ -265,8 +265,7 @@ main(void) "(destructure binding unstamped)\n", rows[i].label); fail++; } - unlink(errf); - unlink(src); unlink(cs_s); unlink(ws_s); + runwait(rmcmd); } if (fail) { diff --git a/test/wcc/956_tuprecv_f64_run.c b/test/wcc/956_tuprecv_f64_run.c index 47735620..549e64d6 100644 --- a/test/wcc/956_tuprecv_f64_run.c +++ b/test/wcc/956_tuprecv_f64_run.c @@ -61,7 +61,6 @@ */ #include #include -#include #include #include #include @@ -471,10 +470,17 @@ main(void) int n = 0, fail = 0; for (int i = 0; rows[i].src; i++, n++) { - char src[64]; - snprintf(src, sizeof src, "/tmp/wwtupf_%d_%d.ww", getpid(), i); + char tmpdir[64], src[128], outbin[128], rmcmd[160]; + snprintf(tmpdir, sizeof tmpdir, "/tmp/wwtupf_%d_d_%d", + getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/wwtupf_%d_%d.ww", + tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/wwtupf_%d_%d", + tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (f == NULL) { fail++; continue; } + if (f == NULL) { runwait(rmcmd); fail++; continue; } fputs(rows[i].src, f); fclose(f); @@ -487,13 +493,9 @@ main(void) * byte-id cmp is skipped. Discriminates against master, which * has no SSE cap and builds the (mis)compile. */ if (rows[i].want_compile_fail) { - char ldir[64]; - snprintf(ldir, sizeof ldir, "/tmp/wwtupf_%d_l_%d", - getpid(), i); - mkdir(ldir, 0755); snprintf(cmd, sizeof cmd, - "cd %s && %s/ww build %s >/dev/null 2>&1", - ldir, bin, src); + "%s/ww build -o %s %s >/dev/null 2>&1", + bin, outbin, src); if (runwait(cmd) == 0) { fprintf(stderr, "row[%s]: cstage build SUCCEEDED, " "want loud-stop (SSE cap)\n", rows[i].label); @@ -513,40 +515,27 @@ main(void) "loud-stop\n", rows[i].label); fail++; } - unlink(src); rmdir(ldir); + runwait(rmcmd); continue; } /* (a) cstage build + run in a scratch dir. */ - char tmpdir[64]; - snprintf(tmpdir, sizeof tmpdir, "/tmp/wwtupf_%d_d_%d", - getpid(), i); - mkdir(tmpdir, 0755); - - snprintf(cmd, sizeof cmd, "cd %s && %s/ww build %s", - tmpdir, bin, src); + snprintf(cmd, sizeof cmd, "%s/ww build -o %s %s", + bin, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: cstage build failed\n", rows[i].label); fail++; - unlink(src); rmdir(tmpdir); + runwait(rmcmd); continue; } - char outbin[128]; - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; - int got = runwait(outbin); if (got != rows[i].want_exit) { fprintf(stderr, "row[%s]: cstage exit %d, want %d\n", rows[i].label, got, rows[i].want_exit); fail++; } - unlink(outbin); rmdir(tmpdir); /* (b) cs==ww byte-id gate: emit .s from both stages, cmp. */ char cs_s[64], ws_s[64]; @@ -559,14 +548,14 @@ main(void) w6c, cs_s, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: w6c failed\n", rows[i].label); - fail++; unlink(src); continue; + fail++; runwait(rmcmd); continue; } snprintf(cmd, sizeof cmd, "%s -o %s %s 2>/dev/null", w6c_ww, ws_s, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: w6c_ww failed\n", rows[i].label); - fail++; unlink(src); unlink(cs_s); continue; + fail++; runwait(rmcmd); unlink(cs_s); continue; } if (slurp_eq(cs_s, ws_s) != 0) { fprintf(stderr, @@ -597,7 +586,7 @@ main(void) } unlink(errf); } - unlink(src); unlink(cs_s); unlink(ws_s); + runwait(rmcmd); unlink(cs_s); unlink(ws_s); } if (fail) { diff --git a/test/wcc/957_assert_builtin_run.c b/test/wcc/957_assert_builtin_run.c index d93bef85..96b9f741 100644 --- a/test/wcc/957_assert_builtin_run.c +++ b/test/wcc/957_assert_builtin_run.c @@ -224,12 +224,17 @@ main(void) char errbuf[4096]; int n = 0, fail = 0; for (int i = 0; rows[i].src; i++, n++) { - char src[64], errf[64]; - snprintf(src, sizeof src, "/tmp/wwasrt_%d_%d.ww", getpid(), i); - snprintf(errf, sizeof errf, "/tmp/wwasrt_%d_%d.err", + char tmpdir[64], src[128], errf[128], rmcmd[160]; + snprintf(tmpdir, sizeof tmpdir, "/tmp/wwasrt_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/wwasrt_%d_%d.ww", + tmpdir, getpid(), i); + snprintf(errf, sizeof errf, "%s/wwasrt_%d_%d.err", + tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (f == NULL) { fail++; continue; } + if (f == NULL) { runwait(rmcmd); fail++; continue; } fputs(rows[i].src, f); fclose(f); @@ -257,34 +262,26 @@ main(void) fail++; } } - unlink(src); unlink(errf); + runwait(rmcmd); continue; } /* (a) cstage build + run in a scratch dir. */ - char tmpdir[64]; - snprintf(tmpdir, sizeof tmpdir, "/tmp/wwasrt_%d_d_%d", - getpid(), i); - mkdir(tmpdir, 0755); + char outbin[128]; + snprintf(outbin, sizeof outbin, "%s/wwasrt_%d_%d", + tmpdir, getpid(), i); char cmd[2048]; - snprintf(cmd, sizeof cmd, "cd %s && %s/ww build %s " - ">/dev/null 2>&1", tmpdir, bin, src); + snprintf(cmd, sizeof cmd, "%s/ww build -o %s %s " + ">/dev/null 2>&1", bin, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: cstage build failed\n", rows[i].label); fail++; - unlink(src); rmdir(tmpdir); + runwait(rmcmd); continue; } - char outbin[128]; - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; - snprintf(cmd, sizeof cmd, "%s >/dev/null 2>%s", outbin, errf); int got = runwait(cmd); if (got != rows[i].want_exit) { @@ -306,27 +303,26 @@ main(void) rows[i].label); fail++; } - unlink(outbin); rmdir(tmpdir); unlink(errf); /* (b) cs==ww byte-id gate. */ - char cs_s[64], ws_s[64]; - snprintf(cs_s, sizeof cs_s, "/tmp/wwasrt_%d_%d_cs.s", - getpid(), i); - snprintf(ws_s, sizeof ws_s, "/tmp/wwasrt_%d_%d_ww.s", - getpid(), i); + char cs_s[128], ws_s[128]; + snprintf(cs_s, sizeof cs_s, "%s/wwasrt_%d_%d_cs.s", + tmpdir, getpid(), i); + snprintf(ws_s, sizeof ws_s, "%s/wwasrt_%d_%d_ww.s", + tmpdir, getpid(), i); snprintf(cmd, sizeof cmd, "%s -o %s %s 2>/dev/null", w6c, cs_s, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: w6c failed\n", rows[i].label); - fail++; unlink(src); continue; + fail++; runwait(rmcmd); continue; } snprintf(cmd, sizeof cmd, "%s -o %s %s 2>/dev/null", w6c_ww, ws_s, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: w6c_ww failed\n", rows[i].label); - fail++; unlink(src); unlink(cs_s); continue; + fail++; runwait(rmcmd); continue; } if (slurp_eq(cs_s, ws_s) != 0) { fprintf(stderr, @@ -334,7 +330,7 @@ main(void) "byte-id violation)\n", rows[i].label); fail++; } - unlink(src); unlink(cs_s); unlink(ws_s); + runwait(rmcmd); } if (fail) { diff --git a/test/wcc/958_types_sizelim_run.c b/test/wcc/958_types_sizelim_run.c index 7b1593c2..b62ac14a 100644 --- a/test/wcc/958_types_sizelim_run.c +++ b/test/wcc/958_types_sizelim_run.c @@ -22,7 +22,6 @@ */ #include #include -#include #include #include #include @@ -99,43 +98,41 @@ main(void) int n = 0, fail = 0; for (int i = 0; rows[i].src; i++, n++) { - char src[64]; - snprintf(src, sizeof src, "/tmp/wwslim_%d_%d.ww", getpid(), i); + char tmpdir[64]; + snprintf(tmpdir, sizeof tmpdir, "/tmp/wwslim_%d_%d", getpid(), i); + mkdir(tmpdir, 0755); + char rmcmd[128]; + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); + + char src[128]; + snprintf(src, sizeof src, "%s/wwslim_%d_%d.ww", tmpdir, getpid(), i); FILE *f = fopen(src, "wb"); - if (f == NULL) { fail++; continue; } + if (f == NULL) { fail++; runwait(rmcmd); continue; } fputs(rows[i].src, f); fclose(f); - char tmpdir[64]; - snprintf(tmpdir, sizeof tmpdir, "/tmp/wwslim_%d_d_%d", getpid(), i); - mkdir(tmpdir, 0755); + char outbin[128]; + snprintf(outbin, sizeof outbin, "%s/out", tmpdir); char cmd[2048]; - snprintf(cmd, sizeof cmd, "cd %s && %s/ww build -I %s/lib %s", - tmpdir, bin, cwd, src); + snprintf(cmd, sizeof cmd, "%s/ww build -I %s/lib -o %s %s", + bin, cwd, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row %d: build failed\n src: %s\n", i, rows[i].src); fail++; - unlink(src); rmdir(tmpdir); + runwait(rmcmd); continue; } - char outbin[128]; - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; - int got = runwait(outbin); if (got != rows[i].want_exit) { fprintf(stderr, "row %d: exit %d, want %d\n src: %s\n", i, got, rows[i].want_exit, rows[i].src); fail++; } - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); } if (fail) { fprintf(stderr, "%d/%d types_sizelim tests failed\n", fail, n); diff --git a/test/wcc/959_types_intlim_run.c b/test/wcc/959_types_intlim_run.c index 858d4c47..3f940f4c 100644 --- a/test/wcc/959_types_intlim_run.c +++ b/test/wcc/959_types_intlim_run.c @@ -19,7 +19,6 @@ */ #include #include -#include #include #include #include @@ -98,43 +97,42 @@ main(void) int n = 0, fail = 0; for (int i = 0; rows[i].src; i++, n++) { - char src[64]; - snprintf(src, sizeof src, "/tmp/wwilim_%d_%d.ww", getpid(), i); + char tmpdir[64]; + snprintf(tmpdir, sizeof tmpdir, "/tmp/wwilim_%d_%d", getpid(), i); + mkdir(tmpdir, 0755); + + char rmcmd[128]; + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); + + char src[128]; + snprintf(src, sizeof src, "%s/wwilim_%d_%d.ww", tmpdir, getpid(), i); FILE *f = fopen(src, "wb"); - if (f == NULL) { fail++; continue; } + if (f == NULL) { fail++; runwait(rmcmd); continue; } fputs(rows[i].src, f); fclose(f); - char tmpdir[64]; - snprintf(tmpdir, sizeof tmpdir, "/tmp/wwilim_%d_d_%d", getpid(), i); - mkdir(tmpdir, 0755); + char outbin[128]; + snprintf(outbin, sizeof outbin, "%s/out", tmpdir); char cmd[2048]; - snprintf(cmd, sizeof cmd, "cd %s && %s/ww build -I %s/lib %s", - tmpdir, bin, cwd, src); + snprintf(cmd, sizeof cmd, "%s/ww build -I %s/lib -o %s %s", + bin, cwd, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row %d: build failed\n src: %s\n", i, rows[i].src); fail++; - unlink(src); rmdir(tmpdir); + runwait(rmcmd); continue; } - char outbin[128]; - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; - int got = runwait(outbin); if (got != rows[i].want_exit) { fprintf(stderr, "row %d: exit %d, want %d\n src: %s\n", i, got, rows[i].want_exit, rows[i].src); fail++; } - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); } if (fail) { fprintf(stderr, "%d/%d types_intlim tests failed\n", fail, n); diff --git a/test/wcc/960_opaque_decl_run.c b/test/wcc/960_opaque_decl_run.c index 8d2b54af..0f2c161e 100644 --- a/test/wcc/960_opaque_decl_run.c +++ b/test/wcc/960_opaque_decl_run.c @@ -24,7 +24,6 @@ */ #include #include -#include #include #include #include @@ -101,43 +100,42 @@ main(void) int n = 0, fail = 0; for (int i = 0; rows[i].src; i++, n++) { - char src[64]; - snprintf(src, sizeof src, "/tmp/wwopq_%d_%d.ww", getpid(), i); + char tmpdir[64]; + snprintf(tmpdir, sizeof tmpdir, "/tmp/wwopq_%d_%d", getpid(), i); + mkdir(tmpdir, 0755); + + char rmcmd[128]; + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); + + char src[128]; + snprintf(src, sizeof src, "%s/wwopq_%d_%d.ww", tmpdir, getpid(), i); FILE *f = fopen(src, "wb"); - if (f == NULL) { fail++; continue; } + if (f == NULL) { fail++; runwait(rmcmd); continue; } fputs(rows[i].src, f); fclose(f); - char tmpdir[64]; - snprintf(tmpdir, sizeof tmpdir, "/tmp/wwopq_%d_d_%d", getpid(), i); - mkdir(tmpdir, 0755); + char outbin[128]; + snprintf(outbin, sizeof outbin, "%s/out", tmpdir); char cmd[2048]; - snprintf(cmd, sizeof cmd, "cd %s && %s/ww build -I %s/lib %s", - tmpdir, bin, cwd, src); + snprintf(cmd, sizeof cmd, "%s/ww build -I %s/lib -o %s %s", + bin, cwd, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row %d: build failed\n src: %s\n", i, rows[i].src); fail++; - unlink(src); rmdir(tmpdir); + runwait(rmcmd); continue; } - char outbin[128]; - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; - int got = runwait(outbin); if (got != rows[i].want_exit) { fprintf(stderr, "row %d: exit %d, want %d\n src: %s\n", i, got, rows[i].want_exit, rows[i].src); fail++; } - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); } if (fail) { fprintf(stderr, "%d/%d opaque tests failed\n", fail, n); diff --git a/test/wcc/961_opaque_guards.c b/test/wcc/961_opaque_guards.c index 69987260..442bd9df 100644 --- a/test/wcc/961_opaque_guards.c +++ b/test/wcc/961_opaque_guards.c @@ -70,7 +70,6 @@ */ #include #include -#include #include #include #include @@ -232,31 +231,22 @@ static const struct row rows[] = { static int run_row(const char *driver, const struct row *r, int i) { - char src[128], tmpdir[128], cmd[2048]; - snprintf(src, sizeof src, "/tmp/wcopg_%d_%d.ww", getpid(), i); + char src[128], tmpdir[128], outbin[128], rmcmd[160], cmd[2048]; snprintf(tmpdir, sizeof tmpdir, "/tmp/wcopg_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/wcopg_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/wcopg_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s >/dev/null 2>&1", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s >/dev/null 2>&1", + driver, outbin, src); int rc = runwait(cmd); - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[256]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; - - char combined[256]; - snprintf(combined, sizeof combined, "/tmp/wcopg_%d_%d.combined.ww", - getpid(), i); - if (r->kind == 0) { /* Negative — build must fail. */ int bad = (rc == 0); @@ -264,27 +254,19 @@ run_row(const char *driver, const struct row *r, int i) fprintf(stderr, "opaque-guard[%s]: build unexpectedly succeeded\n", r->label); - unlink(outbin); } - unlink(src); - unlink(combined); - rmdir(tmpdir); + runwait(rmcmd); return bad ? -1 : 0; } /* Positive — build then run. */ if (rc != 0) { fprintf(stderr, "opaque-guard[%s]: build failed\n", r->label); - unlink(src); - unlink(combined); - rmdir(tmpdir); + runwait(rmcmd); return -1; } int got = runwait(outbin); - unlink(src); - unlink(outbin); - unlink(combined); - rmdir(tmpdir); + runwait(rmcmd); if (got != r->want) { fprintf(stderr, "opaque-guard[%s]: exit=%d want=%d\n", r->label, got, r->want); diff --git a/test/wcc/962_opaque_assign_cast_run.c b/test/wcc/962_opaque_assign_cast_run.c index 27f71cfb..e6b6d8cd 100644 --- a/test/wcc/962_opaque_assign_cast_run.c +++ b/test/wcc/962_opaque_assign_cast_run.c @@ -64,7 +64,6 @@ */ #include #include -#include #include #include #include @@ -203,64 +202,65 @@ main(void) int n = 0, fail = 0; for (int i = 0; rows[i].src; i++, n++) { - char src[64]; - snprintf(src, sizeof src, "/tmp/wwopqc_%d_%d.ww", getpid(), i); - FILE *f = fopen(src, "wb"); - if (f == NULL) { fail++; continue; } - fputs(rows[i].src, f); - fclose(f); - - /* (a) cstage build + run in a scratch dir. */ + /* src reused across (a) build+run AND (b) the byte-id phase; + * keep src, outbin, cs.s, ws.s ALL under the one tmpdir and + * defer a single rm -rf to the end so .sepwork never leaks. */ char tmpdir[64]; snprintf(tmpdir, sizeof tmpdir, "/tmp/wwopqc_%d_d_%d", getpid(), i); mkdir(tmpdir, 0755); + char rmcmd[160]; + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); + + char src[128], outbin[128]; + snprintf(src, sizeof src, "%s/wwopqc_%d_%d.ww", + tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/wwopqc_%d_%d", + tmpdir, getpid(), i); + FILE *f = fopen(src, "wb"); + if (f == NULL) { runwait(rmcmd); fail++; continue; } + fputs(rows[i].src, f); + fclose(f); + + /* (a) cstage build + run. */ char cmd[2048]; - snprintf(cmd, sizeof cmd, "cd %s && %s/ww build %s", - tmpdir, bin, src); + snprintf(cmd, sizeof cmd, "%s/ww build -o %s %s", + bin, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: cstage build failed\n", rows[i].label); fail++; - unlink(src); rmdir(tmpdir); + runwait(rmcmd); continue; } - char outbin[128]; - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; - int got = runwait(outbin); if (got != rows[i].want_exit) { fprintf(stderr, "row[%s]: cstage exit %d, want %d\n", rows[i].label, got, rows[i].want_exit); fail++; } - unlink(outbin); rmdir(tmpdir); /* (b) cs==ww byte-id gate: emit .s from both stages, cmp. */ - char cs_s[64], ws_s[64]; - snprintf(cs_s, sizeof cs_s, "/tmp/wwopqc_%d_%d_cs.s", - getpid(), i); - snprintf(ws_s, sizeof ws_s, "/tmp/wwopqc_%d_%d_ww.s", - getpid(), i); + char cs_s[160], ws_s[160]; + snprintf(cs_s, sizeof cs_s, "%s/wwopqc_%d_%d_cs.s", + tmpdir, getpid(), i); + snprintf(ws_s, sizeof ws_s, "%s/wwopqc_%d_%d_ww.s", + tmpdir, getpid(), i); snprintf(cmd, sizeof cmd, "%s -o %s %s 2>/dev/null", w6c, cs_s, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: w6c failed\n", rows[i].label); - fail++; unlink(src); continue; + fail++; runwait(rmcmd); continue; } snprintf(cmd, sizeof cmd, "%s -o %s %s 2>/dev/null", w6c_ww, ws_s, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: w6c_ww failed\n", rows[i].label); - fail++; unlink(src); unlink(cs_s); continue; + fail++; runwait(rmcmd); continue; } if (slurp_eq(cs_s, ws_s) != 0) { fprintf(stderr, @@ -268,7 +268,7 @@ main(void) "byte-id violation)\n", rows[i].label); fail++; } - unlink(src); unlink(cs_s); unlink(ws_s); + runwait(rmcmd); } if (fail) { diff --git a/test/wcc/963_sort_run.c b/test/wcc/963_sort_run.c index ee98e5a8..54bdbc94 100644 --- a/test/wcc/963_sort_run.c +++ b/test/wcc/963_sort_run.c @@ -27,7 +27,6 @@ */ #include #include -#include #include #include #include @@ -143,42 +142,41 @@ main(void) int n = 0, fail = 0; for (int i = 0; rows[i].src; i++, n++) { - char src[64]; - snprintf(src, sizeof src, "/tmp/wwsort_%d_%d.ww", getpid(), i); + char tmpdir[64]; + snprintf(tmpdir, sizeof tmpdir, "/tmp/wwsort_%d_%d", getpid(), i); + mkdir(tmpdir, 0755); + + char rmcmd[128]; + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); + + char src[128]; + snprintf(src, sizeof src, "%s/wwsort_%d_%d.ww", tmpdir, getpid(), i); FILE *f = fopen(src, "wb"); - if (f == NULL) { fail++; continue; } + if (f == NULL) { fail++; runwait(rmcmd); continue; } fputs(rows[i].src, f); fclose(f); - char tmpdir[64]; - snprintf(tmpdir, sizeof tmpdir, "/tmp/wwsort_%d_d_%d", getpid(), i); - mkdir(tmpdir, 0755); + char outbin[128]; + snprintf(outbin, sizeof outbin, "%s/out", tmpdir); char cmd[2048]; - snprintf(cmd, sizeof cmd, "cd %s && %s/ww build -I %s/lib %s", - tmpdir, bin, cwd, src); + snprintf(cmd, sizeof cmd, "%s/ww build -I %s/lib -o %s %s", + bin, cwd, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: build failed\n", rows[i].label); fail++; - unlink(src); rmdir(tmpdir); + runwait(rmcmd); continue; } - char outbin[128]; - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; - int got = runwait(outbin); if (got != rows[i].want_exit) { fprintf(stderr, "row[%s]: exit %d, want %d\n", rows[i].label, got, rows[i].want_exit); fail++; } - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); } if (fail) { fprintf(stderr, "%d/%d sort tests failed\n", fail, n); diff --git a/test/wcc/964_f32lit_run.c b/test/wcc/964_f32lit_run.c index 14e2e397..a8db3bc4 100644 --- a/test/wcc/964_f32lit_run.c +++ b/test/wcc/964_f32lit_run.c @@ -30,7 +30,6 @@ */ #include #include -#include #include #include #include @@ -141,64 +140,59 @@ main(void) int n = 0, fail = 0; for (int i = 0; rows[i].src; i++, n++) { - char src[64]; - snprintf(src, sizeof src, "/tmp/wwf32l_%d_%d.ww", getpid(), i); - FILE *f = fopen(src, "wb"); - if (f == NULL) { fail++; continue; } - fputs(rows[i].src, f); - fclose(f); - - /* (a) cstage build + run. */ char tmpdir[64]; snprintf(tmpdir, sizeof tmpdir, "/tmp/wwf32l_%d_d_%d", getpid(), i); mkdir(tmpdir, 0755); + char src[128], outbin[128], cs_s[128], ws_s[128], rmcmd[160]; + snprintf(src, sizeof src, "%s/wwf32l_%d_%d.ww", + tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/wwf32l_%d_%d", + tmpdir, getpid(), i); + snprintf(cs_s, sizeof cs_s, "%s/wwf32l_%d_%d_cs.s", + tmpdir, getpid(), i); + snprintf(ws_s, sizeof ws_s, "%s/wwf32l_%d_%d_ww.s", + tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); + + FILE *f = fopen(src, "wb"); + if (f == NULL) { runwait(rmcmd); fail++; continue; } + fputs(rows[i].src, f); + fclose(f); + + /* (a) cstage build + run. */ char cmd[2048]; - snprintf(cmd, sizeof cmd, "cd %s && %s/ww build %s", - tmpdir, bin, src); + snprintf(cmd, sizeof cmd, "%s/ww build -o %s %s", + bin, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: cstage build failed\n", rows[i].label); fail++; - unlink(src); rmdir(tmpdir); + runwait(rmcmd); continue; } - char outbin[128]; - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; - int got = runwait(outbin); if (got != rows[i].want_exit) { fprintf(stderr, "row[%s]: cstage exit %d, want %d\n", rows[i].label, got, rows[i].want_exit); fail++; } - unlink(outbin); rmdir(tmpdir); /* (b) cs==ww byte-id gate: emit .s from both stages, cmp. */ - char cs_s[64], ws_s[64]; - snprintf(cs_s, sizeof cs_s, "/tmp/wwf32l_%d_%d_cs.s", - getpid(), i); - snprintf(ws_s, sizeof ws_s, "/tmp/wwf32l_%d_%d_ww.s", - getpid(), i); - snprintf(cmd, sizeof cmd, "%s -o %s %s 2>/dev/null", w6c, cs_s, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: w6c failed\n", rows[i].label); - fail++; unlink(src); continue; + fail++; runwait(rmcmd); continue; } snprintf(cmd, sizeof cmd, "%s -o %s %s 2>/dev/null", w6c_ww, ws_s, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: w6c_ww failed\n", rows[i].label); - fail++; unlink(src); unlink(cs_s); continue; + fail++; runwait(rmcmd); continue; } if (slurp_eq(cs_s, ws_s) != 0) { fprintf(stderr, @@ -206,7 +200,7 @@ main(void) "byte-id violation)\n", rows[i].label); fail++; } - unlink(src); unlink(cs_s); unlink(ws_s); + runwait(rmcmd); } if (fail) { diff --git a/test/wcc/965_f32stamp_run.c b/test/wcc/965_f32stamp_run.c index 4d8107dc..ef3d1819 100644 --- a/test/wcc/965_f32stamp_run.c +++ b/test/wcc/965_f32stamp_run.c @@ -30,7 +30,6 @@ */ #include #include -#include #include #include #include @@ -138,64 +137,64 @@ main(void) int n = 0, fail = 0; for (int i = 0; rows[i].src; i++, n++) { - char src[64]; - snprintf(src, sizeof src, "/tmp/wwf32s_%d_%d.ww", getpid(), i); - FILE *f = fopen(src, "wb"); - if (f == NULL) { fail++; continue; } - fputs(rows[i].src, f); - fclose(f); - - /* (a) cstage build + run. */ char tmpdir[64]; snprintf(tmpdir, sizeof tmpdir, "/tmp/wwf32s_%d_d_%d", getpid(), i); mkdir(tmpdir, 0755); + char rmcmd[160]; + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); + + char src[128]; + snprintf(src, sizeof src, "%s/wwf32s_%d_%d.ww", + tmpdir, getpid(), i); + FILE *f = fopen(src, "wb"); + if (f == NULL) { fail++; runwait(rmcmd); continue; } + fputs(rows[i].src, f); + fclose(f); + + /* (a) cstage build + run. */ + char outbin[128]; + snprintf(outbin, sizeof outbin, "%s/wwf32s_%d_%d", + tmpdir, getpid(), i); + char cmd[2048]; - snprintf(cmd, sizeof cmd, "cd %s && %s/ww build %s", - tmpdir, bin, src); + snprintf(cmd, sizeof cmd, "%s/ww build -o %s %s", + bin, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: cstage build failed\n", rows[i].label); fail++; - unlink(src); rmdir(tmpdir); + runwait(rmcmd); continue; } - char outbin[128]; - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; - int got = runwait(outbin); if (got != rows[i].want_exit) { fprintf(stderr, "row[%s]: cstage exit %d, want %d\n", rows[i].label, got, rows[i].want_exit); fail++; } - unlink(outbin); rmdir(tmpdir); /* (b) cs==ww byte-id gate: emit .s from both stages, cmp. */ - char cs_s[64], ws_s[64]; - snprintf(cs_s, sizeof cs_s, "/tmp/wwf32s_%d_%d_cs.s", - getpid(), i); - snprintf(ws_s, sizeof ws_s, "/tmp/wwf32s_%d_%d_ww.s", - getpid(), i); + char cs_s[128], ws_s[128]; + snprintf(cs_s, sizeof cs_s, "%s/wwf32s_%d_%d_cs.s", + tmpdir, getpid(), i); + snprintf(ws_s, sizeof ws_s, "%s/wwf32s_%d_%d_ww.s", + tmpdir, getpid(), i); snprintf(cmd, sizeof cmd, "%s -o %s %s 2>/dev/null", w6c, cs_s, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: w6c failed\n", rows[i].label); - fail++; unlink(src); continue; + fail++; runwait(rmcmd); continue; } snprintf(cmd, sizeof cmd, "%s -o %s %s 2>/dev/null", w6c_ww, ws_s, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: w6c_ww failed\n", rows[i].label); - fail++; unlink(src); unlink(cs_s); continue; + fail++; runwait(rmcmd); continue; } if (slurp_eq(cs_s, ws_s) != 0) { fprintf(stderr, @@ -203,7 +202,7 @@ main(void) "byte-id violation)\n", rows[i].label); fail++; } - unlink(src); unlink(cs_s); unlink(ws_s); + runwait(rmcmd); } if (fail) { diff --git a/test/wcc/975_dirs_toolong_run.c b/test/wcc/975_dirs_toolong_run.c index c650c5e6..0eb5b99b 100644 --- a/test/wcc/975_dirs_toolong_run.c +++ b/test/wcc/975_dirs_toolong_run.c @@ -15,7 +15,6 @@ */ #include #include -#include #include #include #include @@ -44,25 +43,25 @@ static const char *PROG = static int run_stage(const char *name, const char *driver) { - char src[64], tmpdir[64], cmd[2048]; - snprintf(src, sizeof src, "/tmp/dtl_%d.ww", getpid()); + char tmpdir[64], src[128], outbin[128], rmcmd[160], cmd[2048]; snprintf(tmpdir, sizeof tmpdir, "/tmp/dtl_%d_d", getpid()); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/dtl_%d.ww", tmpdir, getpid()); + snprintf(outbin, sizeof outbin, "%s/dtl_%d", tmpdir, getpid()); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return 1; + if (!f) { runwait(rmcmd); return 1; } fputs(PROG, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>/dev/null", + driver, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "dirs_toolong[%s]: build failed\n", name); - unlink(src); rmdir(tmpdir); + runwait(rmcmd); return 1; } - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/dtl_%d", tmpdir, getpid()); int fail = 0; @@ -101,7 +100,7 @@ run_stage(const char *name, const char *driver) (void)system(cmd); } - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); snprintf(cmd, sizeof cmd, "rm -rf /tmp/dtl_%d_home", getpid()); (void)system(cmd); return fail; diff --git a/test/wcc/978_intdiv_signed.c b/test/wcc/978_intdiv_signed.c index 4f9b1c64..932748c8 100644 --- a/test/wcc/978_intdiv_signed.c +++ b/test/wcc/978_intdiv_signed.c @@ -23,7 +23,6 @@ */ #include #include -#include #include #include #include @@ -375,34 +374,30 @@ static const struct row rows[] = { static int run_driver(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/wwid_%d_%d.ww", getpid(), i); + char src[128], tmpdir[64], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/wwid_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/wwid_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/wwid_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s", + driver, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "row[%s]: build via %s failed\n", r->label, driver); - unlink(src); rmdir(tmpdir); + runwait(rmcmd); return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; int got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return got; } diff --git a/test/wcc/989_allocalias_run.c b/test/wcc/989_allocalias_run.c index cd232c36..a8d1f206 100644 --- a/test/wcc/989_allocalias_run.c +++ b/test/wcc/989_allocalias_run.c @@ -18,7 +18,6 @@ */ #include #include -#include #include #include #include @@ -64,31 +63,26 @@ static const struct row rows[] = { static int run_build(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/alal_%d_%d.ww", getpid(), i); + char tmpdir[64], src[128], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/alal_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/alal_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/alal_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -2; + if (!f) { runwait(rmcmd); return -2; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>/dev/null", + driver, outbin, src); int brc = runwait(cmd); - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; - int got = -1; if (brc == 0) got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return brc == 0 ? got : -1; } diff --git a/test/wcc/989_ampfncollide_run.c b/test/wcc/989_ampfncollide_run.c index b9e6229a..ba4ab5e7 100644 --- a/test/wcc/989_ampfncollide_run.c +++ b/test/wcc/989_ampfncollide_run.c @@ -29,7 +29,6 @@ */ #include #include -#include #include #include #include @@ -83,31 +82,26 @@ static const struct row rows[] = { static int run_build(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/afc_%d_%d.ww", getpid(), i); + char tmpdir[64], src[128], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/afc_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/afc_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/afc_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -2; + if (!f) { runwait(rmcmd); return -2; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>/dev/null", + driver, outbin, src); int brc = runwait(cmd); - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; - int got = -1; if (brc == 0) got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return brc == 0 ? got : -1; /* -1 == build failed */ } diff --git a/test/wcc/989_arrlit_tail_zero_run.c b/test/wcc/989_arrlit_tail_zero_run.c index 4cd0997c..b0a0f0fe 100644 --- a/test/wcc/989_arrlit_tail_zero_run.c +++ b/test/wcc/989_arrlit_tail_zero_run.c @@ -24,7 +24,6 @@ */ #include #include -#include #include #include #include @@ -71,31 +70,26 @@ static const struct row rows[] = { static int run_build(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/atz_%d_%d.ww", getpid(), i); + char tmpdir[64], src[128], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/atz_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/atz_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/atz_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -2; + if (!f) { runwait(rmcmd); return -2; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>/dev/null", + driver, outbin, src); int brc = runwait(cmd); - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; - int got = -1; if (brc == 0) got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return brc == 0 ? got : -1; } diff --git a/test/wcc/989_callarg_typecheck.c b/test/wcc/989_callarg_typecheck.c index 22dbf9c5..9329f1cc 100644 --- a/test/wcc/989_callarg_typecheck.c +++ b/test/wcc/989_callarg_typecheck.c @@ -207,31 +207,26 @@ static const struct row rows[] = { static int run_build(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/cat_%d_%d.ww", getpid(), i); + char tmpdir[64], src[128], outbin[128], cmd[1024], rmcmd[160]; snprintf(tmpdir, sizeof tmpdir, "/tmp/cat_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/cat_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/cat_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -2; + if (!f) { runwait(rmcmd); return -2; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>/dev/null", + driver, outbin, src); int brc = runwait(cmd); - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; - int got = -1; if (brc == 0) got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return brc == 0 ? got : -1; } @@ -256,32 +251,25 @@ static int build_should_fail(const char *driver, const char *src, const char *diag, int i) { - char s[64], tmpdir[64], cmd[1024], errf[64]; - snprintf(s, sizeof s, "/tmp/catn_%d_%d.ww", getpid(), i); + char tmpdir[64], s[128], outbin[128], cmd[1024], errf[160], rmcmd[160]; snprintf(tmpdir, sizeof tmpdir, "/tmp/catn_%d_d_%d", getpid(), i); - snprintf(errf, sizeof errf, "/tmp/catn_%d_e_%d.txt", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(s, sizeof s, "%s/catn_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/catn_%d_%d", tmpdir, getpid(), i); + snprintf(errf, sizeof errf, "%s/err.txt", tmpdir); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(s, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s >/dev/null 2>%s", - tmpdir, driver, s, errf); + snprintf(cmd, sizeof cmd, "%s build -o %s %s >/dev/null 2>%s", + driver, outbin, s, errf); int rc = runwait(cmd); int hasmsg = filehas(errf, diag); - unlink(s); - unlink(errf); - const char *base = strrchr(s, '/'); - base = base ? base + 1 : s; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; - unlink(outbin); - rmdir(tmpdir); + runwait(rmcmd); /* build must NOT succeed AND must emit its diagnostic. */ return (rc != 0 && hasmsg) ? 0 : -1; } @@ -378,10 +366,11 @@ multimod_build_fail(const char *drv, const char *mainbody, int withmod1, snprintf(mod1d, sizeof mod1d, "%s/mod1", dir); mkdir(dir, 0755); mkdir(io2d, 0755); if (withmod1) mkdir(mod1d, 0755); + snprintf(rm, sizeof rm, "rm -rf %s", dir); snprintf(p, sizeof p, "%s/io2.ww", io2d); FILE *f = fopen(p, "wb"); - if (!f) return -1; + if (!f) { runwait(rm); return -1; } fputs("package io2;\n" "export type vtable = struct { x: i32 };\n" "export type stream = *vtable;\n" @@ -393,7 +382,7 @@ multimod_build_fail(const char *drv, const char *mainbody, int withmod1, if (withmod1) { snprintf(p, sizeof p, "%s/mod1.ww", mod1d); f = fopen(p, "wb"); - if (!f) return -1; + if (!f) { runwait(rm); return -1; } fputs("package mod1;\n" "export type wbox = struct { y: i64 };\n" "export type stream = *wbox;\n" @@ -403,7 +392,7 @@ multimod_build_fail(const char *drv, const char *mainbody, int withmod1, snprintf(p, sizeof p, "%s/main.ww", dir); f = fopen(p, "wb"); - if (!f) return -1; + if (!f) { runwait(rm); return -1; } fputs(mainbody, f); fclose(f); @@ -421,7 +410,6 @@ multimod_build_fail(const char *drv, const char *mainbody, int withmod1, /* Both collision rows reject on "not assignable"; a crash would not (#20). */ int hasmsg = filehas(errf, "not assignable"); - snprintf(rm, sizeof rm, "rm -rf %s", dir); runwait(rm); /* build must NOT succeed AND must emit its diagnostic. */ diff --git a/test/wcc/989_catA_f2_reject.c b/test/wcc/989_catA_f2_reject.c index 8148c002..c88e7d0b 100644 --- a/test/wcc/989_catA_f2_reject.c +++ b/test/wcc/989_catA_f2_reject.c @@ -254,31 +254,26 @@ static const struct row rows[] = { static int run_build(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/f2r_%d_%d.ww", getpid(), i); + char src[128], tmpdir[64], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/f2r_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/f2r_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/f2r_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -2; + if (!f) { runwait(rmcmd); return -2; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>/dev/null", + driver, outbin, src); int brc = runwait(cmd); - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; - int got = -1; if (brc == 0) got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return brc == 0 ? got : -1; } @@ -301,32 +296,25 @@ static int build_should_fail(const char *driver, const char *src, const char *diag, int i) { - char s[64], tmpdir[64], cmd[1024], errf[64]; - snprintf(s, sizeof s, "/tmp/f2n_%d_%d.ww", getpid(), i); + char s[128], tmpdir[64], outbin[128], errf[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/f2n_%d_d_%d", getpid(), i); - snprintf(errf, sizeof errf, "/tmp/f2n_%d_e_%d.txt", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(s, sizeof s, "%s/f2n_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/f2n_%d_%d", tmpdir, getpid(), i); + snprintf(errf, sizeof errf, "%s/err", tmpdir); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(s, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s >/dev/null 2>%s", - tmpdir, driver, s, errf); + snprintf(cmd, sizeof cmd, "%s build -o %s %s >/dev/null 2>%s", + driver, outbin, s, errf); int rc = runwait(cmd); int hasmsg = filehas(errf, diag); - unlink(s); - unlink(errf); - const char *base = strrchr(s, '/'); - base = base ? base + 1 : s; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; - unlink(outbin); - rmdir(tmpdir); + runwait(rmcmd); /* build must NOT succeed AND must emit its diagnostic. */ return (rc != 0 && hasmsg) ? 0 : -1; } diff --git a/test/wcc/989_defercap_run.c b/test/wcc/989_defercap_run.c index a22576ed..04af64cb 100644 --- a/test/wcc/989_defercap_run.c +++ b/test/wcc/989_defercap_run.c @@ -23,7 +23,6 @@ */ #include #include -#include #include #include #include @@ -73,28 +72,23 @@ write_src(const char *path, int ndefers) static int build_run(const char *driver, const struct row *r, int i, int *brc) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/dcap_%d_%d.ww", getpid(), i); + char tmpdir[64], src[128], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/dcap_%d_d_%d", getpid(), i); - - if (write_src(src, r->ndefers) != 0) { *brc = -1; return -1; } - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null", - tmpdir, driver, src); - *brc = runwait(cmd); + snprintf(src, sizeof src, "%s/dcap_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/dcap_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; + if (write_src(src, r->ndefers) != 0) { *brc = -1; runwait(rmcmd); return -1; } + + snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>/dev/null", + driver, outbin, src); + *brc = runwait(cmd); int got = -1; if (*brc == 0) got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return got; } diff --git a/test/wcc/989_ffivariadic_run.c b/test/wcc/989_ffivariadic_run.c index 1c267ac3..551abac9 100644 --- a/test/wcc/989_ffivariadic_run.c +++ b/test/wcc/989_ffivariadic_run.c @@ -27,7 +27,6 @@ */ #include #include -#include #include #include #include @@ -133,32 +132,29 @@ static const struct row rows[] = { static int run_build(const char *driver, const char *libdir, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/ffivar_%d_%d.ww", getpid(), i); - snprintf(tmpdir, sizeof tmpdir, "/tmp/ffivar_%d_d_%d", getpid(), i); + char src[128], tmpdir[64], outbin[128], cmd[1024], rmcmd[128]; + snprintf(tmpdir, sizeof tmpdir, "/tmp/ffivar_%d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/ffivar_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/out", tmpdir); + + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -2; + if (!f) { runwait(rmcmd); return -2; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); + /* explicit -o so both the binary and out.sepwork land INSIDE tmpdir */ snprintf(cmd, sizeof cmd, - "cd %s && %s build -L%s -lffifix %s 2>/dev/null", - tmpdir, driver, libdir, src); + "%s build -L%s -lffifix -o %s %s 2>/dev/null", + driver, libdir, outbin, src); int brc = runwait(cmd); - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; - int got = -1; if (brc == 0) got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return brc == 0 ? got : -1; } diff --git a/test/wcc/989_floatlit_run.c b/test/wcc/989_floatlit_run.c index 4969b8f4..40aa3490 100644 --- a/test/wcc/989_floatlit_run.c +++ b/test/wcc/989_floatlit_run.c @@ -131,37 +131,33 @@ main(void) } int fail = 0; - char src[64], cmd[2048]; + char src[128], outbin[128], cs_s[128], ws_s[128], cmd[2048]; - /* fixture 1: vectors — cstage build+run, then byte-id */ - snprintf(src, sizeof src, "/tmp/wwflit_%d.ww", getpid()); - if (writesrc(src, vectors_src) != 0) return 1; - - char tmpdir[64]; + char tmpdir[64], rmcmd[160]; snprintf(tmpdir, sizeof tmpdir, "/tmp/wwflit_%d_d", getpid()); mkdir(tmpdir, 0755); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); - snprintf(cmd, sizeof cmd, "cd %s && %s/ww build %s", tmpdir, bin, src); + /* fixture 1: vectors — cstage build+run, then byte-id */ + snprintf(src, sizeof src, "%s/wwflit_%d.ww", tmpdir, getpid()); + if (writesrc(src, vectors_src) != 0) { runwait(rmcmd); return 1; } + + snprintf(outbin, sizeof outbin, "%s/wwflit_%d", tmpdir, getpid()); + snprintf(cmd, sizeof cmd, "%s/ww build -o %s %s", bin, outbin, src); if (runwait(cmd) != 0) { fprintf(stderr, "floatlit: cstage build failed\n"); fail++; } else { - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/wwflit_%d", tmpdir, - getpid()); int got = runwait(outbin); if (got != 0) { fprintf(stderr, "floatlit: vector row %d has wrong " "bits at runtime (cstage)\n", got); fail++; } - unlink(outbin); } - rmdir(tmpdir); - char cs_s[64], ws_s[64]; - snprintf(cs_s, sizeof cs_s, "/tmp/wwflit_%d_cs.s", getpid()); - snprintf(ws_s, sizeof ws_s, "/tmp/wwflit_%d_ww.s", getpid()); + snprintf(cs_s, sizeof cs_s, "%s/wwflit_%d_cs.s", tmpdir, getpid()); + snprintf(ws_s, sizeof ws_s, "%s/wwflit_%d_ww.s", tmpdir, getpid()); snprintf(cmd, sizeof cmd, "%s -o %s %s 2>/dev/null", w6c, cs_s, src); if (runwait(cmd) != 0) { fprintf(stderr, "floatlit: w6c failed on vectors\n"); @@ -178,11 +174,10 @@ main(void) fail++; } } - unlink(src); unlink(cs_s); unlink(ws_s); /* fixture 2: overflow literal — BOTH stages must reject */ - snprintf(src, sizeof src, "/tmp/wwflit_%d_ovf.ww", getpid()); - if (writesrc(src, overflow_src) != 0) return 1; + snprintf(src, sizeof src, "%s/wwflit_%d_ovf.ww", tmpdir, getpid()); + if (writesrc(src, overflow_src) != 0) { runwait(rmcmd); return 1; } snprintf(cmd, sizeof cmd, "%s %s >/dev/null 2>&1", w6c, src); if (runwait(cmd) == 0) { fprintf(stderr, "floatlit: w6c ACCEPTED overflow literal\n"); @@ -193,7 +188,7 @@ main(void) fprintf(stderr, "floatlit: w6c_ww ACCEPTED overflow literal\n"); fail++; } - unlink(src); + runwait(rmcmd); if (fail) { fprintf(stderr, "floatlit: %d check(s) failed\n", fail); diff --git a/test/wcc/989_globfloatstructarg_run.c b/test/wcc/989_globfloatstructarg_run.c index 6bd02de4..d7be1e01 100644 --- a/test/wcc/989_globfloatstructarg_run.c +++ b/test/wcc/989_globfloatstructarg_run.c @@ -27,7 +27,6 @@ */ #include #include -#include #include #include #include @@ -78,31 +77,26 @@ static const struct row rows[] = { static int run_build(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/gfsa_%d_%d.ww", getpid(), i); + char src[128], tmpdir[64], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/gfsa_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/gfsa_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/gfsa_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -2; + if (!f) { runwait(rmcmd); return -2; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>/dev/null", + driver, outbin, src); int brc = runwait(cmd); - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; - int got = -1; if (brc == 0) got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return brc == 0 ? got : -1; } diff --git a/test/wcc/989_globstructwiden_run.c b/test/wcc/989_globstructwiden_run.c index dba22b6d..abb1b5ed 100644 --- a/test/wcc/989_globstructwiden_run.c +++ b/test/wcc/989_globstructwiden_run.c @@ -20,7 +20,6 @@ */ #include #include -#include #include #include #include @@ -74,31 +73,26 @@ static const struct row rows[] = { static int run_build(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/gsw_%d_%d.ww", getpid(), i); + char src[128], tmpdir[64], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/gsw_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/gsw_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/gsw_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -2; + if (!f) { runwait(rmcmd); return -2; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>/dev/null", + driver, outbin, src); int brc = runwait(cmd); - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; - int got = -1; if (brc == 0) got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return brc == 0 ? got : -1; } diff --git a/test/wcc/989_globtagisas_run.c b/test/wcc/989_globtagisas_run.c index be45aa85..64158320 100644 --- a/test/wcc/989_globtagisas_run.c +++ b/test/wcc/989_globtagisas_run.c @@ -32,7 +32,6 @@ */ #include #include -#include #include #include #include @@ -91,31 +90,26 @@ static const struct row rows[] = { static int run_build(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/gtia_%d_%d.ww", getpid(), i); + char tmpdir[64], src[128], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/gtia_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/gtia_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/gtia_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -2; + if (!f) { runwait(rmcmd); return -2; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>/dev/null", + driver, outbin, src); int brc = runwait(cmd); - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; - int got = -1; if (brc == 0) got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return brc == 0 ? got : -1; } diff --git a/test/wcc/989_globtagreassign_run.c b/test/wcc/989_globtagreassign_run.c index aa22dcf0..4822aaae 100644 --- a/test/wcc/989_globtagreassign_run.c +++ b/test/wcc/989_globtagreassign_run.c @@ -20,7 +20,6 @@ */ #include #include -#include #include #include #include @@ -84,31 +83,26 @@ static const struct row rows[] = { static int run_build(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/gtr_%d_%d.ww", getpid(), i); + char tmpdir[64], src[128], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/gtr_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/gtr_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/gtr_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -2; + if (!f) { runwait(rmcmd); return -2; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>/dev/null", + driver, outbin, src); int brc = runwait(cmd); - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; - int got = -1; if (brc == 0) got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return brc == 0 ? got : -1; } diff --git a/test/wcc/989_globtagwiden_run.c b/test/wcc/989_globtagwiden_run.c index 69f32715..140cfe2e 100644 --- a/test/wcc/989_globtagwiden_run.c +++ b/test/wcc/989_globtagwiden_run.c @@ -21,7 +21,6 @@ */ #include #include -#include #include #include #include @@ -84,31 +83,26 @@ static const struct row rows[] = { static int run_build(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/gtw_%d_%d.ww", getpid(), i); + char src[128], tmpdir[64], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/gtw_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/gtw_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/gtw_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -2; + if (!f) { runwait(rmcmd); return -2; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>/dev/null", + driver, outbin, src); int brc = runwait(cmd); - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; - int got = -1; if (brc == 0) got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return brc == 0 ? got : -1; } diff --git a/test/wcc/989_intoverflow_reject.c b/test/wcc/989_intoverflow_reject.c index 90a76cbf..1fcf894e 100644 --- a/test/wcc/989_intoverflow_reject.c +++ b/test/wcc/989_intoverflow_reject.c @@ -94,31 +94,26 @@ static const struct row rows[] = { static int run_build(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/iov_%d_%d.ww", getpid(), i); + char src[128], tmpdir[64], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/iov_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/iov_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/iov_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -2; + if (!f) { runwait(rmcmd); return -2; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>/dev/null", + driver, outbin, src); int brc = runwait(cmd); - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; - int got = -1; if (brc == 0) got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return brc == 0 ? got : -1; } @@ -143,32 +138,25 @@ static int build_should_fail(const char *driver, const char *src, const char *diag, int i) { - char s[64], tmpdir[64], cmd[1024], errf[64]; - snprintf(s, sizeof s, "/tmp/iovn_%d_%d.ww", getpid(), i); + char s[128], tmpdir[64], outbin[128], errf[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/iovn_%d_d_%d", getpid(), i); - snprintf(errf, sizeof errf, "/tmp/iovn_%d_e_%d.txt", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(s, sizeof s, "%s/iovn_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/iovn_%d_%d", tmpdir, getpid(), i); + snprintf(errf, sizeof errf, "%s/err", tmpdir); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(s, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s >/dev/null 2>%s", - tmpdir, driver, s, errf); + snprintf(cmd, sizeof cmd, "%s build -o %s %s >/dev/null 2>%s", + driver, outbin, s, errf); int rc = runwait(cmd); int hasmsg = filehas(errf, diag); - unlink(s); - unlink(errf); - const char *base = strrchr(s, '/'); - base = base ? base + 1 : s; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; - unlink(outbin); - rmdir(tmpdir); + runwait(rmcmd); /* build must NOT succeed AND must emit its diagnostic. */ return (rc != 0 && hasmsg) ? 0 : -1; } diff --git a/test/wcc/989_libprecond_abort.c b/test/wcc/989_libprecond_abort.c index f0a131f8..6ea9e6ee 100644 --- a/test/wcc/989_libprecond_abort.c +++ b/test/wcc/989_libprecond_abort.c @@ -31,7 +31,6 @@ */ #include #include -#include #include #include #include @@ -102,30 +101,25 @@ static const struct row rows[] = { static int build_and_run(const char *driver, const char *incs, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[2048]; - snprintf(src, sizeof src, "/tmp/lpc_%d_%d.ww", getpid(), i); + char tmpdir[64], src[128], outbin[128], rmcmd[160], cmd[2048]; snprintf(tmpdir, sizeof tmpdir, "/tmp/lpc_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/lpc_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/lpc_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -2; + if (!f) { runwait(rmcmd); return -2; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s %s 2>/dev/null", - tmpdir, driver, incs, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s %s 2>/dev/null", + driver, outbin, incs, src); int brc = runwait(cmd); - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[160]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; - int got = (brc == 0) ? runwait(outbin) : -1; - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return brc == 0 ? got : -1; } @@ -145,7 +139,7 @@ main(void) /* random lives at lib/math/random, base64 at lib/encoding/base64; * the leaf-only imports resolve via these -I dirs (base64's own * bytes/io/... deps resolve via the driver's default lib srcdir). - * Absolute so the per-row `cd ` does not break resolution. */ + * Absolute so include resolution does not depend on the build cwd. */ char incs[1024]; snprintf(incs, sizeof incs, "-I %s/lib -I %s/lib/math -I %s/lib/encoding", cwd, cwd, cwd); diff --git a/test/wcc/989_loopcap_run.c b/test/wcc/989_loopcap_run.c index 5fee08ba..24e1efd2 100644 --- a/test/wcc/989_loopcap_run.c +++ b/test/wcc/989_loopcap_run.c @@ -23,7 +23,6 @@ */ #include #include -#include #include #include #include @@ -65,28 +64,23 @@ write_src(const char *path, int depth) static int build_run(const char *driver, const struct row *r, int i, int *brc) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/lcap_%d_%d.ww", getpid(), i); + char tmpdir[64], src[128], outbin[128], cmd[1024], rmcmd[160]; snprintf(tmpdir, sizeof tmpdir, "/tmp/lcap_%d_d_%d", getpid(), i); - - if (write_src(src, r->depth) != 0) { *brc = -1; return -1; } + snprintf(src, sizeof src, "%s/lcap_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/lcap_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null", - tmpdir, driver, src); - *brc = runwait(cmd); + if (write_src(src, r->depth) != 0) { runwait(rmcmd); *brc = -1; return -1; } - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; + snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>/dev/null", + driver, outbin, src); + *brc = runwait(cmd); int got = -1; if (*brc == 0) got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return got; } diff --git a/test/wcc/989_nestfield_run.c b/test/wcc/989_nestfield_run.c index d74c7165..1a949116 100644 --- a/test/wcc/989_nestfield_run.c +++ b/test/wcc/989_nestfield_run.c @@ -35,7 +35,6 @@ */ #include #include -#include #include #include #include @@ -112,31 +111,26 @@ static const struct row rows[] = { static int run_build(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/nestfld_%d_%d.ww", getpid(), i); + char tmpdir[64], src[128], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/nestfld_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/nestfld_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/nestfld_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -2; + if (!f) { runwait(rmcmd); return -2; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>/dev/null", + driver, outbin, src); int brc = runwait(cmd); - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; - int got = -1; if (brc == 0) got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return brc == 0 ? got : -1; } diff --git a/test/wcc/989_nullableglobal_reject.c b/test/wcc/989_nullableglobal_reject.c index dc5863bf..296e4847 100644 --- a/test/wcc/989_nullableglobal_reject.c +++ b/test/wcc/989_nullableglobal_reject.c @@ -140,31 +140,26 @@ static const struct row rows[] = { static int run_build(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/nbg_%d_%d.ww", getpid(), i); + char tmpdir[64], src[128], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/nbg_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/nbg_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/nbg_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -2; + if (!f) { runwait(rmcmd); return -2; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>/dev/null", + driver, outbin, src); int brc = runwait(cmd); - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; - int got = -1; if (brc == 0) got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return brc == 0 ? got : -1; } @@ -173,19 +168,21 @@ run_build(const char *driver, const struct row *r, int i) static int build_should_reject(const char *driver, const char *src, int i) { - char s[64], tmpdir[64], errf[80], cmd[1280]; - snprintf(s, sizeof s, "/tmp/nbn_%d_%d.ww", getpid(), i); + char tmpdir[64], s[128], outbin[128], errf[128], rmcmd[160], cmd[1280]; snprintf(tmpdir, sizeof tmpdir, "/tmp/nbn_%d_d_%d", getpid(), i); - snprintf(errf, sizeof errf, "/tmp/nbn_%d_%d.err", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(s, sizeof s, "%s/nbn_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/nbn_%d_%d", tmpdir, getpid(), i); + snprintf(errf, sizeof errf, "%s/nbn_%d_%d.err", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(s, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>%s", - tmpdir, driver, s, errf); + snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>%s", + driver, outbin, s, errf); int rc = runwait(cmd); int have_diag = 0; @@ -198,15 +195,7 @@ build_should_reject(const char *driver, const char *src, int i) have_diag = (strstr(buf, DIAG) != NULL); } - unlink(s); unlink(errf); - const char *base = strrchr(s, '/'); - base = base ? base + 1 : s; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; - unlink(outbin); - rmdir(tmpdir); + runwait(rmcmd); /* build must NOT succeed AND the shared diagnostic must appear. */ return (rc != 0 && have_diag) ? 0 : -1; diff --git a/test/wcc/989_tagged_subset_reject.c b/test/wcc/989_tagged_subset_reject.c index fc877a96..a27b147e 100644 --- a/test/wcc/989_tagged_subset_reject.c +++ b/test/wcc/989_tagged_subset_reject.c @@ -194,31 +194,26 @@ static const struct row rows[] = { static int run_build(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/tsr_%d_%d.ww", getpid(), i); + char src[128], tmpdir[64], outbin[128], cmd[1024], rmcmd[160]; snprintf(tmpdir, sizeof tmpdir, "/tmp/tsr_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/tsr_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/tsr_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -2; + if (!f) { runwait(rmcmd); return -2; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>/dev/null", + driver, outbin, src); int brc = runwait(cmd); - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; - int got = -1; if (brc == 0) got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return brc == 0 ? got : -1; } @@ -241,32 +236,28 @@ static int build_should_fail(const char *driver, const char *src, const char *diag, int i) { - char s[64], tmpdir[64], cmd[1024], errf[64]; - snprintf(s, sizeof s, "/tmp/tsrn_%d_%d.ww", getpid(), i); + char s[128], tmpdir[64], outbin[128], cmd[1024], errf[128], rmcmd[160]; + /* Source, binary, and the OUTPUT-stem-keyed `.sepwork` all land inside + * tmpdir; a reject build still mkdir's the scratch + emits .sepwork + * before failing, so `rm -rf tmpdir` (not unlink/rmdir) cleans it. */ snprintf(tmpdir, sizeof tmpdir, "/tmp/tsrn_%d_d_%d", getpid(), i); - snprintf(errf, sizeof errf, "/tmp/tsrn_%d_e_%d.txt", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(s, sizeof s, "%s/tsrn_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/tsrn_%d_%d", tmpdir, getpid(), i); + snprintf(errf, sizeof errf, "%s/tsrn_%d_e_%d.txt", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(s, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s >/dev/null 2>%s", - tmpdir, driver, s, errf); + snprintf(cmd, sizeof cmd, "%s build -o %s %s >/dev/null 2>%s", + driver, outbin, s, errf); int rc = runwait(cmd); int hasmsg = filehas(errf, diag); - unlink(s); - unlink(errf); - const char *base = strrchr(s, '/'); - base = base ? base + 1 : s; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; - unlink(outbin); - rmdir(tmpdir); + runwait(rmcmd); /* build must NOT succeed AND must emit its diagnostic. */ return (rc != 0 && hasmsg) ? 0 : -1; } diff --git a/test/wcc/989_taggedcompoundderef_reject.c b/test/wcc/989_taggedcompoundderef_reject.c index 8fcee68c..edf5a373 100644 --- a/test/wcc/989_taggedcompoundderef_reject.c +++ b/test/wcc/989_taggedcompoundderef_reject.c @@ -119,31 +119,26 @@ static const struct row rows[] = { static int run_build(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/tcd_%d_%d.ww", getpid(), i); + char tmpdir[64], src[128], outbin[128], cmd[1024], rmcmd[160]; snprintf(tmpdir, sizeof tmpdir, "/tmp/tcd_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/tcd_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/tcd_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -2; + if (!f) { runwait(rmcmd); return -2; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>/dev/null", + driver, outbin, src); int brc = runwait(cmd); - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; - int got = -1; if (brc == 0) got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return brc == 0 ? got : -1; } @@ -152,19 +147,22 @@ run_build(const char *driver, const struct row *r, int i) static int build_should_reject(const char *driver, const char *src, int i) { - char s[64], tmpdir[64], errf[80], cmd[1280]; - snprintf(s, sizeof s, "/tmp/tcn_%d_%d.ww", getpid(), i); + char tmpdir[64], s[128], outbin[128], errf[128], cmd[1280], rmcmd[160]; snprintf(tmpdir, sizeof tmpdir, "/tmp/tcn_%d_d_%d", getpid(), i); - snprintf(errf, sizeof errf, "/tmp/tcn_%d_%d.err", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(s, sizeof s, "%s/tcn_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/tcn_%d_%d", tmpdir, getpid(), i); + snprintf(errf, sizeof errf, "%s/tcn_%d_%d.err", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(s, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>%s", - tmpdir, driver, s, errf); + /* -o into tmpdir keeps the build's .sepwork inside tmpdir. */ + snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>%s", + driver, outbin, s, errf); int rc = runwait(cmd); int have_diag = 0; @@ -177,15 +175,7 @@ build_should_reject(const char *driver, const char *src, int i) have_diag = (strstr(buf, DIAG) != NULL); } - unlink(s); unlink(errf); - const char *base = strrchr(s, '/'); - base = base ? base + 1 : s; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; - unlink(outbin); - rmdir(tmpdir); + runwait(rmcmd); /* build must NOT succeed AND the shared diagnostic must appear. */ return (rc != 0 && have_diag) ? 0 : -1; diff --git a/test/wcc/989_taggedcompoundplace_reject.c b/test/wcc/989_taggedcompoundplace_reject.c index 44847b08..12fe84f0 100644 --- a/test/wcc/989_taggedcompoundplace_reject.c +++ b/test/wcc/989_taggedcompoundplace_reject.c @@ -185,31 +185,26 @@ static const struct row rows[] = { static int run_build(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/tcp_%d_%d.ww", getpid(), i); + char tmpdir[64], src[128], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/tcp_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/tcp_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/tcp_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -2; + if (!f) { runwait(rmcmd); return -2; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>/dev/null", + driver, outbin, src); int brc = runwait(cmd); - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; - int got = -1; if (brc == 0) got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return brc == 0 ? got : -1; } @@ -218,19 +213,21 @@ run_build(const char *driver, const struct row *r, int i) static int build_should_reject(const char *driver, const char *src, const char *diag, int i) { - char s[64], tmpdir[64], errf[80], cmd[1280]; - snprintf(s, sizeof s, "/tmp/tcq_%d_%d.ww", getpid(), i); + char tmpdir[64], s[128], outbin[128], errf[128], rmcmd[160], cmd[1280]; snprintf(tmpdir, sizeof tmpdir, "/tmp/tcq_%d_d_%d", getpid(), i); - snprintf(errf, sizeof errf, "/tmp/tcq_%d_%d.err", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(s, sizeof s, "%s/tcq_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/tcq_%d_%d", tmpdir, getpid(), i); + snprintf(errf, sizeof errf, "%s/tcq_%d_%d.err", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(s, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>%s", - tmpdir, driver, s, errf); + snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>%s", + driver, outbin, s, errf); int rc = runwait(cmd); int have_diag = 0; @@ -243,15 +240,7 @@ build_should_reject(const char *driver, const char *src, const char *diag, int i have_diag = (strstr(buf, diag) != NULL); } - unlink(s); unlink(errf); - const char *base = strrchr(s, '/'); - base = base ? base + 1 : s; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; - unlink(outbin); - rmdir(tmpdir); + runwait(rmcmd); /* build must NOT succeed AND the diagnostic must appear. */ return (rc != 0 && have_diag) ? 0 : -1; diff --git a/test/wcc/989_taggedderefstore_run.c b/test/wcc/989_taggedderefstore_run.c index 7a60eb89..018518f0 100644 --- a/test/wcc/989_taggedderefstore_run.c +++ b/test/wcc/989_taggedderefstore_run.c @@ -33,7 +33,6 @@ */ #include #include -#include #include #include #include @@ -152,31 +151,26 @@ static const struct row rows[] = { static int run_build(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/tagderef_%d_%d.ww", getpid(), i); + char tmpdir[64], src[128], outbin[128], cmd[1024], rmcmd[160]; snprintf(tmpdir, sizeof tmpdir, "/tmp/tagderef_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/tagderef_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/tagderef_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -2; + if (!f) { runwait(rmcmd); return -2; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>/dev/null", + driver, outbin, src); int brc = runwait(cmd); - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; - int got = -1; if (brc == 0) got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return brc == 0 ? got : -1; } diff --git a/test/wcc/989_taggedglobalindex_run.c b/test/wcc/989_taggedglobalindex_run.c index 54a5599b..dae97e76 100644 --- a/test/wcc/989_taggedglobalindex_run.c +++ b/test/wcc/989_taggedglobalindex_run.c @@ -35,7 +35,6 @@ */ #include #include -#include #include #include #include @@ -160,31 +159,26 @@ static const struct row rows[] = { static int run_build(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/tagglobidx_%d_%d.ww", getpid(), i); + char tmpdir[64], src[128], outbin[128], cmd[1024], rmcmd[160]; snprintf(tmpdir, sizeof tmpdir, "/tmp/tagglobidx_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/tagglobidx_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/tagglobidx_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -2; + if (!f) { runwait(rmcmd); return -2; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>/dev/null", + driver, outbin, src); int brc = runwait(cmd); - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; - int got = -1; if (brc == 0) got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return brc == 0 ? got : -1; } diff --git a/test/wcc/989_taggedidx_run.c b/test/wcc/989_taggedidx_run.c index 200a3ebd..56fe590a 100644 --- a/test/wcc/989_taggedidx_run.c +++ b/test/wcc/989_taggedidx_run.c @@ -29,7 +29,6 @@ */ #include #include -#include #include #include #include @@ -114,31 +113,26 @@ static const struct row rows[] = { static int run_build(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/tagidx_%d_%d.ww", getpid(), i); + char tmpdir[64], src[128], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/tagidx_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/tagidx_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/tagidx_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -2; + if (!f) { runwait(rmcmd); return -2; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>/dev/null", + driver, outbin, src); int brc = runwait(cmd); - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; - int got = -1; if (brc == 0) got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return brc == 0 ? got : -1; } diff --git a/test/wcc/989_tagnorm_run.c b/test/wcc/989_tagnorm_run.c index c8050e9e..10802e43 100644 --- a/test/wcc/989_tagnorm_run.c +++ b/test/wcc/989_tagnorm_run.c @@ -52,7 +52,6 @@ */ #include #include -#include #include #include #include @@ -188,31 +187,26 @@ static const struct row rows[] = { static int run_build(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/tagnorm_%d_%d.ww", getpid(), i); + char src[128], tmpdir[64], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/tagnorm_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/tagnorm_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/tagnorm_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -2; + if (!f) { runwait(rmcmd); return -2; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>/dev/null", + driver, outbin, src); int brc = runwait(cmd); - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; - int got = -1; if (brc == 0) got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return brc == 0 ? got : -1; } diff --git a/test/wcc/989_tagtupfieldsize_run.c b/test/wcc/989_tagtupfieldsize_run.c index cf80868c..eaea0eb5 100644 --- a/test/wcc/989_tagtupfieldsize_run.c +++ b/test/wcc/989_tagtupfieldsize_run.c @@ -29,7 +29,6 @@ */ #include #include -#include #include #include #include @@ -91,31 +90,26 @@ static const struct row rows[] = { static int run_build(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/tagtupfs_%d_%d.ww", getpid(), i); + char tmpdir[64], src[128], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/tagtupfs_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/tagtupfs_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/tagtupfs_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -2; + if (!f) { runwait(rmcmd); return -2; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>/dev/null", + driver, outbin, src); int brc = runwait(cmd); - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; - int got = -1; if (brc == 0) got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return brc == 0 ? got : -1; } diff --git a/test/wcc/989_trycallcollide_run.c b/test/wcc/989_trycallcollide_run.c index dcb581b5..1a09555a 100644 --- a/test/wcc/989_trycallcollide_run.c +++ b/test/wcc/989_trycallcollide_run.c @@ -29,7 +29,6 @@ */ #include #include -#include #include #include #include @@ -95,31 +94,26 @@ static const struct row rows[] = { static int run_build(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/tcc_%d_%d.ww", getpid(), i); + char tmpdir[64], src[128], outbin[128], cmd[1024], rmcmd[160]; snprintf(tmpdir, sizeof tmpdir, "/tmp/tcc_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/tcc_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/tcc_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -2; + if (!f) { runwait(rmcmd); return -2; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>/dev/null", + driver, outbin, src); int brc = runwait(cmd); - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; - int got = -1; if (brc == 0) got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return brc == 0 ? got : -1; /* -1 == build failed */ } diff --git a/test/wcc/989_tupfieldsize_run.c b/test/wcc/989_tupfieldsize_run.c index ea7ce091..bafc0f96 100644 --- a/test/wcc/989_tupfieldsize_run.c +++ b/test/wcc/989_tupfieldsize_run.c @@ -46,7 +46,6 @@ */ #include #include -#include #include #include #include @@ -138,31 +137,26 @@ static const struct row rows[] = { static int run_build(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/tupfs_%d_%d.ww", getpid(), i); + char tmpdir[64], src[128], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/tupfs_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/tupfs_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/tupfs_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -2; + if (!f) { runwait(rmcmd); return -2; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>/dev/null", + driver, outbin, src); int brc = runwait(cmd); - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; - int got = -1; if (brc == 0) got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return brc == 0 ? got : -1; } diff --git a/test/wcc/989_unknowndecl_reject.c b/test/wcc/989_unknowndecl_reject.c index fe4397e9..e2dea5df 100644 --- a/test/wcc/989_unknowndecl_reject.c +++ b/test/wcc/989_unknowndecl_reject.c @@ -83,31 +83,26 @@ static const struct row rows[] = { static int run_build(const char *driver, const struct row *r, int i) { - char src[64], tmpdir[64], cmd[1024]; - snprintf(src, sizeof src, "/tmp/und_%d_%d.ww", getpid(), i); + char src[128], tmpdir[64], outbin[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/und_%d_d_%d", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/und_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/und_%d_%d", tmpdir, getpid(), i); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "wb"); - if (!f) return -2; + if (!f) { runwait(rmcmd); return -2; } fputs(r->src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null", - tmpdir, driver, src); + snprintf(cmd, sizeof cmd, "%s build -o %s %s 2>/dev/null", + driver, outbin, src); int brc = runwait(cmd); - const char *base = strrchr(src, '/'); - base = base ? base + 1 : src; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; - int got = -1; if (brc == 0) got = runwait(outbin); - unlink(src); unlink(outbin); rmdir(tmpdir); + runwait(rmcmd); return brc == 0 ? got : -1; } @@ -133,32 +128,25 @@ static int build_should_fail(const char *driver, const char *src, const char *diag, int i) { - char s[64], tmpdir[64], cmd[1024], errf[64]; - snprintf(s, sizeof s, "/tmp/undn_%d_%d.ww", getpid(), i); + char s[128], tmpdir[64], outbin[128], errf[128], rmcmd[160], cmd[1024]; snprintf(tmpdir, sizeof tmpdir, "/tmp/undn_%d_d_%d", getpid(), i); - snprintf(errf, sizeof errf, "/tmp/undn_%d_e_%d.txt", getpid(), i); + mkdir(tmpdir, 0755); + snprintf(s, sizeof s, "%s/undn_%d_%d.ww", tmpdir, getpid(), i); + snprintf(outbin, sizeof outbin, "%s/undn_%d_%d", tmpdir, getpid(), i); + snprintf(errf, sizeof errf, "%s/err", tmpdir); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(s, "wb"); - if (!f) return -1; + if (!f) { runwait(rmcmd); return -1; } fputs(src, f); fclose(f); - mkdir(tmpdir, 0755); - snprintf(cmd, sizeof cmd, "cd %s && %s build %s >/dev/null 2>%s", - tmpdir, driver, s, errf); + snprintf(cmd, sizeof cmd, "%s build -o %s %s >/dev/null 2>%s", + driver, outbin, s, errf); int rc = runwait(cmd); int hasmsg = filehas(errf, diag); - unlink(s); - unlink(errf); - const char *base = strrchr(s, '/'); - base = base ? base + 1 : s; - char outbin[128]; - snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base); - char *dot = strrchr(outbin, '.'); - if (dot && strcmp(dot, ".ww") == 0) *dot = '\0'; - unlink(outbin); - rmdir(tmpdir); + runwait(rmcmd); /* build must NOT succeed AND must emit its diagnostic. */ return (rc != 0 && hasmsg) ? 0 : -1; } diff --git a/test/wcc/990_selfhost.c b/test/wcc/990_selfhost.c index 95740e57..230f5767 100644 --- a/test/wcc/990_selfhost.c +++ b/test/wcc/990_selfhost.c @@ -97,23 +97,26 @@ probe_smoke(const char *bin) char tmpdir[64]; snprintf(tmpdir, sizeof tmpdir, "/tmp/wwsh_%d", getpid()); mkdir(tmpdir, 0755); + char rmcmd[128]; + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); + /* #8: -o routes the binary + .sepwork scratch into tmpdir; without it + * the scratch lands next to the in-repo fixture as + * selfhost/test/smoke.sepwork and races concurrent gates. rm -rf + * clears the now-non-empty tmpdir on every exit path. */ char cmd[2048]; snprintf(cmd, sizeof cmd, - "cd %s && timeout 180 %s/ww build %s/selfhost/test/smoke.ww >/dev/null 2>&1", - tmpdir, bin, cwd); + "timeout 180 %s/ww build -o %s/smoke %s/selfhost/test/smoke.ww " + ">/dev/null 2>&1", bin, tmpdir, cwd); if (runwait(cmd) != 0) { fprintf(stderr, "smoke FAIL: ww build did not succeed\n"); + runwait(rmcmd); return -1; } char outbin[256], runcmd[512]; snprintf(outbin, sizeof outbin, "%s/smoke", tmpdir); snprintf(runcmd, sizeof runcmd, "timeout 180 %s", outbin); int rc = runwait(runcmd); - unlink(outbin); - char tmp[1024]; - snprintf(tmp, sizeof tmp, "%s/smoke.s", tmpdir); unlink(tmp); - snprintf(tmp, sizeof tmp, "%s/smoke.o", tmpdir); unlink(tmp); - rmdir(tmpdir); + runwait(rmcmd); if (rc != 42) { fprintf(stderr, "smoke FAIL: exit=%d (want 42; the number " "names which probe in selfhost/test/smoke.ww broke)\n", rc); diff --git a/test/wcc/993_ww_ww.c b/test/wcc/993_ww_ww.c index 5b17ea0b..e8130bdb 100644 --- a/test/wcc/993_ww_ww.c +++ b/test/wcc/993_ww_ww.c @@ -15,6 +15,7 @@ #include #include #include +#include #include static int @@ -168,16 +169,24 @@ run_build_fail(const char *bin, const char *driver) static int run_missing_pkg(const char *bin, const char *driver) { - char src[64], errf[64]; - snprintf(src, sizeof src, "/tmp/ww_mp_%s_%d.ww", driver, getpid()); - snprintf(errf, sizeof errf, "/tmp/ww_mp_%s_%d.err", driver, getpid()); + char tmpdir[80], src[160], errf[160], outbin[160], rmcmd[200]; + snprintf(tmpdir, sizeof tmpdir, "/tmp/ww_mp_%s_%d", driver, getpid()); + mkdir(tmpdir, 0755); + snprintf(src, sizeof src, "%s/mp.ww", tmpdir); + snprintf(errf, sizeof errf, "%s/mp.err", tmpdir); + snprintf(outbin, sizeof outbin, "%s/mp", tmpdir); + snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir); FILE *f = fopen(src, "w"); - if (!f) return 1; + if (!f) { runwait(rmcmd); return 1; } fputs("import nosuchpkg;\nexport fn main() i32 = { return 0; };\n", f); fclose(f); - char cmd[256]; - snprintf(cmd, sizeof cmd, "%s/%s build %s 2>%s", bin, driver, src, errf); + /* #8: the sep scratch is mkdir'd before the import-resolution failure, + * so a no-o build leaks /tmp/ww_mp_*.sepwork. -o routes it under tmpdir; + * rm -rf clears it. The missing-pkg error wording is -o-independent. */ + char cmd[512]; + snprintf(cmd, sizeof cmd, "%s/%s build -o %s %s 2>%s", + bin, driver, outbin, src, errf); int rc = runwait(cmd); int found = 0; @@ -189,7 +198,7 @@ run_missing_pkg(const char *bin, const char *driver) buf[n] = '\0'; found = strstr(buf, "cannot find package nosuchpkg") != NULL; } - unlink(src); unlink(errf); + runwait(rmcmd); if (rc == 0 || !found) { fprintf(stderr, "ww_ww FAIL: %s missing-pkg rc=%d found=%d " "(want nonzero + 'cannot find package')\n", driver, rc, found);