@@ -87,8 +87,9 @@ struct kunit;
8787 * @name: the name of the test case.
8888 *
8989 * A test case is a function with the signature,
90- * ``void (*)(struct kunit *)`` that makes expectations (see
91- * KUNIT_EXPECT_TRUE()) about code under test. Each test case is associated
90+ * ``void (*)(struct kunit *)``
91+ * that makes expectations and assertions (see KUNIT_EXPECT_TRUE() and
92+ * KUNIT_ASSERT_TRUE()) about code under test. Each test case is associated
9293 * with a &struct kunit_suite and will be run after the suite's init
9394 * function and followed by the suite's exit function.
9495 *
@@ -1210,4 +1211,281 @@ do { \
12101211 fmt , \
12111212 ##__VA_ARGS__ )
12121213
1214+ #define KUNIT_ASSERT_FAILURE (test , fmt , ...) \
1215+ KUNIT_FAIL_ASSERTION (test , KUNIT_ASSERTION , fmt , ##__VA_ARGS__ )
1216+
1217+ /**
1218+ * KUNIT_ASSERT_TRUE() - Sets an assertion that @condition is true.
1219+ * @test: The test context object.
1220+ * @condition: an arbitrary boolean expression. The test fails and aborts when
1221+ * this does not evaluate to true.
1222+ *
1223+ * This and assertions of the form `KUNIT_ASSERT_*` will cause the test case to
1224+ * fail *and immediately abort* when the specified condition is not met. Unlike
1225+ * an expectation failure, it will prevent the test case from continuing to run;
1226+ * this is otherwise known as an *assertion failure*.
1227+ */
1228+ #define KUNIT_ASSERT_TRUE (test , condition ) \
1229+ KUNIT_TRUE_ASSERTION (test , KUNIT_ASSERTION , condition )
1230+
1231+ #define KUNIT_ASSERT_TRUE_MSG (test , condition , fmt , ...) \
1232+ KUNIT_TRUE_MSG_ASSERTION (test , \
1233+ KUNIT_ASSERTION , \
1234+ condition , \
1235+ fmt , \
1236+ ##__VA_ARGS__ )
1237+
1238+ /**
1239+ * KUNIT_ASSERT_FALSE() - Sets an assertion that @condition is false.
1240+ * @test: The test context object.
1241+ * @condition: an arbitrary boolean expression.
1242+ *
1243+ * Sets an assertion that the value that @condition evaluates to is false. This
1244+ * is the same as KUNIT_EXPECT_FALSE(), except it causes an assertion failure
1245+ * (see KUNIT_ASSERT_TRUE()) when the assertion is not met.
1246+ */
1247+ #define KUNIT_ASSERT_FALSE (test , condition ) \
1248+ KUNIT_FALSE_ASSERTION (test , KUNIT_ASSERTION , condition )
1249+
1250+ #define KUNIT_ASSERT_FALSE_MSG (test , condition , fmt , ...) \
1251+ KUNIT_FALSE_MSG_ASSERTION (test , \
1252+ KUNIT_ASSERTION , \
1253+ condition , \
1254+ fmt , \
1255+ ##__VA_ARGS__ )
1256+
1257+ /**
1258+ * KUNIT_ASSERT_EQ() - Sets an assertion that @left and @right are equal.
1259+ * @test: The test context object.
1260+ * @left: an arbitrary expression that evaluates to a primitive C type.
1261+ * @right: an arbitrary expression that evaluates to a primitive C type.
1262+ *
1263+ * Sets an assertion that the values that @left and @right evaluate to are
1264+ * equal. This is the same as KUNIT_EXPECT_EQ(), except it causes an assertion
1265+ * failure (see KUNIT_ASSERT_TRUE()) when the assertion is not met.
1266+ */
1267+ #define KUNIT_ASSERT_EQ (test , left , right ) \
1268+ KUNIT_BINARY_EQ_ASSERTION (test , KUNIT_ASSERTION , left , right )
1269+
1270+ #define KUNIT_ASSERT_EQ_MSG (test , left , right , fmt , ...) \
1271+ KUNIT_BINARY_EQ_MSG_ASSERTION (test , \
1272+ KUNIT_ASSERTION , \
1273+ left , \
1274+ right , \
1275+ fmt , \
1276+ ##__VA_ARGS__ )
1277+
1278+ /**
1279+ * KUNIT_ASSERT_PTR_EQ() - Asserts that pointers @left and @right are equal.
1280+ * @test: The test context object.
1281+ * @left: an arbitrary expression that evaluates to a pointer.
1282+ * @right: an arbitrary expression that evaluates to a pointer.
1283+ *
1284+ * Sets an assertion that the values that @left and @right evaluate to are
1285+ * equal. This is the same as KUNIT_EXPECT_EQ(), except it causes an assertion
1286+ * failure (see KUNIT_ASSERT_TRUE()) when the assertion is not met.
1287+ */
1288+ #define KUNIT_ASSERT_PTR_EQ (test , left , right ) \
1289+ KUNIT_BINARY_PTR_EQ_ASSERTION (test , KUNIT_ASSERTION , left , right )
1290+
1291+ #define KUNIT_ASSERT_PTR_EQ_MSG (test , left , right , fmt , ...) \
1292+ KUNIT_BINARY_PTR_EQ_MSG_ASSERTION (test , \
1293+ KUNIT_ASSERTION , \
1294+ left , \
1295+ right , \
1296+ fmt , \
1297+ ##__VA_ARGS__ )
1298+
1299+ /**
1300+ * KUNIT_ASSERT_NE() - An assertion that @left and @right are not equal.
1301+ * @test: The test context object.
1302+ * @left: an arbitrary expression that evaluates to a primitive C type.
1303+ * @right: an arbitrary expression that evaluates to a primitive C type.
1304+ *
1305+ * Sets an assertion that the values that @left and @right evaluate to are not
1306+ * equal. This is the same as KUNIT_EXPECT_NE(), except it causes an assertion
1307+ * failure (see KUNIT_ASSERT_TRUE()) when the assertion is not met.
1308+ */
1309+ #define KUNIT_ASSERT_NE (test , left , right ) \
1310+ KUNIT_BINARY_NE_ASSERTION (test , KUNIT_ASSERTION , left , right )
1311+
1312+ #define KUNIT_ASSERT_NE_MSG (test , left , right , fmt , ...) \
1313+ KUNIT_BINARY_NE_MSG_ASSERTION (test , \
1314+ KUNIT_ASSERTION , \
1315+ left , \
1316+ right , \
1317+ fmt , \
1318+ ##__VA_ARGS__ )
1319+
1320+ /**
1321+ * KUNIT_ASSERT_PTR_NE() - Asserts that pointers @left and @right are not equal.
1322+ * KUNIT_ASSERT_PTR_EQ() - Asserts that pointers @left and @right are equal.
1323+ * @test: The test context object.
1324+ * @left: an arbitrary expression that evaluates to a pointer.
1325+ * @right: an arbitrary expression that evaluates to a pointer.
1326+ *
1327+ * Sets an assertion that the values that @left and @right evaluate to are not
1328+ * equal. This is the same as KUNIT_EXPECT_NE(), except it causes an assertion
1329+ * failure (see KUNIT_ASSERT_TRUE()) when the assertion is not met.
1330+ */
1331+ #define KUNIT_ASSERT_PTR_NE (test , left , right ) \
1332+ KUNIT_BINARY_PTR_NE_ASSERTION (test , KUNIT_ASSERTION , left , right )
1333+
1334+ #define KUNIT_ASSERT_PTR_NE_MSG (test , left , right , fmt , ...) \
1335+ KUNIT_BINARY_PTR_NE_MSG_ASSERTION (test , \
1336+ KUNIT_ASSERTION , \
1337+ left , \
1338+ right , \
1339+ fmt , \
1340+ ##__VA_ARGS__ )
1341+ /**
1342+ * KUNIT_ASSERT_LT() - An assertion that @left is less than @right.
1343+ * @test: The test context object.
1344+ * @left: an arbitrary expression that evaluates to a primitive C type.
1345+ * @right: an arbitrary expression that evaluates to a primitive C type.
1346+ *
1347+ * Sets an assertion that the value that @left evaluates to is less than the
1348+ * value that @right evaluates to. This is the same as KUNIT_EXPECT_LT(), except
1349+ * it causes an assertion failure (see KUNIT_ASSERT_TRUE()) when the assertion
1350+ * is not met.
1351+ */
1352+ #define KUNIT_ASSERT_LT (test , left , right ) \
1353+ KUNIT_BINARY_LT_ASSERTION (test , KUNIT_ASSERTION , left , right )
1354+
1355+ #define KUNIT_ASSERT_LT_MSG (test , left , right , fmt , ...) \
1356+ KUNIT_BINARY_LT_MSG_ASSERTION (test , \
1357+ KUNIT_ASSERTION , \
1358+ left , \
1359+ right , \
1360+ fmt , \
1361+ ##__VA_ARGS__ )
1362+ /**
1363+ * KUNIT_ASSERT_LE() - An assertion that @left is less than or equal to @right.
1364+ * @test: The test context object.
1365+ * @left: an arbitrary expression that evaluates to a primitive C type.
1366+ * @right: an arbitrary expression that evaluates to a primitive C type.
1367+ *
1368+ * Sets an assertion that the value that @left evaluates to is less than or
1369+ * equal to the value that @right evaluates to. This is the same as
1370+ * KUNIT_EXPECT_LE(), except it causes an assertion failure (see
1371+ * KUNIT_ASSERT_TRUE()) when the assertion is not met.
1372+ */
1373+ #define KUNIT_ASSERT_LE (test , left , right ) \
1374+ KUNIT_BINARY_LE_ASSERTION (test , KUNIT_ASSERTION , left , right )
1375+
1376+ #define KUNIT_ASSERT_LE_MSG (test , left , right , fmt , ...) \
1377+ KUNIT_BINARY_LE_MSG_ASSERTION (test , \
1378+ KUNIT_ASSERTION , \
1379+ left , \
1380+ right , \
1381+ fmt , \
1382+ ##__VA_ARGS__ )
1383+
1384+ /**
1385+ * KUNIT_ASSERT_GT() - An assertion that @left is greater than @right.
1386+ * @test: The test context object.
1387+ * @left: an arbitrary expression that evaluates to a primitive C type.
1388+ * @right: an arbitrary expression that evaluates to a primitive C type.
1389+ *
1390+ * Sets an assertion that the value that @left evaluates to is greater than the
1391+ * value that @right evaluates to. This is the same as KUNIT_EXPECT_GT(), except
1392+ * it causes an assertion failure (see KUNIT_ASSERT_TRUE()) when the assertion
1393+ * is not met.
1394+ */
1395+ #define KUNIT_ASSERT_GT (test , left , right ) \
1396+ KUNIT_BINARY_GT_ASSERTION (test , KUNIT_ASSERTION , left , right )
1397+
1398+ #define KUNIT_ASSERT_GT_MSG (test , left , right , fmt , ...) \
1399+ KUNIT_BINARY_GT_MSG_ASSERTION (test , \
1400+ KUNIT_ASSERTION , \
1401+ left , \
1402+ right , \
1403+ fmt , \
1404+ ##__VA_ARGS__ )
1405+
1406+ /**
1407+ * KUNIT_ASSERT_GE() - Assertion that @left is greater than or equal to @right.
1408+ * @test: The test context object.
1409+ * @left: an arbitrary expression that evaluates to a primitive C type.
1410+ * @right: an arbitrary expression that evaluates to a primitive C type.
1411+ *
1412+ * Sets an assertion that the value that @left evaluates to is greater than the
1413+ * value that @right evaluates to. This is the same as KUNIT_EXPECT_GE(), except
1414+ * it causes an assertion failure (see KUNIT_ASSERT_TRUE()) when the assertion
1415+ * is not met.
1416+ */
1417+ #define KUNIT_ASSERT_GE (test , left , right ) \
1418+ KUNIT_BINARY_GE_ASSERTION (test , KUNIT_ASSERTION , left , right )
1419+
1420+ #define KUNIT_ASSERT_GE_MSG (test , left , right , fmt , ...) \
1421+ KUNIT_BINARY_GE_MSG_ASSERTION (test , \
1422+ KUNIT_ASSERTION , \
1423+ left , \
1424+ right , \
1425+ fmt , \
1426+ ##__VA_ARGS__ )
1427+
1428+ /**
1429+ * KUNIT_ASSERT_STREQ() - An assertion that strings @left and @right are equal.
1430+ * @test: The test context object.
1431+ * @left: an arbitrary expression that evaluates to a null terminated string.
1432+ * @right: an arbitrary expression that evaluates to a null terminated string.
1433+ *
1434+ * Sets an assertion that the values that @left and @right evaluate to are
1435+ * equal. This is the same as KUNIT_EXPECT_STREQ(), except it causes an
1436+ * assertion failure (see KUNIT_ASSERT_TRUE()) when the assertion is not met.
1437+ */
1438+ #define KUNIT_ASSERT_STREQ (test , left , right ) \
1439+ KUNIT_BINARY_STR_EQ_ASSERTION (test , KUNIT_ASSERTION , left , right )
1440+
1441+ #define KUNIT_ASSERT_STREQ_MSG (test , left , right , fmt , ...) \
1442+ KUNIT_BINARY_STR_EQ_MSG_ASSERTION (test , \
1443+ KUNIT_ASSERTION , \
1444+ left , \
1445+ right , \
1446+ fmt , \
1447+ ##__VA_ARGS__ )
1448+
1449+ /**
1450+ * KUNIT_ASSERT_STRNEQ() - Expects that strings @left and @right are not equal.
1451+ * @test: The test context object.
1452+ * @left: an arbitrary expression that evaluates to a null terminated string.
1453+ * @right: an arbitrary expression that evaluates to a null terminated string.
1454+ *
1455+ * Sets an expectation that the values that @left and @right evaluate to are
1456+ * not equal. This is semantically equivalent to
1457+ * KUNIT_ASSERT_TRUE(@test, strcmp((@left), (@right))). See KUNIT_ASSERT_TRUE()
1458+ * for more information.
1459+ */
1460+ #define KUNIT_ASSERT_STRNEQ (test , left , right ) \
1461+ KUNIT_BINARY_STR_NE_ASSERTION (test , KUNIT_ASSERTION , left , right )
1462+
1463+ #define KUNIT_ASSERT_STRNEQ_MSG (test , left , right , fmt , ...) \
1464+ KUNIT_BINARY_STR_NE_MSG_ASSERTION (test , \
1465+ KUNIT_ASSERTION , \
1466+ left , \
1467+ right , \
1468+ fmt , \
1469+ ##__VA_ARGS__ )
1470+
1471+ /**
1472+ * KUNIT_ASSERT_NOT_ERR_OR_NULL() - Assertion that @ptr is not null and not err.
1473+ * @test: The test context object.
1474+ * @ptr: an arbitrary pointer.
1475+ *
1476+ * Sets an assertion that the value that @ptr evaluates to is not null and not
1477+ * an errno stored in a pointer. This is the same as
1478+ * KUNIT_EXPECT_NOT_ERR_OR_NULL(), except it causes an assertion failure (see
1479+ * KUNIT_ASSERT_TRUE()) when the assertion is not met.
1480+ */
1481+ #define KUNIT_ASSERT_NOT_ERR_OR_NULL (test , ptr ) \
1482+ KUNIT_PTR_NOT_ERR_OR_NULL_ASSERTION (test , KUNIT_ASSERTION , ptr )
1483+
1484+ #define KUNIT_ASSERT_NOT_ERR_OR_NULL_MSG (test , ptr , fmt , ...) \
1485+ KUNIT_PTR_NOT_ERR_OR_NULL_MSG_ASSERTION (test , \
1486+ KUNIT_ASSERTION , \
1487+ ptr , \
1488+ fmt , \
1489+ ##__VA_ARGS__ )
1490+
12131491#endif /* _KUNIT_TEST_H */
0 commit comments