Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
7 changes: 6 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
- name: Setup Bazel
uses: abhinavsingh/setup-bazel@v3
with:
version: 4.0.0
version: 6.5.0
- name: Install common dependencies
run: |
sudo apt-get update -q
Expand Down Expand Up @@ -93,6 +93,11 @@ jobs:
with:
python-version: '3.8'

- name: Setup Bazel
uses: abhinavsingh/setup-bazel@v3
with:
version: 6.5.0

- name: Install dependencies
run: sh .github/workflows/install-deps.sh

Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ web/server/www/userguide/gen-docs/
**/a.out
**/tests/projects/objc/DeallocUseAfterFreeErrors

# bazel
**/bazel-*

# idea files
.idea/

Expand Down
1 change: 1 addition & 0 deletions analyzer/pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ addopts =

# do not capture stdout
--capture=sys
--ignore-glob=**/bazel-*
4 changes: 2 additions & 2 deletions analyzer/tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ test_unit_in_env: venv_dev
test_unit_cov_in_env: venv_dev
$(ACTIVATE_DEV_VENV) && $(UNIT_TEST_COV_CMD)

FUNCTIONAL_TEST_CMD = $(REPO_ROOT) $(TEST_PROJECT) \
pytest $(PYTESTCFG) tests/functional || exit 1
FUNCTIONAL_TEST_CMD = $(REPO_ROOT) PATH=$(ROOT)/build/CodeChecker/bin/:$(PATH) \
$(TEST_PROJECT) pytest $(PYTESTCFG) tests/functional || exit 1

test_functional:
${PYTHON_BIN} $(ROOT)/scripts/test/check_clang.py || exit 1;
Expand Down
2 changes: 2 additions & 0 deletions analyzer/tests/functional/codechecker_bazel/.bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Enable Bzlmod for every Bazel command
common --enable_bzlmod
296 changes: 296 additions & 0 deletions analyzer/tests/functional/codechecker_bazel/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,296 @@
# cc_binary for simple C++ tests
load(
"@rules_cc//cc:defs.bzl",
"cc_binary",
"cc_library",
)

# compile_commands rule
load(
"@bazel_codechecker//src:compile_commands.bzl",
"compile_commands",
)

# codechecker rules
load(
"@bazel_codechecker//src:codechecker.bzl",
"codechecker",
"codechecker_config",
"codechecker_suite",
"codechecker_test",
)

# clang-tidy and clang -analyze rules
load(
"@bazel_codechecker//src:clang.bzl",
"clang_analyze_test",
"clang_tidy_test",
)

# clang -analyze + CTU rule
load(
"@bazel_codechecker//src:clang_ctu.bzl",
"clang_ctu_test",
)

# Prototype for CodeChecker analyze --file
# NOTE: CodeChecker analyze --file --ctu does not work
load(
"@bazel_codechecker//src:code_checker.bzl",
"code_checker_test",
)

# Test for strip_include_prefix
cc_library(
name = "test_inc",
hdrs = glob(["inc/*.h"]),
# NOTE: the following is for test purpose only
# NOTE: use includes instead of strip_include_prefix
strip_include_prefix = "inc",
)

# Test defect in transitive dependencies
cc_library(
name = "test_lib",
srcs = ["src/lib.cc"],
)

# Test defect in CTU mode
cc_library(
name = "test_ctu",
srcs = ["src/ctu.cc"],
)

# Simplest C++ test which should PASS
cc_binary(
name = "test_pass",
srcs = ["src/pass.cc"],
deps = ["test_inc"],
)

# Simplest C++ test which should FAIL
cc_binary(
name = "test_fail",
srcs = ["src/fail.cc"],
deps = [
"test_ctu",
"test_inc",
"test_lib",
],
)

# Generate compile_commands.json file for host test
compile_commands(
name = "compile_commands_pass",
targets = [
":test_pass",
],
)

# CodeChecker configuration options specification
# based on Bazel configuration approach
codechecker_config(
name = "codechecker_config",
analyze = [
"--disable=profile:default",
"--enable=core",
"--enable=bugprone-dangling-handle",
"--enable=bugprone-fold-init-type",
"--enable=misc-non-copyable-objects",
"--report-hash=context-free-v2",
],
# env = CODECHECKER_ENV,
parse = [
"--print-step",
],
)

