Repository: oneapi-src/unified-memory-framework (language: python)

Issue:
Fix all valgrind-drd errors in the tests
Fix all valgrind-drd errors in the tests:
```
==4583== ERROR SUMMARY: 571 errors from 3 contexts (suppressed: 13988 from 123)  -  ./test/umf_test-disjointPool
==4601== ERROR SUMMARY: 590 errors from 31 contexts (suppressed: 825 from 92)  -  ./test/umf_test-jemalloc_pool
==4629== ERROR SUMMARY: 1099 errors from 3 contexts (suppressed: 38025 from 111)  -  ./test/umf_test-memoryPool
==4690== ERROR SUMMARY: 10000000 errors from 820 contexts (suppressed: 6479 from 100)  -  ./test/umf_test-scalable_pool
```
Fix all valgrind-helgrind errors in the tests
Fix all valgrind-helgrind errors in the tests:
```
==5236== ERROR SUMMARY: 1259 errors from 21 contexts (suppressed: 13172 from 101)  -  ./test/umf_test-disjointPool
==5254== ERROR SUMMARY: 610 errors from 36 contexts (suppressed: 9990 from 317)  -  ./test/umf_test-jemalloc_pool
==5282== ERROR SUMMARY: 975 errors from 3 contexts (suppressed: 28776 from 79)  -  ./test/umf_test-memoryPool
==5343== ERROR SUMMARY: 1513962 errors from 607 contexts (suppressed: 3017 from 50)  -  ./test/umf_test-scalable_pool
```


Discussion / hints:
See: https://github.com/oneapi-src/unified-memory-framework/pull/158
See: https://github.com/oneapi-src/unified-memory-framework/pull/158

