diff options
Diffstat (limited to 'src/pal/tests/palsuite/miscellaneous/InterlockedBit')
7 files changed, 225 insertions, 0 deletions
diff --git a/src/pal/tests/palsuite/miscellaneous/InterlockedBit/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/InterlockedBit/CMakeLists.txt new file mode 100644 index 0000000000..ef14ea5352 --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/InterlockedBit/CMakeLists.txt @@ -0,0 +1,5 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +add_subdirectory(test1) +add_subdirectory(test2) + diff --git a/src/pal/tests/palsuite/miscellaneous/InterlockedBit/test1/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/InterlockedBit/test1/CMakeLists.txt new file mode 100644 index 0000000000..a70802ea2d --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/InterlockedBit/test1/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test.cpp +) + +add_executable(paltest_interlockedbit_test1 + ${SOURCES} +) + +add_dependencies(paltest_interlockedbit_test1 coreclrpal) + +target_link_libraries(paltest_interlockedbit_test1 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/miscellaneous/InterlockedBit/test1/test.cpp b/src/pal/tests/palsuite/miscellaneous/InterlockedBit/test1/test.cpp new file mode 100644 index 0000000000..1f7c43cddb --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/InterlockedBit/test1/test.cpp @@ -0,0 +1,77 @@ +// 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 : test.c +** +** Purpose: Test for InterlockedBitTestAndReset() function +** +** +**=========================================================*/ + +#include <palsuite.h> + +typedef struct tag_TEST_DATA +{ + LONG baseValue; + UINT bitPosition; + LONG expectedValue; + UCHAR expectedReturnValue; +} TEST_DATA; + +TEST_DATA test_data[] = +{ + { (LONG)0x00000000, 3, (LONG)0x00000000, 0 }, + { (LONG)0x12341234, 2, (LONG)0x12341230, 1 }, + { (LONG)0x12341234, 3, (LONG)0x12341234, 0 }, + { (LONG)0x12341234, 31, (LONG)0x12341234, 0 }, + { (LONG)0x12341234, 28, (LONG)0x02341234, 1 }, + { (LONG)0xffffffff, 28, (LONG)0xefffffff, 1 } +}; + +int __cdecl main(int argc, char *argv[]) { + + /* + * Initialize the PAL and return FAILURE if this fails + */ + + if(0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + for (int i = 0; i < sizeof (test_data) / sizeof (TEST_DATA); i++) + { + LONG baseVal = test_data[i].baseValue; + LONG bitPosition = test_data[i].bitPosition; + + UCHAR ret = InterlockedBitTestAndReset( + &baseVal, /* Variable to manipulate */ + bitPosition); + + if (ret != test_data[i].expectedReturnValue) + { + Fail("ERROR: InterlockedBitTestAndReset(%d): Expected return value is %d," + "Actual return value is %d.", + i, + test_data[i].expectedReturnValue, + ret); + } + + if (baseVal != test_data[i].expectedValue) + { + Fail("ERROR: InterlockedBitTestAndReset(%d): Expected value is %x," + "Actual value is %x.", + i, + test_data[i].expectedValue, + baseVal); + } + + } + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/miscellaneous/InterlockedBit/test1/testinfo.dat b/src/pal/tests/palsuite/miscellaneous/InterlockedBit/test1/testinfo.dat new file mode 100644 index 0000000000..677999906f --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/InterlockedBit/test1/testinfo.dat @@ -0,0 +1,14 @@ +# 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. + +Version = 1.0 +Section = Miscellaneous +Function = InterlockedBitTestAndReset +Name = Test for InterlockedBitTestAndReset +TYPE = DEFAULT +EXE1 = test +Description +Test validates that function InterlockedBitTestAndReset work as intended. + + diff --git a/src/pal/tests/palsuite/miscellaneous/InterlockedBit/test2/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/InterlockedBit/test2/CMakeLists.txt new file mode 100644 index 0000000000..6b50a755fe --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/InterlockedBit/test2/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test.cpp +) + +add_executable(paltest_interlockedbit_test2 + ${SOURCES} +) + +add_dependencies(paltest_interlockedbit_test2 coreclrpal) + +target_link_libraries(paltest_interlockedbit_test2 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/miscellaneous/InterlockedBit/test2/test.cpp b/src/pal/tests/palsuite/miscellaneous/InterlockedBit/test2/test.cpp new file mode 100644 index 0000000000..4230c8a805 --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/InterlockedBit/test2/test.cpp @@ -0,0 +1,77 @@ +// 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 : test.c +** +** Purpose: Test for InterlockedBitTestAndSet() function +** +** +**=========================================================*/ + +#include <palsuite.h> + +typedef struct tag_TEST_DATA +{ + LONG baseValue; + UINT bitPosition; + LONG expectedValue; + UCHAR expectedReturnValue; +} TEST_DATA; + +TEST_DATA test_data[] = +{ + { (LONG)0x00000000, 2, (LONG)0x00000004, 0 }, + { (LONG)0x12341234, 2, (LONG)0x12341234, 1 }, + { (LONG)0x12341234, 3, (LONG)0x1234123c, 0 }, + { (LONG)0x12341234, 31, (LONG)0x92341234, 0 }, + { (LONG)0x12341234, 28, (LONG)0x12341234, 1 }, + { (LONG)0xffffffff, 28, (LONG)0xffffffff, 1 } +}; + +int __cdecl main(int argc, char *argv[]) { + + /* + * Initialize the PAL and return FAILURE if this fails + */ + + if(0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + for (int i = 0; i < sizeof (test_data) / sizeof (TEST_DATA); i++) + { + LONG baseVal = test_data[i].baseValue; + LONG bitPosition = test_data[i].bitPosition; + + UCHAR ret = InterlockedBitTestAndSet( + &baseVal, /* Variable to manipulate */ + bitPosition); + + if (ret != test_data[i].expectedReturnValue) + { + Fail("ERROR: InterlockedBitTestAndSet(%d): Expected return value is %d," + "Actual return value is %d.", + i, + test_data[i].expectedReturnValue, + ret); + } + + if (baseVal != test_data[i].expectedValue) + { + Fail("ERROR: InterlockedBitTestAndSet(%d): Expected value is %x," + "Actual value is %x.", + i, + test_data[i].expectedValue, + baseVal); + } + + } + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/miscellaneous/InterlockedBit/test2/testinfo.dat b/src/pal/tests/palsuite/miscellaneous/InterlockedBit/test2/testinfo.dat new file mode 100644 index 0000000000..3ad431701a --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/InterlockedBit/test2/testinfo.dat @@ -0,0 +1,14 @@ +# 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. + +Version = 1.0 +Section = Miscellaneous +Function = InterlockedBitTestAndSet +Name = Test for InterlockedBitTestAndSet +TYPE = DEFAULT +EXE1 = test +Description +Test validates that function InterlockedBitTestAndSet work as intended. + + |