Linux preempt-rt

Check our new training course

Real-Time Linux with PREEMPT_RT

Check our new training course
with Creative Commons CC-BY-SA
lecture and lab materials

Bootlin logo

Elixir Cross Referencer

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
/* test_sprintf.c - test various sprintf functionality */

/*
 * Copyright (c) 2013-2014 Wind River Systems, Inc.
 *
 * SPDX-License-Identifier: Apache-2.0
 */

/*
 * DESCRIPTION
 * This module contains the code for testing sprintf() functionality.
 */

#include <ztest.h>
#include <stdio.h>
#include <stdarg.h>

#define DEADBEEF  0xdeadbeef

#define DEADBEEF_LHEX_ALT_STR  "0xdeadbeef"
#define DEADBEEF_UHEX_ALT_STR  "0XDEADBEEF"
#define DEADBEEF_LHEX_STR      "deadbeef"
#define DEADBEEF_UHEX_STR      "DEADBEEF"
#define DEADBEEF_UNSIGNED_STR  "3735928559"
#define DEADBEEF_SIGNED_STR    "-559038737"
#define DEADBEEF_OCTAL_STR     "33653337357"
#define DEADBEEF_OCTAL_ALT_STR "033653337357"
#define DEADBEEF_PTR_STR       "0xdeadbeef"

/*
 * A really long string (330 characters + NUL).
 * The underlying sprintf() architecture will truncate it.
 */
#define REALLY_LONG_STRING		     \
	"1111111111111111111111111111111111" \
	"1111111111111111111111111111111"    \
	"22222222222222222222222222222222"   \
	"222222222222222222222222222222222"  \
	"333333333333333333333333333333333"  \
	"33333333333333333333333333333333"   \
	"44444444444444444444444444444444"   \
	"444444444444444444444444444444444"  \
	"555555555555555555555555555555555"  \
	"55555555555555555555555555555555"   \
	"66666666666666666666666666666666"   \
	"666666666666666666666666666666666"

#define PRINTF_MAX_STRING_LENGTH   200

union raw_double_u {
	double d;
	struct {
		u32_t u1;       /* This part contains the exponent */
		u32_t u2;       /* This part contains the fraction */
	};
};

/**
 *
 * @brief Test sprintf with doubles
 *
 */

