|
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: |
@@ -1209,6 +1221,124 @@ def test_gtest_repeated_run(gtest): |
1209 | 1221 | ], |
1210 | 1222 | ) |
1211 | 1223 |
|
| 1224 | +@pytest.fixture |
| 1225 | +def cpputest(tmp_path): |
| 1226 | + mock_platform = mock.Mock() |
| 1227 | + mock_platform.name = "mock_platform" |
| 1228 | + mock_platform.normalized_name = "mock_platform" |
| 1229 | + mock_testsuite = mock.Mock() |
| 1230 | + mock_testsuite.name = "mock_testsuite" |
| 1231 | + mock_testsuite.detailed_test_id = True |
| 1232 | + mock_testsuite.id = "id" |
| 1233 | + mock_testsuite.testcases = [] |
| 1234 | + mock_testsuite.harness_config = {} |
| 1235 | + outdir = tmp_path / 'cpputest_out' |
| 1236 | + outdir.mkdir() |
| 1237 | + |
| 1238 | + instance = TestInstance( |
| 1239 | + testsuite=mock_testsuite, platform=mock_platform, toolchain='zephyr', outdir=outdir |
| 1240 | + ) |
| 1241 | + |
| 1242 | + harness = Cpputest() |
| 1243 | + harness.configure(instance) |
| 1244 | + return harness |
| 1245 | + |
| 1246 | + |
| 1247 | +def test_cpputest_start_test_no_suites_detected(cpputest): |
| 1248 | + process_logs(cpputest, [SAMPLE_CPPUTEST_NO_TESTS]) |
| 1249 | + assert len(cpputest.detected_suite_names) == 0 |
| 1250 | + assert cpputest.status == TwisterStatus.NONE |
| 1251 | + |
| 1252 | + |
| 1253 | +def test_cpputest_start_test(cpputest): |
| 1254 | + process_logs( |
| 1255 | + cpputest, |
| 1256 | + [ |
| 1257 | + SAMPLE_CPPUTEST_START_FMT.format( |
| 1258 | + suite="suite_name", test="test_name" |
| 1259 | + ), |
| 1260 | + ], |
| 1261 | + ) |
| 1262 | + assert cpputest.status == TwisterStatus.NONE |
| 1263 | + assert len(cpputest.detected_suite_names) == 1 |
| 1264 | + assert cpputest.detected_suite_names[0] == "suite_name" |
| 1265 | + assert cpputest.instance.get_case_by_name("id.suite_name.test_name") is not None |
| 1266 | + assert ( |
| 1267 | + cpputest.instance.get_case_by_name("id.suite_name.test_name").status == TwisterStatus.STARTED |
| 1268 | + ) |
| 1269 | + |
| 1270 | + |
| 1271 | +def test_cpputest_one_test_passed(cpputest): |
| 1272 | + process_logs( |
| 1273 | + cpputest, |
| 1274 | + [ |
| 1275 | + SAMPLE_CPPUTEST_START_FMT.format( |
| 1276 | + suite="suite_name", test="test_name" |
| 1277 | + ), |
| 1278 | + SAMPLE_CPPUTEST_END_PASS_FMT.format( |
| 1279 | + tests=1, ran=1, checks=5, ignored=0, filtered=0, time=10 |
| 1280 | + ) |
| 1281 | + ], |
| 1282 | + ) |
| 1283 | + assert len(cpputest.detected_suite_names) == 1 |
| 1284 | + assert cpputest.detected_suite_names[0] == "suite_name" |
| 1285 | + assert cpputest.instance.get_case_by_name("id.suite_name.test_name") != TwisterStatus.NONE |
| 1286 | + assert cpputest.instance.get_case_by_name("id.suite_name.test_name").status == TwisterStatus.PASS |
| 1287 | + |
| 1288 | + |
| 1289 | +def test_cpputest_multiple_test_passed(cpputest): |
| 1290 | + logs = [] |
| 1291 | + total_passed_tests = 5 |
| 1292 | + for i in range(0, total_passed_tests): |
| 1293 | + logs.append(SAMPLE_CPPUTEST_START_FMT.format(suite="suite_name", |
| 1294 | + test="test_name_%d" % i)) |
| 1295 | + logs.append(SAMPLE_CPPUTEST_END_PASS_FMT.format( |
| 1296 | + tests=total_passed_tests, ran=total_passed_tests, checks=5, ignored=0, filtered=0, time=10 |
| 1297 | + )) |
| 1298 | + process_logs(cpputest, logs) |
| 1299 | + assert len(cpputest.detected_suite_names) == 1 |
| 1300 | + assert cpputest.detected_suite_names[0] == "suite_name" |
| 1301 | + for i in range(0, total_passed_tests): |
| 1302 | + test_name = "id.suite_name.test_name_%d" % i |
| 1303 | + assert cpputest.instance.get_case_by_name(test_name) != TwisterStatus.NONE |
| 1304 | + assert cpputest.instance.get_case_by_name(test_name).status == TwisterStatus.PASS |
| 1305 | + |
| 1306 | + |
| 1307 | +def test_cpputest_test_failed(cpputest): |
| 1308 | + process_logs( |
| 1309 | + cpputest, |
| 1310 | + [ |
| 1311 | + SAMPLE_CPPUTEST_START_FMT.format( |
| 1312 | + suite="suite_name", test="test_name" |
| 1313 | + ), |
| 1314 | + SAMPLE_CPPUTEST_FAIL_FMT.format( |
| 1315 | + suite="suite_name", test="test_name" |
| 1316 | + ) |
| 1317 | + ], |
| 1318 | + ) |
| 1319 | + assert cpputest.status == TwisterStatus.NONE |
| 1320 | + assert len(cpputest.detected_suite_names) == 1 |
| 1321 | + assert cpputest.detected_suite_names[0] == "suite_name" |
| 1322 | + assert cpputest.instance.get_case_by_name("id.suite_name.test_name") != TwisterStatus.NONE |
| 1323 | + assert cpputest.instance.get_case_by_name("id.suite_name.test_name").status == TwisterStatus.FAIL |
| 1324 | + |
| 1325 | + |
| 1326 | +def test_cpputest_test_repeated(cpputest): |
| 1327 | + with pytest.raises( |
| 1328 | + AssertionError, |
| 1329 | + match=r"CppUTest error, id.suite_name.test_name running twice", |
| 1330 | + ): |
| 1331 | + process_logs( |
| 1332 | + cpputest, |
| 1333 | + [ |
| 1334 | + SAMPLE_CPPUTEST_START_FMT.format( |
| 1335 | + suite="suite_name", test="test_name" |
| 1336 | + ), |
| 1337 | + SAMPLE_CPPUTEST_START_FMT.format( |
| 1338 | + suite="suite_name", test="test_name" |
| 1339 | + ), |
| 1340 | + ], |
| 1341 | + ) |
1212 | 1342 |
|
1213 | 1343 | def test_bsim_build(monkeypatch, tmp_path): |
1214 | 1344 | mocked_instance = mock.Mock() |
|
0 commit comments