Skip to content

Commit 742a4a0

Browse files
authored
Merge pull request #35539 from JuliaLang/kf/stdlibtests
Test suite tweaks for rr
2 parents 676ccf4 + 7a3c153 commit 742a4a0

File tree

10 files changed

+74
-13
lines changed

10 files changed

+74
-13
lines changed

base/options.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ struct JLOptions
4545
image_file_specified::Int8
4646
warn_scope::Int8
4747
image_codegen::Int8
48+
rr_detach::Int8
4849
end
4950

5051
# This runs early in the sysimage != is not defined yet

src/jlapi.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,17 @@ static void lock_low32(void)
663663
// Actual definition in `ast.c`
664664
void jl_lisp_prompt(void);
665665

666+
static void rr_detach_teleport(void) {
667+
#ifdef _OS_LINUX_
668+
#define RR_CALL_BASE 1000
669+
#define SYS_rrcall_detach_teleport (RR_CALL_BASE + 9)
670+
int err = syscall(SYS_rrcall_detach_teleport, 0, 0, 0, 0, 0, 0);
671+
if (err < 0 || jl_running_under_rr(1)) {
672+
jl_error("Failed to detach from rr session");
673+
}
674+
#endif
675+
}
676+
666677
JL_DLLEXPORT int repl_entrypoint(int argc, char *argv[])
667678
{
668679
// no-op on Windows, note that the caller must have already converted
@@ -678,7 +689,19 @@ JL_DLLEXPORT int repl_entrypoint(int argc, char *argv[])
678689
memmove(&argv[1], &argv[2], (argc-2)*sizeof(void*));
679690
argc--;
680691
}
692+
char **orig_argv = argv;
681693
jl_parse_opts(&argc, (char***)&argv);
694+
695+
// The parent process requested that we detach from the rr session.
696+
// N.B.: In a perfect world, we would only do this for the portion of
697+
// the execution where we actually need to exclude rr (e.g. because we're
698+
// testing for the absence of a memory-model-dependent bug).
699+
if (jl_options.rr_detach && jl_running_under_rr(0)) {
700+
rr_detach_teleport();
701+
execv("/proc/self/exe", orig_argv);
702+
jl_error("Failed to self-execute");
703+
}
704+
682705
julia_init(jl_options.image_file_specified ? JL_IMAGE_CWD : JL_IMAGE_JULIA_HOME);
683706
if (lisp_prompt) {
684707
jl_get_ptls_states()->world_age = jl_get_world_counter();

src/jloptions.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ jl_options_t jl_options = { 0, // quiet
7575
0, // image_file_specified
7676
JL_OPTIONS_WARN_SCOPE_ON, // ambiguous scope warning
7777
0, // image-codegen
78+
0, // rr-detach
7879
};
7980

8081
static const char usage[] = "julia [switches] -- [programfile] [args...]\n";
@@ -203,6 +204,7 @@ JL_DLLEXPORT void jl_parse_opts(int *argcp, char ***argvp)
203204
opt_project,
204205
opt_bug_report,
205206
opt_image_codegen,
207+
opt_rr_detach,
206208
};
207209
static const char* const shortopts = "+vhqH:e:E:L:J:C:it:p:O:g:";
208210
static const struct option longopts[] = {
@@ -254,6 +256,7 @@ JL_DLLEXPORT void jl_parse_opts(int *argcp, char ***argvp)
254256
{ "bind-to", required_argument, 0, opt_bind_to },
255257
{ "lisp", no_argument, 0, 1 },
256258
{ "image-codegen", no_argument, 0, opt_image_codegen },
259+
{ "rr-detach", no_argument, 0, opt_rr_detach },
257260
{ 0, 0, 0, 0 }
258261
};
259262

@@ -655,6 +658,9 @@ JL_DLLEXPORT void jl_parse_opts(int *argcp, char ***argvp)
655658
case opt_image_codegen:
656659
jl_options.image_codegen = 1;
657660
break;
661+
case opt_rr_detach:
662+
jl_options.rr_detach = 1;
663+
break;
658664
default:
659665
jl_errorf("julia: unhandled option -- %c\n"
660666
"This is a bug, please report it.", c);

src/julia.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1957,6 +1957,7 @@ typedef struct {
19571957
int8_t image_file_specified;
19581958
int8_t warn_scope;
19591959
int8_t image_codegen;
1960+
int8_t rr_detach;
19601961
} jl_options_t;
19611962

19621963
extern JL_DLLEXPORT jl_options_t jl_options;

src/julia_internal.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ void JL_UV_LOCK(void);
8383
extern "C" {
8484
#endif
8585

86+
int jl_running_under_rr(int recheck);
87+
8688
//--------------------------------------------------
8789
// timers
8890
// Returns time in nanosec

src/partr.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -274,14 +274,14 @@ JL_DLLEXPORT int jl_enqueue_task(jl_task_t *task)
274274
}
275275

276276