void test_sprintf_double(void)
{
	char buffer[100];
	union raw_double_u var;

#ifndef CONFIG_FLOAT
	ztest_test_skip();
	return;
#endif

	var.u1 = 0x00000000;
	var.u2 = 0x7ff00000;    /* Bit pattern for +INF (double) */
	sprintf(buffer, "%e", var.d);
	zassert_true((strcmp(buffer, "inf") == 0),
		     "sprintf(inf) - incorrect output '%s'\n", buffer);

	sprintf(buffer, "%E", var.d);
	zassert_true((strcmp(buffer, "INF") == 0),
		     "sprintf(INF) - incorrect output '%s'\n", buffer);

	sprintf(buffer, "%f", var.d);
	zassert_true((strcmp(buffer, "inf") == 0),
		     "sprintf(inf) - incorrect output '%s'\n", buffer);

	sprintf(buffer, "%F", var.d);
	zassert_true((strcmp(buffer, "INF") == 0),
		     "sprintf(INF) - incorrect output '%s'\n", buffer);

	sprintf(buffer, "%g", var.d);
	zassert_true((strcmp(buffer, "inf") == 0),
		     "sprintf(inf) - incorrect output '%s'\n", buffer);

	sprintf(buffer, "%G", var.d);
	zassert_true((strcmp(buffer, "INF") == 0),
		     "sprintf(INF) - incorrect output '%s'\n", buffer);

	var.u1 = 0x00000000;
	var.u2 = 0xfff00000;    /* Bit pattern for -INF (double) */
	sprintf(buffer, "%e", var.d);
	zassert_true((strcmp(buffer, "-inf") == 0),
		     "sprintf(-INF) - incorrect output '%s'\n", buffer);

	sprintf(buffer, "%E", var.d);
	zassert_true((strcmp(buffer, "-INF") == 0),
		     "sprintf(-INF) - incorrect output '%s'\n", buffer);

	sprintf(buffer, "%f", var.d);
	zassert_true((strcmp(buffer, "-inf") == 0),
		     "sprintf(-INF) - incorrect output '%s'\n", buffer);

	sprintf(buffer, "%F", var.d);
	zassert_true((strcmp(buffer, "-INF") == 0),
		     "sprintf(-INF) - incorrect output '%s'\n", buffer);

	sprintf(buffer, "%g", var.d);
	zassert_true((strcmp(buffer, "-inf") == 0),
		     "sprintf(-INF) - incorrect output '%s'\n", buffer);

	sprintf(buffer, "%G", var.d);
	zassert_true((strcmp(buffer, "-INF") == 0),
		     "sprintf(-INF) - incorrect output '%s'\n", buffer);

	var.u1 = 0x00000000;
	var.u2 = 0x7ff80000;    /* Bit pattern for NaN (double) */
	sprintf(buffer, "%e", var.d);
	zassert_true((strcmp(buffer, "nan") == 0),
		     "sprintf(nan) - incorrect output '%s'\n", buffer);

	sprintf(buffer, "%E", var.d);
	zassert_true((strcmp(buffer, "NAN") == 0),
		     "sprintf(NAN) - incorrect output '%s'\n", buffer);

	sprintf(buffer, "%f", var.d);
	zassert_true((strcmp(buffer, "nan") == 0),
		     "sprintf(nan) - incorrect output '%s'\n", buffer);

	sprintf(buffer, "%F", var.d);
	zassert_true((strcmp(buffer, "NAN") == 0),
		     "sprintf(NAN) - incorrect output '%s'\n", buffer);

	sprintf(buffer, "%g", var.d);
	zassert_true((strcmp(buffer, "nan") == 0),
		     "sprintf(nan) - incorrect output '%s'\n", buffer);

	sprintf(buffer, "%G", var.d);
	zassert_true((strcmp(buffer, "NAN") == 0),
		     "sprintf(NAN) - incorrect output '%s'\n", buffer);

	var.u1 = 0x00000000;
	var.u2 = 0xfff80000;    /* Bit pattern for -NaN (double) */
	sprintf(buffer, "%e", var.d);
	zassert_true((strcmp(buffer, "-nan") == 0),
		     "sprintf(-nan) - incorrect output '%s'\n", buffer);

	sprintf(buffer, "%E", var.d);
	zassert_true((strcmp(buffer, "-NAN") == 0),
		     "sprintf(-NAN) - incorrect output '%s'\n", buffer);

	sprintf(buffer, "%f", var.d);
	zassert_true((strcmp(buffer, "-nan") == 0),
		     "sprintf(-nan) - incorrect output '%s'\n", buffer);

	sprintf(buffer, "%F", var.d);
	zassert_true((strcmp(buffer, "-NAN") == 0),
		     "sprintf(-NAN) - incorrect output '%s'\n", buffer);

	sprintf(buffer, "%g", var.d);
	zassert_true((strcmp(buffer, "-nan") == 0),
		     "sprintf(-nan) - incorrect output '%s'\n", buffer);

	sprintf(buffer, "%G", var.d);
	zassert_true((strcmp(buffer, "-NAN") == 0),
		     "sprintf(-NAN) - incorrect output '%s'\n", buffer);

	var.d = 1.0;
	sprintf(buffer, "%f", var.d);
	zassert_true((strcmp(buffer, "1.000000") == 0),
		     "sprintf(1.0) - incorrect output '%s'\n", buffer);

	sprintf(buffer, "%+f", var.d);
	zassert_true((strcmp(buffer, "+1.000000") == 0),
		     "sprintf(+1.0) - incorrect output '%s'\n", buffer);

	sprintf(buffer, "%.2f", var.d);
	zassert_true((strcmp(buffer, "1.00") == 0),
		     "sprintf(1.00) - incorrect output '%s'\n", buffer);

	sprintf(buffer, "%.*f", 11, var.d);
	zassert_true((strcmp(buffer, "1.00000000000") == 0),
		     "sprintf(1.00000000000) - incorrect "
		     "output '%s'\n", buffer);

	sprintf(buffer, "%12f", var.d);
	zassert_true((strcmp(buffer, "    1.000000") == 0),
		     "sprintf(    1.000000) - incorrect "
		     "output '%s'\n", buffer);

	sprintf(buffer, "%-12f", var.d);
	zassert_true((strcmp(buffer, "1.000000    ") == 0),
		     "sprintf(1.000000    ) - incorrect "
		     "output '%s'\n", buffer);

	sprintf(buffer, "%012f", var.d);
	zassert_true((strcmp(buffer, "00001.000000") == 0),
		     "sprintf(00001.000000) - incorrect "
		     "output '%s'\n", buffer);

	var.d = -1.0;
	sprintf(buffer, "%f", var.d);
	zassert_true((strcmp(buffer, "-1.000000") == 0),
		     "sprintf(-1.0) - incorrect output '%s'\n", buffer);

	var.d = 1234.56789;
	sprintf(buffer, "%f", var.d);
	zassert_true((strcmp(buffer, "1234.567890") == 0),
		     "sprintf(-1.0) - incorrect output '%s'\n", buffer);

	/*******************/
	var.d = 1234.0;
	sprintf(buffer, "%e", var.d);
	zassert_true((strcmp(buffer, "1.234000e+03") == 0),
		     "sprintf(1.234000e+03) - incorrect "
		     "output '%s'\n", buffer);

	sprintf(buffer, "%E", var.d);
	zassert_true((strcmp(buffer, "1.234000E+03") == 0),
		     "sprintf(1.234000E+03) - incorrect "
		     "output '%s'\n", buffer);

	/*******************/
	var.d = 0.1234;
	sprintf(buffer, "%e", var.d);
	zassert_true((strcmp(buffer, "1.234000e-01") == 0),
		     "sprintf(1.234000e-01) - incorrect "
		     "output '%s'\n", buffer);

	sprintf(buffer, "%E", var.d);
	zassert_true((strcmp(buffer, "1.234000E-01") == 0),
		     "sprintf(1.234000E-01) - incorrect "
		     "output '%s'\n", buffer);

	/*******************/
	var.d = 1234000000.0;
	sprintf(buffer, "%g", var.d);
	zassert_true((strcmp(buffer, "1.234e+09") == 0),
		     "sprintf(1.234e+09) - incorrect "
		     "output '%s'\n", buffer);

	sprintf(buffer, "%G", var.d);
	zassert_true((strcmp(buffer, "1.234E+09") == 0),
		     "sprintf(1.234E+09) - incorrect "
		     "output '%s'\n", buffer);
}

