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