linux/lib/atomic64_test.c
<<
>>
Prefs
   1/*
   2 * Testsuite for atomic64_t functions
   3 *
   4 * Copyright © 2010  Luca Barbieri
   5 *
   6 * This program is free software; you can redistribute it and/or modify
   7 * it under the terms of the GNU General Public License as published by
   8 * the Free Software Foundation; either version 2 of the License, or
   9 * (at your option) any later version.
  10 */
  11#include <linux/init.h>
  12#include <linux/bug.h>
  13#include <linux/kernel.h>
  14#include <linux/atomic.h>
  15
  16#define INIT(c) do { atomic64_set(&v, c); r = c; } while (0)
  17static __init int test_atomic64(void)
  18{
  19        long long v0 = 0xaaa31337c001d00dLL;
  20        long long v1 = 0xdeadbeefdeafcafeLL;
  21        long long v2 = 0xfaceabadf00df001LL;
  22        long long onestwos = 0x1111111122222222LL;
  23        long long one = 1LL;
  24
  25        atomic64_t v = ATOMIC64_INIT(v0);
  26        long long r = v0;
  27        BUG_ON(v.counter != r);
  28
  29        atomic64_set(&v, v1);
  30        r = v1;
  31        BUG_ON(v.counter != r);
  32        BUG_ON(atomic64_read(&v) != r);
  33
  34        INIT(v0);
  35        atomic64_add(onestwos, &v);
  36        r += onestwos;
  37        BUG_ON(v.counter != r);
  38
  39        INIT(v0);
  40        atomic64_add(-one, &v);
  41        r += -one;
  42        BUG_ON(v.counter != r);
  43
  44        INIT(v0);
  45        r += onestwos;
  46        BUG_ON(atomic64_add_return(onestwos, &v) != r);
  47        BUG_ON(v.counter != r);
  48
  49        INIT(v0);
  50        r += -one;
  51        BUG_ON(atomic64_add_return(-one, &v) != r);
  52        BUG_ON(v.counter != r);
  53
  54        INIT(v0);
  55        atomic64_sub(onestwos, &v);
  56        r -= onestwos;
  57        BUG_ON(v.counter != r);
  58
  59        INIT(v0);
  60        atomic64_sub(-one, &v);
  61        r -= -one;
  62        BUG_ON(v.counter != r);
est. .1"
	  >
  v2.6.ON" class="sref">BUG_ON(v);
est. .1"
	  >
  v2.6.ON" clation value="v5 3" id="L6f="+code=v" class="sref="srl0v" class="sref">v.  62        ones6wos, &v);
  56        r -= onestwos;
  57<6a>      6 BUG_ON(v.counter !=   48ame="L60">  60        atomic647+code=v07 class="sref">v0);
7a hre7sref">INIT(v0);
  62r += -one;
  7sub(7one, &v);
  61        r -= -one;
  62<7a>      7 BUG_ON(v.counter != #define .<="L59">  59        INIT(est. 71"
	 7mic64_test.c#L35" id="L35" class="line" name="L35">  35        atomic647omic64_teest.c#L5" id="L5" class=wos, &v);
  56        r -= onestwos;
  57<7a>      7 BUG_ON(v.counter !=   48        atomic648+code=v08 class="sref">v0);
8a hre8sref">INIT(v0);
..<="L59">  59        r -= onestwos(8one, &v);
  61        r -= -one;
  62<8a>      8 BUG_ON(v.counter != #define .<="L59">  59        INIT(est. 81"
	 8mic64_test.c#L55" id="L55" class="line" name="L55">  55        atomic648omic64_t8est.c#L5" id="L5" class8wos, &v);
  56        r -= onestwos * This program is fre57" i8="L57" class="line" name="L57">  57<8a>      8 BUG_ON(v.counter !=   48ame55        atomic649+code=v09 class="sref">v0);
9a hre9sref">INIT(v0);
..<="L59">  59        r -= onestwos(9one, &v);
  61        r -= -one;
  62<9a>      9 BUG_ON(v.counter != v0);
.<="L59">  59        r);
counter != est. 91"
	 9mic64_test.c#L55" id="L55" class="line" name="L55"" name="L29">  29        a9omic64_t9est.c#L5" id="L5" class9wos, &v);
  56        r -= onestwos * This program is fr957" i9="L57" class="line" name="L57">  57<9ss="commeent"> * it under the terclass9"sref">BUG_ON(v.counter !=    8v0);
.<="L59">  59        cof="+code=r" class="sref">r);
counter != 
  29        a10one, &v);
  61        r -= -one  11#03micss="L62" class="line" name="L62">  62<10s="line" 0name="L12">  12#incl04micss"sref">BUG_ON(v.counter !=   13#include &l05micss_test.c#L53" id="L53" class=e=v0" class="sref">v0);
