source: CLRX/CLRadeonExtender/trunk/tests/amdbin/ROCmMsgPackWrite.cpp @ 4956

Last change on this file since 4956 was 4956, checked in by matszpk, 13 months ago

CLRadeonExtender: ROCmBin: Add next testcases to ROCmMsgPackWrite.

File size: 6.2 KB
Line 
1/*
2 *  CLRadeonExtender - Unofficial OpenCL Radeon Extensions Library
3 *  Copyright (C) 2014-2018 Mateusz Szpakowski
4 *
5 *  This library is free software; you can redistribute it and/or
6 *  modify it under the terms of the GNU Lesser General Public
7 *  License as published by the Free Software Foundation; either
8 *  version 2.1 of the License, or (at your option) any later version.
9 *
10 *  This library is distributed in the hope that it will be useful,
11 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 *  Lesser General Public License for more details.
14 *
15 *  You should have received a copy of the GNU Lesser General Public
16 *  License along with this library; if not, write to the Free Software
17 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
18 */
19
20#include <CLRX/Config.h>
21#include <iostream>
22#include <cstring>
23#include <vector>
24#include <memory>
25#include <CLRX/utils/Containers.h>
26#include <CLRX/amdbin/ROCmBinaries.h>
27#include "../TestUtils.h"
28
29using namespace CLRX;
30
31static void testMsgPackBytesWrite()
32{
33    {
34        static const cxbyte outBytes0[3] = { 0x92, 0xc3, 0xc2 };
35        std::vector<cxbyte> out;
36        MsgPackArrayWriter awriter(2, out);
37        awriter.putBool(true);
38        awriter.putBool(false);
39        assertArray("MsgPackWrite0", "tc0",
40                    Array<cxbyte>(outBytes0, outBytes0 + sizeof(outBytes0)), out);
41    }
42    {
43        static const cxbyte outBytes1[16] = { 0x9f, 0, 1, 2, 3, 4, 5, 6, 7,
44            8, 9, 10, 11, 12, 13, 14 };
45        std::vector<cxbyte> out;
46        MsgPackArrayWriter awriter(15, out);
47        for (cxuint i = 0; i < 15; i++)
48            awriter.putUInt(i);
49        assertArray("MsgPackWrite0", "tc1",
50                    Array<cxbyte>(outBytes1, outBytes1 + sizeof(outBytes1)), out);
51    }
52    {   // longer array
53        static const cxbyte outBytes2[21] = { 0xdc, 0x0, 0x12, 0, 1, 2, 3, 4, 5, 6, 7,
54            8, 9, 10, 11, 12, 13, 14, 15, 16, 17 };
55        std::vector<cxbyte> out;
56        MsgPackArrayWriter awriter(18, out);
57        for (cxuint i = 0; i < 18; i++)
58            awriter.putUInt(i);
59        assertArray("MsgPackWrite0", "tc2",
60                    Array<cxbyte>(outBytes2, outBytes2 + sizeof(outBytes2)), out);
61    }
62    {   // long array (12222 elements)
63        Array<cxbyte> outBytes3(12222+3);
64        outBytes3[0] = 0xdc;
65        outBytes3[1] = 12222>>8;
66        outBytes3[2] = 12222&0xff;
67        std::vector<cxbyte> out;
68        MsgPackArrayWriter awriter(12222, out);
69        for (cxuint i = 0; i < 12222; i++)
70        {
71            awriter.putUInt(i&0x7f);
72            outBytes3[i+3] = i&0x7f;
73        }
74        assertArray("MsgPackWrite0", "tc3", outBytes3, out);
75    }
76    {   // long array (1777777 elements)
77        Array<cxbyte> outBytes4(1777777+5);
78        outBytes4[0] = 0xdd;
79        outBytes4[1] = 1777777>>24;
80        outBytes4[2] = (1777777>>16)&0xff;
81        outBytes4[3] = (1777777>>8)&0xff;
82        outBytes4[4] = 1777777&0xff;
83        std::vector<cxbyte> out;
84        MsgPackArrayWriter awriter(1777777, out);
85        for (cxuint i = 0; i < 1777777; i++)
86        {
87            awriter.putUInt(i&0x7f);
88            outBytes4[i+5] = i&0x7f;
89        }
90        assertArray("MsgPackWrite0", "tc4", outBytes4, out);
91    }
92    /* test putting values */
93    {
94        static const cxbyte outBytes5[21] = { 0x95, 0x12, 0xcc, 0xd1, 0xcd, 0xab, 0x73,
95            0xce, 0xa1, 0x18, 0xb9, 0x31,
96            0xcf, 0x11, 0x88, 0x99, 0xa1, 0xb6, 0xa1, 0x9e, 0x1a };
97        std::vector<cxbyte> out;
98        MsgPackArrayWriter awriter(5, out);
99        awriter.putUInt(0x12);
100        awriter.putUInt(0xd1);
101        awriter.putUInt(0xab73);
102        awriter.putUInt(0xa118b931U);
103        awriter.putUInt(0x118899a1b6a19e1aULL);
104        assertArray("MsgPackWrite0", "tc5",
105                    Array<cxbyte>(outBytes5, outBytes5 + sizeof(outBytes5)), out);
106    }
107    // testing string putting (short)
108    {
109        static const cxbyte outBytes6[7] = { 0x91, 0xa5, 0x4a, 0x5b, 0x31, 0x28, 0x44 };
110        std::vector<cxbyte> out;
111        MsgPackArrayWriter awriter(1, out);
112        awriter.putString("\x4a\x5b\x31\x28\x44");
113        assertArray("MsgPackWrite0", "tc6",
114                    Array<cxbyte>(outBytes6, outBytes6 + sizeof(outBytes6)), out);
115    }
116    {
117        Array<cxbyte> outBytes7(187+3);
118        outBytes7[0] = 0x91;
119        outBytes7[1] = 0xd9;
120        outBytes7[2] = 187;
121        std::vector<cxbyte> out;
122        MsgPackArrayWriter awriter(1, out);
123        for (cxuint i = 0; i < 187; i++)
124            outBytes7[i+3] = (i&0x7f)+10;
125        std::string s(reinterpret_cast<cxbyte*>(outBytes7.data())+3,
126                    reinterpret_cast<cxbyte*>(outBytes7.data())+187+3);
127        awriter.putString(s.c_str());
128        assertArray("MsgPackWrite0", "tc7", outBytes7, out);
129    }
130    {
131        Array<cxbyte> outBytes8(18529+4);
132        outBytes8[0] = 0x91;
133        outBytes8[1] = 0xda;
134        outBytes8[2] = 18529>>8;
135        outBytes8[3] = 18529&0xff;
136        std::vector<cxbyte> out;
137        MsgPackArrayWriter awriter(1, out);
138        for (cxuint i = 0; i < 18529; i++)
139            outBytes8[i+4] = (i&0x7f)+10;
140        std::string s(reinterpret_cast<cxbyte*>(outBytes8.data())+4,
141                    reinterpret_cast<cxbyte*>(outBytes8.data())+18529+4);
142        awriter.putString(s.c_str());
143        assertArray("MsgPackWrite0", "tc8", outBytes8, out);
144    }
145    {
146        Array<cxbyte> outBytes9(9838391+6);
147        outBytes9[0] = 0x91;
148        outBytes9[1] = 0xdb;
149        outBytes9[2] = 9838391>>24;
150        outBytes9[3] = (9838391>>16)&0xff;
151        outBytes9[4] = (9838391>>8)&0xff;
152        outBytes9[5] = 9838391&0xff;
153        std::vector<cxbyte> out;
154        MsgPackArrayWriter awriter(1, out);
155        for (cxuint i = 0; i < 9838391; i++)
156            outBytes9[i+6] = (i&0x7f)+10;
157        std::string s(reinterpret_cast<cxbyte*>(outBytes9.data())+6,
158                    reinterpret_cast<cxbyte*>(outBytes9.data())+9838391+6);
159        awriter.putString(s.c_str());
160        assertArray("MsgPackWrite0", "tc9", outBytes9, out);
161    }
162    /* map writer class */
163}
164
165int main(int argc, const char** argv)
166{
167    int retVal = 0;
168    retVal |= callTest(testMsgPackBytesWrite);
169    return retVal;
170}
Note: See TracBrowser for help on using the repository browser.