/**
 * @brief A test wrapper for vsnprintf()
 */
int tvsnprintf(char *s, size_t len, const char *format, ...)
{
	va_list vargs;
	int r;

	va_start(vargs, format);
	r = vsnprintf(s, len, format, vargs);
	va_end(vargs);

	return r;
}

/**
 *
 * @brief Test the vsprintf() routine
 *
 * This routine does not aim to test the same underlying functionality as
 * sprintfTest().  Instead it tries to limit it to functionality specific to
 * vsnprintf().  Instead of calling vsnprintf() directly, it invokes the wrapper
 * routine tvsnprintf().
 *
 */

void test_vsnprintf(void)
{
	int len;
	char buffer[100];

	/*******************/
	buffer[0] = '\0';
	len = tvsnprintf(buffer, 0, "%x", DEADBEEF);
	zassert_true((len == strlen(DEADBEEF_LHEX_STR)),
		     "vsnprintf(%%x).  Expected return value %zu, not %d\n",
		     strlen(DEADBEEF_LHEX_STR), len);

	zassert_true((strcmp(buffer, "") == 0),
		     "vsnprintf(%%x).  Expected '%s', got '%s'\n",
		     "", buffer);

	/*******************/
	len = tvsnprintf(buffer, 4, "%x", DEADBEEF);
	zassert_true((len == strlen(DEADBEEF_LHEX_STR)),
		     "vsnprintf(%%x).  Expected return value %zu, not %d\n",
		     strlen(DEADBEEF_LHEX_STR), len);

	zassert_true((strcmp(buffer, "dea") == 0),
		     "vsnprintf(%%x).  Expected '%s', got '%s'\n",
		     "dea", buffer);

}