Fix patch:
diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml
new file mode 100644
index 000000000..7e315af94
--- /dev/null
+++ b/.github/workflows/nightly.yml
@@ -0,0 +1,45 @@
+name: Nightly
+
+# This job is run at 00:00 UTC every day or on demand.
+on:
+  workflow_dispatch:
+  schedule:
+    - cron:  '0 0 * * *'
+
+jobs:
+    Valgrind:
+        name: Valgrind
+        strategy:
+            fail-fast: false
+            matrix:
+                tool: ['memcheck'] # TODO: enable 'drd' and 'helgrind' when all issues are fixed
+        runs-on: ubuntu-latest
+
+        steps:
+        - name: Checkout repository
+          uses: actions/checkout@v4
+
+        - name: Install apt packages
+          run: |
+            sudo apt-get update
+            sudo apt-get install -y cmake libjemalloc-dev libnuma-dev libtbb-dev valgrind
+
+        - name: Configure CMake
+          run: >
+            cmake
+            -B ${{github.workspace}}/build
+            -DCMAKE_BUILD_TYPE=Debug
+            -DUMF_FORMAT_CODE_STYLE=OFF
+            -DUMF_DEVELOPER_MODE=ON
+            -DUMF_ENABLE_POOL_TRACKING=ON
+            -DUMF_BUILD_LIBUMF_POOL_SCALABLE=ON
+            -DUMF_BUILD_LIBUMF_POOL_DISJOINT=ON
+            -DUMF_BUILD_LIBUMF_POOL_JEMALLOC=ON
+
+        - name: Build
+          run: >
+            cmake --build ${{github.workspace}}/build --config Debug -j$(nproc)
+
+        - name: Run tests under valgrind
+          working-directory: ${{github.workspace}}/build
+          run: ../test/test_valgrind.sh ${{matrix.tool}}
diff --git a/README.md b/README.md
index ff3e885a7..2dfeb937f 100644
--- a/README.md
+++ b/README.md
@@ -5,6 +5,7 @@
 [![SpellCheck](https://github.com/oneapi-src/unified-memory-framework/actions/workflows/spellcheck.yml/badge.svg?branch=main)](https://github.com/oneapi-src/unified-memory-framework/actions/workflows/spellcheck.yml)
 [![GitHubPages](https://github.com/oneapi-src/unified-memory-framework/actions/workflows/docs.yml/badge.svg?branch=main)](https://github.com/oneapi-src/unified-memory-framework/actions/workflows/docs.yml)
 [![Benchmarks](https://github.com/oneapi-src/unified-memory-framework/actions/workflows/benchmarks.yml/badge.svg?branch=main)](https://github.com/oneapi-src/unified-memory-framework/actions/workflows/benchmarks.yml)
+[![Nightly](https://github.com/oneapi-src/unified-memory-framework/actions/workflows/nightly.yml/badge.svg?branch=main)](https://github.com/oneapi-src/unified-memory-framework/actions/workflows/nightly.yml)
 [![OpenSSF Scorecard](https://api.securityscorecards.dev/projects/github.com/oneapi-src/unified-memory-framework/badge)](https://securityscorecards.dev/viewer/?uri=github.com/oneapi-src/unified-memory-framework)
 
 The Unified Memory Framework (UMF) is a library for constructing allocators and memory pools. It also contains broadly useful abstractions and utilities for memory management. UMF allows users to manage multiple memory pools characterized by different attributes, allowing certain allocation types to be isolated from others and allocated using different hardware resources as required.


Test patch:
diff --git a/test/test_valgrind.sh b/test/test_valgrind.sh
new file mode 100755
index 000000000..2fc1b3ea6
--- /dev/null
+++ b/test/test_valgrind.sh
@@ -0,0 +1,81 @@
+#!/bin/bash
+# Copyright (C) 2024 Intel Corporation
+# Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
+# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+
+set -e
+
+TOOL=$1
+
+function print_usage() {
+	echo "$(basename $0) - run UMF tests under valgrind tools (memcheck, drd or helgrind)"
+	echo "This script must be run in the UMF build directory. It looks for './test/umf_test-*' test executables."
+	echo "Usage: $(basename $0) <memcheck|drd|helgrind>"
+}
+
+if ! valgrind --version > /dev/null; then
+	echo "error: valgrind not found"
+	exit 1
+fi
+
+if [ $(ls -1 ./test/umf_test-* 2>/dev/null | wc -l) -eq 0 ]; then
+	echo "error: UMF tests ./test/umf_test-* not found (perhaps wrong directory)"
+	print_usage
+	exit 1
+fi
+
+if [ "$TOOL" == "" ]; then
+	echo "error: valgrind tool is missing"
+	print_usage
+	exit 1
+fi
+
+case $TOOL in
+memcheck)
+	OPTION="--leak-check=full"
+	;;
+drd)
+	OPTION="--tool=drd"
+	;;
+helgrind)
+	OPTION="--tool=helgrind"
+	;;
+*)
+	echo "error: unknown tool: $TOOL"
+	print_usage
+	exit 1
+	;;
+esac
+
+FAIL=0
+
+echo "Running: \"valgrind $OPTION\" for the following tests:"
+
+for tf in $(ls -1 ./test/umf_test-*); do
+	[ ! -x $tf ] && continue
+	echo -n "$tf "
+	LOG=${tf}.log
+	valgrind $OPTION $tf >$LOG 2>&1 || echo -n "(valgrind failed) "
+	if grep -q -e "ERROR SUMMARY: 0 errors from 0 contexts" $LOG; then
+		echo "- OK"
+		rm $LOG
+	else
+		echo "- FAILED! : $(grep -e "ERROR SUMMARY:" $LOG | cut -d' ' -f2-)"
+		FAIL=1
+	fi || true
+done
+
+[ $FAIL -eq 0 ] && echo PASSED && exit 0
+
+echo
+echo "======================================================================"
+echo
+
+for log in $(ls -1 ./test/umf_test-*.log); do
+	echo ">>>>>>> LOG $log"
+	cat $log
+	echo
+	echo
+done
+
+exit 1