Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
ad09716
Add logging to base class
furtib Aug 15, 2025
e301806
Fix path problems
furtib Aug 18, 2025
7300af9
Add way to pass path to base class, move folder change before environ…
furtib Aug 18, 2025
b7767d7
Format
furtib Aug 18, 2025
684b954
Move template into unittest folder
furtib Aug 18, 2025
ba55b0c
Change template place
furtib Aug 18, 2025
86af7d5
Enforce setting __test_path__ BAZEL_BIN_DIR and BAZEL_TESTLOGS_DIR
furtib Aug 18, 2025
f4a49cd
Revert "Move template into unittest folder"
furtib Aug 19, 2025
d3893a2
Revert "Change template place"
furtib Aug 19, 2025
9c4ef5d
Add comments, and teardown method
furtib Aug 19, 2025
caa8916
Move clean command to only run once per suite
furtib Aug 19, 2025
e807c8b
Test splitting to files by platform
furtib Aug 11, 2025
fe64b0c
Revert "Test splitting to files by platform"
furtib Aug 11, 2025
663ddb3
Change message, rename file
furtib Aug 14, 2025
44695be
What extra " ?
furtib Aug 14, 2025
891cf6a
Reword Note
furtib Aug 14, 2025
a43633e
Update Note for rhel9 to
furtib Aug 15, 2025
fb753da
Add composite actions for environment setup
furtib Aug 15, 2025
108e4d6
Use composite actions
furtib Aug 15, 2025
1ca4911
Chenge extension yml to yaml
furtib Aug 18, 2025
38216f9
Move composite actions into a different directory
furtib Aug 18, 2025
a3ad98a
Trigger Build
furtib Aug 18, 2025
55afb25
Trigger Build
furtib Aug 18, 2025
7845c01
Add test for path resolution, in plist files (in accordance with #22)
furtib Aug 12, 2025
60700f0
Add manual tag
furtib Aug 12, 2025
238f971
Add python test
furtib Aug 13, 2025
0972d32
Create __init__.py
furtib Aug 13, 2025
d76faab
Rename to fit unittest standards
furtib Aug 15, 2025
14ed3e3
Set to use common lib
furtib Aug 15, 2025
efedb47
Check whether the _virtual_includes folder really does exists
furtib Aug 15, 2025
ab10737
remove unnecessary imports
furtib Aug 15, 2025
84f9d25
Fix import of common module, by adding unit to pythons path
furtib Aug 15, 2025
edb06ee
Move to common
furtib Aug 15, 2025
c4261b7
Add comments
furtib Aug 15, 2025
30c64bb
Fix to new __init__.py
furtib Aug 15, 2025
e77fcfd
Remove unnecesary include
furtib Aug 15, 2025
30e56c3
Add path override
furtib Aug 18, 2025
f74564f
Format
furtib Aug 18, 2025
fb1302f
change comment
furtib Aug 18, 2025
42b1ee7
Add license
furtib Aug 18, 2025
96819d8
Update test to follow common lib
furtib Aug 18, 2025
7679d95
Form to new template
furtib Aug 19, 2025
e20e8a6
Use base lib grep instead
furtib Aug 21, 2025
17a542e
Fix test to pass
furtib Aug 21, 2025
cb9e07b
Add zero division not detectable by compiler
furtib Aug 21, 2025
ef5159f
Change to lib
furtib Aug 21, 2025
1b94f5c
Remove unused functions
furtib Aug 21, 2025
5c570bb
Change comment
furtib Aug 21, 2025
545eb21
Change way of detection, add new function
furtib Aug 21, 2025
b747da8
Split check into 2
furtib Aug 21, 2025
0f48b4a
Remove comment
furtib Aug 21, 2025
9586d62
remove unnecessary comments
furtib Aug 21, 2025
d3ef687
Update test/unit/virtual_include/test_virtual_include.py
furtib Aug 21, 2025
12fa5c6
Remove comments
furtib Aug 21, 2025
cf98334
Add description to test file
furtib Aug 21, 2025
c590c27
Use common lib
furtib Aug 21, 2025
b9dff14
Add license
furtib Aug 21, 2025
74e7c98
Add comments
furtib Aug 21, 2025
e2ee06f
Fix formating
furtib Aug 21, 2025
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
64 changes: 64 additions & 0 deletions test/unit/virtual_include/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# 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",
"cc_library",
)

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

load(
"@bazel_codechecker//src:code_checker.bzl",
"code_checker_test",
)

# Test for strip_include_prefix
cc_library(
name = "test_inc",
hdrs = glob(["inc/*.h"]),
strip_include_prefix = "inc",
)

cc_library(
name = "virtual_include",
srcs = ["source.cc"],
deps = ["test_inc"],
)

# Simplest virtual include resolution test
codechecker_test(
name = "codechecker_virtual_include",
tags = [
"manual",
],
targets = [
"virtual_include",
],
)

code_checker_test(
name = "code_checker_virtual_include",
tags = [
"manual",
],
targets = [
"virtual_include",
]
)
13 changes: 13 additions & 0 deletions test/unit/virtual_include/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +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.
22 changes: 22 additions & 0 deletions test/unit/virtual_include/inc/zeroDiv.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// 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(int i){
if (i == 0)
return 1/i;
}
#endif //ZERODIV_H

20 changes: 20 additions & 0 deletions test/unit/virtual_include/source.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// 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(){
warnMe(0);
return 0;
}
113 changes: 113 additions & 0 deletions test/unit/virtual_include/test_virtual_include.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
# 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.

"""
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
import re
import unittest
import glob
from typing import final
from common.base import TestBase


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"
)

@final
@classmethod
def setUpClass(cls):
"""Set up before the test suite"""
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.contains_regex_in_file:
result.append(file)
return result

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: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,
)
# Test whether the _virtual_include directory was actually created.
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.
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:codechecker_virtual_include"
)
self.assertEqual(ret, 0)
plist_files = glob.glob(
os.path.join(
self.BAZEL_BIN_DIR,
"codechecker_virtual_include",
"**",
"*.plist",
),
recursive=True,
)
# Test whether the _virtual_include directory was actually created.
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.
self.assertNotEqual(
self.contains_in_files(r"/_virtual_includes/", plist_files), []
)


if __name__ == "__main__":
unittest.main(buffer=True)