Andrew Walbran | bc342d4 | 2019-02-05 16:56:02 +0000 | [diff] [blame] | 1 | /* |
| 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> |
Andrew Walbran | afabe85 | 2019-03-20 17:55:11 +0000 | [diff] [blame] | 18 | #include <stddef.h> |
Andrew Walbran | bc342d4 | 2019-02-05 16:56:02 +0000 | [diff] [blame] | 19 | #include <stdint.h> |
| 20 | #include <stdio.h> |
| 21 | #include <string.h> |
| 22 | #include <unistd.h> |
| 23 | |
| 24 | #include "hf/memiter.h" |
| 25 | |
Andrew Walbran | bc342d4 | 2019-02-05 16:56:02 +0000 | [diff] [blame] | 26 | #include "hftest_common.h" |
Andrew Walbran | 1e7c774 | 2019-12-13 17:10:02 +0000 | [diff] [blame] | 27 | #include "test/hftest.h" |
Andrew Walbran | bc342d4 | 2019-02-05 16:56:02 +0000 | [diff] [blame] | 28 | #include <sys/reboot.h> |
| 29 | |
| 30 | void test_main(int argc, const char *argv[]) |
| 31 | { |
Andrew Scull | 3c351e9 | 2020-01-28 11:26:05 +0000 | [diff] [blame] | 32 | static const char json_command[] = "json"; |
| 33 | static const char run_command[] = "run"; |
Andrew Walbran | bc342d4 | 2019-02-05 16:56:02 +0000 | [diff] [blame] | 34 | const char *command; |
| 35 | |
| 36 | if (argc < 2) { |
| 37 | HFTEST_LOG("Unable to parse command."); |
| 38 | return; |
| 39 | } |
| 40 | command = argv[1]; |
| 41 | |
| 42 | hftest_use_registered_list(); |
| 43 | |
Andrew Scull | 3c351e9 | 2020-01-28 11:26:05 +0000 | [diff] [blame] | 44 | if (strncmp(command, json_command, sizeof(json_command)) == 0) { |
Andrew Walbran | bc342d4 | 2019-02-05 16:56:02 +0000 | [diff] [blame] | 45 | hftest_json(); |
| 46 | return; |
| 47 | } |
| 48 | |
Andrew Scull | 3c351e9 | 2020-01-28 11:26:05 +0000 | [diff] [blame] | 49 | if (strncmp(command, run_command, sizeof(run_command)) == 0) { |
Andrew Walbran | bc342d4 | 2019-02-05 16:56:02 +0000 | [diff] [blame] | 50 | struct memiter suite_name; |
| 51 | struct memiter test_name; |
| 52 | |
| 53 | if (argc != 4) { |
| 54 | HFTEST_LOG("Unable to parse test."); |
| 55 | return; |
| 56 | } |
| 57 | |
Andrew Scull | 55baca6 | 2019-04-05 14:56:20 +0100 | [diff] [blame] | 58 | memiter_init(&suite_name, argv[2], strnlen_s(argv[2], 64)); |
| 59 | memiter_init(&test_name, argv[3], strnlen_s(argv[3], 64)); |
Andrew Walbran | afabe85 | 2019-03-20 17:55:11 +0000 | [diff] [blame] | 60 | hftest_run(suite_name, test_name, NULL); |
Andrew Walbran | bc342d4 | 2019-02-05 16:56:02 +0000 | [diff] [blame] | 61 | return; |
| 62 | } |
| 63 | |
| 64 | hftest_help(); |
| 65 | } |
| 66 | |
| 67 | int main(int argc, const char *argv[]) |
| 68 | { |
| 69 | test_main(argc, argv); |
| 70 | reboot(RB_POWER_OFF); |
| 71 | return 0; |
| 72 | } |