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 be
4 * found in the LICENSE file.
15 #include "native_client/src/trusted/debug_stub/packet.h"
16 #include "native_client/src/trusted/debug_stub/test.h"
18 using gdb_rsp::Packet;
20 int VerifyPacket(Packet *wr, Packet *rd, void *ctx, PacketFunc_t tx) {
29 // Clear the packet may be reused
32 // Verify non alligned writes
34 wr->AddWord16(0x1234);
35 wr->AddWord32(0x56789ABC);
37 if (tx) tx(ctx, wr, rd);
39 if (strcmp("X3412bc9a7856ff", str.data())) errs++;
44 if (ch != 'X') errs++;
46 rd->GetWord16(&word16);
47 if (word16 != 0x1234) errs++;
49 rd->GetWord32(&word32);
50 if (word32 != 0x56789ABC) errs++;
53 if (byte != 0xFF) errs++;
57 if (tx) tx(ctx, wr, rd);
58 if (rd->GetRawChar(&ch)) {
60 printf("Was expecting an empty packet\n");
63 // Check nibble/byte order
64 // Check edge cases of 1, 0, -1, -2
65 wr->AddNumberSep(0x123, ',');
66 wr->AddNumberSep(1, ',');
67 wr->AddNumberSep(0, ',');
68 wr->AddNumberSep(static_cast<uint64_t>(-1), ',');
69 wr->AddNumberSep(static_cast<uint64_t>(-2), 0);
70 if (tx) tx(ctx, wr, rd);
72 if (strcmp("123,1,0,-1,fffffffffffffffe", str.data()) != 0) errs++;
74 // We push "compress" which was generated by a real gdbserver, through into
75 // our packet, then pull it out as a block to decompress, then check against
76 // the 32b values generated by a real gdb debugger. (Inline golden file)
77 const char *compress = "0*488c7280038c72800d4c72800030**fd00637702020* 23"
78 "0*\"2b0*\"2b0*\"2b0*\"530*\"2b0*}00080f83f00c022f8"
79 "07c022f80f3c80040*&80ff3f0**80ff3f7f030* 30*\"0f*"
80 " 0* 58050* 85f7196c2b0*\"b0b801010*}0*}0*b801f0* ";
81 uint32_t vals[16] = { 0, 0, 0, 0x28C788, 0x28C738, 0x28c7d4, 3, 0, 0x776300FD,
82 0x202, 0x23, 0x2B, 0x2B, 0x2B, 0x53, 0x2B };
86 wr->AddString(compress);
87 if (tx) tx(ctx, wr, rd);
88 rd->GetBlock(tmp, sizeof(vals));
89 if (memcmp(tmp, vals, sizeof(vals))) {
91 printf("Failed to decompress as expected.\n");
95 printf("FAILED PACKET TEST\n");
104 errs += VerifyPacket(&pkt, &pkt, NULL, NULL);