Skip to content
Open
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
18 changes: 12 additions & 6 deletions cli/processexecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,12 @@ unsigned int ProcessExecutor::check()
return v + p.size();
});

// pass unmodified suppressions to forked process so we only transfer back the actual changes done by the fork
// and do not see the changes which have already been transferred back
Suppressions supprs;
supprs.nomsg.addSuppressions(mSuppressions.nomsg.getSuppressions());
supprs.nofail.addSuppressions(mSuppressions.nofail.getSuppressions());

std::list<int> rpipes;
std::map<pid_t, std::string> childFile;
std::map<int, std::string> pipeFile;
Expand Down Expand Up @@ -380,13 +386,13 @@ unsigned int ProcessExecutor::check()
#endif
close(pipes[0]);

// reset so we do not have the data which has already been transferred back
// create a separate result object so we do not get the results which have already been transferred back
std::unique_ptr<TimerResults> timerResults;
if (mTimerResults)
mTimerResults->reset();
// TODO: how to "reset" mSuppressions?
timerResults.reset(new TimerResults);

PipeWriter pipewriter(pipes[1], mSettings.debugipc);
CppCheck fileChecker(mSettings, mSuppressions, pipewriter, mTimerResults, false, mExecuteCommand);
CppCheck fileChecker(mSettings, supprs, pipewriter, timerResults.get(), false, mExecuteCommand);
unsigned int resultOfCheck = 0;

if (iFileSettings != mFileSettings.end()) {
Expand All @@ -396,9 +402,9 @@ unsigned int ProcessExecutor::check()
resultOfCheck = fileChecker.check(*iFile);
}

pipewriter.writeSuppr(mSuppressions.nomsg);
pipewriter.writeSuppr(supprs.nomsg);

pipewriter.writeTimer(mTimerResults);
pipewriter.writeTimer(timerResults.get());

pipewriter.writeEnd(std::to_string(resultOfCheck));
std::exit(EXIT_SUCCESS);
Expand Down
92 changes: 92 additions & 0 deletions test/cli/other_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4657,4 +4657,96 @@ def test_ipc(tmp_path):
'writeToPipe - 5 - 0',
'handleRead - 5 - 0'
]
assert stderr.splitlines() == []


@pytest.mark.skipif(sys.platform == 'win32', reason="requires ProcessExecutor")
def test_ipc_suppressions(tmp_path):
test1_file = tmp_path / 'test1.c'
with open(test1_file, "w") as f:
f.write('void f() {}')

test2_file = tmp_path / 'test2.c'
with open(test2_file, "w") as f:
f.write('void f() {}')

test3_file = tmp_path / 'test3.c'
with open(test3_file, "w") as f:
f.write('void f() {}')

args = [
'-q',
'--debug-ipc',
'-j2',
'--executor=process',
'--no-cppcheck-build-dir',
'--suppress=id0:test1.c',
str(tmp_path)
]

exitcode, stdout, stderr = cppcheck(args)
assert exitcode == 0
# sort the lines since the order is not fixed
stdout_exp = [
'writeToPipe - 4 - id0:test1.c;0;1;0;',
'handleRead - 4 - id0:test1.c;0;1;0;',
'writeToPipe - 5 - 0',
'handleRead - 5 - 0',
'writeToPipe - 5 - 0',
'handleRead - 5 - 0',
'writeToPipe - 5 - 0',
'handleRead - 5 - 0'
]
stdout_exp.sort()
stdout_lines = stdout.splitlines()
stdout_lines.sort()
assert stdout_lines == stdout_exp
assert stderr.splitlines() == []


@pytest.mark.skipif(sys.platform == 'win32', reason="requires ProcessExecutor")
def test_ipc_inline_suppressions(tmp_path):
test1_file = tmp_path / 'test1.c'
with open(test1_file, "w") as f:
f.write('void f() {} // cppcheck-suppress id1')

test2_file = tmp_path / 'test2.c'
with open(test2_file, "w") as f:
f.write('void f() {} // cppcheck-suppress id2')

test3_file = tmp_path / 'test3.c'
with open(test3_file, "w") as f:
f.write('void f() {} // cppcheck-suppress id3')

args = [
'-q',
'--debug-ipc',
'-j2',
'--executor=process',
'--no-cppcheck-build-dir',
'--inline-suppr',
str(tmp_path)
]

exitcode, stdout, stderr = cppcheck(args)
assert exitcode == 0
# sort the lines since the order is not fixed
stdout_exp = [
f'writeToPipe - 3 - id1:{test1_file}:1;13;1;0;',
f'handleRead - 3 - id1:{test1_file}:1;13;1;0;',
'writeToPipe - 5 - 0',
'handleRead - 5 - 0',
f'writeToPipe - 3 - id2:{test2_file}:1;13;1;0;',
f'handleRead - 3 - id2:{test2_file}:1;13;1;0;',
'writeToPipe - 5 - 0',
'handleRead - 5 - 0',
f'writeToPipe - 3 - id3:{test3_file}:1;13;1;0;',
f'handleRead - 3 - id3:{test3_file}:1;13;1;0;',
'writeToPipe - 5 - 0',
'handleRead - 5 - 0'
]
stdout_exp.sort()
stdout_lines = stdout.splitlines()
stdout_lines.sort()
assert stdout_lines == stdout_exp
assert stderr.splitlines() == []
Loading