This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git
The following commit(s) were added to refs/heads/master by this push:
new d23eb0149 fs_stat_test: fix fs date case not strict enough
d23eb0149 is described below
commit d23eb014900aec9f0d0ec91723932a911b45c29d
Author: buxiasen <[email protected]>
AuthorDate: Fri Feb 14 12:17:00 2025 +0800
fs_stat_test: fix fs date case not strict enough
use utc diff should prefer and more strict.
Signed-off-by: buxiasen <[email protected]>
---
testing/testsuites/kernel/fs/cases/fs_stat_test.c | 39 +++++------------------
1 file changed, 8 insertions(+), 31 deletions(-)
diff --git a/testing/testsuites/kernel/fs/cases/fs_stat_test.c
b/testing/testsuites/kernel/fs/cases/fs_stat_test.c
index 6a4bfb00c..2afb114e0 100644
--- a/testing/testsuites/kernel/fs/cases/fs_stat_test.c
+++ b/testing/testsuites/kernel/fs/cases/fs_stat_test.c
@@ -88,18 +88,9 @@ void test_nuttx_fs_stat01(FAR void **state)
struct tm *tm_1 = NULL;
struct tm *tm_2 = NULL;
- int year1;
- int year2;
- int month1;
- int month2;
- int day1;
- int day2;
- int hour1;
- int hour2;
- int min1;
- int min2;
time_t t_1;
time_t t_2;
+ time_t t_diff;
struct fs_testsuites_state_s *test_state;
test_state = (struct fs_testsuites_state_s *)*state;
@@ -127,14 +118,6 @@ void test_nuttx_fs_stat01(FAR void **state)
tm_1 = gmtime(&t_1);
assert_non_null(tm_1);
- /* set time */
-
- year1 = tm_1->tm_year;
- month1 = tm_1->tm_mon;
- day1 = tm_1->tm_mday;
- hour1 = tm_1->tm_hour;
- min1 = tm_1->tm_min;
-
/* get file info */
ret = stat(TEST_FILE, &file_s);
@@ -144,23 +127,17 @@ void test_nuttx_fs_stat01(FAR void **state)
t_2 = file_s.st_mtime;
tm_2 = gmtime(&t_2);
-
assert_non_null(tm_2);
- /* set time */
+ /* compare time */
+
+ t_diff = t_2 - t_1;
+
+ /* tolerance for 30s for worst case */
- year2 = tm_2->tm_year;
- month2 = tm_2->tm_mon;
- day2 = tm_2->tm_mday;
- hour2 = tm_2->tm_hour;
- min2 = tm_2->tm_min;
+ assert_int_in_range(t_diff, -30, 30);
- /* compare time and size */
+ /* compare size */
- assert_int_equal(year1, year2);
- assert_int_equal(month1, month2);
- assert_int_equal(day1, day2);
- assert_int_equal(hour1, hour2);
- assert_int_equal(min1, min2);
assert_int_equal(file_s.st_size, BUF_SIZE);
}