/**
 *
 * @brief A test wrapper for vsprintf()
 */

int tvsprintf(char *s, const char *format, ...)
{
	va_list vargs;
	int r;

	va_start(vargs, format);
	r = vsprintf(s, format, vargs);
	va_end(vargs);

	return r;
}

/**
 *
 * @brief Test the vsprintf() routine
 *
 * This routine does not aim to test the same underlying functionality as
 * sprintfTest().  Instead it tries to limit it to functionality specific to
 * vsprintf().
 *
 */

void test_vsprintf(void)
{
	int len;
	char buffer[100];

	/*******************/
	len = tvsprintf(buffer, "%x", DEADBEEF);
	zassert_true((len == strlen(DEADBEEF_LHEX_STR)),
		     "sprintf(%%x).  Expected %zu bytes written, not %d\n",
		     strlen(DEADBEEF_LHEX_STR), len);

	zassert_true((strcmp(buffer, DEADBEEF_LHEX_STR) == 0),
		     "sprintf(%%x).  Expected '%s', got '%s'\n",
		     DEADBEEF_LHEX_STR, buffer);
}

/**
 *
 * @brief Test the snprintf() routine
 *
 * This routine does not aim to test the same underlying functionality as
 * sprintfTest().  Instead it tries to limit it to functionality specific to
 * snprintf().
 *
 */

void test_snprintf(void)
{
#if defined(__GNUC__) && __GNUC__ >= 7
	/*
	 * GCC 7 and newer are smart enough to realize that in the statements
	 * below, the output will not fit in 0 or 4 bytes, but that it requires
	 * 9.
	 * So it throws a warning in compile time. But in this case we are
	 * actually testing that snprintf's return value is what it should be
	 * while truncating the output. So let's suppress this warning here.
	 */
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wformat-truncation"
#endif

	int len;
	char buffer[100];

	/*******************/
	buffer[0] = '\0';
	len = snprintf(buffer, 0, "%x", DEADBEEF);
	zassert_true((len == strlen(DEADBEEF_LHEX_STR)),
		     "snprintf(%%x).  Expected return value %zu, not %d\n",
		     strlen(DEADBEEF_LHEX_STR), len);

	zassert_true((strcmp(buffer, "") == 0),
		     "snprintf(%%x).  Expected '%s', got '%s'\n",
		     "", buffer);
	/*******************/
	len = snprintf(buffer, 4, "%x", DEADBEEF);
	zassert_true((len == strlen(DEADBEEF_LHEX_STR)),
		     "snprintf(%%x).  Expected return value %zu, not %d\n",
		     strlen(DEADBEEF_LHEX_STR), len);

	zassert_true((strcmp(buffer, "dea") == 0),
		     "snprintf(%%x).  Expected '%s', got '%s'\n",
		     "dea", buffer);

#if defined(__GNUC__) && __GNUC__ >= 7
#pragma GCC diagnostic pop
#endif
}

/**
 *
 * @brief Test the sprintf() routine with miscellaneous specifiers
 *
 */

