Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Smoke tests for ASan. #879

Merged
merged 6 commits into from
May 4, 2024
Merged

Conversation

ampandey-AMD
Copy link
Contributor

No description provided.

@saipoorna
Copy link

!psdb

@ampandey-AMD
Copy link
Contributor Author

!psdb

I am going to push the same changes into branch aomp-epsdb.

@estewart08
Copy link
Contributor

Since these asan tests are supposed to fail at runtime, you need to check the pipestatus to filecheck for the return code.

@gregrodgers
Copy link
Contributor

The changes you made to Makefile.defs causes changes to at least all smoke tests which now fail. Example is test/smoke/veccopy
Before your change, this is the compile command.

/work/grodgers/rocm/aomp/bin/clang -O2 -fopenmp --offload-arch=gfx906 -D__OFFLOAD_ARCH_gfx906__ veccopy.c -o veccopy

After your change, I get this with "make run"
make run
/work/grodgers/rocm/aomp/bin/clang -O2 -fopenmp --offload-arch=gfx906:xnack+ -fsanitize=address -shared-libasan -g -D__OFFLOAD_ARCH_gfx906__ veccopy.c -o veccopy
./veccopy 2>&1 | tee run.log
./veccopy: error while loading shared libraries: libclang_rt.asan-x86_64.so: cannot open shared object file: No such file or directory
make: *** [../Makefile.rules:71: run] Error 127

@gregrodgers
Copy link
Contributor

gregrodgers commented Apr 12, 2024

Regarding your changes to Makefile.defs, I believe you want to say ifneq ($(AOMP_SANITIZER).)
which says "if AOMP_SANITIZER is NOT blank"
Then you can remove the statement AOMP_SANITIZER ?= $(AOMP_SANITIZER)
Also, you need to modify RUNENV. So your ifneq block could look like this:

ifneq ($(AOMP_SANITIZER),)
  ASAN_FLAGS = -fsanitize=address -shared-libasan -g
  # For Sanitizer below environment variable should always be enabled by default
  AOMP_TARGET_FEATURES=:xnack+
  # For Sanitizer we need to set LD_LIBRARY_PATH at runtime
  ASAN_RT_DIR := $(shell $(AOMP)/bin/clang --print-runtime-dir)
  ASAN_ENV = LD_LIBRARY_PATH=$(ASAN_RT_DIR) HSA_XNACK=1
endif

Then change the setting ofr RUNENV in the block of code about line 336 ish to this.


ifeq ($(SET_DEVICE_DEBUG),)
   RUNENV = $(ASAN_ENV) $(TKILL) $(CBL_ENV)
else
   RUNENV = env $(SET_DEVICE_DEBUG) $(ASAN_ENV) $(TKILL) $(CBL_ENV)
endif

There may be one other change to prevent invalid tests with AOMP_SANITIZER is on since it will only work for HSA_XNACK on.

@ampandey-AMD
Copy link
Contributor Author

ampandey-AMD commented Apr 16, 2024

The changes you made to Makefile.defs causes changes to at least all smoke tests which now fail. Example is test/smoke/veccopy Before your change, this is the compile command.

/work/grodgers/rocm/aomp/bin/clang -O2 -fopenmp --offload-arch=gfx906 -D__OFFLOAD_ARCH_gfx906__ veccopy.c -o veccopy

After your change, I get this with "make run" make run /work/grodgers/rocm/aomp/bin/clang -O2 -fopenmp --offload-arch=gfx906:xnack+ -fsanitize=address -shared-libasan -g -D__OFFLOAD_ARCH_gfx906__ veccopy.c -o veccopy ./veccopy 2>&1 | tee run.log ./veccopy: error while loading shared libraries: libclang_rt.asan-x86_64.so: cannot open shared object file: No such file or directory make: *** [../Makefile.rules:71: run] Error 127

Thanks @gregrodgers. Actually previously the environment variable AOMP_SANITIZER(Created for testing smoke/smoke-asan tests with AOMP-ASan pipeline) was set with value of AOMP_BUILD_SANITIZER. However, few months back we had by default in aomp_common_vars AOMP_BUILD_SANITIZER=1. So, this dependency was causing by default the AOMP_SANITIZER=1. The current revision of the patch has removed this kind of dependency.

To enable AOMP-ASan testing for smoke/smoke-asan now the users would have to explicitly set AOMP_SANITIZER=1 which executing check_smoke_asan.sh script.

example: $$ AOMP_SANITIZER=1 ./check_smoke_asan.sh
OR
$$ export AOMP_SANITIZER=1 && ./check_smoke_asan.sh

