diff options
author | Sam Sortais | 2016-07-28 16:09:27 -0500 |
---|---|---|
committer | Wendy Liang | 2016-08-13 01:36:45 -0500 |
commit | 3c9a262ae4191f79c93634503ea30cd4c652a13d (patch) | |
tree | 8d85cd14671c3f21bda06f5c15f1dc1430b73de8 | |
parent | b133fae4a8edb40ff4a93b6d8c7d7185581f208f (diff) | |
download | libmetal-3c9a262ae4191f79c93634503ea30cd4c652a13d.tar.gz libmetal-3c9a262ae4191f79c93634503ea30cd4c652a13d.tar.xz libmetal-3c9a262ae4191f79c93634503ea30cd4c652a13d.zip |
generic: atomic ut
Signed-off-by: Sam Sortais <sam.sortais@xilinx.com>
-rw-r--r-- | test/system/generic/CMakeLists.txt | 1 | ||||
-rw-r--r-- | test/system/generic/atomic.c | 58 |
2 files changed, 59 insertions, 0 deletions
diff --git a/test/system/generic/CMakeLists.txt b/test/system/generic/CMakeLists.txt index b723e98..9a94736 100644 --- a/test/system/generic/CMakeLists.txt +++ b/test/system/generic/CMakeLists.txt | |||
@@ -2,6 +2,7 @@ collect (PROJECT_LIB_TESTS main.c) | |||
2 | collect (PROJECT_LIB_TESTS alloc.c) | 2 | collect (PROJECT_LIB_TESTS alloc.c) |
3 | collect (PROJECT_LIB_TESTS irq.c) | 3 | collect (PROJECT_LIB_TESTS irq.c) |
4 | collect (PROJECT_LIB_TESTS mutex.c) | 4 | collect (PROJECT_LIB_TESTS mutex.c) |
5 | collect (PROJECT_LIB_TESTS atomic.c) | ||
5 | 6 | ||
6 | if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_MACHINE}) | 7 | if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_MACHINE}) |
7 | add_subdirectory(${PROJECT_MACHINE}) | 8 | add_subdirectory(${PROJECT_MACHINE}) |
diff --git a/test/system/generic/atomic.c b/test/system/generic/atomic.c new file mode 100644 index 0000000..019a308 --- /dev/null +++ b/test/system/generic/atomic.c | |||
@@ -0,0 +1,58 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2016, Xilinx Inc. and Contributors. All rights reserved. | ||
3 | * | ||
4 | * Redistribution and use in source and binary forms, with or without | ||
5 | * modification, are permitted provided that the following conditions are met: | ||
6 | * | ||
7 | * 1. Redistributions of source code must retain the above copyright notice, | ||
8 | * this list of conditions and the following disclaimer. | ||
9 | * | ||
10 | * 2. Redistributions in binary form must reproduce the above copyright notice, | ||
11 | * this list of conditions and the following disclaimer in the documentation | ||
12 | * and/or other materials provided with the distribution. | ||
13 | * | ||
14 | * 3. Neither the name of Xilinx nor the names of its contributors may be used | ||
15 | * to endorse or promote products derived from this software without | ||
16 | * specific prior written permission. | ||
17 | * | ||
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | ||
22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
28 | * POSSIBILITY OF SUCH DAMAGE. | ||
29 | */ | ||
30 | |||
31 | #include <stdlib.h> | ||
32 | |||
33 | #include <metal-test.h> | ||
34 | #include <metal/atomic.h> | ||
35 | #include <metal/log.h> | ||
36 | #include <metal/sys.h> | ||
37 | |||
38 | static const int atomic_test_count = 1000; | ||
39 | |||
40 | static int atomic(void) | ||
41 | { | ||
42 | atomic_int counter = ATOMIC_VAR_INIT(0); | ||
43 | int value, error=0, i; | ||
44 | |||
45 | for (i = 0; i < atomic_test_count; i++) { | ||
46 | atomic_fetch_add(&counter, 1); | ||
47 | } | ||
48 | |||
49 | value = atomic_load(&counter); | ||
50 | value -= atomic_test_count; | ||
51 | if (value) { | ||
52 | metal_log(LOG_DEBUG, "counter mismatch, delta = %d\n", value); | ||
53 | error = -1; | ||
54 | } | ||
55 | |||
56 | return error; | ||
57 | } | ||
58 | METAL_ADD_TEST(atomic); | ||