Skip to content
Merged
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
83 changes: 83 additions & 0 deletions test/unit/skip/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# 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",
)
load(
"//src:codechecker.bzl",
"codechecker_test",
)

cc_library(
name = "simple_target",
srcs = [
"main.cc",
"skip.cc",
"skip.h",
"skip2.cc",
"skip2.h",
],
tags = ["manual"],
)

# The monolithic rule uses codechecker's built in skipfile
# We expect that to be correct, further testing of it is unnecessary
codechecker_test(
name = "codechecker_skipfile",
skip = [
"-*test/unit/skip/skip*",
],
targets = [
"simple_target",
],
)

codechecker_test(
name = "per_file_skipfile_exact_file_path",
per_file = True,
skip = [
"-*test/unit/skip/skip.cc",
],
tags = ["manual"],
targets = [
"simple_target",
],
)

codechecker_test(
name = "per_file_skipfile_folder_skip_path",
per_file = True,
skip = [
"-*test/*/skip.cc",
],
tags = ["manual"],
targets = [
"simple_target",
],
)

codechecker_test(
name = "per_file_skipfile_both_files",
per_file = True,
skip = [
"-*test/unit/skip/skip*",
],
tags = ["manual"],
targets = [
"simple_target",
],
)
13 changes: 13 additions & 0 deletions test/unit/skip/__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.
24 changes: 24 additions & 0 deletions test/unit/skip/main.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* 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 "skip.h"
#include "skip2.h"

int main(){
skip_function();
skip2_function(nullptr);
return 0;
}
23 changes: 23 additions & 0 deletions test/unit/skip/skip.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* 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 "skip.h"

// cause a division by zero error
int skip_function() {
int zero = 0;
return 0 / zero;
}
22 changes: 22 additions & 0 deletions test/unit/skip/skip.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 SKIP_FUNCTION_H
#define SKIP_FUNCTION_H

int skip_function();

#endif // SKIP_FUNCTION_H
27 changes: 27 additions & 0 deletions test/unit/skip/skip2.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* 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 <stdlib.h>
#include "skip2.h"

// cause a warning
int skip2_function(int* a) {
if(a == nullptr){

}
int thing = *a;
return 0;
}
22 changes: 22 additions & 0 deletions test/unit/skip/skip2.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 SKIP2_FUNCTION_H
#define SKIP2_FUNCTION_H

int skip2_function(int* a);

#endif // SKIP2_FUNCTION_H
108 changes: 108 additions & 0 deletions test/unit/skip/test_skip.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# 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.

"""
Test the skip option for codechecker rules.
"""
import os
import unittest
from common.base import TestBase


class TestSkip(TestBase):
"""Tests involving the skip argument of codechecker rules"""

# Set working directory
__test_path__ = os.path.dirname(os.path.abspath(__file__))
BAZEL_BIN_DIR = os.path.join(
"../../..", "bazel-bin", "test", "unit", "skip"
)
BAZEL_TESTLOGS_DIR = os.path.join(
"../../..", "bazel-testlogs", "test", "unit", "skip"
)

def test_codechecker_skipfile(self):
"""
Test: bazel test //test/unit/skip:codechecker_skipfile
"""
ret, _, stderr = self.run_command(
"bazel test //test/unit/skip:codechecker_skipfile"
)
self.assertEqual(ret, 0, stderr)

def test_per_file_skipfile_full_path(self):
"""
Test: bazel test //test/unit/skip:per_file_skipfile_exact_file_path
"""
ret, _, stderr = self.run_command(
"bazel test //test/unit/skip:per_file_skipfile_exact_file_path"
)
self.assertEqual(ret, 3, stderr)
log_file = (
f"{self.BAZEL_TESTLOGS_DIR}/"
"per_file_skipfile_exact_file_path/test.log"
)
# FIXME: change to assertFalse, this file should be skipped
self.assertTrue(
self.contains_regex_in_file(log_file, r"defect\(s\) in skip.cc")
)
self.assertTrue(
self.contains_regex_in_file(log_file, r"defect\(s\) in skip2.cc")
)

def test_per_file_skipfile_folder_skip_path(self):
"""
Test: bazel test //test/unit/skip:per_file_skipfile_folder_skip_path
"""
ret, _, stderr = self.run_command(
"bazel test //test/unit/skip:per_file_skipfile_folder_skip_path"
)
self.assertEqual(ret, 3, stderr)
log_file = (
f"{self.BAZEL_TESTLOGS_DIR}/"
"per_file_skipfile_folder_skip_path/test.log"
)
# FIXME: change to assertFalse, this file should be skipped
self.assertTrue(
self.contains_regex_in_file(log_file, r"defect\(s\) in skip.cc")
)
# This is correct.
self.assertTrue(
Comment thread
furtib marked this conversation as resolved.
self.contains_regex_in_file(log_file, r"defect\(s\) in skip2.cc")
)

def test_per_file_skipfile_both_files(self):
"""
Test: bazel test //test/unit/skip:per_file_skipfile_both_files
"""
ret, _, stderr = self.run_command(
"bazel test //test/unit/skip:per_file_skipfile_both_files"
)
# FIXME: The return code here should be 0, both files should be skipped
self.assertEqual(ret, 3, stderr)
log_file = (
f"{self.BAZEL_TESTLOGS_DIR}/per_file_skipfile_both_files/test.log"
)
# FIXME: Change to assertFalse after fix, should have been skipped.
self.assertTrue(
Comment thread
furtib marked this conversation as resolved.
self.contains_regex_in_file(log_file, r"defect\(s\) in skip.cc")
)
# FIXME: Change to assertFalse after fix, should have been skipped.
self.assertTrue(
Comment thread
furtib marked this conversation as resolved.
self.contains_regex_in_file(log_file, r"defect\(s\) in skip2.cc")
)


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