.<="L59">  59         = 0xaaa31337c001d00f="+code=r" class="sref">r);
counter != linu0x/kernel.h>

  v2.6.ON" clation value="v5 3" id="L6f="+code=v" class="sref="srl0v" cla64_test.c#L61" id="L61" class="line" name="L61">  61        r -= -onec) do {   62<10f">r 0= BUG_ON(v.counter != BUG_ON(v0);
  59        r a href="+code=counter" class="sref">couunter !=    8v0);
  61        r -= -one
oneone, &v.counter !=   11##incl113test.c#L53" id="L53" class=e=v0" class="sref">v0);
  59        r a href="+code=co"sref">r);
 !=   12#incllude 11"sref">BUG_ON(  48        atomic641ne" name=""L13">  13#include &llt;v0);
  61        r -= -onelinuux/kernel.h>
onec) do { r -= -CONFIG_ARCH_HAS_ref="lib/DEC_IF_POSITIVE/ato="+code=one" class="sref">oner  = BUG_ON(v.oneBUG_ON(v0);
.<="L59">  59        test1_atomic64(void)
  48ame55        atomic641line" nam1e="L19">  19        1long 12lass="sref">v, v1);
  30        r = v1  20        1long 1ong v1        long long v.<0href="+code=v1" class="sref">v1  22     1   lo12"sref">BUG_ON(v0);
.<="L59">  59        rv1 = 0x11111111122222122LL;
v1);
  30        r = v1linu.c#L25" id="L25" class="1line"12b/ato="+code=one" class="sref">oneAT1OMIC61_INIT(v.<      rv1r ef="lib/atomic64_test.c#1L27" 128sref">BUG_ON(v0);
.<="L59">  59        rrv1BUG_ON(v1);
  30        r = v1  28
v1(&  38
  38
  38
one;
one  11#ihref1e" name="L32">  32        BUG_1ONatomic64_read(&oner);
v0);
.<="L59">  59        onelinusref">v0);
  35        atomic641+code=one1stwos" class="sref">ones1twos<1a>, &v);
  36        r += onestwos;
  37<1/a>      1  BUG_ON(v.<0href="+code=v1" class="sref">v1r);
v0);
.<="L59">  59        onev0);
1v);
  36        r += onestwos(1-v1;
v.<      rv1      1  BUG_ON(v0);
.<="L59">  59        oner);
  43
atomic641   I1IT(v0);
  36        r += onestwos  62<1>);
 -= -CONFIG_X8b/ato="+code=one" class="sref">one      1  BUG_ON( -= -printk"lib/atomic64_test.cKERN_INFOhref="+code=cdeKERN_INFO  "lass="sr f">o pFreede_con%s plattarge%s CX8yrige%s SSE\n"ndation,="+code=one" class="sref">oner);
one     1   INITBUG_ON< * the Free ent"ng">"x86-64"ndation,="+code=one" class="sref">one(1       38
ic64_t="lib/atomic64_test.cCONFIG_X8#_CMPXCHG/a>, one;
INITBUG_ON< * the Free ent"ng">"i586+"ndation,="+code=one" class="sref">one      1  v1r);
BUG_ON< * the Free ent"ng">"i386+"ndation,="+code=one" class="sref">onev0);
oneones1twos<1a>, &BUG_ON("with"ndation :N< * the Free ent"ng">"without"ndation,="+code=one" class="sref">oneBUG_ON("with"ndation :N< * the Free ent"ng">"without"ndationonestwos" class="sref">onestwos      1  v1r);
"lass="sr f">o pFreed\n"ndationonestwos" class="sref">onestwosv0);
1one(1-v1;
INITonestwos      1  onestwosr);
linuxx/kernel.h>

  vline" name="L36">re>(&amcall"L38">  38
">re>(&amcall"lib/atomic64_test.c cla_kernel.h    onestwosones16wos<16>, &a
   s" clasfoot6
The original LXR 4LXR Softu&amy, &a, 2.6. experitwaral omic64_tbycstwos" clmailto:lx<@llx<@l
lx<.lRedpill L/bodypa>/htmlrn