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

Last change on this file since 4954 was 4954, checked in by matszpk, 14 months ago

CLRadeonExtender: ROCmBin: Fixed MsgPack? writer classes constructors for long elements number. Add next testcases.

File size: 3.4 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 (12222 elements)
77        Array<cxbyte> outBytes3(1777777+5);
78        outBytes3[0] = 0xdd;
79        outBytes3[1] = 1777777>>24;
80        outBytes3[2] = (1777777>>16)&0xff;
81        outBytes3[3] = (1777777>>8)&0xff;
82        outBytes3[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            outBytes3[i+5] = i&0x7f;
89        }
90        assertArray("MsgPackWrite0", "tc4", outBytes3, out);
91    }
92}
93
94int main(int argc, const char** argv)
95{
96    int retVal = 0;
97    retVal |= callTest(testMsgPackBytesWrite);
98    return retVal;
99}
Note: See TracBrowser for help on using the repository browser.