|
1 | 1 |
|
2 | | -# python -m pytest test-other.py |
| 2 | +# python -m pytest performance_test.py |
3 | 3 |
|
4 | 4 | import os |
5 | 5 | import sys |
@@ -240,3 +240,130 @@ def test_crash_array_in_namespace(tmpdir): |
240 | 240 | }; |
241 | 241 | }""") |
242 | 242 | cppcheck([filename]) # should not take more than ~5 seconds |
| 243 | + |
| 244 | +@pytest.mark.timeout(5) |
| 245 | +def test_slow_bifurcate(tmpdir): |
| 246 | + # #14134 |
| 247 | + filename = os.path.join(tmpdir, 'hang.cpp') |
| 248 | + with open(filename, 'wt') as f: |
| 249 | + f.write(r""" |
| 250 | + class C { |
| 251 | + public: |
| 252 | + enum class Status { |
| 253 | + Ok, |
| 254 | + Waiting, |
| 255 | + Error, |
| 256 | + }; |
| 257 | + void setStatus(Status status, const QString& text); |
| 258 | + QColor m_statusColor; |
| 259 | + }; |
| 260 | +
|
| 261 | + template < size_t N, typename T > |
| 262 | + inline QDataStream& deserialize(QDataStream& in, T& value) { |
| 263 | + if constexpr (N == 0) {} |
| 264 | + else if constexpr (N == 1) { |
| 265 | + auto& [f1] = value; |
| 266 | + in >> f1; |
| 267 | + } |
| 268 | + else if constexpr (N == 2) { |
| 269 | + auto& [f1, f2] = value; |
| 270 | + in >> f1 >> f2; |
| 271 | + } |
| 272 | + else if constexpr (N == 3) { |
| 273 | + auto& [f1, f2, f3] = value; |
| 274 | + in >> f1 >> f2 >> f3; |
| 275 | + } |
| 276 | + else if constexpr (N == 4) { |
| 277 | + auto& [f1, f2, f3, f4] = value; |
| 278 | + in >> f1 >> f2 >> f3 >> f4; |
| 279 | + } |
| 280 | + else if constexpr (N == 5) { |
| 281 | + auto& [f1, f2, f3, f4, f5] = value; |
| 282 | + in >> f1 >> f2 >> f3 >> f4 >> f5; |
| 283 | + } |
| 284 | + else if constexpr (N == 6) { |
| 285 | + auto& [f1, f2, f3, f4, f5, f6] = value; |
| 286 | + in >> f1 >> f2 >> f3 >> f4 >> f5 >> f6; |
| 287 | + } |
| 288 | + else if constexpr (N == 7) { |
| 289 | + auto& [f1, f2, f3, f4, f5, f6, f7] = value; |
| 290 | + in >> f1 >> f2 >> f3 >> f4 >> f5 >> f6 >> f7; |
| 291 | + } |
| 292 | + else if constexpr (N == 8) { |
| 293 | + auto& [f1, f2, f3, f4, f5, f6, f7, f8] = value; |
| 294 | + in >> f1 >> f2 >> f3 >> f4 >> f5 >> f6 >> f7 >> f8; |
| 295 | + } |
| 296 | + else if constexpr (N == 9) { |
| 297 | + auto& [f1, f2, f3, f4, f5, f6, f7, f8, f9] = value; |
| 298 | + in >> f1 >> f2 >> f3 >> f4 >> f5 >> f6 >> f7 >> f8 >> f9; |
| 299 | + } |
| 300 | + else if constexpr (N == 10) { |
| 301 | + auto& [f1, f2, f3, f4, f5, f6, f7, f8, f9, f10] = value; |
| 302 | + in >> f1 >> f2 >> f3 >> f4 >> f5 >> f6 >> f7 >> f8 >> f9 >> f10; |
| 303 | + } |
| 304 | + else if constexpr (N == 11) { |
| 305 | + auto& [f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11] = value; |
| 306 | + in >> f1 >> f2 >> f3 >> f4 >> f5 >> f6 >> f7 >> f8 >> f9 >> f10 >> f11; |
| 307 | + } |
| 308 | + else if constexpr (N == 12) { |
| 309 | + auto& [f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12] = value; |
| 310 | + in >> f1 >> f2 >> f3 >> f4 >> f5 >> f6 >> f7 >> f8 >> f9 >> f10 >> f11 >> f12; |
| 311 | + } |
| 312 | + else if constexpr (N == 13) { |
| 313 | + auto& [f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13] = value; |
| 314 | + in >> f1 >> f2 >> f3 >> f4 >> f5 >> f6 >> f7 >> f8 >> f9 >> f10 >> f11 >> f12 >> f13; |
| 315 | + } |
| 316 | + else if constexpr (N == 14) { |
| 317 | + auto& [f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14] = value; |
| 318 | + in >> f1 >> f2 >> f3 >> f4 >> f5 >> f6 >> f7 >> f8 >> f9 >> f10 >> f11 >> f12 >> f13 >> f14; |
| 319 | + } |
| 320 | + else if constexpr (N == 15) { |
| 321 | + auto& [f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15] = value; |
| 322 | + in >> f1 >> f2 >> f3 >> f4 >> f5 >> f6 >> f7 >> f8 >> f9 >> f10 >> f11 >> f12 >> f13 >> f14 >> f15; |
| 323 | + } |
| 324 | + else if constexpr (N == 16) { |
| 325 | + auto& [f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16] = value; |
| 326 | + in >> f1 >> f2 >> f3 >> f4 >> f5 >> f6 >> f7 >> f8 >> f9 >> f10 >> f11 >> f12 >> f13 >> f14 >> f15 >> f16; |
| 327 | + } |
| 328 | + else if constexpr (N == 17) { |
| 329 | + auto& [f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17] = value; |
| 330 | + in >> f1 >> f2 >> f3 >> f4 >> f5 >> f6 >> f7 >> f8 >> f9 >> f10 >> f11 >> f12 >> f13 >> f14 >> f15 >> f16 >> f17; |
| 331 | + } |
| 332 | + else if constexpr (N == 18) { |
| 333 | + auto& [f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18] = value; |
| 334 | + in >> f1 >> f2 >> f3 >> f4 >> f5 >> f6 >> f7 >> f8 >> f9 >> f10 >> f11 >> f12 >> f13 >> f14 >> f15 >> f16 >> f17 >> f18; |
| 335 | + } |
| 336 | + else if constexpr (N == 19) { |
| 337 | + auto& [f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19] = value; |
| 338 | + in >> f1 >> f2 >> f3 >> f4 >> f5 >> f6 >> f7 >> f8 >> f9 >> f10 >> f11 >> f12 >> f13 >> f14 >> f15 >> f16 >> f17 >> f18 >> f19; |
| 339 | + } |
| 340 | + else if constexpr (N == 20) { |
| 341 | + auto& [f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, f20] = value; |
| 342 | + in >> f1 >> f2 >> f3 >> f4 >> f5 >> f6 >> f7 >> f8 >> f9 >> f10 >> f11 >> f12 >> f13 >> f14 >> f15 >> f16 >> f17 >> f18 >> f19 >> f20; |
| 343 | + } |
| 344 | + else { |
| 345 | + static_assert (!sizeof(T), "missing implementation"); |
| 346 | + } |
| 347 | + return in; |
| 348 | + } |
| 349 | +
|
| 350 | + void C::setStatus(Status status, const QString& text) { |
| 351 | + const auto& colors = Config::get().ui().colors; |
| 352 | + QColor color; |
| 353 | + switch (status) { |
| 354 | + case Status::Ok: |
| 355 | + color = colors.green; |
| 356 | + break; |
| 357 | + case Status::Waiting: |
| 358 | + color = Qt::black; |
| 359 | + break; |
| 360 | + case Status::Error: |
| 361 | + color = colors.red; |
| 362 | + break; |
| 363 | + } |
| 364 | +
|
| 365 | + if (m_statusColor != color) { |
| 366 | + m_statusColor = color; |
| 367 | + } |
| 368 | + }""") |
| 369 | + cppcheck([filename]) # should not take more than ~1 second |
0 commit comments