|
22 | 22 | Bsim, |
23 | 23 | Console, |
24 | 24 | Gtest, |
| 25 | + Cpputest, |
25 | 26 | Harness, |
26 | 27 | HarnessImporter, |
27 | 28 | Pytest, |
|
53 | 54 | "[00:00:00.000,000] [0m<inf> label: [----------] Global test environment tear-down[0m" |
54 | 55 | ) |
55 | 56 |
|
| 57 | +SAMPLE_CPPUTEST_NO_TESTS = ( |
| 58 | + "Errors (ran nothing, 0 tests, 0 ran, 0 checks, 0 ignored, 0 filtered out, 0 ms)") |
| 59 | +SAMPLE_CPPUTEST_START_FMT = "[00:00:00.000,000] [0m<inf> label: TEST({suite}, {test})[0m" |
| 60 | +SAMPLE_CPPUTEST_END_PASS_FMT = "[00:00:00.000,000] [0m<inf> label: OK ({tests} tests" \ |
| 61 | + ", {ran} ran, {checks} checks, {ignored} ignored," \ |
| 62 | + " {filtered} filtered out, {time} ms)[0m" |
| 63 | +SAMPLE_CPPUTEST_FAIL_FMT = "[00:00:00.000,000] [0m<inf> label: Failure in TEST({suite}, {test})[0m" |
| 64 | +SAMPLE_CPPUTEST_END_FAIL_FMT = "[00:00:00.000,000] [0m<inf> label: Errors({failures} failures" \ |
| 65 | + ", {tests} tests, {ran} ran, {checks} checks, {ignored} ignored," \ |
| 66 | + " {filtered} filtered out, {time} ms)[0m" |
| 67 | + |
56 | 68 |
|
57 | 69 | def process_logs(harness, logs): |
58 | 70 | for line in logs: |
@@ -1077,6 +1089,124 @@ def test_gtest_repeated_run(gtest): |
1077 | 1089 | ) |
1078 | 1090 |
|
1079 | 1091 |
|
| 1092 | +@pytest.fixture |
| 1093 | +def cpputest(tmp_path): |
| 1094 | + mock_platform = mock.Mock() |
| 1095 | + mock_platform.name = "mock_platform" |
| 1096 | + mock_platform.normalized_name = "mock_platform" |
| 1097 | + mock_testsuite = mock.Mock() |
| 1098 | + mock_testsuite.name = "mock_testsuite" |
| 1099 | + mock_testsuite.detailed_test_id = True |
| 1100 | + mock_testsuite.id = "id" |
| 1101 | + mock_testsuite.testcases = [] |
| 1102 | + mock_testsuite.harness_config = {} |
| 1103 | + outdir = tmp_path / 'cpputest_out' |
| 1104 | + outdir.mkdir() |
| 1105 | + |
| 1106 | + instance = TestInstance(testsuite=mock_testsuite, platform=mock_platform, outdir=outdir) |
| 1107 | + |
| 1108 | + harness = Cpputest() |
| 1109 | + harness.configure(instance) |
| 1110 | + return harness |
| 1111 | + |
| 1112 | + |
| 1113 | +def test_cpputest_start_test_no_suites_detected(cpputest): |
| 1114 | + process_logs(cpputest, [SAMPLE_CPPUTEST_NO_TESTS]) |
| 1115 | + assert len(cpputest.detected_suite_names) == 0 |
| 1116 | + assert cpputest.status == TwisterStatus.NONE |
| 1117 | + |
| 1118 | + |
| 1119 | +def test_cpputest_start_test(cpputest): |
| 1120 | + process_logs( |
| 1121 | + cpputest, |
| 1122 | + [ |
| 1123 | + SAMPLE_CPPUTEST_START_FMT.format( |
| 1124 | + suite="suite_name", test="test_name" |
| 1125 | + ), |
| 1126 | + ], |
| 1127 | + ) |
| 1128 | + assert cpputest.status == TwisterStatus.NONE |
| 1129 | + assert len(cpputest.detected_suite_names) == 1 |
| 1130 | + assert cpputest.detected_suite_names[0] == "suite_name" |
| 1131 | + assert cpputest.instance.get_case_by_name("id.suite_name.test_name") is not None |
| 1132 | + assert ( |
| 1133 | + cpputest.instance.get_case_by_name("id.suite_name.test_name").status == TwisterStatus.STARTED |
| 1134 | + ) |
| 1135 | + |
| 1136 | + |
| 1137 | +def test_cpputest_one_test_passed(cpputest): |
| 1138 | + process_logs( |
| 1139 | + cpputest, |
| 1140 | + [ |
| 1141 | + SAMPLE_CPPUTEST_START_FMT.format( |
| 1142 | + suite="suite_name", test="test_name" |
| 1143 | + ), |
| 1144 | + SAMPLE_CPPUTEST_END_PASS_FMT.format( |
| 1145 | + tests=1, ran=1, checks=5, ignored=0, filtered=0, time=10 |
| 1146 | + ) |
| 1147 | + ], |
| 1148 | + ) |
| 1149 | + assert len(cpputest.detected_suite_names) == 1 |
| 1150 | + assert cpputest.detected_suite_names[0] == "suite_name" |
| 1151 | + assert cpputest.instance.get_case_by_name("id.suite_name.test_name") != TwisterStatus.NONE |
| 1152 | + assert cpputest.instance.get_case_by_name("id.suite_name.test_name").status == TwisterStatus.PASS |
| 1153 | + |
| 1154 | + |
| 1155 | +def test_cpputest_multiple_test_passed(cpputest): |
| 1156 | + logs = [] |
| 1157 | + total_passed_tests = 5 |
| 1158 | + for i in range(0, total_passed_tests): |
| 1159 | + logs.append(SAMPLE_CPPUTEST_START_FMT.format(suite="suite_name", |
| 1160 | + test="test_name_%d" % i)) |
| 1161 | + logs.append(SAMPLE_CPPUTEST_END_PASS_FMT.format( |
| 1162 | + tests=total_passed_tests, ran=total_passed_tests, checks=5, ignored=0, filtered=0, time=10 |
| 1163 | + )) |
| 1164 | + process_logs(cpputest, logs) |
| 1165 | + assert len(cpputest.detected_suite_names) == 1 |
| 1166 | + assert cpputest.detected_suite_names[0] == "suite_name" |
| 1167 | + for i in range(0, total_passed_tests): |
| 1168 | + test_name = "id.suite_name.test_name_%d" % i |
| 1169 | + assert cpputest.instance.get_case_by_name(test_name) != TwisterStatus.NONE |
| 1170 | + assert cpputest.instance.get_case_by_name(test_name).status == TwisterStatus.PASS |
| 1171 | + |
| 1172 | + |
| 1173 | +def test_cpputest_test_failed(cpputest): |
| 1174 | + process_logs( |
| 1175 | + cpputest, |
| 1176 | + [ |
| 1177 | + SAMPLE_CPPUTEST_START_FMT.format( |
| 1178 | + suite="suite_name", test="test_name" |
| 1179 | + ), |
| 1180 | + SAMPLE_CPPUTEST_FAIL_FMT.format( |
| 1181 | + suite="suite_name", test="test_name" |
| 1182 | + ) |
| 1183 | + ], |
| 1184 | + ) |
| 1185 | + assert cpputest.status == TwisterStatus.NONE |
| 1186 | + assert len(cpputest.detected_suite_names) == 1 |
| 1187 | + assert cpputest.detected_suite_names[0] == "suite_name" |
| 1188 | + assert cpputest.instance.get_case_by_name("id.suite_name.test_name") != TwisterStatus.NONE |
| 1189 | + assert cpputest.instance.get_case_by_name("id.suite_name.test_name").status == TwisterStatus.FAIL |
| 1190 | + |
| 1191 | + |
| 1192 | +def test_cpputest_test_repeated(cpputest): |
| 1193 | + with pytest.raises( |
| 1194 | + AssertionError, |
| 1195 | + match=r"CppUTest error, id.suite_name.test_name running twice", |
| 1196 | + ): |
| 1197 | + process_logs( |
| 1198 | + cpputest, |
| 1199 | + [ |
| 1200 | + SAMPLE_CPPUTEST_START_FMT.format( |
| 1201 | + suite="suite_name", test="test_name" |
| 1202 | + ), |
| 1203 | + SAMPLE_CPPUTEST_START_FMT.format( |
| 1204 | + suite="suite_name", test="test_name" |
| 1205 | + ), |
| 1206 | + ], |
| 1207 | + ) |
| 1208 | + |
| 1209 | + |
1080 | 1210 | def test_bsim_build(monkeypatch, tmp_path): |
1081 | 1211 | mocked_instance = mock.Mock() |
1082 | 1212 | build_dir = tmp_path / "build_dir" |
|
0 commit comments