1 : /*
2 : * Copyright 2010 The Native Client Authors. All rights reserved.
3 : * Use of this source code is governed by a BSD-style license that can
4 : * be found in the LICENSE file.
5 : */
6 :
7 : #include <stdio.h>
8 : #include <stdlib.h>
9 : #include <string.h>
10 :
11 : #include <string>
12 :
13 : #include "native_client/src/trusted/debug_stub/util.h"
14 :
15 : using std::string;
16 : using gdb_rsp::NibbleToInt;
17 : using gdb_rsp::IntToNibble;
18 : using gdb_rsp::stringvec;
19 :
20 :
21 : int TestUtil() {
22 2 : char goodStr[] = "0123456789abcdefABCDEF";
23 1 : int good;
24 1 : int val;
25 1 : int a;
26 1 : int errCnt = 0;
27 :
28 : // Make sure we find expected and only expected conversions (0-9,a-f,A-F)
29 1 : good = 0;
30 514 : for (a = 0; a < 256; a++) {
31 : // NOTE: Exclude 'zero' since the terminator is found by strchr
32 511 : bool found = a && (strrchr(goodStr, a) != NULL);
33 256 : bool xvert = NibbleToInt(static_cast<char>(a), &val);
34 256 : if (xvert != found) {
35 0 : printf("FAILED NibbleToInt of '%c'(#%d), convertion %s.\n",
36 : a, a, xvert ? "succeeded" : "failed");
37 0 : errCnt++;
38 0 : }
39 256 : }
40 :
41 1 : good = 0;
42 1026 : for (a = -256; a < 256; a++) {
43 512 : char ch;
44 512 : bool xvert = IntToNibble(a, &ch);
45 :
46 512 : if (xvert) {
47 16 : good++;
48 16 : if (!NibbleToInt(ch, &val)) {
49 0 : printf("FAILED IntToNibble on good NibbleToInt of #%d\n.\n", a);
50 0 : errCnt++;
51 0 : }
52 : // NOTE: check if IntToNible matches NibbleToInt looking at both
53 : // possitive and negative values of -15 to +15
54 16 : if (val != a) {
55 0 : printf("FAILED IntToNibble != NibbleToInt of #%d\n.\n", a);
56 0 : errCnt++;
57 0 : }
58 16 : }
59 512 : }
60 :
61 : // Although we check -15 to +15 above, we realy only want -7 to +15
62 : // to verify unsiged (0-15) plus signed (-7 to -1).
63 1 : if (good != 16) {
64 0 : printf("FAILED IntToNibble range of 0 to 15.\n");
65 0 : errCnt++;
66 0 : }
67 :
68 2 : string xml = "qXfer:features:read:target.xml:0,7ca";
69 1 : string str;
70 3 : stringvec vec, vec2;
71 :
72 1 : return errCnt;
73 4 : }
74 :
|