void test_sprintf_misc(void)
{
	int count;
	char buffer[100];

	/*******************/
	sprintf(buffer, "%p", (void *) DEADBEEF);
	zassert_false((strcmp(buffer, DEADBEEF_PTR_STR) != 0),
		      "sprintf(%%p).  Expected '%s', got '%s'", DEADBEEF_PTR_STR, buffer);
	/*******************/
	sprintf(buffer, "test data %n test data", &count);
	zassert_false((count != 10), "sprintf(%%n).  Expected count to be %d, not %d",
		      10, count);

	zassert_false((strcmp(buffer, "test data  test data") != 0),
		      "sprintf(%%p).  Expected '%s', got '%s'",
		      "test data  test data", buffer);

	/*******************/
	sprintf(buffer, "%*d", 10, 1234);
	zassert_true((strcmp(buffer, "      1234") == 0),
		     "sprintf(%%p).  Expected '%s', got '%s'",
		     "      1234", buffer);

	/*******************/
	sprintf(buffer, "%*d", -10, 1234);
	zassert_true((strcmp(buffer, "1234      ") == 0),
		     "sprintf(%%p).  Expected '%s', got '%s'",
		     "1234      ", buffer);

	/*******************/
	sprintf(buffer, "% d", 1234);
	zassert_true((strcmp(buffer, " 1234") == 0),
		     "sprintf(%% d). Expected '%s', got '%s'",
		     " 1234", buffer);

	/*******************/
	sprintf(buffer, "%hx", (unsigned short)1234);
	zassert_true((strcmp("4d2", buffer) == 0),
		     "sprintf(%%hx).  Expected '4d2', got '%s'", buffer);

	/*******************/
	sprintf(buffer, "%lx", 1234ul);
	zassert_true((strcmp("4d2", buffer) == 0),
		     "sprintf(%%lx).  Expected '4d2', got '%s'", buffer);

}

/**
 *
 * @brief Test the sprintf() routine with integers
 *
 */
void test_sprintf_integer(void)
{
	int len;
	char buffer[100];

	/*******************/

	/* Note: prints hex numbers in 8 characters */
	len = sprintf(buffer, "%x", 0x11);
	zassert_true((len == 2),
		     "sprintf(%%x). "
		     "Expected 2 bytes written, not %d", len);

	zassert_true((strcmp(buffer, "11") == 0),
		     "sprintf(%%x). "
		     "Expected '%s', got '%s'", "11", buffer);

	/*******************/
	len = sprintf(buffer, "%x", DEADBEEF);
	zassert_true((len == strlen(DEADBEEF_LHEX_STR)),
		     "sprintf(%%x).  Expected %zu bytes written, not %d\n",
		     strlen(DEADBEEF_LHEX_STR), len);
	/*******************/
	zassert_true((strcmp(buffer, DEADBEEF_LHEX_STR) == 0),
		     "sprintf(%%x).  Expected '%s', got '%s'\n",
		     DEADBEEF_LHEX_STR, buffer);
	/*******************/
	len = sprintf(buffer, "%X", DEADBEEF);
	zassert_true((len == strlen(DEADBEEF_UHEX_STR)),
		     "sprintf(%%X).  Expected %zu bytes written, not %d\n",
		     strlen(DEADBEEF_UHEX_STR), len);

	zassert_true((strcmp(buffer, DEADBEEF_UHEX_STR) == 0),
		     "sprintf(%%X).  Expected '%s', got '%s'\n",
		     DEADBEEF_UHEX_STR, buffer);

	/*******************/
	len = sprintf(buffer, "%u", DEADBEEF);
	zassert_true((len == strlen(DEADBEEF_UNSIGNED_STR)),
		     "sprintf(%%u).  Expected %zu bytes written, not %d\n",
		     strlen(DEADBEEF_UNSIGNED_STR), len);

	zassert_true((strcmp(buffer, DEADBEEF_UNSIGNED_STR) == 0),
		     "sprintf(%%u).  Expected '%s', got '%s'\n",
		     DEADBEEF_UNSIGNED_STR, buffer);

	/*******************/
	len = sprintf(buffer, "%d", (int) DEADBEEF);
	zassert_true((len == strlen(DEADBEEF_SIGNED_STR)),
		     "sprintf(%%d).  Expected %zu bytes written, not %d\n",
		     strlen(DEADBEEF_SIGNED_STR), len);

	zassert_true((strcmp(buffer, DEADBEEF_SIGNED_STR) == 0),
		     "sprintf(%%d).  Expected '%s', got '%s'\n",
		     DEADBEEF_SIGNED_STR, buffer);

	/*******************/
	len = sprintf(buffer, "%o", DEADBEEF);
	zassert_true((len == strlen(DEADBEEF_OCTAL_STR)),
		     "sprintf(%%o).  Expected %zu bytes written, not %d\n",
		     strlen(DEADBEEF_OCTAL_STR), len);

	zassert_true((strcmp(buffer, DEADBEEF_OCTAL_STR) == 0),
		     "sprintf(%%o).  Expected '%s', got '%s'\n",
		     DEADBEEF_OCTAL_STR, buffer);

	/*******************/
	len = sprintf(buffer, "%#o", DEADBEEF);
	zassert_true((len == strlen(DEADBEEF_OCTAL_ALT_STR)),
		     "sprintf(%%#o).  Expected %zu bytes written, not %d\n",
		     strlen(DEADBEEF_OCTAL_ALT_STR), len);

	zassert_true((strcmp(buffer, DEADBEEF_OCTAL_ALT_STR) == 0),
		     "sprintf(%%#o).  Expected '%s', got '%s'\n",
		     DEADBEEF_OCTAL_ALT_STR, buffer);

	/*******************/
	len = sprintf(buffer, "%#x", DEADBEEF);
	zassert_true((len == strlen(DEADBEEF_LHEX_ALT_STR)),
		     "sprintf(%%#x).  Expected %zu bytes written, not %d\n",
		     strlen(DEADBEEF_LHEX_ALT_STR), len);

	zassert_true((strcmp(buffer, DEADBEEF_LHEX_ALT_STR) == 0),
		     "sprintf(%%#x).  Expected '%s', got '%s'\n",
		     DEADBEEF_LHEX_ALT_STR, buffer);

	/*******************/
	len = sprintf(buffer, "%#X", DEADBEEF);
	zassert_true((len == strlen(DEADBEEF_UHEX_ALT_STR)),
		     "sprintf(%%#X).  Expected %zu bytes written, not %d\n",
		     strlen(DEADBEEF_UHEX_ALT_STR), len);

	zassert_true((strcmp(buffer, DEADBEEF_UHEX_ALT_STR) == 0),
		     "sprintf(%%#X).  Expected '%s', got '%s'\n",
		     DEADBEEF_UHEX_ALT_STR, buffer);

	/*******************/

	len = sprintf(buffer, "%+d", 1);
	zassert_true((len == 2),
		     "sprintf(%%+d).  Expected %d bytes written, not %d\n",
		     2, len);

	zassert_true((strcmp(buffer, "+1") == 0),
		     "sprintf(%%+d). Expected '+1', got '%s'\n", buffer);

}

