Repository navigation
Commit d277d45
committed
[libc] test: cover settimeofday() field validation
Requested in the review of #11928: add a utest for the narrowing fix.
The case walks the values whose byte range collides with INT32_MAX, so it only
proves something on targets where time_t is wider than long. Instead of silently
passing elsewhere it reports the sizes and skips:
sizeof(time_t)=8 is not wider than sizeof(long)=4, skipping
Cases, all against the on-board rtc device:
tv_sec = 2147483648 INT32_MAX + 1, first value the old cast broke
tv_sec = 2208988800 2040-01-01, the value from #11922
tv_sec = 4294967295 2106-02-07
tv_usec = -1 must keep being rejected with EINVAL
The clock is saved before the first write and restored afterwards.
Without the fix in the previous commit the three large timestamps fail, while the
negative tv_usec case still passes:
[E/utest] tv_sec = INT32_MAX + 1 ((settimeofday(&tv, 0)) not == (0))
[E/utest] tv_sec = 2208988800 ... ((settimeofday(&tv, 0)) not == (0))
[E/utest] tv_sec = 4294967295 ... ((settimeofday(&tv, 0)) not == (0))
[I/utest] tv_usec = -1 must be rejected
[E/utest] [ FAILED ] components.libc.settimeofday
Verified on bsp/qemu-vexpress-a9 (RT_USING_RTC, on-board rtc device):
with the fix : PASSED
without the fix : FAILED, the three boundary assertions listed above
Registered under its own Kconfig symbol rather than the existing time_tc.c, since
it depends on RT_USING_RTC while that case depends on RT_USING_POSIX_CLOCK.
Refs #11922
Refs #119281 parent 3b45c07 commit d277d45
3 files changed
Lines changed: 116 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
8 | 13 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
11 | 14 | | |
12 | 15 | | |
13 | 16 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 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 | + | |
0 commit comments