• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "JITDebugReader_impl.h"
18 
19 #include <android-base/file.h>
20 #include <android-base/test_utils.h>
21 
22 #include <gtest/gtest.h>
23 
24 using namespace simpleperf;
25 
TEST(TempSymFile,smoke)26 TEST(TempSymFile, smoke) {
27   TemporaryFile tmpfile;
28   std::unique_ptr<TempSymFile> symfile = TempSymFile::Create(tmpfile.path, false);
29   ASSERT_TRUE(symfile);
30   // If we write entries starting from offset 0, libunwindstack will treat the whole file as an elf
31   // file in its elf cache. So make sure we don't start from offset 0.
32   uint64_t offset = symfile->GetOffset();
33   ASSERT_NE(offset, 0u);
34 
35   // Write data and read it back.
36   const std::string test_data = "test_data";
37   ASSERT_TRUE(symfile->WriteEntry(test_data.c_str(), test_data.size()));
38   ASSERT_TRUE(symfile->Flush());
39 
40   char buf[16];
41   ASSERT_TRUE(android::base::ReadFullyAtOffset(tmpfile.fd, buf, test_data.size(), offset));
42   ASSERT_EQ(strncmp(test_data.c_str(), buf, test_data.size()), 0);
43 }
44