2026-02-17 17:55:30 +01:00
|
|
|
/* BEGIN_HEADER */
|
|
|
|
|
/* Test access to the Unix primitives used in platform_util.c and elsewhere.
|
|
|
|
|
* We aren't testing that they work, just getting an easy-to-understand
|
|
|
|
|
* diagnostic if they aren't available.
|
|
|
|
|
* (There is a separate test suite for the platform_util.h interfacces.)
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <mbedtls/platform_util.h>
|
|
|
|
|
#include <mbedtls/platform.h>
|
|
|
|
|
#include "common.h"
|
|
|
|
|
|
|
|
|
|
#if defined(MBEDTLS_PLATFORM_IS_UNIXLIKE)
|
|
|
|
|
|
|
|
|
|
#include <time.h>
|
|
|
|
|
#include <unistd.h>
|
2026-02-23 14:00:23 +01:00
|
|
|
#include <sys/time.h>
|
2026-02-17 17:55:30 +01:00
|
|
|
|
2026-02-21 21:17:47 +01:00
|
|
|
#else /* defined(MBEDTLS_PLATFORM_IS_UNIXLIKE) */
|
|
|
|
|
|
|
|
|
|
/* Constants used in the test data need to be defined even if no test
|
2026-02-22 20:40:10 +01:00
|
|
|
* functions that use them are enabled.
|
|
|
|
|
* Undefine the macros first in case a system header does define them
|
|
|
|
|
* even though we haven't recognized the platform as Unix-like. */
|
|
|
|
|
#undef CLOCK_REALTIME
|
2026-02-21 21:17:47 +01:00
|
|
|
#define CLOCK_REALTIME 0
|
2026-02-22 20:40:10 +01:00
|
|
|
#undef CLOCK_MONOTONIC
|
2026-02-21 21:17:47 +01:00
|
|
|
#define CLOCK_MONOTONIC 0
|
|
|
|
|
|
2026-02-17 17:55:30 +01:00
|
|
|
#endif /* defined(MBEDTLS_PLATFORM_IS_UNIXLIKE) */
|
|
|
|
|
|
|
|
|
|
/* END_HEADER */
|
|
|
|
|
|
|
|
|
|
/* Note: we can't make the whole test suite depend on
|
|
|
|
|
* MBEDTLS_PLATFORM_IS_UNIXLIKE, because file-level dependencies can only
|
|
|
|
|
* come from build_info.h, platform.h or some test helper headers, not
|
|
|
|
|
* from internal macros. */
|
|
|
|
|
/* BEGIN_DEPENDENCIES
|
|
|
|
|
* END_DEPENDENCIES */
|
|
|
|
|
|
|
|
|
|
/* BEGIN_CASE depends_on:MBEDTLS_PLATFORM_IS_UNIXLIKE */
|
|
|
|
|
void unistd_available()
|
|
|
|
|
{
|
|
|
|
|
pid_t pid = getpid();
|
|
|
|
|
TEST_LE_S(1, pid);
|
|
|
|
|
}
|
|
|
|
|
/* END_CASE */
|
|
|
|
|
|
|
|
|
|
/* BEGIN_CASE depends_on:MBEDTLS_PLATFORM_IS_UNIXLIKE */
|
|
|
|
|
void clock_gettime_available(int clockid)
|
|
|
|
|
{
|
|
|
|
|
struct timespec ts = { 0, 0 };
|
|
|
|
|
memset(&ts, 0, sizeof(ts));
|
|
|
|
|
int ret = clock_gettime(clockid, &ts);
|
|
|
|
|
TEST_ASSERT_ERRNO(ret == 0);
|
2026-03-02 19:22:24 +01:00
|
|
|
TEST_ASSERT(ts.tv_sec != 0 || ts.tv_nsec != 0);
|
2026-02-17 17:55:30 +01:00
|
|
|
}
|
|
|
|
|
/* END_CASE */
|
2026-02-23 14:00:23 +01:00
|
|
|
|
|
|
|
|
/* BEGIN_CASE depends_on:MBEDTLS_PLATFORM_IS_UNIXLIKE */
|
|
|
|
|
void gettimeofday_available()
|
|
|
|
|
{
|
|
|
|
|
struct timeval tv = { 0, 0 };
|
|
|
|
|
memset(&tv, 0, sizeof(tv));
|
|
|
|
|
int ret = gettimeofday(&tv, NULL);
|
|
|
|
|
TEST_ASSERT_ERRNO(ret == 0);
|
|
|
|
|
TEST_LE_S(1, tv.tv_sec);
|
|
|
|
|
}
|
|
|
|
|
/* END_CASE */
|