1*07fb1d06SElliott Hughes // Copyright 2018 The ChromiumOS Authors
2*07fb1d06SElliott Hughes // Use of this source code is governed by a BSD-style license that can be
3*07fb1d06SElliott Hughes // found in the LICENSE file.
4*07fb1d06SElliott Hughes
5*07fb1d06SElliott Hughes #include "puffin/src/unittest_common.h"
6*07fb1d06SElliott Hughes
7*07fb1d06SElliott Hughes #include <unistd.h>
8*07fb1d06SElliott Hughes
9*07fb1d06SElliott Hughes using std::string;
10*07fb1d06SElliott Hughes using std::vector;
11*07fb1d06SElliott Hughes
12*07fb1d06SElliott Hughes namespace puffin {
13*07fb1d06SElliott Hughes
MakeTempFile(string * filename,int * fd)14*07fb1d06SElliott Hughes bool MakeTempFile(string* filename, int* fd) {
15*07fb1d06SElliott Hughes #ifdef __ANDROID__
16*07fb1d06SElliott Hughes char tmp_template[] = "/data/local/tmp/puffin-XXXXXX";
17*07fb1d06SElliott Hughes #else
18*07fb1d06SElliott Hughes char tmp_template[] = "/tmp/puffin-XXXXXX";
19*07fb1d06SElliott Hughes #endif // __ANDROID__
20*07fb1d06SElliott Hughes int mkstemp_fd = mkstemp(tmp_template);
21*07fb1d06SElliott Hughes TEST_AND_RETURN_FALSE(mkstemp_fd >= 0);
22*07fb1d06SElliott Hughes if (filename) {
23*07fb1d06SElliott Hughes *filename = tmp_template;
24*07fb1d06SElliott Hughes }
25*07fb1d06SElliott Hughes if (fd) {
26*07fb1d06SElliott Hughes *fd = mkstemp_fd;
27*07fb1d06SElliott Hughes } else {
28*07fb1d06SElliott Hughes close(mkstemp_fd);
29*07fb1d06SElliott Hughes }
30*07fb1d06SElliott Hughes return true;
31*07fb1d06SElliott Hughes }
32*07fb1d06SElliott Hughes
33*07fb1d06SElliott Hughes // clang-format off
34*07fb1d06SElliott Hughes const Buffer kDeflatesSample1 = {
35*07fb1d06SElliott Hughes /* raw 0 */ 0x11, 0x22,
36*07fb1d06SElliott Hughes /* def 2 */ 0x63, 0x64, 0x62, 0x66, 0x61, 0x05, 0x00,
37*07fb1d06SElliott Hughes /* raw 9 */ 0x33,
38*07fb1d06SElliott Hughes /* def 10 */ 0x03, 0x00,
39*07fb1d06SElliott Hughes /* raw 12 */
40*07fb1d06SElliott Hughes /* def 12 */ 0x63, 0x04, 0x00,
41*07fb1d06SElliott Hughes /* raw 15 */ 0x44, 0x55
42*07fb1d06SElliott Hughes };
43*07fb1d06SElliott Hughes const Buffer kPuffsSample1 = {
44*07fb1d06SElliott Hughes /* raw 0 */ 0x11, 0x22,
45*07fb1d06SElliott Hughes /* puff 2 */ 0x00, 0x00, 0xA0, 0x04, 0x01, 0x02, 0x03, 0x04, 0x05, 0xFF,
46*07fb1d06SElliott Hughes 0x81,
47*07fb1d06SElliott Hughes /* raw 13 */ 0x00, 0x33,
48*07fb1d06SElliott Hughes /* puff 15 */ 0x00, 0x00, 0xA0, 0xFF, 0x81,
49*07fb1d06SElliott Hughes /* raw 20 */ 0x00,
50*07fb1d06SElliott Hughes /* puff 21 */ 0x00, 0x00, 0xA0, 0x00, 0x01, 0xFF, 0x81,
51*07fb1d06SElliott Hughes /* raw 28 */ 0x00, 0x44, 0x55
52*07fb1d06SElliott Hughes };
53*07fb1d06SElliott Hughes const vector<ByteExtent> kDeflateExtentsSample1 = {
54*07fb1d06SElliott Hughes {2, 7}, {10, 2}, {12, 3}};
55*07fb1d06SElliott Hughes const vector<BitExtent> kSubblockDeflateExtentsSample1 = {
56*07fb1d06SElliott Hughes {16, 50}, {80, 10}, {96, 18}};
57*07fb1d06SElliott Hughes const vector<ByteExtent> kPuffExtentsSample1 = {{2, 11}, {15, 5}, {21, 7}};
58*07fb1d06SElliott Hughes
59*07fb1d06SElliott Hughes const Buffer kDeflatesSample2 = {
60*07fb1d06SElliott Hughes /* def 0 */ 0x63, 0x64, 0x62, 0x66, 0x61, 0x05, 0x00,
61*07fb1d06SElliott Hughes /* raw 7 */ 0x33, 0x66,
62*07fb1d06SElliott Hughes /* def 9 */ 0x01, 0x05, 0x00, 0xFA, 0xFF, 0x01, 0x02, 0x03, 0x04, 0x05,
63*07fb1d06SElliott Hughes /* def 19 */ 0x63, 0x04, 0x00
64*07fb1d06SElliott Hughes };
65*07fb1d06SElliott Hughes const Buffer kPuffsSample2 = {
66*07fb1d06SElliott Hughes /* puff 0 */ 0x00, 0x00, 0xA0, 0x04, 0x01, 0x02, 0x03, 0x04, 0x05, 0xFF,
67*07fb1d06SElliott Hughes 0x81,
68*07fb1d06SElliott Hughes /* raw 11 */ 0x00, 0x33, 0x66,
69*07fb1d06SElliott Hughes /* puff 14 */ 0x00, 0x00, 0x80, 0x04, 0x01, 0x02, 0x03, 0x04, 0x05, 0xFF,
70*07fb1d06SElliott Hughes 0x81,
71*07fb1d06SElliott Hughes /* puff 25 */ 0x00, 0x00, 0xA0, 0x00, 0x01, 0xFF, 0x81,
72*07fb1d06SElliott Hughes /* raw 32 */ 0x00,
73*07fb1d06SElliott Hughes };
74*07fb1d06SElliott Hughes const vector<ByteExtent> kDeflateExtentsSample2 = {
75*07fb1d06SElliott Hughes {0, 7}, {9, 10}, {19, 3}};
76*07fb1d06SElliott Hughes const vector<BitExtent> kSubblockDeflateExtentsSample2 = {
77*07fb1d06SElliott Hughes {0, 50}, {72, 80}, {152, 18}};
78*07fb1d06SElliott Hughes const vector<ByteExtent> kPuffExtentsSample2 = {
79*07fb1d06SElliott Hughes {0, 11}, {14, 11}, {25, 7}};
80*07fb1d06SElliott Hughes // clang-format on
81*07fb1d06SElliott Hughes
82*07fb1d06SElliott Hughes // This data is taken from the failed instances described in crbug.com/915559.
83*07fb1d06SElliott Hughes const Buffer kProblematicCache = {
84*07fb1d06SElliott Hughes 0x51, 0x74, 0x97, 0x71, 0x51, 0x6e, 0x6d, 0x1b, 0x87, 0x4f, 0x5b,
85*07fb1d06SElliott Hughes 0xb1, 0xbb, 0xb6, 0xdd, 0xdd, 0xdd, 0x89, 0x89, 0xa2, 0x88, 0x9d,
86*07fb1d06SElliott Hughes 0x18, 0x4c, 0x1a, 0x8c, 0x8a, 0x1d, 0xa8, 0xd8, 0x89, 0xdd, 0xdd,
87*07fb1d06SElliott Hughes 0x81, 0x89, 0x62, 0x77, 0xb7, 0x32, 0x81, 0x31, 0x98, 0x88, 0x5d,
88*07fb1d06SElliott Hughes 0x83, 0xbd, 0xff, 0xf3, 0xe1, 0xf8, 0x9d, 0xd7, 0xba, 0xd6, 0x9a,
89*07fb1d06SElliott Hughes 0x7b, 0x86, 0x99, 0x3b, 0xf7, 0xbb, 0xdf, 0xfd, 0x90, 0xf0, 0x45,
90*07fb1d06SElliott Hughes 0x0b, 0xb4, 0x44, 0x2b, 0xb4, 0x46, 0x1b, 0xb4, 0xc5, 0xff};
91*07fb1d06SElliott Hughes const vector<BitExtent> kProblematicCacheDeflateExtents = {{2, 606}};
92*07fb1d06SElliott Hughes const vector<BitExtent> kProblematicCachePuffExtents = {{1, 185}};
93*07fb1d06SElliott Hughes
94*07fb1d06SElliott Hughes } // namespace puffin
95