@@ -3190,6 +3190,8 @@ ZTEST(devicetree_api, test_string_unquoted)
31903190#define XA 12.0
31913191#define XB 34.0
31923192#define XPLUS +
3193+ #define XSTR1 "one"
3194+ #define XSTR2 "two"
31933195 const double f0_expected = 0.1234 ;
31943196 const double f1_expected = 0.9e-3 ;
31953197 const double delta = 0.1e-4 ;
@@ -3201,19 +3203,31 @@ ZTEST(devicetree_api, test_string_unquoted)
32013203 f1_expected , delta , "" );
32023204 zassert_within (DT_STRING_UNQUOTED (DT_NODELABEL (test_str_unquoted_t ), val ),
32033205 XA XPLUS XB , delta , "" );
3206+ zassert_within (DT_STRING_UNQUOTED (DT_NODELABEL (test_str_unquoted_esc_t ), val ), XA XPLUS XB ,
3207+ delta , "" );
3208+ zassert_str_equal (DT_STRING_UNQUOTED (DT_NODELABEL (test_str_unquoted_esc_s ), val ),
3209+ "one plus two" );
32043210 /* Test DT_STRING_UNQUOTED_OR */
32053211 zassert_within (DT_STRING_UNQUOTED_OR (DT_NODELABEL (test_str_unquoted_f0 ), val , (0.0 )),
32063212 f0_expected , delta , "" );
32073213 zassert_within (DT_STRING_UNQUOTED_OR (DT_NODELABEL (test_str_unquoted_f1 ), val , (0.0 )),
32083214 f1_expected , delta , "" );
32093215 zassert_within (DT_STRING_UNQUOTED_OR (DT_NODELABEL (test_str_unquoted_t ), val , (0.0 )),
32103216 XA XPLUS XB , delta , "" );
3217+ zassert_within (DT_STRING_UNQUOTED_OR (DT_NODELABEL (test_str_unquoted_esc_t ), val , (0.0 )),
3218+ XA XPLUS XB , delta , "" );
3219+ zassert_str_equal (DT_STRING_UNQUOTED_OR (DT_NODELABEL (test_str_unquoted_esc_s ), val , "nak" ),
3220+ "one plus two" );
32113221 zassert_within (DT_STRING_UNQUOTED_OR (DT_NODELABEL (test_str_unquoted_f0 ), nak , (0.0 )),
32123222 0.0 , delta , "" );
32133223 zassert_within (DT_STRING_UNQUOTED_OR (DT_NODELABEL (test_str_unquoted_f1 ), nak , (0.0 )),
32143224 0.0 , delta , "" );
32153225 zassert_within (DT_STRING_UNQUOTED_OR (DT_NODELABEL (test_str_unquoted_t ), nak , (0.0 )),
32163226 0.0 , delta , "" );
3227+ zassert_within (DT_STRING_UNQUOTED_OR (DT_NODELABEL (test_str_unquoted_esc_t ), nak , (0.0 )),
3228+ 0.0 , delta , "" );
3229+ zassert_str_equal (DT_STRING_UNQUOTED_OR (DT_NODELABEL (test_str_unquoted_esc_s ), nak , "nak" ),
3230+ "nak" );
32173231 /* Test DT_INST_STRING_UNQUOTED */
32183232#define STRING_UNQUOTED_VAR (node_id ) _CONCAT(var_, node_id)
32193233#define STRING_UNQUOTED_TEST_INST_EXPANSION (inst ) \
@@ -3226,6 +3240,8 @@ ZTEST(devicetree_api, test_string_unquoted)
32263240 f1_expected , delta , "" );
32273241 zassert_within (STRING_UNQUOTED_VAR (DT_NODELABEL (test_str_unquoted_t )), XA XPLUS XB ,
32283242 delta , "" );
3243+ zassert_within (STRING_UNQUOTED_VAR (DT_NODELABEL (test_str_unquoted_esc_t )), XA XPLUS XB ,
3244+ delta , "" );
32293245
32303246 /* Test DT_INST_STRING_UNQUOTED_OR */
32313247#define STRING_UNQUOTED_OR_VAR (node_id ) _CONCAT(var_or_, node_id)
@@ -3242,15 +3258,21 @@ ZTEST(devicetree_api, test_string_unquoted)
32423258 f1_expected , delta , "" );
32433259 zassert_within (STRING_UNQUOTED_OR_VAR (DT_NODELABEL (test_str_unquoted_t ))[0 ],
32443260 XA XPLUS XB , delta , "" );
3261+ zassert_within (STRING_UNQUOTED_OR_VAR (DT_NODELABEL (test_str_unquoted_esc_t ))[0 ],
3262+ XA XPLUS XB , delta , "" );
32453263 zassert_within (STRING_UNQUOTED_OR_VAR (DT_NODELABEL (test_str_unquoted_f0 ))[1 ],
32463264 1.0e10 , delta , "" );
32473265 zassert_within (STRING_UNQUOTED_OR_VAR (DT_NODELABEL (test_str_unquoted_f1 ))[1 ],
32483266 1.0e10 , delta , "" );
32493267 zassert_within (STRING_UNQUOTED_OR_VAR (DT_NODELABEL (test_str_unquoted_t ))[1 ],
32503268 1.0e10 , delta , "" );
3269+ zassert_within (STRING_UNQUOTED_OR_VAR (DT_NODELABEL (test_str_unquoted_esc_t ))[1 ], 1.0e10 ,
3270+ delta , "" );
32513271#undef XA
32523272#undef XB
32533273#undef XPLUS
3274+ #undef XSTR1
3275+ #undef XSTR2
32543276}
32553277
32563278#undef DT_DRV_COMPAT
@@ -3263,6 +3285,8 @@ ZTEST(devicetree_api, test_string_idx_unquoted)
32633285#define XD 78.0
32643286#define XPLUS +
32653287#define XMINUS -
3288+ #define XSTR1 "one"
3289+ #define XSTR2 "two"
32663290 const double delta = 0.1e-4 ;
32673291
32683292 /* DT_STRING_UNQUOTED_BY_IDX */
@@ -3293,6 +3317,11 @@ ZTEST(devicetree_api, test_string_idx_unquoted)
32933317 zassert_within (DT_STRING_UNQUOTED_BY_IDX (DT_NODELABEL (test_stra_unquoted_t ), val , 3 ),
32943318 XC XMINUS XD , delta , "" );
32953319
3320+ zassert_within (DT_STRING_UNQUOTED_BY_IDX (DT_NODELABEL (test_stra_unquoted_esc ), val , 0 ),
3321+ XA XPLUS XB , delta , "" );
3322+ zassert_str_equal (DT_STRING_UNQUOTED_BY_IDX (DT_NODELABEL (test_stra_unquoted_esc ), val , 1 ),
3323+ "one plus two" );
3324+
32963325#define STRING_UNQUOTED_BY_IDX_VAR (node_id ) _CONCAT(var_, node_id)
32973326#define STRING_UNQUOTED_BY_IDX_TEST_INST_EXPANSION (inst ) \
32983327 double STRING_UNQUOTED_BY_IDX_VAR(DT_DRV_INST(inst))[] = { \
@@ -3335,6 +3364,26 @@ ZTEST(devicetree_api, test_string_idx_unquoted)
33353364#undef XD
33363365#undef XPLUS
33373366#undef XMINUS
3367+ #undef XSTR1
3368+ #undef XSTR2
3369+ }
3370+
3371+ #undef DT_DRV_COMPAT
3372+ ZTEST (devicetree_api , test_string_escape )
3373+ {
3374+ zassert_str_equal (DT_PROP (DT_NODELABEL (test_str_escape_0 ), val ), "\a\b\f\n\r\t\v" );
3375+ zassert_str_equal (DT_PROP (DT_NODELABEL (test_str_escape_1 ), val ), "\'single\' \"double\"" );
3376+ zassert_str_equal (DT_PROP (DT_NODELABEL (test_str_escape_2 ), val ), "first\nsecond" );
3377+ zassert_str_equal (DT_PROP (DT_NODELABEL (test_str_escape_3 ), val ), "\x01\x7F" );
3378+ }
3379+
3380+ ZTEST (devicetree_api , test_string_array_escape )
3381+ {
3382+ zassert_str_equal (DT_PROP_BY_IDX (DT_NODELABEL (test_stra_escape ), val , 0 ), "\a\b\f\n\r\t\v" );
3383+ zassert_str_equal (DT_PROP_BY_IDX (DT_NODELABEL (test_stra_escape ), val , 1 ),
3384+ "\'single\' \"double\"" );
3385+ zassert_str_equal (DT_PROP_BY_IDX (DT_NODELABEL (test_stra_escape ), val , 2 ), "first\nsecond" );
3386+ zassert_str_equal (DT_PROP_BY_IDX (DT_NODELABEL (test_stra_escape ), val , 3 ), "\x01\x7F" );
33383387}
33393388
33403389#undef DT_DRV_COMPAT
0 commit comments