# CodeChecker configuration file in JSON format
filegroup(
name = "codechecker_config_file",
srcs = [":config.json"],
)

# CodeChecker configuration options specification
# using JSON configuration file based approach,
# inherently supported by CodeChecker
codechecker_config(
name = "codechecker_config_json",
config_file = "codechecker_config_file",
)

# Simple codechecker rule - performs only "build" phase without "test"
codechecker(
name = "codechecker_pass_build",
config = "codechecker_config_json",
targets = [
"test_pass",
],
)

# Simplest codechecker_test example
# Runs CodeChecker on "test_pass" target
codechecker_test(
name = "codechecker_pass",
analyze = [
"--ctu",
],
config = "codechecker_config_json",
targets = [
"test_pass",
],
)

# This codechecker_test example supposed to fail showing findings report
# Note "manual" tag (means should not be run with other tests)
codechecker_test(
name = "codechecker_fail",
tags = [
"manual",
],
analyze = [
"--analyzers clangsa clang-tidy",
],
targets = [
"test_fail",
],
)

# This codechecker_test CTU example supposed to fail showing findings report
# Note "manual" tag (means should not be run with other tests)
codechecker_test(
name = "codechecker_ctu",
analyze = [
"--ctu",
],
tags = [
"manual",
],
targets = [
"test_fail",
],
)

# Simplest codechecker_suite example for "test_pass"
# Can run CodeChecker on targets built for different platforms
# This example performs build for just default platform i.e gcc
codechecker_suite(
name = "codechecker_pass_multi",
config = "codechecker_config_json",
# platforms = [
# "@platforms//os:linux",
# "@platforms//os:ios",
# "@platforms//os:android",
# ],
targets = [
"test_pass",
],
)

# This simple clang-tidy test should pass
clang_tidy_test(
name = "clang_tidy_pass",
targets = [
"test_pass",
],
)

# And this clang-tidy test should fail
# Note "manual" tag (means should not be run with other tests)
clang_tidy_test(
name = "clang_tidy_fail",
tags = [
"manual",
],
targets = [
"test_pass",
"test_fail",
],
)

# This simple clang -analyze test should pass
clang_analyze_test(
name = "clang_analyze_pass",
options = [
"-fno-color-diagnostics", # Example
# "-Xanalyzer -analyzer-disable-all-checks",
],
targets = [
"test_pass",
],
)

# And this clang -analyze test should fail
# Note "manual" tag (means should not be run with other tests)
clang_analyze_test(
name = "clang_analyze_fail",
tags = [
"manual",
],
targets = [
"test_pass",
"test_fail",
],
)

# This simple clang -analyze + CTU test should pass
clang_ctu_test(
name = "clang_ctu_pass",
targets = [
"test_pass",
],
)

# And this clang -analyze + CTU test should fail
# Note "manual" tag (means should not be run with other tests)
clang_ctu_test(
name = "clang_ctu_fail",
options = [
# "-fno-color-diagnostics", # Example
# "-Xanalyzer -analyzer-disable-all-checks",
],
tags = [
"manual",
],
targets = [
"test_pass",
"test_fail",
],
)

code_checker_test(
name = "code_checker_pass",
options = [
"--ctu",
],
targets = [
"test_pass",
],
)

code_checker_test(
name = "code_checker_fail",
tags = [
"manual",
],
targets = [
"test_pass",
"test_fail",
],
)

# FIXME: The following test does not detect CTU problem
# CodeChecker analyze --file --ctu does not work
code_checker_test(
name = "code_checker_ctu",
options = [
"--ctu",
],
tags = [
"manual",
],
targets = [
"test_pass",
"test_fail",
],
)
6 changes: 6 additions & 0 deletions analyzer/tests/functional/codechecker_bazel/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
###############################################################################
# Bazel now uses Bzlmod by default to manage external dependencies.
# Please consider migrating your external dependencies from WORKSPACE to MODULE.bazel.
#
# For more details, please check https://github.com/bazelbuild/bazel/issues/18958
###############################################################################
Loading