blob: c1bfa1abd46adcc41b8e276cca22da21cdbf84ef [file] [log] [blame]
Andrew Walbranbc342d42019-02-05 16:56:02 +00001/*
2 * Copyright 2019 The Hafnium Authors.
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 * https://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 <stdalign.h>
18#include <stdint.h>
19
20#include "hf/fdt.h"
21#include "hf/memiter.h"
22
23#include "hftest.h"
24#include "hftest_common.h"
25
26alignas(4096) uint8_t kstack[4096];
27
28extern struct hftest_test hftest_begin[];
29extern struct hftest_test hftest_end[];
30
31void kmain(const struct fdt_header *fdt)
32{
33 struct fdt_node n;
34 const char *bootargs;
35 uint32_t bootargs_size;
36 struct memiter bootargs_iter;
37 struct memiter command;
38
39 hftest_use_list(hftest_begin, hftest_end - hftest_begin);
40
41 if (!fdt_root_node(&n, fdt)) {
42 HFTEST_LOG("FDT failed validation.");
43 return;
44 }
45
46 if (!fdt_find_child(&n, "")) {
47 HFTEST_LOG("Unable to find root node in FDT.");
48 return;
49 }
50
51 if (!fdt_find_child(&n, "chosen")) {
52 HFTEST_LOG("Unable to find 'chosen' node in FDT.");
53 return;
54 }
55
56 if (!fdt_read_property(&n, "bootargs", &bootargs, &bootargs_size)) {
57 HFTEST_LOG("Unable to read bootargs.");
58 return;
59 }
60
61 /* Remove null terminator. */
62 memiter_init(&bootargs_iter, bootargs, bootargs_size - 1);
63
64 if (!memiter_parse_str(&bootargs_iter, &command)) {
65 HFTEST_LOG("Unable to parse command.");
66 return;
67 }
68
69 if (memiter_iseq(&command, "json")) {
70 hftest_json();
71 return;
72 }
73
74 if (memiter_iseq(&command, "run")) {
75 struct memiter suite_name;
76 struct memiter test_name;
77
78 if (!memiter_parse_str(&bootargs_iter, &suite_name)) {
79 HFTEST_LOG("Unable to parse test suite.");
80 return;
81 }
82
83 if (!memiter_parse_str(&bootargs_iter, &test_name)) {
84 HFTEST_LOG("Unable to parse test.");
85 return;
86 }
Andrew Walbranafabe852019-03-20 17:55:11 +000087 hftest_run(suite_name, test_name, fdt);
Andrew Walbranbc342d42019-02-05 16:56:02 +000088 return;
89 }
90
91 hftest_help();
92}