[PATCH 7/57][Arm][GAS] Add support for MVE instructions: vstr/vldr
[binutils-gdb.git] / gdb / unittests / rsp-low-selftests.c
blobdc3e8f5205476551447a49eb86dd168285cdf6d4
1 /* Unit tests for the rsp-low.c file.
3 Copyright (C) 2017-2019 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 #include "defs.h"
21 #include "common/selftest.h"
22 #include "common/rsp-low.h"
24 namespace selftests {
25 namespace rsp_low {
27 /* Test the variant of hex2bin that returns a byte_vector. */
29 static void test_hex2bin_byte_vector ()
31 gdb::byte_vector bv;
33 /* Test an empty string. */
34 bv = hex2bin ("");
35 SELF_CHECK (bv.size () == 0);
37 /* Test a well-formated hex string. */
38 bv = hex2bin ("abcd01");
39 SELF_CHECK (bv.size () == 3);
40 SELF_CHECK (bv[0] == 0xab);
41 SELF_CHECK (bv[1] == 0xcd);
42 SELF_CHECK (bv[2] == 0x01);
44 /* Test an odd-length hex string. */
45 bv = hex2bin ("0123c");
46 SELF_CHECK (bv.size () == 2);
47 SELF_CHECK (bv[0] == 0x01);
48 SELF_CHECK (bv[1] == 0x23);
51 static void test_hex2str ()
53 SELF_CHECK (hex2str ("666f6f") == "foo");
54 SELF_CHECK (hex2str ("666f6fa") == "foo");
55 SELF_CHECK (hex2str ("666f6f", 2) == "fo");
56 SELF_CHECK (hex2str ("666", 2) == "f");
57 SELF_CHECK (hex2str ("666", 6) == "f");
58 SELF_CHECK (hex2str ("") == "");
61 } /* namespace rsp_low */
62 } /* namespace selftests */
64 void
65 _initialize_rsp_low_selftests ()
67 selftests::register_test ("hex2bin_byte_vector",
68 selftests::rsp_low::test_hex2bin_byte_vector);
69 selftests::register_test ("hex2str",
70 selftests::rsp_low::test_hex2str);