-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
libc: time.h: add test groups for gmtime, mktime, strftime
JIRA: RTOS-609
- Loading branch information
1 parent
21e66a3
commit 31f95c9
Showing
11 changed files
with
1,543 additions
and
1,374 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,174 @@ | ||
/* | ||
* Phoenix-RTOS | ||
* | ||
* test-libc-time | ||
* | ||
* Tests of gmtime function | ||
* | ||
* Copyright 2020 Phoenix Systems | ||
* Author: Marcin Brzykcy | ||
* | ||
* This file is part of Phoenix-RTOS. | ||
* | ||
* %LICENSE% | ||
*/ | ||
|
||
#include <time.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include "time_common.h" | ||
|
||
|
||
#define NCOLS 9 | ||
#define T1_LEN 50 | ||
|
||
static const time_t input_vector[T1_LEN]; | ||
static const int output_vector[T1_LEN][NCOLS]; | ||
|
||
|
||
TEST_GROUP(time_gmtime); | ||
|
||
|
||
TEST_SETUP(time_gmtime) | ||
{ | ||
tzset(); | ||
} | ||
|
||
|
||
TEST_TEAR_DOWN(time_gmtime) | ||
{ | ||
} | ||
|
||
|
||
static void gmtime_assert(const time_t input, const int output[]) | ||
{ | ||
struct tm *t, t_exp; | ||
init_tm(&t_exp, output); | ||
t = gmtime(&input); | ||
struct_tm_assert_equal(&t_exp, t); | ||
} | ||
|
||
|
||
TEST(time_gmtime, basic_test) | ||
{ | ||
for (int i = 0; i < T1_LEN; i++) { | ||
gmtime_assert(input_vector[i], output_vector[i]); | ||
} | ||
} | ||
|
||
|
||
TEST_GROUP_RUNNER(time_gmtime) | ||
{ | ||
RUN_TEST_CASE(time_gmtime, basic_test); | ||
} | ||
|
||
|
||
static const time_t input_vector[] = { | ||
/* 29 FEB 2016 - leap year */ | ||
1456722000, | ||
/* 1 MAR 2016 - leap year */ | ||
1456808400, | ||
/* 1 MAR 2017 - non-leap year */ | ||
1459486800, | ||
/* rest are just various dates */ | ||
1949946106, | ||
1583335484, | ||
475997893, | ||
867123590, | ||
1251255605, | ||
720953890, | ||
1276042708, | ||
727082762, | ||
2048114944, | ||
373707405, | ||
1218907253, | ||
1227599291, | ||
2130320479, | ||
751507207, | ||
1005296574, | ||
1240586883, | ||
980804756, | ||
1569318921, | ||
1357861195, | ||
1026213045, | ||
2043135630, | ||
891386491, | ||
1515284358, | ||
1800111608, | ||
2043766453, | ||
1097080338, | ||
2016495093, | ||
1588779339, | ||
770589226, | ||
1327288866, | ||
1649018558, | ||
931375833, | ||
438811605, | ||
1587475354, | ||
1090887759, | ||
833830546, | ||
899508971, | ||
829967700, | ||
705001964, | ||
1156799347, | ||
1653295606, | ||
1160551878, | ||
1782345742, | ||
1507507360, | ||
1340302000, | ||
1369622567, | ||
1580157611 | ||
}; | ||
|
||
static const int output_vector[][NCOLS] = { | ||
{ 0, 0, 5, 29, 1, 116, 1, 59, 0 }, | ||
{ 0, 0, 5, 1, 2, 116, 2, 60, 0 }, | ||
{ 0, 0, 5, 1, 3, 116, 5, 91, 0 }, | ||
{ 46, 41, 19, 16, 9, 131, 4, 288, 0 }, | ||
{ 44, 24, 15, 4, 2, 120, 3, 63, 0 }, | ||
{ 13, 38, 5, 31, 0, 85, 4, 30, 0 }, | ||
{ 50, 39, 3, 24, 5, 97, 2, 174, 0 }, | ||
{ 5, 0, 3, 26, 7, 109, 3, 237, 0 }, | ||
{ 10, 58, 8, 5, 10, 92, 4, 309, 0 }, | ||
{ 28, 18, 0, 9, 5, 110, 3, 159, 0 }, | ||
{ 2, 26, 7, 15, 0, 93, 5, 14, 0 }, | ||
{ 4, 49, 0, 26, 10, 134, 0, 329, 0 }, | ||
{ 45, 36, 7, 4, 10, 81, 3, 307, 0 }, | ||
{ 53, 20, 17, 16, 7, 108, 6, 228, 0 }, | ||
{ 11, 48, 7, 25, 10, 108, 2, 329, 0 }, | ||
{ 19, 41, 11, 4, 6, 137, 6, 184, 0 }, | ||
{ 7, 0, 0, 25, 9, 93, 1, 297, 0 }, | ||
{ 54, 2, 9, 9, 10, 101, 5, 312, 0 }, | ||
{ 3, 28, 15, 24, 3, 109, 5, 113, 0 }, | ||
{ 56, 45, 21, 29, 0, 101, 1, 28, 0 }, | ||
{ 21, 55, 9, 24, 8, 119, 2, 266, 0 }, | ||
{ 55, 39, 23, 10, 0, 113, 4, 9, 0 }, | ||
{ 45, 10, 11, 9, 6, 102, 2, 189, 0 }, | ||
{ 30, 40, 9, 29, 8, 134, 5, 271, 0 }, | ||
{ 31, 21, 23, 31, 2, 98, 2, 89, 0 }, | ||
{ 18, 19, 0, 7, 0, 118, 0, 6, 0 }, | ||
{ 8, 0, 15, 16, 0, 127, 6, 15, 0 }, | ||
{ 13, 54, 16, 6, 9, 134, 5, 278, 0 }, | ||
{ 18, 32, 16, 6, 9, 104, 3, 279, 0 }, | ||
{ 33, 31, 1, 25, 10, 133, 5, 328, 0 }, | ||
{ 39, 35, 15, 6, 4, 120, 3, 126, 0 }, | ||
{ 46, 33, 20, 2, 5, 94, 4, 152, 0 }, | ||
{ 6, 21, 3, 23, 0, 112, 1, 22, 0 }, | ||
{ 38, 42, 20, 3, 3, 122, 0, 92, 0 }, | ||
{ 33, 30, 19, 7, 6, 99, 3, 187, 0 }, | ||
{ 45, 6, 20, 27, 10, 83, 0, 330, 0 }, | ||
{ 34, 22, 13, 21, 3, 120, 2, 111, 0 }, | ||
{ 39, 22, 0, 27, 6, 104, 2, 208, 0 }, | ||
{ 46, 35, 19, 3, 5, 96, 1, 154, 0 }, | ||
{ 11, 36, 23, 3, 6, 98, 5, 183, 0 }, | ||
{ 0, 35, 2, 20, 3, 96, 6, 110, 0 }, | ||
{ 44, 52, 17, 4, 4, 92, 1, 124, 0 }, | ||
{ 7, 9, 21, 28, 7, 106, 1, 239, 0 }, | ||
{ 46, 46, 8, 23, 4, 122, 1, 142, 0 }, | ||
{ 18, 31, 7, 11, 9, 106, 3, 283, 0 }, | ||
{ 22, 2, 0, 25, 5, 126, 4, 175, 0 }, | ||
{ 40, 2, 0, 9, 9, 117, 1, 281, 0 }, | ||
{ 40, 6, 18, 21, 5, 112, 4, 172, 0 }, | ||
{ 47, 42, 2, 27, 4, 113, 1, 146, 0 }, | ||
{ 11, 40, 20, 27, 0, 120, 1, 26, 0 } | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
/* | ||
* Phoenix-RTOS | ||
* | ||
* test-libc-time | ||
* | ||
* Code for generating test cases. | ||
* | ||
* Copyright 2020 Phoenix Systems | ||
* Author: Marcin Brzykcy | ||
* | ||
* This file is part of Phoenix-RTOS. | ||
* | ||
* %LICENSE% | ||
*/ | ||
|
||
#include <time.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
|
||
#include "time_common.h" | ||
|
||
|
||
#define NCOLS 9 | ||
|
||
|
||
/* help function for future test generation if needed - not used in test functions */ | ||
void generate_input_mktime(int input_length) | ||
{ | ||
int i; | ||
srand(time(NULL)); | ||
for (i = 0; i < input_length; i++) { | ||
printf("{ %d, %d, %d, %d, %d, %d, %d, %d, %d }", rand() % 59, rand() % 59, rand() % 23, | ||
rand() % 30, rand() % 11, 80 + rand() % 60, 0, 0, 0); | ||
if (i != input_length - 1) | ||
printf(",\n"); | ||
} | ||
printf("\n"); | ||
} | ||
|
||
|
||
/* help function for future test generation if needed - not used in test functions */ | ||
void generate_output_mktime(const int input_vector[][NCOLS], int input_length) | ||
{ | ||
int i; | ||
struct tm t; | ||
time_t timestamp; | ||
printf("Printing host output data. Struct tm member values:\n"); | ||
for (i = 0; i < input_length; i++) { | ||
init_tm(&t, input_vector[i]); | ||
timestamp = mktime(&t); | ||
printf("{ %d, %d, %d, %d, %d, %d, %d, %d, %d }", | ||
t.tm_sec, t.tm_min, t.tm_hour, t.tm_mday, t.tm_mon, t.tm_year, | ||
t.tm_wday, t.tm_yday, t.tm_isdst); | ||
if (i != input_length - 1) | ||
printf(",\n"); | ||
} | ||
printf("\nTimestamp values:\n{"); | ||
for (i = 0; i < input_length; i++) { | ||
init_tm(&t, input_vector[i]); | ||
timestamp = mktime(&t); | ||
printf("%lld", (long long int)timestamp); | ||
if (i != input_length - 1) | ||
printf(", "); | ||
} | ||
printf("}\n"); | ||
} | ||
|
||
|
||
/* help function for future test generation if needed - not used in test functions */ | ||
void generate_input_host_gmtime(int input_length) | ||
{ | ||
int i; | ||
struct tm t; | ||
srand(time(NULL)); | ||
for (i = 0; i < input_length; i++) { | ||
t = (struct tm) { | ||
.tm_sec = rand() % 59, | ||
.tm_min = rand() % 59, | ||
.tm_hour = rand() % 23, | ||
.tm_mday = rand() % 30, | ||
.tm_mon = rand() % 11, | ||
.tm_year = 80 + rand() % 60, | ||
.tm_wday = 0, | ||
.tm_yday = 0, | ||
.tm_isdst = 0, | ||
}; | ||
printf("%lld", (long long int)mktime(&t)); | ||
if (i != input_length - 1) | ||
printf(",\n"); | ||
} | ||
printf("\n"); | ||
} | ||
|
||
|
||
/* help function for future test generation if needed - not used in test functions */ | ||
void generate_output_host_gmtime(const time_t input_vector[], int input_length) | ||
{ | ||
int i; | ||
struct tm *t; | ||
printf("Printing host output data. Struct tm member values:\n"); | ||
for (i = 0; i < input_length; i++) { | ||
t = gmtime(&input_vector[i]); | ||
printf("{ %d, %d, %d, %d, %d, %d, %d, %d, %d }", | ||
t->tm_sec, t->tm_min, t->tm_hour, t->tm_mday, t->tm_mon, t->tm_year, | ||
t->tm_wday, t->tm_yday, t->tm_isdst); | ||
if (i != input_length - 1) | ||
printf(",\n"); | ||
} | ||
printf("\n"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Phoenix-RTOS | ||
* | ||
* test-libc-time | ||
* | ||
* Main entry point. | ||
* | ||
* Copyright 2023 Phoenix Systems | ||
* Author: Jacek Maksymowicz | ||
* | ||
* This file is part of Phoenix-RTOS. | ||
* | ||
* %LICENSE% | ||
*/ | ||
|
||
#include "unity_fixture.h" | ||
|
||
void runner(void) | ||
{ | ||
RUN_TEST_GROUP(time_mktime); | ||
RUN_TEST_GROUP(time_gmtime); | ||
RUN_TEST_GROUP(time_strftime); | ||
} | ||
|
||
|
||
int main(int argc, char *argv[]) | ||
{ | ||
int failures = UnityMain(argc, (const char **)argv, runner); | ||
return (failures == 0) ? 0 : 1; | ||
} |
Oops, something went wrong.