|
22 | 22 | Bsim, |
23 | 23 | Console, |
24 | 24 | Gtest, |
| 25 | + Cpputest, |
25 | 26 | Harness, |
26 | 27 | HarnessImporter, |
27 | 28 | Pytest, |
|
54 | 55 | "[00:00:00.000,000] [0m<inf> label: [----------] Global test environment tear-down[0m" |
55 | 56 | ) |
56 | 57 |
|
| 58 | +SAMPLE_CPPUTEST_NO_TESTS = ( |
| 59 | + "Errors (ran nothing, 0 tests, 0 ran, 0 checks, 0 ignored, 0 filtered out, 0 ms)") |
| 60 | +SAMPLE_CPPUTEST_START_FMT = "[00:00:00.000,000] [0m<inf> label: TEST({suite}, {test})[0m" |
| 61 | +SAMPLE_CPPUTEST_END_PASS_FMT = "[00:00:00.000,000] [0m<inf> label: OK ({tests} tests" \ |
| 62 | + ", {ran} ran, {checks} checks, {ignored} ignored," \ |
| 63 | + " {filtered} filtered out, {time} ms)[0m" |
| 64 | +SAMPLE_CPPUTEST_FAIL_FMT = "[00:00:00.000,000] [0m<inf> label: Failure in TEST({suite}, {test})[0m" |
| 65 | +SAMPLE_CPPUTEST_END_FAIL_FMT = "[00:00:00.000,000] [0m<inf> label: Errors({failures} failures" \ |
| 66 | + ", {tests} tests, {ran} ran, {checks} checks, {ignored} ignored," \ |
| 67 | + " {filtered} filtered out, {time} ms)[0m" |
| 68 | + |
57 | 69 |
|
58 | 70 | def process_logs(harness, logs): |
59 | 71 | for line in logs: |
@@ -1235,3 +1247,122 @@ def test_bsim_build(monkeypatch, tmp_path): |
1235 | 1247 | with open(new_exe_path, "r") as file: |
1236 | 1248 | exe_content = file.read() |
1237 | 1249 | assert "TEST_EXE" in exe_content |
| 1250 | + |
| 1251 | +@pytest.fixture |
| 1252 | +def cpputest(tmp_path): |
| 1253 | + mock_platform = mock.Mock() |
| 1254 | + mock_platform.name = "mock_platform" |
| 1255 | + mock_platform.normalized_name = "mock_platform" |
| 1256 | + mock_testsuite = mock.Mock() |
| 1257 | + mock_testsuite.name = "mock_testsuite" |
| 1258 | + mock_testsuite.detailed_test_id = True |
| 1259 | + mock_testsuite.id = "id" |
| 1260 | + mock_testsuite.testcases = [] |
| 1261 | + mock_testsuite.harness_config = {} |
| 1262 | + outdir = tmp_path / 'cpputest_out' |
| 1263 | + outdir.mkdir() |
| 1264 | + |
| 1265 | + instance = TestInstance( |
| 1266 | + testsuite=mock_testsuite, platform=mock_platform, toolchain='zephyr', outdir=outdir |
| 1267 | + ) |
| 1268 | + |
| 1269 | + harness = Cpputest() |
| 1270 | + harness.configure(instance) |
| 1271 | + return harness |
| 1272 | + |
| 1273 | + |
| 1274 | +def test_cpputest_start_test_no_suites_detected(cpputest): |
| 1275 | + process_logs(cpputest, [SAMPLE_CPPUTEST_NO_TESTS]) |
| 1276 | + assert len(cpputest.detected_suite_names) == 0 |
| 1277 | + assert cpputest.status == TwisterStatus.NONE |
| 1278 | + |
| 1279 | + |
| 1280 | +def test_cpputest_start_test(cpputest): |
| 1281 | + process_logs( |
| 1282 | + cpputest, |
| 1283 | + [ |
| 1284 | + SAMPLE_CPPUTEST_START_FMT.format( |
| 1285 | + suite="suite_name", test="test_name" |
| 1286 | + ), |
| 1287 | + ], |
| 1288 | + ) |
| 1289 | + assert cpputest.status == TwisterStatus.NONE |
| 1290 | + assert len(cpputest.detected_suite_names) == 1 |
| 1291 | + assert cpputest.detected_suite_names[0] == "suite_name" |
| 1292 | + assert cpputest.instance.get_case_by_name("id.suite_name.test_name") is not None |
| 1293 | + assert ( |
| 1294 | + cpputest.instance.get_case_by_name("id.suite_name.test_name").status == TwisterStatus.STARTED |
| 1295 | + ) |
| 1296 | + |
| 1297 | + |
| 1298 | +def test_cpputest_one_test_passed(cpputest): |
| 1299 | + process_logs( |
| 1300 | + cpputest, |
| 1301 | + [ |
| 1302 | + SAMPLE_CPPUTEST_START_FMT.format( |
| 1303 | + suite="suite_name", test="test_name" |
| 1304 | + ), |
| 1305 | + SAMPLE_CPPUTEST_END_PASS_FMT.format( |
| 1306 | + tests=1, ran=1, checks=5, ignored=0, filtered=0, time=10 |
| 1307 | + ) |
| 1308 | + ], |
| 1309 | + ) |
| 1310 | + assert len(cpputest.detected_suite_names) == 1 |
| 1311 | + assert cpputest.detected_suite_names[0] == "suite_name" |
| 1312 | + assert cpputest.instance.get_case_by_name("id.suite_name.test_name") != TwisterStatus.NONE |
| 1313 | + assert cpputest.instance.get_case_by_name("id.suite_name.test_name").status == TwisterStatus.PASS |
| 1314 | + |
| 1315 | + |
| 1316 | +def test_cpputest_multiple_test_passed(cpputest): |
| 1317 | + logs = [] |
| 1318 | + total_passed_tests = 5 |
| 1319 | + for i in range(0, total_passed_tests): |
| 1320 | + logs.append(SAMPLE_CPPUTEST_START_FMT.format(suite="suite_name", |
| 1321 | + test=f"test_name_{i}")) |
| 1322 | + logs.append(SAMPLE_CPPUTEST_END_PASS_FMT.format( |
| 1323 | + tests=total_passed_tests, ran=total_passed_tests, checks=5, ignored=0, filtered=0, time=10 |
| 1324 | + )) |
| 1325 | + process_logs(cpputest, logs) |
| 1326 | + assert len(cpputest.detected_suite_names) == 1 |
| 1327 | + assert cpputest.detected_suite_names[0] == "suite_name" |
| 1328 | + for i in range(0, total_passed_tests): |
| 1329 | + test_name = f"id.suite_name.test_name_{i}" |
| 1330 | + assert cpputest.instance.get_case_by_name(test_name) != TwisterStatus.NONE |
| 1331 | + assert cpputest.instance.get_case_by_name(test_name).status == TwisterStatus.PASS |
| 1332 | + |
| 1333 | + |
| 1334 | +def test_cpputest_test_failed(cpputest): |
| 1335 | + process_logs( |
| 1336 | + cpputest, |
| 1337 | + [ |
| 1338 | + SAMPLE_CPPUTEST_START_FMT.format( |
| 1339 | + suite="suite_name", test="test_name" |
| 1340 | + ), |
| 1341 | + SAMPLE_CPPUTEST_FAIL_FMT.format( |
| 1342 | + suite="suite_name", test="test_name" |
| 1343 | + ) |
| 1344 | + ], |
| 1345 | + ) |
| 1346 | + assert cpputest.status == TwisterStatus.NONE |
| 1347 | + assert len(cpputest.detected_suite_names) == 1 |
| 1348 | + assert cpputest.detected_suite_names[0] == "suite_name" |
| 1349 | + assert cpputest.instance.get_case_by_name("id.suite_name.test_name") != TwisterStatus.NONE |
| 1350 | + assert cpputest.instance.get_case_by_name("id.suite_name.test_name").status == TwisterStatus.FAIL |
| 1351 | + |
| 1352 | + |
| 1353 | +def test_cpputest_test_repeated(cpputest): |
| 1354 | + with pytest.raises( |
| 1355 | + AssertionError, |
| 1356 | + match=r"CppUTest error, id.suite_name.test_name running twice", |
| 1357 | + ): |
| 1358 | + process_logs( |
| 1359 | + cpputest, |
| 1360 | + [ |
| 1361 | + SAMPLE_CPPUTEST_START_FMT.format( |
| 1362 | + suite="suite_name", test="test_name" |
| 1363 | + ), |
| 1364 | + SAMPLE_CPPUTEST_START_FMT.format( |
| 1365 | + suite="suite_name", test="test_name" |
| 1366 | + ), |
| 1367 | + ], |
| 1368 | + ) |
0 commit comments