blob: 77e69ff94879776159e629377535c8abfe05a19d [file] [log] [blame]
David Brazdil7a462ec2019-08-15 12:27:47 +01001/*
2 * Copyright 2019 The Hafnium Authors.
3 *
Andrew Walbrane959ec12020-06-17 15:01:09 +01004 * Use of this source code is governed by a BSD-style
5 * license that can be found in the LICENSE file or at
6 * https://opensource.org/licenses/BSD-3-Clause.
David Brazdil7a462ec2019-08-15 12:27:47 +01007 */
8
David Brazdil52256ff2019-08-23 15:15:15 +01009#include <array>
10#include <cstdio>
Andrew Scullae9962e2019-10-03 16:51:16 +010011#include <span>
David Brazdil52256ff2019-08-23 15:15:15 +010012#include <sstream>
13
David Brazdil7a462ec2019-08-15 12:27:47 +010014#include <gmock/gmock.h>
15
16extern "C" {
J-Alves2f86c1e2022-02-23 18:44:19 +000017#include "hf/arch/std.h"
18
David Brazdil7a462ec2019-08-15 12:27:47 +010019#include "hf/manifest.h"
J-Alves2f86c1e2022-02-23 18:44:19 +000020#include "hf/sp_pkg.h"
David Brazdil7a462ec2019-08-15 12:27:47 +010021}
22
23namespace
24{
Andrew Scullae9962e2019-10-03 16:51:16 +010025using ::testing::ElementsAre;
David Brazdil7a462ec2019-08-15 12:27:47 +010026using ::testing::Eq;
Andrew Scullae9962e2019-10-03 16:51:16 +010027using ::testing::IsEmpty;
David Brazdil7a462ec2019-08-15 12:27:47 +010028using ::testing::NotNull;
29
Daniel Boulby801f8ef2022-06-27 14:21:01 +010030using struct_manifest = struct manifest;
31
32constexpr size_t TEST_HEAP_SIZE = PAGE_SIZE * 32;
33
David Brazdil52256ff2019-08-23 15:15:15 +010034template <typename T>
David Brazdil0dbb41f2019-09-09 18:03:35 +010035void exec(const char *program, const char *args[], const T &stdin,
David Brazdil52256ff2019-08-23 15:15:15 +010036 std::vector<char> *stdout)
37{
38 /* Create two pipes, one for stdin and one for stdout. */
39 int pipes[2][2];
40 pipe(pipes[0]);
41 pipe(pipes[1]);
David Brazdil7a462ec2019-08-15 12:27:47 +010042
David Brazdil52256ff2019-08-23 15:15:15 +010043 /* Assign FDs for reading/writing by the parent/child. */
44 int parent_read_fd = pipes[1][0]; /* stdout pipe, read FD */
45 int parent_write_fd = pipes[0][1]; /* stdin pipe, write FD */
46 int child_read_fd = pipes[0][0]; /* stdin pipe, read FD */
47 int child_write_fd = pipes[1][1]; /* stdout pipe, write FD */
David Brazdil7a462ec2019-08-15 12:27:47 +010048
David Brazdil52256ff2019-08-23 15:15:15 +010049 if (fork()) {
50 /* Parent process. */
51 std::array<char, 128> buf;
52 ssize_t res;
53
54 /* Close child FDs which won't be used. */
55 close(child_read_fd);
56 close(child_write_fd);
57
58 /* Write to stdin. */
59 for (size_t count = 0; count < stdin.size();) {
60 res = write(parent_write_fd, stdin.data() + count,
61 stdin.size() - count);
62 if (res < 0) {
63 std::cerr << "IO error" << std::endl;
64 exit(1);
65 }
66 count += res;
67 }
68 close(parent_write_fd);
69
70 /* Read from stdout. */
71 while (true) {
72 res = read(parent_read_fd, buf.data(), buf.size());
73 if (res == 0) {
74 /* EOF */
75 break;
76 } else if (res < 0) {
77 std::cerr << "IO error" << std::endl;
78 exit(1);
79 }
80 stdout->insert(stdout->end(), buf.begin(),
81 buf.begin() + res);
82 }
83 close(parent_read_fd);
84 } else {
85 /* Child process. */
86
87 /* Redirect stdin/stdout to read/write FDs. */
88 dup2(child_read_fd, STDIN_FILENO);
89 dup2(child_write_fd, STDOUT_FILENO);
90
91 /* Close all FDs which are now unused. */
92 close(child_read_fd);
93 close(child_write_fd);
94 close(parent_read_fd);
95 close(parent_write_fd);
96
97 /* Execute the given program. */
David Brazdil0dbb41f2019-09-09 18:03:35 +010098 execv(program, const_cast<char *const *>(args));
David Brazdil52256ff2019-08-23 15:15:15 +010099 }
100}
101
102/**
103 * Class for programatically building a Device Tree.
104 *
105 * Usage:
106 * std::vector<char> dtb = ManifestDtBuilder()
107 * .Command1()
108 * .Command2()
109 * ...
110 * .CommandN()
111 * .Build();
112 */
113class ManifestDtBuilder
114{
115 public:
116 ManifestDtBuilder()
117 {
118 dts_ << "/dts-v1/;" << std::endl;
119 dts_ << std::endl;
120
121 /* Start root node. */
122 StartChild("/");
123 }
124
Andrew Scullae9962e2019-10-03 16:51:16 +0100125 std::vector<char> Build(bool dump = false)
David Brazdil52256ff2019-08-23 15:15:15 +0100126 {
David Brazdil0dbb41f2019-09-09 18:03:35 +0100127 const char *program = "./build/image/dtc.py";
128 const char *dtc_args[] = {program, "compile", NULL};
David Brazdil52256ff2019-08-23 15:15:15 +0100129 std::vector<char> dtc_stdout;
130
131 /* Finish root node. */
132 EndChild();
133
Andrew Scullae9962e2019-10-03 16:51:16 +0100134 if (dump) {
135 Dump();
136 }
137
David Brazdil0dbb41f2019-09-09 18:03:35 +0100138 exec(program, dtc_args, dts_.str(), &dtc_stdout);
David Brazdil52256ff2019-08-23 15:15:15 +0100139 return dtc_stdout;
140 }
141
Andrew Scullae9962e2019-10-03 16:51:16 +0100142 void Dump()
143 {
144 std::cerr << dts_.str() << std::endl;
145 }
146
David Brazdil52256ff2019-08-23 15:15:15 +0100147 ManifestDtBuilder &StartChild(const std::string_view &name)
148 {
149 dts_ << name << " {" << std::endl;
150 return *this;
151 }
152
153 ManifestDtBuilder &EndChild()
154 {
155 dts_ << "};" << std::endl;
156 return *this;
157 }
158
David Brazdil74e9c3b2019-08-28 11:09:08 +0100159 ManifestDtBuilder &Compatible(const std::vector<std::string_view>
160 &value = {"hafnium,hafnium"})
161 {
162 return StringListProperty("compatible", value);
163 }
164
David Brazdil52256ff2019-08-23 15:15:15 +0100165 ManifestDtBuilder &DebugName(const std::string_view &value)
166 {
167 return StringProperty("debug_name", value);
168 }
169
Manish Pandey6542f5c2020-04-27 14:37:46 +0100170 ManifestDtBuilder &Description(const std::string_view &value)
171 {
172 return StringProperty("description", value);
173 }
174
David Brazdil52256ff2019-08-23 15:15:15 +0100175 ManifestDtBuilder &KernelFilename(const std::string_view &value)
176 {
177 return StringProperty("kernel_filename", value);
178 }
179
David Brazdile6f83222019-09-23 14:47:37 +0100180 ManifestDtBuilder &RamdiskFilename(const std::string_view &value)
181 {
182 return StringProperty("ramdisk_filename", value);
183 }
184
David Brazdil080ee312020-02-25 15:30:30 -0800185 ManifestDtBuilder &BootAddress(uint64_t value)
186 {
187 return Integer64Property("boot_address", value);
188 }
189
Andrew Scullae9962e2019-10-03 16:51:16 +0100190 ManifestDtBuilder &VcpuCount(uint32_t value)
David Brazdil52256ff2019-08-23 15:15:15 +0100191 {
192 return IntegerProperty("vcpu_count", value);
193 }
194
Andrew Scullae9962e2019-10-03 16:51:16 +0100195 ManifestDtBuilder &MemSize(uint32_t value)
David Brazdil52256ff2019-08-23 15:15:15 +0100196 {
197 return IntegerProperty("mem_size", value);
198 }
199
Andrew Scullae9962e2019-10-03 16:51:16 +0100200 ManifestDtBuilder &SmcWhitelist(const std::vector<uint32_t> &value)
201 {
202 return IntegerListProperty("smc_whitelist", value);
203 }
204
205 ManifestDtBuilder &SmcWhitelistPermissive()
206 {
207 return BooleanProperty("smc_whitelist_permissive");
208 }
209
Olivier Deprez62d99e32020-01-09 15:58:07 +0100210 ManifestDtBuilder &LoadAddress(uint64_t value)
211 {
212 return Integer64Property("load_address", value);
213 }
214
215 ManifestDtBuilder &FfaPartition()
216 {
217 return BooleanProperty("is_ffa_partition");
218 }
219
Andrew Scullae9962e2019-10-03 16:51:16 +0100220 ManifestDtBuilder &Property(const std::string_view &name,
221 const std::string_view &value)
222 {
223 dts_ << name << " = " << value << ";" << std::endl;
224 return *this;
225 }
226
Manish Pandeyfa1f2912020-05-05 12:57:01 +0100227 ManifestDtBuilder &Label(const std::string_view &name)
228 {
229 dts_ << name << ": ";
230 return *this;
231 }
232
Manish Pandeycb8fbb22020-08-18 00:04:43 +0100233 ManifestDtBuilder &FfaValidManifest()
234 {
235 Compatible({"arm,ffa-manifest-1.0"});
236 Property("ffa-version", "<0x10000>");
237 Property("uuid",
238 "<0xb4b5671e 0x4a904fe1 0xb81ffb13 0xdae1dacb>");
239 Property("execution-ctx-count", "<1>");
240 Property("exception-level", "<2>");
241 Property("execution-state", "<0>");
J-Alves2f86c1e2022-02-23 18:44:19 +0000242 Property("entrypoint-offset", "<0x00002000>");
Manish Pandeycb8fbb22020-08-18 00:04:43 +0100243 Property("xlat-granule", "<0>");
J-Alvesb37fd082020-10-22 12:29:21 +0100244 Property("boot-order", "<0>");
Maksims Svecovsb596eab2021-04-27 00:52:27 +0100245 Property("messaging-method", "<4>");
Madhukar Pappireddy84154052022-06-21 18:30:25 -0500246 Property("ns-interrupts-action", "<1>");
Manish Pandeycb8fbb22020-08-18 00:04:43 +0100247 return *this;
248 }
249
David Brazdil52256ff2019-08-23 15:15:15 +0100250 private:
251 ManifestDtBuilder &StringProperty(const std::string_view &name,
252 const std::string_view &value)
253 {
254 dts_ << name << " = \"" << value << "\";" << std::endl;
255 return *this;
256 }
257
David Brazdil74e9c3b2019-08-28 11:09:08 +0100258 ManifestDtBuilder &StringListProperty(
259 const std::string_view &name,
260 const std::vector<std::string_view> &value)
261 {
262 bool is_first = true;
263
264 dts_ << name << " = ";
265 for (const std::string_view &entry : value) {
266 if (is_first) {
267 is_first = false;
268 } else {
269 dts_ << ", ";
270 }
271 dts_ << "\"" << entry << "\"";
272 }
273 dts_ << ";" << std::endl;
274 return *this;
275 }
276
David Brazdil52256ff2019-08-23 15:15:15 +0100277 ManifestDtBuilder &IntegerProperty(const std::string_view &name,
Andrew Scullae9962e2019-10-03 16:51:16 +0100278 uint32_t value)
David Brazdil52256ff2019-08-23 15:15:15 +0100279 {
280 dts_ << name << " = <" << value << ">;" << std::endl;
281 return *this;
282 }
283
David Brazdil080ee312020-02-25 15:30:30 -0800284 ManifestDtBuilder &Integer64Property(const std::string_view &name,
285 uint64_t value)
286 {
287 uint32_t high = value >> 32;
288 uint32_t low = (uint32_t)value;
289 dts_ << name << " = <" << high << " " << low << ">;"
290 << std::endl;
291 return *this;
292 }
293
Andrew Scullae9962e2019-10-03 16:51:16 +0100294 ManifestDtBuilder &IntegerListProperty(
295 const std::string_view &name,
296 const std::vector<uint32_t> &value)
297 {
298 dts_ << name << " = < ";
299 for (const uint32_t entry : value) {
300 dts_ << entry << " ";
301 }
302 dts_ << ">;" << std::endl;
303 return *this;
304 }
305
306 ManifestDtBuilder &BooleanProperty(const std::string_view &name)
307 {
Andrew Scull5dc089e2019-11-04 13:21:03 +0000308 dts_ << name << ";" << std::endl;
309 return *this;
Andrew Scullae9962e2019-10-03 16:51:16 +0100310 }
311
David Brazdil52256ff2019-08-23 15:15:15 +0100312 std::stringstream dts_;
313};
314
Daniel Boulby801f8ef2022-06-27 14:21:01 +0100315class manifest : public ::testing::Test
David Brazdil0dbb41f2019-09-09 18:03:35 +0100316{
Daniel Boulby801f8ef2022-06-27 14:21:01 +0100317 void SetUp() override
318 {
319 test_heap = std::make_unique<uint8_t[]>(TEST_HEAP_SIZE);
320 mpool_init(&ppool, MM_PPOOL_ENTRY_SIZE);
321 mpool_add_chunk(&ppool, test_heap.get(), TEST_HEAP_SIZE);
322 }
323
Olivier Deprez93644652022-09-09 11:01:12 +0200324 void TearDown() override
325 {
326 manifest_dealloc();
327 }
328
Daniel Boulby801f8ef2022-06-27 14:21:01 +0100329 std::unique_ptr<uint8_t[]> test_heap;
330
331 protected:
Olivier Deprez62d99e32020-01-09 15:58:07 +0100332 struct mpool ppool;
David Brazdil0dbb41f2019-09-09 18:03:35 +0100333
Olivier Deprez93644652022-09-09 11:01:12 +0200334 void manifest_dealloc(void)
335 {
336 manifest_deinit(&ppool);
337 }
338
Daniel Boulby801f8ef2022-06-27 14:21:01 +0100339 public:
340 /**
341 * Class for programatically building a Partition package.
342 */
343 class Partition_package
344 {
345 public:
346 __attribute__((aligned(PAGE_SIZE))) struct sp_pkg_header spkg;
347 __attribute__((
348 aligned(PAGE_SIZE))) char manifest_dtb[PAGE_SIZE] = {};
349 __attribute__((aligned(PAGE_SIZE))) char img[PAGE_SIZE] = {};
David Brazdil0dbb41f2019-09-09 18:03:35 +0100350
Daniel Boulby801f8ef2022-06-27 14:21:01 +0100351 Partition_package(const std::vector<char> &vec)
352 {
353 // Initialise header field
354 spkg.magic = SP_PKG_HEADER_MAGIC;
355 spkg.version = SP_PKG_HEADER_VERSION_2;
356 spkg.pm_offset = PAGE_SIZE;
357 spkg.pm_size = vec.size();
358 spkg.img_offset = 2 * PAGE_SIZE;
359 spkg.img_size = ARRAY_SIZE(img);
360
361 // Copy dtb into package
362 std::copy(vec.begin(), vec.end(), manifest_dtb);
363 }
364 };
365
366 enum manifest_return_code manifest_from_vec(
Olivier Deprez93644652022-09-09 11:01:12 +0200367 struct_manifest **m, const std::vector<char> &vec)
Daniel Boulby801f8ef2022-06-27 14:21:01 +0100368 {
369 struct memiter it;
370 struct mm_stage1_locked mm_stage1_locked;
Daniel Boulby801f8ef2022-06-27 14:21:01 +0100371
372 memiter_init(&it, vec.data(), vec.size());
Daniel Boulby801f8ef2022-06-27 14:21:01 +0100373
Olivier Deprez93644652022-09-09 11:01:12 +0200374 return manifest_init(mm_stage1_locked, m, &it, &ppool);
Daniel Boulby801f8ef2022-06-27 14:21:01 +0100375 }
376
377 enum manifest_return_code ffa_manifest_from_vec(
Olivier Deprez93644652022-09-09 11:01:12 +0200378 struct_manifest **m, const std::vector<char> &vec)
Daniel Boulby801f8ef2022-06-27 14:21:01 +0100379 {
380 struct memiter it;
381 struct mm_stage1_locked mm_stage1_locked;
Daniel Boulby801f8ef2022-06-27 14:21:01 +0100382 Partition_package spkg(vec);
383
384 /* clang-format off */
385 std::vector<char> core_dtb = ManifestDtBuilder()
386 .StartChild("hypervisor")
387 .Compatible()
388 .StartChild("vm1")
389 .DebugName("primary_vm")
390 .FfaPartition()
391 .LoadAddress((uint64_t)&spkg)
392 .EndChild()
393 .EndChild()
394 .Build();
395 /* clang-format on */
396 memiter_init(&it, core_dtb.data(), core_dtb.size());
Daniel Boulby801f8ef2022-06-27 14:21:01 +0100397
Olivier Deprez93644652022-09-09 11:01:12 +0200398 return manifest_init(mm_stage1_locked, m, &it, &ppool);
Daniel Boulby801f8ef2022-06-27 14:21:01 +0100399 }
400};
401
402TEST_F(manifest, no_hypervisor_node)
David Brazdil7a462ec2019-08-15 12:27:47 +0100403{
Olivier Deprez93644652022-09-09 11:01:12 +0200404 struct_manifest *m;
David Brazdil52256ff2019-08-23 15:15:15 +0100405 std::vector<char> dtb = ManifestDtBuilder().Build();
David Brazdil7a462ec2019-08-15 12:27:47 +0100406
David Brazdila2358d42020-01-27 18:51:38 +0000407 ASSERT_EQ(manifest_from_vec(&m, dtb),
David Brazdil7a462ec2019-08-15 12:27:47 +0100408 MANIFEST_ERROR_NO_HYPERVISOR_FDT_NODE);
409}
410
Daniel Boulby801f8ef2022-06-27 14:21:01 +0100411TEST_F(manifest, no_compatible_property)
David Brazdil7a462ec2019-08-15 12:27:47 +0100412{
Olivier Deprez93644652022-09-09 11:01:12 +0200413 struct_manifest *m;
David Brazdil7a462ec2019-08-15 12:27:47 +0100414
David Brazdil52256ff2019-08-23 15:15:15 +0100415 /* clang-format off */
416 std::vector<char> dtb = ManifestDtBuilder()
417 .StartChild("hypervisor")
418 .EndChild()
419 .Build();
420 /* clang-format on */
421
David Brazdilf4925382020-03-25 13:33:51 +0000422 ASSERT_EQ(manifest_from_vec(&m, dtb), MANIFEST_ERROR_NOT_COMPATIBLE);
David Brazdil7a462ec2019-08-15 12:27:47 +0100423}
424
Daniel Boulby801f8ef2022-06-27 14:21:01 +0100425TEST_F(manifest, not_compatible)
David Brazdil7a462ec2019-08-15 12:27:47 +0100426{
Olivier Deprez93644652022-09-09 11:01:12 +0200427 struct_manifest *m;
David Brazdil7a462ec2019-08-15 12:27:47 +0100428
David Brazdil52256ff2019-08-23 15:15:15 +0100429 /* clang-format off */
430 std::vector<char> dtb = ManifestDtBuilder()
431 .StartChild("hypervisor")
David Brazdil74e9c3b2019-08-28 11:09:08 +0100432 .Compatible({ "foo,bar" })
433 .EndChild()
434 .Build();
435 /* clang-format on */
436
David Brazdila2358d42020-01-27 18:51:38 +0000437 ASSERT_EQ(manifest_from_vec(&m, dtb), MANIFEST_ERROR_NOT_COMPATIBLE);
David Brazdil74e9c3b2019-08-28 11:09:08 +0100438}
439
Daniel Boulby801f8ef2022-06-27 14:21:01 +0100440TEST_F(manifest, compatible_one_of_many)
David Brazdil74e9c3b2019-08-28 11:09:08 +0100441{
Olivier Deprez93644652022-09-09 11:01:12 +0200442 struct_manifest *m;
David Brazdil74e9c3b2019-08-28 11:09:08 +0100443
444 /* clang-format off */
445 std::vector<char> dtb = ManifestDtBuilder()
446 .StartChild("hypervisor")
447 .Compatible({ "foo,bar", "hafnium,hafnium" })
448 .StartChild("vm1")
449 .DebugName("primary")
450 .EndChild()
451 .EndChild()
452 .Build();
453 /* clang-format on */
454
David Brazdila2358d42020-01-27 18:51:38 +0000455 ASSERT_EQ(manifest_from_vec(&m, dtb), MANIFEST_SUCCESS);
David Brazdil74e9c3b2019-08-28 11:09:08 +0100456}
457
Daniel Boulby801f8ef2022-06-27 14:21:01 +0100458TEST_F(manifest, no_vm_nodes)
David Brazdil74e9c3b2019-08-28 11:09:08 +0100459{
Olivier Deprez93644652022-09-09 11:01:12 +0200460 struct_manifest *m;
David Brazdil74e9c3b2019-08-28 11:09:08 +0100461
462 /* clang-format off */
463 std::vector<char> dtb = ManifestDtBuilder()
464 .StartChild("hypervisor")
465 .Compatible()
466 .EndChild()
467 .Build();
468 /* clang-format on */
469
David Brazdila2358d42020-01-27 18:51:38 +0000470 ASSERT_EQ(manifest_from_vec(&m, dtb), MANIFEST_ERROR_NO_PRIMARY_VM);
David Brazdil0dbb41f2019-09-09 18:03:35 +0100471}
472
473static std::vector<char> gen_long_string_dtb(bool valid)
474{
475 const char last_valid[] = "1234567890123456789012345678901";
476 const char first_invalid[] = "12345678901234567890123456789012";
David Brazdil136f2942019-09-23 14:11:03 +0100477 static_assert(sizeof(last_valid) == STRING_MAX_SIZE);
478 static_assert(sizeof(first_invalid) == STRING_MAX_SIZE + 1);
David Brazdil0dbb41f2019-09-09 18:03:35 +0100479
480 /* clang-format off */
481 return ManifestDtBuilder()
482 .StartChild("hypervisor")
483 .Compatible()
484 .StartChild("vm1")
485 .DebugName(valid ? last_valid : first_invalid)
486 .EndChild()
487 .EndChild()
488 .Build();
489 /* clang-format on */
490}
491
Daniel Boulby801f8ef2022-06-27 14:21:01 +0100492TEST_F(manifest, long_string)
David Brazdil0dbb41f2019-09-09 18:03:35 +0100493{
Olivier Deprez93644652022-09-09 11:01:12 +0200494 struct_manifest *m;
David Brazdil0dbb41f2019-09-09 18:03:35 +0100495 std::vector<char> dtb_last_valid = gen_long_string_dtb(true);
496 std::vector<char> dtb_first_invalid = gen_long_string_dtb(false);
497
David Brazdila2358d42020-01-27 18:51:38 +0000498 ASSERT_EQ(manifest_from_vec(&m, dtb_last_valid), MANIFEST_SUCCESS);
Olivier Deprez93644652022-09-09 11:01:12 +0200499 manifest_dealloc();
500
David Brazdila2358d42020-01-27 18:51:38 +0000501 ASSERT_EQ(manifest_from_vec(&m, dtb_first_invalid),
502 MANIFEST_ERROR_STRING_TOO_LONG);
David Brazdil74e9c3b2019-08-28 11:09:08 +0100503}
504
Daniel Boulby801f8ef2022-06-27 14:21:01 +0100505TEST_F(manifest, reserved_vm_id)
David Brazdil74e9c3b2019-08-28 11:09:08 +0100506{
Olivier Deprez93644652022-09-09 11:01:12 +0200507 struct_manifest *m;
David Brazdil74e9c3b2019-08-28 11:09:08 +0100508
509 /* clang-format off */
510 std::vector<char> dtb = ManifestDtBuilder()
511 .StartChild("hypervisor")
512 .Compatible()
David Brazdil52256ff2019-08-23 15:15:15 +0100513 .StartChild("vm1")
514 .DebugName("primary_vm")
515 .EndChild()
516 .StartChild("vm0")
517 .DebugName("reserved_vm")
518 .VcpuCount(1)
519 .MemSize(0x1000)
520 .KernelFilename("kernel")
521 .EndChild()
522 .EndChild()
523 .Build();
524 /* clang-format on */
525
David Brazdila2358d42020-01-27 18:51:38 +0000526 ASSERT_EQ(manifest_from_vec(&m, dtb), MANIFEST_ERROR_RESERVED_VM_ID);
David Brazdil7a462ec2019-08-15 12:27:47 +0100527}
528
Andrew Scullae9962e2019-10-03 16:51:16 +0100529static std::vector<char> gen_vcpu_count_limit_dtb(uint32_t vcpu_count)
David Brazdil52256ff2019-08-23 15:15:15 +0100530{
531 /* clang-format off */
532 return ManifestDtBuilder()
533 .StartChild("hypervisor")
David Brazdil74e9c3b2019-08-28 11:09:08 +0100534 .Compatible()
David Brazdil52256ff2019-08-23 15:15:15 +0100535 .StartChild("vm1")
536 .DebugName("primary_vm")
537 .EndChild()
538 .StartChild("vm2")
539 .DebugName("secondary_vm")
540 .VcpuCount(vcpu_count)
541 .MemSize(0x1000)
542 .KernelFilename("kernel")
543 .EndChild()
544 .EndChild()
545 .Build();
546 /* clang-format on */
547}
David Brazdil7a462ec2019-08-15 12:27:47 +0100548
Daniel Boulby801f8ef2022-06-27 14:21:01 +0100549TEST_F(manifest, vcpu_count_limit)
David Brazdil7a462ec2019-08-15 12:27:47 +0100550{
Olivier Deprez93644652022-09-09 11:01:12 +0200551 struct_manifest *m;
David Brazdil52256ff2019-08-23 15:15:15 +0100552 std::vector<char> dtb_last_valid = gen_vcpu_count_limit_dtb(UINT16_MAX);
553 std::vector<char> dtb_first_invalid =
554 gen_vcpu_count_limit_dtb(UINT16_MAX + 1);
David Brazdil7a462ec2019-08-15 12:27:47 +0100555
David Brazdila2358d42020-01-27 18:51:38 +0000556 ASSERT_EQ(manifest_from_vec(&m, dtb_last_valid), MANIFEST_SUCCESS);
Olivier Deprez93644652022-09-09 11:01:12 +0200557 ASSERT_EQ(m->vm_count, 2);
558 ASSERT_EQ(m->vm[1].secondary.vcpu_count, UINT16_MAX);
559 manifest_dealloc();
David Brazdil7a462ec2019-08-15 12:27:47 +0100560
David Brazdila2358d42020-01-27 18:51:38 +0000561 ASSERT_EQ(manifest_from_vec(&m, dtb_first_invalid),
David Brazdil0dbb41f2019-09-09 18:03:35 +0100562 MANIFEST_ERROR_INTEGER_OVERFLOW);
David Brazdil7a462ec2019-08-15 12:27:47 +0100563}
564
Daniel Boulby801f8ef2022-06-27 14:21:01 +0100565TEST_F(manifest, no_ramdisk_primary)
David Brazdile6f83222019-09-23 14:47:37 +0100566{
Olivier Deprez93644652022-09-09 11:01:12 +0200567 struct_manifest *m;
David Brazdile6f83222019-09-23 14:47:37 +0100568
569 /* clang-format off */
570 std::vector<char> dtb = ManifestDtBuilder()
571 .StartChild("hypervisor")
572 .Compatible()
573 .StartChild("vm1")
574 .DebugName("primary_vm")
575 .EndChild()
576 .EndChild()
577 .Build();
578 /* clang-format on */
579
David Brazdila2358d42020-01-27 18:51:38 +0000580 ASSERT_EQ(manifest_from_vec(&m, dtb), MANIFEST_SUCCESS);
Olivier Deprez93644652022-09-09 11:01:12 +0200581 ASSERT_EQ(m->vm_count, 1);
582 ASSERT_STREQ(string_data(&m->vm[0].debug_name), "primary_vm");
583 ASSERT_STREQ(string_data(&m->vm[0].primary.ramdisk_filename), "");
David Brazdile6f83222019-09-23 14:47:37 +0100584}
585
Daniel Boulby801f8ef2022-06-27 14:21:01 +0100586TEST_F(manifest, no_boot_address_primary)
David Brazdil080ee312020-02-25 15:30:30 -0800587{
Olivier Deprez93644652022-09-09 11:01:12 +0200588 struct_manifest *m;
David Brazdil080ee312020-02-25 15:30:30 -0800589
590 /* clang-format off */
591 std::vector<char> dtb = ManifestDtBuilder()
592 .StartChild("hypervisor")
593 .Compatible()
594 .StartChild("vm1")
595 .DebugName("primary_vm")
596 .EndChild()
597 .EndChild()
598 .Build();
599 /* clang-format on */
600
601 ASSERT_EQ(manifest_from_vec(&m, dtb), MANIFEST_SUCCESS);
Olivier Deprez93644652022-09-09 11:01:12 +0200602 ASSERT_EQ(m->vm_count, 1);
603 ASSERT_STREQ(string_data(&m->vm[0].debug_name), "primary_vm");
604 ASSERT_EQ(m->vm[0].primary.boot_address, MANIFEST_INVALID_ADDRESS);
David Brazdil080ee312020-02-25 15:30:30 -0800605}
606
Daniel Boulby801f8ef2022-06-27 14:21:01 +0100607TEST_F(manifest, boot_address_primary)
David Brazdil080ee312020-02-25 15:30:30 -0800608{
Olivier Deprez93644652022-09-09 11:01:12 +0200609 struct_manifest *m;
David Brazdil080ee312020-02-25 15:30:30 -0800610 const uint64_t addr = UINT64_C(0x12345678ABCDEFEF);
611
612 /* clang-format off */
613 std::vector<char> dtb = ManifestDtBuilder()
614 .StartChild("hypervisor")
615 .Compatible()
616 .StartChild("vm1")
617 .DebugName("primary_vm")
618 .BootAddress(addr)
619 .EndChild()
620 .EndChild()
621 .Build();
622 /* clang-format on */
623
624 ASSERT_EQ(manifest_from_vec(&m, dtb), MANIFEST_SUCCESS);
Olivier Deprez93644652022-09-09 11:01:12 +0200625 ASSERT_EQ(m->vm_count, 1);
626 ASSERT_STREQ(string_data(&m->vm[0].debug_name), "primary_vm");
627 ASSERT_EQ(m->vm[0].primary.boot_address, addr);
David Brazdil080ee312020-02-25 15:30:30 -0800628}
629
Andrew Scullb2c3a242019-11-04 13:52:36 +0000630static std::vector<char> gen_malformed_boolean_dtb(
631 const std::string_view &value)
Andrew Scullae9962e2019-10-03 16:51:16 +0100632{
Andrew Scullae9962e2019-10-03 16:51:16 +0100633 /* clang-format off */
Andrew Scullb2c3a242019-11-04 13:52:36 +0000634 return ManifestDtBuilder()
Andrew Scullae9962e2019-10-03 16:51:16 +0100635 .StartChild("hypervisor")
636 .Compatible()
637 .StartChild("vm1")
638 .DebugName("primary_vm")
Andrew Scullb2c3a242019-11-04 13:52:36 +0000639 .Property("smc_whitelist_permissive", value)
Andrew Scull5dc089e2019-11-04 13:21:03 +0000640 .EndChild()
Andrew Scullae9962e2019-10-03 16:51:16 +0100641 .EndChild()
642 .Build();
643 /* clang-format on */
Andrew Scullb2c3a242019-11-04 13:52:36 +0000644}
Andrew Scullae9962e2019-10-03 16:51:16 +0100645
Daniel Boulby801f8ef2022-06-27 14:21:01 +0100646TEST_F(manifest, malformed_booleans)
Andrew Scullb2c3a242019-11-04 13:52:36 +0000647{
Olivier Deprez93644652022-09-09 11:01:12 +0200648 struct_manifest *m;
Andrew Scullae9962e2019-10-03 16:51:16 +0100649
Andrew Scullb2c3a242019-11-04 13:52:36 +0000650 std::vector<char> dtb_false = gen_malformed_boolean_dtb("\"false\"");
651 std::vector<char> dtb_true = gen_malformed_boolean_dtb("\"true\"");
652 std::vector<char> dtb_0 = gen_malformed_boolean_dtb("\"<0>\"");
653 std::vector<char> dtb_1 = gen_malformed_boolean_dtb("\"<1>\"");
Andrew Scullae9962e2019-10-03 16:51:16 +0100654
David Brazdila2358d42020-01-27 18:51:38 +0000655 ASSERT_EQ(manifest_from_vec(&m, dtb_false),
Andrew Scullb2c3a242019-11-04 13:52:36 +0000656 MANIFEST_ERROR_MALFORMED_BOOLEAN);
Olivier Deprez93644652022-09-09 11:01:12 +0200657 manifest_dealloc();
658
David Brazdila2358d42020-01-27 18:51:38 +0000659 ASSERT_EQ(manifest_from_vec(&m, dtb_true),
Andrew Scullb2c3a242019-11-04 13:52:36 +0000660 MANIFEST_ERROR_MALFORMED_BOOLEAN);
Olivier Deprez93644652022-09-09 11:01:12 +0200661 manifest_dealloc();
662
David Brazdila2358d42020-01-27 18:51:38 +0000663 ASSERT_EQ(manifest_from_vec(&m, dtb_0),
Andrew Scullb2c3a242019-11-04 13:52:36 +0000664 MANIFEST_ERROR_MALFORMED_BOOLEAN);
Olivier Deprez93644652022-09-09 11:01:12 +0200665 manifest_dealloc();
666
David Brazdila2358d42020-01-27 18:51:38 +0000667 ASSERT_EQ(manifest_from_vec(&m, dtb_1),
Andrew Scullb2c3a242019-11-04 13:52:36 +0000668 MANIFEST_ERROR_MALFORMED_BOOLEAN);
Andrew Scullae9962e2019-10-03 16:51:16 +0100669}
670
Daniel Boulby801f8ef2022-06-27 14:21:01 +0100671TEST_F(manifest, valid)
David Brazdil7a462ec2019-08-15 12:27:47 +0100672{
Olivier Deprez93644652022-09-09 11:01:12 +0200673 struct_manifest *m;
David Brazdil7a462ec2019-08-15 12:27:47 +0100674 struct manifest_vm *vm;
David Brazdil7a462ec2019-08-15 12:27:47 +0100675
David Brazdil52256ff2019-08-23 15:15:15 +0100676 /* clang-format off */
677 std::vector<char> dtb = ManifestDtBuilder()
678 .StartChild("hypervisor")
David Brazdil74e9c3b2019-08-28 11:09:08 +0100679 .Compatible()
David Brazdil52256ff2019-08-23 15:15:15 +0100680 .StartChild("vm1")
681 .DebugName("primary_vm")
Andrew Scull72b43c02019-09-18 13:53:45 +0100682 .KernelFilename("primary_kernel")
David Brazdile6f83222019-09-23 14:47:37 +0100683 .RamdiskFilename("primary_ramdisk")
Andrew Scullae9962e2019-10-03 16:51:16 +0100684 .SmcWhitelist({0x32000000, 0x33001111})
David Brazdil52256ff2019-08-23 15:15:15 +0100685 .EndChild()
686 .StartChild("vm3")
687 .DebugName("second_secondary_vm")
688 .VcpuCount(43)
689 .MemSize(0x12345)
Andrew Scull72b43c02019-09-18 13:53:45 +0100690 .KernelFilename("second_secondary_kernel")
David Brazdil52256ff2019-08-23 15:15:15 +0100691 .EndChild()
692 .StartChild("vm2")
693 .DebugName("first_secondary_vm")
694 .VcpuCount(42)
695 .MemSize(12345)
Andrew Scullae9962e2019-10-03 16:51:16 +0100696 .SmcWhitelist({0x04000000, 0x30002222, 0x31445566})
697 .SmcWhitelistPermissive()
David Brazdil52256ff2019-08-23 15:15:15 +0100698 .EndChild()
699 .EndChild()
700 .Build();
701 /* clang-format on */
702
David Brazdila2358d42020-01-27 18:51:38 +0000703 ASSERT_EQ(manifest_from_vec(&m, dtb), MANIFEST_SUCCESS);
Olivier Deprez93644652022-09-09 11:01:12 +0200704 ASSERT_EQ(m->vm_count, 3);
David Brazdil7a462ec2019-08-15 12:27:47 +0100705
Olivier Deprez93644652022-09-09 11:01:12 +0200706 vm = &m->vm[0];
David Brazdil136f2942019-09-23 14:11:03 +0100707 ASSERT_STREQ(string_data(&vm->debug_name), "primary_vm");
708 ASSERT_STREQ(string_data(&vm->kernel_filename), "primary_kernel");
David Brazdile6f83222019-09-23 14:47:37 +0100709 ASSERT_STREQ(string_data(&vm->primary.ramdisk_filename),
710 "primary_ramdisk");
Andrew Scullae9962e2019-10-03 16:51:16 +0100711 ASSERT_THAT(
712 std::span(vm->smc_whitelist.smcs, vm->smc_whitelist.smc_count),
713 ElementsAre(0x32000000, 0x33001111));
714 ASSERT_FALSE(vm->smc_whitelist.permissive);
David Brazdil7a462ec2019-08-15 12:27:47 +0100715
Olivier Deprez93644652022-09-09 11:01:12 +0200716 vm = &m->vm[1];
David Brazdil136f2942019-09-23 14:11:03 +0100717 ASSERT_STREQ(string_data(&vm->debug_name), "first_secondary_vm");
718 ASSERT_STREQ(string_data(&vm->kernel_filename), "");
David Brazdil7a462ec2019-08-15 12:27:47 +0100719 ASSERT_EQ(vm->secondary.vcpu_count, 42);
720 ASSERT_EQ(vm->secondary.mem_size, 12345);
Andrew Scullae9962e2019-10-03 16:51:16 +0100721 ASSERT_THAT(
722 std::span(vm->smc_whitelist.smcs, vm->smc_whitelist.smc_count),
723 ElementsAre(0x04000000, 0x30002222, 0x31445566));
724 ASSERT_TRUE(vm->smc_whitelist.permissive);
David Brazdil7a462ec2019-08-15 12:27:47 +0100725
Olivier Deprez93644652022-09-09 11:01:12 +0200726 vm = &m->vm[2];
David Brazdil136f2942019-09-23 14:11:03 +0100727 ASSERT_STREQ(string_data(&vm->debug_name), "second_secondary_vm");
728 ASSERT_STREQ(string_data(&vm->kernel_filename),
729 "second_secondary_kernel");
David Brazdil7a462ec2019-08-15 12:27:47 +0100730 ASSERT_EQ(vm->secondary.vcpu_count, 43);
731 ASSERT_EQ(vm->secondary.mem_size, 0x12345);
Andrew Scullae9962e2019-10-03 16:51:16 +0100732 ASSERT_THAT(
733 std::span(vm->smc_whitelist.smcs, vm->smc_whitelist.smc_count),
734 IsEmpty());
735 ASSERT_FALSE(vm->smc_whitelist.permissive);
David Brazdil7a462ec2019-08-15 12:27:47 +0100736}
737
Daniel Boulby801f8ef2022-06-27 14:21:01 +0100738TEST_F(manifest, ffa_not_compatible)
Olivier Deprez62d99e32020-01-09 15:58:07 +0100739{
Olivier Deprez93644652022-09-09 11:01:12 +0200740 struct_manifest *m;
Olivier Deprez62d99e32020-01-09 15:58:07 +0100741
742 /* clang-format off */
743 std::vector<char> dtb = ManifestDtBuilder()
744 .Compatible({ "arm,ffa-manifest-2.0" })
745 .Property("ffa-version", "<0x10000>")
746 .Property("uuid", "<0xb4b5671e 0x4a904fe1 0xb81ffb13 0xdae1dacb>")
747 .Property("execution-ctx-count", "<1>")
748 .Property("exception-level", "<2>")
749 .Property("execution-state", "<0>")
J-Alves2f86c1e2022-02-23 18:44:19 +0000750 .Property("entrypoint-offset", "<0x00002000>")
Olivier Deprez62d99e32020-01-09 15:58:07 +0100751 .Property("xlat-granule", "<0>")
752 .Property("messaging-method", "<1>")
Madhukar Pappireddy84154052022-06-21 18:30:25 -0500753 .Property("ns-interrupts-action", "<1>")
Olivier Deprez62d99e32020-01-09 15:58:07 +0100754 .Build();
755 /* clang-format on */
756
757 ASSERT_EQ(ffa_manifest_from_vec(&m, dtb),
758 MANIFEST_ERROR_NOT_COMPATIBLE);
759}
760
Daniel Boulby801f8ef2022-06-27 14:21:01 +0100761TEST_F(manifest, ffa_missing_property)
Olivier Deprez62d99e32020-01-09 15:58:07 +0100762{
Olivier Deprez93644652022-09-09 11:01:12 +0200763 struct_manifest *m;
Olivier Deprez62d99e32020-01-09 15:58:07 +0100764
765 /* clang-format off */
766 std::vector<char> dtb = ManifestDtBuilder()
767 .Compatible({ "arm,ffa-manifest-1.0" })
768 .Property("ffa-version", "<0x10000>")
769 .Build();
770 /* clang-format on */
771
772 ASSERT_EQ(ffa_manifest_from_vec(&m, dtb),
773 MANIFEST_ERROR_PROPERTY_NOT_FOUND);
774}
775
Daniel Boulby801f8ef2022-06-27 14:21:01 +0100776TEST_F(manifest, ffa_validate_sanity_check)
Olivier Deprez62d99e32020-01-09 15:58:07 +0100777{
J-Alvesb37fd082020-10-22 12:29:21 +0100778 /*
779 * TODO: write test excluding all optional fields of the manifest, in
780 * accordance with specification.
781 */
Olivier Deprez93644652022-09-09 11:01:12 +0200782 struct_manifest *m;
Olivier Deprez62d99e32020-01-09 15:58:07 +0100783
784 /* Incompatible version */
785 /* clang-format off */
786 std::vector<char> dtb = ManifestDtBuilder()
787 .Compatible({ "arm,ffa-manifest-1.0" })
788 .Property("ffa-version", "<0xa1>")
789 .Property("uuid", "<0xb4b5671e 0x4a904fe1 0xb81ffb13 0xdae1dacb>")
790 .Property("execution-ctx-count", "<1>")
791 .Property("exception-level", "<2>")
792 .Property("execution-state", "<0>")
J-Alves2f86c1e2022-02-23 18:44:19 +0000793 .Property("entrypoint-offset", "<0x00002000>")
Olivier Deprez62d99e32020-01-09 15:58:07 +0100794 .Property("xlat-granule", "<0>")
J-Alvesb37fd082020-10-22 12:29:21 +0100795 .Property("boot-order", "<0>")
Olivier Deprez62d99e32020-01-09 15:58:07 +0100796 .Property("messaging-method", "<1>")
Madhukar Pappireddy84154052022-06-21 18:30:25 -0500797 .Property("ns-interrupts-action", "<1>")
Olivier Deprez62d99e32020-01-09 15:58:07 +0100798 .Build();
799 /* clang-format on */
800 ASSERT_EQ(ffa_manifest_from_vec(&m, dtb),
801 MANIFEST_ERROR_NOT_COMPATIBLE);
Olivier Deprez93644652022-09-09 11:01:12 +0200802 manifest_dealloc();
Olivier Deprez62d99e32020-01-09 15:58:07 +0100803
804 /* Incompatible translation granule */
805 /* clang-format off */
806 dtb = ManifestDtBuilder()
807 .Compatible({ "arm,ffa-manifest-1.0" })
808 .Property("ffa-version", "<0x10000>")
809 .Property("uuid", "<0xb4b5671e 0x4a904fe1 0xb81ffb13 0xdae1dacb>")
810 .Property("execution-ctx-count", "<1>")
811 .Property("exception-level", "<2>")
812 .Property("execution-state", "<0>")
J-Alves2f86c1e2022-02-23 18:44:19 +0000813 .Property("entrypoint-offset", "<0x00002000>")
Olivier Deprez62d99e32020-01-09 15:58:07 +0100814 .Property("xlat-granule", "<3>")
J-Alvesb37fd082020-10-22 12:29:21 +0100815 .Property("boot-order", "<0>")
Olivier Deprez62d99e32020-01-09 15:58:07 +0100816 .Property("messaging-method", "<1>")
Madhukar Pappireddy84154052022-06-21 18:30:25 -0500817 .Property("ns-interrupts-action", "<1>")
Olivier Deprez62d99e32020-01-09 15:58:07 +0100818 .Build();
819 /* clang-format on */
820 ASSERT_EQ(ffa_manifest_from_vec(&m, dtb),
821 MANIFEST_ERROR_NOT_COMPATIBLE);
Olivier Deprez93644652022-09-09 11:01:12 +0200822 manifest_dealloc();
Olivier Deprez62d99e32020-01-09 15:58:07 +0100823
824 /* Incompatible exeption level */
825 /* clang-format off */
826 dtb = ManifestDtBuilder()
827 .Compatible({ "arm,ffa-manifest-1.0" })
828 .Property("ffa-version", "<0x10000>")
829 .Property("uuid", "<0xb4b5671e 0x4a904fe1 0xb81ffb13 0xdae1dacb>")
830 .Property("execution-ctx-count", "<1>")
831 .Property("exception-level", "<6>")
832 .Property("execution-state", "<0>")
J-Alves2f86c1e2022-02-23 18:44:19 +0000833 .Property("entrypoint-offset", "<0x00002000>")
Olivier Deprez62d99e32020-01-09 15:58:07 +0100834 .Property("xlat-granule", "<0>")
J-Alvesb37fd082020-10-22 12:29:21 +0100835 .Property("boot-order", "<0>")
Olivier Deprez62d99e32020-01-09 15:58:07 +0100836 .Property("messaging-method", "<1>")
Madhukar Pappireddy84154052022-06-21 18:30:25 -0500837 .Property("ns-interrupts-action", "<0>")
Olivier Deprez62d99e32020-01-09 15:58:07 +0100838 .Build();
839 /* clang-format on */
840 ASSERT_EQ(ffa_manifest_from_vec(&m, dtb),
841 MANIFEST_ERROR_NOT_COMPATIBLE);
Olivier Deprez93644652022-09-09 11:01:12 +0200842 manifest_dealloc();
Olivier Deprez62d99e32020-01-09 15:58:07 +0100843
844 /* Incompatible execution state */
845 /* clang-format off */
846 dtb = ManifestDtBuilder()
847 .Compatible({ "arm,ffa-manifest-1.0" })
848 .Property("ffa-version", "<0x10000>")
849 .Property("uuid", "<0xb4b5671e 0x4a904fe1 0xb81ffb13 0xdae1dacb>")
850 .Property("execution-ctx-count", "<1>")
851 .Property("exception-level", "<2>")
852 .Property("execution-state", "<2>")
J-Alves2f86c1e2022-02-23 18:44:19 +0000853 .Property("entrypoint-offset", "<0x00002000>")
Olivier Deprez62d99e32020-01-09 15:58:07 +0100854 .Property("xlat-granule", "<0>")
J-Alvesb37fd082020-10-22 12:29:21 +0100855 .Property("boot-order", "<0>")
Olivier Deprez62d99e32020-01-09 15:58:07 +0100856 .Property("messaging-method", "<1>")
Madhukar Pappireddy84154052022-06-21 18:30:25 -0500857 .Property("ns-interrupts-action", "<0>")
Olivier Deprez62d99e32020-01-09 15:58:07 +0100858 .Build();
859 /* clang-format on */
860 ASSERT_EQ(ffa_manifest_from_vec(&m, dtb),
861 MANIFEST_ERROR_NOT_COMPATIBLE);
Olivier Deprez93644652022-09-09 11:01:12 +0200862 manifest_dealloc();
Olivier Deprez62d99e32020-01-09 15:58:07 +0100863
864 /* Incompatible messaging method */
865 /* clang-format off */
866 dtb = ManifestDtBuilder()
867 .Compatible({ "arm,ffa-manifest-1.0" })
868 .Property("ffa-version", "<0x10000>")
869 .Property("uuid", "<0xb4b5671e 0x4a904fe1 0xb81ffb13 0xdae1dacb>")
870 .Property("execution-ctx-count", "<1>")
871 .Property("exception-level", "<2>")
872 .Property("execution-state", "<0>")
J-Alves2f86c1e2022-02-23 18:44:19 +0000873 .Property("entrypoint-offset", "<0x00002000>")
Olivier Deprez62d99e32020-01-09 15:58:07 +0100874 .Property("xlat-granule", "<0>")
J-Alvesb37fd082020-10-22 12:29:21 +0100875 .Property("boot-order", "<0>")
Maksims Svecovsb596eab2021-04-27 00:52:27 +0100876 .Property("messaging-method", "<16>")
Madhukar Pappireddy84154052022-06-21 18:30:25 -0500877 .Property("ns-interrupts-action", "<0>")
Olivier Deprez62d99e32020-01-09 15:58:07 +0100878 .Build();
879 /* clang-format on */
880 ASSERT_EQ(ffa_manifest_from_vec(&m, dtb),
881 MANIFEST_ERROR_NOT_COMPATIBLE);
Olivier Deprez93644652022-09-09 11:01:12 +0200882 manifest_dealloc();
Madhukar Pappireddy84154052022-06-21 18:30:25 -0500883
884 /* Incompatible NS interrupt action */
885 /* clang-format off */
886 dtb = ManifestDtBuilder()
887 .Compatible({ "arm,ffa-manifest-1.0" })
888 .Property("ffa-version", "<0x10000>")
889 .Property("uuid", "<0xb4b5671e 0x4a904fe1 0xb81ffb13 0xdae1dacb>")
890 .Property("execution-ctx-count", "<1>")
891 .Property("exception-level", "<2>")
892 .Property("execution-state", "<0>")
893 .Property("entrypoint-offset", "<0x00002000>")
894 .Property("xlat-granule", "<0>")
895 .Property("boot-order", "<0>")
896 .Property("messaging-method", "<1>")
897 .Property("ns-interrupts-action", "<4>")
898 .Build();
899 /* clang-format on */
900 ASSERT_EQ(ffa_manifest_from_vec(&m, dtb), MANIFEST_ILLEGAL_NS_ACTION);
Olivier Deprez62d99e32020-01-09 15:58:07 +0100901}
902
Daniel Boulby801f8ef2022-06-27 14:21:01 +0100903TEST_F(manifest, ffa_validate_rxtx_info)
Manish Pandeyfa1f2912020-05-05 12:57:01 +0100904{
Olivier Deprez93644652022-09-09 11:01:12 +0200905 struct_manifest *m;
Manish Pandeyfa1f2912020-05-05 12:57:01 +0100906
907 /* Not Compatible */
908 /* clang-format off */
909 std::vector<char> dtb = ManifestDtBuilder()
910 .FfaValidManifest()
911 .StartChild("rx_tx-info")
912 .Compatible({ "foo,bar" })
913 .EndChild()
914 .Build();
915 /* clang-format on */
916 ASSERT_EQ(ffa_manifest_from_vec(&m, dtb),
917 MANIFEST_ERROR_NOT_COMPATIBLE);
Olivier Deprez93644652022-09-09 11:01:12 +0200918 manifest_dealloc();
Manish Pandeyfa1f2912020-05-05 12:57:01 +0100919
920 /* Missing Properties */
921 /* clang-format off */
922 dtb = ManifestDtBuilder()
923 .FfaValidManifest()
924 .StartChild("rx_tx-info")
925 .Compatible({ "arm,ffa-manifest-rx_tx-buffer" })
926 .EndChild()
927 .Build();
928 /* clang-format on */
929 ASSERT_EQ(ffa_manifest_from_vec(&m, dtb),
930 MANIFEST_ERROR_PROPERTY_NOT_FOUND);
931}
932
Daniel Boulby801f8ef2022-06-27 14:21:01 +0100933TEST_F(manifest, ffa_validate_mem_regions)
Manish Pandey6542f5c2020-04-27 14:37:46 +0100934{
Olivier Deprez93644652022-09-09 11:01:12 +0200935 struct_manifest *m;
Manish Pandey6542f5c2020-04-27 14:37:46 +0100936
937 /* Not Compatible */
938 /* clang-format off */
939 std::vector<char> dtb = ManifestDtBuilder()
940 .FfaValidManifest()
941 .StartChild("memory-regions")
942 .Compatible({ "foo,bar" })
943 .EndChild()
944 .Build();
945 /* clang-format on */
946 ASSERT_EQ(ffa_manifest_from_vec(&m, dtb),
947 MANIFEST_ERROR_NOT_COMPATIBLE);
Olivier Deprez93644652022-09-09 11:01:12 +0200948 manifest_dealloc();
Manish Pandey6542f5c2020-04-27 14:37:46 +0100949
950 /* Memory regions unavailable */
951 /* clang-format off */
952 dtb = ManifestDtBuilder()
953 .FfaValidManifest()
954 .StartChild("memory-regions")
955 .Compatible({ "arm,ffa-manifest-memory-regions" })
956 .EndChild()
957 .Build();
958 /* clang-format on */
959 ASSERT_EQ(ffa_manifest_from_vec(&m, dtb),
960 MANIFEST_ERROR_MEMORY_REGION_NODE_EMPTY);
Olivier Deprez93644652022-09-09 11:01:12 +0200961 manifest_dealloc();
Manish Pandey6542f5c2020-04-27 14:37:46 +0100962
963 /* Missing Properties */
964 /* clang-format off */
965 dtb = ManifestDtBuilder()
966 .FfaValidManifest()
967 .StartChild("memory-regions")
968 .Compatible({ "arm,ffa-manifest-memory-regions" })
969 .StartChild("test-memory")
970 .Description("test-memory")
971 .EndChild()
972 .EndChild()
973 .Build();
974 /* clang-format on */
975 ASSERT_EQ(ffa_manifest_from_vec(&m, dtb),
976 MANIFEST_ERROR_PROPERTY_NOT_FOUND);
Olivier Deprez93644652022-09-09 11:01:12 +0200977 manifest_dealloc();
Manish Pandeyf06c9072020-09-29 15:41:58 +0100978
Daniel Boulby9279b552022-06-28 17:04:01 +0100979 /* Overlapping memory regions */
980 /* clang-format off */
981 dtb = ManifestDtBuilder()
982 .FfaValidManifest()
983 .StartChild("memory-regions")
984 .Compatible({ "arm,ffa-manifest-memory-regions" })
985 .Label("rx")
986 .StartChild("rx")
987 .Description("rx-buffer")
988 .Property("base-address", "<0x7300000>")
989 .Property("pages-count", "<1>")
990 .Property("attributes", "<1>")
991 .EndChild()
992 .Label("tx")
993 .StartChild("tx")
994 .Description("tx-buffer")
995 .Property("base-address", "<0x7300000>")
996 .Property("pages-count", "<2>")
997 .Property("attributes", "<3>")
998 .EndChild()
999 .EndChild()
1000 .Build();
1001 /* clang-format on */
1002 ASSERT_EQ(ffa_manifest_from_vec(&m, dtb),
1003 MANIFEST_ERROR_MEM_REGION_OVERLAP);
Olivier Deprez93644652022-09-09 11:01:12 +02001004 manifest_dealloc();
Daniel Boulby9279b552022-06-28 17:04:01 +01001005
1006 /* clang-format off */
1007 dtb = ManifestDtBuilder()
1008 .FfaValidManifest()
1009 .StartChild("memory-regions")
1010 .Compatible({ "arm,ffa-manifest-memory-regions" })
1011 .Label("rx")
1012 .StartChild("rx")
1013 .Description("rx-buffer")
1014 .Property("base-address", "<0x7300000>")
1015 .Property("pages-count", "<2>")
1016 .Property("attributes", "<1>")
1017 .EndChild()
1018 .Label("tx")
1019 .StartChild("tx")
1020 .Description("tx-buffer")
1021 .Property("base-address", "<0x7301000>")
1022 .Property("pages-count", "<2>")
1023 .Property("attributes", "<3>")
1024 .EndChild()
1025 .EndChild()
1026 .Build();
1027 /* clang-format on */
1028 ASSERT_EQ(ffa_manifest_from_vec(&m, dtb),
1029 MANIFEST_ERROR_MEM_REGION_OVERLAP);
Olivier Deprez93644652022-09-09 11:01:12 +02001030 manifest_dealloc();
Daniel Boulby9279b552022-06-28 17:04:01 +01001031
1032 /* clang-format off */
1033 dtb = ManifestDtBuilder()
1034 .FfaValidManifest()
1035 .StartChild("memory-regions")
1036 .Compatible({ "arm,ffa-manifest-memory-regions" })
1037 .Label("rx")
1038 .StartChild("rx")
1039 .Description("rx-buffer")
1040 .Property("base-address", "<0x7300000>")
1041 .Property("pages-count", "<2>")
1042 .Property("attributes", "<1>")
1043 .EndChild()
1044 .Label("tx")
1045 .StartChild("tx")
1046 .Description("tx-buffer")
1047 .Property("base-address", "<0x7301FFF>")
1048 .Property("pages-count", "<2>")
1049 .Property("attributes", "<3>")
1050 .EndChild()
1051 .EndChild()
1052 .Build();
1053 /* clang-format on */
1054 ASSERT_EQ(ffa_manifest_from_vec(&m, dtb),
1055 MANIFEST_ERROR_MEM_REGION_OVERLAP);
Olivier Deprez93644652022-09-09 11:01:12 +02001056 manifest_dealloc();
Daniel Boulby9279b552022-06-28 17:04:01 +01001057
Manish Pandeyf06c9072020-09-29 15:41:58 +01001058 /* Different RXTX buffer sizes */
1059 /* clang-format off */
1060 dtb = ManifestDtBuilder()
1061 .FfaValidManifest()
1062 .StartChild("memory-regions")
1063 .Compatible({ "arm,ffa-manifest-memory-regions" })
1064 .Label("rx")
1065 .StartChild("rx")
1066 .Description("rx-buffer")
1067 .Property("base-address", "<0x7300000>")
1068 .Property("pages-count", "<1>")
1069 .Property("attributes", "<1>")
1070 .EndChild()
1071 .Label("tx")
1072 .StartChild("tx")
1073 .Description("tx-buffer")
1074 .Property("base-address", "<0x7310000>")
1075 .Property("pages-count", "<2>")
1076 .Property("attributes", "<3>")
1077 .EndChild()
1078 .EndChild()
1079 .StartChild("rx_tx-info")
1080 .Compatible({ "arm,ffa-manifest-rx_tx-buffer" })
1081 .Property("rx-buffer", "<&rx>")
1082 .Property("tx-buffer", "<&tx>")
1083 .EndChild()
1084 .Build();
1085 /* clang-format on */
1086 ASSERT_EQ(ffa_manifest_from_vec(&m, dtb),
1087 MANIFEST_ERROR_RXTX_SIZE_MISMATCH);
Manish Pandey6542f5c2020-04-27 14:37:46 +01001088}
1089
Daniel Boulby801f8ef2022-06-27 14:21:01 +01001090TEST_F(manifest, ffa_validate_dev_regions)
Manish Pandeye68e7932020-04-23 15:29:28 +01001091{
Olivier Deprez93644652022-09-09 11:01:12 +02001092 struct_manifest *m;
Manish Pandeye68e7932020-04-23 15:29:28 +01001093
1094 /* Not Compatible */
1095 /* clang-format off */
1096 std::vector<char> dtb = ManifestDtBuilder()
1097 .FfaValidManifest()
1098 .StartChild("device-regions")
1099 .Compatible({ "foo,bar" })
1100 .EndChild()
1101 .Build();
1102 /* clang-format on */
1103 ASSERT_EQ(ffa_manifest_from_vec(&m, dtb),
1104 MANIFEST_ERROR_NOT_COMPATIBLE);
Olivier Deprez93644652022-09-09 11:01:12 +02001105 manifest_dealloc();
Manish Pandeye68e7932020-04-23 15:29:28 +01001106
1107 /* Memory regions unavailable */
1108 /* clang-format off */
1109 dtb = ManifestDtBuilder()
1110 .FfaValidManifest()
1111 .StartChild("device-regions")
1112 .Compatible({ "arm,ffa-manifest-device-regions" })
1113 .EndChild()
1114 .Build();
1115 /* clang-format on */
1116 ASSERT_EQ(ffa_manifest_from_vec(&m, dtb),
1117 MANIFEST_ERROR_DEVICE_REGION_NODE_EMPTY);
Olivier Deprez93644652022-09-09 11:01:12 +02001118 manifest_dealloc();
Manish Pandeye68e7932020-04-23 15:29:28 +01001119
1120 /* Missing Properties */
1121 /* clang-format off */
1122 dtb = ManifestDtBuilder()
1123 .FfaValidManifest()
1124 .StartChild("device-regions")
1125 .Compatible({ "arm,ffa-manifest-device-regions" })
1126 .StartChild("test-device")
1127 .Description("test-device")
1128 .EndChild()
1129 .EndChild()
1130 .Build();
1131 /* clang-format on */
1132 ASSERT_EQ(ffa_manifest_from_vec(&m, dtb),
1133 MANIFEST_ERROR_PROPERTY_NOT_FOUND);
Olivier Deprez93644652022-09-09 11:01:12 +02001134 manifest_dealloc();
Manish Pandeye68e7932020-04-23 15:29:28 +01001135
1136 /* Malformed interrupt list pair */
1137 /* clang-format off */
1138 dtb = ManifestDtBuilder()
1139 .FfaValidManifest()
1140 .StartChild("device-regions")
1141 .Compatible({ "arm,ffa-manifest-device-regions" })
1142 .StartChild("test-device")
1143 .Description("test-device")
1144 .Property("base-address", "<0x7200000>")
1145 .Property("pages-count", "<16>")
1146 .Property("attributes", "<3>")
1147 .Property("smmu-id", "<1>")
1148 .Property("stream-ids", "<0 1>")
1149 .Property("interrupts", "<2 3>, <4>")
1150 .EndChild()
1151 .EndChild()
1152 .Build();
1153 /* clang-format on */
1154 ASSERT_EQ(ffa_manifest_from_vec(&m, dtb),
1155 MANIFEST_ERROR_MALFORMED_INTEGER_LIST);
Olivier Deprez93644652022-09-09 11:01:12 +02001156 manifest_dealloc();
Daniel Boulby667334f2022-06-27 15:23:21 +01001157
1158 /* Non-unique interrupt IDs */
1159 /* clang-format off */
1160 dtb = ManifestDtBuilder()
1161 .FfaValidManifest()
1162 .StartChild("device-regions")
1163 .Compatible({ "arm,ffa-manifest-device-regions" })
1164 .StartChild("test-device-0")
1165 .Description("test-device-0")
1166 .Property("base-address", "<0x7200000>")
1167 .Property("pages-count", "<16>")
1168 .Property("attributes", "<3>")
1169 .Property("interrupts", "<2 3>")
1170 .EndChild()
1171 .StartChild("test-device-1")
1172 .Description("test-device-1")
1173 .Property("base-address", "<0x8200000>")
1174 .Property("pages-count", "<16>")
1175 .Property("attributes", "<3>")
1176 .Property("interrupts", "<1 3>, <2 5> ")
1177 .EndChild()
1178 .EndChild()
1179 .Build();
1180 /* clang-format on */
1181 ASSERT_EQ(ffa_manifest_from_vec(&m, dtb),
1182 MANIFEST_ERROR_INTERRUPT_ID_REPEATED);
1183 /* Check valid interrupts were still mapped */
Olivier Deprez93644652022-09-09 11:01:12 +02001184 ASSERT_EQ(m->vm[0].partition.dev_regions[0].interrupts[0].id, 2);
1185 ASSERT_EQ(m->vm[0].partition.dev_regions[0].interrupts[0].attributes,
1186 3);
1187 ASSERT_EQ(m->vm[0].partition.dev_regions[1].interrupts[0].id, 1);
1188 ASSERT_EQ(m->vm[0].partition.dev_regions[1].interrupts[0].attributes,
1189 3);
Manish Pandeye68e7932020-04-23 15:29:28 +01001190}
Daniel Boulby801f8ef2022-06-27 14:21:01 +01001191
1192TEST_F(manifest, ffa_invalid_memory_region_attributes)
Raghu Krishnamurthy384693c2021-10-11 13:56:24 -07001193{
Olivier Deprez93644652022-09-09 11:01:12 +02001194 struct_manifest *m;
Raghu Krishnamurthy384693c2021-10-11 13:56:24 -07001195
1196 /* clang-format off */
1197 std::vector<char> dtb = ManifestDtBuilder()
1198 .FfaValidManifest()
1199 .StartChild("rx_tx-info")
1200 .Compatible({ "arm,ffa-manifest-rx_tx-buffer" })
1201 .Property("rx-buffer", "<&rx>")
1202 .Property("tx-buffer", "<&tx>")
1203 .EndChild()
1204 .StartChild("memory-regions")
1205 .Compatible({ "arm,ffa-manifest-memory-regions" })
1206 .StartChild("test-memory")
1207 .Description("test-memory")
1208 .Property("base-address", "<0x7100000>")
1209 .Property("pages-count", "<4>")
1210 .Property("attributes", "<7>")
1211 .EndChild()
1212 .Label("rx")
1213 .StartChild("rx")
1214 .Description("rx-buffer")
1215 .Property("base-address", "<0x7300000>")
1216 .Property("pages-count", "<1>")
1217 .Property("attributes", "<1>")
1218 .EndChild()
1219 .Label("tx")
1220 .StartChild("tx")
1221 .Description("tx-buffer")
1222 .Property("base-address", "<0x7310000>")
1223 .Property("pages-count", "<1>")
1224 .Property("attributes", "<3>")
1225 .EndChild()
1226 .EndChild()
1227 .Build();
1228 /* clang-format on */
1229
1230 ASSERT_EQ(ffa_manifest_from_vec(&m, dtb),
1231 MANIFEST_ERROR_INVALID_MEM_PERM);
1232}
1233
Daniel Boulby801f8ef2022-06-27 14:21:01 +01001234TEST_F(manifest, ffa_invalid_device_region_attributes)
Raghu Krishnamurthy384693c2021-10-11 13:56:24 -07001235{
Olivier Deprez93644652022-09-09 11:01:12 +02001236 struct_manifest *m;
Raghu Krishnamurthy384693c2021-10-11 13:56:24 -07001237
1238 /* clang-format off */
1239 std::vector<char> dtb = ManifestDtBuilder()
1240 .FfaValidManifest()
1241 .StartChild("rx_tx-info")
1242 .Compatible({ "arm,ffa-manifest-rx_tx-buffer" })
1243 .Property("rx-buffer", "<&rx>")
1244 .Property("tx-buffer", "<&tx>")
1245 .EndChild()
1246 .StartChild("memory-regions")
1247 .Compatible({ "arm,ffa-manifest-memory-regions" })
1248 .StartChild("test-memory")
1249 .Description("test-memory")
1250 .Property("base-address", "<0x7100000>")
1251 .Property("pages-count", "<4>")
1252 .Property("attributes", "<3>")
1253 .EndChild()
1254 .Label("rx")
1255 .StartChild("rx")
1256 .Description("rx-buffer")
1257 .Property("base-address", "<0x7300000>")
1258 .Property("pages-count", "<1>")
1259 .Property("attributes", "<1>")
1260 .EndChild()
1261 .Label("tx")
1262 .StartChild("tx")
1263 .Description("tx-buffer")
1264 .Property("base-address", "<0x7310000>")
1265 .Property("pages-count", "<1>")
1266 .Property("attributes", "<3>")
1267 .EndChild()
1268 .EndChild()
1269 .StartChild("device-regions")
1270 .Compatible({ "arm,ffa-manifest-device-regions" })
1271 .StartChild("test-device")
1272 .Description("test-device")
1273 .Property("base-address", "<0x7200000>")
1274 .Property("pages-count", "<16>")
1275 .Property("attributes", "<5>")
1276 .Property("smmu-id", "<1>")
1277 .Property("stream-ids", "<0 1>")
1278 .Property("interrupts", "<2 3>, <4 5>")
1279 .EndChild()
1280 .EndChild()
1281 .Build();
1282 /* clang-format on */
1283
1284 ASSERT_EQ(ffa_manifest_from_vec(&m, dtb),
1285 MANIFEST_ERROR_INVALID_MEM_PERM);
1286}
Manish Pandeye68e7932020-04-23 15:29:28 +01001287
Daniel Boulby801f8ef2022-06-27 14:21:01 +01001288TEST_F(manifest, ffa_valid)
Olivier Deprez62d99e32020-01-09 15:58:07 +01001289{
Olivier Deprez93644652022-09-09 11:01:12 +02001290 struct manifest_vm *vm;
1291 struct_manifest *m;
Olivier Deprez62d99e32020-01-09 15:58:07 +01001292
1293 /* clang-format off */
1294 std::vector<char> dtb = ManifestDtBuilder()
Manish Pandeycb8fbb22020-08-18 00:04:43 +01001295 .FfaValidManifest()
Manish Pandeyfa1f2912020-05-05 12:57:01 +01001296 .StartChild("rx_tx-info")
1297 .Compatible({ "arm,ffa-manifest-rx_tx-buffer" })
1298 .Property("rx-buffer", "<&rx>")
1299 .Property("tx-buffer", "<&tx>")
1300 .EndChild()
Manish Pandey6542f5c2020-04-27 14:37:46 +01001301 .StartChild("memory-regions")
1302 .Compatible({ "arm,ffa-manifest-memory-regions" })
1303 .StartChild("test-memory")
1304 .Description("test-memory")
1305 .Property("base-address", "<0x7100000>")
1306 .Property("pages-count", "<4>")
Raghu Krishnamurthy384693c2021-10-11 13:56:24 -07001307 .Property("attributes", "<3>")
Manish Pandey6542f5c2020-04-27 14:37:46 +01001308 .EndChild()
Olivier Deprez035fa152022-03-14 11:19:10 +01001309 .StartChild("test-memory-ns")
1310 .Description("test-memory")
1311 .Property("base-address", "<0x7200000>")
1312 .Property("pages-count", "<1>")
1313 .Property("attributes", "<0xb>")
1314 .EndChild()
Manish Pandeyfa1f2912020-05-05 12:57:01 +01001315 .Label("rx")
1316 .StartChild("rx")
1317 .Description("rx-buffer")
1318 .Property("base-address", "<0x7300000>")
1319 .Property("pages-count", "<1>")
1320 .Property("attributes", "<1>")
1321 .EndChild()
1322 .Label("tx")
1323 .StartChild("tx")
1324 .Description("tx-buffer")
Daniel Boulby9279b552022-06-28 17:04:01 +01001325 .Property("base-address", "<0x7301000>")
Manish Pandeyfa1f2912020-05-05 12:57:01 +01001326 .Property("pages-count", "<1>")
1327 .Property("attributes", "<3>")
1328 .EndChild()
Manish Pandey6542f5c2020-04-27 14:37:46 +01001329 .EndChild()
Manish Pandeye68e7932020-04-23 15:29:28 +01001330 .StartChild("device-regions")
1331 .Compatible({ "arm,ffa-manifest-device-regions" })
1332 .StartChild("test-device")
1333 .Description("test-device")
Olivier Deprez035fa152022-03-14 11:19:10 +01001334 .Property("base-address", "<0x7400000>")
Manish Pandeye68e7932020-04-23 15:29:28 +01001335 .Property("pages-count", "<16>")
1336 .Property("attributes", "<3>")
1337 .Property("smmu-id", "<1>")
1338 .Property("stream-ids", "<0 1>")
1339 .Property("interrupts", "<2 3>, <4 5>")
1340 .EndChild()
Olivier Deprez035fa152022-03-14 11:19:10 +01001341 .StartChild("test-device-ns")
1342 .Description("test-device")
1343 .Property("base-address", "<0x7500000>")
1344 .Property("pages-count", "<1>")
1345 .Property("attributes", "<0x9>")
1346 .EndChild()
Manish Pandeye68e7932020-04-23 15:29:28 +01001347 .EndChild()
Olivier Deprez62d99e32020-01-09 15:58:07 +01001348 .Build();
1349 /* clang-format on */
1350
1351 ASSERT_EQ(ffa_manifest_from_vec(&m, dtb), MANIFEST_SUCCESS);
1352
Olivier Deprez93644652022-09-09 11:01:12 +02001353 vm = &m->vm[0];
1354 ASSERT_EQ(vm->partition.ffa_version, 0x10000);
Olivier Deprez62d99e32020-01-09 15:58:07 +01001355 ASSERT_THAT(
Olivier Deprez93644652022-09-09 11:01:12 +02001356 std::span(vm->partition.uuid.uuid, 4),
Olivier Deprez62d99e32020-01-09 15:58:07 +01001357 ElementsAre(0xb4b5671e, 0x4a904fe1, 0xb81ffb13, 0xdae1dacb));
Olivier Deprez93644652022-09-09 11:01:12 +02001358 ASSERT_EQ(vm->partition.execution_ctx_count, 1);
1359 ASSERT_EQ(vm->partition.run_time_el, S_EL1);
1360 ASSERT_EQ(vm->partition.execution_state, AARCH64);
1361 ASSERT_EQ(vm->partition.ep_offset, 0x00002000);
1362 ASSERT_EQ(vm->partition.xlat_granule, PAGE_4KB);
1363 ASSERT_EQ(vm->partition.boot_order, 0);
1364 ASSERT_EQ(vm->partition.messaging_method, FFA_PARTITION_INDIRECT_MSG);
1365 ASSERT_EQ(vm->partition.ns_interrupts_action, NS_ACTION_ME);
1366 ASSERT_EQ(vm->partition.mem_regions[0].base_address, 0x7100000);
1367 ASSERT_EQ(vm->partition.mem_regions[0].page_count, 4);
1368 ASSERT_EQ(vm->partition.mem_regions[0].attributes, 3);
1369 ASSERT_EQ(vm->partition.mem_regions[1].attributes, (8 | 3));
Raghu Krishnamurthy8c250a92021-07-02 12:16:42 -07001370
Olivier Deprez93644652022-09-09 11:01:12 +02001371 ASSERT_EQ(vm->partition.rxtx.available, true);
1372 ASSERT_EQ(vm->partition.rxtx.rx_buffer->base_address, 0x7300000);
1373 ASSERT_EQ(vm->partition.rxtx.rx_buffer->page_count, 1);
1374 ASSERT_EQ(vm->partition.rxtx.rx_buffer->attributes, 1);
1375 ASSERT_EQ(vm->partition.rxtx.tx_buffer->base_address, 0x7301000);
1376 ASSERT_EQ(vm->partition.rxtx.tx_buffer->page_count, 1);
1377 ASSERT_EQ(vm->partition.rxtx.tx_buffer->attributes, 3);
1378
1379 ASSERT_EQ(vm->partition.dev_regions[0].base_address, 0x7400000);
1380 ASSERT_EQ(vm->partition.dev_regions[0].page_count, 16);
1381 ASSERT_EQ(vm->partition.dev_regions[0].attributes, 3);
1382 ASSERT_EQ(vm->partition.dev_regions[0].smmu_id, 1);
1383 ASSERT_EQ(vm->partition.dev_regions[0].stream_ids[0], 0);
1384 ASSERT_EQ(vm->partition.dev_regions[0].stream_ids[1], 1);
1385 ASSERT_EQ(vm->partition.dev_regions[0].interrupts[0].id, 2);
1386 ASSERT_EQ(vm->partition.dev_regions[0].interrupts[0].attributes, 3);
1387 ASSERT_EQ(vm->partition.dev_regions[0].interrupts[1].id, 4);
1388 ASSERT_EQ(vm->partition.dev_regions[0].interrupts[1].attributes, 5);
1389 ASSERT_EQ(vm->partition.dev_regions[1].attributes, (8 | 1));
Olivier Deprez62d99e32020-01-09 15:58:07 +01001390}
1391
David Brazdil7a462ec2019-08-15 12:27:47 +01001392} /* namespace */