277-
static int running_under_rr(void)
277+
int jl_running_under_rr(int recheck)
278278
{
279279
#ifdef _OS_LINUX_
280280
#define RR_CALL_BASE 1000
281281
#define SYS_rrcall_check_presence (RR_CALL_BASE + 8)
282282
static int checked_running_under_rr = 0;
283283
static int is_running_under_rr = 0;
284-
if (!checked_running_under_rr) {
284+
if (!checked_running_under_rr || recheck) {
285285
int ret = syscall(SYS_rrcall_check_presence, 0, 0, 0, 0, 0, 0);
286286
if (ret == -1) {
287287
// Should always be ENOSYS, but who knows what people do for
@@ -311,7 +311,7 @@ static int sleep_check_after_threshold(uint64_t *start_cycles)
311311
* scheduling logic from switching to other threads. Just don't bother
312312
* trying to wait here
313313
*/
314-
if (running_under_rr())
314+
if (jl_running_under_rr(0))
315315
return 1;
316316
if (!(*start_cycles)) {
317317
*start_cycles = jl_hrtime();

stdlib/FileWatching/test/runtests.jl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,14 @@ for i in 1:n
2323
end
2424
Ctype = Sys.iswindows() ? Ptr{Cvoid} : Cint
2525
FDmax = Sys.iswindows() ? 0x7fff : (n + 60) # expectations on reasonable values
26-
@test 0 <= Int(Base.cconvert(Ctype, pipe_fds[i][1])) <= FDmax
27-
@test 0 <= Int(Base.cconvert(Ctype, pipe_fds[i][2])) <= FDmax
26+
fd_in_limits =
27+
0 <= Int(Base.cconvert(Ctype, pipe_fds[i][1])) <= FDmax &&
28+
0 <= Int(Base.cconvert(Ctype, pipe_fds[i][2])) <= FDmax
29+
# Dump out what file descriptors are open for easier debugging of failure modes
30+
if !fd_in_limits && Sys.islinux()
31+
run(`ls -la /proc/$(getpid())/fd`)
32+
end
33+
@test fd_in_limits
2834
end
2935

3036
function pfd_tst_reads(idx, intvl)

stdlib/SharedArrays/test/runtests.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
using Test, Distributed, SharedArrays, Random
44
include(joinpath(Sys.BINDIR, "..", "share", "julia", "test", "testenv.jl"))
55

6-
addprocs_with_testenv(4)
6+
# These processes explicitly want to share memory, we can't have
7+
# them in separate rr sessions
8+
addprocs_with_testenv(4; rr_allowed=false)
79
@test nprocs() == 5
810

911
@everywhere using Test, SharedArrays

test/testenv.jl

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,16 @@ if !@isdefined(testenv_defined)
2626
const test_exename = popfirst!(test_exeflags.exec)
2727
end
2828

29-
addprocs_with_testenv(X; kwargs...) = addprocs(X; exename=test_exename, exeflags=test_exeflags, kwargs...)
29+
if haskey(ENV, "JULIA_RR")
30+
const rr_exename = `$(Base.shell_split(ENV["JULIA_RR"]))`
31+
else
32+
const rr_exename = ``
33+
end
34+
35+
function addprocs_with_testenv(X; rr_allowed=true, kwargs...)
36+
exename = rr_allowed ? `$rr_exename $test_exename` : test_exename
37+
addprocs(X; exename=exename, exeflags=test_exeflags, kwargs...)
38+
end
3039

3140
const curmod = @__MODULE__
3241
const curmod_name = fullname(curmod)

test/threads.jl

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,27 @@
11
# This file is a part of Julia. License is MIT: https://julialang.org/license
22

3-
let cmd = `$(Base.julia_cmd()) --depwarn=error --startup-file=no threads_exec.jl`
3+
using Test
4+
5+
let cmd = `$(Base.julia_cmd()) --depwarn=error --rr-detach --startup-file=no threads_exec.jl`
46
for test_nthreads in (1, 2, 4, 4) # run once to try single-threaded mode, then try a couple times to trigger bad races
5-
run(pipeline(setenv(cmd, "JULIA_NUM_THREADS" => test_nthreads), stdout = stdout, stderr = stderr))
7+
new_env = copy(ENV)
8+
new_env["JULIA_NUM_THREADS"] = string(test_nthreads)
9+
run(pipeline(setenv(cmd, new_env), stdout = stdout, stderr = stderr))
610
end
711
end
812

913
# issue #34415 - make sure external affinity settings work
10-
if Sys.islinux() && Sys.CPU_THREADS > 1 && Sys.which("taskset") !== nothing
11-
run_with_affinity(spec) = readchomp(`taskset -c $spec $(Base.julia_cmd()) -e "run(\`taskset -p \$(getpid())\`)"`)
12-
@test endswith(run_with_affinity("1"), "2")
13-
@test endswith(run_with_affinity("0,1"), "3")
14+
const SYS_rrcall_check_presence = 1008
15+
running_under_rr() = 0 == ccall(:syscall, Int,
16+
(Int, Int, Int, Int, Int, Int, Int),
17+
SYS_rrcall_check_presence, 0, 0, 0, 0, 0, 0)
18+
19+
if Sys.islinux()
20+
if Sys.CPU_THREADS > 1 && Sys.which("taskset") !== nothing && !running_under_rr()
21+
run_with_affinity(spec) = readchomp(`taskset -c $spec $(Base.julia_cmd()) -e "run(\`taskset -p \$(getpid())\`)"`)
22+
@test endswith(run_with_affinity("1"), "2")
23+
@test endswith(run_with_affinity("0,1"), "3")
24+
end
1425
end
1526

1627
# issue #34769

0 commit comments

Comments
 (0)