Skip to content

Commit c485473

Browse files
committed
properly guard {Process|Thread}Executor implementations
1 parent 21163e8 commit c485473

File tree

8 files changed

+68
-13
lines changed

8 files changed

+68
-13
lines changed

.github/workflows/CI-unixish.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,13 @@ jobs:
571571
warnings="-pedantic -Wall -Wextra -Wcast-qual -Wno-deprecated-declarations -Wfloat-equal -Wmissing-declarations -Wmissing-format-attribute -Wno-long-long -Wpacked -Wredundant-decls -Wundef -Wno-shadow -Wno-missing-field-initializers -Wno-missing-braces -Wno-sign-compare -Wno-multichar"
572572
g++ $warnings -c -Ilib -Iexternals/tinyxml2 democlient/democlient.cpp
573573
574+
- name: Test disabled executors
575+
if: matrix.os == 'ubuntu-22.04'
576+
run: |
577+
g++ -Ilib -c cli/threadexecutor.cpp -DDISALLOW_THREAD_EXECUTOR
578+
test -z "$(nm threadexecutor.o)"
579+
# TODO: test NO_* defines
580+
574581
- name: Show all ignored files
575582
if: false # TODO: currently lists all the contents of ignored folders - we only need what actually matched
576583
run: |

cli/processexecutor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
#include "processexecutor.h"
2424

25-
#if !defined(_WIN32) && !defined(__MINGW32__)
25+
#ifdef HAS_THREADING_MODEL_FORK
2626

2727
#include "cppcheck.h"
2828
#include "errorlogger.h"

cli/processexecutor.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
#ifndef PROCESSEXECUTOR_H
2020
#define PROCESSEXECUTOR_H
2121

22+
#include "config.h"
23+
24+
#ifdef HAS_THREADING_MODEL_FORK
25+
2226
#include "cppcheck.h"
2327
#include "executor.h"
2428

@@ -72,4 +76,6 @@ class ProcessExecutor : public Executor {
7276

7377
/// @}
7478

79+
#endif // HAS_THREADING_MODEL_FORK
80+
7581
#endif // PROCESSEXECUTOR_H

cli/threadexecutor.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
#include "threadexecutor.h"
2020

21+
#ifdef HAS_THREADING_MODEL_THREAD
22+
2123
#include "config.h"
2224
#include "cppcheck.h"
2325
#include "errorlogger.h"
@@ -219,3 +221,5 @@ unsigned int ThreadExecutor::check()
219221

220222
return result;
221223
}
224+
225+
#endif // HAS_THREADING_MODEL_THREAD

cli/threadexecutor.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
#ifndef THREADEXECUTOR_H
2020
#define THREADEXECUTOR_H
2121

22+
#include "config.h"
23+
24+
#ifdef HAS_THREADING_MODEL_THREAD
25+
2226
#include "cppcheck.h"
2327
#include "executor.h"
2428

