gem5 [DEVELOP-FOR-25.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 <cstdlib>
33#include <cerrno>
34#include <fstream>
35#include <string>
36
37#include "base/compiler.hh"
38#include "sim/serialize.hh"
39
40namespace gem5
41{
42
53class SerializationFixture : public ::testing::Test
54{
55 private:
57 std::string dirName = "/tmp/temp_dir_test_XXXXXX";
58
59 public:
60 using ::testing::Test::Test;
61
63 std::string getDirName() const { return dirName; }
64
66 std::string
67 getCptPath() const
68 {
69 return getDirName() + '/' + std::string(CheckpointIn::baseFilename);
70 }
71
77 void
79 {
80 std::ofstream cp(getCptPath());
81 cp << contents;
82 cp.close();
83 }
84
85 void
86 SetUp() override
87 {
88 // Create the directory
89 [[maybe_unused]] char* ret = mkdtemp(dirName.data());
90 assert(ret != nullptr);
91 }
92
93 void
94 TearDown() override
95 {
96 // There may be a cpt file inside, so try to remove it; otherwise,
97 // rmdir does not work
98 std::remove(getCptPath().c_str());
99 // Remove the directory we created on SetUp
100 [[maybe_unused]] int success = rmdir(dirName.c_str());
101 assert(success == 0);
102 }
103};
104
105} // 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.
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 Arm Limited All rights reserved.
Definition binary32.hh:36

Generated on Mon May 26 2025 09:19:06 for gem5 by doxygen 1.13.2