gem5  v19.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
exec_aout.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  * Authors: Bobby R. Bruce
29  */
30 
31 
32 #include <gtest/gtest.h>
33 
34 #include "base/loader/exec_aout.h"
35 
36 #define OMAGIC_STRUCT (*((const aout_exechdr *)omagic))
37 #define NMAGIC_STRUCT (*((const aout_exechdr *)nmagic))
38 #define ZMAGIC_STRUCT (*((const aout_exechdr *)zmagic))
39 #define NO_MAGIC_STRUCT (*((const aout_exechdr *)no_magic))
40 
41 #if (defined(_BIG_ENDIAN) || !defined(_LITTLE_ENDIAN))\
42  && BYTE_ORDER==BIG_ENDIAN
43 const uint8_t omagic[] {
44  0x01, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
45  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
46  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
47  0x00, 0x00, 0x00, 0x00, 0x00
48 };
49 
50 const uint8_t nmagic[] {
51  0x01, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
52  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
53  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
54  0x00, 0x00, 0x00, 0x00, 0x00
55 };
56 
57 const uint8_t zmagic[] {
58  0x01, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
59  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
60  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
61  0x00, 0x00, 0x00, 0x00, 0x00
62 };
63 
64 const uint8_t no_magic[] {
65  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
66  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
67  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
68  0x00, 0x00, 0x00, 0x01, 0x00
69 };
70 #elif defined(_LITTLE_ENDIAN) || BYTE_ORDER==LITTLE_ENDIAN
71 const uint8_t omagic[] {
72  0x07, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
73  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
74  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
75  0x00, 0x00, 0x00, 0x00, 0x00
76 };
77 
78 const uint8_t nmagic[] {
79  0x08, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
80  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
81  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
82  0x00, 0x00, 0x00, 0x00, 0x00
83 };
84 
85 const uint8_t zmagic[] {
86  0x0B, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
87  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
88  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
89  0x00, 0x00, 0x00, 0x00, 0x00
90 };
91 
92 const uint8_t no_magic[] {
93  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
94  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
95  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
96  0x00, 0x00, 0x00, 0x00, 0x01
97 };
98 #else
99  #error Invalid Endianess
100 #endif
101 
102 TEST(ExecAoutTest, IsNotBadMagicNumber)
103 {
107 }
108 
109 TEST(ExecAoutTest, IsBadMagicNumber)
110 {
112 }
113 
114 TEST(ExecAoutTest, AlignNotZmagic)
115 {
116  /*
117  * N_ALIGN will return x if the aout_exechdr does not have ZMAGIC as a
118  * magic number.
119  */
120  int64_t x = 0xABCD;
124 }
125 
126 TEST(ExecAoutTest, AlignIsZmagic)
127 {
128  /*
129  * N_ALIGN will round up X by AOUT_LDPGSZ (1 << 13) if the aout_exechdr
130  * has ZMAGIC as a magic number.
131  */
132  int64_t x = (1 << 20) + (1 << 18) + (1 << 12) + (1 << 5) + 1;
133  EXPECT_EQ((1 << 20) + (1 << 18) + (1 << 13), N_ALIGN(ZMAGIC_STRUCT, x));
134 }
135 
136 TEST(ExecAoutTest, AlignIsZmagicNoRounding)
137 {
138  /*
139  * In this case, there's no rounding needed.
140  */
141  int64_t x = (1 << 20) + (1 << 18) + (1 << 13);
143 }
TEST(ExecAoutTest, IsNotBadMagicNumber)
#define NO_MAGIC_STRUCT
#define N_BADMAG(ex)
Definition: exec_aout.h:54
const uint8_t nmagic[]
#define EXPECT_TRUE(expr)
A macro which verifies that expr evaluates to true.
Definition: unittest.hh:105
#define NMAGIC_STRUCT
#define ZMAGIC_STRUCT
#define N_ALIGN(ex, x)
Definition: exec_aout.h:49
const uint8_t no_magic[]
#define EXPECT_FALSE(expr)
A macro which verifies that expr evaluates to false.
Definition: unittest.hh:108
#define OMAGIC_STRUCT
Bitfield< 1 > x
Definition: types.hh:105
#define EXPECT_EQ(lhs, rhs)
A macro which verifies that lhs and rhs are equal to each other.
Definition: unittest.hh:112
const uint8_t omagic[]
const uint8_t zmagic[]

Generated on Fri Feb 28 2020 16:26:58 for gem5 by doxygen 1.8.13