Home | History | Annotate | Download | only in test
      1 // Copyright 2016, VIXL authors
      2 // 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 //   * Redistributions of source code must retain the above copyright notice,
      8 //     this list of conditions and the following disclaimer.
      9 //   * Redistributions in binary form must reproduce the above copyright notice,
     10 //     this list of conditions and the following disclaimer in the documentation
     11 //     and/or other materials provided with the distribution.
     12 //   * Neither the name of ARM Limited nor the names of its contributors may be
     13 //     used to endorse or promote products derived from this software without
     14 //     specific prior written permission.
     15 //
     16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS CONTRIBUTORS "AS IS" AND
     17 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     18 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     19 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
     20 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     21 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     22 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
     23 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
     24 // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     25 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     26 
     27 #include "test-runner.h"
     28 
     29 // TODO: Add unit tests for operands on AArch64
     30 // TODO: It would be nice to have negative tests here too.
     31 
     32 #ifdef VIXL_INCLUDE_TARGET_AARCH32
     33 #include "aarch32/operands-aarch32.h"
     34 #endif
     35 
     36 #define TEST_AARCH32(name) TEST_(AARCH32_OPERANDS_##name)
     37 
     38 namespace vixl {
     39 
     40 #ifdef VIXL_INCLUDE_TARGET_AARCH32
     41 TEST_AARCH32(operand_from) {
     42   // Test signed and unsigned values.
     43   {
     44     aarch32::Operand op = aarch32::Operand::From(42);
     45     VIXL_CHECK(op.IsImmediate());
     46     VIXL_CHECK(op.GetImmediate() == 42);
     47     VIXL_CHECK(op.GetSignedImmediate() == 42);
     48   }
     49   {
     50     aarch32::Operand op = aarch32::Operand::From(-42);
     51     VIXL_CHECK(op.IsImmediate());
     52     VIXL_CHECK(op.GetImmediate() == (~UINT32_C(42) + 1));
     53     VIXL_CHECK(op.GetSignedImmediate() == -42);
     54   }
     55 
     56   // Test with 32-bit integer limits.
     57   {
     58     aarch32::Operand op = aarch32::Operand::From(-1);
     59     VIXL_CHECK(op.IsImmediate());
     60     VIXL_CHECK(op.GetImmediate() == UINT32_MAX);
     61     VIXL_CHECK(op.GetSignedImmediate() == -1);
     62   }
     63   {
     64     aarch32::Operand op = aarch32::Operand::From(UINT32_MAX);
     65     VIXL_CHECK(op.IsImmediate());
     66     VIXL_CHECK(op.GetImmediate() == UINT32_MAX);
     67     VIXL_CHECK(op.GetSignedImmediate() == -1);
     68   }
     69   {
     70     aarch32::Operand op = aarch32::Operand::From(INT32_MAX);
     71     VIXL_CHECK(op.IsImmediate());
     72     VIXL_CHECK(op.GetImmediate() == 0x7fffffffu);
     73     VIXL_CHECK(op.GetSignedImmediate() == INT32_MAX);
     74   }
     75   {
     76     aarch32::Operand op = aarch32::Operand::From(INT32_MIN);
     77     VIXL_CHECK(op.IsImmediate());
     78     VIXL_CHECK(op.GetImmediate() == 0x80000000u);
     79     VIXL_CHECK(op.GetSignedImmediate() == INT32_MIN);
     80   }
     81 
     82   // Test with 64-bit signed numbers encodable in 32 bits.
     83   {
     84     aarch32::Operand op = aarch32::Operand::From(INT64_C(-1));
     85     VIXL_CHECK(op.IsImmediate());
     86     VIXL_CHECK(op.GetImmediate() == UINT32_MAX);
     87     VIXL_CHECK(op.GetSignedImmediate() == -1);
     88   }
     89   {
     90     aarch32::Operand op = aarch32::Operand::From(INT64_C(-42));
     91     VIXL_CHECK(op.IsImmediate());
     92     VIXL_CHECK(op.GetImmediate() == (~UINT32_C(42) + 1));
     93     VIXL_CHECK(op.GetSignedImmediate() == -42);
     94   }
     95 
     96 #if defined(VIXL_HOST_POINTER_32)
     97   // Test with a pointer that is known to fit into 32 bits.
     98   {
     99     int data = 42;
    100     aarch32::Operand op = aarch32::Operand::From(&data);
    101     VIXL_CHECK(op.IsImmediate());
    102     VIXL_CHECK(op.GetImmediate() == reinterpret_cast<uintptr_t>(&data));
    103     VIXL_CHECK(op.GetSignedImmediate() == reinterpret_cast<intptr_t>(&data));
    104   }
    105   {
    106     int* data = new int;
    107     *data = 42;
    108     aarch32::Operand op = aarch32::Operand::From(data);
    109     VIXL_CHECK(op.IsImmediate());
    110     VIXL_CHECK(op.GetImmediate() == reinterpret_cast<uintptr_t>(data));
    111     VIXL_CHECK(op.GetSignedImmediate() == reinterpret_cast<intptr_t>(data));
    112     delete data;
    113   }
    114 #endif
    115 }
    116 #endif  // VIXL_INCLUDE_TARGET_AARCH32
    117 
    118 }  // namespace vixl
    119