Skip to content
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion .github/workflows/reusable_checks.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Basic checks on the code, incl. coding style, spelling, bandit analysis.
# TODO: add license check
name: Basic checks

on: workflow_call
Expand Down Expand Up @@ -52,6 +51,14 @@ jobs:
- name: Check Python formatting
run: cmake --build build --target black-format-check

- name: Run check-license
run: |
bash ./check_license/check-headers.sh . "Apache-2.0 WITH LLVM-exception" -v

- name: Run copyright-format
run: |
bash ./check_license/check-headers.sh . "Apache-2.0 WITH LLVM-exception" -d

- name: Run a spell check
uses: crate-ci/typos@b63f421581dce830bda2f597a678cb7776b41877 # v1.18.2
with:
Expand Down
142 changes: 142 additions & 0 deletions .github/workflows/sanitizers.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
# Check code with compilers' sanitizers
name: Sanitizers
Copy link
Contributor

Choose a reason for hiding this comment

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

heh, this file shouldn't be here


on: workflow_call

env:
BUILD_DIR : "${{github.workspace}}/build"
INSTL_DIR : "${{github.workspace}}/../install-dir"

permissions:
contents: read

jobs:
ubuntu-build:
name: Ubuntu
strategy:
matrix:
compiler: [{c: gcc, cxx: g++}, {c: clang, cxx: clang++}, {c: icx, cxx: icpx}]
# TSAN is mutually exclusive with other sanitizers
sanitizers: [{asan: ON, ubsan: ON, tsan: OFF}, {asan: OFF, ubsan: OFF, tsan: ON}]
runs-on: ubuntu-22.04

steps:
- name: Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
fetch-depth: 0

- name: Install apt packages
run: |
sudo apt-get update
sudo apt-get install -y clang cmake libhwloc-dev libnuma-dev libjemalloc-dev libtbb-dev
- name: Install oneAPI basekit
if: matrix.compiler.cxx == 'icpx'
run: |
sudo apt-get install -y gpg-agent wget
wget -O- https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB | gpg --dearmor | sudo tee /usr/share/keyrings/oneapi-archive-keyring.gpg > /dev/null
echo "deb [signed-by=/usr/share/keyrings/oneapi-archive-keyring.gpg] https://apt.repos.intel.com/oneapi all main" | sudo tee /etc/apt/sources.list.d/oneAPI.list
sudo apt-get update
sudo apt-get install -y intel-oneapi-ippcp-devel intel-oneapi-ipp-devel intel-oneapi-common-oneapi-vars intel-oneapi-compiler-dpcpp-cpp
- name: Set ptrace value for IPC test
run: sudo bash -c "echo 0 > /proc/sys/kernel/yama/ptrace_scope"

- name: Configure build
run: >
${{ matrix.compiler.cxx == 'icpx' && '. /opt/intel/oneapi/setvars.sh &&' || ''}}
cmake
-B ${{env.BUILD_DIR}}
-DCMAKE_INSTALL_PREFIX="${{env.INSTL_DIR}}"
-DCMAKE_BUILD_TYPE=Debug
-DUMF_BUILD_SHARED_LIBRARY=OFF
-DCMAKE_C_COMPILER=${{matrix.compiler.c}}
-DCMAKE_CXX_COMPILER=${{matrix.compiler.cxx}}
-DUMF_BUILD_LEVEL_ZERO_PROVIDER=ON
-DUMF_FORMAT_CODE_STYLE=OFF
-DUMF_DEVELOPER_MODE=ON
-DUMF_BUILD_LIBUMF_POOL_JEMALLOC=ON
-DUMF_BUILD_LIBUMF_POOL_DISJOINT=ON
-DUMF_USE_ASAN=${{matrix.sanitizers.asan}}
-DUMF_USE_UBSAN=${{matrix.sanitizers.ubsan}}
-DUMF_USE_TSAN=${{matrix.sanitizers.tsan}}
-DUMF_BUILD_EXAMPLES=ON
-DUMF_TESTS_FAIL_ON_SKIP=ON
- name: Build UMF
run: |
${{ matrix.compiler.cxx == 'icpx' && '. /opt/intel/oneapi/setvars.sh' || true }}
cmake --build ${{env.BUILD_DIR}} -j $(nproc)
- name: Run tests
working-directory: ${{env.BUILD_DIR}}
run: >
${{ matrix.compiler.cxx == 'icpx' && '. /opt/intel/oneapi/setvars.sh &&' || ''}}
ctest --output-on-failure
windows-build:
name: cl and clang-cl on Windows
env:
VCPKG_PATH: "${{github.workspace}}/build/vcpkg/packages/hwloc_x64-windows;${{github.workspace}}/build/vcpkg/packages/tbb_x64-windows;${{github.workspace}}/build/vcpkg/packages/jemalloc_x64-windows"
strategy:
matrix:
compiler: [{c: cl, cxx: cl}, {c: clang-cl, cxx: clang-cl}]
# Only ASAN is supported
sanitizers: [{asan: ON}]
runs-on: windows-2022