@@ -52,4 +56,6 @@ class ThreadExecutor : public Executor {
5256

5357
/// @}
5458

59+
#endif // HAS_THREADING_MODEL_THREAD
60+
5561
#endif // THREADEXECUTOR_H

test/testprocessexecutor.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@
1616
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1717
*/
1818

19-
#include "filesettings.h"
2019
#include "fixture.h"
20+
21+
#ifdef HAS_THREADING_MODEL_FORK
22+
#include "filesettings.h"
2123
#include "helpers.h"
2224
#include "processexecutor.h"
2325
#include "redirect.h"
@@ -33,12 +35,19 @@
3335
#include <string>
3436
#include <utility>
3537
#include <vector>
38+
#endif // HAS_THREADING_MODEL_FORK
3639

3740
class TestProcessExecutorBase : public TestFixture {
3841
public:
39-
TestProcessExecutorBase(const char * const name, bool useFS) : TestFixture(name), useFS(useFS) {}
42+
TestProcessExecutorBase(const char * const name, bool useFS)
43+
: TestFixture(name),
44+
#ifdef HAS_THREADING_MODEL_FORK
45+
useFS(useFS)
46+
#endif // HAS_THREADING_MODEL_FORK
47+
{}
4048

4149
private:
50+
#ifdef HAS_THREADING_MODEL_FORK
4251
/*const*/ Settings settings = settingsBuilder().library("std.cfg").build();
4352
bool useFS;
4453

@@ -110,10 +119,11 @@ class TestProcessExecutorBase : public TestFixture {
110119
ProcessExecutor executor(filelist, fileSettings, s, supprs, *this, executeFn);
111120
ASSERT_EQUALS(result, executor.check());
112121
}
122+
#endif // HAS_THREADING_MODEL_FORK
113123

114124
void run() override {
115-
#if !defined(_WIN32) && !defined(__MINGW32__) && !defined(__CYGWIN__)
116125
mNewTemplate = true;
126+
#ifdef HAS_THREADING_MODEL_FORK
117127
TEST_CASE(deadlock_with_many_errors);
118128
TEST_CASE(many_threads);
119129
TEST_CASE(many_threads_showtime);
@@ -130,9 +140,10 @@ class TestProcessExecutorBase : public TestFixture {
130140
TEST_CASE(showtime_file_total);
131141
TEST_CASE(suppress_error_library);
132142
TEST_CASE(unique_errors);
133-
#endif // !WIN32
143+
#endif // HAS_THREADING_MODEL_FORK
134144
}
135145

146+
#ifdef HAS_THREADING_MODEL_FORK
136147
void deadlock_with_many_errors() {
137148
std::ostringstream oss;
138149
oss << "void f()\n"
@@ -315,6 +326,7 @@ class TestProcessExecutorBase : public TestFixture {
315326
}
316327

317328
// TODO: test whole program analysis
329+
#endif // HAS_THREADING_MODEL_FORK
318330
};
319331

320332
class TestProcessExecutorFiles : public TestProcessExecutorBase {

test/testsuppressions.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,14 @@ class TestSuppressions : public TestFixture {
5858
TEST_CASE(suppressionsFileNameWithExtraPath);
5959
TEST_CASE(suppressionsSettingsFiles);
6060
TEST_CASE(suppressionsSettingsFS);
61+
#ifdef HAS_THREADING_MODEL_THREAD
6162
TEST_CASE(suppressionsSettingsThreadsFiles);
6263
TEST_CASE(suppressionsSettingsThreadsFS);
63-
#if !defined(_WIN32) && !defined(__MINGW32__) && !defined(__CYGWIN__)
64+
#endif // HAS_THREADING_MODEL_THREAD
65+
#ifdef HAS_THREADING_MODEL_FORK
6466
TEST_CASE(suppressionsSettingsProcessesFiles);
6567
TEST_CASE(suppressionsSettingsProcessesFS);
66-
#endif
68+
#endif // HAS_THREADING_MODEL_FORK
6769
TEST_CASE(suppressionsMultiFileFiles);
6870
TEST_CASE(suppressionsMultiFileFS);
6971
TEST_CASE(suppressionsPathSeparator);
@@ -294,6 +296,7 @@ class TestSuppressions : public TestFixture {
294296
return exitCode;
295297
}
296298

299+
#ifdef HAS_THREADING_MODEL_THREAD
297300
unsigned int checkSuppressionThreadsFiles(const char code[], const std::string &suppression = "") {
298301
return _checkSuppressionThreads(code, false, suppression);
299302
}
@@ -341,8 +344,9 @@ class TestSuppressions : public TestFixture {
341344

342345
return exitCode;
343346
}
347+
#endif // HAS_THREADING_MODEL_THREAD
344348

345-
#if !defined(_WIN32) && !defined(__MINGW32__) && !defined(__CYGWIN__)
349+
#ifdef HAS_THREADING_MODEL_FORK
346350
unsigned int checkSuppressionProcessesFiles(const char code[], const std::string &suppression = "") {
347351
return _checkSuppressionProcesses(code, false, suppression);
348352
}
@@ -390,7 +394,7 @@ class TestSuppressions : public TestFixture {
390394

391395
return exitCode;
392396
}
393-
#endif
397+
#endif // HAS_THREADING_MODEL_FORK
394398

395399
// TODO: check all results
396400
void runChecks(unsigned int (TestSuppressions::*check)(const char[], const std::string &)) {
@@ -920,23 +924,25 @@ class TestSuppressions : public TestFixture {
920924
runChecks(&TestSuppressions::checkSuppressionFS);
921925
}
922926

927+
#ifdef HAS_THREADING_MODEL_THREAD
923928
void suppressionsSettingsThreadsFiles() {
924929
runChecks(&TestSuppressions::checkSuppressionThreadsFiles);
925930
}
926931

927932
void suppressionsSettingsThreadsFS() {
928933
runChecks(&TestSuppressions::checkSuppressionThreadsFS);
929934
}
935+
#endif // HAS_THREADING_MODEL_THREAD
930936

931-
#if !defined(_WIN32) && !defined(__MINGW32__) && !defined(__CYGWIN__)
937+
#ifdef HAS_THREADING_MODEL_FORK
932938
void suppressionsSettingsProcessesFiles() {
933939
runChecks(&TestSuppressions::checkSuppressionProcessesFiles);
934940
}
935941

936942
void suppressionsSettingsProcessesFS() {
937943
runChecks(&TestSuppressions::checkSuppressionProcessesFS);
938944
}
939-
#endif
945+
#endif // HAS_THREADING_MODEL_FORK
940946

941947
void suppressionsMultiFileInternal(unsigned int (TestSuppressions::*check)(std::map<std::string, std::string> &f, const std::string &)) {
942948
std::map<std::string, std::string> files;

test/testthreadexecutor.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@
1616
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1717
*/
1818

19-
#include "filesettings.h"
2019
#include "fixture.h"
20+
21+
#ifdef HAS_THREADING_MODEL_THREAD
22+
#include "filesettings.h"
2123
#include "helpers.h"
2224
#include "redirect.h"
2325
#include "settings.h"
@@ -33,12 +35,19 @@
3335
#include <string>
3436
#include <utility>
3537
#include <vector>
38+
#endif // HAS_THREADING_MODEL_THREAD
3639

3740
class TestThreadExecutorBase : public TestFixture {
3841
public:
39-
TestThreadExecutorBase(const char * const name, bool useFS) : TestFixture(name), useFS(useFS) {}
42+
TestThreadExecutorBase(const char * const name, bool useFS)
43+
: TestFixture(name),
44+
#ifdef HAS_THREADING_MODEL_THREAD
45+
useFS(useFS)
46+
#endif // HAS_THREADING_MODEL_THREAD
47+
{}
4048

4149
private:
50+
#ifdef HAS_THREADING_MODEL_THREAD
4251
/*const*/ Settings settings = settingsBuilder().library("std.cfg").build();
4352
bool useFS;
4453

@@ -111,9 +120,11 @@ class TestThreadExecutorBase : public TestFixture {
111120
ThreadExecutor executor(filelist, fileSettings, s, supprs, *this, executeFn);
112121
ASSERT_EQUALS(result, executor.check());
113122
}
123+
#endif // HAS_THREADING_MODEL_THREAD
114124

115125
void run() override {
116126
mNewTemplate = true;
127+
#ifdef HAS_THREADING_MODEL_THREAD
117128
TEST_CASE(deadlock_with_many_errors);
118129
TEST_CASE(many_threads);
119130
TEST_CASE(many_threads_showtime);
@@ -130,8 +141,10 @@ class TestThreadExecutorBase : public TestFixture {
130141
TEST_CASE(showtime_file_total);
131142
TEST_CASE(suppress_error_library);
132143
TEST_CASE(unique_errors);
144+
#endif // HAS_THREADING_MODEL_THREAD
133145
}
134146

147+
#ifdef HAS_THREADING_MODEL_THREAD
135148
void deadlock_with_many_errors() {
136149
std::ostringstream oss;
137150
oss << "void f()\n"
@@ -313,6 +326,7 @@ class TestThreadExecutorBase : public TestFixture {
313326
}
314327

315328
// TODO: test whole program analysis
329+
#endif // HAS_THREADING_MODEL_THREAD
316330
};
317331

318332
class TestThreadExecutorFiles : public TestThreadExecutorBase {

0 commit comments

Comments
 (0)