1 | // Licensed to the .NET Foundation under one or more agreements. |
2 | // The .NET Foundation licenses this file to you under the MIT license. |
3 | // See the LICENSE file in the project root for more information. |
4 | |
5 | /*============================================================ |
6 | ** |
7 | ** Source : test.c |
8 | ** |
9 | ** Purpose: Test for InterlockedBitTestAndSet() function |
10 | ** |
11 | ** |
12 | **=========================================================*/ |
13 | |
14 | #include <palsuite.h> |
15 | |
16 | typedef struct tag_TEST_DATA |
17 | { |
18 | LONG baseValue; |
19 | UINT bitPosition; |
20 | LONG expectedValue; |
21 | UCHAR expectedReturnValue; |
22 | } TEST_DATA; |
23 | |
24 | TEST_DATA test_data[] = |
25 | { |
26 | { (LONG)0x00000000, 2, (LONG)0x00000004, 0 }, |
27 | { (LONG)0x12341234, 2, (LONG)0x12341234, 1 }, |
28 | { (LONG)0x12341234, 3, (LONG)0x1234123c, 0 }, |
29 | { (LONG)0x12341234, 31, (LONG)0x92341234, 0 }, |
30 | { (LONG)0x12341234, 28, (LONG)0x12341234, 1 }, |
31 | { (LONG)0xffffffff, 28, (LONG)0xffffffff, 1 } |
32 | }; |
33 | |
34 | int __cdecl main(int argc, char *argv[]) { |
35 | |
36 | /* |
37 | * Initialize the PAL and return FAILURE if this fails |
38 | */ |
39 | |
40 | if(0 != (PAL_Initialize(argc, argv))) |
41 | { |
42 | return FAIL; |
43 | } |
44 | |
45 | for (int i = 0; i < sizeof (test_data) / sizeof (TEST_DATA); i++) |
46 | { |
47 | LONG baseVal = test_data[i].baseValue; |
48 | LONG bitPosition = test_data[i].bitPosition; |
49 | |
50 | UCHAR ret = InterlockedBitTestAndSet( |
51 | &baseVal, /* Variable to manipulate */ |
52 | bitPosition); |
53 | |
54 | if (ret != test_data[i].expectedReturnValue) |
55 | { |
56 | Fail("ERROR: InterlockedBitTestAndSet(%d): Expected return value is %d," |
57 | "Actual return value is %d." , |
58 | i, |
59 | test_data[i].expectedReturnValue, |
60 | ret); |
61 | } |
62 | |
63 | if (baseVal != test_data[i].expectedValue) |
64 | { |
65 | Fail("ERROR: InterlockedBitTestAndSet(%d): Expected value is %x," |
66 | "Actual value is %x." , |
67 | i, |
68 | test_data[i].expectedValue, |
69 | baseVal); |
70 | } |
71 | |
72 | } |
73 | |
74 | PAL_Terminate(); |
75 | return PASS; |
76 | } |
77 | |
78 | |