Skip to content

Commit

Permalink
i#5365: Build core unit tests with SVE enabled (#6371)
Browse files Browse the repository at this point in the history
Build most core tests with SVE flags and high optimisation (-O3), if
building on a AARCH64 SVE machine.

Tests which fail when built with -O3 are not included.

Add some error checking to a few tests to allow the -O3 build and update
template (expected output) files as necessary.

Issue #6429 raised to cover making the removal of optimization flags
more granular.

Issue: #5365
  • Loading branch information
philramsey-arm committed Nov 10, 2023
1 parent 23ad2c3 commit db54259
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 8 deletions.
77 changes: 76 additions & 1 deletion suite/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,9 @@ if (UNIX)
string(REGEX REPLACE "-Wall" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
# some tests rely on specific "nop;nop" patterns that optimization ruins
# we should probably move the -O from top level into core/CMakeLists.txt
#
# -O3 is selectively re-added to some tests using the add_sve_flags() or
# optimize() functions
string(REGEX REPLACE "-O[0-9]? " " " CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
else (UNIX)
# W2 is default (we're using W3). We should also replace
Expand Down Expand Up @@ -474,6 +477,70 @@ function(append_link_flags target newflags)
LINK_FLAGS "${cur_ldflags} ${newflags}")
endfunction(append_link_flags)

# It would be nice to get rid of the
# string(REGEX REPLACE "-O[0-9]? " " " CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
# line above and instead selectively remove -O3 from tests that cannot
# support it.
# This was investigated and proved to be non trivial as the client tests
# use _DR_set_compile_flags() to set the compile flags whereas the core
# tests use set_cflags(). _DR_set_compile_flags() is a public function and we
# didn't want to add a blocklist in there.
# For now we create a list of tests that can be built with -O3.
# This is for AARCH64 UNIX only.
# TODO i#6429 Change this allowlist to a blocklist.
set(sve_tests
simple_app api.ir api.ir_negative api.ir_v81 api.ir_v82 api.ir_v83 api.ir_v84
api.ir_v86 api.ir_sve api.ir_sve2 api.ir-static api.drdecode common.broadfun
common.fib common.nzcv common.getretaddr common.segfault
common.allasm_aarch64_isa common.allasm_aarch64_cache allasm_aarch64_prefetch
allasm_aarch64_flush libutil.frontend_test libutil.drconfig_test
client.call-retarget client.modules client.annotation-concurrency
client.partial_module_map client.execfault client.events client.events_cpp
client.timer client.mangle_suspend client.syscall-mod client.signal
client.cleancallsig client.file_io client.cleancall-opt-1 client.inline
client.null_instrument client.large_options client.stolen-reg-index
client.gonative client.drmgr-test client.drx_buf-test
client.drbbdup-drwrap-test client.drbbdup-emul-test client.process-id
client.drreg-test client.low_on_memory client.tls client.drx-scattergather
client.drwrap-test client.drwrap-drreg-test drstatecmp-fuzz-app
client.drutil-test client.stolen-reg client.ldstex api.dis-a64 api.reenc-a64
api.opnd api.detach api.detach_state api.detach_signal api.detach_spawn
api.detach_spawn_stress_FLAKY api.detach_spawn_quick_exit api.ibl-stress
api.ibl-stress-aarch64-far-link_LONG api.static_startstop api.static_noclient
api.static_noinit api.static_detach api.static_prepop
api.static_reattach_client_flags api.static_crash api.static_sideline_FLAKY
api.static_symbols api.static_maps_mixup_yesvars
api.static_maps_mixup_novars_FLAKY api.thread_churn client.app_args
client.destructor builtin_prefetch tool.multiproc stride_benchmark
tool.fib_plus tool.heap_test tool.drcacheoff.gencode linux.eintr
linux.execve-sub linux.execve-null linux.execve-config linux.execv
linux.execve-rec linux.exit linux.fork linux.fork-sleep linux.infinite
linux.longjmp linux.prctl linux.mmap linux.zero-length-mem-ranges
linux.sigaction linux.syscall_pwait linux.sigaction_nosignals linux.thread
linux.threadexit linux.threadexit2 linux.signalfd linux.alarm
linux.signal_racesys linux.signal_pre_syscall linux.bad-signal-stack
linux.sigsuspend linux.sigmask linux.mangle_asynch linux.app_tls
linux.readlink linux.fib-conflict linux.fib-static linux.fib-pie linux.vfork
pthreads.pthreads pthreads.pthreads_exit pthreads.ptsig
pthreads.pthreads_fork_FLAKY security-linux.trampoline linux.infloop
linux.rseq_disable security-common.codemod security-common.ret_noncall_trace
security-common.retnonexisting security-common.TestAllocWE
security-common.TestMemProtChg_FLAKY client.drx-test
)

function(add_sve_flags target)
if (proc_supports_sve)
if (target IN_LIST sve_tests)
target_compile_options(${target} PRIVATE
-march=armv8.4-a+crypto+rcpc+sha3+sm4+sve+rng+ssbs+nodotprod
# Reinstate the -03 flag which is removed with the
# string(REGEX REPLACE "-O[0-9]? " " " CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
# line above.
-O3)
endif()
endif()
endfunction(add_sve_flags)

function(add_exe test source)
get_filename_component(srcbase ${source} NAME_WE)
get_filename_component(srcpath ${source} PATH)
Expand Down Expand Up @@ -553,6 +620,10 @@ function(add_exe test source)
"${CMAKE_GENERATOR}" MATCHES "Visual Studio")
add_dependencies(${test} ${gen_asm_tgt})
endif ()

# AARCH64 AND UNIX only
add_sve_flags(${test})

endfunction(add_exe)

# normal app
Expand Down Expand Up @@ -1699,7 +1770,11 @@ function(use_MD_not_MTd source_file)
endif ()
endfunction()

# optimize the target
# The -O3 flag is removed above with the
# string(REGEX REPLACE "-O[0-9]? " " " CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
# line. -O3 is then selectively re-added with this function or add_sve_flags().
# It will be desirable to one day remove the "REGEX REPLACE" line and just
# remove -O3 for targets that cannot support it.
function(optimize target)
if (UNIX)
append_property_string(TARGET ${target} COMPILE_FLAGS "-O3")
Expand Down
4 changes: 3 additions & 1 deletion suite/tests/client-interface/drx-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,9 @@ main(int argc, char **argv)
/* child */
int iter = 0;
close(pipefd[0]); /* close unused read end */
write(pipefd[1], &buf, sizeof(buf));
if (write(pipefd[1], &buf, sizeof(buf)) == -1) {
perror("write to pipe failed\n");
}
close(pipefd[1]);
/* spin until parent kills us or we time out */
while (iter++ < 12) {
Expand Down
3 changes: 2 additions & 1 deletion suite/tests/linux/eintr.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ main(int argc, char **argv)
child_ready = false;
pthread_mutex_unlock(&lock);

write(pipefd[1], "ab", 2);
if (write(pipefd[1], "ab", 2) == -1)
perror("Failed to write to pipe\n");

if (pthread_join(thread, &retval) != 0)
perror("failed to join thread");
Expand Down
11 changes: 6 additions & 5 deletions suite/tests/linux/tool.drcov.eintr.template
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,13 @@ DA:126,1
DA:127,1
DA:128,1
DA:130,1
DA:132,1
DA:133,0
DA:135,1
DA:131,0
DA:133,1
DA:134,0
DA:136,1
DA:138,1
DA:137,1
DA:139,1
DA:141,1
DA:140,1
DA:142,1
DA:143,1
end_of_record

0 comments on commit db54259

Please sign in to comment.