lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20230330220506.1399796-1-rmoar@google.com>
Date:   Thu, 30 Mar 2023 22:05:06 +0000
From:   Rae Moar <rmoar@...gle.com>
To:     brendanhiggins@...gle.com, davidgow@...gle.com, dlatypov@...gle.com
Cc:     skhan@...uxfoundation.org, kunit-dev@...glegroups.com,
        linux-kernel@...r.kernel.org, linux-kselftest@...r.kernel.org,
        Rae Moar <rmoar@...gle.com>
Subject: [PATCH v1] kunit: add tests for using current KUnit test field

Create test suite called "kunit_current" to add test coverage for the use
of current->kunit_test, which returns the current KUnit test.

Add three test cases:
- kunit_current_kunit_test_field to test the use of current->kunit_test.

- kunit_current_get_current_test to test the method
  kunit_get_current_test(), which utilizes current->kunit_test.

- kunit_current_fail_current_test to test the method
  kunit_fail_current_test(), which utilizes current->kunit_test.

Signed-off-by: Rae Moar <rmoar@...gle.com>
---
 lib/kunit/kunit-test.c | 61 +++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 60 insertions(+), 1 deletion(-)

diff --git a/lib/kunit/kunit-test.c b/lib/kunit/kunit-test.c
index b63595d3e241..91984b92c916 100644
--- a/lib/kunit/kunit-test.c
+++ b/lib/kunit/kunit-test.c
@@ -6,6 +6,7 @@
  * Author: Brendan Higgins <brendanhiggins@...gle.com>
  */
 #include <kunit/test.h>
+#include <kunit/test-bug.h>
 
 #include "try-catch-impl.h"
 
@@ -532,7 +533,65 @@ static struct kunit_suite kunit_status_test_suite = {
 	.test_cases = kunit_status_test_cases,
 };
 
+static void kunit_current_kunit_test_field(struct kunit *test)
+{
+	struct kunit *current_test;
+
+	/* Check to ensure the result of current->kunit_test
+	 * is equivalent to current test.
+	 */
+	current_test = current->kunit_test;
+	KUNIT_EXPECT_PTR_EQ(test, test, current_test);
+}
+
+static void kunit_current_get_current_test(struct kunit *test)
+{
+	struct kunit *current_test1, *current_test2;
+
+	/* Check to ensure the result of kunit_get_current_test()
+	 * is equivalent to current test.
+	 */
+	current_test1 = kunit_get_current_test();
+	KUNIT_EXPECT_PTR_EQ(test, test, current_test1);
+
+	/* Check to ensure the result of kunit_get_current_test()
+	 * is equivalent to current->kunit_test.
+	 */
+	current_test2 = current->kunit_test;
+	KUNIT_EXPECT_PTR_EQ(test, current_test1, current_test2);
+}
+
+static void kunit_current_fail_current_test(struct kunit *test)
+{
+	struct kunit fake;
+
+	/* Initialize fake test and set as current->kunit_test. */
+	kunit_init_test(&fake, "fake test", NULL);
+	KUNIT_EXPECT_EQ(test, fake.status, KUNIT_SUCCESS);
+	current->kunit_test = &fake;
+
+	/* Fail current test and expect status of fake test to be failed. */
+	kunit_fail_current_test("This test is supposed to fail.");
+	KUNIT_EXPECT_EQ(test, fake.status, (enum kunit_status)KUNIT_FAILURE);
+
+	/* Reset current->kunit_test to current test. */
+	current->kunit_test = test;
+}
+
+static struct kunit_case kunit_current_test_cases[] = {
+	KUNIT_CASE(kunit_current_kunit_test_field),
+	KUNIT_CASE(kunit_current_get_current_test),
+	KUNIT_CASE(kunit_current_fail_current_test),
+	{}
+};
+
+static struct kunit_suite kunit_current_test_suite = {
+	.name = "kunit_current",
+	.test_cases = kunit_current_test_cases,
+};
+
 kunit_test_suites(&kunit_try_catch_test_suite, &kunit_resource_test_suite,
-		  &kunit_log_test_suite, &kunit_status_test_suite);
+		  &kunit_log_test_suite, &kunit_status_test_suite,
+		  &kunit_current_test_suite);
 
 MODULE_LICENSE("GPL v2");

base-commit: 7232282dd47cce6a780c9414bd9baccf232c7686
-- 
2.40.0.348.gf938b09366-goog

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