steps:
- name: Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
fetch-depth: 0

# Use the latest MSVC toolset available, when compiling UMF with ASan.
# Running binaries compiled with older toolsets results in a
# 'STATUS_DLL_INIT_FAILED' error despite being linked with ASan from
# the same toolset as the compiler being used.
# https://github.com/actions/runner-images/issues/8891
- name: Setup MSVC dev command prompt
if: matrix.sanitizers.asan == 'ON'
uses: TheMrMilchmann/setup-msvc-dev@48edcef51a12c80d7e62ace57aae1417795e511c # v3.0.0
with:
arch: x64
toolset: '14'

- name: Initialize vcpkg
uses: lukka/run-vcpkg@5e0cab206a5ea620130caf672fce3e4a6b5666a1 # v11.5
with:
vcpkgGitCommitId: 3dd44b931481d7a8e9ba412621fa810232b66289
vcpkgDirectory: ${{env.BUILD_DIR}}/vcpkg
vcpkgJsonGlob: '**/vcpkg.json'

- name: Install dependencies
run: vcpkg install
shell: pwsh # Specifies PowerShell as the shell for running the script.

# TODO enable level zero provider
- name: Configure build
run: >
cmake
-B ${{env.BUILD_DIR}}
-DCMAKE_INSTALL_PREFIX="${{env.INSTL_DIR}}"
-DCMAKE_C_COMPILER=${{matrix.compiler.c}}
-DCMAKE_CXX_COMPILER=${{matrix.compiler.cxx}}
-DCMAKE_PREFIX_PATH="${{env.VCPKG_PATH}}"
-DUMF_BUILD_SHARED_LIBRARY=OFF
-DUMF_FORMAT_CODE_STYLE=OFF
-DUMF_DEVELOPER_MODE=ON
-DUMF_BUILD_LIBUMF_POOL_DISJOINT=ON
-DUMF_USE_ASAN=${{matrix.sanitizers.asan}}
-DUMF_BUILD_EXAMPLES=ON
-DUMF_BUILD_LEVEL_ZERO_PROVIDER=OFF
-DUMF_TESTS_FAIL_ON_SKIP=ON
- name: Build UMF
run: cmake --build ${{env.BUILD_DIR}} --config Debug -j $Env:NUMBER_OF_PROCESSORS

- name: Run tests
working-directory: ${{env.BUILD_DIR}}
run: ctest -C Debug --output-on-failure
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ else()

add_custom_target(jemalloc_prod
DEPENDS ${jemalloc_targ_BINARY_DIR}/lib/libjemalloc.a)

add_library(jemalloc INTERFACE)
target_link_libraries(
jemalloc INTERFACE ${jemalloc_targ_BINARY_DIR}/lib/libjemalloc.a)
Expand Down
191 changes: 191 additions & 0 deletions check_license/check-headers.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
#!/usr/bin/env bash
Copy link
Contributor

Choose a reason for hiding this comment

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

when all done, the last thing to do would be to make order in your commits. In this PR it would be at best to have 3 commits:

  1. adding check_license based on the pmemstream repository (with link in the description ,where was it copied from)
  2. adding all your changes to the script
  3. fixing copyrights and licenses

Copy link
Contributor

Choose a reason for hiding this comment

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