/**
 *
 * @brief Test sprintf with strings
 *
 */

void test_sprintf_string(void)
{
	int len;
	char buffer[400];

	sprintf(buffer, "%%");
	zassert_true((strcmp(buffer, "%") == 0),
		     "sprintf(%%).  Expected '%%', got '%s'\n", buffer);

	sprintf(buffer, "%c", 't');
	zassert_true((strcmp(buffer, "t") == 0),
		     "sprintf(%%c).  Expected 't', got '%s'\n", buffer);

	sprintf(buffer, "%s", "short string");
	zassert_true((strcmp(buffer, "short string") == 0),
		     "sprintf(%%s). "
		     "Expected 'short string', got '%s'\n", buffer);

	len = sprintf(buffer, "%s", REALLY_LONG_STRING);
#if !defined CONFIG_NEWLIB_LIBC && !defined CONFIG_ARCH_POSIX
	zassert_true((len == PRINTF_MAX_STRING_LENGTH),
		     "Internals changed. "
		     "Max string length no longer %d got %d\n",
		     PRINTF_MAX_STRING_LENGTH, len);
#endif
	zassert_true((strncmp(buffer, REALLY_LONG_STRING,
			      PRINTF_MAX_STRING_LENGTH) == 0),
		     "First %d characters of REALLY_LONG_STRING "
		     "not printed!\n",
		     PRINTF_MAX_STRING_LENGTH);

}

/**
 *
 * @brief Test entry point
 *
 * @return N/A
 */

void test_main(void)
{
	ztest_test_suite(test_sprintf,
			 ztest_unit_test(test_sprintf_double),
			 ztest_unit_test(test_sprintf_integer),
			 ztest_unit_test(test_vsprintf),
			 ztest_unit_test(test_vsnprintf),
			 ztest_unit_test(test_sprintf_string),
			 ztest_unit_test(test_sprintf_misc));
	ztest_run_test_suite(test_sprintf);
}