gem5 v24.0.0.0
Loading...
Searching...
No Matches
serialization_fixture.hh
Go to the documentation of this file.
1/*
2 * Copyright (c) 2021 Daniel R. Carvalho
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
31#include <cassert>
32#include <cerrno>
33#include <fstream>
34#include <string>
35
36#include "base/compiler.hh"
37#include "sim/serialize.hh"
38
39namespace gem5
40{
41
52class SerializationFixture : public ::testing::Test
53{
54 private:
59 static unsigned dirNumber;
60
62 std::string dirName;
63
64 public:
65 using ::testing::Test::Test;
66
68 static std::string
70 {
71 return "/tmp/temp_dir_test" + std::to_string(dirNumber++) + "/";
72 }
73
75 std::string getDirName() const { return dirName; }
76
78 std::string
79 getCptPath() const
80 {
81 return getDirName() + std::string(CheckpointIn::baseFilename);
82 }
83
89 void
91 {
92 std::ofstream cp(getCptPath());
93 cp << contents;
94 cp.close();
95 }
96
97 void
98 SetUp() override
99 {
100 // Create the directory
102 [[maybe_unused]] int success = mkdir(dirName.c_str(), 0775);
103 assert(!(success == -1 && errno != EEXIST));
104 }
105
106 void
107 TearDown() override
108 {
109 // There may be a cpt file inside, so try to remove it; otherwise,
110 // rmdir does not work
111 std::remove(getCptPath().c_str());
112 // Remove the directory we created on SetUp
113 [[maybe_unused]] int success = rmdir(dirName.c_str());
114 assert(success == 0);
115 }
116};
118
119} // anonymous namespace
static const char * baseFilename
Definition serialize.hh:132
Fixture class that handles temporary directory creation.
std::string getDirName() const
Get the name of the directory we have created on SetUp.
std::string getCptPath() const
Get the path to the checkpoint file.
static std::string generateTempDirName()
Generate a temporary directory name.
static unsigned dirNumber
Temporary directory names are generated based on this number, which is updated every time the generat...
void simulateSerialization(std::string contents) const
Create a cpt file with the contents specified by the string.
std::string dirName
The name of the temporary directory.
Bitfield< 2, 1 > contents
Definition syscalls.hh:50
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36

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