ok, so this is not done ideally - a few notes on commits:

  • still there are 4 commits - the last one, with simple fixes should be squashed, for sure
  • descriptions of the commits should be as meaningful as possible; e.g. now, the second one ([Fix formatting of CMakeLists.txt](https://github.com/oneapi-src/unified-memory-framework/pull/997/commits/d8ba0f40dc48ec80eff8e8836d13bf642c780f00)) have a lot of lines, which are not relevant... and the title is inaccurate
  • the title Final version of license check is also not saying what you did in this commit 😉

in case you need any hint on this matter, please let me, or anyone else from the team know and we'll gladly help

# 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

# check-headers.sh - check copyright and license in source files

SELF=$0

function usage() {
echo "Usage: $SELF <source_root_path> <license_tag> [-h|-v|-a|-d]"
echo " -h, --help this help message"
echo " -v, --verbose verbose mode"
echo " -a, --all check all files (only modified files are checked by default)"
echo " -d, --update_dates change Copyright dates in all analyzed files (rather not use with -a)"
}

if [ "$#" -lt 2 ]; then
usage >&2
exit 2
fi

SOURCE_ROOT=$1
shift
LICENSE=$1
shift

PATTERN=`mktemp`
TMP=`mktemp`
TMP2=`mktemp`
TEMPFILE=`mktemp`
rm -f $PATTERN $TMP $TMP2

if [ "$1" == "-h" -o "$1" == "--help" ]; then
usage
exit 0
fi

export GIT="git -C ${SOURCE_ROOT}"
$GIT rev-parse || exit 1

if [ -f $SOURCE_ROOT/.git/shallow ]; then
SHALLOW_CLONE=1
echo
echo "Warning: This is a shallow clone. Checking dates in copyright headers"
echo " will be skipped in case of files that have no history."
echo
else
SHALLOW_CLONE=0
fi

VERBOSE=0
CHECK_ALL=0
UPDATE_DATES=0
while [ "$1" != "" ]; do
case $1 in
-v|--verbose)
VERBOSE=1
;;
-a|--all)
CHECK_ALL=1
;;
-d|--update_dates)
UPDATE_DATES=1
;;
esac
shift
done

if [ $CHECK_ALL -eq 0 ]; then
CURRENT_COMMIT=$($GIT log --pretty=%H -1)
MERGE_BASE=$($GIT merge-base HEAD origin/master 2>/dev/null)
[ -z $MERGE_BASE ] && \
MERGE_BASE=$($GIT log --pretty="%cN:%H" | grep GitHub | head -n1 | cut -d: -f2)
[ -z $MERGE_BASE -o "$CURRENT_COMMIT" = "$MERGE_BASE" ] && \
CHECK_ALL=1
fi

if [ $CHECK_ALL -eq 1 ]; then
echo "INFO: Checking copyright headers of all files..."
GIT_COMMAND="ls-tree -r --name-only HEAD"
else
echo "INFO: Checking copyright headers of modified files only..."
GIT_COMMAND="diff --name-only $MERGE_BASE $CURRENT_COMMIT"
fi

FILES=$($GIT $GIT_COMMAND | ${SOURCE_ROOT}/check_license/file-exceptions.sh)

RV=0

for file in $FILES ; do
if [ $VERBOSE -eq 1 ]; then
echo "Checking file: $file"
fi

# The src_path is a path which should be used in every command except git.
# git is called with -C flag so filepaths should be relative to SOURCE_ROOT
src_path="${SOURCE_ROOT}/$file"
[ ! -f $src_path ] && continue
# ensure that file is UTF-8 encoded
ENCODING=`file -b --mime-encoding $src_path`
iconv -f $ENCODING -t "UTF-8" $src_path > $TEMPFILE

if ! grep -q "SPDX-License-Identifier: $LICENSE" $src_path; then
echo >&2 "error: no $LICENSE SPDX tag in file: $src_path"
RV=1
fi

if [ $SHALLOW_CLONE -eq 0 ]; then
$GIT log --no-merges --format="%ai %aE" -- $file | sort > $TMP
else
# mark the grafted commits (commits with no parents)
$GIT log --no-merges --format="%ai %aE grafted-%p-commit" -- $file | sort > $TMP
fi

# skip checking dates for non-Intel commits
[[ ! $(tail -n1 $TMP) =~ "@intel.com" ]] && continue

