-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
libc: time.h: add test groups for gmtime, mktime, strftime #255
Conversation
8453adc
to
54db782
Compare
54db782
to
b2089c0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great that you've moved the obsolete tests to unity framework!
I've put some nitpicks found by reading the code (I didn't run it).
libc/time/gmtime.c
Outdated
@@ -16,7 +16,9 @@ | |||
#include <time.h> | |||
#include <stdio.h> | |||
#include <stdlib.h> | |||
#include "test_common.h" | |||
#include "../../test_common.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please don't include files from outside of libc
subdir - move necessary functions to the common part of libc tests (or to time
subfolder if you don't think they would be shared between libc tests submodules)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I made a new header file with common functions for time tests.
libc/time/gmtime.c
Outdated
{ | ||
return 0; | ||
} | ||
TEST_ASSERT_FALSE_MESSAGE(compare_tm(t, &t_exp), "Incorrect struct tm"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe it would be better to provide TEST_ASSERT_*
attributed compare_tm
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
{ | ||
struct tm *t, t_exp; | ||
char buff[120]; | ||
init_tm(&t_exp, output); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably we could directly keep struct tm
in output
tab, but you can keep it as is (as it's not directly related to your changes)
libc/time/host_generation.c
Outdated
#include <stdio.h> | ||
#include <stdlib.h> | ||
|
||
#include "../../test_common.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't include files from outside of libc
subdir
❗ Please note that this file introduces new compilation warnings
libc/time/mktime.c
Outdated
@@ -16,7 +16,9 @@ | |||
#include <time.h> | |||
#include <stdio.h> | |||
#include <stdlib.h> | |||
#include "test_common.h" | |||
#include "../../test_common.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't include files from outside of libc
subdir
libc/time/main.c
Outdated
UnityMain(argc, (const char **)argv, runner); | ||
return 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know this is ^C^V from other files but maybe:
UnityMain(argc, (const char **)argv, runner); | |
return 0; | |
int failures = UnityMain(argc, (const char **)argv, runner); | |
return (failures == 0) : 0 : 1; |
libc/time/mktime.c
Outdated
} | ||
timestamp = function_under_test(&t); | ||
TEST_ASSERT_EQUAL_INT_MESSAGE(timestamp_exp, timestamp, "Incorrect time_t"); | ||
TEST_ASSERT_FALSE_MESSAGE(compare_tm(&t, &t_exp), "Incorrect struct tm"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TEST_ASSERT_* attributed compare_tm ?
libc/time/strftime.c
Outdated
printf("STRFTIME TEST STARTED\n"); | ||
save_env(); | ||
#ifdef __phoenix__ | ||
TEST_IGNORE(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe use TEST_IGNORE_MESSAGE("reason, eg. issue ID")
why these tests are ignored?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added messages to tests that are ignored for now. The issue is phoenix-rtos/phoenix-rtos-project#351.
libc/time/strftime.c
Outdated
#endif | ||
#ifndef __phoenix__ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#endif | |
#ifndef __phoenix__ | |
#else |
Or don't put it in else (the code after TEST_IGNORE won't run anyway)
52b78d5
to
2281a4e
Compare
2281a4e
to
78017e5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adapting this piece of code to our environment. The improvements looks clean, small remarks left.
libc/time/gmtime.c
Outdated
RUN_TEST_CASE(time_gmtime, basic_test); | ||
} | ||
|
||
|
||
static const time_t input_vector[] = { | ||
/* 29 FEB 2016 - leap year */ | ||
61414866000, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know that it's not your code and those values are not so crucial, but it would be nice to correct them before enabling in CI (they may be misleading).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same for mktime tests.
libc/time/mktime.c
Outdated
} | ||
|
||
|
||
int mktime_assert(const int input[], const int output[], const time_t timestamp_exp) | ||
static void mktime_assert(const int input[], const int output[], const time_t timestamp_exp) | ||
{ | ||
struct tm t, t_old, t_exp; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
t_old
is not needed.
libc/time/host_generation.c
Outdated
.tm_hour = rand() % 23, | ||
.tm_mday = rand() % 30, | ||
.tm_mon = rand() % 11, | ||
.tm_year = 1980 + rand() % 60, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is an issue mentioned above.
.tm_year = 1980 + rand() % 60, | |
.tm_year = 80 + rand() % 60, |
libc/time/strftime.c
Outdated
|
||
static const struct test_data test_vector[T1_LEN] = { | ||
static const struct test_data basic_formatting[] = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that we could place the declarations at the beginning of the file
like it's done in the rest of time tests. So sth like:
static const struct test_data basic_formatting[] = { | |
static const struct test_data basic_formatting[T1_LEN]; | |
static const struct test_data additional_format_chars[T2_LEN]; | |
... | |
static const struct test_data basic_formatting[] = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then we could place test data below TEST_GROUP_RUNNER
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternatively you could switch to the convention applied in this test in mktime/strftime tests - we just want to be consistent.
78017e5
to
72220c4
Compare
libc/time/gmtime.c
Outdated
#include "time_common.h" | ||
|
||
|
||
#define NCOLS 9 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[clang-format-pr] reported by reviewdog 🐶
suggested fix
#define NCOLS 9 | |
#define NCOLS 9 |
72220c4
to
e71156f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for applying the suggestions, please rebase changes and we can merge it :)
e71156f
to
31f95c9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Moved tests for time functions (gmtime, mktime and strftime) that existed previously and added them to libc automatic testing.
Description
Tests for the mentioned time functions existed, but were never compiled or checked. The tests for gmtime and mktime functions pass. Some tests for strftime would fail (because not all formats are implemented, or because padding is not implemented), so I set them to be ignored for now.
Motivation and Context
Types of changes
How Has This Been Tested?
Checklist:
Special treatment