tests: log_call is not returning any value
[gem5.git] / src / base / loader / image_file_data.test.cc
1 /*
2 * Copyright (c) 2019 The Regents of the University of California
3 * All rights reserved
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 #include <gtest/gtest.h>
30 #include <sys/types.h>
31 #include <unistd.h>
32
33 #include <cstdlib>
34
35 #include "base/loader/image_file_data.hh"
36 #include "base/loader/small_image_file.test.hh"
37
38 using namespace Loader;
39
40 TEST(ImageFileDataTest, SimpleImage)
41 {
42 /*
43 * Create a temporary file from our data blob.
44 */
45 char filename[] = "image-XXXXXX";
46 int fd = mkstemp(filename);
47 ASSERT_NE(-1, fd);
48 ssize_t size = write(fd, image_file, sizeof(image_file));
49
50 /*
51 * In this basic test, the image file is simply loaded to the
52 * ImageFileData object (i.e., no decompression).
53 */
54 ImageFileData idf(filename);
55
56 EXPECT_EQ(idf.filename(), filename);
57 EXPECT_EQ(size, idf.len());
58
59 for (size_t i = 0; i < sizeof(image_file); i++) {
60 EXPECT_EQ(image_file[i], idf.data()[i]);
61 }
62
63 /*
64 * Close and delete the temporary file.
65 */
66 close(fd);
67 unlink(filename);
68 }
69
70
71 TEST(ImageFileDataTest, GZipImage)
72 {
73 /*
74 * Create temporary files from our data blobs.
75 */
76 char filename_gz[] = "image-XXXXXX";
77 int fd_gz = mkstemp(filename_gz);
78 ASSERT_NE(-1, fd_gz);
79 ssize_t size_gz = write(fd_gz, image_file_gzipped,
80 sizeof(image_file_gzipped));
81
82 char filename[] = "image-XXXXXX";
83 int fd = mkstemp(filename);
84 ASSERT_NE(-1, fd);
85 ssize_t size = write(fd, image_file, sizeof(image_file));
86
87 /*
88 * ImageFileData decompresses a gzipped file. image_file_gzipped is just
89 * image_file gzipped. Therefore ifd_gz.len() should equal ifd.len() and
90 * ifd.data() should equal ifd_gz.data().
91 */
92 ImageFileData ifd_gz(filename_gz);
93 ImageFileData ifd(filename);
94
95 EXPECT_EQ(ifd.len(), ifd_gz.len());
96 EXPECT_EQ(size, ifd.len());
97 EXPECT_NE(size_gz, ifd_gz.len());
98
99 for (size_t index = 0; index < ifd.len(); index++) {
100 EXPECT_EQ(ifd.data()[index], ifd_gz.data()[index]);
101 }
102
103 /*
104 * Close and delete the temporary files.
105 */
106 close(fd);
107 unlink(filename);
108 close(fd_gz);
109 unlink(filename_gz);
110 }