# skip checking dates for new files
[ $(cat $TMP | wc -l) -le 1 ] && continue

# grep out the grafted commits (commits with no parents)
# and skip checking dates for non-Intel commits
grep -v -e "grafted--commit" $TMP | grep -e "@intel.com" > $TMP2

[ $(cat $TMP2 | wc -l) -eq 0 ] && continue

FIRST=`head -n1 $TMP2`
LAST=` tail -n1 $TMP2`

YEARS=$(sed '
/.*Copyright (C) \+.*[0-9-]\+ Intel Corporation/!d
s/.*Copyright (C) \([0-9]\+\)-\([0-9]\+\).*/\1-\2/
s/.*Copyright (C) \([0-9]\+\).*/\1/' "$src_path")
if [ -z "$YEARS" ]; then
echo >&2 "No copyright years in $src_path"
RV=1
continue
fi

HEADER_FIRST=`echo $YEARS | cut -d"-" -f1`
HEADER_LAST=` echo $YEARS | cut -d"-" -f2`

COMMIT_FIRST=`echo $FIRST | cut -d"-" -f1`
COMMIT_LAST=` echo $LAST | cut -d"-" -f1`

if [ "$COMMIT_FIRST" != "" -a "$COMMIT_LAST" != "" ]; then
if [[ -n "$COMMIT_FIRST" && -n "$COMMIT_LAST" ]]; then
FL=0
if [[ $HEADER_FIRST -lt $COMMIT_FIRST ]]; then
FL=1
fi

COMMIT_LAST=`date +%G`

if [[ $FL -eq 1 ]]; then
NEW=$HEADER_FIRST-$COMMIT_LAST
else

if [[ $COMMIT_FIRST -eq $COMMIT_LAST ]]; then
NEW=$COMMIT_LAST
else
NEW=$COMMIT_FIRST-$COMMIT_LAST
fi
fi

if [[ "$YEARS" == "$NEW" ]]; then
echo "No change needed: $YEARS"
else
if [[ ${UPDATE_DATES} -eq 1 ]]; then
sed -i "s/Copyright ${YEARS}/Copyright ${NEW}/g" "${src_path}"
else
echo "$file:1: error: wrong copyright date: (is: $YEARS, should be: $NEW)" >&2
RV=1
fi
fi
fi
else
echo "error: unknown commit dates in file: $file" >&2
RV=1
fi
done
rm -f $TMP $TMP2 $TEMPFILE

# check if error found
if [ $RV -eq 0 ]; then
echo "Copyright headers are OK."
else
echo "Error(s) in copyright headers found!" >&2
fi
exit $RV
31 changes: 31 additions & 0 deletions check_license/file-exceptions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/sh -e
# 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

# You can add an exception file
Copy link
Contributor

Choose a reason for hiding this comment

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

is this exception list for license check or for copyright check? or both? please mention it in the comment here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it is for both

Copy link
Contributor

Choose a reason for hiding this comment

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

as I stated above - please mention it in the comment here

grep -v -E -e 'src/uthash/.*' \
-e 'benchmark/ubench.h' \
-e 'include/umf/proxy_lib_new_delete.h' \
-e 'scripts/docs_config/conf.py' \
Copy link
Contributor

Choose a reason for hiding this comment

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

docs files moved to a new <umf_root>/docs dir, so at least this line should be updated

-e 'src/uthash/utlist.h' \
-e 'src/uthash/uthash.h' \
-e '\.yml$'\
-e '\.clang-format$' \
-e '\.md$' \
-e '\.cmake-format$' \
-e 'CODEOWNERS$' \
-e 'scripts/assets/images/.*' \
-e 'scripts/docs_config/.*' \
Copy link
Contributor

Choose a reason for hiding this comment

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

hmm I think not all files from docs_config (now called docs/config) should be omitted

-e '\.xml$' \
-e '\.txt$' \
-e 'test/supp/.*' \
-e '\.json$' \
-e 'LICENSE.TXT' \
-e '.github/workflows/.spellcheck-conf.toml' \
-e '.gitignore' \
-e '.mailmap' \
-e '.trivyignore' \
-e 'ChangeLog' \
-e '\.cmake.in$' \
-e '\.patch$'
Loading
Loading