Skip to content

Commit b72c1cf

Browse files
authored
Merge pull request #1131 from robgjansen/phold-timerfd-tests
Use test macros in phold and timerfd tests, fix bugs
2 parents 7c0c688 + 8946c6e commit b72c1cf

13 files changed

Lines changed: 211 additions & 301 deletions

File tree

src/main/host/descriptor/timer.c

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,14 @@ static SimulationTime _timer_timespecToSimTime(const struct timespec* config, gb
149149
/* the time that was passed in represents an emulated time, so we need to adjust */
150150
EmulatedTime emNanoSecs = (EmulatedTime)(config->tv_sec * SIMTIME_ONE_SECOND);
151151
emNanoSecs += (EmulatedTime) config->tv_nsec;
152-
simNanoSecs = EMULATED_TIME_TO_SIMULATED_TIME(emNanoSecs);
152+
/* If the emulated time passed in by the plugin is before the time we use as the
153+
* start of the simulation (i.e., EMULATED_TIME_OFFSET), then we use t=0 as
154+
* a proxy for "some time in the past". */
155+
if(emNanoSecs >= EMULATED_TIME_OFFSET) {
156+
simNanoSecs = EMULATED_TIME_TO_SIMULATED_TIME(emNanoSecs);
157+
} else {
158+
simNanoSecs = 0;
159+
}
153160
} else {
154161
/* the config is a relative time, so we just use simtime directly */
155162
simNanoSecs = (SimulationTime)(config->tv_sec * SIMTIME_ONE_SECOND);
@@ -210,6 +217,7 @@ static void _timer_scheduleNewExpireEvent(Timer* timer) {
210217
* or disarmed the timer in the meantime. This prevents queueing the task indefinitely. */
211218
delay = MIN(delay, SIMTIME_ONE_SECOND);
212219

220+
debug("Scheduling timer expiration task for %"G_GUINT64_FORMAT" nanoseconds", delay);
213221
worker_scheduleTask(task, delay);
214222
task_unref(task);
215223

@@ -223,7 +231,7 @@ static void _timer_expire(Timer* timer, gpointer data) {
223231
/* this is a task callback event */
224232

225233
guint expireID = GPOINTER_TO_UINT(data);
226-
debug("timer fd %i expired; isClosed=%i expireID=%u minValidExpireID=%u",
234+
debug("timer fd %i expire check; isClosed=%i expireID=%u minValidExpireID=%u",
227235
timer->super.handle, timer->isClosed, expireID,
228236
timer->minValidExpireID);
229237

@@ -273,10 +281,9 @@ static void _timer_arm(Timer* timer, const struct itimerspec *config, gint flags
273281
SimulationTime now = worker_getCurrentTime();
274282
if(timer->nextExpireTime >= now) {
275283
_timer_scheduleNewExpireEvent(timer);
284+
debug("timer fd %i armed to expire in %"G_GUINT64_FORMAT" nanos",
285+
timer->super.handle, timer->nextExpireTime - now);
276286
}
277-
278-
debug("timer fd %i armed to expire in %"G_GUINT64_FORMAT" nanos",
279-
timer->super.handle, timer->nextExpireTime - now);
280287
}
281288

282289
static gboolean _timer_timeIsValid(const struct timespec* config) {
@@ -320,6 +327,10 @@ gint timer_setTime(Timer* timer, gint flags,
320327
/* always disarm to invalidate old expire events */
321328
_timer_disarm(timer);
322329

330+
/* settings were modified, reset expire count and readability */
331+
timer->expireCountSinceLastSet = 0;
332+
descriptor_adjustStatus(&(timer->super), STATUS_DESCRIPTOR_READABLE, FALSE);
333+
323334
/* now set the new times as requested */
324335
if(new_value->it_value.tv_sec > 0 || new_value->it_value.tv_nsec > 0) {
325336
/* the man page does not specify what to do if it_value says
@@ -329,10 +340,6 @@ gint timer_setTime(Timer* timer, gint flags,
329340
_timer_arm(timer, new_value, flags);
330341
}
331342

332-
/* settings were modified, reset expire count and readability */
333-
timer->expireCountSinceLastSet = 0;
334-
descriptor_adjustStatus(&(timer->super), STATUS_DESCRIPTOR_READABLE, FALSE);
335-
336343
return 0;
337344
}
338345

src/test/CMakeLists.txt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ endmacro()
4545
## example: add_shadow_tests(BASENAME bind METHODS ptrace preload LOGLEVEL debug ARGS --pin-cpus)
4646
## will create two tests named bind-shadow-ptrace and bind-shadow-preload
4747
macro(add_shadow_tests)
48-
cmake_parse_arguments(SHADOW_TEST "" "BASENAME;LOGLEVEL" "METHODS;ARGS;CONFIGURATIONS" ${ARGN})
48+
cmake_parse_arguments(SHADOW_TEST "" "BASENAME;LOGLEVEL" "METHODS;ARGS;CONFIGURATIONS;PROPERTIES" ${ARGN})
4949

5050
if(NOT DEFINED SHADOW_TEST_LOGLEVEL)
5151
set(SHADOW_TEST_LOGLEVEL "debug")
@@ -84,6 +84,10 @@ macro(add_shadow_tests)
8484
set_property(TEST ${SHADOW_TEST_NAME} PROPERTY FAIL_REGULAR_EXPRESSION "main error code '.*' for process")
8585
set_property(TEST ${SHADOW_TEST_NAME} PROPERTY ENVIRONMENT "RUST_BACKTRACE=1")
8686

87+
if(DEFINED SHADOW_TEST_PROPERTIES)
88+
set_tests_properties(${SHADOW_TEST_NAME} PROPERTIES ${SHADOW_TEST_PROPERTIES})
89+
endif()
90+
8791
set(ALL_SHADOW_TESTS "${ALL_SHADOW_TESTS}" PARENT_SCOPE)
8892
list(APPEND ALL_SHADOW_TESTS ${SHADOW_TEST_NAME})
8993
endforeach()
@@ -121,6 +125,8 @@ add_subdirectory(timerfd)
121125
add_subdirectory(udp)
122126
add_subdirectory(unistd)
123127

128+
list(LENGTH ALL_SHADOW_TESTS ALL_SHADOW_TESTS_LENGTH)
129+
message(STATUS "Configured to build ${ALL_SHADOW_TESTS_LENGTH} Shadow tests.")
124130
message(STATUS "ALL_SHADOW_TESTS = ${ALL_SHADOW_TESTS}")
125131

126132
## grep the LastTest.log.tmp file for the counter diff lines, and make sure
@@ -131,9 +137,7 @@ add_test(
131137
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
132138
)
133139
# List all shadow tests as dependencies, so that the leakcheck can grep their output for leaks.
134-
## TODO swap the following lines when all tests have been converted to the macros
135-
#set_tests_properties(leakcheck-shadow-grep PROPERTIES DEPENDS "${ALL_SHADOW_TESTS}")
136-
set_tests_properties(leakcheck-shadow-grep PROPERTIES DEPENDS "bind-shadow-ptrace;bind-shadow-preload;clone-shadow-ptrace;config-convert-shadow;cpp-shadow-ptrace;cpp-shadow-preload;epoll-shadow-ptrace;epoll-writeable-shadow-ptrace;eventfd-shadow-ptrace;eventfd-shadow-preload;file-shadow-ptrace;mmap-shadow-ptrace;phold-shadow-ptrace;phold-threaded-shadow-ptrace;random-shadow-ptrace;random-shadow-preload;shutdown-shadow-ptrace;shutdown-shadow-preload;sleep-shadow-ptrace;sleep-shadow-preload;sockbuf-shadow-ptrace;socket-shadow-ptrace;socket-shadow-preload;bind-shadow-ptrace;bind-shadow-preload;listen-shadow-ptrace;listen-shadow-preload;getsockname-shadow-ptrace;getsockname-shadow-preload;accept-shadow-ptrace;accept-shadow-preload;timerfd-shadow-ptrace;udp-uniprocess-shadow-ptrace;udp-uniprocess-shadow-preload;udp-shadow-ptrace;unistd-shadow-ptrace;unistd-shadow-preload")
140+
set_tests_properties(leakcheck-shadow-grep PROPERTIES DEPENDS "${ALL_SHADOW_TESTS}")
137141

138142
add_test(
139143
NAME leakcheck-shadow-compare

src/test/config/CMakeLists.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
1+
# Make sure tests in subdirs append to previously collected tests.
2+
set(ALL_SHADOW_TESTS "${ALL_SHADOW_TESTS}")
3+
14
add_subdirectory(convert)
2-
add_subdirectory(read_from_stdin)
5+
add_subdirectory(read_from_stdin)
6+
7+
# Now set the variable in the parent scope to ours, which includes subdir tests.
8+
set(ALL_SHADOW_TESTS "${ALL_SHADOW_TESTS}" PARENT_SCOPE)

src/test/determinism/determinism2.test.shadow.config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
options:
2-
stoptime: 3
2+
stoptime: 10
33
topology:
44
- graphml: |
55
<graphml xmlns="http://graphml.graphdrawing.org/xmlns" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd">
@@ -29,4 +29,4 @@ hosts:
2929
processes:
3030
- plugin: testphold
3131
starttime: 1
32-
arguments: loglevel=debug basename=peer quantity=10 msgload=5 size=1 cpuload=5 weightsfilepath=weights.txt
32+
arguments: loglevel=debug basename=peer quantity=10 msgload=1 size=1 cpuload=1 weightsfilepath=weights.txt runtime=5

src/test/phold/CMakeLists.txt

Lines changed: 33 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,38 @@
11
include_directories(${GLIB_INCLUDES})
2-
3-
## build the test as a dynamic executable that plugs into shadow
42
add_executable(test-phold test_phold.c)
5-
6-
## if the test needs any libraries, link them here
73
target_link_libraries(test-phold ${M_LIBRARIES} ${RT_LIBRARIES} ${GLIB_LIBRARIES})
8-
9-
## copy the file to the build test dir so that the relative path to it is correct
104
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/weights.txt ${CMAKE_CURRENT_BINARY_DIR}/weights.txt COPYONLY)
115

12-
## register the tests
13-
## dont run with debug logging because it causes the test case to take too long
14-
add_test(
15-
NAME phold-shadow-hybrid
16-
COMMAND sh -c "\
17-
${yaml2xml} ${CMAKE_CURRENT_SOURCE_DIR}/phold.test.shadow.config.yaml --output - \
18-
| ${CMAKE_BINARY_DIR}/src/main/shadow --interpose-method=hybrid --pin-cpus -d phold.shadow-hybrid.data - \
19-
"
20-
)
21-
22-
# Run in ptrace mode *without* shim IPC. This is primarily for measurement purposes.
23-
add_test(
24-
NAME phold-shadow-ptrace
25-
COMMAND sh -c "\
26-
${yaml2xml} ${CMAKE_CURRENT_SOURCE_DIR}/phold.test.shadow.config.yaml --output - \
27-
| ${CMAKE_BINARY_DIR}/src/main/shadow --interpose-method=ptrace --pin-cpus -d phold.shadow-ptrace.data - \
28-
"
29-
)
30-
31-
# FIXME: Enable in all configurations. See https://github.com/shadow/shadow/issues/892
32-
add_test(
33-
NAME phold-shadow-preload
34-
COMMAND sh -c "\
35-
${yaml2xml} ${CMAKE_CURRENT_SOURCE_DIR}/phold.test.shadow.config.yaml --output - \
36-
| ${CMAKE_BINARY_DIR}/src/main/shadow --interpose-method=preload --pin-cpus -d phold.shadow-preload.data -
37-
"
38-
CONFIGURATIONS ilibc
39-
)
40-
41-
add_test(
42-
NAME phold-threaded-shadow-hybrid
43-
COMMAND sh -c "\
44-
${yaml2xml} ${CMAKE_CURRENT_SOURCE_DIR}/phold.test.shadow.config.yaml --output - \
45-
| ${CMAKE_BINARY_DIR}/src/main/shadow --interpose-method=hybrid --pin-cpus -d phold-threaded.shadow-hybrid.data -w 2 - \
46-
"
47-
)
48-
49-
add_test(
50-
NAME phold-threaded-shadow-ptrace
51-
COMMAND sh -c "\
52-
${yaml2xml} ${CMAKE_CURRENT_SOURCE_DIR}/phold.test.shadow.config.yaml --output - \
53-
| ${CMAKE_BINARY_DIR}/src/main/shadow --interpose-method=ptrace --pin-cpus -d phold-threaded.shadow-ptrace.data -w 2 - \
54-
"
55-
)
56-
57-
# FIXME: Enable in all configurations. See https://github.com/shadow/shadow/issues/892
58-
add_test(
59-
NAME phold-threaded-shadow-preload
60-
COMMAND sh -c "\
61-
${yaml2xml} ${CMAKE_CURRENT_SOURCE_DIR}/phold.test.shadow.config.yaml --output - \
62-
| ${CMAKE_BINARY_DIR}/src/main/shadow --interpose-method=preload --pin-cpus -d phold-threaded.shadow-preload.data -w 2 - \
63-
"
64-
CONFIGURATIONS ilibc
65-
)
66-
67-
# These tests currently run very slowly in the GitHub CI, which only gives them 2 CPUs.
68-
# Hopefully will be fixed by https://github.com/shadow/shadow/issues/965.
69-
set_tests_properties(
70-
phold-shadow-hybrid
71-
phold-shadow-ptrace
72-
phold-shadow-preload
73-
phold-threaded-shadow-hybrid
74-
phold-threaded-shadow-ptrace
75-
phold-threaded-shadow-preload
76-
PROPERTIES TIMEOUT 60)
6+
# FIXME: Enable the preload tests in all configurations. See https://github.com/shadow/shadow/issues/892
7+
8+
# We should run tests using --pin-cpus in serial, otherwise all such tests will be
9+
# pinned to the same exact CPUs.
10+
add_shadow_tests(
11+
BASENAME phold-serial
12+
METHODS hybrid ptrace
13+
LOGLEVEL info
14+
ARGS --pin-cpus
15+
PROPERTIES RUN_SERIAL TRUE)
16+
add_shadow_tests(
17+
BASENAME phold-serial
18+
METHODS preload
19+
LOGLEVEL info
20+
ARGS --pin-cpus
21+
PROPERTIES RUN_SERIAL TRUE
22+
CONFIGURATIONS ilibc)
23+
24+
# Due to --pin-cpus, we run this in serial. Otherwise we should set the "PROCESSORS 2"
25+
# property since we use 2 workers here.
26+
add_shadow_tests(
27+
BASENAME phold-parallel
28+
METHODS hybrid ptrace
29+
LOGLEVEL info
30+
ARGS --pin-cpus --workers 2
31+
PROPERTIES RUN_SERIAL TRUE)
32+
add_shadow_tests(
33+
BASENAME phold-parallel
34+
METHODS preload
35+
LOGLEVEL info
36+
ARGS --pin-cpus --workers 2
37+
PROPERTIES RUN_SERIAL TRUE
38+
CONFIGURATIONS ilibc)

src/test/phold/phold-parallel.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
phold.yaml

src/test/phold/phold-serial.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
phold.yaml

src/test/phold/phold.test.shadow.config.yaml renamed to src/test/phold/phold.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# our CI, to work around https://github.com/shadow/shadow/issues/892. It should
33
# have no effect in environments where that directory doesn't exist.
44
options:
5-
stoptime: 3
5+
stoptime: 10
66
environment: LD_LIBRARY_PATH=/opt/libc-interpose-centos7
77
topology:
88
- graphml: |
@@ -33,5 +33,5 @@ hosts:
3333
processes:
3434
- plugin: testphold
3535
starttime: 1
36-
arguments: loglevel=info basename=peer quantity=10 msgload=25 cpuload=100 size=1
37-
weightsfilepath=weights.txt
36+
arguments: loglevel=info basename=peer quantity=10 msgload=1 cpuload=1 size=1
37+
weightsfilepath=weights.txt runtime=5

0 commit comments

Comments
 (0)