Last active
September 17, 2017 09:14
-
-
Save traversaro/c2b6941ef2ddd10e9dd6c1800483696a to your computer and use it in GitHub Desktop.
Tests for various clock.h functions in WSL
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
#include <time.h> | |
#include <iostream> | |
void test_clockid(clockid_t clockid) | |
{ | |
struct timespec res; | |
struct timespec time; | |
struct timespec sleep; | |
struct timespec remainder; | |
sleep.tv_sec = 0; | |
sleep.tv_nsec = 100000000; | |
int retVal; | |
retVal = clock_getres(clockid, &res); | |
int errsv = errno; | |
std::cerr << "clock_getres return value: " << retVal << " with errno " << errsv << std::endl; | |
retVal = clock_gettime(clockid, &time); | |
std::cerr << "clock_gettime return value: " << retVal << std::endl; | |
retVal = clock_nanosleep(clockid, 0, &sleep, &remainder); | |
std::cerr << "clock_nanosleep return value: " << retVal << std::endl; | |
} | |
int main(int argc, char **argv) | |
{ | |
std::cerr << "Error macros values: " << std::endl; | |
std::cerr << "EINTR : " << EINTR << std::endl; | |
std::cerr << "EINVAL: " << EINVAL << std::endl; | |
std::cerr << "ENOTSUP: " << ENOTSUP << std::endl; | |
std::cerr << "Testing CLOCK_MONOTONIC " << std::endl; | |
test_clockid(CLOCK_MONOTONIC); | |
std::cerr << "Testing CLOCK_REALTIME " << std::endl; | |
test_clockid(CLOCK_REALTIME); | |
std::cerr << "Testing CLOCK_PROCESS_CPUTIME_ID " << std::endl; | |
test_clockid(CLOCK_PROCESS_CPUTIME_ID); | |
std::cerr << "Testing CLOCK_THREAD_CPUTIME_ID " << std::endl; | |
test_clockid(CLOCK_THREAD_CPUTIME_ID ); | |
return 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
cmake_minimum_required(VERSION 3.5) | |
project(clockid_wsl_test) | |
set(CMAKE_CXX_STANDARD 11) | |
add_executable(${PROJECT_NAME} ${PROJECT_NAME}.cpp) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment