1 //===- DXContainerTest.cpp - Tests for DXContainerFile --------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "llvm/ADT/StringRef.h"
10 #include "llvm/ADT/Twine.h"
11 #include "llvm/ObjectYAML/ObjectYAML.h"
12 #include "llvm/ObjectYAML/yaml2obj.h"
13 #include "llvm/Support/MemoryBufferRef.h"
14 #include "llvm/Support/YAMLTraits.h"
15 #include "llvm/Support/raw_ostream.h"
16 #include "llvm/Testing/Support/Error.h"
17 #include "gtest/gtest.h"
20 using namespace llvm::object
;
22 static bool convert(SmallVectorImpl
<char> &Output
, const char *YAML
) {
23 raw_svector_ostream
OS(Output
);
24 yaml::Input
YIn(YAML
);
25 return convertYAML(YIn
, OS
, [](const Twine
&Err
) { errs() << Err
; });
28 TEST(DXCFile
, ParseEmptyParts
) {
29 SmallString
<128> Storage
;
31 // First read a fully explicit yaml with all sizes and offsets provided
32 ASSERT_TRUE(convert(Storage
, R
"(--- !dxcontainer
34 Hash: [ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
35 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 ]
41 PartOffsets: [ 60, 68, 76, 84, 92, 100, 108 ]
62 0x44, 0x58, 0x42, 0x43, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
63 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
64 0x74, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x3C, 0x00, 0x00, 0x00,
65 0x44, 0x00, 0x00, 0x00, 0x4C, 0x00, 0x00, 0x00, 0x54, 0x00, 0x00, 0x00,
66 0x5C, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00, 0x6C, 0x00, 0x00, 0x00,
67 0x46, 0x4B, 0x45, 0x30, 0x00, 0x00, 0x00, 0x00, 0x46, 0x4B, 0x45, 0x31,
68 0x00, 0x00, 0x00, 0x00, 0x46, 0x4B, 0x45, 0x32, 0x00, 0x00, 0x00, 0x00,
69 0x46, 0x4B, 0x45, 0x33, 0x00, 0x00, 0x00, 0x00, 0x46, 0x4B, 0x45, 0x34,
70 0x00, 0x00, 0x00, 0x00, 0x46, 0x4B, 0x45, 0x35, 0x00, 0x00, 0x00, 0x00,
71 0x46, 0x4B, 0x45, 0x36, 0x00, 0x00, 0x00, 0x00,
74 EXPECT_EQ(Storage
.size(), 116u);
75 EXPECT_TRUE(memcmp(Buffer
, Storage
.data(), 116) == 0);
79 // Next, read the same file without the part offsets or file size. Both cases
80 // should result in the same final output.
81 ASSERT_TRUE(convert(Storage
, R
"(--- !dxcontainer
83 Hash: [ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
84 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 ]
107 EXPECT_EQ(Storage
.size(), 116u);
108 EXPECT_TRUE(memcmp(Buffer
, Storage
.data(), 116) == 0);