@ampandey-AMD
Copy link
Contributor Author

ampandey-AMD commented Apr 16, 2024

Regarding your changes to Makefile.defs, I believe you want to say ifneq ($(AOMP_SANITIZER),) which says "if AOMP_SANITIZER is NOT blank" Then you can remove the statement AOMP_SANITIZER ?= $(AOMP_SANITIZER) Also, you need to modify RUNENV. So your ifneq block could look like this:

ifneq ($(AOMP_SANITIZER),)
  ASAN_FLAGS = -fsanitize=address -shared-libasan -g
  # For Sanitizer below environment variable should always be enabled by default
  AOMP_TARGET_FEATURES=:xnack+
  # For Sanitizer we need to set LD_LIBRARY_PATH at runtime
  ASAN_RT_DIR := $(shell $(AOMP)/bin/clang --print-runtime-dir)
  ASAN_ENV = LD_LIBRARY_PATH=$(ASAN_RT_DIR) HSA_XNACK=1
endif

Hi @gregrodgers, actually I had the patch in gerrit(1030763) for amd-staging for clang-driver & for legacy-flang driver(ROCm/flang#81) both will add the rpath by default when any application is compiled with sanitizer flags. This, I actually discussed with @estewart08 since AOMP is going for rpath by default for openmp so support rpath for host-asan(libclang_rt.asan.x86_64.so) library and for openmp-asan instrumented libraries. I believe we don't need this setting.

Then change the setting ofr RUNENV in the block of code about line 336 ish to this.


ifeq ($(SET_DEVICE_DEBUG),)
   RUNENV = $(ASAN_ENV) $(TKILL) $(CBL_ENV)
else
   RUNENV = env $(SET_DEVICE_DEBUG) $(ASAN_ENV) $(TKILL) $(CBL_ENV)
endif

Don't think we need this setting also because clang-driver and flang-legacy driver would handle for asan runtime library dependencies.

@ampandey-AMD
Copy link
Contributor Author

Since these asan tests are supposed to fail at runtime, you need to check the pipestatus to filecheck for the return code.

Thanks @estewart08. The current revision had the required changes.

@ampandey-AMD ampandey-AMD force-pushed the asan-smoke branch 2 times, most recently from a4c090b to 875f87d Compare April 18, 2024 09:20
@ampandey-AMD ampandey-AMD force-pushed the asan-smoke branch 2 times, most recently from aa81fc3 to b9f35e1 Compare April 22, 2024 04:36
@ampandey-AMD
Copy link
Contributor Author

ampandey-AMD commented Apr 22, 2024

!psdb

Hi @saipoorna, I think this PR to merge on branch aomp-dev is enough for smoke testing of ASan. I don't require to open a duplicate PR for aomp-epsdb. I checked downstream, the npsdb CI utilizes the aomp-dev branch for aomp smoke testing.

@ampandey-AMD
Copy link
Contributor Author

ampandey-AMD commented Apr 22, 2024

Here is the output of AOMP_SANITIZER=1 ./check_smoke_asan.sh.

/work/ampandey/aomp-toolchain/aomp-src/aomp/test/smoke-asan /work/ampandey/aomp-toolchain/aomp-src/aomp/test/smoke-asan
Script Dir Name: smoke-asan
OMP_TARGET_OFFLOAD=MANDATORY

RUNNING ALL TESTS IN: /work/ampandey/aomp-toolchain/aomp-src/aomp/test/smoke-asan

rm -f hip-global-buffer-overflow hip-global-buffer-overflow.a llbin sbin obin *.i *.ii *.bc *.lk a.out-* *.ll *.s *.o *.log *.mod verify_output *.stb *.ilm *.cmod *.cmdx *.so hip-global-buffer-overflow_og11 make-log.txt TEST_STATUS FILECHECK_STATUS
/opt/rocm-6.1.0-staging/llvm/bin/clang++  -x hip -std=c++11 -L/opt/rocm-6.1.0-staging/llvm/../../lib/asan -lamdhip64 -Wl,-rpath,/opt/rocm-6.1.0-staging/llvm/../../lib/asan    -fopenmp --offload-arch=gfx90a:xnack+ -fsanitize=address -shared-libasan -g     -D__OFFLOAD_ARCH_gfx90a__ hip-global-buffer-overflow.cpp -o hip-global-buffer-overflow

rm -f hip-heap-buffer-overflow hip-heap-buffer-overflow.a llbin sbin obin *.i *.ii *.bc *.lk a.out-* *.ll *.s *.o *.log *.mod verify_output *.stb *.ilm *.cmod *.cmdx *.so hip-heap-buffer-overflow_og11 make-log.txt TEST_STATUS FILECHECK_STATUS
/opt/rocm-6.1.0-staging/llvm/bin/clang++  -x hip -std=c++11 -L/opt/rocm-6.1.0-staging/llvm/../../lib/asan -lamdhip64 -Wl,-rpath,/opt/rocm-6.1.0-staging/llvm/../../lib/asan    -fopenmp --offload-arch=gfx90a:xnack+ -fsanitize=address -shared-libasan -g     -D__OFFLOAD_ARCH_gfx90a__ hip-heap-buffer-overflow.cpp -o hip-heap-buffer-overflow

rm -f hip-use-after-free hip-use-after-free.a llbin sbin obin *.i *.ii *.bc *.lk a.out-* *.ll *.s *.o *.log *.mod verify_output *.stb *.ilm *.cmod *.cmdx *.so hip-use-after-free_og11 make-log.txt TEST_STATUS FILECHECK_STATUS
/opt/rocm-6.1.0-staging/llvm/bin/clang++  -x hip -std=c++11 -L/opt/rocm-6.1.0-staging/llvm/../../lib/asan -lamdhip64 -Wl,-rpath,/opt/rocm-6.1.0-staging/llvm/../../lib/asan    -fopenmp --offload-arch=gfx90a:xnack+ -fsanitize=address -shared-libasan -g     -D__OFFLOAD_ARCH_gfx90a__ hip-use-after-free.cpp -o hip-use-after-free

rm -f omp-global-buffer-overflow omp-global-buffer-overflow.a llbin sbin obin *.i *.ii *.bc *.lk a.out-* *.ll *.s *.o *.log *.mod verify_output *.stb *.ilm *.cmod *.cmdx *.so omp-global-buffer-overflow_og11 make-log.txt TEST_STATUS FILECHECK_STATUS
/opt/rocm-6.1.0-staging/llvm/bin/clang++  -O2    -fopenmp --offload-arch=gfx90a:xnack+ -fsanitize=address -shared-libasan -g      -D__OFFLOAD_ARCH_gfx90a__ omp-global-buffer-overflow.cpp -o omp-global-buffer-overflow

rm -f omp-heap-buffer-overflow omp-heap-buffer-overflow.a llbin sbin obin *.i *.ii *.bc *.lk a.out-* *.ll *.s *.o *.log *.mod verify_output *.stb *.ilm *.cmod *.cmdx *.so omp-heap-buffer-overflow_og11 make-log.txt TEST_STATUS FILECHECK_STATUS
/opt/rocm-6.1.0-staging/llvm/bin/clang++  -O2    -fopenmp --offload-arch=gfx90a:xnack+ -fsanitize=address -shared-libasan -g      -D__OFFLOAD_ARCH_gfx90a__ omp-heap-buffer-overflow.cpp -o omp-heap-buffer-overflow


************************************************************************************
                   A non-zero exit code means a failure occured.
Tests that need to be visually inspected: devices, stream
***********************************************************************************

-------------------- Results --------------------
Number of tests: 5

Passing tests: 5/5

Copy link
Contributor

@estewart08 estewart08 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, I did have some comments on other asan related aomp patches though. This should be ok to land as it is isolated to the tests rather than the build.

@ampandey-AMD
Copy link
Contributor Author

ampandey-AMD commented May 2, 2024

Hi Ethan,

I don't have anything more on this PR to be added, unless I write more tests. Can you please review again this PR.?

Thanks & Regards
Amit

ampandey-AMD and others added 5 commits May 3, 2024 23:35
1. Add a new makefile target 'check-asan'. 'check-asan' is capable of
   getting both the filecheck_status and test_status.

2. Remove dependency of AOMP_SANITIZER on AOMP_BUILD_SANITIZER.

3. Utilize the AOMP_SANITIZER environtment variable in check_smoke.sh to enable
   check-asan target for both parallel and sequential builds.
1. Add comments related to documentation for check-asan target.
2. Ensure that check-asan target should only be executed for smoke-asan
   tests.
@ampandey-AMD ampandey-AMD force-pushed the asan-smoke branch 2 times, most recently from 2eb6965 to 4664675 Compare May 3, 2024 18:08
Copy link
Contributor

@estewart08 estewart08 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, asan enabled testing will be enabled with run_rocm_test.sh -a

@ampandey-AMD
Copy link
Contributor Author

LGTM, asan enabled testing will be enabled with run_rocm_test.sh -a

Thanks. Merging this PR now.

@ampandey-AMD ampandey-AMD merged commit 8370fe9 into ROCm:aomp-dev May 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants