gem5 v24.0.0.0
Loading...
Searching...
No Matches
image_file_data.test.cc
Go to the documentation of this file.
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
37
38using namespace gem5;
39using namespace loader;
40
41TEST(ImageFileDataTest, SimpleImage)
42{
43 /*
44 * Create a temporary file from our data blob.
45 */
46 char filename[] = "image-XXXXXX";
47 int fd = mkstemp(filename);
48 ASSERT_NE(-1, fd);
49 ssize_t size = write(fd, image_file, sizeof(image_file));
50
51 /*
52 * In this basic test, the image file is simply loaded to the
53 * ImageFileData object (i.e., no decompression).
54 */
55 ImageFileData idf(filename);
56
57 EXPECT_EQ(idf.filename(), filename);
58 EXPECT_EQ(size, idf.len());
59
60 for (size_t i = 0; i < sizeof(image_file); i++) {
61 EXPECT_EQ(image_file[i], idf.data()[i]);
62 }
63
64 /*
65 * Close and delete the temporary file.
66 */
67 close(fd);
68 unlink(filename);
69}
70
71
72TEST(ImageFileDataTest, GZipImage)
73{
74 /*
75 * Create temporary files from our data blobs.
76 */
77 char filename_gz[] = "image-XXXXXX";
78 int fd_gz = mkstemp(filename_gz);
79 ASSERT_NE(-1, fd_gz);
80 ssize_t size_gz = write(fd_gz, image_file_gzipped,
81 sizeof(image_file_gzipped));
82
83 char filename[] = "image-XXXXXX";
84 int fd = mkstemp(filename);
85 ASSERT_NE(-1, fd);
86 ssize_t size = write(fd, image_file, sizeof(image_file));
87
88 /*
89 * ImageFileData decompresses a gzipped file. image_file_gzipped is just
90 * image_file gzipped. Therefore ifd_gz.len() should equal ifd.len() and
91 * ifd.data() should equal ifd_gz.data().
92 */
93 ImageFileData ifd_gz(filename_gz);
94 ImageFileData ifd(filename);
95
96 EXPECT_EQ(ifd.len(), ifd_gz.len());
97 EXPECT_EQ(size, ifd.len());
98 EXPECT_NE(size_gz, ifd_gz.len());
99
100 for (size_t index = 0; index < ifd.len(); index++) {
101 EXPECT_EQ(ifd.data()[index], ifd_gz.data()[index]);
102 }
103
104 /*
105 * Close and delete the temporary files.
106 */
107 close(fd);
108 unlink(filename);
109 close(fd_gz);
110 unlink(filename_gz);
111}
const std::string & filename() const
uint8_t const * data() const
TEST(ImageFileDataTest, SimpleImage)
Bitfield< 14, 12 > fd
Definition types.hh:150
Bitfield< 7 > i
Definition misc_types.hh:67
Bitfield< 30, 0 > index
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
const uint8_t image_file[]
This image file contains the text "This is a test image.\n" 31 times.
const uint8_t image_file_gzipped[]
This is "image_file" compressed using GZip.

Generated on Tue Jun 18 2024 16:24:00 for gem5 by doxygen 1.11.0