X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=tests%2Ftest-atomic.c;h=b1a5d9da4642f0b9f2ef1f8f8acf3969db380dfd;hb=c5cf10598f8c9f4428291e9df3ecd72a05fb1ccf;hp=21d8c9e117dbc0c11944ff2eb06a981cf29afdd5;hpb=05d299e0ccca80736cd4438c3224540c5448a7d4;p=sliver-openvswitch.git diff --git a/tests/test-atomic.c b/tests/test-atomic.c index 21d8c9e11..b1a5d9da4 100644 --- a/tests/test-atomic.c +++ b/tests/test-atomic.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013 Nicira, Inc. + * Copyright (c) 2013, 2014 Nicira, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,11 +18,12 @@ #include "ovs-atomic.h" #include "util.h" +#include "ovstest.h" #define TEST_ATOMIC_TYPE(ATOMIC_TYPE, BASE_TYPE) \ { \ ATOMIC_TYPE x = ATOMIC_VAR_INIT(1); \ - BASE_TYPE value; \ + BASE_TYPE value, orig; \ \ atomic_read(&x, &value); \ ovs_assert(value == 1); \ @@ -34,10 +35,46 @@ atomic_init(&x, 3); \ atomic_read(&x, &value); \ ovs_assert(value == 3); \ + \ + atomic_add(&x, 1, &orig); \ + ovs_assert(orig == 3); \ + atomic_read(&x, &value); \ + ovs_assert(value == 4); \ + \ + atomic_sub(&x, 2, &orig); \ + ovs_assert(orig == 4); \ + atomic_read(&x, &value); \ + ovs_assert(value == 2); \ + \ + atomic_or(&x, 6, &orig); \ + ovs_assert(orig == 2); \ + atomic_read(&x, &value); \ + ovs_assert(value == 6); \ + \ + atomic_and(&x, 10, &orig); \ + ovs_assert(orig == 6); \ + atomic_read(&x, &value); \ + ovs_assert(value == 2); \ + \ + atomic_xor(&x, 10, &orig); \ + ovs_assert(orig == 2); \ + atomic_read(&x, &value); \ + ovs_assert(value == 8); \ } -int -main(void) +static void +test_atomic_flag(void) +{ + atomic_flag flag = ATOMIC_FLAG_INIT; + ovs_assert(atomic_flag_test_and_set(&flag) == false); + ovs_assert(atomic_flag_test_and_set(&flag) == true); + atomic_flag_clear(&flag); + ovs_assert(atomic_flag_test_and_set(&flag) == false); +} + + +static void +test_atomic_main(int argc OVS_UNUSED, char *argv[] OVS_UNUSED) { TEST_ATOMIC_TYPE(atomic_char, char); TEST_ATOMIC_TYPE(atomic_uchar, unsigned char); @@ -65,5 +102,7 @@ main(void) TEST_ATOMIC_TYPE(atomic_uint64_t, uint64_t); TEST_ATOMIC_TYPE(atomic_int64_t, int64_t); - return 0; + test_atomic_flag(); } + +OVSTEST_REGISTER("test-atomic", test_atomic_main);