forked from phoenix-rtos/phoenix-rtos-tests
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_common.h
73 lines (58 loc) · 1.49 KB
/
test_common.h
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
/*
* Phoenix-RTOS
*
* libphoenix
*
* test/test_strftime.c
*
* Copyright 2020 Phoenix Systems
* Author: Marcin Brzykcy
*
* This file is part of Phoenix-RTOS.
*
* %LICENSE%
*/
#ifndef TEST_COMMON_H
#define TEST_COMMON_H
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
static int test_verbosity;
static inline void tm_to_str(struct tm *t, char *buff)
{
sprintf(buff, "tm_sec %d, tm_min %d, tm_hour %d, tm_mday %d\n"
"tm_mon %d tm_year %d tm_wday %d tm_yday %d tm_isdst %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);
}
static inline void init_tm(struct tm *t, const int *input)
{
t->tm_sec = input[0];
t->tm_min = input[1];
t->tm_hour = input[2];
t->tm_mday = input[3];
t->tm_mon = input[4];
t->tm_year = input[5];
t->tm_wday = input[6];
t->tm_yday = input[7];
t->tm_isdst = input[8];
}
static inline int compare_tm(struct tm *t1, struct tm *t2)
{
return ((t1->tm_sec != t2->tm_sec) || (t1->tm_min != t2->tm_min) || (t1->tm_hour != t2->tm_hour) ||
(t1->tm_mday != t2->tm_mday) || (t1->tm_mon != t2->tm_mon) || (t1->tm_year != t2->tm_year) ||
(t1->tm_wday != t2->tm_wday) || (t1->tm_yday != t2->tm_yday) || (t1->tm_isdst != t2->tm_isdst));
}
static inline void save_env(void)
{
char *c = getenv("VERBOSE_TEST");
if (c != NULL && c[0] >= '0' && c[0] <= '9')
test_verbosity = (c[0] - '0');
else
test_verbosity = 0;
}
static inline int verbose_test(void)
{
return test_verbosity;
}
#endif