@@ -726,6 +726,239 @@ static void __init test_for_each_set_clump8(void)
726
726
expect_eq_clump8 (start , CLUMP_EXP_NUMBITS , clump_exp , & clump );
727
727
}
728
728
729
+ static void __init test_for_each_set_bit_wrap (void )
730
+ {
731
+ DECLARE_BITMAP (orig , 500 );
732
+ DECLARE_BITMAP (copy , 500 );
733
+ unsigned int wr , bit ;
734
+
735
+ bitmap_zero (orig , 500 );
736
+
737
+ /* Set individual bits */
738
+ for (bit = 0 ; bit < 500 ; bit += 10 )
739
+ bitmap_set (orig , bit , 1 );
740
+
741
+ /* Set range of bits */
742
+ bitmap_set (orig , 100 , 50 );
743
+
744
+ for (wr = 0 ; wr < 500 ; wr ++ ) {
745
+ bitmap_zero (copy , 500 );
746
+
747
+ for_each_set_bit_wrap (bit , orig , 500 , wr )
748
+ bitmap_set (copy , bit , 1 );
749
+
750
+ expect_eq_bitmap (orig , copy , 500 );
751
+ }
752
+ }
753
+
754
+ static void __init test_for_each_set_bit (void )
755
+ {
756
+ DECLARE_BITMAP (orig , 500 );
757
+ DECLARE_BITMAP (copy , 500 );
758
+ unsigned int bit ;
759
+
760
+ bitmap_zero (orig , 500 );
761
+ bitmap_zero (copy , 500 );
762
+
763
+ /* Set individual bits */
764
+ for (bit = 0 ; bit < 500 ; bit += 10 )
765
+ bitmap_set (orig , bit , 1 );
766
+
767
+ /* Set range of bits */
768
+ bitmap_set (orig , 100 , 50 );
769
+
770
+ for_each_set_bit (bit , orig , 500 )
771
+ bitmap_set (copy , bit , 1 );
772
+
773
+ expect_eq_bitmap (orig , copy , 500 );
774
+ }
775
+
776
+ static void __init test_for_each_set_bit_from (void )
777
+ {
778
+ DECLARE_BITMAP (orig , 500 );
779
+ DECLARE_BITMAP (copy , 500 );
780
+ unsigned int wr , bit ;
781
+
782
+ bitmap_zero (orig , 500 );
783
+
784
+ /* Set individual bits */
785
+ for (bit = 0 ; bit < 500 ; bit += 10 )
786
+ bitmap_set (orig , bit , 1 );
787
+
788
+ /* Set range of bits */
789
+ bitmap_set (orig , 100 , 50 );
790
+
791
+ for (wr = 0 ; wr < 500 ; wr ++ ) {
792
+ DECLARE_BITMAP (tmp , 500 );
793
+
794
+ bitmap_zero (copy , 500 );
795
+ bit = wr ;
796
+
797
+ for_each_set_bit_from (bit , orig , 500 )
798
+ bitmap_set (copy , bit , 1 );
799
+
800
+ bitmap_copy (tmp , orig , 500 );
801
+ bitmap_clear (tmp , 0 , wr );
802
+ expect_eq_bitmap (tmp , copy , 500 );
803
+ }
804
+ }
805
+
806
+ static void __init test_for_each_clear_bit (void )
807
+ {
808
+ DECLARE_BITMAP (orig , 500 );
809
+ DECLARE_BITMAP (copy , 500 );
810
+ unsigned int bit ;
811
+
812
+ bitmap_fill (orig , 500 );
813
+ bitmap_fill (copy , 500 );
814
+
815
+ /* Set individual bits */
816
+ for (bit = 0 ; bit < 500 ; bit += 10 )
817
+ bitmap_clear (orig , bit , 1 );
818
+
819
+ /* Set range of bits */
820
+ bitmap_clear (orig , 100 , 50 );
821
+
822
+ for_each_clear_bit (bit , orig , 500 )
823
+ bitmap_clear (copy , bit , 1 );
824
+
825
+ expect_eq_bitmap (orig , copy , 500 );
826
+ }
827
+
828
+ static void __init test_for_each_clear_bit_from (void )
829
+ {
830
+ DECLARE_BITMAP (orig , 500 );
831
+ DECLARE_BITMAP (copy , 500 );
832
+ unsigned int wr , bit ;
833
+
834
+ bitmap_fill (orig , 500 );
835
+
836
+ /* Set individual bits */
837
+ for (bit = 0 ; bit < 500 ; bit += 10 )
838
+ bitmap_clear (orig , bit , 1 );
839
+
840
+ /* Set range of bits */
841
+ bitmap_clear (orig , 100 , 50 );
842
+
843
+ for (wr = 0 ; wr < 500 ; wr ++ ) {
844
+ DECLARE_BITMAP (tmp , 500 );
845
+
846
+ bitmap_fill (copy , 500 );
847
+ bit = wr ;
848
+
849
+ for_each_clear_bit_from (bit , orig , 500 )
850
+ bitmap_clear (copy , bit , 1 );
851
+
852
+ bitmap_copy (tmp , orig , 500 );
853
+ bitmap_set (tmp , 0 , wr );
854
+ expect_eq_bitmap (tmp , copy , 500 );
855
+ }
856
+ }
857
+
858
+ static void __init test_for_each_set_bitrange (void )
859
+ {
860
+ DECLARE_BITMAP (orig , 500 );
861
+ DECLARE_BITMAP (copy , 500 );
862
+ unsigned int s , e ;
863
+
864
+ bitmap_zero (orig , 500 );
865
+ bitmap_zero (copy , 500 );
866
+
867
+ /* Set individual bits */
868
+ for (s = 0 ; s < 500 ; s += 10 )
869
+ bitmap_set (orig , s , 1 );
870
+
871
+ /* Set range of bits */
872
+ bitmap_set (orig , 100 , 50 );
873
+
874
+ for_each_set_bitrange (s , e , orig , 500 )
875
+ bitmap_set (copy , s , e - s );
876
+
877
+ expect_eq_bitmap (orig , copy , 500 );
878
+ }
879
+
880
+ static void __init test_for_each_clear_bitrange (void )
881
+ {
882
+ DECLARE_BITMAP (orig , 500 );
883
+ DECLARE_BITMAP (copy , 500 );
884
+ unsigned int s , e ;
885
+
886
+ bitmap_fill (orig , 500 );
887
+ bitmap_fill (copy , 500 );
888
+
889
+ /* Set individual bits */
890
+ for (s = 0 ; s < 500 ; s += 10 )
891
+ bitmap_clear (orig , s , 1 );
892
+
893
+ /* Set range of bits */
894
+ bitmap_clear (orig , 100 , 50 );
895
+
896
+ for_each_clear_bitrange (s , e , orig , 500 )
897
+ bitmap_clear (copy , s , e - s );
898
+
899
+ expect_eq_bitmap (orig , copy , 500 );
900
+ }
901
+
902
+ static void __init test_for_each_set_bitrange_from (void )
903
+ {
904
+ DECLARE_BITMAP (orig , 500 );
905
+ DECLARE_BITMAP (copy , 500 );
906
+ unsigned int wr , s , e ;
907
+
908
+ bitmap_zero (orig , 500 );
909
+
910
+ /* Set individual bits */
911
+ for (s = 0 ; s < 500 ; s += 10 )
912
+ bitmap_set (orig , s , 1 );
913
+
914
+ /* Set range of bits */
915
+ bitmap_set (orig , 100 , 50 );
916
+
917
+ for (wr = 0 ; wr < 500 ; wr ++ ) {
918
+ DECLARE_BITMAP (tmp , 500 );
919
+
920
+ bitmap_zero (copy , 500 );
921
+ s = wr ;
922
+
923
+ for_each_set_bitrange_from (s , e , orig , 500 )
924
+ bitmap_set (copy , s , e - s );
925
+
926
+ bitmap_copy (tmp , orig , 500 );
927
+ bitmap_clear (tmp , 0 , wr );
928
+ expect_eq_bitmap (tmp , copy , 500 );
929
+ }
930
+ }
931
+
932
+ static void __init test_for_each_clear_bitrange_from (void )
933
+ {
934
+ DECLARE_BITMAP (orig , 500 );
935
+ DECLARE_BITMAP (copy , 500 );
936
+ unsigned int wr , s , e ;
937
+
938
+ bitmap_fill (orig , 500 );
939
+
940
+ /* Set individual bits */
941
+ for (s = 0 ; s < 500 ; s += 10 )
942
+ bitmap_clear (orig , s , 1 );
943
+
944
+ /* Set range of bits */
945
+ bitmap_set (orig , 100 , 50 );
946
+
947
+ for (wr = 0 ; wr < 500 ; wr ++ ) {
948
+ DECLARE_BITMAP (tmp , 500 );
949
+
950
+ bitmap_fill (copy , 500 );
951
+ s = wr ;
952
+
953
+ for_each_clear_bitrange_from (s , e , orig , 500 )
954
+ bitmap_clear (copy , s , e - s );
955
+
956
+ bitmap_copy (tmp , orig , 500 );
957
+ bitmap_set (tmp , 0 , wr );
958
+ expect_eq_bitmap (tmp , copy , 500 );
959
+ }
960
+ }
961
+
729
962
struct test_bitmap_cut {
730
963
unsigned int first ;
731
964
unsigned int cut ;
@@ -989,12 +1222,21 @@ static void __init selftest(void)
989
1222
test_bitmap_parselist ();
990
1223
test_bitmap_printlist ();
991
1224
test_mem_optimisations ();
992
- test_for_each_set_clump8 ();
993
1225
test_bitmap_cut ();
994
1226
test_bitmap_print_buf ();
995
1227
test_bitmap_const_eval ();
996
1228
997
1229
test_find_nth_bit ();
1230
+ test_for_each_set_bit ();
1231
+ test_for_each_set_bit_from ();
1232
+ test_for_each_clear_bit ();
1233
+ test_for_each_clear_bit_from ();
1234
+ test_for_each_set_bitrange ();
1235
+ test_for_each_clear_bitrange ();
1236
+ test_for_each_set_bitrange_from ();
1237
+ test_for_each_clear_bitrange_from ();
1238
+ test_for_each_set_clump8 ();
1239
+ test_for_each_set_bit_wrap ();
998
1240
}
999
1241
1000
1242
KSTM_MODULE_LOADERS (test_bitmap );
0 commit comments