-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from Elektrobit/next
Next
- Loading branch information
Showing
15 changed files
with
434 additions
and
6 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
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
# SPDX-License-Identifier: MIT | ||
|
||
add_subdirectory(safuTimeGetLocalTime) | ||
add_subdirectory(safuTimeSpecCompare) | ||
add_subdirectory(safuTimeSpecInTimeRange) |
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,14 @@ | ||
# SPDX-License-Identifier: MIT | ||
find_package(cmocka_extensions 0.53.1 REQUIRED) | ||
|
||
create_unit_test( | ||
NAME | ||
test_common_safuTimeSpecCompare_utest | ||
SOURCES | ||
case_selected.c | ||
case_exhaustive.c | ||
case_real_timestamps.c | ||
safuTimeSpecCompare_utest.c | ||
LIBRARIES | ||
safu_weak | ||
) |
51 changes: 51 additions & 0 deletions
51
test/utest/safu/time/safuTimeSpecCompare/case_exhaustive.c
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,51 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
#include <limits.h> | ||
#include <safu/result.h> | ||
#include <safu/time.h> | ||
|
||
#include "safuTimeSpecCompare_utest.h" | ||
|
||
int safuTestSafuTimeSpecCompareExhaustiveSetup(UNUSED void **state) { | ||
return 0; | ||
} | ||
|
||
int safuTestSafuTimeSpecCompareExhaustiveTeardown(UNUSED void **state) { | ||
return 0; | ||
} | ||
|
||
static void _checkComparision(struct timespec a, struct timespec b) { | ||
int result = safuTimeSpecCompare(a, b); | ||
int value; | ||
if (a.tv_sec > b.tv_sec) { | ||
value = 1; | ||
} else if (a.tv_sec < b.tv_sec) { | ||
value = -1; | ||
} else if (a.tv_nsec > b.tv_nsec) { | ||
value = 1; | ||
} else if (a.tv_nsec < b.tv_nsec) { | ||
value = -1; | ||
} else { | ||
value = 0; | ||
} | ||
assert_int_equal(result, value); | ||
} | ||
void safuTestSafuTimeSpecCompareExhaustive(UNUSED void **state) { | ||
TEST("safuTimeSpecCompareExhaustive"); | ||
SHOULD("%s", "successfully compare two timespec structs with a lot of combinations of values"); | ||
|
||
time_t secsList[] = {0, 1, 12, 457789, 999999999, INT_MAX}; | ||
long nsecsList[] = {0, 1, 42, 999999999}; | ||
|
||
for (size_t as = 0; as < ARRAY_SIZE(secsList); as++) { | ||
for (size_t an = 0; an < ARRAY_SIZE(nsecsList); an++) { | ||
struct timespec a = {.tv_sec = secsList[as], .tv_nsec = nsecsList[an]}; | ||
for (size_t bs = 0; bs < ARRAY_SIZE(secsList); bs++) { | ||
for (size_t bn = 0; bn < ARRAY_SIZE(nsecsList); bn++) { | ||
struct timespec b = {.tv_sec = secsList[bs], .tv_nsec = nsecsList[bn]}; | ||
_checkComparision(a, b); | ||
} | ||
} | ||
} | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
test/utest/safu/time/safuTimeSpecCompare/case_real_timestamps.c
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,42 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
#include <limits.h> | ||
#include <safu/result.h> | ||
#include <safu/time.h> | ||
|
||
#include "safuTimeSpecCompare_utest.h" | ||
|
||
int safuTestSafuTimeSpecCompareRealTimestampsSetup(UNUSED void **state) { | ||
return 0; | ||
} | ||
|
||
int safuTestSafuTimeSpecCompareRealTimestampsTeardown(UNUSED void **state) { | ||
return 0; | ||
} | ||
|
||
void safuTestSafuTimeSpecCompareRealTimestamps(void **state) { | ||
TEST("safuTimeSpecCompareRealTimestamp"); | ||
SHOULD( | ||
"%s", | ||
"successfully compare two timespec structs gotten from the system clock to make sure it's a real time stamp"); | ||
|
||
int result; | ||
struct timespec *olderTimestamp = *state; | ||
struct timespec newerTimestamp = {0}; | ||
if (clock_gettime(CLOCK_REALTIME, &newerTimestamp) != 0) { | ||
print_error("failed to get newer time stamp for tests"); | ||
fail(); | ||
} | ||
|
||
result = safuTimeSpecCompare(newerTimestamp, *olderTimestamp); | ||
assert_int_equal(result, 1); | ||
|
||
result = safuTimeSpecCompare(newerTimestamp, newerTimestamp); | ||
assert_int_equal(result, 0); | ||
|
||
result = safuTimeSpecCompare(*olderTimestamp, newerTimestamp); | ||
assert_int_equal(result, -1); | ||
|
||
result = safuTimeSpecCompare(*olderTimestamp, *olderTimestamp); | ||
assert_int_equal(result, 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,56 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
#include <limits.h> | ||
#include <safu/result.h> | ||
#include <safu/time.h> | ||
|
||
#include "safuTimeSpecCompare_utest.h" | ||
|
||
int safuTestSafuTimeSpecCompareSelectedSetup(UNUSED void **state) { | ||
return 0; | ||
} | ||
|
||
int safuTestSafuTimeSpecCompareSelectedTeardown(UNUSED void **state) { | ||
return 0; | ||
} | ||
|
||
void safuTestSafuTimeSpecCompareSelected(UNUSED void **state) { | ||
TEST("safuTimeSpecCompareSelected"); | ||
SHOULD("%s", "successfully compare two timespec structs with a selected number of specific comparisons"); | ||
|
||
struct timespec timeA; | ||
struct timespec timeB; | ||
int result; | ||
|
||
// x > y | ||
timeA.tv_sec = 6; | ||
timeB.tv_sec = 4; | ||
result = safuTimeSpecCompare(timeA, timeB); | ||
assert_int_equal(result, 1); | ||
|
||
// x < y | ||
timeA.tv_sec = 6; | ||
timeB.tv_sec = 8; | ||
result = safuTimeSpecCompare(timeA, timeB); | ||
assert_int_equal(result, -1); | ||
|
||
// x > y | ||
timeB.tv_sec = timeA.tv_sec; | ||
timeA.tv_nsec = 23; | ||
timeB.tv_nsec = 12; | ||
result = safuTimeSpecCompare(timeA, timeB); | ||
assert_int_equal(result, 1); | ||
|
||
// x < y | ||
timeB.tv_sec = timeA.tv_sec; | ||
timeA.tv_nsec = 23; | ||
timeB.tv_nsec = 42; | ||
result = safuTimeSpecCompare(timeA, timeB); | ||
assert_int_equal(result, -1); | ||
|
||
// x == y | ||
timeB.tv_sec = timeA.tv_sec; | ||
timeA.tv_nsec = timeB.tv_nsec; | ||
result = safuTimeSpecCompare(timeA, timeB); | ||
assert_int_equal(result, 0); | ||
} |
32 changes: 32 additions & 0 deletions
32
test/utest/safu/time/safuTimeSpecCompare/safuTimeSpecCompare_utest.c
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,32 @@ | ||
// SPDX-License-Identifier: MIT | ||
#include "safuTimeSpecCompare_utest.h" | ||
|
||
#include <bits/time.h> | ||
#include <time.h> | ||
|
||
TEST_SUITE_FUNC_PROTOTYPES(_testSuiteSafuTimeSpecCompare) | ||
|
||
int main() { | ||
const struct CMUnitTest tests[] = { | ||
TEST_CASE(safuTestSafuTimeSpecCompareSelected), | ||
TEST_CASE(safuTestSafuTimeSpecCompareExhaustive), | ||
TEST_CASE(safuTestSafuTimeSpecCompareRealTimestamps), | ||
}; | ||
|
||
return RUN_TEST_SUITE(tests, _testSuiteSafuTimeSpecCompare); | ||
} | ||
|
||
static int _testSuiteSafuTimeSpecCompareSetup(void **state) { | ||
struct timespec *olderTimestamp = calloc(1, sizeof(struct timespec)); | ||
if (olderTimestamp != NULL && clock_gettime(CLOCK_REALTIME, olderTimestamp) != 0) { | ||
print_error("failed to get older time stamp for tests"); | ||
fail(); | ||
} | ||
*state = olderTimestamp; | ||
return 0; | ||
} | ||
static int _testSuiteSafuTimeSpecCompareTeardown(void **state) { | ||
free(*state); | ||
*state = NULL; | ||
return 0; | ||
} |
11 changes: 11 additions & 0 deletions
11
test/utest/safu/time/safuTimeSpecCompare/safuTimeSpecCompare_utest.h
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,11 @@ | ||
// SPDX-License-Identifier: MIT | ||
#ifndef __SAFU_TIME_SPEC_COMPARE_UTEST_H__ | ||
#define __SAFU_TIME_SPEC_COMPARE_UTEST_H__ | ||
|
||
#include <cmocka_extensions/cmocka_extensions.h> | ||
|
||
TEST_CASE_FUNC_PROTOTYPES(safuTestSafuTimeSpecCompareSelected) | ||
TEST_CASE_FUNC_PROTOTYPES(safuTestSafuTimeSpecCompareExhaustive) | ||
TEST_CASE_FUNC_PROTOTYPES(safuTestSafuTimeSpecCompareRealTimestamps) | ||
|
||
#endif /* __SAFU_TIME_SPEC_COMPARE_UTEST_H__*/ |
12 changes: 12 additions & 0 deletions
12
test/utest/safu/time/safuTimeSpecInTimeRange/CMakeLists.txt
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,12 @@ | ||
# SPDX-License-Identifier: MIT | ||
find_package(cmocka_extensions 0.53.1 REQUIRED) | ||
|
||
create_unit_test( | ||
NAME | ||
test_common_safuTimeSpecInTimeRange_utest | ||
SOURCES | ||
case_real_timestamps.c | ||
safuTimeSpecInTimeRange_utest.c | ||
LIBRARIES | ||
safu_weak | ||
) |
Oops, something went wrong.