From db20f3f1bb8595633a7e16c8900fd401a453a6b5 Mon Sep 17 00:00:00 2001 From: Jiyoung Yun Date: Tue, 27 Dec 2016 16:46:08 +0900 Subject: Imported Upstream version 1.0.0.9127 --- .../QueryThreadCycleTime/test1/CMakeLists.txt | 2 +- .../threading/QueryThreadCycleTime/test1/test1.c | 98 ---------------------- .../threading/QueryThreadCycleTime/test1/test1.cpp | 98 ++++++++++++++++++++++ 3 files changed, 99 insertions(+), 99 deletions(-) delete mode 100644 src/pal/tests/palsuite/threading/QueryThreadCycleTime/test1/test1.c create mode 100644 src/pal/tests/palsuite/threading/QueryThreadCycleTime/test1/test1.cpp (limited to 'src/pal/tests/palsuite/threading/QueryThreadCycleTime/test1') diff --git a/src/pal/tests/palsuite/threading/QueryThreadCycleTime/test1/CMakeLists.txt b/src/pal/tests/palsuite/threading/QueryThreadCycleTime/test1/CMakeLists.txt index ad3eec1a45..9a54ad15b6 100644 --- a/src/pal/tests/palsuite/threading/QueryThreadCycleTime/test1/CMakeLists.txt +++ b/src/pal/tests/palsuite/threading/QueryThreadCycleTime/test1/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(SOURCES - test1.c + test1.cpp ) add_executable(paltest_querythreadcycletime_test1 diff --git a/src/pal/tests/palsuite/threading/QueryThreadCycleTime/test1/test1.c b/src/pal/tests/palsuite/threading/QueryThreadCycleTime/test1/test1.c deleted file mode 100644 index 54f0116bd0..0000000000 --- a/src/pal/tests/palsuite/threading/QueryThreadCycleTime/test1/test1.c +++ /dev/null @@ -1,98 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -/*============================================================ -** -** Source: -** -** Source : test1.c -** -** Purpose: Test for QueryThreadCycleTime() function -** -** -**=========================================================*/ - -#include - -int __cdecl main(int argc, char *argv[]) { - int ret = FAIL; - - //Test is failing unreliably, so for now we always return pass. - if (TRUE){ - ret = PASS; - goto EXIT; - } - - LONG64 Actual, Expected, Delta = 850000000; - Actual = 0; - Expected = 0; - const LONG64 MSEC_TO_NSEC = 1000000; - - /* - * Initialize the PAL and return FAILURE if this fails - */ - - if(0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - HANDLE cThread = GetCurrentThread(); - - int i; - /* Take 2000 tiny measurements */ - for (i = 0; i < 2000; i++){ - ULONG64 FirstCount, SecondCount; - LONG64 Init; - - Sleep(1); - - /* Grab a FirstCount, then loop for a bit to make the clock increase */ - if (!QueryThreadCycleTime(cThread, (PULONG64)&FirstCount)) - { - Fail("ERROR: QueryThreadCycleTime returned failure.\n"); - } - - LONG64 x; - /* Init is in milliseconds, so we will convert later */ - Init = (LONG64)GetTickCount(); - x = Init + 3; - volatile int counter; - do { - for (counter = 0; counter < 100000; counter++) - { - // spin to consume CPU time - } - - } while (x > GetTickCount()); - Expected += (GetTickCount() - Init) * MSEC_TO_NSEC; - /* Get a second count */ - if (!QueryThreadCycleTime(cThread, (PULONG64)&SecondCount)) - { - Fail("ERROR: QueryThreadCycleTime returned failure.\n"); - } - - LONG64 trial = (LONG64)SecondCount - (LONG64)FirstCount; - if (trial < 0){ - printf("Negative value %llu measured", trial); - } - Actual += (trial); - - } - - - - if(labs(Expected - Actual) > Delta) - { - Fail("ERROR: The measured time (%llu millisecs) was not within Delta %llu " - "of the expected time (%llu millisecs).\n", - (Actual / MSEC_TO_NSEC), (Delta / MSEC_TO_NSEC), (Expected / MSEC_TO_NSEC)); - } - //printf("%llu, %llu\n", Expected, Actual); - PAL_Terminate(); - ret = PASS; - -EXIT: - return ret; -} diff --git a/src/pal/tests/palsuite/threading/QueryThreadCycleTime/test1/test1.cpp b/src/pal/tests/palsuite/threading/QueryThreadCycleTime/test1/test1.cpp new file mode 100644 index 0000000000..026243c81a --- /dev/null +++ b/src/pal/tests/palsuite/threading/QueryThreadCycleTime/test1/test1.cpp @@ -0,0 +1,98 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +/*============================================================ +** +** Source: +** +** Source : test1.c +** +** Purpose: Test for QueryThreadCycleTime() function +** +** +**=========================================================*/ + +#include + +int __cdecl main(int argc, char *argv[]) { + int ret = FAIL; + + //Test is failing unreliably, so for now we always return pass. + if (TRUE){ + ret = PASS; + goto EXIT; + } + { + LONG64 Actual, Expected, Delta = 850000000; + Actual = 0; + Expected = 0; + const LONG64 MSEC_TO_NSEC = 1000000; + + /* + * Initialize the PAL and return FAILURE if this fails + */ + + if(0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + HANDLE cThread = GetCurrentThread(); + + int i; + /* Take 2000 tiny measurements */ + for (i = 0; i < 2000; i++){ + ULONG64 FirstCount, SecondCount; + LONG64 Init; + + Sleep(1); + + /* Grab a FirstCount, then loop for a bit to make the clock increase */ + if (!QueryThreadCycleTime(cThread, (PULONG64)&FirstCount)) + { + Fail("ERROR: QueryThreadCycleTime returned failure.\n"); + } + + LONG64 x; + /* Init is in milliseconds, so we will convert later */ + Init = (LONG64)GetTickCount(); + x = Init + 3; + volatile int counter; + do { + for (counter = 0; counter < 100000; counter++) + { + // spin to consume CPU time + } + + } while (x > GetTickCount()); + Expected += (GetTickCount() - Init) * MSEC_TO_NSEC; + /* Get a second count */ + if (!QueryThreadCycleTime(cThread, (PULONG64)&SecondCount)) + { + Fail("ERROR: QueryThreadCycleTime returned failure.\n"); + } + + LONG64 trial = (LONG64)SecondCount - (LONG64)FirstCount; + if (trial < 0){ + printf("Negative value %llu measured", trial); + } + Actual += (trial); + + } + + + + if(labs(Expected - Actual) > Delta) + { + Fail("ERROR: The measured time (%llu millisecs) was not within Delta %llu " + "of the expected time (%llu millisecs).\n", + (Actual / MSEC_TO_NSEC), (Delta / MSEC_TO_NSEC), (Expected / MSEC_TO_NSEC)); + } + //printf("%llu, %llu\n", Expected, Actual); + PAL_Terminate(); + ret = PASS; + } +EXIT: + return ret; +} -- cgit v1.2.3