From ad097161eabce5ebf104de0173e5a21518a0f48e Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Fri, 15 Aug 2025 14:15:03 +0200 Subject: [PATCH 01/59] Add logging to base class --- test/unit/common/base.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/unit/common/base.py b/test/unit/common/base.py index 51766ac6..779e92e9 100644 --- a/test/unit/common/base.py +++ b/test/unit/common/base.py @@ -62,6 +62,11 @@ def setUpClass(cls): # Move to test dir cls.test_dir = cls.__test_path__ os.chdir(cls.test_dir) + # Enable debug logs for tests if "super verbose" flag is provided + if "-vvv" in sys.argv: + logging.basicConfig( + level=logging.DEBUG, + format="[TEST] %(levelname)5s: %(message)s") # Save environment and location cls.save_env = os.environ cls.save_cwd = os.getcwd() From e3018060c91960aa0b3e24d55e08431a52d28fbd Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Mon, 18 Aug 2025 08:39:22 +0200 Subject: [PATCH 02/59] Fix path problems --- test/unit/common/base.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/unit/common/base.py b/test/unit/common/base.py index 779e92e9..a48fe8e2 100644 --- a/test/unit/common/base.py +++ b/test/unit/common/base.py @@ -34,7 +34,7 @@ class TestBase(unittest.TestCase): BAZEL_TESTLOGS_DIR: str = None @classmethod - def setUpClass(cls): + def setUpClass(cls, path : str = None): """Load module, save environment""" ErrorCollector: list[str] = [] if cls.__test_path__ == None: @@ -70,6 +70,9 @@ def setUpClass(cls): # Save environment and location cls.save_env = os.environ cls.save_cwd = os.getcwd() + # Move to test dir + cls.test_dir = path + os.chdir(cls.test_dir) @classmethod def tearDownClass(cls): From 7300af910b5a8d98600f00899632c24a44159168 Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Mon, 18 Aug 2025 09:08:07 +0200 Subject: [PATCH 03/59] Add way to pass path to base class, move folder change before environment save --- test/unit/common/base.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/unit/common/base.py b/test/unit/common/base.py index a48fe8e2..3925d5a2 100644 --- a/test/unit/common/base.py +++ b/test/unit/common/base.py @@ -34,7 +34,7 @@ class TestBase(unittest.TestCase): BAZEL_TESTLOGS_DIR: str = None @classmethod - def setUpClass(cls, path : str = None): + def setUpClass(cls): """Load module, save environment""" ErrorCollector: list[str] = [] if cls.__test_path__ == None: @@ -67,12 +67,12 @@ def setUpClass(cls, path : str = None): logging.basicConfig( level=logging.DEBUG, format="[TEST] %(levelname)5s: %(message)s") + # Move to test dir + cls.test_dir = cls.__test_path__ + os.chdir(cls.test_dir) # Save environment and location cls.save_env = os.environ cls.save_cwd = os.getcwd() - # Move to test dir - cls.test_dir = path - os.chdir(cls.test_dir) @classmethod def tearDownClass(cls): From b7767d7cc5b3f567f48862767ef0e421ca636a1d Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Mon, 18 Aug 2025 09:19:47 +0200 Subject: [PATCH 04/59] Format --- test/unit/common/base.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/unit/common/base.py b/test/unit/common/base.py index 3925d5a2..af228501 100644 --- a/test/unit/common/base.py +++ b/test/unit/common/base.py @@ -65,8 +65,8 @@ def setUpClass(cls): # Enable debug logs for tests if "super verbose" flag is provided if "-vvv" in sys.argv: logging.basicConfig( - level=logging.DEBUG, - format="[TEST] %(levelname)5s: %(message)s") + level=logging.DEBUG, format="[TEST] %(levelname)5s: %(message)s" + ) # Move to test dir cls.test_dir = cls.__test_path__ os.chdir(cls.test_dir) From 684b954f977d19e0fd83ae988ecbed29cb57e3df Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Mon, 18 Aug 2025 09:57:06 +0200 Subject: [PATCH 05/59] Move template into unittest folder --- test/unit/template/__init__.py | 0 test/unit/{template => }/test_template.py | 0 2 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 test/unit/template/__init__.py rename test/unit/{template => }/test_template.py (100%) diff --git a/test/unit/template/__init__.py b/test/unit/template/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/test/unit/template/test_template.py b/test/unit/test_template.py similarity index 100% rename from test/unit/template/test_template.py rename to test/unit/test_template.py From ba55b0c634a08282f3a7fdaf920680ab2cc983d3 Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Mon, 18 Aug 2025 10:12:44 +0200 Subject: [PATCH 06/59] Change template place --- test/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/README.md b/test/README.md index f5092dd2..e497ea6e 100644 --- a/test/README.md +++ b/test/README.md @@ -66,4 +66,4 @@ python3 -m unittest discover unit/my_test_dir -vvv > __test_path__ = os.path.dirname(os.path.abspath(__file__)) > ``` -**For a test template look into unit/template** +**A test template can be found in the root of the unit directory From 86af7d5123e7994644a31131cabaace05cd64c37 Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Mon, 18 Aug 2025 14:47:57 +0200 Subject: [PATCH 07/59] Enforce setting __test_path__ BAZEL_BIN_DIR and BAZEL_TESTLOGS_DIR --- test/unit/common/base.py | 8 -------- 1 file changed, 8 deletions(-) diff --git a/test/unit/common/base.py b/test/unit/common/base.py index af228501..51766ac6 100644 --- a/test/unit/common/base.py +++ b/test/unit/common/base.py @@ -62,14 +62,6 @@ def setUpClass(cls): # Move to test dir cls.test_dir = cls.__test_path__ os.chdir(cls.test_dir) - # Enable debug logs for tests if "super verbose" flag is provided - if "-vvv" in sys.argv: - logging.basicConfig( - level=logging.DEBUG, format="[TEST] %(levelname)5s: %(message)s" - ) - # Move to test dir - cls.test_dir = cls.__test_path__ - os.chdir(cls.test_dir) # Save environment and location cls.save_env = os.environ cls.save_cwd = os.getcwd() From f4a49cde078e7c6b0a8a98358bfeda9cb9aa9d7d Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Tue, 19 Aug 2025 14:02:15 +0200 Subject: [PATCH 08/59] Revert "Move template into unittest folder" This reverts commit e52a8ed15320c773c0918d7ff5028f5f07351096. --- test/unit/template/__init__.py | 0 test/unit/{ => template}/test_template.py | 0 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 test/unit/template/__init__.py rename test/unit/{ => template}/test_template.py (100%) diff --git a/test/unit/template/__init__.py b/test/unit/template/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/test/unit/test_template.py b/test/unit/template/test_template.py similarity index 100% rename from test/unit/test_template.py rename to test/unit/template/test_template.py From d3893a2e45aadb08ea0ab69cd9fe9a21ed14368a Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Tue, 19 Aug 2025 14:02:18 +0200 Subject: [PATCH 09/59] Revert "Change template place" This reverts commit 33749cc733310afd6e2f8b71466d64bc9687fce5. --- test/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/README.md b/test/README.md index e497ea6e..f5092dd2 100644 --- a/test/README.md +++ b/test/README.md @@ -66,4 +66,4 @@ python3 -m unittest discover unit/my_test_dir -vvv > __test_path__ = os.path.dirname(os.path.abspath(__file__)) > ``` -**A test template can be found in the root of the unit directory +**For a test template look into unit/template** From 9c4ef5d23287993eb199d1e00a4b044a7edd8464 Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Tue, 19 Aug 2025 14:17:41 +0200 Subject: [PATCH 10/59] Add comments, and teardown method --- test/unit/template/test_template.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/unit/template/test_template.py b/test/unit/template/test_template.py index 8113cdd2..03130a32 100644 --- a/test/unit/template/test_template.py +++ b/test/unit/template/test_template.py @@ -52,6 +52,10 @@ def tearDown(self): """TODO: Define clean up after every test""" return super().tearDown() + def tearDown(self): + """TODO: Define clean up after every test""" + return super().tearDown() + def test_template(self): """Test: TODO: describe your test""" self.assertTrue(True) From caa891614ee1ac03d141f58e22dc271ac3f87009 Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Tue, 19 Aug 2025 14:47:28 +0200 Subject: [PATCH 11/59] Move clean command to only run once per suite --- test/unit/template/test_template.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/test/unit/template/test_template.py b/test/unit/template/test_template.py index 03130a32..8113cdd2 100644 --- a/test/unit/template/test_template.py +++ b/test/unit/template/test_template.py @@ -52,10 +52,6 @@ def tearDown(self): """TODO: Define clean up after every test""" return super().tearDown() - def tearDown(self): - """TODO: Define clean up after every test""" - return super().tearDown() - def test_template(self): """Test: TODO: describe your test""" self.assertTrue(True) From e807c8b329059999640a83448a3765470b9be3a1 Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Mon, 11 Aug 2025 12:51:48 +0200 Subject: [PATCH 12/59] Test splitting to files by platform --- .github/workflows/rhel.yml | 62 +++++++++++++++++++ .github/workflows/ubuntu.yml | 117 +++++++++++++++++++++++++++++++++++ 2 files changed, 179 insertions(+) create mode 100644 .github/workflows/rhel.yml create mode 100644 .github/workflows/ubuntu.yml diff --git a/.github/workflows/rhel.yml b/.github/workflows/rhel.yml new file mode 100644 index 00000000..459d8a55 --- /dev/null +++ b/.github/workflows/rhel.yml @@ -0,0 +1,62 @@ +name: codechecker-bazel-tests + +# Triggers the workflow on push or pull request events. +on: [push, pull_request] + +permissions: read-all + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + rhel9_test: + name: Unit tests on RHEL9 + runs-on: ubuntu-24.04 + container: redhat/ubi9:latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set bazel version to 6.5.0 + run: echo "6.5.0" > .bazelversion + + - name: Install CodeChecker analyzers + run: | + dnf update -y && \ + dnf install -y \ + llvm-toolset \ + clang-tools-extra \ + wget \ + git \ + python3 \ + python3-pip \ + gcc \ + g++ \ + scl-utils \ + + - name: Install CodeChecker + run: pip3 install codechecker + + - name: Setup Bazel + run: | + VERSION=1.26.0; \ + wget "https://github.com/bazelbuild/bazelisk/releases/download/v$VERSION/bazelisk-linux-amd64" && \ + chmod +x bazelisk-linux-amd64 && \ + mv bazelisk-linux-amd64 /usr/local/bin/bazel && \ + USE_BAZEL_VERSION=6.5.0 bazel version + + - name: Print versions + run: | + bazel version + CodeChecker version + echo "[NOTE]: If you are debugging, its possible that " \ + "CodeChecker finds different analyzers when running in " \ + "bazel's sandbox environment!" + CodeChecker analyzers + + - name: Run tests + run: | + cd test + python3 test.py -vvv \ No newline at end of file diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml new file mode 100644 index 00000000..c4d1d6c8 --- /dev/null +++ b/.github/workflows/ubuntu.yml @@ -0,0 +1,117 @@ +name: codechecker-bazel-tests + +# Triggers the workflow on push or pull request events. +on: [push, pull_request] + +permissions: read-all + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + rules_test: + name: Unit tests on ubuntu + runs-on: ubuntu-24.04 + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set bazel version to 6.5.0 + run: echo "6.5.0" > .bazelversion + + - name: Setup Bazel + uses: bazel-contrib/setup-bazel@0.15.0 + + - name: Install python + uses: actions/setup-python@v5 + with: + python-version: '3.12' + + - name: Install CodeChecker analyzers + run: | + sudo apt-get update --quiet + sudo apt-get install --no-install-recommends \ + clang \ + clang-tools \ + clang-tidy + # The default naming of the clang-extdef-mapping, needed for CTU, is + # installed by clang-tools also contains the major version + # (e.g. clang-extdef-mapping-18), but the bazel rules reference it + # without the version number. To this end, we use update-alternatives + # to rename the binary to omit it. + sudo update-alternatives --install \ + /usr/bin/clang-extdef-mapping \ + clang-extdef-mapping \ + /usr/bin/clang-extdef-mapping-$(clang --version | head -n 1 | + sed -E 's/.*version ([0-9]+)\..*/\1/') \ + 100 + + - name: Install CodeChecker + run: pip3 install codechecker + + - name: Print versions + run: | + bazel version + CodeChecker version + echo "[NOTE]: CodeChecker may find different analyzer binaries" \ + "when invoking directly, or in bazel's sandbox environment!" \ + "Be sure to double check during debugging." + CodeChecker analyzers + + - name: Run tests + run: | + cd test + python3 test.py -vvv + + rhel9_test: + name: Unit tests on RHEL9 + runs-on: ubuntu-24.04 + container: redhat/ubi9:latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set bazel version to 6.5.0 + run: echo "6.5.0" > .bazelversion + + - name: Install CodeChecker analyzers + run: | + dnf update -y && \ + dnf install -y \ + llvm-toolset \ + clang-tools-extra \ + wget \ + git \ + python3 \ + python3-pip \ + gcc \ + g++ \ + scl-utils \ + + - name: Install CodeChecker + run: pip3 install codechecker + + - name: Setup Bazel + run: | + VERSION=1.26.0; \ + wget "https://github.com/bazelbuild/bazelisk/releases/download/v$VERSION/bazelisk-linux-amd64" && \ + chmod +x bazelisk-linux-amd64 && \ + mv bazelisk-linux-amd64 /usr/local/bin/bazel && \ + USE_BAZEL_VERSION=6.5.0 bazel version + + - name: Print versions + run: | + bazel version + CodeChecker version + echo "[NOTE]: CodeChecker may find different analyzer binaries" \ + "when invoking directly, or in bazel's sandbox environment!" \ + "Be sure to double check during debugging." + CodeChecker analyzers + + - name: Run tests + run: | + cd test + python3 test.py -vvv From fe64b0c065bf7d811416318b1e7cf908124dc765 Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Mon, 11 Aug 2025 13:53:39 +0200 Subject: [PATCH 13/59] Revert "Test splitting to files by platform" This reverts commit 730ce96577e66dff26e745c7cb82a1f28b1cdc85. --- .github/workflows/rhel.yml | 62 ---------------------- .github/workflows/{ubuntu.yml => test.yml} | 0 2 files changed, 62 deletions(-) delete mode 100644 .github/workflows/rhel.yml rename .github/workflows/{ubuntu.yml => test.yml} (100%) diff --git a/.github/workflows/rhel.yml b/.github/workflows/rhel.yml deleted file mode 100644 index 459d8a55..00000000 --- a/.github/workflows/rhel.yml +++ /dev/null @@ -1,62 +0,0 @@ -name: codechecker-bazel-tests - -# Triggers the workflow on push or pull request events. -on: [push, pull_request] - -permissions: read-all - -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true - -jobs: - rhel9_test: - name: Unit tests on RHEL9 - runs-on: ubuntu-24.04 - container: redhat/ubi9:latest - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Set bazel version to 6.5.0 - run: echo "6.5.0" > .bazelversion - - - name: Install CodeChecker analyzers - run: | - dnf update -y && \ - dnf install -y \ - llvm-toolset \ - clang-tools-extra \ - wget \ - git \ - python3 \ - python3-pip \ - gcc \ - g++ \ - scl-utils \ - - - name: Install CodeChecker - run: pip3 install codechecker - - - name: Setup Bazel - run: | - VERSION=1.26.0; \ - wget "https://github.com/bazelbuild/bazelisk/releases/download/v$VERSION/bazelisk-linux-amd64" && \ - chmod +x bazelisk-linux-amd64 && \ - mv bazelisk-linux-amd64 /usr/local/bin/bazel && \ - USE_BAZEL_VERSION=6.5.0 bazel version - - - name: Print versions - run: | - bazel version - CodeChecker version - echo "[NOTE]: If you are debugging, its possible that " \ - "CodeChecker finds different analyzers when running in " \ - "bazel's sandbox environment!" - CodeChecker analyzers - - - name: Run tests - run: | - cd test - python3 test.py -vvv \ No newline at end of file diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/test.yml similarity index 100% rename from .github/workflows/ubuntu.yml rename to .github/workflows/test.yml From 663ddb3a8212e06ec5d5d11fc12c42ec4a4bf799 Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Thu, 14 Aug 2025 14:16:39 +0200 Subject: [PATCH 14/59] Change message, rename file --- .github/workflows/{test.yml => unit_test.yml} | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) rename .github/workflows/{test.yml => unit_test.yml} (87%) diff --git a/.github/workflows/test.yml b/.github/workflows/unit_test.yml similarity index 87% rename from .github/workflows/test.yml rename to .github/workflows/unit_test.yml index c4d1d6c8..072f0ab4 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/unit_test.yml @@ -55,9 +55,7 @@ jobs: run: | bazel version CodeChecker version - echo "[NOTE]: CodeChecker may find different analyzer binaries" \ - "when invoking directly, or in bazel's sandbox environment!" \ - "Be sure to double check during debugging." + echo "[NOTE]:CodeChecker analyzers may be different in bazel!"" CodeChecker analyzers - name: Run tests @@ -106,9 +104,9 @@ jobs: run: | bazel version CodeChecker version - echo "[NOTE]: CodeChecker may find different analyzer binaries" \ - "when invoking directly, or in bazel's sandbox environment!" \ - "Be sure to double check during debugging." + echo "[NOTE]: If you are debugging, its possible that " \ + "CodeChecker finds different analyzers when running in " \ + "bazel's sandbox environment!" CodeChecker analyzers - name: Run tests From 44695beab9d37b38c6cf9b7a61959dfdd86ebb4f Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Thu, 14 Aug 2025 14:34:51 +0200 Subject: [PATCH 15/59] What extra " ? --- .github/workflows/unit_test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/unit_test.yml b/.github/workflows/unit_test.yml index 072f0ab4..17e15e07 100644 --- a/.github/workflows/unit_test.yml +++ b/.github/workflows/unit_test.yml @@ -55,7 +55,7 @@ jobs: run: | bazel version CodeChecker version - echo "[NOTE]:CodeChecker analyzers may be different in bazel!"" + echo "[NOTE]:CodeChecker analyzers may be different in bazel!" CodeChecker analyzers - name: Run tests From 891cf6aac584d6a747b9e24ea737fbde63f7e45f Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Thu, 14 Aug 2025 14:43:20 +0200 Subject: [PATCH 16/59] Reword Note --- .github/workflows/unit_test.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/unit_test.yml b/.github/workflows/unit_test.yml index 17e15e07..3b23e2ac 100644 --- a/.github/workflows/unit_test.yml +++ b/.github/workflows/unit_test.yml @@ -55,7 +55,9 @@ jobs: run: | bazel version CodeChecker version - echo "[NOTE]:CodeChecker analyzers may be different in bazel!" + echo "[NOTE]: CodeChecker may find different analyzer binaries" \ + "when invoking directly, or in bazel's sandbox environment!" \ + "Be sure to double check during debugging." CodeChecker analyzers - name: Run tests From a43633eb85a0fef43a4e9d2057acae71e389955b Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Fri, 15 Aug 2025 07:50:12 +0200 Subject: [PATCH 17/59] Update Note for rhel9 to --- .github/workflows/unit_test.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/unit_test.yml b/.github/workflows/unit_test.yml index 3b23e2ac..c4d1d6c8 100644 --- a/.github/workflows/unit_test.yml +++ b/.github/workflows/unit_test.yml @@ -106,9 +106,9 @@ jobs: run: | bazel version CodeChecker version - echo "[NOTE]: If you are debugging, its possible that " \ - "CodeChecker finds different analyzers when running in " \ - "bazel's sandbox environment!" + echo "[NOTE]: CodeChecker may find different analyzer binaries" \ + "when invoking directly, or in bazel's sandbox environment!" \ + "Be sure to double check during debugging." CodeChecker analyzers - name: Run tests From fb753da6aedc30a2c8a2c89d70053e59b10830cf Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Fri, 15 Aug 2025 11:53:48 +0200 Subject: [PATCH 18/59] Add composite actions for environment setup --- .github/actions/rhel9_setup/action.yml | 36 ++++++++++++++++++++++ .github/actions/ubuntu_setup/action.yml | 40 +++++++++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 .github/actions/rhel9_setup/action.yml create mode 100644 .github/actions/ubuntu_setup/action.yml diff --git a/.github/actions/rhel9_setup/action.yml b/.github/actions/rhel9_setup/action.yml new file mode 100644 index 00000000..d6cdd999 --- /dev/null +++ b/.github/actions/rhel9_setup/action.yml @@ -0,0 +1,36 @@ +name: 'Setup environment for redhat9' +description: 'Sets up analyzers, CodeChecker and Bazel for rhel9 CI runner' +runs: + using: "composite" + steps: + - name: Set bazel version to 6.5.0 + run: echo "6.5.0" > .bazelversion + shell: bash + + - name: Install CodeChecker analyzers + run: | + dnf update -y && \ + dnf install -y \ + llvm-toolset \ + clang-tools-extra \ + wget \ + git \ + python3 \ + python3-pip \ + gcc \ + g++ \ + scl-utils \ + shell: bash + + - name: Install CodeChecker + run: pip3 install codechecker + shell: bash + + - name: Setup Bazel + run: | + VERSION=1.26.0; \ + wget "https://github.com/bazelbuild/bazelisk/releases/download/v$VERSION/bazelisk-linux-amd64" && \ + chmod +x bazelisk-linux-amd64 && \ + mv bazelisk-linux-amd64 /usr/local/bin/bazel && \ + USE_BAZEL_VERSION=6.5.0 bazel version + shell: bash diff --git a/.github/actions/ubuntu_setup/action.yml b/.github/actions/ubuntu_setup/action.yml new file mode 100644 index 00000000..4e393287 --- /dev/null +++ b/.github/actions/ubuntu_setup/action.yml @@ -0,0 +1,40 @@ +name: 'Setup environment for Ubuntu' +description: 'Sets up analyzers, CodeChecker and Bazel for ubuntu CI runner' +runs: + using: "composite" + steps: + - name: Set bazel version to 6.5.0 + run: echo "6.5.0" > .bazelversion + shell: bash + + - name: Setup Bazel + uses: bazel-contrib/setup-bazel@0.15.0 + + - name: Install python + uses: actions/setup-python@v5 + with: + python-version: '3.12' + + - name: Install CodeChecker analyzers + run: | + sudo apt-get update --quiet + sudo apt-get install --no-install-recommends \ + clang \ + clang-tools \ + clang-tidy + # The default naming of the clang-extdef-mapping, needed for CTU, is + # installed by clang-tools also contains the major version + # (e.g. clang-extdef-mapping-18), but the bazel rules reference it + # without the version number. To this end, we use update-alternatives + # to rename the binary to omit it. + sudo update-alternatives --install \ + /usr/bin/clang-extdef-mapping \ + clang-extdef-mapping \ + /usr/bin/clang-extdef-mapping-$(clang --version | head -n 1 | + sed -E 's/.*version ([0-9]+)\..*/\1/') \ + 100 + shell: bash + + - name: Install CodeChecker + run: pip3 install codechecker + shell: bash \ No newline at end of file From 108e4d638a401e27143a2ab5524d6fbeea131e18 Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Fri, 15 Aug 2025 11:55:28 +0200 Subject: [PATCH 19/59] Use composite actions --- .github/workflows/unit_test.yml | 63 +++------------------------------ 1 file changed, 4 insertions(+), 59 deletions(-) diff --git a/.github/workflows/unit_test.yml b/.github/workflows/unit_test.yml index c4d1d6c8..d7a9ca19 100644 --- a/.github/workflows/unit_test.yml +++ b/.github/workflows/unit_test.yml @@ -18,38 +18,8 @@ jobs: - name: Checkout repository uses: actions/checkout@v4 - - name: Set bazel version to 6.5.0 - run: echo "6.5.0" > .bazelversion - - - name: Setup Bazel - uses: bazel-contrib/setup-bazel@0.15.0 - - - name: Install python - uses: actions/setup-python@v5 - with: - python-version: '3.12' - - - name: Install CodeChecker analyzers - run: | - sudo apt-get update --quiet - sudo apt-get install --no-install-recommends \ - clang \ - clang-tools \ - clang-tidy - # The default naming of the clang-extdef-mapping, needed for CTU, is - # installed by clang-tools also contains the major version - # (e.g. clang-extdef-mapping-18), but the bazel rules reference it - # without the version number. To this end, we use update-alternatives - # to rename the binary to omit it. - sudo update-alternatives --install \ - /usr/bin/clang-extdef-mapping \ - clang-extdef-mapping \ - /usr/bin/clang-extdef-mapping-$(clang --version | head -n 1 | - sed -E 's/.*version ([0-9]+)\..*/\1/') \ - 100 - - - name: Install CodeChecker - run: pip3 install codechecker + - name: Setup environment + uses: ./.github/actions/ubuntu_setup - name: Print versions run: | @@ -74,33 +44,8 @@ jobs: - name: Checkout repository uses: actions/checkout@v4 - - name: Set bazel version to 6.5.0 - run: echo "6.5.0" > .bazelversion - - - name: Install CodeChecker analyzers - run: | - dnf update -y && \ - dnf install -y \ - llvm-toolset \ - clang-tools-extra \ - wget \ - git \ - python3 \ - python3-pip \ - gcc \ - g++ \ - scl-utils \ - - - name: Install CodeChecker - run: pip3 install codechecker - - - name: Setup Bazel - run: | - VERSION=1.26.0; \ - wget "https://github.com/bazelbuild/bazelisk/releases/download/v$VERSION/bazelisk-linux-amd64" && \ - chmod +x bazelisk-linux-amd64 && \ - mv bazelisk-linux-amd64 /usr/local/bin/bazel && \ - USE_BAZEL_VERSION=6.5.0 bazel version + - name: Setup environment + uses: ./.github/actions/rhel9_setup - name: Print versions run: | From 1ca49110297adb0786567662dd4a9a8c731bb62a Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Mon, 18 Aug 2025 08:40:21 +0200 Subject: [PATCH 20/59] Chenge extension yml to yaml --- .../rhel9_setup/{action.yml => action.yaml} | 0 .../ubuntu_setup/{action.yml => action.yaml} | 2 +- .github/workflows/unit_test.yml | 62 ------------------- 3 files changed, 1 insertion(+), 63 deletions(-) rename .github/actions/rhel9_setup/{action.yml => action.yaml} (100%) rename .github/actions/ubuntu_setup/{action.yml => action.yaml} (98%) delete mode 100644 .github/workflows/unit_test.yml diff --git a/.github/actions/rhel9_setup/action.yml b/.github/actions/rhel9_setup/action.yaml similarity index 100% rename from .github/actions/rhel9_setup/action.yml rename to .github/actions/rhel9_setup/action.yaml diff --git a/.github/actions/ubuntu_setup/action.yml b/.github/actions/ubuntu_setup/action.yaml similarity index 98% rename from .github/actions/ubuntu_setup/action.yml rename to .github/actions/ubuntu_setup/action.yaml index 4e393287..d331cc95 100644 --- a/.github/actions/ubuntu_setup/action.yml +++ b/.github/actions/ubuntu_setup/action.yaml @@ -37,4 +37,4 @@ runs: - name: Install CodeChecker run: pip3 install codechecker - shell: bash \ No newline at end of file + shell: bash diff --git a/.github/workflows/unit_test.yml b/.github/workflows/unit_test.yml deleted file mode 100644 index d7a9ca19..00000000 --- a/.github/workflows/unit_test.yml +++ /dev/null @@ -1,62 +0,0 @@ -name: codechecker-bazel-tests - -# Triggers the workflow on push or pull request events. -on: [push, pull_request] - -permissions: read-all - -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true - -jobs: - rules_test: - name: Unit tests on ubuntu - runs-on: ubuntu-24.04 - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Setup environment - uses: ./.github/actions/ubuntu_setup - - - name: Print versions - run: | - bazel version - CodeChecker version - echo "[NOTE]: CodeChecker may find different analyzer binaries" \ - "when invoking directly, or in bazel's sandbox environment!" \ - "Be sure to double check during debugging." - CodeChecker analyzers - - - name: Run tests - run: | - cd test - python3 test.py -vvv - - rhel9_test: - name: Unit tests on RHEL9 - runs-on: ubuntu-24.04 - container: redhat/ubi9:latest - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Setup environment - uses: ./.github/actions/rhel9_setup - - - name: Print versions - run: | - bazel version - CodeChecker version - echo "[NOTE]: CodeChecker may find different analyzer binaries" \ - "when invoking directly, or in bazel's sandbox environment!" \ - "Be sure to double check during debugging." - CodeChecker analyzers - - - name: Run tests - run: | - cd test - python3 test.py -vvv From 38216f95c9fe95a6a1f68030c51e1dec384ee3dd Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Mon, 18 Aug 2025 09:32:33 +0200 Subject: [PATCH 21/59] Move composite actions into a different directory --- .github/actions/rhel9_setup/action.yaml | 36 --------------------- .github/actions/ubuntu_setup/action.yaml | 40 ------------------------ 2 files changed, 76 deletions(-) delete mode 100644 .github/actions/rhel9_setup/action.yaml delete mode 100644 .github/actions/ubuntu_setup/action.yaml diff --git a/.github/actions/rhel9_setup/action.yaml b/.github/actions/rhel9_setup/action.yaml deleted file mode 100644 index d6cdd999..00000000 --- a/.github/actions/rhel9_setup/action.yaml +++ /dev/null @@ -1,36 +0,0 @@ -name: 'Setup environment for redhat9' -description: 'Sets up analyzers, CodeChecker and Bazel for rhel9 CI runner' -runs: - using: "composite" - steps: - - name: Set bazel version to 6.5.0 - run: echo "6.5.0" > .bazelversion - shell: bash - - - name: Install CodeChecker analyzers - run: | - dnf update -y && \ - dnf install -y \ - llvm-toolset \ - clang-tools-extra \ - wget \ - git \ - python3 \ - python3-pip \ - gcc \ - g++ \ - scl-utils \ - shell: bash - - - name: Install CodeChecker - run: pip3 install codechecker - shell: bash - - - name: Setup Bazel - run: | - VERSION=1.26.0; \ - wget "https://github.com/bazelbuild/bazelisk/releases/download/v$VERSION/bazelisk-linux-amd64" && \ - chmod +x bazelisk-linux-amd64 && \ - mv bazelisk-linux-amd64 /usr/local/bin/bazel && \ - USE_BAZEL_VERSION=6.5.0 bazel version - shell: bash diff --git a/.github/actions/ubuntu_setup/action.yaml b/.github/actions/ubuntu_setup/action.yaml deleted file mode 100644 index d331cc95..00000000 --- a/.github/actions/ubuntu_setup/action.yaml +++ /dev/null @@ -1,40 +0,0 @@ -name: 'Setup environment for Ubuntu' -description: 'Sets up analyzers, CodeChecker and Bazel for ubuntu CI runner' -runs: - using: "composite" - steps: - - name: Set bazel version to 6.5.0 - run: echo "6.5.0" > .bazelversion - shell: bash - - - name: Setup Bazel - uses: bazel-contrib/setup-bazel@0.15.0 - - - name: Install python - uses: actions/setup-python@v5 - with: - python-version: '3.12' - - - name: Install CodeChecker analyzers - run: | - sudo apt-get update --quiet - sudo apt-get install --no-install-recommends \ - clang \ - clang-tools \ - clang-tidy - # The default naming of the clang-extdef-mapping, needed for CTU, is - # installed by clang-tools also contains the major version - # (e.g. clang-extdef-mapping-18), but the bazel rules reference it - # without the version number. To this end, we use update-alternatives - # to rename the binary to omit it. - sudo update-alternatives --install \ - /usr/bin/clang-extdef-mapping \ - clang-extdef-mapping \ - /usr/bin/clang-extdef-mapping-$(clang --version | head -n 1 | - sed -E 's/.*version ([0-9]+)\..*/\1/') \ - 100 - shell: bash - - - name: Install CodeChecker - run: pip3 install codechecker - shell: bash From a3ad98aa25c241fcf152cfead18d96892526b02d Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Mon, 18 Aug 2025 12:18:21 +0200 Subject: [PATCH 22/59] Trigger Build From 55afb253a6234a5dbe55664f6fa46e2886bedc82 Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Mon, 18 Aug 2025 13:20:57 +0200 Subject: [PATCH 23/59] Trigger Build From 7845c010c12595357a2656a48b335291e7d016f8 Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Tue, 12 Aug 2025 14:38:19 +0200 Subject: [PATCH 24/59] Add test for path resolution, in plist files (in accordance with #22) --- test/unit/virtual_include/BUILD | 72 +++++++++++++++++++++++++ test/unit/virtual_include/inc/zeroDiv.h | 7 +++ test/unit/virtual_include/source.cc | 5 ++ 3 files changed, 84 insertions(+) create mode 100644 test/unit/virtual_include/BUILD create mode 100644 test/unit/virtual_include/inc/zeroDiv.h create mode 100644 test/unit/virtual_include/source.cc diff --git a/test/unit/virtual_include/BUILD b/test/unit/virtual_include/BUILD new file mode 100644 index 00000000..3ff1334d --- /dev/null +++ b/test/unit/virtual_include/BUILD @@ -0,0 +1,72 @@ +# 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", +) + +# Simplest C++ test which should FAIL +cc_binary( + name = "virtual_include", + srcs = ["source.cc"], + deps = ["test_inc"], +) + +# Simplest virtual include resolution test +codechecker_test( + name = "codechecker_virtual_include", + targets = [ + "virtual_include", + ], +) + +code_checker_test( + name = "code_checker_virtual_include", + targets = [ + "virtual_include", + ] +) diff --git a/test/unit/virtual_include/inc/zeroDiv.h b/test/unit/virtual_include/inc/zeroDiv.h new file mode 100644 index 00000000..f6ebbf2c --- /dev/null +++ b/test/unit/virtual_include/inc/zeroDiv.h @@ -0,0 +1,7 @@ +#ifndef ZERODIV_H +#define ZERODIV_H +int warnMe(){ + return 1/0; +} +#endif //ZERODIV_H + diff --git a/test/unit/virtual_include/source.cc b/test/unit/virtual_include/source.cc new file mode 100644 index 00000000..673f028e --- /dev/null +++ b/test/unit/virtual_include/source.cc @@ -0,0 +1,5 @@ +#include "zeroDiv.h" + +int main(){ + return 0; +} \ No newline at end of file From 60700f0e35805e4d849225b60feebc84a7baa338 Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Tue, 12 Aug 2025 14:41:28 +0200 Subject: [PATCH 25/59] Add manual tag --- test/unit/virtual_include/BUILD | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/unit/virtual_include/BUILD b/test/unit/virtual_include/BUILD index 3ff1334d..504371ad 100644 --- a/test/unit/virtual_include/BUILD +++ b/test/unit/virtual_include/BUILD @@ -59,6 +59,9 @@ cc_binary( # Simplest virtual include resolution test codechecker_test( name = "codechecker_virtual_include", + tags = [ + "manual", + ], targets = [ "virtual_include", ], @@ -66,6 +69,9 @@ codechecker_test( code_checker_test( name = "code_checker_virtual_include", + tags = [ + "manual", + ], targets = [ "virtual_include", ] From 238f971655d2f0728558657bb1d7ca40b0919c98 Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Wed, 13 Aug 2025 13:07:05 +0200 Subject: [PATCH 26/59] Add python test --- .../virtual_include/virtual_include_test.py | 121 ++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 test/unit/virtual_include/virtual_include_test.py diff --git a/test/unit/virtual_include/virtual_include_test.py b/test/unit/virtual_include/virtual_include_test.py new file mode 100644 index 00000000..8d52f9bb --- /dev/null +++ b/test/unit/virtual_include/virtual_include_test.py @@ -0,0 +1,121 @@ +# Copyright 2023 Ericsson AB +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +""" +Unit and functional tests +""" +import logging +import os +import re +import shlex +import subprocess +import sys +import unittest +import glob + + +class TestBase(unittest.TestCase): + """Unittest base abstract class""" + + BAZEL_BIN_DIR = os.path.join("../../..", "bazel-bin", "test", + "unit", "virtual_include") + BAZEL_TESTLOGS_DIR = os.path.join("../../..", "bazel-testlogs", "test", + "unit", "virtual_include") + + @classmethod + def setUpClass(cls): + """Load module, save environment""" + # Save environment and location + cls.save_env = os.environ + cls.save_cwd = os.getcwd() + # Move to test dir + cls.test_dir = os.path.abspath(os.path.dirname(__file__)) + os.chdir(cls.test_dir) + + @classmethod + def tearDownClass(cls): + """Restore environment""" + os.chdir(cls.save_cwd) + os.environ = cls.save_env + + def setUp(self): + """Before every test""" + logging.debug("\n%s", "-" * 70) + + def check_command(self, cmd, exit_code=0): + """Run shell command and check status""" + logging.debug("Running: %s", cmd) + commands = shlex.split(cmd) + with subprocess.Popen(commands, + stdin=subprocess.PIPE, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE) as process: + stdout, stderr = process.communicate() + self.assertEqual( + process.returncode, + exit_code, "\n" + "\n".join([ + f"command: {cmd}", + f"stdout: {stdout.decode('utf-8')}", + f"stderr: {stderr.decode('utf-8')}"])) + + def grep_file(self, filename, regex): + """Grep given filename""" + pattern = re.compile(regex) + logging.debug("RegEx = r'%s'", regex) + with open(filename, "r", encoding="utf-8") as fileobj: + for line in fileobj: + if pattern.search(line): + logging.debug(line) + return line + self.fail(f"Could not find r'{regex}' in '{filename}'") + return "" + +class TestBasic(TestBase): + """Basic tests""" + + def setUp(self): + """Before every test: clean Bazel cache""" + super().setUp() + self.check_command("bazel clean") + + def test_bazel_plist_path_resolved(self): + """Test: bazel build :codechecker_virtual_include""" + self.check_command("bazel build //test/unit/virtual_include:codechecker_virtual_include", exit_code=0) + self.check_command("bazel build //test/unit/virtual_include:code_checker_virtual_include", exit_code=0) + plist_files = glob.glob(os.path.join(self.BAZEL_BIN_DIR, "**", "*.plist"), recursive=True) + for plist_file in plist_files: + logging.debug(f"Checking file: {plist_file}") + with open(plist_file, "r") as f: + content = f.read() + if re.search(r"/_virtual_includes/", content): + self.fail(f"Found unresolved symlink within CodeChecker report: {plist_file}") + +def setup_logging(): + """Setup logging level for test execution""" + # Enable debug logs for tests if "super verbose" flag is provided + if "-vvv" in sys.argv: + logging.basicConfig( + level=logging.DEBUG, + format="[TEST] %(levelname)5s: %(message)s") + + +def main(): + """Run unittest""" + setup_logging() + logging.debug("Start testing...") + unittest.main(buffer=True) + + +if __name__ == "__main__": + main() From 0972d3244e25505333042ce5ed33a30932cdfd0f Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Wed, 13 Aug 2025 14:59:54 +0200 Subject: [PATCH 27/59] Create __init__.py --- test/unit/virtual_include/__init__.py | 1 + 1 file changed, 1 insertion(+) create mode 100644 test/unit/virtual_include/__init__.py diff --git a/test/unit/virtual_include/__init__.py b/test/unit/virtual_include/__init__.py new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/test/unit/virtual_include/__init__.py @@ -0,0 +1 @@ + From d76faab72aaf5f6ab48ca9213c03af2bcba06e39 Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Fri, 15 Aug 2025 07:47:15 +0200 Subject: [PATCH 28/59] Rename to fit unittest standards --- .../{virtual_include_test.py => test_virtual_include.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename test/unit/virtual_include/{virtual_include_test.py => test_virtual_include.py} (100%) diff --git a/test/unit/virtual_include/virtual_include_test.py b/test/unit/virtual_include/test_virtual_include.py similarity index 100% rename from test/unit/virtual_include/virtual_include_test.py rename to test/unit/virtual_include/test_virtual_include.py From 14ed3e3792cb19c939a6a65eaeb124452523a5ac Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Fri, 15 Aug 2025 08:30:22 +0200 Subject: [PATCH 29/59] Set to use common lib --- .../virtual_include/test_virtual_include.py | 63 ++----------------- 1 file changed, 6 insertions(+), 57 deletions(-) diff --git a/test/unit/virtual_include/test_virtual_include.py b/test/unit/virtual_include/test_virtual_include.py index 8d52f9bb..83b7fb20 100644 --- a/test/unit/virtual_include/test_virtual_include.py +++ b/test/unit/virtual_include/test_virtual_include.py @@ -23,63 +23,12 @@ import sys import unittest import glob +from ..common.base import TestBase - -class TestBase(unittest.TestCase): - """Unittest base abstract class""" - - BAZEL_BIN_DIR = os.path.join("../../..", "bazel-bin", "test", - "unit", "virtual_include") - BAZEL_TESTLOGS_DIR = os.path.join("../../..", "bazel-testlogs", "test", - "unit", "virtual_include") - - @classmethod - def setUpClass(cls): - """Load module, save environment""" - # Save environment and location - cls.save_env = os.environ - cls.save_cwd = os.getcwd() - # Move to test dir - cls.test_dir = os.path.abspath(os.path.dirname(__file__)) - os.chdir(cls.test_dir) - - @classmethod - def tearDownClass(cls): - """Restore environment""" - os.chdir(cls.save_cwd) - os.environ = cls.save_env - - def setUp(self): - """Before every test""" - logging.debug("\n%s", "-" * 70) - - def check_command(self, cmd, exit_code=0): - """Run shell command and check status""" - logging.debug("Running: %s", cmd) - commands = shlex.split(cmd) - with subprocess.Popen(commands, - stdin=subprocess.PIPE, - stdout=subprocess.PIPE, - stderr=subprocess.PIPE) as process: - stdout, stderr = process.communicate() - self.assertEqual( - process.returncode, - exit_code, "\n" + "\n".join([ - f"command: {cmd}", - f"stdout: {stdout.decode('utf-8')}", - f"stderr: {stderr.decode('utf-8')}"])) - - def grep_file(self, filename, regex): - """Grep given filename""" - pattern = re.compile(regex) - logging.debug("RegEx = r'%s'", regex) - with open(filename, "r", encoding="utf-8") as fileobj: - for line in fileobj: - if pattern.search(line): - logging.debug(line) - return line - self.fail(f"Could not find r'{regex}' in '{filename}'") - return "" +BAZEL_BIN_DIR = os.path.join("../../..", "bazel-bin", "test", + "unit", "virtual_include") +BAZEL_TESTLOGS_DIR = os.path.join("../../..", "bazel-testlogs", "test", + "unit", "virtual_include") class TestBasic(TestBase): """Basic tests""" @@ -93,7 +42,7 @@ def test_bazel_plist_path_resolved(self): """Test: bazel build :codechecker_virtual_include""" self.check_command("bazel build //test/unit/virtual_include:codechecker_virtual_include", exit_code=0) self.check_command("bazel build //test/unit/virtual_include:code_checker_virtual_include", exit_code=0) - plist_files = glob.glob(os.path.join(self.BAZEL_BIN_DIR, "**", "*.plist"), recursive=True) + plist_files = glob.glob(os.path.join(BAZEL_BIN_DIR, "**", "*.plist"), recursive=True) for plist_file in plist_files: logging.debug(f"Checking file: {plist_file}") with open(plist_file, "r") as f: From efedb4766498a0c8c26753e0e46beb64119423a6 Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Fri, 15 Aug 2025 08:35:05 +0200 Subject: [PATCH 30/59] Check whether the _virtual_includes folder really does exists --- test/unit/virtual_include/test_virtual_include.py | 1 + 1 file changed, 1 insertion(+) diff --git a/test/unit/virtual_include/test_virtual_include.py b/test/unit/virtual_include/test_virtual_include.py index 83b7fb20..9e043488 100644 --- a/test/unit/virtual_include/test_virtual_include.py +++ b/test/unit/virtual_include/test_virtual_include.py @@ -43,6 +43,7 @@ def test_bazel_plist_path_resolved(self): self.check_command("bazel build //test/unit/virtual_include:codechecker_virtual_include", exit_code=0) self.check_command("bazel build //test/unit/virtual_include:code_checker_virtual_include", exit_code=0) plist_files = glob.glob(os.path.join(BAZEL_BIN_DIR, "**", "*.plist"), recursive=True) + self.assertTrue(os.path.isdir(f"{BAZEL_BIN_DIR}/_virtual_includes")) for plist_file in plist_files: logging.debug(f"Checking file: {plist_file}") with open(plist_file, "r") as f: From ab107370e6f7be5656792e0abe672ceece6001c8 Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Fri, 15 Aug 2025 14:00:31 +0200 Subject: [PATCH 31/59] remove unnecessary imports --- test/unit/virtual_include/test_virtual_include.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/unit/virtual_include/test_virtual_include.py b/test/unit/virtual_include/test_virtual_include.py index 9e043488..ca946892 100644 --- a/test/unit/virtual_include/test_virtual_include.py +++ b/test/unit/virtual_include/test_virtual_include.py @@ -18,8 +18,6 @@ import logging import os import re -import shlex -import subprocess import sys import unittest import glob From 84f9d25ea70c40f31d9a230fe3297f20464f0eca Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Fri, 15 Aug 2025 14:09:22 +0200 Subject: [PATCH 32/59] Fix import of common module, by adding unit to pythons path --- test/unit/virtual_include/test_virtual_include.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/unit/virtual_include/test_virtual_include.py b/test/unit/virtual_include/test_virtual_include.py index ca946892..c0235689 100644 --- a/test/unit/virtual_include/test_virtual_include.py +++ b/test/unit/virtual_include/test_virtual_include.py @@ -21,7 +21,9 @@ import sys import unittest import glob -from ..common.base import TestBase +# Python path magic, necessary to avoid module errors +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from common.base import TestBase BAZEL_BIN_DIR = os.path.join("../../..", "bazel-bin", "test", "unit", "virtual_include") From edb06ee38e3cd41e9895131fb166350f3b4de01a Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Fri, 15 Aug 2025 14:09:32 +0200 Subject: [PATCH 33/59] Move to common --- .../virtual_include/test_virtual_include.py | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/test/unit/virtual_include/test_virtual_include.py b/test/unit/virtual_include/test_virtual_include.py index c0235689..808fc071 100644 --- a/test/unit/virtual_include/test_virtual_include.py +++ b/test/unit/virtual_include/test_virtual_include.py @@ -51,21 +51,5 @@ def test_bazel_plist_path_resolved(self): if re.search(r"/_virtual_includes/", content): self.fail(f"Found unresolved symlink within CodeChecker report: {plist_file}") -def setup_logging(): - """Setup logging level for test execution""" - # Enable debug logs for tests if "super verbose" flag is provided - if "-vvv" in sys.argv: - logging.basicConfig( - level=logging.DEBUG, - format="[TEST] %(levelname)5s: %(message)s") - - -def main(): - """Run unittest""" - setup_logging() - logging.debug("Start testing...") - unittest.main(buffer=True) - - if __name__ == "__main__": - main() + unittest.main(buffer=True) From c4261b74ca60eab955f6b4fd2e8b5ba63218a5fc Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Fri, 15 Aug 2025 14:27:02 +0200 Subject: [PATCH 34/59] Add comments --- test/unit/virtual_include/test_virtual_include.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/unit/virtual_include/test_virtual_include.py b/test/unit/virtual_include/test_virtual_include.py index 808fc071..7743a82c 100644 --- a/test/unit/virtual_include/test_virtual_include.py +++ b/test/unit/virtual_include/test_virtual_include.py @@ -13,7 +13,7 @@ # limitations under the License. """ -Unit and functional tests +Unit test for resolving path in all plist files """ import logging import os @@ -30,8 +30,8 @@ BAZEL_TESTLOGS_DIR = os.path.join("../../..", "bazel-testlogs", "test", "unit", "virtual_include") -class TestBasic(TestBase): - """Basic tests""" +class TestVirtualInclude(TestBase): + """Tests checking virtual include path resolution""" def setUp(self): """Before every test: clean Bazel cache""" From 30c64bb2feb372d6a9385b03aa742250023ef66c Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Fri, 15 Aug 2025 16:00:36 +0200 Subject: [PATCH 35/59] Fix to new __init__.py --- test/unit/virtual_include/test_virtual_include.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/unit/virtual_include/test_virtual_include.py b/test/unit/virtual_include/test_virtual_include.py index 7743a82c..b9ead8c7 100644 --- a/test/unit/virtual_include/test_virtual_include.py +++ b/test/unit/virtual_include/test_virtual_include.py @@ -21,8 +21,6 @@ import sys import unittest import glob -# Python path magic, necessary to avoid module errors -sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) from common.base import TestBase BAZEL_BIN_DIR = os.path.join("../../..", "bazel-bin", "test", From e77fcfd41fc1ce971e582f146cb79e5d29674e4c Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Fri, 15 Aug 2025 16:02:00 +0200 Subject: [PATCH 36/59] Remove unnecesary include --- test/unit/virtual_include/test_virtual_include.py | 1 - 1 file changed, 1 deletion(-) diff --git a/test/unit/virtual_include/test_virtual_include.py b/test/unit/virtual_include/test_virtual_include.py index b9ead8c7..f90a21a6 100644 --- a/test/unit/virtual_include/test_virtual_include.py +++ b/test/unit/virtual_include/test_virtual_include.py @@ -18,7 +18,6 @@ import logging import os import re -import sys import unittest import glob from common.base import TestBase From 30e56c3194f130ff155f1c998e34ee8333332aa0 Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Mon, 18 Aug 2025 09:09:16 +0200 Subject: [PATCH 37/59] Add path override --- test/unit/virtual_include/test_virtual_include.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/unit/virtual_include/test_virtual_include.py b/test/unit/virtual_include/test_virtual_include.py index f90a21a6..d1dbcf62 100644 --- a/test/unit/virtual_include/test_virtual_include.py +++ b/test/unit/virtual_include/test_virtual_include.py @@ -29,6 +29,8 @@ class TestVirtualInclude(TestBase): """Tests checking virtual include path resolution""" + # This line is mandatory + __test_path__ = os.path.dirname(os.path.abspath(__file__)) def setUp(self): """Before every test: clean Bazel cache""" From f74564f3ae49981200e3d6db66b5bc47edb8eb98 Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Mon, 18 Aug 2025 09:18:46 +0200 Subject: [PATCH 38/59] Format --- .../virtual_include/test_virtual_include.py | 35 +++++++++++++------ 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/test/unit/virtual_include/test_virtual_include.py b/test/unit/virtual_include/test_virtual_include.py index d1dbcf62..1d619379 100644 --- a/test/unit/virtual_include/test_virtual_include.py +++ b/test/unit/virtual_include/test_virtual_include.py @@ -22,14 +22,16 @@ import glob from common.base import TestBase -BAZEL_BIN_DIR = os.path.join("../../..", "bazel-bin", "test", - "unit", "virtual_include") -BAZEL_TESTLOGS_DIR = os.path.join("../../..", "bazel-testlogs", "test", - "unit", "virtual_include") +BAZEL_BIN_DIR = os.path.join("../../..", "bazel-bin", "test", "unit", "virtual_include") +BAZEL_TESTLOGS_DIR = os.path.join( + "../../..", "bazel-testlogs", "test", "unit", "virtual_include" +) + class TestVirtualInclude(TestBase): """Tests checking virtual include path resolution""" - # This line is mandatory + + # This line is mandatory __test_path__ = os.path.dirname(os.path.abspath(__file__)) def setUp(self): @@ -39,16 +41,27 @@ def setUp(self): def test_bazel_plist_path_resolved(self): """Test: bazel build :codechecker_virtual_include""" - self.check_command("bazel build //test/unit/virtual_include:codechecker_virtual_include", exit_code=0) - self.check_command("bazel build //test/unit/virtual_include:code_checker_virtual_include", exit_code=0) - plist_files = glob.glob(os.path.join(BAZEL_BIN_DIR, "**", "*.plist"), recursive=True) + self.check_command( + "bazel build //test/unit/virtual_include:codechecker_virtual_include", + exit_code=0, + ) + self.check_command( + "bazel build //test/unit/virtual_include:code_checker_virtual_include", + exit_code=0, + ) + plist_files = glob.glob( + os.path.join(BAZEL_BIN_DIR, "**", "*.plist"), recursive=True + ) self.assertTrue(os.path.isdir(f"{BAZEL_BIN_DIR}/_virtual_includes")) for plist_file in plist_files: logging.debug(f"Checking file: {plist_file}") - with open(plist_file, "r") as f: + with open(plist_file, "r") as f: content = f.read() if re.search(r"/_virtual_includes/", content): - self.fail(f"Found unresolved symlink within CodeChecker report: {plist_file}") + self.fail( + f"Found unresolved symlink within CodeChecker report: {plist_file}" + ) + if __name__ == "__main__": - unittest.main(buffer=True) + unittest.main(buffer=True) From fb1302fd5a9875d1da137bc5ddbbed196c9e8b28 Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Mon, 18 Aug 2025 09:54:52 +0200 Subject: [PATCH 39/59] change comment --- test/unit/virtual_include/test_virtual_include.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/unit/virtual_include/test_virtual_include.py b/test/unit/virtual_include/test_virtual_include.py index 1d619379..ef29b395 100644 --- a/test/unit/virtual_include/test_virtual_include.py +++ b/test/unit/virtual_include/test_virtual_include.py @@ -22,7 +22,9 @@ import glob from common.base import TestBase -BAZEL_BIN_DIR = os.path.join("../../..", "bazel-bin", "test", "unit", "virtual_include") +BAZEL_BIN_DIR = os.path.join( + "../../..", "bazel-bin", "test", "unit", "virtual_include" +) BAZEL_TESTLOGS_DIR = os.path.join( "../../..", "bazel-testlogs", "test", "unit", "virtual_include" ) @@ -31,7 +33,7 @@ class TestVirtualInclude(TestBase): """Tests checking virtual include path resolution""" - # This line is mandatory + # Set working directory __test_path__ = os.path.dirname(os.path.abspath(__file__)) def setUp(self): From 42b1ee790b2fa4a69038ef98b88e14605dee6528 Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Mon, 18 Aug 2025 11:34:43 +0200 Subject: [PATCH 40/59] Add license --- test/unit/virtual_include/BUILD | 36 ++++++++++--------------- test/unit/virtual_include/inc/zeroDiv.h | 14 ++++++++++ test/unit/virtual_include/source.cc | 16 ++++++++++- 3 files changed, 43 insertions(+), 23 deletions(-) diff --git a/test/unit/virtual_include/BUILD b/test/unit/virtual_include/BUILD index 504371ad..e897818c 100644 --- a/test/unit/virtual_include/BUILD +++ b/test/unit/virtual_include/BUILD @@ -1,3 +1,17 @@ +# Copyright 2023 Ericsson AB +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + # cc_binary for simple C++ tests load( "@rules_cc//cc:defs.bzl", @@ -5,34 +19,12 @@ load( "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( diff --git a/test/unit/virtual_include/inc/zeroDiv.h b/test/unit/virtual_include/inc/zeroDiv.h index f6ebbf2c..e50cd747 100644 --- a/test/unit/virtual_include/inc/zeroDiv.h +++ b/test/unit/virtual_include/inc/zeroDiv.h @@ -1,3 +1,17 @@ +// Copyright 2023 Ericsson AB +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + #ifndef ZERODIV_H #define ZERODIV_H int warnMe(){ diff --git a/test/unit/virtual_include/source.cc b/test/unit/virtual_include/source.cc index 673f028e..cfb8a011 100644 --- a/test/unit/virtual_include/source.cc +++ b/test/unit/virtual_include/source.cc @@ -1,5 +1,19 @@ +// Copyright 2023 Ericsson AB +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + #include "zeroDiv.h" int main(){ return 0; -} \ No newline at end of file +} From 96819d8561ddfb637146f455f84990e5d9be6ae3 Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Mon, 18 Aug 2025 15:00:43 +0200 Subject: [PATCH 41/59] Update test to follow common lib --- .../virtual_include/test_virtual_include.py | 31 ++++++++++--------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/test/unit/virtual_include/test_virtual_include.py b/test/unit/virtual_include/test_virtual_include.py index ef29b395..0afb03d9 100644 --- a/test/unit/virtual_include/test_virtual_include.py +++ b/test/unit/virtual_include/test_virtual_include.py @@ -22,39 +22,40 @@ import glob from common.base import TestBase -BAZEL_BIN_DIR = os.path.join( - "../../..", "bazel-bin", "test", "unit", "virtual_include" -) -BAZEL_TESTLOGS_DIR = os.path.join( - "../../..", "bazel-testlogs", "test", "unit", "virtual_include" -) - class TestVirtualInclude(TestBase): """Tests checking virtual include path resolution""" # Set working directory __test_path__ = os.path.dirname(os.path.abspath(__file__)) + BAZEL_BIN_DIR = os.path.join( + "../../..", "bazel-bin", "test", "unit", "virtual_include" + ) + BAZEL_TESTLOGS_DIR = os.path.join( + "../../..", "bazel-testlogs", "test", "unit", "virtual_include" + ) def setUp(self): """Before every test: clean Bazel cache""" super().setUp() - self.check_command("bazel clean") + self.run_command("bazel clean") def test_bazel_plist_path_resolved(self): """Test: bazel build :codechecker_virtual_include""" - self.check_command( - "bazel build //test/unit/virtual_include:codechecker_virtual_include", - exit_code=0, + ret, _, _ = self.run_command( + "bazel build //test/unit/virtual_include:codechecker_virtual_include" ) - self.check_command( + self.assertEqual(ret, 0) + self.run_command( "bazel build //test/unit/virtual_include:code_checker_virtual_include", - exit_code=0, ) + self.assertEqual(ret, 0) plist_files = glob.glob( - os.path.join(BAZEL_BIN_DIR, "**", "*.plist"), recursive=True + os.path.join(self.BAZEL_BIN_DIR, "**", "*.plist"), recursive=True + ) + self.assertTrue( + os.path.isdir(f"{self.BAZEL_BIN_DIR}/_virtual_includes") ) - self.assertTrue(os.path.isdir(f"{BAZEL_BIN_DIR}/_virtual_includes")) for plist_file in plist_files: logging.debug(f"Checking file: {plist_file}") with open(plist_file, "r") as f: From 7679d95ce5359c3b5659b382550737787c12c6ec Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Tue, 19 Aug 2025 15:03:00 +0200 Subject: [PATCH 42/59] Form to new template --- .../virtual_include/test_virtual_include.py | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/test/unit/virtual_include/test_virtual_include.py b/test/unit/virtual_include/test_virtual_include.py index 0afb03d9..3b01d124 100644 --- a/test/unit/virtual_include/test_virtual_include.py +++ b/test/unit/virtual_include/test_virtual_include.py @@ -20,6 +20,7 @@ import re import unittest import glob +from typing import final from common.base import TestBase @@ -35,10 +36,26 @@ class TestVirtualInclude(TestBase): "../../..", "bazel-testlogs", "test", "unit", "virtual_include" ) + @final + @classmethod + def setUpClass(cls): + """TODO: Define set up before the test suite""" + super().setUpClass() + cls.run_command("bazel clean") + + @final + @classmethod + def tearDownClass(cls): + """TODO: Define clean up after the test suite""" + super().tearDownClass() + def setUp(self): - """Before every test: clean Bazel cache""" + """TODO: Define clean up before every test""" super().setUp() - self.run_command("bazel clean") + + def tearDown(self): + """TODO: Define clean up after every test""" + return super().tearDown() def test_bazel_plist_path_resolved(self): """Test: bazel build :codechecker_virtual_include""" @@ -46,7 +63,7 @@ def test_bazel_plist_path_resolved(self): "bazel build //test/unit/virtual_include:codechecker_virtual_include" ) self.assertEqual(ret, 0) - self.run_command( + ret, _, _ = self.run_command( "bazel build //test/unit/virtual_include:code_checker_virtual_include", ) self.assertEqual(ret, 0) From e20e8a670af74b57d41b757be3ee24e26a20bd67 Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Thu, 21 Aug 2025 07:04:58 +0200 Subject: [PATCH 43/59] Use base lib grep instead --- test/unit/virtual_include/test_virtual_include.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/test/unit/virtual_include/test_virtual_include.py b/test/unit/virtual_include/test_virtual_include.py index 3b01d124..119c5a4c 100644 --- a/test/unit/virtual_include/test_virtual_include.py +++ b/test/unit/virtual_include/test_virtual_include.py @@ -75,12 +75,10 @@ def test_bazel_plist_path_resolved(self): ) for plist_file in plist_files: logging.debug(f"Checking file: {plist_file}") - with open(plist_file, "r") as f: - content = f.read() - if re.search(r"/_virtual_includes/", content): - self.fail( - f"Found unresolved symlink within CodeChecker report: {plist_file}" - ) + if self.grep_file(plist_file, r"/_virtual_includes/"): + self.fail( + f"Found unresolved symlink within CodeChecker report: {plist_file}" + ) if __name__ == "__main__": From 17a542e7c5f5ea626edf261dc36ac16c7be5002f Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Thu, 21 Aug 2025 09:26:44 +0200 Subject: [PATCH 44/59] Fix test to pass --- test/unit/virtual_include/test_virtual_include.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/unit/virtual_include/test_virtual_include.py b/test/unit/virtual_include/test_virtual_include.py index 119c5a4c..dab23ef1 100644 --- a/test/unit/virtual_include/test_virtual_include.py +++ b/test/unit/virtual_include/test_virtual_include.py @@ -75,7 +75,8 @@ def test_bazel_plist_path_resolved(self): ) for plist_file in plist_files: logging.debug(f"Checking file: {plist_file}") - if self.grep_file(plist_file, r"/_virtual_includes/"): + # FIXME: This shouldn't find anything + if len(self.grep_file(plist_file, r"/_virtual_includes/")) < 0: self.fail( f"Found unresolved symlink within CodeChecker report: {plist_file}" ) From cb9e07b2bc4702c857436c410a9b4d8e9a1e3104 Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Thu, 21 Aug 2025 10:21:09 +0200 Subject: [PATCH 45/59] Add zero division not detectable by compiler --- test/unit/virtual_include/inc/zeroDiv.h | 5 +++-- test/unit/virtual_include/source.cc | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/test/unit/virtual_include/inc/zeroDiv.h b/test/unit/virtual_include/inc/zeroDiv.h index e50cd747..36dc565d 100644 --- a/test/unit/virtual_include/inc/zeroDiv.h +++ b/test/unit/virtual_include/inc/zeroDiv.h @@ -14,8 +14,9 @@ #ifndef ZERODIV_H #define ZERODIV_H -int warnMe(){ - return 1/0; +int warnMe(int i){ + if (i == 0) + return 1/i; } #endif //ZERODIV_H diff --git a/test/unit/virtual_include/source.cc b/test/unit/virtual_include/source.cc index cfb8a011..f8ea427f 100644 --- a/test/unit/virtual_include/source.cc +++ b/test/unit/virtual_include/source.cc @@ -15,5 +15,6 @@ #include "zeroDiv.h" int main(){ + warnMe(0); return 0; } From ef5159f41837978d8dbddb2b0237397a69013a7e Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Thu, 21 Aug 2025 10:21:51 +0200 Subject: [PATCH 46/59] Change to lib --- test/unit/virtual_include/BUILD | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/unit/virtual_include/BUILD b/test/unit/virtual_include/BUILD index e897818c..790b1583 100644 --- a/test/unit/virtual_include/BUILD +++ b/test/unit/virtual_include/BUILD @@ -15,7 +15,6 @@ # cc_binary for simple C++ tests load( "@rules_cc//cc:defs.bzl", - "cc_binary", "cc_library", ) @@ -42,7 +41,7 @@ cc_library( ) # Simplest C++ test which should FAIL -cc_binary( +cc_library( name = "virtual_include", srcs = ["source.cc"], deps = ["test_inc"], From 1b94f5c7f018e2856bde243bb57f501dc858dbe0 Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Thu, 21 Aug 2025 10:22:17 +0200 Subject: [PATCH 47/59] Remove unused functions --- test/unit/virtual_include/test_virtual_include.py | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/test/unit/virtual_include/test_virtual_include.py b/test/unit/virtual_include/test_virtual_include.py index dab23ef1..caf5ff01 100644 --- a/test/unit/virtual_include/test_virtual_include.py +++ b/test/unit/virtual_include/test_virtual_include.py @@ -43,19 +43,6 @@ def setUpClass(cls): super().setUpClass() cls.run_command("bazel clean") - @final - @classmethod - def tearDownClass(cls): - """TODO: Define clean up after the test suite""" - super().tearDownClass() - - def setUp(self): - """TODO: Define clean up before every test""" - super().setUp() - - def tearDown(self): - """TODO: Define clean up after every test""" - return super().tearDown() def test_bazel_plist_path_resolved(self): """Test: bazel build :codechecker_virtual_include""" From 5c570bb3d160ac991ae239ffe7935612e48adee1 Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Thu, 21 Aug 2025 10:22:28 +0200 Subject: [PATCH 48/59] Change comment --- test/unit/virtual_include/test_virtual_include.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/virtual_include/test_virtual_include.py b/test/unit/virtual_include/test_virtual_include.py index caf5ff01..a49d5cf3 100644 --- a/test/unit/virtual_include/test_virtual_include.py +++ b/test/unit/virtual_include/test_virtual_include.py @@ -39,7 +39,7 @@ class TestVirtualInclude(TestBase): @final @classmethod def setUpClass(cls): - """TODO: Define set up before the test suite""" + """Set up before the test suite""" super().setUpClass() cls.run_command("bazel clean") From 545eb218160ea62872c6270033035a121b500239 Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Thu, 21 Aug 2025 10:23:27 +0200 Subject: [PATCH 49/59] Change way of detection, add new function --- .../virtual_include/test_virtual_include.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/test/unit/virtual_include/test_virtual_include.py b/test/unit/virtual_include/test_virtual_include.py index a49d5cf3..b07888e3 100644 --- a/test/unit/virtual_include/test_virtual_include.py +++ b/test/unit/virtual_include/test_virtual_include.py @@ -43,6 +43,13 @@ def setUpClass(cls): super().setUpClass() cls.run_command("bazel clean") + def contains_in_files(self, regex, folder_path): + result = [] + for file in folder_path: + logging.debug(f"Checking file: {file}") + if self.grep_file(file, regex): + result.append(file) + return result def test_bazel_plist_path_resolved(self): """Test: bazel build :codechecker_virtual_include""" @@ -60,13 +67,10 @@ def test_bazel_plist_path_resolved(self): self.assertTrue( os.path.isdir(f"{self.BAZEL_BIN_DIR}/_virtual_includes") ) - for plist_file in plist_files: - logging.debug(f"Checking file: {plist_file}") - # FIXME: This shouldn't find anything - if len(self.grep_file(plist_file, r"/_virtual_includes/")) < 0: - self.fail( - f"Found unresolved symlink within CodeChecker report: {plist_file}" - ) + # FIXME: This should be equal + self.assertNotEqual( + self.contains_in_files(r"/_virtual_includes/", plist_files), [] + ) if __name__ == "__main__": From b747da88cd960780553f31d6f6b6029026f835ee Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Thu, 21 Aug 2025 10:29:38 +0200 Subject: [PATCH 50/59] Split check into 2 --- .../virtual_include/test_virtual_include.py | 35 ++++++++++++++++--- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/test/unit/virtual_include/test_virtual_include.py b/test/unit/virtual_include/test_virtual_include.py index b07888e3..b373c6ca 100644 --- a/test/unit/virtual_include/test_virtual_include.py +++ b/test/unit/virtual_include/test_virtual_include.py @@ -51,18 +51,43 @@ def contains_in_files(self, regex, folder_path): result.append(file) return result - def test_bazel_plist_path_resolved(self): - """Test: bazel build :codechecker_virtual_include""" + def test_bazel_code_checker_plist_path_resolved(self): + """Test: bazel build :code_checker_virtual_include""" ret, _, _ = self.run_command( - "bazel build //test/unit/virtual_include:codechecker_virtual_include" + "bazel build //test/unit/virtual_include:code_checker_virtual_include", ) self.assertEqual(ret, 0) + plist_files = glob.glob( + os.path.join( + self.BAZEL_BIN_DIR, + "code_checker_virtual_include", + "**", + "*.plist", + ), + recursive=True, + ) + self.assertTrue( + os.path.isdir(f"{self.BAZEL_BIN_DIR}/_virtual_includes") + ) + # FIXME: This should be equal + self.assertNotEqual( + self.contains_in_files(r"/_virtual_includes/", plist_files), [] + ) + + def test_bazel_codechecker_plist_path_resolved(self): + """Test: bazel build :codechecker_virtual_include""" ret, _, _ = self.run_command( - "bazel build //test/unit/virtual_include:code_checker_virtual_include", + "bazel build //test/unit/virtual_include:codechecker_virtual_include" ) self.assertEqual(ret, 0) plist_files = glob.glob( - os.path.join(self.BAZEL_BIN_DIR, "**", "*.plist"), recursive=True + os.path.join( + self.BAZEL_BIN_DIR, + "codechecker_virtual_include", + "**", + "*.plist", + ), + recursive=True, ) self.assertTrue( os.path.isdir(f"{self.BAZEL_BIN_DIR}/_virtual_includes") From 0f48b4acad1d6b0a1bab230001321be209eb1137 Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Thu, 21 Aug 2025 10:31:31 +0200 Subject: [PATCH 51/59] Remove comment --- test/unit/virtual_include/BUILD | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/unit/virtual_include/BUILD b/test/unit/virtual_include/BUILD index 790b1583..57db52fb 100644 --- a/test/unit/virtual_include/BUILD +++ b/test/unit/virtual_include/BUILD @@ -24,8 +24,6 @@ load( "codechecker_test", ) -# Prototype for CodeChecker analyze --file -# NOTE: CodeChecker analyze --file --ctu does not work load( "@bazel_codechecker//src:code_checker.bzl", "code_checker_test", From 9586d625933d1ecc53e078ab3c9716aa7530236f Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Thu, 21 Aug 2025 10:42:39 +0200 Subject: [PATCH 52/59] remove unnecessary comments --- test/unit/virtual_include/BUILD | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/unit/virtual_include/BUILD b/test/unit/virtual_include/BUILD index 57db52fb..e589a441 100644 --- a/test/unit/virtual_include/BUILD +++ b/test/unit/virtual_include/BUILD @@ -33,8 +33,6 @@ load( 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", ) From d3ef6870894f3148167b06f0e5bd7422f53cc628 Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Thu, 21 Aug 2025 11:35:12 +0200 Subject: [PATCH 53/59] Update test/unit/virtual_include/test_virtual_include.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Kristóf Umann --- test/unit/virtual_include/test_virtual_include.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/unit/virtual_include/test_virtual_include.py b/test/unit/virtual_include/test_virtual_include.py index b373c6ca..88345ccd 100644 --- a/test/unit/virtual_include/test_virtual_include.py +++ b/test/unit/virtual_include/test_virtual_include.py @@ -69,7 +69,8 @@ def test_bazel_code_checker_plist_path_resolved(self): self.assertTrue( os.path.isdir(f"{self.BAZEL_BIN_DIR}/_virtual_includes") ) - # FIXME: This should be equal + # FIXME: In the postprocessed plists, all _virtual_include paths should've been + # removed. Possible fix is in the github PR #14. self.assertNotEqual( self.contains_in_files(r"/_virtual_includes/", plist_files), [] ) From 12fa5c649d49b9ae61c19d2bc5f4078b99b7993d Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Thu, 21 Aug 2025 13:10:26 +0200 Subject: [PATCH 54/59] Remove comments --- test/unit/virtual_include/BUILD | 1 - 1 file changed, 1 deletion(-) diff --git a/test/unit/virtual_include/BUILD b/test/unit/virtual_include/BUILD index e589a441..a7395156 100644 --- a/test/unit/virtual_include/BUILD +++ b/test/unit/virtual_include/BUILD @@ -36,7 +36,6 @@ cc_library( strip_include_prefix = "inc", ) -# Simplest C++ test which should FAIL cc_library( name = "virtual_include", srcs = ["source.cc"], From cf98334a8fcac76c10d6a44f94221acc974f5030 Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Thu, 21 Aug 2025 13:10:41 +0200 Subject: [PATCH 55/59] Add description to test file --- test/unit/virtual_include/test_virtual_include.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/test/unit/virtual_include/test_virtual_include.py b/test/unit/virtual_include/test_virtual_include.py index 88345ccd..2c1f2192 100644 --- a/test/unit/virtual_include/test_virtual_include.py +++ b/test/unit/virtual_include/test_virtual_include.py @@ -13,7 +13,14 @@ # limitations under the License. """ -Unit test for resolving path in all plist files +We want CodeChecker to point to the original files in its results, this needs +post processing. +Bazel creates _virtual_includes folder for headers, declared in a cc_library +rule with the include_prefix or strip_include_prefix. When warnings are found +in these headers, their paths in the plist files should get resolved to the +original file path. +This unittest test whether these paths containing `_virtual_include` have been +resolved """ import logging import os From c590c276463729daa0661cbc92f57f41bc209fb6 Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Thu, 21 Aug 2025 13:43:30 +0200 Subject: [PATCH 56/59] Use common lib --- test/unit/virtual_include/test_virtual_include.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/virtual_include/test_virtual_include.py b/test/unit/virtual_include/test_virtual_include.py index 2c1f2192..65261ec5 100644 --- a/test/unit/virtual_include/test_virtual_include.py +++ b/test/unit/virtual_include/test_virtual_include.py @@ -54,7 +54,7 @@ def contains_in_files(self, regex, folder_path): result = [] for file in folder_path: logging.debug(f"Checking file: {file}") - if self.grep_file(file, regex): + if self.contains_regex_in_file: result.append(file) return result From b9dff14d1696eecab2a087d469d8f90095e549fd Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Thu, 21 Aug 2025 13:44:16 +0200 Subject: [PATCH 57/59] Add license --- test/unit/virtual_include/__init__.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/test/unit/virtual_include/__init__.py b/test/unit/virtual_include/__init__.py index 8b137891..78bab5f1 100644 --- a/test/unit/virtual_include/__init__.py +++ b/test/unit/virtual_include/__init__.py @@ -1 +1,13 @@ - +# Copyright 2023 Ericsson AB +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. From 74e7c980804c19fdc98f42c5fe7231c331565aa5 Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Thu, 21 Aug 2025 13:47:08 +0200 Subject: [PATCH 58/59] Add comments --- test/unit/virtual_include/test_virtual_include.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/unit/virtual_include/test_virtual_include.py b/test/unit/virtual_include/test_virtual_include.py index 65261ec5..4681e9dc 100644 --- a/test/unit/virtual_include/test_virtual_include.py +++ b/test/unit/virtual_include/test_virtual_include.py @@ -73,6 +73,7 @@ def test_bazel_code_checker_plist_path_resolved(self): ), recursive=True, ) + # Test whether the _virtual_include directory was actually created. self.assertTrue( os.path.isdir(f"{self.BAZEL_BIN_DIR}/_virtual_includes") ) @@ -97,10 +98,12 @@ def test_bazel_codechecker_plist_path_resolved(self): ), recursive=True, ) + # Test whether the _virtual_include directory was actually created. self.assertTrue( os.path.isdir(f"{self.BAZEL_BIN_DIR}/_virtual_includes") ) - # FIXME: This should be equal + # FIXME: In the postprocessed plists, all _virtual_include paths should've been + # removed. Possible fix is in the github PR #14. self.assertNotEqual( self.contains_in_files(r"/_virtual_includes/", plist_files), [] ) From e2ee06fa12f79774f513060399973960de7a64ff Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Thu, 21 Aug 2025 14:22:57 +0200 Subject: [PATCH 59/59] Fix formating --- test/unit/virtual_include/test_virtual_include.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/unit/virtual_include/test_virtual_include.py b/test/unit/virtual_include/test_virtual_include.py index 4681e9dc..b6671d37 100644 --- a/test/unit/virtual_include/test_virtual_include.py +++ b/test/unit/virtual_include/test_virtual_include.py @@ -20,7 +20,7 @@ in these headers, their paths in the plist files should get resolved to the original file path. This unittest test whether these paths containing `_virtual_include` have been -resolved +resolved """ import logging import os @@ -77,8 +77,8 @@ def test_bazel_code_checker_plist_path_resolved(self): self.assertTrue( os.path.isdir(f"{self.BAZEL_BIN_DIR}/_virtual_includes") ) - # FIXME: In the postprocessed plists, all _virtual_include paths should've been - # removed. Possible fix is in the github PR #14. + # FIXME: In the postprocessed plists, all _virtual_include paths + # should've been removed. Possible fix is in the github PR #14. self.assertNotEqual( self.contains_in_files(r"/_virtual_includes/", plist_files), [] ) @@ -102,8 +102,8 @@ def test_bazel_codechecker_plist_path_resolved(self): self.assertTrue( os.path.isdir(f"{self.BAZEL_BIN_DIR}/_virtual_includes") ) - # FIXME: In the postprocessed plists, all _virtual_include paths should've been - # removed. Possible fix is in the github PR #14. + # FIXME: In the postprocessed plists, all _virtual_include paths + # should've been removed. Possible fix is in the github PR #14. self.assertNotEqual( self.contains_in_files(r"/_virtual_includes/", plist_files), [] )