diff --git a/cli/processexecutor.cpp b/cli/processexecutor.cpp index e430f6ccbf2..a410f58d5ea 100644 --- a/cli/processexecutor.cpp +++ b/cli/processexecutor.cpp @@ -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 rpipes; std::map childFile; std::map pipeFile; @@ -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; 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()) { @@ -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); diff --git a/test/cli/other_test.py b/test/cli/other_test.py index baee758be5c..243f600b5a6 100644 --- a/test/cli/other_test.py +++ b/test/cli/other_test.py @@ -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() == [] \ No newline at end of file