@@ -301,6 +301,8 @@ struct kunit {
301
301
struct list_head resources ; /* Protected by lock. */
302
302
303
303
char status_comment [KUNIT_STATUS_COMMENT_SIZE ];
304
+ /* Saves the last seen test. Useful to help with faults. */
305
+ struct kunit_loc last_seen ;
304
306
};
305
307
306
308
static inline void kunit_set_failure (struct kunit * test )
@@ -567,6 +569,15 @@ void __printf(2, 3) kunit_log_append(struct string_stream *log, const char *fmt,
567
569
#define kunit_err (test , fmt , ...) \
568
570
kunit_printk(KERN_ERR, test, fmt, ##__VA_ARGS__)
569
571
572
+ /*
573
+ * Must be called at the beginning of each KUNIT_*_ASSERTION().
574
+ * Cf. KUNIT_CURRENT_LOC.
575
+ */
576
+ #define _KUNIT_SAVE_LOC (test ) do { \
577
+ WRITE_ONCE(test->last_seen.file, __FILE__); \
578
+ WRITE_ONCE(test->last_seen.line, __LINE__); \
579
+ } while (0)
580
+
570
581
/**
571
582
* KUNIT_SUCCEED() - A no-op expectation. Only exists for code clarity.
572
583
* @test: The test context object.
@@ -575,7 +586,7 @@ void __printf(2, 3) kunit_log_append(struct string_stream *log, const char *fmt,
575
586
* words, it does nothing and only exists for code clarity. See
576
587
* KUNIT_EXPECT_TRUE() for more information.
577
588
*/
578
- #define KUNIT_SUCCEED (test ) do {} while (0 )
589
+ #define KUNIT_SUCCEED (test ) _KUNIT_SAVE_LOC(test )
579
590
580
591
void __noreturn __kunit_abort (struct kunit * test );
581
592
@@ -601,14 +612,16 @@ void __printf(6, 7) __kunit_do_failed_assertion(struct kunit *test,
601
612
} while (0 )
602
613
603
614
604
- #define KUNIT_FAIL_ASSERTION (test , assert_type , fmt , ...) \
615
+ #define KUNIT_FAIL_ASSERTION (test , assert_type , fmt , ...) do { \
616
+ _KUNIT_SAVE_LOC (test ); \
605
617
_KUNIT_FAILED (test , \
606
618
assert_type , \
607
619
kunit_fail_assert , \
608
620
kunit_fail_assert_format , \
609
621
{}, \
610
622
fmt , \
611
- ##__VA_ARGS__ )
623
+ ##__VA_ARGS__ ); \
624
+ } while (0 )
612
625
613
626
/**
614
627
* KUNIT_FAIL() - Always causes a test to fail when evaluated.
@@ -637,6 +650,7 @@ void __printf(6, 7) __kunit_do_failed_assertion(struct kunit *test,
637
650
fmt , \
638
651
...) \
639
652
do { \
653
+ _KUNIT_SAVE_LOC(test); \
640
654
if (likely(!!(condition_) == !!expected_true_)) \
641
655
break; \
642
656
\
@@ -698,6 +712,7 @@ do { \
698
712
.right_text = #right, \
699
713
}; \
700
714
\
715
+ _KUNIT_SAVE_LOC(test); \
701
716
if (likely(__left op __right)) \
702
717
break; \
703
718
\
@@ -758,6 +773,7 @@ do { \
758
773
.right_text = #right, \
759
774
}; \
760
775
\
776
+ _KUNIT_SAVE_LOC(test); \
761
777
if (likely((__left) && (__right) && (strcmp(__left, __right) op 0))) \
762
778
break; \
763
779
\
@@ -791,6 +807,7 @@ do { \
791
807
.right_text = #right, \
792
808
}; \
793
809
\
810
+ _KUNIT_SAVE_LOC(test); \
794
811
if (likely(__left && __right)) \
795
812
if (likely(memcmp(__left, __right, __size) op 0)) \
796
813
break; \
@@ -815,6 +832,7 @@ do { \
815
832
do { \
816
833
const typeof(ptr) __ptr = (ptr); \
817
834
\
835
+ _KUNIT_SAVE_LOC(test); \
818
836
if (!IS_ERR_OR_NULL(__ptr)) \
819
837
break; \
820
838
\
0 commit comments