diff --git a/src/cgmemmgr.cpp b/src/cgmemmgr.cpp index 5df575bfc688f0..1ae370f67b211e 100644 --- a/src/cgmemmgr.cpp +++ b/src/cgmemmgr.cpp @@ -36,6 +36,9 @@ namespace { static void print_to_tty(const char *fmt, ...) { + char *env = getenv("JULIA_DEBUG_CGMEMMGR"); + if (!env || !*env) + return; va_list args; va_start(args, fmt); static int fd = -1; @@ -62,17 +65,15 @@ static void *map_anon_page(size_t size) #else void *mem = mmap(nullptr, size, PROT_READ | PROT_WRITE, MAP_NORESERVE | MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); - if (mem == MAP_FAILED) - print_to_tty("%s: %p, %lld\n", __func__, mem, (long long)size); + print_to_tty("%s: %p, %lld\n", __func__, mem, (long long)size); assert(mem != MAP_FAILED); #endif - // jl_safe_printf("%s: %p, %lld\n", __func__, mem, (long long)size); return mem; } static void unmap_page(void *ptr, size_t size) { - // jl_safe_printf("%s: %p, %lld\n", __func__, ptr, (long long)size); + print_to_tty("%s: %p, %lld\n", __func__, ptr, (long long)size); #ifdef _OS_WINDOWS_ VirtualFree(ptr, size, MEM_DECOMMIT); #else @@ -105,13 +106,11 @@ static void protect_page(void *ptr, size_t size, Prot flags) { int ret = mprotect(ptr, size, (int)flags); if (ret != 0) { - print_to_tty("%s: %p, %lld, %d, %d\n", - __func__, ptr, (long long)size, (int)flags, ret); perror(__func__); abort(); } - // jl_safe_printf("%s: %p, %lld, %d, %d\n", - // __func__, ptr, (long long)size, (int)flags, ret); + print_to_tty("%s: %p, %lld, %d, %d\n", + __func__, ptr, (long long)size, (int)flags, ret); } #endif @@ -145,7 +144,7 @@ static intptr_t get_anon_hdl(void) // file system. # ifdef __NR_memfd_create fd = syscall(__NR_memfd_create, "julia-codegen", MFD_CLOEXEC); - // jl_safe_print(f"%s: memfd %d\n", __func__, fd); + print_to_tty("%s: memfd %d\n", __func__, fd); if (check_fd_or_close(fd)) return fd; # endif @@ -162,7 +161,7 @@ static intptr_t get_anon_hdl(void) snprintf(shm_name, sizeof(shm_name), "julia-codegen-%d-%d", (int)pid, rand()); fd = shm_open(shm_name, O_RDWR | O_CREAT | O_EXCL, S_IRWXU); - // jl_safe_printf("%s: shm %d\n", __func__, fd); + print_to_tty("%s: shm %d\n", __func__, fd); if (check_fd_or_close(fd)) { shm_unlink(shm_name); return fd; @@ -171,7 +170,7 @@ static intptr_t get_anon_hdl(void) # endif snprintf(shm_name, sizeof(shm_name), "julia-codegen-%d-XXXXXX", (int)pid); fd = mkstemp(shm_name); - // jl_safe_printf("%s: mkstemp %d\n", __func__, fd); + print_to_tty("%s: mkstemp %d\n", __func__, fd); if (check_fd_or_close(fd)) { unlink(shm_name); return fd; @@ -277,9 +276,7 @@ static void *create_shared_map(size_t size, size_t offset) { void *addr = mmap(nullptr, size, PROT_READ | PROT_WRITE, MAP_SHARED, anon_hdl, offset); - if (addr == MAP_FAILED) - print_to_tty("%s: %p, %lld\n", __func__, addr, (long long)size); - // jl_safe_printf("%s: %p, %lld\n", __func__, addr, (long long)size); + print_to_tty("%s: %p, %lld\n", __func__, addr, (long long)size); assert(addr != MAP_FAILED); return addr; } @@ -292,12 +289,11 @@ static intptr_t init_shared_map() map_offset = 0; map_size = 512 * 1024 * 1024; int ret = ftruncate(anon_hdl, map_size); + print_to_tty("%s: %d, %lld\n", __func__, ret, (long long)map_size); if (ret != 0) { - print_to_tty("%s: %d, %lld\n", __func__, ret, (long long)map_size); perror(__func__); abort(); } - // jl_safe_printf("%s: %d, %lld\n", __func__, ret, (long long)map_size); return anon_hdl; } @@ -313,12 +309,11 @@ static void *alloc_shared_page(size_t size, size_t *offset, bool exec) map_size += 512 * 1024 * 1024; if (old_size != map_size) { int ret = ftruncate(anon_hdl, map_size); + print_to_tty("%s: %d, %lld\n", __func__, ret, (long long)map_size); if (ret != 0) { - print_to_tty("%s: %d, %lld\n", __func__, ret, (long long)map_size); perror(__func__); abort(); } - // jl_safe_printf("%s: %d, %lld\n", __func__, ret, (long long)map_size); } JL_UNLOCK_NOGC(&shared_map_lock); } @@ -544,6 +539,8 @@ class ROAllocator { wr_ptr = get_wr_ptr(block, ptr, size, align); } block.state |= ROBlock::Alloc; + print_to_tty("%s: %p, %p, %lld\n", + __func__, wr_ptr, ptr, (long long)size); allocations.push_back(Allocation{wr_ptr, ptr, size, false}); return wr_ptr; } @@ -570,6 +567,8 @@ class ROAllocator { ptr = wr_ptr; #else block.state = ROBlock::Alloc | ROBlock::InitAlloc; + print_to_tty("%s: %p, %p, %lld\n", + __func__, ptr, ptr, (long long)size); allocations.push_back(Allocation{ptr, ptr, size, false}); #endif return ptr; @@ -631,6 +630,7 @@ class DualMapAllocator : public ROAllocator { public: DualMapAllocator() { + print_to_tty("%s, %d\n", __func__, anon_hdl); assert(anon_hdl != -1); } void finalize() override @@ -789,6 +789,8 @@ class RTDyldMemoryManagerJL : public SectionMemoryManager { template void mapAddresses(DL &Dyld) { + if (!ro_alloc) + return; mapAddresses(Dyld, ro_alloc); mapAddresses(Dyld, exe_alloc); } diff --git a/test/choosetests.jl b/test/choosetests.jl index fc9258e881cdeb..e59f9ab0916568 100644 --- a/test/choosetests.jl +++ b/test/choosetests.jl @@ -15,25 +15,25 @@ Upon return, `tests` is a vector of fully-expanded test names, and """ -> function choosetests(choices = []) testnames = [ - "linalg", "subarray", "core", "inference", "keywordargs", "numbers", - "printf", "char", "string", "triplequote", "unicode", - "dates", "dict", "hashing", "iobuffer", "staged", - "arrayops", "tuple", "reduce", "reducedim", "random", "abstractarray", - "intfuncs", "simdloop", "vecelement", "blas", "sparse", - "bitarray", "copy", "math", "fastmath", "functional", - "operators", "path", "ccall", "parse", "loading", "bigint", - "bigfloat", "sorting", "statistics", "spawn", "backtrace", - "priorityqueue", "file", "read", "mmap", "version", "resolve", - "pollfd", "mpfr", "broadcast", "complex", "socket", - "floatapprox", "datafmt", "reflection", "regex", "float16", - "combinatorics", "sysinfo", "rounding", "ranges", "mod2pi", - "euler", "show", "lineedit", "replcompletions", "repl", - "replutil", "sets", "test", "goto", "llvmcall", "grisu", - "nullable", "meta", "stacktraces", "profile", "libgit2", "docs", - "markdown", "base64", "serialize", "misc", "threads", + # "linalg", "subarray", "core", "inference", "keywordargs", "numbers", + # "printf", "char", "string", "triplequote", "unicode", + # "dates", "dict", "hashing", "iobuffer", "staged", + # "arrayops", "tuple", "reduce", "reducedim", "random", "abstractarray", + # "intfuncs", "simdloop", "vecelement", "blas", "sparse", + # "bitarray", "copy", "math", "fastmath", "functional", + # "operators", "path", "ccall", "parse", "loading", "bigint", + # "bigfloat", "sorting", "statistics", "spawn", "backtrace", + # "priorityqueue", "file", "read", "mmap", "version", "resolve", + # "pollfd", "mpfr", "broadcast", "complex", "socket", + # "floatapprox", "datafmt", "reflection", "regex", "float16", + # "combinatorics", "sysinfo", "rounding", "ranges", "mod2pi", + # "euler", "show", "lineedit", "replcompletions", "repl", + # "replutil", "sets", "test", "goto", "llvmcall", "grisu", + # "nullable", "meta", "stacktraces", "profile", "libgit2", "docs", + # "markdown", "base64", "serialize", "misc", "threads", "enums", "cmdlineargs", "i18n", "workspace", "libdl", "int", - "checked", "intset", "floatfuncs", "compile", "parallel", "inline", - "boundscheck", "error", "ambiguous" + # "checked", "intset", "floatfuncs", "compile", "parallel", "inline", + # "boundscheck", "error", "ambiguous" ] if Base.USE_GPL_LIBS diff --git a/test/cmdlineargs.jl b/test/cmdlineargs.jl index 02df8664f54aa6..c0bb608291c4bc 100644 --- a/test/cmdlineargs.jl +++ b/test/cmdlineargs.jl @@ -1,271 +1,271 @@ # This file is a part of Julia. License is MIT: http://julialang.org/license let exename = `$(Base.julia_cmd()) --precompiled=yes` - # --version - let v = split(readstring(`$exename -v`), "julia version ")[end] - @test Base.VERSION_STRING == chomp(v) - end - @test readstring(`$exename -v`) == readstring(`$exename --version`) - - # --help - let header = "julia [switches] -- [programfile] [args...]" - @test startswith(readstring(`$exename -h`), header) - @test startswith(readstring(`$exename --help`), header) - end - - # --quiet - # This flag is indirectly tested in test/repl.jl - - # --home - @test success(`$exename -H $JULIA_HOME`) - @test success(`$exename --home=$JULIA_HOME`) - - # --eval - @test success(`$exename -e "exit(0)"`) - @test !success(`$exename -e "exit(1)"`) - @test success(`$exename --eval="exit(0)"`) - @test !success(`$exename --eval="exit(1)"`) - @test !success(`$exename -e`) - @test !success(`$exename --eval`) - - # --print - @test readstring(`$exename -E "1+1"`) == "2\n" - @test readstring(`$exename --print="1+1"`) == "2\n" - @test !success(`$exename -E`) - @test !success(`$exename --print`) - - # --post-boot - @test success(`$exename -P "exit(0)"`) - @test !success(`$exename -P "exit(1)"`) - @test success(`$exename --post-boot="exit(0)"`) - @test !success(`$exename --post-boot="exit(1)"`) - @test !success(`$exename -P`) - @test !success(`$exename --post-boot`) - - # --load - let testfile = tempname() - try - write(testfile, "testvar = :test\n") - @test split(readchomp(`$exename --load=$testfile -P "println(testvar)"`), '\n')[end] == "test" - @test split(readchomp(`$exename -P "println(testvar)" -L $testfile`), '\n')[end] == "test" - finally - rm(testfile) - end - end - # -L, --load requires an argument - @test !success(`$exename -L`) - @test !success(`$exename --load`) - - # --cpu-target - # NOTE: this test only holds true when there is a sys.{dll,dylib,so} shared library present. - if Libdl.dlopen_e(splitext(String(Base.JLOptions().image_file))[1]) != C_NULL - @test !success(`$exename -C invalidtarget --precompiled=yes`) - @test !success(`$exename --cpu-target=invalidtarget --precompiled=yes`) - else - warn("--cpu-target test not runnable") - end - - # --procs - @test readchomp(`$exename -q -p 2 -P "println(nworkers()); exit(0)"`) == "2" - @test !success(`$exename -p 0`) - @test !success(`$exename --procs=1.0`) - - # --machinefile - # this does not check that machinefile works, - # only that the filename gets correctly passed to the option struct - let fname = tempname() - touch(fname) - fname = realpath(fname) - try - @test readchomp(`$exename --machinefile $fname -e "println(String(Base.JLOptions().machinefile))"`) == fname - finally - rm(fname) - end - end - - # -i, isinteractive - @test readchomp(`$exename -E "isinteractive()"`) == "false" - @test readchomp(`$exename -E "isinteractive()" -i`) == "true" - - # --color - @test readchomp(`$exename --color=yes -E "Base.have_color"`) == "true" - @test readchomp(`$exename --color=no -E "Base.have_color"`) == "false" - @test !success(`$exename --color=false`) - - # --history-file - @test readchomp(`$exename -E "Bool(Base.JLOptions().historyfile)" --history-file=yes`) == "true" - @test readchomp(`$exename -E "Bool(Base.JLOptions().historyfile)" --history-file=no`) == "false" - # deprecated - @test readchomp(`$exename -E "Bool(Base.JLOptions().historyfile)" --no-history-file`) == "false" - @test !success(`$exename --history-file=false`) - - # --startup-file - let JL_OPTIONS_STARTUPFILE_ON = 1, - JL_OPTIONS_STARTUPFILE_OFF = 2 - @test parse(Int,readchomp(`$exename -E "Base.JLOptions().startupfile" --startup-file=yes`)) == JL_OPTIONS_STARTUPFILE_ON - @test parse(Int,readchomp(`$exename -E "Base.JLOptions().startupfile" --startup-file=no`)) == JL_OPTIONS_STARTUPFILE_OFF - end - @test !success(`$exename --startup-file=false`) - - # --code-coverage - @test readchomp(`$exename -E "Bool(Base.JLOptions().code_coverage)"`) == "false" - @test readchomp(`$exename -E "Bool(Base.JLOptions().code_coverage)" --code-coverage=none`) == "false" - - @test readchomp(`$exename -E "Bool(Base.JLOptions().code_coverage)" --code-coverage`) == "true" - @test readchomp(`$exename -E "Bool(Base.JLOptions().code_coverage)" --code-coverage=user`) == "true" - - # --track-allocation - @test readchomp(`$exename -E "Bool(Base.JLOptions().malloc_log)"`) == "false" - @test readchomp(`$exename -E "Bool(Base.JLOptions().malloc_log)" --track-allocation=none`) == "false" - - @test readchomp(`$exename -E "Bool(Base.JLOptions().malloc_log)" --track-allocation`) == "true" - @test readchomp(`$exename -E "Bool(Base.JLOptions().malloc_log)" --track-allocation=user`) == "true" - - # --optimize - @test readchomp(`$exename -E "Base.JLOptions().opt_level"`) == "2" - @test readchomp(`$exename -E "Base.JLOptions().opt_level" -O`) == "3" - @test readchomp(`$exename -E "Base.JLOptions().opt_level" --optimize`) == "3" - @test readchomp(`$exename -E "Base.JLOptions().opt_level" -O0`) == "0" - - # --check-bounds - let JL_OPTIONS_CHECK_BOUNDS_DEFAULT = 0, - JL_OPTIONS_CHECK_BOUNDS_ON = 1, - JL_OPTIONS_CHECK_BOUNDS_OFF = 2 - @test parse(Int,readchomp(`$exename -E "Int(Base.JLOptions().check_bounds)"`)) == JL_OPTIONS_CHECK_BOUNDS_DEFAULT - @test parse(Int,readchomp(`$exename -E "Int(Base.JLOptions().check_bounds)" --check-bounds=yes`)) == JL_OPTIONS_CHECK_BOUNDS_ON - @test parse(Int,readchomp(`$exename -E "Int(Base.JLOptions().check_bounds)" --check-bounds=no`)) == JL_OPTIONS_CHECK_BOUNDS_OFF - end - # check-bounds takes yes/no as argument - @test !success(`$exename -E "exit(0)" --check-bounds=false`) - - # --depwarn - @test readchomp(`$exename --depwarn=no -E "Base.syntax_deprecation_warnings(true)"`) == "false" - @test readchomp(`$exename --depwarn=yes -E "Base.syntax_deprecation_warnings(false)"`) == "true" - @test !success(`$exename --depwarn=false`) - # test deprecated syntax - @test !success(`$exename -e "foo (x::Int) = x * x" --depwarn=error`) - # test deprecated method - @test !success(`$exename -e " - foo() = :foo; bar() = :bar - @deprecate foo() bar() - foo() - " --depwarn=error`) - - # test deprecated bindings, #13269 - let code = """ - module Foo - import Base: @deprecate_binding - - const NotDeprecated = true - @deprecate_binding Deprecated NotDeprecated - end - - Foo.Deprecated - """ - - @test !success(`$exename -E "$code" --depwarn=error`) - - let out = Pipe(), - proc = spawn(pipeline(`$exename -E "$code" --depwarn=yes`, stderr=out)), - output = @async readchomp(out) - - close(out.in) - wait(proc) - @test success(proc) - @test wait(output) == "WARNING: Foo.Deprecated is deprecated.\n likely near no file:5" - end - - let out = Pipe(), - proc = spawn(pipeline(`$exename -E "$code" --depwarn=no`, stderr=out)) - output = @async readstring(out) - - wait(proc) - close(out.in) - @test success(proc) - @test wait(output) == "" - end - end - - # --inline - @test readchomp(`$exename -E "Bool(Base.JLOptions().can_inline)"`) == "true" - @test readchomp(`$exename --inline=yes -E "Bool(Base.JLOptions().can_inline)"`) == "true" - @test readchomp(`$exename --inline=no -E "Bool(Base.JLOptions().can_inline)"`) == "false" - # --inline takes yes/no as arugment - @test !success(`$exename --inline=false`) - - # --fast-math - let JL_OPTIONS_FAST_MATH_DEFAULT = 0, - JL_OPTIONS_FAST_MATH_ON = 1, - JL_OPTIONS_FAST_MATH_OFF = 2 - @test parse(Int,readchomp(`$exename -E "Int(Base.JLOptions().fast_math)"`)) == JL_OPTIONS_FAST_MATH_DEFAULT - @test parse(Int,readchomp(`$exename --math-mode=user -E "Int(Base.JLOptions().fast_math)"`)) == JL_OPTIONS_FAST_MATH_DEFAULT - @test parse(Int,readchomp(`$exename --math-mode=ieee -E "Int(Base.JLOptions().fast_math)"`)) == JL_OPTIONS_FAST_MATH_OFF - @test parse(Int,readchomp(`$exename --math-mode=fast -E "Int(Base.JLOptions().fast_math)"`)) == JL_OPTIONS_FAST_MATH_ON - end - - # --worker takes default / custom as arugment (default/custom arguments tested in test/parallel.jl, test/examples.jl) - @test !success(`$exename --worker=true`) - - escape(str) = replace(str, "\\", "\\\\") - - # test passing arguments - let testfile = tempname() - try - # write a julia source file that just prints ARGS to STDOUT - write(testfile, """ - println(ARGS) - """) - @test readchomp(`$exename $testfile foo -bar --baz`) == "String[\"foo\",\"-bar\",\"--baz\"]" - @test readchomp(`$exename $testfile -- foo -bar --baz`) == "String[\"foo\",\"-bar\",\"--baz\"]" - @test readchomp(`$exename -L $testfile -e 'exit(0)' -- foo -bar --baz`) == "String[\"foo\",\"-bar\",\"--baz\"]" - @test split(readchomp(`$exename -L $testfile $testfile`), '\n') == ["String[\"$(escape(testfile))\"]", "String[]"] - @test !success(`$exename --foo $testfile`) - @test !success(`$exename -L $testfile -e 'exit(0)' -- foo -bar -- baz`) - finally - rm(testfile) - end - end - - # test the script name - let a = tempname(), b = tempname() - try - write(a, """ - println(@__FILE__) - println(PROGRAM_FILE) - println(length(ARGS)) - include(\"$(escape(b))\") - """) - write(b, """ - println(@__FILE__) - println(PROGRAM_FILE) - println(length(ARGS)) - """) - @test split(readchomp(`$exename $a`), '\n') == ["$a", "$a", "0", "$b", "$a", "0"] - @test split(readchomp(`$exename -L $b -e 'exit(0)'`), '\n') == ["$(realpath(b))", "", "0"] - @test split(readchomp(`$exename -L $b $a`), '\n') == ["$(realpath(b))", "", "1", "$a", "$a", "0", "$b", "$a", "0"] - finally - rm(a) - rm(b) - end - end - - # issue #10562 - @test readchomp(`$exename -e 'println(ARGS);' ''`) == "String[\"\"]" - - # issue #12679 - extrapath = is_windows() ? joinpath(JULIA_HOME, "..", "Git", "usr", "bin") * ";" : "" - withenv("PATH" => extrapath * ENV["PATH"]) do - @test readchomp(pipeline(ignorestatus(`$exename --startup-file=no --compile=yes -foo`),stderr=`cat`)) == "ERROR: unknown option `-o`" - @test readchomp(pipeline(ignorestatus(`$exename --startup-file=no -p`),stderr=`cat`)) == "ERROR: option `-p/--procs` is missing an argument" - @test readchomp(pipeline(ignorestatus(`$exename --startup-file=no --inline`),stderr=`cat`)) == "ERROR: option `--inline` is missing an argument" - @test readchomp(pipeline(ignorestatus(`$exename --startup-file=no -e "@show ARGS" -now -- julia RUN.jl`),stderr=`cat`)) == "ERROR: unknown option `-n`" - end - - # --compilecache={yes|no} - @test readchomp(`$exename -E "Bool(Base.JLOptions().use_compilecache)"`) == "true" - @test readchomp(`$exename --compilecache=yes -E "Bool(Base.JLOptions().use_compilecache)"`) == "true" - @test readchomp(`$exename --compilecache=no -E "Bool(Base.JLOptions().use_compilecache)"`) == "false" - @test !success(`$exename --compilecache=foo -e "exit(0)"`) + # # --version + # let v = split(readstring(`$exename -v`), "julia version ")[end] + # @test Base.VERSION_STRING == chomp(v) + # end + # @test readstring(`$exename -v`) == readstring(`$exename --version`) + + # # --help + # let header = "julia [switches] -- [programfile] [args...]" + # @test startswith(readstring(`$exename -h`), header) + # @test startswith(readstring(`$exename --help`), header) + # end + + # # --quiet + # # This flag is indirectly tested in test/repl.jl + + # # --home + # @test success(`$exename -H $JULIA_HOME`) + # @test success(`$exename --home=$JULIA_HOME`) + + # # --eval + # @test success(`$exename -e "exit(0)"`) + # @test !success(`$exename -e "exit(1)"`) + # @test success(`$exename --eval="exit(0)"`) + # @test !success(`$exename --eval="exit(1)"`) + # @test !success(`$exename -e`) + # @test !success(`$exename --eval`) + + # # --print + # @test readstring(`$exename -E "1+1"`) == "2\n" + # @test readstring(`$exename --print="1+1"`) == "2\n" + # @test !success(`$exename -E`) + # @test !success(`$exename --print`) + + # # --post-boot + # @test success(`$exename -P "exit(0)"`) + # @test !success(`$exename -P "exit(1)"`) + # @test success(`$exename --post-boot="exit(0)"`) + # @test !success(`$exename --post-boot="exit(1)"`) + # @test !success(`$exename -P`) + # @test !success(`$exename --post-boot`) + + # # --load + # let testfile = tempname() + # try + # write(testfile, "testvar = :test\n") + # @test split(readchomp(`$exename --load=$testfile -P "println(testvar)"`), '\n')[end] == "test" + # @test split(readchomp(`$exename -P "println(testvar)" -L $testfile`), '\n')[end] == "test" + # finally + # rm(testfile) + # end + # end + # # -L, --load requires an argument + # @test !success(`$exename -L`) + # @test !success(`$exename --load`) + + # # --cpu-target + # # NOTE: this test only holds true when there is a sys.{dll,dylib,so} shared library present. + # if Libdl.dlopen_e(splitext(String(Base.JLOptions().image_file))[1]) != C_NULL + # @test !success(`$exename -C invalidtarget --precompiled=yes`) + # @test !success(`$exename --cpu-target=invalidtarget --precompiled=yes`) + # else + # warn("--cpu-target test not runnable") + # end + + # # --procs + # @test readchomp(`$exename -q -p 2 -P "println(nworkers()); exit(0)"`) == "2" + # @test !success(`$exename -p 0`) + # @test !success(`$exename --procs=1.0`) + + # # --machinefile + # # this does not check that machinefile works, + # # only that the filename gets correctly passed to the option struct + # let fname = tempname() + # touch(fname) + # fname = realpath(fname) + # try + # @test readchomp(`$exename --machinefile $fname -e "println(String(Base.JLOptions().machinefile))"`) == fname + # finally + # rm(fname) + # end + # end + + # # -i, isinteractive + # @test readchomp(`$exename -E "isinteractive()"`) == "false" + # @test readchomp(`$exename -E "isinteractive()" -i`) == "true" + + # # --color + # @test readchomp(`$exename --color=yes -E "Base.have_color"`) == "true" + # @test readchomp(`$exename --color=no -E "Base.have_color"`) == "false" + # @test !success(`$exename --color=false`) + + # # --history-file + # @test readchomp(`$exename -E "Bool(Base.JLOptions().historyfile)" --history-file=yes`) == "true" + # @test readchomp(`$exename -E "Bool(Base.JLOptions().historyfile)" --history-file=no`) == "false" + # # deprecated + # @test readchomp(`$exename -E "Bool(Base.JLOptions().historyfile)" --no-history-file`) == "false" + # @test !success(`$exename --history-file=false`) + + # # --startup-file + # let JL_OPTIONS_STARTUPFILE_ON = 1, + # JL_OPTIONS_STARTUPFILE_OFF = 2 + # @test parse(Int,readchomp(`$exename -E "Base.JLOptions().startupfile" --startup-file=yes`)) == JL_OPTIONS_STARTUPFILE_ON + # @test parse(Int,readchomp(`$exename -E "Base.JLOptions().startupfile" --startup-file=no`)) == JL_OPTIONS_STARTUPFILE_OFF + # end + # @test !success(`$exename --startup-file=false`) + + # # --code-coverage + # @test readchomp(`$exename -E "Bool(Base.JLOptions().code_coverage)"`) == "false" + # @test readchomp(`$exename -E "Bool(Base.JLOptions().code_coverage)" --code-coverage=none`) == "false" + + # @test readchomp(`$exename -E "Bool(Base.JLOptions().code_coverage)" --code-coverage`) == "true" + # @test readchomp(`$exename -E "Bool(Base.JLOptions().code_coverage)" --code-coverage=user`) == "true" + + # # --track-allocation + # @test readchomp(`$exename -E "Bool(Base.JLOptions().malloc_log)"`) == "false" + # @test readchomp(`$exename -E "Bool(Base.JLOptions().malloc_log)" --track-allocation=none`) == "false" + + # @test readchomp(`$exename -E "Bool(Base.JLOptions().malloc_log)" --track-allocation`) == "true" + # @test readchomp(`$exename -E "Bool(Base.JLOptions().malloc_log)" --track-allocation=user`) == "true" + + # # --optimize + # @test readchomp(`$exename -E "Base.JLOptions().opt_level"`) == "2" + # @test readchomp(`$exename -E "Base.JLOptions().opt_level" -O`) == "3" + # @test readchomp(`$exename -E "Base.JLOptions().opt_level" --optimize`) == "3" + # @test readchomp(`$exename -E "Base.JLOptions().opt_level" -O0`) == "0" + + # # --check-bounds + # let JL_OPTIONS_CHECK_BOUNDS_DEFAULT = 0, + # JL_OPTIONS_CHECK_BOUNDS_ON = 1, + # JL_OPTIONS_CHECK_BOUNDS_OFF = 2 + # @test parse(Int,readchomp(`$exename -E "Int(Base.JLOptions().check_bounds)"`)) == JL_OPTIONS_CHECK_BOUNDS_DEFAULT + # @test parse(Int,readchomp(`$exename -E "Int(Base.JLOptions().check_bounds)" --check-bounds=yes`)) == JL_OPTIONS_CHECK_BOUNDS_ON + # @test parse(Int,readchomp(`$exename -E "Int(Base.JLOptions().check_bounds)" --check-bounds=no`)) == JL_OPTIONS_CHECK_BOUNDS_OFF + # end + # # check-bounds takes yes/no as argument + # @test !success(`$exename -E "exit(0)" --check-bounds=false`) + + # # --depwarn + # @test readchomp(`$exename --depwarn=no -E "Base.syntax_deprecation_warnings(true)"`) == "false" + # @test readchomp(`$exename --depwarn=yes -E "Base.syntax_deprecation_warnings(false)"`) == "true" + # @test !success(`$exename --depwarn=false`) + # # test deprecated syntax + # @test !success(`$exename -e "foo (x::Int) = x * x" --depwarn=error`) + # # test deprecated method + # @test !success(`$exename -e " + # foo() = :foo; bar() = :bar + # @deprecate foo() bar() + # foo() + # " --depwarn=error`) + + # # test deprecated bindings, #13269 + # let code = """ + # module Foo + # import Base: @deprecate_binding + + # const NotDeprecated = true + # @deprecate_binding Deprecated NotDeprecated + # end + + # Foo.Deprecated + # """ + + # @test !success(`$exename -E "$code" --depwarn=error`) + + # let out = Pipe(), + # proc = spawn(pipeline(`$exename -E "$code" --depwarn=yes`, stderr=out)), + # output = @async readchomp(out) + + # close(out.in) + # wait(proc) + # @test success(proc) + # @test wait(output) == "WARNING: Foo.Deprecated is deprecated.\n likely near no file:5" + # end + + # let out = Pipe(), + # proc = spawn(pipeline(`$exename -E "$code" --depwarn=no`, stderr=out)) + # output = @async readstring(out) + + # wait(proc) + # close(out.in) + # @test success(proc) + # @test wait(output) == "" + # end + # end + + # # --inline + # @test readchomp(`$exename -E "Bool(Base.JLOptions().can_inline)"`) == "true" + # @test readchomp(`$exename --inline=yes -E "Bool(Base.JLOptions().can_inline)"`) == "true" + # @test readchomp(`$exename --inline=no -E "Bool(Base.JLOptions().can_inline)"`) == "false" + # # --inline takes yes/no as arugment + # @test !success(`$exename --inline=false`) + + # # --fast-math + # let JL_OPTIONS_FAST_MATH_DEFAULT = 0, + # JL_OPTIONS_FAST_MATH_ON = 1, + # JL_OPTIONS_FAST_MATH_OFF = 2 + # @test parse(Int,readchomp(`$exename -E "Int(Base.JLOptions().fast_math)"`)) == JL_OPTIONS_FAST_MATH_DEFAULT + # @test parse(Int,readchomp(`$exename --math-mode=user -E "Int(Base.JLOptions().fast_math)"`)) == JL_OPTIONS_FAST_MATH_DEFAULT + # @test parse(Int,readchomp(`$exename --math-mode=ieee -E "Int(Base.JLOptions().fast_math)"`)) == JL_OPTIONS_FAST_MATH_OFF + # @test parse(Int,readchomp(`$exename --math-mode=fast -E "Int(Base.JLOptions().fast_math)"`)) == JL_OPTIONS_FAST_MATH_ON + # end + + # # --worker takes default / custom as arugment (default/custom arguments tested in test/parallel.jl, test/examples.jl) + # @test !success(`$exename --worker=true`) + + # escape(str) = replace(str, "\\", "\\\\") + + # # test passing arguments + # let testfile = tempname() + # try + # # write a julia source file that just prints ARGS to STDOUT + # write(testfile, """ + # println(ARGS) + # """) + # @test readchomp(`$exename $testfile foo -bar --baz`) == "String[\"foo\",\"-bar\",\"--baz\"]" + # @test readchomp(`$exename $testfile -- foo -bar --baz`) == "String[\"foo\",\"-bar\",\"--baz\"]" + # @test readchomp(`$exename -L $testfile -e 'exit(0)' -- foo -bar --baz`) == "String[\"foo\",\"-bar\",\"--baz\"]" + # @test split(readchomp(`$exename -L $testfile $testfile`), '\n') == ["String[\"$(escape(testfile))\"]", "String[]"] + # @test !success(`$exename --foo $testfile`) + # @test !success(`$exename -L $testfile -e 'exit(0)' -- foo -bar -- baz`) + # finally + # rm(testfile) + # end + # end + + # # test the script name + # let a = tempname(), b = tempname() + # try + # write(a, """ + # println(@__FILE__) + # println(PROGRAM_FILE) + # println(length(ARGS)) + # include(\"$(escape(b))\") + # """) + # write(b, """ + # println(@__FILE__) + # println(PROGRAM_FILE) + # println(length(ARGS)) + # """) + # @test split(readchomp(`$exename $a`), '\n') == ["$a", "$a", "0", "$b", "$a", "0"] + # @test split(readchomp(`$exename -L $b -e 'exit(0)'`), '\n') == ["$(realpath(b))", "", "0"] + # @test split(readchomp(`$exename -L $b $a`), '\n') == ["$(realpath(b))", "", "1", "$a", "$a", "0", "$b", "$a", "0"] + # finally + # rm(a) + # rm(b) + # end + # end + + # # issue #10562 + # @test readchomp(`$exename -e 'println(ARGS);' ''`) == "String[\"\"]" + + # # issue #12679 + # extrapath = is_windows() ? joinpath(JULIA_HOME, "..", "Git", "usr", "bin") * ";" : "" + # withenv("PATH" => extrapath * ENV["PATH"]) do + # @test readchomp(pipeline(ignorestatus(`$exename --startup-file=no --compile=yes -foo`),stderr=`cat`)) == "ERROR: unknown option `-o`" + # @test readchomp(pipeline(ignorestatus(`$exename --startup-file=no -p`),stderr=`cat`)) == "ERROR: option `-p/--procs` is missing an argument" + # @test readchomp(pipeline(ignorestatus(`$exename --startup-file=no --inline`),stderr=`cat`)) == "ERROR: option `--inline` is missing an argument" + # @test readchomp(pipeline(ignorestatus(`$exename --startup-file=no -e "@show ARGS" -now -- julia RUN.jl`),stderr=`cat`)) == "ERROR: unknown option `-n`" + # end + + # # --compilecache={yes|no} + # @test readchomp(`$exename -E "Bool(Base.JLOptions().use_compilecache)"`) == "true" + # @test readchomp(`$exename --compilecache=yes -E "Bool(Base.JLOptions().use_compilecache)"`) == "true" + # @test readchomp(`$exename --compilecache=no -E "Bool(Base.JLOptions().use_compilecache)"`) == "false" + # @test !success(`$exename --compilecache=foo -e "exit(0)"`) # issue #12671, starting from a non-directory # rm(dir) fails on windows with Permission denied @@ -274,8 +274,10 @@ let exename = `$(Base.julia_cmd()) --precompiled=yes` testdir = mktempdir() cd(testdir) do rm(testdir) - run(`$exename -e "exit(0)"`) - @test success(`$exename -e "exit(0)"`) + withenv("JULIA_DEBUG_CGMEMMGR"=>"1") do + run(`$exename -e "exit(0)"`) + @test success(`$exename -e "exit(0)"`) + end end end end