summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2013-12-12 10:51:45 -0800
committerAlon Zakai <alonzakai@gmail.com>2013-12-12 10:51:45 -0800
commitae3605d437ffe2d764d924458e46da5b6592740c (patch)
tree2a05d3921da6c36fb5f6da573b4402b53e44606c
parentafd5b08108f13349379f2dd58f2304edd6bbf0a8 (diff)
parent04a42801d532c40c2c8f75c778bc6bc599601e32 (diff)
Merge pull request #1903 from ehostunreach/incoming
Read the source and the expected output of simple core tests from seperate files
-rw-r--r--AUTHORS1
-rw-r--r--tests/core/test_addr_of_stacked.in14
-rw-r--r--tests/core/test_addr_of_stacked.out1
-rw-r--r--tests/core/test_alloca.in11
-rw-r--r--tests/core/test_alloca.out1
-rw-r--r--tests/core/test_alloca_stack.in19
-rw-r--r--tests/core/test_alloca_stack.out1
-rw-r--r--tests/core/test_array2.in15
-rw-r--r--tests/core/test_array2.out1
-rw-r--r--tests/core/test_array2b.in16
-rw-r--r--tests/core/test_array2b.out2
-rw-r--r--tests/core/test_assert.in9
-rw-r--r--tests/core/test_assert.out1
-rw-r--r--tests/core/test_atexit.in17
-rw-r--r--tests/core/test_atexit.out1
-rw-r--r--tests/core/test_atoX.in42
-rw-r--r--tests/core/test_atoX.out3
-rw-r--r--tests/core/test_atomic.in20
-rw-r--r--tests/core/test_atomic.out5
-rw-r--r--tests/core/test_bigarray.in19
-rw-r--r--tests/core/test_bigarray.out1
-rw-r--r--tests/core/test_bitfields.in23
-rw-r--r--tests/core/test_bitfields.out1
-rw-r--r--tests/core/test_bsearch.in47
-rw-r--r--tests/core/test_bsearch.out10
-rw-r--r--tests/core/test_bswap64.in56
-rw-r--r--tests/core/test_bswap64.out7
-rw-r--r--tests/core/test_ccall.in19
-rw-r--r--tests/core/test_ccall.out23
-rw-r--r--tests/core/test_class.in26
-rw-r--r--tests/core/test_class.out1
-rw-r--r--tests/core/test_constglobalstructs.in30
-rw-r--r--tests/core/test_constglobalstructs.out1
-rw-r--r--tests/core/test_conststructs.in21
-rw-r--r--tests/core/test_conststructs.out1
-rw-r--r--tests/core/test_copyop.in36
-rw-r--r--tests/core/test_copyop.out4
-rw-r--r--tests/core/test_corruption_2.in26
-rw-r--r--tests/core/test_corruption_2.out2
-rw-r--r--tests/core/test_corruption_3.in22
-rw-r--r--tests/core/test_corruption_3.out1
-rw-r--r--tests/core/test_cxx03_do_run.in12
-rw-r--r--tests/core/test_cxx03_do_run.out1
-rw-r--r--tests/core/test_demangle_stacks.in21
-rw-r--r--tests/core/test_demangle_stacks.out1
-rw-r--r--tests/core/test_direct_string_constant_usage.in13
-rw-r--r--tests/core/test_direct_string_constant_usage.out1
-rw-r--r--tests/core/test_dlfcn_self.in24
-rw-r--r--tests/core/test_dlfcn_self.out2
-rw-r--r--tests/core/test_dlmalloc_partial_2.in14
-rw-r--r--tests/core/test_dlmalloc_partial_2.out2
-rw-r--r--tests/core/test_double_i64_conversion.in69
-rw-r--r--tests/core/test_double_i64_conversion.out1
-rw-r--r--tests/core/test_dynamic_cast.in17
-rw-r--r--tests/core/test_dynamic_cast.out1
-rw-r--r--tests/core/test_dynamic_cast_2.in12
-rw-r--r--tests/core/test_dynamic_cast_2.out1
-rw-r--r--tests/core/test_dynamic_cast_b.in28
-rw-r--r--tests/core/test_dynamic_cast_b.out9
-rw-r--r--tests/core/test_emptyclass.in15
-rw-r--r--tests/core/test_emptyclass.out1
-rw-r--r--tests/core/test_emscripten_api.in17
-rw-r--r--tests/core/test_emscripten_api.out4
-rw-r--r--tests/core/test_erf.in15
-rw-r--r--tests/core/test_erf.out1
-rw-r--r--tests/core/test_errar.in21
-rw-r--r--tests/core/test_errar.out4
-rw-r--r--tests/core/test_exception_2.in26
-rw-r--r--tests/core/test_exception_2.out1
-rw-r--r--tests/core/test_fakestat.in10
-rw-r--r--tests/core/test_fakestat.out1
-rw-r--r--tests/core/test_fast_math.in14
-rw-r--r--tests/core/test_fast_math.out1
-rw-r--r--tests/core/test_fcvt.in14
-rw-r--r--tests/core/test_fcvt.out1
-rw-r--r--tests/core/test_flexarray_struct.in24
-rw-r--r--tests/core/test_flexarray_struct.out1
-rw-r--r--tests/core/test_float32_precise.in21
-rw-r--r--tests/core/test_float32_precise.out2
-rw-r--r--tests/core/test_floatvars.in29
-rw-r--r--tests/core/test_floatvars.out3
-rw-r--r--tests/core/test_frexp.in32
-rw-r--r--tests/core/test_frexp.out7
-rw-r--r--tests/core/test_funcptr.in35
-rw-r--r--tests/core/test_funcptr.out3
-rw-r--r--tests/core/test_funcptr_namecollide.in27
-rw-r--r--tests/core/test_funcptr_namecollide.out1
-rw-r--r--tests/core/test_funcptrfunc.in17
-rw-r--r--tests/core/test_funcptrfunc.out1
-rw-r--r--tests/core/test_funcs.in12
-rw-r--r--tests/core/test_funcs.out1
-rw-r--r--tests/core/test_functionpointer_libfunc_varargs.in13
-rw-r--r--tests/core/test_functionpointer_libfunc_varargs.out1
-rw-r--r--tests/core/test_fwrite_0.in21
-rw-r--r--tests/core/test_fwrite_0.out1
-rw-r--r--tests/core/test_gc.in107
-rw-r--r--tests/core/test_gc.out18
-rw-r--r--tests/core/test_getgep.in17
-rw-r--r--tests/core/test_getgep.out1
-rw-r--r--tests/core/test_getloadavg.in15
-rw-r--r--tests/core/test_getloadavg.out6
-rw-r--r--tests/core/test_getopt.in45
-rw-r--r--tests/core/test_getopt.out2
-rw-r--r--tests/core/test_getopt_long.in82
-rw-r--r--tests/core/test_getopt_long.out2
-rw-r--r--tests/core/test_globaldoubles.in26
-rw-r--r--tests/core/test_globaldoubles.out2
-rw-r--r--tests/core/test_globals.in13
-rw-r--r--tests/core/test_globals.out1
-rw-r--r--tests/core/test_gmtime.in28
-rw-r--r--tests/core/test_gmtime.out1
-rw-r--r--tests/core/test_hello_world.in8
-rw-r--r--tests/core/test_hello_world.out1
-rw-r--r--tests/core/test_i16_emcc_intrinsic.in20
-rw-r--r--tests/core/test_i16_emcc_intrinsic.out1
-rw-r--r--tests/core/test_i32_mul_precise.in11
-rw-r--r--tests/core/test_i32_mul_precise.out1
-rw-r--r--tests/core/test_i32_mul_semiprecise.in28
-rw-r--r--tests/core/test_i32_mul_semiprecise.out10
-rw-r--r--tests/core/test_i64_7z.in17
-rw-r--r--tests/core/test_i64_7z.out1
-rw-r--r--tests/core/test_i64_b.in22
-rw-r--r--tests/core/test_i64_b.out2
-rw-r--r--tests/core/test_i64_cmp.in18
-rw-r--r--tests/core/test_i64_cmp.out1
-rw-r--r--tests/core/test_i64_cmp2.in32
-rw-r--r--tests/core/test_i64_cmp2.out9
-rw-r--r--tests/core/test_i64_double.in38
-rw-r--r--tests/core/test_i64_double.out2
-rw-r--r--tests/core/test_i64_i16.in12
-rw-r--r--tests/core/test_i64_i16.out1
-rw-r--r--tests/core/test_i64_llabs.in9
-rw-r--r--tests/core/test_i64_llabs.out1
-rw-r--r--tests/core/test_i64_qdouble.in21
-rw-r--r--tests/core/test_i64_qdouble.out1
-rw-r--r--tests/core/test_i64_umul.in20
-rw-r--r--tests/core/test_i64_umul.out1
-rw-r--r--tests/core/test_i64_varargs.in30
-rw-r--r--tests/core/test_i64_varargs.out12
-rw-r--r--tests/core/test_i64_zextneg.in16
-rw-r--r--tests/core/test_i64_zextneg.out1
-rw-r--r--tests/core/test_if.in11
-rw-r--r--tests/core/test_if.out1
-rw-r--r--tests/core/test_if_else.in13
-rw-r--r--tests/core/test_if_else.out1
-rw-r--r--tests/core/test_indirectbr.in21
-rw-r--r--tests/core/test_indirectbr.out2
-rw-r--r--tests/core/test_indirectbr_many.in1510
-rw-r--r--tests/core/test_indirectbr_many.out2
-rw-r--r--tests/core/test_inherit.in25
-rw-r--r--tests/core/test_inherit.out1
-rw-r--r--tests/core/test_inlinejs.in26
-rw-r--r--tests/core/test_inlinejs.out2
-rw-r--r--tests/core/test_inlinejs2.in20
-rw-r--r--tests/core/test_inlinejs2.out3
-rw-r--r--tests/core/test_inlinejs3.in26
-rw-r--r--tests/core/test_inlinejs3.out12
-rw-r--r--tests/core/test_intvars.in50
-rw-r--r--tests/core/test_intvars.out5
-rw-r--r--tests/core/test_isdigit_l.in7
-rw-r--r--tests/core/test_isdigit_l.out1
-rw-r--r--tests/core/test_isnan.in17
-rw-r--r--tests/core/test_isnan.out9
-rw-r--r--tests/core/test_istream.in16
-rw-r--r--tests/core/test_istream.out1
-rw-r--r--tests/core/test_iswdigit.in12
-rw-r--r--tests/core/test_iswdigit.out1
-rw-r--r--tests/core/test_libcextra.in13
-rw-r--r--tests/core/test_libcextra.out1
-rw-r--r--tests/core/test_libgen.in41
-rw-r--r--tests/core/test_libgen.out9
-rw-r--r--tests/core/test_linked_list.in42
-rw-r--r--tests/core/test_linked_list.out1
-rw-r--r--tests/core/test_llrint.in8
-rw-r--r--tests/core/test_llrint.out4
-rw-r--r--tests/core/test_llvm_intrinsics.in41
-rw-r--r--tests/core/test_llvm_intrinsics.out10
-rw-r--r--tests/core/test_llvm_used.in14
-rw-r--r--tests/core/test_llvm_used.out1
-rw-r--r--tests/core/test_llvmswitch.in24
-rw-r--r--tests/core/test_llvmswitch.out1
-rw-r--r--tests/core/test_longjmp.in34
-rw-r--r--tests/core/test_longjmp.out4
-rw-r--r--tests/core/test_longjmp2.in37
-rw-r--r--tests/core/test_longjmp2.out6
-rw-r--r--tests/core/test_longjmp3.in42
-rw-r--r--tests/core/test_longjmp3.out7
-rw-r--r--tests/core/test_longjmp4.in44
-rw-r--r--tests/core/test_longjmp4.out4
-rw-r--r--tests/core/test_longjmp_exc.in28
-rw-r--r--tests/core/test_longjmp_exc.out1
-rw-r--r--tests/core/test_longjmp_funcptr.in32
-rw-r--r--tests/core/test_longjmp_funcptr.out2
-rw-r--r--tests/core/test_longjmp_repeat.in15
-rw-r--r--tests/core/test_longjmp_repeat.out8
-rw-r--r--tests/core/test_longjmp_stacked.in44
-rw-r--r--tests/core/test_longjmp_stacked.out13
-rw-r--r--tests/core/test_loop.in17
-rw-r--r--tests/core/test_loop.out1
-rw-r--r--tests/core/test_mainenv.in8
-rw-r--r--tests/core/test_mainenv.out1
-rw-r--r--tests/core/test_math.in34
-rw-r--r--tests/core/test_math.out1
-rw-r--r--tests/core/test_mathfuncptr.in13
-rw-r--r--tests/core/test_mathfuncptr.out1
-rw-r--r--tests/core/test_memcpy2.in22
-rw-r--r--tests/core/test_memcpy2.out1
-rw-r--r--tests/core/test_memcpy_memcmp.in45
-rw-r--r--tests/core/test_memcpy_memcmp.out1
-rw-r--r--tests/core/test_memmove.in10
-rw-r--r--tests/core/test_memmove.out1
-rw-r--r--tests/core/test_memmove2.in24
-rw-r--r--tests/core/test_memmove2.out1
-rw-r--r--tests/core/test_memmove3.in10
-rw-r--r--tests/core/test_memmove3.out1
-rw-r--r--tests/core/test_mmap.in38
-rw-r--r--tests/core/test_mmap.out1
-rw-r--r--tests/core/test_mod_globalstruct.in19
-rw-r--r--tests/core/test_mod_globalstruct.out1
-rw-r--r--tests/core/test_multiexception.in48
-rw-r--r--tests/core/test_multiexception.out9
-rw-r--r--tests/core/test_negative_zero.in30
-rw-r--r--tests/core/test_negative_zero.out20
-rw-r--r--tests/core/test_perrar.in13
-rw-r--r--tests/core/test_perrar.out1
-rw-r--r--tests/core/test_phiundef.in33
-rw-r--r--tests/core/test_phiundef.out5
-rw-r--r--tests/core/test_poll.in30
-rw-r--r--tests/core/test_poll.out7
-rw-r--r--tests/core/test_polymorph.in34
-rw-r--r--tests/core/test_polymorph.out3
-rw-r--r--tests/core/test_printf_2.in17
-rw-r--r--tests/core/test_printf_2.out2
-rw-r--r--tests/core/test_printf_more.in13
-rw-r--r--tests/core/test_printf_more.out2
-rw-r--r--tests/core/test_ptrtoint.in16
-rw-r--r--tests/core/test_ptrtoint.out1
-rw-r--r--tests/core/test_regex.in37
-rw-r--r--tests/core/test_regex.out2
-rw-r--r--tests/core/test_reinterpreted_ptrs.in41
-rw-r--r--tests/core/test_reinterpreted_ptrs.out1
-rw-r--r--tests/core/test_rounding.in29
-rw-r--r--tests/core/test_rounding.out1
-rw-r--r--tests/core/test_simd.in61
-rw-r--r--tests/core/test_simd.out8
-rw-r--r--tests/core/test_simd2.in39
-rw-r--r--tests/core/test_simd2.out4
-rw-r--r--tests/core/test_simd3.in471
-rw-r--r--tests/core/test_simd3.out1
-rw-r--r--tests/core/test_sintvars.in25
-rw-r--r--tests/core/test_sintvars.out4
-rw-r--r--tests/core/test_sizeof.in29
-rw-r--r--tests/core/test_sizeof.out1
-rw-r--r--tests/core/test_sscanf.in88
-rw-r--r--tests/core/test_sscanf.out29
-rw-r--r--tests/core/test_sscanf_3.in17
-rw-r--r--tests/core/test_sscanf_3.out4
-rw-r--r--tests/core/test_sscanf_4.in11
-rw-r--r--tests/core/test_sscanf_4.out2
-rw-r--r--tests/core/test_sscanf_5.in19
-rw-r--r--tests/core/test_sscanf_5.out3
-rw-r--r--tests/core/test_sscanf_6.in15
-rw-r--r--tests/core/test_sscanf_6.out2
-rw-r--r--tests/core/test_sscanf_caps.in10
-rw-r--r--tests/core/test_sscanf_caps.out1
-rw-r--r--tests/core/test_sscanf_float.in9
-rw-r--r--tests/core/test_sscanf_float.out2
-rw-r--r--tests/core/test_sscanf_hex.in9
-rw-r--r--tests/core/test_sscanf_hex.out1
-rw-r--r--tests/core/test_sscanf_n.in21
-rw-r--r--tests/core/test_sscanf_n.out3
-rw-r--r--tests/core/test_sscanf_other_whitespace.in29
-rw-r--r--tests/core/test_sscanf_other_whitespace.out1
-rw-r--r--tests/core/test_sscanf_skip.in16
-rw-r--r--tests/core/test_sscanf_skip.out4
-rw-r--r--tests/core/test_sscanf_whitespace.in23
-rw-r--r--tests/core/test_sscanf_whitespace.out1
-rw-r--r--tests/core/test_stack.in19
-rw-r--r--tests/core/test_stack.out1
-rw-r--r--tests/core/test_stack_byval.in25
-rw-r--r--tests/core/test_stack_byval.out1
-rw-r--r--tests/core/test_stack_varargs.in16
-rw-r--r--tests/core/test_stack_varargs.out1
-rw-r--r--tests/core/test_stack_void.in16
-rw-r--r--tests/core/test_stack_void.out1
-rw-r--r--tests/core/test_static_variable.in26
-rw-r--r--tests/core/test_static_variable.out1
-rw-r--r--tests/core/test_statics.in39
-rw-r--r--tests/core/test_statics.out2
-rw-r--r--tests/core/test_statvfs.in26
-rw-r--r--tests/core/test_statvfs.out13
-rw-r--r--tests/core/test_std_cout_new.in24
-rw-r--r--tests/core/test_std_cout_new.out1
-rw-r--r--tests/core/test_std_exception.in15
-rw-r--r--tests/core/test_std_exception.out1
-rw-r--r--tests/core/test_stdvec.in31
-rw-r--r--tests/core/test_stdvec.out2
-rw-r--r--tests/core/test_strcasecmp.in81
-rw-r--r--tests/core/test_strcasecmp.out62
-rw-r--r--tests/core/test_strcmp_uni.in11
-rw-r--r--tests/core/test_strcmp_uni.out3
-rw-r--r--tests/core/test_strftime.in153
-rw-r--r--tests/core/test_strftime.out1
-rw-r--r--tests/core/test_strings.in53
-rw-r--r--tests/core/test_strings.out13
-rw-r--r--tests/core/test_strndup.in39
-rw-r--r--tests/core/test_strndup.out6
-rw-r--r--tests/core/test_strptime_days.in34
-rw-r--r--tests/core/test_strptime_days.out12
-rw-r--r--tests/core/test_strptime_reentrant.in47
-rw-r--r--tests/core/test_strptime_reentrant.out1
-rw-r--r--tests/core/test_strptime_tm.in21
-rw-r--r--tests/core/test_strptime_tm.out1
-rw-r--r--tests/core/test_strstr.in35
-rw-r--r--tests/core/test_strstr.out24
-rw-r--r--tests/core/test_strtok.in20
-rw-r--r--tests/core/test_strtok.out32
-rw-r--r--tests/core/test_strtol_bin.in17
-rw-r--r--tests/core/test_strtol_bin.out1
-rw-r--r--tests/core/test_strtol_dec.in22
-rw-r--r--tests/core/test_strtol_dec.out1
-rw-r--r--tests/core/test_strtol_hex.in22
-rw-r--r--tests/core/test_strtol_hex.out1
-rw-r--r--tests/core/test_strtol_oct.in22
-rw-r--r--tests/core/test_strtol_oct.out1
-rw-r--r--tests/core/test_strtoll_bin.in17
-rw-r--r--tests/core/test_strtoll_bin.out1
-rw-r--r--tests/core/test_strtoll_dec.in22
-rw-r--r--tests/core/test_strtoll_dec.out1
-rw-r--r--tests/core/test_strtoll_hex.in22
-rw-r--r--tests/core/test_strtoll_hex.out1
-rw-r--r--tests/core/test_strtoll_oct.in22
-rw-r--r--tests/core/test_strtoll_oct.out1
-rw-r--r--tests/core/test_structs.in22
-rw-r--r--tests/core/test_structs.out1
-rw-r--r--tests/core/test_time_c.in9
-rw-r--r--tests/core/test_time_c.out1
-rw-r--r--tests/core/test_timeb.in15
-rw-r--r--tests/core/test_timeb.out1
-rw-r--r--tests/core/test_tinyfuncstr.in13
-rw-r--r--tests/core/test_tinyfuncstr.out1
-rw-r--r--tests/core/test_transtrcase.in13
-rw-r--r--tests/core/test_transtrcase.out1
-rw-r--r--tests/core/test_trickystring.in26
-rw-r--r--tests/core/test_trickystring.out1
-rw-r--r--tests/core/test_typeid.in53
-rw-r--r--tests/core/test_typeid.out23
-rw-r--r--tests/core/test_uname.in16
-rw-r--r--tests/core/test_uname.out6
-rw-r--r--tests/core/test_utf.in13
-rw-r--r--tests/core/test_utf.out2
-rw-r--r--tests/core/test_varargs.in103
-rw-r--r--tests/core/test_varargs.out16
-rw-r--r--tests/core/test_vprintf.in18
-rw-r--r--tests/core/test_vprintf.out2
-rw-r--r--tests/core/test_vsnprintf.in44
-rw-r--r--tests/core/test_vsnprintf.out7
-rw-r--r--tests/core/test_white_list_exception.in22
-rw-r--r--tests/core/test_white_list_exception.out1
-rw-r--r--tests/core/test_zero_multiplication.in14
-rw-r--r--tests/core/test_zero_multiplication.out1
-rw-r--r--tests/core/test_zerodiv.in21
-rw-r--r--tests/core/test_zerodiv.out4
-rwxr-xr-xtests/runner.py6
-rw-r--r--tests/test_core.py6201
365 files changed, 7991 insertions, 5602 deletions
diff --git a/AUTHORS b/AUTHORS
index b03bfe7b..413b9de1 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -111,3 +111,4 @@ a license to everyone to use it as detailed in LICENSE.)
* Daniel Baulig <dbaulig@fb.com> (copyright owned by Facebook, Inc.)
* Lu Wang <coolwanglu@gmail.com>
* Heidi Pan <heidi.pan@intel.com> (copyright owned by Intel)
+* Vasilis Kalintiris <ehostunreach@gmail.com>
diff --git a/tests/core/test_addr_of_stacked.in b/tests/core/test_addr_of_stacked.in
new file mode 100644
index 00000000..af5a6e32
--- /dev/null
+++ b/tests/core/test_addr_of_stacked.in
@@ -0,0 +1,14 @@
+
+ #include <stdio.h>
+ void alter(int *y)
+ {
+ *y += 5;
+ }
+ int main()
+ {
+ int x = 2;
+ alter(&x);
+ printf("*%d*\n", x);
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_addr_of_stacked.out b/tests/core/test_addr_of_stacked.out
new file mode 100644
index 00000000..2b8cf4a1
--- /dev/null
+++ b/tests/core/test_addr_of_stacked.out
@@ -0,0 +1 @@
+*7* \ No newline at end of file
diff --git a/tests/core/test_alloca.in b/tests/core/test_alloca.in
new file mode 100644
index 00000000..7b53e56c
--- /dev/null
+++ b/tests/core/test_alloca.in
@@ -0,0 +1,11 @@
+
+ #include <stdio.h>
+ #include <stdlib.h>
+
+ int main() {
+ char *pc;
+ pc = (char *)alloca(5);
+ printf("z:%d*%d*\n", pc > 0, (int)pc);
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_alloca.out b/tests/core/test_alloca.out
new file mode 100644
index 00000000..37de3d6b
--- /dev/null
+++ b/tests/core/test_alloca.out
@@ -0,0 +1 @@
+z:1* \ No newline at end of file
diff --git a/tests/core/test_alloca_stack.in b/tests/core/test_alloca_stack.in
new file mode 100644
index 00000000..ab7c7306
--- /dev/null
+++ b/tests/core/test_alloca_stack.in
@@ -0,0 +1,19 @@
+
+// We should not blow up the stack with numerous allocas
+ #include <stdio.h>
+ #include <stdlib.h>
+
+ func(int i) {
+ char *pc = (char *)alloca(100);
+ *pc = i;
+ (*pc)++;
+ return (*pc) % 10;
+ }
+ int main() {
+ int total = 0;
+ for (int i = 0; i < 1024*1024; i++)
+ total += func(i);
+ printf("ok:%d*\n", total);
+ return 0;
+ }
+
diff --git a/tests/core/test_alloca_stack.out b/tests/core/test_alloca_stack.out
new file mode 100644
index 00000000..d6a90d4e
--- /dev/null
+++ b/tests/core/test_alloca_stack.out
@@ -0,0 +1 @@
+ok:-32768* \ No newline at end of file
diff --git a/tests/core/test_array2.in b/tests/core/test_array2.in
new file mode 100644
index 00000000..0e5bcbfb
--- /dev/null
+++ b/tests/core/test_array2.in
@@ -0,0 +1,15 @@
+
+ #include <stdio.h>
+
+ static const double grid[4][2] = {
+ {-3/3.,-1/3.},{+1/3.,-3/3.},
+ {-1/3.,+3/3.},{+3/3.,+1/3.}
+ };
+
+ int main() {
+ for (int i = 0; i < 4; i++)
+ printf("%d:%.2f,%.2f ", i, grid[i][0], grid[i][1]);
+ printf("\n");
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_array2.out b/tests/core/test_array2.out
new file mode 100644
index 00000000..a6ee88bb
--- /dev/null
+++ b/tests/core/test_array2.out
@@ -0,0 +1 @@
+0:-1.00,-0.33 1:0.33,-1.00 2:-0.33,1.00 3:1.00,0.33 \ No newline at end of file
diff --git a/tests/core/test_array2b.in b/tests/core/test_array2b.in
new file mode 100644
index 00000000..b94821d8
--- /dev/null
+++ b/tests/core/test_array2b.in
@@ -0,0 +1,16 @@
+
+ #include <stdio.h>
+
+ static const struct {
+ unsigned char left;
+ unsigned char right;
+ } prioritah[] = {
+ {6, 6}, {6, 6}, {7, 95}, {7, 7}
+ };
+
+ int main() {
+ printf("*%d,%d\n", prioritah[1].left, prioritah[1].right);
+ printf("%d,%d*\n", prioritah[2].left, prioritah[2].right);
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_array2b.out b/tests/core/test_array2b.out
new file mode 100644
index 00000000..422896dc
--- /dev/null
+++ b/tests/core/test_array2b.out
@@ -0,0 +1,2 @@
+*6,6
+7,95* \ No newline at end of file
diff --git a/tests/core/test_assert.in b/tests/core/test_assert.in
new file mode 100644
index 00000000..7547468e
--- /dev/null
+++ b/tests/core/test_assert.in
@@ -0,0 +1,9 @@
+
+ #include <stdio.h>
+ #include <assert.h>
+ int main() {
+ assert(1 == true); // pass
+ assert(1 == false); // fail
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_assert.out b/tests/core/test_assert.out
new file mode 100644
index 00000000..870c1784
--- /dev/null
+++ b/tests/core/test_assert.out
@@ -0,0 +1 @@
+Assertion failed: 1 == false \ No newline at end of file
diff --git a/tests/core/test_atexit.in b/tests/core/test_atexit.in
new file mode 100644
index 00000000..56489a6c
--- /dev/null
+++ b/tests/core/test_atexit.in
@@ -0,0 +1,17 @@
+
+ #include <stdio.h>
+ #include <stdlib.h>
+
+ static void cleanA() {
+ printf("A");
+ }
+ static void cleanB() {
+ printf("B");
+ }
+
+ int main() {
+ atexit(cleanA);
+ atexit(cleanB);
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_atexit.out b/tests/core/test_atexit.out
new file mode 100644
index 00000000..c1c30196
--- /dev/null
+++ b/tests/core/test_atexit.out
@@ -0,0 +1 @@
+BA \ No newline at end of file
diff --git a/tests/core/test_atoX.in b/tests/core/test_atoX.in
new file mode 100644
index 00000000..8325acfa
--- /dev/null
+++ b/tests/core/test_atoX.in
@@ -0,0 +1,42 @@
+
+ #include <stdio.h>
+ #include <stdlib.h>
+
+ int main () {
+ printf("%d*", atoi(""));
+ printf("%d*", atoi("a"));
+ printf("%d*", atoi(" b"));
+ printf("%d*", atoi(" c "));
+ printf("%d*", atoi("6"));
+ printf("%d*", atoi(" 5"));
+ printf("%d*", atoi("4 "));
+ printf("%d*", atoi("3 6"));
+ printf("%d*", atoi(" 3 7"));
+ printf("%d*", atoi("9 d"));
+ printf("%d\n", atoi(" 8 e"));
+ printf("%d*", atol(""));
+ printf("%d*", atol("a"));
+ printf("%d*", atol(" b"));
+ printf("%d*", atol(" c "));
+ printf("%d*", atol("6"));
+ printf("%d*", atol(" 5"));
+ printf("%d*", atol("4 "));
+ printf("%d*", atol("3 6"));
+ printf("%d*", atol(" 3 7"));
+ printf("%d*", atol("9 d"));
+ printf("%d\n", atol(" 8 e"));
+ printf("%lld*", atoll("6294967296"));
+ printf("%lld*", atoll(""));
+ printf("%lld*", atoll("a"));
+ printf("%lld*", atoll(" b"));
+ printf("%lld*", atoll(" c "));
+ printf("%lld*", atoll("6"));
+ printf("%lld*", atoll(" 5"));
+ printf("%lld*", atoll("4 "));
+ printf("%lld*", atoll("3 6"));
+ printf("%lld*", atoll(" 3 7"));
+ printf("%lld*", atoll("9 d"));
+ printf("%lld\n", atoll(" 8 e"));
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_atoX.out b/tests/core/test_atoX.out
new file mode 100644
index 00000000..4b76d26d
--- /dev/null
+++ b/tests/core/test_atoX.out
@@ -0,0 +1,3 @@
+0*0*0*0*6*5*4*3*3*9*8
+0*0*0*0*6*5*4*3*3*9*8
+6294967296*0*0*0*0*6*5*4*3*3*9*8
diff --git a/tests/core/test_atomic.in b/tests/core/test_atomic.in
new file mode 100644
index 00000000..d0950551
--- /dev/null
+++ b/tests/core/test_atomic.in
@@ -0,0 +1,20 @@
+
+ #include <stdio.h>
+ int main() {
+ int x = 10;
+ int y = __sync_add_and_fetch(&x, 5);
+ printf("*%d,%d*\n", x, y);
+ x = 10;
+ y = __sync_fetch_and_add(&x, 5);
+ printf("*%d,%d*\n", x, y);
+ x = 10;
+ y = __sync_lock_test_and_set(&x, 6);
+ printf("*%d,%d*\n", x, y);
+ x = 10;
+ y = __sync_bool_compare_and_swap(&x, 9, 7);
+ printf("*%d,%d*\n", x, y);
+ y = __sync_bool_compare_and_swap(&x, 10, 7);
+ printf("*%d,%d*\n", x, y);
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_atomic.out b/tests/core/test_atomic.out
new file mode 100644
index 00000000..ed11bce0
--- /dev/null
+++ b/tests/core/test_atomic.out
@@ -0,0 +1,5 @@
+*15,15*
+*15,10*
+*6,10*
+*10,0*
+*7,1* \ No newline at end of file
diff --git a/tests/core/test_bigarray.in b/tests/core/test_bigarray.in
new file mode 100644
index 00000000..0255c207
--- /dev/null
+++ b/tests/core/test_bigarray.in
@@ -0,0 +1,19 @@
+
+// avoid "array initializer too large" errors
+ #include <stdio.h>
+ #include <assert.h>
+
+ #define SIZE (1024*100)
+ struct Struct {
+ char x;
+ int y;
+ };
+ Struct buffy[SIZE];
+
+ int main() {
+ for (int i = 0; i < SIZE; i++) { assert(buffy[i].x == 0 && buffy[i].y == 0); } // we were zeroinitialized
+ for (int i = 0; i < SIZE; i++) { buffy[i].x = i*i; buffy[i].y = i*i*i; } // we can save data
+ printf("*%d*\n", buffy[SIZE/3].x);
+ return 0;
+ }
+
diff --git a/tests/core/test_bigarray.out b/tests/core/test_bigarray.out
new file mode 100644
index 00000000..33485c46
--- /dev/null
+++ b/tests/core/test_bigarray.out
@@ -0,0 +1 @@
+*57* \ No newline at end of file
diff --git a/tests/core/test_bitfields.in b/tests/core/test_bitfields.in
new file mode 100644
index 00000000..08831f23
--- /dev/null
+++ b/tests/core/test_bitfields.in
@@ -0,0 +1,23 @@
+
+ #include <stdio.h>
+ struct bitty {
+ unsigned x : 1;
+ unsigned y : 1;
+ unsigned z : 1;
+ };
+ int main()
+ {
+ bitty b;
+ printf("*");
+ for (int i = 0; i <= 1; i++)
+ for (int j = 0; j <= 1; j++)
+ for (int k = 0; k <= 1; k++) {
+ b.x = i;
+ b.y = j;
+ b.z = k;
+ printf("%d,%d,%d,", b.x, b.y, b.z);
+ }
+ printf("*\n");
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_bitfields.out b/tests/core/test_bitfields.out
new file mode 100644
index 00000000..e121b181
--- /dev/null
+++ b/tests/core/test_bitfields.out
@@ -0,0 +1 @@
+*0,0,0,0,0,1,0,1,0,0,1,1,1,0,0,1,0,1,1,1,0,1,1,1,* \ No newline at end of file
diff --git a/tests/core/test_bsearch.in b/tests/core/test_bsearch.in
new file mode 100644
index 00000000..285210bd
--- /dev/null
+++ b/tests/core/test_bsearch.in
@@ -0,0 +1,47 @@
+
+ #include <stdlib.h>
+ #include <stdio.h>
+
+ int cmp(const void* key, const void* member) {
+ return *(int *)key - *(int *)member;
+ }
+
+ void printResult(int* needle, int* haystack, unsigned int len) {
+ void *result = bsearch(needle, haystack, len, sizeof(unsigned int), cmp);
+
+ if (result == NULL) {
+ printf("null\n");
+ } else {
+ printf("%d\n", *(unsigned int *)result);
+ }
+ }
+
+ int main() {
+ int a[] = { -2, -1, 0, 6, 7, 9 };
+ int b[] = { 0, 1 };
+
+ /* Find all keys that exist. */
+ for(int i = 0; i < 6; i++) {
+ int val = a[i];
+
+ printResult(&val, a, 6);
+ }
+
+ /* Keys that are covered by the range of the array but aren't in
+ * the array cannot be found.
+ */
+ int v1 = 3;
+ int v2 = 8;
+ printResult(&v1, a, 6);
+ printResult(&v2, a, 6);
+
+ /* Keys outside the range of the array cannot be found. */
+ int v3 = -1;
+ int v4 = 2;
+
+ printResult(&v3, b, 2);
+ printResult(&v4, b, 2);
+
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_bsearch.out b/tests/core/test_bsearch.out
new file mode 100644
index 00000000..cc6a3205
--- /dev/null
+++ b/tests/core/test_bsearch.out
@@ -0,0 +1,10 @@
+-2
+-1
+0
+6
+7
+9
+null
+null
+null
+null \ No newline at end of file
diff --git a/tests/core/test_bswap64.in b/tests/core/test_bswap64.in
new file mode 100644
index 00000000..addf6086
--- /dev/null
+++ b/tests/core/test_bswap64.in
@@ -0,0 +1,56 @@
+
+ #include <stdio.h>
+ #include <stdlib.h>
+
+ #include <iostream>
+ #include <string>
+ #include <sstream>
+
+ typedef unsigned long long quint64;
+
+ using namespace std;
+
+ inline quint64 qbswap(quint64 source)
+ {
+ return 0
+ | ((source & quint64(0x00000000000000ffLL)) << 56)
+ | ((source & quint64(0x000000000000ff00LL)) << 40)
+ | ((source & quint64(0x0000000000ff0000LL)) << 24)
+ | ((source & quint64(0x00000000ff000000LL)) << 8)
+ | ((source & quint64(0x000000ff00000000LL)) >> 8)
+ | ((source & quint64(0x0000ff0000000000LL)) >> 24)
+ | ((source & quint64(0x00ff000000000000LL)) >> 40)
+ | ((source & quint64(0xff00000000000000LL)) >> 56);
+ }
+
+ int main()
+ {
+ quint64 v = strtoull("4433ffeeddccbb00", NULL, 16);
+ printf("%lld\n", v);
+
+ const string string64bitInt = "4433ffeeddccbb00";
+ stringstream s(string64bitInt);
+ quint64 int64bitInt = 0;
+ printf("1\n");
+ s >> hex >> int64bitInt;
+ printf("2\n");
+
+ stringstream out;
+ out << hex << qbswap(int64bitInt);
+
+ cout << out.str() << endl;
+ cout << hex << int64bitInt << endl;
+ cout << string64bitInt << endl;
+
+ if (out.str() != "bbccddeeff3344")
+ {
+ cout << "Failed!" << endl;
+ }
+ else
+ {
+ cout << "Succeeded!" << endl;
+ }
+
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_bswap64.out b/tests/core/test_bswap64.out
new file mode 100644
index 00000000..af129b5f
--- /dev/null
+++ b/tests/core/test_bswap64.out
@@ -0,0 +1,7 @@
+4914553019779824384
+1
+2
+bbccddeeff3344
+4433ffeeddccbb00
+4433ffeeddccbb00
+Succeeded!
diff --git a/tests/core/test_ccall.in b/tests/core/test_ccall.in
new file mode 100644
index 00000000..6374ebb3
--- /dev/null
+++ b/tests/core/test_ccall.in
@@ -0,0 +1,19 @@
+
+ #include <stdio.h>
+ #include <stdlib.h>
+
+ extern "C" {
+ int get_int() { return 5; }
+ float get_float() { return 3.14; }
+ char * get_string() { return "hello world"; }
+ void print_int(int x) { printf("%d\n", x); }
+ void print_float(float x) { printf("%.2f\n", x); }
+ void print_string(char *x) { printf("%s\n", x); }
+ int multi(int x, float y, int z, char *str) { if (x) puts(str); return (x+y)*z; }
+ int * pointer(int *in) { printf("%d\n", *in); static int ret = 21; return &ret; }
+ }
+
+ int main(int argc, char **argv) {
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_ccall.out b/tests/core/test_ccall.out
new file mode 100644
index 00000000..526ed80d
--- /dev/null
+++ b/tests/core/test_ccall.out
@@ -0,0 +1,23 @@
+*
+number,5
+number,3.14
+string,hello world
+12
+undefined
+14.56
+undefined
+cheez
+undefined
+arr-ay
+undefined
+more
+number,10
+650
+number,21
+*
+atr
+10
+bret
+53
+*
+stack is ok.
diff --git a/tests/core/test_class.in b/tests/core/test_class.in
new file mode 100644
index 00000000..fc61869e
--- /dev/null
+++ b/tests/core/test_class.in
@@ -0,0 +1,26 @@
+
+ #include <stdio.h>
+ struct Random {
+ enum { IM = 139968, IA = 3877, IC = 29573 };
+ Random() : last(42) {}
+ float get( float max = 1.0f ) {
+ last = ( last * IA + IC ) % IM;
+ return max * last / IM;
+ }
+ protected:
+ unsigned int last;
+ } rng1;
+ int main()
+ {
+ Random rng2;
+ int count = 0;
+ for (int i = 0; i < 100; i++) {
+ float x1 = rng1.get();
+ float x2 = rng2.get();
+ printf("%f, %f\n", x1, x2);
+ if (x1 != x2) count += 1;
+ }
+ printf("*%d*\n", count);
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_class.out b/tests/core/test_class.out
new file mode 100644
index 00000000..a5e8240e
--- /dev/null
+++ b/tests/core/test_class.out
@@ -0,0 +1 @@
+*0* \ No newline at end of file
diff --git a/tests/core/test_constglobalstructs.in b/tests/core/test_constglobalstructs.in
new file mode 100644
index 00000000..f2f23c5d
--- /dev/null
+++ b/tests/core/test_constglobalstructs.in
@@ -0,0 +1,30 @@
+
+ #include <stdio.h>
+ struct IUB {
+ int c;
+ double p;
+ unsigned int pi;
+ };
+
+ IUB iub[] = {
+ { 'a', 0.27, 5 },
+ { 'c', 0.15, 4 },
+ { 'g', 0.12, 3 },
+ { 't', 0.27, 2 },
+ };
+
+ const unsigned char faceedgesidx[6][4] =
+ {
+ { 4, 5, 8, 10 },
+ { 6, 7, 9, 11 },
+ { 0, 2, 8, 9 },
+ { 1, 3, 10,11 },
+ { 0, 1, 4, 6 },
+ { 2, 3, 5, 7 },
+ };
+
+ int main( int argc, const char *argv[] ) {
+ printf("*%d,%d,%d,%d*\n", iub[0].c, int(iub[1].p*100), iub[2].pi, faceedgesidx[3][2]);
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_constglobalstructs.out b/tests/core/test_constglobalstructs.out
new file mode 100644
index 00000000..1d530091
--- /dev/null
+++ b/tests/core/test_constglobalstructs.out
@@ -0,0 +1 @@
+*97,15,3,10* \ No newline at end of file
diff --git a/tests/core/test_conststructs.in b/tests/core/test_conststructs.in
new file mode 100644
index 00000000..e95fd6be
--- /dev/null
+++ b/tests/core/test_conststructs.in
@@ -0,0 +1,21 @@
+
+ #include <stdio.h>
+ struct IUB {
+ int c;
+ double p;
+ unsigned int pi;
+ };
+
+ int main( int argc, const char *argv[] ) {
+ int before = 70;
+ IUB iub[] = {
+ { 'a', 0.3029549426680, 5 },
+ { 'c', 0.15, 4 },
+ { 'g', 0.12, 3 },
+ { 't', 0.27, 2 },
+ };
+ int after = 90;
+ printf("*%d,%d,%d,%d,%d,%d*\n", before, iub[0].c, int(iub[1].p*100), iub[2].pi, int(iub[0].p*10000), after);
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_conststructs.out b/tests/core/test_conststructs.out
new file mode 100644
index 00000000..af600061
--- /dev/null
+++ b/tests/core/test_conststructs.out
@@ -0,0 +1 @@
+*70,97,15,3,3029,90* \ No newline at end of file
diff --git a/tests/core/test_copyop.in b/tests/core/test_copyop.in
new file mode 100644
index 00000000..4bf7da12
--- /dev/null
+++ b/tests/core/test_copyop.in
@@ -0,0 +1,36 @@
+
+ #include <stdio.h>
+ #include <math.h>
+ #include <string.h>
+
+ struct vec {
+ double x,y,z;
+ vec() : x(0), y(0), z(0) { };
+ vec(const double a, const double b, const double c) : x(a), y(b), z(c) { };
+ };
+
+ struct basis {
+ vec a, b, c;
+ basis(const vec& v) {
+ a=v; // should not touch b!
+ printf("*%.2f,%.2f,%.2f*\n", b.x, b.y, b.z);
+ }
+ };
+
+ int main() {
+ basis B(vec(1,0,0));
+
+ // Part 2: similar problem with memset and memmove
+ int x = 1, y = 77, z = 2;
+ memset((void*)&x, 0, sizeof(int));
+ memset((void*)&z, 0, sizeof(int));
+ printf("*%d,%d,%d*\n", x, y, z);
+ memcpy((void*)&x, (void*)&z, sizeof(int));
+ memcpy((void*)&z, (void*)&x, sizeof(int));
+ printf("*%d,%d,%d*\n", x, y, z);
+ memmove((void*)&x, (void*)&z, sizeof(int));
+ memmove((void*)&z, (void*)&x, sizeof(int));
+ printf("*%d,%d,%d*\n", x, y, z);
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_copyop.out b/tests/core/test_copyop.out
new file mode 100644
index 00000000..17bde9e7
--- /dev/null
+++ b/tests/core/test_copyop.out
@@ -0,0 +1,4 @@
+*0.00,0.00,0.00*
+*0,77,0*
+*0,77,0*
+*0,77,0* \ No newline at end of file
diff --git a/tests/core/test_corruption_2.in b/tests/core/test_corruption_2.in
new file mode 100644
index 00000000..87aef9da
--- /dev/null
+++ b/tests/core/test_corruption_2.in
@@ -0,0 +1,26 @@
+
+ #include <iostream>
+ #include <fstream>
+ #include <stdlib.h>
+ #include <stdio.h>
+
+ void bye() {
+ printf("all ok\n");
+ }
+
+ int main() {
+ atexit(bye);
+
+ std::string testPath = "/Script/WA-KA.txt";
+ std::fstream str(testPath.c_str(), std::ios::in | std::ios::binary);
+
+ if (str.is_open())
+ {
+ std::cout << "open!" << std::endl;
+ } else {
+ std::cout << "missing!" << std::endl;
+ }
+
+ return 1;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_corruption_2.out b/tests/core/test_corruption_2.out
new file mode 100644
index 00000000..26795dba
--- /dev/null
+++ b/tests/core/test_corruption_2.out
@@ -0,0 +1,2 @@
+missing!
+all ok
diff --git a/tests/core/test_corruption_3.in b/tests/core/test_corruption_3.in
new file mode 100644
index 00000000..b951ac6b
--- /dev/null
+++ b/tests/core/test_corruption_3.in
@@ -0,0 +1,22 @@
+
+ #include <stdlib.h>
+ #include <stdio.h>
+ #include <assert.h>
+
+ void bye() {
+ printf("all ok\n");
+ }
+
+ int main(int argc, char **argv) {
+ atexit(bye);
+
+ char *buffer = (char*)malloc(100);
+ for (int i = 0; i < 100; i++) buffer[i] = (i*i)%256;
+ buffer = (char*)realloc(buffer, argc + 50);
+ for (int i = 0; i < argc + 50; i++) {
+ //printf("%d : %d : %d : %d\n", i, (int)(buffer + i), buffer[i], (char)((i*i)%256));
+ assert(buffer[i] == (char)((i*i)%256));
+ }
+ return 1;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_corruption_3.out b/tests/core/test_corruption_3.out
new file mode 100644
index 00000000..d48ce729
--- /dev/null
+++ b/tests/core/test_corruption_3.out
@@ -0,0 +1 @@
+all ok
diff --git a/tests/core/test_cxx03_do_run.in b/tests/core/test_cxx03_do_run.in
new file mode 100644
index 00000000..ec7d1189
--- /dev/null
+++ b/tests/core/test_cxx03_do_run.in
@@ -0,0 +1,12 @@
+
+ #include <stdio.h>
+
+ #if __cplusplus != 199711L
+ #error By default, if no -std is specified, emscripten should be compiling with -std=c++03!
+ #endif
+
+ int main( int argc, const char *argv[] ) {
+ printf("Hello world!\n");
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_cxx03_do_run.out b/tests/core/test_cxx03_do_run.out
new file mode 100644
index 00000000..6769dd60
--- /dev/null
+++ b/tests/core/test_cxx03_do_run.out
@@ -0,0 +1 @@
+Hello world! \ No newline at end of file
diff --git a/tests/core/test_demangle_stacks.in b/tests/core/test_demangle_stacks.in
new file mode 100644
index 00000000..8db34832
--- /dev/null
+++ b/tests/core/test_demangle_stacks.in
@@ -0,0 +1,21 @@
+
+ #include<stdio.h>
+ #include<stdlib.h>
+
+ namespace NameSpace {
+ class Class {
+ public:
+ int Aborter(double x, char y, int *z) {
+ int addr = x+y+(int)z;
+ void *p = (void*)addr;
+ for (int i = 0; i < 100; i++) free(p); // will abort, should show proper stack trace
+ }
+ };
+ }
+
+ int main(int argc, char **argv) {
+ NameSpace::Class c;
+ c.Aborter(1.234, 'a', NULL);
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_demangle_stacks.out b/tests/core/test_demangle_stacks.out
new file mode 100644
index 00000000..d1c61b45
--- /dev/null
+++ b/tests/core/test_demangle_stacks.out
@@ -0,0 +1 @@
+NameSpace::Class::Aborter(double, char, int*) \ No newline at end of file
diff --git a/tests/core/test_direct_string_constant_usage.in b/tests/core/test_direct_string_constant_usage.in
new file mode 100644
index 00000000..e43232f0
--- /dev/null
+++ b/tests/core/test_direct_string_constant_usage.in
@@ -0,0 +1,13 @@
+
+ #include <iostream>
+ template<int i>
+ void printText( const char (&text)[ i ] )
+ {
+ std::cout << text;
+ }
+ int main()
+ {
+ printText( "some string constant" );
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_direct_string_constant_usage.out b/tests/core/test_direct_string_constant_usage.out
new file mode 100644
index 00000000..ddb4b681
--- /dev/null
+++ b/tests/core/test_direct_string_constant_usage.out
@@ -0,0 +1 @@
+some string constant \ No newline at end of file
diff --git a/tests/core/test_dlfcn_self.in b/tests/core/test_dlfcn_self.in
new file mode 100644
index 00000000..687c4d6f
--- /dev/null
+++ b/tests/core/test_dlfcn_self.in
@@ -0,0 +1,24 @@
+
+#include <stdio.h>
+#include <dlfcn.h>
+#include <emscripten.h>
+
+int EMSCRIPTEN_KEEPALIVE global = 123;
+
+extern "C" EMSCRIPTEN_KEEPALIVE void foo(int x) {
+printf("%d\n", x);
+}
+
+extern "C" EMSCRIPTEN_KEEPALIVE void repeatable() {
+void* self = dlopen(NULL, RTLD_LAZY);
+int* global_ptr = (int*)dlsym(self, "global");
+void (*foo_ptr)(int) = (void (*)(int))dlsym(self, "foo");
+foo_ptr(*global_ptr);
+dlclose(self);
+}
+
+int main() {
+repeatable();
+repeatable();
+return 0;
+} \ No newline at end of file
diff --git a/tests/core/test_dlfcn_self.out b/tests/core/test_dlfcn_self.out
new file mode 100644
index 00000000..4ca9456b
--- /dev/null
+++ b/tests/core/test_dlfcn_self.out
@@ -0,0 +1,2 @@
+123
+123 \ No newline at end of file
diff --git a/tests/core/test_dlmalloc_partial_2.in b/tests/core/test_dlmalloc_partial_2.in
new file mode 100644
index 00000000..f68e9cdf
--- /dev/null
+++ b/tests/core/test_dlmalloc_partial_2.in
@@ -0,0 +1,14 @@
+
+ #include <stdio.h>
+ #include <stdlib.h>
+ void *malloc(size_t size)
+ {
+ return (void*)123;
+ }
+ int main() {
+ void *x = malloc(10);
+ printf("got %p\n", x);
+ free(x);
+ printf("freed the faker\n");
+ return 1;
+ }
diff --git a/tests/core/test_dlmalloc_partial_2.out b/tests/core/test_dlmalloc_partial_2.out
new file mode 100644
index 00000000..5512c7a8
--- /dev/null
+++ b/tests/core/test_dlmalloc_partial_2.out
@@ -0,0 +1,2 @@
+got 0x7b
+freed \ No newline at end of file
diff --git a/tests/core/test_double_i64_conversion.in b/tests/core/test_double_i64_conversion.in
new file mode 100644
index 00000000..404c6796
--- /dev/null
+++ b/tests/core/test_double_i64_conversion.in
@@ -0,0 +1,69 @@
+
+ #include <cassert>
+ #include <inttypes.h>
+ #include <stdio.h>
+
+ __attribute((noinline)) bool eq(double d, int64_t i) {
+ int64_t i2 = (int64_t)d;
+ if (i != i2) {
+ printf("%.20g converted to int64 returns %lld, not %lld as expected!\n", d, i2, i);
+ }
+ return i == i2;
+ }
+
+ int main() {
+ assert(eq(0.0, 0));
+ assert(eq(-0.0, 0));
+ assert(eq(0.1, 0));
+ assert(eq(-0.1, 0));
+ assert(eq(0.6, 0));
+ assert(eq(-0.6, 0));
+ assert(eq(1.0, 1));
+ assert(eq(-1.0, -1));
+ assert(eq(1.1, 1));
+ assert(eq(-1.1, -1));
+ assert(eq(1.6, 1));
+ assert(eq(-1.6, -1));
+ assert(eq(4294967295.0, 4294967295LL));
+ assert(eq(4294967295.5, 4294967295LL));
+ assert(eq(4294967296.0, 4294967296LL));
+ assert(eq(4294967296.5, 4294967296LL));
+ assert(eq(14294967295.0, 14294967295LL));
+ assert(eq(14294967295.5, 14294967295LL));
+ assert(eq(14294967296.0, 14294967296LL));
+ assert(eq(14294967296.5, 14294967296LL));
+ assert(eq(-4294967295.0, -4294967295LL));
+ assert(eq(-4294967295.5, -4294967295LL));
+ assert(eq(-4294967296.0, -4294967296LL));
+ assert(eq(-4294967296.5, -4294967296LL));
+ assert(eq(-14294967295.0, -14294967295LL));
+ assert(eq(-14294967295.5, -14294967295LL));
+ assert(eq(-14294967296.0, -14294967296LL));
+ assert(eq(-14294967296.5, -14294967296LL));
+
+ assert(eq(4294967295.3, 4294967295LL));
+ assert(eq(4294967296.3, 4294967296LL));
+ assert(eq(14294967295.3, 14294967295LL));
+ assert(eq(14294967296.3, 14294967296LL));
+ assert(eq(-4294967295.3, -4294967295LL));
+ assert(eq(-4294967296.3, -4294967296LL));
+ assert(eq(-14294967295.3, -14294967295LL));
+ assert(eq(-14294967296.3, -14294967296LL));
+
+ assert(eq(4294967295.8, 4294967295LL));
+ assert(eq(4294967296.8, 4294967296LL));
+ assert(eq(14294967295.8, 14294967295LL));
+ assert(eq(14294967296.8, 14294967296LL));
+ assert(eq(-4294967295.8, -4294967295LL));
+ assert(eq(-4294967296.8, -4294967296LL));
+ assert(eq(-14294967295.8, -14294967295LL));
+ assert(eq(-14294967296.8, -14294967296LL));
+
+ // The following number is the largest double such that all integers smaller than this can exactly be represented in a double.
+ assert(eq(9007199254740992.0, 9007199254740992LL /* == 2^53 */));
+ assert(eq(-9007199254740992.0, -9007199254740992LL /* == -2^53 */));
+
+ printf("OK!\n");
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_double_i64_conversion.out b/tests/core/test_double_i64_conversion.out
new file mode 100644
index 00000000..d6406617
--- /dev/null
+++ b/tests/core/test_double_i64_conversion.out
@@ -0,0 +1 @@
+OK!
diff --git a/tests/core/test_dynamic_cast.in b/tests/core/test_dynamic_cast.in
new file mode 100644
index 00000000..ebe9263b
--- /dev/null
+++ b/tests/core/test_dynamic_cast.in
@@ -0,0 +1,17 @@
+
+ #include <stdio.h>
+
+ struct Support {
+ virtual void f() {
+ printf("f()\n");
+ }
+ };
+
+ struct Derived : Support {
+ };
+
+ int main() {
+ Support * p = new Derived;
+ dynamic_cast<Derived*>(p)->f();
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_dynamic_cast.out b/tests/core/test_dynamic_cast.out
new file mode 100644
index 00000000..a19096b5
--- /dev/null
+++ b/tests/core/test_dynamic_cast.out
@@ -0,0 +1 @@
+f()
diff --git a/tests/core/test_dynamic_cast_2.in b/tests/core/test_dynamic_cast_2.in
new file mode 100644
index 00000000..6da4cade
--- /dev/null
+++ b/tests/core/test_dynamic_cast_2.in
@@ -0,0 +1,12 @@
+
+ #include <stdio.h>
+ #include <typeinfo>
+
+ class Class {};
+
+ int main() {
+ const Class* dp = dynamic_cast<const Class*>(&typeid(Class));
+ // should return dp == NULL,
+ printf("pointer: %p\n", dp);
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_dynamic_cast_2.out b/tests/core/test_dynamic_cast_2.out
new file mode 100644
index 00000000..be38bbcc
--- /dev/null
+++ b/tests/core/test_dynamic_cast_2.out
@@ -0,0 +1 @@
+pointer: (nil) \ No newline at end of file
diff --git a/tests/core/test_dynamic_cast_b.in b/tests/core/test_dynamic_cast_b.in
new file mode 100644
index 00000000..f5931fef
--- /dev/null
+++ b/tests/core/test_dynamic_cast_b.in
@@ -0,0 +1,28 @@
+
+ #include <stdio.h>
+
+ class CBase { virtual void dummy() {} };
+ class CDerived : public CBase { int a; };
+ class CDerivedest : public CDerived { float b; };
+
+ int main ()
+ {
+ CBase *pa = new CBase;
+ CBase *pb = new CDerived;
+ CBase *pc = new CDerivedest;
+
+ printf("a1: %d\n", dynamic_cast<CDerivedest*>(pa) != NULL);
+ printf("a2: %d\n", dynamic_cast<CDerived*>(pa) != NULL);
+ printf("a3: %d\n", dynamic_cast<CBase*>(pa) != NULL);
+
+ printf("b1: %d\n", dynamic_cast<CDerivedest*>(pb) != NULL);
+ printf("b2: %d\n", dynamic_cast<CDerived*>(pb) != NULL);
+ printf("b3: %d\n", dynamic_cast<CBase*>(pb) != NULL);
+
+ printf("c1: %d\n", dynamic_cast<CDerivedest*>(pc) != NULL);
+ printf("c2: %d\n", dynamic_cast<CDerived*>(pc) != NULL);
+ printf("c3: %d\n", dynamic_cast<CBase*>(pc) != NULL);
+
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_dynamic_cast_b.out b/tests/core/test_dynamic_cast_b.out
new file mode 100644
index 00000000..090390e8
--- /dev/null
+++ b/tests/core/test_dynamic_cast_b.out
@@ -0,0 +1,9 @@
+a1: 0
+a2: 0
+a3: 1
+b1: 0
+b2: 1
+b3: 1
+c1: 1
+c2: 1
+c3: 1
diff --git a/tests/core/test_emptyclass.in b/tests/core/test_emptyclass.in
new file mode 100644
index 00000000..24a550db
--- /dev/null
+++ b/tests/core/test_emptyclass.in
@@ -0,0 +1,15 @@
+
+ #include <stdio.h>
+
+ struct Randomized {
+ Randomized(int x) {
+ printf("*zzcheezzz*\n");
+ }
+ };
+
+ int main( int argc, const char *argv[] ) {
+ new Randomized(55);
+
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_emptyclass.out b/tests/core/test_emptyclass.out
new file mode 100644
index 00000000..1be15e15
--- /dev/null
+++ b/tests/core/test_emptyclass.out
@@ -0,0 +1 @@
+*zzcheezzz* \ No newline at end of file
diff --git a/tests/core/test_emscripten_api.in b/tests/core/test_emscripten_api.in
new file mode 100644
index 00000000..fb25175e
--- /dev/null
+++ b/tests/core/test_emscripten_api.in
@@ -0,0 +1,17 @@
+
+ #include <stdio.h>
+ #include "emscripten.h"
+
+ extern "C" {
+ void save_me_aimee() { printf("mann\n"); }
+ }
+
+ int main() {
+ // EMSCRIPTEN_COMMENT("hello from the source");
+ emscripten_run_script("Module.print('hello world' + '!')");
+ printf("*%d*\n", emscripten_run_script_int("5*20"));
+ printf("*%s*\n", emscripten_run_script_string("'five'+'six'"));
+ emscripten_run_script("Module['_save_me_aimee']()");
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_emscripten_api.out b/tests/core/test_emscripten_api.out
new file mode 100644
index 00000000..c0807cf1
--- /dev/null
+++ b/tests/core/test_emscripten_api.out
@@ -0,0 +1,4 @@
+hello world!
+*100*
+*fivesix*
+mann
diff --git a/tests/core/test_erf.in b/tests/core/test_erf.in
new file mode 100644
index 00000000..70658ea5
--- /dev/null
+++ b/tests/core/test_erf.in
@@ -0,0 +1,15 @@
+
+ #include <math.h>
+ #include <stdio.h>
+ int main()
+ {
+ printf("%1.6f, %1.6f, %1.6f, %1.6f, %1.6f, %1.6f\n",
+ erf(1.0),
+ erf(3.0),
+ erf(-1.0),
+ erfc(1.0),
+ erfc(3.0),
+ erfc(-1.5));
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_erf.out b/tests/core/test_erf.out
new file mode 100644
index 00000000..3b48202f
--- /dev/null
+++ b/tests/core/test_erf.out
@@ -0,0 +1 @@
+0.842701, 0.999978, -0.842701, 0.157299, 0.000022, 1.966105 \ No newline at end of file
diff --git a/tests/core/test_errar.in b/tests/core/test_errar.in
new file mode 100644
index 00000000..7ef2b23d
--- /dev/null
+++ b/tests/core/test_errar.in
@@ -0,0 +1,21 @@
+
+ #include <stdio.h>
+ #include <errno.h>
+ #include <string.h>
+
+ int main() {
+ char* err;
+ char buffer[200];
+
+ err = strerror(EDOM);
+ strerror_r(EWOULDBLOCK, buffer, 200);
+ printf("<%s>\n", err);
+ printf("<%s>\n", buffer);
+
+ printf("<%d>\n", strerror_r(EWOULDBLOCK, buffer, 0));
+ errno = 123;
+ printf("<%d>\n", errno);
+
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_errar.out b/tests/core/test_errar.out
new file mode 100644
index 00000000..2a042eb1
--- /dev/null
+++ b/tests/core/test_errar.out
@@ -0,0 +1,4 @@
+<Math arg out of domain of func>
+<No more processes>
+<34>
+<123>
diff --git a/tests/core/test_exception_2.in b/tests/core/test_exception_2.in
new file mode 100644
index 00000000..5a9efce5
--- /dev/null
+++ b/tests/core/test_exception_2.in
@@ -0,0 +1,26 @@
+
+ #include <stdexcept>
+ #include <stdio.h>
+
+ typedef void (*FuncPtr)();
+
+ void ThrowException()
+ {
+ throw std::runtime_error("catch me!");
+ }
+
+ FuncPtr ptr = ThrowException;
+
+ int main()
+ {
+ try
+ {
+ ptr();
+ }
+ catch(...)
+ {
+ printf("Exception caught successfully!\n");
+ }
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_exception_2.out b/tests/core/test_exception_2.out
new file mode 100644
index 00000000..aa89c67d
--- /dev/null
+++ b/tests/core/test_exception_2.out
@@ -0,0 +1 @@
+Exception caught successfully! \ No newline at end of file
diff --git a/tests/core/test_fakestat.in b/tests/core/test_fakestat.in
new file mode 100644
index 00000000..9a09b57c
--- /dev/null
+++ b/tests/core/test_fakestat.in
@@ -0,0 +1,10 @@
+
+ #include <stdio.h>
+ struct stat { int x, y; };
+ int main() {
+ stat s;
+ s.x = 10;
+ s.y = 22;
+ printf("*%d,%d*\n", s.x, s.y);
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_fakestat.out b/tests/core/test_fakestat.out
new file mode 100644
index 00000000..fbb3ab3c
--- /dev/null
+++ b/tests/core/test_fakestat.out
@@ -0,0 +1 @@
+*10,22* \ No newline at end of file
diff --git a/tests/core/test_fast_math.in b/tests/core/test_fast_math.in
new file mode 100644
index 00000000..27bd01fd
--- /dev/null
+++ b/tests/core/test_fast_math.in
@@ -0,0 +1,14 @@
+
+#include <stdio.h>
+#include <stdlib.h>
+
+int main(int argc, char** argv) {
+ char* endptr;
+ --argc, ++argv;
+ double total = 0.0;
+ for (; argc; argc--, argv++) {
+ total += strtod(*argv, &endptr);
+ }
+ printf("total: %g\n", total);
+ return 0;
+}
diff --git a/tests/core/test_fast_math.out b/tests/core/test_fast_math.out
new file mode 100644
index 00000000..d1bb5700
--- /dev/null
+++ b/tests/core/test_fast_math.out
@@ -0,0 +1 @@
+total: 19 \ No newline at end of file
diff --git a/tests/core/test_fcvt.in b/tests/core/test_fcvt.in
new file mode 100644
index 00000000..66b5adef
--- /dev/null
+++ b/tests/core/test_fcvt.in
@@ -0,0 +1,14 @@
+/* This example borrowed from MSDN documentation */
+ #include <stdlib.h>
+ #include <stdio.h>
+
+ int main() {
+ int decimal, sign;
+ char *buffer;
+ double source = 3.1415926535;
+
+ buffer = fcvt(source, 7, &decimal, &sign);
+ printf("source: %2.10f buffer: '%s' decimal: %d sign: %d\n",
+ source, buffer, decimal, sign);
+ }
+
diff --git a/tests/core/test_fcvt.out b/tests/core/test_fcvt.out
new file mode 100644
index 00000000..835f34e7
--- /dev/null
+++ b/tests/core/test_fcvt.out
@@ -0,0 +1 @@
+source: 3.1415926535 buffer: '31415927' decimal: 1 sign: 0 \ No newline at end of file
diff --git a/tests/core/test_flexarray_struct.in b/tests/core/test_flexarray_struct.in
new file mode 100644
index 00000000..40ee1ddd
--- /dev/null
+++ b/tests/core/test_flexarray_struct.in
@@ -0,0 +1,24 @@
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+typedef struct
+{
+ uint16_t length;
+ struct
+ {
+ int32_t int32;
+ } value[];
+} Tuple;
+
+int main() {
+ Tuple T[10];
+ Tuple *t = &T[0];
+
+ t->length = 4;
+ t->value->int32 = 100;
+
+ printf("(%d, %d)\n", t->length, t->value->int32);
+ return 0;
+}
diff --git a/tests/core/test_flexarray_struct.out b/tests/core/test_flexarray_struct.out
new file mode 100644
index 00000000..b6f53a0d
--- /dev/null
+++ b/tests/core/test_flexarray_struct.out
@@ -0,0 +1 @@
+(4, 100) \ No newline at end of file
diff --git a/tests/core/test_float32_precise.in b/tests/core/test_float32_precise.in
new file mode 100644
index 00000000..231b4289
--- /dev/null
+++ b/tests/core/test_float32_precise.in
@@ -0,0 +1,21 @@
+
+ #include <stdio.h>
+
+ int main(int argc, char **argv) {
+ float x = 1.23456789123456789;
+ float y = 5.20456089123406709;
+ while (argc > 10 || argc % 19 == 15) {
+ // confuse optimizer
+ x /= y;
+ y = 2*y - 1;
+ argc--;
+ }
+ x = x - y;
+ y = 3*y - x/2;
+ x = x*y;
+ y += 0.000000000123123123123;
+ x -= y/7.654;
+ printf("\n%.20f, %.20f\n", x, y);
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_float32_precise.out b/tests/core/test_float32_precise.out
new file mode 100644
index 00000000..f5eeb505
--- /dev/null
+++ b/tests/core/test_float32_precise.out
@@ -0,0 +1,2 @@
+
+-72.16590881347656250000, 17.59867858886718750000
diff --git a/tests/core/test_floatvars.in b/tests/core/test_floatvars.in
new file mode 100644
index 00000000..f63da19c
--- /dev/null
+++ b/tests/core/test_floatvars.in
@@ -0,0 +1,29 @@
+
+ #include <stdio.h>
+
+ // headers test, see issue #1013
+ #include<cfloat>
+ #include<cmath>
+
+ int main(int argc, char **argv)
+ {
+ float x = 1.234, y = 3.5, q = 0.00000001;
+ y *= 3;
+ int z = x < y;
+ printf("*%d,%d,%.1f,%d,%.4f,%.2f*\n", z, int(y), y, (int)x, x, q);
+
+ printf("%.2f, %.2f, %.2f, %.2f\n", fmin(0.5, 3.3), fmin(NAN, 3.3), fmax(0.5, 3.3), fmax(NAN, 3.3));
+
+ printf("small: %.10f\n", argc * 0.000001);
+
+ /*
+ // Rounding behavior
+ float fs[6] = { -2.75, -2.50, -2.25, 2.25, 2.50, 2.75 };
+ double ds[6] = { -2.75, -2.50, -2.25, 2.25, 2.50, 2.75 };
+ for (int i = 0; i < 6; i++)
+ printf("*int(%.2f)=%d,%d*\n", fs[i], int(fs[i]), int(ds[i]));
+ */
+
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_floatvars.out b/tests/core/test_floatvars.out
new file mode 100644
index 00000000..57635092
--- /dev/null
+++ b/tests/core/test_floatvars.out
@@ -0,0 +1,3 @@
+*1,10,10.5,1,1.2340,0.00*
+0.50, 3.30, 3.30, 3.30
+small: 0.0000010000
diff --git a/tests/core/test_frexp.in b/tests/core/test_frexp.in
new file mode 100644
index 00000000..d3facca8
--- /dev/null
+++ b/tests/core/test_frexp.in
@@ -0,0 +1,32 @@
+
+ #include <stdio.h>
+ #include <math.h>
+ #include <assert.h>
+
+ static const double tol=1e-16;
+
+ void test_value(double value)
+ {
+ int exponent;
+ double x=frexp(value, &exponent);
+ double expected=x*pow(2.0, exponent);
+
+ printf("%f=%f*2^%d\n", value, x, exponent);
+
+ assert(fabs(expected-value)<tol);
+ assert(x==0 || (fabs(x)>=5e-1 && fabs(x)<1)); // x has a magnitude in the interval [1/2, 1)
+ }
+
+ int main()
+ {
+ test_value(0);
+ test_value(100.1);
+ test_value(-100.1);
+ test_value(.5);
+ test_value(-.5);
+ test_value(1-1e-16);
+ test_value(-(1-1e-16));
+
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_frexp.out b/tests/core/test_frexp.out
new file mode 100644
index 00000000..341b790e
--- /dev/null
+++ b/tests/core/test_frexp.out
@@ -0,0 +1,7 @@
+0.000000=0.000000*2^0
+100.100000=0.782031*2^7
+-100.100000=-0.782031*2^7
+0.500000=0.500000*2^0
+-0.500000=-0.500000*2^0
+1.000000=1.000000*2^0
+-1.000000=-1.000000*2^0 \ No newline at end of file
diff --git a/tests/core/test_funcptr.in b/tests/core/test_funcptr.in
new file mode 100644
index 00000000..8328924a
--- /dev/null
+++ b/tests/core/test_funcptr.in
@@ -0,0 +1,35 @@
+
+ #include <stdio.h>
+ int calc1() { return 26; }
+ int calc2() { return 90; }
+ typedef int (*fp_t)();
+
+ fp_t globally1 = calc1;
+ fp_t globally2 = calc2;
+
+ int nothing(const char *str) { return 0; }
+
+ int main()
+ {
+ fp_t fp = calc1;
+ void *vp = (void*)fp;
+ fp_t fpb = (fp_t)vp;
+ fp_t fp2 = calc2;
+ void *vp2 = (void*)fp2;
+ fp_t fpb2 = (fp_t)vp2;
+ printf("*%d,%d,%d,%d,%d,%d*\n", fp(), fpb(), fp2(), fpb2(), globally1(), globally2());
+
+ fp_t t = calc1;
+ printf("*%d,%d", t == calc1, t == calc2);
+ t = calc2;
+ printf(",%d,%d*\n", t == calc1, t == calc2);
+
+ int (*other)(const char *str);
+ other = nothing;
+ other("*hello!*");
+ other = puts;
+ other("*goodbye!*");
+
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_funcptr.out b/tests/core/test_funcptr.out
new file mode 100644
index 00000000..d6d3366a
--- /dev/null
+++ b/tests/core/test_funcptr.out
@@ -0,0 +1,3 @@
+*26,26,90,90,26,90*
+*1,0,0,1*
+*goodbye!* \ No newline at end of file
diff --git a/tests/core/test_funcptr_namecollide.in b/tests/core/test_funcptr_namecollide.in
new file mode 100644
index 00000000..0b27b07c
--- /dev/null
+++ b/tests/core/test_funcptr_namecollide.in
@@ -0,0 +1,27 @@
+
+ #include <stdio.h>
+
+ void do_call(void (*puts)(const char *), const char *str);
+
+ void do_print(const char *str) {
+ if (!str) do_call(NULL, "delusion");
+ if ((int)str == -1) do_print(str+10);
+ puts("====");
+ puts(str);
+ puts("====");
+ }
+
+ void do_call(void (*puts)(const char *), const char *str) {
+ if (!str) do_print("confusion");
+ if ((int)str == -1) do_call(NULL, str-10);
+ (*puts)(str);
+ }
+
+ int main(int argc, char **argv)
+ {
+ for (int i = 0; i < argc; i++) {
+ do_call(i != 10 ? do_print : NULL, i != 15 ? "waka waka" : NULL);
+ }
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_funcptr_namecollide.out b/tests/core/test_funcptr_namecollide.out
new file mode 100644
index 00000000..360b24da
--- /dev/null
+++ b/tests/core/test_funcptr_namecollide.out
@@ -0,0 +1 @@
+waka \ No newline at end of file
diff --git a/tests/core/test_funcptrfunc.in b/tests/core/test_funcptrfunc.in
new file mode 100644
index 00000000..6c146421
--- /dev/null
+++ b/tests/core/test_funcptrfunc.in
@@ -0,0 +1,17 @@
+
+ #include <stdio.h>
+
+ typedef void (*funcptr)(int, int);
+ typedef funcptr (*funcptrfunc)(int);
+
+ funcptr __attribute__ ((noinline)) getIt(int x) {
+ return (funcptr)x;
+ }
+
+ int main(int argc, char **argv)
+ {
+ funcptrfunc fpf = argc < 100 ? getIt : NULL;
+ printf("*%p*\n", fpf(argc));
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_funcptrfunc.out b/tests/core/test_funcptrfunc.out
new file mode 100644
index 00000000..0d1299f6
--- /dev/null
+++ b/tests/core/test_funcptrfunc.out
@@ -0,0 +1 @@
+*0x1* \ No newline at end of file
diff --git a/tests/core/test_funcs.in b/tests/core/test_funcs.in
new file mode 100644
index 00000000..f2e707f9
--- /dev/null
+++ b/tests/core/test_funcs.in
@@ -0,0 +1,12 @@
+
+ #include <stdio.h>
+ int funcy(int x)
+ {
+ return x*9;
+ }
+ int main()
+ {
+ printf("*%d,%d*\n", funcy(8), funcy(10));
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_funcs.out b/tests/core/test_funcs.out
new file mode 100644
index 00000000..f58def9a
--- /dev/null
+++ b/tests/core/test_funcs.out
@@ -0,0 +1 @@
+*72,90* \ No newline at end of file
diff --git a/tests/core/test_functionpointer_libfunc_varargs.in b/tests/core/test_functionpointer_libfunc_varargs.in
new file mode 100644
index 00000000..6cabe8c5
--- /dev/null
+++ b/tests/core/test_functionpointer_libfunc_varargs.in
@@ -0,0 +1,13 @@
+
+ #include <stdio.h>
+ #include <fcntl.h>
+ typedef int (*fp_t)(int, int, ...);
+ int main(int argc, char **argv) {
+ fp_t fp = &fcntl;
+ if (argc == 1337) fp = (fp_t)&main;
+ (*fp)(0, 10);
+ (*fp)(0, 10, 5);
+ printf("waka\n");
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_functionpointer_libfunc_varargs.out b/tests/core/test_functionpointer_libfunc_varargs.out
new file mode 100644
index 00000000..360b24da
--- /dev/null
+++ b/tests/core/test_functionpointer_libfunc_varargs.out
@@ -0,0 +1 @@
+waka \ No newline at end of file
diff --git a/tests/core/test_fwrite_0.in b/tests/core/test_fwrite_0.in
new file mode 100644
index 00000000..478524bb
--- /dev/null
+++ b/tests/core/test_fwrite_0.in
@@ -0,0 +1,21 @@
+
+ #include <stdio.h>
+ #include <stdlib.h>
+
+ int main ()
+ {
+ FILE *fh;
+
+ fh = fopen("a.txt", "wb");
+ if (!fh) exit(1);
+ fclose(fh);
+
+ fh = fopen("a.txt", "rb");
+ if (!fh) exit(1);
+
+ char data[] = "foobar";
+ size_t written = fwrite(data, 1, sizeof(data), fh);
+
+ printf("written=%zu\n", written);
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_fwrite_0.out b/tests/core/test_fwrite_0.out
new file mode 100644
index 00000000..d96592d1
--- /dev/null
+++ b/tests/core/test_fwrite_0.out
@@ -0,0 +1 @@
+written=0 \ No newline at end of file
diff --git a/tests/core/test_gc.in b/tests/core/test_gc.in
new file mode 100644
index 00000000..ae94b0ec
--- /dev/null
+++ b/tests/core/test_gc.in
@@ -0,0 +1,107 @@
+
+ #include <stdio.h>
+ #include <gc.h>
+ #include <assert.h>
+
+ void *global;
+
+ void finalizer(void *ptr, void *arg) {
+ printf("finalizing %d (global == %d)\n", (int)arg, ptr == global);
+ }
+
+ void finalizer2(void *ptr, void *arg) {
+ printf("finalizing2 %d (global == %d)\n", (int)arg, ptr == global);
+ }
+
+ int main() {
+ GC_INIT();
+
+ void *local, *local2, *local3, *local4, *local5, *local6;
+
+ // Hold on to global, drop locals
+
+ global = GC_MALLOC(1024); // rooted since in a static allocation
+ GC_REGISTER_FINALIZER_NO_ORDER(global, finalizer, 0, 0, 0);
+ printf("alloc %p\n", global);
+
+ local = GC_MALLOC(1024); // not rooted since stack is not scanned
+ GC_REGISTER_FINALIZER_NO_ORDER(local, finalizer, (void*)1, 0, 0);
+ printf("alloc %p\n", local);
+
+ assert((char*)local - (char*)global >= 1024 || (char*)global - (char*)local >= 1024);
+
+ local2 = GC_MALLOC(1024); // no finalizer
+ printf("alloc %p\n", local2);
+
+ local3 = GC_MALLOC(1024); // with finalizable2
+ GC_REGISTER_FINALIZER_NO_ORDER(local3, finalizer2, (void*)2, 0, 0);
+ printf("alloc %p\n", local);
+
+ local4 = GC_MALLOC(1024); // yet another
+ GC_REGISTER_FINALIZER_NO_ORDER(local4, finalizer2, (void*)3, 0, 0);
+ printf("alloc %p\n", local);
+
+ printf("basic test\n");
+
+ GC_FORCE_COLLECT();
+
+ printf("*\n");
+
+ GC_FREE(global); // force free will actually work
+
+ // scanning inside objects
+
+ global = GC_MALLOC(12);
+ GC_REGISTER_FINALIZER_NO_ORDER(global, finalizer, 0, 0, 0);
+ local = GC_MALLOC(12);
+ GC_REGISTER_FINALIZER_NO_ORDER(local, finalizer, (void*)1, 0, 0);
+ local2 = GC_MALLOC_ATOMIC(12);
+ GC_REGISTER_FINALIZER_NO_ORDER(local2, finalizer, (void*)2, 0, 0);
+ local3 = GC_MALLOC(12);
+ GC_REGISTER_FINALIZER_NO_ORDER(local3, finalizer, (void*)3, 0, 0);
+ local4 = GC_MALLOC(12);
+ GC_REGISTER_FINALIZER_NO_ORDER(local4, finalizer, (void*)4, 0, 0);
+ local5 = GC_MALLOC_UNCOLLECTABLE(12);
+ // This should never trigger since local5 is uncollectable
+ GC_REGISTER_FINALIZER_NO_ORDER(local5, finalizer, (void*)5, 0, 0);
+
+ printf("heap size = %d\n", GC_get_heap_size());
+
+ local4 = GC_REALLOC(local4, 24);
+
+ printf("heap size = %d\n", GC_get_heap_size());
+
+ local6 = GC_MALLOC(12);
+ GC_REGISTER_FINALIZER_NO_ORDER(local6, finalizer, (void*)6, 0, 0);
+ // This should be the same as a free
+ GC_REALLOC(local6, 0);
+
+ void **globalData = (void**)global;
+ globalData[0] = local;
+ globalData[1] = local2;
+
+ void **localData = (void**)local;
+ localData[0] = local3;
+
+ void **local2Data = (void**)local2;
+ local2Data[0] = local4; // actually ignored, because local2 is atomic, so 4 is freeable
+
+ printf("object scan test test\n");
+
+ GC_FORCE_COLLECT();
+
+ printf("*\n");
+
+ GC_FREE(global); // force free will actually work
+
+ printf("*\n");
+
+ GC_FORCE_COLLECT();
+
+ printf(".\n");
+
+ global = 0;
+
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_gc.out b/tests/core/test_gc.out
new file mode 100644
index 00000000..6ce8bff9
--- /dev/null
+++ b/tests/core/test_gc.out
@@ -0,0 +1,18 @@
+basic test
+finalizing 1 (global == 0)
+finalizing2 2 (global == 0)
+finalizing2 3 (global == 0)
+*
+finalizing 0 (global == 1)
+heap size = 72
+heap size = 84
+finalizing 6 (global == 0)
+object scan test test
+finalizing 4 (global == 0)
+*
+finalizing 0 (global == 1)
+*
+finalizing 1 (global == 0)
+finalizing 2 (global == 0)
+finalizing 3 (global == 0)
+.
diff --git a/tests/core/test_getgep.in b/tests/core/test_getgep.in
new file mode 100644
index 00000000..b92c4a1a
--- /dev/null
+++ b/tests/core/test_getgep.in
@@ -0,0 +1,17 @@
+
+ #include <stdio.h>
+ struct {
+ int y[10];
+ int z[10];
+ } commonblock;
+
+ int main()
+ {
+ for (int i = 0; i < 10; ++i) {
+ commonblock.y[i] = 1;
+ commonblock.z[i] = 2;
+ }
+ printf("*%d %d*\n", commonblock.y[0], commonblock.z[0]);
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_getgep.out b/tests/core/test_getgep.out
new file mode 100644
index 00000000..a53d59ff
--- /dev/null
+++ b/tests/core/test_getgep.out
@@ -0,0 +1 @@
+*1 2* \ No newline at end of file
diff --git a/tests/core/test_getloadavg.in b/tests/core/test_getloadavg.in
new file mode 100644
index 00000000..8365a9a1
--- /dev/null
+++ b/tests/core/test_getloadavg.in
@@ -0,0 +1,15 @@
+
+ #include <stdio.h>
+ #include <stdlib.h>
+
+ int main() {
+ double load[5] = {42.13, 42.13, 42.13, 42.13, 42.13};
+ printf("ret: %d\n", getloadavg(load, 5));
+ printf("load[0]: %.3lf\n", load[0]);
+ printf("load[1]: %.3lf\n", load[1]);
+ printf("load[2]: %.3lf\n", load[2]);
+ printf("load[3]: %.3lf\n", load[3]);
+ printf("load[4]: %.3lf\n", load[4]);
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_getloadavg.out b/tests/core/test_getloadavg.out
new file mode 100644
index 00000000..a7433f65
--- /dev/null
+++ b/tests/core/test_getloadavg.out
@@ -0,0 +1,6 @@
+ret: 3
+load[0]: 0.100
+load[1]: 0.100
+load[2]: 0.100
+load[3]: 42.130
+load[4]: 42.130
diff --git a/tests/core/test_getopt.in b/tests/core/test_getopt.in
new file mode 100644
index 00000000..1f03ef4e
--- /dev/null
+++ b/tests/core/test_getopt.in
@@ -0,0 +1,45 @@
+
+ #pragma clang diagnostic ignored "-Winvalid-pp-token"
+ #include <unistd.h>
+ #include <stdlib.h>
+ #include <stdio.h>
+
+ int
+ main(int argc, char *argv[])
+ {
+ int flags, opt;
+ int nsecs, tfnd;
+
+ nsecs = 0;
+ tfnd = 0;
+ flags = 0;
+ while ((opt = getopt(argc, argv, "nt:")) != -1) {
+ switch (opt) {
+ case 'n':
+ flags = 1;
+ break;
+ case 't':
+ nsecs = atoi(optarg);
+ tfnd = 1;
+ break;
+ default: /* '?' */
+ fprintf(stderr, "Usage: %s [-t nsecs] [-n] name\n",
+ argv[0]);
+ exit(EXIT_FAILURE);
+ }
+ }
+
+ printf("flags=%d; tfnd=%d; optind=%d\n", flags, tfnd, optind);
+
+ if (optind >= argc) {
+ fprintf(stderr, "Expected argument after options\n");
+ exit(EXIT_FAILURE);
+ }
+
+ printf("name argument = %s\n", argv[optind]);
+
+ /* Other code omitted */
+
+ exit(EXIT_SUCCESS);
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_getopt.out b/tests/core/test_getopt.out
new file mode 100644
index 00000000..d06da507
--- /dev/null
+++ b/tests/core/test_getopt.out
@@ -0,0 +1,2 @@
+flags=1; tfnd=1; optind=4
+name argument = foobar \ No newline at end of file
diff --git a/tests/core/test_getopt_long.in b/tests/core/test_getopt_long.in
new file mode 100644
index 00000000..cc5c3e21
--- /dev/null
+++ b/tests/core/test_getopt_long.in
@@ -0,0 +1,82 @@
+
+ #pragma clang diagnostic ignored "-Winvalid-pp-token"
+ #pragma clang diagnostic ignored "-Wdeprecated-writable-strings"
+ #include <stdio.h> /* for printf */
+ #include <stdlib.h> /* for exit */
+ #include <getopt.h>
+
+ int
+ main(int argc, char **argv)
+ {
+ int c;
+ int digit_optind = 0;
+
+ while (1) {
+ int this_option_optind = optind ? optind : 1;
+ int option_index = 0;
+ static struct option long_options[] = {
+ {"add", required_argument, 0, 0 },
+ {"append", no_argument, 0, 0 },
+ {"delete", required_argument, 0, 0 },
+ {"verbose", no_argument, 0, 0 },
+ {"create", required_argument, 0, 'c'},
+ {"file", required_argument, 0, 0 },
+ {0, 0, 0, 0 }
+ };
+
+ c = getopt_long(argc, argv, "abc:d:012",
+ long_options, &option_index);
+ if (c == -1)
+ break;
+
+ switch (c) {
+ case 0:
+ printf("option %s", long_options[option_index].name);
+ if (optarg)
+ printf(" with arg %s", optarg);
+ printf("\n");
+ break;
+
+ case '0':
+ case '1':
+ case '2':
+ if (digit_optind != 0 && digit_optind != this_option_optind)
+ printf("digits occur in two different argv-elements.\n");
+ digit_optind = this_option_optind;
+ printf("option %c\n", c);
+ break;
+
+ case 'a':
+ printf("option a\n");
+ break;
+
+ case 'b':
+ printf("option b\n");
+ break;
+
+ case 'c':
+ printf("option c with value '%s'\n", optarg);
+ break;
+
+ case 'd':
+ printf("option d with value '%s'\n", optarg);
+ break;
+
+ case '?':
+ break;
+
+ default:
+ printf("?? getopt returned character code 0%o ??\n", c);
+ }
+ }
+
+ if (optind < argc) {
+ printf("non-option ARGV-elements: ");
+ while (optind < argc)
+ printf("%s ", argv[optind++]);
+ printf("\n");
+ }
+
+ exit(EXIT_SUCCESS);
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_getopt_long.out b/tests/core/test_getopt_long.out
new file mode 100644
index 00000000..22a7bd52
--- /dev/null
+++ b/tests/core/test_getopt_long.out
@@ -0,0 +1,2 @@
+option file with arg foobar
+option b \ No newline at end of file
diff --git a/tests/core/test_globaldoubles.in b/tests/core/test_globaldoubles.in
new file mode 100644
index 00000000..45acc194
--- /dev/null
+++ b/tests/core/test_globaldoubles.in
@@ -0,0 +1,26 @@
+
+ #include <stdlib.h>
+ #include <stdio.h>
+
+ double testVu, testVv, testWu, testWv;
+
+ void Test(double _testVu, double _testVv, double _testWu, double _testWv)
+ {
+ testVu = _testVu;
+ testVv = _testVv;
+ testWu = _testWu;
+ testWv = _testWv;
+ printf("BUG?\n");
+ printf("Display: Vu=%f Vv=%f Wu=%f Wv=%f\n", testVu, testVv, testWu, testWv);
+ }
+
+ int main(void)
+ {
+ double v1 = 465.1;
+ double v2 = 465.2;
+ double v3 = 160.3;
+ double v4 = 111.4;
+ Test(v1, v2, v3, v4);
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_globaldoubles.out b/tests/core/test_globaldoubles.out
new file mode 100644
index 00000000..b47c9691
--- /dev/null
+++ b/tests/core/test_globaldoubles.out
@@ -0,0 +1,2 @@
+BUG?
+Display: Vu=465.100000 Vv=465.200000 Wu=160.300000 Wv=111.400000 \ No newline at end of file
diff --git a/tests/core/test_globals.in b/tests/core/test_globals.in
new file mode 100644
index 00000000..ed5e7891
--- /dev/null
+++ b/tests/core/test_globals.in
@@ -0,0 +1,13 @@
+
+ #include <stdio.h>
+
+ char cache[256], *next = cache;
+
+ int main()
+ {
+ cache[10] = 25;
+ next[20] = 51;
+ printf("*%d,%d*\n", next[10], cache[20]);
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_globals.out b/tests/core/test_globals.out
new file mode 100644
index 00000000..2cb6768e
--- /dev/null
+++ b/tests/core/test_globals.out
@@ -0,0 +1 @@
+*25,51* \ No newline at end of file
diff --git a/tests/core/test_gmtime.in b/tests/core/test_gmtime.in
new file mode 100644
index 00000000..41ce87f9
--- /dev/null
+++ b/tests/core/test_gmtime.in
@@ -0,0 +1,28 @@
+
+ #include <stdio.h>
+ #include <stdlib.h>
+ #include <time.h>
+ #include <assert.h>
+
+ int main(void)
+ {
+ time_t t=time(NULL);
+ struct tm *ptm=gmtime(&t);
+ struct tm tmCurrent=*ptm;
+ int hour=tmCurrent.tm_hour;
+
+ t-=hour*3600; // back to midnight
+ int yday = -1;
+ for(hour=0;hour<24;hour++)
+ {
+ ptm=gmtime(&t);
+ // tm_yday must be constant all day...
+ printf("yday: %d, hour: %d\n", ptm->tm_yday, hour);
+ if (yday == -1) yday = ptm->tm_yday;
+ else assert(yday == ptm->tm_yday);
+ t+=3600; // add one hour
+ }
+ printf("ok!\n");
+ return(0);
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_gmtime.out b/tests/core/test_gmtime.out
new file mode 100644
index 00000000..e036282a
--- /dev/null
+++ b/tests/core/test_gmtime.out
@@ -0,0 +1 @@
+ok! \ No newline at end of file
diff --git a/tests/core/test_hello_world.in b/tests/core/test_hello_world.in
new file mode 100644
index 00000000..d9ca3acb
--- /dev/null
+++ b/tests/core/test_hello_world.in
@@ -0,0 +1,8 @@
+
+ #include <stdio.h>
+ int main()
+ {
+ printf("hello, world!\n");
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_hello_world.out b/tests/core/test_hello_world.out
new file mode 100644
index 00000000..30f51a3f
--- /dev/null
+++ b/tests/core/test_hello_world.out
@@ -0,0 +1 @@
+hello, world! \ No newline at end of file
diff --git a/tests/core/test_i16_emcc_intrinsic.in b/tests/core/test_i16_emcc_intrinsic.in
new file mode 100644
index 00000000..54008cee
--- /dev/null
+++ b/tests/core/test_i16_emcc_intrinsic.in
@@ -0,0 +1,20 @@
+
+ #include <stdio.h>
+
+ int test(unsigned short a, unsigned short b) {
+ unsigned short result = a;
+ result += b;
+ if (result < b) printf("C!");
+ return result;
+ }
+
+ int main(void) {
+ printf(",%d,", test(0, 0));
+ printf(",%d,", test(1, 1));
+ printf(",%d,", test(65535, 1));
+ printf(",%d,", test(1, 65535));
+ printf(",%d,", test(32768, 32767));
+ printf(",%d,", test(32768, 32768));
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_i16_emcc_intrinsic.out b/tests/core/test_i16_emcc_intrinsic.out
new file mode 100644
index 00000000..35af1e0d
--- /dev/null
+++ b/tests/core/test_i16_emcc_intrinsic.out
@@ -0,0 +1 @@
+,0,,2,C!,0,C!,0,,65535,C!,0, \ No newline at end of file
diff --git a/tests/core/test_i32_mul_precise.in b/tests/core/test_i32_mul_precise.in
new file mode 100644
index 00000000..f045a768
--- /dev/null
+++ b/tests/core/test_i32_mul_precise.in
@@ -0,0 +1,11 @@
+
+ #include <stdio.h>
+
+ int main(int argc, char **argv) {
+ unsigned long d1 = 0x847c9b5d;
+ unsigned long q = 0x549530e1;
+ if (argc > 1000) { q += argc; d1 -= argc; } // confuse optimizer
+ printf("%lu\n", d1*q);
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_i32_mul_precise.out b/tests/core/test_i32_mul_precise.out
new file mode 100644
index 00000000..d46a5055
--- /dev/null
+++ b/tests/core/test_i32_mul_precise.out
@@ -0,0 +1 @@
+3217489085 \ No newline at end of file
diff --git a/tests/core/test_i32_mul_semiprecise.in b/tests/core/test_i32_mul_semiprecise.in
new file mode 100644
index 00000000..c7b4cb96
--- /dev/null
+++ b/tests/core/test_i32_mul_semiprecise.in
@@ -0,0 +1,28 @@
+
+ #include <stdio.h>
+
+ typedef unsigned int uint;
+
+ // from cube2, zlib licensed
+
+ #define N (624)
+ #define M (397)
+ #define K (0x9908B0DFU)
+
+ static uint state[N];
+ static int next = N;
+
+ void seedMT(uint seed)
+ {
+ state[0] = seed;
+ for(uint i = 1; i < N; i++) // if we do not do this precisely, at least we should coerce to int immediately, not wait
+ state[i] = seed = 1812433253U * (seed ^ (seed >> 30)) + i;
+ next = 0;
+ }
+
+ int main() {
+ seedMT(5497);
+ for (int i = 0; i < 10; i++) printf("%d: %u\n", i, state[i]);
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_i32_mul_semiprecise.out b/tests/core/test_i32_mul_semiprecise.out
new file mode 100644
index 00000000..261bf9a9
--- /dev/null
+++ b/tests/core/test_i32_mul_semiprecise.out
@@ -0,0 +1,10 @@
+0: 5497
+1: 2916432318
+2: 2502517762
+3: 3151524867
+4: 2323729668
+5: 2053478917
+6: 2409490438
+7: 848473607
+8: 691103752
+9: 3915535113
diff --git a/tests/core/test_i64_7z.in b/tests/core/test_i64_7z.in
new file mode 100644
index 00000000..1d2f03a8
--- /dev/null
+++ b/tests/core/test_i64_7z.in
@@ -0,0 +1,17 @@
+
+ #include <stdint.h>
+ #include <stdio.h>
+ uint64_t a, b;
+ int main(int argc, char *argv[])
+ {
+ a = argc;
+ b = argv[1][0];
+ printf("%d,%d\n", a, b);
+ if (a > a + b || a > a + b + 1) {
+ printf("one %lld, %lld", a, b);
+ return 0;
+ }
+ printf("zero %lld, %lld", a, b);
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_i64_7z.out b/tests/core/test_i64_7z.out
new file mode 100644
index 00000000..3e9d35a4
--- /dev/null
+++ b/tests/core/test_i64_7z.out
@@ -0,0 +1 @@
+zero 2, 104 \ No newline at end of file
diff --git a/tests/core/test_i64_b.in b/tests/core/test_i64_b.in
new file mode 100644
index 00000000..b373a3aa
--- /dev/null
+++ b/tests/core/test_i64_b.in
@@ -0,0 +1,22 @@
+
+ #include <stdio.h>
+ #include <sys/time.h>
+
+ typedef long long int64;
+
+ #define PRMJ_USEC_PER_SEC 1000000L
+
+ int main(int argc, char * argv[]) {
+ int64 sec = 1329409675 + argc;
+ int64 usec = 2329509675;
+ int64 mul = int64(sec) * PRMJ_USEC_PER_SEC;
+ int64 add = mul + int64(usec);
+ int add_low = add;
+ int add_high = add >> 32;
+ printf("*%lld,%lld,%u,%u*\n", mul, add, add_low, add_high);
+ int64 x = sec + (usec << 25);
+ x >>= argc*3;
+ printf("*%llu*\n", x);
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_i64_b.out b/tests/core/test_i64_b.out
new file mode 100644
index 00000000..70d0a95c
--- /dev/null
+++ b/tests/core/test_i64_b.out
@@ -0,0 +1,2 @@
+*1329409676000000,1329412005509675,3663280683,309527*
+*9770671914067409*
diff --git a/tests/core/test_i64_cmp.in b/tests/core/test_i64_cmp.in
new file mode 100644
index 00000000..b967d2ff
--- /dev/null
+++ b/tests/core/test_i64_cmp.in
@@ -0,0 +1,18 @@
+
+ #include <stdio.h>
+
+ typedef long long int64;
+
+ bool compare(int64 val) {
+ return val == -12;
+ }
+
+ bool compare2(int64 val) {
+ return val < -12;
+ }
+
+ int main(int argc, char * argv[]) {
+ printf("*%d,%d,%d,%d,%d,%d*\n", argc, compare(argc-1-12), compare(1000+argc), compare2(argc-1-10), compare2(argc-1-14), compare2(argc+1000));
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_i64_cmp.out b/tests/core/test_i64_cmp.out
new file mode 100644
index 00000000..6474e7f5
--- /dev/null
+++ b/tests/core/test_i64_cmp.out
@@ -0,0 +1 @@
+*1,1,0,0,1,0*
diff --git a/tests/core/test_i64_cmp2.in b/tests/core/test_i64_cmp2.in
new file mode 100644
index 00000000..b285e1a1
--- /dev/null
+++ b/tests/core/test_i64_cmp2.in
@@ -0,0 +1,32 @@
+
+ #include <inttypes.h>
+ #include <stdio.h>
+
+ typedef int32_t INT32;
+ typedef int64_t INT64;
+ typedef uint8_t UINT8;
+
+ void interface_clock_changed()
+ {
+ UINT8 m_divshift;
+ INT32 m_divisor;
+
+ //INT64 attos = m_attoseconds_per_cycle;
+ INT64 attos = 279365114840;
+ m_divshift = 0;
+ while (attos >= (1UL << 31))
+ {
+ m_divshift++;
+ printf("m_divshift is %i, on %Ld >?= %lu\n", m_divshift, attos, 1UL << 31);
+ attos >>= 1;
+ }
+ m_divisor = attos;
+
+ printf("m_divisor is %i\n",m_divisor);
+ }
+
+ int main() {
+ interface_clock_changed();
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_i64_cmp2.out b/tests/core/test_i64_cmp2.out
new file mode 100644
index 00000000..893bb826
--- /dev/null
+++ b/tests/core/test_i64_cmp2.out
@@ -0,0 +1,9 @@
+m_divshift is 1, on 279365114840 >?= 2147483648
+m_divshift is 2, on 139682557420 >?= 2147483648
+m_divshift is 3, on 69841278710 >?= 2147483648
+m_divshift is 4, on 34920639355 >?= 2147483648
+m_divshift is 5, on 17460319677 >?= 2147483648
+m_divshift is 6, on 8730159838 >?= 2147483648
+m_divshift is 7, on 4365079919 >?= 2147483648
+m_divshift is 8, on 2182539959 >?= 2147483648
+m_divisor is 1091269979
diff --git a/tests/core/test_i64_double.in b/tests/core/test_i64_double.in
new file mode 100644
index 00000000..4b39355e
--- /dev/null
+++ b/tests/core/test_i64_double.in
@@ -0,0 +1,38 @@
+
+ #include <stdio.h>
+
+ typedef long long int64;
+ #define JSDOUBLE_HI32_SIGNBIT 0x80000000
+
+ bool JSDOUBLE_IS_NEGZERO(double d)
+ {
+ union {
+ struct {
+ unsigned int lo, hi;
+ } s;
+ double d;
+ } x;
+ if (d != 0)
+ return false;
+ x.d = d;
+ return (x.s.hi & JSDOUBLE_HI32_SIGNBIT) != 0;
+ }
+
+ bool JSINT64_IS_NEGZERO(int64 l)
+ {
+ union {
+ int64 i;
+ double d;
+ } x;
+ if (l != 0)
+ return false;
+ x.i = l;
+ return x.d == -0;
+ }
+
+ int main(int argc, char * argv[]) {
+ printf("*%d,%d,%d,%d*\n", JSDOUBLE_IS_NEGZERO(0), JSDOUBLE_IS_NEGZERO(-0), JSDOUBLE_IS_NEGZERO(-1), JSDOUBLE_IS_NEGZERO(+1));
+ printf("*%d,%d,%d,%d*\n", JSINT64_IS_NEGZERO(0), JSINT64_IS_NEGZERO(-0), JSINT64_IS_NEGZERO(-1), JSINT64_IS_NEGZERO(+1));
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_i64_double.out b/tests/core/test_i64_double.out
new file mode 100644
index 00000000..cfb98703
--- /dev/null
+++ b/tests/core/test_i64_double.out
@@ -0,0 +1,2 @@
+*0,0,0,0*
+*1,1,0,0*
diff --git a/tests/core/test_i64_i16.in b/tests/core/test_i64_i16.in
new file mode 100644
index 00000000..dcd9a69e
--- /dev/null
+++ b/tests/core/test_i64_i16.in
@@ -0,0 +1,12 @@
+
+ #include <stdint.h>
+ #include <stdio.h>
+ int main(int argc, char ** argv){
+ int y=-133;
+ int64_t x= ((int64_t)((short)(y)))*(100 + argc);
+ if(x>0)
+ printf(">0\n");
+ else
+ printf("<=0\n");
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_i64_i16.out b/tests/core/test_i64_i16.out
new file mode 100644
index 00000000..01adb429
--- /dev/null
+++ b/tests/core/test_i64_i16.out
@@ -0,0 +1 @@
+<=0 \ No newline at end of file
diff --git a/tests/core/test_i64_llabs.in b/tests/core/test_i64_llabs.in
new file mode 100644
index 00000000..10961970
--- /dev/null
+++ b/tests/core/test_i64_llabs.in
@@ -0,0 +1,9 @@
+
+ #include <stdio.h>
+ #include <stdlib.h>
+
+ int main(int argc, char ** argv) {
+ printf("%lld,%lld\n", llabs(-576460752303423489), llabs(576460752303423489));
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_i64_llabs.out b/tests/core/test_i64_llabs.out
new file mode 100644
index 00000000..e1ec5062
--- /dev/null
+++ b/tests/core/test_i64_llabs.out
@@ -0,0 +1 @@
+576460752303423489,576460752303423489 \ No newline at end of file
diff --git a/tests/core/test_i64_qdouble.in b/tests/core/test_i64_qdouble.in
new file mode 100644
index 00000000..1b8297e4
--- /dev/null
+++ b/tests/core/test_i64_qdouble.in
@@ -0,0 +1,21 @@
+
+ #include <stdio.h>
+ typedef long long qint64; /* 64 bit signed */
+ typedef double qreal;
+
+
+ int main(int argc, char **argv)
+ {
+ qreal c = 111;
+ qint64 d = -111 + (argc - 1);
+ c += d;
+ if (c < -1 || c > 1)
+ {
+ printf("Failed!\n");
+ }
+ else
+ {
+ printf("Succeeded!\n");
+ }
+ };
+ \ No newline at end of file
diff --git a/tests/core/test_i64_qdouble.out b/tests/core/test_i64_qdouble.out
new file mode 100644
index 00000000..0b9e5e9e
--- /dev/null
+++ b/tests/core/test_i64_qdouble.out
@@ -0,0 +1 @@
+Succeeded! \ No newline at end of file
diff --git a/tests/core/test_i64_umul.in b/tests/core/test_i64_umul.in
new file mode 100644
index 00000000..4b4bdaca
--- /dev/null
+++ b/tests/core/test_i64_umul.in
@@ -0,0 +1,20 @@
+
+ #include <inttypes.h>
+ #include <stdio.h>
+
+ typedef uint32_t UINT32;
+ typedef uint64_t UINT64;
+
+ int main() {
+ volatile UINT32 testu32a = 2375724032U;
+ UINT32 bigu32 = 0xffffffffU;
+ volatile UINT64 testu64a = 14746250828952703000U;
+
+ while ((UINT64)testu32a * (UINT64)bigu32 < testu64a) {
+ printf("testu64a is %llu\n", testu64a);
+ testu64a /= 2;
+ }
+
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_i64_umul.out b/tests/core/test_i64_umul.out
new file mode 100644
index 00000000..eb85c3ab
--- /dev/null
+++ b/tests/core/test_i64_umul.out
@@ -0,0 +1 @@
+testu64a is 14746250828952703000
diff --git a/tests/core/test_i64_varargs.in b/tests/core/test_i64_varargs.in
new file mode 100644
index 00000000..94982b51
--- /dev/null
+++ b/tests/core/test_i64_varargs.in
@@ -0,0 +1,30 @@
+
+ #include <stdio.h>
+ #include <stdint.h>
+ #include <stdarg.h>
+
+ int64_t ccv_cache_generate_signature(char *msg, int len, int64_t sig_start, ...) {
+ if (sig_start < 10123)
+ printf("%s\n", msg+len);
+ va_list v;
+ va_start(v, sig_start);
+ if (sig_start > 1413)
+ printf("%d\n", va_arg(v, int));
+ else
+ printf("nada\n");
+ va_end(v);
+ return len*sig_start*(msg[0]+1);
+ }
+
+ int main(int argc, char **argv)
+ {
+ for (int i = 0; i < argc; i++) {
+ int64_t x;
+ if (i % 123123 == 0)
+ x = ccv_cache_generate_signature(argv[i], i+2, (int64_t)argc*argc, 54.111);
+ else
+ x = ccv_cache_generate_signature(argv[i], i+2, (int64_t)argc*argc, 13);
+ printf("%lld\n", x);
+ }
+ };
+ \ No newline at end of file
diff --git a/tests/core/test_i64_varargs.out b/tests/core/test_i64_varargs.out
new file mode 100644
index 00000000..8c7b7843
--- /dev/null
+++ b/tests/core/test_i64_varargs.out
@@ -0,0 +1,12 @@
+in/this.program
+nada
+1536
+a
+nada
+5760
+fl
+nada
+6592
+sdfasdfasdf
+nada
+7840
diff --git a/tests/core/test_i64_zextneg.in b/tests/core/test_i64_zextneg.in
new file mode 100644
index 00000000..3f77131d
--- /dev/null
+++ b/tests/core/test_i64_zextneg.in
@@ -0,0 +1,16 @@
+
+ #include <stdint.h>
+ #include <stdio.h>
+
+ int main(int argc, char *argv[])
+ {
+ uint8_t byte = 0x80;
+ uint16_t two = byte;
+ uint32_t four = byte;
+ uint64_t eight = byte;
+
+ printf("value: %d,%d,%d,%lld.\n", byte, two, four, eight);
+
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_i64_zextneg.out b/tests/core/test_i64_zextneg.out
new file mode 100644
index 00000000..e2d9fd34
--- /dev/null
+++ b/tests/core/test_i64_zextneg.out
@@ -0,0 +1 @@
+value: 128,128,128,128. \ No newline at end of file
diff --git a/tests/core/test_if.in b/tests/core/test_if.in
new file mode 100644
index 00000000..20ed3a01
--- /dev/null
+++ b/tests/core/test_if.in
@@ -0,0 +1,11 @@
+
+ #include <stdio.h>
+ int main()
+ {
+ int x = 5;
+ if (x > 3) {
+ printf("*yes*\n");
+ }
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_if.out b/tests/core/test_if.out
new file mode 100644
index 00000000..f74b0639
--- /dev/null
+++ b/tests/core/test_if.out
@@ -0,0 +1 @@
+*yes* \ No newline at end of file
diff --git a/tests/core/test_if_else.in b/tests/core/test_if_else.in
new file mode 100644
index 00000000..03b2bfa6
--- /dev/null
+++ b/tests/core/test_if_else.in
@@ -0,0 +1,13 @@
+
+ #include <stdio.h>
+ int main()
+ {
+ int x = 5;
+ if (x > 10) {
+ printf("*yes*\n");
+ } else {
+ printf("*no*\n");
+ }
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_if_else.out b/tests/core/test_if_else.out
new file mode 100644
index 00000000..208ac5ec
--- /dev/null
+++ b/tests/core/test_if_else.out
@@ -0,0 +1 @@
+*no* \ No newline at end of file
diff --git a/tests/core/test_indirectbr.in b/tests/core/test_indirectbr.in
new file mode 100644
index 00000000..bdc66b53
--- /dev/null
+++ b/tests/core/test_indirectbr.in
@@ -0,0 +1,21 @@
+
+ #include <stdio.h>
+ int main(void) {
+ const void *addrs[2] = { &&FOO, &&BAR };
+
+ // confuse the optimizer so it doesn't hardcode the jump and avoid generating an |indirectbr| instruction
+ int which = 0;
+ for (int x = 0; x < 1000; x++) which = (which + x*x) % 7;
+ which = (which % 2) + 1;
+
+ goto *addrs[which];
+
+ FOO:
+ printf("bad\n");
+ return 0;
+ BAR:
+ printf("good\n");
+ const void *addr = &&FOO;
+ goto *addr;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_indirectbr.out b/tests/core/test_indirectbr.out
new file mode 100644
index 00000000..5364b418
--- /dev/null
+++ b/tests/core/test_indirectbr.out
@@ -0,0 +1,2 @@
+good
+bad \ No newline at end of file
diff --git a/tests/core/test_indirectbr_many.in b/tests/core/test_indirectbr_many.in
new file mode 100644
index 00000000..769c331f
--- /dev/null
+++ b/tests/core/test_indirectbr_many.in
@@ -0,0 +1,1510 @@
+
+ #include <stdio.h>
+ int main(int argc, char **argv) {
+ printf("\n");
+ const void *addrs[] = { &&B0, &&B1, &&B2, &&B3, &&B4, &&B5, &&B6, &&B7, &&B8, &&B9, &&B10, &&B11, &&B12, &&B13, &&B14, &&B15, &&B16, &&B17, &&B18, &&B19, &&B20, &&B21, &&B22, &&B23, &&B24, &&B25, &&B26, &&B27, &&B28, &&B29, &&B30, &&B31, &&B32, &&B33, &&B34, &&B35, &&B36, &&B37, &&B38, &&B39, &&B40, &&B41, &&B42, &&B43, &&B44, &&B45, &&B46, &&B47, &&B48, &&B49, &&B50, &&B51, &&B52, &&B53, &&B54, &&B55, &&B56, &&B57, &&B58, &&B59, &&B60, &&B61, &&B62, &&B63, &&B64, &&B65, &&B66, &&B67, &&B68, &&B69, &&B70, &&B71, &&B72, &&B73, &&B74, &&B75, &&B76, &&B77, &&B78, &&B79, &&B80, &&B81, &&B82, &&B83, &&B84, &&B85, &&B86, &&B87, &&B88, &&B89, &&B90, &&B91, &&B92, &&B93, &&B94, &&B95, &&B96, &&B97, &&B98, &&B99, &&B100, &&B101, &&B102, &&B103, &&B104, &&B105, &&B106, &&B107, &&B108, &&B109, &&B110, &&B111, &&B112, &&B113, &&B114, &&B115, &&B116, &&B117, &&B118, &&B119, &&B120, &&B121, &&B122, &&B123, &&B124, &&B125, &&B126, &&B127, &&B128, &&B129, &&B130, &&B131, &&B132, &&B133, &&B134, &&B135, &&B136, &&B137, &&B138, &&B139, &&B140, &&B141, &&B142, &&B143, &&B144, &&B145, &&B146, &&B147, &&B148, &&B149, &&B150, &&B151, &&B152, &&B153, &&B154, &&B155, &&B156, &&B157, &&B158, &&B159, &&B160, &&B161, &&B162, &&B163, &&B164, &&B165, &&B166, &&B167, &&B168, &&B169, &&B170, &&B171, &&B172, &&B173, &&B174, &&B175, &&B176, &&B177, &&B178, &&B179, &&B180, &&B181, &&B182, &&B183, &&B184, &&B185, &&B186, &&B187, &&B188, &&B189, &&B190, &&B191, &&B192, &&B193, &&B194, &&B195, &&B196, &&B197, &&B198, &&B199, &&B200, &&B201, &&B202, &&B203, &&B204, &&B205, &&B206, &&B207, &&B208, &&B209, &&B210, &&B211, &&B212, &&B213, &&B214, &&B215, &&B216, &&B217, &&B218, &&B219, &&B220, &&B221, &&B222, &&B223, &&B224, &&B225, &&B226, &&B227, &&B228, &&B229, &&B230, &&B231, &&B232, &&B233, &&B234, &&B235, &&B236, &&B237, &&B238, &&B239, &&B240, &&B241, &&B242, &&B243, &&B244, &&B245, &&B246, &&B247, &&B248, &&B249, &&B250, &&B251, &&B252, &&B253, &&B254, &&B255, &&B256, &&B257, &&B258, &&B259, &&B260, &&B261, &&B262, &&B263, &&B264, &&B265, &&B266, &&B267, &&B268, &&B269, &&B270, &&B271, &&B272, &&B273, &&B274, &&B275, &&B276, &&B277, &&B278, &&B279, &&B280, &&B281, &&B282, &&B283, &&B284, &&B285, &&B286, &&B287, &&B288, &&B289, &&B290, &&B291, &&B292, &&B293, &&B294, &&B295, &&B296, &&B297, &&B298, &&B299, &&B300, &&B301, &&B302, &&B303, &&B304, &&B305, &&B306, &&B307, &&B308, &&B309, &&B310, &&B311, &&B312, &&B313, &&B314, &&B315, &&B316, &&B317, &&B318, &&B319, &&B320, &&B321, &&B322, &&B323, &&B324, &&B325, &&B326, &&B327, &&B328, &&B329, &&B330, &&B331, &&B332, &&B333, &&B334, &&B335, &&B336, &&B337, &&B338, &&B339, &&B340, &&B341, &&B342, &&B343, &&B344, &&B345, &&B346, &&B347, &&B348, &&B349, &&B350, &&B351, &&B352, &&B353, &&B354, &&B355, &&B356, &&B357, &&B358, &&B359, &&B360, &&B361, &&B362, &&B363, &&B364, &&B365, &&B366, &&B367, &&B368, &&B369, &&B370, &&B371, &&B372, &&B373, &&B374, &&B375, &&B376, &&B377, &&B378, &&B379, &&B380, &&B381, &&B382, &&B383, &&B384, &&B385, &&B386, &&B387, &&B388, &&B389, &&B390, &&B391, &&B392, &&B393, &&B394, &&B395, &&B396, &&B397, &&B398, &&B399, &&B400, &&B401, &&B402, &&B403, &&B404, &&B405, &&B406, &&B407, &&B408, &&B409, &&B410, &&B411, &&B412, &&B413, &&B414, &&B415, &&B416, &&B417, &&B418, &&B419, &&B420, &&B421, &&B422, &&B423, &&B424, &&B425, &&B426, &&B427, &&B428, &&B429, &&B430, &&B431, &&B432, &&B433, &&B434, &&B435, &&B436, &&B437, &&B438, &&B439, &&B440, &&B441, &&B442, &&B443, &&B444, &&B445, &&B446, &&B447, &&B448, &&B449, &&B450, &&B451, &&B452, &&B453, &&B454, &&B455, &&B456, &&B457, &&B458, &&B459, &&B460, &&B461, &&B462, &&B463, &&B464, &&B465, &&B466, &&B467, &&B468, &&B469, &&B470, &&B471, &&B472, &&B473, &&B474, &&B475, &&B476, &&B477, &&B478, &&B479, &&B480, &&B481, &&B482, &&B483, &&B484, &&B485, &&B486, &&B487, &&B488, &&B489, &&B490, &&B491, &&B492, &&B493, &&B494, &&B495, &&B496, &&B497, &&B498, &&B499, &&B500, &&B501, &&B502, &&B503, &&B504, &&B505, &&B506, &&B507, &&B508, &&B509, &&B510, &&B511, &&B512, &&B513, &&B514, &&B515, &&B516, &&B517, &&B518, &&B519, &&B520, &&B521, &&B522, &&B523, &&B524, &&B525, &&B526, &&B527, &&B528, &&B529, &&B530, &&B531, &&B532, &&B533, &&B534, &&B535, &&B536, &&B537, &&B538, &&B539, &&B540, &&B541, &&B542, &&B543, &&B544, &&B545, &&B546, &&B547, &&B548, &&B549, &&B550, &&B551, &&B552, &&B553, &&B554, &&B555, &&B556, &&B557, &&B558, &&B559, &&B560, &&B561, &&B562, &&B563, &&B564, &&B565, &&B566, &&B567, &&B568, &&B569, &&B570, &&B571, &&B572, &&B573, &&B574, &&B575, &&B576, &&B577, &&B578, &&B579, &&B580, &&B581, &&B582, &&B583, &&B584, &&B585, &&B586, &&B587, &&B588, &&B589, &&B590, &&B591, &&B592, &&B593, &&B594, &&B595, &&B596, &&B597, &&B598, &&B599, &&B600, &&B601, &&B602, &&B603, &&B604, &&B605, &&B606, &&B607, &&B608, &&B609, &&B610, &&B611, &&B612, &&B613, &&B614, &&B615, &&B616, &&B617, &&B618, &&B619, &&B620, &&B621, &&B622, &&B623, &&B624, &&B625, &&B626, &&B627, &&B628, &&B629, &&B630, &&B631, &&B632, &&B633, &&B634, &&B635, &&B636, &&B637, &&B638, &&B639, &&B640, &&B641, &&B642, &&B643, &&B644, &&B645, &&B646, &&B647, &&B648, &&B649, &&B650, &&B651, &&B652, &&B653, &&B654, &&B655, &&B656, &&B657, &&B658, &&B659, &&B660, &&B661, &&B662, &&B663, &&B664, &&B665, &&B666, &&B667, &&B668, &&B669, &&B670, &&B671, &&B672, &&B673, &&B674, &&B675, &&B676, &&B677, &&B678, &&B679, &&B680, &&B681, &&B682, &&B683, &&B684, &&B685, &&B686, &&B687, &&B688, &&B689, &&B690, &&B691, &&B692, &&B693, &&B694, &&B695, &&B696, &&B697, &&B698, &&B699, &&B700, &&B701, &&B702, &&B703, &&B704, &&B705, &&B706, &&B707, &&B708, &&B709, &&B710, &&B711, &&B712, &&B713, &&B714, &&B715, &&B716, &&B717, &&B718, &&B719, &&B720, &&B721, &&B722, &&B723, &&B724, &&B725, &&B726, &&B727, &&B728, &&B729, &&B730, &&B731, &&B732, &&B733, &&B734, &&B735, &&B736, &&B737, &&B738, &&B739, &&B740, &&B741, &&B742, &&B743, &&B744, &&B745, &&B746, &&B747, &&B748, &&B749, &&B750, &&B751, &&B752, &&B753, &&B754, &&B755, &&B756, &&B757, &&B758, &&B759, &&B760, &&B761, &&B762, &&B763, &&B764, &&B765, &&B766, &&B767, &&B768, &&B769, &&B770, &&B771, &&B772, &&B773, &&B774, &&B775, &&B776, &&B777, &&B778, &&B779, &&B780, &&B781, &&B782, &&B783, &&B784, &&B785, &&B786, &&B787, &&B788, &&B789, &&B790, &&B791, &&B792, &&B793, &&B794, &&B795, &&B796, &&B797, &&B798, &&B799, &&B800, &&B801, &&B802, &&B803, &&B804, &&B805, &&B806, &&B807, &&B808, &&B809, &&B810, &&B811, &&B812, &&B813, &&B814, &&B815, &&B816, &&B817, &&B818, &&B819, &&B820, &&B821, &&B822, &&B823, &&B824, &&B825, &&B826, &&B827, &&B828, &&B829, &&B830, &&B831, &&B832, &&B833, &&B834, &&B835, &&B836, &&B837, &&B838, &&B839, &&B840, &&B841, &&B842, &&B843, &&B844, &&B845, &&B846, &&B847, &&B848, &&B849, &&B850, &&B851, &&B852, &&B853, &&B854, &&B855, &&B856, &&B857, &&B858, &&B859, &&B860, &&B861, &&B862, &&B863, &&B864, &&B865, &&B866, &&B867, &&B868, &&B869, &&B870, &&B871, &&B872, &&B873, &&B874, &&B875, &&B876, &&B877, &&B878, &&B879, &&B880, &&B881, &&B882, &&B883, &&B884, &&B885, &&B886, &&B887, &&B888, &&B889, &&B890, &&B891, &&B892, &&B893, &&B894, &&B895, &&B896, &&B897, &&B898, &&B899, &&B900, &&B901, &&B902, &&B903, &&B904, &&B905, &&B906, &&B907, &&B908, &&B909, &&B910, &&B911, &&B912, &&B913, &&B914, &&B915, &&B916, &&B917, &&B918, &&B919, &&B920, &&B921, &&B922, &&B923, &&B924, &&B925, &&B926, &&B927, &&B928, &&B929, &&B930, &&B931, &&B932, &&B933, &&B934, &&B935, &&B936, &&B937, &&B938, &&B939, &&B940, &&B941, &&B942, &&B943, &&B944, &&B945, &&B946, &&B947, &&B948, &&B949, &&B950, &&B951, &&B952, &&B953, &&B954, &&B955, &&B956, &&B957, &&B958, &&B959, &&B960, &&B961, &&B962, &&B963, &&B964, &&B965, &&B966, &&B967, &&B968, &&B969, &&B970, &&B971, &&B972, &&B973, &&B974, &&B975, &&B976, &&B977, &&B978, &&B979, &&B980, &&B981, &&B982, &&B983, &&B984, &&B985, &&B986, &&B987, &&B988, &&B989, &&B990, &&B991, &&B992, &&B993, &&B994, &&B995, &&B996, &&B997, &&B998, &&B999, &&B1000, &&B1001, &&B1002, &&B1003, &&B1004, &&B1005, &&B1006, &&B1007, &&B1008, &&B1009, &&B1010, &&B1011, &&B1012, &&B1013, &&B1014, &&B1015, &&B1016, &&B1017, &&B1018, &&B1019, &&B1020, &&B1021, &&B1022, &&B1023, &&B1024, &&B1025, &&B1026, &&B1027, &&B1028, &&B1029, &&B1030, &&B1031, &&B1032, &&B1033, &&B1034, &&B1035, &&B1036, &&B1037, &&B1038, &&B1039, &&B1040, &&B1041, &&B1042, &&B1043, &&B1044, &&B1045, &&B1046, &&B1047, &&B1048, &&B1049, &&B1050, &&B1051, &&B1052, &&B1053, &&B1054, &&B1055, &&B1056, &&B1057, &&B1058, &&B1059, &&B1060, &&B1061, &&B1062, &&B1063, &&B1064, &&B1065, &&B1066, &&B1067, &&B1068, &&B1069, &&B1070, &&B1071, &&B1072, &&B1073, &&B1074, &&B1075, &&B1076, &&B1077, &&B1078, &&B1079, &&B1080, &&B1081, &&B1082, &&B1083, &&B1084, &&B1085, &&B1086, &&B1087, &&B1088, &&B1089, &&B1090, &&B1091, &&B1092, &&B1093, &&B1094, &&B1095, &&B1096, &&B1097, &&B1098, &&B1099, &&B1100, &&B1101, &&B1102, &&B1103, &&B1104, &&B1105, &&B1106, &&B1107, &&B1108, &&B1109, &&B1110, &&B1111, &&B1112, &&B1113, &&B1114, &&B1115, &&B1116, &&B1117, &&B1118, &&B1119, &&B1120, &&B1121, &&B1122, &&B1123, &&B1124, &&B1125, &&B1126, &&B1127, &&B1128, &&B1129, &&B1130, &&B1131, &&B1132, &&B1133, &&B1134, &&B1135, &&B1136, &&B1137, &&B1138, &&B1139, &&B1140, &&B1141, &&B1142, &&B1143, &&B1144, &&B1145, &&B1146, &&B1147, &&B1148, &&B1149, &&B1150, &&B1151, &&B1152, &&B1153, &&B1154, &&B1155, &&B1156, &&B1157, &&B1158, &&B1159, &&B1160, &&B1161, &&B1162, &&B1163, &&B1164, &&B1165, &&B1166, &&B1167, &&B1168, &&B1169, &&B1170, &&B1171, &&B1172, &&B1173, &&B1174, &&B1175, &&B1176, &&B1177, &&B1178, &&B1179, &&B1180, &&B1181, &&B1182, &&B1183, &&B1184, &&B1185, &&B1186, &&B1187, &&B1188, &&B1189, &&B1190, &&B1191, &&B1192, &&B1193, &&B1194, &&B1195, &&B1196, &&B1197, &&B1198, &&B1199, &&B1200, &&B1201, &&B1202, &&B1203, &&B1204, &&B1205, &&B1206, &&B1207, &&B1208, &&B1209, &&B1210, &&B1211, &&B1212, &&B1213, &&B1214, &&B1215, &&B1216, &&B1217, &&B1218, &&B1219, &&B1220, &&B1221, &&B1222, &&B1223, &&B1224, &&B1225, &&B1226, &&B1227, &&B1228, &&B1229, &&B1230, &&B1231, &&B1232, &&B1233, &&B1234, &&B1235, &&B1236, &&B1237, &&B1238, &&B1239, &&B1240, &&B1241, &&B1242, &&B1243, &&B1244, &&B1245, &&B1246, &&B1247, &&B1248, &&B1249, &&B1250, &&B1251, &&B1252, &&B1253, &&B1254, &&B1255, &&B1256, &&B1257, &&B1258, &&B1259, &&B1260, &&B1261, &&B1262, &&B1263, &&B1264, &&B1265, &&B1266, &&B1267, &&B1268, &&B1269, &&B1270, &&B1271, &&B1272, &&B1273, &&B1274, &&B1275, &&B1276, &&B1277, &&B1278, &&B1279, &&B1280, &&B1281, &&B1282, &&B1283, &&B1284, &&B1285, &&B1286, &&B1287, &&B1288, &&B1289, &&B1290, &&B1291, &&B1292, &&B1293, &&B1294, &&B1295, &&B1296, &&B1297, &&B1298, &&B1299, &&B1300, &&B1301, &&B1302, &&B1303, &&B1304, &&B1305, &&B1306, &&B1307, &&B1308, &&B1309, &&B1310, &&B1311, &&B1312, &&B1313, &&B1314, &&B1315, &&B1316, &&B1317, &&B1318, &&B1319, &&B1320, &&B1321, &&B1322, &&B1323, &&B1324, &&B1325, &&B1326, &&B1327, &&B1328, &&B1329, &&B1330, &&B1331, &&B1332, &&B1333, &&B1334, &&B1335, &&B1336, &&B1337, &&B1338, &&B1339, &&B1340, &&B1341, &&B1342, &&B1343, &&B1344, &&B1345, &&B1346, &&B1347, &&B1348, &&B1349, &&B1350, &&B1351, &&B1352, &&B1353, &&B1354, &&B1355, &&B1356, &&B1357, &&B1358, &&B1359, &&B1360, &&B1361, &&B1362, &&B1363, &&B1364, &&B1365, &&B1366, &&B1367, &&B1368, &&B1369, &&B1370, &&B1371, &&B1372, &&B1373, &&B1374, &&B1375, &&B1376, &&B1377, &&B1378, &&B1379, &&B1380, &&B1381, &&B1382, &&B1383, &&B1384, &&B1385, &&B1386, &&B1387, &&B1388, &&B1389, &&B1390, &&B1391, &&B1392, &&B1393, &&B1394, &&B1395, &&B1396, &&B1397, &&B1398, &&B1399, &&B1400, &&B1401, &&B1402, &&B1403, &&B1404, &&B1405, &&B1406, &&B1407, &&B1408, &&B1409, &&B1410, &&B1411, &&B1412, &&B1413, &&B1414, &&B1415, &&B1416, &&B1417, &&B1418, &&B1419, &&B1420, &&B1421, &&B1422, &&B1423, &&B1424, &&B1425, &&B1426, &&B1427, &&B1428, &&B1429, &&B1430, &&B1431, &&B1432, &&B1433, &&B1434, &&B1435, &&B1436, &&B1437, &&B1438, &&B1439, &&B1440, &&B1441, &&B1442, &&B1443, &&B1444, &&B1445, &&B1446, &&B1447, &&B1448, &&B1449, &&B1450, &&B1451, &&B1452, &&B1453, &&B1454, &&B1455, &&B1456, &&B1457, &&B1458, &&B1459, &&B1460, &&B1461, &&B1462, &&B1463, &&B1464, &&B1465, &&B1466, &&B1467, &&B1468, &&B1469, &&B1470, &&B1471, &&B1472, &&B1473, &&B1474, &&B1475, &&B1476, &&B1477, &&B1478, &&B1479, &&B1480, &&B1481, &&B1482, &&B1483, &&B1484, &&B1485, &&B1486, &&B1487, &&B1488, &&B1489, &&B1490, &&B1491, &&B1492, &&B1493, &&B1494, &&B1495, &&B1496, &&B1497, &&B1498, &&B1499 };
+ goto *addrs[argc*argc + 1000];
+
+B0: printf("0\n"); return 0;
+B1: printf("1\n"); return 0;
+B2: printf("2\n"); return 0;
+B3: printf("3\n"); return 0;
+B4: printf("4\n"); return 0;
+B5: printf("5\n"); return 0;
+B6: printf("6\n"); return 0;
+B7: printf("7\n"); return 0;
+B8: printf("8\n"); return 0;
+B9: printf("9\n"); return 0;
+B10: printf("10\n"); return 0;
+B11: printf("11\n"); return 0;
+B12: printf("12\n"); return 0;
+B13: printf("13\n"); return 0;
+B14: printf("14\n"); return 0;
+B15: printf("15\n"); return 0;
+B16: printf("16\n"); return 0;
+B17: printf("17\n"); return 0;
+B18: printf("18\n"); return 0;
+B19: printf("19\n"); return 0;
+B20: printf("20\n"); return 0;
+B21: printf("21\n"); return 0;
+B22: printf("22\n"); return 0;
+B23: printf("23\n"); return 0;
+B24: printf("24\n"); return 0;
+B25: printf("25\n"); return 0;
+B26: printf("26\n"); return 0;
+B27: printf("27\n"); return 0;
+B28: printf("28\n"); return 0;
+B29: printf("29\n"); return 0;
+B30: printf("30\n"); return 0;
+B31: printf("31\n"); return 0;
+B32: printf("32\n"); return 0;
+B33: printf("33\n"); return 0;
+B34: printf("34\n"); return 0;
+B35: printf("35\n"); return 0;
+B36: printf("36\n"); return 0;
+B37: printf("37\n"); return 0;
+B38: printf("38\n"); return 0;
+B39: printf("39\n"); return 0;
+B40: printf("40\n"); return 0;
+B41: printf("41\n"); return 0;
+B42: printf("42\n"); return 0;
+B43: printf("43\n"); return 0;
+B44: printf("44\n"); return 0;
+B45: printf("45\n"); return 0;
+B46: printf("46\n"); return 0;
+B47: printf("47\n"); return 0;
+B48: printf("48\n"); return 0;
+B49: printf("49\n"); return 0;
+B50: printf("50\n"); return 0;
+B51: printf("51\n"); return 0;
+B52: printf("52\n"); return 0;
+B53: printf("53\n"); return 0;
+B54: printf("54\n"); return 0;
+B55: printf("55\n"); return 0;
+B56: printf("56\n"); return 0;
+B57: printf("57\n"); return 0;
+B58: printf("58\n"); return 0;
+B59: printf("59\n"); return 0;
+B60: printf("60\n"); return 0;
+B61: printf("61\n"); return 0;
+B62: printf("62\n"); return 0;
+B63: printf("63\n"); return 0;
+B64: printf("64\n"); return 0;
+B65: printf("65\n"); return 0;
+B66: printf("66\n"); return 0;
+B67: printf("67\n"); return 0;
+B68: printf("68\n"); return 0;
+B69: printf("69\n"); return 0;
+B70: printf("70\n"); return 0;
+B71: printf("71\n"); return 0;
+B72: printf("72\n"); return 0;
+B73: printf("73\n"); return 0;
+B74: printf("74\n"); return 0;
+B75: printf("75\n"); return 0;
+B76: printf("76\n"); return 0;
+B77: printf("77\n"); return 0;
+B78: printf("78\n"); return 0;
+B79: printf("79\n"); return 0;
+B80: printf("80\n"); return 0;
+B81: printf("81\n"); return 0;
+B82: printf("82\n"); return 0;
+B83: printf("83\n"); return 0;
+B84: printf("84\n"); return 0;
+B85: printf("85\n"); return 0;
+B86: printf("86\n"); return 0;
+B87: printf("87\n"); return 0;
+B88: printf("88\n"); return 0;
+B89: printf("89\n"); return 0;
+B90: printf("90\n"); return 0;
+B91: printf("91\n"); return 0;
+B92: printf("92\n"); return 0;
+B93: printf("93\n"); return 0;
+B94: printf("94\n"); return 0;
+B95: printf("95\n"); return 0;
+B96: printf("96\n"); return 0;
+B97: printf("97\n"); return 0;
+B98: printf("98\n"); return 0;
+B99: printf("99\n"); return 0;
+B100: printf("100\n"); return 0;
+B101: printf("101\n"); return 0;
+B102: printf("102\n"); return 0;
+B103: printf("103\n"); return 0;
+B104: printf("104\n"); return 0;
+B105: printf("105\n"); return 0;
+B106: printf("106\n"); return 0;
+B107: printf("107\n"); return 0;
+B108: printf("108\n"); return 0;
+B109: printf("109\n"); return 0;
+B110: printf("110\n"); return 0;
+B111: printf("111\n"); return 0;
+B112: printf("112\n"); return 0;
+B113: printf("113\n"); return 0;
+B114: printf("114\n"); return 0;
+B115: printf("115\n"); return 0;
+B116: printf("116\n"); return 0;
+B117: printf("117\n"); return 0;
+B118: printf("118\n"); return 0;
+B119: printf("119\n"); return 0;
+B120: printf("120\n"); return 0;
+B121: printf("121\n"); return 0;
+B122: printf("122\n"); return 0;
+B123: printf("123\n"); return 0;
+B124: printf("124\n"); return 0;
+B125: printf("125\n"); return 0;
+B126: printf("126\n"); return 0;
+B127: printf("127\n"); return 0;
+B128: printf("128\n"); return 0;
+B129: printf("129\n"); return 0;
+B130: printf("130\n"); return 0;
+B131: printf("131\n"); return 0;
+B132: printf("132\n"); return 0;
+B133: printf("133\n"); return 0;
+B134: printf("134\n"); return 0;
+B135: printf("135\n"); return 0;
+B136: printf("136\n"); return 0;
+B137: printf("137\n"); return 0;
+B138: printf("138\n"); return 0;
+B139: printf("139\n"); return 0;
+B140: printf("140\n"); return 0;
+B141: printf("141\n"); return 0;
+B142: printf("142\n"); return 0;
+B143: printf("143\n"); return 0;
+B144: printf("144\n"); return 0;
+B145: printf("145\n"); return 0;
+B146: printf("146\n"); return 0;
+B147: printf("147\n"); return 0;
+B148: printf("148\n"); return 0;
+B149: printf("149\n"); return 0;
+B150: printf("150\n"); return 0;
+B151: printf("151\n"); return 0;
+B152: printf("152\n"); return 0;
+B153: printf("153\n"); return 0;
+B154: printf("154\n"); return 0;
+B155: printf("155\n"); return 0;
+B156: printf("156\n"); return 0;
+B157: printf("157\n"); return 0;
+B158: printf("158\n"); return 0;
+B159: printf("159\n"); return 0;
+B160: printf("160\n"); return 0;
+B161: printf("161\n"); return 0;
+B162: printf("162\n"); return 0;
+B163: printf("163\n"); return 0;
+B164: printf("164\n"); return 0;
+B165: printf("165\n"); return 0;
+B166: printf("166\n"); return 0;
+B167: printf("167\n"); return 0;
+B168: printf("168\n"); return 0;
+B169: printf("169\n"); return 0;
+B170: printf("170\n"); return 0;
+B171: printf("171\n"); return 0;
+B172: printf("172\n"); return 0;
+B173: printf("173\n"); return 0;
+B174: printf("174\n"); return 0;
+B175: printf("175\n"); return 0;
+B176: printf("176\n"); return 0;
+B177: printf("177\n"); return 0;
+B178: printf("178\n"); return 0;
+B179: printf("179\n"); return 0;
+B180: printf("180\n"); return 0;
+B181: printf("181\n"); return 0;
+B182: printf("182\n"); return 0;
+B183: printf("183\n"); return 0;
+B184: printf("184\n"); return 0;
+B185: printf("185\n"); return 0;
+B186: printf("186\n"); return 0;
+B187: printf("187\n"); return 0;
+B188: printf("188\n"); return 0;
+B189: printf("189\n"); return 0;
+B190: printf("190\n"); return 0;
+B191: printf("191\n"); return 0;
+B192: printf("192\n"); return 0;
+B193: printf("193\n"); return 0;
+B194: printf("194\n"); return 0;
+B195: printf("195\n"); return 0;
+B196: printf("196\n"); return 0;
+B197: printf("197\n"); return 0;
+B198: printf("198\n"); return 0;
+B199: printf("199\n"); return 0;
+B200: printf("200\n"); return 0;
+B201: printf("201\n"); return 0;
+B202: printf("202\n"); return 0;
+B203: printf("203\n"); return 0;
+B204: printf("204\n"); return 0;
+B205: printf("205\n"); return 0;
+B206: printf("206\n"); return 0;
+B207: printf("207\n"); return 0;
+B208: printf("208\n"); return 0;
+B209: printf("209\n"); return 0;
+B210: printf("210\n"); return 0;
+B211: printf("211\n"); return 0;
+B212: printf("212\n"); return 0;
+B213: printf("213\n"); return 0;
+B214: printf("214\n"); return 0;
+B215: printf("215\n"); return 0;
+B216: printf("216\n"); return 0;
+B217: printf("217\n"); return 0;
+B218: printf("218\n"); return 0;
+B219: printf("219\n"); return 0;
+B220: printf("220\n"); return 0;
+B221: printf("221\n"); return 0;
+B222: printf("222\n"); return 0;
+B223: printf("223\n"); return 0;
+B224: printf("224\n"); return 0;
+B225: printf("225\n"); return 0;
+B226: printf("226\n"); return 0;
+B227: printf("227\n"); return 0;
+B228: printf("228\n"); return 0;
+B229: printf("229\n"); return 0;
+B230: printf("230\n"); return 0;
+B231: printf("231\n"); return 0;
+B232: printf("232\n"); return 0;
+B233: printf("233\n"); return 0;
+B234: printf("234\n"); return 0;
+B235: printf("235\n"); return 0;
+B236: printf("236\n"); return 0;
+B237: printf("237\n"); return 0;
+B238: printf("238\n"); return 0;
+B239: printf("239\n"); return 0;
+B240: printf("240\n"); return 0;
+B241: printf("241\n"); return 0;
+B242: printf("242\n"); return 0;
+B243: printf("243\n"); return 0;
+B244: printf("244\n"); return 0;
+B245: printf("245\n"); return 0;
+B246: printf("246\n"); return 0;
+B247: printf("247\n"); return 0;
+B248: printf("248\n"); return 0;
+B249: printf("249\n"); return 0;
+B250: printf("250\n"); return 0;
+B251: printf("251\n"); return 0;
+B252: printf("252\n"); return 0;
+B253: printf("253\n"); return 0;
+B254: printf("254\n"); return 0;
+B255: printf("255\n"); return 0;
+B256: printf("256\n"); return 0;
+B257: printf("257\n"); return 0;
+B258: printf("258\n"); return 0;
+B259: printf("259\n"); return 0;
+B260: printf("260\n"); return 0;
+B261: printf("261\n"); return 0;
+B262: printf("262\n"); return 0;
+B263: printf("263\n"); return 0;
+B264: printf("264\n"); return 0;
+B265: printf("265\n"); return 0;
+B266: printf("266\n"); return 0;
+B267: printf("267\n"); return 0;
+B268: printf("268\n"); return 0;
+B269: printf("269\n"); return 0;
+B270: printf("270\n"); return 0;
+B271: printf("271\n"); return 0;
+B272: printf("272\n"); return 0;
+B273: printf("273\n"); return 0;
+B274: printf("274\n"); return 0;
+B275: printf("275\n"); return 0;
+B276: printf("276\n"); return 0;
+B277: printf("277\n"); return 0;
+B278: printf("278\n"); return 0;
+B279: printf("279\n"); return 0;
+B280: printf("280\n"); return 0;
+B281: printf("281\n"); return 0;
+B282: printf("282\n"); return 0;
+B283: printf("283\n"); return 0;
+B284: printf("284\n"); return 0;
+B285: printf("285\n"); return 0;
+B286: printf("286\n"); return 0;
+B287: printf("287\n"); return 0;
+B288: printf("288\n"); return 0;
+B289: printf("289\n"); return 0;
+B290: printf("290\n"); return 0;
+B291: printf("291\n"); return 0;
+B292: printf("292\n"); return 0;
+B293: printf("293\n"); return 0;
+B294: printf("294\n"); return 0;
+B295: printf("295\n"); return 0;
+B296: printf("296\n"); return 0;
+B297: printf("297\n"); return 0;
+B298: printf("298\n"); return 0;
+B299: printf("299\n"); return 0;
+B300: printf("300\n"); return 0;
+B301: printf("301\n"); return 0;
+B302: printf("302\n"); return 0;
+B303: printf("303\n"); return 0;
+B304: printf("304\n"); return 0;
+B305: printf("305\n"); return 0;
+B306: printf("306\n"); return 0;
+B307: printf("307\n"); return 0;
+B308: printf("308\n"); return 0;
+B309: printf("309\n"); return 0;
+B310: printf("310\n"); return 0;
+B311: printf("311\n"); return 0;
+B312: printf("312\n"); return 0;
+B313: printf("313\n"); return 0;
+B314: printf("314\n"); return 0;
+B315: printf("315\n"); return 0;
+B316: printf("316\n"); return 0;
+B317: printf("317\n"); return 0;
+B318: printf("318\n"); return 0;
+B319: printf("319\n"); return 0;
+B320: printf("320\n"); return 0;
+B321: printf("321\n"); return 0;
+B322: printf("322\n"); return 0;
+B323: printf("323\n"); return 0;
+B324: printf("324\n"); return 0;
+B325: printf("325\n"); return 0;
+B326: printf("326\n"); return 0;
+B327: printf("327\n"); return 0;
+B328: printf("328\n"); return 0;
+B329: printf("329\n"); return 0;
+B330: printf("330\n"); return 0;
+B331: printf("331\n"); return 0;
+B332: printf("332\n"); return 0;
+B333: printf("333\n"); return 0;
+B334: printf("334\n"); return 0;
+B335: printf("335\n"); return 0;
+B336: printf("336\n"); return 0;
+B337: printf("337\n"); return 0;
+B338: printf("338\n"); return 0;
+B339: printf("339\n"); return 0;
+B340: printf("340\n"); return 0;
+B341: printf("341\n"); return 0;
+B342: printf("342\n"); return 0;
+B343: printf("343\n"); return 0;
+B344: printf("344\n"); return 0;
+B345: printf("345\n"); return 0;
+B346: printf("346\n"); return 0;
+B347: printf("347\n"); return 0;
+B348: printf("348\n"); return 0;
+B349: printf("349\n"); return 0;
+B350: printf("350\n"); return 0;
+B351: printf("351\n"); return 0;
+B352: printf("352\n"); return 0;
+B353: printf("353\n"); return 0;
+B354: printf("354\n"); return 0;
+B355: printf("355\n"); return 0;
+B356: printf("356\n"); return 0;
+B357: printf("357\n"); return 0;
+B358: printf("358\n"); return 0;
+B359: printf("359\n"); return 0;
+B360: printf("360\n"); return 0;
+B361: printf("361\n"); return 0;
+B362: printf("362\n"); return 0;
+B363: printf("363\n"); return 0;
+B364: printf("364\n"); return 0;
+B365: printf("365\n"); return 0;
+B366: printf("366\n"); return 0;
+B367: printf("367\n"); return 0;
+B368: printf("368\n"); return 0;
+B369: printf("369\n"); return 0;
+B370: printf("370\n"); return 0;
+B371: printf("371\n"); return 0;
+B372: printf("372\n"); return 0;
+B373: printf("373\n"); return 0;
+B374: printf("374\n"); return 0;
+B375: printf("375\n"); return 0;
+B376: printf("376\n"); return 0;
+B377: printf("377\n"); return 0;
+B378: printf("378\n"); return 0;
+B379: printf("379\n"); return 0;
+B380: printf("380\n"); return 0;
+B381: printf("381\n"); return 0;
+B382: printf("382\n"); return 0;
+B383: printf("383\n"); return 0;
+B384: printf("384\n"); return 0;
+B385: printf("385\n"); return 0;
+B386: printf("386\n"); return 0;
+B387: printf("387\n"); return 0;
+B388: printf("388\n"); return 0;
+B389: printf("389\n"); return 0;
+B390: printf("390\n"); return 0;
+B391: printf("391\n"); return 0;
+B392: printf("392\n"); return 0;
+B393: printf("393\n"); return 0;
+B394: printf("394\n"); return 0;
+B395: printf("395\n"); return 0;
+B396: printf("396\n"); return 0;
+B397: printf("397\n"); return 0;
+B398: printf("398\n"); return 0;
+B399: printf("399\n"); return 0;
+B400: printf("400\n"); return 0;
+B401: printf("401\n"); return 0;
+B402: printf("402\n"); return 0;
+B403: printf("403\n"); return 0;
+B404: printf("404\n"); return 0;
+B405: printf("405\n"); return 0;
+B406: printf("406\n"); return 0;
+B407: printf("407\n"); return 0;
+B408: printf("408\n"); return 0;
+B409: printf("409\n"); return 0;
+B410: printf("410\n"); return 0;
+B411: printf("411\n"); return 0;
+B412: printf("412\n"); return 0;
+B413: printf("413\n"); return 0;
+B414: printf("414\n"); return 0;
+B415: printf("415\n"); return 0;
+B416: printf("416\n"); return 0;
+B417: printf("417\n"); return 0;
+B418: printf("418\n"); return 0;
+B419: printf("419\n"); return 0;
+B420: printf("420\n"); return 0;
+B421: printf("421\n"); return 0;
+B422: printf("422\n"); return 0;
+B423: printf("423\n"); return 0;
+B424: printf("424\n"); return 0;
+B425: printf("425\n"); return 0;
+B426: printf("426\n"); return 0;
+B427: printf("427\n"); return 0;
+B428: printf("428\n"); return 0;
+B429: printf("429\n"); return 0;
+B430: printf("430\n"); return 0;
+B431: printf("431\n"); return 0;
+B432: printf("432\n"); return 0;
+B433: printf("433\n"); return 0;
+B434: printf("434\n"); return 0;
+B435: printf("435\n"); return 0;
+B436: printf("436\n"); return 0;
+B437: printf("437\n"); return 0;
+B438: printf("438\n"); return 0;
+B439: printf("439\n"); return 0;
+B440: printf("440\n"); return 0;
+B441: printf("441\n"); return 0;
+B442: printf("442\n"); return 0;
+B443: printf("443\n"); return 0;
+B444: printf("444\n"); return 0;
+B445: printf("445\n"); return 0;
+B446: printf("446\n"); return 0;
+B447: printf("447\n"); return 0;
+B448: printf("448\n"); return 0;
+B449: printf("449\n"); return 0;
+B450: printf("450\n"); return 0;
+B451: printf("451\n"); return 0;
+B452: printf("452\n"); return 0;
+B453: printf("453\n"); return 0;
+B454: printf("454\n"); return 0;
+B455: printf("455\n"); return 0;
+B456: printf("456\n"); return 0;
+B457: printf("457\n"); return 0;
+B458: printf("458\n"); return 0;
+B459: printf("459\n"); return 0;
+B460: printf("460\n"); return 0;
+B461: printf("461\n"); return 0;
+B462: printf("462\n"); return 0;
+B463: printf("463\n"); return 0;
+B464: printf("464\n"); return 0;
+B465: printf("465\n"); return 0;
+B466: printf("466\n"); return 0;
+B467: printf("467\n"); return 0;
+B468: printf("468\n"); return 0;
+B469: printf("469\n"); return 0;
+B470: printf("470\n"); return 0;
+B471: printf("471\n"); return 0;
+B472: printf("472\n"); return 0;
+B473: printf("473\n"); return 0;
+B474: printf("474\n"); return 0;
+B475: printf("475\n"); return 0;
+B476: printf("476\n"); return 0;
+B477: printf("477\n"); return 0;
+B478: printf("478\n"); return 0;
+B479: printf("479\n"); return 0;
+B480: printf("480\n"); return 0;
+B481: printf("481\n"); return 0;
+B482: printf("482\n"); return 0;
+B483: printf("483\n"); return 0;
+B484: printf("484\n"); return 0;
+B485: printf("485\n"); return 0;
+B486: printf("486\n"); return 0;
+B487: printf("487\n"); return 0;
+B488: printf("488\n"); return 0;
+B489: printf("489\n"); return 0;
+B490: printf("490\n"); return 0;
+B491: printf("491\n"); return 0;
+B492: printf("492\n"); return 0;
+B493: printf("493\n"); return 0;
+B494: printf("494\n"); return 0;
+B495: printf("495\n"); return 0;
+B496: printf("496\n"); return 0;
+B497: printf("497\n"); return 0;
+B498: printf("498\n"); return 0;
+B499: printf("499\n"); return 0;
+B500: printf("500\n"); return 0;
+B501: printf("501\n"); return 0;
+B502: printf("502\n"); return 0;
+B503: printf("503\n"); return 0;
+B504: printf("504\n"); return 0;
+B505: printf("505\n"); return 0;
+B506: printf("506\n"); return 0;
+B507: printf("507\n"); return 0;
+B508: printf("508\n"); return 0;
+B509: printf("509\n"); return 0;
+B510: printf("510\n"); return 0;
+B511: printf("511\n"); return 0;
+B512: printf("512\n"); return 0;
+B513: printf("513\n"); return 0;
+B514: printf("514\n"); return 0;
+B515: printf("515\n"); return 0;
+B516: printf("516\n"); return 0;
+B517: printf("517\n"); return 0;
+B518: printf("518\n"); return 0;
+B519: printf("519\n"); return 0;
+B520: printf("520\n"); return 0;
+B521: printf("521\n"); return 0;
+B522: printf("522\n"); return 0;
+B523: printf("523\n"); return 0;
+B524: printf("524\n"); return 0;
+B525: printf("525\n"); return 0;
+B526: printf("526\n"); return 0;
+B527: printf("527\n"); return 0;
+B528: printf("528\n"); return 0;
+B529: printf("529\n"); return 0;
+B530: printf("530\n"); return 0;
+B531: printf("531\n"); return 0;
+B532: printf("532\n"); return 0;
+B533: printf("533\n"); return 0;
+B534: printf("534\n"); return 0;
+B535: printf("535\n"); return 0;
+B536: printf("536\n"); return 0;
+B537: printf("537\n"); return 0;
+B538: printf("538\n"); return 0;
+B539: printf("539\n"); return 0;
+B540: printf("540\n"); return 0;
+B541: printf("541\n"); return 0;
+B542: printf("542\n"); return 0;
+B543: printf("543\n"); return 0;
+B544: printf("544\n"); return 0;
+B545: printf("545\n"); return 0;
+B546: printf("546\n"); return 0;
+B547: printf("547\n"); return 0;
+B548: printf("548\n"); return 0;
+B549: printf("549\n"); return 0;
+B550: printf("550\n"); return 0;
+B551: printf("551\n"); return 0;
+B552: printf("552\n"); return 0;
+B553: printf("553\n"); return 0;
+B554: printf("554\n"); return 0;
+B555: printf("555\n"); return 0;
+B556: printf("556\n"); return 0;
+B557: printf("557\n"); return 0;
+B558: printf("558\n"); return 0;
+B559: printf("559\n"); return 0;
+B560: printf("560\n"); return 0;
+B561: printf("561\n"); return 0;
+B562: printf("562\n"); return 0;
+B563: printf("563\n"); return 0;
+B564: printf("564\n"); return 0;
+B565: printf("565\n"); return 0;
+B566: printf("566\n"); return 0;
+B567: printf("567\n"); return 0;
+B568: printf("568\n"); return 0;
+B569: printf("569\n"); return 0;
+B570: printf("570\n"); return 0;
+B571: printf("571\n"); return 0;
+B572: printf("572\n"); return 0;
+B573: printf("573\n"); return 0;
+B574: printf("574\n"); return 0;
+B575: printf("575\n"); return 0;
+B576: printf("576\n"); return 0;
+B577: printf("577\n"); return 0;
+B578: printf("578\n"); return 0;
+B579: printf("579\n"); return 0;
+B580: printf("580\n"); return 0;
+B581: printf("581\n"); return 0;
+B582: printf("582\n"); return 0;
+B583: printf("583\n"); return 0;
+B584: printf("584\n"); return 0;
+B585: printf("585\n"); return 0;
+B586: printf("586\n"); return 0;
+B587: printf("587\n"); return 0;
+B588: printf("588\n"); return 0;
+B589: printf("589\n"); return 0;
+B590: printf("590\n"); return 0;
+B591: printf("591\n"); return 0;
+B592: printf("592\n"); return 0;
+B593: printf("593\n"); return 0;
+B594: printf("594\n"); return 0;
+B595: printf("595\n"); return 0;
+B596: printf("596\n"); return 0;
+B597: printf("597\n"); return 0;
+B598: printf("598\n"); return 0;
+B599: printf("599\n"); return 0;
+B600: printf("600\n"); return 0;
+B601: printf("601\n"); return 0;
+B602: printf("602\n"); return 0;
+B603: printf("603\n"); return 0;
+B604: printf("604\n"); return 0;
+B605: printf("605\n"); return 0;
+B606: printf("606\n"); return 0;
+B607: printf("607\n"); return 0;
+B608: printf("608\n"); return 0;
+B609: printf("609\n"); return 0;
+B610: printf("610\n"); return 0;
+B611: printf("611\n"); return 0;
+B612: printf("612\n"); return 0;
+B613: printf("613\n"); return 0;
+B614: printf("614\n"); return 0;
+B615: printf("615\n"); return 0;
+B616: printf("616\n"); return 0;
+B617: printf("617\n"); return 0;
+B618: printf("618\n"); return 0;
+B619: printf("619\n"); return 0;
+B620: printf("620\n"); return 0;
+B621: printf("621\n"); return 0;
+B622: printf("622\n"); return 0;
+B623: printf("623\n"); return 0;
+B624: printf("624\n"); return 0;
+B625: printf("625\n"); return 0;
+B626: printf("626\n"); return 0;
+B627: printf("627\n"); return 0;
+B628: printf("628\n"); return 0;
+B629: printf("629\n"); return 0;
+B630: printf("630\n"); return 0;
+B631: printf("631\n"); return 0;
+B632: printf("632\n"); return 0;
+B633: printf("633\n"); return 0;
+B634: printf("634\n"); return 0;
+B635: printf("635\n"); return 0;
+B636: printf("636\n"); return 0;
+B637: printf("637\n"); return 0;
+B638: printf("638\n"); return 0;
+B639: printf("639\n"); return 0;
+B640: printf("640\n"); return 0;
+B641: printf("641\n"); return 0;
+B642: printf("642\n"); return 0;
+B643: printf("643\n"); return 0;
+B644: printf("644\n"); return 0;
+B645: printf("645\n"); return 0;
+B646: printf("646\n"); return 0;
+B647: printf("647\n"); return 0;
+B648: printf("648\n"); return 0;
+B649: printf("649\n"); return 0;
+B650: printf("650\n"); return 0;
+B651: printf("651\n"); return 0;
+B652: printf("652\n"); return 0;
+B653: printf("653\n"); return 0;
+B654: printf("654\n"); return 0;
+B655: printf("655\n"); return 0;
+B656: printf("656\n"); return 0;
+B657: printf("657\n"); return 0;
+B658: printf("658\n"); return 0;
+B659: printf("659\n"); return 0;
+B660: printf("660\n"); return 0;
+B661: printf("661\n"); return 0;
+B662: printf("662\n"); return 0;
+B663: printf("663\n"); return 0;
+B664: printf("664\n"); return 0;
+B665: printf("665\n"); return 0;
+B666: printf("666\n"); return 0;
+B667: printf("667\n"); return 0;
+B668: printf("668\n"); return 0;
+B669: printf("669\n"); return 0;
+B670: printf("670\n"); return 0;
+B671: printf("671\n"); return 0;
+B672: printf("672\n"); return 0;
+B673: printf("673\n"); return 0;
+B674: printf("674\n"); return 0;
+B675: printf("675\n"); return 0;
+B676: printf("676\n"); return 0;
+B677: printf("677\n"); return 0;
+B678: printf("678\n"); return 0;
+B679: printf("679\n"); return 0;
+B680: printf("680\n"); return 0;
+B681: printf("681\n"); return 0;
+B682: printf("682\n"); return 0;
+B683: printf("683\n"); return 0;
+B684: printf("684\n"); return 0;
+B685: printf("685\n"); return 0;
+B686: printf("686\n"); return 0;
+B687: printf("687\n"); return 0;
+B688: printf("688\n"); return 0;
+B689: printf("689\n"); return 0;
+B690: printf("690\n"); return 0;
+B691: printf("691\n"); return 0;
+B692: printf("692\n"); return 0;
+B693: printf("693\n"); return 0;
+B694: printf("694\n"); return 0;
+B695: printf("695\n"); return 0;
+B696: printf("696\n"); return 0;
+B697: printf("697\n"); return 0;
+B698: printf("698\n"); return 0;
+B699: printf("699\n"); return 0;
+B700: printf("700\n"); return 0;
+B701: printf("701\n"); return 0;
+B702: printf("702\n"); return 0;
+B703: printf("703\n"); return 0;
+B704: printf("704\n"); return 0;
+B705: printf("705\n"); return 0;
+B706: printf("706\n"); return 0;
+B707: printf("707\n"); return 0;
+B708: printf("708\n"); return 0;
+B709: printf("709\n"); return 0;
+B710: printf("710\n"); return 0;
+B711: printf("711\n"); return 0;
+B712: printf("712\n"); return 0;
+B713: printf("713\n"); return 0;
+B714: printf("714\n"); return 0;
+B715: printf("715\n"); return 0;
+B716: printf("716\n"); return 0;
+B717: printf("717\n"); return 0;
+B718: printf("718\n"); return 0;
+B719: printf("719\n"); return 0;
+B720: printf("720\n"); return 0;
+B721: printf("721\n"); return 0;
+B722: printf("722\n"); return 0;
+B723: printf("723\n"); return 0;
+B724: printf("724\n"); return 0;
+B725: printf("725\n"); return 0;
+B726: printf("726\n"); return 0;
+B727: printf("727\n"); return 0;
+B728: printf("728\n"); return 0;
+B729: printf("729\n"); return 0;
+B730: printf("730\n"); return 0;
+B731: printf("731\n"); return 0;
+B732: printf("732\n"); return 0;
+B733: printf("733\n"); return 0;
+B734: printf("734\n"); return 0;
+B735: printf("735\n"); return 0;
+B736: printf("736\n"); return 0;
+B737: printf("737\n"); return 0;
+B738: printf("738\n"); return 0;
+B739: printf("739\n"); return 0;
+B740: printf("740\n"); return 0;
+B741: printf("741\n"); return 0;
+B742: printf("742\n"); return 0;
+B743: printf("743\n"); return 0;
+B744: printf("744\n"); return 0;
+B745: printf("745\n"); return 0;
+B746: printf("746\n"); return 0;
+B747: printf("747\n"); return 0;
+B748: printf("748\n"); return 0;
+B749: printf("749\n"); return 0;
+B750: printf("750\n"); return 0;
+B751: printf("751\n"); return 0;
+B752: printf("752\n"); return 0;
+B753: printf("753\n"); return 0;
+B754: printf("754\n"); return 0;
+B755: printf("755\n"); return 0;
+B756: printf("756\n"); return 0;
+B757: printf("757\n"); return 0;
+B758: printf("758\n"); return 0;
+B759: printf("759\n"); return 0;
+B760: printf("760\n"); return 0;
+B761: printf("761\n"); return 0;
+B762: printf("762\n"); return 0;
+B763: printf("763\n"); return 0;
+B764: printf("764\n"); return 0;
+B765: printf("765\n"); return 0;
+B766: printf("766\n"); return 0;
+B767: printf("767\n"); return 0;
+B768: printf("768\n"); return 0;
+B769: printf("769\n"); return 0;
+B770: printf("770\n"); return 0;
+B771: printf("771\n"); return 0;
+B772: printf("772\n"); return 0;
+B773: printf("773\n"); return 0;
+B774: printf("774\n"); return 0;
+B775: printf("775\n"); return 0;
+B776: printf("776\n"); return 0;
+B777: printf("777\n"); return 0;
+B778: printf("778\n"); return 0;
+B779: printf("779\n"); return 0;
+B780: printf("780\n"); return 0;
+B781: printf("781\n"); return 0;
+B782: printf("782\n"); return 0;
+B783: printf("783\n"); return 0;
+B784: printf("784\n"); return 0;
+B785: printf("785\n"); return 0;
+B786: printf("786\n"); return 0;
+B787: printf("787\n"); return 0;
+B788: printf("788\n"); return 0;
+B789: printf("789\n"); return 0;
+B790: printf("790\n"); return 0;
+B791: printf("791\n"); return 0;
+B792: printf("792\n"); return 0;
+B793: printf("793\n"); return 0;
+B794: printf("794\n"); return 0;
+B795: printf("795\n"); return 0;
+B796: printf("796\n"); return 0;
+B797: printf("797\n"); return 0;
+B798: printf("798\n"); return 0;
+B799: printf("799\n"); return 0;
+B800: printf("800\n"); return 0;
+B801: printf("801\n"); return 0;
+B802: printf("802\n"); return 0;
+B803: printf("803\n"); return 0;
+B804: printf("804\n"); return 0;
+B805: printf("805\n"); return 0;
+B806: printf("806\n"); return 0;
+B807: printf("807\n"); return 0;
+B808: printf("808\n"); return 0;
+B809: printf("809\n"); return 0;
+B810: printf("810\n"); return 0;
+B811: printf("811\n"); return 0;
+B812: printf("812\n"); return 0;
+B813: printf("813\n"); return 0;
+B814: printf("814\n"); return 0;
+B815: printf("815\n"); return 0;
+B816: printf("816\n"); return 0;
+B817: printf("817\n"); return 0;
+B818: printf("818\n"); return 0;
+B819: printf("819\n"); return 0;
+B820: printf("820\n"); return 0;
+B821: printf("821\n"); return 0;
+B822: printf("822\n"); return 0;
+B823: printf("823\n"); return 0;
+B824: printf("824\n"); return 0;
+B825: printf("825\n"); return 0;
+B826: printf("826\n"); return 0;
+B827: printf("827\n"); return 0;
+B828: printf("828\n"); return 0;
+B829: printf("829\n"); return 0;
+B830: printf("830\n"); return 0;
+B831: printf("831\n"); return 0;
+B832: printf("832\n"); return 0;
+B833: printf("833\n"); return 0;
+B834: printf("834\n"); return 0;
+B835: printf("835\n"); return 0;
+B836: printf("836\n"); return 0;
+B837: printf("837\n"); return 0;
+B838: printf("838\n"); return 0;
+B839: printf("839\n"); return 0;
+B840: printf("840\n"); return 0;
+B841: printf("841\n"); return 0;
+B842: printf("842\n"); return 0;
+B843: printf("843\n"); return 0;
+B844: printf("844\n"); return 0;
+B845: printf("845\n"); return 0;
+B846: printf("846\n"); return 0;
+B847: printf("847\n"); return 0;
+B848: printf("848\n"); return 0;
+B849: printf("849\n"); return 0;
+B850: printf("850\n"); return 0;
+B851: printf("851\n"); return 0;
+B852: printf("852\n"); return 0;
+B853: printf("853\n"); return 0;
+B854: printf("854\n"); return 0;
+B855: printf("855\n"); return 0;
+B856: printf("856\n"); return 0;
+B857: printf("857\n"); return 0;
+B858: printf("858\n"); return 0;
+B859: printf("859\n"); return 0;
+B860: printf("860\n"); return 0;
+B861: printf("861\n"); return 0;
+B862: printf("862\n"); return 0;
+B863: printf("863\n"); return 0;
+B864: printf("864\n"); return 0;
+B865: printf("865\n"); return 0;
+B866: printf("866\n"); return 0;
+B867: printf("867\n"); return 0;
+B868: printf("868\n"); return 0;
+B869: printf("869\n"); return 0;
+B870: printf("870\n"); return 0;
+B871: printf("871\n"); return 0;
+B872: printf("872\n"); return 0;
+B873: printf("873\n"); return 0;
+B874: printf("874\n"); return 0;
+B875: printf("875\n"); return 0;
+B876: printf("876\n"); return 0;
+B877: printf("877\n"); return 0;
+B878: printf("878\n"); return 0;
+B879: printf("879\n"); return 0;
+B880: printf("880\n"); return 0;
+B881: printf("881\n"); return 0;
+B882: printf("882\n"); return 0;
+B883: printf("883\n"); return 0;
+B884: printf("884\n"); return 0;
+B885: printf("885\n"); return 0;
+B886: printf("886\n"); return 0;
+B887: printf("887\n"); return 0;
+B888: printf("888\n"); return 0;
+B889: printf("889\n"); return 0;
+B890: printf("890\n"); return 0;
+B891: printf("891\n"); return 0;
+B892: printf("892\n"); return 0;
+B893: printf("893\n"); return 0;
+B894: printf("894\n"); return 0;
+B895: printf("895\n"); return 0;
+B896: printf("896\n"); return 0;
+B897: printf("897\n"); return 0;
+B898: printf("898\n"); return 0;
+B899: printf("899\n"); return 0;
+B900: printf("900\n"); return 0;
+B901: printf("901\n"); return 0;
+B902: printf("902\n"); return 0;
+B903: printf("903\n"); return 0;
+B904: printf("904\n"); return 0;
+B905: printf("905\n"); return 0;
+B906: printf("906\n"); return 0;
+B907: printf("907\n"); return 0;
+B908: printf("908\n"); return 0;
+B909: printf("909\n"); return 0;
+B910: printf("910\n"); return 0;
+B911: printf("911\n"); return 0;
+B912: printf("912\n"); return 0;
+B913: printf("913\n"); return 0;
+B914: printf("914\n"); return 0;
+B915: printf("915\n"); return 0;
+B916: printf("916\n"); return 0;
+B917: printf("917\n"); return 0;
+B918: printf("918\n"); return 0;
+B919: printf("919\n"); return 0;
+B920: printf("920\n"); return 0;
+B921: printf("921\n"); return 0;
+B922: printf("922\n"); return 0;
+B923: printf("923\n"); return 0;
+B924: printf("924\n"); return 0;
+B925: printf("925\n"); return 0;
+B926: printf("926\n"); return 0;
+B927: printf("927\n"); return 0;
+B928: printf("928\n"); return 0;
+B929: printf("929\n"); return 0;
+B930: printf("930\n"); return 0;
+B931: printf("931\n"); return 0;
+B932: printf("932\n"); return 0;
+B933: printf("933\n"); return 0;
+B934: printf("934\n"); return 0;
+B935: printf("935\n"); return 0;
+B936: printf("936\n"); return 0;
+B937: printf("937\n"); return 0;
+B938: printf("938\n"); return 0;
+B939: printf("939\n"); return 0;
+B940: printf("940\n"); return 0;
+B941: printf("941\n"); return 0;
+B942: printf("942\n"); return 0;
+B943: printf("943\n"); return 0;
+B944: printf("944\n"); return 0;
+B945: printf("945\n"); return 0;
+B946: printf("946\n"); return 0;
+B947: printf("947\n"); return 0;
+B948: printf("948\n"); return 0;
+B949: printf("949\n"); return 0;
+B950: printf("950\n"); return 0;
+B951: printf("951\n"); return 0;
+B952: printf("952\n"); return 0;
+B953: printf("953\n"); return 0;
+B954: printf("954\n"); return 0;
+B955: printf("955\n"); return 0;
+B956: printf("956\n"); return 0;
+B957: printf("957\n"); return 0;
+B958: printf("958\n"); return 0;
+B959: printf("959\n"); return 0;
+B960: printf("960\n"); return 0;
+B961: printf("961\n"); return 0;
+B962: printf("962\n"); return 0;
+B963: printf("963\n"); return 0;
+B964: printf("964\n"); return 0;
+B965: printf("965\n"); return 0;
+B966: printf("966\n"); return 0;
+B967: printf("967\n"); return 0;
+B968: printf("968\n"); return 0;
+B969: printf("969\n"); return 0;
+B970: printf("970\n"); return 0;
+B971: printf("971\n"); return 0;
+B972: printf("972\n"); return 0;
+B973: printf("973\n"); return 0;
+B974: printf("974\n"); return 0;
+B975: printf("975\n"); return 0;
+B976: printf("976\n"); return 0;
+B977: printf("977\n"); return 0;
+B978: printf("978\n"); return 0;
+B979: printf("979\n"); return 0;
+B980: printf("980\n"); return 0;
+B981: printf("981\n"); return 0;
+B982: printf("982\n"); return 0;
+B983: printf("983\n"); return 0;
+B984: printf("984\n"); return 0;
+B985: printf("985\n"); return 0;
+B986: printf("986\n"); return 0;
+B987: printf("987\n"); return 0;
+B988: printf("988\n"); return 0;
+B989: printf("989\n"); return 0;
+B990: printf("990\n"); return 0;
+B991: printf("991\n"); return 0;
+B992: printf("992\n"); return 0;
+B993: printf("993\n"); return 0;
+B994: printf("994\n"); return 0;
+B995: printf("995\n"); return 0;
+B996: printf("996\n"); return 0;
+B997: printf("997\n"); return 0;
+B998: printf("998\n"); return 0;
+B999: printf("999\n"); return 0;
+B1000: printf("1000\n"); return 0;
+B1001: printf("1001\n"); return 0;
+B1002: printf("1002\n"); return 0;
+B1003: printf("1003\n"); return 0;
+B1004: printf("1004\n"); return 0;
+B1005: printf("1005\n"); return 0;
+B1006: printf("1006\n"); return 0;
+B1007: printf("1007\n"); return 0;
+B1008: printf("1008\n"); return 0;
+B1009: printf("1009\n"); return 0;
+B1010: printf("1010\n"); return 0;
+B1011: printf("1011\n"); return 0;
+B1012: printf("1012\n"); return 0;
+B1013: printf("1013\n"); return 0;
+B1014: printf("1014\n"); return 0;
+B1015: printf("1015\n"); return 0;
+B1016: printf("1016\n"); return 0;
+B1017: printf("1017\n"); return 0;
+B1018: printf("1018\n"); return 0;
+B1019: printf("1019\n"); return 0;
+B1020: printf("1020\n"); return 0;
+B1021: printf("1021\n"); return 0;
+B1022: printf("1022\n"); return 0;
+B1023: printf("1023\n"); return 0;
+B1024: printf("1024\n"); return 0;
+B1025: printf("1025\n"); return 0;
+B1026: printf("1026\n"); return 0;
+B1027: printf("1027\n"); return 0;
+B1028: printf("1028\n"); return 0;
+B1029: printf("1029\n"); return 0;
+B1030: printf("1030\n"); return 0;
+B1031: printf("1031\n"); return 0;
+B1032: printf("1032\n"); return 0;
+B1033: printf("1033\n"); return 0;
+B1034: printf("1034\n"); return 0;
+B1035: printf("1035\n"); return 0;
+B1036: printf("1036\n"); return 0;
+B1037: printf("1037\n"); return 0;
+B1038: printf("1038\n"); return 0;
+B1039: printf("1039\n"); return 0;
+B1040: printf("1040\n"); return 0;
+B1041: printf("1041\n"); return 0;
+B1042: printf("1042\n"); return 0;
+B1043: printf("1043\n"); return 0;
+B1044: printf("1044\n"); return 0;
+B1045: printf("1045\n"); return 0;
+B1046: printf("1046\n"); return 0;
+B1047: printf("1047\n"); return 0;
+B1048: printf("1048\n"); return 0;
+B1049: printf("1049\n"); return 0;
+B1050: printf("1050\n"); return 0;
+B1051: printf("1051\n"); return 0;
+B1052: printf("1052\n"); return 0;
+B1053: printf("1053\n"); return 0;
+B1054: printf("1054\n"); return 0;
+B1055: printf("1055\n"); return 0;
+B1056: printf("1056\n"); return 0;
+B1057: printf("1057\n"); return 0;
+B1058: printf("1058\n"); return 0;
+B1059: printf("1059\n"); return 0;
+B1060: printf("1060\n"); return 0;
+B1061: printf("1061\n"); return 0;
+B1062: printf("1062\n"); return 0;
+B1063: printf("1063\n"); return 0;
+B1064: printf("1064\n"); return 0;
+B1065: printf("1065\n"); return 0;
+B1066: printf("1066\n"); return 0;
+B1067: printf("1067\n"); return 0;
+B1068: printf("1068\n"); return 0;
+B1069: printf("1069\n"); return 0;
+B1070: printf("1070\n"); return 0;
+B1071: printf("1071\n"); return 0;
+B1072: printf("1072\n"); return 0;
+B1073: printf("1073\n"); return 0;
+B1074: printf("1074\n"); return 0;
+B1075: printf("1075\n"); return 0;
+B1076: printf("1076\n"); return 0;
+B1077: printf("1077\n"); return 0;
+B1078: printf("1078\n"); return 0;
+B1079: printf("1079\n"); return 0;
+B1080: printf("1080\n"); return 0;
+B1081: printf("1081\n"); return 0;
+B1082: printf("1082\n"); return 0;
+B1083: printf("1083\n"); return 0;
+B1084: printf("1084\n"); return 0;
+B1085: printf("1085\n"); return 0;
+B1086: printf("1086\n"); return 0;
+B1087: printf("1087\n"); return 0;
+B1088: printf("1088\n"); return 0;
+B1089: printf("1089\n"); return 0;
+B1090: printf("1090\n"); return 0;
+B1091: printf("1091\n"); return 0;
+B1092: printf("1092\n"); return 0;
+B1093: printf("1093\n"); return 0;
+B1094: printf("1094\n"); return 0;
+B1095: printf("1095\n"); return 0;
+B1096: printf("1096\n"); return 0;
+B1097: printf("1097\n"); return 0;
+B1098: printf("1098\n"); return 0;
+B1099: printf("1099\n"); return 0;
+B1100: printf("1100\n"); return 0;
+B1101: printf("1101\n"); return 0;
+B1102: printf("1102\n"); return 0;
+B1103: printf("1103\n"); return 0;
+B1104: printf("1104\n"); return 0;
+B1105: printf("1105\n"); return 0;
+B1106: printf("1106\n"); return 0;
+B1107: printf("1107\n"); return 0;
+B1108: printf("1108\n"); return 0;
+B1109: printf("1109\n"); return 0;
+B1110: printf("1110\n"); return 0;
+B1111: printf("1111\n"); return 0;
+B1112: printf("1112\n"); return 0;
+B1113: printf("1113\n"); return 0;
+B1114: printf("1114\n"); return 0;
+B1115: printf("1115\n"); return 0;
+B1116: printf("1116\n"); return 0;
+B1117: printf("1117\n"); return 0;
+B1118: printf("1118\n"); return 0;
+B1119: printf("1119\n"); return 0;
+B1120: printf("1120\n"); return 0;
+B1121: printf("1121\n"); return 0;
+B1122: printf("1122\n"); return 0;
+B1123: printf("1123\n"); return 0;
+B1124: printf("1124\n"); return 0;
+B1125: printf("1125\n"); return 0;
+B1126: printf("1126\n"); return 0;
+B1127: printf("1127\n"); return 0;
+B1128: printf("1128\n"); return 0;
+B1129: printf("1129\n"); return 0;
+B1130: printf("1130\n"); return 0;
+B1131: printf("1131\n"); return 0;
+B1132: printf("1132\n"); return 0;
+B1133: printf("1133\n"); return 0;
+B1134: printf("1134\n"); return 0;
+B1135: printf("1135\n"); return 0;
+B1136: printf("1136\n"); return 0;
+B1137: printf("1137\n"); return 0;
+B1138: printf("1138\n"); return 0;
+B1139: printf("1139\n"); return 0;
+B1140: printf("1140\n"); return 0;
+B1141: printf("1141\n"); return 0;
+B1142: printf("1142\n"); return 0;
+B1143: printf("1143\n"); return 0;
+B1144: printf("1144\n"); return 0;
+B1145: printf("1145\n"); return 0;
+B1146: printf("1146\n"); return 0;
+B1147: printf("1147\n"); return 0;
+B1148: printf("1148\n"); return 0;
+B1149: printf("1149\n"); return 0;
+B1150: printf("1150\n"); return 0;
+B1151: printf("1151\n"); return 0;
+B1152: printf("1152\n"); return 0;
+B1153: printf("1153\n"); return 0;
+B1154: printf("1154\n"); return 0;
+B1155: printf("1155\n"); return 0;
+B1156: printf("1156\n"); return 0;
+B1157: printf("1157\n"); return 0;
+B1158: printf("1158\n"); return 0;
+B1159: printf("1159\n"); return 0;
+B1160: printf("1160\n"); return 0;
+B1161: printf("1161\n"); return 0;
+B1162: printf("1162\n"); return 0;
+B1163: printf("1163\n"); return 0;
+B1164: printf("1164\n"); return 0;
+B1165: printf("1165\n"); return 0;
+B1166: printf("1166\n"); return 0;
+B1167: printf("1167\n"); return 0;
+B1168: printf("1168\n"); return 0;
+B1169: printf("1169\n"); return 0;
+B1170: printf("1170\n"); return 0;
+B1171: printf("1171\n"); return 0;
+B1172: printf("1172\n"); return 0;
+B1173: printf("1173\n"); return 0;
+B1174: printf("1174\n"); return 0;
+B1175: printf("1175\n"); return 0;
+B1176: printf("1176\n"); return 0;
+B1177: printf("1177\n"); return 0;
+B1178: printf("1178\n"); return 0;
+B1179: printf("1179\n"); return 0;
+B1180: printf("1180\n"); return 0;
+B1181: printf("1181\n"); return 0;
+B1182: printf("1182\n"); return 0;
+B1183: printf("1183\n"); return 0;
+B1184: printf("1184\n"); return 0;
+B1185: printf("1185\n"); return 0;
+B1186: printf("1186\n"); return 0;
+B1187: printf("1187\n"); return 0;
+B1188: printf("1188\n"); return 0;
+B1189: printf("1189\n"); return 0;
+B1190: printf("1190\n"); return 0;
+B1191: printf("1191\n"); return 0;
+B1192: printf("1192\n"); return 0;
+B1193: printf("1193\n"); return 0;
+B1194: printf("1194\n"); return 0;
+B1195: printf("1195\n"); return 0;
+B1196: printf("1196\n"); return 0;
+B1197: printf("1197\n"); return 0;
+B1198: printf("1198\n"); return 0;
+B1199: printf("1199\n"); return 0;
+B1200: printf("1200\n"); return 0;
+B1201: printf("1201\n"); return 0;
+B1202: printf("1202\n"); return 0;
+B1203: printf("1203\n"); return 0;
+B1204: printf("1204\n"); return 0;
+B1205: printf("1205\n"); return 0;
+B1206: printf("1206\n"); return 0;
+B1207: printf("1207\n"); return 0;
+B1208: printf("1208\n"); return 0;
+B1209: printf("1209\n"); return 0;
+B1210: printf("1210\n"); return 0;
+B1211: printf("1211\n"); return 0;
+B1212: printf("1212\n"); return 0;
+B1213: printf("1213\n"); return 0;
+B1214: printf("1214\n"); return 0;
+B1215: printf("1215\n"); return 0;
+B1216: printf("1216\n"); return 0;
+B1217: printf("1217\n"); return 0;
+B1218: printf("1218\n"); return 0;
+B1219: printf("1219\n"); return 0;
+B1220: printf("1220\n"); return 0;
+B1221: printf("1221\n"); return 0;
+B1222: printf("1222\n"); return 0;
+B1223: printf("1223\n"); return 0;
+B1224: printf("1224\n"); return 0;
+B1225: printf("1225\n"); return 0;
+B1226: printf("1226\n"); return 0;
+B1227: printf("1227\n"); return 0;
+B1228: printf("1228\n"); return 0;
+B1229: printf("1229\n"); return 0;
+B1230: printf("1230\n"); return 0;
+B1231: printf("1231\n"); return 0;
+B1232: printf("1232\n"); return 0;
+B1233: printf("1233\n"); return 0;
+B1234: printf("1234\n"); return 0;
+B1235: printf("1235\n"); return 0;
+B1236: printf("1236\n"); return 0;
+B1237: printf("1237\n"); return 0;
+B1238: printf("1238\n"); return 0;
+B1239: printf("1239\n"); return 0;
+B1240: printf("1240\n"); return 0;
+B1241: printf("1241\n"); return 0;
+B1242: printf("1242\n"); return 0;
+B1243: printf("1243\n"); return 0;
+B1244: printf("1244\n"); return 0;
+B1245: printf("1245\n"); return 0;
+B1246: printf("1246\n"); return 0;
+B1247: printf("1247\n"); return 0;
+B1248: printf("1248\n"); return 0;
+B1249: printf("1249\n"); return 0;
+B1250: printf("1250\n"); return 0;
+B1251: printf("1251\n"); return 0;
+B1252: printf("1252\n"); return 0;
+B1253: printf("1253\n"); return 0;
+B1254: printf("1254\n"); return 0;
+B1255: printf("1255\n"); return 0;
+B1256: printf("1256\n"); return 0;
+B1257: printf("1257\n"); return 0;
+B1258: printf("1258\n"); return 0;
+B1259: printf("1259\n"); return 0;
+B1260: printf("1260\n"); return 0;
+B1261: printf("1261\n"); return 0;
+B1262: printf("1262\n"); return 0;
+B1263: printf("1263\n"); return 0;
+B1264: printf("1264\n"); return 0;
+B1265: printf("1265\n"); return 0;
+B1266: printf("1266\n"); return 0;
+B1267: printf("1267\n"); return 0;
+B1268: printf("1268\n"); return 0;
+B1269: printf("1269\n"); return 0;
+B1270: printf("1270\n"); return 0;
+B1271: printf("1271\n"); return 0;
+B1272: printf("1272\n"); return 0;
+B1273: printf("1273\n"); return 0;
+B1274: printf("1274\n"); return 0;
+B1275: printf("1275\n"); return 0;
+B1276: printf("1276\n"); return 0;
+B1277: printf("1277\n"); return 0;
+B1278: printf("1278\n"); return 0;
+B1279: printf("1279\n"); return 0;
+B1280: printf("1280\n"); return 0;
+B1281: printf("1281\n"); return 0;
+B1282: printf("1282\n"); return 0;
+B1283: printf("1283\n"); return 0;
+B1284: printf("1284\n"); return 0;
+B1285: printf("1285\n"); return 0;
+B1286: printf("1286\n"); return 0;
+B1287: printf("1287\n"); return 0;
+B1288: printf("1288\n"); return 0;
+B1289: printf("1289\n"); return 0;
+B1290: printf("1290\n"); return 0;
+B1291: printf("1291\n"); return 0;
+B1292: printf("1292\n"); return 0;
+B1293: printf("1293\n"); return 0;
+B1294: printf("1294\n"); return 0;
+B1295: printf("1295\n"); return 0;
+B1296: printf("1296\n"); return 0;
+B1297: printf("1297\n"); return 0;
+B1298: printf("1298\n"); return 0;
+B1299: printf("1299\n"); return 0;
+B1300: printf("1300\n"); return 0;
+B1301: printf("1301\n"); return 0;
+B1302: printf("1302\n"); return 0;
+B1303: printf("1303\n"); return 0;
+B1304: printf("1304\n"); return 0;
+B1305: printf("1305\n"); return 0;
+B1306: printf("1306\n"); return 0;
+B1307: printf("1307\n"); return 0;
+B1308: printf("1308\n"); return 0;
+B1309: printf("1309\n"); return 0;
+B1310: printf("1310\n"); return 0;
+B1311: printf("1311\n"); return 0;
+B1312: printf("1312\n"); return 0;
+B1313: printf("1313\n"); return 0;
+B1314: printf("1314\n"); return 0;
+B1315: printf("1315\n"); return 0;
+B1316: printf("1316\n"); return 0;
+B1317: printf("1317\n"); return 0;
+B1318: printf("1318\n"); return 0;
+B1319: printf("1319\n"); return 0;
+B1320: printf("1320\n"); return 0;
+B1321: printf("1321\n"); return 0;
+B1322: printf("1322\n"); return 0;
+B1323: printf("1323\n"); return 0;
+B1324: printf("1324\n"); return 0;
+B1325: printf("1325\n"); return 0;
+B1326: printf("1326\n"); return 0;
+B1327: printf("1327\n"); return 0;
+B1328: printf("1328\n"); return 0;
+B1329: printf("1329\n"); return 0;
+B1330: printf("1330\n"); return 0;
+B1331: printf("1331\n"); return 0;
+B1332: printf("1332\n"); return 0;
+B1333: printf("1333\n"); return 0;
+B1334: printf("1334\n"); return 0;
+B1335: printf("1335\n"); return 0;
+B1336: printf("1336\n"); return 0;
+B1337: printf("1337\n"); return 0;
+B1338: printf("1338\n"); return 0;
+B1339: printf("1339\n"); return 0;
+B1340: printf("1340\n"); return 0;
+B1341: printf("1341\n"); return 0;
+B1342: printf("1342\n"); return 0;
+B1343: printf("1343\n"); return 0;
+B1344: printf("1344\n"); return 0;
+B1345: printf("1345\n"); return 0;
+B1346: printf("1346\n"); return 0;
+B1347: printf("1347\n"); return 0;
+B1348: printf("1348\n"); return 0;
+B1349: printf("1349\n"); return 0;
+B1350: printf("1350\n"); return 0;
+B1351: printf("1351\n"); return 0;
+B1352: printf("1352\n"); return 0;
+B1353: printf("1353\n"); return 0;
+B1354: printf("1354\n"); return 0;
+B1355: printf("1355\n"); return 0;
+B1356: printf("1356\n"); return 0;
+B1357: printf("1357\n"); return 0;
+B1358: printf("1358\n"); return 0;
+B1359: printf("1359\n"); return 0;
+B1360: printf("1360\n"); return 0;
+B1361: printf("1361\n"); return 0;
+B1362: printf("1362\n"); return 0;
+B1363: printf("1363\n"); return 0;
+B1364: printf("1364\n"); return 0;
+B1365: printf("1365\n"); return 0;
+B1366: printf("1366\n"); return 0;
+B1367: printf("1367\n"); return 0;
+B1368: printf("1368\n"); return 0;
+B1369: printf("1369\n"); return 0;
+B1370: printf("1370\n"); return 0;
+B1371: printf("1371\n"); return 0;
+B1372: printf("1372\n"); return 0;
+B1373: printf("1373\n"); return 0;
+B1374: printf("1374\n"); return 0;
+B1375: printf("1375\n"); return 0;
+B1376: printf("1376\n"); return 0;
+B1377: printf("1377\n"); return 0;
+B1378: printf("1378\n"); return 0;
+B1379: printf("1379\n"); return 0;
+B1380: printf("1380\n"); return 0;
+B1381: printf("1381\n"); return 0;
+B1382: printf("1382\n"); return 0;
+B1383: printf("1383\n"); return 0;
+B1384: printf("1384\n"); return 0;
+B1385: printf("1385\n"); return 0;
+B1386: printf("1386\n"); return 0;
+B1387: printf("1387\n"); return 0;
+B1388: printf("1388\n"); return 0;
+B1389: printf("1389\n"); return 0;
+B1390: printf("1390\n"); return 0;
+B1391: printf("1391\n"); return 0;
+B1392: printf("1392\n"); return 0;
+B1393: printf("1393\n"); return 0;
+B1394: printf("1394\n"); return 0;
+B1395: printf("1395\n"); return 0;
+B1396: printf("1396\n"); return 0;
+B1397: printf("1397\n"); return 0;
+B1398: printf("1398\n"); return 0;
+B1399: printf("1399\n"); return 0;
+B1400: printf("1400\n"); return 0;
+B1401: printf("1401\n"); return 0;
+B1402: printf("1402\n"); return 0;
+B1403: printf("1403\n"); return 0;
+B1404: printf("1404\n"); return 0;
+B1405: printf("1405\n"); return 0;
+B1406: printf("1406\n"); return 0;
+B1407: printf("1407\n"); return 0;
+B1408: printf("1408\n"); return 0;
+B1409: printf("1409\n"); return 0;
+B1410: printf("1410\n"); return 0;
+B1411: printf("1411\n"); return 0;
+B1412: printf("1412\n"); return 0;
+B1413: printf("1413\n"); return 0;
+B1414: printf("1414\n"); return 0;
+B1415: printf("1415\n"); return 0;
+B1416: printf("1416\n"); return 0;
+B1417: printf("1417\n"); return 0;
+B1418: printf("1418\n"); return 0;
+B1419: printf("1419\n"); return 0;
+B1420: printf("1420\n"); return 0;
+B1421: printf("1421\n"); return 0;
+B1422: printf("1422\n"); return 0;
+B1423: printf("1423\n"); return 0;
+B1424: printf("1424\n"); return 0;
+B1425: printf("1425\n"); return 0;
+B1426: printf("1426\n"); return 0;
+B1427: printf("1427\n"); return 0;
+B1428: printf("1428\n"); return 0;
+B1429: printf("1429\n"); return 0;
+B1430: printf("1430\n"); return 0;
+B1431: printf("1431\n"); return 0;
+B1432: printf("1432\n"); return 0;
+B1433: printf("1433\n"); return 0;
+B1434: printf("1434\n"); return 0;
+B1435: printf("1435\n"); return 0;
+B1436: printf("1436\n"); return 0;
+B1437: printf("1437\n"); return 0;
+B1438: printf("1438\n"); return 0;
+B1439: printf("1439\n"); return 0;
+B1440: printf("1440\n"); return 0;
+B1441: printf("1441\n"); return 0;
+B1442: printf("1442\n"); return 0;
+B1443: printf("1443\n"); return 0;
+B1444: printf("1444\n"); return 0;
+B1445: printf("1445\n"); return 0;
+B1446: printf("1446\n"); return 0;
+B1447: printf("1447\n"); return 0;
+B1448: printf("1448\n"); return 0;
+B1449: printf("1449\n"); return 0;
+B1450: printf("1450\n"); return 0;
+B1451: printf("1451\n"); return 0;
+B1452: printf("1452\n"); return 0;
+B1453: printf("1453\n"); return 0;
+B1454: printf("1454\n"); return 0;
+B1455: printf("1455\n"); return 0;
+B1456: printf("1456\n"); return 0;
+B1457: printf("1457\n"); return 0;
+B1458: printf("1458\n"); return 0;
+B1459: printf("1459\n"); return 0;
+B1460: printf("1460\n"); return 0;
+B1461: printf("1461\n"); return 0;
+B1462: printf("1462\n"); return 0;
+B1463: printf("1463\n"); return 0;
+B1464: printf("1464\n"); return 0;
+B1465: printf("1465\n"); return 0;
+B1466: printf("1466\n"); return 0;
+B1467: printf("1467\n"); return 0;
+B1468: printf("1468\n"); return 0;
+B1469: printf("1469\n"); return 0;
+B1470: printf("1470\n"); return 0;
+B1471: printf("1471\n"); return 0;
+B1472: printf("1472\n"); return 0;
+B1473: printf("1473\n"); return 0;
+B1474: printf("1474\n"); return 0;
+B1475: printf("1475\n"); return 0;
+B1476: printf("1476\n"); return 0;
+B1477: printf("1477\n"); return 0;
+B1478: printf("1478\n"); return 0;
+B1479: printf("1479\n"); return 0;
+B1480: printf("1480\n"); return 0;
+B1481: printf("1481\n"); return 0;
+B1482: printf("1482\n"); return 0;
+B1483: printf("1483\n"); return 0;
+B1484: printf("1484\n"); return 0;
+B1485: printf("1485\n"); return 0;
+B1486: printf("1486\n"); return 0;
+B1487: printf("1487\n"); return 0;
+B1488: printf("1488\n"); return 0;
+B1489: printf("1489\n"); return 0;
+B1490: printf("1490\n"); return 0;
+B1491: printf("1491\n"); return 0;
+B1492: printf("1492\n"); return 0;
+B1493: printf("1493\n"); return 0;
+B1494: printf("1494\n"); return 0;
+B1495: printf("1495\n"); return 0;
+B1496: printf("1496\n"); return 0;
+B1497: printf("1497\n"); return 0;
+B1498: printf("1498\n"); return 0;
+B1499: printf("1499\n"); return 0;
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_indirectbr_many.out b/tests/core/test_indirectbr_many.out
new file mode 100644
index 00000000..d53baec4
--- /dev/null
+++ b/tests/core/test_indirectbr_many.out
@@ -0,0 +1,2 @@
+
+1001
diff --git a/tests/core/test_inherit.in b/tests/core/test_inherit.in
new file mode 100644
index 00000000..e9a152e8
--- /dev/null
+++ b/tests/core/test_inherit.in
@@ -0,0 +1,25 @@
+
+ #include <stdio.h>
+ struct Parent {
+ int x1, x2;
+ };
+ struct Child : Parent {
+ int y;
+ };
+ int main()
+ {
+ Parent a;
+ a.x1 = 50;
+ a.x2 = 87;
+ Child b;
+ b.x1 = 78;
+ b.x2 = 550;
+ b.y = 101;
+ Child* c = (Child*)&a;
+ c->x1 ++;
+ c = &b;
+ c->y --;
+ printf("*%d,%d,%d,%d,%d,%d,%d*\n", a.x1, a.x2, b.x1, b.x2, b.y, c->x1, c->x2);
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_inherit.out b/tests/core/test_inherit.out
new file mode 100644
index 00000000..34570bd7
--- /dev/null
+++ b/tests/core/test_inherit.out
@@ -0,0 +1 @@
+*51,87,78,550,100,78,550* \ No newline at end of file
diff --git a/tests/core/test_inlinejs.in b/tests/core/test_inlinejs.in
new file mode 100644
index 00000000..0359b707
--- /dev/null
+++ b/tests/core/test_inlinejs.in
@@ -0,0 +1,26 @@
+
+ #include <stdio.h>
+
+ double get() {
+ double ret = 0;
+ __asm __volatile__("Math.abs(-12/3.3)":"=r"(ret)); // write to a variable
+ asm("#comment1");
+ asm volatile("#comment2");
+ asm volatile("#comment3\n"
+ "#comment4\n");
+ return ret;
+ }
+
+ int main() {
+ asm("Module.print('Inline JS is very cool')");
+ printf("%.2f\n", get());
+
+ // Test that passing multiple input and output variables works.
+ int src1 = 1, src2 = 2, src3 = 3;
+ int dst1 = 0, dst2 = 0, dst3 = 0;
+ // TODO asm("Module.print(%3); Module.print(%4); Module.print(%5); %0 = %3; %1 = %4; %2 = %5;" : "=r"(dst1),"=r"(dst2),"=r"(dst3): "r"(src1),"r"(src2),"r"(src3));
+ // TODO printf("%d\n%d\n%d\n", dst1, dst2, dst3);
+
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_inlinejs.out b/tests/core/test_inlinejs.out
new file mode 100644
index 00000000..1838ef2e
--- /dev/null
+++ b/tests/core/test_inlinejs.out
@@ -0,0 +1,2 @@
+Inline JS is very cool
+3.64
diff --git a/tests/core/test_inlinejs2.in b/tests/core/test_inlinejs2.in
new file mode 100644
index 00000000..7a05fd67
--- /dev/null
+++ b/tests/core/test_inlinejs2.in
@@ -0,0 +1,20 @@
+
+ #include <stdio.h>
+
+ int mix(int x, int y) {
+ int ret;
+ asm("Math.pow(2, %0+%1+1)" : "=r"(ret) : "r"(x), "r"(y)); // read and write
+ return ret;
+ }
+
+ void mult() {
+ asm("var $_$1 = Math.abs(-100); $_$1 *= 2; Module.print($_$1)"); // multiline
+ asm __volatile__("Module.print('done')");
+ }
+
+ int main(int argc, char **argv) {
+ printf("%d\n", mix(argc, argc/2));
+ mult();
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_inlinejs2.out b/tests/core/test_inlinejs2.out
new file mode 100644
index 00000000..68dd9b64
--- /dev/null
+++ b/tests/core/test_inlinejs2.out
@@ -0,0 +1,3 @@
+4
+200
+done
diff --git a/tests/core/test_inlinejs3.in b/tests/core/test_inlinejs3.in
new file mode 100644
index 00000000..e7d9b1e8
--- /dev/null
+++ b/tests/core/test_inlinejs3.in
@@ -0,0 +1,26 @@
+
+ #include <stdio.h>
+ #include <emscripten.h>
+
+ int main(int argc, char **argv) {
+ EM_ASM(Module.print('hello dere1'));
+ EM_ASM(
+ Module.print('hello dere2');
+ );
+ for (int i = 0; i < 3; i++) {
+ EM_ASM(
+ Module.print('hello dere3');
+ Module.print('hello dere' + 4);
+ );
+ }
+ int sum = 0;
+ for (int i = 0; i < argc*3; i++) {
+ sum += EM_ASM_INT({
+ Module.print('i: ' + [$0, ($1).toFixed(2)]);
+ return $0*2;
+ }, i, double(i)/12);
+ }
+ printf("sum: %d\n", sum);
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_inlinejs3.out b/tests/core/test_inlinejs3.out
new file mode 100644
index 00000000..c293e80b
--- /dev/null
+++ b/tests/core/test_inlinejs3.out
@@ -0,0 +1,12 @@
+hello dere1
+hello dere2
+hello dere3
+hello dere4
+hello dere3
+hello dere4
+hello dere3
+hello dere4
+i: 0,0.00
+i: 1,0.08
+i: 2,0.17
+sum: 6
diff --git a/tests/core/test_intvars.in b/tests/core/test_intvars.in
new file mode 100644
index 00000000..7cf7df89
--- /dev/null
+++ b/tests/core/test_intvars.in
@@ -0,0 +1,50 @@
+
+ #include <stdio.h>
+ int global = 20;
+ int *far;
+ int main()
+ {
+ int x = 5;
+ int y = x+17;
+ int z = (y-1)/2; // Should stay an integer after division!
+ y += 1;
+ int w = x*3+4;
+ int k = w < 15 ? 99 : 101;
+ far = &k;
+ *far += global;
+ int i = k > 100; // Should be an int, not a bool!
+ int j = i << 6;
+ j >>= 1;
+ j = j ^ 5;
+ int h = 1;
+ h |= 0;
+ int p = h;
+ p &= 0;
+ printf("*%d,%d,%d,%d,%d,%d,%d,%d,%d*\n", x, y, z, w, k, i, j, h, p);
+
+ long hash = -1;
+ size_t perturb;
+ int ii = 0;
+ for (perturb = hash; ; perturb >>= 5) {
+ printf("%d:%d", ii, perturb);
+ ii++;
+ if (ii == 9) break;
+ printf(",");
+ }
+ printf("*\n");
+ printf("*%.1d,%.2d*\n", 56, 9);
+
+ // Fixed-point math on 64-bit ints. Tricky to support since we have no 64-bit shifts in JS
+ {
+ struct Fixed {
+ static int Mult(int a, int b) {
+ return ((long long)a * (long long)b) >> 16;
+ }
+ };
+ printf("fixed:%d\n", Fixed::Mult(150000, 140000));
+ }
+
+ printf("*%ld*%p\n", (long)21, &hash); // The %p should not enter an infinite loop!
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_intvars.out b/tests/core/test_intvars.out
new file mode 100644
index 00000000..9d1cada7
--- /dev/null
+++ b/tests/core/test_intvars.out
@@ -0,0 +1,5 @@
+*5,23,10,19,121,1,37,1,0*
+0:-1,1:134217727,2:4194303,3:131071,4:4095,5:127,6:3,7:0,8:0*
+*56,09*
+fixed:320434
+*21* \ No newline at end of file
diff --git a/tests/core/test_isdigit_l.in b/tests/core/test_isdigit_l.in
new file mode 100644
index 00000000..b94f618d
--- /dev/null
+++ b/tests/core/test_isdigit_l.in
@@ -0,0 +1,7 @@
+
+ #include <iostream>
+ int main() {
+ using namespace std;
+ use_facet<num_put<char> >(cout.getloc()).put(cout, cout, '0', 3.14159265);
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_isdigit_l.out b/tests/core/test_isdigit_l.out
new file mode 100644
index 00000000..2c0cac55
--- /dev/null
+++ b/tests/core/test_isdigit_l.out
@@ -0,0 +1 @@
+3.14159 \ No newline at end of file
diff --git a/tests/core/test_isnan.in b/tests/core/test_isnan.in
new file mode 100644
index 00000000..d5ca7a6e
--- /dev/null
+++ b/tests/core/test_isnan.in
@@ -0,0 +1,17 @@
+
+ #include <stdio.h>
+
+ int IsNaN(double x){
+ int rc; /* The value return */
+ volatile double y = x;
+ volatile double z = y;
+ rc = (y!=z);
+ return rc;
+ }
+
+ int main() {
+ double tests[] = { 1.0, 3.333, 1.0/0.0, 0.0/0.0, -1.0/0.0, -0, 0, -123123123, 12.0E200 };
+ for (int i = 0; i < sizeof(tests)/sizeof(double); i++)
+ printf("%d - %f - %d\n", i, tests[i], IsNaN(tests[i]));
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_isnan.out b/tests/core/test_isnan.out
new file mode 100644
index 00000000..b7e33f0e
--- /dev/null
+++ b/tests/core/test_isnan.out
@@ -0,0 +1,9 @@
+0 - 1.000000 - 0
+1 - 3.333000 - 0
+2 - inf - 0
+3 - nan - 1
+4 - -inf - 0
+5 - 0.000000 - 0
+6 - 0.000000 - 0
+7 - -123123123.000000 - 0
+8 - 1.2e+201 - 0
diff --git a/tests/core/test_istream.in b/tests/core/test_istream.in
new file mode 100644
index 00000000..9a9d1c9a
--- /dev/null
+++ b/tests/core/test_istream.in
@@ -0,0 +1,16 @@
+
+ #include <string>
+ #include <sstream>
+ #include <iostream>
+
+ int main()
+ {
+ std::string mystring("1 2 3");
+ std::istringstream is(mystring);
+ int one, two, three;
+
+ is >> one >> two >> three;
+
+ printf( "%i %i %i", one, two, three );
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_istream.out b/tests/core/test_istream.out
new file mode 100644
index 00000000..703ca85b
--- /dev/null
+++ b/tests/core/test_istream.out
@@ -0,0 +1 @@
+1 2 3 \ No newline at end of file
diff --git a/tests/core/test_iswdigit.in b/tests/core/test_iswdigit.in
new file mode 100644
index 00000000..cc1b4a74
--- /dev/null
+++ b/tests/core/test_iswdigit.in
@@ -0,0 +1,12 @@
+
+ #include <stdio.h>
+ #include <cctype>
+ #include <cwctype>
+
+ int main() {
+ using namespace std;
+ printf("%d ", isdigit('0'));
+ printf("%d ", iswdigit(L'0'));
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_iswdigit.out b/tests/core/test_iswdigit.out
new file mode 100644
index 00000000..92880af7
--- /dev/null
+++ b/tests/core/test_iswdigit.out
@@ -0,0 +1 @@
+1 1 \ No newline at end of file
diff --git a/tests/core/test_libcextra.in b/tests/core/test_libcextra.in
new file mode 100644
index 00000000..e0ff2f8e
--- /dev/null
+++ b/tests/core/test_libcextra.in
@@ -0,0 +1,13 @@
+
+ #include <stdio.h>
+ #include <wchar.h>
+
+ int main()
+ {
+ const wchar_t* wstr = L"Hello";
+
+ printf("wcslen: %d\n", wcslen(wstr));
+
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_libcextra.out b/tests/core/test_libcextra.out
new file mode 100644
index 00000000..d0191c32
--- /dev/null
+++ b/tests/core/test_libcextra.out
@@ -0,0 +1 @@
+wcslen: 5 \ No newline at end of file
diff --git a/tests/core/test_libgen.in b/tests/core/test_libgen.in
new file mode 100644
index 00000000..c7918a78
--- /dev/null
+++ b/tests/core/test_libgen.in
@@ -0,0 +1,41 @@
+
+ #include <stdio.h>
+ #include <libgen.h>
+
+ int main() {
+ char p1[16] = "/usr/lib", p1x[16] = "/usr/lib";
+ printf("%s -> ", p1);
+ printf("%s : %s\n", dirname(p1x), basename(p1));
+
+ char p2[16] = "/usr", p2x[16] = "/usr";
+ printf("%s -> ", p2);
+ printf("%s : %s\n", dirname(p2x), basename(p2));
+
+ char p3[16] = "/usr/", p3x[16] = "/usr/";
+ printf("%s -> ", p3);
+ printf("%s : %s\n", dirname(p3x), basename(p3));
+
+ char p4[16] = "/usr/lib///", p4x[16] = "/usr/lib///";
+ printf("%s -> ", p4);
+ printf("%s : %s\n", dirname(p4x), basename(p4));
+
+ char p5[16] = "/", p5x[16] = "/";
+ printf("%s -> ", p5);
+ printf("%s : %s\n", dirname(p5x), basename(p5));
+
+ char p6[16] = "///", p6x[16] = "///";
+ printf("%s -> ", p6);
+ printf("%s : %s\n", dirname(p6x), basename(p6));
+
+ char p7[16] = "/usr/../lib/..", p7x[16] = "/usr/../lib/..";
+ printf("%s -> ", p7);
+ printf("%s : %s\n", dirname(p7x), basename(p7));
+
+ char p8[16] = "", p8x[16] = "";
+ printf("(empty) -> %s : %s\n", dirname(p8x), basename(p8));
+
+ printf("(null) -> %s : %s\n", dirname(0), basename(0));
+
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_libgen.out b/tests/core/test_libgen.out
new file mode 100644
index 00000000..b29893a8
--- /dev/null
+++ b/tests/core/test_libgen.out
@@ -0,0 +1,9 @@
+/usr/lib -> /usr : lib
+/usr -> / : usr
+/usr/ -> / : usr
+/usr/lib/// -> /usr : lib
+/ -> / : /
+/// -> / : /
+/usr/../lib/.. -> /usr/../lib : ..
+(empty) -> . : .
+(null) -> . : .
diff --git a/tests/core/test_linked_list.in b/tests/core/test_linked_list.in
new file mode 100644
index 00000000..4ca978bf
--- /dev/null
+++ b/tests/core/test_linked_list.in
@@ -0,0 +1,42 @@
+
+ #include <stdio.h>
+ struct worker_args {
+ int value;
+ struct worker_args *next;
+ };
+ int main()
+ {
+ worker_args a;
+ worker_args b;
+ a.value = 60;
+ a.next = &b;
+ b.value = 900;
+ b.next = NULL;
+ worker_args* c = &a;
+ int total = 0;
+ while (c) {
+ total += c->value;
+ c = c->next;
+ }
+
+ // Chunk of em
+ worker_args chunk[10];
+ for (int i = 0; i < 9; i++) {
+ chunk[i].value = i*10;
+ chunk[i].next = &chunk[i+1];
+ }
+ chunk[9].value = 90;
+ chunk[9].next = &chunk[0];
+
+ c = chunk;
+ do {
+ total += c->value;
+ c = c->next;
+ } while (c != chunk);
+
+ printf("*%d,%d*\n", total, b.next);
+ // NULL *is* 0, in C/C++. No JS null! (null == 0 is false, etc.)
+
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_linked_list.out b/tests/core/test_linked_list.out
new file mode 100644
index 00000000..f3b615b1
--- /dev/null
+++ b/tests/core/test_linked_list.out
@@ -0,0 +1 @@
+*1410,0* \ No newline at end of file
diff --git a/tests/core/test_llrint.in b/tests/core/test_llrint.in
new file mode 100644
index 00000000..cbba8a21
--- /dev/null
+++ b/tests/core/test_llrint.in
@@ -0,0 +1,8 @@
+
+ #include <stdio.h>
+ #include <math.h>
+ int main() {
+ printf("%lld\n%lld\n%lld\n%lld\n", llrint(0.1), llrint(0.6), llrint(1.25), llrint(1099511627776.667));
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_llrint.out b/tests/core/test_llrint.out
new file mode 100644
index 00000000..80e9c908
--- /dev/null
+++ b/tests/core/test_llrint.out
@@ -0,0 +1,4 @@
+0
+1
+1
+1099511627777
diff --git a/tests/core/test_llvm_intrinsics.in b/tests/core/test_llvm_intrinsics.in
new file mode 100644
index 00000000..6c235bdf
--- /dev/null
+++ b/tests/core/test_llvm_intrinsics.in
@@ -0,0 +1,41 @@
+
+ #include <stdio.h>
+ #include <sys/types.h>
+
+ extern "C" {
+ extern unsigned short llvm_bswap_i16(unsigned short x);
+ extern unsigned int llvm_bswap_i32(unsigned int x);
+ extern int32_t llvm_ctlz_i32(int32_t x);
+ extern int64_t llvm_ctlz_i64(int64_t x);
+ extern int32_t llvm_cttz_i32(int32_t x);
+ extern int64_t llvm_cttz_i64(int64_t x);
+ extern int32_t llvm_ctpop_i32(int32_t x);
+ extern int64_t llvm_ctpop_i64(int64_t x);
+ extern int llvm_expect_i32(int x, int y);
+ }
+
+ int main(void) {
+ unsigned short x = 0xc8ef;
+ printf("%x,%x\n", x&0xff, x >> 8);
+ x = llvm_bswap_i16(x);
+ printf("%x,%x\n", x&0xff, x >> 8);
+
+ unsigned int y = 0xc5de158a;
+ printf("%x,%x,%x,%x\n", y&0xff, (y>>8)&0xff, (y>>16)&0xff, (y>>24)&0xff);
+ y = llvm_bswap_i32(y);
+ printf("%x,%x,%x,%x\n", y&0xff, (y>>8)&0xff, (y>>16)&0xff, (y>>24)&0xff);
+
+ printf("%d,%d\n", (int)llvm_ctlz_i64(((int64_t)1) << 40), llvm_ctlz_i32(1<<10));
+ printf("%d,%d\n", (int)llvm_cttz_i64(((int64_t)1) << 40), llvm_cttz_i32(1<<10));
+ printf("%d,%d\n", (int)llvm_ctpop_i64((0x3101ULL << 32) | 1), llvm_ctpop_i32(0x3101));
+ printf("%d\n", (int)llvm_ctpop_i32(-594093059));
+
+ printf("%d\n", llvm_expect_i32(x % 27, 3));
+
+ int64_t a = 1;
+ a = __builtin_bswap64(a);
+ printf("%lld\n", a);
+
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_llvm_intrinsics.out b/tests/core/test_llvm_intrinsics.out
new file mode 100644
index 00000000..659b3c21
--- /dev/null
+++ b/tests/core/test_llvm_intrinsics.out
@@ -0,0 +1,10 @@
+ef,c8
+c8,ef
+8a,15,de,c5
+c5,de,15,8a
+23,21
+40,10
+5,4
+22
+13
+72057594037927936
diff --git a/tests/core/test_llvm_used.in b/tests/core/test_llvm_used.in
new file mode 100644
index 00000000..e40ae09e
--- /dev/null
+++ b/tests/core/test_llvm_used.in
@@ -0,0 +1,14 @@
+
+ #include <stdio.h>
+ #include <emscripten.h>
+
+ extern "C" {
+ EMSCRIPTEN_KEEPALIVE void foobar(int x) {
+ printf("Worked! %d\n", x);
+ }
+ }
+
+ int main() {
+ emscripten_run_script("Module['_foobar'](10)");
+ return 0;
+ } \ No newline at end of file
diff --git a/tests/core/test_llvm_used.out b/tests/core/test_llvm_used.out
new file mode 100644
index 00000000..87ef2612
--- /dev/null
+++ b/tests/core/test_llvm_used.out
@@ -0,0 +1 @@
+Worked! 10
diff --git a/tests/core/test_llvmswitch.in b/tests/core/test_llvmswitch.in
new file mode 100644
index 00000000..64cfa652
--- /dev/null
+++ b/tests/core/test_llvmswitch.in
@@ -0,0 +1,24 @@
+
+ #include <stdio.h>
+ #include <string.h>
+
+ int switcher(int p)
+ {
+ switch(p) {
+ case 'a':
+ case 'b':
+ case 'c':
+ return p-1;
+ case -15:
+ return p+1;
+ }
+ return p;
+ }
+
+ int main( int argc, const char *argv[] ) {
+ unsigned int x = 0xfffffff1;
+ x >>= (argc-1); // force it to be unsigned for purpose of checking our switch comparison in signed/unsigned
+ printf("*%d,%d,%d,%d,%d,%d*\n", switcher('a'), switcher('b'), switcher('c'), switcher(x), switcher(-15), switcher('e'));
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_llvmswitch.out b/tests/core/test_llvmswitch.out
new file mode 100644
index 00000000..4647c7e1
--- /dev/null
+++ b/tests/core/test_llvmswitch.out
@@ -0,0 +1 @@
+*96,97,98,-14,-14,101* \ No newline at end of file
diff --git a/tests/core/test_longjmp.in b/tests/core/test_longjmp.in
new file mode 100644
index 00000000..4260ed15
--- /dev/null
+++ b/tests/core/test_longjmp.in
@@ -0,0 +1,34 @@
+
+ #include <stdio.h>
+ #include <setjmp.h>
+
+ static jmp_buf buf;
+
+ void second(void) {
+ printf("second\n");
+ longjmp(buf,-1);
+ }
+
+ void first(void) {
+ printf("first\n"); // prints
+ longjmp(buf,1); // jumps back to where setjmp was called - making setjmp now return 1
+ }
+
+ int main() {
+ volatile int x = 0;
+ int jmpval = setjmp(buf);
+ if (!jmpval) {
+ x++; // should be properly restored once longjmp jumps back
+ first(); // when executed, setjmp returns 1
+ printf("skipped\n"); // does not print
+ } else if (jmpval == 1) { // when first() jumps back, setjmp returns 1
+ printf("result: %d %d\n", x, jmpval); // prints
+ x++;
+ second(); // when executed, setjmp returns -1
+ } else if (jmpval == -1) { // when second() jumps back, setjmp returns -1
+ printf("result: %d %d\n", x, jmpval); // prints
+ }
+
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_longjmp.out b/tests/core/test_longjmp.out
new file mode 100644
index 00000000..4a412fef
--- /dev/null
+++ b/tests/core/test_longjmp.out
@@ -0,0 +1,4 @@
+first
+result: 1 1
+second
+result: 2 -1 \ No newline at end of file
diff --git a/tests/core/test_longjmp2.in b/tests/core/test_longjmp2.in
new file mode 100644
index 00000000..ef73c8ba
--- /dev/null
+++ b/tests/core/test_longjmp2.in
@@ -0,0 +1,37 @@
+
+ #include <setjmp.h>
+ #include <stdio.h>
+
+ typedef struct {
+ jmp_buf* jmp;
+ } jmp_state;
+
+ void stack_manipulate_func(jmp_state* s, int level) {
+ jmp_buf buf;
+
+ printf("Entering stack_manipulate_func, level: %d\n", level);
+
+ if (level == 0) {
+ s->jmp = &buf;
+ if (setjmp(*(s->jmp)) == 0) {
+ printf("Setjmp normal execution path, level: %d\n", level);
+ stack_manipulate_func(s, level + 1);
+ } else {
+ printf("Setjmp error execution path, level: %d\n", level);
+ }
+ } else {
+ printf("Perform longjmp at level %d\n", level);
+ longjmp(*(s->jmp), 1);
+ }
+
+ printf("Exiting stack_manipulate_func, level: %d\n", level);
+ }
+
+ int main(int argc, char *argv[]) {
+ jmp_state s;
+ s.jmp = NULL;
+ stack_manipulate_func(&s, 0);
+
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_longjmp2.out b/tests/core/test_longjmp2.out
new file mode 100644
index 00000000..82956215
--- /dev/null
+++ b/tests/core/test_longjmp2.out
@@ -0,0 +1,6 @@
+Entering stack_manipulate_func, level: 0
+Setjmp normal execution path, level: 0
+Entering stack_manipulate_func, level: 1
+Perform longjmp at level 1
+Setjmp error execution path, level: 0
+Exiting stack_manipulate_func, level: 0
diff --git a/tests/core/test_longjmp3.in b/tests/core/test_longjmp3.in
new file mode 100644
index 00000000..95fcf36c
--- /dev/null
+++ b/tests/core/test_longjmp3.in
@@ -0,0 +1,42 @@
+
+ #include <setjmp.h>
+ #include <stdio.h>
+
+ typedef struct {
+ jmp_buf* jmp;
+ } jmp_state;
+
+ void setjmp_func(jmp_state* s, int level) {
+ jmp_buf* prev_jmp = s->jmp;
+ jmp_buf c_jmp;
+
+ if (level == 2) {
+ printf("level is 2, perform longjmp!\n");
+ longjmp(*(s->jmp), 1);
+ }
+
+ if (setjmp(c_jmp) == 0) {
+ printf("setjmp normal execution path, level: %d\n", level);
+ s->jmp = &c_jmp;
+ setjmp_func(s, level + 1);
+ } else {
+ printf("setjmp exception execution path, level: %d\n", level);
+ if (prev_jmp) {
+ printf("prev_jmp is not empty, continue with longjmp!\n");
+ s->jmp = prev_jmp;
+ longjmp(*(s->jmp), 1);
+ }
+ }
+
+ printf("Exiting setjmp function, level: %d\n", level);
+ }
+
+ int main(int argc, char *argv[]) {
+ jmp_state s;
+ s.jmp = NULL;
+
+ setjmp_func(&s, 0);
+
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_longjmp3.out b/tests/core/test_longjmp3.out
new file mode 100644
index 00000000..c0d39cfb
--- /dev/null
+++ b/tests/core/test_longjmp3.out
@@ -0,0 +1,7 @@
+setjmp normal execution path, level: 0
+setjmp normal execution path, level: 1
+level is 2, perform longjmp!
+setjmp exception execution path, level: 1
+prev_jmp is not empty, continue with longjmp!
+setjmp exception execution path, level: 0
+Exiting setjmp function, level: 0
diff --git a/tests/core/test_longjmp4.in b/tests/core/test_longjmp4.in
new file mode 100644
index 00000000..ce27f751
--- /dev/null
+++ b/tests/core/test_longjmp4.in
@@ -0,0 +1,44 @@
+
+ #include <setjmp.h>
+ #include <stdio.h>
+
+ typedef struct {
+ jmp_buf* jmp;
+ } jmp_state;
+
+ void second_func(jmp_state* s);
+
+ void first_func(jmp_state* s) {
+ jmp_buf* prev_jmp = s->jmp;
+ jmp_buf c_jmp;
+ volatile int once = 0;
+
+ if (setjmp(c_jmp) == 0) {
+ printf("Normal execution path of first function!\n");
+
+ s->jmp = &c_jmp;
+ second_func(s);
+ } else {
+ printf("Exception execution path of first function! %d\n", once);
+
+ if (!once) {
+ printf("Calling longjmp the second time!\n");
+ once = 1;
+ longjmp(*(s->jmp), 1);
+ }
+ }
+ }
+
+ void second_func(jmp_state* s) {
+ longjmp(*(s->jmp), 1);
+ }
+
+ int main(int argc, char *argv[]) {
+ jmp_state s;
+ s.jmp = NULL;
+
+ first_func(&s);
+
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_longjmp4.out b/tests/core/test_longjmp4.out
new file mode 100644
index 00000000..53fdd41b
--- /dev/null
+++ b/tests/core/test_longjmp4.out
@@ -0,0 +1,4 @@
+Normal execution path of first function!
+Exception execution path of first function! 0
+Calling longjmp the second time!
+Exception execution path of first function! 1
diff --git a/tests/core/test_longjmp_exc.in b/tests/core/test_longjmp_exc.in
new file mode 100644
index 00000000..3fc07b85
--- /dev/null
+++ b/tests/core/test_longjmp_exc.in
@@ -0,0 +1,28 @@
+
+ #include <stdlib.h>
+ #include <stdio.h>
+ #include <setjmp.h>
+ #include <emscripten.h>
+
+ jmp_buf abortframe;
+
+ void dostuff(int a) {
+ printf("pre\n");
+ if (a != 42) emscripten_run_script("waka_waka()"); // this should fail, and never reach "never"
+ printf("never\n");
+
+ if (a == 100) {
+ longjmp (abortframe, -1);
+ }
+
+ if (setjmp(abortframe)) {
+ printf("got 100");
+ }
+ }
+
+ int main(int argc, char **argv) {
+ dostuff(argc);
+ exit(1);
+ return 1;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_longjmp_exc.out b/tests/core/test_longjmp_exc.out
new file mode 100644
index 00000000..b12dbd82
--- /dev/null
+++ b/tests/core/test_longjmp_exc.out
@@ -0,0 +1 @@
+waka_waka \ No newline at end of file
diff --git a/tests/core/test_longjmp_funcptr.in b/tests/core/test_longjmp_funcptr.in
new file mode 100644
index 00000000..e699bae6
--- /dev/null
+++ b/tests/core/test_longjmp_funcptr.in
@@ -0,0 +1,32 @@
+
+ #include <stdio.h>
+ #include <setjmp.h>
+
+ static jmp_buf buf;
+
+ void (*fp)() = NULL;
+
+ void second(void) {
+ printf("second\n"); // prints
+ longjmp(buf,1); // jumps back to where setjmp was called - making setjmp now return 1
+ }
+
+ void first(void) {
+ fp();
+ printf("first\n"); // does not print
+ }
+
+ int main(int argc, char **argv) {
+ fp = argc == 200 ? NULL : second;
+
+ volatile int x = 0;
+ if ( ! setjmp(buf) ) {
+ x++;
+ first(); // when executed, setjmp returns 0
+ } else { // when longjmp jumps back, setjmp returns 1
+ printf("main: %d\n", x); // prints
+ }
+
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_longjmp_funcptr.out b/tests/core/test_longjmp_funcptr.out
new file mode 100644
index 00000000..0e823e76
--- /dev/null
+++ b/tests/core/test_longjmp_funcptr.out
@@ -0,0 +1,2 @@
+second
+main: 1
diff --git a/tests/core/test_longjmp_repeat.in b/tests/core/test_longjmp_repeat.in
new file mode 100644
index 00000000..4476f8dd
--- /dev/null
+++ b/tests/core/test_longjmp_repeat.in
@@ -0,0 +1,15 @@
+
+ #include <stdio.h>
+ #include <setjmp.h>
+
+ static jmp_buf buf;
+
+ int main() {
+ volatile int x = 0;
+ printf("setjmp:%d\n", setjmp(buf));
+ x++;
+ printf("x:%d\n", x);
+ if (x < 4) longjmp(buf, x*2);
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_longjmp_repeat.out b/tests/core/test_longjmp_repeat.out
new file mode 100644
index 00000000..8f4183b9
--- /dev/null
+++ b/tests/core/test_longjmp_repeat.out
@@ -0,0 +1,8 @@
+setjmp:0
+x:1
+setjmp:2
+x:2
+setjmp:4
+x:3
+setjmp:6
+x:4
diff --git a/tests/core/test_longjmp_stacked.in b/tests/core/test_longjmp_stacked.in
new file mode 100644
index 00000000..19539561
--- /dev/null
+++ b/tests/core/test_longjmp_stacked.in
@@ -0,0 +1,44 @@
+
+ #include <stdio.h>
+ #include <setjmp.h>
+ #include <stdlib.h>
+ #include <string.h>
+
+ int bottom, top;
+
+ int run(int y) {
+ // confuse stack
+ char *s = (char*)alloca(100);
+ memset(s, 1, 100);
+ s[y] = y;
+ s[y/2] = y*2;
+ volatile int x = s[y];
+ top = (int)alloca(4);
+ if (x <= 2) return x;
+ jmp_buf buf;
+ printf("setjmp of %d\n", x);
+ if (setjmp(buf) == 0) {
+ printf("going\n");
+ x += run(x/2);
+ longjmp(buf, 1);
+ }
+ printf("back\n");
+ return x/2;
+ }
+
+ int main(int argc, char **argv) {
+ int sum = 0;
+ for (int i = 0; i < argc*2; i++) {
+ bottom = (int)alloca(4);
+ sum += run(10);
+ // scorch the earth
+ if (bottom < top) {
+ memset((void*)bottom, 1, top - bottom);
+ } else {
+ memset((void*)top, 1, bottom - top);
+ }
+ }
+ printf("%d\n", sum);
+ return sum;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_longjmp_stacked.out b/tests/core/test_longjmp_stacked.out
new file mode 100644
index 00000000..d16a8e7d
--- /dev/null
+++ b/tests/core/test_longjmp_stacked.out
@@ -0,0 +1,13 @@
+setjmp of 10
+going
+setjmp of 5
+going
+back
+back
+setjmp of 10
+going
+setjmp of 5
+going
+back
+back
+12
diff --git a/tests/core/test_loop.in b/tests/core/test_loop.in
new file mode 100644
index 00000000..9df45457
--- /dev/null
+++ b/tests/core/test_loop.in
@@ -0,0 +1,17 @@
+
+ #include <stdio.h>
+ int main()
+ {
+ int x = 5;
+ for (int i = 0; i < 6; i++) {
+ x += x*i;
+ if (x > 1000) {
+ if (x % 7 == 0) printf("cheez\n");
+ x /= 2;
+ break;
+ }
+ }
+ printf("*%d*\n", x);
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_loop.out b/tests/core/test_loop.out
new file mode 100644
index 00000000..428e01b6
--- /dev/null
+++ b/tests/core/test_loop.out
@@ -0,0 +1 @@
+*1800* \ No newline at end of file
diff --git a/tests/core/test_mainenv.in b/tests/core/test_mainenv.in
new file mode 100644
index 00000000..da434196
--- /dev/null
+++ b/tests/core/test_mainenv.in
@@ -0,0 +1,8 @@
+
+ #include <stdio.h>
+ int main(int argc, char **argv, char **envp)
+ {
+ printf("*%p*\n", envp);
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_mainenv.out b/tests/core/test_mainenv.out
new file mode 100644
index 00000000..abc8f766
--- /dev/null
+++ b/tests/core/test_mainenv.out
@@ -0,0 +1 @@
+*(nil)* \ No newline at end of file
diff --git a/tests/core/test_math.in b/tests/core/test_math.in
new file mode 100644
index 00000000..0685c178
--- /dev/null
+++ b/tests/core/test_math.in
@@ -0,0 +1,34 @@
+
+ #include <stdio.h>
+ #include <stdlib.h>
+ #include <cmath>
+ int main(int argc, char **argv)
+ {
+ printf("*%.2f,%.2f,%d", M_PI, -M_PI, (1/0.0) > 1e300); // could end up as infinity, or just a very very big number
+ printf(",%d", isfinite(NAN) != 0);
+ printf(",%d", isfinite(INFINITY) != 0);
+ printf(",%d", isfinite(-INFINITY) != 0);
+ printf(",%d", isfinite(12.3) != 0);
+ printf(",%d", isinf(NAN) != 0);
+ printf(",%d", isinf(INFINITY) != 0);
+ printf(",%d", isinf(-INFINITY) != 0);
+ printf(",%d", isinf(12.3) != 0);
+ div_t div_result = div(23, 10);
+ printf(",%d", div_result.quot);
+ printf(",%d", div_result.rem);
+ double sine = -1.0, cosine = -1.0;
+ sincos(0.0, &sine, &cosine);
+ printf(",%1.1lf", sine);
+ printf(",%1.1lf", cosine);
+ float fsine = -1.0f, fcosine = -1.0f;
+ sincosf(0.0, &fsine, &fcosine);
+ printf(",%1.1f", fsine);
+ printf(",%1.1f", fcosine);
+ fsine = sinf(1.1 + argc - 1);
+ fcosine = cosf(1.1 + argc - 1);
+ printf(",%1.1f", fsine);
+ printf(",%1.1f", fcosine);
+ printf("*\n");
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_math.out b/tests/core/test_math.out
new file mode 100644
index 00000000..6deb8df4
--- /dev/null
+++ b/tests/core/test_math.out
@@ -0,0 +1 @@
+*3.14,-3.14,1,0,0,0,1,0,1,1,0,2,3,0.0,1.0,0.0,1.0,0.9,0.5* \ No newline at end of file
diff --git a/tests/core/test_mathfuncptr.in b/tests/core/test_mathfuncptr.in
new file mode 100644
index 00000000..96e78401
--- /dev/null
+++ b/tests/core/test_mathfuncptr.in
@@ -0,0 +1,13 @@
+
+ #include <math.h>
+ #include <stdio.h>
+
+ int
+ main(int argc, char **argv) {
+ float (*fn)(float) = argc != 12 ? &sqrtf : &fabsf;
+ float (*fn2)(float) = argc != 13 ? &fabsf : &sqrtf;
+ float (*fn3)(float) = argc != 14 ? &erff : &fabsf;
+ printf("fn2(-5) = %d, fn(10) = %.2f, erf(10) = %.2f\n", (int)fn2(-5), fn(10), fn3(10));
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_mathfuncptr.out b/tests/core/test_mathfuncptr.out
new file mode 100644
index 00000000..166cc3da
--- /dev/null
+++ b/tests/core/test_mathfuncptr.out
@@ -0,0 +1 @@
+fn2(-5) = 5, fn(10) = 3.16, erf(10) = 1.00 \ No newline at end of file
diff --git a/tests/core/test_memcpy2.in b/tests/core/test_memcpy2.in
new file mode 100644
index 00000000..91e0b6a0
--- /dev/null
+++ b/tests/core/test_memcpy2.in
@@ -0,0 +1,22 @@
+
+ #include <stdio.h>
+ #include <string.h>
+ #include <assert.h>
+ int main() {
+ char buffer[256];
+ for (int i = 0; i < 10; i++) {
+ for (int j = 0; j < 10; j++) {
+ for (int k = 0; k < 35; k++) {
+ for (int t = 0; t < 256; t++) buffer[t] = t;
+ char *dest = buffer + i + 128;
+ char *src = buffer+j;
+ //printf("%d, %d, %d\n", i, j, k);
+ assert(memcpy(dest, src, k) == dest);
+ assert(memcmp(dest, src, k) == 0);
+ }
+ }
+ }
+ printf("ok.\n");
+ return 1;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_memcpy2.out b/tests/core/test_memcpy2.out
new file mode 100644
index 00000000..59f3f984
--- /dev/null
+++ b/tests/core/test_memcpy2.out
@@ -0,0 +1 @@
+ok. \ No newline at end of file
diff --git a/tests/core/test_memcpy_memcmp.in b/tests/core/test_memcpy_memcmp.in
new file mode 100644
index 00000000..c89d7ef6
--- /dev/null
+++ b/tests/core/test_memcpy_memcmp.in
@@ -0,0 +1,45 @@
+
+ #include <stdio.h>
+ #include <string.h>
+ #include <assert.h>
+
+ #define MAXX 48
+ void reset(unsigned char *buffer) {
+ for (int i = 0; i < MAXX; i++) buffer[i] = i+1;
+ }
+ void dump(unsigned char *buffer) {
+ for (int i = 0; i < MAXX-1; i++) printf("%2d,", buffer[i]);
+ printf("%d\n", buffer[MAXX-1]);
+ }
+ int main() {
+ unsigned char buffer[MAXX];
+ for (int i = MAXX/4; i < MAXX-MAXX/4; i++) {
+ for (int j = MAXX/4; j < MAXX-MAXX/4; j++) {
+ for (int k = 1; k < MAXX/4; k++) {
+ if (i == j) continue;
+ if (i < j && i+k > j) continue;
+ if (j < i && j+k > i) continue;
+ printf("[%d,%d,%d] ", i, j, k);
+ reset(buffer);
+ memcpy(buffer+i, buffer+j, k);
+ dump(buffer);
+ assert(memcmp(buffer+i, buffer+j, k) == 0);
+ buffer[i + k/2]++;
+ if (buffer[i + k/2] != 0) {
+ assert(memcmp(buffer+i, buffer+j, k) > 0);
+ } else {
+ assert(memcmp(buffer+i, buffer+j, k) < 0);
+ }
+ buffer[i + k/2]--;
+ buffer[j + k/2]++;
+ if (buffer[j + k/2] != 0) {
+ assert(memcmp(buffer+i, buffer+j, k) < 0);
+ } else {
+ assert(memcmp(buffer+i, buffer+j, k) > 0);
+ }
+ }
+ }
+ }
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_memcpy_memcmp.out b/tests/core/test_memcpy_memcmp.out
new file mode 100644
index 00000000..93420981
--- /dev/null
+++ b/tests/core/test_memcpy_memcmp.out
@@ -0,0 +1 @@
+6c9cdfe937383b79e52ca7a2cce83a21d9f5422c \ No newline at end of file
diff --git a/tests/core/test_memmove.in b/tests/core/test_memmove.in
new file mode 100644
index 00000000..690075d9
--- /dev/null
+++ b/tests/core/test_memmove.in
@@ -0,0 +1,10 @@
+
+ #include <stdio.h>
+ #include <string.h>
+ int main() {
+ char str[] = "memmove can be very useful....!";
+ memmove (str+20, str+15, 11);
+ puts(str);
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_memmove.out b/tests/core/test_memmove.out
new file mode 100644
index 00000000..e2a1ac2f
--- /dev/null
+++ b/tests/core/test_memmove.out
@@ -0,0 +1 @@
+memmove can be very very useful \ No newline at end of file
diff --git a/tests/core/test_memmove2.in b/tests/core/test_memmove2.in
new file mode 100644
index 00000000..087f59b8
--- /dev/null
+++ b/tests/core/test_memmove2.in
@@ -0,0 +1,24 @@
+
+ #include <stdio.h>
+ #include <string.h>
+ #include <assert.h>
+ int main() {
+ int sum = 0;
+ char buffer[256];
+ for (int i = 0; i < 10; i++) {
+ for (int j = 0; j < 10; j++) {
+ for (int k = 0; k < 35; k++) {
+ for (int t = 0; t < 256; t++) buffer[t] = t;
+ char *dest = buffer + i;
+ char *src = buffer + j;
+ if (dest == src) continue;
+ //printf("%d, %d, %d\n", i, j, k);
+ assert(memmove(dest, src, k) == dest);
+ for (int t = 0; t < 256; t++) sum += buffer[t];
+ }
+ }
+ }
+ printf("final: %d.\n", sum);
+ return 1;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_memmove2.out b/tests/core/test_memmove2.out
new file mode 100644
index 00000000..0e06b2e7
--- /dev/null
+++ b/tests/core/test_memmove2.out
@@ -0,0 +1 @@
+final: -403200. \ No newline at end of file
diff --git a/tests/core/test_memmove3.in b/tests/core/test_memmove3.in
new file mode 100644
index 00000000..a28267cd
--- /dev/null
+++ b/tests/core/test_memmove3.in
@@ -0,0 +1,10 @@
+
+ #include <stdio.h>
+ #include <string.h>
+ int main() {
+ char str[] = "memmove can be vvery useful....!";
+ memmove(str+15, str+16, 17);
+ puts(str);
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_memmove3.out b/tests/core/test_memmove3.out
new file mode 100644
index 00000000..1adadcc2
--- /dev/null
+++ b/tests/core/test_memmove3.out
@@ -0,0 +1 @@
+memmove can be very useful....! \ No newline at end of file
diff --git a/tests/core/test_mmap.in b/tests/core/test_mmap.in
new file mode 100644
index 00000000..46400278
--- /dev/null
+++ b/tests/core/test_mmap.in
@@ -0,0 +1,38 @@
+
+ #include <stdio.h>
+ #include <sys/mman.h>
+ #include <assert.h>
+
+ int main(int argc, char *argv[]) {
+ for (int i = 0; i < 10; i++) {
+ int* map = (int*)mmap(0, 5000, PROT_READ | PROT_WRITE,
+ MAP_SHARED | MAP_ANON, -1, 0);
+ /* TODO: Should we align to 4k?
+ assert(((int)map) % 4096 == 0); // aligned
+ */
+ assert(munmap(map, 5000) == 0);
+ }
+
+ const int NUM_BYTES = 8 * 1024 * 1024;
+ const int NUM_INTS = NUM_BYTES / sizeof(int);
+
+ int* map = (int*)mmap(0, NUM_BYTES, PROT_READ | PROT_WRITE,
+ MAP_SHARED | MAP_ANON, -1, 0);
+ assert(map != MAP_FAILED);
+
+ int i;
+
+ for (i = 0; i < NUM_INTS; i++) {
+ map[i] = i;
+ }
+
+ for (i = 0; i < NUM_INTS; i++) {
+ assert(map[i] == i);
+ }
+
+ assert(munmap(map, NUM_BYTES) == 0);
+
+ printf("hello,world");
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_mmap.out b/tests/core/test_mmap.out
new file mode 100644
index 00000000..f2fff68f
--- /dev/null
+++ b/tests/core/test_mmap.out
@@ -0,0 +1 @@
+hello,world \ No newline at end of file
diff --git a/tests/core/test_mod_globalstruct.in b/tests/core/test_mod_globalstruct.in
new file mode 100644
index 00000000..3e1ed493
--- /dev/null
+++ b/tests/core/test_mod_globalstruct.in
@@ -0,0 +1,19 @@
+
+ #include <stdio.h>
+
+ struct malloc_params {
+ size_t magic, page_size;
+ };
+
+ malloc_params mparams;
+
+ #define SIZE_T_ONE ((size_t)1)
+ #define page_align(S) (((S) + (mparams.page_size - SIZE_T_ONE)) & ~(mparams.page_size - SIZE_T_ONE))
+
+ int main()
+ {
+ mparams.page_size = 4096;
+ printf("*%d,%d,%d,%d*\n", mparams.page_size, page_align(1000), page_align(6000), page_align(66474));
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_mod_globalstruct.out b/tests/core/test_mod_globalstruct.out
new file mode 100644
index 00000000..3be9bc19
--- /dev/null
+++ b/tests/core/test_mod_globalstruct.out
@@ -0,0 +1 @@
+*4096,4096,8192,69632* \ No newline at end of file
diff --git a/tests/core/test_multiexception.in b/tests/core/test_multiexception.in
new file mode 100644
index 00000000..93795388
--- /dev/null
+++ b/tests/core/test_multiexception.in
@@ -0,0 +1,48 @@
+
+#include <stdio.h>
+
+static int current_exception_id = 0;
+
+typedef struct {
+int jmp;
+} jmp_state;
+
+void setjmp_func(jmp_state* s, int level) {
+int prev_jmp = s->jmp;
+int c_jmp;
+
+if (level == 2) {
+ printf("level is 2, perform longjmp!\n");
+ throw 1;
+}
+
+c_jmp = current_exception_id++;
+try {
+ printf("setjmp normal execution path, level: %d, prev_jmp: %d\n", level, prev_jmp);
+ s->jmp = c_jmp;
+ setjmp_func(s, level + 1);
+} catch (int catched_eid) {
+ printf("caught %d\n", catched_eid);
+ if (catched_eid == c_jmp) {
+ printf("setjmp exception execution path, level: %d, prev_jmp: %d\n", level, prev_jmp);
+ if (prev_jmp != -1) {
+ printf("prev_jmp is not empty, continue with longjmp!\n");
+ s->jmp = prev_jmp;
+ throw s->jmp;
+ }
+ } else {
+ throw;
+ }
+}
+
+printf("Exiting setjmp function, level: %d, prev_jmp: %d\n", level, prev_jmp);
+}
+
+int main(int argc, char *argv[]) {
+jmp_state s;
+s.jmp = -1;
+
+setjmp_func(&s, 0);
+
+return 0;
+}
diff --git a/tests/core/test_multiexception.out b/tests/core/test_multiexception.out
new file mode 100644
index 00000000..33efe46e
--- /dev/null
+++ b/tests/core/test_multiexception.out
@@ -0,0 +1,9 @@
+setjmp normal execution path, level: 0, prev_jmp: -1
+setjmp normal execution path, level: 1, prev_jmp: 0
+level is 2, perform longjmp!
+caught 1
+setjmp exception execution path, level: 1, prev_jmp: 0
+prev_jmp is not empty, continue with longjmp!
+caught 0
+setjmp exception execution path, level: 0, prev_jmp: -1
+Exiting setjmp function, level: 0, prev_jmp: -1
diff --git a/tests/core/test_negative_zero.in b/tests/core/test_negative_zero.in
new file mode 100644
index 00000000..8e1fcc0b
--- /dev/null
+++ b/tests/core/test_negative_zero.in
@@ -0,0 +1,30 @@
+
+ #include <stdio.h>
+ #include <math.h>
+
+ int main() {
+ #define TEST(x, y) \
+ printf("%.2f, %.2f ==> %.2f\n", x, y, copysign(x, y));
+ TEST( 5.0f, 5.0f);
+ TEST( 5.0f, -5.0f);
+ TEST(-5.0f, 5.0f);
+ TEST(-5.0f, -5.0f);
+ TEST( 5.0f, 4.0f);
+ TEST( 5.0f, -4.0f);
+ TEST(-5.0f, 4.0f);
+ TEST(-5.0f, -4.0f);
+ TEST( 0.0f, 5.0f);
+ TEST( 0.0f, -5.0f);
+ TEST(-0.0f, 5.0f);
+ TEST(-0.0f, -5.0f);
+ TEST( 5.0f, 0.0f);
+ TEST( 5.0f, -0.0f);
+ TEST(-5.0f, 0.0f);
+ TEST(-5.0f, -0.0f);
+ TEST( 0.0f, 0.0f);
+ TEST( 0.0f, -0.0f);
+ TEST(-0.0f, 0.0f);
+ TEST(-0.0f, -0.0f);
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_negative_zero.out b/tests/core/test_negative_zero.out
new file mode 100644
index 00000000..5d792ffb
--- /dev/null
+++ b/tests/core/test_negative_zero.out
@@ -0,0 +1,20 @@
+5.00, 5.00 ==> 5.00
+5.00, -5.00 ==> -5.00
+-5.00, 5.00 ==> 5.00
+-5.00, -5.00 ==> -5.00
+5.00, 4.00 ==> 5.00
+5.00, -4.00 ==> -5.00
+-5.00, 4.00 ==> 5.00
+-5.00, -4.00 ==> -5.00
+0.00, 5.00 ==> 0.00
+0.00, -5.00 ==> -0.00
+-0.00, 5.00 ==> 0.00
+-0.00, -5.00 ==> -0.00
+5.00, 0.00 ==> 5.00
+5.00, -0.00 ==> -5.00
+-5.00, 0.00 ==> 5.00
+-5.00, -0.00 ==> -5.00
+0.00, 0.00 ==> 0.00
+0.00, -0.00 ==> -0.00
+-0.00, 0.00 ==> 0.00
+-0.00, -0.00 ==> -0.00
diff --git a/tests/core/test_perrar.in b/tests/core/test_perrar.in
new file mode 100644
index 00000000..e15c583a
--- /dev/null
+++ b/tests/core/test_perrar.in
@@ -0,0 +1,13 @@
+
+ #include <sys/types.h>
+ #include <sys/stat.h>
+ #include <fcntl.h>
+ #include <stdio.h>
+
+ int main( int argc, char** argv ){
+ int retval = open( "NonExistingFile", O_RDONLY );
+ if( retval == -1 )
+ perror( "Cannot open NonExistingFile" );
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_perrar.out b/tests/core/test_perrar.out
new file mode 100644
index 00000000..0de5f448
--- /dev/null
+++ b/tests/core/test_perrar.out
@@ -0,0 +1 @@
+Cannot open NonExistingFile: No such file or directory
diff --git a/tests/core/test_phiundef.in b/tests/core/test_phiundef.in
new file mode 100644
index 00000000..cf4b0f18
--- /dev/null
+++ b/tests/core/test_phiundef.in
@@ -0,0 +1,33 @@
+
+#include <stdlib.h>
+#include <stdio.h>
+
+static int state;
+
+struct my_struct {
+union {
+ struct {
+ unsigned char a;
+ unsigned char b;
+ } c;
+ unsigned int d;
+} e;
+unsigned int f;
+};
+
+int main(int argc, char **argv) {
+ struct my_struct r;
+
+ state = 0;
+
+ for (int i=0;i<argc+10;i++)
+ {
+ if (state % 2 == 0)
+ r.e.c.a = 3;
+ else
+ printf("%d\n", r.e.c.a);
+ state++;
+ }
+ return 0;
+}
+ \ No newline at end of file
diff --git a/tests/core/test_phiundef.out b/tests/core/test_phiundef.out
new file mode 100644
index 00000000..3b04a039
--- /dev/null
+++ b/tests/core/test_phiundef.out
@@ -0,0 +1,5 @@
+3
+3
+3
+3
+3
diff --git a/tests/core/test_poll.in b/tests/core/test_poll.in
new file mode 100644
index 00000000..3fb0ebc9
--- /dev/null
+++ b/tests/core/test_poll.in
@@ -0,0 +1,30 @@
+
+ #include <stdio.h>
+ #include <errno.h>
+ #include <fcntl.h>
+ #include <poll.h>
+
+ int main() {
+ struct pollfd multi[5];
+ multi[0].fd = open("/file", O_RDONLY, 0777);
+ multi[1].fd = open("/device", O_RDONLY, 0777);
+ multi[2].fd = 123;
+ multi[3].fd = open("/file", O_RDONLY, 0777);
+ multi[4].fd = open("/file", O_RDONLY, 0777);
+ multi[0].events = POLLIN | POLLOUT | POLLNVAL | POLLERR;
+ multi[1].events = POLLIN | POLLOUT | POLLNVAL | POLLERR;
+ multi[2].events = POLLIN | POLLOUT | POLLNVAL | POLLERR;
+ multi[3].events = 0x00;
+ multi[4].events = POLLOUT | POLLNVAL | POLLERR;
+
+ printf("ret: %d\n", poll(multi, 5, 123));
+ printf("errno: %d\n", errno);
+ printf("multi[0].revents: %d\n", multi[0].revents == (POLLIN | POLLOUT));
+ printf("multi[1].revents: %d\n", multi[1].revents == (POLLIN | POLLOUT));
+ printf("multi[2].revents: %d\n", multi[2].revents == POLLNVAL);
+ printf("multi[3].revents: %d\n", multi[3].revents == 0);
+ printf("multi[4].revents: %d\n", multi[4].revents == POLLOUT);
+
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_poll.out b/tests/core/test_poll.out
new file mode 100644
index 00000000..8ffd3264
--- /dev/null
+++ b/tests/core/test_poll.out
@@ -0,0 +1,7 @@
+ret: 4
+errno: 0
+multi[0].revents: 1
+multi[1].revents: 1
+multi[2].revents: 1
+multi[3].revents: 1
+multi[4].revents: 1
diff --git a/tests/core/test_polymorph.in b/tests/core/test_polymorph.in
new file mode 100644
index 00000000..2faa1935
--- /dev/null
+++ b/tests/core/test_polymorph.in
@@ -0,0 +1,34 @@
+
+ #include <stdio.h>
+ struct Pure {
+ virtual int implme() = 0;
+ };
+ struct Parent : Pure {
+ virtual int getit() { return 11; };
+ int implme() { return 32; }
+ };
+ struct Child : Parent {
+ int getit() { return 74; }
+ int implme() { return 1012; }
+ };
+
+ struct Other {
+ int one() { return 11; }
+ int two() { return 22; }
+ };
+
+ int main()
+ {
+ Parent *x = new Parent();
+ Parent *y = new Child();
+ printf("*%d,%d,%d,%d*\n", x->getit(), y->getit(), x->implme(), y->implme());
+
+ Other *o = new Other;
+ int (Other::*Ls)() = &Other::one;
+ printf("*%d*\n", (o->*(Ls))());
+ Ls = &Other::two;
+ printf("*%d*\n", (o->*(Ls))());
+
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_polymorph.out b/tests/core/test_polymorph.out
new file mode 100644
index 00000000..0d036bf0
--- /dev/null
+++ b/tests/core/test_polymorph.out
@@ -0,0 +1,3 @@
+*11,74,32,1012*
+*11*
+*22* \ No newline at end of file
diff --git a/tests/core/test_printf_2.in b/tests/core/test_printf_2.in
new file mode 100644
index 00000000..ef94aec1
--- /dev/null
+++ b/tests/core/test_printf_2.in
@@ -0,0 +1,17 @@
+
+ #include <stdio.h>
+
+ int main() {
+ char c = '1';
+ short s = 2;
+ int i = 3;
+ long long l = 4;
+ float f = 5.5;
+ double d = 6.6;
+
+ printf("%c,%hd,%d,%lld,%.1f,%.1llf\n", c, s, i, l, f, d);
+ printf("%#x,%#x\n", 1, 0);
+
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_printf_2.out b/tests/core/test_printf_2.out
new file mode 100644
index 00000000..002cd93a
--- /dev/null
+++ b/tests/core/test_printf_2.out
@@ -0,0 +1,2 @@
+1,2,3,4,5.5,6.6
+0x1,0
diff --git a/tests/core/test_printf_more.in b/tests/core/test_printf_more.in
new file mode 100644
index 00000000..b8e3ba61
--- /dev/null
+++ b/tests/core/test_printf_more.in
@@ -0,0 +1,13 @@
+
+ #include <stdio.h>
+ int main() {
+ int size = snprintf(NULL, 0, "%s %d %.2f\n", "me and myself", 25, 1.345);
+ char buf[size];
+ snprintf(buf, size, "%s %d %.2f\n", "me and myself", 25, 1.345);
+ printf("%d : %s\n", size, buf);
+ char *buff = NULL;
+ asprintf(&buff, "%d waka %d\n", 21, 95);
+ puts(buff);
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_printf_more.out b/tests/core/test_printf_more.out
new file mode 100644
index 00000000..e31f1d50
--- /dev/null
+++ b/tests/core/test_printf_more.out
@@ -0,0 +1,2 @@
+22 : me and myself 25 1.34
+21 waka 95
diff --git a/tests/core/test_ptrtoint.in b/tests/core/test_ptrtoint.in
new file mode 100644
index 00000000..be7214e8
--- /dev/null
+++ b/tests/core/test_ptrtoint.in
@@ -0,0 +1,16 @@
+
+ #include <stdio.h>
+
+ int main( int argc, const char *argv[] ) {
+ char *a = new char[10];
+ char *a0 = a+0;
+ char *a5 = a+5;
+ int *b = new int[10];
+ int *b0 = b+0;
+ int *b5 = b+5;
+ int c = (int)b5-(int)b0; // Emscripten should warn!
+ int d = (int)b5-(int)b0; // Emscripten should warn!
+ printf("*%d*\n", (int)a5-(int)a0);
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_ptrtoint.out b/tests/core/test_ptrtoint.out
new file mode 100644
index 00000000..770e08e0
--- /dev/null
+++ b/tests/core/test_ptrtoint.out
@@ -0,0 +1 @@
+*5* \ No newline at end of file
diff --git a/tests/core/test_regex.in b/tests/core/test_regex.in
new file mode 100644
index 00000000..a7ceb7a3
--- /dev/null
+++ b/tests/core/test_regex.in
@@ -0,0 +1,37 @@
+// This is from http://pic.dhe.ibm.com/infocenter/iseries/v7r1m0/index.jsp?topic=%2Frtref%2Fregexec.htm
+ #include <regex.h>
+ #include <stdio.h>
+ #include <stdlib.h>
+
+ int main(void)
+ {
+ regex_t preg;
+ const char *string = "a very simple simple simple string";
+ const char *pattern = "\\(sim[a-z]le\\) \\1";
+ int rc;
+ size_t nmatch = 2;
+ regmatch_t pmatch[2];
+
+ if (0 != (rc = regcomp(&preg, pattern, 0))) {
+ printf("regcomp() failed, returning nonzero (%d)\n", rc);
+ exit(EXIT_FAILURE);
+ }
+
+ if (0 != (rc = regexec(&preg, string, nmatch, pmatch, 0))) {
+ printf("Failed to match '%s' with '%s',returning %d.\n",
+ string, pattern, rc);
+ }
+ else {
+ printf("With the whole expression, "
+ "a matched substring \"%.*s\" is found at position %d to %d.\n",
+ pmatch[0].rm_eo - pmatch[0].rm_so, &string[pmatch[0].rm_so],
+ pmatch[0].rm_so, pmatch[0].rm_eo - 1);
+ printf("With the sub-expression, "
+ "a matched substring \"%.*s\" is found at position %d to %d.\n",
+ pmatch[1].rm_eo - pmatch[1].rm_so, &string[pmatch[1].rm_so],
+ pmatch[1].rm_so, pmatch[1].rm_eo - 1);
+ }
+ regfree(&preg);
+ return 0;
+ }
+
diff --git a/tests/core/test_regex.out b/tests/core/test_regex.out
new file mode 100644
index 00000000..f238d2e3
--- /dev/null
+++ b/tests/core/test_regex.out
@@ -0,0 +1,2 @@
+With the whole expression, a matched substring "simple simple" is found at position 7 to 19.
+With the sub-expression, a matched substring "simple" is found at position 7 to 12. \ No newline at end of file
diff --git a/tests/core/test_reinterpreted_ptrs.in b/tests/core/test_reinterpreted_ptrs.in
new file mode 100644
index 00000000..e5e257e0
--- /dev/null
+++ b/tests/core/test_reinterpreted_ptrs.in
@@ -0,0 +1,41 @@
+
+#include <stdio.h>
+
+class Foo {
+private:
+ float bar;
+public:
+ int baz;
+
+ Foo(): bar(0), baz(4711) {};
+
+ int getBar() const;
+};
+
+int Foo::getBar() const {
+ return this->bar;
+};
+
+const Foo *magic1 = reinterpret_cast<Foo*>(0xDEAD111F);
+const Foo *magic2 = reinterpret_cast<Foo*>(0xDEAD888F);
+
+static void runTest() {
+
+ const Foo *a = new Foo();
+ const Foo *b = a;
+
+ if (a->getBar() == 0) {
+ if (a->baz == 4712)
+ b = magic1;
+ else
+ b = magic2;
+ }
+
+ printf("%s\n", (b == magic1 ? "magic1" : (b == magic2 ? "magic2" : "neither")));
+};
+
+extern "C" {
+ int main(int argc, char **argv) {
+ runTest();
+ }
+}
diff --git a/tests/core/test_reinterpreted_ptrs.out b/tests/core/test_reinterpreted_ptrs.out
new file mode 100644
index 00000000..36033502
--- /dev/null
+++ b/tests/core/test_reinterpreted_ptrs.out
@@ -0,0 +1 @@
+magic2 \ No newline at end of file
diff --git a/tests/core/test_rounding.in b/tests/core/test_rounding.in
new file mode 100644
index 00000000..63960ac4
--- /dev/null
+++ b/tests/core/test_rounding.in
@@ -0,0 +1,29 @@
+
+ #include <stdio.h>
+ #include <math.h>
+
+ int main()
+ {
+ printf("%.1f ", round(1.4));
+ printf("%.1f ", round(1.6));
+ printf("%.1f ", round(-1.4));
+ printf("%.1f ", round(-1.6));
+
+ printf("%.1f ", round(1.5));
+ printf("%.1f ", round(2.5));
+ printf("%.1f ", round(-1.5));
+ printf("%.1f ", round(-2.5));
+
+ printf("%ld ", lrint(1.4));
+ printf("%ld ", lrint(1.6));
+ printf("%ld ", lrint(-1.4));
+ printf("%ld ", lrint(-1.6));
+
+ printf("%ld ", lrint(1.5));
+ printf("%ld ", lrint(2.5));
+ printf("%ld ", lrint(-1.5));
+ printf("%ld ", lrint(-2.5));
+
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_rounding.out b/tests/core/test_rounding.out
new file mode 100644
index 00000000..b826ceab
--- /dev/null
+++ b/tests/core/test_rounding.out
@@ -0,0 +1 @@
+1.0 2.0 -1.0 -2.0 2.0 3.0 -2.0 -3.0 1 2 -1 -2 2 2 -2 -2 \ No newline at end of file
diff --git a/tests/core/test_simd.in b/tests/core/test_simd.in
new file mode 100644
index 00000000..978ea96a
--- /dev/null
+++ b/tests/core/test_simd.in
@@ -0,0 +1,61 @@
+
+#include <stdio.h>
+
+#include <emscripten/vector.h>
+
+static inline float32x4 __attribute__((always_inline))
+_mm_set_ps(const float __Z, const float __Y, const float __X, const float __W)
+{
+ return (float32x4){ __W, __X, __Y, __Z };
+}
+
+static __inline__ float32x4 __attribute__((__always_inline__))
+_mm_setzero_ps(void)
+{
+ return (float32x4){ 0.0, 0.0, 0.0, 0.0 };
+}
+
+int main(int argc, char **argv) {
+ float data[8];
+ for (int i = 0; i < 32; i++) data[i] = (1+i+argc)*(2+i+argc*argc); // confuse optimizer
+ {
+ float32x4 *a = (float32x4*)&data[0];
+ float32x4 *b = (float32x4*)&data[4];
+ float32x4 c, d;
+ c = *a;
+ d = *b;
+ printf("1floats! %d, %d, %d, %d %d, %d, %d, %d\n", (int)c[0], (int)c[1], (int)c[2], (int)c[3], (int)d[0], (int)d[1], (int)d[2], (int)d[3]);
+ c = c+d;
+ printf("2floats! %d, %d, %d, %d %d, %d, %d, %d\n", (int)c[0], (int)c[1], (int)c[2], (int)c[3], (int)d[0], (int)d[1], (int)d[2], (int)d[3]);
+ d = c*d;
+ printf("3floats! %d, %d, %d, %d %d, %d, %d, %d\n", (int)c[0], (int)c[1], (int)c[2], (int)c[3], (int)d[0], (int)d[1], (int)d[2], (int)d[3]);
+ c = _mm_setzero_ps();
+ printf("zeros %d, %d, %d, %d\n", (int)c[0], (int)c[1], (int)c[2], (int)c[3]);
+ }
+ {
+ int32x4 *a = (int32x4*)&data[0];
+ int32x4 *b = (int32x4*)&data[4];
+ int32x4 c, d, e, f;
+ c = *a;
+ d = *b;
+ printf("4ints! %d, %d, %d, %d %d, %d, %d, %d\n", c[0], c[1], c[2], c[3], d[0], d[1], d[2], d[3]);
+ e = c+d;
+ f = c-d;
+ printf("5ints! %d, %d, %d, %d %d, %d, %d, %d\n", e[0], e[1], e[2], e[3], f[0], f[1], f[2], f[3]);
+ e = c&d;
+ f = c|d;
+ e = ~c&d;
+ f = c^d;
+ printf("5intops! %d, %d, %d, %d %d, %d, %d, %d\n", e[0], e[1], e[2], e[3], f[0], f[1], f[2], f[3]);
+ }
+ {
+ float32x4 c, d, e, f;
+ c = _mm_set_ps(9.0, 4.0, 0, -9.0);
+ d = _mm_set_ps(10.0, 14.0, -12, -2.0);
+ printf("6floats! %d, %d, %d, %d %d, %d, %d, %d\n", (int)c[0], (int)c[1], (int)c[2], (int)c[3], (int)d[0], (int)d[1], (int)d[2], (int)d[3]);
+ printf("7calcs: %d\n", emscripten_float32x4_signmask(c)); // TODO: just not just compilation but output as well
+ }
+
+ return 0;
+}
+ \ No newline at end of file
diff --git a/tests/core/test_simd.out b/tests/core/test_simd.out
new file mode 100644
index 00000000..08ca3738
--- /dev/null
+++ b/tests/core/test_simd.out
@@ -0,0 +1,8 @@
+1floats! 6, 12, 20, 30 42, 56, 72, 90
+2floats! 48, 68, 92, 120 42, 56, 72, 90
+3floats! 48, 68, 92, 120 2016, 3808, 6624, 10800
+zeros 0, 0, 0, 0
+4ints! 1086324736, 1094713344, 1101004800, 1106247680 1109917696, 1113587712, 1116733440, 1119092736
+5ints! -2098724864, -2086666240, -2077229056, -2069626880 -23592960, -18874368, -15728640, -12845056
+5intops! 36175872, 35651584, 34603008, 33816576 48758784, 52428800, 53477376, 54788096
+6floats! -9, 0, 4, 9 -2, -12, 14, 10
diff --git a/tests/core/test_simd2.in b/tests/core/test_simd2.in
new file mode 100644
index 00000000..97b1d841
--- /dev/null
+++ b/tests/core/test_simd2.in
@@ -0,0 +1,39 @@
+
+ #include <stdio.h>
+
+ typedef float __m128 __attribute__ ((__vector_size__ (16)));
+
+ static inline __m128 __attribute__((always_inline))
+ _mm_set_ps(const float __Z, const float __Y, const float __X, const float __W)
+ {
+ return (__m128){ __W, __X, __Y, __Z };
+ }
+
+ static inline void __attribute__((always_inline))
+ _mm_store_ps(float *__P, __m128 __A)
+ {
+ *(__m128 *)__P = __A;
+ }
+
+ static inline __m128 __attribute__((always_inline))
+ _mm_add_ps(__m128 __A, __m128 __B)
+ {
+ return __A + __B;
+ }
+
+ using namespace std;
+
+ int main(int argc, char ** argv) {
+ float __attribute__((__aligned__(16))) ar[4];
+ __m128 v1 = _mm_set_ps(9.0, 4.0, 0, -9.0);
+ __m128 v2 = _mm_set_ps(7.0, 3.0, 2.5, 1.0);
+ __m128 v3 = _mm_add_ps(v1, v2);
+ _mm_store_ps(ar, v3);
+
+ for (int i = 0; i < 4; i++) {
+ printf("%f\n", ar[i]);
+ }
+
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_simd2.out b/tests/core/test_simd2.out
new file mode 100644
index 00000000..4b01ec86
--- /dev/null
+++ b/tests/core/test_simd2.out
@@ -0,0 +1,4 @@
+-8.000000
+2.500000
+7.000000
+16.000000
diff --git a/tests/core/test_simd3.in b/tests/core/test_simd3.in
new file mode 100644
index 00000000..462370e7
--- /dev/null
+++ b/tests/core/test_simd3.in
@@ -0,0 +1,471 @@
+
+ #include <iostream>
+ #include <emmintrin.h>
+ #include <assert.h>
+ #include <stdint.h>
+ #include <bitset>
+
+ using namespace std;
+
+ void testSetPs() {
+ float __attribute__((__aligned__(16))) ar[4];
+ __m128 v = _mm_set_ps(1.0, 2.0, 3.0, 4.0);
+ _mm_store_ps(ar, v);
+ assert(ar[0] == 4.0);
+ assert(ar[1] == 3.0);
+ assert(ar[2] == 2.0);
+ assert(ar[3] == 1.0);
+ }
+
+ void testSet1Ps() {
+ float __attribute__((__aligned__(16))) ar[4];
+ __m128 v = _mm_set1_ps(5.5);
+ _mm_store_ps(ar, v);
+ assert(ar[0] == 5.5);
+ assert(ar[1] == 5.5);
+ assert(ar[2] == 5.5);
+ assert(ar[3] == 5.5);
+ }
+
+ void testSetZeroPs() {
+ float __attribute__((__aligned__(16))) ar[4];
+ __m128 v = _mm_setzero_ps();
+ _mm_store_ps(ar, v);
+ assert(ar[0] == 0);
+ assert(ar[1] == 0);
+ assert(ar[2] == 0);
+ assert(ar[3] == 0);
+ }
+
+ void testSetEpi32() {
+ int32_t __attribute__((__aligned__(16))) ar[4];
+ __m128i v = _mm_set_epi32(5, 7, 126, 381);
+ _mm_store_si128((__m128i *)ar, v);
+ assert(ar[0] == 381);
+ assert(ar[1] == 126);
+ assert(ar[2] == 7);
+ assert(ar[3] == 5);
+ v = _mm_set_epi32(0x55555555, 0xaaaaaaaa, 0xffffffff, 0x12345678);
+ _mm_store_si128((__m128i *)ar, v);
+ assert(ar[0] == 0x12345678);
+ assert(ar[1] == 0xffffffff);
+ assert(ar[2] == 0xaaaaaaaa);
+ assert(ar[3] == 0x55555555);
+ }
+
+ void testSet1Epi32() {
+ int32_t __attribute__((__aligned__(16))) ar[4];
+ __m128i v = _mm_set1_epi32(-5);
+ _mm_store_si128((__m128i *)ar, v);
+ assert(ar[0] == -5);
+ assert(ar[1] == -5);
+ assert(ar[2] == -5);
+ assert(ar[3] == -5);
+ }
+
+ void testSetZeroSi128() {
+ int32_t __attribute__((__aligned__(16))) ar[4];
+ __m128i v = _mm_setzero_si128();
+ _mm_store_si128((__m128i *)ar, v);
+ assert(ar[0] == 0);
+ assert(ar[1] == 0);
+ assert(ar[2] == 0);
+ assert(ar[3] == 0);
+ }
+
+ void testBitCasts() {
+ int32_t __attribute__((__aligned__(16))) ar1[4];
+ float __attribute__((__aligned__(16))) ar2[4];
+ __m128i v1 = _mm_set_epi32(0x3f800000, 0x40000000, 0x40400000, 0x40800000);
+ __m128 v2 = _mm_castsi128_ps(v1);
+ _mm_store_ps(ar2, v2);
+ assert(ar2[0] == 4.0);
+ assert(ar2[1] == 3.0);
+ assert(ar2[2] == 2.0);
+ assert(ar2[3] == 1.0);
+ v2 = _mm_set_ps(5.0, 6.0, 7.0, 8.0);
+ v1 = _mm_castps_si128(v2);
+ _mm_store_si128((__m128i *)ar1, v1);
+ assert(ar1[0] == 0x41000000);
+ assert(ar1[1] == 0x40e00000);
+ assert(ar1[2] == 0x40c00000);
+ assert(ar1[3] == 0x40a00000);
+ float w = 0;
+ float z = -278.3;
+ float y = 5.2;
+ float x = -987654321;
+ v1 = _mm_castps_si128(_mm_set_ps(w, z, y, x));
+ _mm_store_ps(ar2, _mm_castsi128_ps(v1));
+ assert(ar2[0] == x);
+ assert(ar2[1] == y);
+ assert(ar2[2] == z);
+ assert(ar2[3] == w);
+ /*
+ std::bitset<sizeof(float)*CHAR_BIT> bits1x(*reinterpret_cast<unsigned long*>(&(ar2[0])));
+ std::bitset<sizeof(float)*CHAR_BIT> bits1y(*reinterpret_cast<unsigned long*>(&(ar2[1])));
+ std::bitset<sizeof(float)*CHAR_BIT> bits1z(*reinterpret_cast<unsigned long*>(&(ar2[2])));
+ std::bitset<sizeof(float)*CHAR_BIT> bits1w(*reinterpret_cast<unsigned long*>(&(ar2[3])));
+ std::bitset<sizeof(float)*CHAR_BIT> bits2x(*reinterpret_cast<unsigned long*>(&x));
+ std::bitset<sizeof(float)*CHAR_BIT> bits2y(*reinterpret_cast<unsigned long*>(&y));
+ std::bitset<sizeof(float)*CHAR_BIT> bits2z(*reinterpret_cast<unsigned long*>(&z));
+ std::bitset<sizeof(float)*CHAR_BIT> bits2w(*reinterpret_cast<unsigned long*>(&w));
+ assert(bits1x == bits2x);
+ assert(bits1y == bits2y);
+ assert(bits1z == bits2z);
+ assert(bits1w == bits2w);
+ */
+ v2 = _mm_castsi128_ps(_mm_set_epi32(0xffffffff, 0, 0x5555cccc, 0xaaaaaaaa));
+ _mm_store_si128((__m128i *)ar1, _mm_castps_si128(v2));
+ assert(ar1[0] == 0xaaaaaaaa);
+ assert(ar1[1] == 0x5555cccc);
+ assert(ar1[2] == 0);
+ assert(ar1[3] == 0xffffffff);
+ }
+
+ void testConversions() {
+ int32_t __attribute__((__aligned__(16))) ar1[4];
+ float __attribute__((__aligned__(16))) ar2[4];
+ __m128i v1 = _mm_set_epi32(0, -3, -517, 256);
+ __m128 v2 = _mm_cvtepi32_ps(v1);
+ _mm_store_ps(ar2, v2);
+ assert(ar2[0] == 256.0);
+ assert(ar2[1] == -517.0);
+ assert(ar2[2] == -3.0);
+ assert(ar2[3] == 0);
+ v2 = _mm_set_ps(5.0, 6.0, 7.45, -8.0);
+ v1 = _mm_cvtps_epi32(v2);
+ _mm_store_si128((__m128i *)ar1, v1);
+ assert(ar1[0] == -8);
+ assert(ar1[1] == 7);
+ assert(ar1[2] == 6);
+ assert(ar1[3] == 5);
+ }
+
+ void testMoveMaskPs() {
+ __m128 v = _mm_castsi128_ps(_mm_set_epi32(0xffffffff, 0xffffffff, 0, 0xffffffff));
+ int mask = _mm_movemask_ps(v);
+ assert(mask == 13);
+ }
+
+ void testAddPs() {
+ float __attribute__((__aligned__(16))) ar[4];
+ __m128 v1 = _mm_set_ps(4.0, 3.0, 2.0, 1.0);
+ __m128 v2 = _mm_set_ps(10.0, 20.0, 30.0, 40.0);
+ __m128 v = _mm_add_ps(v1, v2);
+ _mm_store_ps(ar, v);
+ assert(ar[0] == 41.0);
+ assert(ar[1] == 32.0);
+ assert(ar[2] == 23.0);
+ assert(ar[3] == 14.0);
+ }
+
+ void testSubPs() {
+ float __attribute__((__aligned__(16))) ar[4];
+ __m128 v1 = _mm_set_ps(4.0, 3.0, 2.0, 1.0);
+ __m128 v2 = _mm_set_ps(10.0, 20.0, 30.0, 40.0);
+ __m128 v = _mm_sub_ps(v1, v2);
+ _mm_store_ps(ar, v);
+ assert(ar[0] == -39.0);
+ assert(ar[1] == -28.0);
+ assert(ar[2] == -17.0);
+ assert(ar[3] == -6.0);
+ }
+
+ void testMulPs() {
+ float __attribute__((__aligned__(16))) ar[4];
+ __m128 v1 = _mm_set_ps(4.0, 3.0, 2.0, 1.0);
+ __m128 v2 = _mm_set_ps(10.0, 20.0, 30.0, 40.0);
+ __m128 v = _mm_mul_ps(v1, v2);
+ _mm_store_ps(ar, v);
+ assert(ar[0] == 40.0);
+ assert(ar[1] == 60.0);
+ assert(ar[2] == 60.0);
+ assert(ar[3] == 40.0);
+ }
+
+ void testDivPs() {
+ float __attribute__((__aligned__(16))) ar[4];
+ __m128 v1 = _mm_set_ps(4.0, 9.0, 8.0, 1.0);
+ __m128 v2 = _mm_set_ps(2.0, 3.0, 1.0, 0.5);
+ __m128 v = _mm_div_ps(v1, v2);
+ _mm_store_ps(ar, v);
+ assert(ar[0] == 2.0);
+ assert(ar[1] == 8.0);
+ assert(ar[2] == 3.0);
+ assert(ar[3] == 2.0);
+ }
+
+ void testMinPs() {
+ float __attribute__((__aligned__(16))) ar[4];
+ __m128 v1 = _mm_set_ps(-20.0, 10.0, 30.0, 0.5);
+ __m128 v2 = _mm_set_ps(2.0, 1.0, 50.0, 0.0);
+ __m128 v = _mm_min_ps(v1, v2);
+ _mm_store_ps(ar, v);
+ assert(ar[0] == 0.0);
+ assert(ar[1] == 30.0);
+ assert(ar[2] == 1.0);
+ assert(ar[3] == -20.0);
+ }
+
+ void testMaxPs() {
+ float __attribute__((__aligned__(16))) ar[4];
+ __m128 v1 = _mm_set_ps(-20.0, 10.0, 30.0, 0.5);
+ __m128 v2 = _mm_set_ps(2.5, 5.0, 55.0, 1.0);
+ __m128 v = _mm_max_ps(v1, v2);
+ _mm_store_ps(ar, v);
+ assert(ar[0] == 1.0);
+ assert(ar[1] == 55.0);
+ assert(ar[2] == 10.0);
+ assert(ar[3] == 2.5);
+ }
+
+ void testSqrtPs() {
+ float __attribute__((__aligned__(16))) ar[4];
+ __m128 v1 = _mm_set_ps(16.0, 9.0, 4.0, 1.0);
+ __m128 v = _mm_sqrt_ps(v1);
+ _mm_store_ps(ar, v);
+ assert(ar[0] == 1.0);
+ assert(ar[1] == 2.0);
+ assert(ar[2] == 3.0);
+ assert(ar[3] == 4.0);
+ }
+
+ void testCmpLtPs() {
+ int32_t __attribute__((__aligned__(16))) ar[4];
+ __m128 v1 = _mm_set_ps(1.0, 2.0, 0.1, 0.001);
+ __m128 v2 = _mm_set_ps(2.0, 2.0, 0.001, 0.1);
+ __m128 v = _mm_cmplt_ps(v1, v2);
+ _mm_store_si128((__m128i *)ar, _mm_castps_si128(v));
+ assert(ar[0] == 0xffffffff);
+ assert(ar[1] == 0);
+ assert(ar[2] == 0);
+ assert(ar[3] == 0xffffffff);
+ assert(_mm_movemask_ps(v) == 9);
+ }
+
+ void testCmpLePs() {
+ int32_t __attribute__((__aligned__(16))) ar[4];
+ __m128 v1 = _mm_set_ps(1.0, 2.0, 0.1, 0.001);
+ __m128 v2 = _mm_set_ps(2.0, 2.0, 0.001, 0.1);
+ __m128 v = _mm_cmple_ps(v1, v2);
+ _mm_store_si128((__m128i *)ar, _mm_castps_si128(v));
+ assert(ar[0] == 0xffffffff);
+ assert(ar[1] == 0);
+ assert(ar[2] == 0xffffffff);
+ assert(ar[3] == 0xffffffff);
+ assert(_mm_movemask_ps(v) == 13);
+ }
+
+ void testCmpEqPs() {
+ int32_t __attribute__((__aligned__(16))) ar[4];
+ __m128 v1 = _mm_set_ps(1.0, 2.0, 0.1, 0.001);
+ __m128 v2 = _mm_set_ps(2.0, 2.0, 0.001, 0.1);
+ __m128 v = _mm_cmpeq_ps(v1, v2);
+ _mm_store_si128((__m128i *)ar, _mm_castps_si128(v));
+ assert(ar[0] == 0);
+ assert(ar[1] == 0);
+ assert(ar[2] == 0xffffffff);
+ assert(ar[3] == 0);
+ assert(_mm_movemask_ps(v) == 4);
+ }
+
+ void testCmpGePs() {
+ int32_t __attribute__((__aligned__(16))) ar[4];
+ __m128 v1 = _mm_set_ps(1.0, 2.0, 0.1, 0.001);
+ __m128 v2 = _mm_set_ps(2.0, 2.0, 0.001, 0.1);
+ __m128 v = _mm_cmpge_ps(v1, v2);
+ _mm_store_si128((__m128i *)ar, _mm_castps_si128(v));
+ assert(ar[0] == 0);
+ assert(ar[1] == 0xffffffff);
+ assert(ar[2] == 0xffffffff);
+ assert(ar[3] == 0);
+ assert(_mm_movemask_ps(v) == 6);
+ }
+
+ void testCmpGtPs() {
+ int32_t __attribute__((__aligned__(16))) ar[4];
+ __m128 v1 = _mm_set_ps(1.0, 2.0, 0.1, 0.001);
+ __m128 v2 = _mm_set_ps(2.0, 2.0, 0.001, 0.1);
+ __m128 v = _mm_cmpgt_ps(v1, v2);
+ _mm_store_si128((__m128i *)ar, _mm_castps_si128(v));
+ assert(ar[0] == 0);
+ assert(ar[1] == 0xffffffff);
+ assert(ar[2] == 0);
+ assert(ar[3] == 0);
+ assert(_mm_movemask_ps(v) == 2);
+ }
+
+ void testAndPs() {
+ float __attribute__((__aligned__(16))) ar[4];
+ __m128 v1 = _mm_set_ps(425, -501, -32, 68);
+ __m128 v2 = _mm_castsi128_ps(_mm_set_epi32(0xffffffff, 0xffffffff, 0, 0xffffffff));
+ __m128 v = _mm_and_ps(v1, v2);
+ _mm_store_ps(ar, v);
+ assert(ar[0] == 68);
+ assert(ar[1] == 0);
+ assert(ar[2] == -501);
+ assert(ar[3] == 425);
+ int32_t __attribute__((__aligned__(16))) ar2[4];
+ v1 = _mm_castsi128_ps(_mm_set_epi32(0xaaaaaaaa, 0xaaaaaaaa, -1431655766, 0xaaaaaaaa));
+ v2 = _mm_castsi128_ps(_mm_set_epi32(0x55555555, 0x55555555, 0x55555555, 0x55555555));
+ v = _mm_and_ps(v1, v2);
+ _mm_store_si128((__m128i *)ar2, _mm_castps_si128(v));
+ assert(ar2[0] == 0);
+ assert(ar2[1] == 0);
+ assert(ar2[2] == 0);
+ assert(ar2[3] == 0);
+ }
+
+ void testAndNotPs() {
+ float __attribute__((__aligned__(16))) ar[4];
+ __m128 v1 = _mm_set_ps(425, -501, -32, 68);
+ __m128 v2 = _mm_castsi128_ps(_mm_set_epi32(0xffffffff, 0xffffffff, 0, 0xffffffff));
+ __m128 v = _mm_andnot_ps(v2, v1);
+ _mm_store_ps(ar, v);
+ assert(ar[0] == 0);
+ assert(ar[1] == -32);
+ assert(ar[2] == 0);
+ assert(ar[3] == 0);
+ int32_t __attribute__((__aligned__(16))) ar2[4];
+ v1 = _mm_castsi128_ps(_mm_set_epi32(0xaaaaaaaa, 0xaaaaaaaa, -1431655766, 0xaaaaaaaa));
+ v2 = _mm_castsi128_ps(_mm_set_epi32(0x55555555, 0x55555555, 0x55555555, 0x55555555));
+ v = _mm_andnot_ps(v1, v2);
+ _mm_store_si128((__m128i *)ar2, _mm_castps_si128(v));
+ assert(ar2[0] == 0x55555555);
+ assert(ar2[1] == 0x55555555);
+ assert(ar2[2] == 0x55555555);
+ assert(ar2[3] == 0x55555555);
+ }
+
+ void testOrPs() {
+ int32_t __attribute__((__aligned__(16))) ar[4];
+ __m128 v1 = _mm_castsi128_ps(_mm_set_epi32(0xaaaaaaaa, 0xaaaaaaaa, 0xffffffff, 0));
+ __m128 v2 = _mm_castsi128_ps(_mm_set_epi32(0x55555555, 0x55555555, 0x55555555, 0x55555555));
+ __m128 v = _mm_or_ps(v1, v2);
+ _mm_store_si128((__m128i *)ar, _mm_castps_si128(v));
+ assert(ar[0] == 0x55555555);
+ assert(ar[1] == 0xffffffff);
+ assert(ar[2] == 0xffffffff);
+ assert(ar[3] == 0xffffffff);
+ }
+
+ void testXorPs() {
+ int32_t __attribute__((__aligned__(16))) ar[4];
+ __m128 v1 = _mm_castsi128_ps(_mm_set_epi32(0xaaaaaaaa, 0xaaaaaaaa, 0xffffffff, 0));
+ __m128 v2 = _mm_castsi128_ps(_mm_set_epi32(0x55555555, 0x55555555, 0x55555555, 0x55555555));
+ __m128 v = _mm_xor_ps(v1, v2);
+ _mm_store_si128((__m128i *)ar, _mm_castps_si128(v));
+ assert(ar[0] == 0x55555555);
+ assert(ar[1] == 0xaaaaaaaa);
+ assert(ar[2] == 0xffffffff);
+ assert(ar[3] == 0xffffffff);
+ }
+
+ void testAndSi128() {
+ int32_t __attribute__((__aligned__(16))) ar[4];
+ __m128i v1 = _mm_set_epi32(0xaaaaaaaa, 0xaaaaaaaa, -1431655766, 0xaaaaaaaa);
+ __m128i v2 = _mm_set_epi32(0x55555555, 0x55555555, 0x55555555, 0x55555555);
+ __m128i v = _mm_and_si128(v1, v2);
+ _mm_store_si128((__m128i *)ar, v);
+ assert(ar[0] == 0);
+ assert(ar[1] == 0);
+ assert(ar[2] == 0);
+ assert(ar[3] == 0);
+ }
+
+ void testAndNotSi128() {
+ int32_t __attribute__((__aligned__(16))) ar[4];
+ __m128i v1 = _mm_set_epi32(0xaaaaaaaa, 0xaaaaaaaa, -1431655766, 0xaaaaaaaa);
+ __m128i v2 = _mm_set_epi32(0x55555555, 0x55555555, 0x55555555, 0x55555555);
+ __m128i v = _mm_andnot_si128(v1, v2);
+ _mm_store_si128((__m128i *)ar, v);
+ assert(ar[0] == 0x55555555);
+ assert(ar[1] == 0x55555555);
+ assert(ar[2] == 0x55555555);
+ assert(ar[3] == 0x55555555);
+ }
+
+ void testOrSi128() {
+ int32_t __attribute__((__aligned__(16))) ar[4];
+ __m128i v1 = _mm_set_epi32(0xaaaaaaaa, 0xaaaaaaaa, 0xffffffff, 0);
+ __m128i v2 = _mm_set_epi32(0x55555555, 0x55555555, 0x55555555, 0x55555555);
+ __m128i v = _mm_or_si128(v1, v2);
+ _mm_store_si128((__m128i *)ar, v);
+ assert(ar[0] == 0x55555555);
+ assert(ar[1] == 0xffffffff);
+ assert(ar[2] == 0xffffffff);
+ assert(ar[3] == 0xffffffff);
+ }
+
+ void testXorSi128() {
+ int32_t __attribute__((__aligned__(16))) ar[4];
+ __m128i v1 = _mm_set_epi32(0xaaaaaaaa, 0xaaaaaaaa, 0xffffffff, 0);
+ __m128i v2 = _mm_set_epi32(0x55555555, 0x55555555, 0x55555555, 0x55555555);
+ __m128i v = _mm_xor_si128(v1, v2);
+ _mm_store_si128((__m128i *)ar, v);
+ assert(ar[0] == 0x55555555);
+ assert(ar[1] == 0xaaaaaaaa);
+ assert(ar[2] == 0xffffffff);
+ assert(ar[3] == 0xffffffff);
+ }
+
+ void testAddEpi32() {
+ int32_t __attribute__((__aligned__(16))) ar[4];
+ __m128i v1 = _mm_set_epi32(4, 3, 2, 1);
+ __m128i v2 = _mm_set_epi32(10, 20, 30, 40);
+ __m128i v = _mm_add_epi32(v1, v2);
+ _mm_store_si128((__m128i *)ar, v);
+ assert(ar[0] == 41);
+ assert(ar[1] == 32);
+ assert(ar[2] == 23);
+ assert(ar[3] == 14);
+ }
+
+ void testSubEpi32() {
+ int32_t __attribute__((__aligned__(16))) ar[4];
+ __m128i v1 = _mm_set_epi32(4, 3, 2, 1);
+ __m128i v2 = _mm_set_epi32(10, 20, 30, 40);
+ __m128i v = _mm_sub_epi32(v1, v2);
+ _mm_store_si128((__m128i *)ar, v);
+ assert(ar[0] == -39);
+ assert(ar[1] == -28);
+ assert(ar[2] == -17);
+ assert(ar[3] == -6);
+ }
+
+ int main(int argc, char ** argv) {
+ testSetPs();
+ testSet1Ps();
+ testSetZeroPs();
+ testSetEpi32();
+ testSet1Epi32();
+ testSetZeroSi128();
+ testBitCasts();
+ testConversions();
+ testMoveMaskPs();
+ testAddPs();
+ testSubPs();
+ testMulPs();
+ testDivPs();
+ testMaxPs();
+ testMinPs();
+ testSqrtPs();
+ testCmpLtPs();
+ testCmpLePs();
+ testCmpEqPs();
+ testCmpGePs();
+ testCmpGtPs();
+ testAndPs();
+ testAndNotPs();
+ testOrPs();
+ testXorPs();
+ testAndSi128();
+ testAndNotSi128();
+ testOrSi128();
+ testXorSi128();
+ testAddEpi32();
+ testSubEpi32();
+ printf("DONE");
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_simd3.out b/tests/core/test_simd3.out
new file mode 100644
index 00000000..09626497
--- /dev/null
+++ b/tests/core/test_simd3.out
@@ -0,0 +1 @@
+DONE \ No newline at end of file
diff --git a/tests/core/test_sintvars.in b/tests/core/test_sintvars.in
new file mode 100644
index 00000000..1b377c7c
--- /dev/null
+++ b/tests/core/test_sintvars.in
@@ -0,0 +1,25 @@
+
+ #include <stdio.h>
+ struct S {
+ char *match_start;
+ char *strstart;
+ };
+ int main()
+ {
+ struct S _s;
+ struct S *s = &_s;
+ unsigned short int sh;
+
+ s->match_start = (char*)32522;
+ s->strstart = (char*)(32780);
+ printf("*%d,%d,%d*\n", (int)s->strstart, (int)s->match_start, (int)(s->strstart - s->match_start));
+ sh = s->strstart - s->match_start;
+ printf("*%d,%d*\n", sh, sh>>7);
+
+ s->match_start = (char*)32999;
+ s->strstart = (char*)(32780);
+ printf("*%d,%d,%d*\n", (int)s->strstart, (int)s->match_start, (int)(s->strstart - s->match_start));
+ sh = s->strstart - s->match_start;
+ printf("*%d,%d*\n", sh, sh>>7);
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_sintvars.out b/tests/core/test_sintvars.out
new file mode 100644
index 00000000..aea5592e
--- /dev/null
+++ b/tests/core/test_sintvars.out
@@ -0,0 +1,4 @@
+*32780,32522,258*
+*258,2*
+*32780,32999,-219*
+*65317,510* \ No newline at end of file
diff --git a/tests/core/test_sizeof.in b/tests/core/test_sizeof.in
new file mode 100644
index 00000000..952e900e
--- /dev/null
+++ b/tests/core/test_sizeof.in
@@ -0,0 +1,29 @@
+
+ #include <stdio.h>
+ #include <string.h>
+ #include "emscripten.h"
+
+ struct A { int x, y; };
+
+ int main( int argc, const char *argv[] ) {
+ int *a = new int[10];
+ int *b = new int[1];
+ int *c = new int[10];
+ for (int i = 0; i < 10; i++)
+ a[i] = 2;
+ *b = 5;
+ for (int i = 0; i < 10; i++)
+ c[i] = 8;
+ printf("*%d,%d,%d,%d,%d*\n", a[0], a[9], *b, c[0], c[9]);
+ // Should overwrite a, but not touch b!
+ memcpy(a, c, 10*sizeof(int));
+ printf("*%d,%d,%d,%d,%d*\n", a[0], a[9], *b, c[0], c[9]);
+
+ // Part 2
+ A as[3] = { { 5, 12 }, { 6, 990 }, { 7, 2 } };
+ memcpy(&as[0], &as[2], sizeof(A));
+
+ printf("*%d,%d,%d,%d,%d,%d*\n", as[0].x, as[0].y, as[1].x, as[1].y, as[2].x, as[2].y);
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_sizeof.out b/tests/core/test_sizeof.out
new file mode 100644
index 00000000..43d2c3b7
--- /dev/null
+++ b/tests/core/test_sizeof.out
@@ -0,0 +1 @@
+*2,2,5,8,8***8,8,5,8,8***7,2,6,990,7,2* \ No newline at end of file
diff --git a/tests/core/test_sscanf.in b/tests/core/test_sscanf.in
new file mode 100644
index 00000000..821e0c86
--- /dev/null
+++ b/tests/core/test_sscanf.in
@@ -0,0 +1,88 @@
+
+ #include <stdio.h>
+ #include <string.h>
+ #include <stdlib.h>
+
+ int main () {
+ #define CHECK(str) \
+ { \
+ char name[1000]; \
+ memset(name, 0, 1000); \
+ int prio = 99; \
+ sscanf(str, "%s %d", name, &prio); \
+ printf("%s : %d\n", name, prio); \
+ }
+ CHECK("en-us 2");
+ CHECK("en-r");
+ CHECK("en 3");
+
+ printf("%f, %f\n", atof("1.234567"), atof("cheez"));
+
+ char float_formats[] = "fegE";
+ char format[] = "%_";
+ for(int i = 0; i < 4; ++i) {
+ format[1] = float_formats[i];
+
+ float n = -1;
+ sscanf(" 2.8208", format, &n);
+ printf("%.4f\n", n);
+
+ float a = -1;
+ sscanf("-3.03", format, &a);
+ printf("%.4f\n", a);
+ }
+
+ char buffy[100];
+ sscanf("cheez some thing moar 123\nyet more\n", "cheez %s", buffy);
+ printf("|%s|\n", buffy);
+ sscanf("cheez something\nmoar 123\nyet more\n", "cheez %s", buffy);
+ printf("|%s|\n", buffy);
+ sscanf("cheez somethingmoar\tyet more\n", "cheez %s", buffy);
+ printf("|%s|\n", buffy);
+
+ int numverts = -1;
+ printf("%d\n", sscanf(" numverts 1499\n", " numverts %d", &numverts)); // white space is the same, even if tab vs space
+ printf("%d\n", numverts);
+
+ int index;
+ float u, v;
+ short start, count;
+ printf("%d\n", sscanf(" vert 87 ( 0.481565 0.059481 ) 0 1\n", " vert %d ( %f %f ) %hu %hu", &index, &u, &v, &start, &count));
+ printf("%d,%.6f,%.6f,%hu,%hu\n", index, u, v, start, count);
+
+ int neg, neg2, neg3 = 0;
+ printf("%d\n", sscanf("-123 -765 -34-6", "%d %u %d", &neg, &neg2, &neg3));
+ printf("%d,%u,%d\n", neg, neg2, neg3);
+
+ {
+ int a = 0;
+ sscanf("1", "%i", &a);
+ printf("%i\n", a);
+ }
+
+ char buf1[100], buf2[100], buf3[100], buf4[100];
+
+ int numItems = sscanf("level=4:ref=3", "%255[^:=]=%255[^:]:%255[^=]=%255c", buf1, buf2, buf3, buf4);
+ printf("%d, %s, %s, %s, %s\n", numItems, buf1, buf2, buf3, buf4);
+
+ numItems = sscanf("def|456", "%[a-z]|%[0-9]", buf1, buf2);
+ printf("%d, %s, %s\n", numItems, buf1, buf2);
+
+ numItems = sscanf("3-4,-ab", "%[-0-9],%[ab-z-]", buf1, buf2);
+ printf("%d, %s, %s\n", numItems, buf1, buf2);
+
+ numItems = sscanf("Hello,World", "%[A-Za-z],%[^0-9]", buf1, buf2);
+ printf("%d, %s, %s\n", numItems, buf1, buf2);
+
+ numItems = sscanf("Hello4711", "%[^0-9],%[^0-9]", buf1, buf2);
+ printf("%d, %s\n", numItems, buf1);
+
+ numItems = sscanf("JavaScript", "%4[A-Za-z]", buf1);
+ printf("%d, %s\n", numItems, buf1);
+
+ numItems = sscanf("[]", "%1[[]%1[]]", buf1, buf2);
+ printf("%d, %s, %s\n", numItems, buf1, buf2);
+
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_sscanf.out b/tests/core/test_sscanf.out
new file mode 100644
index 00000000..f9c3d478
--- /dev/null
+++ b/tests/core/test_sscanf.out
@@ -0,0 +1,29 @@
+en-us : 2
+en-r : 99
+en : 3
+1.234567, 0.000000
+2.8208
+-3.0300
+2.8208
+-3.0300
+2.8208
+-3.0300
+2.8208
+-3.0300
+|some|
+|something|
+|somethingmoar|
+1
+1499
+5
+87,0.481565,0.059481,0,1
+3
+-123,4294966531,-34
+1
+4, level, 4, ref, 3
+2, def, 456
+2, 3-4, -ab
+2, Hello, World
+1, Hello
+1, Java
+2, [, ] \ No newline at end of file
diff --git a/tests/core/test_sscanf_3.in b/tests/core/test_sscanf_3.in
new file mode 100644
index 00000000..fb8949e7
--- /dev/null
+++ b/tests/core/test_sscanf_3.in
@@ -0,0 +1,17 @@
+
+ #include <stdint.h>
+ #include <stdio.h>
+
+ int main(){
+
+ int64_t s, m, l;
+ printf("%d\n", sscanf("123 1073741823 1125899906842620", "%lld %lld %lld", &s, &m, &l));
+ printf("%lld,%lld,%lld\n", s, m, l);
+
+ int64_t negS, negM, negL;
+ printf("%d\n", sscanf("-123 -1073741823 -1125899906842620", "%lld %lld %lld", &negS, &negM, &negL));
+ printf("%lld,%lld,%lld\n", negS, negM, negL);
+
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_sscanf_3.out b/tests/core/test_sscanf_3.out
new file mode 100644
index 00000000..fe1d5b41
--- /dev/null
+++ b/tests/core/test_sscanf_3.out
@@ -0,0 +1,4 @@
+3
+123,1073741823,1125899906842620
+3
+-123,-1073741823,-1125899906842620
diff --git a/tests/core/test_sscanf_4.in b/tests/core/test_sscanf_4.in
new file mode 100644
index 00000000..b54176c5
--- /dev/null
+++ b/tests/core/test_sscanf_4.in
@@ -0,0 +1,11 @@
+
+ #include <stdio.h>
+
+ int main()
+ {
+ char pYear[16], pMonth[16], pDay[16], pDate[64];
+ printf("%d\n", sscanf("Nov 19 2012", "%s%s%s", pMonth, pDay, pYear));
+ printf("day %s, month %s, year %s \n", pDay, pMonth, pYear);
+ return(0);
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_sscanf_4.out b/tests/core/test_sscanf_4.out
new file mode 100644
index 00000000..02dba361
--- /dev/null
+++ b/tests/core/test_sscanf_4.out
@@ -0,0 +1,2 @@
+3
+day 19, month Nov, year 2012 \ No newline at end of file
diff --git a/tests/core/test_sscanf_5.in b/tests/core/test_sscanf_5.in
new file mode 100644
index 00000000..c3c1ed8a
--- /dev/null
+++ b/tests/core/test_sscanf_5.in
@@ -0,0 +1,19 @@
+
+ #include "stdio.h"
+
+ static const char *colors[] = {
+ " c black",
+ ". c #001100",
+ "X c #111100"
+ };
+
+ int main(){
+ unsigned char code;
+ char color[32];
+ int rcode;
+ for(int i = 0; i < 3; i++) {
+ rcode = sscanf(colors[i], "%c c %s", &code, color);
+ printf("%i, %c, %s\n", rcode, code, color);
+ }
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_sscanf_5.out b/tests/core/test_sscanf_5.out
new file mode 100644
index 00000000..823ae41f
--- /dev/null
+++ b/tests/core/test_sscanf_5.out
@@ -0,0 +1,3 @@
+2, , black
+2, ., #001100
+2, X, #111100 \ No newline at end of file
diff --git a/tests/core/test_sscanf_6.in b/tests/core/test_sscanf_6.in
new file mode 100644
index 00000000..2f2f58a3
--- /dev/null
+++ b/tests/core/test_sscanf_6.in
@@ -0,0 +1,15 @@
+
+ #include <stdio.h>
+ #include <string.h>
+ int main()
+ {
+ char *date = "18.07.2013w";
+ char c[10];
+ memset(c, 0, 10);
+ int y, m, d, i;
+ i = sscanf(date, "%d.%d.%4d%c", &d, &m, &y, c);
+ printf("date: %s; day %2d, month %2d, year %4d, extra: %c, %d\n", date, d, m, y, c[0], i);
+ i = sscanf(date, "%d.%d.%3c", &d, &m, c);
+ printf("date: %s; day %2d, month %2d, year %4d, extra: %s, %d\n", date, d, m, y, c, i);
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_sscanf_6.out b/tests/core/test_sscanf_6.out
new file mode 100644
index 00000000..4aee073e
--- /dev/null
+++ b/tests/core/test_sscanf_6.out
@@ -0,0 +1,2 @@
+date: 18.07.2013w; day 18, month 7, year 2013, extra: w, 4
+date: 18.07.2013w; day 18, month 7, year 2013, extra: 201, 3
diff --git a/tests/core/test_sscanf_caps.in b/tests/core/test_sscanf_caps.in
new file mode 100644
index 00000000..39a90db5
--- /dev/null
+++ b/tests/core/test_sscanf_caps.in
@@ -0,0 +1,10 @@
+
+ #include "stdio.h"
+
+ int main(){
+ unsigned int a;
+ float e, f, g;
+ sscanf("a 1.1 1.1 1.1", "%X %E %F %G", &a, &e, &f, &g);
+ printf("%d %.1F %.1F %.1F\n", a, e, f, g);
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_sscanf_caps.out b/tests/core/test_sscanf_caps.out
new file mode 100644
index 00000000..20e20fe8
--- /dev/null
+++ b/tests/core/test_sscanf_caps.out
@@ -0,0 +1 @@
+10 1.1 1.1 1.1 \ No newline at end of file
diff --git a/tests/core/test_sscanf_float.in b/tests/core/test_sscanf_float.in
new file mode 100644
index 00000000..e87d839a
--- /dev/null
+++ b/tests/core/test_sscanf_float.in
@@ -0,0 +1,9 @@
+
+ #include "stdio.h"
+
+ int main(){
+ float f1, f2, f3, f4, f5, f6, f7, f8, f9;
+ sscanf("0.512 0.250x5.129_-9.98 1.12*+54.32E3 +54.32E3^87.5E-3 87.5E-3$", "%f %fx%f_%f %f*%f %f^%f %f$", &f1, &f2, &f3, &f4, &f5, &f6, &f7, &f8, &f9);
+ printf("\n%f, %f, %f, %f, %f, %f, %f, %f, %f\n", f1, f2, f3, f4, f5, f6, f7, f8, f9);
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_sscanf_float.out b/tests/core/test_sscanf_float.out
new file mode 100644
index 00000000..ea5a276d
--- /dev/null
+++ b/tests/core/test_sscanf_float.out
@@ -0,0 +1,2 @@
+
+0.512000, 0.250000, 5.129000, -9.980000, 1.120000, 54320.000000, 54320.000000, 0.087500, 0.087500
diff --git a/tests/core/test_sscanf_hex.in b/tests/core/test_sscanf_hex.in
new file mode 100644
index 00000000..af6c158e
--- /dev/null
+++ b/tests/core/test_sscanf_hex.in
@@ -0,0 +1,9 @@
+
+ #include "stdio.h"
+
+ int main(){
+ unsigned int a, b;
+ sscanf("0x12AB 12AB", "%x %x", &a, &b);
+ printf("%d %d\n", a, b);
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_sscanf_hex.out b/tests/core/test_sscanf_hex.out
new file mode 100644
index 00000000..ac855044
--- /dev/null
+++ b/tests/core/test_sscanf_hex.out
@@ -0,0 +1 @@
+4779 4779 \ No newline at end of file
diff --git a/tests/core/test_sscanf_n.in b/tests/core/test_sscanf_n.in
new file mode 100644
index 00000000..78142b3a
--- /dev/null
+++ b/tests/core/test_sscanf_n.in
@@ -0,0 +1,21 @@
+
+ #include<stdio.h>
+ int main() {
+ char *line = "version 1.0";
+ int i, l, lineno;
+ char word[80];
+ if (sscanf(line, "%s%n", word, &l) != 1) {
+ printf("Header format error, line %d\n", lineno);
+ }
+ printf("[DEBUG] word 1: %s, l: %d\n", word, l);
+
+ int x = sscanf("one %n two", "%s %n", word, &l);
+ printf("%d,%s,%d\n", x, word, l);
+ {
+ int a, b, c, count;
+ count = sscanf("12345 6789", "%d %n%d", &a, &b, &c);
+ printf("%i %i %i %i\n", count, a, b, c);
+ }
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_sscanf_n.out b/tests/core/test_sscanf_n.out
new file mode 100644
index 00000000..c3ce6f04
--- /dev/null
+++ b/tests/core/test_sscanf_n.out
@@ -0,0 +1,3 @@
+[DEBUG] word 1: version, l: 7
+1,one,4
+2 12345 6 6789
diff --git a/tests/core/test_sscanf_other_whitespace.in b/tests/core/test_sscanf_other_whitespace.in
new file mode 100644
index 00000000..224d1a23
--- /dev/null
+++ b/tests/core/test_sscanf_other_whitespace.in
@@ -0,0 +1,29 @@
+
+ #include<stdio.h>
+
+ int main() {
+ short int x;
+ short int y;
+
+ const char* buffer[] = {
+ "\t2\t3\t", /* TAB - horizontal tab */
+ "\t\t5\t\t7\t\t",
+ "\n11\n13\n", /* LF - line feed */
+ "\n\n17\n\n19\n\n",
+ "\v23\v29\v", /* VT - vertical tab */
+ "\v\v31\v\v37\v\v",
+ "\f41\f43\f", /* FF - form feed */
+ "\f\f47\f\f53\f\f",
+ "\r59\r61\r", /* CR - carrage return */
+ "\r\r67\r\r71\r\r"
+ };
+
+ for (int i=0; i<10; ++i) {
+ x = 0; y = 0;
+ sscanf(buffer[i], " %d %d ", &x, &y);
+ printf("%d, %d, ", x, y);
+ }
+
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_sscanf_other_whitespace.out b/tests/core/test_sscanf_other_whitespace.out
new file mode 100644
index 00000000..0d0f4beb
--- /dev/null
+++ b/tests/core/test_sscanf_other_whitespace.out
@@ -0,0 +1 @@
+2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, \ No newline at end of file
diff --git a/tests/core/test_sscanf_skip.in b/tests/core/test_sscanf_skip.in
new file mode 100644
index 00000000..0faae7aa
--- /dev/null
+++ b/tests/core/test_sscanf_skip.in
@@ -0,0 +1,16 @@
+
+ #include <stdint.h>
+ #include <stdio.h>
+
+ int main(){
+ int val1;
+ printf("%d\n", sscanf("10 20 30 40", "%*lld %*d %d", &val1));
+ printf("%d\n", val1);
+
+ int64_t large, val2;
+ printf("%d\n", sscanf("1000000 -1125899906842620 -123 -1073741823", "%lld %*lld %ld %*d", &large, &val2));
+ printf("%lld,%d\n", large, val2);
+
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_sscanf_skip.out b/tests/core/test_sscanf_skip.out
new file mode 100644
index 00000000..cf1cdfb8
--- /dev/null
+++ b/tests/core/test_sscanf_skip.out
@@ -0,0 +1,4 @@
+1
+30
+2
+1000000,-123
diff --git a/tests/core/test_sscanf_whitespace.in b/tests/core/test_sscanf_whitespace.in
new file mode 100644
index 00000000..6947203f
--- /dev/null
+++ b/tests/core/test_sscanf_whitespace.in
@@ -0,0 +1,23 @@
+
+ #include<stdio.h>
+
+ int main() {
+ short int x;
+ short int y;
+
+ const char* buffer[] = {
+ "173,16",
+ " 16,173",
+ "183, 173",
+ " 17, 287",
+ " 98, 123, "
+ };
+
+ for (int i=0; i<5; ++i) {
+ sscanf(buffer[i], "%hd,%hd", &x, &y);
+ printf("%d:%d,%d ", i, x, y);
+ }
+
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_sscanf_whitespace.out b/tests/core/test_sscanf_whitespace.out
new file mode 100644
index 00000000..9a26dd1d
--- /dev/null
+++ b/tests/core/test_sscanf_whitespace.out
@@ -0,0 +1 @@
+0:173,16 1:16,173 2:183,173 3:17,287 4:98,123 \ No newline at end of file
diff --git a/tests/core/test_stack.in b/tests/core/test_stack.in
new file mode 100644
index 00000000..94e5d380
--- /dev/null
+++ b/tests/core/test_stack.in
@@ -0,0 +1,19 @@
+
+ #include <stdio.h>
+ int test(int i) {
+ int x = 10;
+ if (i > 0) {
+ return test(i-1);
+ }
+ return int(&x); // both for the number, and forces x to not be nativized
+ }
+ int main(int argc, char **argv)
+ {
+ // We should get the same value for the first and last - stack has unwound
+ int x1 = test(argc - 2);
+ int x2 = test(100);
+ int x3 = test((argc - 2) / 4);
+ printf("*%d,%d*\n", x3-x1, x2 != x1);
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_stack.out b/tests/core/test_stack.out
new file mode 100644
index 00000000..687e8ad6
--- /dev/null
+++ b/tests/core/test_stack.out
@@ -0,0 +1 @@
+*0,1* \ No newline at end of file
diff --git a/tests/core/test_stack_byval.in b/tests/core/test_stack_byval.in
new file mode 100644
index 00000000..565866ee
--- /dev/null
+++ b/tests/core/test_stack_byval.in
@@ -0,0 +1,25 @@
+
+// We should also not blow up the stack with byval arguments
+ #include<stdio.h>
+ struct vec {
+ int x, y, z;
+ vec(int x_, int y_, int z_) : x(x_), y(y_), z(z_) {}
+ static vec add(vec a, vec b) {
+ return vec(a.x+b.x, a.y+b.y, a.z+b.z);
+ }
+ };
+ int main() {
+ int total = 0;
+ for (int i = 0; i < 1000; i++) {
+ for (int j = 0; j < 1000; j++) {
+ vec c(i+i%10, j*2, i%255);
+ vec d(j*2, j%255, i%120);
+ vec f = vec::add(c, d);
+ total += (f.x + f.y + f.z) % 100;
+ total %= 10240;
+ }
+ }
+ printf("sum:%d*\n", total);
+ return 0;
+ }
+
diff --git a/tests/core/test_stack_byval.out b/tests/core/test_stack_byval.out
new file mode 100644
index 00000000..62f1b081
--- /dev/null
+++ b/tests/core/test_stack_byval.out
@@ -0,0 +1 @@
+sum:9780* \ No newline at end of file
diff --git a/tests/core/test_stack_varargs.in b/tests/core/test_stack_varargs.in
new file mode 100644
index 00000000..74b600bd
--- /dev/null
+++ b/tests/core/test_stack_varargs.in
@@ -0,0 +1,16 @@
+
+// We should not blow up the stack with numerous varargs
+ #include <stdio.h>
+ #include <stdlib.h>
+
+ void func(int i) {
+ printf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n",
+ i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i);
+ }
+ int main() {
+ for (int i = 0; i < 1024; i++)
+ func(i);
+ printf("ok!\n");
+ return 0;
+ }
+
diff --git a/tests/core/test_stack_varargs.out b/tests/core/test_stack_varargs.out
new file mode 100644
index 00000000..e036282a
--- /dev/null
+++ b/tests/core/test_stack_varargs.out
@@ -0,0 +1 @@
+ok! \ No newline at end of file
diff --git a/tests/core/test_stack_void.in b/tests/core/test_stack_void.in
new file mode 100644
index 00000000..7e48a0f0
--- /dev/null
+++ b/tests/core/test_stack_void.in
@@ -0,0 +1,16 @@
+
+ #include <stdio.h>
+
+ static char s[100]="aaaaa";
+ static int func(void) {
+ if(s[0]!='a') return 0;
+ printf("iso open %s\n", s, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001);
+ return 0;
+ }
+ int main(){
+ int i;
+ for(i=0;i<5000;i++)
+ func();
+ printf(".ok.\n");
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_stack_void.out b/tests/core/test_stack_void.out
new file mode 100644
index 00000000..c8e99c4e
--- /dev/null
+++ b/tests/core/test_stack_void.out
@@ -0,0 +1 @@
+.ok.
diff --git a/tests/core/test_static_variable.in b/tests/core/test_static_variable.in
new file mode 100644
index 00000000..82fcadac
--- /dev/null
+++ b/tests/core/test_static_variable.in
@@ -0,0 +1,26 @@
+
+ #include <stdio.h>
+
+ struct DATA
+ {
+ int value;
+
+ DATA()
+ {
+ value = 0;
+ }
+ };
+
+ DATA & GetData()
+ {
+ static DATA data;
+
+ return data;
+ }
+
+ int main()
+ {
+ GetData().value = 10;
+ printf( "value:%i", GetData().value );
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_static_variable.out b/tests/core/test_static_variable.out
new file mode 100644
index 00000000..8ab80f3b
--- /dev/null
+++ b/tests/core/test_static_variable.out
@@ -0,0 +1 @@
+value:10 \ No newline at end of file
diff --git a/tests/core/test_statics.in b/tests/core/test_statics.in
new file mode 100644
index 00000000..0935aade
--- /dev/null
+++ b/tests/core/test_statics.in
@@ -0,0 +1,39 @@
+
+ #include <stdio.h>
+ #include <string.h>
+
+ #define CONSTRLEN 32
+
+ char * (*func)(char *, const char *) = NULL;
+
+ void conoutfv(const char *fmt)
+ {
+ static char buf[CONSTRLEN];
+ func(buf, fmt); // call by function pointer to make sure we test strcpy here
+ puts(buf);
+ }
+
+ struct XYZ {
+ float x, y, z;
+ XYZ(float a, float b, float c) : x(a), y(b), z(c) { }
+ static const XYZ& getIdentity()
+ {
+ static XYZ iT(1,2,3);
+ return iT;
+ }
+ };
+ struct S {
+ static const XYZ& getIdentity()
+ {
+ static const XYZ iT(XYZ::getIdentity());
+ return iT;
+ }
+ };
+
+ int main() {
+ func = &strcpy;
+ conoutfv("*staticccz*");
+ printf("*%.2f,%.2f,%.2f*\n", S::getIdentity().x, S::getIdentity().y, S::getIdentity().z);
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_statics.out b/tests/core/test_statics.out
new file mode 100644
index 00000000..c34f2cb6
--- /dev/null
+++ b/tests/core/test_statics.out
@@ -0,0 +1,2 @@
+*staticccz*
+*1.00,2.00,3.00* \ No newline at end of file
diff --git a/tests/core/test_statvfs.in b/tests/core/test_statvfs.in
new file mode 100644
index 00000000..f9bd781a
--- /dev/null
+++ b/tests/core/test_statvfs.in
@@ -0,0 +1,26 @@
+
+ #include <stdio.h>
+ #include <errno.h>
+ #include <sys/statvfs.h>
+
+ int main() {
+ struct statvfs s;
+
+ printf("result: %d\n", statvfs("/test", &s));
+ printf("errno: %d\n", errno);
+
+ printf("f_bsize: %lu\n", s.f_bsize);
+ printf("f_frsize: %lu\n", s.f_frsize);
+ printf("f_blocks: %lu\n", s.f_blocks);
+ printf("f_bfree: %lu\n", s.f_bfree);
+ printf("f_bavail: %lu\n", s.f_bavail);
+ printf("f_files: %d\n", s.f_files > 5);
+ printf("f_ffree: %lu\n", s.f_ffree);
+ printf("f_favail: %lu\n", s.f_favail);
+ printf("f_fsid: %lu\n", s.f_fsid);
+ printf("f_flag: %lu\n", s.f_flag);
+ printf("f_namemax: %lu\n", s.f_namemax);
+
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_statvfs.out b/tests/core/test_statvfs.out
new file mode 100644
index 00000000..8c414d09
--- /dev/null
+++ b/tests/core/test_statvfs.out
@@ -0,0 +1,13 @@
+result: 0
+errno: 0
+f_bsize: 4096
+f_frsize: 4096
+f_blocks: 1000000
+f_bfree: 500000
+f_bavail: 500000
+f_files: 1
+f_ffree: 1000000
+f_favail: 1000000
+f_fsid: 42
+f_flag: 2
+f_namemax: 255
diff --git a/tests/core/test_std_cout_new.in b/tests/core/test_std_cout_new.in
new file mode 100644
index 00000000..20895169
--- /dev/null
+++ b/tests/core/test_std_cout_new.in
@@ -0,0 +1,24 @@
+
+ #include <iostream>
+
+ struct NodeInfo { //structure that we want to transmit to our shaders
+ float x;
+ float y;
+ float s;
+ float c;
+ };
+ const int nbNodes = 100;
+ NodeInfo * data = new NodeInfo[nbNodes]; //our data that will be transmitted using float texture.
+
+ template<int i>
+ void printText( const char (&text)[ i ] )
+ {
+ std::cout << text << std::endl;
+ }
+
+ int main()
+ {
+ printText( "some string constant" );
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_std_cout_new.out b/tests/core/test_std_cout_new.out
new file mode 100644
index 00000000..ddb4b681
--- /dev/null
+++ b/tests/core/test_std_cout_new.out
@@ -0,0 +1 @@
+some string constant \ No newline at end of file
diff --git a/tests/core/test_std_exception.in b/tests/core/test_std_exception.in
new file mode 100644
index 00000000..280faed2
--- /dev/null
+++ b/tests/core/test_std_exception.in
@@ -0,0 +1,15 @@
+
+ #include <stdio.h>
+ #include <exception>
+
+ int main()
+ {
+ std::exception e;
+ try {
+ throw e;
+ } catch(std::exception e) {
+ printf("caught std::exception\n");
+ }
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_std_exception.out b/tests/core/test_std_exception.out
new file mode 100644
index 00000000..c1660de4
--- /dev/null
+++ b/tests/core/test_std_exception.out
@@ -0,0 +1 @@
+caught std::exception \ No newline at end of file
diff --git a/tests/core/test_stdvec.in b/tests/core/test_stdvec.in
new file mode 100644
index 00000000..884933c2
--- /dev/null
+++ b/tests/core/test_stdvec.in
@@ -0,0 +1,31 @@
+
+ #include <vector>
+ #include <stdio.h>
+
+ struct S {
+ int a;
+ float b;
+ };
+
+ void foo(int a, float b)
+ {
+ printf("%d:%.2f\n", a, b);
+ }
+
+ int main ( int argc, char *argv[] )
+ {
+ std::vector<S> ar;
+ S s;
+
+ s.a = 789;
+ s.b = 123.456f;
+ ar.push_back(s);
+
+ s.a = 0;
+ s.b = 100.1f;
+ ar.push_back(s);
+
+ foo(ar[0].a, ar[0].b);
+ foo(ar[1].a, ar[1].b);
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_stdvec.out b/tests/core/test_stdvec.out
new file mode 100644
index 00000000..cb3a61fc
--- /dev/null
+++ b/tests/core/test_stdvec.out
@@ -0,0 +1,2 @@
+789:123.46
+0:100.1 \ No newline at end of file
diff --git a/tests/core/test_strcasecmp.in b/tests/core/test_strcasecmp.in
new file mode 100644
index 00000000..6186e50b
--- /dev/null
+++ b/tests/core/test_strcasecmp.in
@@ -0,0 +1,81 @@
+
+ #include <stdio.h>
+ #include <strings.h>
+ int sign(int x) {
+ if (x < 0) return -1;
+ if (x > 0) return 1;
+ return 0;
+ }
+ int main() {
+ printf("*\n");
+
+ printf("%d\n", sign(strcasecmp("hello", "hello")));
+ printf("%d\n", sign(strcasecmp("hello1", "hello")));
+ printf("%d\n", sign(strcasecmp("hello", "hello1")));
+ printf("%d\n", sign(strcasecmp("hello1", "hello1")));
+ printf("%d\n", sign(strcasecmp("iello", "hello")));
+ printf("%d\n", sign(strcasecmp("hello", "iello")));
+ printf("%d\n", sign(strcasecmp("A", "hello")));
+ printf("%d\n", sign(strcasecmp("Z", "hello")));
+ printf("%d\n", sign(strcasecmp("a", "hello")));
+ printf("%d\n", sign(strcasecmp("z", "hello")));
+ printf("%d\n", sign(strcasecmp("hello", "a")));
+ printf("%d\n", sign(strcasecmp("hello", "z")));
+
+ printf("%d\n", sign(strcasecmp("Hello", "hello")));
+ printf("%d\n", sign(strcasecmp("Hello1", "hello")));
+ printf("%d\n", sign(strcasecmp("Hello", "hello1")));
+ printf("%d\n", sign(strcasecmp("Hello1", "hello1")));
+ printf("%d\n", sign(strcasecmp("Iello", "hello")));
+ printf("%d\n", sign(strcasecmp("Hello", "iello")));
+ printf("%d\n", sign(strcasecmp("A", "hello")));
+ printf("%d\n", sign(strcasecmp("Z", "hello")));
+ printf("%d\n", sign(strcasecmp("a", "hello")));
+ printf("%d\n", sign(strcasecmp("z", "hello")));
+ printf("%d\n", sign(strcasecmp("Hello", "a")));
+ printf("%d\n", sign(strcasecmp("Hello", "z")));
+
+ printf("%d\n", sign(strcasecmp("hello", "Hello")));
+ printf("%d\n", sign(strcasecmp("hello1", "Hello")));
+ printf("%d\n", sign(strcasecmp("hello", "Hello1")));
+ printf("%d\n", sign(strcasecmp("hello1", "Hello1")));
+ printf("%d\n", sign(strcasecmp("iello", "Hello")));
+ printf("%d\n", sign(strcasecmp("hello", "Iello")));
+ printf("%d\n", sign(strcasecmp("A", "Hello")));
+ printf("%d\n", sign(strcasecmp("Z", "Hello")));
+ printf("%d\n", sign(strcasecmp("a", "Hello")));
+ printf("%d\n", sign(strcasecmp("z", "Hello")));
+ printf("%d\n", sign(strcasecmp("hello", "a")));
+ printf("%d\n", sign(strcasecmp("hello", "z")));
+
+ printf("%d\n", sign(strcasecmp("Hello", "Hello")));
+ printf("%d\n", sign(strcasecmp("Hello1", "Hello")));
+ printf("%d\n", sign(strcasecmp("Hello", "Hello1")));
+ printf("%d\n", sign(strcasecmp("Hello1", "Hello1")));
+ printf("%d\n", sign(strcasecmp("Iello", "Hello")));
+ printf("%d\n", sign(strcasecmp("Hello", "Iello")));
+ printf("%d\n", sign(strcasecmp("A", "Hello")));
+ printf("%d\n", sign(strcasecmp("Z", "Hello")));
+ printf("%d\n", sign(strcasecmp("a", "Hello")));
+ printf("%d\n", sign(strcasecmp("z", "Hello")));
+ printf("%d\n", sign(strcasecmp("Hello", "a")));
+ printf("%d\n", sign(strcasecmp("Hello", "z")));
+
+ printf("%d\n", sign(strncasecmp("hello", "hello", 3)));
+ printf("%d\n", sign(strncasecmp("hello1", "hello", 3)));
+ printf("%d\n", sign(strncasecmp("hello", "hello1", 3)));
+ printf("%d\n", sign(strncasecmp("hello1", "hello1", 3)));
+ printf("%d\n", sign(strncasecmp("iello", "hello", 3)));
+ printf("%d\n", sign(strncasecmp("hello", "iello", 3)));
+ printf("%d\n", sign(strncasecmp("A", "hello", 3)));
+ printf("%d\n", sign(strncasecmp("Z", "hello", 3)));
+ printf("%d\n", sign(strncasecmp("a", "hello", 3)));
+ printf("%d\n", sign(strncasecmp("z", "hello", 3)));
+ printf("%d\n", sign(strncasecmp("hello", "a", 3)));
+ printf("%d\n", sign(strncasecmp("hello", "z", 3)));
+
+ printf("*\n");
+
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_strcasecmp.out b/tests/core/test_strcasecmp.out
new file mode 100644
index 00000000..b572c269
--- /dev/null
+++ b/tests/core/test_strcasecmp.out
@@ -0,0 +1,62 @@
+*
+0
+1
+-1
+0
+1
+-1
+-1
+1
+-1
+1
+1
+-1
+0
+1
+-1
+0
+1
+-1
+-1
+1
+-1
+1
+1
+-1
+0
+1
+-1
+0
+1
+-1
+-1
+1
+-1
+1
+1
+-1
+0
+1
+-1
+0
+1
+-1
+-1
+1
+-1
+1
+1
+-1
+0
+0
+0
+0
+1
+-1
+-1
+1
+-1
+1
+1
+-1
+*
diff --git a/tests/core/test_strcmp_uni.in b/tests/core/test_strcmp_uni.in
new file mode 100644
index 00000000..4ccd7db8
--- /dev/null
+++ b/tests/core/test_strcmp_uni.in
@@ -0,0 +1,11 @@
+
+ #include <stdio.h>
+ #include <string.h>
+ int main()
+ {
+ #define TEST(func) { char *word = "WORD"; char wordEntry[2] = { -61,-126 }; /* "Â"; */ int cmp = func(word, wordEntry, 2); printf("Compare value " #func " is %d\n", cmp); }
+ TEST(strncmp);
+ TEST(strncasecmp);
+ TEST(memcmp);
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_strcmp_uni.out b/tests/core/test_strcmp_uni.out
new file mode 100644
index 00000000..58e237d7
--- /dev/null
+++ b/tests/core/test_strcmp_uni.out
@@ -0,0 +1,3 @@
+Compare value strncmp is -1
+Compare value strncasecmp is -1
+Compare value memcmp is -1
diff --git a/tests/core/test_strftime.in b/tests/core/test_strftime.in
new file mode 100644
index 00000000..1897c58a
--- /dev/null
+++ b/tests/core/test_strftime.in
@@ -0,0 +1,153 @@
+
+ #include <time.h>
+ #include <stdio.h>
+ #include <string.h>
+ #include <stdlib.h>
+
+ void test(int result, const char* comment, const char* parsed = "") {
+ printf("%d",result);
+ if (!result) {
+ printf("\nERROR: %s (\"%s\")\n", comment, parsed);
+ }
+ }
+
+ int cmp(const char *s1, const char *s2) {
+ for ( ; *s1 == *s2 ; s1++,s2++ ) {
+ if ( *s1 == '\0' )
+ break;
+ }
+
+ return (*s1 - *s2);
+ }
+
+ int main() {
+ struct tm tm;
+ char s[1000];
+ size_t size;
+
+ tm.tm_sec = 4;
+ tm.tm_min = 23;
+ tm.tm_hour = 20;
+ tm.tm_mday = 21;
+ tm.tm_mon = 1;
+ tm.tm_year = 74;
+ tm.tm_wday = 4;
+ tm.tm_yday = 51;
+ tm.tm_isdst = 0;
+
+ size = strftime(s, 1000, "", &tm);
+ test((size==0) && (*s=='\0'), "strftime test #1", s);
+
+ size = strftime(s, 1000, "%a", &tm);
+ test((size==3) && !cmp(s, "Thu"), "strftime test #2", s);
+
+ size = strftime(s, 1000, "%A", &tm);
+ test((size==8) && !cmp(s, "Thursday"), "strftime test #3", s);
+
+ size = strftime(s, 1000, "%b", &tm);
+ test((size==3) && !cmp(s, "Feb"), "strftime test #4", s);
+
+ size = strftime(s, 1000, "%B", &tm);
+ test((size==8) && !cmp(s, "February"),
+ "strftime test #5", s);
+
+ size = strftime(s, 1000, "%d", &tm);
+ test((size==2) && !cmp(s, "21"),
+ "strftime test #6", s);
+
+ size = strftime(s, 1000, "%H", &tm);
+ test((size==2) && !cmp(s, "20"),
+ "strftime test #7", s);
+
+ size = strftime(s, 1000, "%I", &tm);
+ test((size==2) && !cmp(s, "08"),
+ "strftime test #8", s);
+
+ size = strftime(s, 1000, "%j", &tm);
+ test((size==3) && !cmp(s, "052"),
+ "strftime test #9", s);
+
+ size = strftime(s, 1000, "%m", &tm);
+ test((size==2) && !cmp(s, "02"),
+ "strftime test #10", s);
+
+ size = strftime(s, 1000, "%M", &tm);
+ test((size==2) && !cmp(s, "23"),
+ "strftime test #11", s);
+
+ size = strftime(s, 1000, "%p", &tm);
+ test((size==2) && !cmp(s, "PM"),
+ "strftime test #12", s);
+
+ size = strftime(s, 1000, "%S", &tm);
+ test((size==2) && !cmp(s, "04"),
+ "strftime test #13", s);
+
+ size = strftime(s, 1000, "%U", &tm);
+ test((size==2) && !cmp(s, "07"),
+ "strftime test #14", s);
+
+ size = strftime(s, 1000, "%w", &tm);
+ test((size==1) && !cmp(s, "4"),
+ "strftime test #15", s);
+
+ size = strftime(s, 1000, "%W", &tm);
+ test((size==2) && !cmp(s, "07"),
+ "strftime test #16", s);
+
+ size = strftime(s, 1000, "%y", &tm);
+ test((size==2) && !cmp(s, "74"),
+ "strftime test #17", s);
+
+ size = strftime(s, 1000, "%Y", &tm);
+ test((size==4) && !cmp(s, "1974"),
+ "strftime test #18", s);
+
+ size = strftime(s, 1000, "%%", &tm);
+ test((size==1) && !cmp(s, "%"),
+ "strftime test #19", s);
+
+ size = strftime(s, 5, "%Y", &tm);
+ test((size==4) && !cmp(s, "1974"),
+ "strftime test #20", s);
+
+ size = strftime(s, 4, "%Y", &tm);
+ test((size==0), "strftime test #21", s);
+
+ tm.tm_mon = 0;
+ tm.tm_mday = 1;
+ size = strftime(s, 10, "%U", &tm);
+ test((size==2) && !cmp(s, "00"), "strftime test #22", s);
+
+ size = strftime(s, 10, "%W", &tm);
+ test((size==2) && !cmp(s, "00"), "strftime test #23", s);
+
+ // 1/1/1973 was a Sunday and is in CW 1
+ tm.tm_year = 73;
+ size = strftime(s, 10, "%W", &tm);
+ test((size==2) && !cmp(s, "01"), "strftime test #24", s);
+
+ // 1/1/1978 was a Monday and is in CW 1
+ tm.tm_year = 78;
+ size = strftime(s, 10, "%U", &tm);
+ test((size==2) && !cmp(s, "01"), "strftime test #25", s);
+
+ // 2/1/1999
+ tm.tm_year = 99;
+ tm.tm_yday = 1;
+ size = strftime(s, 10, "%G (%V)", &tm);
+ test((size==9) && !cmp(s, "1998 (53)"), "strftime test #26", s);
+
+ size = strftime(s, 10, "%g", &tm);
+ test((size==2) && !cmp(s, "98"), "strftime test #27", s);
+
+ // 30/12/1997
+ tm.tm_year = 97;
+ tm.tm_yday = 363;
+ size = strftime(s, 10, "%G (%V)", &tm);
+ test((size==9) && !cmp(s, "1998 (01)"), "strftime test #28", s);
+
+ size = strftime(s, 10, "%g", &tm);
+ test((size==2) && !cmp(s, "98"), "strftime test #29", s);
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_strftime.out b/tests/core/test_strftime.out
new file mode 100644
index 00000000..0e2f2d7c
--- /dev/null
+++ b/tests/core/test_strftime.out
@@ -0,0 +1 @@
+11111111111111111111111111111 \ No newline at end of file
diff --git a/tests/core/test_strings.in b/tests/core/test_strings.in
new file mode 100644
index 00000000..6c7e2366
--- /dev/null
+++ b/tests/core/test_strings.in
@@ -0,0 +1,53 @@
+
+ #include <stdio.h>
+ #include <stdlib.h>
+ #include <string.h>
+
+ int main(int argc, char **argv)
+ {
+ int x = 5, y = 9, magic = 7; // fool compiler with magic
+ memmove(&x, &y, magic-7); // 0 should not crash us
+
+ int xx, yy, zz;
+ char s[32];
+ int cc = sscanf("abc_10.b1_xyz9_543_defg", "abc_%d.%2x_xyz9_%3d_%3s", &xx, &yy, &zz, s);
+ printf("%d:%d,%d,%d,%s\n", cc, xx, yy, zz, s);
+
+ printf("%d\n", argc);
+ puts(argv[1]);
+ puts(argv[2]);
+ printf("%d\n", atoi(argv[3])+2);
+ const char *foolingthecompiler = "\rabcd";
+ printf("%d\n", strlen(foolingthecompiler)); // Tests parsing /0D in llvm - should not be a 0 (end string) then a D!
+ printf("%s\n", NULL); // Should print '(null)', not the string at address 0, which is a real address for us!
+ printf("/* a comment */\n"); // Should not break the generated code!
+ printf("// another\n"); // Should not break the generated code!
+
+ char* strdup_val = strdup("test");
+ printf("%s\n", strdup_val);
+ free(strdup_val);
+
+ {
+ char *one = "one 1 ONE !";
+ char *two = "two 2 TWO ?";
+ char three[1024];
+ memset(three, '.', 1024);
+ three[50] = 0;
+ strncpy(three + argc, one + (argc/2), argc+1);
+ strncpy(three + argc*3, two + (argc/3), argc+2);
+ printf("waka %s\n", three);
+ }
+
+ {
+ char *one = "string number one top notch";
+ char *two = "fa la sa ho fi FI FO FUM WHEN WHERE WHY HOW WHO";
+ char three[1000];
+ strcpy(three, &one[argc*2]);
+ char *four = strcat(three, &two[argc*3]);
+ printf("cat |%s|\n", three);
+ printf("returned |%s|\n", four);
+ }
+
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_strings.out b/tests/core/test_strings.out
new file mode 100644
index 00000000..ddf9aee7
--- /dev/null
+++ b/tests/core/test_strings.out
@@ -0,0 +1,13 @@
+4:10,177,543,def
+4
+wowie
+too
+76
+5
+(null)
+/* a comment */
+// another
+test
+waka ....e 1 O...wo 2 T................................
+cat |umber one top notchfi FI FO FUM WHEN WHERE WHY HOW WHO|
+returned |umber one top notchfi FI FO FUM WHEN WHERE WHY HOW WHO| \ No newline at end of file
diff --git a/tests/core/test_strndup.in b/tests/core/test_strndup.in
new file mode 100644
index 00000000..938452a1
--- /dev/null
+++ b/tests/core/test_strndup.in
@@ -0,0 +1,39 @@
+
+ //---------------
+ //- http://pubs.opengroup.org/onlinepubs/9699919799/functions/strndup.html
+ //---------------
+
+ #include <stdio.h>
+ #include <stdlib.h>
+ #include <string.h>
+
+ int main(int argc, char **argv) {
+ const char* source = "strndup - duplicate a specific number of bytes from a string";
+
+ char* strdup_val = strndup(source, 0);
+ printf("1:%s\n", strdup_val);
+ free(strdup_val);
+
+ strdup_val = strndup(source, 7);
+ printf("2:%s\n", strdup_val);
+ free(strdup_val);
+
+ strdup_val = strndup(source, 1000);
+ printf("3:%s\n", strdup_val);
+ free(strdup_val);
+
+ strdup_val = strndup(source, 60);
+ printf("4:%s\n", strdup_val);
+ free(strdup_val);
+
+ strdup_val = strndup(source, 19);
+ printf("5:%s\n", strdup_val);
+ free(strdup_val);
+
+ strdup_val = strndup(source, -1);
+ printf("6:%s\n", strdup_val);
+ free(strdup_val);
+
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_strndup.out b/tests/core/test_strndup.out
new file mode 100644
index 00000000..681f00cc
--- /dev/null
+++ b/tests/core/test_strndup.out
@@ -0,0 +1,6 @@
+1:
+2:strndup
+3:strndup - duplicate a specific number of bytes from a string
+4:strndup - duplicate a specific number of bytes from a string
+5:strndup - duplicate
+6:
diff --git a/tests/core/test_strptime_days.in b/tests/core/test_strptime_days.in
new file mode 100644
index 00000000..d4f0c079
--- /dev/null
+++ b/tests/core/test_strptime_days.in
@@ -0,0 +1,34 @@
+
+ #include <time.h>
+ #include <stdio.h>
+ #include <string.h>
+
+ static const struct {
+ const char *input;
+ const char *format;
+ } day_tests[] = {
+ { "2000-01-01", "%Y-%m-%d"},
+ { "03/03/00", "%D"},
+ { "9/9/99", "%x"},
+ { "19990502123412", "%Y%m%d%H%M%S"},
+ { "2001 20 Mon", "%Y %U %a"},
+ { "2006 4 Fri", "%Y %U %a"},
+ { "2001 21 Mon", "%Y %W %a"},
+ { "2013 29 Wed", "%Y %W %a"},
+ { "2000-01-01 08:12:21 AM", "%Y-%m-%d %I:%M:%S %p"},
+ { "2000-01-01 08:12:21 PM", "%Y-%m-%d %I:%M:%S %p"},
+ { "2001 17 Tue", "%Y %U %a"},
+ { "2001 8 Thursday", "%Y %W %a"},
+ };
+
+ int main() {
+ struct tm tm;
+
+ for (int i = 0; i < sizeof (day_tests) / sizeof (day_tests[0]); ++i) {
+ memset (&tm, '\0', sizeof (tm));
+ char *ptr = strptime(day_tests[i].input, day_tests[i].format, &tm);
+
+ printf("%s: %d/%d/%d (%dth DoW, %dth DoY)\n", (ptr != NULL && *ptr=='\0') ? "OK" : "ERR", tm.tm_mon+1, tm.tm_mday, 1900+tm.tm_year, tm.tm_wday, tm.tm_yday);
+ }
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_strptime_days.out b/tests/core/test_strptime_days.out
new file mode 100644
index 00000000..dc409032
--- /dev/null
+++ b/tests/core/test_strptime_days.out
@@ -0,0 +1,12 @@
+OK: 1/1/2000 (6th DoW, 0th DoY)
+OK: 3/3/2000 (5th DoW, 62th DoY)
+OK: 9/9/1999 (4th DoW, 251th DoY)
+OK: 5/2/1999 (0th DoW, 121th DoY)
+OK: 5/21/2001 (1th DoW, 140th DoY)
+OK: 1/27/2006 (5th DoW, 26th DoY)
+OK: 5/21/2001 (1th DoW, 140th DoY)
+OK: 7/24/2013 (3th DoW, 204th DoY)
+OK: 1/1/2000 (6th DoW, 0th DoY)
+OK: 1/1/2000 (6th DoW, 0th DoY)
+OK: 5/1/2001 (2th DoW, 120th DoY)
+OK: 2/22/2001 (4th DoW, 52th DoY)
diff --git a/tests/core/test_strptime_reentrant.in b/tests/core/test_strptime_reentrant.in
new file mode 100644
index 00000000..b52d2399
--- /dev/null
+++ b/tests/core/test_strptime_reentrant.in
@@ -0,0 +1,47 @@
+
+ #include <time.h>
+ #include <stdio.h>
+ #include <string.h>
+ #include <stdlib.h>
+
+ int main () {
+ int result = 0;
+ struct tm tm;
+
+ memset (&tm, 0xaa, sizeof (tm));
+
+ /* Test we don't crash on uninitialized struct tm.
+ Some fields might contain bogus values until everything
+ needed is initialized, but we shouldn't crash. */
+ if (strptime ("2007", "%Y", &tm) == NULL
+ || strptime ("12", "%d", &tm) == NULL
+ || strptime ("Feb", "%b", &tm) == NULL
+ || strptime ("13", "%M", &tm) == NULL
+ || strptime ("21", "%S", &tm) == NULL
+ || strptime ("16", "%H", &tm) == NULL) {
+ printf("ERR: returned NULL");
+ exit(EXIT_FAILURE);
+ }
+
+ if (tm.tm_sec != 21 || tm.tm_min != 13 || tm.tm_hour != 16
+ || tm.tm_mday != 12 || tm.tm_mon != 1 || tm.tm_year != 107
+ || tm.tm_wday != 1 || tm.tm_yday != 42) {
+ printf("ERR: unexpected tm content (1) - %d/%d/%d %d:%d:%d", tm.tm_mon+1, tm.tm_mday, tm.tm_year+1900, tm.tm_hour, tm.tm_min, tm.tm_sec);
+ exit(EXIT_FAILURE);
+ }
+
+ if (strptime ("8", "%d", &tm) == NULL) {
+ printf("ERR: strptime failed");
+ exit(EXIT_FAILURE);
+ }
+
+ if (tm.tm_sec != 21 || tm.tm_min != 13 || tm.tm_hour != 16
+ || tm.tm_mday != 8 || tm.tm_mon != 1 || tm.tm_year != 107
+ || tm.tm_wday != 4 || tm.tm_yday != 38) {
+ printf("ERR: unexpected tm content (2) - %d/%d/%d %d:%d:%d", tm.tm_mon+1, tm.tm_mday, tm.tm_year+1900, tm.tm_hour, tm.tm_min, tm.tm_sec);
+ exit(EXIT_FAILURE);
+ }
+
+ printf("OK");
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_strptime_reentrant.out b/tests/core/test_strptime_reentrant.out
new file mode 100644
index 00000000..a0aba931
--- /dev/null
+++ b/tests/core/test_strptime_reentrant.out
@@ -0,0 +1 @@
+OK \ No newline at end of file
diff --git a/tests/core/test_strptime_tm.in b/tests/core/test_strptime_tm.in
new file mode 100644
index 00000000..29e40223
--- /dev/null
+++ b/tests/core/test_strptime_tm.in
@@ -0,0 +1,21 @@
+
+ #include <time.h>
+ #include <stdio.h>
+ #include <string.h>
+
+ int main() {
+ struct tm tm;
+ char *ptr = strptime("17410105012000", "%H%M%S%d%m%Y", &tm);
+
+ printf("%s: %s, %d/%d/%d %d:%d:%d",
+ (ptr != NULL && *ptr=='\0') ? "OK" : "ERR",
+ tm.tm_wday == 0 ? "Sun" : (tm.tm_wday == 1 ? "Mon" : (tm.tm_wday == 2 ? "Tue" : (tm.tm_wday == 3 ? "Wed" : (tm.tm_wday == 4 ? "Thu" : (tm.tm_wday == 5 ? "Fri" : (tm.tm_wday == 6 ? "Sat" : "ERR")))))),
+ tm.tm_mon+1,
+ tm.tm_mday,
+ tm.tm_year+1900,
+ tm.tm_hour,
+ tm.tm_min,
+ tm.tm_sec
+ );
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_strptime_tm.out b/tests/core/test_strptime_tm.out
new file mode 100644
index 00000000..32c321f7
--- /dev/null
+++ b/tests/core/test_strptime_tm.out
@@ -0,0 +1 @@
+OK: Wed, 1/5/2000 17:41:1 \ No newline at end of file
diff --git a/tests/core/test_strstr.in b/tests/core/test_strstr.in
new file mode 100644
index 00000000..ab049cac
--- /dev/null
+++ b/tests/core/test_strstr.in
@@ -0,0 +1,35 @@
+
+ #include <stdio.h>
+ #include <string.h>
+
+ int main()
+ {
+ printf("%d\n", !!strstr("\\n", "\\n"));
+ printf("%d\n", !!strstr("cheezy", "ez"));
+ printf("%d\n", !!strstr("cheeezy", "ez"));
+ printf("%d\n", !!strstr("cheeeeeeeeeezy", "ez"));
+ printf("%d\n", !!strstr("cheeeeeeeeee1zy", "ez"));
+ printf("%d\n", !!strstr("che1ezy", "ez"));
+ printf("%d\n", !!strstr("che1ezy", "che"));
+ printf("%d\n", !!strstr("ce1ezy", "che"));
+ printf("%d\n", !!strstr("ce1ezy", "ezy"));
+ printf("%d\n", !!strstr("ce1ezyt", "ezy"));
+ printf("%d\n", !!strstr("ce1ez1y", "ezy"));
+ printf("%d\n", !!strstr("cheezy", "a"));
+ printf("%d\n", !!strstr("cheezy", "b"));
+ printf("%d\n", !!strstr("cheezy", "c"));
+ printf("%d\n", !!strstr("cheezy", "d"));
+ printf("%d\n", !!strstr("cheezy", "g"));
+ printf("%d\n", !!strstr("cheezy", "h"));
+ printf("%d\n", !!strstr("cheezy", "i"));
+ printf("%d\n", !!strstr("cheezy", "e"));
+ printf("%d\n", !!strstr("cheezy", "x"));
+ printf("%d\n", !!strstr("cheezy", "y"));
+ printf("%d\n", !!strstr("cheezy", "z"));
+ printf("%d\n", !!strstr("cheezy", "_"));
+
+ const char *str = "a big string";
+ printf("%d\n", strstr(str, "big") - str);
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_strstr.out b/tests/core/test_strstr.out
new file mode 100644
index 00000000..aa0d917b
--- /dev/null
+++ b/tests/core/test_strstr.out
@@ -0,0 +1,24 @@
+1
+1
+1
+1
+0
+1
+1
+0
+1
+1
+0
+0
+0
+1
+0
+0
+1
+0
+1
+0
+1
+1
+0
+2
diff --git a/tests/core/test_strtok.in b/tests/core/test_strtok.in
new file mode 100644
index 00000000..6391b9b0
--- /dev/null
+++ b/tests/core/test_strtok.in
@@ -0,0 +1,20 @@
+
+ #include<stdio.h>
+ #include<string.h>
+
+ int main() {
+ char test[80], blah[80];
+ char *sep = "\\/:;=-";
+ char *word, *phrase, *brkt, *brkb;
+
+ strcpy(test, "This;is.a:test:of=the/string\\tokenizer-function.");
+
+ for (word = strtok_r(test, sep, &brkt); word; word = strtok_r(NULL, sep, &brkt)) {
+ strcpy(blah, "blah:blat:blab:blag");
+ for (phrase = strtok_r(blah, sep, &brkb); phrase; phrase = strtok_r(NULL, sep, &brkb)) {
+ printf("at %s:%s\n", word, phrase);
+ }
+ }
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_strtok.out b/tests/core/test_strtok.out
new file mode 100644
index 00000000..1e63af4b
--- /dev/null
+++ b/tests/core/test_strtok.out
@@ -0,0 +1,32 @@
+at This:blah
+at This:blat
+at This:blab
+at This:blag
+at is.a:blah
+at is.a:blat
+at is.a:blab
+at is.a:blag
+at test:blah
+at test:blat
+at test:blab
+at test:blag
+at of:blah
+at of:blat
+at of:blab
+at of:blag
+at the:blah
+at the:blat
+at the:blab
+at the:blag
+at string:blah
+at string:blat
+at string:blab
+at string:blag
+at tokenizer:blah
+at tokenizer:blat
+at tokenizer:blab
+at tokenizer:blag
+at function.:blah
+at function.:blat
+at function.:blab
+at function.:blag
diff --git a/tests/core/test_strtol_bin.in b/tests/core/test_strtol_bin.in
new file mode 100644
index 00000000..972853ba
--- /dev/null
+++ b/tests/core/test_strtol_bin.in
@@ -0,0 +1,17 @@
+
+ #include <stdio.h>
+ #include <stdlib.h>
+
+ int main() {
+ const char *STRING = "1 -101 +1011";
+ char *end_char;
+
+ // defined base
+ long l4 = strtol(STRING, &end_char, 2);
+ long l5 = strtol(end_char, &end_char, 2);
+ long l6 = strtol(end_char, NULL, 2);
+
+ printf("%d%d%d\n", l4==1, l5==-5, l6==11);
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_strtol_bin.out b/tests/core/test_strtol_bin.out
new file mode 100644
index 00000000..9d07aa0d
--- /dev/null
+++ b/tests/core/test_strtol_bin.out
@@ -0,0 +1 @@
+111 \ No newline at end of file
diff --git a/tests/core/test_strtol_dec.in b/tests/core/test_strtol_dec.in
new file mode 100644
index 00000000..496e5dc8
--- /dev/null
+++ b/tests/core/test_strtol_dec.in
@@ -0,0 +1,22 @@
+
+ #include <stdio.h>
+ #include <stdlib.h>
+
+ int main() {
+ const char *STRING = "4 -38 +4711";
+ char *end_char;
+
+ // undefined base
+ long l1 = strtol(STRING, &end_char, 0);
+ long l2 = strtol(end_char, &end_char, 0);
+ long l3 = strtol(end_char, NULL, 0);
+
+ // defined base
+ long l4 = strtol(STRING, &end_char, 10);
+ long l5 = strtol(end_char, &end_char, 10);
+ long l6 = strtol(end_char, NULL, 10);
+
+ printf("%d%d%d%d%d%d\n", l1==4, l2==-38, l3==4711, l4==4, l5==-38, l6==4711);
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_strtol_dec.out b/tests/core/test_strtol_dec.out
new file mode 100644
index 00000000..b23c1c51
--- /dev/null
+++ b/tests/core/test_strtol_dec.out
@@ -0,0 +1 @@
+111111 \ No newline at end of file
diff --git a/tests/core/test_strtol_hex.in b/tests/core/test_strtol_hex.in
new file mode 100644
index 00000000..f11d786a
--- /dev/null
+++ b/tests/core/test_strtol_hex.in
@@ -0,0 +1,22 @@
+
+ #include <stdio.h>
+ #include <stdlib.h>
+
+ int main() {
+ const char *STRING = "0x4 -0x3A +0xDEAD";
+ char *end_char;
+
+ // undefined base
+ long l1 = strtol(STRING, &end_char, 0);
+ long l2 = strtol(end_char, &end_char, 0);
+ long l3 = strtol(end_char, NULL, 0);
+
+ // defined base
+ long l4 = strtol(STRING, &end_char, 16);
+ long l5 = strtol(end_char, &end_char, 16);
+ long l6 = strtol(end_char, NULL, 16);
+
+ printf("%d%d%d%d%d%d\n", l1==0x4, l2==-0x3a, l3==0xdead, l4==0x4, l5==-0x3a, l6==0xdead);
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_strtol_hex.out b/tests/core/test_strtol_hex.out
new file mode 100644
index 00000000..b23c1c51
--- /dev/null
+++ b/tests/core/test_strtol_hex.out
@@ -0,0 +1 @@
+111111 \ No newline at end of file
diff --git a/tests/core/test_strtol_oct.in b/tests/core/test_strtol_oct.in
new file mode 100644
index 00000000..a50166a4
--- /dev/null
+++ b/tests/core/test_strtol_oct.in
@@ -0,0 +1,22 @@
+
+ #include <stdio.h>
+ #include <stdlib.h>
+
+ int main() {
+ const char *STRING = "0 -035 +04711";
+ char *end_char;
+
+ // undefined base
+ long l1 = strtol(STRING, &end_char, 0);
+ long l2 = strtol(end_char, &end_char, 0);
+ long l3 = strtol(end_char, NULL, 0);
+
+ // defined base
+ long l4 = strtol(STRING, &end_char, 8);
+ long l5 = strtol(end_char, &end_char, 8);
+ long l6 = strtol(end_char, NULL, 8);
+
+ printf("%d%d%d%d%d%d\n", l1==0, l2==-29, l3==2505, l4==0, l5==-29, l6==2505);
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_strtol_oct.out b/tests/core/test_strtol_oct.out
new file mode 100644
index 00000000..b23c1c51
--- /dev/null
+++ b/tests/core/test_strtol_oct.out
@@ -0,0 +1 @@
+111111 \ No newline at end of file
diff --git a/tests/core/test_strtoll_bin.in b/tests/core/test_strtoll_bin.in
new file mode 100644
index 00000000..ed3c4acf
--- /dev/null
+++ b/tests/core/test_strtoll_bin.in
@@ -0,0 +1,17 @@
+
+ #include <stdio.h>
+ #include <stdlib.h>
+
+ int main() {
+ const char *STRING = "1 -101 +1011";
+ char *end_char;
+
+ // defined base
+ long long int l4 = strtoll(STRING, &end_char, 2);
+ long long int l5 = strtoll(end_char, &end_char, 2);
+ long long int l6 = strtoll(end_char, NULL, 2);
+
+ printf("%d%d%d\n", l4==1, l5==-5, l6==11);
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_strtoll_bin.out b/tests/core/test_strtoll_bin.out
new file mode 100644
index 00000000..9d07aa0d
--- /dev/null
+++ b/tests/core/test_strtoll_bin.out
@@ -0,0 +1 @@
+111 \ No newline at end of file
diff --git a/tests/core/test_strtoll_dec.in b/tests/core/test_strtoll_dec.in
new file mode 100644
index 00000000..fbd5749c
--- /dev/null
+++ b/tests/core/test_strtoll_dec.in
@@ -0,0 +1,22 @@
+
+ #include <stdio.h>
+ #include <stdlib.h>
+
+ int main() {
+ const char *STRING = "4 -38 +4711";
+ char *end_char;
+
+ // undefined base
+ long long int l1 = strtoll(STRING, &end_char, 0);
+ long long int l2 = strtoll(end_char, &end_char, 0);
+ long long int l3 = strtoll(end_char, NULL, 0);
+
+ // defined base
+ long long int l4 = strtoll(STRING, &end_char, 10);
+ long long int l5 = strtoll(end_char, &end_char, 10);
+ long long int l6 = strtoll(end_char, NULL, 10);
+
+ printf("%d%d%d%d%d%d\n", l1==4, l2==-38, l3==4711, l4==4, l5==-38, l6==4711);
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_strtoll_dec.out b/tests/core/test_strtoll_dec.out
new file mode 100644
index 00000000..b23c1c51
--- /dev/null
+++ b/tests/core/test_strtoll_dec.out
@@ -0,0 +1 @@
+111111 \ No newline at end of file
diff --git a/tests/core/test_strtoll_hex.in b/tests/core/test_strtoll_hex.in
new file mode 100644
index 00000000..333fe512
--- /dev/null
+++ b/tests/core/test_strtoll_hex.in
@@ -0,0 +1,22 @@
+
+ #include <stdio.h>
+ #include <stdlib.h>
+
+ int main() {
+ const char *STRING = "0x4 -0x3A +0xDEADBEEF";
+ char *end_char;
+
+ // undefined base
+ long long int l1 = strtoll(STRING, &end_char, 0);
+ long long int l2 = strtoll(end_char, &end_char, 0);
+ long long int l3 = strtoll(end_char, NULL, 0);
+
+ // defined base
+ long long int l4 = strtoll(STRING, &end_char, 16);
+ long long int l5 = strtoll(end_char, &end_char, 16);
+ long long int l6 = strtoll(end_char, NULL, 16);
+
+ printf("%d%d%d%d%d%d\n", l1==0x4, l2==-0x3a, l3==0xdeadbeef, l4==0x4, l5==-0x3a, l6==0xdeadbeef);
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_strtoll_hex.out b/tests/core/test_strtoll_hex.out
new file mode 100644
index 00000000..b23c1c51
--- /dev/null
+++ b/tests/core/test_strtoll_hex.out
@@ -0,0 +1 @@
+111111 \ No newline at end of file
diff --git a/tests/core/test_strtoll_oct.in b/tests/core/test_strtoll_oct.in
new file mode 100644
index 00000000..260c7245
--- /dev/null
+++ b/tests/core/test_strtoll_oct.in
@@ -0,0 +1,22 @@
+
+ #include <stdio.h>
+ #include <stdlib.h>
+
+ int main() {
+ const char *STRING = "0 -035 +04711";
+ char *end_char;
+
+ // undefined base
+ long long int l1 = strtoll(STRING, &end_char, 0);
+ long long int l2 = strtoll(end_char, &end_char, 0);
+ long long int l3 = strtoll(end_char, NULL, 0);
+
+ // defined base
+ long long int l4 = strtoll(STRING, &end_char, 8);
+ long long int l5 = strtoll(end_char, &end_char, 8);
+ long long int l6 = strtoll(end_char, NULL, 8);
+
+ printf("%d%d%d%d%d%d\n", l1==0, l2==-29, l3==2505, l4==0, l5==-29, l6==2505);
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_strtoll_oct.out b/tests/core/test_strtoll_oct.out
new file mode 100644
index 00000000..b23c1c51
--- /dev/null
+++ b/tests/core/test_strtoll_oct.out
@@ -0,0 +1 @@
+111111 \ No newline at end of file
diff --git a/tests/core/test_structs.in b/tests/core/test_structs.in
new file mode 100644
index 00000000..47158351
--- /dev/null
+++ b/tests/core/test_structs.in
@@ -0,0 +1,22 @@
+
+ #include <stdio.h>
+ struct S
+ {
+ int x, y;
+ };
+ int main()
+ {
+ S a, b;
+ a.x = 5; a.y = 6;
+ b.x = 101; b.y = 7009;
+ S *c, *d;
+ c = &a;
+ c->x *= 2;
+ c = &b;
+ c->y -= 1;
+ d = c;
+ d->y += 10;
+ printf("*%d,%d,%d,%d,%d,%d,%d,%d*\n", a.x, a.y, b.x, b.y, c->x, c->y, d->x, d->y);
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_structs.out b/tests/core/test_structs.out
new file mode 100644
index 00000000..7748b49e
--- /dev/null
+++ b/tests/core/test_structs.out
@@ -0,0 +1 @@
+*10,6,101,7018,101,7018,101,7018* \ No newline at end of file
diff --git a/tests/core/test_time_c.in b/tests/core/test_time_c.in
new file mode 100644
index 00000000..57b47217
--- /dev/null
+++ b/tests/core/test_time_c.in
@@ -0,0 +1,9 @@
+
+ #include <time.h>
+ #include <stdio.h>
+
+ int main() {
+ time_t t = time(0);
+ printf("time: %s\n", ctime(&t));
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_time_c.out b/tests/core/test_time_c.out
new file mode 100644
index 00000000..dc3e339b
--- /dev/null
+++ b/tests/core/test_time_c.out
@@ -0,0 +1 @@
+time: \ No newline at end of file
diff --git a/tests/core/test_timeb.in b/tests/core/test_timeb.in
new file mode 100644
index 00000000..baaefb8c
--- /dev/null
+++ b/tests/core/test_timeb.in
@@ -0,0 +1,15 @@
+
+ #include <stdio.h>
+ #include <assert.h>
+ #include <sys/timeb.h>
+
+ int main() {
+ timeb tb;
+ tb.timezone = 1;
+ printf("*%d\n", ftime(&tb));
+ assert(tb.time > 10000);
+ assert(tb.timezone == 0);
+ assert(tb.dstflag == 0);
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_timeb.out b/tests/core/test_timeb.out
new file mode 100644
index 00000000..488c9af7
--- /dev/null
+++ b/tests/core/test_timeb.out
@@ -0,0 +1 @@
+*0
diff --git a/tests/core/test_tinyfuncstr.in b/tests/core/test_tinyfuncstr.in
new file mode 100644
index 00000000..ea07ff33
--- /dev/null
+++ b/tests/core/test_tinyfuncstr.in
@@ -0,0 +1,13 @@
+
+ #include <stdio.h>
+
+ struct Class {
+ static char *name1() { return "nameA"; }
+ char *name2() { return "nameB"; }
+ };
+
+ int main() {
+ printf("*%s,%s*\n", Class::name1(), (new Class())->name2());
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_tinyfuncstr.out b/tests/core/test_tinyfuncstr.out
new file mode 100644
index 00000000..ed0d2567
--- /dev/null
+++ b/tests/core/test_tinyfuncstr.out
@@ -0,0 +1 @@
+*nameA,nameB* \ No newline at end of file
diff --git a/tests/core/test_transtrcase.in b/tests/core/test_transtrcase.in
new file mode 100644
index 00000000..0592405e
--- /dev/null
+++ b/tests/core/test_transtrcase.in
@@ -0,0 +1,13 @@
+
+ #include <stdio.h>
+ #include <string.h>
+ int main() {
+ char szToupr[] = "hello, ";
+ char szTolwr[] = "EMSCRIPTEN";
+ strupr(szToupr);
+ strlwr(szTolwr);
+ printf(szToupr);
+ printf(szTolwr);
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_transtrcase.out b/tests/core/test_transtrcase.out
new file mode 100644
index 00000000..dbb541e6
--- /dev/null
+++ b/tests/core/test_transtrcase.out
@@ -0,0 +1 @@
+HELLO, emscripten \ No newline at end of file
diff --git a/tests/core/test_trickystring.in b/tests/core/test_trickystring.in
new file mode 100644
index 00000000..95744369
--- /dev/null
+++ b/tests/core/test_trickystring.in
@@ -0,0 +1,26 @@
+
+ #include <stdio.h>
+
+ typedef struct
+ {
+ int (*f)(void *);
+ void *d;
+ char s[16];
+ } LMEXFunctionStruct;
+
+ int f(void *user)
+ {
+ return 0;
+ }
+
+ static LMEXFunctionStruct const a[] =
+ {
+ {f, (void *)(int)'a', "aa"}
+ };
+
+ int main()
+ {
+ printf("ok\n");
+ return a[0].f(a[0].d);
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_trickystring.out b/tests/core/test_trickystring.out
new file mode 100644
index 00000000..9766475a
--- /dev/null
+++ b/tests/core/test_trickystring.out
@@ -0,0 +1 @@
+ok
diff --git a/tests/core/test_typeid.in b/tests/core/test_typeid.in
new file mode 100644
index 00000000..fc777183
--- /dev/null
+++ b/tests/core/test_typeid.in
@@ -0,0 +1,53 @@
+
+ #include <stdio.h>
+ #include <string.h>
+ #include <typeinfo>
+ int main() {
+ printf("*\n");
+ #define MAX 100
+ int ptrs[MAX];
+ int groups[MAX];
+ memset(ptrs, 0, MAX*sizeof(int));
+ memset(groups, 0, MAX*sizeof(int));
+ int next_group = 1;
+ #define TEST(X) { \
+ int ptr = (int)&typeid(X); \
+ int group = 0; \
+ int i; \
+ for (i = 0; i < MAX; i++) { \
+ if (!groups[i]) break; \
+ if (ptrs[i] == ptr) { \
+ group = groups[i]; \
+ break; \
+ } \
+ } \
+ if (!group) { \
+ groups[i] = group = next_group++; \
+ ptrs[i] = ptr; \
+ } \
+ printf("%s:%d\n", #X, group); \
+ }
+ TEST(int);
+ TEST(unsigned int);
+ TEST(unsigned);
+ TEST(signed int);
+ TEST(long);
+ TEST(unsigned long);
+ TEST(signed long);
+ TEST(long long);
+ TEST(unsigned long long);
+ TEST(signed long long);
+ TEST(short);
+ TEST(unsigned short);
+ TEST(signed short);
+ TEST(char);
+ TEST(unsigned char);
+ TEST(signed char);
+ TEST(float);
+ TEST(double);
+ TEST(long double);
+ TEST(void);
+ TEST(void*);
+ printf("*\n");
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_typeid.out b/tests/core/test_typeid.out
new file mode 100644
index 00000000..6355c27d
--- /dev/null
+++ b/tests/core/test_typeid.out
@@ -0,0 +1,23 @@
+*
+int:1
+unsigned int:2
+unsigned:2
+signed int:1
+long:3
+unsigned long:4
+signed long:3
+long long:5
+unsigned long long:6
+signed long long:5
+short:7
+unsigned short:8
+signed short:7
+char:9
+unsigned char:10
+signed char:11
+float:12
+double:13
+long double:14
+void:15
+void*:16
+*
diff --git a/tests/core/test_uname.in b/tests/core/test_uname.in
new file mode 100644
index 00000000..5ea40b06
--- /dev/null
+++ b/tests/core/test_uname.in
@@ -0,0 +1,16 @@
+
+ #include <stdio.h>
+ #include <sys/utsname.h>
+
+ int main() {
+ struct utsname u;
+ printf("ret: %d\n", uname(&u));
+ printf("sysname: %s\n", u.sysname);
+ printf("nodename: %s\n", u.nodename);
+ printf("release: %s\n", u.release);
+ printf("version: %s\n", u.version);
+ printf("machine: %s\n", u.machine);
+ printf("invalid: %d\n", uname(0));
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_uname.out b/tests/core/test_uname.out
new file mode 100644
index 00000000..cd36c531
--- /dev/null
+++ b/tests/core/test_uname.out
@@ -0,0 +1,6 @@
+ret: 0
+sysname: Emscripten
+nodename: emscripten
+release: 1.0
+version: #1
+machine: x86-JS
diff --git a/tests/core/test_utf.in b/tests/core/test_utf.in
new file mode 100644
index 00000000..29cb6eac
--- /dev/null
+++ b/tests/core/test_utf.in
@@ -0,0 +1,13 @@
+
+ #include <stdio.h>
+ #include <emscripten.h>
+
+ int main() {
+ char *c = "μ†ℱ ╋ℯ╳╋ 😇";
+ printf("%d %d %d %d %s\n", c[0]&0xff, c[1]&0xff, c[2]&0xff, c[3]&0xff, c);
+ emscripten_run_script(
+ "cheez = _malloc(100);"
+ "Module.writeStringToMemory(\"μ†ℱ ╋ℯ╳╋ 😇\", cheez);"
+ "Module.print([Pointer_stringify(cheez), Module.getValue(cheez, 'i8')&0xff, Module.getValue(cheez+1, 'i8')&0xff, Module.getValue(cheez+2, 'i8')&0xff, Module.getValue(cheez+3, 'i8')&0xff, ]);");
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_utf.out b/tests/core/test_utf.out
new file mode 100644
index 00000000..a2af5f8b
--- /dev/null
+++ b/tests/core/test_utf.out
@@ -0,0 +1,2 @@
+206 188 226 128 μ†ℱ ╋ℯ╳╋ 😇
+μ†ℱ ╋ℯ╳╋ 😇,206,188,226,128
diff --git a/tests/core/test_varargs.in b/tests/core/test_varargs.in
new file mode 100644
index 00000000..d169c151
--- /dev/null
+++ b/tests/core/test_varargs.in
@@ -0,0 +1,103 @@
+
+ #include <stdio.h>
+ #include <stdarg.h>
+
+ void vary(const char *s, ...)
+ {
+ va_list v;
+ va_start(v, s);
+ char d[20];
+ vsnprintf(d, 20, s, v);
+ puts(d);
+
+ // Try it with copying
+ va_list tempva;
+ va_copy(tempva, v);
+ vsnprintf(d, 20, s, tempva);
+ puts(d);
+
+ va_end(v);
+ }
+
+ void vary2(char color, const char *s, ...)
+ {
+ va_list v;
+ va_start(v, s);
+ char d[21];
+ d[0] = color;
+ vsnprintf(d+1, 20, s, v);
+ puts(d);
+ va_end(v);
+ }
+
+ void varargs_listoffsets_list_evaluate(int count, va_list ap, int vaIteration)
+ {
+ while(count > 0)
+ {
+ const char* string = va_arg(ap, const char*);
+ printf("%s", string);
+ count--;
+ }
+ printf("\n");
+ }
+
+ void varags_listoffsets_list_copy(int count, va_list ap, int iteration)
+ {
+ va_list ap_copy;
+ va_copy(ap_copy, ap);
+ varargs_listoffsets_list_evaluate(count, ap_copy, iteration);
+ va_end(ap_copy);
+ }
+
+ void varargs_listoffsets_args(int type, int count, ...)
+ {
+ va_list ap;
+ va_start(ap, count);
+
+ // evaluate a copied list
+ varags_listoffsets_list_copy(count, ap, 1);
+ varags_listoffsets_list_copy(count, ap, 2);
+ varags_listoffsets_list_copy(count, ap, 3);
+ varags_listoffsets_list_copy(count, ap, 4);
+
+ varargs_listoffsets_list_evaluate(count, ap, 1);
+
+ // NOTE: we expect this test to fail, so we will check the stdout for <BAD+0><BAD+1>.....
+ varargs_listoffsets_list_evaluate(count, ap, 2);
+
+ // NOTE: this test has to work again, as we restart the list
+ va_end(ap);
+ va_start(ap, count);
+ varargs_listoffsets_list_evaluate(count, ap, 3);
+ va_end(ap);
+ }
+
+ void varargs_listoffsets_main()
+ {
+ varargs_listoffsets_args(0, 5, "abc", "def", "ghi", "jkl", "mno", "<BAD+0>", "<BAD+1>", "<BAD+2>", "<BAD+3>", "<BAD+4>", "<BAD+5>", "<BAD+6>", "<BAD+7>", "<BAD+8>", "<BAD+9>", "<BAD+10>", "<BAD+11>", "<BAD+12>", "<BAD+13>", "<BAD+14>", "<BAD+15>", "<BAD+16>");
+ }
+
+ #define GETMAX(pref, type) type getMax##pref(int num, ...) { va_list vv; va_start(vv, num); type maxx = va_arg(vv, type); for (int i = 1; i < num; i++) { type curr = va_arg(vv, type); maxx = curr > maxx ? curr : maxx; } va_end(vv); return maxx; }
+ GETMAX(i, int);
+ GETMAX(D, double);
+
+ int main(int argc, char **argv) {
+ vary("*cheez: %d+%d*", 0, 24); // Also tests that '0' is not special as an array ender
+ vary("*albeit*"); // Should not fail with no var args in vararg function
+ vary2('Q', "%d*", 85);
+
+ int maxxi = getMaxi(6, 2, 5, 21, 4, -10, 19);
+ printf("maxxi:%d*\n", maxxi);
+ double maxxD = getMaxD(6, (double)2.1, (double)5.1, (double)22.1, (double)4.1, (double)-10.1, (double)19.1, (double)2);
+ printf("maxxD:%.2f*\n", (float)maxxD);
+
+ // And, as a function pointer
+ void (*vfp)(const char *s, ...) = argc == 1211 ? NULL : vary;
+ vfp("*vfp:%d,%d*", 22, 199);
+
+ // ensure lists work properly when copied, reinited etc.
+ varargs_listoffsets_main();
+
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_varargs.out b/tests/core/test_varargs.out
new file mode 100644
index 00000000..42a30d74
--- /dev/null
+++ b/tests/core/test_varargs.out
@@ -0,0 +1,16 @@
+*cheez: 0+24*
+*cheez: 0+24*
+*albeit*
+*albeit*
+Q85*
+maxxi:21*
+maxxD:22.10*
+*vfp:22,199*
+*vfp:22,199*
+abcdefghijklmno
+abcdefghijklmno
+abcdefghijklmno
+abcdefghijklmno
+abcdefghijklmno
+<BAD+0><BAD+1><BAD+2><BAD+3><BAD+4>
+abcdefghijklmno
diff --git a/tests/core/test_vprintf.in b/tests/core/test_vprintf.in
new file mode 100644
index 00000000..fcaad9d9
--- /dev/null
+++ b/tests/core/test_vprintf.in
@@ -0,0 +1,18 @@
+
+ #include <stdio.h>
+ #include <stdarg.h>
+
+ void print(char* format, ...) {
+ va_list args;
+ va_start (args, format);
+ vprintf (format, args);
+ va_end (args);
+ }
+
+ int main () {
+ print("Call with %d variable argument.\n", 1);
+ print("Call with %d variable %s.\n", 2, "arguments");
+
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_vprintf.out b/tests/core/test_vprintf.out
new file mode 100644
index 00000000..16f21510
--- /dev/null
+++ b/tests/core/test_vprintf.out
@@ -0,0 +1,2 @@
+Call with 1 variable argument.
+Call with 2 variable arguments.
diff --git a/tests/core/test_vsnprintf.in b/tests/core/test_vsnprintf.in
new file mode 100644
index 00000000..938729b6
--- /dev/null
+++ b/tests/core/test_vsnprintf.in
@@ -0,0 +1,44 @@
+
+ #include <stdio.h>
+ #include <stdarg.h>
+ #include <stdint.h>
+
+ void printy(const char *f, ...)
+ {
+ char buffer[256];
+ va_list args;
+ va_start(args, f);
+ vsnprintf(buffer, 256, f, args);
+ puts(buffer);
+ va_end(args);
+ }
+
+ int main(int argc, char **argv) {
+ int64_t x = argc - 1;
+ int64_t y = argc - 1 + 0x400000;
+ if (x % 3 == 2) y *= 2;
+
+ printy("0x%llx_0x%llx", x, y);
+ printy("0x%llx_0x%llx", x, x);
+ printy("0x%llx_0x%llx", y, x);
+ printy("0x%llx_0x%llx", y, y);
+
+ {
+ uint64_t A = 0x800000;
+ uint64_t B = 0x800000000000ULL;
+ printy("0x%llx_0x%llx", A, B);
+ }
+ {
+ uint64_t A = 0x800;
+ uint64_t B = 0x12340000000000ULL;
+ printy("0x%llx_0x%llx", A, B);
+ }
+ {
+ uint64_t A = 0x000009182746756;
+ uint64_t B = 0x192837465631ACBDULL;
+ printy("0x%llx_0x%llx", A, B);
+ }
+
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_vsnprintf.out b/tests/core/test_vsnprintf.out
new file mode 100644
index 00000000..ef8a3f7e
--- /dev/null
+++ b/tests/core/test_vsnprintf.out
@@ -0,0 +1,7 @@
+0x0_0x400000
+0x0_0x0
+0x400000_0x0
+0x400000_0x400000
+0x800000_0x800000000000
+0x800_0x12340000000000
+0x9182746756_0x192837465631acbd
diff --git a/tests/core/test_white_list_exception.in b/tests/core/test_white_list_exception.in
new file mode 100644
index 00000000..c7c29c35
--- /dev/null
+++ b/tests/core/test_white_list_exception.in
@@ -0,0 +1,22 @@
+
+ #include <stdio.h>
+
+ void thrower() {
+ printf("infunc...");
+ throw(99);
+ printf("FAIL");
+ }
+
+ void somefunction() {
+ try {
+ thrower();
+ } catch(...) {
+ printf("done!*\n");
+ }
+ }
+
+ int main() {
+ somefunction();
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_white_list_exception.out b/tests/core/test_white_list_exception.out
new file mode 100644
index 00000000..62e1a81c
--- /dev/null
+++ b/tests/core/test_white_list_exception.out
@@ -0,0 +1 @@
+infunc...done!* \ No newline at end of file
diff --git a/tests/core/test_zero_multiplication.in b/tests/core/test_zero_multiplication.in
new file mode 100644
index 00000000..2be87594
--- /dev/null
+++ b/tests/core/test_zero_multiplication.in
@@ -0,0 +1,14 @@
+
+ #include <stdio.h>
+ int main(int argc, char * argv[]) {
+ int one = argc;
+
+ printf("%d ", 0 * one);
+ printf("%d ", 0 * -one);
+ printf("%d ", -one * 0);
+ printf("%g ", 0.0 * one);
+ printf("%g ", 0.0 * -one);
+ printf("%g", -one * 0.0);
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_zero_multiplication.out b/tests/core/test_zero_multiplication.out
new file mode 100644
index 00000000..bb69c671
--- /dev/null
+++ b/tests/core/test_zero_multiplication.out
@@ -0,0 +1 @@
+0 0 0 0 -0 -0 \ No newline at end of file
diff --git a/tests/core/test_zerodiv.in b/tests/core/test_zerodiv.in
new file mode 100644
index 00000000..991b6c1d
--- /dev/null
+++ b/tests/core/test_zerodiv.in
@@ -0,0 +1,21 @@
+
+ #include <stdio.h>
+ int main(int argc, const char* argv[])
+ {
+ float f1 = 1.0f;
+ float f2 = 0.0f;
+ float f_zero = 0.0f;
+
+ float f3 = 0.0f / f2;
+ float f4 = f2 / 0.0f;
+ float f5 = f2 / f2;
+ float f6 = f2 / f_zero;
+
+ printf("f3: %f\n", f3);
+ printf("f4: %f\n", f4);
+ printf("f5: %f\n", f5);
+ printf("f6: %f\n", f6);
+
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_zerodiv.out b/tests/core/test_zerodiv.out
new file mode 100644
index 00000000..3bb47f8a
--- /dev/null
+++ b/tests/core/test_zerodiv.out
@@ -0,0 +1,4 @@
+f3: nan
+f4: nan
+f5: nan
+f6: nan
diff --git a/tests/runner.py b/tests/runner.py
index 34435383..8a5e1129 100755
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -418,6 +418,12 @@ process(sys.argv[1])
'''
return (main, supp)
+ def do_run_from_file(self, src, expected_output, args=[], output_nicerizer=None, output_processor=None, no_build=False, main_file=None, additional_files=[], js_engines=None, post_build=None, basename='src.cpp', libraries=[], includes=[], force_c=False, build_ll_hook=None, extra_emscripten_args=[]):
+ self.do_run(open(src).read(), open(expected_output).read(),
+ args, output_nicerizer, output_processor, no_build, main_file,
+ additional_files, js_engines, post_build, basename, libraries,
+ includes, force_c, build_ll_hook, extra_emscripten_args)
+
## Does a complete test - builds, runs, checks output, etc.
def do_run(self, src, expected_output, args=[], output_nicerizer=None, output_processor=None, no_build=False, main_file=None, additional_files=[], js_engines=None, post_build=None, basename='src.cpp', libraries=[], includes=[], force_c=False, build_ll_hook=None, extra_emscripten_args=[]):
if force_c or (main_file is not None and main_file[-2:]) == '.c':
diff --git a/tests/test_core.py b/tests/test_core.py
index b3e57490..f8b077b7 100644
--- a/tests/test_core.py
+++ b/tests/test_core.py
@@ -10,103 +10,29 @@ class T(RunnerCore): # Short name, to make it more fun to use manually on the co
return not ('i386-pc-linux-gnu' in COMPILER_OPTS or self.env.get('EMCC_LLVM_TARGET') == 'i386-pc-linux-gnu')
def test_hello_world(self):
- src = '''
- #include <stdio.h>
- int main()
- {
- printf("hello, world!\\n");
- return 0;
- }
- '''
- self.do_run(src, 'hello, world!')
+ test_path = path_from_root('tests', 'core', 'test_hello_world')
+ src, output = (test_path + s for s in ('.in', '.out'))
+
+ self.do_run_from_file(src, output)
assert 'EMSCRIPTEN_GENERATED_FUNCTIONS' not in open(self.in_dir('src.cpp.o.js')).read(), 'must not emit this unneeded internal thing'
def test_intvars(self):
if self.emcc_args == None: return self.skip('needs ta2')
- src = '''
- #include <stdio.h>
- int global = 20;
- int *far;
- int main()
- {
- int x = 5;
- int y = x+17;
- int z = (y-1)/2; // Should stay an integer after division!
- y += 1;
- int w = x*3+4;
- int k = w < 15 ? 99 : 101;
- far = &k;
- *far += global;
- int i = k > 100; // Should be an int, not a bool!
- int j = i << 6;
- j >>= 1;
- j = j ^ 5;
- int h = 1;
- h |= 0;
- int p = h;
- p &= 0;
- printf("*%d,%d,%d,%d,%d,%d,%d,%d,%d*\\n", x, y, z, w, k, i, j, h, p);
-
- long hash = -1;
- size_t perturb;
- int ii = 0;
- for (perturb = hash; ; perturb >>= 5) {
- printf("%d:%d", ii, perturb);
- ii++;
- if (ii == 9) break;
- printf(",");
- }
- printf("*\\n");
- printf("*%.1d,%.2d*\\n", 56, 9);
-
- // Fixed-point math on 64-bit ints. Tricky to support since we have no 64-bit shifts in JS
- {
- struct Fixed {
- static int Mult(int a, int b) {
- return ((long long)a * (long long)b) >> 16;
- }
- };
- printf("fixed:%d\\n", Fixed::Mult(150000, 140000));
- }
+ test_path = path_from_root('tests', 'core', 'test_intvars')
+ src, output = (test_path + s for s in ('.in', '.out'))
- printf("*%ld*%p\\n", (long)21, &hash); // The %p should not enter an infinite loop!
- return 0;
- }
- '''
- self.do_run(src, '*5,23,10,19,121,1,37,1,0*\n0:-1,1:134217727,2:4194303,3:131071,4:4095,5:127,6:3,7:0,8:0*\n*56,09*\nfixed:320434\n*21*')
+ self.do_run_from_file(src, output)
def test_sintvars(self):
Settings.CORRECT_SIGNS = 1 # Relevant to this test
- src = '''
- #include <stdio.h>
- struct S {
- char *match_start;
- char *strstart;
- };
- int main()
- {
- struct S _s;
- struct S *s = &_s;
- unsigned short int sh;
-
- s->match_start = (char*)32522;
- s->strstart = (char*)(32780);
- printf("*%d,%d,%d*\\n", (int)s->strstart, (int)s->match_start, (int)(s->strstart - s->match_start));
- sh = s->strstart - s->match_start;
- printf("*%d,%d*\\n", sh, sh>>7);
-
- s->match_start = (char*)32999;
- s->strstart = (char*)(32780);
- printf("*%d,%d,%d*\\n", (int)s->strstart, (int)s->match_start, (int)(s->strstart - s->match_start));
- sh = s->strstart - s->match_start;
- printf("*%d,%d*\\n", sh, sh>>7);
- }
- '''
- output = '*32780,32522,258*\n*258,2*\n*32780,32999,-219*\n*65317,510*'
Settings.CORRECT_OVERFLOWS = 0 # We should not need overflow correction to get this right
- self.do_run(src, output, force_c=True)
+
+ test_path = path_from_root('tests', 'core', 'test_sintvars')
+ src, output = (test_path + s for s in ('.in', '.out'))
+
+ self.do_run_from_file(src, output, force_c=True)
def test_i64(self):
if Settings.USE_TYPED_ARRAYS != 2: return self.skip('i64 mode 1 requires ta2')
@@ -338,169 +264,42 @@ class T(RunnerCore): # Short name, to make it more fun to use manually on the co
def test_i64_b(self):
if Settings.USE_TYPED_ARRAYS != 2: return self.skip('full i64 stuff only in ta2')
- src = r'''
- #include <stdio.h>
- #include <sys/time.h>
-
- typedef long long int64;
-
- #define PRMJ_USEC_PER_SEC 1000000L
-
- int main(int argc, char * argv[]) {
- int64 sec = 1329409675 + argc;
- int64 usec = 2329509675;
- int64 mul = int64(sec) * PRMJ_USEC_PER_SEC;
- int64 add = mul + int64(usec);
- int add_low = add;
- int add_high = add >> 32;
- printf("*%lld,%lld,%u,%u*\n", mul, add, add_low, add_high);
- int64 x = sec + (usec << 25);
- x >>= argc*3;
- printf("*%llu*\n", x);
- return 0;
- }
- '''
+ test_path = path_from_root('tests', 'core', 'test_i64_b')
+ src, output = (test_path + s for s in ('.in', '.out'))
- self.do_run(src, '*1329409676000000,1329412005509675,3663280683,309527*\n*9770671914067409*\n')
+ self.do_run_from_file(src, output)
def test_i64_cmp(self):
if Settings.USE_TYPED_ARRAYS != 2: return self.skip('full i64 stuff only in ta2')
- src = r'''
- #include <stdio.h>
-
- typedef long long int64;
-
- bool compare(int64 val) {
- return val == -12;
- }
-
- bool compare2(int64 val) {
- return val < -12;
- }
-
- int main(int argc, char * argv[]) {
- printf("*%d,%d,%d,%d,%d,%d*\n", argc, compare(argc-1-12), compare(1000+argc), compare2(argc-1-10), compare2(argc-1-14), compare2(argc+1000));
- return 0;
- }
- '''
+ test_path = path_from_root('tests', 'core', 'test_i64_cmp')
+ src, output = (test_path + s for s in ('.in', '.out'))
- self.do_run(src, '*1,1,0,0,1,0*\n')
+ self.do_run_from_file(src, output)
def test_i64_cmp2(self):
if Settings.USE_TYPED_ARRAYS != 2: return self.skip('full i64 stuff only in ta2')
- src = r'''
- #include <inttypes.h>
- #include <stdio.h>
-
- typedef int32_t INT32;
- typedef int64_t INT64;
- typedef uint8_t UINT8;
+ test_path = path_from_root('tests', 'core', 'test_i64_cmp2')
+ src, output = (test_path + s for s in ('.in', '.out'))
- void interface_clock_changed()
- {
- UINT8 m_divshift;
- INT32 m_divisor;
-
- //INT64 attos = m_attoseconds_per_cycle;
- INT64 attos = 279365114840;
- m_divshift = 0;
- while (attos >= (1UL << 31))
- {
- m_divshift++;
- printf("m_divshift is %i, on %Ld >?= %lu\n", m_divshift, attos, 1UL << 31);
- attos >>= 1;
- }
- m_divisor = attos;
-
- printf("m_divisor is %i\n",m_divisor);
- }
-
- int main() {
- interface_clock_changed();
- return 0;
- }
- '''
- self.do_run(src, '''m_divshift is 1, on 279365114840 >?= 2147483648
-m_divshift is 2, on 139682557420 >?= 2147483648
-m_divshift is 3, on 69841278710 >?= 2147483648
-m_divshift is 4, on 34920639355 >?= 2147483648
-m_divshift is 5, on 17460319677 >?= 2147483648
-m_divshift is 6, on 8730159838 >?= 2147483648
-m_divshift is 7, on 4365079919 >?= 2147483648
-m_divshift is 8, on 2182539959 >?= 2147483648
-m_divisor is 1091269979
-''')
+ self.do_run_from_file(src, output)
def test_i64_double(self):
if Settings.USE_TYPED_ARRAYS != 2: return self.skip('full i64 stuff only in ta2')
+ test_path = path_from_root('tests', 'core', 'test_i64_double')
+ src, output = (test_path + s for s in ('.in', '.out'))
- src = r'''
- #include <stdio.h>
-
- typedef long long int64;
- #define JSDOUBLE_HI32_SIGNBIT 0x80000000
-
- bool JSDOUBLE_IS_NEGZERO(double d)
- {
- union {
- struct {
- unsigned int lo, hi;
- } s;
- double d;
- } x;
- if (d != 0)
- return false;
- x.d = d;
- return (x.s.hi & JSDOUBLE_HI32_SIGNBIT) != 0;
- }
-
- bool JSINT64_IS_NEGZERO(int64 l)
- {
- union {
- int64 i;
- double d;
- } x;
- if (l != 0)
- return false;
- x.i = l;
- return x.d == -0;
- }
-
- int main(int argc, char * argv[]) {
- printf("*%d,%d,%d,%d*\n", JSDOUBLE_IS_NEGZERO(0), JSDOUBLE_IS_NEGZERO(-0), JSDOUBLE_IS_NEGZERO(-1), JSDOUBLE_IS_NEGZERO(+1));
- printf("*%d,%d,%d,%d*\n", JSINT64_IS_NEGZERO(0), JSINT64_IS_NEGZERO(-0), JSINT64_IS_NEGZERO(-1), JSINT64_IS_NEGZERO(+1));
- return 0;
- }
- '''
- self.do_run(src, '*0,0,0,0*\n*1,1,0,0*\n') # same as gcc
+ self.do_run_from_file(src, output)
def test_i64_umul(self):
if Settings.USE_TYPED_ARRAYS != 2: return self.skip('full i64 stuff only in ta2')
- src = r'''
- #include <inttypes.h>
- #include <stdio.h>
-
- typedef uint32_t UINT32;
- typedef uint64_t UINT64;
+ test_path = path_from_root('tests', 'core', 'test_i64_umul')
+ src, output = (test_path + s for s in ('.in', '.out'))
- int main() {
- volatile UINT32 testu32a = 2375724032U;
- UINT32 bigu32 = 0xffffffffU;
- volatile UINT64 testu64a = 14746250828952703000U;
-
- while ((UINT64)testu32a * (UINT64)bigu32 < testu64a) {
- printf("testu64a is %llu\n", testu64a);
- testu64a /= 2;
- }
-
- return 0;
- }
- '''
- self.do_run(src, 'testu64a is 14746250828952703000\n')
+ self.do_run_from_file(src, output)
def test_i64_precise(self):
if Settings.USE_TYPED_ARRAYS != 2: return self.skip('full i64 stuff only in ta2')
@@ -579,513 +378,117 @@ m_divisor is 1091269979
def test_i64_llabs(self):
if Settings.USE_TYPED_ARRAYS != 2: return self.skip('full i64 stuff only in ta2')
Settings.PRECISE_I64_MATH = 2
- self.do_run(r'''
- #include <stdio.h>
- #include <stdlib.h>
- int main(int argc, char ** argv) {
- printf("%lld,%lld\n", llabs(-576460752303423489), llabs(576460752303423489));
- return 0;
- }
- ''', '576460752303423489,576460752303423489')
+ test_path = path_from_root('tests', 'core', 'test_i64_llabs')
+ src, output = (test_path + s for s in ('.in', '.out'))
+
+ self.do_run_from_file(src, output)
def test_i64_zextneg(self):
if Settings.USE_TYPED_ARRAYS != 2: return self.skip('full i64 stuff only in ta2')
- src = r'''
- #include <stdint.h>
- #include <stdio.h>
+ test_path = path_from_root('tests', 'core', 'test_i64_zextneg')
+ src, output = (test_path + s for s in ('.in', '.out'))
- int main(int argc, char *argv[])
- {
- uint8_t byte = 0x80;
- uint16_t two = byte;
- uint32_t four = byte;
- uint64_t eight = byte;
-
- printf("value: %d,%d,%d,%lld.\n", byte, two, four, eight);
-
- return 0;
- }
- '''
- self.do_run(src, 'value: 128,128,128,128.')
+ self.do_run_from_file(src, output)
def test_i64_7z(self):
if Settings.USE_TYPED_ARRAYS != 2: return self.skip('full i64 stuff only in ta2')
- src = r'''
- #include <stdint.h>
- #include <stdio.h>
- uint64_t a, b;
- int main(int argc, char *argv[])
- {
- a = argc;
- b = argv[1][0];
- printf("%d,%d\n", a, b);
- if (a > a + b || a > a + b + 1) {
- printf("one %lld, %lld", a, b);
- return 0;
- }
- printf("zero %lld, %lld", a, b);
- return 0;
- }
- '''
- self.do_run(src, 'zero 2, 104', ['hallo'])
+ test_path = path_from_root('tests', 'core', 'test_i64_7z')
+ src, output = (test_path + s for s in ('.in', '.out'))
+
+ self.do_run_from_file(src, output, ['hallo'])
def test_i64_i16(self):
if Settings.USE_TYPED_ARRAYS != 2: return self.skip('full i64 stuff only in ta2')
- src = r'''
- #include <stdint.h>
- #include <stdio.h>
- int main(int argc, char ** argv){
- int y=-133;
- int64_t x= ((int64_t)((short)(y)))*(100 + argc);
- if(x>0)
- printf(">0\n");
- else
- printf("<=0\n");
- }
- '''
- self.do_run(src, '<=0')
+ test_path = path_from_root('tests', 'core', 'test_i64_i16')
+ src, output = (test_path + s for s in ('.in', '.out'))
+
+ self.do_run_from_file(src, output)
def test_i64_qdouble(self):
if Settings.USE_TYPED_ARRAYS != 2: return self.skip('full i64 stuff only in ta2')
- src = r'''
- #include <stdio.h>
- typedef long long qint64; /* 64 bit signed */
- typedef double qreal;
+ test_path = path_from_root('tests', 'core', 'test_i64_qdouble')
+ src, output = (test_path + s for s in ('.in', '.out'))
-
- int main(int argc, char **argv)
- {
- qreal c = 111;
- qint64 d = -111 + (argc - 1);
- c += d;
- if (c < -1 || c > 1)
- {
- printf("Failed!\n");
- }
- else
- {
- printf("Succeeded!\n");
- }
- };
- '''
- self.do_run(src, 'Succeeded!')
+ self.do_run_from_file(src, output)
def test_i64_varargs(self):
if Settings.USE_TYPED_ARRAYS != 2: return self.skip('full i64 stuff only in ta2')
- src = r'''
- #include <stdio.h>
- #include <stdint.h>
- #include <stdarg.h>
-
- int64_t ccv_cache_generate_signature(char *msg, int len, int64_t sig_start, ...) {
- if (sig_start < 10123)
- printf("%s\n", msg+len);
- va_list v;
- va_start(v, sig_start);
- if (sig_start > 1413)
- printf("%d\n", va_arg(v, int));
- else
- printf("nada\n");
- va_end(v);
- return len*sig_start*(msg[0]+1);
- }
+ test_path = path_from_root('tests', 'core', 'test_i64_varargs')
+ src, output = (test_path + s for s in ('.in', '.out'))
- int main(int argc, char **argv)
- {
- for (int i = 0; i < argc; i++) {
- int64_t x;
- if (i % 123123 == 0)
- x = ccv_cache_generate_signature(argv[i], i+2, (int64_t)argc*argc, 54.111);
- else
- x = ccv_cache_generate_signature(argv[i], i+2, (int64_t)argc*argc, 13);
- printf("%lld\n", x);
- }
- };
- '''
- self.do_run(src, '''in/this.program
-nada
-1536
-a
-nada
-5760
-fl
-nada
-6592
-sdfasdfasdf
-nada
-7840
-''', 'waka fleefl asdfasdfasdfasdf'.split(' '))
+ self.do_run_from_file(src, output, 'waka fleefl asdfasdfasdfasdf'.split(' '))
def test_i32_mul_precise(self):
if self.emcc_args == None: return self.skip('needs ta2')
- src = r'''
- #include <stdio.h>
+ test_path = path_from_root('tests', 'core', 'test_i32_mul_precise')
+ src, output = (test_path + s for s in ('.in', '.out'))
- int main(int argc, char **argv) {
- unsigned long d1 = 0x847c9b5d;
- unsigned long q = 0x549530e1;
- if (argc > 1000) { q += argc; d1 -= argc; } // confuse optimizer
- printf("%lu\n", d1*q);
- return 0;
- }
- '''
- self.do_run(src, '3217489085')
+ self.do_run_from_file(src, output)
def test_i32_mul_semiprecise(self):
if Settings.ASM_JS: return self.skip('asm is always fully precise')
Settings.PRECISE_I32_MUL = 0 # we want semiprecise here
- src = r'''
- #include <stdio.h>
-
- typedef unsigned int uint;
-
- // from cube2, zlib licensed
+ test_path = path_from_root('tests', 'core', 'test_i32_mul_semiprecise')
+ src, output = (test_path + s for s in ('.in', '.out'))
- #define N (624)
- #define M (397)
- #define K (0x9908B0DFU)
-
- static uint state[N];
- static int next = N;
-
- void seedMT(uint seed)
- {
- state[0] = seed;
- for(uint i = 1; i < N; i++) // if we do not do this precisely, at least we should coerce to int immediately, not wait
- state[i] = seed = 1812433253U * (seed ^ (seed >> 30)) + i;
- next = 0;
- }
-
- int main() {
- seedMT(5497);
- for (int i = 0; i < 10; i++) printf("%d: %u\n", i, state[i]);
- return 0;
- }
- '''
- self.do_run(src, '''0: 5497
-1: 2916432318
-2: 2502517762
-3: 3151524867
-4: 2323729668
-5: 2053478917
-6: 2409490438
-7: 848473607
-8: 691103752
-9: 3915535113
-''')
+ self.do_run_from_file(src, output)
def test_i16_emcc_intrinsic(self):
Settings.CORRECT_SIGNS = 1 # Relevant to this test
- src = r'''
- #include <stdio.h>
-
- int test(unsigned short a, unsigned short b) {
- unsigned short result = a;
- result += b;
- if (result < b) printf("C!");
- return result;
- }
+ test_path = path_from_root('tests', 'core', 'test_i16_emcc_intrinsic')
+ src, output = (test_path + s for s in ('.in', '.out'))
- int main(void) {
- printf(",%d,", test(0, 0));
- printf(",%d,", test(1, 1));
- printf(",%d,", test(65535, 1));
- printf(",%d,", test(1, 65535));
- printf(",%d,", test(32768, 32767));
- printf(",%d,", test(32768, 32768));
- return 0;
- }
- '''
- self.do_run(src, ',0,,2,C!,0,C!,0,,65535,C!,0,')
+ self.do_run_from_file(src, output)
def test_double_i64_conversion(self):
if Settings.USE_TYPED_ARRAYS != 2: return self.skip('needs ta2')
- src = r'''
- #include <cassert>
- #include <inttypes.h>
- #include <stdio.h>
+ test_path = path_from_root('tests', 'core', 'test_double_i64_conversion')
+ src, output = (test_path + s for s in ('.in', '.out'))
- __attribute((noinline)) bool eq(double d, int64_t i) {
- int64_t i2 = (int64_t)d;
- if (i != i2) {
- printf("%.20g converted to int64 returns %lld, not %lld as expected!\n", d, i2, i);
- }
- return i == i2;
- }
-
- int main() {
- assert(eq(0.0, 0));
- assert(eq(-0.0, 0));
- assert(eq(0.1, 0));
- assert(eq(-0.1, 0));
- assert(eq(0.6, 0));
- assert(eq(-0.6, 0));
- assert(eq(1.0, 1));
- assert(eq(-1.0, -1));
- assert(eq(1.1, 1));
- assert(eq(-1.1, -1));
- assert(eq(1.6, 1));
- assert(eq(-1.6, -1));
- assert(eq(4294967295.0, 4294967295LL));
- assert(eq(4294967295.5, 4294967295LL));
- assert(eq(4294967296.0, 4294967296LL));
- assert(eq(4294967296.5, 4294967296LL));
- assert(eq(14294967295.0, 14294967295LL));
- assert(eq(14294967295.5, 14294967295LL));
- assert(eq(14294967296.0, 14294967296LL));
- assert(eq(14294967296.5, 14294967296LL));
- assert(eq(-4294967295.0, -4294967295LL));
- assert(eq(-4294967295.5, -4294967295LL));
- assert(eq(-4294967296.0, -4294967296LL));
- assert(eq(-4294967296.5, -4294967296LL));
- assert(eq(-14294967295.0, -14294967295LL));
- assert(eq(-14294967295.5, -14294967295LL));
- assert(eq(-14294967296.0, -14294967296LL));
- assert(eq(-14294967296.5, -14294967296LL));
-
- assert(eq(4294967295.3, 4294967295LL));
- assert(eq(4294967296.3, 4294967296LL));
- assert(eq(14294967295.3, 14294967295LL));
- assert(eq(14294967296.3, 14294967296LL));
- assert(eq(-4294967295.3, -4294967295LL));
- assert(eq(-4294967296.3, -4294967296LL));
- assert(eq(-14294967295.3, -14294967295LL));
- assert(eq(-14294967296.3, -14294967296LL));
-
- assert(eq(4294967295.8, 4294967295LL));
- assert(eq(4294967296.8, 4294967296LL));
- assert(eq(14294967295.8, 14294967295LL));
- assert(eq(14294967296.8, 14294967296LL));
- assert(eq(-4294967295.8, -4294967295LL));
- assert(eq(-4294967296.8, -4294967296LL));
- assert(eq(-14294967295.8, -14294967295LL));
- assert(eq(-14294967296.8, -14294967296LL));
-
- // The following number is the largest double such that all integers smaller than this can exactly be represented in a double.
- assert(eq(9007199254740992.0, 9007199254740992LL /* == 2^53 */));
- assert(eq(-9007199254740992.0, -9007199254740992LL /* == -2^53 */));
-
- printf("OK!\n");
- return 0;
- }
- '''
- self.do_run(src, 'OK!\n');
+ self.do_run_from_file(src, output)
def test_float32_precise(self):
Settings.PRECISE_F32 = 1
- src = r'''
- #include <stdio.h>
+ test_path = path_from_root('tests', 'core', 'test_float32_precise')
+ src, output = (test_path + s for s in ('.in', '.out'))
- int main(int argc, char **argv) {
- float x = 1.23456789123456789;
- float y = 5.20456089123406709;
- while (argc > 10 || argc % 19 == 15) {
- // confuse optimizer
- x /= y;
- y = 2*y - 1;
- argc--;
- }
- x = x - y;
- y = 3*y - x/2;
- x = x*y;
- y += 0.000000000123123123123;
- x -= y/7.654;
- printf("\n%.20f, %.20f\n", x, y);
- return 0;
- }
- '''
- self.do_run(src, '\n-72.16590881347656250000, 17.59867858886718750000\n')
+ self.do_run_from_file(src, output)
def test_negative_zero(self):
- src = r'''
- #include <stdio.h>
- #include <math.h>
+ test_path = path_from_root('tests', 'core', 'test_negative_zero')
+ src, output = (test_path + s for s in ('.in', '.out'))
- int main() {
- #define TEST(x, y) \
- printf("%.2f, %.2f ==> %.2f\n", x, y, copysign(x, y));
- TEST( 5.0f, 5.0f);
- TEST( 5.0f, -5.0f);
- TEST(-5.0f, 5.0f);
- TEST(-5.0f, -5.0f);
- TEST( 5.0f, 4.0f);
- TEST( 5.0f, -4.0f);
- TEST(-5.0f, 4.0f);
- TEST(-5.0f, -4.0f);
- TEST( 0.0f, 5.0f);
- TEST( 0.0f, -5.0f);
- TEST(-0.0f, 5.0f);
- TEST(-0.0f, -5.0f);
- TEST( 5.0f, 0.0f);
- TEST( 5.0f, -0.0f);
- TEST(-5.0f, 0.0f);
- TEST(-5.0f, -0.0f);
- TEST( 0.0f, 0.0f);
- TEST( 0.0f, -0.0f);
- TEST(-0.0f, 0.0f);
- TEST(-0.0f, -0.0f);
- return 0;
- }
- '''
- self.do_run(src, '''5.00, 5.00 ==> 5.00
-5.00, -5.00 ==> -5.00
--5.00, 5.00 ==> 5.00
--5.00, -5.00 ==> -5.00
-5.00, 4.00 ==> 5.00
-5.00, -4.00 ==> -5.00
--5.00, 4.00 ==> 5.00
--5.00, -4.00 ==> -5.00
-0.00, 5.00 ==> 0.00
-0.00, -5.00 ==> -0.00
--0.00, 5.00 ==> 0.00
--0.00, -5.00 ==> -0.00
-5.00, 0.00 ==> 5.00
-5.00, -0.00 ==> -5.00
--5.00, 0.00 ==> 5.00
--5.00, -0.00 ==> -5.00
-0.00, 0.00 ==> 0.00
-0.00, -0.00 ==> -0.00
--0.00, 0.00 ==> 0.00
--0.00, -0.00 ==> -0.00
-''')
+ self.do_run_from_file(src, output)
def test_llvm_intrinsics(self):
if self.emcc_args == None: return self.skip('needs ta2')
Settings.PRECISE_I64_MATH = 2 # for bswap64
- src = r'''
- #include <stdio.h>
- #include <sys/types.h>
-
- extern "C" {
- extern unsigned short llvm_bswap_i16(unsigned short x);
- extern unsigned int llvm_bswap_i32(unsigned int x);
- extern int32_t llvm_ctlz_i32(int32_t x);
- extern int64_t llvm_ctlz_i64(int64_t x);
- extern int32_t llvm_cttz_i32(int32_t x);
- extern int64_t llvm_cttz_i64(int64_t x);
- extern int32_t llvm_ctpop_i32(int32_t x);
- extern int64_t llvm_ctpop_i64(int64_t x);
- extern int llvm_expect_i32(int x, int y);
- }
-
- int main(void) {
- unsigned short x = 0xc8ef;
- printf("%x,%x\n", x&0xff, x >> 8);
- x = llvm_bswap_i16(x);
- printf("%x,%x\n", x&0xff, x >> 8);
-
- unsigned int y = 0xc5de158a;
- printf("%x,%x,%x,%x\n", y&0xff, (y>>8)&0xff, (y>>16)&0xff, (y>>24)&0xff);
- y = llvm_bswap_i32(y);
- printf("%x,%x,%x,%x\n", y&0xff, (y>>8)&0xff, (y>>16)&0xff, (y>>24)&0xff);
-
- printf("%d,%d\n", (int)llvm_ctlz_i64(((int64_t)1) << 40), llvm_ctlz_i32(1<<10));
- printf("%d,%d\n", (int)llvm_cttz_i64(((int64_t)1) << 40), llvm_cttz_i32(1<<10));
- printf("%d,%d\n", (int)llvm_ctpop_i64((0x3101ULL << 32) | 1), llvm_ctpop_i32(0x3101));
- printf("%d\n", (int)llvm_ctpop_i32(-594093059));
-
- printf("%d\n", llvm_expect_i32(x % 27, 3));
+ test_path = path_from_root('tests', 'core', 'test_llvm_intrinsics')
+ src, output = (test_path + s for s in ('.in', '.out'))
- int64_t a = 1;
- a = __builtin_bswap64(a);
- printf("%lld\n", a);
-
- return 0;
- }
- '''
- self.do_run(src, '''ef,c8
-c8,ef
-8a,15,de,c5
-c5,de,15,8a
-23,21
-40,10
-5,4
-22
-13
-72057594037927936
-''')
+ self.do_run_from_file(src, output)
def test_bswap64(self):
if Settings.USE_TYPED_ARRAYS != 2: return self.skip('needs ta2')
- src = r'''
- #include <stdio.h>
- #include <stdlib.h>
-
- #include <iostream>
- #include <string>
- #include <sstream>
-
- typedef unsigned long long quint64;
+ test_path = path_from_root('tests', 'core', 'test_bswap64')
+ src, output = (test_path + s for s in ('.in', '.out'))
- using namespace std;
-
- inline quint64 qbswap(quint64 source)
- {
- return 0
- | ((source & quint64(0x00000000000000ffLL)) << 56)
- | ((source & quint64(0x000000000000ff00LL)) << 40)
- | ((source & quint64(0x0000000000ff0000LL)) << 24)
- | ((source & quint64(0x00000000ff000000LL)) << 8)
- | ((source & quint64(0x000000ff00000000LL)) >> 8)
- | ((source & quint64(0x0000ff0000000000LL)) >> 24)
- | ((source & quint64(0x00ff000000000000LL)) >> 40)
- | ((source & quint64(0xff00000000000000LL)) >> 56);
- }
-
- int main()
- {
- quint64 v = strtoull("4433ffeeddccbb00", NULL, 16);
- printf("%lld\n", v);
-
- const string string64bitInt = "4433ffeeddccbb00";
- stringstream s(string64bitInt);
- quint64 int64bitInt = 0;
- printf("1\n");
- s >> hex >> int64bitInt;
- printf("2\n");
-
- stringstream out;
- out << hex << qbswap(int64bitInt);
-
- cout << out.str() << endl;
- cout << hex << int64bitInt << endl;
- cout << string64bitInt << endl;
-
- if (out.str() != "bbccddeeff3344")
- {
- cout << "Failed!" << endl;
- }
- else
- {
- cout << "Succeeded!" << endl;
- }
-
- return 0;
- }
- '''
- self.do_run(src, '''4914553019779824384
-1
-2
-bbccddeeff3344
-4433ffeeddccbb00
-4433ffeeddccbb00
-Succeeded!
-''')
+ self.do_run_from_file(src, output)
def test_sha1(self):
if self.emcc_args == None: return self.skip('needs ta2')
@@ -1351,240 +754,64 @@ Succeeded!
def test_bitfields(self):
if self.emcc_args is None: Settings.SAFE_HEAP = 0 # bitfields do loads on invalid areas, by design
- src = '''
- #include <stdio.h>
- struct bitty {
- unsigned x : 1;
- unsigned y : 1;
- unsigned z : 1;
- };
- int main()
- {
- bitty b;
- printf("*");
- for (int i = 0; i <= 1; i++)
- for (int j = 0; j <= 1; j++)
- for (int k = 0; k <= 1; k++) {
- b.x = i;
- b.y = j;
- b.z = k;
- printf("%d,%d,%d,", b.x, b.y, b.z);
- }
- printf("*\\n");
- return 0;
- }
- '''
- self.do_run(src, '*0,0,0,0,0,1,0,1,0,0,1,1,1,0,0,1,0,1,1,1,0,1,1,1,*')
- def test_floatvars(self):
- src = '''
- #include <stdio.h>
+ test_path = path_from_root('tests', 'core', 'test_bitfields')
+ src, output = (test_path + s for s in ('.in', '.out'))
- // headers test, see issue #1013
- #include<cfloat>
- #include<cmath>
+ self.do_run_from_file(src, output)
- int main(int argc, char **argv)
- {
- float x = 1.234, y = 3.5, q = 0.00000001;
- y *= 3;
- int z = x < y;
- printf("*%d,%d,%.1f,%d,%.4f,%.2f*\\n", z, int(y), y, (int)x, x, q);
-
- printf("%.2f, %.2f, %.2f, %.2f\\n", fmin(0.5, 3.3), fmin(NAN, 3.3), fmax(0.5, 3.3), fmax(NAN, 3.3));
-
- printf("small: %.10f\\n", argc * 0.000001);
-
- /*
- // Rounding behavior
- float fs[6] = { -2.75, -2.50, -2.25, 2.25, 2.50, 2.75 };
- double ds[6] = { -2.75, -2.50, -2.25, 2.25, 2.50, 2.75 };
- for (int i = 0; i < 6; i++)
- printf("*int(%.2f)=%d,%d*\\n", fs[i], int(fs[i]), int(ds[i]));
- */
+ def test_floatvars(self):
+ test_path = path_from_root('tests', 'core', 'test_floatvars')
+ src, output = (test_path + s for s in ('.in', '.out'))
- return 0;
- }
- '''
- self.do_run(src, '*1,10,10.5,1,1.2340,0.00*\n0.50, 3.30, 3.30, 3.30\nsmall: 0.0000010000\n')
+ self.do_run_from_file(src, output)
def test_fast_math(self):
if self.emcc_args is None: return self.skip('requires emcc')
Building.COMPILER_TEST_OPTS += ['-ffast-math']
- self.do_run(r'''
-#include <stdio.h>
-#include <stdlib.h>
-
-int main(int argc, char** argv) {
- char* endptr;
- --argc, ++argv;
- double total = 0.0;
- for (; argc; argc--, argv++) {
- total += strtod(*argv, &endptr);
- }
- printf("total: %g\n", total);
- return 0;
-}
-''', 'total: 19', ['5', '6', '8'])
-
- def test_zerodiv(self):
- self.do_run(r'''
- #include <stdio.h>
- int main(int argc, const char* argv[])
- {
- float f1 = 1.0f;
- float f2 = 0.0f;
- float f_zero = 0.0f;
+ test_path = path_from_root('tests', 'core', 'test_fast_math')
+ src, output = (test_path + s for s in ('.in', '.out'))
- float f3 = 0.0f / f2;
- float f4 = f2 / 0.0f;
- float f5 = f2 / f2;
- float f6 = f2 / f_zero;
+ self.do_run_from_file(src, output, ['5', '6', '8'])
- printf("f3: %f\n", f3);
- printf("f4: %f\n", f4);
- printf("f5: %f\n", f5);
- printf("f6: %f\n", f6);
+ def test_zerodiv(self):
+ test_path = path_from_root('tests', 'core', 'test_zerodiv')
+ src, output = (test_path + s for s in ('.in', '.out'))
- return 0;
- }
- ''', '''f3: nan
-f4: nan
-f5: nan
-f6: nan
-''')
+ self.do_run_from_file(src, output)
def test_zero_multiplication(self):
- src = '''
- #include <stdio.h>
- int main(int argc, char * argv[]) {
- int one = argc;
-
- printf("%d ", 0 * one);
- printf("%d ", 0 * -one);
- printf("%d ", -one * 0);
- printf("%g ", 0.0 * one);
- printf("%g ", 0.0 * -one);
- printf("%g", -one * 0.0);
- return 0;
- }
- '''
- self.do_run(src, '0 0 0 0 -0 -0')
+ test_path = path_from_root('tests', 'core', 'test_zero_multiplication')
+ src, output = (test_path + s for s in ('.in', '.out'))
+
+ self.do_run_from_file(src, output)
def test_isnan(self):
- src = r'''
- #include <stdio.h>
+ test_path = path_from_root('tests', 'core', 'test_isnan')
+ src, output = (test_path + s for s in ('.in', '.out'))
- int IsNaN(double x){
- int rc; /* The value return */
- volatile double y = x;
- volatile double z = y;
- rc = (y!=z);
- return rc;
- }
-
- int main() {
- double tests[] = { 1.0, 3.333, 1.0/0.0, 0.0/0.0, -1.0/0.0, -0, 0, -123123123, 12.0E200 };
- for (int i = 0; i < sizeof(tests)/sizeof(double); i++)
- printf("%d - %f - %d\n", i, tests[i], IsNaN(tests[i]));
- }
- '''
- self.do_run(src, '''0 - 1.000000 - 0
-1 - 3.333000 - 0
-2 - inf - 0
-3 - nan - 1
-4 - -inf - 0
-5 - 0.000000 - 0
-6 - 0.000000 - 0
-7 - -123123123.000000 - 0
-8 - 1.2e+201 - 0
-''')
+ self.do_run_from_file(src, output)
def test_globaldoubles(self):
- src = r'''
- #include <stdlib.h>
- #include <stdio.h>
-
- double testVu, testVv, testWu, testWv;
+ test_path = path_from_root('tests', 'core', 'test_globaldoubles')
+ src, output = (test_path + s for s in ('.in', '.out'))
- void Test(double _testVu, double _testVv, double _testWu, double _testWv)
- {
- testVu = _testVu;
- testVv = _testVv;
- testWu = _testWu;
- testWv = _testWv;
- printf("BUG?\n");
- printf("Display: Vu=%f Vv=%f Wu=%f Wv=%f\n", testVu, testVv, testWu, testWv);
- }
-
- int main(void)
- {
- double v1 = 465.1;
- double v2 = 465.2;
- double v3 = 160.3;
- double v4 = 111.4;
- Test(v1, v2, v3, v4);
- return 0;
- }
- '''
- self.do_run(src, 'BUG?\nDisplay: Vu=465.100000 Vv=465.200000 Wu=160.300000 Wv=111.400000')
+ self.do_run_from_file(src, output)
def test_math(self):
if Settings.USE_TYPED_ARRAYS != 2: return self.skip('requires ta2')
- src = '''
- #include <stdio.h>
- #include <stdlib.h>
- #include <cmath>
- int main(int argc, char **argv)
- {
- printf("*%.2f,%.2f,%d", M_PI, -M_PI, (1/0.0) > 1e300); // could end up as infinity, or just a very very big number
- printf(",%d", isfinite(NAN) != 0);
- printf(",%d", isfinite(INFINITY) != 0);
- printf(",%d", isfinite(-INFINITY) != 0);
- printf(",%d", isfinite(12.3) != 0);
- printf(",%d", isinf(NAN) != 0);
- printf(",%d", isinf(INFINITY) != 0);
- printf(",%d", isinf(-INFINITY) != 0);
- printf(",%d", isinf(12.3) != 0);
- div_t div_result = div(23, 10);
- printf(",%d", div_result.quot);
- printf(",%d", div_result.rem);
- double sine = -1.0, cosine = -1.0;
- sincos(0.0, &sine, &cosine);
- printf(",%1.1lf", sine);
- printf(",%1.1lf", cosine);
- float fsine = -1.0f, fcosine = -1.0f;
- sincosf(0.0, &fsine, &fcosine);
- printf(",%1.1f", fsine);
- printf(",%1.1f", fcosine);
- fsine = sinf(1.1 + argc - 1);
- fcosine = cosf(1.1 + argc - 1);
- printf(",%1.1f", fsine);
- printf(",%1.1f", fcosine);
- printf("*\\n");
- return 0;
- }
- '''
- self.do_run(src, '*3.14,-3.14,1,0,0,0,1,0,1,1,0,2,3,0.0,1.0,0.0,1.0,0.9,0.5*')
+
+ test_path = path_from_root('tests', 'core', 'test_math')
+ src, output = (test_path + s for s in ('.in', '.out'))
+
+ self.do_run_from_file(src, output)
def test_erf(self):
- src = '''
- #include <math.h>
- #include <stdio.h>
- int main()
- {
- printf("%1.6f, %1.6f, %1.6f, %1.6f, %1.6f, %1.6f\\n",
- erf(1.0),
- erf(3.0),
- erf(-1.0),
- erfc(1.0),
- erfc(3.0),
- erfc(-1.5));
- return 0;
- }
- '''
- self.do_run(src, '0.842701, 0.999978, -0.842701, 0.157299, 0.000022, 1.966105')
+ test_path = path_from_root('tests', 'core', 'test_erf')
+ src, output = (test_path + s for s in ('.in', '.out'))
+
+ self.do_run_from_file(src, output)
def test_math_hyperbolic(self):
src = open(path_from_root('tests', 'hyperbolic', 'src.c'), 'r').read()
@@ -1592,131 +819,39 @@ f6: nan
self.do_run(src, expected)
def test_frexp(self):
- src = '''
- #include <stdio.h>
- #include <math.h>
- #include <assert.h>
-
- static const double tol=1e-16;
-
- void test_value(double value)
- {
- int exponent;
- double x=frexp(value, &exponent);
- double expected=x*pow(2.0, exponent);
+ test_path = path_from_root('tests', 'core', 'test_frexp')
+ src, output = (test_path + s for s in ('.in', '.out'))
- printf("%f=%f*2^%d\\n", value, x, exponent);
-
- assert(fabs(expected-value)<tol);
- assert(x==0 || (fabs(x)>=5e-1 && fabs(x)<1)); // x has a magnitude in the interval [1/2, 1)
- }
-
- int main()
- {
- test_value(0);
- test_value(100.1);
- test_value(-100.1);
- test_value(.5);
- test_value(-.5);
- test_value(1-1e-16);
- test_value(-(1-1e-16));
-
- return 0;
- }
- '''
- self.do_run(src, '''0.000000=0.000000*2^0
-100.100000=0.782031*2^7
--100.100000=-0.782031*2^7
-0.500000=0.500000*2^0
--0.500000=-0.500000*2^0
-1.000000=1.000000*2^0
--1.000000=-1.000000*2^0''')
+ self.do_run_from_file(src, output)
def test_rounding(self):
- src = '''
- #include <stdio.h>
- #include <math.h>
+ test_path = path_from_root('tests', 'core', 'test_rounding')
+ src, output = (test_path + s for s in ('.in', '.out'))
- int main()
- {
- printf("%.1f ", round(1.4));
- printf("%.1f ", round(1.6));
- printf("%.1f ", round(-1.4));
- printf("%.1f ", round(-1.6));
-
- printf("%.1f ", round(1.5));
- printf("%.1f ", round(2.5));
- printf("%.1f ", round(-1.5));
- printf("%.1f ", round(-2.5));
-
- printf("%ld ", lrint(1.4));
- printf("%ld ", lrint(1.6));
- printf("%ld ", lrint(-1.4));
- printf("%ld ", lrint(-1.6));
-
- printf("%ld ", lrint(1.5));
- printf("%ld ", lrint(2.5));
- printf("%ld ", lrint(-1.5));
- printf("%ld ", lrint(-2.5));
+ self.do_run_from_file(src, output)
- return 0;
- }
- '''
- self.do_run(src, "1.0 2.0 -1.0 -2.0 2.0 3.0 -2.0 -3.0 "
- "1 2 -1 -2 2 2 -2 -2")
-
- # This example borrowed from MSDN documentation
def test_fcvt(self):
if self.emcc_args is None: return self.skip('requires emcc')
- src = '''
- #include <stdlib.h>
- #include <stdio.h>
+ test_path = path_from_root('tests', 'core', 'test_fcvt')
+ src, output = (test_path + s for s in ('.in', '.out'))
- int main() {
- int decimal, sign;
- char *buffer;
- double source = 3.1415926535;
-
- buffer = fcvt(source, 7, &decimal, &sign);
- printf("source: %2.10f buffer: '%s' decimal: %d sign: %d\\n",
- source, buffer, decimal, sign);
- }
- '''
- self.do_run(src, "source: 3.1415926535 buffer: '31415927' decimal: 1 sign: 0");
+ self.do_run_from_file(src, output)
def test_llrint(self):
if Settings.USE_TYPED_ARRAYS != 2: return self.skip('requires ta2')
- src = r'''
- #include <stdio.h>
- #include <math.h>
- int main() {
- printf("%lld\n%lld\n%lld\n%lld\n", llrint(0.1), llrint(0.6), llrint(1.25), llrint(1099511627776.667));
- return 0;
- }
- '''
- self.do_run(src, '0\n1\n1\n1099511627777\n')
+
+ test_path = path_from_root('tests', 'core', 'test_llrint')
+ src, output = (test_path + s for s in ('.in', '.out'))
+
+ self.do_run_from_file(src, output)
def test_getgep(self):
- # Generated code includes getelementptr (getelementptr, 0, 1), i.e., GEP as the first param to GEP
- src = '''
- #include <stdio.h>
- struct {
- int y[10];
- int z[10];
- } commonblock;
+ # Generated code includes getelementptr (getelementptr, 0, 1), i.e., GEP as the first param to GEP
+ test_path = path_from_root('tests', 'core', 'test_getgep')
+ src, output = (test_path + s for s in ('.in', '.out'))
- int main()
- {
- for (int i = 0; i < 10; ++i) {
- commonblock.y[i] = 1;
- commonblock.z[i] = 2;
- }
- printf("*%d %d*\\n", commonblock.y[0], commonblock.z[0]);
- return 0;
- }
- '''
- self.do_run(src, '*1 2*')
+ self.do_run_from_file(src, output)
def test_multiply_defined_symbols(self):
a1 = "int f() { return 1; }"
@@ -1759,288 +894,80 @@ f6: nan
self.do_ll_run(all_name, 'result: 1')
def test_if(self):
- src = '''
- #include <stdio.h>
- int main()
- {
- int x = 5;
- if (x > 3) {
- printf("*yes*\\n");
- }
- return 0;
- }
- '''
- self.do_run(src, '*yes*')
+ test_path = path_from_root('tests', 'core', 'test_if')
+ src, output = (test_path + s for s in ('.in', '.out'))
+
+ self.do_run_from_file(src, output)
def test_if_else(self):
- src = '''
- #include <stdio.h>
- int main()
- {
- int x = 5;
- if (x > 10) {
- printf("*yes*\\n");
- } else {
- printf("*no*\\n");
- }
- return 0;
- }
- '''
- self.do_run(src, '*no*')
+ test_path = path_from_root('tests', 'core', 'test_if_else')
+ src, output = (test_path + s for s in ('.in', '.out'))
- def test_loop(self):
- src = '''
- #include <stdio.h>
- int main()
- {
- int x = 5;
- for (int i = 0; i < 6; i++) {
- x += x*i;
- if (x > 1000) {
- if (x % 7 == 0) printf("cheez\\n");
- x /= 2;
- break;
- }
- }
- printf("*%d*\\n", x);
- return 0;
- }
- '''
+ self.do_run_from_file(src, output)
- self.do_run(src, '*1800*')
+ def test_loop(self):
+ test_path = path_from_root('tests', 'core', 'test_loop')
+ src, output = (test_path + s for s in ('.in', '.out'))
- generated = open('src.cpp.o.js', 'r').read()
+ self.do_run_from_file(src, output)
def test_stack(self):
- Settings.INLINING_LIMIT = 50
-
- src = '''
- #include <stdio.h>
- int test(int i) {
- int x = 10;
- if (i > 0) {
- return test(i-1);
- }
- return int(&x); // both for the number, and forces x to not be nativized
- }
- int main(int argc, char **argv)
- {
- // We should get the same value for the first and last - stack has unwound
- int x1 = test(argc - 2);
- int x2 = test(100);
- int x3 = test((argc - 2) / 4);
- printf("*%d,%d*\\n", x3-x1, x2 != x1);
- return 0;
- }
- '''
- self.do_run(src, '*0,1*')
+ Settings.INLINING_LIMIT = 50
- def test_strings(self):
- src = '''
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
+ test_path = path_from_root('tests', 'core', 'test_stack')
+ src, output = (test_path + s for s in ('.in', '.out'))
- int main(int argc, char **argv)
- {
- int x = 5, y = 9, magic = 7; // fool compiler with magic
- memmove(&x, &y, magic-7); // 0 should not crash us
-
- int xx, yy, zz;
- char s[32];
- int cc = sscanf("abc_10.b1_xyz9_543_defg", "abc_%d.%2x_xyz9_%3d_%3s", &xx, &yy, &zz, s);
- printf("%d:%d,%d,%d,%s\\n", cc, xx, yy, zz, s);
-
- printf("%d\\n", argc);
- puts(argv[1]);
- puts(argv[2]);
- printf("%d\\n", atoi(argv[3])+2);
- const char *foolingthecompiler = "\\rabcd";
- printf("%d\\n", strlen(foolingthecompiler)); // Tests parsing /0D in llvm - should not be a 0 (end string) then a D!
- printf("%s\\n", NULL); // Should print '(null)', not the string at address 0, which is a real address for us!
- printf("/* a comment */\\n"); // Should not break the generated code!
- printf("// another\\n"); // Should not break the generated code!
-
- char* strdup_val = strdup("test");
- printf("%s\\n", strdup_val);
- free(strdup_val);
+ self.do_run_from_file(src, output)
- {
- char *one = "one 1 ONE !";
- char *two = "two 2 TWO ?";
- char three[1024];
- memset(three, '.', 1024);
- three[50] = 0;
- strncpy(three + argc, one + (argc/2), argc+1);
- strncpy(three + argc*3, two + (argc/3), argc+2);
- printf("waka %s\\n", three);
- }
-
- {
- char *one = "string number one top notch";
- char *two = "fa la sa ho fi FI FO FUM WHEN WHERE WHY HOW WHO";
- char three[1000];
- strcpy(three, &one[argc*2]);
- char *four = strcat(three, &two[argc*3]);
- printf("cat |%s|\\n", three);
- printf("returned |%s|\\n", four);
- }
+ def test_strings(self):
+ test_path = path_from_root('tests', 'core', 'test_strings')
+ src, output = (test_path + s for s in ('.in', '.out'))
- return 0;
- }
- '''
for named in (0, 1):
print named
+
Settings.NAMED_GLOBALS = named
- self.do_run(src, '''4:10,177,543,def\n4\nwowie\ntoo\n76\n5\n(null)\n/* a comment */\n// another\ntest\nwaka ....e 1 O...wo 2 T................................
-cat |umber one top notchfi FI FO FUM WHEN WHERE WHY HOW WHO|
-returned |umber one top notchfi FI FO FUM WHEN WHERE WHY HOW WHO|''', ['wowie', 'too', '74'])
+ self.do_run_from_file(src, output, ['wowie', 'too', '74'])
+
if self.emcc_args == []:
gen = open(self.in_dir('src.cpp.o.js')).read()
assert ('var __str1;' in gen) == named
def test_strcmp_uni(self):
- src = '''
- #include <stdio.h>
- #include <string.h>
- int main()
- {
- #define TEST(func) \
- { \
- char *word = "WORD"; \
- char wordEntry[2] = { -61,-126 }; /* "Â"; */ \
- int cmp = func(word, wordEntry, 2); \
- printf("Compare value " #func " is %d\\n", cmp); \
- }
- TEST(strncmp);
- TEST(strncasecmp);
- TEST(memcmp);
- }
- '''
- self.do_run(src, 'Compare value strncmp is -1\nCompare value strncasecmp is -1\nCompare value memcmp is -1\n')
-
- def test_strndup(self):
- src = '''
- //---------------
- //- http://pubs.opengroup.org/onlinepubs/9699919799/functions/strndup.html
- //---------------
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
-
- int main(int argc, char **argv) {
- const char* source = "strndup - duplicate a specific number of bytes from a string";
-
- char* strdup_val = strndup(source, 0);
- printf("1:%s\\n", strdup_val);
- free(strdup_val);
-
- strdup_val = strndup(source, 7);
- printf("2:%s\\n", strdup_val);
- free(strdup_val);
+ test_path = path_from_root('tests', 'core', 'test_strcmp_uni')
+ src, output = (test_path + s for s in ('.in', '.out'))
- strdup_val = strndup(source, 1000);
- printf("3:%s\\n", strdup_val);
- free(strdup_val);
+ self.do_run_from_file(src, output)
- strdup_val = strndup(source, 60);
- printf("4:%s\\n", strdup_val);
- free(strdup_val);
-
- strdup_val = strndup(source, 19);
- printf("5:%s\\n", strdup_val);
- free(strdup_val);
-
- strdup_val = strndup(source, -1);
- printf("6:%s\\n", strdup_val);
- free(strdup_val);
+ def test_strndup(self):
+ test_path = path_from_root('tests', 'core', 'test_strndup')
+ src, output = (test_path + s for s in ('.in', '.out'))
- return 0;
- }
- '''
- self.do_run(src, '1:\n2:strndup\n3:strndup - duplicate a specific number of bytes from a string\n4:strndup - duplicate a specific number of bytes from a string\n5:strndup - duplicate\n6:\n')
+ self.do_run_from_file(src, output)
def test_errar(self):
- src = r'''
- #include <stdio.h>
- #include <errno.h>
- #include <string.h>
-
- int main() {
- char* err;
- char buffer[200];
-
- err = strerror(EDOM);
- strerror_r(EWOULDBLOCK, buffer, 200);
- printf("<%s>\n", err);
- printf("<%s>\n", buffer);
+ test_path = path_from_root('tests', 'core', 'test_errar')
+ src, output = (test_path + s for s in ('.in', '.out'))
- printf("<%d>\n", strerror_r(EWOULDBLOCK, buffer, 0));
- errno = 123;
- printf("<%d>\n", errno);
-
- return 0;
- }
- '''
- expected = '''
- <Math arg out of domain of func>
- <No more processes>
- <34>
- <123>
- '''
- self.do_run(src, re.sub('(^|\n)\s+', '\\1', expected))
+ self.do_run_from_file(src, output)
def test_mainenv(self):
- src = '''
- #include <stdio.h>
- int main(int argc, char **argv, char **envp)
- {
- printf("*%p*\\n", envp);
- return 0;
- }
- '''
- self.do_run(src, '*(nil)*')
+ test_path = path_from_root('tests', 'core', 'test_mainenv')
+ src, output = (test_path + s for s in ('.in', '.out'))
+
+ self.do_run_from_file(src, output)
def test_funcs(self):
- src = '''
- #include <stdio.h>
- int funcy(int x)
- {
- return x*9;
- }
- int main()
- {
- printf("*%d,%d*\\n", funcy(8), funcy(10));
- return 0;
- }
- '''
- self.do_run(src, '*72,90*')
+ test_path = path_from_root('tests', 'core', 'test_funcs')
+ src, output = (test_path + s for s in ('.in', '.out'))
+
+ self.do_run_from_file(src, output)
def test_structs(self):
- src = '''
- #include <stdio.h>
- struct S
- {
- int x, y;
- };
- int main()
- {
- S a, b;
- a.x = 5; a.y = 6;
- b.x = 101; b.y = 7009;
- S *c, *d;
- c = &a;
- c->x *= 2;
- c = &b;
- c->y -= 1;
- d = c;
- d->y += 10;
- printf("*%d,%d,%d,%d,%d,%d,%d,%d*\\n", a.x, a.y, b.x, b.y, c->x, c->y, d->x, d->y);
- return 0;
- }
- '''
- self.do_run(src, '*10,6,101,7018,101,7018,101,7018*')
+ test_path = path_from_root('tests', 'core', 'test_structs')
+ src, output = (test_path + s for s in ('.in', '.out'))
+
+ self.do_run_from_file(src, output)
gen_struct_src = '''
#include <stdio.h>
@@ -2069,82 +996,22 @@ returned |umber one top notchfi FI FO FUM WHEN WHERE WHY HOW WHO|''', ['wowie',
self.do_run(self.gen_struct_src.replace('{{gen_struct}}', 'new S').replace('{{del_struct}}', 'delete'), '*51,62*')
def test_addr_of_stacked(self):
- src = '''
- #include <stdio.h>
- void alter(int *y)
- {
- *y += 5;
- }
- int main()
- {
- int x = 2;
- alter(&x);
- printf("*%d*\\n", x);
- return 0;
- }
- '''
- self.do_run(src, '*7*')
+ test_path = path_from_root('tests', 'core', 'test_addr_of_stacked')
+ src, output = (test_path + s for s in ('.in', '.out'))
- def test_globals(self):
- src = '''
- #include <stdio.h>
+ self.do_run_from_file(src, output)
- char cache[256], *next = cache;
+ def test_globals(self):
+ test_path = path_from_root('tests', 'core', 'test_globals')
+ src, output = (test_path + s for s in ('.in', '.out'))
- int main()
- {
- cache[10] = 25;
- next[20] = 51;
- printf("*%d,%d*\\n", next[10], cache[20]);
- return 0;
- }
- '''
- self.do_run(src, '*25,51*')
+ self.do_run_from_file(src, output)
def test_linked_list(self):
- src = '''
- #include <stdio.h>
- struct worker_args {
- int value;
- struct worker_args *next;
- };
- int main()
- {
- worker_args a;
- worker_args b;
- a.value = 60;
- a.next = &b;
- b.value = 900;
- b.next = NULL;
- worker_args* c = &a;
- int total = 0;
- while (c) {
- total += c->value;
- c = c->next;
- }
+ test_path = path_from_root('tests', 'core', 'test_linked_list')
+ src, output = (test_path + s for s in ('.in', '.out'))
- // Chunk of em
- worker_args chunk[10];
- for (int i = 0; i < 9; i++) {
- chunk[i].value = i*10;
- chunk[i].next = &chunk[i+1];
- }
- chunk[9].value = 90;
- chunk[9].next = &chunk[0];
-
- c = chunk;
- do {
- total += c->value;
- c = c->next;
- } while (c != chunk);
-
- printf("*%d,%d*\\n", total, b.next);
- // NULL *is* 0, in C/C++. No JS null! (null == 0 is false, etc.)
-
- return 0;
- }
- '''
- self.do_run(src, '*1410,0*')
+ self.do_run_from_file(src, output)
def test_sup(self):
src = '''
@@ -2197,416 +1064,77 @@ returned |umber one top notchfi FI FO FUM WHEN WHERE WHY HOW WHO|''', ['wowie',
self.do_run(src, 'sizeofs:6,8\n*C___: 0,6,12,20<24*\n*Carr: 0,6,12,20<24*\n*C__w: 0,6,12,20<24*\n*Cp1_: 4,6,12,20<24*\n*Cp2_: 0,6,12,20<24*\n*Cint: 0,8,12,20<24*\n*C4__: 0,8,12,20<24*\n*C4_2: 0,6,10,16<20*\n*C__z: 0,8,16,24<28*')
def test_assert(self):
- src = '''
- #include <stdio.h>
- #include <assert.h>
- int main() {
- assert(1 == true); // pass
- assert(1 == false); // fail
- return 0;
- }
- '''
- self.do_run(src, 'Assertion failed: 1 == false')
+ test_path = path_from_root('tests', 'core', 'test_assert')
+ src, output = (test_path + s for s in ('.in', '.out'))
+
+ self.do_run_from_file(src, output)
def test_libcextra(self):
if self.emcc_args is None: return self.skip('needs emcc for libcextra')
- src = r'''
- #include <stdio.h>
- #include <wchar.h>
-
- int main()
- {
- const wchar_t* wstr = L"Hello";
- printf("wcslen: %d\n", wcslen(wstr));
+ test_path = path_from_root('tests', 'core', 'test_libcextra')
+ src, output = (test_path + s for s in ('.in', '.out'))
- return 0;
- }
- '''
- self.do_run(src, 'wcslen: 5')
+ self.do_run_from_file(src, output)
def test_regex(self):
- # This is from http://pic.dhe.ibm.com/infocenter/iseries/v7r1m0/index.jsp?topic=%2Frtref%2Fregexec.htm
if self.emcc_args is None: return self.skip('needs emcc for libcextra')
- src = r'''
- #include <regex.h>
- #include <stdio.h>
- #include <stdlib.h>
- int main(void)
- {
- regex_t preg;
- const char *string = "a very simple simple simple string";
- const char *pattern = "\\(sim[a-z]le\\) \\1";
- int rc;
- size_t nmatch = 2;
- regmatch_t pmatch[2];
-
- if (0 != (rc = regcomp(&preg, pattern, 0))) {
- printf("regcomp() failed, returning nonzero (%d)\n", rc);
- exit(EXIT_FAILURE);
- }
-
- if (0 != (rc = regexec(&preg, string, nmatch, pmatch, 0))) {
- printf("Failed to match '%s' with '%s',returning %d.\n",
- string, pattern, rc);
- }
- else {
- printf("With the whole expression, "
- "a matched substring \"%.*s\" is found at position %d to %d.\n",
- pmatch[0].rm_eo - pmatch[0].rm_so, &string[pmatch[0].rm_so],
- pmatch[0].rm_so, pmatch[0].rm_eo - 1);
- printf("With the sub-expression, "
- "a matched substring \"%.*s\" is found at position %d to %d.\n",
- pmatch[1].rm_eo - pmatch[1].rm_so, &string[pmatch[1].rm_so],
- pmatch[1].rm_so, pmatch[1].rm_eo - 1);
- }
- regfree(&preg);
- return 0;
- }
- '''
- self.do_run(src, 'With the whole expression, a matched substring "simple simple" is found at position 7 to 19.\n'
- 'With the sub-expression, a matched substring "simple" is found at position 7 to 12.')
+ test_path = path_from_root('tests', 'core', 'test_regex')
+ src, output = (test_path + s for s in ('.in', '.out'))
- def test_longjmp(self):
- src = r'''
- #include <stdio.h>
- #include <setjmp.h>
-
- static jmp_buf buf;
-
- void second(void) {
- printf("second\n");
- longjmp(buf,-1);
- }
+ self.do_run_from_file(src, output)
- void first(void) {
- printf("first\n"); // prints
- longjmp(buf,1); // jumps back to where setjmp was called - making setjmp now return 1
- }
-
- int main() {
- volatile int x = 0;
- int jmpval = setjmp(buf);
- if (!jmpval) {
- x++; // should be properly restored once longjmp jumps back
- first(); // when executed, setjmp returns 1
- printf("skipped\n"); // does not print
- } else if (jmpval == 1) { // when first() jumps back, setjmp returns 1
- printf("result: %d %d\n", x, jmpval); // prints
- x++;
- second(); // when executed, setjmp returns -1
- } else if (jmpval == -1) { // when second() jumps back, setjmp returns -1
- printf("result: %d %d\n", x, jmpval); // prints
- }
+ def test_longjmp(self):
+ test_path = path_from_root('tests', 'core', 'test_longjmp')
+ src, output = (test_path + s for s in ('.in', '.out'))
- return 0;
- }
- '''
- self.do_run(src, 'first\nresult: 1 1\nsecond\nresult: 2 -1')
+ self.do_run_from_file(src, output)
def test_longjmp2(self):
- src = r'''
- #include <setjmp.h>
- #include <stdio.h>
+ test_path = path_from_root('tests', 'core', 'test_longjmp2')
+ src, output = (test_path + s for s in ('.in', '.out'))
- typedef struct {
- jmp_buf* jmp;
- } jmp_state;
-
- void stack_manipulate_func(jmp_state* s, int level) {
- jmp_buf buf;
-
- printf("Entering stack_manipulate_func, level: %d\n", level);
-
- if (level == 0) {
- s->jmp = &buf;
- if (setjmp(*(s->jmp)) == 0) {
- printf("Setjmp normal execution path, level: %d\n", level);
- stack_manipulate_func(s, level + 1);
- } else {
- printf("Setjmp error execution path, level: %d\n", level);
- }
- } else {
- printf("Perform longjmp at level %d\n", level);
- longjmp(*(s->jmp), 1);
- }
-
- printf("Exiting stack_manipulate_func, level: %d\n", level);
- }
-
- int main(int argc, char *argv[]) {
- jmp_state s;
- s.jmp = NULL;
- stack_manipulate_func(&s, 0);
-
- return 0;
- }
- '''
- self.do_run(src, '''Entering stack_manipulate_func, level: 0
-Setjmp normal execution path, level: 0
-Entering stack_manipulate_func, level: 1
-Perform longjmp at level 1
-Setjmp error execution path, level: 0
-Exiting stack_manipulate_func, level: 0
-''')
+ self.do_run_from_file(src, output)
def test_longjmp3(self):
- src = r'''
- #include <setjmp.h>
- #include <stdio.h>
-
- typedef struct {
- jmp_buf* jmp;
- } jmp_state;
+ test_path = path_from_root('tests', 'core', 'test_longjmp3')
+ src, output = (test_path + s for s in ('.in', '.out'))
- void setjmp_func(jmp_state* s, int level) {
- jmp_buf* prev_jmp = s->jmp;
- jmp_buf c_jmp;
-
- if (level == 2) {
- printf("level is 2, perform longjmp!\n");
- longjmp(*(s->jmp), 1);
- }
-
- if (setjmp(c_jmp) == 0) {
- printf("setjmp normal execution path, level: %d\n", level);
- s->jmp = &c_jmp;
- setjmp_func(s, level + 1);
- } else {
- printf("setjmp exception execution path, level: %d\n", level);
- if (prev_jmp) {
- printf("prev_jmp is not empty, continue with longjmp!\n");
- s->jmp = prev_jmp;
- longjmp(*(s->jmp), 1);
- }
- }
-
- printf("Exiting setjmp function, level: %d\n", level);
- }
-
- int main(int argc, char *argv[]) {
- jmp_state s;
- s.jmp = NULL;
-
- setjmp_func(&s, 0);
-
- return 0;
- }
- '''
- self.do_run(src, '''setjmp normal execution path, level: 0
-setjmp normal execution path, level: 1
-level is 2, perform longjmp!
-setjmp exception execution path, level: 1
-prev_jmp is not empty, continue with longjmp!
-setjmp exception execution path, level: 0
-Exiting setjmp function, level: 0
-''')
+ self.do_run_from_file(src, output)
def test_longjmp4(self):
- src = r'''
- #include <setjmp.h>
- #include <stdio.h>
-
- typedef struct {
- jmp_buf* jmp;
- } jmp_state;
-
- void second_func(jmp_state* s);
-
- void first_func(jmp_state* s) {
- jmp_buf* prev_jmp = s->jmp;
- jmp_buf c_jmp;
- volatile int once = 0;
-
- if (setjmp(c_jmp) == 0) {
- printf("Normal execution path of first function!\n");
+ test_path = path_from_root('tests', 'core', 'test_longjmp4')
+ src, output = (test_path + s for s in ('.in', '.out'))
- s->jmp = &c_jmp;
- second_func(s);
- } else {
- printf("Exception execution path of first function! %d\n", once);
-
- if (!once) {
- printf("Calling longjmp the second time!\n");
- once = 1;
- longjmp(*(s->jmp), 1);
- }
- }
- }
-
- void second_func(jmp_state* s) {
- longjmp(*(s->jmp), 1);
- }
-
- int main(int argc, char *argv[]) {
- jmp_state s;
- s.jmp = NULL;
-
- first_func(&s);
-
- return 0;
- }
- '''
- self.do_run(src, '''Normal execution path of first function!
-Exception execution path of first function! 0
-Calling longjmp the second time!
-Exception execution path of first function! 1
-''')
+ self.do_run_from_file(src, output)
def test_longjmp_funcptr(self):
- src = r'''
- #include <stdio.h>
- #include <setjmp.h>
-
- static jmp_buf buf;
-
- void (*fp)() = NULL;
+ test_path = path_from_root('tests', 'core', 'test_longjmp_funcptr')
+ src, output = (test_path + s for s in ('.in', '.out'))
- void second(void) {
- printf("second\n"); // prints
- longjmp(buf,1); // jumps back to where setjmp was called - making setjmp now return 1
- }
-
- void first(void) {
- fp();
- printf("first\n"); // does not print
- }
-
- int main(int argc, char **argv) {
- fp = argc == 200 ? NULL : second;
-
- volatile int x = 0;
- if ( ! setjmp(buf) ) {
- x++;
- first(); // when executed, setjmp returns 0
- } else { // when longjmp jumps back, setjmp returns 1
- printf("main: %d\n", x); // prints
- }
-
- return 0;
- }
- '''
- self.do_run(src, 'second\nmain: 1\n')
+ self.do_run_from_file(src, output)
def test_longjmp_repeat(self):
Settings.MAX_SETJMPS = 1
- src = r'''
- #include <stdio.h>
- #include <setjmp.h>
-
- static jmp_buf buf;
+ test_path = path_from_root('tests', 'core', 'test_longjmp_repeat')
+ src, output = (test_path + s for s in ('.in', '.out'))
- int main() {
- volatile int x = 0;
- printf("setjmp:%d\n", setjmp(buf));
- x++;
- printf("x:%d\n", x);
- if (x < 4) longjmp(buf, x*2);
- return 0;
- }
- '''
- self.do_run(src, '''setjmp:0
-x:1
-setjmp:2
-x:2
-setjmp:4
-x:3
-setjmp:6
-x:4
-''')
+ self.do_run_from_file(src, output)
def test_longjmp_stacked(self):
- src = r'''
- #include <stdio.h>
- #include <setjmp.h>
- #include <stdlib.h>
- #include <string.h>
+ test_path = path_from_root('tests', 'core', 'test_longjmp_stacked')
+ src, output = (test_path + s for s in ('.in', '.out'))
- int bottom, top;
-
- int run(int y) {
- // confuse stack
- char *s = (char*)alloca(100);
- memset(s, 1, 100);
- s[y] = y;
- s[y/2] = y*2;
- volatile int x = s[y];
- top = (int)alloca(4);
- if (x <= 2) return x;
- jmp_buf buf;
- printf("setjmp of %d\n", x);
- if (setjmp(buf) == 0) {
- printf("going\n");
- x += run(x/2);
- longjmp(buf, 1);
- }
- printf("back\n");
- return x/2;
- }
+ self.do_run_from_file(src, output)
- int main(int argc, char **argv) {
- int sum = 0;
- for (int i = 0; i < argc*2; i++) {
- bottom = (int)alloca(4);
- sum += run(10);
- // scorch the earth
- if (bottom < top) {
- memset((void*)bottom, 1, top - bottom);
- } else {
- memset((void*)top, 1, bottom - top);
- }
- }
- printf("%d\n", sum);
- return sum;
- }
- '''
- self.do_run(src, '''setjmp of 10
-going
-setjmp of 5
-going
-back
-back
-setjmp of 10
-going
-setjmp of 5
-going
-back
-back
-12
-''')
def test_longjmp_exc(self):
- src = r'''
- #include <stdlib.h>
- #include <stdio.h>
- #include <setjmp.h>
- #include <emscripten.h>
-
- jmp_buf abortframe;
+ test_path = path_from_root('tests', 'core', 'test_longjmp_exc')
+ src, output = (test_path + s for s in ('.in', '.out'))
- void dostuff(int a) {
- printf("pre\n");
- if (a != 42) emscripten_run_script("waka_waka()"); // this should fail, and never reach "never"
- printf("never\n");
-
- if (a == 100) {
- longjmp (abortframe, -1);
- }
-
- if (setjmp(abortframe)) {
- printf("got 100");
- }
- }
-
- int main(int argc, char **argv) {
- dostuff(argc);
- exit(1);
- return 1;
- }
- '''
- self.do_run(src, 'waka_waka');
+ self.do_run_from_file(src, output)
def test_setjmp_many(self):
src = r'''
@@ -2716,62 +1244,21 @@ back
def test_exception_2(self):
if self.emcc_args is None: return self.skip('need emcc to add in libcxx properly')
Settings.DISABLE_EXCEPTION_CATCHING = 0
- src = r'''
- #include <stdexcept>
- #include <stdio.h>
- typedef void (*FuncPtr)();
+ test_path = path_from_root('tests', 'core', 'test_exception_2')
+ src, output = (test_path + s for s in ('.in', '.out'))
- void ThrowException()
- {
- throw std::runtime_error("catch me!");
- }
-
- FuncPtr ptr = ThrowException;
-
- int main()
- {
- try
- {
- ptr();
- }
- catch(...)
- {
- printf("Exception caught successfully!\n");
- }
- return 0;
- }
- '''
- self.do_run(src, 'Exception caught successfully!')
+ self.do_run_from_file(src, output)
def test_white_list_exception(self):
Settings.DISABLE_EXCEPTION_CATCHING = 2
Settings.EXCEPTION_CATCHING_WHITELIST = ["__Z12somefunctionv"]
Settings.INLINING_LIMIT = 50 # otherwise it is inlined and not identified
- src = '''
- #include <stdio.h>
+ test_path = path_from_root('tests', 'core', 'test_white_list_exception')
+ src, output = (test_path + s for s in ('.in', '.out'))
- void thrower() {
- printf("infunc...");
- throw(99);
- printf("FAIL");
- }
-
- void somefunction() {
- try {
- thrower();
- } catch(...) {
- printf("done!*\\n");
- }
- }
-
- int main() {
- somefunction();
- return 0;
- }
- '''
- self.do_run(src, 'infunc...done!*')
+ self.do_run_from_file(src, output)
Settings.DISABLE_EXCEPTION_CATCHING = 0
Settings.EXCEPTION_CATCHING_WHITELIST = []
@@ -2824,87 +1311,21 @@ back
def test_multiexception(self):
Settings.DISABLE_EXCEPTION_CATCHING = 0
- src = r'''
-#include <stdio.h>
-
-static int current_exception_id = 0;
-typedef struct {
-int jmp;
-} jmp_state;
+ test_path = path_from_root('tests', 'core', 'test_multiexception')
+ src, output = (test_path + s for s in ('.in', '.out'))
-void setjmp_func(jmp_state* s, int level) {
-int prev_jmp = s->jmp;
-int c_jmp;
-
-if (level == 2) {
- printf("level is 2, perform longjmp!\n");
- throw 1;
-}
-
-c_jmp = current_exception_id++;
-try {
- printf("setjmp normal execution path, level: %d, prev_jmp: %d\n", level, prev_jmp);
- s->jmp = c_jmp;
- setjmp_func(s, level + 1);
-} catch (int catched_eid) {
- printf("caught %d\n", catched_eid);
- if (catched_eid == c_jmp) {
- printf("setjmp exception execution path, level: %d, prev_jmp: %d\n", level, prev_jmp);
- if (prev_jmp != -1) {
- printf("prev_jmp is not empty, continue with longjmp!\n");
- s->jmp = prev_jmp;
- throw s->jmp;
- }
- } else {
- throw;
- }
-}
-
-printf("Exiting setjmp function, level: %d, prev_jmp: %d\n", level, prev_jmp);
-}
-
-int main(int argc, char *argv[]) {
-jmp_state s;
-s.jmp = -1;
-
-setjmp_func(&s, 0);
-
-return 0;
-}
-'''
- self.do_run(src, '''setjmp normal execution path, level: 0, prev_jmp: -1
-setjmp normal execution path, level: 1, prev_jmp: 0
-level is 2, perform longjmp!
-caught 1
-setjmp exception execution path, level: 1, prev_jmp: 0
-prev_jmp is not empty, continue with longjmp!
-caught 0
-setjmp exception execution path, level: 0, prev_jmp: -1
-Exiting setjmp function, level: 0, prev_jmp: -1
-''')
+ self.do_run_from_file(src, output)
def test_std_exception(self):
if self.emcc_args is None: return self.skip('requires emcc')
Settings.DISABLE_EXCEPTION_CATCHING = 0
self.emcc_args += ['-s', 'SAFE_HEAP=0']
- src = r'''
- #include <stdio.h>
- #include <exception>
+ test_path = path_from_root('tests', 'core', 'test_std_exception')
+ src, output = (test_path + s for s in ('.in', '.out'))
- int main()
- {
- std::exception e;
- try {
- throw e;
- } catch(std::exception e) {
- printf("caught std::exception\n");
- }
- return 0;
- }
- '''
- self.do_run(src, 'caught std::exception')
+ self.do_run_from_file(src, output)
def test_async_exit(self):
open('main.c', 'w').write(r'''
@@ -2974,128 +1395,40 @@ Exiting setjmp function, level: 0, prev_jmp: -1
self.do_run(src, '''reported\nExit Status: 1\npostRun\nok.\n''')
def test_class(self):
- src = '''
- #include <stdio.h>
- struct Random {
- enum { IM = 139968, IA = 3877, IC = 29573 };
- Random() : last(42) {}
- float get( float max = 1.0f ) {
- last = ( last * IA + IC ) % IM;
- return max * last / IM;
- }
- protected:
- unsigned int last;
- } rng1;
- int main()
- {
- Random rng2;
- int count = 0;
- for (int i = 0; i < 100; i++) {
- float x1 = rng1.get();
- float x2 = rng2.get();
- printf("%f, %f\\n", x1, x2);
- if (x1 != x2) count += 1;
- }
- printf("*%d*\\n", count);
- return 0;
- }
- '''
- self.do_run(src, '*0*')
+ test_path = path_from_root('tests', 'core', 'test_class')
+ src, output = (test_path + s for s in ('.in', '.out'))
+
+ self.do_run_from_file(src, output)
def test_inherit(self):
- src = '''
- #include <stdio.h>
- struct Parent {
- int x1, x2;
- };
- struct Child : Parent {
- int y;
- };
- int main()
- {
- Parent a;
- a.x1 = 50;
- a.x2 = 87;
- Child b;
- b.x1 = 78;
- b.x2 = 550;
- b.y = 101;
- Child* c = (Child*)&a;
- c->x1 ++;
- c = &b;
- c->y --;
- printf("*%d,%d,%d,%d,%d,%d,%d*\\n", a.x1, a.x2, b.x1, b.x2, b.y, c->x1, c->x2);
- return 0;
- }
- '''
- self.do_run(src, '*51,87,78,550,100,78,550*')
+ test_path = path_from_root('tests', 'core', 'test_inherit')
+ src, output = (test_path + s for s in ('.in', '.out'))
+
+ self.do_run_from_file(src, output)
def test_isdigit_l(self):
if self.emcc_args is None: return self.skip('no libcxx inclusion without emcc')
- src = '''
- #include <iostream>
- int main() {
- using namespace std;
- use_facet<num_put<char> >(cout.getloc()).put(cout, cout, '0', 3.14159265);
- }
- '''
- self.do_run(src, '3.14159')
+ test_path = path_from_root('tests', 'core', 'test_isdigit_l')
+ src, output = (test_path + s for s in ('.in', '.out'))
+
+ self.do_run_from_file(src, output)
def test_iswdigit(self):
if self.emcc_args is None: return self.skip('no libcxx inclusion without emcc')
- src = '''
- #include <stdio.h>
- #include <cctype>
- #include <cwctype>
+ test_path = path_from_root('tests', 'core', 'test_iswdigit')
+ src, output = (test_path + s for s in ('.in', '.out'))
- int main() {
- using namespace std;
- printf("%d ", isdigit('0'));
- printf("%d ", iswdigit(L'0'));
- return 0;
- }
- '''
- self.do_run(src, '1 1')
+ self.do_run_from_file(src, output)
def test_polymorph(self):
if self.emcc_args is None: return self.skip('requires emcc')
- src = '''
- #include <stdio.h>
- struct Pure {
- virtual int implme() = 0;
- };
- struct Parent : Pure {
- virtual int getit() { return 11; };
- int implme() { return 32; }
- };
- struct Child : Parent {
- int getit() { return 74; }
- int implme() { return 1012; }
- };
-
- struct Other {
- int one() { return 11; }
- int two() { return 22; }
- };
-
- int main()
- {
- Parent *x = new Parent();
- Parent *y = new Child();
- printf("*%d,%d,%d,%d*\\n", x->getit(), y->getit(), x->implme(), y->implme());
- Other *o = new Other;
- int (Other::*Ls)() = &Other::one;
- printf("*%d*\\n", (o->*(Ls))());
- Ls = &Other::two;
- printf("*%d*\\n", (o->*(Ls))());
+ test_path = path_from_root('tests', 'core', 'test_polymorph')
+ src, output = (test_path + s for s in ('.in', '.out'))
- return 0;
- }
- '''
- self.do_run(src, '*11,74,32,1012*\n*11*\n*22*')
+ self.do_run_from_file(src, output)
def test_segfault(self):
if self.emcc_args is None: return self.skip('SAFE_HEAP without ta2 means we check types too, which hide segfaults')
@@ -3165,211 +1498,64 @@ Exiting setjmp function, level: 0, prev_jmp: -1
def test_dynamic_cast(self):
if self.emcc_args is None: return self.skip('need libcxxabi')
- src = r'''
- #include <stdio.h>
+ test_path = path_from_root('tests', 'core', 'test_dynamic_cast')
+ src, output = (test_path + s for s in ('.in', '.out'))
- struct Support {
- virtual void f() {
- printf("f()\n");
- }
- };
-
- struct Derived : Support {
- };
-
- int main() {
- Support * p = new Derived;
- dynamic_cast<Derived*>(p)->f();
- }
- '''
- self.do_run(src, 'f()\n')
+ self.do_run_from_file(src, output)
def test_dynamic_cast_b(self):
if self.emcc_args is None: return self.skip('need libcxxabi')
- src = '''
- #include <stdio.h>
+ test_path = path_from_root('tests', 'core', 'test_dynamic_cast_b')
+ src, output = (test_path + s for s in ('.in', '.out'))
- class CBase { virtual void dummy() {} };
- class CDerived : public CBase { int a; };
- class CDerivedest : public CDerived { float b; };
-
- int main ()
- {
- CBase *pa = new CBase;
- CBase *pb = new CDerived;
- CBase *pc = new CDerivedest;
-
- printf("a1: %d\\n", dynamic_cast<CDerivedest*>(pa) != NULL);
- printf("a2: %d\\n", dynamic_cast<CDerived*>(pa) != NULL);
- printf("a3: %d\\n", dynamic_cast<CBase*>(pa) != NULL);
-
- printf("b1: %d\\n", dynamic_cast<CDerivedest*>(pb) != NULL);
- printf("b2: %d\\n", dynamic_cast<CDerived*>(pb) != NULL);
- printf("b3: %d\\n", dynamic_cast<CBase*>(pb) != NULL);
-
- printf("c1: %d\\n", dynamic_cast<CDerivedest*>(pc) != NULL);
- printf("c2: %d\\n", dynamic_cast<CDerived*>(pc) != NULL);
- printf("c3: %d\\n", dynamic_cast<CBase*>(pc) != NULL);
-
- return 0;
- }
- '''
- self.do_run(src, 'a1: 0\na2: 0\na3: 1\nb1: 0\nb2: 1\nb3: 1\nc1: 1\nc2: 1\nc3: 1\n')
+ self.do_run_from_file(src, output)
def test_dynamic_cast_2(self):
if self.emcc_args is None: return self.skip('need libcxxabi')
- src = r'''
- #include <stdio.h>
- #include <typeinfo>
-
- class Class {};
+ test_path = path_from_root('tests', 'core', 'test_dynamic_cast_2')
+ src, output = (test_path + s for s in ('.in', '.out'))
- int main() {
- const Class* dp = dynamic_cast<const Class*>(&typeid(Class));
- // should return dp == NULL,
- printf("pointer: %p\n", dp);
- }
- '''
- self.do_run(src, "pointer: (nil)")
+ self.do_run_from_file(src, output)
def test_funcptr(self):
- src = '''
- #include <stdio.h>
- int calc1() { return 26; }
- int calc2() { return 90; }
- typedef int (*fp_t)();
-
- fp_t globally1 = calc1;
- fp_t globally2 = calc2;
-
- int nothing(const char *str) { return 0; }
+ test_path = path_from_root('tests', 'core', 'test_funcptr')
+ src, output = (test_path + s for s in ('.in', '.out'))
- int main()
- {
- fp_t fp = calc1;
- void *vp = (void*)fp;
- fp_t fpb = (fp_t)vp;
- fp_t fp2 = calc2;
- void *vp2 = (void*)fp2;
- fp_t fpb2 = (fp_t)vp2;
- printf("*%d,%d,%d,%d,%d,%d*\\n", fp(), fpb(), fp2(), fpb2(), globally1(), globally2());
-
- fp_t t = calc1;
- printf("*%d,%d", t == calc1, t == calc2);
- t = calc2;
- printf(",%d,%d*\\n", t == calc1, t == calc2);
-
- int (*other)(const char *str);
- other = nothing;
- other("*hello!*");
- other = puts;
- other("*goodbye!*");
-
- return 0;
- }
- '''
- self.do_run(src, '*26,26,90,90,26,90*\n*1,0,0,1*\n*goodbye!*')
+ self.do_run_from_file(src, output)
def test_mathfuncptr(self):
- src = '''
- #include <math.h>
- #include <stdio.h>
+ test_path = path_from_root('tests', 'core', 'test_mathfuncptr')
+ src, output = (test_path + s for s in ('.in', '.out'))
- int
- main(int argc, char **argv) {
- float (*fn)(float) = argc != 12 ? &sqrtf : &fabsf;
- float (*fn2)(float) = argc != 13 ? &fabsf : &sqrtf;
- float (*fn3)(float) = argc != 14 ? &erff : &fabsf;
- printf("fn2(-5) = %d, fn(10) = %.2f, erf(10) = %.2f\\n", (int)fn2(-5), fn(10), fn3(10));
- return 0;
- }
- '''
- self.do_run(src, 'fn2(-5) = 5, fn(10) = 3.16, erf(10) = 1.00')
+ self.do_run_from_file(src, output)
def test_funcptrfunc(self):
- src = r'''
- #include <stdio.h>
-
- typedef void (*funcptr)(int, int);
- typedef funcptr (*funcptrfunc)(int);
+ test_path = path_from_root('tests', 'core', 'test_funcptrfunc')
+ src, output = (test_path + s for s in ('.in', '.out'))
- funcptr __attribute__ ((noinline)) getIt(int x) {
- return (funcptr)x;
- }
-
- int main(int argc, char **argv)
- {
- funcptrfunc fpf = argc < 100 ? getIt : NULL;
- printf("*%p*\n", fpf(argc));
- return 0;
- }
- '''
- self.do_run(src, '*0x1*')
+ self.do_run_from_file(src, output)
def test_funcptr_namecollide(self):
- src = r'''
- #include <stdio.h>
-
- void do_call(void (*puts)(const char *), const char *str);
+ test_path = path_from_root('tests', 'core', 'test_funcptr_namecollide')
+ src, output = (test_path + s for s in ('.in', '.out'))
- void do_print(const char *str) {
- if (!str) do_call(NULL, "delusion");
- if ((int)str == -1) do_print(str+10);
- puts("====");
- puts(str);
- puts("====");
- }
-
- void do_call(void (*puts)(const char *), const char *str) {
- if (!str) do_print("confusion");
- if ((int)str == -1) do_call(NULL, str-10);
- (*puts)(str);
- }
-
- int main(int argc, char **argv)
- {
- for (int i = 0; i < argc; i++) {
- do_call(i != 10 ? do_print : NULL, i != 15 ? "waka waka" : NULL);
- }
- return 0;
- }
- '''
- self.do_run(src, 'waka', force_c=True)
+ self.do_run_from_file(src, output, force_c=True)
def test_emptyclass(self):
if self.emcc_args is None: return self.skip('requires emcc')
- src = '''
- #include <stdio.h>
- struct Randomized {
- Randomized(int x) {
- printf("*zzcheezzz*\\n");
- }
- };
+ test_path = path_from_root('tests', 'core', 'test_emptyclass')
+ src, output = (test_path + s for s in ('.in', '.out'))
- int main( int argc, const char *argv[] ) {
- new Randomized(55);
-
- return 0;
- }
- '''
- self.do_run(src, '*zzcheezzz*')
+ self.do_run_from_file(src, output)
def test_alloca(self):
- src = '''
- #include <stdio.h>
- #include <stdlib.h>
+ test_path = path_from_root('tests', 'core', 'test_alloca')
+ src, output = (test_path + s for s in ('.in', '.out'))
- int main() {
- char *pc;
- pc = (char *)alloca(5);
- printf("z:%d*%d*\\n", pc > 0, (int)pc);
- return 0;
- }
- '''
- self.do_run(src, 'z:1*', force_c=True)
+ self.do_run_from_file(src, output, force_c=True)
def test_rename(self):
src = open(path_from_root('tests', 'stdio', 'test_rename.c'), 'r').read()
@@ -3378,80 +1564,29 @@ Exiting setjmp function, level: 0, prev_jmp: -1
def test_alloca_stack(self):
if self.emcc_args is None: return # too slow in other modes
- # We should not blow up the stack with numerous allocas
- src = '''
- #include <stdio.h>
- #include <stdlib.h>
+ test_path = path_from_root('tests', 'core', 'test_alloca_stack')
+ src, output = (test_path + s for s in ('.in', '.out'))
- func(int i) {
- char *pc = (char *)alloca(100);
- *pc = i;
- (*pc)++;
- return (*pc) % 10;
- }
- int main() {
- int total = 0;
- for (int i = 0; i < 1024*1024; i++)
- total += func(i);
- printf("ok:%d*\\n", total);
- return 0;
- }
- '''
- self.do_run(src, 'ok:-32768*', force_c=True)
+ self.do_run_from_file(src, output, force_c=True)
def test_stack_byval(self):
if self.emcc_args is None: return # too slow in other modes
- # We should also not blow up the stack with byval arguments
- src = r'''
- #include<stdio.h>
- struct vec {
- int x, y, z;
- vec(int x_, int y_, int z_) : x(x_), y(y_), z(z_) {}
- static vec add(vec a, vec b) {
- return vec(a.x+b.x, a.y+b.y, a.z+b.z);
- }
- };
- int main() {
- int total = 0;
- for (int i = 0; i < 1000; i++) {
- for (int j = 0; j < 1000; j++) {
- vec c(i+i%10, j*2, i%255);
- vec d(j*2, j%255, i%120);
- vec f = vec::add(c, d);
- total += (f.x + f.y + f.z) % 100;
- total %= 10240;
- }
- }
- printf("sum:%d*\n", total);
- return 0;
- }
- '''
- self.do_run(src, 'sum:9780*')
+ test_path = path_from_root('tests', 'core', 'test_stack_byval')
+ src, output = (test_path + s for s in ('.in', '.out'))
+
+ self.do_run_from_file(src, output)
def test_stack_varargs(self):
if self.emcc_args is None: return # too slow in other modes
Settings.INLINING_LIMIT = 50
+ Settings.TOTAL_STACK = 1024
- # We should not blow up the stack with numerous varargs
- src = r'''
- #include <stdio.h>
- #include <stdlib.h>
+ test_path = path_from_root('tests', 'core', 'test_stack_varargs')
+ src, output = (test_path + s for s in ('.in', '.out'))
- void func(int i) {
- printf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n",
- i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i);
- }
- int main() {
- for (int i = 0; i < 1024; i++)
- func(i);
- printf("ok!\n");
- return 0;
- }
- '''
- Settings.TOTAL_STACK = 1024
- self.do_run(src, 'ok!')
+ self.do_run_from_file(src, output)
def test_stack_varargs2(self):
if self.emcc_args is None: return # too slow in other modes
@@ -3532,23 +1667,10 @@ Exiting setjmp function, level: 0, prev_jmp: -1
def test_stack_void(self):
Settings.INLINING_LIMIT = 50
- src = r'''
- #include <stdio.h>
+ test_path = path_from_root('tests', 'core', 'test_stack_void')
+ src, output = (test_path + s for s in ('.in', '.out'))
- static char s[100]="aaaaa";
- static int func(void) {
- if(s[0]!='a') return 0;
- printf("iso open %s\n", s, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001);
- return 0;
- }
- int main(){
- int i;
- for(i=0;i<5000;i++)
- func();
- printf(".ok.\n");
- }
- '''
- self.do_run(src, '.ok.\n')
+ self.do_run_from_file(src, output)
def test_life(self):
if self.emcc_args is None: return self.skip('need c99')
@@ -3591,145 +1713,42 @@ Exiting setjmp function, level: 0, prev_jmp: -1
''', ['2'], force_c=True)
def test_array2(self):
- src = '''
- #include <stdio.h>
+ test_path = path_from_root('tests', 'core', 'test_array2')
+ src, output = (test_path + s for s in ('.in', '.out'))
- static const double grid[4][2] = {
- {-3/3.,-1/3.},{+1/3.,-3/3.},
- {-1/3.,+3/3.},{+3/3.,+1/3.}
- };
-
- int main() {
- for (int i = 0; i < 4; i++)
- printf("%d:%.2f,%.2f ", i, grid[i][0], grid[i][1]);
- printf("\\n");
- return 0;
- }
- '''
- self.do_run(src, '0:-1.00,-0.33 1:0.33,-1.00 2:-0.33,1.00 3:1.00,0.33')
+ self.do_run_from_file(src, output)
def test_array2b(self):
- src = '''
- #include <stdio.h>
-
- static const struct {
- unsigned char left;
- unsigned char right;
- } prioritah[] = {
- {6, 6}, {6, 6}, {7, 95}, {7, 7}
- };
-
- int main() {
- printf("*%d,%d\\n", prioritah[1].left, prioritah[1].right);
- printf("%d,%d*\\n", prioritah[2].left, prioritah[2].right);
- return 0;
- }
- '''
- self.do_run(src, '*6,6\n7,95*')
+ test_path = path_from_root('tests', 'core', 'test_array2b')
+ src, output = (test_path + s for s in ('.in', '.out'))
+ self.do_run_from_file(src, output)
def test_constglobalstructs(self):
- src = '''
- #include <stdio.h>
- struct IUB {
- int c;
- double p;
- unsigned int pi;
- };
-
- IUB iub[] = {
- { 'a', 0.27, 5 },
- { 'c', 0.15, 4 },
- { 'g', 0.12, 3 },
- { 't', 0.27, 2 },
- };
-
- const unsigned char faceedgesidx[6][4] =
- {
- { 4, 5, 8, 10 },
- { 6, 7, 9, 11 },
- { 0, 2, 8, 9 },
- { 1, 3, 10,11 },
- { 0, 1, 4, 6 },
- { 2, 3, 5, 7 },
- };
+ test_path = path_from_root('tests', 'core', 'test_constglobalstructs')
+ src, output = (test_path + s for s in ('.in', '.out'))
- int main( int argc, const char *argv[] ) {
- printf("*%d,%d,%d,%d*\\n", iub[0].c, int(iub[1].p*100), iub[2].pi, faceedgesidx[3][2]);
- return 0;
- }
- '''
- self.do_run(src, '*97,15,3,10*')
+ self.do_run_from_file(src, output)
def test_conststructs(self):
- src = '''
- #include <stdio.h>
- struct IUB {
- int c;
- double p;
- unsigned int pi;
- };
+ test_path = path_from_root('tests', 'core', 'test_conststructs')
+ src, output = (test_path + s for s in ('.in', '.out'))
- int main( int argc, const char *argv[] ) {
- int before = 70;
- IUB iub[] = {
- { 'a', 0.3029549426680, 5 },
- { 'c', 0.15, 4 },
- { 'g', 0.12, 3 },
- { 't', 0.27, 2 },
- };
- int after = 90;
- printf("*%d,%d,%d,%d,%d,%d*\\n", before, iub[0].c, int(iub[1].p*100), iub[2].pi, int(iub[0].p*10000), after);
- return 0;
- }
- '''
- self.do_run(src, '*70,97,15,3,3029,90*')
+ self.do_run_from_file(src, output)
def test_bigarray(self):
if self.emcc_args is None: return self.skip('need ta2 to compress type data on zeroinitializers')
- # avoid "array initializer too large" errors
- src = r'''
- #include <stdio.h>
- #include <assert.h>
+ test_path = path_from_root('tests', 'core', 'test_bigarray')
+ src, output = (test_path + s for s in ('.in', '.out'))
- #define SIZE (1024*100)
- struct Struct {
- char x;
- int y;
- };
- Struct buffy[SIZE];
-
- int main() {
- for (int i = 0; i < SIZE; i++) { assert(buffy[i].x == 0 && buffy[i].y == 0); } // we were zeroinitialized
- for (int i = 0; i < SIZE; i++) { buffy[i].x = i*i; buffy[i].y = i*i*i; } // we can save data
- printf("*%d*\n", buffy[SIZE/3].x);
- return 0;
- }
- '''
- self.do_run(src, '*57*')
+ self.do_run_from_file(src, output)
def test_mod_globalstruct(self):
- src = '''
- #include <stdio.h>
-
- struct malloc_params {
- size_t magic, page_size;
- };
-
- malloc_params mparams;
+ test_path = path_from_root('tests', 'core', 'test_mod_globalstruct')
+ src, output = (test_path + s for s in ('.in', '.out'))
- #define SIZE_T_ONE ((size_t)1)
- #define page_align(S) (((S) + (mparams.page_size - SIZE_T_ONE)) & ~(mparams.page_size - SIZE_T_ONE))
-
- int main()
- {
- mparams.page_size = 4096;
- printf("*%d,%d,%d,%d*\\n", mparams.page_size, page_align(1000), page_align(6000), page_align(66474));
- return 0;
- }
- '''
- self.do_run(src, '*4096,4096,8192,69632*')
+ self.do_run_from_file(src, output)
def test_pystruct(self):
src = '''
@@ -3803,62 +1822,25 @@ Exiting setjmp function, level: 0, prev_jmp: -1
def test_ptrtoint(self):
if self.emcc_args is None: return self.skip('requires emcc')
- src = '''
- #include <stdio.h>
- int main( int argc, const char *argv[] ) {
- char *a = new char[10];
- char *a0 = a+0;
- char *a5 = a+5;
- int *b = new int[10];
- int *b0 = b+0;
- int *b5 = b+5;
- int c = (int)b5-(int)b0; // Emscripten should warn!
- int d = (int)b5-(int)b0; // Emscripten should warn!
- printf("*%d*\\n", (int)a5-(int)a0);
- return 0;
- }
- '''
runner = self
def check_warnings(output):
runner.assertEquals(filter(lambda line: 'Warning' in line, output.split('\n')).__len__(), 4)
- self.do_run(src, '*5*', output_processor=check_warnings)
+
+ test_path = path_from_root('tests', 'core', 'test_ptrtoint')
+ src, output = (test_path + s for s in ('.in', '.out'))
+
+ self.do_run_from_file(src, output, output_processor=check_warnings)
def test_sizeof(self):
if self.emcc_args is None: return self.skip('requires emcc')
# Has invalid writes between printouts
Settings.SAFE_HEAP = 0
- src = '''
- #include <stdio.h>
- #include <string.h>
- #include "emscripten.h"
-
- struct A { int x, y; };
+ test_path = path_from_root('tests', 'core', 'test_sizeof')
+ src, output = (test_path + s for s in ('.in', '.out'))
- int main( int argc, const char *argv[] ) {
- int *a = new int[10];
- int *b = new int[1];
- int *c = new int[10];
- for (int i = 0; i < 10; i++)
- a[i] = 2;
- *b = 5;
- for (int i = 0; i < 10; i++)
- c[i] = 8;
- printf("*%d,%d,%d,%d,%d*\\n", a[0], a[9], *b, c[0], c[9]);
- // Should overwrite a, but not touch b!
- memcpy(a, c, 10*sizeof(int));
- printf("*%d,%d,%d,%d,%d*\\n", a[0], a[9], *b, c[0], c[9]);
-
- // Part 2
- A as[3] = { { 5, 12 }, { 6, 990 }, { 7, 2 } };
- memcpy(&as[0], &as[2], sizeof(A));
-
- printf("*%d,%d,%d,%d,%d,%d*\\n", as[0].x, as[0].y, as[1].x, as[1].y, as[2].x, as[2].y);
- return 0;
- }
- '''
- self.do_run(src, '*2,2,5,8,8***8,8,5,8,8***7,2,6,990,7,2*', [], lambda x, err: x.replace('\n', '*'))
+ self.do_run_from_file(src, output, [], lambda x, err: x.replace('\n', '*'))
def test_float_h(self):
process = Popen([PYTHON, EMCC, path_from_root('tests', 'float+.c')], stdout=PIPE, stderr=PIPE)
@@ -3866,44 +1848,18 @@ Exiting setjmp function, level: 0, prev_jmp: -1
assert process.returncode is 0, 'float.h should agree with our system'
def test_llvm_used(self):
- src = r'''
- #include <stdio.h>
- #include <emscripten.h>
-
- extern "C" {
- EMSCRIPTEN_KEEPALIVE void foobar(int x) {
- printf("Worked! %d\n", x);
- }
- }
-
- int main() {
- emscripten_run_script("Module['_foobar'](10)");
- return 0;
- }'''
-
Building.LLVM_OPTS = 3
- self.do_run(src, 'Worked! 10\n')
- def test_emscripten_api(self):
- #if Settings.MICRO_OPTS or Settings.RELOOP or Building.LLVM_OPTS: return self.skip('FIXME')
+ test_path = path_from_root('tests', 'core', 'test_llvm_used')
+ src, output = (test_path + s for s in ('.in', '.out'))
- src = r'''
- #include <stdio.h>
- #include "emscripten.h"
+ self.do_run_from_file(src, output)
- extern "C" {
- void save_me_aimee() { printf("mann\n"); }
- }
+ def test_emscripten_api(self):
+ #if Settings.MICRO_OPTS or Settings.RELOOP or Building.LLVM_OPTS: return self.skip('FIXME')
- int main() {
- // EMSCRIPTEN_COMMENT("hello from the source");
- emscripten_run_script("Module.print('hello world' + '!')");
- printf("*%d*\n", emscripten_run_script_int("5*20"));
- printf("*%s*\n", emscripten_run_script_string("'five'+'six'"));
- emscripten_run_script("Module['_save_me_aimee']()");
- return 0;
- }
- '''
+ test_path = path_from_root('tests', 'core', 'test_emscripten_api')
+ src, output = (test_path + s for s in ('.in', '.out'))
check = '''
def process(filename):
@@ -3911,12 +1867,12 @@ def process(filename):
# TODO: restore this (see comment in emscripten.h) assert '// hello from the source' in src
'''
Settings.EXPORTED_FUNCTIONS = ['_main', '_save_me_aimee']
- self.do_run(src, 'hello world!\n*100*\n*fivesix*\nmann\n', post_build=check)
+ self.do_run_from_file(src, output, post_build=check)
# test EXPORT_ALL
Settings.EXPORTED_FUNCTIONS = []
Settings.EXPORT_ALL = 1
- self.do_run(src, 'hello world!\n*100*\n*fivesix*\nmann\n', post_build=check)
+ self.do_run_from_file(src, output, post_build=check)
def test_emscripten_get_now(self):
if Settings.USE_TYPED_ARRAYS != 2: return self.skip('requires ta2')
@@ -3927,92 +1883,29 @@ def process(filename):
def test_inlinejs(self):
if not self.is_le32(): return self.skip('le32 needed for inline js')
- src = r'''
- #include <stdio.h>
- double get() {
- double ret = 0;
- __asm __volatile__("Math.abs(-12/3.3)":"=r"(ret)); // write to a variable
- asm("#comment1");
- asm volatile("#comment2");
- asm volatile("#comment3\n"
- "#comment4\n");
- return ret;
- }
+ test_path = path_from_root('tests', 'core', 'test_inlinejs')
+ src, output = (test_path + s for s in ('.in', '.out'))
- int main() {
- asm("Module.print('Inline JS is very cool')");
- printf("%.2f\n", get());
-
- // Test that passing multiple input and output variables works.
- int src1 = 1, src2 = 2, src3 = 3;
- int dst1 = 0, dst2 = 0, dst3 = 0;
- // TODO asm("Module.print(%3); Module.print(%4); Module.print(%5); %0 = %3; %1 = %4; %2 = %5;" : "=r"(dst1),"=r"(dst2),"=r"(dst3): "r"(src1),"r"(src2),"r"(src3));
- // TODO printf("%d\n%d\n%d\n", dst1, dst2, dst3);
+ self.do_run_from_file(src, output)
- return 0;
- }
- '''
-
- self.do_run(src, 'Inline JS is very cool\n3.64\n') # TODO 1\n2\n3\n1\n2\n3\n')
if self.emcc_args == []: # opts will eliminate the comments
out = open('src.cpp.o.js').read()
for i in range(1, 5): assert ('comment%d' % i) in out
def test_inlinejs2(self):
if not self.is_le32(): return self.skip('le32 needed for inline js')
- src = r'''
- #include <stdio.h>
-
- int mix(int x, int y) {
- int ret;
- asm("Math.pow(2, %0+%1+1)" : "=r"(ret) : "r"(x), "r"(y)); // read and write
- return ret;
- }
- void mult() {
- asm("var $_$1 = Math.abs(-100); $_$1 *= 2; Module.print($_$1)"); // multiline
- asm __volatile__("Module.print('done')");
- }
+ test_path = path_from_root('tests', 'core', 'test_inlinejs2')
+ src, output = (test_path + s for s in ('.in', '.out'))
- int main(int argc, char **argv) {
- printf("%d\n", mix(argc, argc/2));
- mult();
- return 0;
- }
- '''
-
- self.do_run(src, '4\n200\ndone\n')
+ self.do_run_from_file(src, output)
def test_inlinejs3(self):
- src = r'''
- #include <stdio.h>
- #include <emscripten.h>
-
- int main(int argc, char **argv) {
- EM_ASM(Module.print('hello dere1'));
- EM_ASM(
- Module.print('hello dere2');
- );
- for (int i = 0; i < 3; i++) {
- EM_ASM(
- Module.print('hello dere3');
- Module.print('hello dere' + 4);
- );
- }
- int sum = 0;
- for (int i = 0; i < argc*3; i++) {
- sum += EM_ASM_INT({
- Module.print('i: ' + [$0, ($1).toFixed(2)]);
- return $0*2;
- }, i, double(i)/12);
- }
- printf("sum: %d\n", sum);
- return 0;
- }
- '''
+ test_path = path_from_root('tests', 'core', 'test_inlinejs3')
+ src, output = (test_path + s for s in ('.in', '.out'))
- self.do_run(src, 'hello dere1\nhello dere2\nhello dere3\nhello dere4\nhello dere3\nhello dere4\nhello dere3\nhello dere4\ni: 0,0.00\ni: 1,0.08\ni: 2,0.17\nsum: 6\n')
+ self.do_run_from_file(src, output)
def test_memorygrowth(self):
if Settings.USE_TYPED_ARRAYS == 0: return self.skip('memory growth is only supported with typed arrays')
@@ -4106,68 +1999,29 @@ def process(filename):
def test_tinyfuncstr(self):
if self.emcc_args is None: return self.skip('requires emcc')
- src = '''
- #include <stdio.h>
- struct Class {
- static char *name1() { return "nameA"; }
- char *name2() { return "nameB"; }
- };
+ test_path = path_from_root('tests', 'core', 'test_tinyfuncstr')
+ src, output = (test_path + s for s in ('.in', '.out'))
- int main() {
- printf("*%s,%s*\\n", Class::name1(), (new Class())->name2());
- return 0;
- }
- '''
- self.do_run(src, '*nameA,nameB*')
+ self.do_run_from_file(src, output)
def test_llvmswitch(self):
Settings.CORRECT_SIGNS = 1
- src = '''
- #include <stdio.h>
- #include <string.h>
+ test_path = path_from_root('tests', 'core', 'test_llvmswitch')
+ src, output = (test_path + s for s in ('.in', '.out'))
- int switcher(int p)
- {
- switch(p) {
- case 'a':
- case 'b':
- case 'c':
- return p-1;
- case -15:
- return p+1;
- }
- return p;
- }
-
- int main( int argc, const char *argv[] ) {
- unsigned int x = 0xfffffff1;
- x >>= (argc-1); // force it to be unsigned for purpose of checking our switch comparison in signed/unsigned
- printf("*%d,%d,%d,%d,%d,%d*\\n", switcher('a'), switcher('b'), switcher('c'), switcher(x), switcher(-15), switcher('e'));
- return 0;
- }
- '''
- self.do_run(src, '*96,97,98,-14,-14,101*')
+ self.do_run_from_file(src, output)
# By default, when user has not specified a -std flag, Emscripten should always build .cpp files using the C++03 standard,
# i.e. as if "-std=c++03" had been passed on the command line. On Linux with Clang 3.2 this is the case, but on Windows
# with Clang 3.2 -std=c++11 has been chosen as default, because of
# < jrose> clb: it's deliberate, with the idea that for people who don't care about the standard, they should be using the "best" thing we can offer on that platform
def test_cxx03_do_run(self):
- src = '''
- #include <stdio.h>
-
- #if __cplusplus != 199711L
- #error By default, if no -std is specified, emscripten should be compiling with -std=c++03!
- #endif
+ test_path = path_from_root('tests', 'core', 'test_cxx03_do_run')
+ src, output = (test_path + s for s in ('.in', '.out'))
- int main( int argc, const char *argv[] ) {
- printf("Hello world!\\n");
- return 0;
- }
- '''
- self.do_run(src, 'Hello world!')
+ self.do_run_from_file(src, output)
def test_bigswitch(self):
if self.run_name != 'default': return self.skip('TODO: issue #781')
@@ -4181,47 +2035,18 @@ def process(filename):
def test_indirectbr(self):
Building.COMPILER_TEST_OPTS = filter(lambda x: x != '-g', Building.COMPILER_TEST_OPTS)
- src = '''
- #include <stdio.h>
- int main(void) {
- const void *addrs[2] = { &&FOO, &&BAR };
-
- // confuse the optimizer so it doesn't hardcode the jump and avoid generating an |indirectbr| instruction
- int which = 0;
- for (int x = 0; x < 1000; x++) which = (which + x*x) % 7;
- which = (which % 2) + 1;
+ test_path = path_from_root('tests', 'core', 'test_indirectbr')
+ src, output = (test_path + s for s in ('.in', '.out'))
- goto *addrs[which];
-
- FOO:
- printf("bad\\n");
- return 0;
- BAR:
- printf("good\\n");
- const void *addr = &&FOO;
- goto *addr;
- }
- '''
- self.do_run(src, 'good\nbad')
+ self.do_run_from_file(src, output)
def test_indirectbr_many(self):
if Settings.USE_TYPED_ARRAYS != 2: return self.skip('blockaddr > 255 requires ta2')
- blocks = range(1500)
- init = ', '.join(['&&B%d' % b for b in blocks])
- defs = '\n'.join(['B%d: printf("%d\\n"); return 0;' % (b,b) for b in blocks])
- src = '''
- #include <stdio.h>
- int main(int argc, char **argv) {
- printf("\\n");
- const void *addrs[] = { %s };
- goto *addrs[argc*argc + 1000];
+ test_path = path_from_root('tests', 'core', 'test_indirectbr_many')
+ src, output = (test_path + s for s in ('.in', '.out'))
-%s
- return 0;
- }
- ''' % (init, defs)
- self.do_run(src, '\n1001\n')
+ self.do_run_from_file(src, output)
def test_pack(self):
src = '''
@@ -4261,124 +2086,10 @@ def process(filename):
if Settings.QUANTUM_SIZE == 1: return self.skip('FIXME: Add support for this')
if not self.is_le32(): return self.skip('we do not support all varargs stuff without le32')
- src = '''
- #include <stdio.h>
- #include <stdarg.h>
+ test_path = path_from_root('tests', 'core', 'test_varargs')
+ src, output = (test_path + s for s in ('.in', '.out'))
- void vary(const char *s, ...)
- {
- va_list v;
- va_start(v, s);
- char d[20];
- vsnprintf(d, 20, s, v);
- puts(d);
-
- // Try it with copying
- va_list tempva;
- va_copy(tempva, v);
- vsnprintf(d, 20, s, tempva);
- puts(d);
-
- va_end(v);
- }
-
- void vary2(char color, const char *s, ...)
- {
- va_list v;
- va_start(v, s);
- char d[21];
- d[0] = color;
- vsnprintf(d+1, 20, s, v);
- puts(d);
- va_end(v);
- }
-
- void varargs_listoffsets_list_evaluate(int count, va_list ap, int vaIteration)
- {
- while(count > 0)
- {
- const char* string = va_arg(ap, const char*);
- printf("%s", string);
- count--;
- }
- printf("\\n");
- }
-
- void varags_listoffsets_list_copy(int count, va_list ap, int iteration)
- {
- va_list ap_copy;
- va_copy(ap_copy, ap);
- varargs_listoffsets_list_evaluate(count, ap_copy, iteration);
- va_end(ap_copy);
- }
-
- void varargs_listoffsets_args(int type, int count, ...)
- {
- va_list ap;
- va_start(ap, count);
-
- // evaluate a copied list
- varags_listoffsets_list_copy(count, ap, 1);
- varags_listoffsets_list_copy(count, ap, 2);
- varags_listoffsets_list_copy(count, ap, 3);
- varags_listoffsets_list_copy(count, ap, 4);
-
- varargs_listoffsets_list_evaluate(count, ap, 1);
-
- // NOTE: we expect this test to fail, so we will check the stdout for <BAD+0><BAD+1>.....
- varargs_listoffsets_list_evaluate(count, ap, 2);
-
- // NOTE: this test has to work again, as we restart the list
- va_end(ap);
- va_start(ap, count);
- varargs_listoffsets_list_evaluate(count, ap, 3);
- va_end(ap);
- }
-
- void varargs_listoffsets_main()
- {
- varargs_listoffsets_args(0, 5, "abc", "def", "ghi", "jkl", "mno", "<BAD+0>", "<BAD+1>", "<BAD+2>", "<BAD+3>", "<BAD+4>", "<BAD+5>", "<BAD+6>", "<BAD+7>", "<BAD+8>", "<BAD+9>", "<BAD+10>", "<BAD+11>", "<BAD+12>", "<BAD+13>", "<BAD+14>", "<BAD+15>", "<BAD+16>");
- }
-
- #define GETMAX(pref, type) \
- type getMax##pref(int num, ...) \
- { \
- va_list vv; \
- va_start(vv, num); \
- type maxx = va_arg(vv, type); \
- for (int i = 1; i < num; i++) \
- { \
- type curr = va_arg(vv, type); \
- maxx = curr > maxx ? curr : maxx; \
- } \
- va_end(vv); \
- return maxx; \
- }
- GETMAX(i, int);
- GETMAX(D, double);
-
- int main(int argc, char **argv) {
- vary("*cheez: %d+%d*", 0, 24); // Also tests that '0' is not special as an array ender
- vary("*albeit*"); // Should not fail with no var args in vararg function
- vary2('Q', "%d*", 85);
-
- int maxxi = getMaxi(6, 2, 5, 21, 4, -10, 19);
- printf("maxxi:%d*\\n", maxxi);
- double maxxD = getMaxD(6, (double)2.1, (double)5.1, (double)22.1, (double)4.1, (double)-10.1, (double)19.1, (double)2);
- printf("maxxD:%.2f*\\n", (float)maxxD);
-
- // And, as a function pointer
- void (*vfp)(const char *s, ...) = argc == 1211 ? NULL : vary;
- vfp("*vfp:%d,%d*", 22, 199);
-
- // ensure lists work properly when copied, reinited etc.
- varargs_listoffsets_main();
-
- return 0;
- }
- '''
- self.do_run(src, '*cheez: 0+24*\n*cheez: 0+24*\n*albeit*\n*albeit*\nQ85*\nmaxxi:21*\nmaxxD:22.10*\n*vfp:22,199*\n*vfp:22,199*\n'+
- 'abcdefghijklmno\nabcdefghijklmno\nabcdefghijklmno\nabcdefghijklmno\nabcdefghijklmno\n<BAD+0><BAD+1><BAD+2><BAD+3><BAD+4>\nabcdefghijklmno\n')
+ self.do_run_from_file(src, output)
def test_varargs_byval(self):
if Settings.USE_TYPED_ARRAYS != 2: return self.skip('FIXME: Add support for this')
@@ -4454,20 +2165,10 @@ The current type of b is: 9
''')
def test_functionpointer_libfunc_varargs(self):
- src = r'''
- #include <stdio.h>
- #include <fcntl.h>
- typedef int (*fp_t)(int, int, ...);
- int main(int argc, char **argv) {
- fp_t fp = &fcntl;
- if (argc == 1337) fp = (fp_t)&main;
- (*fp)(0, 10);
- (*fp)(0, 10, 5);
- printf("waka\n");
- return 0;
- }
- '''
- self.do_run(src, '''waka''')
+ test_path = path_from_root('tests', 'core', 'test_functionpointer_libfunc_varargs')
+ src, output = (test_path + s for s in ('.in', '.out'))
+
+ self.do_run_from_file(src, output)
def test_structbyval(self):
Settings.INLINING_LIMIT = 50
@@ -4655,228 +2356,72 @@ The current type of b is: 9
if self.emcc_args is None: return self.skip('requires emcc')
# tests strtoll for hex strings (0x...)
- src = r'''
- #include <stdio.h>
- #include <stdlib.h>
+ test_path = path_from_root('tests', 'core', 'test_strtoll_hex')
+ src, output = (test_path + s for s in ('.in', '.out'))
- int main() {
- const char *STRING = "0x4 -0x3A +0xDEADBEEF";
- char *end_char;
-
- // undefined base
- long long int l1 = strtoll(STRING, &end_char, 0);
- long long int l2 = strtoll(end_char, &end_char, 0);
- long long int l3 = strtoll(end_char, NULL, 0);
-
- // defined base
- long long int l4 = strtoll(STRING, &end_char, 16);
- long long int l5 = strtoll(end_char, &end_char, 16);
- long long int l6 = strtoll(end_char, NULL, 16);
-
- printf("%d%d%d%d%d%d\n", l1==0x4, l2==-0x3a, l3==0xdeadbeef, l4==0x4, l5==-0x3a, l6==0xdeadbeef);
- return 0;
- }
- '''
- self.do_run(src, '111111')
+ self.do_run_from_file(src, output)
def test_strtoll_dec(self):
if self.emcc_args is None: return self.skip('requires emcc')
# tests strtoll for decimal strings (0x...)
- src = r'''
- #include <stdio.h>
- #include <stdlib.h>
-
- int main() {
- const char *STRING = "4 -38 +4711";
- char *end_char;
+ test_path = path_from_root('tests', 'core', 'test_strtoll_dec')
+ src, output = (test_path + s for s in ('.in', '.out'))
- // undefined base
- long long int l1 = strtoll(STRING, &end_char, 0);
- long long int l2 = strtoll(end_char, &end_char, 0);
- long long int l3 = strtoll(end_char, NULL, 0);
-
- // defined base
- long long int l4 = strtoll(STRING, &end_char, 10);
- long long int l5 = strtoll(end_char, &end_char, 10);
- long long int l6 = strtoll(end_char, NULL, 10);
-
- printf("%d%d%d%d%d%d\n", l1==4, l2==-38, l3==4711, l4==4, l5==-38, l6==4711);
- return 0;
- }
- '''
- self.do_run(src, '111111')
+ self.do_run_from_file(src, output)
def test_strtoll_bin(self):
if self.emcc_args is None: return self.skip('requires emcc')
# tests strtoll for binary strings (0x...)
- src = r'''
- #include <stdio.h>
- #include <stdlib.h>
-
- int main() {
- const char *STRING = "1 -101 +1011";
- char *end_char;
-
- // defined base
- long long int l4 = strtoll(STRING, &end_char, 2);
- long long int l5 = strtoll(end_char, &end_char, 2);
- long long int l6 = strtoll(end_char, NULL, 2);
+ test_path = path_from_root('tests', 'core', 'test_strtoll_bin')
+ src, output = (test_path + s for s in ('.in', '.out'))
- printf("%d%d%d\n", l4==1, l5==-5, l6==11);
- return 0;
- }
- '''
- self.do_run(src, '111')
+ self.do_run_from_file(src, output)
def test_strtoll_oct(self):
if self.emcc_args is None: return self.skip('requires emcc')
# tests strtoll for decimal strings (0x...)
- src = r'''
- #include <stdio.h>
- #include <stdlib.h>
-
- int main() {
- const char *STRING = "0 -035 +04711";
- char *end_char;
+ test_path = path_from_root('tests', 'core', 'test_strtoll_oct')
+ src, output = (test_path + s for s in ('.in', '.out'))
- // undefined base
- long long int l1 = strtoll(STRING, &end_char, 0);
- long long int l2 = strtoll(end_char, &end_char, 0);
- long long int l3 = strtoll(end_char, NULL, 0);
+ self.do_run_from_file(src, output)
- // defined base
- long long int l4 = strtoll(STRING, &end_char, 8);
- long long int l5 = strtoll(end_char, &end_char, 8);
- long long int l6 = strtoll(end_char, NULL, 8);
-
- printf("%d%d%d%d%d%d\n", l1==0, l2==-29, l3==2505, l4==0, l5==-29, l6==2505);
- return 0;
- }
- '''
- self.do_run(src, '111111')
-
def test_strtol_hex(self):
# tests strtoll for hex strings (0x...)
- src = r'''
- #include <stdio.h>
- #include <stdlib.h>
+ test_path = path_from_root('tests', 'core', 'test_strtol_hex')
+ src, output = (test_path + s for s in ('.in', '.out'))
- int main() {
- const char *STRING = "0x4 -0x3A +0xDEAD";
- char *end_char;
-
- // undefined base
- long l1 = strtol(STRING, &end_char, 0);
- long l2 = strtol(end_char, &end_char, 0);
- long l3 = strtol(end_char, NULL, 0);
-
- // defined base
- long l4 = strtol(STRING, &end_char, 16);
- long l5 = strtol(end_char, &end_char, 16);
- long l6 = strtol(end_char, NULL, 16);
-
- printf("%d%d%d%d%d%d\n", l1==0x4, l2==-0x3a, l3==0xdead, l4==0x4, l5==-0x3a, l6==0xdead);
- return 0;
- }
- '''
- self.do_run(src, '111111')
+ self.do_run_from_file(src, output)
def test_strtol_dec(self):
# tests strtoll for decimal strings (0x...)
- src = r'''
- #include <stdio.h>
- #include <stdlib.h>
-
- int main() {
- const char *STRING = "4 -38 +4711";
- char *end_char;
+ test_path = path_from_root('tests', 'core', 'test_strtol_dec')
+ src, output = (test_path + s for s in ('.in', '.out'))
- // undefined base
- long l1 = strtol(STRING, &end_char, 0);
- long l2 = strtol(end_char, &end_char, 0);
- long l3 = strtol(end_char, NULL, 0);
-
- // defined base
- long l4 = strtol(STRING, &end_char, 10);
- long l5 = strtol(end_char, &end_char, 10);
- long l6 = strtol(end_char, NULL, 10);
-
- printf("%d%d%d%d%d%d\n", l1==4, l2==-38, l3==4711, l4==4, l5==-38, l6==4711);
- return 0;
- }
- '''
- self.do_run(src, '111111')
+ self.do_run_from_file(src, output)
def test_strtol_bin(self):
# tests strtoll for binary strings (0x...)
- src = r'''
- #include <stdio.h>
- #include <stdlib.h>
-
- int main() {
- const char *STRING = "1 -101 +1011";
- char *end_char;
+ test_path = path_from_root('tests', 'core', 'test_strtol_bin')
+ src, output = (test_path + s for s in ('.in', '.out'))
- // defined base
- long l4 = strtol(STRING, &end_char, 2);
- long l5 = strtol(end_char, &end_char, 2);
- long l6 = strtol(end_char, NULL, 2);
-
- printf("%d%d%d\n", l4==1, l5==-5, l6==11);
- return 0;
- }
- '''
- self.do_run(src, '111')
+ self.do_run_from_file(src, output)
def test_strtol_oct(self):
# tests strtoll for decimal strings (0x...)
- src = r'''
- #include <stdio.h>
- #include <stdlib.h>
-
- int main() {
- const char *STRING = "0 -035 +04711";
- char *end_char;
-
- // undefined base
- long l1 = strtol(STRING, &end_char, 0);
- long l2 = strtol(end_char, &end_char, 0);
- long l3 = strtol(end_char, NULL, 0);
+ test_path = path_from_root('tests', 'core', 'test_strtol_oct')
+ src, output = (test_path + s for s in ('.in', '.out'))
- // defined base
- long l4 = strtol(STRING, &end_char, 8);
- long l5 = strtol(end_char, &end_char, 8);
- long l6 = strtol(end_char, NULL, 8);
-
- printf("%d%d%d%d%d%d\n", l1==0, l2==-29, l3==2505, l4==0, l5==-29, l6==2505);
- return 0;
- }
- '''
- self.do_run(src, '111111')
+ self.do_run_from_file(src, output)
def test_atexit(self):
# Confirms they are called in reverse order
- src = r'''
- #include <stdio.h>
- #include <stdlib.h>
+ test_path = path_from_root('tests', 'core', 'test_atexit')
+ src, output = (test_path + s for s in ('.in', '.out'))
- static void cleanA() {
- printf("A");
- }
- static void cleanB() {
- printf("B");
- }
-
- int main() {
- atexit(cleanA);
- atexit(cleanB);
- return 0;
- }
- '''
- self.do_run(src, 'BA')
+ self.do_run_from_file(src, output)
def test_pthread_specific(self):
if self.emcc_args is None: return self.skip('requires emcc')
@@ -4899,344 +2444,46 @@ The current type of b is: 9
def test_timeb(self):
# Confirms they are called in reverse order
- src = r'''
- #include <stdio.h>
- #include <assert.h>
- #include <sys/timeb.h>
+ test_path = path_from_root('tests', 'core', 'test_timeb')
+ src, output = (test_path + s for s in ('.in', '.out'))
- int main() {
- timeb tb;
- tb.timezone = 1;
- printf("*%d\n", ftime(&tb));
- assert(tb.time > 10000);
- assert(tb.timezone == 0);
- assert(tb.dstflag == 0);
- return 0;
- }
- '''
- self.do_run(src, '*0\n')
+ self.do_run_from_file(src, output)
def test_time_c(self):
- src = r'''
- #include <time.h>
- #include <stdio.h>
+ test_path = path_from_root('tests', 'core', 'test_time_c')
+ src, output = (test_path + s for s in ('.in', '.out'))
- int main() {
- time_t t = time(0);
- printf("time: %s\n", ctime(&t));
- }
- '''
- self.do_run(src, 'time: ') # compilation check, mainly
+ self.do_run_from_file(src, output)
def test_gmtime(self):
- src = r'''
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- #include <assert.h>
+ test_path = path_from_root('tests', 'core', 'test_gmtime')
+ src, output = (test_path + s for s in ('.in', '.out'))
- int main(void)
- {
- time_t t=time(NULL);
- struct tm *ptm=gmtime(&t);
- struct tm tmCurrent=*ptm;
- int hour=tmCurrent.tm_hour;
-
- t-=hour*3600; // back to midnight
- int yday = -1;
- for(hour=0;hour<24;hour++)
- {
- ptm=gmtime(&t);
- // tm_yday must be constant all day...
- printf("yday: %d, hour: %d\n", ptm->tm_yday, hour);
- if (yday == -1) yday = ptm->tm_yday;
- else assert(yday == ptm->tm_yday);
- t+=3600; // add one hour
- }
- printf("ok!\n");
- return(0);
- }
- '''
- self.do_run(src, '''ok!''')
+ self.do_run_from_file(src, output)
def test_strptime_tm(self):
- src=r'''
- #include <time.h>
- #include <stdio.h>
- #include <string.h>
+ test_path = path_from_root('tests', 'core', 'test_strptime_tm')
+ src, output = (test_path + s for s in ('.in', '.out'))
- int main() {
- struct tm tm;
- char *ptr = strptime("17410105012000", "%H%M%S%d%m%Y", &tm);
-
- printf("%s: %s, %d/%d/%d %d:%d:%d",
- (ptr != NULL && *ptr=='\0') ? "OK" : "ERR",
- tm.tm_wday == 0 ? "Sun" : (tm.tm_wday == 1 ? "Mon" : (tm.tm_wday == 2 ? "Tue" : (tm.tm_wday == 3 ? "Wed" : (tm.tm_wday == 4 ? "Thu" : (tm.tm_wday == 5 ? "Fri" : (tm.tm_wday == 6 ? "Sat" : "ERR")))))),
- tm.tm_mon+1,
- tm.tm_mday,
- tm.tm_year+1900,
- tm.tm_hour,
- tm.tm_min,
- tm.tm_sec
- );
- }
- '''
- self.do_run(src, 'OK: Wed, 1/5/2000 17:41:1')
+ self.do_run_from_file(src, output)
def test_strptime_days(self):
- src = r'''
- #include <time.h>
- #include <stdio.h>
- #include <string.h>
+ test_path = path_from_root('tests', 'core', 'test_strptime_days')
+ src, output = (test_path + s for s in ('.in', '.out'))
- static const struct {
- const char *input;
- const char *format;
- } day_tests[] = {
- { "2000-01-01", "%Y-%m-%d"},
- { "03/03/00", "%D"},
- { "9/9/99", "%x"},
- { "19990502123412", "%Y%m%d%H%M%S"},
- { "2001 20 Mon", "%Y %U %a"},
- { "2006 4 Fri", "%Y %U %a"},
- { "2001 21 Mon", "%Y %W %a"},
- { "2013 29 Wed", "%Y %W %a"},
- { "2000-01-01 08:12:21 AM", "%Y-%m-%d %I:%M:%S %p"},
- { "2000-01-01 08:12:21 PM", "%Y-%m-%d %I:%M:%S %p"},
- { "2001 17 Tue", "%Y %U %a"},
- { "2001 8 Thursday", "%Y %W %a"},
- };
-
- int main() {
- struct tm tm;
-
- for (int i = 0; i < sizeof (day_tests) / sizeof (day_tests[0]); ++i) {
- memset (&tm, '\0', sizeof (tm));
- char *ptr = strptime(day_tests[i].input, day_tests[i].format, &tm);
-
- printf("%s: %d/%d/%d (%dth DoW, %dth DoY)\n", (ptr != NULL && *ptr=='\0') ? "OK" : "ERR", tm.tm_mon+1, tm.tm_mday, 1900+tm.tm_year, tm.tm_wday, tm.tm_yday);
- }
- }
- '''
- self.do_run(src, 'OK: 1/1/2000 (6th DoW, 0th DoY)\n'\
- 'OK: 3/3/2000 (5th DoW, 62th DoY)\n'\
- 'OK: 9/9/1999 (4th DoW, 251th DoY)\n'\
- 'OK: 5/2/1999 (0th DoW, 121th DoY)\n'\
- 'OK: 5/21/2001 (1th DoW, 140th DoY)\n'\
- 'OK: 1/27/2006 (5th DoW, 26th DoY)\n'\
- 'OK: 5/21/2001 (1th DoW, 140th DoY)\n'\
- 'OK: 7/24/2013 (3th DoW, 204th DoY)\n'\
- 'OK: 1/1/2000 (6th DoW, 0th DoY)\n'\
- 'OK: 1/1/2000 (6th DoW, 0th DoY)\n'\
- 'OK: 5/1/2001 (2th DoW, 120th DoY)\n'\
- 'OK: 2/22/2001 (4th DoW, 52th DoY)\n'\
- )
+ self.do_run_from_file(src, output)
def test_strptime_reentrant(self):
- src=r'''
- #include <time.h>
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
-
- int main () {
- int result = 0;
- struct tm tm;
-
- memset (&tm, 0xaa, sizeof (tm));
-
- /* Test we don't crash on uninitialized struct tm.
- Some fields might contain bogus values until everything
- needed is initialized, but we shouldn't crash. */
- if (strptime ("2007", "%Y", &tm) == NULL
- || strptime ("12", "%d", &tm) == NULL
- || strptime ("Feb", "%b", &tm) == NULL
- || strptime ("13", "%M", &tm) == NULL
- || strptime ("21", "%S", &tm) == NULL
- || strptime ("16", "%H", &tm) == NULL) {
- printf("ERR: returned NULL");
- exit(EXIT_FAILURE);
- }
-
- if (tm.tm_sec != 21 || tm.tm_min != 13 || tm.tm_hour != 16
- || tm.tm_mday != 12 || tm.tm_mon != 1 || tm.tm_year != 107
- || tm.tm_wday != 1 || tm.tm_yday != 42) {
- printf("ERR: unexpected tm content (1) - %d/%d/%d %d:%d:%d", tm.tm_mon+1, tm.tm_mday, tm.tm_year+1900, tm.tm_hour, tm.tm_min, tm.tm_sec);
- exit(EXIT_FAILURE);
- }
-
- if (strptime ("8", "%d", &tm) == NULL) {
- printf("ERR: strptime failed");
- exit(EXIT_FAILURE);
- }
-
- if (tm.tm_sec != 21 || tm.tm_min != 13 || tm.tm_hour != 16
- || tm.tm_mday != 8 || tm.tm_mon != 1 || tm.tm_year != 107
- || tm.tm_wday != 4 || tm.tm_yday != 38) {
- printf("ERR: unexpected tm content (2) - %d/%d/%d %d:%d:%d", tm.tm_mon+1, tm.tm_mday, tm.tm_year+1900, tm.tm_hour, tm.tm_min, tm.tm_sec);
- exit(EXIT_FAILURE);
- }
+ test_path = path_from_root('tests', 'core', 'test_strptime_reentrant')
+ src, output = (test_path + s for s in ('.in', '.out'))
- printf("OK");
- }
- '''
- self.do_run(src, 'OK')
+ self.do_run_from_file(src, output)
def test_strftime(self):
- src=r'''
- #include <time.h>
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
-
- void test(int result, const char* comment, const char* parsed = "") {
- printf("%d",result);
- if (!result) {
- printf("\nERROR: %s (\"%s\")\n", comment, parsed);
- }
- }
-
- int cmp(const char *s1, const char *s2) {
- for ( ; *s1 == *s2 ; s1++,s2++ ) {
- if ( *s1 == '\0' )
- break;
- }
+ test_path = path_from_root('tests', 'core', 'test_strftime')
+ src, output = (test_path + s for s in ('.in', '.out'))
- return (*s1 - *s2);
- }
-
- int main() {
- struct tm tm;
- char s[1000];
- size_t size;
-
- tm.tm_sec = 4;
- tm.tm_min = 23;
- tm.tm_hour = 20;
- tm.tm_mday = 21;
- tm.tm_mon = 1;
- tm.tm_year = 74;
- tm.tm_wday = 4;
- tm.tm_yday = 51;
- tm.tm_isdst = 0;
-
- size = strftime(s, 1000, "", &tm);
- test((size==0) && (*s=='\0'), "strftime test #1", s);
-
- size = strftime(s, 1000, "%a", &tm);
- test((size==3) && !cmp(s, "Thu"), "strftime test #2", s);
-
- size = strftime(s, 1000, "%A", &tm);
- test((size==8) && !cmp(s, "Thursday"), "strftime test #3", s);
-
- size = strftime(s, 1000, "%b", &tm);
- test((size==3) && !cmp(s, "Feb"), "strftime test #4", s);
-
- size = strftime(s, 1000, "%B", &tm);
- test((size==8) && !cmp(s, "February"),
- "strftime test #5", s);
-
- size = strftime(s, 1000, "%d", &tm);
- test((size==2) && !cmp(s, "21"),
- "strftime test #6", s);
-
- size = strftime(s, 1000, "%H", &tm);
- test((size==2) && !cmp(s, "20"),
- "strftime test #7", s);
-
- size = strftime(s, 1000, "%I", &tm);
- test((size==2) && !cmp(s, "08"),
- "strftime test #8", s);
-
- size = strftime(s, 1000, "%j", &tm);
- test((size==3) && !cmp(s, "052"),
- "strftime test #9", s);
-
- size = strftime(s, 1000, "%m", &tm);
- test((size==2) && !cmp(s, "02"),
- "strftime test #10", s);
-
- size = strftime(s, 1000, "%M", &tm);
- test((size==2) && !cmp(s, "23"),
- "strftime test #11", s);
-
- size = strftime(s, 1000, "%p", &tm);
- test((size==2) && !cmp(s, "PM"),
- "strftime test #12", s);
-
- size = strftime(s, 1000, "%S", &tm);
- test((size==2) && !cmp(s, "04"),
- "strftime test #13", s);
-
- size = strftime(s, 1000, "%U", &tm);
- test((size==2) && !cmp(s, "07"),
- "strftime test #14", s);
-
- size = strftime(s, 1000, "%w", &tm);
- test((size==1) && !cmp(s, "4"),
- "strftime test #15", s);
-
- size = strftime(s, 1000, "%W", &tm);
- test((size==2) && !cmp(s, "07"),
- "strftime test #16", s);
-
- size = strftime(s, 1000, "%y", &tm);
- test((size==2) && !cmp(s, "74"),
- "strftime test #17", s);
-
- size = strftime(s, 1000, "%Y", &tm);
- test((size==4) && !cmp(s, "1974"),
- "strftime test #18", s);
-
- size = strftime(s, 1000, "%%", &tm);
- test((size==1) && !cmp(s, "%"),
- "strftime test #19", s);
-
- size = strftime(s, 5, "%Y", &tm);
- test((size==4) && !cmp(s, "1974"),
- "strftime test #20", s);
-
- size = strftime(s, 4, "%Y", &tm);
- test((size==0), "strftime test #21", s);
-
- tm.tm_mon = 0;
- tm.tm_mday = 1;
- size = strftime(s, 10, "%U", &tm);
- test((size==2) && !cmp(s, "00"), "strftime test #22", s);
-
- size = strftime(s, 10, "%W", &tm);
- test((size==2) && !cmp(s, "00"), "strftime test #23", s);
-
- // 1/1/1973 was a Sunday and is in CW 1
- tm.tm_year = 73;
- size = strftime(s, 10, "%W", &tm);
- test((size==2) && !cmp(s, "01"), "strftime test #24", s);
-
- // 1/1/1978 was a Monday and is in CW 1
- tm.tm_year = 78;
- size = strftime(s, 10, "%U", &tm);
- test((size==2) && !cmp(s, "01"), "strftime test #25", s);
-
- // 2/1/1999
- tm.tm_year = 99;
- tm.tm_yday = 1;
- size = strftime(s, 10, "%G (%V)", &tm);
- test((size==9) && !cmp(s, "1998 (53)"), "strftime test #26", s);
-
- size = strftime(s, 10, "%g", &tm);
- test((size==2) && !cmp(s, "98"), "strftime test #27", s);
-
- // 30/12/1997
- tm.tm_year = 97;
- tm.tm_yday = 363;
- size = strftime(s, 10, "%G (%V)", &tm);
- test((size==9) && !cmp(s, "1998 (01)"), "strftime test #28", s);
-
- size = strftime(s, 10, "%g", &tm);
- test((size==2) && !cmp(s, "98"), "strftime test #29", s);
- }
- '''
- self.do_run(src, '11111111111111111111111111111')
+ self.do_run_from_file(src, output)
def test_intentional_fault(self):
# Some programs intentionally segfault themselves, we should compile that into a throw
@@ -5249,33 +2496,10 @@ The current type of b is: 9
self.do_run(src, 'fault on write to 0' if not Settings.ASM_JS else 'abort()')
def test_trickystring(self):
- src = r'''
- #include <stdio.h>
-
- typedef struct
- {
- int (*f)(void *);
- void *d;
- char s[16];
- } LMEXFunctionStruct;
-
- int f(void *user)
- {
- return 0;
- }
-
- static LMEXFunctionStruct const a[] =
- {
- {f, (void *)(int)'a', "aa"}
- };
+ test_path = path_from_root('tests', 'core', 'test_trickystring')
+ src, output = (test_path + s for s in ('.in', '.out'))
- int main()
- {
- printf("ok\n");
- return a[0].f(a[0].d);
- }
- '''
- self.do_run(src, 'ok\n')
+ self.do_run_from_file(src, output)
def test_statics(self):
# static initializers save i16 but load i8 for some reason (or i64 and load i8)
@@ -5283,46 +2507,10 @@ The current type of b is: 9
Settings.SAFE_HEAP = 3
Settings.SAFE_HEAP_LINES = ['src.cpp:19', 'src.cpp:26', 'src.cpp:28']
- src = '''
- #include <stdio.h>
- #include <string.h>
-
- #define CONSTRLEN 32
+ test_path = path_from_root('tests', 'core', 'test_statics')
+ src, output = (test_path + s for s in ('.in', '.out'))
- char * (*func)(char *, const char *) = NULL;
-
- void conoutfv(const char *fmt)
- {
- static char buf[CONSTRLEN];
- func(buf, fmt); // call by function pointer to make sure we test strcpy here
- puts(buf);
- }
-
- struct XYZ {
- float x, y, z;
- XYZ(float a, float b, float c) : x(a), y(b), z(c) { }
- static const XYZ& getIdentity()
- {
- static XYZ iT(1,2,3);
- return iT;
- }
- };
- struct S {
- static const XYZ& getIdentity()
- {
- static const XYZ iT(XYZ::getIdentity());
- return iT;
- }
- };
-
- int main() {
- func = &strcpy;
- conoutfv("*staticccz*");
- printf("*%.2f,%.2f,%.2f*\\n", S::getIdentity().x, S::getIdentity().y, S::getIdentity().z);
- return 0;
- }
- '''
- self.do_run(src, '*staticccz*\n*1.00,2.00,3.00*')
+ self.do_run_from_file(src, output)
def test_copyop(self):
if self.emcc_args is None: return self.skip('requires emcc')
@@ -5331,392 +2519,75 @@ The current type of b is: 9
# memcpy for assignments, with hardcoded numbers of bytes
# (llvm-gcc copies items one by one). See QUANTUM_SIZE in
# settings.js.
- src = '''
- #include <stdio.h>
- #include <math.h>
- #include <string.h>
-
- struct vec {
- double x,y,z;
- vec() : x(0), y(0), z(0) { };
- vec(const double a, const double b, const double c) : x(a), y(b), z(c) { };
- };
-
- struct basis {
- vec a, b, c;
- basis(const vec& v) {
- a=v; // should not touch b!
- printf("*%.2f,%.2f,%.2f*\\n", b.x, b.y, b.z);
- }
- };
+ test_path = path_from_root('tests', 'core', 'test_copyop')
+ src, output = (test_path + s for s in ('.in', '.out'))
- int main() {
- basis B(vec(1,0,0));
-
- // Part 2: similar problem with memset and memmove
- int x = 1, y = 77, z = 2;
- memset((void*)&x, 0, sizeof(int));
- memset((void*)&z, 0, sizeof(int));
- printf("*%d,%d,%d*\\n", x, y, z);
- memcpy((void*)&x, (void*)&z, sizeof(int));
- memcpy((void*)&z, (void*)&x, sizeof(int));
- printf("*%d,%d,%d*\\n", x, y, z);
- memmove((void*)&x, (void*)&z, sizeof(int));
- memmove((void*)&z, (void*)&x, sizeof(int));
- printf("*%d,%d,%d*\\n", x, y, z);
- return 0;
- }
- '''
- self.do_run(src, '*0.00,0.00,0.00*\n*0,77,0*\n*0,77,0*\n*0,77,0*')
+ self.do_run_from_file(src, output)
def test_memcpy_memcmp(self):
- src = '''
- #include <stdio.h>
- #include <string.h>
- #include <assert.h>
+ test_path = path_from_root('tests', 'core', 'test_memcpy_memcmp')
+ src, output = (test_path + s for s in ('.in', '.out'))
- #define MAXX 48
- void reset(unsigned char *buffer) {
- for (int i = 0; i < MAXX; i++) buffer[i] = i+1;
- }
- void dump(unsigned char *buffer) {
- for (int i = 0; i < MAXX-1; i++) printf("%2d,", buffer[i]);
- printf("%d\\n", buffer[MAXX-1]);
- }
- int main() {
- unsigned char buffer[MAXX];
- for (int i = MAXX/4; i < MAXX-MAXX/4; i++) {
- for (int j = MAXX/4; j < MAXX-MAXX/4; j++) {
- for (int k = 1; k < MAXX/4; k++) {
- if (i == j) continue;
- if (i < j && i+k > j) continue;
- if (j < i && j+k > i) continue;
- printf("[%d,%d,%d] ", i, j, k);
- reset(buffer);
- memcpy(buffer+i, buffer+j, k);
- dump(buffer);
- assert(memcmp(buffer+i, buffer+j, k) == 0);
- buffer[i + k/2]++;
- if (buffer[i + k/2] != 0) {
- assert(memcmp(buffer+i, buffer+j, k) > 0);
- } else {
- assert(memcmp(buffer+i, buffer+j, k) < 0);
- }
- buffer[i + k/2]--;
- buffer[j + k/2]++;
- if (buffer[j + k/2] != 0) {
- assert(memcmp(buffer+i, buffer+j, k) < 0);
- } else {
- assert(memcmp(buffer+i, buffer+j, k) > 0);
- }
- }
- }
- }
- return 0;
- }
- '''
def check(result, err):
return hashlib.sha1(result).hexdigest()
- self.do_run(src, '6c9cdfe937383b79e52ca7a2cce83a21d9f5422c',
- output_nicerizer = check)
+
+ self.do_run_from_file(src, output, output_nicerizer = check)
def test_memcpy2(self):
- src = r'''
- #include <stdio.h>
- #include <string.h>
- #include <assert.h>
- int main() {
- char buffer[256];
- for (int i = 0; i < 10; i++) {
- for (int j = 0; j < 10; j++) {
- for (int k = 0; k < 35; k++) {
- for (int t = 0; t < 256; t++) buffer[t] = t;
- char *dest = buffer + i + 128;
- char *src = buffer+j;
- //printf("%d, %d, %d\n", i, j, k);
- assert(memcpy(dest, src, k) == dest);
- assert(memcmp(dest, src, k) == 0);
- }
- }
- }
- printf("ok.\n");
- return 1;
- }
- '''
- self.do_run(src, 'ok.');
+ test_path = path_from_root('tests', 'core', 'test_memcpy2')
+ src, output = (test_path + s for s in ('.in', '.out'))
+
+ self.do_run_from_file(src, output)
def test_getopt(self):
if self.emcc_args is None: return self.skip('needs emcc for libc')
- src = '''
- #pragma clang diagnostic ignored "-Winvalid-pp-token"
- #include <unistd.h>
- #include <stdlib.h>
- #include <stdio.h>
+ test_path = path_from_root('tests', 'core', 'test_getopt')
+ src, output = (test_path + s for s in ('.in', '.out'))
- int
- main(int argc, char *argv[])
- {
- int flags, opt;
- int nsecs, tfnd;
-
- nsecs = 0;
- tfnd = 0;
- flags = 0;
- while ((opt = getopt(argc, argv, "nt:")) != -1) {
- switch (opt) {
- case 'n':
- flags = 1;
- break;
- case 't':
- nsecs = atoi(optarg);
- tfnd = 1;
- break;
- default: /* '?' */
- fprintf(stderr, "Usage: %s [-t nsecs] [-n] name\\n",
- argv[0]);
- exit(EXIT_FAILURE);
- }
- }
-
- printf("flags=%d; tfnd=%d; optind=%d\\n", flags, tfnd, optind);
-
- if (optind >= argc) {
- fprintf(stderr, "Expected argument after options\\n");
- exit(EXIT_FAILURE);
- }
-
- printf("name argument = %s\\n", argv[optind]);
-
- /* Other code omitted */
-
- exit(EXIT_SUCCESS);
- }
- '''
- self.do_run(src, 'flags=1; tfnd=1; optind=4\nname argument = foobar', args=['-t', '12', '-n', 'foobar'])
+ self.do_run_from_file(src, output, args=['-t', '12', '-n', 'foobar'])
def test_getopt_long(self):
if self.emcc_args is None: return self.skip('needs emcc for libc')
- src = '''
- #pragma clang diagnostic ignored "-Winvalid-pp-token"
- #pragma clang diagnostic ignored "-Wdeprecated-writable-strings"
- #include <stdio.h> /* for printf */
- #include <stdlib.h> /* for exit */
- #include <getopt.h>
-
- int
- main(int argc, char **argv)
- {
- int c;
- int digit_optind = 0;
-
- while (1) {
- int this_option_optind = optind ? optind : 1;
- int option_index = 0;
- static struct option long_options[] = {
- {"add", required_argument, 0, 0 },
- {"append", no_argument, 0, 0 },
- {"delete", required_argument, 0, 0 },
- {"verbose", no_argument, 0, 0 },
- {"create", required_argument, 0, 'c'},
- {"file", required_argument, 0, 0 },
- {0, 0, 0, 0 }
- };
-
- c = getopt_long(argc, argv, "abc:d:012",
- long_options, &option_index);
- if (c == -1)
- break;
-
- switch (c) {
- case 0:
- printf("option %s", long_options[option_index].name);
- if (optarg)
- printf(" with arg %s", optarg);
- printf("\\n");
- break;
-
- case '0':
- case '1':
- case '2':
- if (digit_optind != 0 && digit_optind != this_option_optind)
- printf("digits occur in two different argv-elements.\\n");
- digit_optind = this_option_optind;
- printf("option %c\\n", c);
- break;
-
- case 'a':
- printf("option a\\n");
- break;
-
- case 'b':
- printf("option b\\n");
- break;
-
- case 'c':
- printf("option c with value '%s'\\n", optarg);
- break;
-
- case 'd':
- printf("option d with value '%s'\\n", optarg);
- break;
-
- case '?':
- break;
-
- default:
- printf("?? getopt returned character code 0%o ??\\n", c);
- }
- }
-
- if (optind < argc) {
- printf("non-option ARGV-elements: ");
- while (optind < argc)
- printf("%s ", argv[optind++]);
- printf("\\n");
- }
-
- exit(EXIT_SUCCESS);
- }
- '''
- self.do_run(src, 'option file with arg foobar\noption b', args=['--file', 'foobar', '-b'])
+ test_path = path_from_root('tests', 'core', 'test_getopt_long')
+ src, output = (test_path + s for s in ('.in', '.out'))
+
+ self.do_run_from_file(src, output, args=['--file', 'foobar', '-b'])
def test_memmove(self):
- src = '''
- #include <stdio.h>
- #include <string.h>
- int main() {
- char str[] = "memmove can be very useful....!";
- memmove (str+20, str+15, 11);
- puts(str);
- return 0;
- }
- '''
- self.do_run(src, 'memmove can be very very useful')
+ test_path = path_from_root('tests', 'core', 'test_memmove')
+ src, output = (test_path + s for s in ('.in', '.out'))
+
+ self.do_run_from_file(src, output)
def test_memmove2(self):
if Settings.USE_TYPED_ARRAYS != 2: return self.skip('need ta2')
- src = r'''
- #include <stdio.h>
- #include <string.h>
- #include <assert.h>
- int main() {
- int sum = 0;
- char buffer[256];
- for (int i = 0; i < 10; i++) {
- for (int j = 0; j < 10; j++) {
- for (int k = 0; k < 35; k++) {
- for (int t = 0; t < 256; t++) buffer[t] = t;
- char *dest = buffer + i;
- char *src = buffer + j;
- if (dest == src) continue;
- //printf("%d, %d, %d\n", i, j, k);
- assert(memmove(dest, src, k) == dest);
- for (int t = 0; t < 256; t++) sum += buffer[t];
- }
- }
- }
- printf("final: %d.\n", sum);
- return 1;
- }
- '''
- self.do_run(src, 'final: -403200.');
+ test_path = path_from_root('tests', 'core', 'test_memmove2')
+ src, output = (test_path + s for s in ('.in', '.out'))
+
+ self.do_run_from_file(src, output)
def test_memmove3(self):
- src = '''
- #include <stdio.h>
- #include <string.h>
- int main() {
- char str[] = "memmove can be vvery useful....!";
- memmove(str+15, str+16, 17);
- puts(str);
- return 0;
- }
- '''
- self.do_run(src, 'memmove can be very useful....!')
+ test_path = path_from_root('tests', 'core', 'test_memmove3')
+ src, output = (test_path + s for s in ('.in', '.out'))
+
+ self.do_run_from_file(src, output)
def test_flexarray_struct(self):
- src = r'''
-#include <stdint.h>
-#include <stdlib.h>
-#include <stdio.h>
+ test_path = path_from_root('tests', 'core', 'test_flexarray_struct')
+ src, output = (test_path + s for s in ('.in', '.out'))
-typedef struct
-{
- uint16_t length;
- struct
- {
- int32_t int32;
- } value[];
-} Tuple;
-
-int main() {
- Tuple T[10];
- Tuple *t = &T[0];
-
- t->length = 4;
- t->value->int32 = 100;
-
- printf("(%d, %d)\n", t->length, t->value->int32);
- return 0;
-}
-'''
- self.do_run(src, '(4, 100)')
+ self.do_run_from_file(src, output)
def test_bsearch(self):
if Settings.QUANTUM_SIZE == 1: return self.skip('Test cannot work with q1')
- src = '''
- #include <stdlib.h>
- #include <stdio.h>
-
- int cmp(const void* key, const void* member) {
- return *(int *)key - *(int *)member;
- }
-
- void printResult(int* needle, int* haystack, unsigned int len) {
- void *result = bsearch(needle, haystack, len, sizeof(unsigned int), cmp);
-
- if (result == NULL) {
- printf("null\\n");
- } else {
- printf("%d\\n", *(unsigned int *)result);
- }
- }
-
- int main() {
- int a[] = { -2, -1, 0, 6, 7, 9 };
- int b[] = { 0, 1 };
-
- /* Find all keys that exist. */
- for(int i = 0; i < 6; i++) {
- int val = a[i];
-
- printResult(&val, a, 6);
- }
+ test_path = path_from_root('tests', 'core', 'test_bsearch')
+ src, output = (test_path + s for s in ('.in', '.out'))
- /* Keys that are covered by the range of the array but aren't in
- * the array cannot be found.
- */
- int v1 = 3;
- int v2 = 8;
- printResult(&v1, a, 6);
- printResult(&v2, a, 6);
-
- /* Keys outside the range of the array cannot be found. */
- int v3 = -1;
- int v4 = 2;
-
- printResult(&v3, b, 2);
- printResult(&v4, b, 2);
-
- return 0;
- }
- '''
-
- self.do_run(src, '-2\n-1\n0\n6\n7\n9\nnull\nnull\nnull\nnull')
+ self.do_run_from_file(src, output)
def test_nestedstructs(self):
src = '''
@@ -6196,30 +3067,6 @@ def process(filename):
if Settings.USE_TYPED_ARRAYS == 1: return self.skip('Does not work with USE_TYPED_ARRAYS=1')
Settings.DLOPEN_SUPPORT = 1
- src = r'''
-#include <stdio.h>
-#include <dlfcn.h>
-#include <emscripten.h>
-
-int EMSCRIPTEN_KEEPALIVE global = 123;
-
-extern "C" EMSCRIPTEN_KEEPALIVE void foo(int x) {
-printf("%d\n", x);
-}
-
-extern "C" EMSCRIPTEN_KEEPALIVE void repeatable() {
-void* self = dlopen(NULL, RTLD_LAZY);
-int* global_ptr = (int*)dlsym(self, "global");
-void (*foo_ptr)(int) = (void (*)(int))dlsym(self, "foo");
-foo_ptr(*global_ptr);
-dlclose(self);
-}
-
-int main() {
-repeatable();
-repeatable();
-return 0;
-}'''
def post(filename):
with open(filename) as f:
for line in f:
@@ -6231,8 +3078,11 @@ return 0;
table = table[table.find('{'):table.rfind('}')+1]
# ensure there aren't too many globals; we don't want unnamed_addr
assert table.count(',') <= 4
- self.do_run(src, '123\n123', post_build=(None, post))
+ test_path = path_from_root('tests', 'core', 'test_dlfcn_self')
+ src, output = (test_path + s for s in ('.in', '.out'))
+
+ self.do_run_from_file(src, output, post_build=(None, post))
def test_dlfcn_unique_sig(self):
if not self.can_dlfcn(): return
@@ -6711,61 +3561,10 @@ ok
self.do_run(src.replace('strtod', 'strtold'), re.sub(r'\n\s+', '\n', expected)) # XXX add real support for long double
def test_strtok(self):
- src = r'''
- #include<stdio.h>
- #include<string.h>
-
- int main() {
- char test[80], blah[80];
- char *sep = "\\/:;=-";
- char *word, *phrase, *brkt, *brkb;
+ test_path = path_from_root('tests', 'core', 'test_strtok')
+ src, output = (test_path + s for s in ('.in', '.out'))
- strcpy(test, "This;is.a:test:of=the/string\\tokenizer-function.");
-
- for (word = strtok_r(test, sep, &brkt); word; word = strtok_r(NULL, sep, &brkt)) {
- strcpy(blah, "blah:blat:blab:blag");
- for (phrase = strtok_r(blah, sep, &brkb); phrase; phrase = strtok_r(NULL, sep, &brkb)) {
- printf("at %s:%s\n", word, phrase);
- }
- }
- return 0;
- }
- '''
-
- expected = '''at This:blah
-at This:blat
-at This:blab
-at This:blag
-at is.a:blah
-at is.a:blat
-at is.a:blab
-at is.a:blag
-at test:blah
-at test:blat
-at test:blab
-at test:blag
-at of:blah
-at of:blat
-at of:blab
-at of:blag
-at the:blah
-at the:blat
-at the:blab
-at the:blag
-at string:blah
-at string:blat
-at string:blab
-at string:blag
-at tokenizer:blah
-at tokenizer:blat
-at tokenizer:blab
-at tokenizer:blag
-at function.:blah
-at function.:blat
-at function.:blab
-at function.:blag
-'''
- self.do_run(src, expected)
+ self.do_run_from_file(src, output)
def test_parseInt(self):
if Settings.USE_TYPED_ARRAYS != 2: return self.skip('i64 mode 1 requires ta2')
@@ -6775,20 +3574,10 @@ at function.:blag
self.do_run(src, expected)
def test_transtrcase(self):
- src = '''
- #include <stdio.h>
- #include <string.h>
- int main() {
- char szToupr[] = "hello, ";
- char szTolwr[] = "EMSCRIPTEN";
- strupr(szToupr);
- strlwr(szTolwr);
- printf(szToupr);
- printf(szTolwr);
- return 0;
- }
- '''
- self.do_run(src, 'HELLO, emscripten')
+ test_path = path_from_root('tests', 'core', 'test_transtrcase')
+ src, output = (test_path + s for s in ('.in', '.out'))
+
+ self.do_run_from_file(src, output)
def test_printf(self):
if Settings.USE_TYPED_ARRAYS != 2: return self.skip('i64 mode 1 requires ta2')
@@ -6799,350 +3588,58 @@ at function.:blag
self.do_run(src, expected)
def test_printf_2(self):
- src = r'''
- #include <stdio.h>
+ test_path = path_from_root('tests', 'core', 'test_printf_2')
+ src, output = (test_path + s for s in ('.in', '.out'))
- int main() {
- char c = '1';
- short s = 2;
- int i = 3;
- long long l = 4;
- float f = 5.5;
- double d = 6.6;
-
- printf("%c,%hd,%d,%lld,%.1f,%.1llf\n", c, s, i, l, f, d);
- printf("%#x,%#x\n", 1, 0);
-
- return 0;
- }
- '''
- self.do_run(src, '1,2,3,4,5.5,6.6\n0x1,0\n')
+ self.do_run_from_file(src, output)
def test_vprintf(self):
- src = r'''
- #include <stdio.h>
- #include <stdarg.h>
-
- void print(char* format, ...) {
- va_list args;
- va_start (args, format);
- vprintf (format, args);
- va_end (args);
- }
+ test_path = path_from_root('tests', 'core', 'test_vprintf')
+ src, output = (test_path + s for s in ('.in', '.out'))
- int main () {
- print("Call with %d variable argument.\n", 1);
- print("Call with %d variable %s.\n", 2, "arguments");
-
- return 0;
- }
- '''
- expected = '''
- Call with 1 variable argument.
- Call with 2 variable arguments.
- '''
- self.do_run(src, re.sub('(^|\n)\s+', '\\1', expected))
+ self.do_run_from_file(src, output)
def test_vsnprintf(self):
if self.emcc_args is None: return self.skip('needs i64 math')
- src = r'''
- #include <stdio.h>
- #include <stdarg.h>
- #include <stdint.h>
-
- void printy(const char *f, ...)
- {
- char buffer[256];
- va_list args;
- va_start(args, f);
- vsnprintf(buffer, 256, f, args);
- puts(buffer);
- va_end(args);
- }
-
- int main(int argc, char **argv) {
- int64_t x = argc - 1;
- int64_t y = argc - 1 + 0x400000;
- if (x % 3 == 2) y *= 2;
-
- printy("0x%llx_0x%llx", x, y);
- printy("0x%llx_0x%llx", x, x);
- printy("0x%llx_0x%llx", y, x);
- printy("0x%llx_0x%llx", y, y);
-
- {
- uint64_t A = 0x800000;
- uint64_t B = 0x800000000000ULL;
- printy("0x%llx_0x%llx", A, B);
- }
- {
- uint64_t A = 0x800;
- uint64_t B = 0x12340000000000ULL;
- printy("0x%llx_0x%llx", A, B);
- }
- {
- uint64_t A = 0x000009182746756;
- uint64_t B = 0x192837465631ACBDULL;
- printy("0x%llx_0x%llx", A, B);
- }
+ test_path = path_from_root('tests', 'core', 'test_vsnprintf')
+ src, output = (test_path + s for s in ('.in', '.out'))
- return 0;
- }
- '''
- self.do_run(src, '''0x0_0x400000
-0x0_0x0
-0x400000_0x0
-0x400000_0x400000
-0x800000_0x800000000000
-0x800_0x12340000000000
-0x9182746756_0x192837465631acbd
-''')
+ self.do_run_from_file(src, output)
def test_printf_more(self):
- src = r'''
- #include <stdio.h>
- int main() {
- int size = snprintf(NULL, 0, "%s %d %.2f\n", "me and myself", 25, 1.345);
- char buf[size];
- snprintf(buf, size, "%s %d %.2f\n", "me and myself", 25, 1.345);
- printf("%d : %s\n", size, buf);
- char *buff = NULL;
- asprintf(&buff, "%d waka %d\n", 21, 95);
- puts(buff);
- return 0;
- }
- '''
- self.do_run(src, '22 : me and myself 25 1.34\n21 waka 95\n')
+ test_path = path_from_root('tests', 'core', 'test_printf_more')
+ src, output = (test_path + s for s in ('.in', '.out'))
+
+ self.do_run_from_file(src, output)
def test_perrar(self):
- src = r'''
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <fcntl.h>
- #include <stdio.h>
+ test_path = path_from_root('tests', 'core', 'test_perrar')
+ src, output = (test_path + s for s in ('.in', '.out'))
- int main( int argc, char** argv ){
- int retval = open( "NonExistingFile", O_RDONLY );
- if( retval == -1 )
- perror( "Cannot open NonExistingFile" );
- return 0;
- }
- '''
- self.do_run(src, 'Cannot open NonExistingFile: No such file or directory\n')
+ self.do_run_from_file(src, output)
def test_atoX(self):
if self.emcc_args is None: return self.skip('requires ta2')
- src = r'''
- #include <stdio.h>
- #include <stdlib.h>
+ test_path = path_from_root('tests', 'core', 'test_atoX')
+ src, output = (test_path + s for s in ('.in', '.out'))
- int main () {
- printf("%d*", atoi(""));
- printf("%d*", atoi("a"));
- printf("%d*", atoi(" b"));
- printf("%d*", atoi(" c "));
- printf("%d*", atoi("6"));
- printf("%d*", atoi(" 5"));
- printf("%d*", atoi("4 "));
- printf("%d*", atoi("3 6"));
- printf("%d*", atoi(" 3 7"));
- printf("%d*", atoi("9 d"));
- printf("%d\n", atoi(" 8 e"));
- printf("%d*", atol(""));
- printf("%d*", atol("a"));
- printf("%d*", atol(" b"));
- printf("%d*", atol(" c "));
- printf("%d*", atol("6"));
- printf("%d*", atol(" 5"));
- printf("%d*", atol("4 "));
- printf("%d*", atol("3 6"));
- printf("%d*", atol(" 3 7"));
- printf("%d*", atol("9 d"));
- printf("%d\n", atol(" 8 e"));
- printf("%lld*", atoll("6294967296"));
- printf("%lld*", atoll(""));
- printf("%lld*", atoll("a"));
- printf("%lld*", atoll(" b"));
- printf("%lld*", atoll(" c "));
- printf("%lld*", atoll("6"));
- printf("%lld*", atoll(" 5"));
- printf("%lld*", atoll("4 "));
- printf("%lld*", atoll("3 6"));
- printf("%lld*", atoll(" 3 7"));
- printf("%lld*", atoll("9 d"));
- printf("%lld\n", atoll(" 8 e"));
- return 0;
- }
- '''
- self.do_run(src, '0*0*0*0*6*5*4*3*3*9*8\n0*0*0*0*6*5*4*3*3*9*8\n6294967296*0*0*0*0*6*5*4*3*3*9*8\n')
+ self.do_run_from_file(src, output)
def test_strstr(self):
- src = r'''
- #include <stdio.h>
- #include <string.h>
+ test_path = path_from_root('tests', 'core', 'test_strstr')
+ src, output = (test_path + s for s in ('.in', '.out'))
- int main()
- {
- printf("%d\n", !!strstr("\\n", "\\n"));
- printf("%d\n", !!strstr("cheezy", "ez"));
- printf("%d\n", !!strstr("cheeezy", "ez"));
- printf("%d\n", !!strstr("cheeeeeeeeeezy", "ez"));
- printf("%d\n", !!strstr("cheeeeeeeeee1zy", "ez"));
- printf("%d\n", !!strstr("che1ezy", "ez"));
- printf("%d\n", !!strstr("che1ezy", "che"));
- printf("%d\n", !!strstr("ce1ezy", "che"));
- printf("%d\n", !!strstr("ce1ezy", "ezy"));
- printf("%d\n", !!strstr("ce1ezyt", "ezy"));
- printf("%d\n", !!strstr("ce1ez1y", "ezy"));
- printf("%d\n", !!strstr("cheezy", "a"));
- printf("%d\n", !!strstr("cheezy", "b"));
- printf("%d\n", !!strstr("cheezy", "c"));
- printf("%d\n", !!strstr("cheezy", "d"));
- printf("%d\n", !!strstr("cheezy", "g"));
- printf("%d\n", !!strstr("cheezy", "h"));
- printf("%d\n", !!strstr("cheezy", "i"));
- printf("%d\n", !!strstr("cheezy", "e"));
- printf("%d\n", !!strstr("cheezy", "x"));
- printf("%d\n", !!strstr("cheezy", "y"));
- printf("%d\n", !!strstr("cheezy", "z"));
- printf("%d\n", !!strstr("cheezy", "_"));
-
- const char *str = "a big string";
- printf("%d\n", strstr(str, "big") - str);
- return 0;
- }
- '''
- self.do_run(src, '''1
-1
-1
-1
-0
-1
-1
-0
-1
-1
-0
-0
-0
-1
-0
-0
-1
-0
-1
-0
-1
-1
-0
-2
-''')
+ self.do_run_from_file(src, output)
def test_sscanf(self):
if self.emcc_args is None: return self.skip('needs emcc for libc')
- src = r'''
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
-
- int main () {
- #define CHECK(str) \
- { \
- char name[1000]; \
- memset(name, 0, 1000); \
- int prio = 99; \
- sscanf(str, "%s %d", name, &prio); \
- printf("%s : %d\n", name, prio); \
- }
- CHECK("en-us 2");
- CHECK("en-r");
- CHECK("en 3");
+ test_path = path_from_root('tests', 'core', 'test_sscanf')
+ src, output = (test_path + s for s in ('.in', '.out'))
- printf("%f, %f\n", atof("1.234567"), atof("cheez"));
-
- char float_formats[] = "fegE";
- char format[] = "%_";
- for(int i = 0; i < 4; ++i) {
- format[1] = float_formats[i];
-
- float n = -1;
- sscanf(" 2.8208", format, &n);
- printf("%.4f\n", n);
-
- float a = -1;
- sscanf("-3.03", format, &a);
- printf("%.4f\n", a);
- }
-
- char buffy[100];
- sscanf("cheez some thing moar 123\nyet more\n", "cheez %s", buffy);
- printf("|%s|\n", buffy);
- sscanf("cheez something\nmoar 123\nyet more\n", "cheez %s", buffy);
- printf("|%s|\n", buffy);
- sscanf("cheez somethingmoar\tyet more\n", "cheez %s", buffy);
- printf("|%s|\n", buffy);
-
- int numverts = -1;
- printf("%d\n", sscanf(" numverts 1499\n", " numverts %d", &numverts)); // white space is the same, even if tab vs space
- printf("%d\n", numverts);
-
- int index;
- float u, v;
- short start, count;
- printf("%d\n", sscanf(" vert 87 ( 0.481565 0.059481 ) 0 1\n", " vert %d ( %f %f ) %hu %hu", &index, &u, &v, &start, &count));
- printf("%d,%.6f,%.6f,%hu,%hu\n", index, u, v, start, count);
-
- int neg, neg2, neg3 = 0;
- printf("%d\n", sscanf("-123 -765 -34-6", "%d %u %d", &neg, &neg2, &neg3));
- printf("%d,%u,%d\n", neg, neg2, neg3);
-
- {
- int a = 0;
- sscanf("1", "%i", &a);
- printf("%i\n", a);
- }
-
- char buf1[100], buf2[100], buf3[100], buf4[100];
-
- int numItems = sscanf("level=4:ref=3", "%255[^:=]=%255[^:]:%255[^=]=%255c", buf1, buf2, buf3, buf4);
- printf("%d, %s, %s, %s, %s\n", numItems, buf1, buf2, buf3, buf4);
-
- numItems = sscanf("def|456", "%[a-z]|%[0-9]", buf1, buf2);
- printf("%d, %s, %s\n", numItems, buf1, buf2);
-
- numItems = sscanf("3-4,-ab", "%[-0-9],%[ab-z-]", buf1, buf2);
- printf("%d, %s, %s\n", numItems, buf1, buf2);
-
- numItems = sscanf("Hello,World", "%[A-Za-z],%[^0-9]", buf1, buf2);
- printf("%d, %s, %s\n", numItems, buf1, buf2);
-
- numItems = sscanf("Hello4711", "%[^0-9],%[^0-9]", buf1, buf2);
- printf("%d, %s\n", numItems, buf1);
-
- numItems = sscanf("JavaScript", "%4[A-Za-z]", buf1);
- printf("%d, %s\n", numItems, buf1);
-
- numItems = sscanf("[]", "%1[[]%1[]]", buf1, buf2);
- printf("%d, %s, %s\n", numItems, buf1, buf2);
-
- return 0;
- }
- '''
- self.do_run(src, 'en-us : 2\nen-r : 99\nen : 3\n1.234567, 0.000000\n2.8208\n-3.0300\n2.8208\n-3.0300\n2.8208\n-3.0300\n2.8208\n-3.0300\n|some|\n|something|\n|somethingmoar|\n' +
- '1\n1499\n' +
- '5\n87,0.481565,0.059481,0,1\n' +
- '3\n-123,4294966531,-34\n' +
- '1\n' +
- '4, level, 4, ref, 3\n' +
- '2, def, 456\n' +
- '2, 3-4, -ab\n' +
- '2, Hello, World\n' +
- '1, Hello\n' +
- '1, Java\n' +
- '2, [, ]')
+ self.do_run_from_file(src, output)
def test_sscanf_2(self):
# doubles
@@ -7201,226 +3698,77 @@ Pass: 0.000012 0.000012
Pass: 0.000012 0.000012''')
def test_sscanf_n(self):
- src = r'''
- #include<stdio.h>
- int main() {
- char *line = "version 1.0";
- int i, l, lineno;
- char word[80];
- if (sscanf(line, "%s%n", word, &l) != 1) {
- printf("Header format error, line %d\n", lineno);
- }
- printf("[DEBUG] word 1: %s, l: %d\n", word, l);
+ test_path = path_from_root('tests', 'core', 'test_sscanf_n')
+ src, output = (test_path + s for s in ('.in', '.out'))
- int x = sscanf("one %n two", "%s %n", word, &l);
- printf("%d,%s,%d\n", x, word, l);
- {
- int a, b, c, count;
- count = sscanf("12345 6789", "%d %n%d", &a, &b, &c);
- printf("%i %i %i %i\n", count, a, b, c);
- }
- return 0;
- }
- '''
- self.do_run(src, '''[DEBUG] word 1: version, l: 7\n1,one,4\n2 12345 6 6789\n''')
+ self.do_run_from_file(src, output)
def test_sscanf_whitespace(self):
- src = r'''
- #include<stdio.h>
-
- int main() {
- short int x;
- short int y;
-
- const char* buffer[] = {
- "173,16",
- " 16,173",
- "183, 173",
- " 17, 287",
- " 98, 123, "
- };
+ test_path = path_from_root('tests', 'core', 'test_sscanf_whitespace')
+ src, output = (test_path + s for s in ('.in', '.out'))
- for (int i=0; i<5; ++i) {
- sscanf(buffer[i], "%hd,%hd", &x, &y);
- printf("%d:%d,%d ", i, x, y);
- }
-
- return 0;
- }
- '''
- self.do_run(src, '''0:173,16 1:16,173 2:183,173 3:17,287 4:98,123''')
+ self.do_run_from_file(src, output)
def test_sscanf_other_whitespace(self):
Settings.SAFE_HEAP = 0 # use i16s in printf
- src = r'''
- #include<stdio.h>
+ test_path = path_from_root('tests', 'core', 'test_sscanf_other_whitespace')
+ src, output = (test_path + s for s in ('.in', '.out'))
- int main() {
- short int x;
- short int y;
-
- const char* buffer[] = {
- "\t2\t3\t", /* TAB - horizontal tab */
- "\t\t5\t\t7\t\t",
- "\n11\n13\n", /* LF - line feed */
- "\n\n17\n\n19\n\n",
- "\v23\v29\v", /* VT - vertical tab */
- "\v\v31\v\v37\v\v",
- "\f41\f43\f", /* FF - form feed */
- "\f\f47\f\f53\f\f",
- "\r59\r61\r", /* CR - carrage return */
- "\r\r67\r\r71\r\r"
- };
-
- for (int i=0; i<10; ++i) {
- x = 0; y = 0;
- sscanf(buffer[i], " %d %d ", &x, &y);
- printf("%d, %d, ", x, y);
- }
-
- return 0;
- }
- '''
- self.do_run(src, '''2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, ''')
+ self.do_run_from_file(src, output)
def test_sscanf_3(self):
# i64
if not Settings.USE_TYPED_ARRAYS == 2: return self.skip('64-bit sscanf only supported in ta2')
- src = r'''
- #include <stdint.h>
- #include <stdio.h>
-
- int main(){
-
- int64_t s, m, l;
- printf("%d\n", sscanf("123 1073741823 1125899906842620", "%lld %lld %lld", &s, &m, &l));
- printf("%lld,%lld,%lld\n", s, m, l);
-
- int64_t negS, negM, negL;
- printf("%d\n", sscanf("-123 -1073741823 -1125899906842620", "%lld %lld %lld", &negS, &negM, &negL));
- printf("%lld,%lld,%lld\n", negS, negM, negL);
- return 0;
- }
- '''
+ test_path = path_from_root('tests', 'core', 'test_sscanf_3')
+ src, output = (test_path + s for s in ('.in', '.out'))
- self.do_run(src, '3\n123,1073741823,1125899906842620\n' +
- '3\n-123,-1073741823,-1125899906842620\n')
+ self.do_run_from_file(src, output)
def test_sscanf_4(self):
- src = r'''
- #include <stdio.h>
+ test_path = path_from_root('tests', 'core', 'test_sscanf_4')
+ src, output = (test_path + s for s in ('.in', '.out'))
- int main()
- {
- char pYear[16], pMonth[16], pDay[16], pDate[64];
- printf("%d\n", sscanf("Nov 19 2012", "%s%s%s", pMonth, pDay, pYear));
- printf("day %s, month %s, year %s \n", pDay, pMonth, pYear);
- return(0);
- }
- '''
- self.do_run(src, '3\nday 19, month Nov, year 2012');
+ self.do_run_from_file(src, output)
def test_sscanf_5(self):
- src = r'''
- #include "stdio.h"
+ test_path = path_from_root('tests', 'core', 'test_sscanf_5')
+ src, output = (test_path + s for s in ('.in', '.out'))
- static const char *colors[] = {
- " c black",
- ". c #001100",
- "X c #111100"
- };
-
- int main(){
- unsigned char code;
- char color[32];
- int rcode;
- for(int i = 0; i < 3; i++) {
- rcode = sscanf(colors[i], "%c c %s", &code, color);
- printf("%i, %c, %s\n", rcode, code, color);
- }
- }
- '''
- self.do_run(src, '2, , black\n2, ., #001100\n2, X, #111100');
+ self.do_run_from_file(src, output)
def test_sscanf_6(self):
- src = r'''
- #include <stdio.h>
- #include <string.h>
- int main()
- {
- char *date = "18.07.2013w";
- char c[10];
- memset(c, 0, 10);
- int y, m, d, i;
- i = sscanf(date, "%d.%d.%4d%c", &d, &m, &y, c);
- printf("date: %s; day %2d, month %2d, year %4d, extra: %c, %d\n", date, d, m, y, c[0], i);
- i = sscanf(date, "%d.%d.%3c", &d, &m, c);
- printf("date: %s; day %2d, month %2d, year %4d, extra: %s, %d\n", date, d, m, y, c, i);
- }
- '''
- self.do_run(src, '''date: 18.07.2013w; day 18, month 7, year 2013, extra: w, 4
-date: 18.07.2013w; day 18, month 7, year 2013, extra: 201, 3
-''');
+ test_path = path_from_root('tests', 'core', 'test_sscanf_6')
+ src, output = (test_path + s for s in ('.in', '.out'))
+
+ self.do_run_from_file(src, output)
def test_sscanf_skip(self):
if Settings.USE_TYPED_ARRAYS != 2: return self.skip("need ta2 for full i64")
- src = r'''
- #include <stdint.h>
- #include <stdio.h>
-
- int main(){
- int val1;
- printf("%d\n", sscanf("10 20 30 40", "%*lld %*d %d", &val1));
- printf("%d\n", val1);
+ test_path = path_from_root('tests', 'core', 'test_sscanf_skip')
+ src, output = (test_path + s for s in ('.in', '.out'))
- int64_t large, val2;
- printf("%d\n", sscanf("1000000 -1125899906842620 -123 -1073741823", "%lld %*lld %ld %*d", &large, &val2));
- printf("%lld,%d\n", large, val2);
-
- return 0;
- }
- '''
- self.do_run(src, '1\n30\n2\n1000000,-123\n')
+ self.do_run_from_file(src, output)
def test_sscanf_caps(self):
- src = r'''
- #include "stdio.h"
+ test_path = path_from_root('tests', 'core', 'test_sscanf_caps')
+ src, output = (test_path + s for s in ('.in', '.out'))
- int main(){
- unsigned int a;
- float e, f, g;
- sscanf("a 1.1 1.1 1.1", "%X %E %F %G", &a, &e, &f, &g);
- printf("%d %.1F %.1F %.1F\n", a, e, f, g);
- }
- '''
- self.do_run(src, '10 1.1 1.1 1.1');
+ self.do_run_from_file(src, output)
def test_sscanf_hex(self):
- src = r'''
- #include "stdio.h"
+ test_path = path_from_root('tests', 'core', 'test_sscanf_hex')
+ src, output = (test_path + s for s in ('.in', '.out'))
- int main(){
- unsigned int a, b;
- sscanf("0x12AB 12AB", "%x %x", &a, &b);
- printf("%d %d\n", a, b);
- }
- '''
- self.do_run(src, '4779 4779')
+ self.do_run_from_file(src, output)
def test_sscanf_float(self):
- src = r'''
- #include "stdio.h"
+ test_path = path_from_root('tests', 'core', 'test_sscanf_float')
+ src, output = (test_path + s for s in ('.in', '.out'))
- int main(){
- float f1, f2, f3, f4, f5, f6, f7, f8, f9;
- sscanf("0.512 0.250x5.129_-9.98 1.12*+54.32E3 +54.32E3^87.5E-3 87.5E-3$", "%f %fx%f_%f %f*%f %f^%f %f$", &f1, &f2, &f3, &f4, &f5, &f6, &f7, &f8, &f9);
- printf("\n%f, %f, %f, %f, %f, %f, %f, %f, %f\n", f1, f2, f3, f4, f5, f6, f7, f8, f9);
- }
- '''
- self.do_run(src, '\n0.512000, 0.250000, 5.129000, -9.980000, 1.120000, 54320.000000, 54320.000000, 0.087500, 0.087500\n')
+ self.do_run_from_file(src, output)
def test_langinfo(self):
src = open(path_from_root('tests', 'langinfo', 'test.c'), 'r').read()
@@ -7499,28 +3847,10 @@ def process(filename):
self.do_run(src, ('got: 35\ngot: 45\ngot: 25\ngot: 15\nisatty? 0,0,1\n', 'isatty? 0,0,1\ngot: 35\ngot: 45\ngot: 25\ngot: 15\n'), post_build=post)
def test_fwrite_0(self):
- src = r'''
- #include <stdio.h>
- #include <stdlib.h>
-
- int main ()
- {
- FILE *fh;
-
- fh = fopen("a.txt", "wb");
- if (!fh) exit(1);
- fclose(fh);
+ test_path = path_from_root('tests', 'core', 'test_fwrite_0')
+ src, output = (test_path + s for s in ('.in', '.out'))
- fh = fopen("a.txt", "rb");
- if (!fh) exit(1);
-
- char data[] = "foobar";
- size_t written = fwrite(data, 1, sizeof(data), fh);
-
- printf("written=%zu\n", written);
- }
- '''
- self.do_run(src, 'written=0')
+ self.do_run_from_file(src, output)
def test_fgetc_ungetc(self):
src = open(path_from_root('tests', 'stdio', 'test_fgetc_ungetc.c'), 'r').read()
@@ -7651,145 +3981,22 @@ def process(filename):
)
open(filename, 'w').write(src)
'''
- src = r'''
- #include <stdio.h>
- #include <errno.h>
- #include <fcntl.h>
- #include <poll.h>
+ test_path = path_from_root('tests', 'core', 'test_poll')
+ src, output = (test_path + s for s in ('.in', '.out'))
- int main() {
- struct pollfd multi[5];
- multi[0].fd = open("/file", O_RDONLY, 0777);
- multi[1].fd = open("/device", O_RDONLY, 0777);
- multi[2].fd = 123;
- multi[3].fd = open("/file", O_RDONLY, 0777);
- multi[4].fd = open("/file", O_RDONLY, 0777);
- multi[0].events = POLLIN | POLLOUT | POLLNVAL | POLLERR;
- multi[1].events = POLLIN | POLLOUT | POLLNVAL | POLLERR;
- multi[2].events = POLLIN | POLLOUT | POLLNVAL | POLLERR;
- multi[3].events = 0x00;
- multi[4].events = POLLOUT | POLLNVAL | POLLERR;
-
- printf("ret: %d\n", poll(multi, 5, 123));
- printf("errno: %d\n", errno);
- printf("multi[0].revents: %d\n", multi[0].revents == (POLLIN | POLLOUT));
- printf("multi[1].revents: %d\n", multi[1].revents == (POLLIN | POLLOUT));
- printf("multi[2].revents: %d\n", multi[2].revents == POLLNVAL);
- printf("multi[3].revents: %d\n", multi[3].revents == 0);
- printf("multi[4].revents: %d\n", multi[4].revents == POLLOUT);
-
- return 0;
- }
- '''
- expected = r'''
- ret: 4
- errno: 0
- multi[0].revents: 1
- multi[1].revents: 1
- multi[2].revents: 1
- multi[3].revents: 1
- multi[4].revents: 1
- '''
- self.do_run(src, re.sub('(^|\n)\s+', '\\1', expected), post_build=add_pre_run, extra_emscripten_args=['-H', 'libc/fcntl.h,poll.h'])
+ self.do_run_from_file(src, output, post_build=add_pre_run, extra_emscripten_args=['-H', 'libc/fcntl.h,poll.h'])
def test_statvfs(self):
- src = r'''
- #include <stdio.h>
- #include <errno.h>
- #include <sys/statvfs.h>
+ test_path = path_from_root('tests', 'core', 'test_statvfs')
+ src, output = (test_path + s for s in ('.in', '.out'))
- int main() {
- struct statvfs s;
-
- printf("result: %d\n", statvfs("/test", &s));
- printf("errno: %d\n", errno);
-
- printf("f_bsize: %lu\n", s.f_bsize);
- printf("f_frsize: %lu\n", s.f_frsize);
- printf("f_blocks: %lu\n", s.f_blocks);
- printf("f_bfree: %lu\n", s.f_bfree);
- printf("f_bavail: %lu\n", s.f_bavail);
- printf("f_files: %d\n", s.f_files > 5);
- printf("f_ffree: %lu\n", s.f_ffree);
- printf("f_favail: %lu\n", s.f_favail);
- printf("f_fsid: %lu\n", s.f_fsid);
- printf("f_flag: %lu\n", s.f_flag);
- printf("f_namemax: %lu\n", s.f_namemax);
-
- return 0;
- }
- '''
- expected = r'''
- result: 0
- errno: 0
- f_bsize: 4096
- f_frsize: 4096
- f_blocks: 1000000
- f_bfree: 500000
- f_bavail: 500000
- f_files: 1
- f_ffree: 1000000
- f_favail: 1000000
- f_fsid: 42
- f_flag: 2
- f_namemax: 255
- '''
- self.do_run(src, re.sub('(^|\n)\s+', '\\1', expected))
+ self.do_run_from_file(src, output)
def test_libgen(self):
- src = r'''
- #include <stdio.h>
- #include <libgen.h>
-
- int main() {
- char p1[16] = "/usr/lib", p1x[16] = "/usr/lib";
- printf("%s -> ", p1);
- printf("%s : %s\n", dirname(p1x), basename(p1));
-
- char p2[16] = "/usr", p2x[16] = "/usr";
- printf("%s -> ", p2);
- printf("%s : %s\n", dirname(p2x), basename(p2));
-
- char p3[16] = "/usr/", p3x[16] = "/usr/";
- printf("%s -> ", p3);
- printf("%s : %s\n", dirname(p3x), basename(p3));
+ test_path = path_from_root('tests', 'core', 'test_libgen')
+ src, output = (test_path + s for s in ('.in', '.out'))
- char p4[16] = "/usr/lib///", p4x[16] = "/usr/lib///";
- printf("%s -> ", p4);
- printf("%s : %s\n", dirname(p4x), basename(p4));
-
- char p5[16] = "/", p5x[16] = "/";
- printf("%s -> ", p5);
- printf("%s : %s\n", dirname(p5x), basename(p5));
-
- char p6[16] = "///", p6x[16] = "///";
- printf("%s -> ", p6);
- printf("%s : %s\n", dirname(p6x), basename(p6));
-
- char p7[16] = "/usr/../lib/..", p7x[16] = "/usr/../lib/..";
- printf("%s -> ", p7);
- printf("%s : %s\n", dirname(p7x), basename(p7));
-
- char p8[16] = "", p8x[16] = "";
- printf("(empty) -> %s : %s\n", dirname(p8x), basename(p8));
-
- printf("(null) -> %s : %s\n", dirname(0), basename(0));
-
- return 0;
- }
- '''
- expected = '''
- /usr/lib -> /usr : lib
- /usr -> / : usr
- /usr/ -> / : usr
- /usr/lib/// -> /usr : lib
- / -> / : /
- /// -> / : /
- /usr/../lib/.. -> /usr/../lib : ..
- (empty) -> . : .
- (null) -> . : .
- '''
- self.do_run(src, re.sub('(^|\n)\s+', '\\1', expected))
+ self.do_run_from_file(src, output)
def test_utime(self):
src = open(path_from_root('tests', 'utime', 'test_utime.c'), 'r').read()
@@ -7799,20 +4006,10 @@ def process(filename):
self.banned_js_engines = [SPIDERMONKEY_ENGINE] # only node handles utf well
Settings.EXPORTED_FUNCTIONS = ['_main', '_malloc']
- src = r'''
- #include <stdio.h>
- #include <emscripten.h>
+ test_path = path_from_root('tests', 'core', 'test_utf')
+ src, output = (test_path + s for s in ('.in', '.out'))
- int main() {
- char *c = "μ†ℱ ╋ℯ╳╋ 😇";
- printf("%d %d %d %d %s\n", c[0]&0xff, c[1]&0xff, c[2]&0xff, c[3]&0xff, c);
- emscripten_run_script(
- "cheez = _malloc(100);"
- "Module.writeStringToMemory(\"μ†ℱ ╋ℯ╳╋ 😇\", cheez);"
- "Module.print([Pointer_stringify(cheez), Module.getValue(cheez, 'i8')&0xff, Module.getValue(cheez+1, 'i8')&0xff, Module.getValue(cheez+2, 'i8')&0xff, Module.getValue(cheez+3, 'i8')&0xff, ]);");
- }
- '''
- self.do_run(src, '206 188 226 128 μ†ℱ ╋ℯ╳╋ 😇\nμ†ℱ ╋ℯ╳╋ 😇,206,188,226,128\n');
+ self.do_run_from_file(src, output)
def test_utf32(self):
if self.emcc_args is None: return self.skip('need libc for wcslen()')
@@ -7823,74 +4020,29 @@ def process(filename):
def test_direct_string_constant_usage(self):
if self.emcc_args is None: return self.skip('requires libcxx')
- src = '''
- #include <iostream>
- template<int i>
- void printText( const char (&text)[ i ] )
- {
- std::cout << text;
- }
- int main()
- {
- printText( "some string constant" );
- return 0;
- }
- '''
- self.do_run(src, "some string constant")
+ test_path = path_from_root('tests', 'core', 'test_direct_string_constant_usage')
+ src, output = (test_path + s for s in ('.in', '.out'))
+
+ self.do_run_from_file(src, output)
def test_std_cout_new(self):
if self.emcc_args is None: return self.skip('requires emcc')
- src = '''
- #include <iostream>
+ test_path = path_from_root('tests', 'core', 'test_std_cout_new')
+ src, output = (test_path + s for s in ('.in', '.out'))
- struct NodeInfo { //structure that we want to transmit to our shaders
- float x;
- float y;
- float s;
- float c;
- };
- const int nbNodes = 100;
- NodeInfo * data = new NodeInfo[nbNodes]; //our data that will be transmitted using float texture.
-
- template<int i>
- void printText( const char (&text)[ i ] )
- {
- std::cout << text << std::endl;
- }
-
- int main()
- {
- printText( "some string constant" );
- return 0;
- }
- '''
-
- self.do_run(src, "some string constant")
+ self.do_run_from_file(src, output)
def test_istream(self):
if self.emcc_args is None: return self.skip('requires libcxx')
- src = '''
- #include <string>
- #include <sstream>
- #include <iostream>
-
- int main()
- {
- std::string mystring("1 2 3");
- std::istringstream is(mystring);
- int one, two, three;
+ test_path = path_from_root('tests', 'core', 'test_istream')
+ src, output = (test_path + s for s in ('.in', '.out'))
- is >> one >> two >> three;
-
- printf( "%i %i %i", one, two, three );
- }
- '''
for linkable in [0]:#, 1]:
print linkable
Settings.LINKABLE = linkable # regression check for issue #273
- self.do_run(src, "1 2 3")
+ self.do_run_from_file(src, output)
def test_fs_base(self):
Settings.INCLUDE_FULL_LIBRARY = 1
@@ -8032,31 +4184,10 @@ def process(filename):
self.do_run(src, expected, js_engines=[NODE_JS])
def test_uname(self):
- src = r'''
- #include <stdio.h>
- #include <sys/utsname.h>
+ test_path = path_from_root('tests', 'core', 'test_uname')
+ src, output = (test_path + s for s in ('.in', '.out'))
- int main() {
- struct utsname u;
- printf("ret: %d\n", uname(&u));
- printf("sysname: %s\n", u.sysname);
- printf("nodename: %s\n", u.nodename);
- printf("release: %s\n", u.release);
- printf("version: %s\n", u.version);
- printf("machine: %s\n", u.machine);
- printf("invalid: %d\n", uname(0));
- return 0;
- }
- '''
- expected = '''
- ret: 0
- sysname: Emscripten
- nodename: emscripten
- release: 1.0
- version: #1
- machine: x86-JS
- '''
- self.do_run(src, re.sub('(^|\n)\s+', '\\1', expected))
+ self.do_run_from_file(src, output)
def test_env(self):
src = open(path_from_root('tests', 'env', 'src.c'), 'r').read()
@@ -8069,30 +4200,10 @@ def process(filename):
self.do_run(src, expected)
def test_getloadavg(self):
- src = r'''
- #include <stdio.h>
- #include <stdlib.h>
+ test_path = path_from_root('tests', 'core', 'test_getloadavg')
+ src, output = (test_path + s for s in ('.in', '.out'))
- int main() {
- double load[5] = {42.13, 42.13, 42.13, 42.13, 42.13};
- printf("ret: %d\n", getloadavg(load, 5));
- printf("load[0]: %.3lf\n", load[0]);
- printf("load[1]: %.3lf\n", load[1]);
- printf("load[2]: %.3lf\n", load[2]);
- printf("load[3]: %.3lf\n", load[3]);
- printf("load[4]: %.3lf\n", load[4]);
- return 0;
- }
- '''
- expected = '''
- ret: 3
- load[0]: 0.100
- load[1]: 0.100
- load[2]: 0.100
- load[3]: 42.130
- load[4]: 42.130
- '''
- self.do_run(src, re.sub('(^|\n)\s+', '\\1', expected))
+ self.do_run_from_file(src, output)
def test_799(self):
src = open(path_from_root('tests', '799.cpp'), 'r').read()
@@ -8109,149 +4220,22 @@ PORT: 3979
self.do_run(src, expected)
def test_strcasecmp(self):
- src = r'''
- #include <stdio.h>
- #include <strings.h>
- int sign(int x) {
- if (x < 0) return -1;
- if (x > 0) return 1;
- return 0;
- }
- int main() {
- printf("*\n");
-
- printf("%d\n", sign(strcasecmp("hello", "hello")));
- printf("%d\n", sign(strcasecmp("hello1", "hello")));
- printf("%d\n", sign(strcasecmp("hello", "hello1")));
- printf("%d\n", sign(strcasecmp("hello1", "hello1")));
- printf("%d\n", sign(strcasecmp("iello", "hello")));
- printf("%d\n", sign(strcasecmp("hello", "iello")));
- printf("%d\n", sign(strcasecmp("A", "hello")));
- printf("%d\n", sign(strcasecmp("Z", "hello")));
- printf("%d\n", sign(strcasecmp("a", "hello")));
- printf("%d\n", sign(strcasecmp("z", "hello")));
- printf("%d\n", sign(strcasecmp("hello", "a")));
- printf("%d\n", sign(strcasecmp("hello", "z")));
-
- printf("%d\n", sign(strcasecmp("Hello", "hello")));
- printf("%d\n", sign(strcasecmp("Hello1", "hello")));
- printf("%d\n", sign(strcasecmp("Hello", "hello1")));
- printf("%d\n", sign(strcasecmp("Hello1", "hello1")));
- printf("%d\n", sign(strcasecmp("Iello", "hello")));
- printf("%d\n", sign(strcasecmp("Hello", "iello")));
- printf("%d\n", sign(strcasecmp("A", "hello")));
- printf("%d\n", sign(strcasecmp("Z", "hello")));
- printf("%d\n", sign(strcasecmp("a", "hello")));
- printf("%d\n", sign(strcasecmp("z", "hello")));
- printf("%d\n", sign(strcasecmp("Hello", "a")));
- printf("%d\n", sign(strcasecmp("Hello", "z")));
-
- printf("%d\n", sign(strcasecmp("hello", "Hello")));
- printf("%d\n", sign(strcasecmp("hello1", "Hello")));
- printf("%d\n", sign(strcasecmp("hello", "Hello1")));
- printf("%d\n", sign(strcasecmp("hello1", "Hello1")));
- printf("%d\n", sign(strcasecmp("iello", "Hello")));
- printf("%d\n", sign(strcasecmp("hello", "Iello")));
- printf("%d\n", sign(strcasecmp("A", "Hello")));
- printf("%d\n", sign(strcasecmp("Z", "Hello")));
- printf("%d\n", sign(strcasecmp("a", "Hello")));
- printf("%d\n", sign(strcasecmp("z", "Hello")));
- printf("%d\n", sign(strcasecmp("hello", "a")));
- printf("%d\n", sign(strcasecmp("hello", "z")));
-
- printf("%d\n", sign(strcasecmp("Hello", "Hello")));
- printf("%d\n", sign(strcasecmp("Hello1", "Hello")));
- printf("%d\n", sign(strcasecmp("Hello", "Hello1")));
- printf("%d\n", sign(strcasecmp("Hello1", "Hello1")));
- printf("%d\n", sign(strcasecmp("Iello", "Hello")));
- printf("%d\n", sign(strcasecmp("Hello", "Iello")));
- printf("%d\n", sign(strcasecmp("A", "Hello")));
- printf("%d\n", sign(strcasecmp("Z", "Hello")));
- printf("%d\n", sign(strcasecmp("a", "Hello")));
- printf("%d\n", sign(strcasecmp("z", "Hello")));
- printf("%d\n", sign(strcasecmp("Hello", "a")));
- printf("%d\n", sign(strcasecmp("Hello", "z")));
-
- printf("%d\n", sign(strncasecmp("hello", "hello", 3)));
- printf("%d\n", sign(strncasecmp("hello1", "hello", 3)));
- printf("%d\n", sign(strncasecmp("hello", "hello1", 3)));
- printf("%d\n", sign(strncasecmp("hello1", "hello1", 3)));
- printf("%d\n", sign(strncasecmp("iello", "hello", 3)));
- printf("%d\n", sign(strncasecmp("hello", "iello", 3)));
- printf("%d\n", sign(strncasecmp("A", "hello", 3)));
- printf("%d\n", sign(strncasecmp("Z", "hello", 3)));
- printf("%d\n", sign(strncasecmp("a", "hello", 3)));
- printf("%d\n", sign(strncasecmp("z", "hello", 3)));
- printf("%d\n", sign(strncasecmp("hello", "a", 3)));
- printf("%d\n", sign(strncasecmp("hello", "z", 3)));
-
- printf("*\n");
+ test_path = path_from_root('tests', 'core', 'test_strcasecmp')
+ src, output = (test_path + s for s in ('.in', '.out'))
- return 0;
- }
- '''
- self.do_run(src, '''*\n0\n1\n-1\n0\n1\n-1\n-1\n1\n-1\n1\n1\n-1\n0\n1\n-1\n0\n1\n-1\n-1\n1\n-1\n1\n1\n-1\n0\n1\n-1\n0\n1\n-1\n-1\n1\n-1\n1\n1\n-1\n0\n1\n-1\n0\n1\n-1\n-1\n1\n-1\n1\n1\n-1\n0\n0\n0\n0\n1\n-1\n-1\n1\n-1\n1\n1\n-1\n*\n''')
+ self.do_run_from_file(src, output)
def test_atomic(self):
- src = '''
- #include <stdio.h>
- int main() {
- int x = 10;
- int y = __sync_add_and_fetch(&x, 5);
- printf("*%d,%d*\\n", x, y);
- x = 10;
- y = __sync_fetch_and_add(&x, 5);
- printf("*%d,%d*\\n", x, y);
- x = 10;
- y = __sync_lock_test_and_set(&x, 6);
- printf("*%d,%d*\\n", x, y);
- x = 10;
- y = __sync_bool_compare_and_swap(&x, 9, 7);
- printf("*%d,%d*\\n", x, y);
- y = __sync_bool_compare_and_swap(&x, 10, 7);
- printf("*%d,%d*\\n", x, y);
- return 0;
- }
- '''
+ test_path = path_from_root('tests', 'core', 'test_atomic')
+ src, output = (test_path + s for s in ('.in', '.out'))
- self.do_run(src, '*15,15*\n*15,10*\n*6,10*\n*10,0*\n*7,1*')
+ self.do_run_from_file(src, output)
def test_phiundef(self):
- src = r'''
-#include <stdlib.h>
-#include <stdio.h>
-
-static int state;
-
-struct my_struct {
-union {
- struct {
- unsigned char a;
- unsigned char b;
- } c;
- unsigned int d;
-} e;
-unsigned int f;
-};
-
-int main(int argc, char **argv) {
- struct my_struct r;
-
- state = 0;
-
- for (int i=0;i<argc+10;i++)
- {
- if (state % 2 == 0)
- r.e.c.a = 3;
- else
- printf("%d\n", r.e.c.a);
- state++;
- }
- return 0;
-}
- '''
+ test_path = path_from_root('tests', 'core', 'test_phiundef')
+ src, output = (test_path + s for s in ('.in', '.out'))
- self.do_run(src, '3\n3\n3\n3\n3\n')
+ self.do_run_from_file(src, output)
# libc++ tests
@@ -8274,86 +4258,19 @@ int main(int argc, char **argv) {
def test_stdvec(self):
if self.emcc_args is None: return self.skip('requires emcc')
- src = '''
- #include <vector>
- #include <stdio.h>
- struct S {
- int a;
- float b;
- };
-
- void foo(int a, float b)
- {
- printf("%d:%.2f\\n", a, b);
- }
-
- int main ( int argc, char *argv[] )
- {
- std::vector<S> ar;
- S s;
-
- s.a = 789;
- s.b = 123.456f;
- ar.push_back(s);
-
- s.a = 0;
- s.b = 100.1f;
- ar.push_back(s);
-
- foo(ar[0].a, ar[0].b);
- foo(ar[1].a, ar[1].b);
- }
- '''
+ test_path = path_from_root('tests', 'core', 'test_stdvec')
+ src, output = (test_path + s for s in ('.in', '.out'))
- self.do_run(src, '789:123.46\n0:100.1')
+ self.do_run_from_file(src, output)
def test_reinterpreted_ptrs(self):
if self.emcc_args is None: return self.skip('needs emcc and libc')
- src = r'''
-#include <stdio.h>
-
-class Foo {
-private:
- float bar;
-public:
- int baz;
-
- Foo(): bar(0), baz(4711) {};
-
- int getBar() const;
-};
-
-int Foo::getBar() const {
- return this->bar;
-};
-
-const Foo *magic1 = reinterpret_cast<Foo*>(0xDEAD111F);
-const Foo *magic2 = reinterpret_cast<Foo*>(0xDEAD888F);
-
-static void runTest() {
-
- const Foo *a = new Foo();
- const Foo *b = a;
+ test_path = path_from_root('tests', 'core', 'test_reinterpreted_ptrs')
+ src, output = (test_path + s for s in ('.in', '.out'))
- if (a->getBar() == 0) {
- if (a->baz == 4712)
- b = magic1;
- else
- b = magic2;
- }
-
- printf("%s\n", (b == magic1 ? "magic1" : (b == magic2 ? "magic2" : "neither")));
-};
-
-extern "C" {
- int main(int argc, char **argv) {
- runTest();
- }
-}
-'''
- self.do_run(src, 'magic2')
+ self.do_run_from_file(src, output)
def test_jansson(self):
return self.skip('currently broken')
@@ -8522,22 +4439,11 @@ return malloc(size);
def test_dlmalloc_partial_2(self):
if self.emcc_args is None or 'SAFE_HEAP' in str(self.emcc_args) or 'CHECK_HEAP_ALIGN' in str(self.emcc_args): return self.skip('only emcc will link in dlmalloc, and we do unsafe stuff')
# present part of the symbols of dlmalloc, not all. malloc is harder to link than new which is weak.
- src = r'''
- #include <stdio.h>
- #include <stdlib.h>
- void *malloc(size_t size)
- {
- return (void*)123;
- }
- int main() {
- void *x = malloc(10);
- printf("got %p\n", x);
- free(x);
- printf("freed the faker\n");
- return 1;
- }
-'''
- self.do_run(src, 'got 0x7b\nfreed')
+
+ test_path = path_from_root('tests', 'core', 'test_dlmalloc_partial_2')
+ src, output = (test_path + s for s in ('.in', '.out'))
+
+ self.do_run_from_file(src, output)
def test_libcxx(self):
if self.emcc_args is None: return self.skip('requires emcc')
@@ -8556,171 +4462,35 @@ return malloc(size);
''', 'hello world');
def test_typeid(self):
- self.do_run(r'''
- #include <stdio.h>
- #include <string.h>
- #include <typeinfo>
- int main() {
- printf("*\n");
- #define MAX 100
- int ptrs[MAX];
- int groups[MAX];
- memset(ptrs, 0, MAX*sizeof(int));
- memset(groups, 0, MAX*sizeof(int));
- int next_group = 1;
- #define TEST(X) { \
- int ptr = (int)&typeid(X); \
- int group = 0; \
- int i; \
- for (i = 0; i < MAX; i++) { \
- if (!groups[i]) break; \
- if (ptrs[i] == ptr) { \
- group = groups[i]; \
- break; \
- } \
- } \
- if (!group) { \
- groups[i] = group = next_group++; \
- ptrs[i] = ptr; \
- } \
- printf("%s:%d\n", #X, group); \
- }
- TEST(int);
- TEST(unsigned int);
- TEST(unsigned);
- TEST(signed int);
- TEST(long);
- TEST(unsigned long);
- TEST(signed long);
- TEST(long long);
- TEST(unsigned long long);
- TEST(signed long long);
- TEST(short);
- TEST(unsigned short);
- TEST(signed short);
- TEST(char);
- TEST(unsigned char);
- TEST(signed char);
- TEST(float);
- TEST(double);
- TEST(long double);
- TEST(void);
- TEST(void*);
- printf("*\n");
- }
- ''', '''*
-int:1
-unsigned int:2
-unsigned:2
-signed int:1
-long:3
-unsigned long:4
-signed long:3
-long long:5
-unsigned long long:6
-signed long long:5
-short:7
-unsigned short:8
-signed short:7
-char:9
-unsigned char:10
-signed char:11
-float:12
-double:13
-long double:14
-void:15
-void*:16
-*
-''');
+ test_path = path_from_root('tests', 'core', 'test_typeid')
+ src, output = (test_path + s for s in ('.in', '.out'))
+
+ self.do_run_from_file(src, output)
def test_static_variable(self):
if self.emcc_args is None: Settings.SAFE_HEAP = 0 # LLVM mixes i64 and i8 in the guard check
- src = '''
- #include <stdio.h>
-
- struct DATA
- {
- int value;
- DATA()
- {
- value = 0;
- }
- };
+ test_path = path_from_root('tests', 'core', 'test_static_variable')
+ src, output = (test_path + s for s in ('.in', '.out'))
- DATA & GetData()
- {
- static DATA data;
-
- return data;
- }
-
- int main()
- {
- GetData().value = 10;
- printf( "value:%i", GetData().value );
- }
- '''
- self.do_run(src, 'value:10')
+ self.do_run_from_file(src, output)
def test_fakestat(self):
- src = r'''
- #include <stdio.h>
- struct stat { int x, y; };
- int main() {
- stat s;
- s.x = 10;
- s.y = 22;
- printf("*%d,%d*\n", s.x, s.y);
- }
- '''
- self.do_run(src, '*10,22*')
+ test_path = path_from_root('tests', 'core', 'test_fakestat')
+ src, output = (test_path + s for s in ('.in', '.out'))
+
+ self.do_run_from_file(src, output)
def test_mmap(self):
if self.emcc_args is None: return self.skip('requires emcc')
Settings.TOTAL_MEMORY = 128*1024*1024
- src = '''
- #include <stdio.h>
- #include <sys/mman.h>
- #include <assert.h>
-
- int main(int argc, char *argv[]) {
- for (int i = 0; i < 10; i++) {
- int* map = (int*)mmap(0, 5000, PROT_READ | PROT_WRITE,
- MAP_SHARED | MAP_ANON, -1, 0);
- /* TODO: Should we align to 4k?
- assert(((int)map) % 4096 == 0); // aligned
- */
- assert(munmap(map, 5000) == 0);
- }
+ test_path = path_from_root('tests', 'core', 'test_mmap')
+ src, output = (test_path + s for s in ('.in', '.out'))
- const int NUM_BYTES = 8 * 1024 * 1024;
- const int NUM_INTS = NUM_BYTES / sizeof(int);
-
- int* map = (int*)mmap(0, NUM_BYTES, PROT_READ | PROT_WRITE,
- MAP_SHARED | MAP_ANON, -1, 0);
- assert(map != MAP_FAILED);
-
- int i;
-
- for (i = 0; i < NUM_INTS; i++) {
- map[i] = i;
- }
-
- for (i = 0; i < NUM_INTS; i++) {
- assert(map[i] == i);
- }
-
- assert(munmap(map, NUM_BYTES) == 0);
-
- printf("hello,world");
- return 0;
- }
- '''
- self.do_run(src, 'hello,world')
- self.do_run(src, 'hello,world', force_c=True)
+ self.do_run_from_file(src, output)
+ self.do_run_from_file(src, output, force_c=True)
def test_mmap_file(self):
if self.emcc_args is None: return self.skip('requires emcc')
@@ -8778,602 +4548,28 @@ void*:16
def test_simd(self):
if Settings.USE_TYPED_ARRAYS != 2: return self.skip('needs ta2')
if Settings.ASM_JS: Settings.ASM_JS = 2 # does not validate
- src = r'''
-#include <stdio.h>
-#include <emscripten/vector.h>
+ test_path = path_from_root('tests', 'core', 'test_simd')
+ src, output = (test_path + s for s in ('.in', '.out'))
-static inline float32x4 __attribute__((always_inline))
-_mm_set_ps(const float __Z, const float __Y, const float __X, const float __W)
-{
- return (float32x4){ __W, __X, __Y, __Z };
-}
-
-static __inline__ float32x4 __attribute__((__always_inline__))
-_mm_setzero_ps(void)
-{
- return (float32x4){ 0.0, 0.0, 0.0, 0.0 };
-}
-
-int main(int argc, char **argv) {
- float data[8];
- for (int i = 0; i < 32; i++) data[i] = (1+i+argc)*(2+i+argc*argc); // confuse optimizer
- {
- float32x4 *a = (float32x4*)&data[0];
- float32x4 *b = (float32x4*)&data[4];
- float32x4 c, d;
- c = *a;
- d = *b;
- printf("1floats! %d, %d, %d, %d %d, %d, %d, %d\n", (int)c[0], (int)c[1], (int)c[2], (int)c[3], (int)d[0], (int)d[1], (int)d[2], (int)d[3]);
- c = c+d;
- printf("2floats! %d, %d, %d, %d %d, %d, %d, %d\n", (int)c[0], (int)c[1], (int)c[2], (int)c[3], (int)d[0], (int)d[1], (int)d[2], (int)d[3]);
- d = c*d;
- printf("3floats! %d, %d, %d, %d %d, %d, %d, %d\n", (int)c[0], (int)c[1], (int)c[2], (int)c[3], (int)d[0], (int)d[1], (int)d[2], (int)d[3]);
- c = _mm_setzero_ps();
- printf("zeros %d, %d, %d, %d\n", (int)c[0], (int)c[1], (int)c[2], (int)c[3]);
- }
- {
- int32x4 *a = (int32x4*)&data[0];
- int32x4 *b = (int32x4*)&data[4];
- int32x4 c, d, e, f;
- c = *a;
- d = *b;
- printf("4ints! %d, %d, %d, %d %d, %d, %d, %d\n", c[0], c[1], c[2], c[3], d[0], d[1], d[2], d[3]);
- e = c+d;
- f = c-d;
- printf("5ints! %d, %d, %d, %d %d, %d, %d, %d\n", e[0], e[1], e[2], e[3], f[0], f[1], f[2], f[3]);
- e = c&d;
- f = c|d;
- e = ~c&d;
- f = c^d;
- printf("5intops! %d, %d, %d, %d %d, %d, %d, %d\n", e[0], e[1], e[2], e[3], f[0], f[1], f[2], f[3]);
- }
- {
- float32x4 c, d, e, f;
- c = _mm_set_ps(9.0, 4.0, 0, -9.0);
- d = _mm_set_ps(10.0, 14.0, -12, -2.0);
- printf("6floats! %d, %d, %d, %d %d, %d, %d, %d\n", (int)c[0], (int)c[1], (int)c[2], (int)c[3], (int)d[0], (int)d[1], (int)d[2], (int)d[3]);
- printf("7calcs: %d\n", emscripten_float32x4_signmask(c)); // TODO: just not just compilation but output as well
- }
-
- return 0;
-}
- '''
-
- self.do_run(src, '''1floats! 6, 12, 20, 30 42, 56, 72, 90
-2floats! 48, 68, 92, 120 42, 56, 72, 90
-3floats! 48, 68, 92, 120 2016, 3808, 6624, 10800
-zeros 0, 0, 0, 0
-4ints! 1086324736, 1094713344, 1101004800, 1106247680 1109917696, 1113587712, 1116733440, 1119092736
-5ints! -2098724864, -2086666240, -2077229056, -2069626880 -23592960, -18874368, -15728640, -12845056
-5intops! 36175872, 35651584, 34603008, 33816576 48758784, 52428800, 53477376, 54788096
-6floats! -9, 0, 4, 9 -2, -12, 14, 10
-''')
+ self.do_run_from_file(src, output)
def test_simd2(self):
if Settings.ASM_JS: Settings.ASM_JS = 2 # does not validate
- self.do_run(r'''
- #include <stdio.h>
-
- typedef float __m128 __attribute__ ((__vector_size__ (16)));
-
- static inline __m128 __attribute__((always_inline))
- _mm_set_ps(const float __Z, const float __Y, const float __X, const float __W)
- {
- return (__m128){ __W, __X, __Y, __Z };
- }
-
- static inline void __attribute__((always_inline))
- _mm_store_ps(float *__P, __m128 __A)
- {
- *(__m128 *)__P = __A;
- }
-
- static inline __m128 __attribute__((always_inline))
- _mm_add_ps(__m128 __A, __m128 __B)
- {
- return __A + __B;
- }
+ test_path = path_from_root('tests', 'core', 'test_simd2')
+ src, output = (test_path + s for s in ('.in', '.out'))
- using namespace std;
-
- int main(int argc, char ** argv) {
- float __attribute__((__aligned__(16))) ar[4];
- __m128 v1 = _mm_set_ps(9.0, 4.0, 0, -9.0);
- __m128 v2 = _mm_set_ps(7.0, 3.0, 2.5, 1.0);
- __m128 v3 = _mm_add_ps(v1, v2);
- _mm_store_ps(ar, v3);
-
- for (int i = 0; i < 4; i++) {
- printf("%f\n", ar[i]);
- }
-
- return 0;
- }
- ''', '''-8.000000
-2.500000
-7.000000
-16.000000
-''')
+ self.do_run_from_file(src, output)
def test_simd3(self):
if Settings.USE_TYPED_ARRAYS != 2: return self.skip('needs ta2')
if Settings.ASM_JS: Settings.ASM_JS = 2 # does not validate
- src = r'''
- #include <iostream>
- #include <emmintrin.h>
- #include <assert.h>
- #include <stdint.h>
- #include <bitset>
-
- using namespace std;
-
- void testSetPs() {
- float __attribute__((__aligned__(16))) ar[4];
- __m128 v = _mm_set_ps(1.0, 2.0, 3.0, 4.0);
- _mm_store_ps(ar, v);
- assert(ar[0] == 4.0);
- assert(ar[1] == 3.0);
- assert(ar[2] == 2.0);
- assert(ar[3] == 1.0);
- }
-
- void testSet1Ps() {
- float __attribute__((__aligned__(16))) ar[4];
- __m128 v = _mm_set1_ps(5.5);
- _mm_store_ps(ar, v);
- assert(ar[0] == 5.5);
- assert(ar[1] == 5.5);
- assert(ar[2] == 5.5);
- assert(ar[3] == 5.5);
- }
-
- void testSetZeroPs() {
- float __attribute__((__aligned__(16))) ar[4];
- __m128 v = _mm_setzero_ps();
- _mm_store_ps(ar, v);
- assert(ar[0] == 0);
- assert(ar[1] == 0);
- assert(ar[2] == 0);
- assert(ar[3] == 0);
- }
-
- void testSetEpi32() {
- int32_t __attribute__((__aligned__(16))) ar[4];
- __m128i v = _mm_set_epi32(5, 7, 126, 381);
- _mm_store_si128((__m128i *)ar, v);
- assert(ar[0] == 381);
- assert(ar[1] == 126);
- assert(ar[2] == 7);
- assert(ar[3] == 5);
- v = _mm_set_epi32(0x55555555, 0xaaaaaaaa, 0xffffffff, 0x12345678);
- _mm_store_si128((__m128i *)ar, v);
- assert(ar[0] == 0x12345678);
- assert(ar[1] == 0xffffffff);
- assert(ar[2] == 0xaaaaaaaa);
- assert(ar[3] == 0x55555555);
- }
-
- void testSet1Epi32() {
- int32_t __attribute__((__aligned__(16))) ar[4];
- __m128i v = _mm_set1_epi32(-5);
- _mm_store_si128((__m128i *)ar, v);
- assert(ar[0] == -5);
- assert(ar[1] == -5);
- assert(ar[2] == -5);
- assert(ar[3] == -5);
- }
-
- void testSetZeroSi128() {
- int32_t __attribute__((__aligned__(16))) ar[4];
- __m128i v = _mm_setzero_si128();
- _mm_store_si128((__m128i *)ar, v);
- assert(ar[0] == 0);
- assert(ar[1] == 0);
- assert(ar[2] == 0);
- assert(ar[3] == 0);
- }
-
- void testBitCasts() {
- int32_t __attribute__((__aligned__(16))) ar1[4];
- float __attribute__((__aligned__(16))) ar2[4];
- __m128i v1 = _mm_set_epi32(0x3f800000, 0x40000000, 0x40400000, 0x40800000);
- __m128 v2 = _mm_castsi128_ps(v1);
- _mm_store_ps(ar2, v2);
- assert(ar2[0] == 4.0);
- assert(ar2[1] == 3.0);
- assert(ar2[2] == 2.0);
- assert(ar2[3] == 1.0);
- v2 = _mm_set_ps(5.0, 6.0, 7.0, 8.0);
- v1 = _mm_castps_si128(v2);
- _mm_store_si128((__m128i *)ar1, v1);
- assert(ar1[0] == 0x41000000);
- assert(ar1[1] == 0x40e00000);
- assert(ar1[2] == 0x40c00000);
- assert(ar1[3] == 0x40a00000);
- float w = 0;
- float z = -278.3;
- float y = 5.2;
- float x = -987654321;
- v1 = _mm_castps_si128(_mm_set_ps(w, z, y, x));
- _mm_store_ps(ar2, _mm_castsi128_ps(v1));
- assert(ar2[0] == x);
- assert(ar2[1] == y);
- assert(ar2[2] == z);
- assert(ar2[3] == w);
- /*
- std::bitset<sizeof(float)*CHAR_BIT> bits1x(*reinterpret_cast<unsigned long*>(&(ar2[0])));
- std::bitset<sizeof(float)*CHAR_BIT> bits1y(*reinterpret_cast<unsigned long*>(&(ar2[1])));
- std::bitset<sizeof(float)*CHAR_BIT> bits1z(*reinterpret_cast<unsigned long*>(&(ar2[2])));
- std::bitset<sizeof(float)*CHAR_BIT> bits1w(*reinterpret_cast<unsigned long*>(&(ar2[3])));
- std::bitset<sizeof(float)*CHAR_BIT> bits2x(*reinterpret_cast<unsigned long*>(&x));
- std::bitset<sizeof(float)*CHAR_BIT> bits2y(*reinterpret_cast<unsigned long*>(&y));
- std::bitset<sizeof(float)*CHAR_BIT> bits2z(*reinterpret_cast<unsigned long*>(&z));
- std::bitset<sizeof(float)*CHAR_BIT> bits2w(*reinterpret_cast<unsigned long*>(&w));
- assert(bits1x == bits2x);
- assert(bits1y == bits2y);
- assert(bits1z == bits2z);
- assert(bits1w == bits2w);
- */
- v2 = _mm_castsi128_ps(_mm_set_epi32(0xffffffff, 0, 0x5555cccc, 0xaaaaaaaa));
- _mm_store_si128((__m128i *)ar1, _mm_castps_si128(v2));
- assert(ar1[0] == 0xaaaaaaaa);
- assert(ar1[1] == 0x5555cccc);
- assert(ar1[2] == 0);
- assert(ar1[3] == 0xffffffff);
- }
-
- void testConversions() {
- int32_t __attribute__((__aligned__(16))) ar1[4];
- float __attribute__((__aligned__(16))) ar2[4];
- __m128i v1 = _mm_set_epi32(0, -3, -517, 256);
- __m128 v2 = _mm_cvtepi32_ps(v1);
- _mm_store_ps(ar2, v2);
- assert(ar2[0] == 256.0);
- assert(ar2[1] == -517.0);
- assert(ar2[2] == -3.0);
- assert(ar2[3] == 0);
- v2 = _mm_set_ps(5.0, 6.0, 7.45, -8.0);
- v1 = _mm_cvtps_epi32(v2);
- _mm_store_si128((__m128i *)ar1, v1);
- assert(ar1[0] == -8);
- assert(ar1[1] == 7);
- assert(ar1[2] == 6);
- assert(ar1[3] == 5);
- }
-
- void testMoveMaskPs() {
- __m128 v = _mm_castsi128_ps(_mm_set_epi32(0xffffffff, 0xffffffff, 0, 0xffffffff));
- int mask = _mm_movemask_ps(v);
- assert(mask == 13);
- }
-
- void testAddPs() {
- float __attribute__((__aligned__(16))) ar[4];
- __m128 v1 = _mm_set_ps(4.0, 3.0, 2.0, 1.0);
- __m128 v2 = _mm_set_ps(10.0, 20.0, 30.0, 40.0);
- __m128 v = _mm_add_ps(v1, v2);
- _mm_store_ps(ar, v);
- assert(ar[0] == 41.0);
- assert(ar[1] == 32.0);
- assert(ar[2] == 23.0);
- assert(ar[3] == 14.0);
- }
-
- void testSubPs() {
- float __attribute__((__aligned__(16))) ar[4];
- __m128 v1 = _mm_set_ps(4.0, 3.0, 2.0, 1.0);
- __m128 v2 = _mm_set_ps(10.0, 20.0, 30.0, 40.0);
- __m128 v = _mm_sub_ps(v1, v2);
- _mm_store_ps(ar, v);
- assert(ar[0] == -39.0);
- assert(ar[1] == -28.0);
- assert(ar[2] == -17.0);
- assert(ar[3] == -6.0);
- }
-
- void testMulPs() {
- float __attribute__((__aligned__(16))) ar[4];
- __m128 v1 = _mm_set_ps(4.0, 3.0, 2.0, 1.0);
- __m128 v2 = _mm_set_ps(10.0, 20.0, 30.0, 40.0);
- __m128 v = _mm_mul_ps(v1, v2);
- _mm_store_ps(ar, v);
- assert(ar[0] == 40.0);
- assert(ar[1] == 60.0);
- assert(ar[2] == 60.0);
- assert(ar[3] == 40.0);
- }
-
- void testDivPs() {
- float __attribute__((__aligned__(16))) ar[4];
- __m128 v1 = _mm_set_ps(4.0, 9.0, 8.0, 1.0);
- __m128 v2 = _mm_set_ps(2.0, 3.0, 1.0, 0.5);
- __m128 v = _mm_div_ps(v1, v2);
- _mm_store_ps(ar, v);
- assert(ar[0] == 2.0);
- assert(ar[1] == 8.0);
- assert(ar[2] == 3.0);
- assert(ar[3] == 2.0);
- }
-
- void testMinPs() {
- float __attribute__((__aligned__(16))) ar[4];
- __m128 v1 = _mm_set_ps(-20.0, 10.0, 30.0, 0.5);
- __m128 v2 = _mm_set_ps(2.0, 1.0, 50.0, 0.0);
- __m128 v = _mm_min_ps(v1, v2);
- _mm_store_ps(ar, v);
- assert(ar[0] == 0.0);
- assert(ar[1] == 30.0);
- assert(ar[2] == 1.0);
- assert(ar[3] == -20.0);
- }
-
- void testMaxPs() {
- float __attribute__((__aligned__(16))) ar[4];
- __m128 v1 = _mm_set_ps(-20.0, 10.0, 30.0, 0.5);
- __m128 v2 = _mm_set_ps(2.5, 5.0, 55.0, 1.0);
- __m128 v = _mm_max_ps(v1, v2);
- _mm_store_ps(ar, v);
- assert(ar[0] == 1.0);
- assert(ar[1] == 55.0);
- assert(ar[2] == 10.0);
- assert(ar[3] == 2.5);
- }
-
- void testSqrtPs() {
- float __attribute__((__aligned__(16))) ar[4];
- __m128 v1 = _mm_set_ps(16.0, 9.0, 4.0, 1.0);
- __m128 v = _mm_sqrt_ps(v1);
- _mm_store_ps(ar, v);
- assert(ar[0] == 1.0);
- assert(ar[1] == 2.0);
- assert(ar[2] == 3.0);
- assert(ar[3] == 4.0);
- }
-
- void testCmpLtPs() {
- int32_t __attribute__((__aligned__(16))) ar[4];
- __m128 v1 = _mm_set_ps(1.0, 2.0, 0.1, 0.001);
- __m128 v2 = _mm_set_ps(2.0, 2.0, 0.001, 0.1);
- __m128 v = _mm_cmplt_ps(v1, v2);
- _mm_store_si128((__m128i *)ar, _mm_castps_si128(v));
- assert(ar[0] == 0xffffffff);
- assert(ar[1] == 0);
- assert(ar[2] == 0);
- assert(ar[3] == 0xffffffff);
- assert(_mm_movemask_ps(v) == 9);
- }
-
- void testCmpLePs() {
- int32_t __attribute__((__aligned__(16))) ar[4];
- __m128 v1 = _mm_set_ps(1.0, 2.0, 0.1, 0.001);
- __m128 v2 = _mm_set_ps(2.0, 2.0, 0.001, 0.1);
- __m128 v = _mm_cmple_ps(v1, v2);
- _mm_store_si128((__m128i *)ar, _mm_castps_si128(v));
- assert(ar[0] == 0xffffffff);
- assert(ar[1] == 0);
- assert(ar[2] == 0xffffffff);
- assert(ar[3] == 0xffffffff);
- assert(_mm_movemask_ps(v) == 13);
- }
-
- void testCmpEqPs() {
- int32_t __attribute__((__aligned__(16))) ar[4];
- __m128 v1 = _mm_set_ps(1.0, 2.0, 0.1, 0.001);
- __m128 v2 = _mm_set_ps(2.0, 2.0, 0.001, 0.1);
- __m128 v = _mm_cmpeq_ps(v1, v2);
- _mm_store_si128((__m128i *)ar, _mm_castps_si128(v));
- assert(ar[0] == 0);
- assert(ar[1] == 0);
- assert(ar[2] == 0xffffffff);
- assert(ar[3] == 0);
- assert(_mm_movemask_ps(v) == 4);
- }
-
- void testCmpGePs() {
- int32_t __attribute__((__aligned__(16))) ar[4];
- __m128 v1 = _mm_set_ps(1.0, 2.0, 0.1, 0.001);
- __m128 v2 = _mm_set_ps(2.0, 2.0, 0.001, 0.1);
- __m128 v = _mm_cmpge_ps(v1, v2);
- _mm_store_si128((__m128i *)ar, _mm_castps_si128(v));
- assert(ar[0] == 0);
- assert(ar[1] == 0xffffffff);
- assert(ar[2] == 0xffffffff);
- assert(ar[3] == 0);
- assert(_mm_movemask_ps(v) == 6);
- }
-
- void testCmpGtPs() {
- int32_t __attribute__((__aligned__(16))) ar[4];
- __m128 v1 = _mm_set_ps(1.0, 2.0, 0.1, 0.001);
- __m128 v2 = _mm_set_ps(2.0, 2.0, 0.001, 0.1);
- __m128 v = _mm_cmpgt_ps(v1, v2);
- _mm_store_si128((__m128i *)ar, _mm_castps_si128(v));
- assert(ar[0] == 0);
- assert(ar[1] == 0xffffffff);
- assert(ar[2] == 0);
- assert(ar[3] == 0);
- assert(_mm_movemask_ps(v) == 2);
- }
-
- void testAndPs() {
- float __attribute__((__aligned__(16))) ar[4];
- __m128 v1 = _mm_set_ps(425, -501, -32, 68);
- __m128 v2 = _mm_castsi128_ps(_mm_set_epi32(0xffffffff, 0xffffffff, 0, 0xffffffff));
- __m128 v = _mm_and_ps(v1, v2);
- _mm_store_ps(ar, v);
- assert(ar[0] == 68);
- assert(ar[1] == 0);
- assert(ar[2] == -501);
- assert(ar[3] == 425);
- int32_t __attribute__((__aligned__(16))) ar2[4];
- v1 = _mm_castsi128_ps(_mm_set_epi32(0xaaaaaaaa, 0xaaaaaaaa, -1431655766, 0xaaaaaaaa));
- v2 = _mm_castsi128_ps(_mm_set_epi32(0x55555555, 0x55555555, 0x55555555, 0x55555555));
- v = _mm_and_ps(v1, v2);
- _mm_store_si128((__m128i *)ar2, _mm_castps_si128(v));
- assert(ar2[0] == 0);
- assert(ar2[1] == 0);
- assert(ar2[2] == 0);
- assert(ar2[3] == 0);
- }
-
- void testAndNotPs() {
- float __attribute__((__aligned__(16))) ar[4];
- __m128 v1 = _mm_set_ps(425, -501, -32, 68);
- __m128 v2 = _mm_castsi128_ps(_mm_set_epi32(0xffffffff, 0xffffffff, 0, 0xffffffff));
- __m128 v = _mm_andnot_ps(v2, v1);
- _mm_store_ps(ar, v);
- assert(ar[0] == 0);
- assert(ar[1] == -32);
- assert(ar[2] == 0);
- assert(ar[3] == 0);
- int32_t __attribute__((__aligned__(16))) ar2[4];
- v1 = _mm_castsi128_ps(_mm_set_epi32(0xaaaaaaaa, 0xaaaaaaaa, -1431655766, 0xaaaaaaaa));
- v2 = _mm_castsi128_ps(_mm_set_epi32(0x55555555, 0x55555555, 0x55555555, 0x55555555));
- v = _mm_andnot_ps(v1, v2);
- _mm_store_si128((__m128i *)ar2, _mm_castps_si128(v));
- assert(ar2[0] == 0x55555555);
- assert(ar2[1] == 0x55555555);
- assert(ar2[2] == 0x55555555);
- assert(ar2[3] == 0x55555555);
- }
-
- void testOrPs() {
- int32_t __attribute__((__aligned__(16))) ar[4];
- __m128 v1 = _mm_castsi128_ps(_mm_set_epi32(0xaaaaaaaa, 0xaaaaaaaa, 0xffffffff, 0));
- __m128 v2 = _mm_castsi128_ps(_mm_set_epi32(0x55555555, 0x55555555, 0x55555555, 0x55555555));
- __m128 v = _mm_or_ps(v1, v2);
- _mm_store_si128((__m128i *)ar, _mm_castps_si128(v));
- assert(ar[0] == 0x55555555);
- assert(ar[1] == 0xffffffff);
- assert(ar[2] == 0xffffffff);
- assert(ar[3] == 0xffffffff);
- }
-
- void testXorPs() {
- int32_t __attribute__((__aligned__(16))) ar[4];
- __m128 v1 = _mm_castsi128_ps(_mm_set_epi32(0xaaaaaaaa, 0xaaaaaaaa, 0xffffffff, 0));
- __m128 v2 = _mm_castsi128_ps(_mm_set_epi32(0x55555555, 0x55555555, 0x55555555, 0x55555555));
- __m128 v = _mm_xor_ps(v1, v2);
- _mm_store_si128((__m128i *)ar, _mm_castps_si128(v));
- assert(ar[0] == 0x55555555);
- assert(ar[1] == 0xaaaaaaaa);
- assert(ar[2] == 0xffffffff);
- assert(ar[3] == 0xffffffff);
- }
-
- void testAndSi128() {
- int32_t __attribute__((__aligned__(16))) ar[4];
- __m128i v1 = _mm_set_epi32(0xaaaaaaaa, 0xaaaaaaaa, -1431655766, 0xaaaaaaaa);
- __m128i v2 = _mm_set_epi32(0x55555555, 0x55555555, 0x55555555, 0x55555555);
- __m128i v = _mm_and_si128(v1, v2);
- _mm_store_si128((__m128i *)ar, v);
- assert(ar[0] == 0);
- assert(ar[1] == 0);
- assert(ar[2] == 0);
- assert(ar[3] == 0);
- }
-
- void testAndNotSi128() {
- int32_t __attribute__((__aligned__(16))) ar[4];
- __m128i v1 = _mm_set_epi32(0xaaaaaaaa, 0xaaaaaaaa, -1431655766, 0xaaaaaaaa);
- __m128i v2 = _mm_set_epi32(0x55555555, 0x55555555, 0x55555555, 0x55555555);
- __m128i v = _mm_andnot_si128(v1, v2);
- _mm_store_si128((__m128i *)ar, v);
- assert(ar[0] == 0x55555555);
- assert(ar[1] == 0x55555555);
- assert(ar[2] == 0x55555555);
- assert(ar[3] == 0x55555555);
- }
-
- void testOrSi128() {
- int32_t __attribute__((__aligned__(16))) ar[4];
- __m128i v1 = _mm_set_epi32(0xaaaaaaaa, 0xaaaaaaaa, 0xffffffff, 0);
- __m128i v2 = _mm_set_epi32(0x55555555, 0x55555555, 0x55555555, 0x55555555);
- __m128i v = _mm_or_si128(v1, v2);
- _mm_store_si128((__m128i *)ar, v);
- assert(ar[0] == 0x55555555);
- assert(ar[1] == 0xffffffff);
- assert(ar[2] == 0xffffffff);
- assert(ar[3] == 0xffffffff);
- }
-
- void testXorSi128() {
- int32_t __attribute__((__aligned__(16))) ar[4];
- __m128i v1 = _mm_set_epi32(0xaaaaaaaa, 0xaaaaaaaa, 0xffffffff, 0);
- __m128i v2 = _mm_set_epi32(0x55555555, 0x55555555, 0x55555555, 0x55555555);
- __m128i v = _mm_xor_si128(v1, v2);
- _mm_store_si128((__m128i *)ar, v);
- assert(ar[0] == 0x55555555);
- assert(ar[1] == 0xaaaaaaaa);
- assert(ar[2] == 0xffffffff);
- assert(ar[3] == 0xffffffff);
- }
-
- void testAddEpi32() {
- int32_t __attribute__((__aligned__(16))) ar[4];
- __m128i v1 = _mm_set_epi32(4, 3, 2, 1);
- __m128i v2 = _mm_set_epi32(10, 20, 30, 40);
- __m128i v = _mm_add_epi32(v1, v2);
- _mm_store_si128((__m128i *)ar, v);
- assert(ar[0] == 41);
- assert(ar[1] == 32);
- assert(ar[2] == 23);
- assert(ar[3] == 14);
- }
-
- void testSubEpi32() {
- int32_t __attribute__((__aligned__(16))) ar[4];
- __m128i v1 = _mm_set_epi32(4, 3, 2, 1);
- __m128i v2 = _mm_set_epi32(10, 20, 30, 40);
- __m128i v = _mm_sub_epi32(v1, v2);
- _mm_store_si128((__m128i *)ar, v);
- assert(ar[0] == -39);
- assert(ar[1] == -28);
- assert(ar[2] == -17);
- assert(ar[3] == -6);
- }
-
- int main(int argc, char ** argv) {
- testSetPs();
- testSet1Ps();
- testSetZeroPs();
- testSetEpi32();
- testSet1Epi32();
- testSetZeroSi128();
- testBitCasts();
- testConversions();
- testMoveMaskPs();
- testAddPs();
- testSubPs();
- testMulPs();
- testDivPs();
- testMaxPs();
- testMinPs();
- testSqrtPs();
- testCmpLtPs();
- testCmpLePs();
- testCmpEqPs();
- testCmpGePs();
- testCmpGtPs();
- testAndPs();
- testAndNotPs();
- testOrPs();
- testXorPs();
- testAndSi128();
- testAndNotSi128();
- testOrSi128();
- testXorSi128();
- testAddEpi32();
- testSubEpi32();
- printf("DONE");
- return 0;
- }
- '''
- self.do_run(src, 'DONE')
+ test_path = path_from_root('tests', 'core', 'test_simd3')
+ src, output = (test_path + s for s in ('.in', '.out'))
+ self.do_run_from_file(src, output)
def test_gcc_unmangler(self):
Settings.NAMED_GLOBALS = 1 # test coverage for this
@@ -9913,33 +5109,10 @@ def process(filename):
Settings.CORRUPTION_CHECK = 1
# test for free(0), malloc(0), etc.
- src = r'''
- #include <iostream>
- #include <fstream>
- #include <stdlib.h>
- #include <stdio.h>
+ test_path = path_from_root('tests', 'core', 'test_corruption_2')
+ src, output = (test_path + s for s in ('.in', '.out'))
- void bye() {
- printf("all ok\n");
- }
-
- int main() {
- atexit(bye);
-
- std::string testPath = "/Script/WA-KA.txt";
- std::fstream str(testPath.c_str(), std::ios::in | std::ios::binary);
-
- if (str.is_open())
- {
- std::cout << "open!" << std::endl;
- } else {
- std::cout << "missing!" << std::endl;
- }
-
- return 1;
- }
- '''
- self.do_run(src, 'missing!\nall ok\n')
+ self.do_run_from_file(src, output)
def test_corruption_3(self):
if Settings.ASM_JS: return self.skip('cannot use corruption checks in asm')
@@ -9948,29 +5121,10 @@ def process(filename):
Settings.CORRUPTION_CHECK = 1
# realloc
- src = r'''
- #include <stdlib.h>
- #include <stdio.h>
- #include <assert.h>
+ test_path = path_from_root('tests', 'core', 'test_corruption_3')
+ src, output = (test_path + s for s in ('.in', '.out'))
- void bye() {
- printf("all ok\n");
- }
-
- int main(int argc, char **argv) {
- atexit(bye);
-
- char *buffer = (char*)malloc(100);
- for (int i = 0; i < 100; i++) buffer[i] = (i*i)%256;
- buffer = (char*)realloc(buffer, argc + 50);
- for (int i = 0; i < argc + 50; i++) {
- //printf("%d : %d : %d : %d\n", i, (int)(buffer + i), buffer[i], (char)((i*i)%256));
- assert(buffer[i] == (char)((i*i)%256));
- }
- return 1;
- }
- '''
- self.do_run(src, 'all ok\n')
+ self.do_run_from_file(src, output)
### Integration tests
@@ -9978,26 +5132,6 @@ def process(filename):
if self.emcc_args is not None and '-O2' in self.emcc_args:
self.emcc_args += ['--closure', '1'] # Use closure here, to test we export things right
- src = r'''
- #include <stdio.h>
- #include <stdlib.h>
-
- extern "C" {
- int get_int() { return 5; }
- float get_float() { return 3.14; }
- char * get_string() { return "hello world"; }
- void print_int(int x) { printf("%d\n", x); }
- void print_float(float x) { printf("%.2f\n", x); }
- void print_string(char *x) { printf("%s\n", x); }
- int multi(int x, float y, int z, char *str) { if (x) puts(str); return (x+y)*z; }
- int * pointer(int *in) { printf("%d\n", *in); static int ret = 21; return &ret; }
- }
-
- int main(int argc, char **argv) {
- return 0;
- }
- '''
-
post = '''
def process(filename):
src = \'\'\'
@@ -10036,7 +5170,10 @@ def process(filename):
Settings.EXPORTED_FUNCTIONS += ['_get_int', '_get_float', '_get_string', '_print_int', '_print_float', '_print_string', '_multi', '_pointer', '_malloc']
- self.do_run(src, '*\nnumber,5\nnumber,3.14\nstring,hello world\n12\nundefined\n14.56\nundefined\ncheez\nundefined\narr-ay\nundefined\nmore\nnumber,10\n650\nnumber,21\n*\natr\n10\nbret\n53\n*\nstack is ok.\n', post_build=post)
+ test_path = path_from_root('tests', 'core', 'test_ccall')
+ src, output = (test_path + s for s in ('.in', '.out'))
+
+ self.do_run_from_file(src, output, post_build=post)
def test_pgo(self):
if Settings.ASM_JS: return self.skip('PGO does not work in asm mode')
@@ -10223,28 +5360,10 @@ def process(filename):
def test_demangle_stacks(self):
if Settings.ASM_JS: return self.skip('spidermonkey has stack trace issues')
- src = r'''
- #include<stdio.h>
- #include<stdlib.h>
+ test_path = path_from_root('tests', 'core', 'test_demangle_stacks')
+ src, output = (test_path + s for s in ('.in', '.out'))
- namespace NameSpace {
- class Class {
- public:
- int Aborter(double x, char y, int *z) {
- int addr = x+y+(int)z;
- void *p = (void*)addr;
- for (int i = 0; i < 100; i++) free(p); // will abort, should show proper stack trace
- }
- };
- }
-
- int main(int argc, char **argv) {
- NameSpace::Class c;
- c.Aborter(1.234, 'a', NULL);
- return 0;
- }
- '''
- self.do_run(src, 'NameSpace::Class::Aborter(double, char, int*)');
+ self.do_run_from_file(src, output)
def test_embind(self):
if self.emcc_args is None: return self.skip('requires emcc')
@@ -11084,132 +6203,10 @@ def process(filename):
Settings.GC_SUPPORT = 1
- src = r'''
- #include <stdio.h>
- #include <gc.h>
- #include <assert.h>
-
- void *global;
-
- void finalizer(void *ptr, void *arg) {
- printf("finalizing %d (global == %d)\n", (int)arg, ptr == global);
- }
-
- void finalizer2(void *ptr, void *arg) {
- printf("finalizing2 %d (global == %d)\n", (int)arg, ptr == global);
- }
-
- int main() {
- GC_INIT();
-
- void *local, *local2, *local3, *local4, *local5, *local6;
-
- // Hold on to global, drop locals
-
- global = GC_MALLOC(1024); // rooted since in a static allocation
- GC_REGISTER_FINALIZER_NO_ORDER(global, finalizer, 0, 0, 0);
- printf("alloc %p\n", global);
-
- local = GC_MALLOC(1024); // not rooted since stack is not scanned
- GC_REGISTER_FINALIZER_NO_ORDER(local, finalizer, (void*)1, 0, 0);
- printf("alloc %p\n", local);
+ test_path = path_from_root('tests', 'core', 'test_gc')
+ src, output = (test_path + s for s in ('.in', '.out'))
- assert((char*)local - (char*)global >= 1024 || (char*)global - (char*)local >= 1024);
-
- local2 = GC_MALLOC(1024); // no finalizer
- printf("alloc %p\n", local2);
-
- local3 = GC_MALLOC(1024); // with finalizable2
- GC_REGISTER_FINALIZER_NO_ORDER(local3, finalizer2, (void*)2, 0, 0);
- printf("alloc %p\n", local);
-
- local4 = GC_MALLOC(1024); // yet another
- GC_REGISTER_FINALIZER_NO_ORDER(local4, finalizer2, (void*)3, 0, 0);
- printf("alloc %p\n", local);
-
- printf("basic test\n");
-
- GC_FORCE_COLLECT();
-
- printf("*\n");
-
- GC_FREE(global); // force free will actually work
-
- // scanning inside objects
-
- global = GC_MALLOC(12);
- GC_REGISTER_FINALIZER_NO_ORDER(global, finalizer, 0, 0, 0);
- local = GC_MALLOC(12);
- GC_REGISTER_FINALIZER_NO_ORDER(local, finalizer, (void*)1, 0, 0);
- local2 = GC_MALLOC_ATOMIC(12);
- GC_REGISTER_FINALIZER_NO_ORDER(local2, finalizer, (void*)2, 0, 0);
- local3 = GC_MALLOC(12);
- GC_REGISTER_FINALIZER_NO_ORDER(local3, finalizer, (void*)3, 0, 0);
- local4 = GC_MALLOC(12);
- GC_REGISTER_FINALIZER_NO_ORDER(local4, finalizer, (void*)4, 0, 0);
- local5 = GC_MALLOC_UNCOLLECTABLE(12);
- // This should never trigger since local5 is uncollectable
- GC_REGISTER_FINALIZER_NO_ORDER(local5, finalizer, (void*)5, 0, 0);
-
- printf("heap size = %d\n", GC_get_heap_size());
-
- local4 = GC_REALLOC(local4, 24);
-
- printf("heap size = %d\n", GC_get_heap_size());
-
- local6 = GC_MALLOC(12);
- GC_REGISTER_FINALIZER_NO_ORDER(local6, finalizer, (void*)6, 0, 0);
- // This should be the same as a free
- GC_REALLOC(local6, 0);
-
- void **globalData = (void**)global;
- globalData[0] = local;
- globalData[1] = local2;
-
- void **localData = (void**)local;
- localData[0] = local3;
-
- void **local2Data = (void**)local2;
- local2Data[0] = local4; // actually ignored, because local2 is atomic, so 4 is freeable
-
- printf("object scan test test\n");
-
- GC_FORCE_COLLECT();
-
- printf("*\n");
-
- GC_FREE(global); // force free will actually work
-
- printf("*\n");
-
- GC_FORCE_COLLECT();
-
- printf(".\n");
-
- global = 0;
-
- return 0;
- }
- '''
- self.do_run(src, '''basic test
-finalizing 1 (global == 0)
-finalizing2 2 (global == 0)
-finalizing2 3 (global == 0)
-*
-finalizing 0 (global == 1)
-heap size = 72
-heap size = 84
-finalizing 6 (global == 0)
-object scan test test
-finalizing 4 (global == 0)
-*
-finalizing 0 (global == 1)
-*
-finalizing 1 (global == 0)
-finalizing 2 (global == 0)
-finalizing 3 (global == 0)
-.
-''')
+ self.do_run_from_file(src, output)
# Generate tests for everything
def make_run(fullname, name=-1, compiler=-1, embetter=0, quantum_size=0,