@@ -917,6 +917,160 @@ static void __init of_unittest_changeset(void)
917
917
#endif
918
918
}
919
919
920
+ static void __init __maybe_unused changeset_check_string (struct device_node * np ,
921
+ const char * prop_name ,
922
+ const char * expected_str )
923
+ {
924
+ const char * str ;
925
+ int ret ;
926
+
927
+ ret = of_property_read_string (np , prop_name , & str );
928
+ if (unittest (ret == 0 , "failed to read %s\n" , prop_name ))
929
+ return ;
930
+
931
+ unittest (strcmp (str , expected_str ) == 0 ,
932
+ "%s value mismatch (read '%s', exp '%s')\n" ,
933
+ prop_name , str , expected_str );
934
+ }
935
+
936
+ static void __init __maybe_unused changeset_check_string_array (struct device_node * np ,
937
+ const char * prop_name ,
938
+ const char * const * expected_array ,
939
+ unsigned int count )
940
+ {
941
+ const char * str ;
942
+ unsigned int i ;
943
+ int ret ;
944
+ int cnt ;
945
+
946
+ cnt = of_property_count_strings (np , prop_name );
947
+ if (unittest (cnt >= 0 , "failed to get %s count\n" , prop_name ))
948
+ return ;
949
+
950
+ if (unittest (cnt == count ,
951
+ "%s count mismatch (read %d, exp %u)\n" ,
952
+ prop_name , cnt , count ))
953
+ return ;
954
+
955
+ for (i = 0 ; i < count ; i ++ ) {
956
+ ret = of_property_read_string_index (np , prop_name , i , & str );
957
+ if (unittest (ret == 0 , "failed to read %s[%d]\n" , prop_name , i ))
958
+ continue ;
959
+
960
+ unittest (strcmp (str , expected_array [i ]) == 0 ,
961
+ "%s[%d] value mismatch (read '%s', exp '%s')\n" ,
962
+ prop_name , i , str , expected_array [i ]);
963
+ }
964
+ }
965
+
966
+ static void __init __maybe_unused changeset_check_u32 (struct device_node * np ,
967
+ const char * prop_name ,
968
+ u32 expected_u32 )
969
+ {
970
+ u32 val32 ;
971
+ int ret ;
972
+
973
+ ret = of_property_read_u32 (np , prop_name , & val32 );
974
+ if (unittest (ret == 0 , "failed to read %s\n" , prop_name ))
975
+ return ;
976
+
977
+ unittest (val32 == expected_u32 ,
978
+ "%s value mismatch (read '%u', exp '%u')\n" ,
979
+ prop_name , val32 , expected_u32 );
980
+ }
981
+
982
+ static void __init __maybe_unused changeset_check_u32_array (struct device_node * np ,
983
+ const char * prop_name ,
984
+ const u32 * expected_array ,
985
+ unsigned int count )
986
+ {
987
+ unsigned int i ;
988
+ u32 val32 ;
989
+ int ret ;
990
+ int cnt ;
991
+
992
+ cnt = of_property_count_u32_elems (np , prop_name );
993
+ if (unittest (cnt >= 0 , "failed to get %s count\n" , prop_name ))
994
+ return ;
995
+
996
+ if (unittest (cnt == count ,
997
+ "%s count mismatch (read %d, exp %u)\n" ,
998
+ prop_name , cnt , count ))
999
+ return ;
1000
+
1001
+ for (i = 0 ; i < count ; i ++ ) {
1002
+ ret = of_property_read_u32_index (np , prop_name , i , & val32 );
1003
+ if (unittest (ret == 0 , "failed to read %s[%d]\n" , prop_name , i ))
1004
+ continue ;
1005
+
1006
+ unittest (val32 == expected_array [i ],
1007
+ "%s[%d] value mismatch (read '%u', exp '%u')\n" ,
1008
+ prop_name , i , val32 , expected_array [i ]);
1009
+ }
1010
+ }
1011
+
1012
+ static void __init of_unittest_changeset_prop (void )
1013
+ {
1014
+ #ifdef CONFIG_OF_DYNAMIC
1015
+ static const char * const str_array [] = { "abc" , "defg" , "hij" };
1016
+ static const u32 u32_array [] = { 123 , 4567 , 89 , 10 , 11 };
1017
+ struct device_node * nchangeset , * np ;
1018
+ struct of_changeset chgset ;
1019
+ int ret ;
1020
+
1021
+ nchangeset = of_find_node_by_path ("/testcase-data/changeset" );
1022
+ if (!nchangeset ) {
1023
+ pr_err ("missing testcase data\n" );
1024
+ return ;
1025
+ }
1026
+
1027
+ of_changeset_init (& chgset );
1028
+
1029
+ np = of_changeset_create_node (& chgset , nchangeset , "test-prop" );
1030
+ if (unittest (np , "failed to create test-prop node\n" ))
1031
+ goto end_changeset_destroy ;
1032
+
1033
+ ret = of_changeset_add_prop_string (& chgset , np , "prop-string" , "abcde" );
1034
+ unittest (ret == 0 , "failed to add prop-string\n" );
1035
+
1036
+ ret = of_changeset_add_prop_string_array (& chgset , np , "prop-string-array" ,
1037
+ str_array , ARRAY_SIZE (str_array ));
1038
+ unittest (ret == 0 , "failed to add prop-string-array\n" );
1039
+
1040
+ ret = of_changeset_add_prop_u32 (& chgset , np , "prop-u32" , 1234 );
1041
+ unittest (ret == 0 , "failed to add prop-u32\n" );
1042
+
1043
+ ret = of_changeset_add_prop_u32_array (& chgset , np , "prop-u32-array" ,
1044
+ u32_array , ARRAY_SIZE (u32_array ));
1045
+ unittest (ret == 0 , "failed to add prop-u32-array\n" );
1046
+
1047
+ of_node_put (np );
1048
+
1049
+ ret = of_changeset_apply (& chgset );
1050
+ if (unittest (ret == 0 , "failed to apply changeset\n" ))
1051
+ goto end_changeset_destroy ;
1052
+
1053
+ np = of_find_node_by_path ("/testcase-data/changeset/test-prop" );
1054
+ if (unittest (np , "failed to find test-prop node\n" ))
1055
+ goto end_revert_changeset ;
1056
+
1057
+ changeset_check_string (np , "prop-string" , "abcde" );
1058
+ changeset_check_string_array (np , "prop-string-array" , str_array , ARRAY_SIZE (str_array ));
1059
+ changeset_check_u32 (np , "prop-u32" , 1234 );
1060
+ changeset_check_u32_array (np , "prop-u32-array" , u32_array , ARRAY_SIZE (u32_array ));
1061
+
1062
+ of_node_put (np );
1063
+
1064
+ end_revert_changeset :
1065
+ ret = of_changeset_revert (& chgset );
1066
+ unittest (ret == 0 , "failed to revert changeset\n" );
1067
+
1068
+ end_changeset_destroy :
1069
+ of_changeset_destroy (& chgset );
1070
+ of_node_put (nchangeset );
1071
+ #endif
1072
+ }
1073
+
920
1074
static void __init of_unittest_dma_get_max_cpu_address (void )
921
1075
{
922
1076
struct device_node * np ;
@@ -4101,6 +4255,7 @@ static int __init of_unittest(void)
4101
4255
of_unittest_property_string ();
4102
4256
of_unittest_property_copy ();
4103
4257
of_unittest_changeset ();
4258
+ of_unittest_changeset_prop ();
4104
4259
of_unittest_parse_interrupts ();
4105
4260
of_unittest_parse_interrupts_extended ();
4106
4261
of_unittest_dma_get_max_cpu_address ();
0 commit comments